1
$\begingroup$

I'm trying to do one simple thing on Google's C++ Oboe library: pick 2 recordings and merge both. That is, make as if the 2 were playing at the same time.

Oboe works with Float numbers from -1.0 to +1.0. Can I simply do like this:

Audio1:

-0.2, -0.221, -0.23, -0.24, ...

Audio2:

-0.3, -0.23, -0.12, -0.87, ...

Audio Mixed:

(-0.2+-0.3)/2,  (-0.221+-.023)/2, (-0.23 -0.12)/2, (-0.24-0.87)/2, ...

?

That is, take the average of both audios into the new audio?

Is this how 2 simple audio files are merged together?

$\endgroup$
  • $\begingroup$ Have you tried doing what you mentioned? If yes, what did you observe that made you ask this question? $\endgroup$ – Paddy Aug 22 at 11:22
1
$\begingroup$

If your goal is to simply make it sound like they were playing at the same time, you can simply just add them together element-wise. There is need to "average". The resulting waveform is the same, but scaled by a factor of 2 in your case. Technically, that number could really be anything.

If you want different properties, where maybe one sounds louder than the other, then you'll have to do something else.

| improve this answer | |
$\endgroup$
  • $\begingroup$ but if I dont scale it down then wouldnt it blow up if I add 2 sounds like 0.5f and 0.5f? $\endgroup$ – Guerlando OCs Aug 19 at 3:28
  • $\begingroup$ @GuerlandoOCs That depends on your application. If you're doing this purely digitally then numbers like these shouldn't be a problem. $\endgroup$ – Envidia Aug 19 at 4:22
0
$\begingroup$

To merge two sound sources with the Google's C++ Oboe library: first, you use a Mixer object to sum the outputs from multiple tracks into a single output. See section 6. Play multiple sounds of a Build a Musical Game using Oboe tutorial.

How to proceed with the mixed sound depends on your usage scenario. You can play it to your audio output devices or save it to an audio file. For the latter option, see https://stackoverflow.com/questions/53890415/how-to-capture-audio-data-and-save-to-wav-file.

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.