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,65 @@
/**
* @file receive-mp3.ino
* @brief Example of receiving an mp3 stream over serial and playing it over I2S
* using the AudioTools library.
* The processing implements a xon-xoff flow control over Serial. We
* process the data receiving in a separate task and the playback in the main
* loop.
*/
#include "AudioTools.h"
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/Concurrency/RTOS.h"
// xon/xoff flow control
const char xon = 17;
const char xoff = 19;
const int min_percent = 10;
const int max_percent = 90;
AudioBoardStream i2s(AudioKitEs8388V1); // final output of decoded stream
MP3DecoderHelix helix;
EncodedAudioStream dec(&i2s, &helix); // Decoding stream
// queue
BufferRTOS<uint8_t> buffer(0);
QueueStream<uint8_t> queue(buffer);
// copy
StreamCopy copierFill(queue, Serial1);
StreamCopy copierPlay(dec, queue);
Task task("mp3-copy", 10000, 1, 0);
void setup() {
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
Serial0.begin(115200);
// set up buffer here to allow PSRAM usage
buffer.resize(1024 * 10); // 10kB buffer
queue.begin(50); // start when half full
// setup i2s
auto config = i2s.defaultConfig(TX_MODE);
i2s.begin(config);
// setup decoder
dec.begin();
// start fill buffer copy task
task.begin([]() {
copierFill.copy();
// data synchronization to prevent buffer overflow
if (buffer.levelPercent() >= max_percent) {
Serial1.write(xoff); // stop receiving
Serial1.flush();
} else if (buffer.levelPercent() <= min_percent) {
Serial1.write(xon); // start receiving
Serial1.flush();
}
});
}
void loop() { copierPlay.copy(); }

View File

@@ -0,0 +1,48 @@
/**
* @file send-mp3.ino
* @brief Example of sending an mp3 stream over Serial the AudioTools library.
* We use xon/xoff to control the flow of the data.
* I am using an ESP32 Dev Module for the test with the pins TX=17 and RX=16.
*/
#include "AudioTools.h"
#include "AudioTools/Communication/AudioHttp.h"
URLStream url("ssid", "password"); // or replace with ICYStream to get metadata
StreamCopy copier(Serial1, url); // copy url to decoder
// xon/xoff flow control
const char xon = 17;
const char xoff = 19;
bool is_active = false;
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Error);
// setup serial data sink
Serial2.begin(115200);
// mp3 radio
url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128", "audio/mp3");
}
// Determine if we can send data from the flow control sent by the receiver
bool isActive() {
char c = Serial2.read();
switch (c) {
case xon:
is_active = true;
break;
case xoff:
is_active = false;
break;
}
return is_active;
}
void loop() {
if (isActive()) {
copier.copy();
}
}