[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using the Sound Manager in MacIvory



 >Date: Thu, 1 Mar 90 11:07 PST
 >From: Larry Baum <larry@atc.boeing.com>
 >Subject: Using the Sound Manager in MacIvory
 >To: slug@Warbucks.AI.SRI.COM
 >
 >According to the MacIvory Programmer's Reference, I should be able to
 >access the following two functions:
 >
 >_SndPlay (channel sndhdl async) 
 >_SndNewChannel (chan synth init userroutine) -> newchan
 >
 [...]
 >But if I do:
 >
 >(_SndPlay nil (_getresource "snd " 4) t)
 >or
 >(_SndNewChannel nil 0 0 nil)
 >
 >in either case I get into the debugger with the error: 
 >   mac-os-error-badchannel: Invalid channel queue length

Here is some code we use to play mac "snd " resources from a MacIvory:

;;; -*- Mode: LISP; Syntax: Common-lisp; Package: USER; Base: 10 -*-

;; general facilities for interacting with Mac sounds

;; Play a mac snd resource by name. Name is a string.
(defun play-mac-sound (name)
  (let ((resource (condition-case ()
		       (mtb::_getnamedresource "snd " name)
		     (MTB:MAC-OS-ERROR-RESNOTFOUND 
		       (cerror "Continue into Debugger" 
			       "Sound resource ~A not found"
			       name)))))
    (mtb:_sndplay 0 resource t)))

;; Return a list of all snd resources in the system file.
(defun all-mac-sounds ()
  (let ((names))
    (mtb::do-rsrcs (ignore ignore name) ("snd " :all)
      (push (format nil "~A" name) names))
    (sort names #'string-lessp)))

(defun sound-menu ()
  (let ((sound (tv:menu-choose (all-mac-sounds) "Play sound:")))
    (if sound 
	(play-mac-sound sound))))


The only difference in the call to _sndplay from what you tried is that the
channel argument is 0, not nil. Perhaps the value NIL in "Inside MacIntosh" is
a predefined constant in MPW Pascal. I had to play with this quite a bit to
make it work too. It seems so simple now.

Jack Greenbaum
Dept. of Cognitive Science
U.C. San Diego

jackg@cogsci.ucsd.edu