2 Wav file mixing
Does anybody know how to mix together two Wav files to playy at the same time.
get an audio libraby like openAL or sfml-audio
You can either:
1. use an API like DTSCode suggests and just play two streams at the same time. This works well if you are mixing during runtime.
2. Simply load both WAVE files into memory and then "add" the signals togeather. This is an easy way to do it if you are "preprocessing"
// Load wav1, wav2 and allocate the size of wavOut
float gain1 = 1.f; // Tune these to your liking
float gain2 = 1.f;
for (int &i : wavOutData)
wavOutData[i] = clip(gain1 * wav1data[i] + gain2 * wav2data[i]);
Where clip will "clip" your signal to avoid overflows:
short clip(int input)
if (input > 0x7FFF)
if (input < - 0x7FFF)
Last edited on
Topic archived. No new replies allowed.