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:

http://static.commentcamarche.net/en.kioskea.net/pictures/4eSBzlz1-auda-7-s-.png

The following image shows our full setup:

http://i.imgur.com/HFr8ra4.jpg

Following is the video of a working Music Player:

Components

  • MBED
  • Text LCD
  • Speaker
  • SD Card
  • Pushbuttons

Circuit

Speaker PinMbed Pin
+vep18
-veVU
SD Card PinMbed Pin
CSp8
DIp5
VCCVOUT
SCKP7
GNDGND
DOp6
CDp17
PushbuttonsMbed Pin
Stopp27
Songs Upp28
Songs Downp29
Playp30
LCD PinMbed Pin
VSSGND
VDDVU
VEGND
Register Selectp9
Read/WriteGND
Enablep10
Data 4p11
Data 5p12
Data 6p13
Data 7p14

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:

05 Aug 2015

can change the mbed pindetect code to joystick mode?

09 Aug 2015

Just change the interrupt PinDetect to appropriate of joystick pin =) for example joystick p14 is fire then just change it... hope this help u

11 Aug 2016

i tried the same code but the sound is played slow and distorted. Has anyone any idea why?

09 Mar 2018

a completely free app which provides you several things in one place. it's quite interesting to go online to watch live TV and play the online game through Live Tv Kodi Add-ons. its all about the entertainment world from you can have a colorful and beautiful experience. https://crumbles.co/live-tv-kodi-addons/

Please log in to post comments.