This commit is contained in:
2026-02-12 21:00:02 -08:00
parent cb1f2b0efd
commit 40714a3a68
1141 changed files with 1010880 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
#include "Arduino.h"
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
AudioBoardStream out(AudioKitEs8388V1);
//CsvOutput<int24_t> out(Serial);
SineWaveGenerator<int24_t> sine_wave; // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int24_t> in_stream(sine_wave); // Stream generated from sine wave
StreamCopy copier(out, in_stream); // copies sound to out
void setup(){
Serial.begin(115200);
delay(2000);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
auto cfg = out.defaultConfig();
cfg.bits_per_sample = 24;
out.begin(cfg);
sine_wave.begin(cfg, N_B4);
in_stream.begin(cfg);
}
void loop(){
copier.copy();
}

View File

@@ -0,0 +1,25 @@
#include "AudioTools.h"
struct X {
X() { value = 'a'; }
char value;
};
Vector<X> vector{10, DefaultAllocator};
void setup() {
Serial.begin(115200);
int count = 0;
//vector.resize(10);
for (auto &ref : vector) {
Serial.print(ref.value);
assert(ref.value == 'a');
count++;
}
assert(count == 10);
Serial.println();
Serial.println("test ok");
}
void loop() {}

View File

@@ -0,0 +1,50 @@
#include "AudioTools.h"
// test different buffer implementations
void test(BaseBuffer<int16_t>& b, const char* title) {
Serial.println(title);
assert(b.isEmpty());
for (int j = 0; j < 200; j++) {
assert(b.write(j));
}
assert(b.isFull());
for (int j = 0; j < 200; j++) {
int16_t v = 0;
assert(b.read(v));
assert(v == j);
}
assert(b.isEmpty());
int16_t array[200];
for (int j = 0; j < 200; j++) {
array[j] = j;
}
b.clear();
int len = b.writeArray(array, 200);
Serial.println(len);
len = b.readArray(array, 200);
Serial.println(len);
for (int j = 0; j < 200; j++) {
assert(array[j] == j);
}
Serial.println("Test OK");
}
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
SingleBuffer<int16_t> b1(200);
test(b1, "SingleBuffer");
RingBuffer<int16_t> b2(200);
test(b2, "RingBuffer");
NBuffer<int16_t> b3(50, 4);
test(b3, "NBuffer");
Serial.println("Tests OK");
}
void loop() {}

View File

@@ -0,0 +1,70 @@
/**
* Testing peek and readBytes of BufferedStream
* - fill DynamicMemoryStream with data
* - check data of DynamicMemoryStream
* - peek data
* - check data vis BufferedStream
*/
#include "AudioTools.h"
DynamicMemoryStream data;
BufferedStream buffered(data);
HexDumpOutput out;
const int processingSize = 1024;
uint8_t buffer[processingSize];
void fillData() {
Serial.println("Filling data...");
for (int j = 0; j < processingSize; j++) {
buffer[j] = j % 256;
}
while (data.size() < processingSize * 10) {
assert(data.write(buffer, processingSize) == processingSize);
}
}
void testPeek() {
int len = buffered.peekBytes(&buffer[0], 160);
Serial.println("Peek:");
out.write(buffer, len);
Serial.println();
}
void checkData(Stream &data, bool isPrint = false) {
// check data
Serial.print("TestingData");
int n = data.readBytes(buffer, processingSize);
Serial.print(" ");
Serial.println(n);
while (n == processingSize) {
for (int j = 0; j < processingSize; j++) {
uint8_t expected = j % 256;
if (isPrint) {
Serial.print(buffer[j]);
Serial.print(", ");
Serial.println(expected);
}
assert(buffer[j] == expected);
n = data.readBytes(buffer, processingSize);
assert(n == 0 || n == processingSize);
}
}
Serial.println("test OK!");
}
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
delay(5000);
data.begin();
fillData();
testPeek();
checkData(data);
data.rewind();
checkData(buffered);
}
void loop() {
}

View File

@@ -0,0 +1,45 @@
#include "AudioTools.h"
#include "AudioTools/Concurrency/LockFree/QueueLockFree.h"
#include "AudioTools/Concurrency/RTOS/QueueRTOS.h"
// test different queue implementations:
template <typename T>
void test(T &q, const char* cls){
Serial.println(cls);
assert(q.empty());
for (int j=0;j<10;j++){
q.enqueue(j);
assert(!q.empty());
assert(q.size()==j+1);
}
int number;
for (int j=0;j<10;j++){
q.dequeue(number);
assert(number == j);
assert(q.size()==10-(j+1));
}
assert(q.empty());
Serial.println("ok");
}
void setup() {
Serial.begin(115200);
Queue<int> q1;
test<Queue<int>>(q1,"Queue");
QueueFromVector<int> q2{10, 0};
test<QueueFromVector<int>>(q2,"QueueFromVector");
QueueLockFree<int> q3(10);
test<QueueLockFree<int>>(q3,"QueueLockFree");
QueueRTOS<int> q4(10);
test<QueueRTOS<int>>(q4,"QueueRTOS");
Serial.println("all tests passed");
}
void loop(){}

View File

@@ -0,0 +1,151 @@
#include "AudioTools.h"
void print(const char *title, Vector<int> &vector) {
Serial.println(title);
for (int j = 0; j < vector.size(); j++) {
Serial.print(vector[j]);
Serial.print(" ");
}
Serial.println();
Serial.println();
}
void testPushBack() {
Vector<int> vector;
for (int j = 0; j < 10; j++) {
vector.push_back(j);
}
print("testPushBack", vector);
for (int j = 0; j < 10; j++) {
assert(vector[j] == j);
}
}
void testPushFront() {
Vector<int> vector;
for (int j = 0; j < 10; j++) {
vector.push_front(j);
}
print("testPushFront", vector);
for (int j = 0; j < 10; j++) {
assert(vector[9 - j] == j);
}
}
void testPopFront() {
Vector<int> vector;
for (int j = 0; j < 10; j++) {
vector.push_back(j);
}
vector.pop_front();
print("testPopFront", vector);
assert(vector.size() == 9);
for (int j = 0; j < 9; j++) {
assert(vector[j] == j + 1);
}
}
void testPopBack() {
Vector<int> vector;
for (int j = 0; j < 10; j++) {
vector.push_back(j);
}
vector.pop_back();
print("testPopBack", vector);
assert(vector.size() == 9);
for (int j = 0; j < 9; j++) {
assert(vector[j] == j);
}
}
void testErase() {
Vector<int> vector;
for (int j = 0; j < 10; j++) {
vector.push_back(j);
}
vector.erase(0);
print("testErase", vector);
assert(vector.size() == 9);
for (int j = 0; j < 9; j++) {
assert(vector[j] == j + 1);
}
}
void testCopy() {
Vector<int> vector;
for (int j = 0; j < 10; j++) {
vector.push_back(j);
}
print("testCopy", vector);
for (int j = 0; j < 9; j++) {
assert(vector[j] == j);
}
Vector<int> v1{vector};
assert(v1.size()==10);
for (int j = 0; j < 9; j++) {
assert(v1[j] == j);
}
Vector<int> v2 = vector;
assert(v2.size()==10);
for (int j = 0; j < 9; j++) {
assert(v1[j] == j);
}
vector.erase(0);
assert(v1.size()==10);
assert(v2.size()==10);
}
void testArg1(Vector<int> arg){
print("testArg1", arg);
assert(arg.size()==10);
}
void testArg2(Vector<int> &arg){
print("testArg2", arg);
assert(arg.size()==10);
}
Vector<int> testArg3(Vector<int> arg){
print("testArg3", arg);
Vector<int> result = arg;
assert(result.size()==10);
return result;
}
void testArg() {
Vector<int> vector;
for (int j = 0; j < 10; j++) {
vector.push_back(j);
}
testArg1(vector);
testArg2(vector);
Vector<int> v3 = testArg3(vector);
assert(v3.size()==10);
for (int j = 0; j < 9; j++) {
assert(v3[j] == j);
}
}
void setup() {
Serial.begin(115200);
testPushBack();
testPushFront();
testPopFront();
testPopBack();
testErase();
testCopy();
testArg();
Serial.print("All tests passed");
}
void loop() {}