SCAudio is a QuickTime thing (which happens to make heavy use of CoreAudio), so I'm posting this answer back to the qt-api list as well...
On Sep 11, 2006, at 5:14 AM, Sandeep Chandna wrote:
plz c inline
On 11/09/06, Brad Ford <email@hidden> wrote:
<SNIP>
OUTPUT from SCAudioFillBuffer():
QuickTime Movie using AddMediaSample2 (data may be any format,
compressed or uncompressed)
.CAF file using AudioFileWritePackets (data may be any format).
My question here is that if I get a pointer to audio data (raw samples) how do I copy it to the AudioBufferList (which is passed to the inInputDataProcRefCon) for scaudiofillbuffer to read/encode.
If you have a buffer of data, you don't have to copy it, you can just point your AudioBufferList's mData at it. For example, if you've got, say, a 512 frame buffer 16-bit PCM big endian, interleaved, stereo audio:
// do a quick sanity check on the buffer list passed to you)
assert(ioData->mNumberBuffers == 1);
assert(ioData->mBuffers[0].mNumberChannels == 2);
// point the abl buffer at your data buffer:
ioData->mBuffers[0].mData = myDataBuffer;
ioData->mBuffers[0].mDataByteSize = 2048; (512 * 2 channels * 2 bytes)
You may not free "myDataBuffer" until
1) your input proc gets called again, or
2) SCAudioFillBuffer() returns.
>
> I need to encode the raw data and write into AudioBufferList
> without using MovieAudioExtraction APIs. Can anyone help?
Not sure I understand the question. What's your source format? What
format do you want to produce? Are you asking how to properly fill
out an AudioStreamBasicDescription for some flavor of PCM?
Yes! Like we had SoundComponentData in the SoundMgr API how do we set the corresponding AudioStreamBasicDescription with the necessary encoding parameters to get started with the encoding?
Please look at CoreAudioTypes.h, it gives very good instruction on how to fill out an audio buffer list. For example, an ASBD for the above mentioned 16-bit PCM big endian, interleaved, stereo audio, would look like this:
asbd.mFormatID = kAudioFormatLinearPCM;
asbd.mSampleRate = 44100.0; // or whatever the sample rate is
asbd.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
asbd.mBytesPerPacket = 4; // 16-bit * 2 channels
asbd.mFramesPerPacket = 1; // For PCM, frames per packet is always 1
asbd.mBytesPerFrame = 4; // for PCM, frames per packet and bytes per packet are equivalent
asbd.mChannelsPerFrame = 2;
asbd.mBitsPerChannel = 16;
If you're filling out an asbd for a compressed format (to pass to SCAudio), you aren't required to fill out every field, you may just fill in the fields you know, for instance, for AAC, you might only know format id, sample rate, and number of channels, and set the rest of the fields to 0:
asbd.mFormatID = kAudioFormatMPEG4AAC;
asbd.mSampleRate = 44100.0; // or whatever the sample rate is
asbd.mFormatFlags = 0;
asbd.mBytesPerPacket = 0;
asbd.mFramesPerPacket = 0;
asbd.mBytesPerFrame = 0;
asbd.mChannelsPerFrame = 2;
asbd.mBitsPerChannel = 0;
SCAudio will fill in the rest of the fields with the specifics. After setting the format on the component instance, you can then get the property, and the asbd returned will be fully populated.
Alternately, if you already have a SoundDescription, for some reason, you can use the QTSoundDescription accessor API's in Movies.h to get an asbd for the format described by the SoundDescription. See QTSoundDescriptionGetProperty().
-Brad Ford
QuickTime Engineering