Go Down

Topic: audio crossfade (Read 1 time) previous topic - next topic


Hi everyone!

Quick question - can audio crossfading between two tracks done with one audio shield? otherwise, is it possible to use two in a stack and command arduino to gradually reduce volume on one and increase on another?

Idea is to continuously playing back audio changing tracks according to data drops/rises from sensors

Thanks very much!


I've never used an audio shield, but crossfading should be easy in software, as long as your software has access to the uncompressed (or decompressed) audio data.

Mixing is done by addition.   Sample one from file one is added to sample one from file two, sample two from file one is added to sample two from file two,  etc., etc..

Volume control is done by multiplication (or division).  For example, multiply every sample by two, and you've increased the volume by 6dB.   Divide by two (or multiply by 0.5) and you 've reduced the voolume by 6dB.

By reducing one set of samples while increasing the other, and adding them together, you are crossfading!

When mixing or boosting volume, you have to be careful not to exceed the maximum sample-value for the given bit-depth.   If you try to go higher than you can "count" with the given number of bits, you will get clipping (distortion).   This is not an issue with a normal crossfade, since one value goes down while the other goes up.

Go Up