2012-04-23 16 views
6

AudioUnitRenderのエラー-50(無効なパラメータ)が次のコンテキストで発生します。私はこのPitch Detectorサンプルアプリケーションを私の出発点として使用しています。私のプロジェクトで唯一の大きな違いは、オーディオ出力用にもリモートI/Oユニットを使用していることです。オーディオ出力が正常に動作します。ここに私の入力コールバックと私の初期化コード(簡潔さのためにエラーチェックを削除して)です。私はそれがたくさんあることは分かっていますが、エラーは本当に私には問題がどこにあるのかについての情報はほとんどありません。AudioUnitRenderのエラー-50

入力コールバック:

OSStatus inputCallback(void* inRefCon, 
          AudioUnitRenderActionFlags *ioActionFlags, 
          const AudioTimeStamp  *inTimeStamp, 
          UInt32      inBusNumber, 
          UInt32      inNumberFrames, 
          AudioBufferList    *ioData) { 

    WBAudio* audioObject= (WBAudio*)inRefCon; 

    AudioUnit rioUnit = audioObject->m_audioUnit; 
    OSStatus renderErr; 
    UInt32 bus1 = 1; 

    renderErr = AudioUnitRender(rioUnit, ioActionFlags, 
           inTimeStamp, bus1, inNumberFrames, audioObject->m_inBufferList); 
    if (renderErr < 0) { 
     return renderErr; // breaks here 
    } 

    return noErr; 
} // end inputCallback() 

初期化:

- (id) init { 

    self= [super init]; 
    if(!self) return nil; 

    OSStatus result; 

    //! Initialize a buffer list for rendering input 
    size_t bytesPerSample; 
    bytesPerSample = sizeof(SInt16); 
    m_inBufferList = (AudioBufferList *)malloc(sizeof(AudioBuffer)); 
    m_inBufferList->mNumberBuffers = 1; 
    m_inBufferList->mBuffers[0].mNumberChannels = 1; 
    m_inBufferList->mBuffers[0].mDataByteSize = 512*bytesPerSample; 
    m_inBufferList->mBuffers[0].mData = calloc(512, bytesPerSample); 

    //! Initialize an audio session to get buffer size 
    result = AudioSessionInitialize(NULL, NULL, NULL, NULL); 

    UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord; 
    result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory); 

    // Set preferred buffer size 
    Float32 preferredBufferSize = static_cast<float>(m_pBoard->m_uBufferSize)/m_pBoard->m_fSampleRate; 
    result = AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(preferredBufferSize), &preferredBufferSize); 

    // Get actual buffer size 
    Float32 audioBufferSize; 
    UInt32 size = sizeof (audioBufferSize); 
    result = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareIOBufferDuration, &size, &audioBufferSize); 

    result = AudioSessionSetActive(true); 

    //! Create our Remote I/O component description 
    AudioComponentDescription desc; 
    desc.componentType= kAudioUnitType_Output; 
    desc.componentSubType= kAudioUnitSubType_RemoteIO; 
    desc.componentFlags= 0; 
    desc.componentFlagsMask= 0; 
    desc.componentManufacturer= kAudioUnitManufacturer_Apple; 

    //! Find the corresponding component 
    AudioComponent outputComponent = AudioComponentFindNext(NULL, &desc); 

    //! Create the component instance 
    result = AudioComponentInstanceNew(outputComponent, &m_audioUnit); 

    //! Enable audio output 
    UInt32 flag = 1; 
    result = AudioUnitSetProperty(m_audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &flag, sizeof(flag)); 

    //! Enable audio input 
    result= AudioUnitSetProperty(m_audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, kInputBus, &flag, sizeof(flag)); 

    //! Create our audio stream description 
    m_audioFormat.mSampleRate= m_pBoard->m_fSampleRate; 
    m_audioFormat.mFormatID= kAudioFormatLinearPCM; 
    m_audioFormat.mFormatFlags= kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; 
    m_audioFormat.mFramesPerPacket= 1; 
    m_audioFormat.mChannelsPerFrame= 1; 
    m_audioFormat.mBitsPerChannel= 16; 
    m_audioFormat.mBytesPerPacket= 2; 
    m_audioFormat.mBytesPerFrame= 2; 

    //! Set the stream format 
    result = AudioUnitSetProperty(m_audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &m_audioFormat, sizeof(m_audioFormat)); 

    result = AudioUnitSetProperty(m_audioUnit, kAudioUnitProperty_StreamFormat, 
           kAudioUnitScope_Output, 
           kInputBus, &m_audioFormat, sizeof(m_audioFormat)); 

    //! Set the render callback 
    AURenderCallbackStruct renderCallbackStruct= {0}; 
    renderCallbackStruct.inputProc= renderCallback; 
    renderCallbackStruct.inputProcRefCon= m_pBoard; 
    result = AudioUnitSetProperty(m_audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, kOutputBus, &renderCallbackStruct, sizeof(renderCallbackStruct)); 

    //! Set the input callback 
    AURenderCallbackStruct inputCallbackStruct = {0}; 
    inputCallbackStruct.inputProc= inputCallback; 
    inputCallbackStruct.inputProcRefCon= self; 
    result= AudioUnitSetProperty(m_audioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Input, kOutputBus, &inputCallbackStruct, sizeof(inputCallbackStruct)); 

    //! Initialize the unit 
    result = AudioUnitInitialize(m_audioUnit); 

    return self; 
} 
+1

チェックを確認してください。また、あなたが言及したWebサイトにはピッチ検出器のコードはありませんが、誤ってラベル付けされたピーク周波数検出器のみがピッチ推定に失敗することがよくあります。 – hotpaw2

+0

彼らは同じです。そして、私は間違いなく塩の穀物でピッチ検出を取るでしょう。 – Luke

+0

解決できましたか?私は通常、AudioUnitRenderの呼び出しが成功するという問題があります。しかし、入力コールバックがより多くのバイトを要求するため、私のアプリケーションがバックグラウンドから戻ってくると失敗します。私の最初の考えは、それは私のバッファサイズと関係があったが、それらを増やすことは助けにならなかったということでした – tomk

答えて

0

あなたはm_inBufferListを割り当てているよう:

m_inBufferList = (AudioBufferList *)malloc(sizeof(AudioBuffer)); 

これは次のようになります。

m_inBufferList = (AudioBufferList *)malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer) * numberOfBuffers); //numberOfBuffers in your case is 1 

あなたの問題を解決できるかもしれません。開発docに

+0

あなたはかっこがどこかにありません。 –

+0

良いキャッチですが、エラーはまだあります。 – Luke

+2

AudioBufferListの宣言で既に1つのmbufferが割り当てられているので、彼は1つのバッファしか必要としないので、2番目のsizeofはスキップできます。 – tomk

1

エラー-50はのparamsのエラー、 あなたはAudioUnitRenderの右のparamsを渡す持っていることを確認してくださいを意味します。 あなたBUS1とinBusNumberが同じであることを確認するストリーム形式とあなたのユニット

関連する問題