1

我使用 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;
}

在这个我只得到麦克风的声音,但没有音频文件的声音

4

0 回答 0