OGeek|极客世界-中国程序员成长平台

标题: iphone - iOS LPCM 非交错音频输入,2 个 channel : not possible? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:38
标题: iphone - iOS LPCM 非交错音频输入,2 个 channel : not possible?

aurioTouch示例应用程序 RemoteIO 音频单元配置为 8.24 定点格式的 2 channel 非交错 LPCM。这是 iOS 平台上的首选格式,我假设这就是硬件 ADC 发出的内容。他们甚至对此发表了评论(source):

// set our required format - Canonical AU format: LPCM non-interleaved 8.24 fixed point
outFormat.SetAUCanonical(2, false);

所以我希望当应用程序稍后收到一个音频缓冲区时,它的 mData 成员中会以某种顺序包含两个 channel 的数据。像这样的:

mData = [L1, L2, L3, L4, R1, R2, R3, R4];

其中 L 和 R 代表来自立体声麦克风左右声道的数据。只是似乎不可能,因为 SetAUCannonical() 没有设置足够的内存来保存附加 channel :

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' 乘以 channel 数。帧中没有足够的位来存储额外的 channel 。

那么当示例代码要求 2 个 channel 时,它会不会有点误导?它是否应该只要求 1 个 channel ,因为无论如何它都会返回:

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 个 channel ?我什至不认为麦克风是立体声麦克风。



Best Answer-推荐答案


内置麦克风和耳机麦克风输入均为单声道。

相机连接套件可能允许在运行某些以前的操作系统版本的一些较新的 iOS 设备上从某些 USB 麦克风输入立体声音频,但我没有看到任何关于这与当前操作系统版本一起使用的报告。

另外,检查 2 channel (立体声)非交错格式是否可能将 2 个缓冲区返回到 RemoteIO 回调,而不是 1 个缓冲区中的连接数据。

关于iphone - iOS LPCM 非交错音频输入,2 个 channel : not possible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4422672/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4