[Speex-dev] mixing N sounds together...

Jean-Marc Valin
Fri, 06 Aug 2004 15:02:08 -0000

> I want to mix N samples of 20ms  into one sample of 20ms...is the
> algorithm above exact? :

First, note that there's no definition of "exact" for that.
It's mainly
a matter of what you want to do. I assume what you want to know is
whether it's "right" to divide by N. I'd say that you have 3
choices
here:

1) not to divide. This means that each voice (assuming it's speech) in
the output will be as "loud" as in was in the input. The drawback is
that you need to be careful not to cause saturation

2) divide by N. This means that the voices won't be as loud in the final
signal. Even the total energy (loudness) will be smaller in the final
result than in any input. For example, when mixing 10 voices at 0 dB,
each voice will be reduced by -20dB and even the mixed output will be at
-10dB. Of course, the advantage is that you're certain never to have
saturation

3) divide by sqrt(N). This means that the output energy will be similar
to the input energy of each signal. Saturation is less likely (though
not impossible) and each voice is only slightly reduced when mixing.

Last thing, instead of dividing by N (or sqrt(N) ), you'd probably want
to pre-compute 1.0/N and then multiply.

Jean-Marc

> short inputsamples[160][N];
> short outputsample[160];
> int i,j;
> for(i=0;i<160;++i){
>     outputsample[i] = 0;
>     for(j=0;j<N;++j){
>         outputsample[i]  +=  inputsample[i][j];
>     }
>     outputsample[i] /= N;
> }
>
> _______________________________________________
> Speex-dev mailing list
> Speex-dev@xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev
--
Jean-Marc Valin
http://www.xiph.org/~jm/
LABORIUS
Universit? de Sherbrooke, Qu?bec, Canada
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Ceci est une partie de message
=?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e=2E?Url :