【问题标题】:Record stereo from digital line in从数字线路输入立体声
【发布时间】:2014-05-22 10:09:03
【问题描述】:

我正在尝试从 iPhone/iPad 上的数字线路获取立体声样本。 为了获得立体声线路输入,我使用适用于 iOS 的 Mickey Blue 麦克风“Addon”。

This

我使用来自Here 的Aruts iOS CoreAudio 示例。

这非常适合从线路中获取单声道样本,但我无法弄清楚立体声的正确设置。

如果有人可以为我指明正确的方向,那将非常有帮助。 我需要先直接处理样本,所以不能先写入文件。

【问题讨论】:

    标签: ios objective-c core-audio audiotoolbox


    【解决方案1】:

    我猜你可以像这样使用AVAudioRecorder

    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
    [session setActive:YES error:nil];
    
    NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
    [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
    //this should enable stereo
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
    
    AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
    recorder.delegate = self;
    [recorder prepareToRecord];
    [recorder record];
    

    【讨论】:

    【解决方案2】:

    找到解决方案:

    AudioStreamBasicDescription 在立体声模式下只能接受每声道 32 位。使用下面的代码可以获取立体声样本(目前仅使用额外的硬件)

    这是我用来让它工作的音频格式:

    AudioStreamBasicDescription stereoStreamFormat;
    stereoStreamFormat.mSampleRate          = 44100.00;
    stereoStreamFormat.mFormatID            = kAudioFormatLinearPCM;
    stereoStreamFormat.mFormatFlags         = kAudioFormatFlagsAudioUnitCanonical;
    stereoStreamFormat.mBytesPerPacket      = 4;
    stereoStreamFormat.mBytesPerFrame       = 4;
    stereoStreamFormat.mFramesPerPacket     = 1;
    stereoStreamFormat.mChannelsPerFrame    = 2;
    stereoStreamFormat.mBitsPerChannel      = 32;
    

    此外,我为每个通道使用单独的缓冲区和修改后的 AudioBufferList struct :

    struct AudioBufferListStereo
    {
        UInt32      mNumberBuffers;
        AudioBuffer mBuffers[2]; //<-- this array has been set hardcoded to 2 channels because the standard iOS version did not work as expected.
    #if defined(__cplusplus) && CA_STRICT
    public:
        AudioBufferListStereo() {}
    private:
        //  Copying and assigning a variable length struct is problematic so turn their use into a
        //  compile time error for eacy spotting.
        AudioBufferListStereo(const AudioBufferListStereo&);
        AudioBufferListStereo&    operator=(const AudioBufferListStereo&);
    #endif
    
    };
    typedef struct AudioBufferListStereo  AudioBufferListStereo;
    

    完整的源码比较长,如果有人需要,我会在GitHub上发布。

    【讨论】:

      猜你喜欢
      • 2013-01-26
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多