Skip to content

Commit 2eb9ece

Browse files
committed
more codecs
1 parent 08515f7 commit 2eb9ece

File tree

13 files changed

+149
-92696
lines changed

13 files changed

+149
-92696
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.vscode/
2-
build/
2+
build/

CMakeLists.txt

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ set(CMAKE_CXX_STANDARD 17)
1212
option(ADD_PORTAUDIO "Do not use Portaudio" OFF)
1313
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
1414

15+
set(CODEC "opus" CACHE STRING "codec selected by the user")
16+
set_property(CACHE CODEC PROPERTY STRINGS flac ogg opus pcm)
17+
1518

1619
# lots of warnings and all warnings as errors ?
1720
## add_compile_options(-Wall -Wextra )
@@ -25,20 +28,39 @@ if(NOT arduino-audio-tools_POPULATED)
2528
endif()
2629

2730
# opus
28-
FetchContent_Declare(arduino_libopus GIT_REPOSITORY https://github.com/pschatzmann/arduino-libopus.git GIT_TAG main )
29-
FetchContent_GetProperties(arduino_libopus)
30-
if(NOT arduino_libopus_POPULATED)
31-
FetchContent_Populate(arduino_libopus)
32-
add_subdirectory(${arduino_libopus_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/arduino_libopus)
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()
38+
endif()
39+
40+
# flac
41+
if(CODEC==flac)
42+
FetchContent_Declare(arduino_libflac GIT_REPOSITORY https://github.com/pschatzmann/arduino-libflac.git GIT_TAG main )
43+
FetchContent_GetProperties(arduino_libflac)
44+
if(NOT arduino_libflac_POPULATED)
45+
FetchContent_Populate(arduino_libflac)
46+
add_subdirectory(${arduino_libflac_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/arduino_libflac)
47+
endif()
3348
endif()
3449

50+
3551
add_library(snapclient INTERFACE)
3652

3753
# define location for header files
3854
target_include_directories(snapclient INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src )
3955

4056
# specify libraries
41-
target_link_libraries(snapclient INTERFACE arduino-audio-tools arduino_emulator arduino_libopus)
57+
if(CODEC==opus)
58+
target_link_libraries(snapclient INTERFACE arduino-audio-tools arduino_emulator arduino_libopus)
59+
endif()
60+
if(CODEC==flac)
61+
target_link_libraries(snapclient INTERFACE arduino-audio-tools arduino_emulator arduino_libflac)
62+
endif()
4263

64+
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)
4365

4466

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,28 @@
77
### Feature list
88

99
- Header only C++ implementation
10-
- Opus and PCM decoding are currently supported
10+
- PCM, Opus and FLAC decoding are 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
1414
- Use any output device or DSP chain suppored by the [Audio Tools](https://github.com/pschatzmann/arduino-audio-tools)
1515

1616
### Description
1717

18-
I have converted the [snapclient](https://github.com/jorgenkraghjakobsen/snapclient) from Jørgen Kragh Jakobsen to an Arduino Library and integrated my AudioTools project to be used to define the output devices.
18+
I have rewritten the [snapclient](https://github.com/jorgenkraghjakobsen/snapclient) from Jørgen Kragh Jakobsen to an Arduino Library and integrated my AudioTools project to be used to define the output devices.
1919

2020
### Example Arduino Sketch
2121

22-
Here is an example Arduino sketch that uses the Wifi as communication API, the Opus codec and outputs the audio with I2S:
22+
Here is an example Arduino sketch that uses the Wifi as communication API, the WAVs codec and outputs the audio with I2S:
2323

2424
```C++
2525
#include "AudioTools.h"
2626
#include "SnapClient.h"
27-
#include "AudioCodecs/CodecOpus.h"
2827

29-
#define ARDUINO_LOOP_STACK_SIZE (10 * 1024)
30-
31-
OpusAudioDecoder opus;
32-
I2SStream out;
28+
WAVDecoder pcm;
3329
WiFiClient wifi;
34-
SnapClient client(wifi, out, opus);
30+
I2SStream out;
31+
SnapClient client(wifi, out, pcm);
3532

3633
void setup() {
3734
Serial.begin(115200);
@@ -63,13 +60,23 @@ void loop() {
6360
}
6461

6562
```
63+
Change the snapserver.conf to define ```codec = pcm``` and restart the snapserver with ```sudo service snapserver restart```.
64+
You can test now your sketch e.g. with ```ffmpeg -i http://stream.srg-ssr.ch/m/rsj/mp3_128 -f s16le -ar 48000 /tmp/snapfifo```
65+
66+
For further information on codecs please check the information in the Uncyclo!
67+
68+
69+
### Documentation
6670
67-
You can test your sketch e.g. with ```ffmpeg -i http://stream.srg-ssr.ch/m/rsj/mp3_128 -f s16le -ar 48000 /tmp/snapfifo```
71+
For further information
72+
- consult the [class documentation](https://pschatzmann.github.io/arduino-snapclient/html/annotated.html) or
73+
- the [examples](examples/)
74+
- the Uncyclo
6875
6976
7077
### Dependencies
7178
72-
- [Audio Tools](https://github.com/pschatzmann/arduino-audio-tools)
79+
- [Audio Tools](https://github.com/pschatzmann/arduino-audio-tools) (mandatory)
7380
- [LibOpus](https://github.com/pschatzmann/arduino-libopus) (optional)
7481
- [LibFLAC.h](https://github.com/pschatzmann/arduino-libflac) (optinal)
7582
- [CodecVorbis](https://github.com/pschatzmann/arduino-libvorbis-idec) (optional)
@@ -80,10 +87,3 @@ You can test your sketch e.g. with ```ffmpeg -i http://stream.srg-ssr.ch/m/rsj/m
8087
Configuration settings can be found in [SnapConfig.h](https://github.com/pschatzmann/arduino-snapcast/blob/main/src/SnapConfig.h)
8188
8289
83-
84-
85-
### Documentation
86-
87-
For further information consult the [class documentation](https://pschatzmann.github.io/arduino-snapclient/html/annotated.html) or the [examples](examples/).
88-
89-

desktop-client/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 2.34)
22

33
# set the project name
44
project(desktop-client)
5-
set (CMAKE_CXX_STANDARD 11)
5+
set (CMAKE_CXX_STANDARD 17)
66
set (DCMAKE_CXX_FLAGS "-Werror")
7+
# set (FETCHCONTENT_FULLY_DISCONNECTED ON)
8+
79
include(FetchContent)
810

911
# Download miniaudio.h
@@ -15,14 +17,15 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
1517
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/snapclient )
1618
endif()
1719

20+
1821
# build sketch as executable
1922
add_executable (desktop-client SnapClient.cpp)
2023

2124
# set preprocessor defines
22-
target_compile_definitions(desktop-client PUBLIC -DARDUINO -DEXIT_ON_STOP -DIS_DESKTOP -DCONFIG_USE_RTOS=0 -DCONFIG_USE_PSRAM=0 -DCONFIG_SNAPCLIENT_SNTP_ENABLE=0 -DCONFIG_SNAPCLIENT_USE_MDNS=0)
25+
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)
2326

2427
# specify libraries
25-
target_link_libraries(desktop-client snapclient)
28+
target_link_libraries(desktop-client snapclient arduino-audio-tools arduino_emulator arduino_libvorbis)
2629

2730
# to find include for miniaudio
2831
target_include_directories(desktop-client PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

desktop-client/SnapClient.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
#include "SnapClient.h"
88
#include "AudioLibs/MiniAudioStream.h"
99
#include "AudioCodecs/CodecOpus.h"
10+
//#include "AudioCodecs/CodecFLAC.h" // https://github.com/pschatzmann/arduino-libflac.git
1011

12+
//CsvOutput<int16_t> out;
1113
MiniAudioStream out;
1214
OpusAudioDecoder opus;
15+
//FLACDecoder flac;
1316
WiFiClient wifi;
1417
SnapClient client(wifi, out, opus);
1518

0 commit comments

Comments
 (0)