Skip to content

Selecting a Decoder

Phil Schatzmann edited this page Nov 16, 2023 · 31 revisions

Define the Decoder on the Server

First you need to define the codec or audio format that snapcast is using in /etc/snapserver.conf

codec = pcm

is selecting pcm the data will be provided as pcm. Supported values are flac, ogg, opus and pcm. The default sample rate is a bit high for pcm, so I suggest to adjust it as well e.g. with

sampleformat = 44100:16:2

Define the Decoder for the Arduino Client

You need to install the necessary decoder library first. Then you can use them in your sketch as follows:

#include "AudioCodecs/CodecOpus.h"   // https://github.com/pschatzmann/arduino-libopus.git
#include "AudioCodecs/CodecFLAC.h"   // https://github.com/pschatzmann/arduino-libflac.git
#include "AudioCodecs/CodecVorbis.h" //https://github.com/pschatzmann/arduino-libvorbis-idec

// codecs
OpusAudioDecoder opus;
FLACDecoder flac;
VorbisDecoder ogg;
WAVDecoder pcm;
// setup client
WiFiClient wifi;
I2SStream out;
SnapClient client(wifi, out, opus);

In the example above we defined all possible decoders, but we only use opus in the snap client.

Clone this wiki locally