mbeduino MP3 Sheild player MP3 player that runs on mebeduin with MP3 Shield. Regarding mbeduino, refer to: http://mbed.org/users/okini3939/notebook/mbeduino/ Regarding MP3 Shiled, refer to: http://www.sparkfun.com/commerce/product_info.php?products_id=9736
Dependencies: mbed SDFileSystem
main.cpp@1:c47269f0e9e1, 2010-10-16 (annotated)
- Committer:
- xshige
- Date:
- Sat Oct 16 05:14:59 2010 +0000
- Revision:
- 1:c47269f0e9e1
- Parent:
- 0:67cb2f650c15
2010/10/16 version: (1) Patch loading is supported. The patch is needed to make FLAC decoder work. (2)MP3,Ogg,MIDI,WMA,FLAC,AAC work correctly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xshige | 0:67cb2f650c15 | 1 | // |
xshige | 0:67cb2f650c15 | 2 | // mbeduino MP3 Shield Player |
xshige | 0:67cb2f650c15 | 3 | // |
xshige | 0:67cb2f650c15 | 4 | // Note: |
xshige | 0:67cb2f650c15 | 5 | // (1)Push reset button on the MP3 Sheild to reboot |
xshige | 0:67cb2f650c15 | 6 | // when this program does not work correctly. |
xshige | 0:67cb2f650c15 | 7 | // (2)Remenber the file system does not support long file/directory name. |
xshige | 1:c47269f0e9e1 | 8 | // (3)I have confirmed MP3,Ogg,MIDI,WMA,FLAC,AAC work correcly. (FLAC needs patch) |
xshige | 1:c47269f0e9e1 | 9 | // WAV needs data transfer(mbed to VS1053) optimized. |
xshige | 1:c47269f0e9e1 | 10 | // |
xshige | 1:c47269f0e9e1 | 11 | // 2010/10/16 |
xshige | 1:c47269f0e9e1 | 12 | // Patch loading is supported. |
xshige | 1:c47269f0e9e1 | 13 | // (the patch is needed to make FLAC decoder work) |
xshige | 1:c47269f0e9e1 | 14 | // MP3,Ogg,MIDI,WMA,FLAC,AAC work correcly. |
xshige | 0:67cb2f650c15 | 15 | // |
xshige | 0:67cb2f650c15 | 16 | // 2010/10/12 |
xshige | 0:67cb2f650c15 | 17 | // ported on mbeduino with MP3 Shield by xshige |
xshige | 0:67cb2f650c15 | 18 | |
xshige | 1:c47269f0e9e1 | 19 | |
xshige | 0:67cb2f650c15 | 20 | #define mbeduino |
xshige | 0:67cb2f650c15 | 21 | |
xshige | 0:67cb2f650c15 | 22 | #include "mbed.h" |
xshige | 0:67cb2f650c15 | 23 | #include "VS1053.h" |
xshige | 0:67cb2f650c15 | 24 | |
xshige | 0:67cb2f650c15 | 25 | #ifdef mbeduino |
xshige | 0:67cb2f650c15 | 26 | #include "ArduinoShield.h" |
xshige | 0:67cb2f650c15 | 27 | #endif |
xshige | 0:67cb2f650c15 | 28 | |
xshige | 0:67cb2f650c15 | 29 | /* |
xshige | 0:67cb2f650c15 | 30 | |
xshige | 0:67cb2f650c15 | 31 | MP3 Shield Pin Assigment on mbeduino |
xshige | 0:67cb2f650c15 | 32 | |
xshige | 0:67cb2f650c15 | 33 | Arduino MP3 Side: |
xshige | 0:67cb2f650c15 | 34 | RX NC |
xshige | 0:67cb2f650c15 | 35 | TX NC |
xshige | 0:67cb2f650c15 | 36 | |
xshige | 0:67cb2f650c15 | 37 | D2(BSYNC) |
xshige | 0:67cb2f650c15 | 38 | D3(DREQ) |
xshige | 0:67cb2f650c15 | 39 | |
xshige | 0:67cb2f650c15 | 40 | D4(GPIO2) NC |
xshige | 0:67cb2f650c15 | 41 | D5(GPIO3) NC |
xshige | 0:67cb2f650c15 | 42 | |
xshige | 0:67cb2f650c15 | 43 | D9(CS) |
xshige | 0:67cb2f650c15 | 44 | |
xshige | 0:67cb2f650c15 | 45 | D11(MOSI) |
xshige | 0:67cb2f650c15 | 46 | D12(MISO) |
xshige | 0:67cb2f650c15 | 47 | D13(SCK) |
xshige | 0:67cb2f650c15 | 48 | |
xshige | 0:67cb2f650c15 | 49 | NC: means None-Connection so that I cut pin away. |
xshige | 0:67cb2f650c15 | 50 | |
xshige | 0:67cb2f650c15 | 51 | //------------- |
xshige | 0:67cb2f650c15 | 52 | |
xshige | 0:67cb2f650c15 | 53 | this program comming from the following code: |
xshige | 0:67cb2f650c15 | 54 | |
xshige | 0:67cb2f650c15 | 55 | Arduino MP3 Shield MP3Player |
xshige | 0:67cb2f650c15 | 56 | 2010/10/3 |
xshige | 0:67cb2f650c15 | 57 | |
xshige | 0:67cb2f650c15 | 58 | This program comes from http://mbed.org/cookbook/VS1002-MP3-Decoder |
xshige | 0:67cb2f650c15 | 59 | (Very small modification done to fit latest libs) |
xshige | 0:67cb2f650c15 | 60 | |
xshige | 0:67cb2f650c15 | 61 | |
xshige | 0:67cb2f650c15 | 62 | Pin Assigenment for Arduino MP3 Shield |
xshige | 0:67cb2f650c15 | 63 | (VS1053 employed, issued by sparkfun.com) |
xshige | 0:67cb2f650c15 | 64 | |
xshige | 0:67cb2f650c15 | 65 | MP3 Sheild Side | mbed Side |
xshige | 0:67cb2f650c15 | 66 | --------------------------------------- |
xshige | 0:67cb2f650c15 | 67 | D2(BSYNC)------------17 |
xshige | 0:67cb2f650c15 | 68 | D3(DREQ)-------------16 |
xshige | 0:67cb2f650c15 | 69 | |
xshige | 0:67cb2f650c15 | 70 | D9(CS)---------------14 |
xshige | 0:67cb2f650c15 | 71 | |
xshige | 0:67cb2f650c15 | 72 | D11(MOSI)------------11 |
xshige | 0:67cb2f650c15 | 73 | D12(MISO)------------12 |
xshige | 0:67cb2f650c15 | 74 | D13(SCK)-------------13 |
xshige | 0:67cb2f650c15 | 75 | |
xshige | 0:67cb2f650c15 | 76 | GND------------------GND(1) |
xshige | 0:67cb2f650c15 | 77 | 5V-------------------VU(39) |
xshige | 0:67cb2f650c15 | 78 | RESET----------------15 |
xshige | 0:67cb2f650c15 | 79 | |
xshige | 0:67cb2f650c15 | 80 | Volume will not used. (pin20 will not used) |
xshige | 0:67cb2f650c15 | 81 | |
xshige | 0:67cb2f650c15 | 82 | */ |
xshige | 0:67cb2f650c15 | 83 | |
xshige | 0:67cb2f650c15 | 84 | #include "SDFileSystem.h" |
xshige | 0:67cb2f650c15 | 85 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
xshige | 0:67cb2f650c15 | 86 | |
xshige | 0:67cb2f650c15 | 87 | VS1053 mp3( |
xshige | 0:67cb2f650c15 | 88 | // PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, |
xshige | 0:67cb2f650c15 | 89 | // PinName dreq, PinName dcs, PinName vol) |
xshige | 1:c47269f0e9e1 | 90 | |
xshige | 0:67cb2f650c15 | 91 | #ifdef mbeduino |
xshige | 0:67cb2f650c15 | 92 | ARD_D11,ARD_D12,ARD_D13,ARD_D9,p15, |
xshige | 0:67cb2f650c15 | 93 | ARD_D3,ARD_D2,p20); |
xshige | 1:c47269f0e9e1 | 94 | #else |
xshige | 1:c47269f0e9e1 | 95 | p11, p12, p13, p14, p15, |
xshige | 1:c47269f0e9e1 | 96 | p16, p17, p20); |
xshige | 0:67cb2f650c15 | 97 | #endif |
xshige | 0:67cb2f650c15 | 98 | |
xshige | 0:67cb2f650c15 | 99 | |
xshige | 0:67cb2f650c15 | 100 | int main () |
xshige | 0:67cb2f650c15 | 101 | { |
xshige | 0:67cb2f650c15 | 102 | // make debug port Fast |
xshige | 0:67cb2f650c15 | 103 | Serial pc(USBTX, USBRX); |
xshige | 0:67cb2f650c15 | 104 | // pc.baud(9600); |
xshige | 0:67cb2f650c15 | 105 | pc.baud(115200); |
xshige | 0:67cb2f650c15 | 106 | // pc.baud(230400); |
xshige | 0:67cb2f650c15 | 107 | |
xshige | 0:67cb2f650c15 | 108 | |
xshige | 0:67cb2f650c15 | 109 | /*============================================================ |
xshige | 0:67cb2f650c15 | 110 | * MP3 Initialising |
xshige | 0:67cb2f650c15 | 111 | *==========================================================*/ |
xshige | 1:c47269f0e9e1 | 112 | |
xshige | 1:c47269f0e9e1 | 113 | mp3.initialize(); |
xshige | 1:c47269f0e9e1 | 114 | |
xshige | 0:67cb2f650c15 | 115 | /*============================================================ |
xshige | 0:67cb2f650c15 | 116 | * This is the good part |
xshige | 0:67cb2f650c15 | 117 | *==========================================================*/ |
xshige | 0:67cb2f650c15 | 118 | |
xshige | 0:67cb2f650c15 | 119 | /*====== Song Select ======*/ |
xshige | 0:67cb2f650c15 | 120 | for(int a=1; a<24; a++) |
xshige | 0:67cb2f650c15 | 121 | { |
xshige | 0:67cb2f650c15 | 122 | printf("Song#:%d\r\n",a); |
xshige | 0:67cb2f650c15 | 123 | int song_number = a; |
xshige | 0:67cb2f650c15 | 124 | |
xshige | 0:67cb2f650c15 | 125 | // char list[10000] = {0}; |
xshige | 0:67cb2f650c15 | 126 | char list[1000] = {0}; |
xshige | 0:67cb2f650c15 | 127 | char str[16] = {"/sd/"}; |
xshige | 0:67cb2f650c15 | 128 | unsigned int startplace = 0; |
xshige | 0:67cb2f650c15 | 129 | unsigned int endplace = 0; |
xshige | 0:67cb2f650c15 | 130 | unsigned int play = 0; |
xshige | 0:67cb2f650c15 | 131 | int num_of_files = 0; |
xshige | 0:67cb2f650c15 | 132 | |
xshige | 0:67cb2f650c15 | 133 | DIR *d; |
xshige | 0:67cb2f650c15 | 134 | struct dirent *p; |
xshige | 0:67cb2f650c15 | 135 | d = opendir("/sd"); |
xshige | 0:67cb2f650c15 | 136 | if(d != NULL) |
xshige | 0:67cb2f650c15 | 137 | { |
xshige | 0:67cb2f650c15 | 138 | while((p = readdir(d)) != NULL) |
xshige | 0:67cb2f650c15 | 139 | { |
xshige | 0:67cb2f650c15 | 140 | strcat(list, "*"); |
xshige | 0:67cb2f650c15 | 141 | strcat(list, p->d_name); |
xshige | 0:67cb2f650c15 | 142 | num_of_files++; |
xshige | 0:67cb2f650c15 | 143 | } |
xshige | 0:67cb2f650c15 | 144 | } |
xshige | 0:67cb2f650c15 | 145 | else |
xshige | 0:67cb2f650c15 | 146 | { |
xshige | 0:67cb2f650c15 | 147 | perror("Could not open directory!"); |
xshige | 0:67cb2f650c15 | 148 | } |
xshige | 0:67cb2f650c15 | 149 | strcat(list, "*"); //terminating * |
xshige | 0:67cb2f650c15 | 150 | |
xshige | 0:67cb2f650c15 | 151 | while(play != song_number) |
xshige | 0:67cb2f650c15 | 152 | { |
xshige | 0:67cb2f650c15 | 153 | char symbol = list[startplace]; |
xshige | 0:67cb2f650c15 | 154 | startplace++; |
xshige | 0:67cb2f650c15 | 155 | if(symbol == 0x2A) //0x2A = "*" |
xshige | 0:67cb2f650c15 | 156 | { |
xshige | 0:67cb2f650c15 | 157 | play++; |
xshige | 0:67cb2f650c15 | 158 | } |
xshige | 0:67cb2f650c15 | 159 | } |
xshige | 0:67cb2f650c15 | 160 | play = 0; |
xshige | 0:67cb2f650c15 | 161 | while(play != (song_number+1)) |
xshige | 0:67cb2f650c15 | 162 | { |
xshige | 0:67cb2f650c15 | 163 | char symbol = list[endplace]; |
xshige | 0:67cb2f650c15 | 164 | endplace++; |
xshige | 0:67cb2f650c15 | 165 | if(symbol == 0x2A) //0x2A = "*" |
xshige | 0:67cb2f650c15 | 166 | { |
xshige | 0:67cb2f650c15 | 167 | play++; |
xshige | 0:67cb2f650c15 | 168 | } |
xshige | 0:67cb2f650c15 | 169 | } |
xshige | 0:67cb2f650c15 | 170 | |
xshige | 0:67cb2f650c15 | 171 | strncat(str, &list[startplace], endplace-startplace); |
xshige | 0:67cb2f650c15 | 172 | str[(endplace-startplace)+3] = '\0'; |
xshige | 0:67cb2f650c15 | 173 | |
xshige | 0:67cb2f650c15 | 174 | //printf("list: %s\r\n",list); //debug |
xshige | 0:67cb2f650c15 | 175 | |
xshige | 0:67cb2f650c15 | 176 | /*====== File Transfer ======*/ |
xshige | 0:67cb2f650c15 | 177 | |
xshige | 0:67cb2f650c15 | 178 | printf("Now Playing: %s\r\n",str); |
xshige | 0:67cb2f650c15 | 179 | |
xshige | 0:67cb2f650c15 | 180 | FILE *song; |
xshige | 1:c47269f0e9e1 | 181 | // unsigned char array[8*1024]; |
xshige | 1:c47269f0e9e1 | 182 | unsigned char array[4*1024]; // bigger size makes click tone in AAC playing |
xshige | 0:67cb2f650c15 | 183 | |
xshige | 0:67cb2f650c15 | 184 | song = fopen(str, "rb"); |
xshige | 0:67cb2f650c15 | 185 | |
xshige | 0:67cb2f650c15 | 186 | if(!song) |
xshige | 0:67cb2f650c15 | 187 | { |
xshige | 0:67cb2f650c15 | 188 | exit(1); |
xshige | 0:67cb2f650c15 | 189 | } |
xshige | 0:67cb2f650c15 | 190 | |
xshige | 0:67cb2f650c15 | 191 | while(!feof(song)) |
xshige | 0:67cb2f650c15 | 192 | { |
xshige | 0:67cb2f650c15 | 193 | int n=fread(&array, 1, sizeof(array), song); |
xshige | 0:67cb2f650c15 | 194 | mp3.writeStream(array,n); |
xshige | 0:67cb2f650c15 | 195 | } |
xshige | 0:67cb2f650c15 | 196 | mp3.terminateStream(); |
xshige | 0:67cb2f650c15 | 197 | |
xshige | 0:67cb2f650c15 | 198 | fclose(song); //close the file |
xshige | 0:67cb2f650c15 | 199 | |
xshige | 0:67cb2f650c15 | 200 | } // for |
xshige | 0:67cb2f650c15 | 201 | |
xshige | 0:67cb2f650c15 | 202 | printf("Done.\r\n"); |
xshige | 0:67cb2f650c15 | 203 | } |