home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!agate!apple!mumbo.apple.com!gallant.apple.com!NewsWatcher!user
- From: REEKES@applelink.apple.com (Jim Reekes)
- Subject: Re: sndPlay while animating
- Sender: news@gallant.apple.com
- Message-ID: <REEKES-161192131919@90.10.20.67>
- Date: Mon, 16 Nov 1992 21:19:52 GMT
- References: <BxruHF.F11.1@cs.cmu.edu> <1992Nov15.235830.17180@afterlife.ncsc.mil>
- Organization: Apple Computer, Inc.
- Followup-To: comp.sys.mac.programmer
- Lines: 57
-
- In article <1992Nov15.235830.17180@afterlife.ncsc.mil>,
- mssmith@afterlife.ncsc.mil (M. Scott Smith) wrote:
- >
- > In article <BxruHF.F11.1@cs.cmu.edu> mak+@cs.cmu.edu (Matthew Alan Kane) writes:
- > >Situation:
- > >I have animation running during vbl
- > >and am playing snd resources with sndPlay.
- > >
- > >Problem:
- > >How do I keep my animation going while the sound is playing?
- >
- > Here's the code:
- >
- > First, set up a sound channel.
- >
- > void ThisWorks(void)
- > {
- > SndChannelPtr myChannel;
- > OSErr myErr;
- > SndCommand mySndCommand;
- > Handle mySoundEffect;
- >
- > myErr = SndNewChannel(&myChannel, sampledSynth, initMono, nil);
- >
- > mySoundEffect = GetResource('snd ', SOUND_RESOURCE_ID);
- >
- > mySndCommand.param1 = 0;
- > mySndCommand.param2 = 0;
- > mySndCommand.cmd = flushCmd;
- >
- > myErr = SndDoImmediate(myChannel, &mySndCommand);
- > myErr = SndPlay(myChannel, mySoundEffect, true);
- > }
-
- You didn't initialize the channel pointer before calling SndNewChannel.
- This will trash random locations of memory. You need to add the line:
-
- myChannel = nil;
-
- before calling SndNewChannel.
-
- > I'm not certain the "flushCmd" deal is necessary..
-
- It's not. Also, the next problem is that after you play this sound you
- need to know when you can dispose of the sound channel. Also, in this
- example the channel was a local variable on the stack so you'll lose your
- referece to it. It needs to be a global or some how be made available
- later in the program so you can call SndDisposeChannel. Using a
- CallBackProc and the callBackCmd will help you to determine when the sound
- has finished.
-
- -----------------------------------------------------------------------
- Jim Reekes, Polterzeitgeist | 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."
-