dweisman@umiami.ir.miami.edu (Ordinary Man) (06/01/91)
How do you get that darn callback routine for sound playing to work!? It bombs the second sound stops playing. I tried BOTH samples from the UMPG and neither seem to work (I copied them to the letter). The only thing I can think of right now is maybe there's a change for system 7. Help, please! System info: Mac Classic, 4Meg RAM, System 7. Thanks, Dan /-------------------------------------------------------------------------\ | Dan Weisman - University of Miami - Florida | || || || || | |--------------------------------------------------| || || ||\ /|| | | INTERNET -----> dweisman@umiami.IR.Miami.edu | || || || | || | | BITNET -----> dweisman@umiami | ||||||| || | || | |-------------------------------------------------------------------------| | "...the fact is- this friction will only be worn by persistance." -RUSH | \_________________________________________________________________________/
REEKES@applelink.apple.com (Jim Reekes) (06/02/91)
In article <1991May31.150602.10301@umiami.ir.miami.edu>, dweisman@umiami.ir.miami.edu (Ordinary Man) writes: > > > How do you get that darn callback routine for sound playing to work!? > It bombs the second sound stops playing. I tried BOTH samples from the UMPG and > neither seem to work (I copied them to the letter). The only thing I can think > of right now is maybe there's a change for system 7. Help, please! There's been no change in the callback routines. Here's a very short example of using a callback routine. I've never compiled these routines. Looks good; I say we ship it. This is in Pascal and you probably wanted it in C. Oh well, this is easy to translate. Maybe you forgot to declare the callback routine as Pascal? {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} PROCEDURE DoCallBack(chan: SndChannelPtr; theCmd: SndCommand); {If this routine was written in C I would setup A5, then call a seperate subroutine. Since C will do special optimizing of registers even before calling any of your code, it may attempt to assign an address to the global before we've had a chance to setup A5. This would be bad, so you'll have to watch out for that.} VAR theA5: LONGINT; BEGIN IF thecmd.param1 = kSoundComplete THEN BEGIN {if itUs my callBackCmd} theA5:= SetA5(theCmd.param2); {refer to tech note 208} gCalledBack:= TRUE; {set a global} theA5:= SetA5(theA5); {restore original A5} END; END; {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} FUNCTION PlaySounds: OSErr; {I need to pass in our A5 along with the command so that the callBack routine can access my globals. I could even put my A5 into the user field of the sndChannel. I wait until the channel is ready for another command in the case of the channel being full. Once the Sound Manager calls my call back procedure I will dispose of the channel. So, this is the last sound command to be sent to a channel. I pass to the call back A5 in the second parameter of the callBackCmd. Refer to Tech Note #208.} VAR theErr: OSErr; theCmd: SndCommand; BEGIN theErr:= noErr; IF gChan <> NIL THEN {global sound channel for asynchronous use} theErr:= SndDisposeChannel(gChan, NOT kWait); gChan:= NIL; theErr:= SndNewChannel(gChan, sampledSynth, 0, @DoCallBack); IF theErr = noErr THEN BEGIN {send some sound commands} WITH theCmd DO BEGIN cmd:= callBackCmd; param1:= kSoundComplete; {private constant} param2:= SetCurrentA5; END; theErr:= SndDoCommand(gChan, theCmd, kWait); END; PlaySound:= theErr; END; ----------------------------------------------------------------------- Jim Reekes, E.O. | Macintosh Toolbox Engineering | Sound Manger Expert Apple Computer, Inc. | "All opinions expressed are mine, and do 20525 Mariani Ave. MS: 81-EQ | not necessarily represent those of my Cupertino, CA 95014 | employer, Apple Computer Inc."