1
1
//
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.
5
2
//
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
+ */
6
14
7
15
#include " AudioTools.h"
8
- #include " AudioTools/AudioLibs/HLSStream.h"
9
16
#include " AudioTools/AudioCodecs/CodecHelix.h"
10
17
#include " AudioTools/AudioCodecs/CodecMTS.h"
18
+ #include " AudioTools/AudioLibs/HLSStream.h"
11
19
#include " AudioTools/Concurrency/RTOS.h"
12
- // #include "AudioTools/AudioLibs/AudioBoardStream.h"
13
-
20
+ // #include "AudioTools/AudioLibs/AudioBoardStream.h"
14
21
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
17
24
BufferRTOS<uint8_t > buffer (0 );
18
25
QueueStream<uint8_t > queue (buffer);
19
- HLSStream hls_stream (" ssid" , " password" );
26
+ HLSStream hls_stream (" ssid" , " password" ); // audio data source
20
27
// decoder
21
28
MP3DecoderHelix mp3;
22
29
AACDecoderHelix 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
26
32
EncodedAudioOutput dec (&out, &multi);
27
-
33
+ // 2 separate copy processes
28
34
StreamCopy copier_play (dec, queue);
29
35
StreamCopy copier_write_queue (queue, hls_stream);
30
36
Task writeTask (" write" , 1024 * 8 , 10 , 0 );
31
37
32
-
33
38
// Arduino Setup
34
39
void setup (void ) {
35
40
Serial.begin (115200 );
@@ -38,26 +43,26 @@ void setup(void) {
38
43
// https://streams.radiomast.io/ref-128k-mp3-stereo/hls.m3u8
39
44
// https://streams.radiomast.io/ref-128k-aaclc-stereo/hls.m3u8
40
45
// 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" ))
42
48
stop ();
43
49
50
+ // register decoders with mime types
44
51
multi.addDecoder (mp3, " audio/mpeg" );
45
52
multi.addDecoder (aac, " audio/aac" );
46
- multi.addDecoder (mts, " video/MP2T" ); // MPEG-TS
53
+ multi.addDecoder (mts, " video/MP2T" ); // MPEG-TS
47
54
55
+ // start output
48
56
auto cfg = out.defaultConfig (TX_MODE);
57
+ // add optional configuration here: e.g. pins
49
58
out.begin (cfg);
50
59
51
60
buffer.resize (10 * 1024 ); // increase to 50k psram
52
61
dec.begin (); // start decoder
53
62
queue.begin (100 ); // activate read when 100% full
54
63
55
- writeTask.begin ([]() {
56
- copier_write_queue.copy ();
57
- });
64
+ writeTask.begin ([]() { copier_write_queue.copy (); });
58
65
}
59
66
60
67
// Arduino loop
61
- void loop () {
62
- copier_play.copy ();
63
- }
68
+ void loop () { copier_play.copy (); }
0 commit comments