Skip to content

Commit f71001c

Browse files
committed
hls examples
1 parent 6996a89 commit f71001c

File tree

3 files changed

+100
-57
lines changed

3 files changed

+100
-57
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// Buffered playback of HLSStream: activate PSRAM!
3+
// We use a MultiDecoder to handle different formats
4+
//
5+
6+
#include "AudioTools.h"
7+
#include "AudioTools/AudioLibs/HLSStream.h"
8+
#include "AudioTools/AudioCodecs/CodecHelix.h"
9+
#include "AudioTools/Concurrency/RTOS.h"
10+
//#include "AudioTools/AudioLibs/AudioBoardStream.h"
11+
12+
13+
//AudioBoardStream out(AudioKitEs8388V1); // final output of decoded stream
14+
I2SStream out;
15+
BufferRTOS<uint8_t> buffer(0);
16+
QueueStream<uint8_t> queue(buffer);
17+
HLSStream hls_stream("ssid", "password");
18+
// decoder
19+
MP3DecoderHelix mp3;
20+
AACDecoderHelix aac;
21+
MultiDecoder multi(hls_stream); // MultiDecoder using mime from hls_stream
22+
EncodedAudioOutput dec(&out, &multi);
23+
24+
StreamCopy copier_play(dec, queue);
25+
StreamCopy copier_write_queue(queue, hls_stream);
26+
Task writeTask("write", 1024 * 8, 10, 0);
27+
28+
29+
// Arduino Setup
30+
void setup(void) {
31+
Serial.begin(115200);
32+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
33+
34+
// https://streams.radiomast.io/ref-128k-mp3-stereo/hls.m3u8
35+
// https://streams.radiomast.io/ref-128k-aaclc-stereo/hls.m3u8
36+
// https://streams.radiomast.io/ref-64k-heaacv1-stereo/hls.m3u8
37+
if (!hls_stream.begin("https://streams.radiomast.io/ref-128k-mp3-stereo/hls.m3u8"))
38+
stop()
39+
40+
multi.addDecoder(mp3, "audio/mpeg");
41+
multi.addDecoder(aac, "audio/aac");
42+
43+
auto cfg = out.defaultConfig(TX_MODE);
44+
out.begin(cfg);
45+
46+
buffer.resize(10 * 1024); // increase to 50k psram
47+
dec.begin(); // start decoder
48+
queue.begin(100); // activate read when 100% full
49+
50+
writeTask.begin([]() {
51+
copier_write_queue.copy();
52+
});
53+
}
54+
55+
// Arduino loop
56+
void loop() {
57+
copier_play.copy();
58+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// Copy hls stream to decoder: the realoading of data is causig pauses
3+
// We use a MultiDecoder to handle different formats
4+
//
5+
#include "AudioTools.h"
6+
#include "AudioTools/AudioLibs/HLSStream.h"
7+
#include "AudioTools/AudioCodecs/CodecHelix.h"
8+
//#include "AudioTools/AudioLibs/AudioBoardStream.h"
9+
10+
//AudioBoardStream out(AudioKitEs8388V1);
11+
I2SStream out;
12+
HLSStream hls_stream("ssid", "password");
13+
MP3DecoderHelix mp3;
14+
AACDecoderHelix aac;
15+
MultiDecoder multi(hls_stream); // MultiDecoder using mime from hls_stream
16+
EncodedAudioOutput dec(&out, &multi);
17+
StreamCopy copier(dec, hls_stream);
18+
19+
// Arduino Setup
20+
void setup(void) {
21+
Serial.begin(115200);
22+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
23+
24+
// https://streams.radiomast.io/ref-128k-mp3-stereo/hls.m3u8
25+
// https://streams.radiomast.io/ref-128k-aaclc-stereo/hls.m3u8
26+
// https://streams.radiomast.io/ref-64k-heaacv1-stereo/hls.m3u8
27+
if (!hls_stream.begin("https://streams.radiomast.io/ref-128k-mp3-stereo/hls.m3u8"))
28+
stop()
29+
30+
multi.addDecoder(mp3, "audio/mpeg");
31+
multi.addDecoder(aac, "audio/aac");
32+
33+
auto cfg = out.defaultConfig(TX_MODE);
34+
out.begin(cfg);
35+
36+
dec.begin(); // start decoder
37+
}
38+
39+
// Arduino loop
40+
void loop() {
41+
copier.copy();
42+
}

examples/sandbox/stream-hls-audiokit/stream-hls-audiokit.ino

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)