Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

audio mixing two pcm streams

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

like image 557
noztol Avatar asked Jan 25 '26 04:01

noztol


1 Answers

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.

like image 154
Bjorn Roche Avatar answered Jan 26 '26 21:01

Bjorn Roche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!