earlephilhower / ESP8266Audio

Arduino library to play MOD, WAV, FLAC, MIDI, RTTTL, MP3, and AAC files on I2S DACs or with a software emulated delta-sigma DAC on the ESP8266 and ESP32
GNU General Public License v3.0
2.01k stars 432 forks source link

[NodeMCU: SD source, Internal DAC] MP3 done instantly, without playing audio #548

Closed Janmorgen closed 2 years ago

Janmorgen commented 2 years ago

The program does output the address of the file, indicating that it has been opened and is being decoded to play sound, but it plays nothing but a jumble of pitches when it does play, then reports "MP3 done"

I have tried using AudioFileSourceBuffer which didnt produce anything different, Ive also tried adding a parameter for the dma buffer on AudioOutputI2C also to no effect. It was playing sound earlier (although grainy and poppy, like a badly tuned radio), but now it doesn't play at all and I am so frustrated.

Code:

  boolean cardMounted=true;
  void setup(){
    WiFi.mode(WIFI_OFF);
      Serial.begin(115200);
      sdSPI.begin(SD_CLK,SD_MISO,SD_MOSI,SD_CS);
      SPI.setFrequency(80000000);
  //    delay(5000);
  //SPIFFS.begin();
      if(!SD.begin(SD_CS,sdSPI,80000000)){
          Serial.println("Card Mount Failed");
          cardMounted=false;
          return;
      }
      uint8_t cardType = SD.cardType();

      if(cardType == CARD_NONE){
          Serial.println("No SD card attached");
          return;
      }

      Serial.print("SD Card Type: ");
      if(cardType == CARD_MMC){
          Serial.println("MMC");
      } else if(cardType == CARD_SD){
          Serial.println("SDSC");
      } else if(cardType == CARD_SDHC){
          Serial.println("SDHC");
      } else {
          Serial.println("UNKNOWN");
      }

      uint64_t cardSize = SD.cardSize() / (1024 * 1024);
      Serial.printf("SD Card Size: %lluMB\n", cardSize);

      listDir(SD, "/", 0);
      testFileIO(SD, "/test.txt");
      Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
      Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));

      if (cardMounted){
        audioLogger=&Serial;
        file= new AudioFileSourceSD("/bigiron.mp3");
        out = new AudioOutputI2S();
        mp3 = new AudioGeneratorMP3();

        mp3->begin(file, out);
      }

  }

  void loop(){
    if (cardMounted){
  //    delay(300);
      if (mp3->isRunning()) {
        if (!mp3->loop()) mp3->stop();
      } else {
        Serial.printf("MP3 done\n");
        delay(1000);
  //      mp3->stop();
      }
    }
  }