buffer size magical reduction
buffer size magical reduction
- Subject: buffer size magical reduction
- From: David Plans <email@hidden>
- Date: Sun, 28 Nov 2010 15:27:55 -0500
Hello
I have the following code that asks Puredata (puredata.info) for its blocksize, which is alway 64, and then creates an AudioSession. I establish bufferSize by multiplying by number of ticks (set by app delegate, in this case 64 again), then bufferDuration by dividing by sampleRate (44100) to get buffer duration in seconds (which is then 64*64/44100 = 0.092879818594104)
Problem is, setting that with kAudioSessionProperty_PreferredHardwareIOBufferDuration works fine, but when I try to get kAudioSessionProperty_CurrentHardwareIOBufferDuration, it invariably comes back as half of what I asked for, i.e. 0.046...
I see in the docs that:
"The actual I/O buffer duration may be different from the value that you request, and can be obtained from thekAudioSessionProperty_CurrentHardwareIOBufferDuration property."
But if we don’t ‘necessarily get what we ask for’, what do we get?
// set buffer size
Float32 bufferSize = (Float32) [PdBase getBlockSize] * ticks; // requested buffer size
Float32 bufferDuration = bufferSize / sampleRate; // buffer duration in seconds
AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration,
sizeof(bufferDuration), &bufferDuration);
NSLog(@"AudioSession === setting PreferredHardwareIOBufferDuration to %3.2fms.", bufferDuration*1000.0);
// NOTE: note that round-off errors make it hard to determine whether the requested buffersize
// was granted. we just assume that it was and carry on.
AudioSessionSetActive(true);
NSLog(@"AudioSession === starting Audio Session.");
// print value of properties to check that everything was set properly
Float64 audioSessionProperty64 = 0;
Float32 audioSessionProperty32 = 0;
UInt32 audioSessionPropertySize64 = sizeof(audioSessionProperty64);
UInt32 audioSessionPropertySize32 = sizeof(audioSessionProperty32);
AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareSampleRate,
&audioSessionPropertySize64, &audioSessionProperty64);
NSLog(@"AudioSession === CurrentHardwareSampleRate: %.0fHz", audioSessionProperty64);
sampleRate = audioSessionProperty64;
AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareIOBufferDuration,
&audioSessionPropertySize32, &audioSessionProperty32);
int blockSize = lrint(audioSessionProperty32 * audioSessionProperty64);
NSLog(@"AudioSession === CurrentHardwareIOBufferDuration: %3.2fms", audioSessionProperty32*1000.0f);
NSLog(@"AudioSession === block size: %i", blockSize);
David _______________________________________________
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