This commit is contained in:
2026-02-12 21:00:02 -08:00
parent 77f8236347
commit 8bdbf227ca
1141 changed files with 1010880 additions and 2 deletions

View File

@@ -0,0 +1,76 @@
#include "SPI.h"
#include "SD.h"
#include "SD_MMC.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
uint8_t data[1024 * 100];
int len[] = { 1, 5, 10, 25, 100, 256, 512, 1024, 1024 * 10, 1024 * 100 };
size_t totalSize = 1024 * 1024 * 1;
const char* test_file = "/test.txt";
void testWrite(Stream& file, int writeSize, int totalSize) {
memset(data, 0, sizeof(data));
int32_t start = millis();
while (totalSize > 0) {
int written = file.write(data, min(writeSize, totalSize));
//Serial.println(written);
//assert(written > 0);
totalSize -= written;
}
}
void testRead(Stream& file, int readSize, int totalSize) {
memset(data, 0, sizeof(data));
while (totalSize > 0) {
int read = file.readBytes(data, min(readSize, totalSize));
//assert(read>0);
totalSize -= read;
}
}
void logTime(uint32_t start, int i, const char* name, const char* op) {
int32_t time = millis() - start;
float thru = (float)totalSize / (float)time / 1000.0;
Serial.printf("%s, %s, %d, %d, %f\n", op, name, i, time, thru);
}
template<typename SD, typename Open>
void testFS(const char* name, SD& sd, Open write, Open read) {
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, write);
file.seek(0);
assert(file);
testWrite(file, i, totalSize);
file.close();
logTime(start, i, name, "Write");
}
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, read);
assert(file);
testRead(file, i, totalSize);
file.close();
logTime(start, i, name, "Read");
}
sd.end();
}
void setup() {
Serial.begin(115200);
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 error");
delay(1000);
}
testFS<fs::SDFS, const char*>("SD", SD, FILE_WRITE, FILE_READ);
}
void loop() {}

View File

@@ -0,0 +1,21 @@
Write, SD, 1, 12813, 0.081837
Write, SD, 5, 4578, 0.229047
Write, SD, 10, 3550, 0.295374
Write, SD, 25, 2927, 0.358243
Write, SD, 100, 2623, 0.399762
Write, SD, 256, 2607, 0.402216
Write, SD, 512, 2571, 0.407848
Write, SD, 1024, 2601, 0.403143
Write, SD, 10240, 2531, 0.414293
Write, SD, 102400, 2451, 0.427816
Read, SD, 1, 13009, 0.080604
Read, SD, 5, 4538, 0.231066
Read, SD, 10, 3478, 0.301488
Read, SD, 25, 2845, 0.368568
Read, SD, 100, 2527, 0.414949
Read, SD, 256, 2463, 0.425731
Read, SD, 512, 2443, 0.429217
Read, SD, 1024, 2432, 0.431158
Read, SD, 10240, 2423, 0.432759
Read, SD, 102400, 2421, 0.433117

View File

@@ -0,0 +1,86 @@
#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
#define SPI_CLOCK SD_SCK_MHZ(10)
uint8_t* data = nullptr;
int len[] = { 1, 5, 10, 25, 100, 256, 512, 1024, 1024 * 10, 1024 * 100 };
size_t totalSize = 1024 * 1024 * 1;
const char* test_file = "/test.txt";
void testWrite(Stream& file, int writeSize, int totalSize) {
memset(data, 0xff, sizeof(data));
int32_t start = millis();
while (totalSize > 0) {
int written = file.write(data, min(writeSize, totalSize));
//Serial.println(written);
//assert(written > 0);
totalSize -= written;
}
}
void testRead(Stream& file, int readSize, int totalSize) {
memset(data, 0, sizeof(data));
while (totalSize > 0) {
int read = file.readBytes(data, min(readSize, totalSize));
//assert(read>0);
totalSize -= read;
}
}
void logTime(uint32_t start, int i, const char* name, const char* op) {
int32_t time = millis() - start;
float thru = (float)totalSize / (float)time / 1000.0;
Serial.printf("%s, %s, %d, %d, %f\n", op, name, i, time, thru);
}
template<typename SD, typename Open>
void testFS(const char* name, SD& sd, Open write, Open read) {
SdSpiConfig cfg(PIN_AUDIO_KIT_SD_CARD_CS, DEDICATED_SPI, SPI_CLOCK, &SPI);
while (!sd.begin(cfg)) {
Serial.print(name);
Serial.println(" error");
delay(1000);
}
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, write);
assert(file);
file.seek(0);
testWrite(file, len[i], totalSize);
file.close();
logTime(start, i, name, "Write");
}
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, read);
assert(file);
testRead(file, len[i], totalSize);
file.close();
logTime(start, i, name, "Read");
}
sd.end();
}
void setup() {
Serial.begin(115200);
// allocate read/write buffer
data = new uint8_t[1024 * 100];
assert(data != nullptr);
// setup SPI pins
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);
delay(1000);
// test SD
SdFat sdfat;
testFS<SdFat, int>("SDFAT", sdfat, FILE_WRITE, FILE_READ);
}
void loop() {}

View File

@@ -0,0 +1 @@
There seems to be a bug in the library, since this is dumping!

View File

@@ -0,0 +1,75 @@
#include "SPI.h"
#include "SD.h"
#include "SD_MMC.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
uint8_t data[1024 * 100];
int len[] = { 1, 5, 10, 25, 100, 256, 512, 1024, 1024 * 10, 1024 * 100 };
size_t totalSize = 1024 * 1024 * 1;
const char* test_file = "/test.txt";
void testWrite(Stream& file, int writeSize, int totalSize) {
memset(data, 0, sizeof(data));
int32_t start = millis();
while (totalSize > 0) {
int written = file.write(data, min(writeSize, totalSize));
//Serial.println(written);
//assert(written > 0);
totalSize -= written;
}
}
void testRead(Stream& file, int readSize, int totalSize) {
memset(data, 0, sizeof(data));
while (totalSize > 0) {
int read = file.readBytes(data, min(readSize, totalSize));
//assert(read>0);
totalSize -= read;
}
}
void logTime(uint32_t start, int i, const char* name, const char* op) {
int32_t time = millis() - start;
float thru = (float)totalSize / (float)time / 1000.0;
Serial.printf("%s, %s, %d, %d, %f\n", op, name, i, time, thru);
}
template<typename SD, typename Open>
void testFS(const char* name, SD& sd, Open write, Open read) {
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, write);
file.seek(0);
assert(file);
testWrite(file, i, totalSize);
file.close();
logTime(start, i, name, "Write");
}
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, read);
assert(file);
testRead(file, i, totalSize);
file.close();
logTime(start, i, name, "Read");
}
sd.end();
}
void setup() {
Serial.begin(115200);
while (!SD_MMC.begin()) {
Serial.println("SDMMC error");
delay(1000);
}
testFS<fs::SDMMCFS, const char*>("SD_MMC", SD_MMC, FILE_WRITE, FILE_READ);
}
void loop() {}

View File

@@ -0,0 +1,40 @@
Write, SD, 1, 12813, 0.081837
Write, SD, 5, 4578, 0.229047
Write, SD, 10, 3550, 0.295374
Write, SD, 25, 2927, 0.358243
Write, SD, 100, 2623, 0.399762
Write, SD, 256, 2607, 0.402216
Write, SD, 512, 2571, 0.407848
Write, SD, 1024, 2601, 0.403143
Write, SD, 10240, 2531, 0.414293
Write, SD, 102400, 2451, 0.427816
Read, SD, 1, 13009, 0.080604
Read, SD, 5, 4538, 0.231066
Read, SD, 10, 3478, 0.301488
Read, SD, 25, 2845, 0.368568
Read, SD, 100, 2527, 0.414949
Read, SD, 256, 2463, 0.425731
Read, SD, 512, 2443, 0.429217
Read, SD, 1024, 2432, 0.431158
Read, SD, 10240, 2423, 0.432759
Read, SD, 102400, 2421, 0.433117
Write, SD_MMC, 1, 10605, 0.098876
Write, SD_MMC, 5, 2384, 0.439839
Write, SD_MMC, 10, 1313, 0.798611
Write, SD_MMC, 25, 728, 1.440352
Write, SD_MMC, 100, 391, 2.681780
Write, SD_MMC, 256, 351, 2.987396
Write, SD_MMC, 512, 313, 3.350083
Write, SD_MMC, 1024, 315, 3.328813
Write, SD_MMC, 10240, 215, 4.877098
Write, SD_MMC, 102400, 109, 9.619963
Read, SD_MMC, 1, 10703, 0.097970
Read, SD_MMC, 5, 2230, 0.470213
Read, SD_MMC, 10, 1171, 0.895453
Read, SD_MMC, 25, 537, 1.952656
Read, SD_MMC, 100, 219, 4.788018
Read, SD_MMC, 256, 155, 6.765007
Read, SD_MMC, 512, 135, 7.767230
Read, SD_MMC, 1024, 124, 8.456258
Read, SD_MMC, 10240, 115, 9.118052
Read, SD_MMC, 102400, 115, 9.118052

View File

@@ -0,0 +1,83 @@
#define AUDIOBOARD_SD
#include "AudioTools.h"
#include "AudioTools/Disk/VFS_SDSPI.h"
#include "AudioTools/Disk/VFSFile.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
const size_t max_len = 1024 * 100;
uint8_t *data = nullptr;
int len[] = { 1, 5, 10, 25, 100, 256, 512, 1024, 1024 * 10, 1024 * 100 };
size_t totalSize = 1024 * 1024 * 1;
const char* test_file = "/test.txt";
void testWrite(Stream& file, int writeSize, int totalSize) {
memset(data, 0, max_len);
int32_t start = millis();
while (totalSize > 0) {
int written = file.write(data, min(writeSize, totalSize));
//Serial.println(written);
//assert(written > 0);
totalSize -= written;
}
}
void testRead(Stream& file, int readSize, int totalSize) {
memset(data, 0, max_len);
while (totalSize > 0) {
int read = file.readBytes(data, min(readSize, totalSize));
//assert(read>0);
totalSize -= read;
}
}
void logTime(uint32_t start, int i, const char* name, const char* op) {
int32_t time = millis() - start;
float thru = (float)totalSize / (float)time / 1000.0;
Serial.printf("%s, %s, %d, %d, %f\n", op, name, i, time, thru);
}
template<typename SD, typename Open>
void testFS(const char* name, SD& sd, Open write, Open read) {
while (!sd.begin()) {
Serial.print(name);
Serial.println(" error");
delay(1000);
}
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, write);
file.seek(0);
assert(file);
testWrite(file, i, totalSize);
file.close();
logTime(start, i, name, "Write");
}
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, read);
assert(file);
testRead(file, i, totalSize);
file.close();
logTime(start, i, name, "Read");
}
sd.end();
}
void setup() {
Serial.begin(115200);
VFS_SDSPI sd;
data = new uint8_t[max_len];
assert(data!=nullptr);
testFS<VFS_SDSPI, FileMode>("VFS_SDSPI", sd, VFS_FILE_WRITE, VFS_FILE_READ);
//testFS<VFS_SDMMC, FileMode>("VFS_SDMMC", sdmmc, VFS_FILE_WRITE, VFS_FILE_READ);
}
void loop() {}

View File

@@ -0,0 +1,22 @@
Write, VFS_SDSPI, 1, 3046, 0.344247
Write, VFS_SDSPI, 5, 2949, 0.355570
Write, VFS_SDSPI, 10, 2931, 0.357754
Write, VFS_SDSPI, 25, 2926, 0.358365
Write, VFS_SDSPI, 100, 2920, 0.359101
Write, VFS_SDSPI, 256, 2925, 0.358488
Write, VFS_SDSPI, 512, 2912, 0.360088
Write, VFS_SDSPI, 1024, 2925, 0.358488
Write, VFS_SDSPI, 10240, 2925, 0.358488
Write, VFS_SDSPI, 102400, 2928, 0.358120
Read, VFS_SDSPI, 1, 2500, 0.419430
Read, VFS_SDSPI, 5, 1521, 0.689399
Read, VFS_SDSPI, 10, 1398, 0.750054
Read, VFS_SDSPI, 25, 1324, 0.791976
Read, VFS_SDSPI, 100, 1287, 0.814744
Read, VFS_SDSPI, 256, 1169, 0.896985
Read, VFS_SDSPI, 512, 1127, 0.930413
Read, VFS_SDSPI, 1024, 936, 1.120274
Read, VFS_SDSPI, 10240, 665, 1.576806
Read, VFS_SDSPI, 102400, 639, 1.640964

View File

@@ -0,0 +1,78 @@
#define AUDIOBOARD_SD
#include "AudioTools.h"
#include "AudioTools/Disk/VFSFile.h"
#include "AudioTools/Disk/VFS_SDMMC.h"
const size_t max_len = 1024 * 100;
uint8_t *data = nullptr;
int len[] = { 1, 5, 10, 25, 100, 256, 512, 1024, 1024 * 10, 1024 * 100 };
size_t totalSize = 1024 * 1024 * 1;
const char* test_file = "/test.txt";
void testWrite(Stream& file, int writeSize, int totalSize) {
memset(data, 0, max_len);
int32_t start = millis();
while (totalSize > 0) {
int written = file.write(data, min(writeSize, totalSize));
//Serial.println(written);
//assert(written > 0);
totalSize -= written;
}
}
void testRead(Stream& file, int readSize, int totalSize) {
memset(data, 0, max_len);
while (totalSize > 0) {
int read = file.readBytes(data, min(readSize, totalSize));
//assert(read>0);
totalSize -= read;
}
}
void logTime(uint32_t start, int i, const char* name, const char* op) {
int32_t time = millis() - start;
float thru = (float)totalSize / (float)time / 1000.0;
Serial.printf("%s, %s, %d, %d, %f\n", op, name, i, time, thru);
}
template<typename SD, typename Open>
void testFS(const char* name, SD& sd, Open write, Open read) {
while (!sd.begin()) {
Serial.print(name);
Serial.println(" error");
delay(1000);
}
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, write);
file.seek(0);
assert(file);
testWrite(file, i, totalSize);
file.close();
logTime(start, i, name, "Write");
}
for (int i : len) {
int32_t start = millis();
auto file = sd.open(test_file, read);
assert(file);
testRead(file, i, totalSize);
file.close();
logTime(start, i, name, "Read");
}
sd.end();
}
void setup() {
Serial.begin(115200);
VFS_SDMMC sdmmc;
data = new uint8_t[max_len];
assert(data!=nullptr);
// testFS<VFS_SDSPI, FileMode>("VFS_SDSPI", sd, VFS_FILE_WRITE, VFS_FILE_READ);
testFS<VFS_SDMMC, FileMode>("VFS_SDMMC", sdmmc, VFS_FILE_WRITE, VFS_FILE_READ);
}
void loop() {}

View File

@@ -0,0 +1,21 @@
Write, VFS_SDMMC, 1, 2478, 0.423154
Write, VFS_SDMMC, 5, 2363, 0.443748
Write, VFS_SDMMC, 10, 2342, 0.447727
Write, VFS_SDMMC, 25, 2336, 0.448877
Write, VFS_SDMMC, 100, 2331, 0.449840
Write, VFS_SDMMC, 256, 2337, 0.448685
Write, VFS_SDMMC, 512, 2325, 0.451000
Write, VFS_SDMMC, 1024, 2335, 0.449069
Write, VFS_SDMMC, 10240, 2337, 0.448685
Write, VFS_SDMMC, 102400, 2336, 0.448877
Read, VFS_SDMMC, 1, 1808, 0.579965
Read, VFS_SDMMC, 5, 827, 1.267928
Read, VFS_SDMMC, 10, 705, 1.487342
Read, VFS_SDMMC, 25, 631, 1.661769
Read, VFS_SDMMC, 100, 594, 1.765279
Read, VFS_SDMMC, 256, 508, 2.064126
Read, VFS_SDMMC, 512, 467, 2.245345
Read, VFS_SDMMC, 1024, 277, 3.785473
Read, VFS_SDMMC, 10240, 88, 11.915637
Read, VFS_SDMMC, 102400, 69, 15.196754

View File

@@ -0,0 +1,45 @@
/**
* @file mp3-SynchronizedRingBuffer.ino
* @author Phil Schatzmann
* @brief Performance test for mp3 decoding form SD on core 1
* @version 0.1
* @date 2022-12-06
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/Disk/AudioSourceSDFAT.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
const char *startFilePath="/";
const char* ext="mp3";
AudioSourceSDFAT source(startFilePath, ext, PIN_AUDIO_KIT_SD_CARD_CS);
MP3DecoderHelix decoder;
MeasuringStream out;
AudioPlayer player(source, out, decoder);
int count=0;
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// sd_active is setting up SPI with the right SD pins by calling
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);
// setup player
player.setDelayIfOutputFull(0);
player.setVolume(0.1);
player.begin();
}
void loop() {
player.copy();
count++;
if (count==100){
Serial.println(out.bytesPerSecond()/32);
count = 0;
}
}

View File

@@ -0,0 +1,84 @@
/**
* @file mp3-BufferRTOS.ino
* @author Phil Schatzmann
* @brief Performance test for mp3 decoding form SD on core 1 and pass the data
* to core 0;
* @version 0.1
* @date 2022-12-06
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/AudioLibs/Concurrency.h"
#include "AudioTools/Disk/AudioSourceSDFAT.h"
const int buffer_count = 30;
const int buffer_size = 512;
const char *startFilePath = "/";
const char *ext = "mp3";
AudioSourceSDFAT source(startFilePath, ext, PIN_AUDIO_KIT_SD_CARD_CS);
MP3DecoderHelix decoder;
BufferRTOS<uint8_t> buffer(buffer_size *buffer_count, buffer_size,
portMAX_DELAY, 10); // fast synchronized buffer
QueueStream<uint8_t> out(buffer); // convert Buffer to Stream
AudioPlayer player(source, out, decoder);
int32_t get_data(uint8_t *data, int32_t bytes);
uint8_t data[buffer_size];
// Performance measurement: Receive data on core 0
Task task("name", 10000, 10, 0);
// Provide data to A2DP
int32_t get_data(uint8_t *data, int32_t bytes) {
size_t result_bytes = buffer.readArray(data, bytes);
// LOGI("get_data_channels %d -> %d of (%d)", bytes, result_bytes ,
// buffer.available());
return result_bytes;
}
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// sd_active is setting up SPI with the right SD pins by calling
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);
// start QueueStream
out.begin();
// setup player
player.setDelayIfOutputFull(0);
player.setVolume(0.1);
player.begin();
// fill buffer with some data
player.getStreamCopy().copyN(5);
// start the task on kernel 0
task.begin([]() {
uint64_t start = millis();
size_t bytes = 0;
for (int i = 0; i < 100; i++) {
bytes += get_data(data, buffer_size);
yield();
}
uint64_t timeMs = millis() - start;
// prevent div by 0
if (timeMs == 0) {
timeMs = 1;
}
// calculate samples per second
size_t samples_per_second = bytes / timeMs * 1000 / 4;
Serial.print("Samples per second: ");
Serial.println(samples_per_second);
});
}
void loop() {
// decode data to buffer
player.copy();
}

View File

@@ -0,0 +1,84 @@
/**
* @file mp3-BufferRTOS.ino
* @author Phil Schatzmann
* @brief Performance test for mp3 decoding form SD on core 1 and pass the data
* to core 0;
* @version 0.1
* @date 2022-12-06
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/AudioLibs/Concurrency.h"
#include "AudioTools/Disk/AudioSourceSDFAT.h"
const int buffer_count = 30;
const int buffer_size = 512;
const char *startFilePath = "/";
const char *ext = "mp3";
AudioSourceSDFAT source(startFilePath, ext, PIN_AUDIO_KIT_SD_CARD_CS);
MP3DecoderHelix decoder;
SynchronizedNBuffer buffer(buffer_size, buffer_count, portMAX_DELAY,
10);
QueueStream<uint8_t> out(buffer); // convert Buffer to Stream
AudioPlayer player(source, out, decoder);
int32_t get_data(uint8_t *data, int32_t bytes);
uint8_t data[buffer_size];
// Performance measurement: Receive data on core 0
Task task("name", 10000, 10, 0);
// Provide data to A2DP
int32_t get_data(uint8_t *data, int32_t bytes) {
size_t result_bytes = buffer.readArray(data, bytes);
// LOGI("get_data_channels %d -> %d of (%d)", bytes, result_bytes ,
// buffer.available());
return result_bytes;
}
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// sd_active is setting up SPI with the right SD pins by calling
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);
// start QueueStream
out.begin();
// setup player
player.setDelayIfOutputFull(0);
player.setVolume(0.1);
player.begin();
// fill buffer with some data
player.getStreamCopy().copyN(5);
// start the task on kernel 0
task.begin([]() {
uint64_t start = millis();
size_t bytes = 0;
for (int i = 0; i < 100; i++) {
bytes += get_data(data, buffer_size);
}
// yield();
uint64_t timeMs = millis() - start;
// prevent div by 0
if (timeMs == 0) {
timeMs = 1;
}
// calculate samples per second
size_t samples_per_second = bytes / timeMs * 1000 / 4;
Serial.print("Samples per second: ");
Serial.println(samples_per_second);
});
}
void loop() {
// decode data to buffer
player.copy();
}

View File

@@ -0,0 +1,85 @@
/**
* @file mp3-SynchronizedRingBuffer.ino
* @author Phil Schatzmann
* @brief Performance test for mp3 decoding form SD on core 1 and pass the data
* to core 0;
* @version 0.1
* @date 2022-12-06
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/AudioLibs/Concurrency.h"
#include "AudioTools/Disk/AudioSourceSDFAT.h"
const int buffer_count = 30;
const int buffer_size = 512;
const char *startFilePath = "/";
const char *ext = "mp3";
AudioSourceSDFAT source(startFilePath, ext, PIN_AUDIO_KIT_SD_CARD_CS);
MP3DecoderHelix decoder;
audio_tools::Mutex mutex;
RingBuffer<uint8_t> nbuffer(buffer_size *buffer_count);
SynchronizedBuffer<uint8_t> buffer(nbuffer, mutex);
QueueStream<uint8_t> out(buffer); // convert Buffer to Stream
AudioPlayer player(source, out, decoder);
int32_t get_data(uint8_t *data, int32_t bytes);
uint8_t data[buffer_size];
// Performance measurement: Receive data on core 0
Task task("name", 10000, 10, 0);
// Provide data to A2DP
int32_t get_data(uint8_t *data, int32_t bytes) {
size_t result_bytes = buffer.readArray(data, bytes);
// LOGI("get_data_channels %d -> %d of (%d)", bytes, result_bytes ,
// buffer.available());
return result_bytes;
}
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// sd_active is setting up SPI with the right SD pins by calling
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);
// start QueueStream
out.begin();
// setup player
player.setDelayIfOutputFull(0);
player.setVolume(0.1);
player.begin();
// fill buffer with some data
player.getStreamCopy().copyN(5);
// start the task on kernel 0
task.begin([]() {
uint64_t start = millis();
size_t bytes = 0;
for (int i = 0; i < 100; i++) {
bytes += get_data(data, buffer_size);
yield();
}
uint64_t timeMs = millis() - start;
// prevent div by 0
if (timeMs == 0) {
timeMs = 1;
}
// calculate samples per second
size_t samples_per_second = bytes / timeMs * 1000 / 4;
Serial.print("Samples per second: ");
Serial.println(samples_per_second);
});
}
void loop() {
// decode data to buffer
player.copy();
}

View File

@@ -0,0 +1,37 @@
#include "AudioTools.h"
SineWaveGenerator<int16_t> sine_wave(32000); // subclass of SoundGenerator with max amplitude of 32000
SineFromTable<int16_t> sine_table(32000); // subclass of SoundGenerator with max amplitude of 32000
FastSineGenerator<int16_t> sine_fast(32000);
size_t measure(SoundGenerator<int16_t> *gen){
uint64_t start = millis();
size_t count = 0;
for(int i=0;i<1000000;i++){
int16_t s = gen->readSample();
}
uint64_t timeMs = millis()-start;
// calculate samples per second
return 1000000.0 / timeMs *1000;
}
const char* resultStr(const char* name, size_t count){
static char msg[160];
sprintf(msg, "%s: %ld", name, count);
return msg;
}
void setup(){
Serial.begin(115200);
Serial.print("Number of samples per sec");
}
void loop(){
Serial.print(resultStr("SineWaveGenerator", measure(&sine_wave)));
Serial.print(" - ");
Serial.print(resultStr("SineFromTable", measure(&sine_table)));
Serial.print(" - ");
Serial.print(resultStr("FastSineGenerator", measure(&sine_fast)));
Serial.println();
}

View File

@@ -0,0 +1,20 @@
#include "AudioTools.h"
AudioInfo info(44100, 2, 16);
SilenceGenerator<int16_t> silence;
GeneratedSoundStream<int16_t> sound(silence);
Throttle throttle(sound);
MeasuringStream out(200, &Serial);
StreamCopy copier(out, throttle);
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
out.begin(info);
sound.begin(info);
throttle.begin(info);
}
void loop() { copier.copy(); }

View File

@@ -0,0 +1,18 @@
#include "AudioTools.h"
#include "AudioTools/Communication/AudioHttp.h"
URLStream url("SSID","PASSWORD"); // or replace with ICYStream to get metadata
MeasuringStream out(50, &Serial); // final output of decoded stream
StreamCopy copier(out, url); // copy url to decoder
void setup(){
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
while(!Serial);
url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128","audio/mp3");
}
void loop(){
copier.copy();
}