• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Input buffer size for SCAudioFillBuffer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: AudioUnit and iPhone
  • Next by Date: Re: How do I set the sample rate of the output in a play-only audio unit iPhone app?
  • Previous by thread: Re: AudioUnit and iPhone
  • Next by thread: AudioQueues seems to be leaking threads on iPhone?
  • Index(es):
    • Date
    • Thread