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,67 @@
/**
* @file synchBufferRTOS.ino
* @author Phil Schatzmann
* @brief Multitask with BufferRTOS
* @version 0.1
* @date 2022-11-25
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/Concurrency/RTOS.h"
BufferRTOS<int16_t> buffer(512 * 10);
Task writeTask("write", 3000, 10, 0);
Task readTask("read", 3000, 10, 1);
void setup() {
Serial.begin(115200);
writeTask.begin([]() {
int16_t data[512];
for (int j = 0; j < 512; j++) {
data[j] = j;
}
size_t len = buffer.writeArray(data, 512);
});
readTask.begin([]() {
static uint64_t start = millis();
static size_t total_bytes = 0;
static size_t errors = 0;
static int16_t data[512];
// read data
size_t read = buffer.readArray(data, 512);
assert(read==512);
// check data
for (int j = 0; j < 512; j++) {
if (data[j] != j) errors++;
}
// calculate bytes per second
total_bytes += sizeof(int16_t) * 512;
if (total_bytes >= 1024000) {
uint64_t duration = millis() - start;
float mbps = static_cast<float>(total_bytes) / duration / 1000.0;
// print result
Serial.print("Mbytes per second: ");
Serial.print(mbps);
Serial.print(" with ");
Serial.print(errors);
Serial.println(" errors");
start = millis();
errors = 0;
total_bytes = 0;
}
});
}
void loop() { delay(1000); }

View File

@@ -0,0 +1,69 @@
/**
* @file NBuffer.ino
* @author Phil Schatzmann
* @brief multi tasks test with unsynchronized NBuffer
* @version 0.1
* @date 2022-11-25
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
NBuffer<int16_t> buffer(512, 4);
Task writeTask("write", 3000, 10, 0);
Task readTask("read", 3000, 10, 1);
void setup() {
Serial.begin(115200);
writeTask.begin([]() {
int16_t data[512];
for (int j = 0; j < 512; j++) {
data[j] = j;
}
assert(buffer.writeArray(data, 512)==512);
// prevent watchdog
delay(1);
});
readTask.begin([]() {
static uint64_t start = millis();
static size_t total_bytes = 0;
static size_t errors = 0;
static int16_t data[512];
// read data
size_t read = buffer.readArray(data, 512);
delay(1);
if (read==0) return;
assert(read==512);
// check data
for (int j = 0; j < 512; j++) {
if (data[j] != j) errors++;
}
// calculate bytes per second
total_bytes += sizeof(int16_t) * 512;
if (total_bytes >= 1024000) {
uint64_t duration = millis() - start;
float mbps = static_cast<float>(total_bytes) / duration / 1000.0;
// print result
Serial.print("Mbytes per second: ");
Serial.print(mbps);
Serial.print(" with ");
Serial.print(errors);
Serial.println(" errors");
start = millis();
errors = 0;
total_bytes = 0;
}
});
}
void loop() { delay(1000); }

View File

@@ -0,0 +1,50 @@
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/Concurrency/RTOS.h"
AudioInfo info(44100, 2, 16);
// source and sink
SineWaveGenerator<int16_t> sineWave(32000);
GeneratedSoundStream<int16_t> sound(sineWave);
AudioBoardStream out(AudioKitEs8388V1);
// queue
// SynchronizedNBuffer buffer(1024, 10);
BufferRTOS<uint8_t> buffer(1024 * 10);
QueueStream<uint8_t> queue(buffer);
// copy
StreamCopy copierSource(queue, sound);
StreamCopy copierSink(out, queue);
// tasks
Task writeTask("write", 3000, 10, 0);
Task readTask("read", 3000, 10, 1);
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// start Queue
queue.begin();
// start I2S
Serial.println("starting I2S...");
auto config = out.defaultConfig(TX_MODE);
config.copyFrom(info);
out.begin(config);
// Setup sine wave
sineWave.begin(info, N_B4);
Serial.println("started...");
writeTask.begin([]() {
copierSource.copy();
});
readTask.begin([]() {
copierSink.copy();
});
Serial.println("started...");
}
void loop() { delay(1000); }

View File

@@ -0,0 +1,69 @@
/**
* @file synchBufferRTOS.ino
* @author Phil Schatzmann
* @brief Multitask with SynchronizedBuffer using NBuffer
* @version 0.1
* @date 2022-11-25
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/Concurrency/RTOS.h"
MutexRTOS mutex;
NBuffer<int16_t> nbuffer(512, 10);
SynchronizedBuffer<int16_t> buffer(nbuffer, mutex);
Task writeTask("write", 3000, 10, 0);
Task readTask("read", 3000, 10, 1);
void setup() {
Serial.begin(115200);
writeTask.begin([]() {
int16_t data[512];
for (int j = 0; j < 512; j++) {
data[j] = j;
}
assert(buffer.writeArray(data, 512)==512);
delay(1);
});
readTask.begin([]() {
static uint64_t start = millis();
static size_t total_bytes = 0;
static size_t errors = 0;
static int16_t data[512];
// read data
assert(buffer.readArray(data, 512)==512);
delay(1);
// check data
for (int j = 0; j < 512; j++) {
if (data[j] != j) errors++;
}
// calculate bytes per second
total_bytes += sizeof(int16_t) * 512;
if (total_bytes >= 1024000) {
uint64_t duration = millis() - start;
float mbps = static_cast<float>(total_bytes) / duration / 1000.0;
// print result
Serial.print("Mbytes per second: ");
Serial.print(mbps);
Serial.print(" with ");
Serial.print(errors);
Serial.println(" errors");
start = millis();
errors = 0;
total_bytes = 0;
}
});
}
void loop() { delay(1000); }

View File

@@ -0,0 +1,69 @@
/**
* @file synchBufferRTOS.ino
* @author Phil Schatzmann
* @brief Multitask with SynchronizedBuffer using RingBuffer
* @version 0.1
* @date 2022-11-25
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/Concurrency/RTOS.h"
MutexRTOS mutex;
RingBuffer<int16_t> nbuffer(512 * 4);
SynchronizedBuffer<int16_t> buffer(nbuffer, mutex);
Task writeTask("write", 3000, 10, 0);
Task readTask("read", 3000, 10, 1);
void setup() {
Serial.begin(115200);
writeTask.begin([]() {
int16_t data[512];
for (int j = 0; j < 512; j++) {
data[j] = j;
}
assert(buffer.writeArray(data, 512)==512);
delay(1);
});
readTask.begin([]() {
static uint64_t start = millis();
static size_t total_bytes = 0;
static size_t errors = 0;
static int16_t data[512];
// read data
assert(buffer.readArray(data, 512)==512);
delay(1);
// check data
for (int j = 0; j < 512; j++) {
if (data[j] != j) errors++;
}
// calculate bytes per second
total_bytes += sizeof(int16_t) * 512;
if (total_bytes >= 1024000) {
uint64_t duration = millis() - start;
float mbps = static_cast<float>(total_bytes) / duration / 1000.0;
// print result
Serial.print("Mbytes per second: ");
Serial.print(mbps);
Serial.print(" with ");
Serial.print(errors);
Serial.println(" errors");
start = millis();
errors = 0;
total_bytes = 0;
}
});
}
void loop() { delay(1000); }