home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18450 < prev    next >
Encoding:
Internet Message Format  |  1992-11-15  |  2.3 KB

  1. Path: sparky!uunet!ornl!rsg1.er.usgs.gov!darwin.sura.net!haven.umd.edu!mimsy!afterlife!mssmith
  2. From: mssmith@afterlife.ncsc.mil (M. Scott Smith)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: sndPlay while animating
  5. Keywords: Mac, sndPlay, animation
  6. Message-ID: <1992Nov15.235830.17180@afterlife.ncsc.mil>
  7. Date: 15 Nov 92 23:58:30 GMT
  8. References: <BxruHF.F11.1@cs.cmu.edu>
  9. Organization: The Great Beyond
  10. Lines: 61
  11.  
  12. In article <BxruHF.F11.1@cs.cmu.edu> mak+@cs.cmu.edu (Matthew Alan Kane) writes:
  13. >Situation:
  14. >I have animation running during vbl
  15. >and am playing snd resources with sndPlay.
  16. >
  17. >Problem:
  18. >How do I keep my animation going while the sound is playing?
  19. >
  20. >mak@cs.cmu.edu
  21.  
  22. Hi..
  23.  
  24.    I assume when you call SndPlay, the computer then freezes until it's
  25. done playing the sound?  Or even if you're playing it asynchronously and
  26. that's not working well, the following should help.
  27.  
  28.    I wrote some simple code in Think C for a game I'm working on to play
  29. sounds in the background.  For me the sounds seem totally independent of
  30. the animation; that is, the animation doesn't get in the way of the sound
  31. and vice-versa.  It works.
  32.  
  33. Here's the code:
  34.  
  35. First, set up a sound channel.
  36.  
  37. void ThisWorks(void)
  38. {
  39.   SndChannelPtr   myChannel;
  40.   OSErr           myErr;
  41.   SndCommand      mySndCommand;
  42.   Handle          mySoundEffect;
  43.  
  44.   myErr = SndNewChannel(&myChannel, sampledSynth, initMono, nil);
  45.  
  46.   mySoundEffect = GetResource('snd ', SOUND_RESOURCE_ID);
  47.  
  48.   mySndCommand.param1 = 0;
  49.   mySndCommand.param2 = 0;
  50.   mySndCommand.cmd = flushCmd;
  51.  
  52.   myErr = SndDoImmediate(myChannel, &mySndCommand);
  53.   myErr = SndPlay(myChannel, mySoundEffect, true);
  54. }
  55.  
  56. Of course, you need to include <sound.h> at the beginning of your program.
  57.  
  58. I'm not certain the "flushCmd" deal is necessary..  (I wrote this awhile ago,
  59. in Pascal at first, so if you're using Pascal and have a problem converting
  60. it, buzz me.)  I think that just flushes the channel in case any other sounds
  61. are playing on it.
  62.  
  63. Actually, it's useful to set up multiple channels (on sound-capable Macs you
  64. have 4), because then you can use one channel for a continuous soundtrack,
  65. and another channel for sound effects, etc.  (Of course this method might
  66. cause problems if you're competing with other programs for the same channel,
  67. etc.)
  68.  
  69. Hope that helps!
  70.  
  71. M. Scott Smith
  72.   (mssmith@afterlife.ncsc.mil || umsmith@mcs.drexel.edu)
  73.