在aurioTouch示例应用程序中,RemoteIO音频单元以8.24固定点格式配置为2通道非交错LPCM。这是iOS平台上的首选格式,我认为这就是硬件ADC发出的格式。他们甚至对此进行了评论(source)。
如果“interleaved”为false,则不会将'mBytesPerPacket'和'mBytesPerFrame'乘以通道数。帧中没有足够的位来存储额外的通道。
因此,当示例代码要求2个通道时,它是否有些误导?既然无论如何都只会返回1个通道,那么它应该只要求1个通道吗?
// set our required format - Canonical AU format: LPCM non-interleaved 8.24 fixed point
outFormat.SetAUCanonical(2, false);
因此,我期望当应用程序稍后接收到音频缓冲区时,它将在其mData成员中以某种顺序打包两个通道的数据。类似于这样:
mData = [L1, L2, L3, L4, R1, R2, R3, R4];
在这里,L和R代表立体声麦克风左右通道的数据。但似乎并非如此,因为SetAUCannonical()
没有设置足够的内存来容纳额外的通道:
void SetAUCanonical(UInt32 nChannels, bool interleaved)
{
mFormatID = kAudioFormatLinearPCM;
#if CA_PREFER_FIXED_POINT
mFormatFlags = kAudioFormatFlagsCanonical | (kAudioUnitSampleFractionBits << kLinearPCMFormatFlagsSampleFractionShift);
#else
mFormatFlags = kAudioFormatFlagsCanonical;
#endif
mChannelsPerFrame = nChannels;
mFramesPerPacket = 1;
mBitsPerChannel = 8 * sizeof(AudioUnitSampleType);
if (interleaved)
mBytesPerPacket = mBytesPerFrame = nChannels * sizeof(AudioUnitSampleType);
else {
mBytesPerPacket = mBytesPerFrame = sizeof(AudioUnitSampleType);
mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
}
}
如果“interleaved”为false,则不会将'mBytesPerPacket'和'mBytesPerFrame'乘以通道数。帧中没有足够的位来存储额外的通道。
因此,当示例代码要求2个通道时,它是否有些误导?既然无论如何都只会返回1个通道,那么它应该只要求1个通道吗?
outFormat.SetAUCanonical(1, false);
我能否这样简单地“修复” SetAUCannonical 以使事情更清晰?
mChannelsPerFrame = nChannels;
if (!interleaved) {
mChannelsPerFrame = 1
mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
}
mFramesPerPacket = 1;
mBitsPerChannel = 8 * sizeof(AudioUnitSampleType);
mBytesPerPacket = mBytesPerFrame = nChannels * sizeof(AudioUnitSampleType);
或者你是因为其他原因才需要2个通道?我甚至认为麦克风并不是立体声麦克风。