Tanyatep Tothong / Mbed 2 deprecated Scat

Dependencies:   SDFileSystem VS1053 mbed

Fork of VS1053Player by Sonthaya Boonchan

Committer:
jackcom
Date:
Sat Dec 03 22:30:43 2016 +0000
Revision:
1:f7477dd40643
Parent:
0:610f985fb40a
Child:
2:163a628206c5
V.0.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
silis 0:610f985fb40a 1 #include "mbed.h"
silis 0:610f985fb40a 2 #include <VS1053.h>
jackcom 1:f7477dd40643 3 #include"SDFileSystem.h"
jackcom 1:f7477dd40643 4
jackcom 1:f7477dd40643 5 VS1053 player(D11, D12, D13, D6, D7, D2, D8);//mosi,miso,sclk,xcs,xdcs,dreq,xreset
jackcom 1:f7477dd40643 6
jackcom 1:f7477dd40643 7 SDFileSystem sd(D11, D12, D13, D9, "sd"); // the pinout on the mbed Cool
jackcom 1:f7477dd40643 8
jackcom 1:f7477dd40643 9 static unsigned char fileBuf[1024];
jackcom 1:f7477dd40643 10 unsigned char *bufptr;
silis 0:610f985fb40a 11
silis 0:610f985fb40a 12
jackcom 1:f7477dd40643 13 void playFile(char *file) {
jackcom 1:f7477dd40643 14 int bytes; // How many bytes in buffer left
jackcom 1:f7477dd40643 15
jackcom 1:f7477dd40643 16 printf("Current file is %s\n",file);
jackcom 1:f7477dd40643 17
jackcom 1:f7477dd40643 18 FileHandle *fp =sd.open(file, O_RDONLY);
jackcom 1:f7477dd40643 19
jackcom 1:f7477dd40643 20 if(fp == NULL) {
jackcom 1:f7477dd40643 21 printf("Could not open %s\r\n",file);
jackcom 1:f7477dd40643 22 }
jackcom 1:f7477dd40643 23 else
jackcom 1:f7477dd40643 24 {
jackcom 1:f7477dd40643 25 printf("Playing %s ...\r\n",file);
jackcom 1:f7477dd40643 26
jackcom 1:f7477dd40643 27 /* Main playback loop */
jackcom 1:f7477dd40643 28 while((bytes = fp->read(fileBuf,1)) > 0)
jackcom 1:f7477dd40643 29 {
jackcom 1:f7477dd40643 30 bufptr = fileBuf;
jackcom 1:f7477dd40643 31 player.sendDataBlock(bufptr, bytes);
jackcom 1:f7477dd40643 32 }
jackcom 1:f7477dd40643 33 }
jackcom 1:f7477dd40643 34 }
jackcom 1:f7477dd40643 35
silis 0:610f985fb40a 36 Serial com(USBTX, USBRX); //Initiallize the Serial Port 0 (9600 bits/sec)
silis 0:610f985fb40a 37
silis 0:610f985fb40a 38 int main() {
silis 0:610f985fb40a 39 com.printf("VS1053 Hello World\n");
silis 0:610f985fb40a 40 player.hardwareReset(); //Make a reset to the VS1053 board
silis 0:610f985fb40a 41 player.modeSwitch(); //Patch the VS1054 board to play MP3 files (very important!).
silis 0:610f985fb40a 42 while(1) { //Do that loop forever
jackcom 1:f7477dd40643 43 playFile("track001.mp3");wait(1);
jackcom 1:f7477dd40643 44 playFile("track002.mp3");wait(1);
jackcom 1:f7477dd40643 45 playFile("track003.mp3");wait(1);
jackcom 1:f7477dd40643 46 playFile("track004.mp3");wait(1);
jackcom 1:f7477dd40643 47 playFile("track005.mp3");wait(1);
jackcom 1:f7477dd40643 48 playFile("track006.mp3");wait(1);
jackcom 1:f7477dd40643 49 playFile("track007.mp3");wait(1);
jackcom 1:f7477dd40643 50 playFile("track008.mp3");wait(1);
silis 0:610f985fb40a 51 }
silis 0:610f985fb40a 52 }