
MP3 players are very popular in today's technology market and come in many shapes and sizes. Using the MMC/SD card reader E-block EB037 it is possible to incorporate files straight into the microcontroller devices ready for streaming out to a pair of headphones or a loudspeaker. To save having to buy an expensive dedicated MP3 chip we will instead be using WAV files as they are uncompressed and easy to stream out via a DAC or PWM output. It would not be much of a push to forward the audio data onto an MP3 chip once the operation of the FAT16 code is understood. The FAT16 driver will only work with the PIC18 series and the ARM devices. AVR device support is on route.
The WAV files can be created using Windows Sound Recorder, Winamp, Audio Recorder for Free plus many other free audio software packages. The format we need is either an 8-bit @ 8khz mono for the PICmicro example or an 8-bit @16khz mono for the ARM example. The WAV files are then placed onto the MMC/SD ready for streaming.
Both the PICmicro and the ARM Flowcode examples employ a buffering scheme to allow the audio data to be streamed without causing ticks or glitches in the playback audio signal. The files are read from the memory card in chunks of 512 bytes called sectors. Two neighbouring sectors of the file may not be located one after another on the physical card memory so there is a small amount of time to seek out and read the next sector for the card. Don't worry this is all handled automatically by the Flowcode FAT16 driver. However it does mean that the previously mentioned buffering technique needs to be used to keep the audio streaming correctly. As each set of 512 bytes is loaded there is a timer interrupt that starts streaming out the data. While this is happening a section at the end of the 512 bytes is stored into a local array. This is done so that when the timer interrupt is nearing the end of the 512 bytes it can stream the audio from the local buffer while the FAT routine is moving and collecting the next file sector.

The audio output can be driven by using an 8-bit R2R Ladder DAC connected to one of the chips ports or by using a single PWM output as the speaker device will remove all of the high frequency noise created. Both the example files use the PWM method as this seems to be less susceptible to noise and it only uses one I/O pin instead of eight. To take the design further an audio amplifier chip can be used connected to the PWM output to push and pull the signal high and low with more power. The NJM2073D is a 2 Watt audio amplifier that can be purchased from Rapid for £0.79 order code 82-2154.

To get the examples working simply copy the custom_code.c file into your Flowcode/Components folder. For the ARM version you will also need to copy the FCD file into your Flowcode/FCD folder before running the Flowcode file.