[comp.sys.mac.programmer] Sound Manager problem

halpern@csri.toronto.edu (Charles Halpern) (03/19/90)

*** REPLACE THIS LINE WITH YOUR MESSAGE ***
The following Think C 3.02 bombs on a Mac SE with no inits.
I commucicated the code over the phone to someone using a Mac II,
and again it bombed.  Usually, though not always, the bomb occurs
with the second SndNewChannel call.  Variously, the problem is a 
bus error, odd address, illegal instruction, or the computer hangs.
It even happens without the Multifinder or the Debugger.  

osErr is never set to anything but noErr.

I presume that I am not understanding something.  I am using IM 5, 
I haven't got the relevant tech notes.  The code:

#include <SoundMgr.h>

void			main ()
{
OSErr 			osErr;
SndChannelPtr	channelP;

	channelP	= 0L;	

	osErr 		= SndNewChannel (&channelP, sampledSynth, 0L, 0L);

	osErr 		= SndDisposeChannel (channelP, TRUE);

	channelP	= 0L;	

	osErr 		= SndNewChannel (&channelP, sampledSynth, 0L, 0L);
}


That's the whole thing.  (My problems started in a complete program, but
I've shrunk it down to this with the same error.)  Variations have included
skipping the SndDisposeChannel, checking with availableCmd, varying the
synthesizer asked for, etc.  

Thanks,

Charlie Halpern
halpern@toronto.edu

vandevyver@ketje.enet.dec.com (Luc Van de Vyver) (12/10/90)

    I am writing a program, to control 2 slide-projectors with the MAC.

    The projectors can be controlled by sound. Every frequency has a
    meaning (ex. advance A, advance B, %light for projectore A ...);

    Everything works fine, except a fluent dissolve from one projector to
    the other. The reason for this is that I am using NOTES to send the a
    sound with the right frequency to the projector.

    For one reason or another exact FREQUENCY output seems not to work as
    indicated in the INSIDE MACINTOSH IV.

    I included the some test code which explains exactly what is not
    working. 
    btw, I am using a MAC SE, THINK C 3.0, finder 6.0.4

    All help is appreciated very much.

    Luc.


    CODE EXTRACT :

    #include "SoundMgr.h"
    #include "stdio.h"

    #define NIL			0
    #define NIL_POINTER		0L

    SndChannelPtr   	chanPtr 		= NIL;
    SndCommand      	sndCmd;
    long 		status, currNote;
    long		note			= 80L;
    long		freq1  			= 0x000F5DDE;
    long		freq2			= 0xEE0F5DDE;

    Frequency()

    {

    		/* Assign a channel to the Notesynthesizer */
    		chanPtr 	= NIL;
    		status 		= SndNewChannel(&chanPtr, 1, NIL, NIL_POINTER);


    		/* set the default timbre */
    		sndCmd.cmd	=	timbreCmd;
    		sndCmd.param1	=	1;
    		sndCmd.param2	= 	NIL;
    		status 		= 	SndDoImmediate(chanPtr, &sndCmd);
    		
    		sndCmd.cmd	=	ampCmd;
    		sndCmd.param1	=	100;
    		sndCmd.param2	= 	NIL;
    		status 		= 	SndDoImmediate(chanPtr, &sndCmd);

    /* this says piep */	
    		sndCmd.cmd	=	freqCmd;
    		sndCmd.param1	=	NIL;
    		sndCmd.param2	= 	note;
    		status 		= 	SndDoImmediate(chanPtr, &sndCmd);
    		printf("\n Status = %ld - freq = %ld", status,
      					sndCmd.param2, sndCmd.param2);
    		Wait(30);
    		
    /* this is silence WHY?????? */
    		sndCmd.cmd	=	freqCmd;
    		sndCmd.param1	=	NIL;
    		sndCmd.param2	= 	freq1;
    		status 		= 	SndDoImmediate(chanPtr, &sndCmd);                   
    		printf("\n Status = %ld - freq = %ld (%lX)", status,
    					sndCmd.param2, sndCmd.param2);
    		Wait(30);
    		
    /* this is silence WHY???????*/
    		sndCmd.cmd	=	freqCmd;
    		sndCmd.param1	=	NIL;
    		sndCmd.param2	= 	freq2;
    		status 		= 	SndDoImmediate(chanPtr, &sndCmd);
    		printf("\n Status = %ld - freq = %ld (%lX)", status,
    					sndCmd.param2, sndCmd.param2);
    		Wait(30);

    /* this says piep */	
    		sndCmd.cmd	=	freqCmd;
    		sndCmd.param1	=	NIL;
    		sndCmd.param2	= 	note;
    		status 		= 	SndDoImmediate(chanPtr, &sndCmd);
    		printf("\n Status = %ld - freq = %ld (%lX)", status,
    					sndCmd.param2, sndCmd.param2);
    		Wait (30);

    		status = SndDisposeChannel (chanPtr, FALSE);
    		chanPtr = NIL;


    }