I’m writing a VOIP app for iPad (currently targeting 2&3).
I originally wrote the audio code using the Audio Unit API, with a kAudioUnitSubtype_RemoteIO unit. This worked well, but unsurprisingly echo was a problem. I tried to use the built-in echo-suppression by switching to using a kAudioUnitSubType_VoiceProcessingIO unit. This works really well on iOS 6 (iPad 3), but the same code on iOS 5.1 (iPad 2) produces white noise on the microphone input.
The documentation just mentions that it should be available in iOS 3.0 and later
The iOS version seems to be the important difference here. I tried running the app on two iPhone 4Ss, one with iOS 6 which sounded fine and one with iOS 5.1 which sounded like white noise.
My ASBD looks like this:
typedef int16_t sample_t;
#define AUDIO_BUFFER_SAMPLE_RATE 48000
#define FORMAT_FLAGS (kAudioFormatFlagsIsSignedInteger | kAudioFormatFlagsIsNonInterleaved)
#define CHANNELS_PER_FRAME 1
...
const size_t bytes_per_sample = sizeof(sample_t);
const int eight_bits_per_byte = 8;
AudioStreamBasicDescription streamFormat;
streamFormat.mFormatID = kAudioFormatLinearPCM;
streamFormat.mSampleRate = AUDIO_BUFFER_SAMPLE_RATE;
streamFormat.mFormatFlags = FORMAT_FLAGS;
streamFormat.mChannelsPerFrame = CHANNELS_PER_FRAME;
streamFormat.mBytesPerFrame = bytes_per_sample * CHANNELS_PER_FRAME;
streamFormat.mBitsPerChannel = bytes_per_sample * eight_bits_per_byte;
streamFormat.mFramesPerPacket = 1;
streamFormat.mBytesPerPacket = streamFormat.mBytesPerFrame * streamFormat.mFramesPerPacket;
streamFormat.mReserved = 0;
Has anyone ever got kAudioUnitSubType_VoiceProcessingIO to work on iOS 5.1?
Does anyone know of any serious documentation for this IO?
TL;DR add
kAudioFormatFlagsIsPackedtoFORMAT_FLAGSI discovered this via a bit of a convoluted route. None of this seems to be well documentated anywhere, but I came across this SO post talking about using the IO on a Mac. One of the things mentioned was using "FlagsCononical". I tried setting:
which didn’t work, and the call to AudioUnitInitialize failed with a return code of 29759. I couldn’t find any documentation about what this meant, but when I tried:
everything worked! Success!
The definition of
kAudioFormatFlagsCanonicalin CoreAudioTypes.h if you are building for an iPad (and therefore haveCA_PREFER_FIXED_POINTdefined as1) is:After adding
kAudioFormatFlagIsPackedto my original code it worked. I addedkAudioFormatFlagsNativeEndianfor good measure. I removedkAudioFormatFlagsIsNonInterleavedas it was unnecessary for single channel audio anyway. What I was left with is identical tokAudioFormatFlagsCanonical.So my set-up, which worked on an iPad 2 (iOs 5.1) and an iPad 3 (iOS 6.0) was the following:
48000kAudioFormatFlagsCanonicalint16_tsamplesI’m still keen on documentation for this IO if anyone has any.