Snapcast is a multiroom client-server audio player, where all clients are time synchronized with the server to play perfectly synced audio. It’s not a standalone player, but an extension that turns your existing audio player into a Sonos-like multiroom solution.
This week I have spent some time to work a new client for Arduino that should integrate with my AudioTools and I have a first DRAFT version that started to work.
Arduino Sketch
Here is the related Arduino Sketch that I have tested with an ESP32:
#include "AudioCodecs/CodecOpus.h"
#include "AudioTools.h"
#include "SnapClient.h"
#define ARDUINO_LOOP_STACK_SIZE (10 * 1024)
OpusAudioDecoder opus;
I2SStream out;
SnapClient client(out, opus);
void setup() {
Serial.begin(115200);
// login to wifi
WiFi.begin(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
// print ip address
Serial.println();
Serial.println(WiFi.localIP());
// setup I2S to define custom pins
auto cfg = out.defaultConfig();
config.pin_bck = 14;
config.pin_ws = 15;
config.pin_data = 22;
out.begin(cfg);
// start snap client
client.begin();
}
void loop() { client.doLoop(); }
So we just need to pass the decoder and the output stream as argments to the constructor of the SnapClient object, start the Wifi and the client and call doLoop() in the Arduino loop!
To test it out I was executing the following command on my Linux Desktop: ffmpeg -i http://stream.srg-ssr.ch/m/rsj/mp3_128 -f s16le -ar 48000 /tmp/snapfifo
!
For further information please read the documentation in the project.
Open Topics
There are still a couple of additional things to do:
- testing more codecs
- adding additional support for playback synchronization
- testing and issue resolution on other platforms
Please let me know if you want to work on any of these topics or if you have an further proposals
Dependencies
arduino-audio-tools.h
arduino-libopus
arduino-snapclient
Final Comments
Please do not use the sketch from this page, but double check with the examples in the projects. I am not updating this page and I can’t guarantee that there are no changes to the API…
0 Comments