Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucsd!hub!castor!stoms From: stoms@castor.ncgia.ucsb.edu (David Stoms) Newsgroups: comp.sys.mac.programmer Subject: Re: Need help with the new sound manager! Message-ID: <4271@hub.UUCP> Date: 11 Mar 90 19:17:53 GMT References: <900004@hpvcfs1.HP.COM> Sender: news@hub.UUCP Reply-To: stoms@castor.ncgia.ucsb.edu (David Stoms) Organization: U. C. Santa Barbara, Geography Department Lines: 81 In article <900004@hpvcfs1.HP.COM> stevem@hpvcfs1.HP.COM (Steve Miller) writes: >OK boys and girls, I'm about at my wits end on the subject of playing 'snd ' >resources on the Mac. I'm trying to use snd's in a simple game where the >sounds are played asynchronously while arcade style animation is occuring. I found this in one of my text directories (I can't verify that this is right)---- In article <1354@ndmath.UUCP> milo@ndmath.UUCP (Greg Corson) writes: > >Would anyone happen to have a code fragment that illustrates how to setup >the required callback routines so you can have SoundPlay play a sound in the >background (async) mode? > >1. open the channel and specify a callback >2. play a snd resource >3. have the callback set a global flag >4. have my main event loop close the channel when the flag is set. This is the code I am using. There is NO guarantee or warranty with this code. Use at your own risk! This is NOT Apple DTS sanctioned code. 1. the main application needs to keep a global variable is a SndChannelPtr. Initialize it to NIL. 2. Pass in the handle to the snd resource that you want to play. This should bootstrap to you greater understanding of the world of the Sound Manager. PROCEDURE PlayIt(VAR chan: SndChannelPtr; theSound: Handle); VAR err: OSErr; myWish: SndCommand; BEGIN IF chan <> NIL THEN {cancel sound in progress} BEGIN err := SndDisposeChannel(chan, TRUE); {TRUE means now} IF err <> noErr THEN BEGIN DebugStr('Cannot dispose of old channel'); Exit(PlayIt); END ELSE chan := NIL; END; err := SndNewChannel(chan, 0, 0, NIL); IF err <> noErr THEN BEGIN DebugStr('Cannot allocate new channel'); Exit(PlayIt); END; IF theSound <> NIL THEN {we have a handle} IF theSound^ <> NIL THEN {and is not a nil handle } BEGIN err:=SndPlay(chan, theSound, TRUE); IF err <> noErr THEN BEGIN DebugStr('Cannot play sound'); Exit(PlayIt); END; WITH myWish DO { set up a sound mgr command block } BEGIN cmd := freeCmd; {to free self when done } param1 := 0; param2 := 0; END; {with} err := SndDoCommand(chan, myWish, FALSE); IF err <> noErr THEN BEGIN DebugStr('cannot add command'); Exit(PlayIt); END; END; END;