snapshot
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Disk/AudioSource.h"
|
||||
#include "SPI.h"
|
||||
#include "SdFat.h"
|
||||
|
||||
#define PIN_AUDIO_KIT_SD_CARD_CS 13
|
||||
#define PIN_AUDIO_KIT_SD_CARD_MISO 2
|
||||
#define PIN_AUDIO_KIT_SD_CARD_MOSI 15
|
||||
#define PIN_AUDIO_KIT_SD_CARD_CLK 14
|
||||
|
||||
// SDFAT objects
|
||||
SdFat sd;
|
||||
File32 file;
|
||||
|
||||
// file names in program mem
|
||||
const char* filesNames[] = {
|
||||
"/Bob Dylan/Bringing It All Back Home/04 Love minus zero_no limit.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/11 It's all over now, Baby Blue.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/06 On the road again.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/08 Mr. Tambourine Man.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/10 It's alright, Ma (I'm only bl.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/02 She belongs to me.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/03 Maggie's farm.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/01 Subterranean homesick blues.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/07 Bob Dylan's 115th dream.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/05 Outlaw blues.mp3",
|
||||
"/Bob Dylan/Bringing It All Back Home/09 Gates of Eden.mp3"};
|
||||
|
||||
// Audio objects
|
||||
File32* fileToStreamCB(const char* path, File32& oldFile);
|
||||
AudioSourceArray<File32> audioSource(filesNames, fileToStreamCB);
|
||||
File32 audioFile;
|
||||
|
||||
// Callback to convert file path to stream for AudioSourceVector
|
||||
File32* fileToStreamCB(const char* path, File32& oldFile) {
|
||||
oldFile.close();
|
||||
audioFile.open(path);
|
||||
|
||||
if (!audioFile) {
|
||||
Serial.print("Failed to open: ");
|
||||
Serial.println(path);
|
||||
return nullptr;
|
||||
}
|
||||
return &audioFile;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioLogger::instance().begin(Serial, AudioLogger::Info);
|
||||
|
||||
Serial.println("AudioSourceVector with SDFAT Test");
|
||||
|
||||
// Initialize SD card
|
||||
SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO,
|
||||
PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
|
||||
if (!sd.begin(PIN_AUDIO_KIT_SD_CARD_CS, SPI_HALF_SPEED)) {
|
||||
Serial.println("SD card initialization failed!");
|
||||
return;
|
||||
}
|
||||
Serial.println("SD card initialized successfully");
|
||||
Serial.print("\nTotal files: ");
|
||||
Serial.println(audioSource.size());
|
||||
|
||||
// Display collected files
|
||||
Serial.println("\n--- Collected Files ---");
|
||||
for (int i = 0; i < audioSource.size(); i++) {
|
||||
Serial.print(i);
|
||||
Serial.print(": ");
|
||||
Serial.println(audioSource.name(i));
|
||||
}
|
||||
|
||||
// Test navigation
|
||||
if (audioSource.size() > 0) {
|
||||
Serial.println("\n--- Testing AudioSource Navigation ---");
|
||||
|
||||
// Start playback simulation
|
||||
audioSource.begin();
|
||||
|
||||
// Select first file
|
||||
File32* stream = audioSource.selectStream(0);
|
||||
if (stream) {
|
||||
Serial.print("Selected file 0: ");
|
||||
Serial.println(audioSource.toStr());
|
||||
stream->close();
|
||||
}
|
||||
|
||||
// Try next file
|
||||
if (audioSource.size() > 1) {
|
||||
stream = audioSource.nextStream(1);
|
||||
if (stream) {
|
||||
Serial.print("Next file: ");
|
||||
Serial.println(audioSource.toStr());
|
||||
stream->close();
|
||||
}
|
||||
}
|
||||
|
||||
// Test selectStream by path
|
||||
if (audioSource.size() > 0) {
|
||||
const char* firstFile = audioSource.name(0);
|
||||
Serial.print("Selecting by path: ");
|
||||
Serial.println(firstFile);
|
||||
|
||||
stream = audioSource.selectStream(firstFile);
|
||||
if (stream) {
|
||||
Serial.println("Successfully selected by path!");
|
||||
stream->close();
|
||||
} else {
|
||||
Serial.println("Failed to select by path");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("\nTest completed!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Nothing to do in loop for this test
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "FS.h"
|
||||
#include "SD.h"
|
||||
#include "SPI.h"
|
||||
#include "AudioTools/Disk/SDIndex.h"
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
|
||||
while (!SD.begin(PIN_AUDIO_KIT_SD_CARD_CS)) {
|
||||
Serial.println("SD.begin failed");
|
||||
delay(1000);
|
||||
}
|
||||
SDIndex<fs::SDFS,fs::File> idx{SD};
|
||||
idx.ls(Serial, "/", "mp3","*");
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#define USE_SDFAT
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include "AudioTools/Disk/SDIndex.h"
|
||||
#define SD_FAT_TYPE 3
|
||||
|
||||
#if SD_FAT_TYPE == 0
|
||||
typedef SdFat AudioFs;
|
||||
typedef File AudioFile;
|
||||
#elif SD_FAT_TYPE == 1
|
||||
typedef SdFat32 AudioFs;
|
||||
typedef File32 AudioFile;
|
||||
#elif SD_FAT_TYPE == 2
|
||||
typedef SdExFat AudioFs;
|
||||
typedef ExFile AudioFile;
|
||||
#elif SD_FAT_TYPE == 3
|
||||
typedef SdFs AudioFs;
|
||||
typedef FsFile AudioFile;
|
||||
#else // SD_FAT_TYPE
|
||||
#endif
|
||||
|
||||
|
||||
AudioFs sd;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
SdSpiConfig cfg(PIN_AUDIO_KIT_SD_CARD_CS, DEDICATED_SPI, SD_SCK_MHZ(2));
|
||||
SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
|
||||
while (!sd.begin(cfg)) {
|
||||
Serial.println("sd.begin failed");
|
||||
delay(1000);
|
||||
}
|
||||
SDIndex<AudioFs,AudioFile> idx(sd);
|
||||
idx.ls(Serial, "/", "mp3","*");
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#define USE_SDFAT
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include "AudioTools/Disk/SDIndex.h"
|
||||
#define SD_FAT_TYPE 3
|
||||
|
||||
#if SD_FAT_TYPE == 0
|
||||
typedef SdFat AudioFs;
|
||||
typedef File AudioFile;
|
||||
#elif SD_FAT_TYPE == 1
|
||||
typedef SdFat32 AudioFs;
|
||||
typedef File32 AudioFile;
|
||||
#elif SD_FAT_TYPE == 2
|
||||
typedef SdExFat AudioFs;
|
||||
typedef ExFile AudioFile;
|
||||
#elif SD_FAT_TYPE == 3
|
||||
typedef SdFs AudioFs;
|
||||
typedef FsFile AudioFile;
|
||||
#else // SD_FAT_TYPE
|
||||
#endif
|
||||
|
||||
|
||||
AudioFs sd;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
SdSpiConfig cfg(PIN_AUDIO_KIT_SD_CARD_CS, DEDICATED_SPI, SD_SCK_MHZ(2));
|
||||
SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
|
||||
while (!sd.begin(cfg)) {
|
||||
Serial.println("sd.begin failed");
|
||||
delay(1000);
|
||||
}
|
||||
SDIndex<AudioFs,AudioFile> idx(sd);
|
||||
idx.ls(Serial, "/", "mp3","*");
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @file test-player.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2022-04-21
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
// install https://github.com/greiman/SdFat.git
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Disk/AudioSourceSDFAT.h"
|
||||
#include "AudioTools/Disk/AudioSourceURL.h"
|
||||
#include "AudioTools/Communication/AudioHttp.h"
|
||||
|
||||
|
||||
const char *urls[] = {
|
||||
"http://stream.srg-ssr.ch/m/rsj/mp3_128",
|
||||
"http://stream.srg-ssr.ch/m/drs3/mp3_128",
|
||||
"http://stream.srg-ssr.ch/m/rr/mp3_128",
|
||||
"http://sunshineradio.ice.infomaniak.ch/sunshineradio-128.mp3",
|
||||
"http://streaming.swisstxt.ch/m/drsvirus/mp3_128"
|
||||
};
|
||||
|
||||
URLStream urlStream("SSID","password");
|
||||
AudioSourceURL source(urlStream, urls, "audio/mp3");
|
||||
|
||||
|
||||
void testUrl(){
|
||||
for (int j=-10;j<10;j++){
|
||||
Stream *out = source.selectStream(j);
|
||||
Serial.printf("%d -> %d / %s \n", j, source.index(), source.toStr());
|
||||
if (out!=nullptr){
|
||||
delay(500);
|
||||
assert(out->available()>0);
|
||||
}
|
||||
}
|
||||
Serial.println("--------------------------");
|
||||
}
|
||||
|
||||
const char *startFilePath="/";
|
||||
const char* ext="mp3";
|
||||
AudioSourceSDFAT sdSource(startFilePath, ext);
|
||||
|
||||
void testSD() {
|
||||
sdSource.setPath("/");
|
||||
sdSource.begin();
|
||||
|
||||
for (int j=-5;j<20;j++){
|
||||
Stream *out = sdSource.selectStream(j);
|
||||
Serial.printf("%d -> %d / %s \n", j, sdSource.index(), sdSource.toStr());
|
||||
if (out!=nullptr){
|
||||
assert(out->available()>0);
|
||||
}
|
||||
}
|
||||
Serial.println("--------------------------");
|
||||
}
|
||||
|
||||
void testSDNext() {
|
||||
sdSource.setPath("/");
|
||||
sdSource.begin();
|
||||
for (int j=0;j<20;j++){
|
||||
Stream *out = sdSource.nextStream(1);
|
||||
Serial.printf("%d -> %d / %s \n", j, sdSource.index(), sdSource.toStr());
|
||||
if (out!=nullptr){
|
||||
assert(out->available()>0);
|
||||
}
|
||||
}
|
||||
Serial.println("--------------------------");
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Error);
|
||||
//testUrl();
|
||||
testSD();
|
||||
testSDNext();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Disk/AudioSource.h"
|
||||
#include "SdFat.h"
|
||||
#include "SPI.h"
|
||||
|
||||
#define PIN_AUDIO_KIT_SD_CARD_CS 13
|
||||
#define PIN_AUDIO_KIT_SD_CARD_MISO 2
|
||||
#define PIN_AUDIO_KIT_SD_CARD_MOSI 15
|
||||
#define PIN_AUDIO_KIT_SD_CARD_CLK 14
|
||||
|
||||
// SDFAT objects
|
||||
SdFat sd;
|
||||
File32 file;
|
||||
const char* path = "/Bob Dylan/Bringing It All Back Home";
|
||||
|
||||
// Audio objects
|
||||
AudioSourceVector<File32> audioSource;
|
||||
NamePrinter namePrinter(audioSource, path);
|
||||
File32 audioFile;
|
||||
|
||||
// Callback to convert file path to stream for AudioSourceVector
|
||||
File32* fileToStream(const char* path, File32& oldFile) {
|
||||
oldFile.close();
|
||||
audioFile.open(path);
|
||||
|
||||
if (!audioFile) {
|
||||
Serial.print("Failed to open: ");
|
||||
Serial.println(path);
|
||||
return nullptr;
|
||||
}
|
||||
return &audioFile;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioLogger::instance().begin(Serial, AudioLogger::Info);
|
||||
|
||||
Serial.println("AudioSourceVector with SDFAT Test");
|
||||
|
||||
// Initialize SD card
|
||||
SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
|
||||
if (!sd.begin(PIN_AUDIO_KIT_SD_CARD_CS, SPI_HALF_SPEED)) {
|
||||
Serial.println("SD card initialization failed!");
|
||||
return;
|
||||
}
|
||||
Serial.println("SD card initialized successfully");
|
||||
|
||||
Serial.println("\n--- Collecting audio files from SD card ---");
|
||||
|
||||
// Set up the callback for AudioSourceVector
|
||||
audioSource.setNameToStreamCallback(fileToStream);
|
||||
|
||||
// Use SDFAT's ls method to list files and automatically add them via NamePrinter
|
||||
// This will print each file name, and NamePrinter will capture each line
|
||||
// and call audioSource.addName() for each file
|
||||
auto dir = sd.open(path, FILE_READ);
|
||||
dir.ls(&namePrinter, 0);
|
||||
dir.close();
|
||||
|
||||
Serial.print("\nTotal files collected: ");
|
||||
Serial.println(audioSource.size());
|
||||
|
||||
// Display collected files
|
||||
Serial.println("\n--- Collected Files ---");
|
||||
for (int i = 0; i < audioSource.size(); i++) {
|
||||
Serial.print(i);
|
||||
Serial.print(": ");
|
||||
Serial.println(audioSource.name(i));
|
||||
}
|
||||
|
||||
// Test navigation
|
||||
if (audioSource.size() > 0) {
|
||||
Serial.println("\n--- Testing AudioSource Navigation ---");
|
||||
|
||||
// Start playback simulation
|
||||
audioSource.begin();
|
||||
|
||||
// Select first file
|
||||
File32* stream = audioSource.selectStream(0);
|
||||
if (stream) {
|
||||
Serial.print("Selected file 0: ");
|
||||
Serial.println(audioSource.toStr());
|
||||
stream->close();
|
||||
}
|
||||
|
||||
// Try next file
|
||||
if (audioSource.size() > 1) {
|
||||
stream = audioSource.nextStream(1);
|
||||
if (stream) {
|
||||
Serial.print("Next file: ");
|
||||
Serial.println(audioSource.toStr());
|
||||
stream->close();
|
||||
}
|
||||
}
|
||||
|
||||
// Test selectStream by path
|
||||
if (audioSource.size() > 0) {
|
||||
const char* firstFile = audioSource.name(0);
|
||||
Serial.print("Selecting by path: ");
|
||||
Serial.println(firstFile);
|
||||
|
||||
stream = audioSource.selectStream(firstFile);
|
||||
if (stream) {
|
||||
Serial.println("Successfully selected by path!");
|
||||
stream->close();
|
||||
} else {
|
||||
Serial.println("Failed to select by path");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("\nTest completed!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Nothing to do in loop for this test
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Disk/AudioSourceVFS.h"
|
||||
#include "AudioTools/Disk/VFS_SDSPI.h"
|
||||
|
||||
// We use an AudioKit or LyraT for the tests which uses the following pins
|
||||
// CS, MOSI, MISO, SCK
|
||||
VFS_SDSPI sd(13, 15, 2, 14);
|
||||
AudioSourceVFS source(sd, "/sdcard", ".mp3");
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
source.begin();
|
||||
for (int j = 0; j < 10; j++) {
|
||||
VFSFile* p_file = (VFSFile*)source.selectStream(j);
|
||||
if (p_file)
|
||||
Serial.println(p_file->name());
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
Reference in New Issue
Block a user