home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 19853 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.8 KB  |  90 lines

  1. Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!cs.utexas.edu!tamsun.tamu.edu!tamsun.tamu.edu!news
  2. From: bpb9204@tamsun.tamu.edu (Brent Burton)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Sound Input questions (real time usage)
  5. Date: 15 Dec 1992 12:24:33 -0600
  6. Organization: Texas A&M Univ., Inc.
  7. Lines: 77
  8. Distribution: usa
  9. Message-ID: <1gl7t1INN18m@tamsun.tamu.edu>
  10. References: <1gh855INNj70@tamsun.tamu.edu>
  11. NNTP-Posting-Host: tamsun.tamu.edu
  12.  
  13. bpb9204@tamsun.tamu.edu (Brent Burton) writes:
  14. |
  15. |Think of my program as simply drawing a bar, which has a height
  16. |that is proportional to the sound level coming in, like a meter.
  17. |
  18. |Since my program is effectively a level meter, I just need the current
  19. |values.  Another approach I was thinking about was using a small buffer,
  20. |like << 100 bytes.  Since the buffer is small, the value contained in
  21. |it would be relatively close the the current value.  Is this feasible?
  22.  
  23. I have learned a lot about the Sound Manager during the last few days,
  24. and I have solved my problem.  
  25.  
  26. Essentially, what you would do is to call a routine, InitSound() for example,
  27. to open the driver and begin recording.  You would then poll the device
  28. to determine the current sound level whenever you needed to know the
  29. sound level.  Finally, when you are done polling/using the device, you
  30. call a routine such as KillSound() to stop recording and close the device.
  31.  
  32. This turned out to be simple, and brief pseudocode follows for the
  33. routines:  (The code is from memory, so be sure to check, for instance,
  34.   the parameter block's field names)
  35.  
  36. ------------------------------------
  37. #include <SoundInput.h>
  38.  
  39. long sndRefNum;
  40.  
  41. #define kAsynch TRUE
  42.  
  43. InitSound()
  44. {
  45.   OSErr e;
  46.   SPB   s;
  47.  
  48.   e = SPBOpenDevice( NULL, siWritePermission, &sndRefNum);
  49.   if ( e != noErr)
  50.   {
  51.     /** initialize the parameter block - fill in all fields - see IM 6 **/
  52.     s.count =0;  s.milliseconds=0; s.buffPtr = NULL;  s.buffLen = 0;
  53.     s.completionRoutine=NULL; s.interruptRoutine=NULL; 
  54.     s.inRefNum = sndRefNum;          /* ... */
  55.  
  56.     e = SPBRecord( &s, kAsynch);  /* record asynchronously */
  57.     if (e != noErr)
  58.     {  /* error */  }
  59.  
  60.   } else { /* error */ }
  61. } /* InitSound() */
  62.  
  63. /**** After InitSound() is called, you can poll the device to get 
  64. ***** various characteristics about the recording.
  65. **  Call SPBGetRecordingStatus()  (see inside mac 6)  to get
  66. **  recording time so far, remaining, the current sound level on the
  67. ** input, etc.
  68. *****/
  69.  
  70. /** Once your are done with polling, call KillSound() to clean up **/
  71. KillSound()
  72. {
  73.   OSErr e;
  74.   e = SPBStopRecording( sndRefNum);
  75.   e = SPBCloseDevice( sndRefNum);
  76.   sndRefNum=0;
  77. } /* killSound() */
  78.  
  79. ----------------------------
  80.  
  81. Hope this can help someone else.  It works for me.
  82.  
  83. -Brent
  84.  
  85. -- 
  86. +-------------------------+
  87. | Brent Burton    N5VMG   |    
  88. | bpb9204@tamsun.tamu.edu |  
  89. +-------------------------+ 
  90.