schreibfaul1 / ESP32-audioI2S

Play mp3 files from SD via I2S
GNU General Public License v3.0
1.07k stars 282 forks source link

No Matching function for call to 'ConnecttoFS(fs::SDFS&, String&) #523

Closed The-Valveman closed 1 year ago

The-Valveman commented 1 year ago

Hi I am trying to an SD card based MP3 player to work i have tried various sketches douwnloaded as i want an MP3 player to incorporate in a touch screen dab/FM receiver project that i am working on i have the DAB/FM and internet radio functions working ok but i am struggling to get a MP3 player that reads MP3s from a local SD card to work i found the sketch below on github which would be perfect if i could just get it working this sketch uses the ESP32- audioi2s library. I have tried an example by hard coding a track using the line 'audio.connecttoFS(SD,"/TRACK003.mp3.mp3"); ' and making sure the SD card contains an MP3 file with the name 'TRACK003.mp3 this works and the track plays perfectly. But i need to be able get the player to read the SD card and allow the user to select which tracks to play and for it to play the tracks one after another until all tracks have been played. when i try to compile the below sketch i get this error:- 'Compilation error: no matching function for call to 'Audio::connecttoFS(fs::SDFS&, String&)' If i comment out the line audio.connecttoFS(SD, filename); the code compiles but it doesn't play the files but it does read the SD card and lists the tracks on the card. The code


include "Arduino.h"

//#include "WiFiMulti.h"

include "Audio.h"

include "SPI.h"

include "SD.h"

include "FS.h"

include

include

//SD Card

define SD_CS 22

define SPI_MOSI 23

define SPI_MISO 19

define SPI_SCK 18

//Digital I/O used //Makerfabs Audio V2.0

define I2S_DOUT 27

define I2S_BCLK 26

define I2S_LRC 25

//SSD1306

define MAKEPYTHON_ESP32_SDA 4

define MAKEPYTHON_ESP32_SCL 5

define SCREEN_WIDTH 128 // OLED display width, in pixels

define SCREEN_HEIGHT 64 // OLED display height, in pixels

define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

//Button const int Pin_vol_up = 39; const int Pin_vol_down = 36; const int Pin_mute = 35;

const int Pin_previous = 15; const int Pin_pause = 33; const int Pin_next = 2;

Audio audio;

struct Music_info { String name; int length; int runtime; int volume; int status; int mute_volume; } music_info = {"", 0, 0, 0, 0, 0};

String file_list[20]; int file_num = 0; int file_index = 0;

void setup() { //IO mode init pinMode(Pin_vol_up, INPUT_PULLUP); pinMode(Pin_vol_down, INPUT_PULLUP); pinMode(Pin_mute, INPUT_PULLUP); pinMode(Pin_previous, INPUT_PULLUP); pinMode(Pin_pause, INPUT_PULLUP); pinMode(Pin_next, INPUT_PULLUP);

//Serial
Serial.begin(115200);

//LCD
Wire.begin(MAKEPYTHON_ESP32_SDA, MAKEPYTHON_ESP32_SCL);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{ // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
        ; // Don't proceed, loop forever
}
display.clearDisplay();
logoshow();

//SD(SPI)
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
SPI.setFrequency(1000000);
if (!SD.begin(SD_CS, SPI))
{
    Serial.println("Card Mount Failed");
    lcd_text("SD ERR");
    while (1)
        ;
}
else
{
    lcd_text("SD OK");
}

//Read SD
file_num = get_music_list(SD, "/", 0, file_list);
Serial.print("Music file count:");
Serial.println(file_num);
Serial.println("All music:");
for (int i = 0; i < file_num; i++)
{
    Serial.println(file_list[i]);
}

//Audio(I2S)
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(21); // 0...21
open_new_song(file_list[file_index]);
print_song_time();

}

uint run_time = 0; uint button_time = 0;

void loop() { audio.loop(); if (millis() - run_time > 1000) { run_time = millis(); print_song_time(); display_music(); }

if (millis() - button_time > 300)
{
    //Button logic
    if (digitalRead(Pin_next) == 0)
    {
        Serial.println("Pin_next");
        if (file_index < file_num - 1)
            file_index++;
        else
            file_index = 0;
        open_new_song(file_list[file_index]);
        print_song_time();
        button_time = millis();
    }
    if (digitalRead(Pin_previous) == 0)
    {
        Serial.println("Pin_previous");
        if (file_index > 0)
            file_index--;
        else
            file_index = file_num - 1;
        open_new_song(file_list[file_index]);
        print_song_time();
        button_time = millis();
    }
    if (digitalRead(Pin_vol_up) == 0)
    {
        Serial.println("Pin_vol_up");
        if (music_info.volume < 21)
            music_info.volume++;
        audio.setVolume(music_info.volume);
        button_time = millis();
    }
    if (digitalRead(Pin_vol_down) == 0)
    {
        Serial.println("Pin_vol_down");
        if (music_info.volume > 0)
            music_info.volume--;
        audio.setVolume(music_info.volume);
        button_time = millis();
    }
    if (digitalRead(Pin_mute) == 0)
    {
        Serial.println("Pin_mute");
        if (music_info.volume != 0)
        {
            music_info.mute_volume = music_info.volume;
            music_info.volume = 0;
        }
        else
        {
            music_info.volume = music_info.mute_volume;
        }
        audio.setVolume(music_info.volume);
        button_time = millis();
    }
    if (digitalRead(Pin_pause) == 0)
    {
        Serial.println("Pin_pause");
        audio.pauseResume();
        button_time = millis();
    }
}

if (Serial.available())
{
    String r = Serial.readString();
    r.trim();
    if (r.length() > 5)
    {
        audio.stopSong();
        open_new_song(file_list[0]);
        print_song_info();
    }
    else
    {
        audio.setVolume(r.toInt());
    }
}

}

void open_new_song(String filename) { music_info.name = filename.substring(1, filename.indexOf("."));

audio.connecttoFS(SD, filename);       // this line causes the code not to compile if i comment out this line the code compiles
music_info.runtime = audio.getAudioCurrentTime();
music_info.length = audio.getAudioFileDuration();
music_info.volume = audio.getVolume();
music_info.status = 1;
Serial.println("**********start a new sound************");

}

void display_music() { int line_step = 24; int line = 0; char buff[20]; ; sprintf(buff, "%d:%d", music_info.runtime, music_info.length);

display.clearDisplay();

display.setTextSize(2);              // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text

display.setCursor(0, line); // Start at top-left corner
display.println(music_info.name);
line += line_step;

display.setCursor(0, line);
display.println(buff);
line += line_step;

sprintf(buff, "V:%d",music_info.volume);

display.setCursor(0, line);
display.println(buff);
line += line_step;

display.setCursor(0, line);
display.println(music_info.status);
line += line_step;

display.display();

}

void logoshow(void) { display.clearDisplay();

display.setTextSize(2);              // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0);             // Start at top-left corner
display.println(F("ESP32"));
display.setCursor(0, 20); // Start at top-left corner
display.println(F("MUSIC"));
display.setCursor(0, 40); // Start at top-left corner
display.println(F("PLAYER"));
display.display();
delay(2000);

}

void lcd_text(String text) { display.clearDisplay();

display.setTextSize(2);              // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0);             // Start at top-left corner
display.println(text);
display.display();
delay(500);

}

void print_song_info() { Serial.println(""); Serial.println(audio.getFileSize()); Serial.println(audio.getFilePos()); Serial.println(audio.getSampleRate()); Serial.println(audio.getBitsPerSample()); Serial.println(audio.getChannels()); Serial.println(audio.getVolume()); Serial.println(""); }

void print_song_time() { //Serial.println(audio.getAudioCurrentTime()); //Serial.println(audio.getAudioFileDuration()); music_info.runtime = audio.getAudioCurrentTime(); music_info.length = audio.getAudioFileDuration(); music_info.volume = audio.getVolume(); }

int get_music_list(fs::FS &fs, const char *dirname, uint8_t levels, String wavlist[30]) { Serial.printf("Listing directory: %s\n", dirname); int i = 0;

File root = fs.open(dirname);
if (!root)
{
    Serial.println("Failed to open directory");
    return i;
}
if (!root.isDirectory())
{
    Serial.println("Not a directory");
    return i;
}

File file = root.openNextFile();
while (file)
{
    if (file.isDirectory())
    {
    }
    else
    {
        String temp = file.name();
        if (temp.endsWith(".wav"))
        {
            wavlist[i] = temp;
            i++;
        }
        else if (temp.endsWith(".mp3"))
        {
            wavlist[i] = temp;
            i++;
        }
    }
    file = root.openNextFile();
}
return i;

}

//** // optional void audio_info(const char info) { Serial.print("info "); Serial.println(info); } void audio_id3data(const char info) { //id3 metadata Serial.print("id3data "); Serial.println(info); }

void audio_eof_mp3(const char info) { //end of file Serial.print("eof_mp3 "); Serial.println(info); file_index++; if (file_index >= file_num) { file_index = 0; } open_new_song(file_list[file_index]); } void audio_showstation(const char info) { Serial.print("station "); Serial.println(info); } void audio_showstreaminfo(const char info) { Serial.print("streaminfo "); Serial.println(info); } void audio_showstreamtitle(const char info) { Serial.print("streamtitle "); Serial.println(info); } void audio_bitrate(const char info) { Serial.print("bitrate "); Serial.println(info); } void audio_commercial(const char info) { //duration in sec Serial.print("commercial "); Serial.println(info); } void audio_icyurl(const char info) { //homepage Serial.print("icyurl "); Serial.println(info); } void audio_lasthost(const char info) { //stream URL played Serial.print("lasthost "); Serial.println(info); } void audio_eof_speech(const char *info) { Serial.print("eof_speech "); Serial.println(info); }

schreibfaul1 commented 1 year ago

The call is: connecttoFS(fs::FS &fs, const char path) String is not const char use filename.c_str()

The-Valveman commented 1 year ago

Thankyou @schreibfaul1 for your help that sorted it as it is now working. I am relatively new to programming this receiver project it certainly testing my somewhat limited programming skills. I have always been more comfortable handling a soldering iron and an oscilloscope than a keyboard lol.