Question

I am trying to write some data to the beginning of an audio file. But the file is getting overwritten. If I write data worth 20 seconds to the beginning of the audio file using AudioFileWritePackets, the initial 20 seconds of data is overwritten in the original audio file.

This is what I use

AudioFileOpenURL((CFURLRef)flUrl, kAudioFileReadWritePermission, 0, &audioId);
//initialize my 20 sec data into a buffer
AudioFileWritePackets(audioId, FALSE, numBytesToWrite, NULL, 0, &packetsToWrite, packBuffer);

Can someone please tell me how I can achieve this (prepend the 20 sec worth of audio to the original audio file)

Thanks.

Was it helpful?

Solution

You're going to need to open a new file, write your new data to it, and then copy the old audio from the old file to the end of the new file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top