home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!cs.utexas.edu!tamsun.tamu.edu!tamsun.tamu.edu!news
- From: bpb9204@tamsun.tamu.edu (Brent Burton)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Sound Input questions (real time usage)
- Date: 15 Dec 1992 12:24:33 -0600
- Organization: Texas A&M Univ., Inc.
- Lines: 77
- Distribution: usa
- Message-ID: <1gl7t1INN18m@tamsun.tamu.edu>
- References: <1gh855INNj70@tamsun.tamu.edu>
- NNTP-Posting-Host: tamsun.tamu.edu
-
- bpb9204@tamsun.tamu.edu (Brent Burton) writes:
- |
- |Think of my program as simply drawing a bar, which has a height
- |that is proportional to the sound level coming in, like a meter.
- |
- |Since my program is effectively a level meter, I just need the current
- |values. Another approach I was thinking about was using a small buffer,
- |like << 100 bytes. Since the buffer is small, the value contained in
- |it would be relatively close the the current value. Is this feasible?
-
- I have learned a lot about the Sound Manager during the last few days,
- and I have solved my problem.
-
- Essentially, what you would do is to call a routine, InitSound() for example,
- to open the driver and begin recording. You would then poll the device
- to determine the current sound level whenever you needed to know the
- sound level. Finally, when you are done polling/using the device, you
- call a routine such as KillSound() to stop recording and close the device.
-
- This turned out to be simple, and brief pseudocode follows for the
- routines: (The code is from memory, so be sure to check, for instance,
- the parameter block's field names)
-
- ------------------------------------
- #include <SoundInput.h>
-
- long sndRefNum;
-
- #define kAsynch TRUE
-
- InitSound()
- {
- OSErr e;
- SPB s;
-
- e = SPBOpenDevice( NULL, siWritePermission, &sndRefNum);
- if ( e != noErr)
- {
- /** initialize the parameter block - fill in all fields - see IM 6 **/
- s.count =0; s.milliseconds=0; s.buffPtr = NULL; s.buffLen = 0;
- s.completionRoutine=NULL; s.interruptRoutine=NULL;
- s.inRefNum = sndRefNum; /* ... */
-
- e = SPBRecord( &s, kAsynch); /* record asynchronously */
- if (e != noErr)
- { /* error */ }
-
- } else { /* error */ }
- } /* InitSound() */
-
- /**** After InitSound() is called, you can poll the device to get
- ***** various characteristics about the recording.
- ** Call SPBGetRecordingStatus() (see inside mac 6) to get
- ** recording time so far, remaining, the current sound level on the
- ** input, etc.
- *****/
-
- /** Once your are done with polling, call KillSound() to clean up **/
- KillSound()
- {
- OSErr e;
- e = SPBStopRecording( sndRefNum);
- e = SPBCloseDevice( sndRefNum);
- sndRefNum=0;
- } /* killSound() */
-
- ----------------------------
-
- Hope this can help someone else. It works for me.
-
- -Brent
-
- --
- +-------------------------+
- | Brent Burton N5VMG |
- | bpb9204@tamsun.tamu.edu |
- +-------------------------+
-