lostInTransit
lostInTransit

Reputation: 71047

iPhone - combine two wav/caf files into one

Is it possible to combine two wav files into one as if they've been played simultaneously? I need to do this programatically.

The only way I found till now is to play both simultaneously and record the output using AVAudioRecorder. But this won't work if the user's using headphones.

Can someone please point me to the right direction.

Thanks.

Upvotes: 3

Views: 1314

Answers (2)

lucius
lucius

Reputation: 8685

You'll need to read the sample data of each file, average each sample value, and write the result to a new file. You can use ExtAudioFile to read and write files, including the headers and the sample data.

You also need to update the header with the correct length of the file, because there are fields whose value depends on the length of the sample data.

Upvotes: 2

ttvd
ttvd

Reputation: 1675

There might be a better way, but if both wavs have same encoding/bitrate, etc, you can just strip the wav header (first 44 bytes according to wav format spec) of the second file and concatenate the rest of 2nd wav to first.

Upvotes: 0

Related Questions