.

Fork of VS1053 by Chaiyaporn Boonyasathian

player.cpp

Committer:
PloyLL
Date:
2016-12-05
Revision:
1:ab6777568920
Parent:
0:58524d569dfd
Child:
2:787946147566

File content as of revision 1:ab6777568920:

#include "player.h"
#include"SDFileSystem.h"
#include<string.h>

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);
playerStatetype  playerState;
ctrlStatetype ctrlState;
static unsigned char fileBuf[1024];
unsigned char *bufptr;

/*  This function plays back an audio file.  */
void Player::playFile(char *file){
    int bytes;        // How many bytes in buffer left
    char n;

    playerState = PS_PLAY;
    vs1053.setFreq(24000000);     //hight speed
	
    FileHandle *fp =sd.open(file, O_RDONLY);
    if(fp == NULL){
        printf("Could not open %s\r\n",file);

    }else{
        printf("Playing %s ...\r\n",file);

        /* Main playback loop */
         while((bytes = fp->read(fileBuf,512)) > 0) {
            bufptr = fileBuf;
            // actual audio data gets sent to VS10xx.
            //pc.printf("now: playing\n");
            while(bytes > 0) {
                n = (bytes < 32)?bytes:32;
                vs1053.writeData(bufptr,n);
                bytes -= n;
                bufptr += n;
                if(playerState == PS_STOP) break;
				//pc.printf("now: bype>0\n");
            }
            if(playerState == PS_STOP) break;
        }
        fp->close();
        vs1053.softReset();
        printf("[done!]\r\n");
    }
}