lecteur mp3
Dependencies: MPR121 SDFileSystem TextLCD VS1053lib mbed
Fork of MP3_test by
Diff: mp3.cpp
- Revision:
- 0:acb04070ad91
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mp3.cpp Wed Sep 28 18:10:24 2016 +0000 @@ -0,0 +1,79 @@ +//******************************** +// version 27/09/16 +// G.Raynaud +//******************************** +#include "mbed.h" +#include "TextLCD.h" +#include "SDFileSystem.h" +#include <VLSIcodec.h> + +#define BUFFER_SIZE 2048 + +Serial com(USBTX, USBRX); //Initiallize the Serial Port 0 (9600 bits/sec) +unsigned char buff[BUFFER_SIZE]; +// codec +VS1053Codec codec(p11, p12, p13, p14, p16, p15, p17); // mosi, miso, sck, cs, dreq, rst, bsync +// I2C Communication +I2C i2c_lcd(p28, p27 ); // SCL, SDA +// LCD +TextLCD_I2C lcd(&i2c_lcd, 0x40, TextLCD::LCD16x2); // I2C bus, PCF8574 Slaveaddress, LCD Type +// SD card +SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs the pinout on the mbed Cool Components workshop board + +int main() +{ + char ligne[17]; + lcd.cls(); + lcd.setBacklight(TextLCD::LightOff); + wait(1); + lcd.printf(" "); + lcd.cls(); + lcd.setBacklight(TextLCD::LightOn); + lcd.setCursor(TextLCD::CurOff_BlkOff); + mkdir("/sd/mydir", 0777); + FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + fprintf(fp, "IUT---MP3"); + fclose(fp); + fp = fopen("/sd/mydir/sdtest.txt", "r"); + fscanf(fp,"%s",ligne); + lcd.printf(ligne); + fclose(fp); + + + wait(1); + // + codec.init(); // initialise le codec + codec.loadpatch(); // charge le patch (rev 1.5) + codec.setbassboost( 15, 150); // basse + codec.settrebleboost( 7, 15000); // aigue + codec.setvolume( 0x10, 0x10); // volume + + + FILE *song = fopen("/sd/music/1.mp3", "r"); // ouverture fichier MP3 + codec.resetplaytime(); + int aff=0; + + while(1) { + + while(!feof(song)) { // tant que fichier non termine + + fread(buff, 1, BUFFER_SIZE, song); // lecture buffer + aff++; + if(aff%1==0){ + codec.getplaytime(ligne); + ligne[5]=NULL; + lcd.locate(2,1); + lcd.puts(ligne);} + int iSize=0; + while( iSize < BUFFER_SIZE) { + codec.testdreq(); + codec.writedata( buff[ iSize++]); + //if ( iSize > BUFFER_SIZE) + //break; + } + } + } +} \ No newline at end of file