Giter Site home page Giter Site logo

hhy5277 / snapcast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from badaix/snapcast

0.0 1.0 0.0 20.15 MB

Synchronous multi-room audio player

License: GNU General Public License v3.0

Makefile 1.39% C++ 94.19% Shell 0.08% Python 0.67% Roff 0.28% CMake 1.88% HTML 1.50%

snapcast's Introduction

Snapcast

Snapcast

Synchronous audio player

Build Status Github Releases Donate

Snapcast is a multi-room 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 multi-room solution. The server's audio input is a named pipe /tmp/snapfifo. All data that is fed into this file will be send to the connected clients. One of the most generic ways to use Snapcast is in conjunction with the music player daemon (MPD) or Mopidy, which can be configured to use a named pipe as audio output.

How does it work

The Snapserver reads PCM chunks from the pipe /tmp/snapfifo. The chunk is encoded and tagged with the local time. Supported codecs are:

  • PCM lossless uncompressed
  • FLAC lossless compressed [default]
  • Vorbis lossy compression
  • Opus lossy low-latency compression

The encoded chunk is sent via a TCP connection to the Snapclients. Each client does continuos time synchronization with the server, so that the client is always aware of the local server time. Every received chunk is first decoded and added to the client's chunk-buffer. Knowing the server's time, the chunk is played out using ALSA at the appropriate time. Time deviations are corrected by

  • skipping parts or whole chunks
  • playing silence
  • playing faster/slower

Typically the deviation is smaller than 1ms.

Installation

You can either build and install snapcast from source, or on debian systems install a prebuild .deb package

Installation from source

Please follow this guide to build Snapcast for

Install linux packages

For Debian download the package for your CPU architecture from the latest release page, e.g. for Raspberry pi snapclient_0.x.x_armhf.deb Install the package:

$ sudo dpkg -i snapclient_0.x.x_armhf.deb

Install missing dependencies:

$ sudo apt-get -f install

On OpenWrt do:

$ opkg install snapclient_0.x.x_ar71xx.ipk

On Alpine Linux do:

$ apk add snapcast

# Or for just the client:

$ apk add snapcast-client

# Or for just the server:

$ apk add snapcast-server

On Gentoo Linux do:

$ emerge --ask media-sound/snapcast

On Archlinux, snapcast is available through the AUR. To install, use your favorite AUR helper, or do:

$ git clone https://aur.archlinux.org/snapcast
$ cd snapcast
$ makepkg -si

SnapOS

For the brave of you, there is a guide with buildfiles available to build SnapOS, a small and fast-booting OS to run Snapcast, comming in two flavors: Buildroot based, or OpenWrt based. Please note that there are no pre-build firmware packages available.

Configuration

After installation, Snapserver and Snapclient are started with the command line arguments that are configured in /etc/default/snapserver and /etc/default/snapclient. Allowed options are listed in the man pages (man snapserver, man snapclient) or by invoking the snapserver or snapclient with the -h option.

The server configuration is done in /etc/snapserver.conf. Different streams can by configured in the [stream] section with a list of stream options, e.g.:

[stream]
stream = pipe:///tmp/snapfifo?name=Radio&sampleformat=48000:16:2&codec=flac
stream = file:///home/user/Musik/Some%20wave%20file.wav?name=File

The pipe stream (stream = pipe) will per default create the pipe. Sometimes your audio source might insist in creating the pipe itself. So the pipe creation mode can by changed to "not create, but only read mode", using the mode option set to create or read:

stream = pipe:///tmp/snapfifo?name=Radio&mode=read"

Test

You can test your installation by copying random data into the server's fifo file

$ sudo cat /dev/urandom > /tmp/snapfifo

All connected clients should play random noise now. You might raise the client's volume with "alsamixer". It's also possible to let the server play a wave file. Simply configure a file stream in /etc/snapserver.conf, and restart the server:

[stream]
stream = file:///home/user/Musik/Some%20wave%20file.wav?name=test

When you are using a Raspberry pi, you might have to change your audio output to the 3.5mm jack:

#The last number is the audio output with 1 being the 3.5 jack, 2 being HDMI and 0 being auto.
$ amixer cset numid=3 1

To setup WiFi on a raspberry pi, you can follow this guide: https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md

Control

Snapcast can be controlled using a JSON-RPC API:

  • Set client's volume
  • Mute clients
  • Rename clients
  • Assign a client to a stream
  • ...

There is an Android client snapdroid available in Releases and on Google Play

Snapcast for Android

There is also an unofficial WebApp from @atoomic atoomic/snapcast-volume-ui. This app list all clients connected to a server and allow to control individualy the volume of each client. Once installed, you can use any mobile device, laptop, desktop, or browser.

There is also an unofficial FHEM module from @unimatrix27 which integrates a snapcast controller in to the FHEM home automation system.

There is a snapcast component for Home Assistant which integrates a snapcast controller in to the Home Assistant home automation system.

For a webinterface in python, see snapcastr, based on python-snapcast. This interface controls client volume and assigns streams to groups.

Another webinterface running on any device, see snapcast-websockets-ui, running entirely in the browser, needs websockify. No configuration needed, features almost all functions, still needs some tuning for the optics.

A webinterface called HydraPlay which integrates Snapcast and multiple Mopidy instances. It is JavaScript based and uses Angular 7. A Snapcast websocket proxy server is needed to connect Snapcast to HydraPlay over web sockets.

Setup of audio players/server

Snapcast can be used with a number of different audio players and servers, and so it can be integrated into your favorite audio-player solution and make it synced-multiroom capable. The only requirement is that the player's audio can be redirected into the Snapserver's fifo /tmp/snapfifo. In the following configuration hints for MPD and Mopidy are given, which are base of other audio player solutions, like Volumio or RuneAudio (both MPD) or Pi MusicBox (Mopidy).

The goal is to build the following chain:

audio player software -> snapfifo -> snapserver -> network -> snapclient -> alsa

This guide shows how to configure different players/audio sources to redirect their audio signal into the Snapserver's fifo:

Roadmap

Unordered list of features that should make it into the v1.0

  • Remote control JSON-RPC API to change client latency, volume, zone, ...
  • Android client JSON-RPC client and Snapclient
  • Streams Support multiple streams
  • Debian packages prebuild deb packages
  • Endian independent code
  • OpenWrt port Snapclient to OpenWrt
  • Hi-Res audio support (like 192kHz 24bit)
  • Groups support multiple Groups of clients ("Zones")
  • JSON-RPC Possibility to add, remove, rename streams
  • Protocol specification Snapcast binary streaming protocol, JSON-RPC protocol
  • Ports Snapclient for Windows, Mac OS X, ...

snapcast's People

Contributors

airdrummingfool avatar atoomic avatar axelsimon avatar badaix avatar bfi3103 avatar celevra avatar derglaus avatar frafall avatar gitter-badger avatar happyleavesaoc avatar joerg-krause avatar kutmasterk avatar mariolukas avatar miawgogo avatar miek avatar mogwa1 avatar nickaknudson avatar nimonimonimo avatar pille avatar pmalessa avatar realglotzi avatar santreim avatar sbungartz avatar slackline avatar ssiegel avatar streep avatar tgurr avatar thecb1 avatar unimatrix27 avatar xabolcs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.