my Problem concerns AudioUnits. In order to design a voicechanging App for iPhone (with Objective-C xCode) i use RemoteIO audioUnit sample from this website:
http://
There is no problem in defining and initializing an AudioSession
with the RemoteIO
Audio-Unit, and that's the way to set the desired buffer length. I have some code doing exactly this, but it will take me a few hours till I get back home and can post it. You can look at Apple's AurioTouch code-sample, or wait till I post it later.
Anyway keep in mind 2 things:
PreferredHardwareIOBufferDuration
. The buffer size is always a power of 2.With that in mind, did you consider allocating your own buffer and accumulate it till you have the desired number of samples?
EDIT
The code for initializing the audio session (should go before the audio unit is initialized):
OSStatus result;
result = AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory);
// set preferred buffer size
Float32 preferredBufferSize = .04; // in seconds
result = AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(preferredBufferSize), &preferredBufferSize);
// get actuall buffer size
Float32 audioBufferSize;
UInt32 size = sizeof (audioBufferSize);
result = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareIOBufferDuration, &size, &audioBufferSize);
result = AudioSessionSetActive(true);
You can/should inspect result
after each call in order to look for possible errors.
You can read the documentation for AudioSessionInitialize
for more information, but passing NULL
for all 4 arguments still work. You should change it if, for example, you need to establish an interruption-listener callback.