11//
2- // Buffered playback of HLSStream: activate PSRAM!
3- // We use a MultiDecoder to handle different formats.
4- // For MPEG-TS (MTS) you need to set the log level to Warning or higher.
52//
3+ //
4+
5+ /* *
6+ * @file hls-buffer-i2s.ino
7+ * @brief Buffered playback of HLSStream: activate PSRAM!
8+ * We use a MultiDecoder to handle different formats.
9+ * For MPEG-TS (MTS) you need to set the log level to Warning or higher.
10+ *
11+ * @author Phil Schatzmann
12+ * @copyright GPLv3
13+ */
614
715#include " AudioTools.h"
8- #include " AudioTools/AudioLibs/HLSStream.h"
916#include " AudioTools/AudioCodecs/CodecHelix.h"
1017#include " AudioTools/AudioCodecs/CodecMTS.h"
18+ #include " AudioTools/AudioLibs/HLSStream.h"
1119#include " AudioTools/Concurrency/RTOS.h"
12- // #include "AudioTools/AudioLibs/AudioBoardStream.h"
13-
20+ // #include "AudioTools/AudioLibs/AudioBoardStream.h"
1421
15- // AudioBoardStream out(AudioKitEs8388V1); // final output of decoded stream
16- I2SStream out;
22+ // AudioBoardStream out(AudioKitEs8388V1); // final output of decoded stream
23+ I2SStream out; // audio output
1724BufferRTOS<uint8_t > buffer (0 );
1825QueueStream<uint8_t > queue (buffer);
19- HLSStream hls_stream (" ssid" , " password" );
26+ HLSStream hls_stream (" ssid" , " password" ); // audio data source
2027// decoder
2128MP3DecoderHelix mp3;
2229AACDecoderHelix aac;
23- MTSDecoder mts (aac); // MPEG-TS (MTS) decoder
24-
25- MultiDecoder multi (hls_stream); // MultiDecoder using mime from hls_stream
30+ MTSDecoder mts (aac); // MPEG-TS (MTS) decoder
31+ MultiDecoder multi (hls_stream); // MultiDecoder using mime from hls_stream
2632EncodedAudioOutput dec (&out, &multi);
27-
33+ // 2 separate copy processes
2834StreamCopy copier_play (dec, queue);
2935StreamCopy copier_write_queue (queue, hls_stream);
3036Task writeTask (" write" , 1024 * 8 , 10 , 0 );
3137
32-
3338// Arduino Setup
3439void setup (void ) {
3540 Serial.begin (115200 );
@@ -38,26 +43,26 @@ void setup(void) {
3843 // https://streams.radiomast.io/ref-128k-mp3-stereo/hls.m3u8
3944 // https://streams.radiomast.io/ref-128k-aaclc-stereo/hls.m3u8
4045 // https://streams.radiomast.io/ref-64k-heaacv1-stereo/hls.m3u8
41- if (!hls_stream.begin (" https://streams.radiomast.io/ref-128k-mp3-stereo/hls.m3u8" ))
46+ if (!hls_stream.begin (
47+ " https://streams.radiomast.io/ref-128k-mp3-stereo/hls.m3u8" ))
4248 stop ();
4349
50+ // register decoders with mime types
4451 multi.addDecoder (mp3, " audio/mpeg" );
4552 multi.addDecoder (aac, " audio/aac" );
46- multi.addDecoder (mts, " video/MP2T" ); // MPEG-TS
53+ multi.addDecoder (mts, " video/MP2T" ); // MPEG-TS
4754
55+ // start output
4856 auto cfg = out.defaultConfig (TX_MODE);
57+ // add optional configuration here: e.g. pins
4958 out.begin (cfg);
5059
5160 buffer.resize (10 * 1024 ); // increase to 50k psram
5261 dec.begin (); // start decoder
5362 queue.begin (100 ); // activate read when 100% full
5463
55- writeTask.begin ([]() {
56- copier_write_queue.copy ();
57- });
64+ writeTask.begin ([]() { copier_write_queue.copy (); });
5865}
5966
6067// Arduino loop
61- void loop () {
62- copier_play.copy ();
63- }
68+ void loop () { copier_play.copy (); }
0 commit comments