【问题标题】:Stereo playback gets converted to mono (on iPad only) even when using stereo headphones即使使用立体声耳机,立体声播放也会转换为单声道(仅限 iPad)
【发布时间】:2011-10-25 14:36:44
【问题描述】:

我正在开发一个使用核心音频的音频处理应用程序,它通过耳机麦克风记录声音并通过耳机播放。

我为平衡添加了一项功能,即将播放转移到一只耳朵上。

这在我测试过的 iPod 和 iPhone 上完美运行。但不是在 iPad 上。在 iPad 上,声音的位置根本没有改变。

这是用于渲染音频输出的代码:

static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
{
    // Get a pointer to the dataBuffer of the AudioBufferList
    AudioBuffer firstBuffer = ioData->mBuffers[0];
    AudioSampleType *outA = (AudioSampleType *)firstBuffer.mData;
    int numChannels = firstBuffer.mNumberChannels;
    NSLog(@"numChannels = %d, left = %d, right = %d", numChannels, leftBalVolume, rightBalVolume);
    // Loop through the callback buffer, generating samples
    for (UInt32 i = 0; i < inNumberFrames * numChannels; i += numChannels) {        
        int outSignal = getFilteredSampleData(sampleDataTail);
        outA[i] = (outSignal * leftBalVolume) / 32768;
        if (numChannels > 1) {
            outA[i + 1] = (outSignal * rightBalVolume) / 32768;    
        }
        sampleDataTail = (sampleDataTail + 1) % sampleDataLen;
    }
    return noErr;
}

NSLog 的输出如下:

numChannels = 2, left = 16557, right = 32767

...告诉我它基本上是在立体声模式下工作,我应该听到稍微向右的音频。但即使我把它 100% 放在右边,我仍然可以听到中间的音频,两个耳机的音量相同。

显然,iPad 2 将音频信号混合为单声道,然后在两个耳机上播放。我认为这可能与 iPad 只有一个扬声器有关,因此通常会混音成单声道……但为什么即使连接了立体声耳机,它也会这样做?

非常感谢任何帮助!

【问题讨论】:

  • 仅供参考:这是 AudioStreamBasicDescription:2 ch,22050 Hz,'lpcm' (0x0000000C) 16 位 little-endian 有符号整数

标签: iphone objective-c ios ipad core-audio


【解决方案1】:

找到罪魁祸首:

我打过电话

desc.SetAUCanonical(1, true);

在混音器输出的 StreamFormat 描述符上。现在我只是为每个属性设置值,它也适用于 iPad...

desc.mSampleRate         = kGraphSampleRate;
desc.mFormatID           = kAudioFormatLinearPCM;
desc.mFormatFlags        = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
desc.mFramesPerPacket    = 1;
desc.mChannelsPerFrame   = 2;
desc.mBitsPerChannel     = 16;
desc.mBytesPerPacket     = 4;
desc.mBytesPerFrame      = 4;

似乎 SetAUCanonical 在 iPad 与 iPod Touch 和 iPhone 上做了不同的事情

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 2019-07-14
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    相关资源
    最近更新 更多