mp3
Diff: player.cpp
- Revision:
- 4:5b1bd3cca8dc
- Parent:
- 3:94b538ace77a
- Child:
- 5:ce3a3ce60f30
--- a/player.cpp Sun Dec 10 07:14:12 2017 +0000 +++ b/player.cpp Mon Dec 11 12:29:47 2017 +0000 @@ -3,11 +3,14 @@ SDFileSystem sd(D11, D12, D13, D9, "sd"); // the pinout on the mbed Cool vs10xx vs1053(D11, D12, D13, D6, D7, D2, D8);//mosi,miso,sclk,xcs,xdcs,dreq,xreset -Serial pc(USBTX, USBRX); +Serial aa(USBTX, USBRX); +Serial pc(D1, D0); playerStatetype playerState; -static unsigned char fileBuf[32768]; +static unsigned char fileBuf[48000]; unsigned char *bufptr; char green; +bool startplaysong; +bool playsong; char list[20][50]; //song list @@ -22,7 +25,7 @@ vs1053.reset(); dir = opendir("/sd"); - printf("\r\n**********playing list**********\r\n"); + //printf("\r\n**********playing list**********\r\n"); unsigned char i = 0,j=0; while(((ptr = dir->readdir()) != NULL)&&(i <20)) { @@ -37,7 +40,7 @@ list[i][j++] = *byte++; green=i; } - pc.printf("%2d . %s\r\n", i,list[i++]); + aa.printf("%2d . %s\r\n", i,list[i++]); //fp->close(); } } @@ -47,14 +50,50 @@ + + +/* select file by num. */ +void Player::selectfile(char n){ + startplaysong=false; + playerState =PS_STOP; + playsong=false; + green = n; + } + + + +/* This function stop an audio file. */ void Player::stop(void){ + startplaysong=true; playerState =PS_STOP; } +void Player::run(void){ + if(pc.readable()){ + + char datainput; + + if(datainput=='1'){ + selectfile(1); + stop(); + } + if(datainput=='2'){ + selectfile(2); + stop(); + } + } +} + +void Player::read(void){ + pc.readable(); + + } + -/* This function plays back an audio file. */ + +/* This function plays audio file. */ void Player::playFile(char *file) { int bytes; // How many bytes in buffer left char n; @@ -74,8 +113,7 @@ printf("Playing %s ...\r\n",file); /* Main playback loop */ - while((bytes = fp->read(fileBuf,32768)) > 0) { - while((bytes = fp->read(fileBuf,32000)) > 0) { + while((bytes = fp->read(fileBuf,48000)) > 0) { { bufptr = fileBuf; // actual audio data gets sent to VS10xx. @@ -96,7 +134,6 @@ vs1053.softReset(); } - } } } }