从数字线录制立体声

时间:2014-05-22 10:09:03

标签: ios objective-c core-audio audiotoolbox

我试图从iPhone / iPad上的数字线路中获取立体声样本。 为了获得立体声输入线路,我使用了Mickey Blue麦克风" Addon"对于iOS。

This

我使用Here中的Aruts iOS CoreAudio示例。

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

如果有人能指出我正确的方向,那将是非常有帮助的。 我需要直接对样本进行处理,因此首先写入文件不是一种选择。

2 个答案:

答案 0 :(得分:0)

我猜你可以像这样使用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];

答案 1 :(得分:0)

找到解决方案:

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 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上发布它。