home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18489 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.5 KB  |  70 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!agate!apple!mumbo.apple.com!gallant.apple.com!NewsWatcher!user
  3. From: REEKES@applelink.apple.com (Jim Reekes)
  4. Subject: Re: sndPlay while animating
  5. Sender: news@gallant.apple.com
  6. Message-ID: <REEKES-161192131919@90.10.20.67>
  7. Date: Mon, 16 Nov 1992 21:19:52 GMT
  8. References: <BxruHF.F11.1@cs.cmu.edu> <1992Nov15.235830.17180@afterlife.ncsc.mil>
  9. Organization: Apple Computer, Inc.
  10. Followup-To: comp.sys.mac.programmer
  11. Lines: 57
  12.  
  13. In article <1992Nov15.235830.17180@afterlife.ncsc.mil>,
  14. mssmith@afterlife.ncsc.mil (M. Scott Smith) wrote:
  15. > In article <BxruHF.F11.1@cs.cmu.edu> mak+@cs.cmu.edu (Matthew Alan Kane) writes:
  16. > >Situation:
  17. > >I have animation running during vbl
  18. > >and am playing snd resources with sndPlay.
  19. > >
  20. > >Problem:
  21. > >How do I keep my animation going while the sound is playing?
  22. >
  23. > Here's the code:
  24. > First, set up a sound channel.
  25. > void ThisWorks(void)
  26. > {
  27. >   SndChannelPtr   myChannel;
  28. >   OSErr           myErr;
  29. >   SndCommand      mySndCommand;
  30. >   Handle          mySoundEffect;
  31. >   myErr = SndNewChannel(&myChannel, sampledSynth, initMono, nil);
  32. >   mySoundEffect = GetResource('snd ', SOUND_RESOURCE_ID);
  33. >   mySndCommand.param1 = 0;
  34. >   mySndCommand.param2 = 0;
  35. >   mySndCommand.cmd = flushCmd;
  36. >   myErr = SndDoImmediate(myChannel, &mySndCommand);
  37. >   myErr = SndPlay(myChannel, mySoundEffect, true);
  38. > }
  39.  
  40. You didn't initialize the channel pointer before calling SndNewChannel. 
  41. This will trash random locations of memory.  You need to add the line:
  42.  
  43.     myChannel = nil;
  44.  
  45. before calling SndNewChannel.
  46.  
  47. > I'm not certain the "flushCmd" deal is necessary..
  48.  
  49. It's not.  Also, the next problem is that after you play this sound you
  50. need to know when you can dispose of the sound channel.  Also, in this
  51. example the channel was a local variable on the stack so you'll lose your
  52. referece to it.  It needs to be a global or some how be made available
  53. later in the program so you can call SndDisposeChannel. Using a
  54. CallBackProc and the callBackCmd will help you to determine when the sound
  55. has finished.
  56.  
  57. -----------------------------------------------------------------------
  58. Jim Reekes, Polterzeitgeist  |     Macintosh Toolbox Engineering
  59.                              |          Sound Manager Expert
  60. Apple Computer, Inc.         | "All opinions expressed are mine, and do
  61. 20525 Mariani Ave. MS: 81-KS |   not necessarily represent those of my
  62. Cupertino, CA 95014          |       employer, Apple Computer Inc."
  63.