iphone - iOS LPCM Non-interleaved Audio input with 2 channels : not possible?

标签 iphone ios audio core-audio microphone

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);

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

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

最佳答案

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

Camera Connection 套件可能允许在运行某些旧操作系统版本的某些较新 iOS 设备上从某些 USB 麦克风输入立体声音频,但我还没有看到任何关于此功能适用于当前操作系统版本的报告。

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

关于iphone - iOS LPCM Non-interleaved Audio input with 2 channels : not possible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4422672/

相关文章:

javascript - Html 通过 jquery/javascript 在 iphone 上保持键盘可见

iPhone 仅横向实用程序模板应用程序

php - 自动合成声音 - php 或类似的东西 - GD 声音库?

windows - 如何通过程序检查应用是否发出某种声音?

iphone - 在 iPhone 中将图像文本转换为其他语言

iphone - PhoneGap 应用程序可以使用服务器页面加载吗?

ios - [self presentViewController : animated: completion:] 后 UITextView 和 UITextField 没有响应

iphone - UIScrollView 问题 : forbid to "scroll to empty space"

javascript - iOS 上 jQuery.each() 和 Underscore.each() 的神秘失败

python - 如何从Jupyter Notebook下载音频?