home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15225 < prev    next >
Encoding:
Internet Message Format  |  1992-09-09  |  2.7 KB

  1. Path: sparky!uunet!olivea!spool.mu.edu!news.nd.edu!mentor.cc.purdue.edu!noose.ecn.purdue.edu!samsung!transfer!ceylon!choffman.gte.com!user
  2. From: chuck@gte.com (Chuck Hoffman)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Need small example of playing a sound in THINK C.
  5. Message-ID: <chuck-090992095031@choffman.gte.com>
  6. Date: 9 Sep 92 14:19:17 GMT
  7. References: <1992Sep7.001953.570@nynexst.com>
  8. Sender: news@ceylon.gte.com
  9. Followup-To: comp.sys.mac.programmer
  10. Organization: GTE Laboratories
  11. Lines: 71
  12.  
  13. In article <1992Sep7.001953.570@nynexst.com>, rsilvers@powwow.nynexst.com
  14. (Rob Silvers) wrote:
  15. >     I have gotton the Mac to play sampled sound resources in
  16. > THINK C, but I am having trouble playing a synthesized square wave.
  17. > Could someone send me a small example of playing a simple note?
  18.  
  19. I did it recently this way, to play a sound asynchronously:
  20.  
  21. I used ResEdit to create (and preview play) a 'snd ' resource (trailing
  22. blank required) with the following hexidecimal values.  Actually, I created
  23. a template for ResEdit to make this easy.  Sound resource number should be
  24. above 8191.  I used 9000.
  25.  
  26. ============   'snd ' RESOURCE:
  27.  
  28. 0001               Format 1
  29. 0001                                                   Number of mod/synth's is 1
  30. 000100000000       Note synth id is 1, and null initial parm
  31. 0003               Number of commands
  32. 002B00FF00000000   Amplitude command (full blast)
  33. 002C008000000000   Timbre command (half between square and sine)
  34. 002803E800000036   Note command (1000 half miliseconds, F-sharp/A-flat)
  35.  
  36. ============  TO PLAY THE SOUND:
  37.  
  38. SndCommand    myCallbk;
  39.  
  40. ------------
  41. disposeAlmaMater = FALSE;
  42. myCallbk.cmd = callBackCmd;
  43. myCallbk.param1 = NIL;
  44. myCallbk.param2 = (long) &disposeAlmaMater;
  45. SetItem (myMenuHandle[3], AlmaMaterItem, myStifleStr);
  46. mySoundH = GetResource ('snd ', 9000);
  47. HLock (mySoundH);
  48. mySndChPtr = NIL;
  49. myErr = SndNewChannel (&mySndChPtr, NIL, NIL,
  50.     (ProcPtr) myCallBack);
  51. myErr = SndPlay (mySndChPtr, mySoundH, TRUE);
  52. myErr = SndDoCommand (mySndChPtr, &myCallbk, TRUE);
  53.  
  54. ============   TO STOP THE SOUND
  55.  
  56. sndRC = SndDisposeChannel (mySndChPtr, TRUE);
  57. HUnlock (mySoundH);
  58. ReleaseResource (mySoundH);
  59. disposeAlmaMater = FALSE;
  60.  
  61. ============   CALLBACK ROUTINE
  62.  
  63. pascal void    myCallBack(SndChannelPtr workChPtr, SndCommand workCmd)
  64. {
  65.     *((Ptr) workCmd.param2) = (char) 0x08;  /* set flag in disposeAlmaMater */
  66.     return;
  67. }    
  68.  
  69. ============
  70.  
  71. I'm a real beginner at this sound stuff, so postings of any other ways
  72. would be of interest to me as well.
  73.  
  74.  
  75. Chuck Hoffman
  76. chuck@gte.com
  77. GTE Laboratories, Waltham, Massachusetts, USA
  78. (617) 466-2131
  79. =====================================
  80. I'm not sure why we're here, but I am sure that while we're here we're
  81. supposed to help each other.
  82. =====================================
  83.