TL;DR add kAudioFormatFlagsIsPacked
to FORMAT_FLAGS
I 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:
#define FORMAT_FLAGS kAudioFormatFlagsAudioUnitCanonical
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:
#define FORMAT_FLAGS kAudioFormatFlagsCanonical
everything worked! Success!
The definition of kAudioFormatFlagsCanonical
in CoreAudioTypes.h if you are building for an iPad (and therefore have CA_PREFER_FIXED_POINT
defined as 1
) is:
kAudioFormatFlagsCanonical = kAudioFormatFlagsIsSignedInteger
| kAudioFormatFlagsNativeEndian
| kAudioFormatFlagIsPacked;
After adding kAudioFormatFlagIsPacked
to my original code it worked. I added kAudioFormatFlagsNativeEndian
for good measure. I removed kAudioFormatFlagsIsNonInterleaved
as it was unnecessary for single channel audio anyway. What I was left with is identical to kAudioFormatFlagsCanonical
.
So my set-up, which worked on an iPad 2 (iOs 5.1) and an iPad 3 (iOS 6.0) was the following:
- Sample rate of
48000
- 1 channel
kAudioFormatFlagsCanonical
int16_t
samples
- Linear PCM
I'm still keen on documentation for this IO if anyone has any, and of course if this helped you don't forget to upvote :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…