home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / programm / 13987 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  2.6 KB

  1. Path: sparky!uunet!olivea!mintaka.lcs.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!slchambe
  2. From: slchambe@athena.mit.edu (Stephen L Chamberlin)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: help with asynchronous sounds
  5. Message-ID: <1992Aug14.141851.945@athena.mit.edu>
  6. Date: 14 Aug 92 14:18:51 GMT
  7. Sender: news@athena.mit.edu (News system)
  8. Organization: Massachusetts Institute of Technology
  9. Lines: 57
  10. Nntp-Posting-Host: e40-008-11.mit.edu
  11.  
  12. I'm going crazy trying to write some code that plays sounds asynchronously
  13. (for sound effects in a game). After reading the sound manager chapter in
  14. IM 5, I wrote some code that seems to work great under system 7, but chokes
  15. under system 6. Could somebody tell me what I'm doing wrong, or give me a 
  16. pointer to an example use of asynchronous sounds? I checked the soundapp at
  17. ftp.apple.com, but the only way it plays asynchronous sounds is by creating
  18. a new channel, playing the sound asynchronously, and then disposing of the
  19. channel. I want to create 1 channel that I keep around for the whole game that
  20. plays all the sound effects.
  21.  
  22. When my program starts up, I create a new sound channel, which I use for
  23. playing all my sound effects. Each time I want to play a sound effect, I
  24. do SndPlay(myChan, mySound, TRUE); to play it asynchronously. This works
  25. fine for system 7, but when I try it under system 6, the 1st sound effect
  26. I try to play works, but all others afterward don't get played. No crashes
  27. or anything, just no more sound effects. Here's what I'm doing:
  28.  
  29. SndChannelPtr myChan;
  30. Handle mySound, mySound2;
  31.  
  32. some_routine() 
  33. {
  34.    myChan = (SndChannelPtr)0L;
  35.    if (SndNewChannel(&myChan,sampledSynth,0,0L) != noErr)
  36.       MyHandleError();
  37.    
  38.    mySound = GetResource('snd ',128);
  39.    if (mySound == 0L)
  40.       MyHandleError();
  41.    HLock(mySound);
  42.    mySound2 = GetResource('snd ',129);
  43.    if (mySound2 == 0L)
  44.       MyHandleError();
  45.    HLock(mySound2);
  46.  
  47.    ...
  48.  
  49.    SndPlay(myChan,mySound,TRUE);  /* this sound gets played asynchronously */
  50.    SndPlay(myChan,mySound2,TRUE); /* this sound is never heard */
  51.  
  52.    /* any subsequent SndPlay(myChan...) calls fail to produce any sound */
  53.  
  54.    ...
  55.  
  56. }
  57.  
  58. I also tried this with "sampledSynth" replace by "0" with the same results.
  59. Any ideas why this doesn't work? As I said, it seems to work fine under
  60. system 7, but not system 6. I can't understand why. Is there some other
  61. way I should be playing asynchronous sounds? The sounds don't need to overlap
  62. each other, they just shouldn't stop program execution while they play.
  63.  
  64. Any help you could give me with this problem would be greatly appreciated. It's
  65. driving me nuts! Thanks in advance!
  66.  
  67. Steve Chamberlin
  68. slchambe@athena.mit.edu
  69.