DSPRelated.com
Forums

Mixing of multiple audio files

Started by MyMo...@gmail.com December 16, 2008
Hi everyone,

I am new to the field of audio programming and gave myself some tasks to bring myself up to speed. The first task is programming a (simple) DAW, that can mix several channels of audio.

I would like to get some opinions if my approach is somewhat ok. this is what I do:

1. defined audio buffer
2. for each WORD in the audio buffer I loop through all my channels and get the WORD value. I convert each WORD in float and add build a sum over all channels. At the end I divide the sum by the number of channels. the result is the WORD in the output buffer. I repead this for each WORD in the buffer.

Is this a good/bad approach ? Are there better and more accurate approaches to do so ? What about speed ? Is converting int (16 bit audio) to float slow ? Should I use rather Fixed Point ?

Thanks for helping me getting up to speed.

Mozzak

P.S. If you can also point me to good article regarding this topic would be great.
On Mon, 15 Dec 2008, M...@gmail.com wrote:

> I would like to get some opinions if my approach is somewhat ok. this is what I do:

> 1. defined audio buffer
> 2. for each WORD in the audio buffer I loop through all my channels and
> get the WORD value. I convert each WORD in float and add build a sum
> over all channels. At the end I divide the sum by the number of
> channels. the result is the WORD in the output buffer. I repead this
> for each WORD in the buffer.

> Is this a good/bad approach?

Good, except of using floats.

> Are there better and more accurate approaches to do so?

Yes. Use a longword (signed 32-bit), it is 'int32_t' in standard
conforming C compilers. This way you will avoid conversion and
accumulation errors of floats. It allows you to mixdown up to 65536
channels. Then you divide by number of channels, the same as for
floats. If you have a number of channels, which is a power of two, you can
replace division by right-bit-shifting, which is significantly faster.

> What about speed?

Integer mixing is much faster. Integer addition is faster than floating
point one. You also avoid int->float and float->int conversion, which is
time consuming.

--
Grzegorz Kraszewski
http://teleinfo.pb.edu.pl/~krashan
Lately, i'd achived the function of mix voice/sound.In fact,the values coming a number of channels are added, and then you saturate the result of addition to short. Provided you use division or shift-bit-right, the volume can turn lower.


2008-12-17 05:27:17"Grzegorz Kraszewski" ะด
On Mon, 15 Dec 2008, M...@gmail.com wrote:

> I would like to get some opinions if my approach is somewhat ok. this is what I do:

> 1. defined audio buffer
> 2. for each WORD in the audio buffer I loop through all my channels and
> get the WORD value. I convert each WORD in float and add build a sum
> over all channels. At the end I divide the sum by the number of
> channels. the result is the WORD in the output buffer. I repead this
> for each WORD in the buffer.

> Is this a good/bad approach?

Good, except of using floats.

> Are there better and more accurate approaches to do so?

Yes. Use a longword (signed 32-bit), it is 'int32_t' in standard
conforming C compilers. This way you will avoid conversion and
accumulation errors of floats. It allows you to mixdown up to 65536
channels. Then you divide by number of channels, the same as for
floats. If you have a number of channels, which is a power of two, you can
replace division by right-bit-shifting, which is significantly faster.

> What about speed?

Integer mixing is much faster. Integer addition is faster than floating
point one. You also avoid int->float and float->int conversion, which is
time consuming.