0
0

Hey Guys…

I was just wondering if anyone had any idea how to merge to sound from 2 (or more) audio files into one file?
I do not mean merge the files into one big one by concatenating audio2 to the end of audio1, however actually
merging the sound layers over the top of each other so the final result is both audio files playing together.

E.g. 2 track sof the same length, Guitar track + Bass track = One audio track with BOTH guitar and bass.

Any suggestiong would be splendid.
I have googled for a while, maybe im getting the wording wrong because ‘merge’ suggests appending the files,
which is not my desired result :)

Thank people,

Chris Rickard.

  • You must to post comments
0
0

the word you are looking for is ‘mix’.

It is not hard to do, you just need to access the raw data in both sounds, which you could do with Sound::lock Sound::unlock.
Once you have that, if they are the same format , just add the 2 buffers together.

If it is 16bit integer data, then you will have to sum the result into a 32bit value, then clamp the value at -32768 to +32767 then store it in the 16bit destination buffer.

ie
int temp = (int)srcA[i] + (int)srcB[i];
dest[i] = temp < -32768 ? -32768 : temp > 32767 ? 32767 : (signed short)temp;

  • You must to post comments
0
0

Howdy,

I have been able to mix to mp3s into a single wav file by using the code that Brett had posted:
nt temp = (int)srcA[i] + (int)srcB[i];
dest[i] = temp < -32768 ? -32768 : temp > 32767 ? 32767 : (signed short)temp;

However, although the resulting audio IS the two inputted sounds mixed together, there is a hiss in background, and lots of loud glitches – especially when one of the mixes is a loud mp3.

Does anyone have an idea why this might be occuring?

Thanks heaps,
Chris Rickard.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.