【发布时间】:2010-12-12 16:36:17
【问题描述】:
在aurioTouch 示例应用程序中,RemoteIO 音频单元配置为 8.24 定点格式的 2 通道非交错 LPCM。这是 iOS 平台上的首选格式,我假设这就是硬件 ADC 发出的内容。他们甚至对此发表了评论(source):
// 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 个频道,因为无论如何它都会返回:
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 个频道?我什至不认为麦克风是立体声麦克风。
【问题讨论】:
标签: iphone ios audio core-audio microphone