Question

I am using the windows mmSystem.h to generate a few pcm files. Well they are not files yet, really byte arrays. what I want to do is merge or mux these two streams so the sounds overlap before I export them to a wav file. searching stackoverflow everyone has mentioned using ffmpeg but no one has any example code, they just use the fmpeg.exe with a few flags. I'd prefer a solution that does point me to use any other third party library or sdk other than whats available in windows and ffmpeg.

Thanks for any help

Was it helpful?

Solution

If you have byte arrays, you must first convert those byte arrays to the correct sample format, such as 16-bit integer (short). Once you've done that, you have a few options, including:

  1. Average the data, sample-by-sample.

  2. Sum the data, sample-by-sample, and then "clip" any samples that are out of range.

The first option is the only correct way to do it without distorting your signal.

Finally, you may need to convert back to bytes to save to a file.

For more details, including code, you may want to see something more like a tutorial.

OTHER TIPS

Assuming the two streams have the same sample rate and bits/sample you can just add the samples:

merged[n] = streama[n] + streamb[n];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top