Guide [EN]

Le forum de support du shield Tune, décodeurs MP3 DiY pour Arduino

Guide [EN]

Message non lude Laetitia » Ven 25 Juil 2014 19:01

Library for Tune - MP3 decoder shield

Turn your Arduino into an MP3 player !

This library allows playing MP3 files from the SD card of the Tune shield simply by telling their name.
It also simplifies volume, bass and treble setting, and MP3 tag searching.

Tune.h : Header file to be included in the sketch
Tune.cpp : Definition of the Tune object and the associated methods
/examples : Folder containing examples of use of the shield
- OperationalTest : tests writing/reading in the codec's registers and audio outputs
- RemoteMP3 : how to control your Tune with an IR remote
- TagDeuligne : playing an audio file and printing its MP3 tags on the Deuligne's LCD
- TagPrint : playing an audio file and printing its MP3 tags on the serial monitor

UPDATE : version 1.1 and following of the library is based on SdFat lib instead of IDE's SD library. You can find the latest version of SdFat here, or simply use the one included in the Tune library. You need to download it, install it and include it at the beginning of your sketch. The Tune library also includes newer versions of SPI.h and SPI.cpp.

- Initialization -

To use the Tune library, you first need to include it in your sketch :

Code: Tout sélectionner
#include <Tune.h>
#include <SdFat.h> // from 1.1 lib version

Then declare the Tune object from which you'll call the methods you need. For example :

Code: Tout sélectionner
Tune player;

Then, before every other manipulation, you need to initialize the shield with begin() :

Code: Tout sélectionner
void setup()

Note : begin() returns 1 if everything went OK and 0 if SD fails to initialize.

- Codec setting -

VS1011e datasheet to understand how the codec works.

Reads a register from the codec and return its current value as an unsigned int. Registers are called by their names or addresses, see datasheet p.28.

writeSCI(registerAddress, highbyte, lowbyte)
Writes two bytes in a register, starting by the highest one. It's also possible to make an int out of the two bytes and call writeSCI(registerAddress, data).

setBit(registerAddress, bitAddress)
Sets a bit to 1 in one of VS1011's registers. See Tune.h and datasheet for register and bit definition.

clearBit(registerAddress, bitAddress)
Sets a bit to 0 in one of VS1011's registers. See Tune.h and datasheet for register and bit definition.

Sends SDI data to the codec.

Read all the codec's registers and prints their current values in the serial monitor. You'll need to call Serial.begin() before.

Sine generator : generates a note at a given frequency during 2 seconds (1 KHz without parameter, otherwise see Tune.h for useful constants). Useful to test both audio output, as volume can be set separately for both channels (see below).

- File playing -

setVolume(leftChannel, rightChannel)
Sets the volume for left and right channels separately, from 0 to 254.
UPDATE : v1.2 sets volume while initializing the shield so you don't have to mind your ears ;)

Sets the volume for both channels with the same level (0 to 254).

Plays an MP3 file by passing its name as a parameter. trackName must not exceed 8 characters + the .mp3 extension, for example :

Code: Tout sélectionner"TuneFile.mp3"); // 8 characters"Song.mp3"); // 4 characters, valid too

Plays an MP3 file which name is "trackXXX.mp3", where XXX is a number between 0 and 999. You just have to specify the number of the track :

Code: Tout sélectionner
player.playTrack(5); // plays file track005.mp3

playPlaylist(start, end)
Plays a list of MP3 files which names are "trackXXX.mp3", just like above. You simply indicate the start and end number :

Code: Tout sélectionner
player.playPlaylist(0,5); // plays from track000.mp3 to track005.mp3

Note that the playlist can only stop once every selected track has been played.

Plays next available file on the SD card.

Plays previous available file on the SD card.

setBass(bassAmp, bassFreq)
Amplifies basses : frequencies below bassFreq (2 to 15, 10 Hz steps) will be amplified by bassAmp (0 to 15 dB).

Code: Tout sélectionner
player.setBass(10, 8); // enhances 8 dB basses below 100 Hz

setTreble(trebAmp, trebFreq)
Sets the treble : frequencies above trebFreq (0 to 15 KHz) will be amplified by trebAmp (-8 to 7, 1.5 dB steps).

Code: Tout sélectionner
player.setTreble(3, 12); // enhances 4.5 dB treble above 12 KHz

Pauses current playing.

Resumes current playing.

Stops current track, closes the file and allows playing next one. Returns 1 for success and 0 if file closure failed.

- MP3 tags -

NOTE : reading an MP3 tag can be longer than expected. On ID3v2 tags (see here for more info on MP3 tags), searching time can delay playback. Use at your own risk !

getTrackInfo(frame, infobuffer)
Gets an MP3 tag from the currently playing track, indicating the frame needed (TITLE, ARTIST or ALBUM) and an array (char) to store search result. See examples "TagPrint" and "TagDeuligne" included in the /examples folder to learn how to send them, respectively, to the serial monitor or the Deuligne shield.

Gets the "title" tag frame from the currently playing track, indicating an array to store it.

Gets the "artist" tag frame from the currently playing track, indicating an array to store it.

Gets the "album" tag frame from the currently playing track, indicating an array to store it.
"If it's itchy, scratch it !" - "DIY or die"

RTFM (À lire avant de poster) - ANDb (Arduino Noob Database)
Avatar de l’utilisateur
Messages: 296
Inscription: Mar 7 Aoû 2012 15:07
Localisation: Toulouse

Retourner vers Tune

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité