Electronic – Mixing audio in a microprocessor

audioembeddedmicrocontroller

I need to do a project where I mix up to 8 to 10 audio channels together to play through a speaker. This needs to be done on a low cost microcontroller such as an ARM cortex M0 and I am thinking about how to do it.

The audio will be placed in an SPI FLASH memory chip in raw mono format (bit depth should 12-16).

The only way I can see to do it is to add the samples together – but for this I need a much higher dynamic range than 16 bits. So I think I would need a 24 bit DAC.

Is there anything else I am missing? Any other ways to mix audio or to do it without an expensive DAC? Is it even achievable?

Best Answer

Adding 8 samples together only requires 3 extra bits.

After adding the samples together to get the mixed signal, divide by the number of samples. That is always guaranteed to fit into the original word width, although the sum needs to be wider. Specifically, the accumulator needs Log2(samples) more bits than each of the samples. Note that dividing by 2N is just shifting right by N bits. To get the average of 8 samples, add them up, then shift the result right 3 bits.

This kind of arithmetic is what DSPs are intended for. They have accumulators you can add into that are wider than regular data words. They also generally can shift the result a arbitrary number of bits in a single instruction cycle.

You said your original samples might be only 12 bits. In that case, you can add up to 16 of them without overflowing a 16 bit word. That might be good enough for your purposes.

Related Topic