2

Apologies if this has been answered. I've seen lots of questions but no good answers.

I'm trying to export stereo music from my iPod library to two mono caf files. How can I do this on iOS? I'm currently using Objective C.

Thanks!

Update: I've managed to get the sample code working from apple thats here: https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html

My code will now import a media file and output as a valid caf file which plays fine. My problem is I can't work out how to modify the buffer before writing it. Here is my code I have so far:

// Get the next audio sample buffer, and append it to the output file.
CMSampleBufferRef sampleBuffer = [self.assetReaderAudioOutput copyNextSampleBuffer];
if (sampleBuffer != NULL)
{
    /////////////////////////////////////////
    CMBlockBufferRef blockBuffer;
    AudioBufferList audioBufferList;
    NSMutableData *data= [NSMutableData data];

    CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(AudioBufferList), NULL, NULL, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &blockBuffer);

    AudioBuffer audioBuffer = audioBufferList.mBuffers[0];

    for( int y=0; y< audioBufferList.mNumberBuffers; y=y+4 ){
        [data appendBytes:(audioBuffer.mData+y) length:2];
    }

    // how do I replace data in sampleBuffer with new data?

    CFRelease(blockBuffer);

    //////////////////////////////////////////

    BOOL success = [self.assetWriterAudioInput appendSampleBuffer:sampleBuffer];

    CFRelease(sampleBuffer);
    sampleBuffer = NULL;
    completedOrFailed = !success;
}
else
{
    completedOrFailed = YES;
}
Castles
  • 897
  • 1
  • 10
  • 29
  • Can you post your current export code so we can see what type of assets you're using for the current export? – jnpdx Jan 12 '15 at 05:18
  • Have you verified by looking at the bytes of the written file that the header is correct? – jnpdx Jan 12 '15 at 23:45
  • I haven't. Is this how you do that? hexdump -x monoleft.caf 0000000 6163 6666 0100 0000 6564 6373 0000 0000 0000010 0000 2000 e540 8088 0000 0000 0000 0000 0000020 0000 0c00 0000 0200 0000 0100 0000 0200 0000030 0000 1000 7266 6565 0000 0000 0000 b00f 0000040 0000 0000 0000 0000 0000 0000 0000 0000 * 0000ff0 6164 6174 0000 0000 2f01 0454 0000 0100 0001000 0000 0000 0000 0000 0000 0000 0000 0000 – Castles Jan 13 '15 at 12:20

1 Answers1

1

I've managed to do this by manually creating the header and writing to the file. This post gave me most of what I needed: https://stackoverflow.com/a/8677726/313272

Community
  • 1
  • 1
Castles
  • 897
  • 1
  • 10
  • 29