Décodeur MP3 de test monofichier
Dependencies: SDFileSystem TextLCD VS1053lib mbed MPR121
Fork of MP3_test by
mp3.cpp@0:acb04070ad91, 2016-09-28 (annotated)
- Committer:
- gr66
- Date:
- Wed Sep 28 18:10:24 2016 +0000
- Revision:
- 0:acb04070ad91
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gr66 | 0:acb04070ad91 | 1 | //******************************** |
gr66 | 0:acb04070ad91 | 2 | // version 27/09/16 |
gr66 | 0:acb04070ad91 | 3 | // G.Raynaud |
gr66 | 0:acb04070ad91 | 4 | //******************************** |
gr66 | 0:acb04070ad91 | 5 | #include "mbed.h" |
gr66 | 0:acb04070ad91 | 6 | #include "TextLCD.h" |
gr66 | 0:acb04070ad91 | 7 | #include "SDFileSystem.h" |
gr66 | 0:acb04070ad91 | 8 | #include <VLSIcodec.h> |
gr66 | 0:acb04070ad91 | 9 | |
gr66 | 0:acb04070ad91 | 10 | #define BUFFER_SIZE 2048 |
gr66 | 0:acb04070ad91 | 11 | |
gr66 | 0:acb04070ad91 | 12 | Serial com(USBTX, USBRX); //Initiallize the Serial Port 0 (9600 bits/sec) |
gr66 | 0:acb04070ad91 | 13 | unsigned char buff[BUFFER_SIZE]; |
gr66 | 0:acb04070ad91 | 14 | // codec |
gr66 | 0:acb04070ad91 | 15 | VS1053Codec codec(p11, p12, p13, p14, p16, p15, p17); // mosi, miso, sck, cs, dreq, rst, bsync |
gr66 | 0:acb04070ad91 | 16 | // I2C Communication |
gr66 | 0:acb04070ad91 | 17 | I2C i2c_lcd(p28, p27 ); // SCL, SDA |
gr66 | 0:acb04070ad91 | 18 | // LCD |
gr66 | 0:acb04070ad91 | 19 | TextLCD_I2C lcd(&i2c_lcd, 0x40, TextLCD::LCD16x2); // I2C bus, PCF8574 Slaveaddress, LCD Type |
gr66 | 0:acb04070ad91 | 20 | // SD card |
gr66 | 0:acb04070ad91 | 21 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs the pinout on the mbed Cool Components workshop board |
gr66 | 0:acb04070ad91 | 22 | |
gr66 | 0:acb04070ad91 | 23 | int main() |
gr66 | 0:acb04070ad91 | 24 | { |
gr66 | 0:acb04070ad91 | 25 | char ligne[17]; |
gr66 | 0:acb04070ad91 | 26 | lcd.cls(); |
gr66 | 0:acb04070ad91 | 27 | lcd.setBacklight(TextLCD::LightOff); |
gr66 | 0:acb04070ad91 | 28 | wait(1); |
gr66 | 0:acb04070ad91 | 29 | lcd.printf(" "); |
gr66 | 0:acb04070ad91 | 30 | lcd.cls(); |
gr66 | 0:acb04070ad91 | 31 | lcd.setBacklight(TextLCD::LightOn); |
gr66 | 0:acb04070ad91 | 32 | lcd.setCursor(TextLCD::CurOff_BlkOff); |
gr66 | 0:acb04070ad91 | 33 | mkdir("/sd/mydir", 0777); |
gr66 | 0:acb04070ad91 | 34 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
gr66 | 0:acb04070ad91 | 35 | if(fp == NULL) { |
gr66 | 0:acb04070ad91 | 36 | error("Could not open file for write\n"); |
gr66 | 0:acb04070ad91 | 37 | } |
gr66 | 0:acb04070ad91 | 38 | fprintf(fp, "IUT---MP3"); |
gr66 | 0:acb04070ad91 | 39 | fclose(fp); |
gr66 | 0:acb04070ad91 | 40 | fp = fopen("/sd/mydir/sdtest.txt", "r"); |
gr66 | 0:acb04070ad91 | 41 | fscanf(fp,"%s",ligne); |
gr66 | 0:acb04070ad91 | 42 | lcd.printf(ligne); |
gr66 | 0:acb04070ad91 | 43 | fclose(fp); |
gr66 | 0:acb04070ad91 | 44 | |
gr66 | 0:acb04070ad91 | 45 | |
gr66 | 0:acb04070ad91 | 46 | wait(1); |
gr66 | 0:acb04070ad91 | 47 | // |
gr66 | 0:acb04070ad91 | 48 | codec.init(); // initialise le codec |
gr66 | 0:acb04070ad91 | 49 | codec.loadpatch(); // charge le patch (rev 1.5) |
gr66 | 0:acb04070ad91 | 50 | codec.setbassboost( 15, 150); // basse |
gr66 | 0:acb04070ad91 | 51 | codec.settrebleboost( 7, 15000); // aigue |
gr66 | 0:acb04070ad91 | 52 | codec.setvolume( 0x10, 0x10); // volume |
gr66 | 0:acb04070ad91 | 53 | |
gr66 | 0:acb04070ad91 | 54 | |
gr66 | 0:acb04070ad91 | 55 | FILE *song = fopen("/sd/music/1.mp3", "r"); // ouverture fichier MP3 |
gr66 | 0:acb04070ad91 | 56 | codec.resetplaytime(); |
gr66 | 0:acb04070ad91 | 57 | int aff=0; |
gr66 | 0:acb04070ad91 | 58 | |
gr66 | 0:acb04070ad91 | 59 | while(1) { |
gr66 | 0:acb04070ad91 | 60 | |
gr66 | 0:acb04070ad91 | 61 | while(!feof(song)) { // tant que fichier non termine |
gr66 | 0:acb04070ad91 | 62 | |
gr66 | 0:acb04070ad91 | 63 | fread(buff, 1, BUFFER_SIZE, song); // lecture buffer |
gr66 | 0:acb04070ad91 | 64 | aff++; |
gr66 | 0:acb04070ad91 | 65 | if(aff%1==0){ |
gr66 | 0:acb04070ad91 | 66 | codec.getplaytime(ligne); |
gr66 | 0:acb04070ad91 | 67 | ligne[5]=NULL; |
gr66 | 0:acb04070ad91 | 68 | lcd.locate(2,1); |
gr66 | 0:acb04070ad91 | 69 | lcd.puts(ligne);} |
gr66 | 0:acb04070ad91 | 70 | int iSize=0; |
gr66 | 0:acb04070ad91 | 71 | while( iSize < BUFFER_SIZE) { |
gr66 | 0:acb04070ad91 | 72 | codec.testdreq(); |
gr66 | 0:acb04070ad91 | 73 | codec.writedata( buff[ iSize++]); |
gr66 | 0:acb04070ad91 | 74 | //if ( iSize > BUFFER_SIZE) |
gr66 | 0:acb04070ad91 | 75 | //break; |
gr66 | 0:acb04070ad91 | 76 | } |
gr66 | 0:acb04070ad91 | 77 | } |
gr66 | 0:acb04070ad91 | 78 | } |
gr66 | 0:acb04070ad91 | 79 | } |