snapshot
This commit is contained in:
4
libraries/audio-tools/examples/tests/README.md
Normal file
4
libraries/audio-tools/examples/tests/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
# Tests
|
||||
|
||||
These sketches are used to verify that the functionality is working as expected
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file read-csv.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief Test case for the new continuous API of the ESP32:
|
||||
* Default Pins ESP32: 34, 35 (ADC_CHANNEL_6, ADC_CHANNEL_7)
|
||||
* Default Pins ESP32C3: 2, 3 (ADC_CHANNEL_2, ADC_CHANNEL_3)
|
||||
* @version 0.1
|
||||
* @date 2023-11-01
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
|
||||
typedef int16_t audio_t;
|
||||
AudioInfo info(44100, 1, 8 * sizeof(audio_t));
|
||||
// input
|
||||
AnalogAudioStream in;
|
||||
CsvOutput<audio_t> csv(Serial); // ASCII output stream
|
||||
StreamCopy copy_in(csv, in);
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
|
||||
auto cfg_rx = in.defaultConfig(RX_MODE);
|
||||
// cfg_rx.is_auto_center_read = false;
|
||||
// cfg_rx.adc_calibration_active = true;
|
||||
cfg_rx.copyFrom(info);
|
||||
|
||||
in.begin(cfg_rx);
|
||||
|
||||
// open output
|
||||
csv.begin(info);
|
||||
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copy_in.copy();
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file read-csv.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief Test case for the new continuous API of the ESP32:
|
||||
* Default Pins ESP32: 34, 35 (ADC_CHANNEL_6, ADC_CHANNEL_7)
|
||||
* Default Pins ESP32C3: 2, 3 (ADC_CHANNEL_2, ADC_CHANNEL_3)
|
||||
* @version 0.1
|
||||
* @date 2023-11-01
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
|
||||
typedef uint16_t audio_t;
|
||||
AudioInfo info(44100, 1, 8 * sizeof(audio_t));
|
||||
// input
|
||||
AnalogAudioStream in;
|
||||
CsvOutput<audio_t> csv(Serial); // ASCII output stream
|
||||
StreamCopy copy_in(csv, in);
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
|
||||
auto cfg_rx = in.defaultConfig(RX_MODE);
|
||||
//cfg_rx.is_auto_center_read = false;
|
||||
//cfg_rx.adc_calibration_active = true;
|
||||
cfg_rx.copyFrom(info);
|
||||
in.begin(cfg_rx);
|
||||
|
||||
// open output
|
||||
csv.begin(info);
|
||||
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copy_in.copy();
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @file read-esp32-multi-channel-csv.ino
|
||||
* @author Urs Utzinger
|
||||
* @copyright GPLv3
|
||||
*/
|
||||
|
||||
// | attenuation | range | accurate range |
|
||||
// | ------------ | --------| -------------- |
|
||||
// | ADC_ATTEN_DB_0 | 0..1.1V | 100-950mV |
|
||||
// | ADC_ATTEN_DB_2_5| 0..1.5V | 100-1250mV |
|
||||
// | ADC_ATTEN_DB_6 | 0..2.2V | 150-1750mV |
|
||||
// | ADC_ATTEN_DB_12 | 0..3.9V | 150-2450mV |
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "AudioTools.h"
|
||||
|
||||
#define NUM_CHANNELS 6 // number of channels
|
||||
#define DEC_FACTOR 48 // decimating
|
||||
#define ADC_ATTENUATION ADC_ATTEN_DB_12 // ADC attenuation, see above
|
||||
#define ADC_BIT_WIDTH 12 // the ADC bit width 9..12, values will be stored in 16 bit integers
|
||||
#define BIT_DEPTH 16 // default bit width of data returned from analgo_in. Do not change.
|
||||
|
||||
// It looks like Buffer larger than 1024 is capped by stream copy for decimater or csvoutput
|
||||
#define BUFFER_SIZE_FACTOR (1024/ (NUM_CHANNELS*DEC_FACTOR*BIT_DEPTH/8)) // 3.5
|
||||
#define ADC_BUFFER_SIZE (NUM_CHANNELS*DEC_FACTOR*BUFFER_SIZE_FACTOR) // Total number of samples (not bytes), needs to be divisible by 4 // 3*3*96 = 864
|
||||
#define BUFFER_SIZE ADC_BUFFER_SIZE*BIT_DEPTH/8 // Number of bytes for processing buffer
|
||||
#define SERIAL_BUFFER_SIZE BUFFER_SIZE/DEC_FACTOR // There will be factor times less data after decimating
|
||||
|
||||
// Sampling rates
|
||||
#define SERIAL_SAMPLE_RATE 300 // samples per channel per second
|
||||
#define SAMPLE_RATE SERIAL_SAMPLE_RATE*DEC_FACTOR // number of samples per channel before decimating
|
||||
#define ADC_SAMPLE_RATE SAMPLE_RATE*NUM_CHANNELS // actual sampling rate of ADC
|
||||
// BAUD rate required: SERIAL_SAMPLE_RATE * (NUM_CHANNELS * approx 6 chars + 2 EOL) * 10 approx 40,000 baud
|
||||
|
||||
#define ADC0 ADC_CHANNEL_7 // ADC channel 0
|
||||
#define ADC1 ADC_CHANNEL_0 // ADC channel 1
|
||||
#define ADC2 ADC_CHANNEL_3 // ADC channel 2
|
||||
#define ADC3 ADC_CHANNEL_6 // ADC channel 3
|
||||
#define ADC4 ADC_CHANNEL_4 // ADC channel 4
|
||||
#define ADC5 ADC_CHANNEL_5 // ADC channel 5
|
||||
#define ADC6 ADC_CHANNEL_1 // ADC channel 6, not routed on the ESP32 WROOM module
|
||||
#define ADC7 ADC_CHANNEL_2 // ADC channel 7, not routed on ESP32 WROOM module
|
||||
#define ADC8 ADC_CHANNEL_8 // ADC channel 8, only ESP32S3,S2
|
||||
#define ADC9 ADC_CHANNEL_9 // ADC channel 9, only ESP32S3,S2
|
||||
|
||||
AudioInfo info_serial(SERIAL_SAMPLE_RATE, NUM_CHANNELS, BIT_DEPTH);
|
||||
|
||||
AnalogAudioStream analog_in; // on board analog to digital converter
|
||||
Decimate decimater(DEC_FACTOR, NUM_CHANNELS, BIT_DEPTH); // skip samples
|
||||
ConverterStream<int16_t> decimated_stream(analog_in, decimater); // pipe the sound to the decimater
|
||||
CsvOutput<int16_t> serial_out(Serial, NUM_CHANNELS, SERIAL_BUFFER_SIZE); // serial output
|
||||
StreamCopy copier(serial_out, decimated_stream, BUFFER_SIZE); // stream the decimated output to serial port
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
// Include logging to serial, If you want no logging comment this line
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning); // Error, Warning, Info, Debug
|
||||
|
||||
auto adcConfig = analog_in.defaultConfig(RX_MODE);
|
||||
|
||||
// For ESP32 by Espressif Systems version 3.0.0 and later:
|
||||
// see examples/README_ESP32.md
|
||||
adcConfig.sample_rate = SAMPLE_RATE; // sample rate per channel
|
||||
adcConfig.channels = NUM_CHANNELS; // up to 6 channels
|
||||
adcConfig.adc_bit_width = ADC_BIT_WIDTH; // Supports only 12
|
||||
adcConfig.buffer_size = ADC_BUFFER_SIZE; // in total number of samples
|
||||
adcConfig.adc_calibration_active = true; // use and apply the calibration settings of ADC stored in ESP32
|
||||
adcConfig.is_auto_center_read = false; // do not engage auto-centering of signal (would subtract average of signal)
|
||||
adcConfig.adc_attenuation = ADC_ATTENUATION; // set analog input range
|
||||
adcConfig.adc_channels[0] = ADC0; // ensure configuration for each channel
|
||||
adcConfig.adc_channels[1] = ADC1;
|
||||
adcConfig.adc_channels[2] = ADC2;
|
||||
adcConfig.adc_channels[3] = ADC3;
|
||||
adcConfig.adc_channels[4] = ADC4;
|
||||
adcConfig.adc_channels[5] = ADC5;
|
||||
|
||||
analog_in.begin(adcConfig);
|
||||
serial_out.begin(info_serial);
|
||||
|
||||
}
|
||||
|
||||
// Arduino loop
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @file read.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief reads the data from the ADC
|
||||
* Default Pins ESP32: 34, 35 (ADC_CHANNEL_6, ADC_CHANNEL_7)
|
||||
* Default Pins ESP32C3: 2, 3 (ADC_CHANNEL_2, ADC_CHANNEL_3)
|
||||
* @version 0.1
|
||||
* @date 2023-11-11
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*/
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info(44100, 2, 16);
|
||||
AnalogAudioStream adc;
|
||||
MeasuringStream out(10, &Serial);
|
||||
StreamCopy copier(out, adc);
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
#ifdef ESP32
|
||||
LOGI("Supported samples rates: %d - %d", SOC_ADC_SAMPLE_FREQ_THRES_LOW, SOC_ADC_SAMPLE_FREQ_THRES_HIGH);
|
||||
LOGI("Supported bit width: %d - %d", SOC_ADC_DIGI_MIN_BITWIDTH, SOC_ADC_DIGI_MAX_BITWIDTH);
|
||||
#endif
|
||||
|
||||
auto cfg = adc.defaultConfig(RX_MODE);
|
||||
cfg.copyFrom(info);
|
||||
//cfg.use_apll = false; // try with yes
|
||||
if (!adc.begin(cfg)) {
|
||||
LOGE("adc.begin() failed");
|
||||
stop();
|
||||
}
|
||||
|
||||
// make sure that we have the correct channels set up
|
||||
out.begin(info);
|
||||
}
|
||||
|
||||
// Arduino loop - copy data
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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() {}
|
||||
@@ -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() {}
|
||||
@@ -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() {
|
||||
}
|
||||
@@ -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(){}
|
||||
@@ -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() {}
|
||||
@@ -0,0 +1,36 @@
|
||||
// FDK AAC decoding test: psram must be active
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecAACFDK.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "AudioTools/Communication/AudioHttp.h"
|
||||
|
||||
SET_LOOP_TASK_STACK_SIZE(50 * 1024);
|
||||
|
||||
URLStream url("ssid","password"); // or replace with ICYStream to get metadata
|
||||
AudioBoardStream i2s(AudioKitEs8388V1); // final output of decoded stream
|
||||
EncodedAudioStream dec(&i2s, new AACDecoderFDK()); // Decoding stream
|
||||
StreamCopy copier(dec, url); // copy url to decoder
|
||||
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup i2s
|
||||
auto config = i2s.defaultConfig(TX_MODE);
|
||||
config.buffer_size = 1024;
|
||||
config.buffer_count = 20;
|
||||
i2s.begin(config);
|
||||
|
||||
// setup I2S based on sampling rate provided by decoder
|
||||
dec.begin();
|
||||
|
||||
// aac radio
|
||||
url.begin("http://peacefulpiano.stream.publicradio.org/peacefulpiano.aac","audio/aac");
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecAACFDK.h"
|
||||
|
||||
// test case for sine -> aac encoder -> hex output
|
||||
AudioInfo info(44100,2,16);
|
||||
AACEncoderFDK fdk;
|
||||
SineWaveGenerator<int16_t> sineWave;
|
||||
GeneratedSoundStream<int16_t> in(sineWave);
|
||||
HexDumpOutput out(Serial);
|
||||
EncodedAudioStream encoder(&out, &fdk);
|
||||
StreamCopy copier(encoder, in);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioLogger::instance().begin(Serial,AudioLogger::Warning);
|
||||
|
||||
auto cfg = encoder.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
encoder.begin(cfg);
|
||||
|
||||
// start generation of sound
|
||||
sineWave.begin(info, N_B4);
|
||||
}
|
||||
|
||||
|
||||
// copy the data
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @file test-codec-adpcm.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecADPCMXQ.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.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
|
||||
//AudioBoardStream out(AudioKitEs8388V1);
|
||||
//I2SStream out;
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new ADPCMDecoderXQ()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new ADPCMEncoderXQ()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfgs = sineWave.defaultConfig();
|
||||
cfgs.copyFrom(info);
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @file test-codec-adpcm.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* Please install the https://github.com/pschatzmann/adpcm library
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecADPCM.h" // https://github.com/pschatzmann/adpcm
|
||||
//#include "AudioTools/AudioLibs/AudioBoardStream.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
|
||||
//I2SStream out;
|
||||
//AudioBoardStream out(AudioKitEs8388V1);
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
AVCodecID id = AV_CODEC_ID_ADPCM_IMA_WAV;
|
||||
EncodedAudioStream decoder(&out, new ADPCMDecoder(id)); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new ADPCMEncoder(id)); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfgs = sineWave.defaultConfig();
|
||||
cfgs.copyFrom(info);
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @file test-codec-alac.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @note Activate PSRAM or dicrease the frame size e.g. by adding 1024 to the constructor of the enc_alac and dec_alac
|
||||
* @version 0.1
|
||||
*
|
||||
* @copyright Copyright (c) 2025
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecALAC.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
// SET_LOOP_TASK_STACK_SIZE(16*1024); // 16KB - not needed
|
||||
|
||||
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
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
//I2SStream out;
|
||||
//CsvOutput<int16_t> out(Serial);
|
||||
EncoderALAC enc_alac;
|
||||
DecoderALAC dec_alac;
|
||||
CodecNOP dec_nop;
|
||||
EncodedAudioStream decoder(&out, &dec_alac); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, &enc_alac); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Debug);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// optionally copy config from encoder to decoder
|
||||
// since decoder already has audio info and frames
|
||||
// dec_alac.setCodecConfig(enc_alac.config());
|
||||
// dec_alac.setCodecConfig(enc_alac.binaryConfig());
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecAPTX.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(24000, 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
|
||||
//AudioBoardStream out(AudioKitEs8388V1);
|
||||
//I2SStream out;
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new APTXDecoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new APTXEncoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfgs = sineWave.defaultConfig();
|
||||
cfgs.copyFrom(info);
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new DecoderBase64()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new EncoderBase64()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin();
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> csv (Serial)
|
||||
* Unfortunately codec2 needs more stack then we have available in Arduino. So we do the processing
|
||||
* in a separate task with a stack of 20k
|
||||
*
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecCodec2.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
//CsvOutput<int16_t> out(Serial, channels);
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new Codec2Decoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new Codec2Encoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
|
||||
void loop1(void*) {
|
||||
// setup decoder
|
||||
decoder.begin(info);
|
||||
// setup encoder
|
||||
encoder.begin(info);
|
||||
// processing loop
|
||||
while(true){
|
||||
copier.copy();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
auto cfg = out.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
out.begin(cfg);
|
||||
|
||||
int stack = 20000;
|
||||
xTaskCreate(loop1,"loopTask", stack, nullptr,1, nullptr);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecFLAC.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.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
|
||||
HexDumpOutput out(Serial);
|
||||
EncodedAudioStream encoder(&out, new FLACEncoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecG7xx.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new G711_ALAWDecoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new G711_ALAWEncoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecG7xx.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new G711_ULAWDecoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new G711_ULAWEncoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecG7xx.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new G721Decoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new G721Encoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecG722.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(24000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new G722Decoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new G722Encoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecG7xx.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new G723_24Decoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new G723_24Encoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecG7xx.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new G723_40Decoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new G723_40Encoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecGSM.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new GSMDecoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new GSMEncoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @file test-codec-iLBC.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecILBC.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new ILBCDecoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new ILBCEncoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void loop1(void*) {
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
while(true){
|
||||
copier.copy();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
int stack = 20000;
|
||||
xTaskCreate(loop1,"loopTask", stack, nullptr,1, nullptr);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecL8.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(24000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
//I2SStream out;
|
||||
//CsvOutput<int16_t> out(Serial,channels);
|
||||
EncodedAudioStream decoder(&out, new DecoderL8()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new EncoderL8()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);// LC3 does not provide audio info from source
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecLC3.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(24000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
//I2SStream out;
|
||||
//CsvOutput<int16_t> out(Serial,channels);
|
||||
EncodedAudioStream decoder(&out, new LC3Decoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new LC3Encoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);// LC3 does not provide audio info from source
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @file test-codec-opus.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "AudioTools/AudioCodecs/CodecOpus.h"
|
||||
|
||||
AudioInfo info(24000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
OpusAudioDecoder dec;
|
||||
OpusAudioEncoder enc;
|
||||
EncodedAudioStream decoder(&out, &dec); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, &enc); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// Opus encoder and decoder need to know the audio info
|
||||
decoder.begin(info);
|
||||
encoder.begin(info);
|
||||
|
||||
// configure additinal parameters
|
||||
// auto &enc_cfg = enc.config()
|
||||
// enc_cfg.application = OPUS_APPLICATION_RESTRICTED_LOWDELAY;
|
||||
// enc_cfg.frame_sizes_ms_x2 = OPUS_FRAMESIZE_20_MS;
|
||||
// enc_cfg.complexity = 5;
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @file test-codec-opusogg.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "AudioTools/AudioCodecs/CodecOpusOgg.h"
|
||||
|
||||
AudioInfo info(24000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
//CsvOutput<int16_t> out(Serial);
|
||||
OpusOggEncoder enc;
|
||||
OpusOggDecoder dec;
|
||||
EncodedAudioStream decoder(&out, &dec); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, &enc); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Setup output
|
||||
auto cfgo = out.defaultConfig();
|
||||
cfgo.copyFrom(info);
|
||||
out.begin(cfgo);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfgs = sineWave.defaultConfig();
|
||||
cfgs.copyFrom(info);
|
||||
sineWave.begin(cfgs, N_B4);
|
||||
|
||||
// Opus encoder needs to know the audio info
|
||||
encoder.begin(info);
|
||||
decoder.begin(info);
|
||||
|
||||
// configure additinal parameters
|
||||
//enc.config().application = OPUS_APPLICATION_RESTRICTED_LOWDELAY;
|
||||
//enc.config().frame_sizes_ms_x2 = OPUS_FRAMESIZE_20_MS;
|
||||
//enc.config().complexity = 5;
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecSBC.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.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
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new SBCDecoder()); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, new SBCEncoder()); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecWAV.h"
|
||||
#include "AudioTools/AudioCodecs/CodecADPCM.h"
|
||||
|
||||
AudioInfo info(16000, 2, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000);
|
||||
GeneratedSoundStream<int16_t> sound( sineWave);
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
AVCodecID id = AV_CODEC_ID_ADPCM_IMA_WAV;
|
||||
ADPCMDecoder adpcm_decoder(id);
|
||||
ADPCMEncoder adpcm_encoder(id);
|
||||
WAVDecoder wav_decoder(adpcm_decoder, AudioFormat::ADPCM);
|
||||
WAVEncoder wav_encoder(adpcm_encoder, AudioFormat::ADPCM);
|
||||
EncodedAudioStream decoder(&out, &wav_decoder);
|
||||
EncodedAudioStream encoder(&decoder, &wav_encoder);
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start Output
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfgs = sineWave.defaultConfig();
|
||||
cfgs.copyFrom(info);
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/All.h"
|
||||
|
||||
void setup() {
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @file communication-container-binary-meta.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* We demonstrate how to pass any type of metadata from the encoder to the
|
||||
* decoder
|
||||
* @version 0.1
|
||||
* @date 2023-05-18
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecOpus.h"
|
||||
#include "AudioTools/AudioCodecs/ContainerBinary.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
struct MetaData {
|
||||
MetaData(const char* typeArg, float vol) {
|
||||
volume = vol;
|
||||
strncpy(type, typeArg, 5);
|
||||
}
|
||||
MetaData(MetaData* data) {
|
||||
volume = data->volume;
|
||||
strncpy(type, data->type, 5);
|
||||
}
|
||||
|
||||
void log() {
|
||||
Serial.print("====> ");
|
||||
Serial.print(type);
|
||||
Serial.print(": volume ");
|
||||
Serial.println(volume);
|
||||
}
|
||||
|
||||
protected:
|
||||
float volume;
|
||||
char type[5];
|
||||
};
|
||||
|
||||
void metaCallback(uint8_t* data, int len, void*ref) {
|
||||
assert(sizeof(MetaData)==len);
|
||||
MetaData meta((MetaData*)data);
|
||||
meta.log();
|
||||
}
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> sound(sineWave);
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
BinaryContainerDecoder cont_dec(new OpusAudioDecoder());
|
||||
BinaryContainerEncoder cont_enc(new OpusAudioEncoder());
|
||||
EncodedAudioStream decoder(&out, &cont_dec);
|
||||
EncodedAudioStream encoder(&decoder, &cont_enc);StreamCopy copier(encoder, sound);
|
||||
MetaData meta{"opus", 0.5};
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
// receive meta data
|
||||
cont_dec.setMetaCallback(metaCallback);
|
||||
|
||||
// write meta data
|
||||
cont_enc.writeMeta((const uint8_t*)&meta, sizeof(MetaData));
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @file communication-container-binary.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/ContainerBinary.h"
|
||||
#include "AudioTools/AudioCodecs/CodecOpus.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000,1,16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new BinaryContainerDecoder(new OpusAudioDecoder()));
|
||||
EncodedAudioStream encoder(&decoder, new BinaryContainerEncoder(new OpusAudioEncoder()));
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @file communication-codec-test.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief generate sine wave -> encoder -> decoder -> audiokit (i2s)
|
||||
* @version 0.1
|
||||
* @date 2022-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/ContainerOgg.h"
|
||||
#include "AudioTools/AudioCodecs/CodecSBC.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(16000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave( 32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound( sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
OggContainerEncoder enc(new SBCEncoder());
|
||||
OggContainerDecoder dec(new SBCDecoder());
|
||||
//OggContainerEncoder enc;
|
||||
//OggContainerDecoder dec;
|
||||
EncodedAudioStream decoder(&out, &dec); // encode and write
|
||||
EncodedAudioStream encoder(&decoder, &enc); // encode and write
|
||||
StreamCopy copier(encoder, sound);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto cfgi = out.defaultConfig(TX_MODE);
|
||||
cfgi.copyFrom(info);
|
||||
out.begin(cfgi);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start decoder
|
||||
decoder.begin(info);
|
||||
|
||||
// start encoder
|
||||
encoder.begin(info);
|
||||
|
||||
Serial.println("Test started...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
#include "AudioTools/Communication/AudioHttp.h"
|
||||
|
||||
/**
|
||||
* @brief Sketch to test the memory usage with libhelix with an ESP32
|
||||
* => Available heap 140980-151484
|
||||
*/
|
||||
|
||||
|
||||
|
||||
URLStream url("SSID","password");
|
||||
I2SStream i2s; // final output of decoded stream
|
||||
VolumeStream volume(i2s);
|
||||
LogarithmicVolumeControl lvc(0.1);
|
||||
EncodedAudioStream dec(&volume,new MP3DecoderHelix()); // Decoding stream
|
||||
StreamCopy copier(dec, url); // copy url to decoder
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup i2s
|
||||
auto config = i2s.defaultConfig(TX_MODE);
|
||||
i2s.begin(config);
|
||||
|
||||
// setup I2S based on sampling rate provided by decoder
|
||||
dec.begin();
|
||||
|
||||
// set initial volume
|
||||
volume.setVolumeControl(lvc);
|
||||
volume.setVolume(0.5);
|
||||
|
||||
// mp3 radio
|
||||
url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128","audio/mp3");
|
||||
}
|
||||
|
||||
uint32_t i=0;
|
||||
uint32_t minFree=0xFFFFFFFF;
|
||||
uint32_t maxFree=0;
|
||||
uint32_t actFree;
|
||||
|
||||
void minMax(){
|
||||
if (i%1000==0){
|
||||
actFree = ESP.getFreeHeap();
|
||||
if (actFree < minFree){
|
||||
minFree = actFree;
|
||||
}
|
||||
if (actFree > maxFree){
|
||||
maxFree = actFree;
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print(actFree);
|
||||
Serial.print(":");
|
||||
Serial.print(minFree);
|
||||
Serial.print("-");
|
||||
Serial.println(maxFree);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
minMax();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @brief Tesing the MP3DecoderHelix: Decoding
|
||||
* on the input side.
|
||||
*/
|
||||
// install https://github.com/pschatzmann/arduino-libhelix.git
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
#include "BabyElephantWalk60_mp3.h"
|
||||
|
||||
MemoryStream mp3(BabyElephantWalk60_mp3, BabyElephantWalk60_mp3_len);
|
||||
//CsvOutput<int16_t> out(Serial,2);
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream pcm_source(&mp3, new MP3DecoderHelix()); // output to decoder
|
||||
StreamCopy copier(out, pcm_source);
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup I2s
|
||||
out.begin(out.defaultConfig());
|
||||
|
||||
// make sure that i2s is updated
|
||||
pcm_source.addNotifyAudioChange(out);
|
||||
// setup pcm_source
|
||||
pcm_source.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @brief Tesing the MP3DecoderHelix
|
||||
*
|
||||
*/
|
||||
// install https://github.com/pschatzmann/arduino-libhelix.git
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
#include "BabyElephantWalk60_mp3.h"
|
||||
|
||||
MemoryStream mp3(BabyElephantWalk60_mp3, BabyElephantWalk60_mp3_len);
|
||||
//CsvOutput<int16_t> out(Serial,2);
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new MP3DecoderHelix()); // output to decoder
|
||||
StreamCopy copier(decoder, mp3);
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
|
||||
// setup I2s
|
||||
out.begin(out.defaultConfig());
|
||||
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
decoder.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @brief Testing MP3DecoderMAD
|
||||
*
|
||||
*/
|
||||
// install https://github.com/pschatzmann/arduino-libhelix.git
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3MAD.h"
|
||||
#include "BabyElephantWalk60_mp3.h"
|
||||
|
||||
MemoryStream mp3(BabyElephantWalk60_mp3, BabyElephantWalk60_mp3_len);
|
||||
//CsvOutput<int16_t> out(Serial,2);
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
EncodedAudioStream decoder(&out, new MP3DecoderMAD()); // output to decoder
|
||||
StreamCopy copier(decoder, mp3);
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup I2s
|
||||
out.begin(out.defaultConfig());
|
||||
|
||||
decoder.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Disk/AudioSourceSD.h" // or AudioSourceIdxSD.h
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h" // for SD pins
|
||||
|
||||
AudioSourceSD source("/", "", PIN_AUDIO_KIT_SD_CARD_CS);
|
||||
HeaderParserMP3 mp3;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
source.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
File* p_file = (File*) source.nextStream();
|
||||
if (p_file==nullptr) stop();
|
||||
File& file = *p_file;
|
||||
|
||||
uint8_t tmp[1024];
|
||||
int len = file.readBytes((char*)tmp, 1024);
|
||||
|
||||
// check if mp3 file
|
||||
bool is_mp3 = mp3.isValid(tmp, len);
|
||||
|
||||
// print result
|
||||
Serial.print(" ==> ");
|
||||
Serial.print(file.name());
|
||||
Serial.println(is_mp3 ? " +":" -");
|
||||
file.close();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "AudioTools/Communication/AudioHttp.h"
|
||||
|
||||
URLStream url("ssid","password"); // or replace with ICYStream to get metadata
|
||||
AudioBoardStream i2s(AudioKitEs8388V1); // final output of decoded stream
|
||||
MP3DecoderHelix helix;
|
||||
StreamingDecoderAdapter decoder(helix, "audaudio/mpeg");
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup i2s
|
||||
auto config = i2s.defaultConfig(TX_MODE);
|
||||
i2s.begin(config);
|
||||
|
||||
// setup I2S based on sampling rate provided by decoder
|
||||
decoder.setInput(url);
|
||||
decoder.setOutput(i2s);
|
||||
decoder.begin();
|
||||
|
||||
// mp3 radio
|
||||
url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128","audio/mp3");
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
decoder.copy();
|
||||
}
|
||||
@@ -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); }
|
||||
@@ -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); }
|
||||
@@ -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); }
|
||||
@@ -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); }
|
||||
@@ -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); }
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file channel-converter-avg.ino
|
||||
* @brief Test calculating pairwise average of channels
|
||||
* @author Urs Utzinger
|
||||
* @copyright GPLv3
|
||||
**/
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info1(44100, 1, 16);
|
||||
AudioInfo info2(44100, 2, 16);
|
||||
SineWaveGenerator<int16_t> sineWave1(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
SineWaveGenerator<int16_t> sineWave2(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound1(sineWave1); // stream generated from sine wave1
|
||||
GeneratedSoundStream<int16_t> sound2(sineWave2); // stream generated from sine wave2
|
||||
InputMerge<int16_t> imerge; // merge two inputs to stereo
|
||||
ChannelAvg averager; // channel averager
|
||||
ConverterStream<int16_t> averaged_stream(imerge, averager); // pipe the sound to the averager
|
||||
CsvOutput<int16_t> serial_out(Serial); // serial output
|
||||
StreamCopy copier(serial_out, averaged_stream); // stream the binner output to serial port
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
while(!Serial); // wait for Serial to be ready
|
||||
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Setup sine waves
|
||||
sineWave1.begin(info1, N_B4);
|
||||
sineWave2.begin(info1, N_B5);
|
||||
|
||||
// Merge input to stereo
|
||||
imerge.add(sound1, 1);
|
||||
imerge.add(sound2, 1);
|
||||
imerge.begin(info2);
|
||||
|
||||
// Define CSV Output
|
||||
serial_out.begin(info1);
|
||||
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out with conversion
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @file channel-converter-avg.ino
|
||||
* @brief Test calculating average of two channels
|
||||
* @author Urs Utzinger
|
||||
* @copyright GPLv3
|
||||
**/
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
#define BINSIZE 4
|
||||
|
||||
AudioInfo info1(44100, 1, 16);
|
||||
AudioInfo info2(44100, 2, 16);
|
||||
AudioInfo info_out(44100/BINSIZE, 2, 16);
|
||||
SineWaveGenerator<int16_t> sineWave1(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
SineWaveGenerator<int16_t> sineWave2(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound1(sineWave1); // stream generated from sine wave1
|
||||
GeneratedSoundStream<int16_t> sound2(sineWave2); // stream generated from sine wave2
|
||||
InputMerge<int16_t> imerge; // merge two inputs to stereo
|
||||
Bin binner; // channel averager
|
||||
ConverterStream<int16_t> binned_stream(imerge, binner); // pipe the sound to the averager
|
||||
CsvOutput<int16_t> serial_out(Serial); // serial output
|
||||
StreamCopy copier(serial_out, binned_stream); // stream the binner output to serial port
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
while(!Serial); // wait for Serial to be ready
|
||||
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Setup sine waves
|
||||
sineWave1.begin(info1, N_B4);
|
||||
sineWave2.begin(info1, N_B5);
|
||||
|
||||
// Merge input to stereo
|
||||
imerge.add(sound1, 1);
|
||||
imerge.add(sound2, 1);
|
||||
imerge.begin(info2);
|
||||
|
||||
// Configure binning
|
||||
binner.setChannels(2);
|
||||
binner.setBits(16);
|
||||
binner.setBinSize(BINSIZE);
|
||||
binner.setAverage(true);
|
||||
|
||||
// Define CSV Output
|
||||
serial_out.begin(info_out);
|
||||
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out with conversion
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @file channel-converter-bin-diff.ino
|
||||
* @author Urs Utzinger
|
||||
* @brief On two channels reduce number of samples by binning, then compute difference between two channels
|
||||
* @copyright GPLv3
|
||||
**/
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
#define BINSIZE 4
|
||||
|
||||
AudioInfo info1(44100, 1, 16);
|
||||
AudioInfo info2(44100, 2, 16);
|
||||
AudioInfo info_out(44100/BINSIZE, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave1(16000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
SineWaveGenerator<int16_t> sineWave2(16000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound1(sineWave1); // stream generated from sine wave
|
||||
GeneratedSoundStream<int16_t> sound2(sineWave2); // stream generated from sine wave
|
||||
InputMerge<int16_t> imerge;
|
||||
ChannelBinDiff bindiffer; // Binning each channel by average length, setup see below
|
||||
ConverterStream<int16_t> converted_stream(imerge, bindiffer); // pipe the merged sound to the converter
|
||||
CsvOutput<int16_t> serial_out(Serial); // serial output
|
||||
StreamCopy copier(serial_out, converted_stream); // stream the binner output to serial port
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Debug); // Info, Warning, Error, Debug
|
||||
|
||||
// Setup sine wave
|
||||
sineWave1.begin(info1, N_B4);
|
||||
sineWave2.begin(info1, N_B5);
|
||||
|
||||
// Merge input to stereo
|
||||
imerge.add(sound1, 1);
|
||||
imerge.add(sound2, 1);
|
||||
imerge.begin(info2);
|
||||
|
||||
// Setup binning
|
||||
bindiffer.setChannels(2);
|
||||
bindiffer.setBits(16);
|
||||
bindiffer.setBinSize(BINSIZE);
|
||||
bindiffer.setAverage(true);
|
||||
|
||||
// Define CSV Output
|
||||
serial_out.begin(info_out);
|
||||
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out with conversion
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file channel-converter-decimate.ino
|
||||
* @author Urs Utzinger
|
||||
* @brief Reduce samples by binning; which is summing consecutive samples and optionally dividing by the number of samples summed.
|
||||
* @copyright GPLv3
|
||||
**/
|
||||
|
||||
#include "AudioTools.h"
|
||||
#define FACTOR 4
|
||||
|
||||
AudioInfo info1(44100, 1, 16);
|
||||
AudioInfo info2(44100, 2, 16);
|
||||
AudioInfo info_out(44100/FACTOR, 2, 16);
|
||||
SineWaveGenerator<int16_t> sineWave1(16000); // subclass of SoundGenerator with max amplitude of 16000
|
||||
SineWaveGenerator<int16_t> sineWave2(16000); // subclass of SoundGenerator with max amplitude of 16000
|
||||
GeneratedSoundStream<int16_t> sound1(sineWave1); // stream generated from sine wave
|
||||
GeneratedSoundStream<int16_t> sound2(sineWave2); // stream generated from sine wave
|
||||
InputMerge<int16_t> imerge(sound1,sound2);
|
||||
Decimate decimater(FACTOR, 2, 16); // decimate by FACTOR on each channel
|
||||
ConverterStream<int16_t> decimated_stream(imerge, decimater); // pipe the sounds to the decimater
|
||||
CsvOutput<int16_t> serial_out(Serial); // serial output
|
||||
StreamCopy copier(serial_out, decimated_stream); // stream the decimater output to serial port
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
while(!Serial);
|
||||
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave1.begin(info1, N_B4);
|
||||
sineWave2.begin(info1, N_B5);
|
||||
|
||||
// Merge input to stereo
|
||||
imerge.begin(info2);
|
||||
|
||||
// Define CSV Output
|
||||
serial_out.begin(info_out);
|
||||
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out with conversion
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @file channel-converter-diff.ino
|
||||
* @brief Test calculating parwise difference of channels
|
||||
* @author Urs Utzinger
|
||||
* @copyright GPLv3
|
||||
**/
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info1(44100, 1, 16);
|
||||
AudioInfo info2(44100, 2, 16);
|
||||
SineWaveGenerator<int16_t> sineWave1(16000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
SineWaveGenerator<int16_t> sineWave2(16000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound1(sineWave1); // stream generated from sine wave1
|
||||
GeneratedSoundStream<int16_t> sound2(sineWave2); // stream generated from sine wave2
|
||||
InputMerge<int16_t> imerge; // merge two inputs to stereo
|
||||
ChannelDiff differ; // channel averager
|
||||
ConverterStream<int16_t> diffed_stream(imerge, differ); // pipe the sound to the averager
|
||||
CsvOutput<int16_t> serial_out(Serial); // serial output
|
||||
StreamCopy copier(serial_out, diffed_stream); // stream the binner output to serial port
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
while(!Serial); // wait for Serial to be ready
|
||||
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Setup sine waves
|
||||
sineWave1.begin(info1, N_B4);
|
||||
sineWave2.begin(info1, N_B5);
|
||||
|
||||
// Merge input to stereo
|
||||
imerge.add(sound1, 1);
|
||||
imerge.add(sound2, 1);
|
||||
imerge.begin(info2);
|
||||
|
||||
// Define CSV Output
|
||||
serial_out.begin(info1);
|
||||
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out with conversion
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info(44100, 1, 16);
|
||||
uint8_t to_channels = 2; // The stream will have 2 channels
|
||||
SineWaveGenerator<int16_t> sine_wave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> in_stream(sine_wave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial, to_channels); // Output to Serial
|
||||
ChannelFormatConverterStream conv(in_stream);
|
||||
StreamCopy copier(out, conv); // copies converted sound to out
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
sine_wave.begin(info, N_B4);
|
||||
conv.begin(info, to_channels);
|
||||
in_stream.begin();
|
||||
|
||||
out.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info(44100, 1, 16);
|
||||
uint8_t to_channels = 2; // The stream will have 2 channels
|
||||
SineWaveGenerator<int16_t> sine_wave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> in_stream(sine_wave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial, to_channels); // Output to Serial
|
||||
ChannelFormatConverterStream conv(out);
|
||||
StreamCopy copier(conv, in_stream); // copies sound to out
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
sine_wave.begin(info, N_B4);
|
||||
conv.begin(info, to_channels);
|
||||
in_stream.begin();
|
||||
|
||||
out.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info(44100, 2, 16);
|
||||
uint8_t to_channels = 1; // The stream will have 2 channels
|
||||
SineWaveGenerator<int16_t> sine_wave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> in_stream(sine_wave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial, to_channels); // Output to Serial
|
||||
ChannelFormatConverterStream conv(in_stream);
|
||||
StreamCopy copier(out, conv); // copies sound to out
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
sine_wave.begin(info, N_B4);
|
||||
conv.begin(info, to_channels);
|
||||
in_stream.begin();
|
||||
|
||||
out.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info(44100, 2, 16);
|
||||
uint8_t to_channels = 1; // The stream will have 2 channels
|
||||
SineWaveGenerator<int16_t> sine_wave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> in_stream(sine_wave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial, to_channels); // Output to Serial
|
||||
ChannelFormatConverterStream conv(out);
|
||||
StreamCopy copier(conv, in_stream); // copies sound to out
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
sine_wave.begin(info, N_B4);
|
||||
conv.begin(info, to_channels);
|
||||
in_stream.begin();
|
||||
|
||||
out.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo from_info(44100, 2, 32);
|
||||
AudioInfo to_info(44100, 2, 16);
|
||||
SineWaveGenerator<int32_t> sine_wave; // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int32_t> in_stream(sine_wave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial); // Output to Serial
|
||||
FormatConverterStream conv(in_stream);
|
||||
StreamCopy copier(out, conv); // copies sound to out
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
sine_wave.begin(from_info, N_B4);
|
||||
in_stream.begin();
|
||||
|
||||
out.begin(to_info);
|
||||
|
||||
conv.begin(from_info, to_info);
|
||||
assert(out.audioInfo() == to_info);
|
||||
assert(sine_wave.audioInfo() == from_info);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
using target_t = uint32_t; // uint8_t, int8_t, int16_t, uint16_t, int24_t, uint32_t, int32_t, FloatAudio
|
||||
SineWaveGenerator<int16_t> sineWave; // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
CsvOutput<target_t> out(Serial, sound.audioInfo().channels);
|
||||
NumberFormatConverterStreamT<int16_t, target_t> nfc(out);
|
||||
StreamCopy copier(nfc, sound); // copies sound into i2s
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
nfc.begin();
|
||||
out.begin();
|
||||
sineWave.begin();
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.setFrequency(N_B4);
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(48000, 2, 16);
|
||||
AudioInfo info_to(48000, 2, 32);
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
NumberFormatConverterStream nfc(out);
|
||||
StreamCopy copier(nfc, sound); // copies sound into i2s
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
nfc.begin(info.bits_per_sample, info_to.bits_per_sample);
|
||||
|
||||
// start I2S
|
||||
Serial.println("starting I2S...");
|
||||
auto config = out.defaultConfig(TX_MODE);
|
||||
config.copyFrom(info_to);
|
||||
out.begin(config);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
int16_t AR1[] = { 0, 4560, 9031, 13327, 17363, 21062, 24350, 27165, 29450, 31163, 32269, 32747, 32587, 31793, 30381, 28377, 25820, 22761, 19259, 15383, 11206, 6812, 2285, -2285, -6812, -11206, -15383, -19259, -22761, -25820, -28377, -30381, -31793, -32587, -32747, -32269, -31163, -29450, -27165, -24350, -21062, -17363, -13327, -9031, -4560 };
|
||||
|
||||
AudioInfo info(44100, 2, 16);
|
||||
GeneratorFromArray<int16_t> wave(AR1, 0, false);
|
||||
GeneratedSoundStream<int16_t> snd(wave);
|
||||
Pipeline pip;
|
||||
ResampleStream resample;
|
||||
VolumeStream volume;
|
||||
ChannelFormatConverterStream channels;
|
||||
NumberFormatConverterStream bits;
|
||||
AudioBoardStream i2s(AudioKitEs8388V1);
|
||||
//I2SStream i2s;
|
||||
StreamCopy copier(pip, snd);
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
snd.begin(info);
|
||||
resample.setStepSize(0.4f);
|
||||
volume.setVolume(0.5);
|
||||
channels.setToChannels(1);
|
||||
bits.setToBits(16);
|
||||
|
||||
pip.add(resample);
|
||||
pip.add(volume);
|
||||
pip.add(channels);
|
||||
pip.add(bits);
|
||||
pip.setOutput(i2s);
|
||||
pip.begin(info);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
int16_t AR1[] = { 0, 4560, 9031, 13327, 17363, 21062, 24350, 27165, 29450, 31163, 32269, 32747, 32587, 31793, 30381, 28377, 25820, 22761, 19259, 15383, 11206, 6812, 2285, -2285, -6812, -11206, -15383, -19259, -22761, -25820, -28377, -30381, -31793, -32587, -32747, -32269, -31163, -29450, -27165, -24350, -21062, -17363, -13327, -9031, -4560 };
|
||||
|
||||
AudioInfo info(44100, 2, 16);
|
||||
GeneratorFromArray<int16_t> wave(AR1, 0, false);
|
||||
GeneratedSoundStream<int16_t> snd(wave);
|
||||
Pipeline pip;
|
||||
ResampleStream resample;
|
||||
VolumeStream volume;
|
||||
ChannelFormatConverterStream channels;
|
||||
NumberFormatConverterStream bits;
|
||||
AudioBoardStream i2s(AudioKitEs8388V1);
|
||||
//I2SStream i2s;
|
||||
StreamCopy copier(i2s, pip);
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
i2s.begin();
|
||||
resample.setStepSize(0.4f);
|
||||
volume.setVolume(0.5);
|
||||
channels.setToChannels(1);
|
||||
bits.setToBits(16);
|
||||
|
||||
pip.setInput(snd);
|
||||
pip.add(resample);
|
||||
pip.add(volume);
|
||||
pip.add(channels);
|
||||
pip.add(bits);
|
||||
pip.begin(info);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <AudioTools.h>
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
int16_t AR1[] = { 0, 4560, 9031, 13327, 17363, 21062, 24350, 27165, 29450, 31163, 32269, 32747, 32587, 31793, 30381, 28377, 25820, 22761, 19259, 15383, 11206, 6812, 2285, -2285, -6812, -11206, -15383, -19259, -22761, -25820, -28377, -30381, -31793, -32587, -32747, -32269, -31163, -29450, -27165, -24350, -21062, -17363, -13327, -9031, -4560 };
|
||||
|
||||
AudioInfo info(44100, 1, 16);
|
||||
GeneratorFromArray<int16_t> wave(AR1, 0, false);
|
||||
GeneratedSoundStream<int16_t> snd(wave); // Stream generated from array1
|
||||
VolumeStream volume(snd);
|
||||
ResampleStream resample(volume);
|
||||
InputMixer<int16_t> mixer;
|
||||
AudioBoardStream i2s(AudioKitEs8388V1);
|
||||
StreamCopy copier(i2s, mixer);
|
||||
|
||||
// Arduino Setup
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
auto rcfg1 = resample.defaultConfig();
|
||||
rcfg1.copyFrom(info);
|
||||
rcfg1.step_size = 0.6;
|
||||
resample.begin(rcfg1);
|
||||
|
||||
// start I2S internal
|
||||
auto config = i2s.defaultConfig(TX_MODE);
|
||||
config.copyFrom(info);
|
||||
config.use_apll = false;
|
||||
i2s.begin(config);
|
||||
|
||||
mixer.add(resample); //SOUND1
|
||||
mixer.begin(info);
|
||||
|
||||
//waveAR1.begin(info);
|
||||
snd.begin(info);
|
||||
|
||||
volume.begin(info);
|
||||
volume.setVolume(1.0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(44100, 2, 32);
|
||||
SineWaveGenerator<int32_t> sineWave; // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int32_t> sound(sineWave); // Stream generated from sine wave
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
VolumeStream volume(out);
|
||||
StreamCopy copier(volume, sound); // copies sound into i2s
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
//AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
// start input sound
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// start I2S in
|
||||
auto cfg = out.defaultConfig(TX_MODE);
|
||||
cfg.copyFrom(info);
|
||||
out.begin(cfg);
|
||||
// set AudioKit to full volume
|
||||
out.setVolume(1.0);
|
||||
|
||||
// setup volume
|
||||
volume.begin(info);
|
||||
volume.setVolume(0.0, 0);
|
||||
volume.setVolume(0.3, 1);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
copier.copy(); // Arduino loop - copy sound to out
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "AudioTools.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
|
||||
ResampleStream resample(sound);
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
StreamCopy copier(out, resample); // copies sound to out
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// define resample
|
||||
auto rcfg = resample.defaultConfig();
|
||||
rcfg.copyFrom(info);
|
||||
rcfg.step_size = 0.5;
|
||||
resample.begin(rcfg);
|
||||
|
||||
// Define CSV Output
|
||||
out.begin(info);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
ResampleStream resample(out);
|
||||
StreamCopy copier(resample, sound); // copies sound to out
|
||||
AudioInfo info(44100,2,16);
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// define resample
|
||||
auto rcfg = resample.defaultConfig();
|
||||
rcfg.copyFrom(info);
|
||||
rcfg.step_size = 0.5;
|
||||
resample.begin(rcfg);
|
||||
|
||||
// Define CSV Output
|
||||
auto config = out.defaultConfig();
|
||||
config.copyFrom(info);
|
||||
out.begin(config);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @file test-volumestream.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief test for VolumeStream class
|
||||
* @copyright GPLv3
|
||||
**/
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo audio_info(44100, 2, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave);
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
VolumeStream vol(out);
|
||||
StreamCopy copier(vol, sound);
|
||||
float f_volume = 0.1;
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Define CSV Output
|
||||
out.begin(audio_info);
|
||||
vol.begin(audio_info);
|
||||
vol.setVolume(f_volume);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(audio_info, N_B4);
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
int hz = 200;
|
||||
AudioInfo info(44100, 1, 16);
|
||||
SineWaveGenerator<int16_t> sine;
|
||||
GeneratedSoundStream<int16_t> gen(sine);
|
||||
AudioEffectStream effects(gen); // apply effects to input: reading from gen
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
StreamCopy copier(out, effects);
|
||||
Delay dly(998, 0.5, 1.0, info.sample_rate);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// setup effects
|
||||
effects.addEffect(dly);
|
||||
|
||||
// Setup audio objects
|
||||
out.begin(info);
|
||||
sine.begin(info, hz);
|
||||
gen.begin(info);
|
||||
effects.begin(info);
|
||||
}
|
||||
// copy the data
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info(44100, 1, 16);
|
||||
int hz = 200;
|
||||
SineWaveGenerator<int16_t> sine;
|
||||
GeneratedSoundStream<int16_t> gen(sine);
|
||||
CsvOutput<int16_t> csv(Serial);
|
||||
AudioEffectStream effects(csv); // apply effects to output: writing to effects
|
||||
StreamCopy copier(effects, gen);
|
||||
Delay dly(998, 0.5, 1.0,info.sample_rate);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// setup effects
|
||||
effects.addEffect(dly);
|
||||
|
||||
// Setup audio objects
|
||||
csv.begin(info);
|
||||
sine.begin(info, hz);
|
||||
gen.begin(info);
|
||||
effects.begin(info);
|
||||
}
|
||||
// copy the data
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
int pitch_buffer_size = 256;
|
||||
float pitch_shift = 1.5;
|
||||
AudioInfo info(44100, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
//PitchShiftOutput<int16_t, VariableSpeedRingBufferSimple<int16_t>> pitchShift(out);
|
||||
PitchShiftOutput<int16_t, VariableSpeedRingBuffer180<int16_t>> pitchShift(out);
|
||||
//PitchShiftOutput<int16_t, VariableSpeedRingBuffer<int16_t>> pitchShift(out);
|
||||
StreamCopy copier(pitchShift, sound); // copies sound to out
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Define CSV Output
|
||||
out.begin(info);
|
||||
|
||||
auto pcfg = pitchShift.defaultConfig();
|
||||
pcfg.copyFrom(info);
|
||||
pcfg.pitch_shift = pitch_shift;
|
||||
pcfg.buffer_size = pitch_buffer_size;
|
||||
pitchShift.begin(pcfg);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
int pitch_buffer_size = 256;
|
||||
float pitch_shift = 1.5;
|
||||
AudioInfo info(44100, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
PitchShiftOutput<int16_t, VariableSpeedRingBufferSimple<int16_t>> pitchShift(out);
|
||||
//PitchShiftOutput<int16_t, VariableSpeedRingBuffer180<int16_t>> pitchShift(out);
|
||||
//PitchShiftOutput<int16_t, VariableSpeedRingBuffer<int16_t>> pitchShift(out);
|
||||
StreamCopy copier(pitchShift, sound); // copies sound to out
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Define CSV Output
|
||||
out.begin(info);
|
||||
|
||||
auto pcfg = pitchShift.defaultConfig();
|
||||
pcfg.copyFrom(info);
|
||||
pcfg.pitch_shift = pitch_shift;
|
||||
pcfg.buffer_size = pitch_buffer_size;
|
||||
pitchShift.begin(pcfg);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
int pitch_buffer_size = 256;
|
||||
float pitch_shift = 1.5;
|
||||
AudioInfo info(44100, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
CsvOutput<int16_t> out(Serial);
|
||||
//PitchShiftOutput<int16_t, VariableSpeedRingBufferSimple<int16_t>> pitchShift(out);
|
||||
//PitchShiftOutput<int16_t, VariableSpeedRingBuffer180<int16_t>> pitchShift(out);
|
||||
PitchShiftOutput<int16_t, VariableSpeedRingBuffer<int16_t>> pitchShift(out);
|
||||
StreamCopy copier(pitchShift, sound); // copies sound to out
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Define CSV Output
|
||||
out.begin(info);
|
||||
|
||||
auto pcfg = pitchShift.defaultConfig();
|
||||
pcfg.copyFrom(info);
|
||||
pcfg.pitch_shift = pitch_shift;
|
||||
pcfg.buffer_size = pitch_buffer_size;
|
||||
pitchShift.begin(pcfg);
|
||||
|
||||
// Setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(44100, 2, 16);
|
||||
SineWaveGenerator<int32_t> sineWave; // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int32_t> sound(sineWave); // Stream generated from sine wave
|
||||
auto invert = [](uint8_t* data, size_t bytes) {
|
||||
size_t sample_count = bytes / sizeof(int16_t);
|
||||
int16_t* data16 = (int16_t*)data;
|
||||
for (int j = 0; j < sample_count; j++) {
|
||||
data16[j] = -data16[j];
|
||||
}
|
||||
return bytes;
|
||||
};
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
CallbackStream cb(out, invert);
|
||||
StreamCopy copier(cb, sound); // copies sound into i2s
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
//AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
// start input sound
|
||||
sineWave.begin(info, N_B4);
|
||||
cb.begin(info);
|
||||
|
||||
// start I2S in
|
||||
auto cfg = out.defaultConfig(TX_MODE);
|
||||
cfg.copyFrom(info);
|
||||
out.begin(cfg);
|
||||
// set AudioKit to full volume
|
||||
out.setVolume(0.3);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
copier.copy(); // Arduino loop - copy sound to out
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
I2SStream s1;
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
I2SStream s2;
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
I2SStream s3;
|
||||
|
||||
void setup(){
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
/**
|
||||
* @brief Pin Tests for AudioKit
|
||||
*
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
for (int j=10;j<=36;j++){
|
||||
pinMode(j, INPUT_PULLUP);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int j=10;j<=36;j++){
|
||||
int value = digitalRead(j);
|
||||
Serial.print(value ? "-":"+");
|
||||
}
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* @file test-ringbufferfile.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief genTest for the file backed ringbuffer
|
||||
* @version 0.1
|
||||
* @date 2023-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Test for the file backed ringbuffer
|
||||
*/
|
||||
#include <SdFat.h>
|
||||
|
||||
#include "AudioTools.h"
|
||||
// SD pins
|
||||
#define PIN_SD_CARD_CS 13
|
||||
#define PIN_SD_CARD_MISO 2
|
||||
#define PIN_SD_CARD_MOSI 15
|
||||
#define PIN_SD_CARD_CLK 14
|
||||
|
||||
const char* file_name = "/tmp.bin";
|
||||
SdFs SD;
|
||||
FsFile file;
|
||||
RingBufferFile<FsFile, int16_t> buffer(file);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup SD
|
||||
SPI.begin(PIN_SD_CARD_CLK, PIN_SD_CARD_MISO, PIN_SD_CARD_MOSI,
|
||||
PIN_SD_CARD_CS);
|
||||
while (!SD.begin(PIN_SD_CARD_CS, SPI_HALF_SPEED)) {
|
||||
Serial.println("Card Mount Failed");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// create file and setup buffer
|
||||
file = SD.open(file_name, O_RDWR | O_CREAT);
|
||||
if (!file) {
|
||||
Serial.println("Failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
if (!buffer.begin(file)) {
|
||||
Serial.println("Failed to create buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
// test write
|
||||
for (int j = 0; j < 10; j++) {
|
||||
buffer.write(j);
|
||||
}
|
||||
|
||||
// test write array
|
||||
int16_t tmp[10];
|
||||
for (int j = 0; j < 10; j++) {
|
||||
tmp[j] = j;
|
||||
}
|
||||
buffer.writeArray(tmp, 10);
|
||||
|
||||
// test read
|
||||
Serial.println("read");
|
||||
for (int j = 0; j < 10; j++) {
|
||||
int16_t result;
|
||||
if (buffer.read(result)) {
|
||||
Serial.print(result);
|
||||
Serial.print(" ");
|
||||
}
|
||||
assert(result == j);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// test read array
|
||||
Serial.print("readArray");
|
||||
Serial.print(" ");
|
||||
Serial.println(buffer.available());
|
||||
memset(tmp, 0, 10 * sizeof(int16_t));
|
||||
|
||||
int max = buffer.readArray(tmp, buffer.available());
|
||||
for (int j = 0; j < max; j++) {
|
||||
Serial.print(tmp[j]);
|
||||
Serial.print(" ");
|
||||
assert(j == tmp[j]);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
file.close();
|
||||
Serial.println("Test success!");
|
||||
|
||||
// cleanup
|
||||
SD.remove(file_name);
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
@@ -0,0 +1,57 @@
|
||||
// TDM test using a RP2040 with a CS42448 DAC
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
const AudioInfo info_in(44100, 1, 16);
|
||||
const AudioInfo info_out(44100, 8, 16);
|
||||
const MusicalNotes notes;
|
||||
Vector<SineWaveGenerator<int16_t>> sineWaves{info_out.channels};
|
||||
Vector<GeneratedSoundStream<int16_t>> sound{info_out.channels};
|
||||
InputMerge<int16_t> imerge; // merge to 8 channels
|
||||
DriverPins dac_pins;
|
||||
AudioBoard board(AudioDriverCS42448, dac_pins);
|
||||
AudioBoardStream tdm(board);
|
||||
StreamCopy copier(tdm, imerge);
|
||||
|
||||
// we use the AudioBoard API to set up the pins for the DAC
|
||||
void setupDACPins() {
|
||||
// add i2c codec pins: scl, sda, port
|
||||
dac_pins.addI2C(PinFunction::CODEC, 4, 5);
|
||||
// add i2s pins: mclk, bck, ws,data_out, data_in ,(port)
|
||||
dac_pins.addI2S(PinFunction::CODEC,-1, 3, 4, 5, -1);
|
||||
}
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup input sound and merge -> we get an merge with 8 channels
|
||||
for (int j = 0; j < info_out.channels; j++) {
|
||||
// use a different tone for each channel
|
||||
sineWaves[j].begin(info_in, notes.frequency(j * 2));
|
||||
// setup GeneratedSoundStream
|
||||
sound[j].setInput(sineWaves[j]);
|
||||
sound[j].begin(info_in);
|
||||
// setup merge input stream channels
|
||||
imerge.add(sound[j], 1);
|
||||
}
|
||||
|
||||
// setup DAC pins
|
||||
setupDACPins();
|
||||
|
||||
// setup DAC & I2S
|
||||
auto cfg = tdm.defaultConfig();
|
||||
cfg.copyFrom(info_out);
|
||||
cfg.input_device = ADC_INPUT_NONE;
|
||||
cfg.output_device = DAC_OUTPUT_ALL;
|
||||
cfg.signal_type = TDM;
|
||||
tdm.begin();
|
||||
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
#define SAMPLE_COUNT 2048
|
||||
#define SAMPLE_BUFFER_SIZE sizeof(int32_t) * SAMPLE_COUNT
|
||||
unsigned char raw_data[SAMPLE_BUFFER_SIZE];
|
||||
AudioInfo info(8000, 1, 32);
|
||||
I2SStream i2sStream; // Access I2S as stream
|
||||
MemoryStream raw_samples(raw_data, SAMPLE_BUFFER_SIZE, true, RAM);
|
||||
StreamCopy copier(raw_samples, i2sStream, 1024); // copies sound
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
auto cfg = i2sStream.defaultConfig(RX_MODE);
|
||||
cfg.copyFrom(info);
|
||||
i2sStream.begin(cfg);
|
||||
|
||||
raw_samples.begin();
|
||||
|
||||
copier.copy();
|
||||
|
||||
assert(raw_samples.available()== 1024);
|
||||
assert(raw_samples.availableForWrite()== 7168);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioCmsisFFT.h" // using CMSIS DSP
|
||||
|
||||
AudioCmsisFFT fft; // or AudioKissFFT
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> in(sineWave);
|
||||
StreamCopy copier(fft, in);
|
||||
AudioInfo info(44100, 1, 16);
|
||||
float value = 0;
|
||||
|
||||
// display fft result
|
||||
void fftResult(AudioFFTBase &fft) {
|
||||
float diff;
|
||||
auto result = fft.result();
|
||||
if (result.magnitude > 100) {
|
||||
Serial.print(result.frequency);
|
||||
Serial.print(" ");
|
||||
Serial.print(result.magnitude);
|
||||
Serial.print(" => ");
|
||||
Serial.print(result.frequencyAsNote(diff));
|
||||
Serial.print(" diff: ");
|
||||
Serial.print(diff);
|
||||
Serial.print(" - time ms ");
|
||||
Serial.print(fft.resultTime() - fft.resultTimeBegin());
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
while(!Serial);
|
||||
|
||||
// set the frequency
|
||||
sineWave.setFrequency(N_B4);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfg = in.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
in.begin(cfg);
|
||||
|
||||
// Setup FFT
|
||||
auto tcfg = fft.defaultConfig();
|
||||
tcfg.copyFrom(info);
|
||||
tcfg.length = 4096;
|
||||
tcfg.callback = &fftResult;
|
||||
fft.begin(tcfg);
|
||||
}
|
||||
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioESP32FFT.h" // Using ESP32FFT
|
||||
|
||||
AudioESP32FFT fftc; // or AudioKissFFT
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> in(sineWave);
|
||||
StreamCopy copier(fftc, in);
|
||||
AudioInfo info(44100, 1, 16);
|
||||
float value = 0;
|
||||
|
||||
// display fftc result
|
||||
void fftcResult(AudioFFTBase &fftc) {
|
||||
float diff;
|
||||
auto result = fftc.result();
|
||||
if (result.magnitude > 100) {
|
||||
Serial.print(result.frequency);
|
||||
Serial.print(" ");
|
||||
Serial.print(result.magnitude);
|
||||
Serial.print(" => ");
|
||||
Serial.print(result.frequencyAsNote(diff));
|
||||
Serial.print(" diff: ");
|
||||
Serial.print(diff);
|
||||
Serial.print(" - time ms ");
|
||||
Serial.print(fftc.resultTime() - fftc.resultTimeBegin());
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// set the frequency
|
||||
sineWave.setFrequency(N_B4);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfg = in.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
in.begin(cfg);
|
||||
|
||||
// Setup FFT
|
||||
auto tcfg = fftc.defaultConfig();
|
||||
tcfg.copyFrom(info);
|
||||
tcfg.length = 4096;
|
||||
tcfg.callback = &fftcResult;
|
||||
fftc.begin(tcfg);
|
||||
}
|
||||
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioEspressifFFT.h" // Using Espressif DSP Library
|
||||
|
||||
AudioEspressifFFT fftc;
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> in(sineWave);
|
||||
StreamCopy copier(fftc, in);
|
||||
AudioInfo info(44100, 1, 16);
|
||||
float value = 0;
|
||||
|
||||
// display fftc result
|
||||
void fftcResult(AudioFFTBase &fftc) {
|
||||
float diff;
|
||||
auto result = fftc.result();
|
||||
if (result.magnitude > 100) {
|
||||
Serial.print(result.frequency);
|
||||
Serial.print(" ");
|
||||
Serial.print(result.magnitude);
|
||||
Serial.print(" => ");
|
||||
Serial.print(result.frequencyAsNote(diff));
|
||||
Serial.print(" diff: ");
|
||||
Serial.print(diff);
|
||||
Serial.print(" - time ms ");
|
||||
Serial.print(fftc.resultTime() - fftc.resultTimeBegin());
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// set the frequency
|
||||
sineWave.setFrequency(N_B4);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfg = in.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
in.begin(cfg);
|
||||
|
||||
// Setup FFT
|
||||
auto tcfg = fftc.defaultConfig();
|
||||
tcfg.copyFrom(info);
|
||||
tcfg.length = 4096;
|
||||
tcfg.callback = &fftcResult;
|
||||
fftc.begin(tcfg);
|
||||
}
|
||||
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioRealFFT.h" // using RealFFT
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
AudioRealFFT afft; // or AudioKissFFT
|
||||
Hann hann;
|
||||
BufferedWindow buffered(&hann);
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> in(sineWave);
|
||||
StreamCopy copier(afft, in);
|
||||
//CsvOutput<int16_t> out(Serial);
|
||||
//I2SStream out;
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
StreamCopy copierIFFT(out, afft);
|
||||
|
||||
// process fft result
|
||||
void fftResult(AudioFFTBase &fft) {
|
||||
// copy ifft result to output
|
||||
while (copierIFFT.copy());
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// set the frequency
|
||||
sineWave.setFrequency(N_B4);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfg = in.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
in.begin(cfg);
|
||||
|
||||
// Setup FFT
|
||||
auto tcfg = afft.defaultConfig(RXTX_MODE);
|
||||
tcfg.copyFrom(info);
|
||||
tcfg.length = 1024;
|
||||
//tcfg.window_function = &buffered;
|
||||
//tcfg.stride = 512;
|
||||
tcfg.callback = fftResult;
|
||||
afft.begin(tcfg);
|
||||
|
||||
// setup output
|
||||
auto ocfg = out.defaultConfig(TX_MODE);
|
||||
ocfg.copyFrom(info);
|
||||
out.begin(ocfg);
|
||||
}
|
||||
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioKissFFT.h" // Using KissFFT
|
||||
|
||||
AudioKissFFT fft; // or AudioKissFFT
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> in(sineWave);
|
||||
StreamCopy copier(fft, in);
|
||||
AudioInfo info(44100, 1, 16);
|
||||
float value = 0;
|
||||
|
||||
// display fft result
|
||||
void fftResult(AudioFFTBase &fft) {
|
||||
float diff;
|
||||
auto result = fft.result();
|
||||
if (result.magnitude > 100) {
|
||||
Serial.print(result.frequency);
|
||||
Serial.print(" ");
|
||||
Serial.print(result.magnitude);
|
||||
Serial.print(" => ");
|
||||
Serial.print(result.frequencyAsNote(diff));
|
||||
Serial.print(" diff: ");
|
||||
Serial.print(diff);
|
||||
Serial.print(" - time ms ");
|
||||
Serial.print(fft.resultTime() - fft.resultTimeBegin());
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// set the frequency
|
||||
sineWave.setFrequency(N_B4);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfg = in.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
in.begin(cfg);
|
||||
|
||||
// Setup FFT
|
||||
auto tcfg = fft.defaultConfig();
|
||||
tcfg.copyFrom(info);
|
||||
tcfg.length = 4096;
|
||||
tcfg.callback = &fftResult;
|
||||
fft.begin(tcfg);
|
||||
}
|
||||
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioRealFFT.h" // using RealFFT
|
||||
|
||||
AudioRealFFT fft; // or AudioKissFFT
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> in(sineWave);
|
||||
StreamCopy copier(fft, in);
|
||||
AudioInfo info(44100, 1, 16);
|
||||
float value = 0;
|
||||
|
||||
// display fft result
|
||||
void fftResult(AudioFFTBase &fft) {
|
||||
float diff;
|
||||
auto result = fft.result();
|
||||
if (result.magnitude > 100) {
|
||||
Serial.print(result.frequency);
|
||||
Serial.print(" ");
|
||||
Serial.print(result.magnitude);
|
||||
Serial.print(" => ");
|
||||
Serial.print(result.frequencyAsNote(diff));
|
||||
Serial.print(" diff: ");
|
||||
Serial.print(diff);
|
||||
Serial.print(" - time ms ");
|
||||
Serial.print(fft.resultTime() - fft.resultTimeBegin());
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// set the frequency
|
||||
sineWave.setFrequency(N_B4);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfg = in.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
in.begin(cfg);
|
||||
|
||||
// Setup FFT
|
||||
auto tcfg = fft.defaultConfig();
|
||||
tcfg.copyFrom(info);
|
||||
tcfg.length = 4096;
|
||||
tcfg.callback = &fftResult;
|
||||
fft.begin(tcfg);
|
||||
}
|
||||
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,62 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioRealFFT.h" // using RealFFT
|
||||
|
||||
AudioRealFFT fft; // or AudioKissFFT
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> in(sineWave);
|
||||
StreamCopy copier(fft, in);
|
||||
AudioInfo info(44100, 1, 16);
|
||||
float value = 0;
|
||||
static const int N = 5;
|
||||
|
||||
// check fft result
|
||||
void fftResult(AudioFFTBase &fft) {
|
||||
// build result array
|
||||
AudioFFTResult all[fft.size()];
|
||||
for (int j=0;j<fft.size();j++){
|
||||
all[j].bin = j;
|
||||
all[j].magnitude = fft.magnitude(j);
|
||||
all[j].frequency = fft.frequency(j);
|
||||
}
|
||||
// sort descending
|
||||
std::sort(all, all + fft.size(), [](AudioFFTResult a, AudioFFTResult b){ return a.magnitude > b.magnitude; });
|
||||
|
||||
// get top 5
|
||||
AudioFFTResult topn[N];
|
||||
fft.resultArray(topn);
|
||||
|
||||
// compare the topn with sorted result
|
||||
for (int j=0;j<N;j++){
|
||||
Serial.print(all[j].bin);
|
||||
Serial.print(":");
|
||||
Serial.print(topn[j].bin);
|
||||
Serial.print(" ");
|
||||
assert(all[j].bin==topn[j].bin);
|
||||
}
|
||||
Serial.print(" -> TOP: ");
|
||||
Serial.println(fft.result().bin);
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// set the frequency
|
||||
sineWave.setFrequency(N_B4);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfg = in.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
in.begin(cfg);
|
||||
|
||||
// Setup FFT
|
||||
auto tcfg = fft.defaultConfig();
|
||||
tcfg.copyFrom(info);
|
||||
tcfg.length = 512;
|
||||
tcfg.callback = &fftResult;
|
||||
fft.begin(tcfg);
|
||||
}
|
||||
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioRealFFT.h" // using RealFFT
|
||||
|
||||
AudioRealFFT fft; // or AudioKissFFT
|
||||
Hann hann;
|
||||
BufferedWindow buffered(&hann);
|
||||
SineWaveGenerator<int16_t> sineWave(32000);
|
||||
GeneratedSoundStream<int16_t> in(sineWave);
|
||||
StreamCopy copier(fft, in);
|
||||
AudioInfo info(44100, 1, 16);
|
||||
float value = 0;
|
||||
|
||||
// display fft result
|
||||
void fftResult(AudioFFTBase &fft) {
|
||||
float diff;
|
||||
auto result = fft.result();
|
||||
if (result.magnitude > 100) {
|
||||
Serial.print(result.frequency);
|
||||
Serial.print(" ");
|
||||
Serial.print(result.magnitude);
|
||||
Serial.print(" => ");
|
||||
Serial.print(result.frequencyAsNote(diff));
|
||||
Serial.print(" diff: ");
|
||||
Serial.print(diff);
|
||||
Serial.print(" - time ms ");
|
||||
Serial.print(fft.resultTime() - fft.resultTimeBegin());
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// set the frequency
|
||||
sineWave.setFrequency(N_B4);
|
||||
|
||||
// Setup sine wave
|
||||
auto cfg = in.defaultConfig();
|
||||
cfg.copyFrom(info);
|
||||
in.begin(cfg);
|
||||
|
||||
// Setup FFT
|
||||
auto tcfg = fft.defaultConfig();
|
||||
tcfg.copyFrom(info);
|
||||
tcfg.length = 4096;
|
||||
tcfg.callback = &fftResult;
|
||||
tcfg.window_function = &buffered;
|
||||
fft.begin(tcfg);
|
||||
}
|
||||
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,206 @@
|
||||
const float coeffs_hilbert_101Taps_44100_200_19000[] = {
|
||||
0.0001845375,
|
||||
0.0001450338,
|
||||
-0.0001337144,
|
||||
0.0002717566,
|
||||
-0.0002084398,
|
||||
0.0004367564,
|
||||
-0.0002414144,
|
||||
0.0005601507,
|
||||
-0.0001045179,
|
||||
0.0005116525,
|
||||
0.0003299699,
|
||||
0.0002667884,
|
||||
0.0009759046,
|
||||
0.0001011561,
|
||||
0.0014366282,
|
||||
0.0005237720,
|
||||
0.0012552952,
|
||||
0.0018758583,
|
||||
0.0004146737,
|
||||
0.0038272159,
|
||||
-0.0002700868,
|
||||
0.0052244278,
|
||||
0.0006200192,
|
||||
0.0047704995,
|
||||
0.0040194220,
|
||||
0.0023590833,
|
||||
0.0091023742,
|
||||
-0.0000317342,
|
||||
0.0130758105,
|
||||
0.0009912826,
|
||||
0.0127741163,
|
||||
0.0078721470,
|
||||
0.0074909738,
|
||||
0.0193576732,
|
||||
0.0010717165,
|
||||
0.0297314269,
|
||||
0.0009902233,
|
||||
0.0316786844,
|
||||
0.0139422831,
|
||||
0.0218861827,
|
||||
0.0402704410,
|
||||
0.0061432626,
|
||||
0.0711015341,
|
||||
0.0006455787,
|
||||
0.0911099193,
|
||||
0.0299764082,
|
||||
0.0863535827,
|
||||
0.1363124787,
|
||||
0.0527935654,
|
||||
0.6078831408,
|
||||
0.0000000000,
|
||||
-0.6078831408,
|
||||
-0.0527935654,
|
||||
-0.1363124787,
|
||||
-0.0863535827,
|
||||
-0.0299764082,
|
||||
-0.0911099193,
|
||||
-0.0006455787,
|
||||
-0.0711015341,
|
||||
-0.0061432626,
|
||||
-0.0402704410,
|
||||
-0.0218861827,
|
||||
-0.0139422831,
|
||||
-0.0316786844,
|
||||
-0.0009902233,
|
||||
-0.0297314269,
|
||||
-0.0010717165,
|
||||
-0.0193576732,
|
||||
-0.0074909738,
|
||||
-0.0078721470,
|
||||
-0.0127741163,
|
||||
-0.0009912826,
|
||||
-0.0130758105,
|
||||
0.0000317342,
|
||||
-0.0091023742,
|
||||
-0.0023590833,
|
||||
-0.0040194220,
|
||||
-0.0047704995,
|
||||
-0.0006200192,
|
||||
-0.0052244278,
|
||||
0.0002700868,
|
||||
-0.0038272159,
|
||||
-0.0004146737,
|
||||
-0.0018758583,
|
||||
-0.0012552952,
|
||||
-0.0005237720,
|
||||
-0.0014366282,
|
||||
-0.0001011561,
|
||||
-0.0009759046,
|
||||
-0.0002667884,
|
||||
-0.0003299699,
|
||||
-0.0005116525,
|
||||
0.0001045179,
|
||||
-0.0005601507,
|
||||
0.0002414144,
|
||||
-0.0004367564,
|
||||
0.0002084398,
|
||||
-0.0002717566,
|
||||
0.0001337144,
|
||||
-0.0001450338,
|
||||
-0.0001845375,
|
||||
};
|
||||
const float coeffs_delay_101[] = {
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
1.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
};
|
||||
@@ -0,0 +1,326 @@
|
||||
const float coeffs_hilbert_161Taps_44100_200_19000[] = {
|
||||
0.0001075981,
|
||||
0.0000635907,
|
||||
-0.0000542276,
|
||||
0.0000961953,
|
||||
-0.0000716834,
|
||||
0.0001336577,
|
||||
-0.0000789160,
|
||||
0.0001545559,
|
||||
-0.0000439131,
|
||||
0.0001317663,
|
||||
0.0000491225,
|
||||
0.0000706399,
|
||||
0.0001755277,
|
||||
0.0000254666,
|
||||
0.0002580754,
|
||||
0.0000897251,
|
||||
0.0002169548,
|
||||
0.0003133418,
|
||||
0.0000581998,
|
||||
0.0006286168,
|
||||
-0.0000754266,
|
||||
0.0008392822,
|
||||
0.0000402148,
|
||||
0.0007511820,
|
||||
0.0005300339,
|
||||
0.0003618778,
|
||||
0.0012546584,
|
||||
-0.0000299573,
|
||||
0.0017994327,
|
||||
0.0000509181,
|
||||
0.0017333288,
|
||||
0.0009076391,
|
||||
0.0009870086,
|
||||
0.0023260763,
|
||||
0.0000899613,
|
||||
0.0035316813,
|
||||
-0.0000373396,
|
||||
0.0036412806,
|
||||
0.0012852664,
|
||||
0.0023796747,
|
||||
0.0038172312,
|
||||
0.0005709556,
|
||||
0.0062487082,
|
||||
-0.0001464004,
|
||||
0.0069161256,
|
||||
0.0016193144,
|
||||
0.0050623765,
|
||||
0.0057705049,
|
||||
0.0017956620,
|
||||
0.0102989249,
|
||||
-0.0001816732,
|
||||
0.0122841073,
|
||||
0.0017915891,
|
||||
0.0099584706,
|
||||
0.0081873463,
|
||||
0.0045180791,
|
||||
0.0162287653,
|
||||
0.0001456066,
|
||||
0.0210527205,
|
||||
0.0017191509,
|
||||
0.0188841071,
|
||||
0.0112623705,
|
||||
0.0103599299,
|
||||
0.0255213793,
|
||||
0.0015590770,
|
||||
0.0367573548,
|
||||
0.0013623582,
|
||||
0.0371301257,
|
||||
0.0160506910,
|
||||
0.0245615957,
|
||||
0.0442212665,
|
||||
0.0067177403,
|
||||
0.0754282206,
|
||||
0.0007616364,
|
||||
0.0941804141,
|
||||
0.0307184143,
|
||||
0.0876509472,
|
||||
0.1374531039,
|
||||
0.0530080088,
|
||||
0.6084394667,
|
||||
0.0000000000,
|
||||
-0.6084394667,
|
||||
-0.0530080088,
|
||||
-0.1374531039,
|
||||
-0.0876509472,
|
||||
-0.0307184143,
|
||||
-0.0941804141,
|
||||
-0.0007616364,
|
||||
-0.0754282206,
|
||||
-0.0067177403,
|
||||
-0.0442212665,
|
||||
-0.0245615957,
|
||||
-0.0160506910,
|
||||
-0.0371301257,
|
||||
-0.0013623582,
|
||||
-0.0367573548,
|
||||
-0.0015590770,
|
||||
-0.0255213793,
|
||||
-0.0103599299,
|
||||
-0.0112623705,
|
||||
-0.0188841071,
|
||||
-0.0017191509,
|
||||
-0.0210527205,
|
||||
-0.0001456066,
|
||||
-0.0162287653,
|
||||
-0.0045180791,
|
||||
-0.0081873463,
|
||||
-0.0099584706,
|
||||
-0.0017915891,
|
||||
-0.0122841073,
|
||||
0.0001816732,
|
||||
-0.0102989249,
|
||||
-0.0017956620,
|
||||
-0.0057705049,
|
||||
-0.0050623765,
|
||||
-0.0016193144,
|
||||
-0.0069161256,
|
||||
0.0001464004,
|
||||
-0.0062487082,
|
||||
-0.0005709556,
|
||||
-0.0038172312,
|
||||
-0.0023796747,
|
||||
-0.0012852664,
|
||||
-0.0036412806,
|
||||
0.0000373396,
|
||||
-0.0035316813,
|
||||
-0.0000899613,
|
||||
-0.0023260763,
|
||||
-0.0009870086,
|
||||
-0.0009076391,
|
||||
-0.0017333288,
|
||||
-0.0000509181,
|
||||
-0.0017994327,
|
||||
0.0000299573,
|
||||
-0.0012546584,
|
||||
-0.0003618778,
|
||||
-0.0005300339,
|
||||
-0.0007511820,
|
||||
-0.0000402148,
|
||||
-0.0008392822,
|
||||
0.0000754266,
|
||||
-0.0006286168,
|
||||
-0.0000581998,
|
||||
-0.0003133418,
|
||||
-0.0002169548,
|
||||
-0.0000897251,
|
||||
-0.0002580754,
|
||||
-0.0000254666,
|
||||
-0.0001755277,
|
||||
-0.0000706399,
|
||||
-0.0000491225,
|
||||
-0.0001317663,
|
||||
0.0000439131,
|
||||
-0.0001545559,
|
||||
0.0000789160,
|
||||
-0.0001336577,
|
||||
0.0000716834,
|
||||
-0.0000961953,
|
||||
0.0000542276,
|
||||
-0.0000635907,
|
||||
-0.0001075981,
|
||||
};
|
||||
const float coeffs_delay_161[] = {
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
1.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
};
|
||||
@@ -0,0 +1,126 @@
|
||||
const float coeffs_hilbert_61Taps_44100_200_19000[] = {
|
||||
0.0001242450,
|
||||
0.0006874208,
|
||||
-0.0001184992,
|
||||
-0.0000561422,
|
||||
0.0010530539,
|
||||
-0.0008422607,
|
||||
0.0025708659,
|
||||
-0.0015788004,
|
||||
0.0043398859,
|
||||
-0.0015410467,
|
||||
0.0053526877,
|
||||
0.0008794383,
|
||||
0.0043167306,
|
||||
0.0067832875,
|
||||
0.0016847233,
|
||||
0.0144120317,
|
||||
0.0014897183,
|
||||
0.0186966822,
|
||||
0.0101060312,
|
||||
0.0147341586,
|
||||
0.0313924993,
|
||||
0.0040699439,
|
||||
0.0605202855,
|
||||
-0.0002146265,
|
||||
0.0831567061,
|
||||
0.0276660224,
|
||||
0.0829874083,
|
||||
0.1328479631,
|
||||
0.0522707209,
|
||||
0.6063302901,
|
||||
0.0000000000,
|
||||
-0.6063302901,
|
||||
-0.0522707209,
|
||||
-0.1328479631,
|
||||
-0.0829874083,
|
||||
-0.0276660224,
|
||||
-0.0831567061,
|
||||
0.0002146265,
|
||||
-0.0605202855,
|
||||
-0.0040699439,
|
||||
-0.0313924993,
|
||||
-0.0147341586,
|
||||
-0.0101060312,
|
||||
-0.0186966822,
|
||||
-0.0014897183,
|
||||
-0.0144120317,
|
||||
-0.0016847233,
|
||||
-0.0067832875,
|
||||
-0.0043167306,
|
||||
-0.0008794383,
|
||||
-0.0053526877,
|
||||
0.0015410467,
|
||||
-0.0043398859,
|
||||
0.0015788004,
|
||||
-0.0025708659,
|
||||
0.0008422607,
|
||||
-0.0010530539,
|
||||
0.0000561422,
|
||||
0.0001184992,
|
||||
-0.0006874208,
|
||||
-0.0001242450,
|
||||
};
|
||||
const float coeffs_delay_61[] = {
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
1.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
0.0000000000,
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "AudioTools.h"
|
||||
//#include "fir_coeffs_61Taps_44100_200_19000.h"
|
||||
//#include "fir_coeffs_101Taps_44100_200_19000.h"
|
||||
#include "fir_coeffs_161Taps_44100_200_19000.h"
|
||||
|
||||
AudioInfo from(44100, 2, 32);
|
||||
AudioInfo to(44100, 2, 16);
|
||||
SineWaveGenerator<int32_t> sineWave;
|
||||
GeneratedSoundStream<int32_t> in(sineWave);
|
||||
CsvOutput<int16_t> out;
|
||||
FilteredStream<int16_t, float> filtered(out, from.channels);
|
||||
NumberFormatConverterStream conv (filtered);
|
||||
StreamCopy copier(conv, in);
|
||||
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
filtered.setFilter(0, new FIR<float>(coeffs_hilbert_161Taps_44100_200_19000));
|
||||
filtered.setFilter(1, new FIR<float>(coeffs_delay_161));
|
||||
|
||||
// start in
|
||||
auto config_in = in.defaultConfig();
|
||||
config_in.copyFrom(from);
|
||||
in.begin(config_in);
|
||||
sineWave.begin(config_in, 8000.0);
|
||||
|
||||
// start out
|
||||
auto config_out = out.defaultConfig(TX_MODE);
|
||||
config_out.copyFrom(to);
|
||||
out.begin(config_out);
|
||||
|
||||
// Start conversion
|
||||
conv.begin(from, to);
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
|
||||
double coefd[137] = {
|
||||
0.000188725585189891, 0.000091879473225926, -0.000016920442768766,
|
||||
-0.000133280461026043, -0.000251640080720683, -0.000364923626390918,
|
||||
-0.000464412185430885, -0.000539946399700805, -0.000580528007418057,
|
||||
-0.000575329172682575, -0.000515050625648420, -0.000393501287598472,
|
||||
-0.000209212939699419, 0.000033137236602991, 0.000321738209246393,
|
||||
0.000637316639800423, 0.000953645970946306, 0.001238992395833948,
|
||||
0.001458495336203241, 0.001577364656923383, 0.001564660155918535,
|
||||
0.001397314635940224, 0.001063983705740325, 0.000568265297502738,
|
||||
-0.000069161528118792, -0.000809871255352040, -0.001598785008585991,
|
||||
-0.002367155523627244, -0.003037394102238113, -0.003529490734672840,
|
||||
-0.003768583450610565, -0.003693062300853045, -0.003262467087264144,
|
||||
-0.002464373079849631, -0.001319467692097694, 0.000115890783337027,
|
||||
0.001750175413602121, 0.003460562753784068, 0.005100198277458642,
|
||||
0.006508564756602457, 0.007524348715512882, 0.007999914326580530,
|
||||
0.007816265949382166, 0.006897235277941903, 0.005221586005661731,
|
||||
0.002831799051373308, -0.000161514004361169, -0.003580331626899644,
|
||||
-0.007185463286171087, -0.010688262221784543, -0.013767303340739213,
|
||||
-0.016089076144421111, -0.017331352983485829, -0.017207593283301702,
|
||||
-0.015490564521582872, -0.012033321379788043, -0.006785795029102398,
|
||||
0.000194498174472729, 0.008738731003948556, 0.018570633247558595,
|
||||
0.029318005390909025, 0.040531349219315310, 0.051708529390585928,
|
||||
0.062323892873769583, 0.071859896969611939, 0.079839064047870847,
|
||||
0.085854013433190587, 0.089593426008022170, 0.090862068888852371,
|
||||
0.089593426008022170, 0.085854013433190587, 0.079839064047870847,
|
||||
0.071859896969611939, 0.062323892873769583, 0.051708529390585928,
|
||||
0.040531349219315317, 0.029318005390909029, 0.018570633247558595,
|
||||
0.008738731003948556, 0.000194498174472729, -0.006785795029102398,
|
||||
-0.012033321379788046, -0.015490564521582872, -0.017207593283301702,
|
||||
-0.017331352983485829, -0.016089076144421115, -0.013767303340739216,
|
||||
-0.010688262221784546, -0.007185463286171090, -0.003580331626899644,
|
||||
-0.000161514004361169, 0.002831799051373308, 0.005221586005661734,
|
||||
0.006897235277941905, 0.007816265949382166, 0.007999914326580530,
|
||||
0.007524348715512883, 0.006508564756602457, 0.005100198277458645,
|
||||
0.003460562753784068, 0.001750175413602121, 0.000115890783337027,
|
||||
-0.001319467692097694, -0.002464373079849632, -0.003262467087264142,
|
||||
-0.003693062300853045, -0.003768583450610565, -0.003529490734672841,
|
||||
-0.003037394102238113, -0.002367155523627246, -0.001598785008585990,
|
||||
-0.000809871255352040, -0.000069161528118792, 0.000568265297502738,
|
||||
0.001063983705740327, 0.001397314635940224, 0.001564660155918536,
|
||||
0.001577364656923383, 0.001458495336203241, 0.001238992395833948,
|
||||
0.000953645970946307, 0.000637316639800423, 0.000321738209246393,
|
||||
0.000033137236602991, -0.000209212939699420, -0.000393501287598472,
|
||||
-0.000515050625648420, -0.000575329172682575, -0.000580528007418057,
|
||||
-0.000539946399700805, -0.000464412185430885, -0.000364923626390918,
|
||||
-0.000251640080720683, -0.000133280461026043, -0.000016920442768766,
|
||||
0.000091879473225926, 0.000188725585189891};
|
||||
|
||||
|
||||
float coeff[137];
|
||||
int16_t coef16[137];
|
||||
int32_t coef32[137];
|
||||
int64_t coef64[137];
|
||||
|
||||
static int16_t const max_array = 300;
|
||||
int16_t result_array[max_array];
|
||||
|
||||
void setupCoef() {
|
||||
for (int j=0;j<137;j++){
|
||||
coeff[j] = coefd[j];
|
||||
coef16[j] = coefd[j]*32767;
|
||||
coef32[j] = coefd[j]*32767;
|
||||
coef64[j] = coefd[j]*32767;
|
||||
}
|
||||
}
|
||||
|
||||
void listResult() {
|
||||
for (int j = 0; j < 200; j++) {
|
||||
Serial.print(result_array[j]);
|
||||
Serial.print(" ");
|
||||
}
|
||||
}
|
||||
|
||||
void processFloat() {
|
||||
FIR<float> firf(coeff);
|
||||
unsigned long start = millis();
|
||||
for (int j = 0; j < 44100; j++) {
|
||||
auto result = firf.process(32767);
|
||||
if (j < max_array) {
|
||||
result_array[j] = result;
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("float ms: ");
|
||||
Serial.println(millis() - start);
|
||||
}
|
||||
|
||||
void processDouble() {
|
||||
FIR<double> fird(coefd);
|
||||
unsigned long start = millis();
|
||||
for (int j = 0; j < 44100; j++) {
|
||||
auto result = fird.process(32767);
|
||||
if (j < max_array) {
|
||||
result_array[j] = result;
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("double ms: ");
|
||||
Serial.println(millis() - start);
|
||||
}
|
||||
|
||||
void processInt16() {
|
||||
FIR<int16_t> fir16(coef16, 32767);
|
||||
unsigned long start = millis();
|
||||
for (int j = 0; j < 44100; j++) {
|
||||
auto result = fir16.process(32767);
|
||||
if (j < max_array) {
|
||||
result_array[j] = result;
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("int16 ms: ");
|
||||
Serial.println(millis() - start);
|
||||
}
|
||||
|
||||
void processInt32() {
|
||||
FIR<int32_t> fir32(coef32, 32767);
|
||||
unsigned long start = millis();
|
||||
for (int j = 0; j < 44100; j++) {
|
||||
auto result = fir32.process(32767);
|
||||
if (j < max_array) {
|
||||
result_array[j] = result;
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("int32 ms: ");
|
||||
Serial.println(millis() - start);
|
||||
}
|
||||
|
||||
void processInt64() {
|
||||
FIR<int64_t> fir64(coef64, 32767);
|
||||
unsigned long start = millis();
|
||||
for (int j = 0; j < 44100; j++) {
|
||||
auto result = fir64.process(32767);
|
||||
if (j < max_array) {
|
||||
result_array[j] = result;
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("int64 ms: ");
|
||||
Serial.println(millis() - start);
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(119200);
|
||||
while (!Serial)
|
||||
;
|
||||
setupCoef();
|
||||
processFloat();
|
||||
listResult();
|
||||
processDouble();
|
||||
listResult();
|
||||
// processInt16();
|
||||
// listResult();
|
||||
processInt32();
|
||||
listResult();
|
||||
processInt64();
|
||||
listResult();
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info(44100, 2 , 16);
|
||||
VolumeMeter meter;
|
||||
FilteredStream<int16_t, float> filtered(meter);
|
||||
SineWaveGenerator<int16_t> sine;
|
||||
GeneratedSoundStream<int16_t> sine_stream(sine);
|
||||
StreamCopy copier(filtered, sine_stream);
|
||||
float filter_freq = 8000;
|
||||
|
||||
// Filter: or replace with other filters
|
||||
LowPassFilter<float> filter1(filter_freq, info.sample_rate);
|
||||
LowPassFilter<float> filter2(filter_freq, info.sample_rate);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
sine.begin(info, 0);
|
||||
if (!sine_stream.begin(info)){
|
||||
Serial.println("Generator error");
|
||||
stop();
|
||||
}
|
||||
|
||||
if (!filtered.begin(info)){
|
||||
Serial.println("filter error");
|
||||
stop();
|
||||
}
|
||||
filtered.setFilter(0, filter1);
|
||||
filtered.setFilter(1, filter2);
|
||||
|
||||
if (!meter.begin(info)){
|
||||
Serial.println("meter error");
|
||||
stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int freq= 20; freq<20000; freq+=100){
|
||||
meter.clear();
|
||||
sine.setFrequency(freq);
|
||||
copier.copyN(10);
|
||||
Serial.print(freq);
|
||||
Serial.print(": ");
|
||||
Serial.println(meter.volumeRatio());
|
||||
}
|
||||
stop();
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Test case for MedianFilter
|
||||
*/
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(44100, 1, 16);
|
||||
|
||||
// provide sine wave damaged with some rare random noise samples
|
||||
class TestGenerator : public SoundGenerator<int16_t> {
|
||||
public:
|
||||
TestGenerator() {
|
||||
gen_sine.begin(info);
|
||||
gen_sine.setFrequency(N_B4);
|
||||
gen_noise.begin(info);
|
||||
}
|
||||
virtual int16_t readSample() {
|
||||
// proper signal
|
||||
int16_t sample = gen_sine.readSample();
|
||||
if (count-- == 0){
|
||||
// plan for next random value
|
||||
count = random(100, 10000);
|
||||
// replace proper singal value with a random value
|
||||
sample = gen_noise.readSample();;
|
||||
}
|
||||
return sample;
|
||||
};
|
||||
protected:
|
||||
SineWaveGenerator<int16_t> gen_sine;
|
||||
WhiteNoiseGenerator<int16_t> gen_noise;
|
||||
size_t count = 0;
|
||||
} testSound;
|
||||
|
||||
GeneratedSoundStream<int16_t> testStream(testSound); // Stream generated from sine wave
|
||||
FilteredStream<int16_t, int16_t> inFiltered(testStream, info.channels); // Defiles the filter as BaseConverter
|
||||
MedianFilter<int16_t> medianFilter;
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
StreamCopy copier(out, inFiltered);
|
||||
//StreamCopy copier(out, testStream); //compare with this
|
||||
|
||||
|
||||
void setup() {
|
||||
inFiltered.setFilter(0, &medianFilter);
|
||||
auto cfg = out.defaultConfig(TX_MODE);
|
||||
cfg.copyFrom(info);
|
||||
out.begin(cfg);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -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() {}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user