iOS.使用USB麦克风以96kHz录制 [英] iOS. Record at 96kHz with USB microphone

查看:227
本文介绍了iOS.使用USB麦克风以96kHz录制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用RØDEiXY USB麦克风以96kHz的频率进行录音.
录制没有错误,当我在连接麦克风的情况下启动应用程序时,我看到AVAudioSession以96kHz采样率成功运行.
但是,如果我看一下频谱,很明显,除了对20kHz以上的噪声进行重采样之外,没有任何其他东西:

I am trying to record at full 96kHz with my RØDE iXY USB microphone.
Recording goes without error and when I launch the app with the mic connected, I see that AVAudioSession is running successfully at 96kHz sample rate.
But if I look at the spectrum it is clear that there is nothing but resample noise above 20kHz:

为进行比较,这是使用与USB麦克风(RØDERec)捆绑在一起的应用程序进行的同一录音的频谱:

For comparison this is a spectrum of the same recording using the app bundled with the USB mic (RØDE Rec):

要以本机96kHz录制,还需要做些其他事情吗? 还是RØDERec应用程序通过USB通过某些专有协议与麦克风通信,我在这里很不走运?

Is there anything else I must do to record at native 96kHz? Or maybe the RØDE Rec app communicates with the mic with some proprietary protocol over USB and I'm out of luck here?

我包括了我使用的源代码:

I included the source code that I use:

static AudioStreamBasicDescription AudioDescription24BitStereo96000 = (AudioStreamBasicDescription) {
    .mFormatID          = kAudioFormatLinearPCM,
    .mFormatFlags       = kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger,
    .mChannelsPerFrame  = 2,
    .mBytesPerPacket    = 6,
    .mFramesPerPacket   = 1,
    .mBytesPerFrame     = 6,
    .mBitsPerChannel    = 24,
    .mSampleRate        = 96000.0
};

- (void)setupAudioSession
{
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryRecord error:&error];
    [session setActive:YES error:&error];
    [session setPreferredSampleRate:96000.0f error:&error];

    //I got my 96000Hz with the USB mic plugged in!
    NSLog(@"sampleRate = %lf", session.sampleRate);
}

- (void)startRecording
{
    AudioComponentDescription desc;
    desc.componentType = kAudioUnitType_Output;
    desc.componentSubType = kAudioUnitSubType_RemoteIO;
    desc.componentFlags = 0;
    desc.componentFlagsMask = 0;
    desc.componentManufacturer = kAudioUnitManufacturer_Apple;

    AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc);
    AudioComponentInstanceNew(inputComponent, &audioUnit);

    AudioUnitScope inputBus = 1;

    UInt32 flag = 1;
    AudioUnitSetProperty(audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, inputBus, &flag, sizeof(flag));

    audioDescription = AudioDescription24BitStereo96000;

    AudioUnitSetProperty(audioUnit,
                         kAudioUnitProperty_StreamFormat,
                         kAudioUnitScope_Output,
                         inputBus,
                         &audioDescription,
                         sizeof(audioDescription));

    AURenderCallbackStruct callbackStruct;
    callbackStruct.inputProc = recordingCallback;
    callbackStruct.inputProcRefCon = (__bridge void *)(self);
    AudioUnitSetProperty(audioUnit,
                         kAudioOutputUnitProperty_SetInputCallback,
                         kAudioUnitScope_Global,
                         inputBus, &callbackStruct,
                         sizeof(callbackStruct));

    AudioOutputUnitStart(audioUnit);
}

static OSStatus recordingCallback(void *inRefCon,
                                  AudioUnitRenderActionFlags *ioActionFlags,
                                  const AudioTimeStamp *inTimeStamp,
                                  UInt32 inBusNumber,
                                  UInt32 inNumberFrames,
                                  AudioBufferList *ioData)
{
    AudioBuffer audioBuffer;
    audioBuffer.mNumberChannels = 1;
    audioBuffer.mDataByteSize = inNumberFrames * audioDescription.mBytesPerFrame;
    audioBuffer.mData = malloc( inNumberFrames * audioDescription.mBytesPerFrame );

    // Put buffer in a AudioBufferList
    AudioBufferList bufferList;
    bufferList.mNumberBuffers = 1;
    bufferList.mBuffers[0] = audioBuffer;

    AudioUnitRender(audioUnit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, &bufferList);

    //I then take the samples and write them to WAV file
}

推荐答案

在插入麦克风的情况下检查硬件采样率音频会话属性.还要检查所有音频单元功能错误返回值.

Check the hardware sample rate audio session property with your microphone plugged in. Also check all audio unit function error return values.

RemoteIO可能会使用较低的输入采样率,然后重新采样为96k流.

RemoteIO may be using a lower input sample rate and then resampling to a 96k stream.

这篇关于iOS.使用USB麦克风以96kHz录制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆