Skip to content

Commit 7e546fd

Browse files
committed
Codec support
1 parent f2d7bde commit 7e546fd

File tree

13 files changed

+80
-89
lines changed

13 files changed

+80
-89
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ I have converted the [snapclient](https://github.com/jorgenkraghjakobsen/snapcli
2020

2121
- [Audio Tools](https://github.com/pschatzmann/arduino-audio-tools)
2222
- [LibOpus](https://github.com/pschatzmann/arduino-libopus)
23+
- [LibFLAC.h](https://github.com/pschatzmann/arduino-libflac)
24+
- [CodecVorbis](https://github.com/pschatzmann/arduino-libvorbis-idec)
2325

2426

2527
### Configuration

docs/html/SnapProcessor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ class SnapProcessor {
139139
while (rc) {
140140
rc = processMessageLoop();
141141
p_snap_output->doLoop();
142-
logHeap(TAG);
142+
logHeap();
143143
checkHeap();
144144
}
145145

146146
ESP_LOGI(TAG, "... done reading from socket");
147147
p_client->stop();
148148

149149
if (id_counter % 100 == 0) {
150-
logHeap(TAG);
150+
logHeap();
151151
}
152152
checkHeap();
153153
}

docs/html/_snap_output_tasks_8h_source.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160; <span class="keywordflow">if</span> (counter &gt; 10)</div>
167167
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>&#160; local_dsp_measure_time(header);</div>
168168
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>&#160; <span class="keywordflow">if</span> (counter++ % 100 == 0) {</div>
169-
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>&#160; logHeap(TAG);</div>
169+
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>&#160; logHeap();</div>
170170
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>&#160; }</div>
171171
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>&#160; checkHeap();</div>
172172
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160; }</div>

docs/html/_snap_processor_8h_source.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@
193193
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>&#160; <span class="keywordflow">while</span> (rc) {</div>
194194
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span>&#160; rc = processMessageLoop();</div>
195195
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span>&#160; p_snap_output-&gt;doLoop();</div>
196-
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span>&#160; logHeap(TAG);</div>
196+
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span>&#160; logHeap();</div>
197197
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span>&#160; checkHeap();</div>
198198
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span>&#160; }</div>
199199
<div class="line"><a name="l00142"></a><span class="lineno"> 142</span>&#160; </div>
200200
<div class="line"><a name="l00143"></a><span class="lineno"> 143</span>&#160; ESP_LOGI(TAG, <span class="stringliteral">&quot;... done reading from socket&quot;</span>);</div>
201201
<div class="line"><a name="l00144"></a><span class="lineno"> 144</span>&#160; p_client-&gt;stop();</div>
202202
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span>&#160; </div>
203203
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>&#160; <span class="keywordflow">if</span> (id_counter % 100 == 0) {</div>
204-
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160; logHeap(TAG);</div>
204+
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160; logHeap();</div>
205205
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span>&#160; }</div>
206206
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>&#160; checkHeap();</div>
207207
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>&#160; }</div>

examples/SnapClientAudioKit/SnapClientAudioKit.ino

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
*/
66
#include "AudioTools.h"
77
#include "SnapClient.h"
8-
#include "AudioLibs/AudioKit.h"
9-
#include "AudioCodecs/CodecOpus.h"
8+
#include "AudioLibs/AudioKit.h"
9+
#include "AudioCodecs/CodecOpus.h" // https://github.com/pschatzmann/arduino-libopus
10+
#include "AudioCodecs/CodecFLAC.h" // https://github.com/pschatzmann/arduino-libflac.git
11+
#include "AudioCodecs/CodecVorbis.h" //https://github.com/pschatzmann/arduino-libvorbis-idec
1012

1113
#define ARDUINO_LOOP_STACK_SIZE (10 * 1024)
1214

1315
AudioKitStream out;
16+
//FLACDecoder flac;
17+
//VorbisDecoder vorbis;
18+
//PCMDecoder pcm;
1419
OpusAudioDecoder opus;
1520
SnapClient client(out, opus);
1621

examples/SnapClientInternalDAC/SnapClientInternalDAC.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "AudioTools.h"
88
#include "SnapClient.h"
99
#include "AudioCodecs/CodecOpus.h"
10+
1011
#define ARDUINO_LOOP_STACK_SIZE (10 * 1024)
1112

1213
OpusAudioDecoder opus;

examples/SnapRTOSClient/SnapRTOSClient.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
22
* @brief SnapClient with Opus decoder: I2S Output to an AudioKit.
33
* This version is using FreeRTOS!
4+
*
5+
* TODO investigate crash!
6+
*
47
* @author Phil Schatzmann
58
* @copyright GPLv3
69
*/
@@ -12,6 +15,8 @@
1215
#include "api/SnapOutputTasks.h"
1316
#include "api/SnapProcessorTasks.h"
1417

18+
#define ARDUINO_LOOP_STACK_SIZE (10 * 1024)
19+
1520
AudioKitStream out;
1621
OpusAudioDecoder opus;
1722
SnapClient client(out, opus);

src/SnapClient.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,28 @@ class SnapClient {
4141
p_snapprocessor->setDecoder(decoder);
4242
}
4343

44+
SnapClient(AudioStream &stream, StreamingDecoder &decoder, int bufferSize = 5*1024) {
45+
p_decoder_adapter = new DecoderFromStreaming(decoder, bufferSize);
46+
output_adapter.setStream(stream);
47+
p_snapprocessor->setOutput(output_adapter);
48+
p_snapprocessor->setDecoder(*p_decoder_adapter);
49+
}
50+
51+
4452
SnapClient(AudioOutput &output, AudioDecoder &decoder) {
4553
p_snapprocessor->setOutput(output);
4654
p_snapprocessor->setDecoder(decoder);
4755
}
4856

57+
SnapClient(AudioOutput &output, StreamingDecoder &decoder, int bufferSize = 5*1024) {
58+
p_decoder_adapter = new DecoderFromStreaming(decoder, bufferSize);
59+
p_snapprocessor->setOutput(output);
60+
p_snapprocessor->setDecoder(*p_decoder_adapter);
61+
}
62+
4963
/// Destructor
5064
~SnapClient(){
65+
if (p_decoder_adapter != nullptr) delete p_decoder_adapter;
5166
end();
5267
}
5368

@@ -109,6 +124,7 @@ class SnapClient {
109124
protected:
110125
const char *TAG = "SnapClient";
111126
AdapterAudioStreamToAudioOutput output_adapter;
127+
DecoderFromStreaming *p_decoder_adapter = nullptr;
112128
// default setup
113129
#if CONFIG_USE_RTOS
114130
SnapOutputTasks snap_output;
@@ -127,9 +143,7 @@ class SnapClient {
127143
const int daylightOffset_sec = 1 * 60 * 60;
128144
for (int retry = 0; retry < 5; retry++) {
129145
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
130-
struct tm timeinfo;
131-
if (!getLocalTime(&timeinfo)) {
132-
ESP_LOGE(TAG, "Failed to obtain time");
146+
if(!printLocalTime()){
133147
continue;
134148
}
135149
checkHeap();

src/SnapConfig.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define CONFIG_PSRAM_LIMIT 512
1212
#endif
1313
#ifndef CONFIG_SNAPCLIENT_SNTP_ENABLE
14-
# define CONFIG_SNAPCLIENT_SNTP_ENABLE true
14+
# define CONFIG_SNAPCLIENT_SNTP_ENABLE false
1515
#endif
1616
#ifndef CONFIG_SNAPCLIENT_USE_MDNS
1717
# define CONFIG_SNAPCLIENT_USE_MDNS true
@@ -20,7 +20,7 @@
2020
# define CONFIG_NVS_FLASH false
2121
#endif
2222
#ifndef CONFIG_CHECK_HEAP
23-
# define CONFIG_CHECK_HEAP false
23+
# define CONFIG_CHECK_HEAP true
2424
#endif
2525

2626
// snapast parameters;
@@ -50,9 +50,7 @@
5050
// Only relevant with FreeRTOS implementation
5151
#define CONFIG_TASK_PRIORITY 5
5252
#define CONFIG_TASK_CORE 1
53-
#define CONFIG_TASK_STACK_PROCESSOR (5 * 1024)
54-
#define CONFIG_TASK_STACK_OUTPUT (8 * 1024)
53+
#define CONFIG_TASK_STACK_PROCESSOR (10 * 1024)
54+
#define CONFIG_TASK_STACK_OUTPUT (10 * 1024)
5555
#define BUFFER_SIZE_PSRAM 32 * 1024
56-
#define BUFFER_SIZE_NO_PSRAM 2 * 1024
57-
58-
56+
#define BUFFER_SIZE_NO_PSRAM 10 * 1024

src/api/SnapCommon.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
#pragma once
66
#include <sys/time.h>
77

8-
enum codec_type { NO_CODEC, PCM, FLAC, OGG, OPUS };
9-
8+
enum codec_type { NO_CODEC, PCM, FLAC, OGG, OPUS, VORBIS };
9+
static const char *TAG="COMMON";
1010
/**
1111
* @brief Information about the next bucket
1212
* @author Phil Schatzmann
1313
* @version 0.1
1414
* @date 2023-10-28
1515
* @copyright Copyright (c) 2023
16-
*/
16+
*/
1717
struct SnapAudioHeader {
1818
int32_t sec = 0;
1919
int32_t usec = 0;
@@ -31,9 +31,19 @@ inline void checkHeap() {
3131
#endif
3232
}
3333

34-
inline void logHeap(const char* TAG) {
34+
inline void logHeap() {
3535
#ifdef ESP32
3636
ESP_LOGD(TAG, "Free Heap: %d / Free Heap PSRAM %d", ESP.getFreeHeap(),
3737
ESP.getFreePsram());
3838
#endif
3939
}
40+
41+
inline bool printLocalTime() {
42+
tm timeinfo;
43+
if (!getLocalTime(&timeinfo)) {
44+
ESP_LOGE(TAG, "Failed to obtain time");
45+
return false;
46+
}
47+
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
48+
return true;
49+
}

0 commit comments

Comments
 (0)