CelliesProjects / ESP32_VS1053_Stream

A streaming library for Arduino esp32 with a vs1053 mp3/aac/ogg/flac decoder. Plays http, https (insecure mode) and chunked streams and parses the metadata. Also plays ogg and mp3 from sdcard.
MIT License
37 stars 9 forks source link

How to use an existing buffer #22

Open lidense opened 7 months ago

lidense commented 7 months ago

Hi, I have used your app to listen to some radios and works great. Now I have developed a small app that provides a buffer in a loop with some aac audio data in chunks of about 1600 bytes coming from an decoded HLS stream. The buffer has this format: uint8 * data. I can play the data using Adafruit VS1053 library with this code if(vs_player.readyForData()) vs_player.playData(data,read); but the sound is hashed and sometimes some bits are skipped. I thought that using a circular buffer like esp32 Stream vs1053 might be better but I don't see how to feed the data to the stream. I see that the main function stream.connectTohost is used to create a stream from a website, how can I instead feed by data buffer to the stream and get it played from vs1053? Thanks for your help.

CelliesProjects commented 7 months ago

Hi lidense.

how can I instead feed by data buffer to the stream and get it played from vs1053?

Not that easy I think. This library is intended purely as a (internet) stream client. All internal functions depend on a WiFiClient pointer to function. Something like you suggest would require a separate codepath in the loop to function. And probably several helper functions.

CelliesProjects commented 7 months ago

If that is all your app is doing then you could maybe use just the VS1053 library and use the VS1053 playChunk() function.

It says that the function blocks, but that is only true if you dont use data_request() as a good to go signal.

This library uses playChunk() exactly in that way. Simplified:

While data_request() is true, { send max 32 bytes if any data left }

https://github.com/CelliesProjects/ESP32_VS1053_Stream/blob/master/src/ESP32_VS1053_Stream.cpp#L584-L596

If you dont mind blocking use it to send the whole buffer in one go:

void playChunk(data, len);

lidense commented 7 months ago

OK thanks for your answer, I will try. Regards Dave

----- Mail original ----- De: "Cellie" @.> À: "CelliesProjects/ESP32_VS1053_Stream" @.> Cc: "lidense" @.>, "Author" @.> Envoyé: Jeudi 14 Décembre 2023 16:24:57 Objet: Re: [CelliesProjects/ESP32_VS1053_Stream] How to use an existing buffer (Issue #22)

If that is all your app is doing then you could maybe use just the VS1053 library and use the VS1053 playChunk() function.

It says that the function blocks, but that is only true if you dont use data_request() as a good to go signal.

This library uses playChunk() exactly in that way.

While data_request() is true, send 32 bytes until data is gone.

https://github.com/CelliesProjects/ESP32_VS1053_Stream/blob/master/src/ESP32_VS1053_Stream.cpp#L584-L596

If you dont mind blocking use it to send the whole buffer:

void playChunk(uint8_t *data, size_t len);

— Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you authored the thread. Message ID: <CelliesProjects/ESP32_VS1053_Stream/issues/22/1856052665 @ github . com>