Daenou / ansible-multiroom-audio

9 stars 0 forks source link
ansible ansible-playbook multiroom-audio snapcast

ansible-multiroom-audio

This collection is being used to maintain (at least) three quite different multiroom audio setups based on Raspberry Pi and high quality audio HATs. We use hifiberry, but this works with any supported audio HAT. We are happy to hear from anyone else being successful using these roles.

Features

The roles support setting up an audio multiroom system from a collection of Raspberry Pis. We try to make available all audio sources, so you can

As a side product, it is also possible with these roles to create a standalone mpd music box that can be used offline. If you are crazy enough, you could run snapcast there too :smile:.

Architecture

Audio Hardware Limitations

Hardware audio sources and sinks need to be driven individually, so that we can receive audio from the analog input, digitize it, stream it synchronously over the network to (all other clients and) the local client that sends the audio to the analog output. This will have some delay, but exactly the same delay as all other networked clients. On the other hand, a soundcard has one global digital clock for all inputs/outputs. Therefore, we use only one digital audio format in all components and set that format explicitly wherever possible. This also minimizes the CPU load (and audio quality loss) for unwanted format conversions.

ALSA dmix devices can be used to mix multiple streams together (provided that all streams have the same digital audio format) without any conversion. dsnoop devices can be used to consume the same audio stream by multiple recorders. dmix/dsnoop devices proved to be very useful, but they are apparently not usable for alsaloop as sinks/sources.

In order to support multiple audio inputs and mix them with a dmix device, we use the snd_aloop kernel module. This creates a virtual soundcard and whatever you stream to dmix:CARD=Loopback,DEV=0 comes out of device=dsnoop:CARD=Loopback,DEV=1 (and 1->2 and 2->3 etc). To make that work without any audio stuttering or other issues, the default audio format for dmix/dsnoop has to be set in /etc/asound.conf.

Design Goals

Implementation on Pi

Ansible implementation

Roles

Requirements

Ansible host:

Pi:

Your Environment:

Howto

Config

1) Populate the variables in the host_vars/$HOSTGROUPNAME/main.yml files with your settings. Checkout roles/*/defaults/main.yml to see all variables available.

2) Populate the inventory file with a [snapclient] and [snapservers] hostgroup and list all snapclients/servers you want to target 3) Write a playbook

A working example uses the following files (TODO change this before going to ansible galaxy):

Deployment

(TODO change this before going to ansible galaxy)

In the docroot of this repo, do the following (in check mode).

ansible-playbook multiroom-amsel.yml --check --diff -u pi -i inventory_amsel