Skip to content

Selecting a Decoder

Phil Schatzmann edited this page Jan 13, 2025 · 31 revisions

Define the Decoder on the Server

If you change any of the server settings, do not forget to restart the server with

service snapserver restart

First you need to define the codec or audio format that snapcast is using in /etc/snapserver.conf. Currently supported values are opus and pcm. My recommendation would be to use opus!

codec = opus

Settings for PCM

The advantage of PCM is that it is a simple audio format and no additional codec library needs to be installed.

codec = pcm

is selecting pcm and the data will be provided as wav.

The default server settings are a too high for PCM: I recommend to lower the following values:

# Default source stream read chunk size [ms]
chunk_ms = 8

# Buffer [ms]
buffer = 500

Define the Decoder for the Arduino Client

You need to install the necessary decoder library first! (See the urls below). Then you can use them in your Arduino sketch as follows:

PCM (WAV)

// codecs
WAVDecoder pcm;
// setup client
WiFiClient wifi;
I2SStream out;
SnapClient client(wifi, out, pcm);

The WAVDecoder is part of the AudioTools. If you use PCM with the default Processor, you need to increase the I2S buffer: e.g.

  auto cfg = out.defaultConfig();
  cfg.buffer_size = 512;
  cfg.buffer_count = 40;
  out.begin(cfg);

With the SnapProcessorRTOS, the buffering is done with the encoded data and the default i2s settings are ok.

Opus

#include "AudioTools/AudioCodecs/CodecOpus.h"   // https://github.com/pschatzmann/arduino-libopus.git

// codecs
OpusAudioDecoder opus;
// setup client
WiFiClient wifi;
I2SStream out;
SnapClient client(wifi, out, opus);

You need to install libopus

Exerimental (not working yet)

FLAC

#include "AudioTools/AudioCodecs/CodecFLACFoxen.h"   // https://github.com/pschatzmann/arduino-libfoxenflac

// codecs
FLACDecoderFoxen flac;
// setup client
WiFiClient wifi;
I2SStream out;
SnapClient client(wifi, out, flac);

You need to install libfoxenflac

OGG (Vorbis)

#include "AudioTools/AudioCodecs/CodecVorbis.h" //https://github.com/pschatzmann/arduino-libvorbis-tremor

// codecs
VorbisDecoder ogg;
// setup client
WiFiClient wifi;
I2SStream out;
SnapClient client(wifi, out, ogg);

You need to install libvorbis-tremor. Currently it is only working with the low memory branch.