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,47 @@
/**
* @file example-serial-receive.ino
* @author Phil Schatzmann
* @brief Receiving audio via ESPNow and decoding data to I2S
* @version 0.1
* @date 2022-03-09
*
* @copyright Copyright (c) 2022
*/
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.h"
#include "AudioTools/AudioCodecs/CodecSBC.h"
// #include "AudioTools/AudioLibs/AudioBoardStream.h"
ESPNowStream now;
I2SStream out; // or AudioBoardStream
EncodedAudioStream decoder(&out, new SBCDecoder(256)); // decode and write to I2S - ESP Now is limited to 256 bytes
StreamCopy copier(decoder, now);
const char *peers[] = {"A8:48:FA:0B:93:02"};
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// setup esp-now
auto cfg = now.defaultConfig();
cfg.mac_address = "A8:48:FA:0B:93:01";
now.begin(cfg);
now.addPeers(peers);
// start I2S
Serial.println("starting I2S...");
auto config = out.defaultConfig(TX_MODE);
out.begin(config);
// start decoder
decoder.begin();
Serial.println("Receiver started...");
}
void loop() {
copier.copy();
}

View File

@@ -0,0 +1,41 @@
/**
* @file example-serial-receive_measure.ino
* @author Phil Schatzmann
* @brief Receiving audio via ESPNow with max speed to measure thruput
* @version 0.1
* @date 2022-03-09
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.h"
#include "AudioTools/AudioCodecs/CodecSBC.h"
ESPNowStream now;
MeasuringStream out(1000, &Serial);
EncodedAudioStream decoder(&out, new SBCDecoder()); // decode and write to I2S
StreamCopy copier(decoder, now);
const char *peers[] = {"A8:48:FA:0B:93:02"};
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// start esp-now
auto cfg = now.defaultConfig();
cfg.mac_address = "A8:48:FA:0B:93:01";
now.begin(cfg);
now.addPeers(peers);
// start output
decoder.begin();
out.begin();
Serial.println("Receiver started...");
}
void loop() {
copier.copy();
}

View File

@@ -0,0 +1,44 @@
/**
* @file example-serial-send.ino
* @author Phil Schatzmann
* @brief Sending encoded audio over ESPNow
* @version 0.1
* @date 2022-03-09
*
* @copyright Copyright (c) 2022
*/
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.h"
#include "AudioTools/AudioCodecs/CodecSBC.h"
AudioInfo info(32000,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
ESPNowStream now;
SBCEncoder sbc;
EncodedAudioStream encoder(&now, &sbc); // encode and write to ESP-now
StreamCopy copier(encoder, sound); // copies sound into i2s
const char *peers[] = {"A8:48:FA:0B:93:01"};
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
auto cfg = now.defaultConfig();
cfg.mac_address = "A8:48:FA:0B:93:02";
now.begin(cfg);
now.addPeers(peers);
// Setup sine wave
sineWave.begin(info, N_B4);
// start encoder
encoder.begin(info);
Serial.println("Sender started...");
}
void loop() {
copier.copy();
}

View File

@@ -0,0 +1,42 @@
/**
* @file example-espnow-receive.ino
* @author Phil Schatzmann
* @brief Receiving audio via ESPNow
* @version 0.1
* @date 2022-03-09
*
* @copyright Copyright (c) 2022
*/
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.h"
AudioInfo info(8000, 1, 16);
ESPNowStream now;
MeasuringStream now1(now);
I2SStream out;
StreamCopy copier(out, now1);
const char *peers[] = {"A8:48:FA:0B:93:02"};
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
auto cfg = now.defaultConfig();
cfg.mac_address = "A8:48:FA:0B:93:01";
now.begin(cfg);
now.addPeers(peers);
// start I2S
Serial.println("starting I2S...");
auto config = out.defaultConfig(TX_MODE);
config.copyFrom(info);
out.begin(config);
Serial.println("Receiver started...");
}
void loop() {
copier.copy();
}

View File

@@ -0,0 +1,34 @@
/**
* @file example-espnow-receive_csv.ino
* @author Phil Schatzmann
* @brief Receiving audio via ESPNow
* @version 0.1
* @date 2022-03-09
*
* @copyright Copyright (c) 2022
*/
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.h"
ESPNowStream now;
const char *peers[] = {"A8:48:FA:0B:93:02"};
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
auto cfg = now.defaultConfig();
cfg.mac_address = "A8:48:FA:0B:93:01";
now.begin(cfg);
now.addPeers(peers);
Serial.println("Receiver started...");
}
void loop() {
int16_t sample;
if (now.readBytes((uint8_t*)&sample,2)){
Serial.println(sample);
}
}

View File

@@ -0,0 +1,38 @@
/**
* @file example-espnow-receive_measure.ino
* @author Phil Schatzmann
* @brief Receiving audio via ESPNow with max speed to measure thruput
* @version 0.1
* @date 2022-03-09
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.h"
ESPNowStream now;
MeasuringStream out;
StreamCopy copier(out, now);
const char *peers[] = {"A8:48:FA:0B:93:02"};
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
auto cfg = now.defaultConfig();
cfg.mac_address = "A8:48:FA:0B:93:01";
now.begin(cfg);
now.addPeers(peers);
// start I2S
Serial.println("starting Out...");
out.begin();
Serial.println("Receiver started...");
}
void loop() {
copier.copy();
}

View File

@@ -0,0 +1,37 @@
/**
* @file example-espnow-send.ino
* @author Phil Schatzmann
* @brief Sending audio over ESPNow
* @version 0.1
* @date 2022-03-09
*
* @copyright Copyright (c) 2022
*/
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.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
ESPNowStream now;
StreamCopy copier(now, sound); // copies sound into i2s
const char *peers[] = {"A8:48:FA:0B:93:01"};
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
auto cfg = now.defaultConfig();
cfg.mac_address = "A8:48:FA:0B:93:02";
now.begin(cfg);
now.addPeers(peers);
// Setup sine wave
sineWave.begin(info, N_B4);
Serial.println("Sender started...");
}
void loop() {
copier.copy();
}

View File

@@ -0,0 +1,39 @@
/**
* @file example-serial-receive_measure.ino
* @author Phil Schatzmann
* @brief Receiving data via ESPNow with max speed to measure thruput. We define a specific esp-now rate
* @version 0.1
* @date 2022-03-09
*
* @copyright Copyright (c) 2022
*
*/
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.h"
ESPNowStream now;
MeasuringStream out;
StreamCopy copier(out, now);
const char *peers[] = {"A8:48:FA:0B:93:02"};
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
auto cfg = now.defaultConfig();
cfg.mac_address = "A8:48:FA:0B:93:01";
cfg.rate = WIFI_PHY_RATE_24M;
now.begin(cfg);
now.addPeers(peers);
// start I2S
Serial.println("starting Out...");
out.begin();
Serial.println("Receiver started...");
}
void loop() {
copier.copy();
}

View File

@@ -0,0 +1,33 @@
/**
* @file example-serial-send.ino
* @author Phil Schatzmann
* @brief Sending data over ESPNow. We define a specific esp-now rate
* @version 0.1
* @date 2022-03-09
*
* @copyright Copyright (c) 2022
*/
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.h"
ESPNowStream now;
const char *peers[] = {"A8:48:FA:0B:93:01"};
uint8_t buffer[1024] = {0};
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
auto cfg = now.defaultConfig();
cfg.mac_address = "A8:48:FA:0B:93:02";
cfg.rate = WIFI_PHY_RATE_24M;
now.begin(cfg);
now.addPeers(peers);
Serial.println("Sender started...");
}
void loop() {
now.write(buffer, 1024);
}