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

  1. Path: sparky!uunet!pageworks.com!world!eff!sol.ctr.columbia.edu!emory!swrinde!zaphod.mps.ohio-state.edu!darwin.sura.net!udel!intercon!psinntp!uu0570!Daniel_R._Sandler
  2. Message-ID: <1992Nov16.162355.40024@uu0570.foggybottom.com>
  3. Newsgroups: comp.sys.mac.programmer
  4. Distribution: world
  5. From: Daniel_R._Sandler@uu0570.foggybottom.com
  6. Organization: Foggy Bottom / Washington, D.C.
  7. Date: Mon, 16 Nov 1992 16:23:55 EST
  8. Subject: Fwd: Re: sndPlay while animat
  9. Lines: 87
  10.  
  11. In article <BxruHF.F11.1@cs.cmu.edu> mak+@cs.cmu.edu (Matthew Alan Kane)
  12. 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
  31. sound
  32. and vice-versa.  It works.
  33.  
  34. Here's the code:
  35.  
  36. First, set up a sound channel.
  37.  
  38. void ThisWorks(void)
  39. {
  40.   SndChannelPtr   myChannel;
  41.   OSErr           myErr;
  42.   SndCommand      mySndCommand;
  43.   Handle          mySoundEffect;
  44.  
  45.   myErr = SndNewChannel(&myChannel, sampledSynth, initMono, nil);
  46.  
  47.   mySoundEffect = GetResource('snd ', SOUND_RESOURCE_ID);
  48.  
  49.   mySndCommand.param1 = 0;
  50.   mySndCommand.param2 = 0;
  51.   mySndCommand.cmd = flushCmd;
  52.  
  53.   myErr = SndDoImmediate(myChannel, &mySndCommand);
  54.   myErr = SndPlay(myChannel, mySoundEffect, true);
  55. }
  56.  
  57. Of course, you need to include <sound.h> at the beginning of your program.
  58.  
  59. I'm not certain the "flushCmd" deal is necessary..  (I wrote this awhile
  60. ago,
  61. in Pascal at first, so if you're using Pascal and have a problem
  62. converting
  63. it, buzz me.)  I think that just flushes the channel in case any other
  64. sounds
  65. are playing on it.
  66.  
  67. Actually, it's useful to set up multiple channels (on sound-capable Macs
  68. you
  69. have 4), because then you can use one channel for a continuous
  70. soundtrack,
  71. and another channel for sound effects, etc.  (Of course this method
  72. might
  73. cause problems if you're competing with other programs for the same channel,
  74. etc.)
  75.  
  76. Hope that helps!
  77.  
  78. M. Scott Smith
  79.   (mssmith@afterlife.ncsc.mil || umsmith@mcs.drexel.edu)
  80.  
  81.  
  82. ------ Internet Message Header Follows ------
  83. Path:
  84. uupsi!psinntp!rpi!usc!sdd.hp.com!wupost!darwin.sura.net!haven.umd.edu!mimsy!afterlife!mssmith
  85. From: mssmith@afterlife.ncsc.mil (M. Scott Smith)
  86. Newsgroups: comp.sys.mac.programmer
  87. Subject: Re: sndPlay while animating
  88. Keywords: Mac, sndPlay, animation
  89. Message-ID: <1992Nov15.235830.17180@afterlife.ncsc.mil>
  90. Date: 15 Nov 92 23:58:30 GMT
  91. References: <BxruHF.F11.1@cs.cmu.edu>
  92. Organization: The Great Beyond
  93. Lines: 61
  94.  
  95.  
  96. Foggy Bottom - your FirstClass Mac connection in Washington, DC
  97.  
  98.