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,36 @@
#include "AudioTools.h"
#include "AudioTools/Concurrency/RP2040.h"
BufferRP2040T<int> buffer(10, 20); //20 blocks with 10 ints->100 ints
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
while (!Serial)
;
delay(1000);
Serial.println("testing...");
assert(buffer.size() == 200);
assert(buffer.available() == 0);
assert(buffer.availableForWrite() == 200);
for (int j = 0; j < 10; j++) {
assert(buffer.write(j));
}
assert(buffer.size() == 200);
assert(buffer.available() == 10);
int tmp[20];
assert(buffer.readArray(tmp, 20) == 10);
for (int j = 0; j < 10; j++) {
assert(tmp[j] == j);
}
assert(buffer.writeArray(tmp, 10) == 10);
Serial.println("success!");
}
void loop() {
}

View File

@@ -0,0 +1,31 @@
#include "AudioTools.h"
#include "AudioTools/Concurrency/RP2040.h"
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
BufferRP2040 buffer(1024, 10);
QueueStream queue(buffer);
CsvOutput<int16_t> csv(Serial);
StreamCopy copierFill(queue, sound); // copies sound into i2s
StreamCopy copierConsume(csv, queue); // copies sound into i2s
void setup(){
Serial.begin(115200);
while(!Serial);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
queue.begin();
sineWave.begin(info, N_B4);
csv.begin(info);
}
void loop(){
copierFill.copy();
}
void loop1(){
copierConsume.copy();
}

View File

@@ -0,0 +1,61 @@
#include "AudioTools.h"
#include "AudioTools/Concurrency/RP2040.h"
SpinLock mutex;
NBuffer<int16_t> nbuffer(512, 10);
SynchronizedBuffer<int16_t> buffer(nbuffer, mutex);
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("starting...");
}
void loop() {
int16_t data[512];
for (int j = 0; j < 512; j++) {
data[j] = j;
}
size_t result = buffer.writeArray(data, 512);
if(result != 512){
// queue is full: give the reading queue some chance to empty
delay(5);
}
}
void loop1() {
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 result = buffer.readArray(data, 512);
if(result == 0){
// reading queue is empty: give some time to fill
delay(5);
return;
}
// 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;
}
}

View File

@@ -0,0 +1,60 @@
#include "AudioTools.h"
#include "AudioTools/Concurrency/RP2040.h"
MutexRP2040 mutex;
NBuffer<int16_t> nbuffer(512, 10);
SynchronizedBuffer<int16_t> buffer(nbuffer, mutex);
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("starting...");
}
void loop() {
int16_t data[512];
for (int j = 0; j < 512; j++) {
data[j] = j;
}
size_t result = buffer.writeArray(data, 512);
if(result != 512){
Serial.print("write failed: ");
Serial.println(result);
}
}
void loop1() {
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 result = buffer.readArray(data, 512);
if(result != 512){
Serial.print("read failed: ");
Serial.println(result);
}
// 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;
}
}