Tuesday, November 23, 2010

How to Record and Play the Sound from IMac/iPhone?

Collected some userful information as start points.

The easiest way is to use QuickTime sequence grabber API.
Look at WhackedTV example code. Basically (without any error checking), it goes like this:

#import <Cocoa/Cocoa.h>
#import <QuickTime/QuickTimeComponents.h>
    // Don't forget to add QuickTime.framework to your project
//// Setup
SeqGrabComponent sequenceGrabber;
OpenADefaultComponent(SeqGrabComponentType, 0, &sequenceGrabber);
SGInitialize(sequenceGrabber);
SGChannel channel;
SGNewChannel(sequenceGrabber, SGAudioMediaType, &channel);
SGSetChannelUsage(channel, seqGrabRecord);
Handle dataRef = NULL;
OSType dataRefType = 0;
QTNewDataReferenceFromFullPathCFString((CFStringRef)@"/tmp/AudioRecording.mov",
                                                 (UInt32)kQTNativeDefaultPathStyle,
                                                 0,
                                                 &dataRef,
                                                 &dataRefType);
SGSetDataRef(sequenceGrabber, dataRef, dataRefType, seqGrabToDisk);
DisposeHandle(dataRef);
//// Recording
SGStartRecord(sequenceGrabber);
// Setup a timer to drive the sequence grabber. The timer method should call SGIdle(sequenceGrabber)
//// Stoping
SGStop(sequenceGrabber);
// Stop also the idle timer
//// Cleanup
SGDisposeChannel(sequenceGrabber, channel);
CloseComponent(sequenceGrabber);

Also,found a very good example! Visit this link: http://borkware.com/rants/sound/

Others FYI:AudioHardwareGetProperty() 
AudioDeviceAddIOProc()
(*AudioDeviceIOProc)(AudioDeviceID inDevice, const AudioTimeStamp*inNow,
            const AudioBufferList *inInputData, const AudioTimeStamp *inInputTime,
            AudioBufferList *outOutputData,  const AudioTimeStamp*inOutputTime,
            void *inClientData); typedef OSStatus
AudioDeviceGetProperty()
AudioDeviceStart()
AudioDeviceStop()
AudioDeviceRemoveIOProc()

No comments:

Post a Comment