[comp.sys.mac.programmer] Sys 6.0 sound manager on a plus

castan@munnari.oz (Jason Castan) (07/19/88)

I have written some sound playing program which uses the new sound manager.
However there seem to be some major differences between the mac ][ version, and
the plus version. For instance, when playing snd format one resources
I open a new channel with SndNewChannel - passing all the resource initialization variables, then call SndPlay (which works). However to dispose of the channel
I call SndDisposeChannel - here is the problem. On a mac ][ this is ok - works with no problems, on a plus - it bombs (deleting SndDisposeChannel stops the bomb). Does anyone know if SndPlay destroys the channel itself? (which would be a 
prblem when playing async - like I am). The code looks something like:

	SndChannelPtr	*chan;

	SndNewChannnel(&chan , ....);
	SndPlay(chan, TRUE); 		/* play asycronously */
	while (stillplaying...) loop
	/* when finished */
	SndDisposeChannel(chan, FALSE);		/* works on ][/ bombs on + */


Any comments or suggestions would be great. 
	Thanks,
			Jason.

adail@pnet06.cts.com (Alan Dail) (07/21/88)

I discovered the same thing on the 512E/Plus/SE.  WHat I do is to simply skip
the SndDisposeChannel call of SysEnvirons tells me that I'm not running on a
Mac II and everything seems to work just fine.
I don't know what will happen when system 6.01 is released though.

Alan Dail

UUCP: {crash uunet}!pnet06!adail
ARPA: crash!pnet06!adail@nosc.mil
INET: adail@pnet06.cts.com

lsr@Apple.COM (Larry Rosenstein) (07/29/88)

In article <2238@munnari.oz> castan@munnari.oz (Jason Castan) writes:
>I call SndDisposeChannel - here is the problem. On a mac ][ this is ok - works with no problems, on a plus - it bombs (deleting SndDisposeChannel stops the bomb). Does anyone know if SndPlay destroys the channel itself? (which would be a 
>prblem when playing async - like I am). The code looks something like:

When I was writing TimeKeeper (which plays a snd resource asynchronously), I
found that if you did not call SndDisposeChannel, you would disable the
SysBeep call on a Mac II.  Therefore,  I call SndDisposeChannel whenever the
sound is done.  The exact same code worked fine on a Mac Plus under System
6.0 (without recompiling).

The relevant procedures follow:

{ This plays the snd resource in gChime, or SysBeep if something goes
wrong.}

	PROCEDURE Chime;
		VAR	err:	OSErr;
			
	BEGIN
		err := 1; { default so SysBeep will get called }
		
		DisposeChannel; 		{ this also stops the sound }

		IF gChime <> NIL THEN
			BEGIN
			LoadResource(gChime);
			IF gChime^ <> NIL THEN
				BEGIN
				IF gSndChan = NIL THEN
					IF SndNewChannel(gSndChan, 0, 0, @ChanCallBack) = noErr THEN ;
					
				err := SndPlay(gSndChan, gChime, TRUE);
				
				END;
			END;
		
		IF err <> noErr THEN
			SysBeep(1);

		gSoundDone := gSndChan = NIL;
		gSoundStart := TickCount;
		
		IF NOT gSoundDone THEN
			err := SndDoCommand(gSndChan, gSndCallBack, FALSE);
	END;
	

	PROCEDURE DisposeChannel;
	BEGIN
		IF gSndChan <> NIL THEN
			IF SndDisposeChannel(gSndChan, TRUE) = noErr THEN 
				gSndChan := NIL;
		gSoundDone := TRUE;
	END;
	
	
The call back routine simply sets up A5 (because it is called at interrupt
level) and sets the gSoundDone boolean.  I haven't had any reports of
TimeKeeper crashing when trying to play its sound.  I even call
DisposeChannel before the sound is finished, which immediately terminates
the sound.

Therefore, I don't think the problem is a bug in the Mac Plus Sound Manager.

		 Larry Rosenstein,  Object Specialist
 Apple Computer, Inc.  20525 Mariani Ave, MS 46-B  Cupertino, CA 95014
	    AppleLink:Rosenstein1    domain:lsr@Apple.COM
		UUCP:{sun,voder,nsc,decwrl}!apple!lsr