Re: Capturing Raw Audio
Re: Capturing Raw Audio
- Subject: Re: Capturing Raw Audio
- From: email@hidden (Patrick Beard)
- Date: Thu, 5 Jun 2003 16:26:04 -0700
On Tuesday, June 3, 2003, at 02:02 PM, Joseph Catalano wrote:
I'm looking for the simplest way to read in audio and write it to a
file as raw bytes. I have a device for interfacing a Mic with USB and
it shows up in the Sounds panel of System Preferences. The goal is to
pass this though a DSP algorithm to do some speech recognition
research. I just don't know how to get access to the audio data as it
comes in.
There are 2 ways to do this on Mac OS X, using the legacy SPBRecord
API, or using CoreAudio. They both work, but I find that the CoreAudio
APIs are simpler to use. The basic approach with CoreAudio is to
install an IOProc using the audio device that you get by calling
AudioDeviceID defaultInputDevice;
UInt32 propertySize = sizeof(defaultInputDevice);
AudioHardwareGetProperty(AudioDeviceID, &propertySize,
&defaultInputDevice);
After you install the IOProc with AudioDeviceAddIOProc, the IOProc will
be called with successive buffers of samples, and it's your job to save
these buffers in a file. I use another thread to do the file I/O, and
send it audio buffers using MP thread queues.
Check out
http://homepage.mac.com/pcbeard/Audio.tar.gz
for some sample code. It includes a simple Objective C class
@interface AudioRecorder : NSObject {
}
+ (OSStatus)recordToFile:(NSURL*)fileURL;
+ (OSStatus)stopRecording;
+ (OSStatus)getLevels:(AudioLevels)levels;
@end
which does recording to a file, plus some rudimentary level metering.
- Patrick
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.