From: REEKES@applelink.apple.com (Jim Reekes)
Newsgroups: comp.sys.mac.programmer
Subject: Re: Simple Sound Program
Date: 10 Apr 92 20:01:59 GMT
Distribution: comp.sys.mac.programmer
Organization: Apple Computer, Inc.

In article <1992Apr3.212545.18525@zip.eecs.umich.edu>, jacbop@z.eecs.umich.edu (Thomas Wilberding) writes:
> 
> I'm trying to write a simple program that will just play a 'snd ' res.
> I compiled the following program with THINK 5.0 and put a sound ID=128 into
> the application.
> 
> What I'd hoped would happen is, that teh sound would play and the app would
> quit. However I get error code -205 (badChannel, Channel is corrupt or
> unusable).
> 
> I also tried to use PlaySnd() after using GetResource(). This didn't
> work either.
> 
> _________________________________________________________________________
> #include <Types.h>
> #include <Sound.h>
> 
> int PlayFromFile(int);
> 
> void main()
> {
> 	PlayFromFile(128);
> }
> 
> int PlayFromFile(int myResNum)
> {
> 	SndChannelPtr	mySndChan;
> 	
> 	mySndChan = NULL;
> 	SndNewChannel(mySndChan,sampledSynth,initMono,NULL);
> 	
> 	SndStartFilePlay(mySndChan,0,myResNum,16*1024,NULL,NULL,NULL,1);
> 	
> 	if (mySndChan != NULL) {
> 		SndDisposeChannel(mySndChan,0);
> 	}
> }
> _________________________________________________________________________
> 
> If you haven't guessed, I have no clue how to program the Mac and really
> have no "World View". I'm just taking Chap 22 of Vol VI very literally
> and hoping things will work without knowing the big picture.
> 
> Perhaps a kind soul could point me towards some sample code for sound
> input. Eventually, I want to write my own XCMD's to record/play AIFF
> files for use in Supercard 1.6. The Hypercard audio palette won't work
> with a standalone Supercard stack.
>  
> Thanks in advance,
> Tom
> 
> 
> -- 
> Tom Wilberding
> jacbop@eecs.umich.edu
> jacbop@engin.umich.edu


1. Don't use type int for the toolbox.  You're passing int as the refNum.
   This could be bad.  Use short as defined in Inside Mac.

2. SndNewChannel returns an error, as does SndStartFilePlay.  NEVER ignore
   errors.  For example, don't call the second trap if the first one failed.

3. SndNewChannel is defined to take a VAR parameter of type SndChannelPtr.
   You've passed SndChannelPtr, and it's supposed to be a pointer to a
   SndChannelPtr.  If you recompile you're MacHeaders and turn on prototype
   checking for toolbox routines.  By default, it's off.  This SUCKS!  You
   should always have this turned on.  Open the file "Mac #includes.c".
   Change the definition of SIMPLIFY_PROTOTYPES to be true.  Then precompile
   the file and save it as MacHeaders.  Then if you attempt to build your
   program it will complain that you've incorrectly called SndNewChannel.

4. If you call SndStartFilePlay with a channel, you can play it asynchronously.
   If you call SndDisposeChannel immediately afterwards, with quietNow set
   to false then it's just like calling SndStartFilePlay "synchronously."
   You should and a call to SndChannelStatus to your event loop and dispose
   of the channel when the busy flag is false.

5. You have to use a value of 20000 or greater for the size of the buffers
   passed to SndStartFilePlay.

6. Use the constants true and false, instead of 1 and 0.
 

Ok, now I'm starting to become annoying.


-----------------------------------------------------------------------
Jim Reekes, E.O.             |     Macintosh Toolbox Engineering
                             |          Sound Manager Expert
Apple Computer, Inc.         | "All opinions expressed are mine, and do
20525 Mariani Ave. MS: 81-KS |   not necessarily represent those of my
Cupertino, CA 95014          |       employer, Apple Computer Inc."