Arduino DUE DAC.. panning between the 2 DAC channels..

Hi y'all. :stuck_out_tongue_closed_eyes:

I am currently half way through an audio project using the DIGIX, a 3.2" TFT and some Sharp IR sensors.
I am usiing Gaith's Groovuino library to play wav files from an SD card.
I am using both DAC channels to output 4 wav files which are turned on or off by button presses on the TFT touchscreen.

I'm trying to work out how to pan wav data from one DAC channel to the other.. Currently I have wav 1 and wav 2 coming out of DAC channel 0 and wavs 3 and 4 coming out of DAC channel 1.
COuld anyone help me with how I would implement panning of the wavs from DAC channel 0 to DAC channel 1 and vice versa ?

Any help appreciated .
Thanks again.
Steve.S.

I don't know the details of how to do it, but in concept it's easy. (I've never done any DSP or audio programming on the Arduino, and I've never had my hands on a DUE.)

Some basic DSP... If you want to adjust the volume, you multiply the data sample-by-sample. i.e. If you want to cut the amplitude in half (-6dB) you multiply all of the samples by 0.5.

If you want to pan to the left, you simply increase the level of the samples going to the left and reduce the levels going to the right. For the sound to be centered, of course send the same data to the left & right DACs.

It gets a little tricky if you want to do "constant power panning". That is, if you want to move from left to right while keeping constant volume, you'll have to convert to decibels. i.e. -3dB is half-power, so as you move from hard-left to center the volume in both channels needs to be reduced by 3dB in both channels for the same power as one channel alone.

Mixing is done by summation. In fact, analog mxers are built around summing amplifiers. If you want to mix two WAVs together, you simply add the two sample-sets together sample-by-sample. i.e Add the 1st sample of each file, the 2nd sample of each file, etc.

One more tricky thing... DACs are integer devices and you should prevent clipping (or worse, "rollover"). That means when you sum two or more audio streams, you need scale-down the volume before (or after) summing. If you want to mix two signals at equal volumes, you typically reduce the level in half before mixing. So in-effect, you are averaging, rather than than simply summing the streams.

Of course, there is no rule that says you have to mix equally but there is a rule that you should never exceed the bit-depth of your DAC. And, if you do exceed the bit depth, it's important that you clip (maximize) rather than roll-over and simply loose the most-significant bit(s).

And of course, before you mix all of the files must have the same sample-rate and the same bit-depth.

Most "real DSP" is done in 32-bit or 64-bit floating-point, so you don't have to worry about exceeding the bit-depth 'till you render to an integer format or or "play" the sound through a DAC, but in this case that shouldn't be necessary.