Skip to content

Instantly share code, notes, and snippets.

@tuldok89
Last active September 11, 2019 05:09
Show Gist options
  • Save tuldok89/946e18e5547e21100d12b2734f501235 to your computer and use it in GitHub Desktop.
Save tuldok89/946e18e5547e21100d12b2734f501235 to your computer and use it in GitHub Desktop.
WIP MP3 Player
#include <Arduino.h>
#include <ESP8266HTTPClient.h>
#include <AudioFileSourceSD.h>
#include <cstring>
#include <EDB.h>
#include "crc32.h"
using namespace std;
#define SD_CS 0
#define SPI_MOSI 8
#define SPI_MISO 7
#define SPI_SCK 6
#define I2S_DOUT 21
#define I2S_BLCK 16
#define I2S_LRC 17
File root;
File playlistDb;
uint32_t filesCrc;
void enumerateFiles(vector<string> &files, File dir);
uint32_t getFilesCrc(File dir, uint32_t previousCrc);
void updatePlaylistDb(const char* dbName);
void writer(unsigned long address, const byte* data, unsigned int recsize);
void reader(unsigned long address, byte* data, unsigned int recsize);
void setup()
{
SPI.pins(SPI_SCK, SPI_MISO, SPI_MOSI, SD_CS);
SD.begin(SD_CS);
filesCrc = 0;
root = SD.open("/");
}
void loop()
{
}
void updatePlaylistDb(const char* dbName)
{
File db = SD.open("/playlist.db", FILE_WRITE);
}
uint32_t getFilesCrc(File dir, uint32_t previousCrc)
{
File entry;
uint32_t crc;
while (!(entry = dir.openNextFile()))
{
if (entry.isFile())
{
char* ext = strrchr(entry.name(), '.') + 1; // get file extension
// check file type
if (strcasecmp(ext, "mp3") != 0 && strcasecmp(ext, "aac") != 0)
continue;
crc = crc32(entry.fullName(), strlen(entry.fullName()), previousCrc);
}
else
{
crc = getFilesCrc(entry, previousCrc);
}
}
return crc;
}
void writer(unsigned long address, const byte* data, unsigned int recsize)
{
playlistDb.seek(address);
playlistDb.write(data, recsize);
playlistDb.flush();
}
void reader(unsigned long address, byte* data, unsigned int recsize)
{
playlistDb.seek(address);
playlistDb.read(data,recsize);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment