Input buffer size for SCAudioFillBuffer
Input buffer size for SCAudioFillBuffer
- Subject: Input buffer size for SCAudioFillBuffer
- From: Thomas Zoechling <email@hidden>
- Date: Sat, 14 Feb 2009 16:58:52 +0100
I am trying to compress audio in real-time (=while recording) using
SCAudioFillBuffer.
The input comes from the following audio unit:
ComponentDescription audioUnitDescription;
audioUnitDescription.componentType = kAudioUnitType_Output;
audioUnitDescription.componentSubType = kAudioUnitSubType_HALOutput;
audioUnitDescription.componentManufacturer =
kAudioUnitManufacturer_Apple;
audioUnitDescription.componentFlags = 0;
audioUnitDescription.componentFlagsMask = 0;
...
err = AudioUnitSetProperty(audioUnit,
kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0,
&callback, sizeof(AURenderCallbackStruct));
...
Within the callback, I call AudioUnitRender and SCAudioFillBuffer:
OSStatus AudioInputProcVBR(void* inRefCon, AudioUnitRenderActionFlags*
ioActionFlags, const AudioTimeStamp* inTimeStamp, UInt32 inBusNumber,
UInt32 inNumberFrames, AudioBufferList* ioData)
{
...
AudioUnitRender(audioRecorder.audioUnit, ioActionFlags, inTimeStamp,
inBusNumber, inNumberFrames, audioRecorder.microphoneAudioBufferList);
...
UInt32 numberOfPackets = audioRecorder.compressorAudioBufferList-
>mBuffers[0].mDataByteSize / audioRecorder.maxBytesPerPacket;
AudioStreamPacketDescription* aspds =
(AudioStreamPacketDescription*)calloc(numberOfPackets,
sizeof(AudioStreamPacketDescription));
//1768846202 == invalid parameter size
error = SCAudioFillBuffer(audioRecorder.compressor,
ConverterInputProcVBR, inRefCon, &numberOfPackets,
audioRecorder.compressorAudioBufferList, aspds);
...
}
The compression is configured with MovieExportDoUserDialog. The final
(compressed) frames are written to a QuickTime movie with
AddMediaSample2.
Everything works fine for some sample rates.
I found out that if the kAudioDevicePropertyBufferFrameSize has the
"correct" size to provide enough data for SCAudioFillBuffer, the
compression works fine - otherwise I get random crashes, audio
stuttering, ...
I am currently testing MPEG-4 Audio compression and I get crashes if
SCAudioFillBuffer returns with less than 4 packets.
E.g. MPEG-4 Audio (AAC-LC), with 44.1kHz output sample rate and a
kAudioDevicePropertyBufferFrameSize of 4096 works fine.
But how can I determine the optimal constellation of
kAudioDevicePropertyBufferFrameSize and number of packets to pull from
the compressor?
--thomas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden