1

Dependencies:   VS1053 WIZnetInterface mbed-src

Committer:
WizLeo
Date:
Wed Jun 29 04:42:50 2016 +0000
Revision:
1:964dd9f476a7
Parent:
0:6a47d12e2093
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WizLeo 0:6a47d12e2093 1 /**
WizLeo 0:6a47d12e2093 2 * WebRadio player 2 (Icecast music streams player)
WizLeo 0:6a47d12e2093 3 *
WizLeo 0:6a47d12e2093 4 * Listen to your favorite WebRadio music stations up to 320 kbps !
WizLeo 0:6a47d12e2093 5 *
WizLeo 0:6a47d12e2093 6 * Used components: VS1053 MP3 decoder and WIZ-wiki-W7500 ARM Cortex-M0 board
WizLeo 0:6a47d12e2093 7 *
WizLeo 0:6a47d12e2093 8 * 5 September 2015 by Vassilis Serasidis
WizLeo 0:6a47d12e2093 9 *
WizLeo 0:6a47d12e2093 10 * Home: http://www.serasidis.gr
WizLeo 0:6a47d12e2093 11 * email: avrsite@yahoo.gr
WizLeo 0:6a47d12e2093 12 *
WizLeo 0:6a47d12e2093 13 * Edit the file "W7500x_toe.cpp" and add the following lines:
WizLeo 0:6a47d12e2093 14 *
WizLeo 0:6a47d12e2093 15 * **
WizLeo 0:6a47d12e2093 16 * * Use only one socket with 16 kBytes of RAM for Tx and 16 kBytes of RAM for Rx
WizLeo 0:6a47d12e2093 17 * *
WizLeo 0:6a47d12e2093 18 * sreg<uint8_t>(0, Sn_RXBUF_SIZE, 16); //Vassilis Serasidis
WizLeo 0:6a47d12e2093 19 * sreg<uint8_t>(0, Sn_TXBUF_SIZE, 16); //Vassilis Serasidis
WizLeo 0:6a47d12e2093 20 *
WizLeo 0:6a47d12e2093 21 * -= NOTE =-
WizLeo 0:6a47d12e2093 22 * This project is provided as-is without any waranty, under the GNU General Public License v3
WizLeo 0:6a47d12e2093 23 * ( http://www.gnu.org/licenses/gpl-3.0.en.html )
WizLeo 0:6a47d12e2093 24 *
WizLeo 0:6a47d12e2093 25 */
WizLeo 0:6a47d12e2093 26
WizLeo 0:6a47d12e2093 27 #include "mbed.h"
WizLeo 0:6a47d12e2093 28 #include "VS1053.h"
WizLeo 0:6a47d12e2093 29 #include "EthernetInterface.h"
WizLeo 0:6a47d12e2093 30
WizLeo 0:6a47d12e2093 31 #define BUFFER_LENGTH 1024
WizLeo 0:6a47d12e2093 32 #define BUFFER_LENGTH2 32
WizLeo 0:6a47d12e2093 33 #define MAX_RADIO_STATIONS 4 // 18 pre-defined webradio station. You can increase the number if you want.
WizLeo 0:6a47d12e2093 34
WizLeo 0:6a47d12e2093 35 //VS1002 mp3(PB_3, PB_2, PB_1, PB_0,"sdc",D11, D12 ,D13, PC_12, PC_15, PC_14, PC_13);
WizLeo 0:6a47d12e2093 36 //VS1002::VS1002( mmosi, mmiso, ssck, ccs, const char *name, mosi, miso, sck, cs, rst, dreq, dcs)
WizLeo 0:6a47d12e2093 37 // : _DREQ(dreq), _RST(rst), _spi(mosi, miso, sck), _CS(cs), _DCS(dcs), _sd(mmosi, mmiso, ssck, ccs, name) {
WizLeo 0:6a47d12e2093 38 // }
WizLeo 0:6a47d12e2093 39
WizLeo 0:6a47d12e2093 40 VS1053 player(D11, D12 ,D13, PC_12, PC_13, PC_14, PC_15); // mosi, miso, sck, cs, dcs, dreq, rst
WizLeo 0:6a47d12e2093 41 //VS1002 player(PB_3, PB_2, PB_1, PB_0,"sdc",D11, D12 ,D13, PC_12, PC_15, PC_14, PC_13);
WizLeo 0:6a47d12e2093 42 char ramBuffer[BUFFER_LENGTH];
WizLeo 0:6a47d12e2093 43 int radioStationNumber = 0; //Initial webradio station
WizLeo 0:6a47d12e2093 44
WizLeo 0:6a47d12e2093 45 Serial com(USBTX, USBRX); //Create a Serial Port instance.
WizLeo 0:6a47d12e2093 46
WizLeo 0:6a47d12e2093 47 DigitalIn dreq(PC_14); //Set DREQ pin as input (D8).
WizLeo 0:6a47d12e2093 48 DigitalIn sw1(D2); //Next webradio station selection button (D5).
WizLeo 0:6a47d12e2093 49 //DigitalIn sw2(D6); //Previous webradio station selection button (D6).
WizLeo 0:6a47d12e2093 50 //int sw1 = 0;
WizLeo 0:6a47d12e2093 51 //int sw2 = 0;
WizLeo 0:6a47d12e2093 52 typedef struct station {
WizLeo 0:6a47d12e2093 53 char const * rAddress;
WizLeo 0:6a47d12e2093 54 unsigned int port;
WizLeo 0:6a47d12e2093 55 } STATION;
WizLeo 0:6a47d12e2093 56
WizLeo 0:6a47d12e2093 57 /**
WizLeo 0:6a47d12e2093 58 * 18 pre-defined webradio stations.
WizLeo 0:6a47d12e2093 59 * You can increase the number of the stations because there is plenty of memory bytes.
WizLeo 0:6a47d12e2093 60 * Syntax: {"WebRadio_station_address", port_number}
WizLeo 0:6a47d12e2093 61 */
WizLeo 0:6a47d12e2093 62 const STATION stations[MAX_RADIO_STATIONS] = {
WizLeo 0:6a47d12e2093 63 // {"radiolive.sbs.co.kr",80},
WizLeo 0:6a47d12e2093 64 // {"sc03.saycast.com",80},
WizLeo 0:6a47d12e2093 65 // {"72.232.255.92", 12978},
WizLeo 0:6a47d12e2093 66 {"ks386954.kimsufi.com", 8248}, // <01> La Grosse Radio Metal - Hard Heavy - From Paris :: 48 kbps :: aacp
WizLeo 0:6a47d12e2093 67 {"205.164.62.15",10032}, // <02> 1.FM - GAIA :: 64-kbps :: aacp
WizLeo 0:6a47d12e2093 68 {"205.164.36.153",80}, // <03> BOM PSYTRANCE (1.FM TM) :: 64-kbps :: aacp
WizLeo 0:6a47d12e2093 69 {"topfm-st1.kbcnet.rs",80}, // <04> TOP FM Beograd 106,8 :: 64-kpbs :: mpeg
WizLeo 0:6a47d12e2093 70 // {"sc8.1.fm",8030}, // :: 64-kbps :: aacp
WizLeo 0:6a47d12e2093 71 // {"www.inbalancemusic.com",80}, // <05> Cosmoradio 95.1 - Thessaloniki - Greece :: 128 kbps :: mpeg
WizLeo 0:6a47d12e2093 72 // {"s10.voscast.com",9940}, // <06> Zoo Radio 90.8 Greece :: 128 kbps :: mpeg
WizLeo 0:6a47d12e2093 73 // {"radio.onweb.gr",8078}, // <07> 1055 ROCK - THESSALONIKI - GREECE :: 128 kbps :: mpeg
WizLeo 0:6a47d12e2093 74 // {"149.255.59.162", 8030}, // <08> ORIGINUK.NET DRUM AND BASS AND OLDSKOOL :: 128 kbps :: mpeg
WizLeo 0:6a47d12e2093 75 // {"uk3.internet-radio.com", 8060}, // <09> Champion 5768 FM - Non Stop Hits From All Eras :: 128 kbps :: mpeg
WizLeo 0:6a47d12e2093 76 // {"46.41.129.195", 8000}, // <10> Trance1.FM :: 128 kbps :: mpeg
WizLeo 0:6a47d12e2093 77 // {"uk3.internet-radio.com", 10523}, // <11> Tonik Radio Ireland :: 192 kbps :: mpeg
WizLeo 0:6a47d12e2093 78 // {"95.141.24.4", 80}, // <12> #MUSIK.CLUB (DANCE) - WWW.RAUTEMUSIK.FM :: 192 kbps :: mpeg
WizLeo 0:6a47d12e2093 79 // {"193.34.51.33", 80}, // <13> WackenRadio.com - Metal Rock Alternative :: 192 kbps :: mpeg
WizLeo 0:6a47d12e2093 80 // {"uk4.internet-radio.com",15938}, // <14> GoHamRadio - Trance Dance Progressive Chillout :: 256 kbps :: mpeg
WizLeo 0:6a47d12e2093 81 // {"206.190.152.194", 8000}, // <15> PARTY VIBE RADIO: Reggae Roots Dancehall :: 256 kbps :: mpeg
WizLeo 0:6a47d12e2093 82 // {"213.251.157.145", 8016}, // <16> Audiophile Baroque Clasic Music :: 320 kbps :: mpeg
WizLeo 0:6a47d12e2093 83 // {"83.137.145.141", 14280}, // <17> Nautic Radio - Beats 'n Breaks - drum and bass :: 320 kbps :: mpeg
WizLeo 0:6a47d12e2093 84 // {"50.7.173.162", 8014} // <18> Audiophile Jazz :: 320 kbps :: mpeg
WizLeo 0:6a47d12e2093 85 };
WizLeo 0:6a47d12e2093 86
WizLeo 0:6a47d12e2093 87
WizLeo 0:6a47d12e2093 88 /*************************************
WizLeo 0:6a47d12e2093 89 *
WizLeo 0:6a47d12e2093 90 *************************************/
WizLeo 0:6a47d12e2093 91 int main() {
WizLeo 0:6a47d12e2093 92 *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
WizLeo 0:6a47d12e2093 93 com.baud(115200); //Set the Serial port baud rate to 115200 bits/second
WizLeo 0:6a47d12e2093 94
WizLeo 0:6a47d12e2093 95 com.printf("\r\n---------------------------------------");
WizLeo 0:6a47d12e2093 96 com.printf("\r\n WebRadio player\n");
WizLeo 0:6a47d12e2093 97 // com.printf("\r\n(c) 05 Sept 2015 by Vassilis Serasidis");
WizLeo 0:6a47d12e2093 98 // com.printf("\r\n Home: http://www.serasidis.gr");
WizLeo 0:6a47d12e2093 99 com.printf("\r\n---------------------------------------");
WizLeo 0:6a47d12e2093 100 com.printf("\r\nGetting IP address...");
WizLeo 0:6a47d12e2093 101 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x09}; //Ethernet MAC address
WizLeo 0:6a47d12e2093 102
WizLeo 0:6a47d12e2093 103
WizLeo 0:6a47d12e2093 104 EthernetInterface eth;
WizLeo 0:6a47d12e2093 105 eth.init(mac_addr); //Use DHCP
WizLeo 0:6a47d12e2093 106
WizLeo 0:6a47d12e2093 107 eth.connect();
WizLeo 0:6a47d12e2093 108
WizLeo 0:6a47d12e2093 109 com.printf("\r\nLocal IP Address: %s\r\n", eth.getIPAddress()); //Print the local IP address.
WizLeo 0:6a47d12e2093 110
WizLeo 0:6a47d12e2093 111 int i,m;
WizLeo 0:6a47d12e2093 112 TCPSocketConnection client; //Create a client.
WizLeo 0:6a47d12e2093 113
WizLeo 0:6a47d12e2093 114 player.hardwareReset(); //Do a reset to the VS1053 board.
WizLeo 0:6a47d12e2093 115 // player.clockUp(); //Set the VS1053 at faster SPI speed.
WizLeo 0:6a47d12e2093 116 player.modeSwitch(); //Patch the VS1053 board to play MP3 files (very important!).
WizLeo 0:6a47d12e2093 117 // player.setVolume(44); //Set the VS1053 volume. Value 0 is MAX volume, 255 is mute.
WizLeo 0:6a47d12e2093 118 // player._RST = 1;
WizLeo 0:6a47d12e2093 119 // player.cs_high(); //chip disabled
WizLeo 0:6a47d12e2093 120 // player.sci_initialise(); //initialise MBED
WizLeo 0:6a47d12e2093 121 // player.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF));
WizLeo 0:6a47d12e2093 122 // player.sci_write(0x03, 0x9800);
WizLeo 0:6a47d12e2093 123 // player.sdi_initialise();
WizLeo 0:6a47d12e2093 124
WizLeo 0:6a47d12e2093 125 while(1){
WizLeo 0:6a47d12e2093 126 com.printf("\r\n----------------------------------------------");
WizLeo 0:6a47d12e2093 127 com.printf("\r\nConnecting to [%s] ...",stations[radioStationNumber].rAddress);
WizLeo 0:6a47d12e2093 128
WizLeo 0:6a47d12e2093 129 /* Connect to the Icecast server defined by 'radioStationNumber' variable (1-18) */
WizLeo 0:6a47d12e2093 130 client.connect(stations[radioStationNumber].rAddress, stations[radioStationNumber].port);
WizLeo 0:6a47d12e2093 131
WizLeo 0:6a47d12e2093 132 /* Check if the client was connected to the server */
WizLeo 0:6a47d12e2093 133 if(client.is_connected()){
WizLeo 0:6a47d12e2093 134 com.printf("\r\nConnected!\r\n");
WizLeo 0:6a47d12e2093 135 }else{
WizLeo 0:6a47d12e2093 136 //com.printf("Is NOT connected. Please try again.\n");
WizLeo 0:6a47d12e2093 137 for(;;); //Stay here for ever.
WizLeo 0:6a47d12e2093 138 }
WizLeo 0:6a47d12e2093 139
WizLeo 0:6a47d12e2093 140 client.send("GET / HTTP/1.1\r\n",16); //Send the Header to the Server.
WizLeo 0:6a47d12e2093 141 client.send("\r\n",2);
WizLeo 0:6a47d12e2093 142 wait(0.5);
WizLeo 0:6a47d12e2093 143
WizLeo 0:6a47d12e2093 144 com.printf("\r\nReading Icecast radiostation information...");
WizLeo 0:6a47d12e2093 145 /* Read the Icecast server information (station name, bit rate and more)*/
WizLeo 0:6a47d12e2093 146 client.receive(ramBuffer, BUFFER_LENGTH); //Store the received data to the RAM buffer.
WizLeo 0:6a47d12e2093 147 com.printf("\r\nDone!");
WizLeo 0:6a47d12e2093 148 com.printf("\r\n<%d> ",radioStationNumber + 1); //Print the station number (1-18)
WizLeo 0:6a47d12e2093 149
WizLeo 0:6a47d12e2093 150 /**
WizLeo 0:6a47d12e2093 151 * From the 1024 received bytes extract only the WebRadio station information.
WizLeo 0:6a47d12e2093 152 * The information data ends with the bytes \r\n\r\n
WizLeo 0:6a47d12e2093 153 * In other words, ends with the four hexadecimal bytes [0x0d 0x0a 0x0d 0x0a] .
WizLeo 0:6a47d12e2093 154 */
WizLeo 0:6a47d12e2093 155 for(i=0;i<(BUFFER_LENGTH - 4);i++){
WizLeo 0:6a47d12e2093 156 if((ramBuffer[i] == 0x0d)&&(ramBuffer[i+1] == 0x0a)&&(ramBuffer[i+2] == 0x0d)&&(ramBuffer[i+3] == 0x0a))
WizLeo 0:6a47d12e2093 157 break; //If you found the end-sequence then break the <for> loop.
WizLeo 0:6a47d12e2093 158 else
WizLeo 0:6a47d12e2093 159 com.putc(ramBuffer[i]);
WizLeo 0:6a47d12e2093 160 }
WizLeo 0:6a47d12e2093 161 com.printf("\r\n");
WizLeo 0:6a47d12e2093 162
WizLeo 0:6a47d12e2093 163
WizLeo 0:6a47d12e2093 164 /* Do that loop forever */
WizLeo 0:6a47d12e2093 165
WizLeo 0:6a47d12e2093 166 m = 1;
WizLeo 0:6a47d12e2093 167
WizLeo 0:6a47d12e2093 168 while(m > 0){
WizLeo 0:6a47d12e2093 169 client.receive(ramBuffer, BUFFER_LENGTH2);
WizLeo 0:6a47d12e2093 170 while(!dreq);
WizLeo 0:6a47d12e2093 171 if(sw1){ //If the NEXT button is pressed,
WizLeo 0:6a47d12e2093 172 if(radioStationNumber < MAX_RADIO_STATIONS - 1 )
WizLeo 0:6a47d12e2093 173 radioStationNumber++; //select the NEXT webradio station.
WizLeo 0:6a47d12e2093 174 else
WizLeo 0:6a47d12e2093 175 radioStationNumber = 0;
WizLeo 0:6a47d12e2093 176 m = 0; //Exit from this loop.
WizLeo 0:6a47d12e2093 177 }
WizLeo 0:6a47d12e2093 178 //
WizLeo 0:6a47d12e2093 179 // if(sw2){ //If the PREVIOUS button is pressed,
WizLeo 0:6a47d12e2093 180 // if(radioStationNumber > 0)
WizLeo 0:6a47d12e2093 181 // radioStationNumber--; //select the PREVIOUS webradio station.
WizLeo 0:6a47d12e2093 182 // else
WizLeo 0:6a47d12e2093 183 // radioStationNumber = MAX_RADIO_STATIONS - 1;
WizLeo 0:6a47d12e2093 184 // m = 0; //Exit from this loop.
WizLeo 0:6a47d12e2093 185 // }
WizLeo 0:6a47d12e2093 186 player.sendDataBlock(ramBuffer, BUFFER_LENGTH2); // and pass the data to the VS1053 MP3 decoder module.
WizLeo 0:6a47d12e2093 187 }
WizLeo 0:6a47d12e2093 188
WizLeo 0:6a47d12e2093 189 }
WizLeo 0:6a47d12e2093 190 }
WizLeo 0:6a47d12e2093 191