MBED Music Player
For our ECE 4180 Lab 4, we chose option 3. We made a music player using MicroSD card, Speakers, Pushbuttons and a Text LCD Screen. This music player allows the user to stop/play a song, shift up or shift down to the next song in the SD card and it also allows user to control the volume of the song. These 4 functionality are acheived with the help of pushbuttons. The user can also see the current song being played on the LCD screen. The user can also scroll up or down the song and see the name of the other song in the SD card before playing it. The volume of the music player has been configured so it starts at the max volume, and then on pressing a pushbutton it slowly decreases until the volume reaches 0. Upon pressing the volume pushbutton again, the volume becomes maximum again.
Also, the original wave files were sampled at 80kbs 44Khz. They were then resampled using Audacity to make it sound better.
Changing the Sample Rate in Audacity
1) Click on the Edit Menu > Preferences
2) In the window that opens scroll to the "Quality" section
3) In the right pane next to "Defaul Sample Rate" choose a value:
The following image shows our full setup:
Following is the video of a working Music Player:
Components
- MBED
- Text LCD
- Speaker
- SD Card
- Pushbuttons
Circuit
Speaker Pin | Mbed Pin |
---|---|
+ve | p18 |
-ve | VU |
SD Card Pin | Mbed Pin |
---|---|
CS | p8 |
DI | p5 |
VCC | VOUT |
SCK | P7 |
GND | GND |
DO | p6 |
CD | p17 |
Pushbuttons | Mbed Pin |
---|---|
Stop | p27 |
Songs Up | p28 |
Songs Down | p29 |
Play | p30 |
LCD Pin | Mbed Pin |
---|---|
VSS | GND |
VDD | VU |
VE | GND |
Register Select | p9 |
Read/Write | GND |
Enable | p10 |
Data 4 | p11 |
Data 5 | p12 |
Data 6 | p13 |
Data 7 | p14 |
Program
Import programmusicplayer
This is a MBED music player.
Problems We Faced
The biggest problems we faced were in changing volume levels and in stopping the song. For stopping the song, in main.cpp a one line command plays the entire song using the wave player library and stops only after it has played the song. So, initially we were trying to stop the song from main.cpp but weren't much successful as it would either not play any song at all or will stop only after the song has finished. We later realized that we must change how the wave player library works and must stop the song from there. Once, we realized this, the problem was much easier to solve. We were able to pass a boolean (bool playing) from main.cpp to the wave player library. Based on this boolean value, during the loop where samples of the song is being played, a break statement is added, which stops the song.
Similarly, for volume as well we realized we must change the code in the wave player file to be able to make the change. We had to understand how volume works, and once we did it was much easier. The volume code has been explained below.
Code Explained
Volume Control
Volume in wave player is controlled by the following line:
DAC_fifo[DAC_wptr]= dac_data;
To add 16 levels of volume, we divided the dac_data by 16 by right shifting dac_data by 4. Then, we multiplied dac_data by a volume variable. This volume variable is initialized in the main.cpp file and is controlled by a pushbutton. When, the pushbutton is pressed, the value of this variable increases by 1, until it reaches 16. At reaching 16, it resets back to 0. This variable is then, used in the wave player file, to set which 16th level of volume needs to be played. These changes can be shown by the following code:
DAC_fifo[DAC_wptr]=((16-vol)* dac_data)>>4;
In the code, we used 16-vol instead of just using vol. This is because in our program, vol = 0, means highest volume. That is, the default volume of our music player is the full volume. Then, pressing the push button decreases the volume till it reaches 0, and then it goes back to the highest volume again. Thus, we do 16- vol, rather than just vol.
4 comments on MBED Music Player:
Please log in to post comments.
can change the mbed pindetect code to joystick mode?