Results 1 to 2 of 2

Thread: how to merge two caf file into one m4a(iLBC format) file

  1. #1
    Senior Member
    Join Date
    Mar 2013
    Posts
    416,482

    how to merge two caf file into one m4a(iLBC format) file

    first, thank @creker very much. in page "How can I record conversation / phone call on iOS?" .second,in this page ,the convert function merge two caf file into one m4a(AAC format) file. so how can i merge two caf file into one m4a(iLBC format) file. i want to get a least size file

    void Convert(){//File URLsCFURLRef micUrl = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)kMicFilePath, kCFURLPOSIXPathStyle, false);CFURLRef speakerUrl = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)kSpeakerFilePath, kCFURLPOSIXPathStyle, false);CFURLRef mixUrl = CFURLCreateWithFileSystemPath(NULL, (CFStringRef)kResultFilePath, kCFURLPOSIXPathStyle, false);ExtAudioFileRef micFile = NULL;ExtAudioFileRef speakerFile = NULL;ExtAudioFileRef mixFile = NULL;//Opening input files (speaker and mic)ExtAudioFileOpenURL(micUrl, &micFile);ExtAudioFileOpenURL(speakerUrl, &speakerFile);//Reading input file audio format (mono LPCM)AudioStreamBasicDescription inputFormat, outputFormat;UInt32 descSize = sizeof(inputFormat);ExtAudioFileGetProperty(micFil e, kExtAudioFileProperty_FileDataFormat, &descSize, &inputFormat);int sampleSize = inputFormat.mBytesPerFrame;//Filling input stream format for output file (stereo LPCM)FillOutASBDForLPCM(inputFormat, inputFormat.mSampleRate, 2, inputFormat.mBitsPerChannel, inputFormat.mBitsPerChannel, true, false, false);//Filling output file audio format (AAC)memset(&outputFormat, 0, sizeof(outputFormat));outputFormat.mFormatID = kAudioFormatMPEG4AAC;outputFormat.mSampleRate = 8000;outputFormat.mFormatFlags = kMPEG4Object_AAC_Main;outputFormat.mChannelsPerFra me = 2;//Opening output fileExtAudioFileCreateWithURL(mixUrl, kAudioFileM4AType, &outputFormat, NULL, kAudioFileFlags_EraseFile, &mixFile);ExtAudioFileSetProperty(mixFile, kExtAudioFileProperty_ClientDataFormat, sizeof(inputFormat), &inputFormat);//Freeing URLsCFRelease(micUrl);CFRelease(speakerUrl);CFRele ase(mixUrl);//Setting up audio buffersint bufferSizeInSamples = 64 * 1024;AudioBufferList micBuffer;micBuffer.mNumberBuffers = 1;micBuffer.mBuffers[0].mNumberChannels = 1;micBuffer.mBuffers[0].mDataByteSize = sampleSize * bufferSizeInSamples;micBuffer.mBuffers[0].mData = malloc(micBuffer.mBuffers[0].mDataByteSize);AudioBufferList speakerBuffer;speakerBuffer.mNumberBuffers = 1;speakerBuffer.mBuffers[0].mNumberChannels = 1;speakerBuffer.mBuffers[0].mDataByteSize = sampleSize * bufferSizeInSamples;speakerBuffer.mBuffers[0].mData = malloc(speakerBuffer.mBuffers[0].mDataByteSize);AudioBufferList mixBuffer;mixBuffer.mNumberBuffers = 1;mixBuffer.mBuffers[0].mNumberChannels = 2;mixBuffer.mBuffers[0].mDataByteSize = sampleSize * bufferSizeInSamples * 2;mixBuffer.mBuffers[0].mData = malloc(mixBuffer.mBuffers[0].mDataByteSize);//Convertingwhile (true){ //Reading data from input files UInt32 framesToRead = bufferSizeInSamples; ExtAudioFileRead(micFile, &framesToRead, &micBuffer); ExtAudioFileRead(speakerFile, &framesToRead, &speakerBuffer); if (framesToRead == 0) { break; } //Building interleaved stereo buffer - left channel is mic, right - speaker for (int i = 0; i < framesToRead; i++) { memcpy((char*)mixBuffer.mBuffers[0].mData + i * sampleSize * 2, (char*)micBuffer.mBuffers[0].mData + i * sampleSize, sampleSize); memcpy((char*)mixBuffer.mBuffers[0].mData + i * sampleSize * 2 + sampleSize, (char*)speakerBuffer.mBuffers[0].mData + i * sampleSize, sampleSize); } //Writing to output file - LPCM will be converted to AAC ExtAudioFileWrite(mixFile, framesToRead, &mixBuffer);}//Closing filesExtAudioFileDispose(micFile);ExtAudioFileDisp ose(speakerFile);ExtAudioFileDispose(mixFile);//Freeing audio buffersfree(micBuffer.mBuffers[0].mData);free(speakerBuffer.mBuffers[0].mData);free(mixBuffer.mBuffers[0].mData);}

    View solution

  2. #2
    Junior Member
    Join Date
    Apr 2015
    Posts
    1
    You may refer to this step by step guide to merge two or more caf files into one m4a at Audio Joiner Mac/PC - Merge WAV, M4A, FLAC, MP3, AAC, AC3, Audio Files.



    This guide also helps joining any audio formats like merge MP3, WAV, M4A, FLAC, AAC, WMA, M4B, AC3, VOC, CAF, APE, AIFF, Apple Lossless ALAC, QCP, AMR, AWB, DTS, AU, RA, OGG, XWM, 3GA and more.



    Besides, it also enalbes to join M4A and many other audio formats as well as keep the source audio formats; Or merge M4A, MP3, WAV etc as well as convert them to other audio formats.

Similar Threads

  1. Replies: 1
    Last Post: 06-11-2015, 10:09 AM
  2. Replies: 0
    Last Post: 01-16-2014, 05:10 AM
  3. Audio conversion of CAF file
    By bigdata in forum Iphone Issues
    Replies: 0
    Last Post: 11-12-2013, 11:00 AM
  4. hadoop RC file format : merge small files in hdfs
    By bigdata in forum Hadoop basics
    Replies: 0
    Last Post: 10-21-2013, 11:10 PM
  5. Replies: 0
    Last Post: 05-14-2013, 03:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •