Help - Search - Members - Calendar
Full Version: mix two wav files
Hydrogenaudio Forums > Hydrogenaudio Forum > General Audio
marcan
I would like to develop a small app capable to mix two wav files together.

Both source wav files would be stereo 32 bits floating point, the result as well.
Someone could confirm that I just have to add the respective raw sound data of each source file in order to get the respective values of the result file.

Thank you for your help
bryant
QUOTE(marcan @ Apr 1 2005, 03:09 PM)
I would like to develop a small app capable to mix two wav files together.

Both source wav files would be stereo 32 bits floating point, the result as well.
Someone could confirm that I just have to add the respective raw sound data of each source file in order to get the respective values of the result file.

Thank you for your help
*


That will do it. Depending on your application you might want to divide by 2 after to avoid clipping (although floating audio won't clip, when it gets truncated to 24-bit it might).
marcan
QUOTE(bryant @ Apr 1 2005, 03:14 PM)
That will do it. Depending on your application you might want to divide by 2 after to avoid clipping (although floating audio won't clip, when it gets truncated to 24-bit it might).
*


Thx bryant.

It will be converted into mp3. However the level of both source files are tuned in order to not clip when they are both mixed at 0 db (no gain, no attenuation).
In that case I should avoid cliping during the playback...
ChiGung
QUOTE(marcan @ Apr 1 2005, 11:44 PM)
QUOTE(bryant @ Apr 1 2005, 03:14 PM)
That will do it. Depending on your application you might want to divide by 2 after to avoid clipping (although floating audio won't clip, when it gets truncated to 24-bit it might).
*


Thx bryant.

It will be converted into mp3. However the level of both source files are tuned in order to not clip when they are both mixed at 0 db (no gain, no attenuation).
In that case I should avoid cliping during the playback...
*



Ive come across a theoretical problem with this though:

Imagine two tracks both of a pure sine note at same freq and volume, but recorded at different times. If you add these two tracks together -sample by sample, the resulting mix will just as likely be silent as be twice as loud as either of the source tracks (!) its most likely to be around the same loudness as either of them - depending on the wether the phase of the signals in each track happen to reinforce, oppose each other, or just move each other over a bit.

I dont know how this fundamental observation manifests itself in practice, maybe mixing like this can produce flanging and strange loudness wobbling ?
It should be better off if they are dissimilar like one track of drums and other vocal.
There may be some techniques used to combat wobbling artifacts - like.... ~time dithering or something... Some mixing techniques could manipulate frequency spectrums...

It would be about the best way of forcing two signals into one. In the real world energy makes sure it is mantained when brought together, but in this virtual analogue it can easily dissappear without a trace ohmy.gif

marcan
QUOTE(ChiGung @ Apr 1 2005, 04:36 PM)

Ive come across a theoretical problem with this though:

Imagine two tracks both of a pure sine note at same freq and volume, but recorded at different times. If you add these two tracks together -sample by sample, the resulting mix will just as likely be silent as be twice as loud as either of the source tracks (!) its most likely to be around the same loudness as either of them - depending on the wether the phase of the signals in each track happen to reinforce, oppose each other, or just move each other over a bit.

I dont know how this fundamental observation manifests itself in practice, maybe mixing like this can produce flanging and strange loudness wobbling ?
It should be better off if they are dissimilar like one track of drums and other vocal.
There may be some techniques used to combat wobbling artifacts - like.... ~time dithering or something... Some mixing techniques could manipulate frequency spectrums...

It would be about the best way of forcing two signals into one. In the real world energy makes sure it is mantained when brought together, but in this virtual analogue it can easily dissappear without a trace ohmy.gif
*


I guess this is the same phase problem with an analogical mixer?
Anyway, we will mix instrument and voice, so it shouldn’t be a problem.

Do you know a better algorithm than simple addition?
ChiGung
QUOTE(marcan @ Apr 2 2005, 10:25 AM)
I guess this is the same phase problem with an analogical mixer?
Anyway, we will mix instrument and voice, so it shouldn’t be a problem.

Do you know a better algorithm than simple addition?
*


It seems to be a commonly used downmixing technique - maybe its the most 'real' way
Im thinking of in real life - if I pluck two guitar strings which are almost but not quite the same note, the loudness can be heard to wobble as the slowly changing phases interfere with each other. If the two strings are near exactly the same note, they syncronise phase and reinforce each other. I think resonance then helps them keep inphase with each other. Two wind instruments mightnt resonate in sync though.. so now Im thinking maybe this phase interference is natural and common in the real world, come to think of it, it would be to do with why badly tuned instruments sound bad - because the notes really are grating each other...

As for different algorithm for downmixing, I couldnt say some may have a goal or different sense, but sound terrible. I think now plain addition could sound the most natural.

Hope you dont mind that little wild goose chase~
jkml
QUOTE(marcan @ Apr 2 2005, 08:09 AM)
I would like to develop a small app capable to mix two wav files together.

Both source wav files would be stereo 32 bits floating point, the result as well.
Someone could confirm that I just have to add the respective raw sound data of each source file in order to get the respective values of the result file.

Thank you for your help
*



You might want to check out sox because soxmix (included in the sox package) can already mix two or more WAVE files together and adjust the final volume accordingly.
marcan
QUOTE(jkml @ Apr 2 2005, 05:07 AM)
You might want to check out sox because soxmix (included in the sox package) can already mix two or more WAVE files together and adjust the final volume accordingly.
*


Thx jkml, I have to develop my own app, but this could be useful.
As always you rock here on HA. cool.gif
ChiGung
Sox w00t.gif -thats a fine lookin GPL tool!
antz
QUOTE(ChiGung @ Apr 2 2005, 01:36 AM)
QUOTE(marcan @ Apr 1 2005, 11:44 PM)
QUOTE(bryant @ Apr 1 2005, 03:14 PM)
That will do it. Depending on your application you might want to divide by 2 after to avoid clipping (although floating audio won't clip, when it gets truncated to 24-bit it might).
*


Thx bryant.

It will be converted into mp3. However the level of both source files are tuned in order to not clip when they are both mixed at 0 db (no gain, no attenuation).
In that case I should avoid cliping during the playback...
*



Ive come across a theoretical problem with this though:

Imagine two tracks both of a pure sine note at same freq and volume, but recorded at different times. If you add these two tracks together -sample by sample, the resulting mix will just as likely be silent as be twice as loud as either of the source tracks (!) its most likely to be around the same loudness as either of them - depending on the wether the phase of the signals in each track happen to reinforce, oppose each other, or just move each other over a bit.

I dont know how this fundamental observation manifests itself in practice, maybe mixing like this can produce flanging and strange loudness wobbling ?
It should be better off if they are dissimilar like one track of drums and other vocal.
There may be some techniques used to combat wobbling artifacts - like.... ~time dithering or something... Some mixing techniques could manipulate frequency spectrums...

It would be about the best way of forcing two signals into one. In the real world energy makes sure it is mantained when brought together, but in this virtual analogue it can easily dissappear without a trace ohmy.gif
*



An anlogue mixer does in the analogue world exactly what is proposed digitally here - it sums the volumes. If each track is adjusted to -3dB then the result will not exceed 0dB (i.e. it'll be correctand un-clipped). Also, in analogue mixing there could be "wobbling" i.e. interference, so the digital summing is still correct. Drums/vocals/etc makes no difference, the potential for frequencies to exist is still there. The only problem I can see is inherent in MP3 encoding, there MIGHT be problems in the encoding that analogue summing followed by encoding wouldn't have caused.

I'll stand corrected if anyone can show me a reason, but I don't see a problem in the theory...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.