.
Fork of VS1053 by
player.cpp@1:ab6777568920, 2016-12-05 (annotated)
- Committer:
- PloyLL
- Date:
- Mon Dec 05 10:36:24 2016 +0000
- Revision:
- 1:ab6777568920
- Parent:
- 0:58524d569dfd
- Child:
- 2:787946147566
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cha45689 | 0:58524d569dfd | 1 | #include "player.h" |
cha45689 | 0:58524d569dfd | 2 | #include"SDFileSystem.h" |
PloyLL | 1:ab6777568920 | 3 | #include<string.h> |
cha45689 | 0:58524d569dfd | 4 | |
cha45689 | 0:58524d569dfd | 5 | SDFileSystem sd(D11, D12, D13, D9, "sd"); // the pinout on the mbed Cool |
cha45689 | 0:58524d569dfd | 6 | vs10xx vs1053(D11, D12, D13, D6, D7, D2, D8);//mosi,miso,sclk,xcs,xdcs,dreq,xreset |
cha45689 | 0:58524d569dfd | 7 | Serial pc(USBTX, USBRX); |
cha45689 | 0:58524d569dfd | 8 | playerStatetype playerState; |
cha45689 | 0:58524d569dfd | 9 | ctrlStatetype ctrlState; |
cha45689 | 0:58524d569dfd | 10 | static unsigned char fileBuf[1024]; |
cha45689 | 0:58524d569dfd | 11 | unsigned char *bufptr; |
cha45689 | 0:58524d569dfd | 12 | |
cha45689 | 0:58524d569dfd | 13 | /* This function plays back an audio file. */ |
PloyLL | 1:ab6777568920 | 14 | void Player::playFile(char *file){ |
cha45689 | 0:58524d569dfd | 15 | int bytes; // How many bytes in buffer left |
cha45689 | 0:58524d569dfd | 16 | char n; |
PloyLL | 1:ab6777568920 | 17 | |
cha45689 | 0:58524d569dfd | 18 | playerState = PS_PLAY; |
cha45689 | 0:58524d569dfd | 19 | vs1053.setFreq(24000000); //hight speed |
PloyLL | 1:ab6777568920 | 20 | |
cha45689 | 0:58524d569dfd | 21 | FileHandle *fp =sd.open(file, O_RDONLY); |
PloyLL | 1:ab6777568920 | 22 | if(fp == NULL){ |
cha45689 | 0:58524d569dfd | 23 | printf("Could not open %s\r\n",file); |
cha45689 | 0:58524d569dfd | 24 | |
PloyLL | 1:ab6777568920 | 25 | }else{ |
cha45689 | 0:58524d569dfd | 26 | printf("Playing %s ...\r\n",file); |
PloyLL | 1:ab6777568920 | 27 | |
cha45689 | 0:58524d569dfd | 28 | /* Main playback loop */ |
PloyLL | 1:ab6777568920 | 29 | while((bytes = fp->read(fileBuf,512)) > 0) { |
cha45689 | 0:58524d569dfd | 30 | bufptr = fileBuf; |
cha45689 | 0:58524d569dfd | 31 | // actual audio data gets sent to VS10xx. |
PloyLL | 1:ab6777568920 | 32 | //pc.printf("now: playing\n"); |
PloyLL | 1:ab6777568920 | 33 | while(bytes > 0) { |
PloyLL | 1:ab6777568920 | 34 | n = (bytes < 32)?bytes:32; |
cha45689 | 0:58524d569dfd | 35 | vs1053.writeData(bufptr,n); |
cha45689 | 0:58524d569dfd | 36 | bytes -= n; |
cha45689 | 0:58524d569dfd | 37 | bufptr += n; |
PloyLL | 1:ab6777568920 | 38 | if(playerState == PS_STOP) break; |
PloyLL | 1:ab6777568920 | 39 | //pc.printf("now: bype>0\n"); |
cha45689 | 0:58524d569dfd | 40 | } |
PloyLL | 1:ab6777568920 | 41 | if(playerState == PS_STOP) break; |
cha45689 | 0:58524d569dfd | 42 | } |
cha45689 | 0:58524d569dfd | 43 | fp->close(); |
PloyLL | 1:ab6777568920 | 44 | vs1053.softReset(); |
cha45689 | 0:58524d569dfd | 45 | printf("[done!]\r\n"); |
cha45689 | 0:58524d569dfd | 46 | } |
cha45689 | 0:58524d569dfd | 47 | } |
cha45689 | 0:58524d569dfd | 48 | |
cha45689 | 0:58524d569dfd | 49 |