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

View File

@@ -0,0 +1,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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}