AudioUnit:如何获取混合音频数据

时间:2012-08-15 02:32:16

标签: iphone audiounit mixer

我用AudioUnit来混合两个音频文件,而ioUnit用麦克风录音,我想用混音器和录音来获取同步音频数据,但是在“RenderNotify”回调中我只得到了录音数据,怎么能我这样做?

    AUGraphAddRenderNotify(processingGraph, auRenderCallbac, self);

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

{


    if(*ioActionFlags & kAudioUnitRenderAction_PostRender)
    {
        MixerHostAudio *THIS = (MixerHostAudio *)inRefCon;

        AudioUnitSampleType samples[inNumberFrames]; // A large enough size to not have to worry about buffer overrun
        memset (&samples, 0, sizeof (samples));

        AudioBufferList bufferList;
        bufferList.mNumberBuffers = 1;
        bufferList.mBuffers[0].mData = samples;
        bufferList.mBuffers[0].mNumberChannels = 1;
        bufferList.mBuffers[0].mDataByteSize = inNumberFrames*sizeof(AudioUnitSampleType);

        OSStatus err = AudioUnitRender(THIS.ioUnit, ioActionFlags, 
                                       inTimeStamp, 1, inNumberFrames, &bufferList);
        printf("%lu \n",err);

        unsigned char aacData[2048] = {0};
        int inLen = inNumberFrames;
        int outLen;

        [THIS->aacEncoder encFuncWithInCode:(short *)bufferList.mBuffers[0].mData outCode:aacData inLen:&inLen outLen:&outLen];

        fwrite(aacData, 1, outLen, THIS->outfile);
    }

    return noErr;
}
  

在此我只能听到麦克风的声音,但没有音频文件的声音

0 个答案:

没有答案