ESP32 Radio-如何提高音质?

时间:2018-12-01 17:25:58

标签: arduino

我从this site获得了ESP32 Radio源代码。

我喜欢它,因为它的广播非常简单,并且可以在ESP32上正常工作。

但是有时候声音非常震撼。

我怀疑可能是因为缺少适当的缓冲区,但是我不知道如何解决它。

代码:

/*
WITHOUT OLED, only ESP32 & VS1053    
VS1053 - connections detail
XRST = EN (D3)
 MISO = D19
 MOSI = D23
 SCLK = D18
 VCC = 5V / 3.3 V
 Gnd = Gnd 
*/


#include <VS1053.h> //ESP_VS1053_Library

#include <Preferences.h>  //For reading and writing into the ROM memory
Preferences preferences;
unsigned int counter,old_counter,new_counter;

#include "helloMp3.h"
#include <WiFi.h>
#include <HTTPClient.h>
#include <esp_wifi.h>

char ssid[] = "SSID";    //  your network SSID (name) 
char pass[] = "PASSWORD";   // your network password

char *host[7] = {"184.95.47.178","us4.internet-radio.com","us3.internet-radio.com","us3.internet-radio.com","174.36.206.197","sj64.hnux.com","uk7.internet-radio.com"};
char *path[7] = {"/","/","/live.m3u","/","/","/","/"};
int   port[7] = {9328,8266,8371,8297,8000,80,8226};

char *sname[7] = {"Love-Radio-USA","Smooth-Jazz-Florida","Best-Rock-Radio","Country-Radio","Venice-Classic-Radio","Smooth-Jazz-Global","UK-Top-40"};


int change=13;
bool x=true;
int status = WL_IDLE_STATUS;
WiFiClient  client;
uint8_t mp3buff[32];   // vs1053 likes 32 bytes at a time

// Wiring of VS1053 board (SPI connected in a standard way)
#define VS1053_CS    32 //32
#define VS1053_DCS   33  //33
#define VS1053_DREQ  35 //15
#define VOLUME  100 // volume level 0-100
VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ);

void setup () {

   pinMode(change,INPUT_PULLUP);
// initialize SPI
   Serial.begin(115200);
   delay(500);
// initialize SPI bus;
    SPI.begin();

// initialize VS1053 player
    player.begin();
//    player.switchToMp3Mode(); // optional, some boards require this
    player.setVolume(VOLUME);

   WiFi.begin(ssid, pass);
   while (WiFi.status() != WL_CONNECTED) {
  //  display.drawString(0,15,"   Connecting..");
    delay(500);
    Serial.print(".");
   }
  Serial.println("WiFi connected");  
  Serial.print("IP address:");  
  Serial.println(WiFi.localIP());

preferences.begin("my-app", false);
counter = preferences.getUInt("counter", 0);
old_counter=counter;

Serial.printf("Current counter value1: %u\n", counter);
//if(counter>0) counter=0;
//Serial.printf("Current counter value2: %u\n", counter);
delay(100);
player.playChunk(hello2, sizeof(hello2)); //VS1053 is wake up & running
station_connect(counter); 
}

void loop() {

      if (client.available() > 0) {
      uint8_t bytesread = client.read(mp3buff, 32);
      player.playChunk(mp3buff, bytesread);
      }

    if(digitalRead(change)==0 and x==true){
    x=false;
    counter = counter+1;
    if(counter>6) counter=0;
    preferences.putUInt("counter",counter);
    new_counter=counter;
    Serial.printf("Old_Counter: %u\n",old_counter);
    Serial.printf("New_Counter: %u\n",new_counter);
    Serial.printf("Set counter to new_value: %u\n", counter);
    delay(500); 

    if(old_counter != new_counter) {

    player.softReset(); 
    x=true;
    station_connect(new_counter); 
    preferences.putUInt("counter",new_counter); 

    }
  } 
}

void station_connect (int station_no ) {
    if (client.connect(host[station_no],port[station_no]) ) {
    Serial.println("Connected now");
     }
    Serial.print(host[station_no]);
    Serial.println(path[station_no]);
    Serial.println(sname[station_no]);
    client.print(String("GET ") + path[station_no] + " HTTP/1.1\r\n" +
               "Host: " + host[station_no] + "\r\n" + 
               "Connection: close\r\n\r\n");     
  }

如何改善音质?请帮助

感谢所有帮手! :)

0 个答案:

没有答案