Working example of URLStreamBuffered #1626
-
Dear Community and pschatzmann, thanks so much for this library! In general I want to stream from a "lossless" aac 96khz internet radio and it sounds good most of the time but each minute or so on average, I have those repeated samples/chunks (why does this happen at all, feels like it "hangs" shortly but I don't think it actually does, so why would it make this robotic noise instead of not repeating non-existent samples/chunks). I made use of all other options in the performance section and the best was more or less defaults with a little bit raised buffers on StreamCopy and i2s_cfg.buffer_size (probably cosmetically). But I really wanted to try and add network buffering and also maybe monitor when the buffer runs out and actually detect when the bottleneck is the wifi/network/(not so far existent)buffer. P.S.: This is my now workaround-code (also wanted concurrency) after getting over copier so far (WIP, not nice and also maybe not better than copier), it sounds good most of the time as well (didn't came to measuring if it's less or more "crackle"/haning). But I still feel like missing out on UrlStreamBuffered ^^ #include "AudioTools.h"
#include "AudioCodecs/CodecAACHelix.h"
#include "AudioLibs/AudioBoardStream.h"
#include "Concurrency/SynchronizedBuffers.h"
const char *ssid = "wifisid";
const char *password = "wifipw";
const char *url = "https://motherearth.streamserver24.com/listen/motherearth_klassik/motherearth.klassik.aac";
#define bfsz 2048
#define bfcnt 512
URLStream urlStream(ssid, password);
AudioBoardStream i2s(AudioKitEs8388V1);
EncodedAudioStream decoder(&i2s, new AACDecoderHelix());
SynchronizedBufferRTOS<uint8_t> buffer(bfsz, bfcnt);
TaskHandle_t readerTaskHandle = NULL;
TaskHandle_t playerTaskHandle = NULL;
void readerTask(void *parameter) {
uint8_t tempBuffer[512];
while (true) {
size_t bytesRead = urlStream.readBytes(tempBuffer, sizeof(tempBuffer));
if (bytesRead > 0) {
buffer.writeArray(tempBuffer, bytesRead);
}
vTaskDelay(1);
}
}
void playerTask(void *parameter) {
uint8_t tempBuffer[512];
while (true) {
size_t available = buffer.available();
if (available >= sizeof(tempBuffer)) {
size_t bytesRead = buffer.readArray(tempBuffer, sizeof(tempBuffer));
decoder.write(tempBuffer, bytesRead);
}
vTaskDelay(1);
}
}
void setup() {
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
auto config = i2s.defaultConfig(TX_MODE);
config.sample_rate = 96000;
config.bits_per_sample = 16;
config.channels = 2;
config.buffer_size = 1024*2;
i2s.begin(config);
urlStream.begin(url, "audio/aac");
decoder.begin();
xTaskCreatePinnedToCore(readerTask, "ReaderTask", 10000, NULL, 1, &readerTaskHandle, 0);
xTaskCreatePinnedToCore(playerTask, "PlayerTask", 10000, NULL, 1, &playerTaskHandle, 1);
}
void loop() {
vTaskDelay(1000 / portTICK_PERIOD_MS);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I committed a correction... |
Beta Was this translation helpful? Give feedback.
I committed a correction...