Skip to content

Commit fe3c397

Browse files
committed
timed_stream
1 parent 2eb9ece commit fe3c397

File tree

7 files changed

+49
-20
lines changed

7 files changed

+49
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vscode/
22
build/
3+
miniaudio.h

CMakeLists.txt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ if(NOT arduino-audio-tools_POPULATED)
2828
endif()
2929

3030
# opus
31-
if(CODEC==opus)
32-
FetchContent_Declare(arduino_libopus GIT_REPOSITORY https://github.com/pschatzmann/arduino-libopus.git GIT_TAG main )
33-
FetchContent_GetProperties(arduino_libopus)
34-
if(NOT arduino_libopus_POPULATED)
35-
FetchContent_Populate(arduino_libopus)
36-
add_subdirectory(${arduino_libopus_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/arduino_libopus)
37-
endif()
31+
FetchContent_Declare(arduino_libopus GIT_REPOSITORY https://github.com/pschatzmann/arduino-libopus.git GIT_TAG main )
32+
FetchContent_GetProperties(arduino_libopus)
33+
if(NOT arduino_libopus_POPULATED)
34+
FetchContent_Populate(arduino_libopus)
35+
add_subdirectory(${arduino_libopus_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/arduino_libopus)
3836
endif()
3937

4038
# flac
@@ -47,6 +45,16 @@ if(CODEC==flac)
4745
endif()
4846
endif()
4947

48+
# ogg
49+
if(CODEC==ogg)
50+
FetchContent_Declare(arduino_libvorbis GIT_REPOSITORY https://github.com/pschatzmann/arduino-libvorbis-idec GIT_TAG main )
51+
FetchContent_GetProperties(arduino_libvorbis)
52+
if(NOT arduino_libvorbis_POPULATED)
53+
FetchContent_Populate(arduino_libvorbis)
54+
add_subdirectory(${arduino_libvorbis_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/arduino_libvorbis)
55+
endif()
56+
endif()
57+
5058

5159
add_library(snapclient INTERFACE)
5260

@@ -58,7 +66,10 @@ if(CODEC==opus)
5866
target_link_libraries(snapclient INTERFACE arduino-audio-tools arduino_emulator arduino_libopus)
5967
endif()
6068
if(CODEC==flac)
61-
target_link_libraries(snapclient INTERFACE arduino-audio-tools arduino_emulator arduino_libflac)
69+
target_link_libraries(snapclient INTERFACE arduino-audio-tools arduino_emulator arduino_libopus arduino_libflac)
70+
endif()
71+
if(CODEC==ogg)
72+
target_link_libraries(snapclient INTERFACE arduino-audio-tools arduino_emulator arduino_libopus arduino_libvorbis)
6273
endif()
6374

6475
target_compile_definitions(snapclient INTERFACE -DARDUINO -DEXIT_ON_STOP -DIS_DESKTOP -DCONFIG_USE_RTOS=0 -DCONFIG_USE_PSRAM=0 -DCONFIG_SNAPCLIENT_SNTP_ENABLE=0 -DCONFIG_SNAPCLIENT_USE_MDNS=0)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
### Feature list
88

99
- Header only C++ implementation
10-
- PCM, Opus and FLAC decoding are supported
10+
- PCM, Opus, FLAC and Ogg decoding is supported
1111
- Auto connect to snapcast server on network
1212
- The functionality has been tested on an ESP32
1313
- Memory efficient implementation, so that PSRAM is not needed

desktop-client/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
1717
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/snapclient )
1818
endif()
1919

20+
FetchContent_Declare(arduino_libvorbis GIT_REPOSITORY https://github.com/pschatzmann/arduino-libvorbis-tremor.git GIT_TAG main )
21+
FetchContent_GetProperties(arduino_libvorbis)
22+
if(NOT arduino_libvorbis_POPULATED)
23+
FetchContent_Populate(arduino_libvorbis)
24+
add_subdirectory(${arduino_libvorbis_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/arduino_libvorbis)
25+
endif()
26+
2027

2128
# build sketch as executable
2229
add_executable (desktop-client SnapClient.cpp)
@@ -25,7 +32,7 @@ add_executable (desktop-client SnapClient.cpp)
2532
target_compile_definitions(desktop-client PUBLIC -DARDUINO -DEXIT_ON_STOP -DIS_DESKTOP -DCONFIG_USE_PSRAM=0 -DCONFIG_SNAPCLIENT_SNTP_ENABLE=0 -DCONFIG_SNAPCLIENT_USE_MDNS=0)
2633

2734
# specify libraries
28-
target_link_libraries(desktop-client snapclient arduino-audio-tools arduino_emulator arduino_libvorbis)
35+
target_link_libraries(desktop-client snapclient arduino-audio-tools arduino_emulator arduino_libopus arduino_libvorbis)
2936

3037
# to find include for miniaudio
31-
target_include_directories(desktop-client PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
38+
target_include_directories(desktop-client PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

desktop-client/SnapClient.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@
66
#include "AudioTools.h"
77
#include "SnapClient.h"
88
#include "AudioLibs/MiniAudioStream.h"
9-
#include "AudioCodecs/CodecOpus.h"
9+
//#include "AudioCodecs/CodecOpus.h"
1010
//#include "AudioCodecs/CodecFLAC.h" // https://github.com/pschatzmann/arduino-libflac.git
11+
#include "AudioCodecs/CodecVorbis.h" //https://github.com/pschatzmann/arduino-libvorbis-idec
12+
#include "AudioLibs/StdioStream.h"
1113

1214
//CsvOutput<int16_t> out;
15+
//StdioStream out;
1316
MiniAudioStream out;
14-
OpusAudioDecoder opus;
17+
//OpusAudioDecoder opus;
18+
VorbisDecoder ogg;
1519
//FLACDecoder flac;
1620
WiFiClient wifi;
17-
SnapClient client(wifi, out, opus);
21+
SnapClient client(wifi, out, ogg);
1822

1923
void setup() {
2024
Serial.begin(115200);
25+
//AudioLogger::instance().begin(Serial, AudioLogger::Info);
2126
// login to wifi
2227
WiFi.begin(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
2328
Serial.print("Connecting to WiFi ..");
@@ -30,6 +35,7 @@ void setup() {
3035
Serial.println();
3136
Serial.println(WiFi.localIP());
3237

38+
3339
// start snap client
3440
client.begin();
3541
}

src/api/SnapOutput.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ friend SnapProcessor;
8989
this->out = &output; // final output
9090
resample.setStream(output);
9191
vol_stream.setStream(resample); // adjust volume
92-
decoder_stream.setStream(&vol_stream); // decode to pcm
92+
timed_stream.setStream(vol_stream);
93+
decoder_stream.setStream(&timed_stream); // decode to pcm
9394
}
9495

9596
/// Defines the decoder class
@@ -103,6 +104,7 @@ friend SnapProcessor;
103104
if (is_audio_begin_called){
104105
vol_stream.setAudioInfo(info);
105106
out->setAudioInfo(info);
107+
timed_stream.setAudioInfo(info);
106108
}
107109
}
108110

@@ -129,6 +131,7 @@ friend SnapProcessor;
129131
EncodedAudioStream decoder_stream;
130132
VolumeStream vol_stream;
131133
ResampleStream resample;
134+
TimedStream timed_stream;
132135
float vol = 1.0; // volume in the range 0.0 - 1.0
133136
float vol_factor = 1.0; //
134137
bool is_mute = false;
@@ -149,8 +152,6 @@ friend SnapProcessor;
149152
auto vol_cfg = vol_stream.defaultConfig();
150153
vol_cfg.copyFrom(audio_info);
151154
vol_cfg.allow_boost = true;
152-
vol_cfg.channels = 2;
153-
vol_cfg.bits_per_sample = 16;
154155
vol_stream.begin(vol_cfg);
155156

156157
// open final output
@@ -169,6 +170,9 @@ friend SnapProcessor;
169170
res_cfg.copyFrom(audio_info);
170171
resample.begin(res_cfg);
171172

173+
// set up timed stream
174+
timed_stream.begin(audio_info);
175+
172176
ESP_LOGD(TAG, "end");
173177
is_audio_begin_called = true;
174178
return true;
@@ -245,7 +249,8 @@ friend SnapProcessor;
245249
} else {
246250
// wait for the audio to become valid
247251
ESP_LOGI(TAG, "starting after %d ms", delay_ms);
248-
delay(delay_ms);
252+
// replaced delay(delay_ms); with timed_stream
253+
timed_stream.setStartMs(delay_ms);
249254
is_sync_started = true;
250255
result = true;
251256
}

src/api/SnapProcessor.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "SnapProcessor.h"
88
#include "SnapProtocol.h"
99
#include "SnapTime.h"
10-
#include "opus.h"
1110
#include "vector"
1211

1312
/**
@@ -367,7 +366,7 @@ class SnapProcessor {
367366
ESP_LOGD(TAG, "start");
368367
start = &send_receive_buffer[0];
369368
SnapMessageWireChunk wire_chunk_message;
370-
memset(&wire_chunk_message, 0, sizeof(wire_chunk_message));
369+
memset((void*)&wire_chunk_message, 0, sizeof(wire_chunk_message));
371370
int result = wire_chunk_message.deserialize(start, size);
372371
if (result) {
373372
ESP_LOGI(TAG, "Failed to read wire chunk: %d", result);

0 commit comments

Comments
 (0)