Question

I've just implemented callbacks for input and output. My app is receiving and playing audio. Can I get delay between input and output? I don't know how because there's no identificator in AudioBufferList structure. Memory address is same for every buffer. Thanks for reply!

static void inputCallback(id receiver,
                      AEAudioController  *audioController,
                      void  *source,
                      const AudioTimeStamp *time,
                      UInt32 frames,
                      AudioBufferList *audio) {
AEPlaythroughChannel *THIS = receiver;
.
.
.
}

and output

static OSStatus renderCallback(id channel,
                           AEAudioController *audioController,
                           const AudioTimeStamp *time,
                           UInt32 frames,
                           AudioBufferList *audio) {
.
.
.
}
Was it helpful?

Solution

You can set the preferred latency

Float32 aBufferLength = 0.005; // In seconds
OSStatus err = AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(aBufferLength), &aBufferLength);

if (noErr != err) {
    NSLog(@"Cannot set preferred audio buffer duration");
}

Which will try to set the buffer size to one that matches the size in seconds. The latency will be roughly around this size.

OTHER TIPS

You would want to get the actual buffer duration used. When you set the buffer duration, it is only a suggestion on your preferred value. The audio system will typically choose something close to the value you set. The reason it does not always listen is because the values it chooses are typically based on powers of 2 and your sample rate. So just because you set it to 0.005 does not mean it will actually use 0.005. Query the actual value used after you set your preferred value.

// set your preferred duration
Float32 aBufferLength = 0.005; // In seconds
OSStatus err = AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(aBufferLength), &aBufferLength);


// now get the actual duration used
UInt32 size;
Float32 bufferDuration;
size = sizeof(bufferDuration);
err = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareIOBufferDuration,&size, &bufferDuration);
NSLog(@"The actual buffer duration used is %f",bufferDuration);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top