0

Please see code below. All I want to, is to merge bufflist1 and bufflist2, then inset to ioData. But I don't know how.

OSStatus PlayCallback(void *inRefCon,
                        AudioUnitRenderActionFlags *ioActionFlags,
                        const AudioTimeStamp *inTimeStamp,
                        UInt32 inBusNumber,
                        UInt32 inNumberFrames,
                        AudioBufferList *ioData) {
    ALNPlayer *player = (__bridge ALNPlayer *)inRefCon;
    
    OSStatus status;
    
    player->buffList->mBuffers[0].mDataByteSize = CONST_BUFFER_SIZEV3;
    //read audio1 data to bufflist1
    status = AudioConverterFillComplexBuffer(player->audioConverter1, lyInInputDataProcV1, inRefCon, &inNumberFrames, player->buffList1, NULL);
    
    //read audio2 data to bufflist2
    status = AudioConverterFillComplexBuffer(player->audioConverter2, lyInInputDataProcV2, inRefCon, &inNumberFrames, player->buffList2, NULL);
    

    //below is copy bufferlist1 to ioData
    //and now i want to merge bufflist1 and buflist2,then inset to iodata. But I don't know how.
    memcpy(ioData->mBuffers[0].mData, player->buffList->mBuffers[0].mData, player->buffList->mBuffers[0].mDataByteSize);
    

}
koen
  • 5,383
  • 7
  • 50
  • 89
Alan Luo
  • 159
  • 1
  • 13
  • 1
    Could you define what you mean by merge? – sbooth Feb 15 '23 at 13:53
  • @sbooth thanks for replying. I want to play two file at the same time. Or should I use two audiounits to play? – Alan Luo Feb 16 '23 at 03:02
  • There are multiple ways to handle this. Since you're using the C API an option is to use a multi-channel mixer (`kAudioUnitSubType_MultiChannelMixer`) with an input channel for each file (each with a corresponding input callback) and your play callback would get its input from the mixer's output channel. – sbooth Feb 16 '23 at 15:57
  • Thanks for helping. I would have a try. – Alan Luo Feb 17 '23 at 08:48

0 Answers0