MP3 Player

By Olga Nee and Alexandr Braverman.

Introduction

 

The purpose of our project is to implement MP3 player using LPC2148 microcontroller and SD card interface.

 

Software

 

1.    Open source Fixed-point MP3 decoder library, developed by RealNetworks.

 

https://helixcommunity.org/viewcvs/datatype/mp3/codec/fixpt/

 

The library supports:

            - layer 3

            - MPEG1, MPEG2, and MPEG2.5 (low sampling frequency extensions)

            - constant bitrate, variable bitrate, and free bitrate modes

- mono and all stereo modes (normal stereo, joint stereo, dual-mono)

 

We haven’t used the dynamic memory allocation, but we have a rather static memory assignment. So, we changed mp3_init() function and added header file in which we perform static memory allocations needed by the decoder.

When we tried to run the program on the board we faced the problem of lack of RAM memory. Static allocations we made exceeded the amount of RAM (32 kB) on LPC2148. So we decided to use additional 8 kB of USB RAM. To use it we enabled USB power/clock, so we can use USB RAM: PCONP |= 1 << 31. We allocated

                                                                                                                                

LPC2148 education board is equipped with 10 bit digital to analog converter.

The DAC is used as it is as audio output device. With this approach only a mono channel is supported. So, before storing mp3 file in the SD card, it is needed to convert it into the mono version. For this purpose we used Audacity, free open source software:

           

            http://audacity.sourceforge.net/

 

 

2.    EFSL library released under GPL. The library supports FAT12/16/32 reading and writing on SD-cards. EFSL source code is available at:

 

http://sourceforge.net/projects/efsl/

 

Our player can also play simple WAV files. The minimal WAV file contains two required chunks: format chunk and data chunk. There are more complex WAV formats. But while converting CD to WAV format, most of software supply simple WAV files.

 

 

 

 

 

 

 

 

Hardware

 

An amplifier was connected to DAC.

We used SanDisk microSD card with capacity of 2 GB. 

SD card works with SPI1. Here are jumper settings:

 

 

 

System Timing

 

CPU operating frequency generated from a 12 MHz crystal is 60 MHz.

So Timer0, which supplies music sampling frequency, runs with 60 MHz CPU clock.

 

 

 

 

 

 

 

 

 

How we used mp3 decoder

 

How we used the decoder:

To use the decoder library properly, we allocated a buffer SDBuff of size 8192 Bytes to read from mp3 file amount of bytes which is at least the size of mp3 frame. Each time beginning of frame is found in this buffer and is decoded by the decoder. The result of decoding is kept in buffer outBuf of size 2304 Bytes. The sample rate of the decoded frame is stored in mp3FrameInfo.samprate .

After that the rate of counter, which determines at which rate the pcm samples are placed in DAC, is set to mp3FrameInfo.samprate .  And the content of outBuf is sampled by render_sample_block() function in the following way: the pcm samples are stored in a buffer of size 1536 which is sampled by dac at given rate. If there is not enough space in that buffer, we wait in loop until the next sample in the buffer is sampled.

When the frame was successfully decoded we moved undecoded bytes which remained in SDBuff to the beginning of the SDBuff and read from mp3 file the amount of bytes needed to fill the SDBuff.