|
Multichannel SD Audio Mixing
Making a MOD player without much RAM.
|
TRAXMOD K9spud.com |
| TRAXMOD |
|
Main Page Support Forum |
By Edward Schlunder / K9spud LLC
April 1st, 2008
Introduction
Previously, in our SD Caching Methodology paper, we described a system of caching 64 byte blocks of SD card data in RAM in order to achieve playback of multichannel digital audio from an SD Card. While that method does work, it hits some major scaling limitations when trying to play multichannel audio beyond 4 or 8 channels. Because each channel requires two 64 byte RAM buffers, RAM becomes prohibitively tight:
| Channels | RAM Required |
| 4 | 512 |
| 8 | 1024 |
| 12 | 1536 |
| 16 | 2048 |
| 20 | 2560 |
| 24 | 3072 |
| 28 | 3584 |
| 32 | 4096 |
MMC/SD Card Theoretical Limits
Let's take a step back and look at the theoretical limits of the SD Card. If audio was perfectly interleved and contiguously placed on the SD Card, how many channels of audio could we possibly stream off of the SD Card? SD Cards accept a maximum clock rate of 25MHz, and using SPI, it takes a minimum of 16 clocks to retrieve each 16-bit sample.
While MOD files do not have perfectly interleaved audio data, they do have vastly less demanding samples to mix. A typical MOD file is 4 channels of audio, sampled at around 8KHz, with only 8 bits of resolution. Going by these numbers, it seems reasonable to assume that an SD Card should easily play a MOD file with audio data being streamed off of the SD Card.
Mixing Algorithm
Instead of keeping two 64 byte RAM buffers for each audio channel, let's use only two 512 byte RAM buffers total, no matter how many audio channels we have. 512 bytes is chosen because that is the default block size used for SD Cards, and it will be a required block size for future SDHC Cards that need to address more than 4GB of space.
Basically, we want the SD Card to be loading sample data for a channel into one of the two 512 byte RAM buffers, while the other RAM buffer is being mixed into the output audio. When the SD Card finishes reading, the SD Card will read another channel's sample data into the other 512 byte RAM buffer and the recently loaded RAM buffer will be mixed into the output audio.
It gets complicated because each channel will mix a different length of data into the output audio depending on the frequency of the note that the channel is playing.