From 53f0c43e7b44c914680a75c25defa775065ded96 Mon Sep 17 00:00:00 2001 From: Laurent Constantin Date: Fri, 9 Feb 2024 14:47:25 +0100 Subject: [PATCH 1/4] Update readme --- README.md | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 2c1e92ec..3c970e48 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,8 @@ ![logo](https://raw.githubusercontent.com/balena-io-projects/balena-sound/master/docs/images/balenaSound-logo.png) -**Starter project enabling you to add multi-room audio streaming via Bluetooth, Airplay2, Spotify Connect and others to any old speakers or Hi-Fi using just a Raspberry Pi.** +This is a fork of Balena-Sound project -## Highlights -- **Audio source plugins**: Stream audio from your favourite music services: Bluetooth, Airplay2, Spotify Connect, UPnP and more! -- **Multi-room synchronous playing**: Play perfectly synchronized audio on multiple devices all over your place. -- **Extended DAC support**: Upgrade your audio quality with one of our supported DACs +# Added features -## Setup and configuration - -Running this app is as simple as deploying it to a balenaCloud fleet. You can do it in just one click by using the button below: - -[![deploy button](https://balena.io/deploy.svg)](https://dashboard.balena-cloud.com/deploy?repoUrl=https://github.com/balena-io-experimental/balena-sound&defaultDeviceType=raspberry-pi) - -## Documentation - -Head over to our [docs](https://balena-sound.pages.dev) for detailed installation and usage instructions, customization options, and more! - -## Motivation - -![concept](https://raw.githubusercontent.com/balenalabs/balena-sound/master/docs/images/sound.png) - -There are many commercial solutions out there that provide functionality similar to balenaSound. Most of them though come with a premium price tag and are riddled with privacy concerns. - -balenaSound is an open source project that allows you to build your own DIY audio streaming platform without compromises. Why spend big money on hardware that might be deemed obsolete by the vendor as they see fit? With balenaSound you are in control, bring your old speakers back to life! - -This project is in active development so if you have any feature requests or issues please submit them here on GitHub. PRs are welcome, too. - -## Getting Help - -If you're having any problem, please [raise an issue](https://github.com/balena-io-experimental/balena-sound/issues/new) on GitHub and we will be happy to help. +- Mount drive and start mpd From 1ff3d0ea2398505f3853fc830f5387d6ff5b95d3 Mon Sep 17 00:00:00 2001 From: Laurent Constantin Date: Fri, 9 Feb 2024 14:47:39 +0100 Subject: [PATCH 2/4] mpd: Add mpd feature This feature adds mpd deamon to balenaSound. It expect an external hard drive to be plugged with your music. New services added: - mpd Configuration extra: - SOUND_MPD_DEVNAME: Drive path to mount it, (defaults to "/dev/sda1") - SOUND_DISABLE_MPD: Disable the MPD service Change-type: major --- docker-compose.yml | 14 ++++++++++ plugins/mpd/Dockerfile.template | 17 ++++++++++++ plugins/mpd/mpd.conf | 25 ++++++++++++++++++ plugins/mpd/start.sh | 47 +++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 plugins/mpd/Dockerfile.template create mode 100644 plugins/mpd/mpd.conf create mode 100755 plugins/mpd/start.sh diff --git a/docker-compose.yml b/docker-compose.yml index 337632c5..494432a9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,8 @@ version: "2" volumes: spotifycache: + mpd_db: + mpd_state: services: # Core services @@ -56,6 +58,18 @@ services: labels: io.balena.features.dbus: 1 + mpd: + build: ./plugins/mpd + restart: on-failure + ports: + - 6600:6600 + privileged: true + labels: + io.balena.features.dbus: 1 + volumes: + - mpd_db:/var/lib/mpd/database" + - mpd_state:/var/lib/mpd/state" + spotify: build: ./plugins/spotify restart: on-failure diff --git a/plugins/mpd/Dockerfile.template b/plugins/mpd/Dockerfile.template new file mode 100644 index 00000000..0e5d2e0c --- /dev/null +++ b/plugins/mpd/Dockerfile.template @@ -0,0 +1,17 @@ +FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine +ENV PULSE_SERVER=tcp:localhost:4317 +ENV UDEV=on + +RUN apk add --no-cache mpd mpc + +# Install filesytem dependencies +RUN install_packages findmnt util-linux grep + + +RUN mkdir -p /usr/src/mpd + +COPY start.sh /usr/src/mpd/start.sh +COPY mpd.conf /etc/mpd.conf + +USER root +CMD ["/bin/bash", "/usr/src/mpd/start.sh"] diff --git a/plugins/mpd/mpd.conf b/plugins/mpd/mpd.conf new file mode 100644 index 00000000..9505fd25 --- /dev/null +++ b/plugins/mpd/mpd.conf @@ -0,0 +1,25 @@ + + +music_directory "/var/lib/mpd/music" +playlist_directory "/var/lib/mpd/playlists" +db_file "/var/lib/mpd/database" +state_file "/var/lib/mpd/state" + +bind_to_address "0.0.0.0" +port "6600" +auto_update "yes" +auto_update_depth "3" + +decoder { + plugin "hybrid_dsd" + enabled "no" +# gapless "no" +} + + +audio_output { + type "pulse" + name "My Pulse Output" +} + +filesystem_charset "UTF-8" \ No newline at end of file diff --git a/plugins/mpd/start.sh b/plugins/mpd/start.sh new file mode 100755 index 00000000..96173a2d --- /dev/null +++ b/plugins/mpd/start.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +if [[ -n "$SOUND_DISABLE_MPD" ]]; then + echo "MPD is disabled, exiting..." + exit 0 +fi + + +DEVNAME=${SOUND_MPD_DEVNAME:-"/dev/sda1"} + +if [[ -z $DEVNAME ]]; then + echo "Invalid device name: $DEVNAME" + exit 1 +fi + +if [[ ! -e "$DEVNAME" ]]; then + echo "Device $DEVNAME not found, exiting..." + exit 1 +fi + +# Mount external filesystem +# Doc: https://docs.balena.io/learn/develop/runtime/#mounting-external-storage-media +if findmnt -rno SOURCE,TARGET $DEVNAME > /dev/null; then + echo "Device $DEVNAME is already mounted!" +else + DESTINATION=/var/lib/mpd + echo "Mounting $DEVNAME to $DESTINATION" + mkdir -p $DESTINATION + mount "$DEVNAME" "$DESTINATION" +fi + +mkdir -p $DESTINATION/playlists +mkdir -p $DESTINATION/music + +# Start MPD +mpdcommand=$(command -v mpd) + +# SOUND_MPD_VERBOSE: Run mpc in verbose mode +if [[ -z ${SOUND_MPD_VERBOSE+x} ]]; then + set -- "$@" \ + --verbose +fi + + +set -- $mpdcommand --no-daemon --stderr + "$@" +exec "$@" From b23a3ed82389f2a3de157e5085c8758a7b1a79b1 Mon Sep 17 00:00:00 2001 From: Laurent Constantin Date: Fri, 9 Feb 2024 15:08:03 +0100 Subject: [PATCH 3/4] Use network mode to be able to access pulseaudio ? --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 494432a9..70e4c8aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -61,8 +61,7 @@ services: mpd: build: ./plugins/mpd restart: on-failure - ports: - - 6600:6600 + network_mode: host privileged: true labels: io.balena.features.dbus: 1 From ac426f90f86ff172d8c2244136767d8622a1b324 Mon Sep 17 00:00:00 2001 From: Laurent Constantin Date: Sun, 21 Apr 2024 15:33:48 +0200 Subject: [PATCH 4/4] Fix multiroom ip? --- core/multiroom/client/start.sh | 9 +++++++-- core/multiroom/server/start.sh | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/multiroom/client/start.sh b/core/multiroom/client/start.sh index 20765623..ab91b571 100644 --- a/core/multiroom/client/start.sh +++ b/core/multiroom/client/start.sh @@ -9,8 +9,13 @@ while ! curl --silent --output /dev/null "$SOUND_SUPERVISOR/ping"; do sleep 5; e # Get mode and snapserver from sound supervisor # mode: default to MULTI_ROOM # snapserver: default to multiroom-server (local) -MODE=$(curl --silent "$SOUND_SUPERVISOR/mode" || true) -SNAPSERVER=$(curl --silent "$SOUND_SUPERVISOR/multiroom/master" || true) +MODE=$(curl -f --silent "$SOUND_SUPERVISOR/mode" || echo 'MULTI_ROOM') + +SNAPSERVER=$(curl -f --silent "$SOUND_SUPERVISOR/multiroom/master" || echo 'localhost') +# Make sure localhost is not used, but the default route instead +if [[ "$SNAPSERVER" == "localhost" ]]; then + SNAPSERVER=$(ip route | awk '/default / { print $3 }') +fi # --- ENV VARS --- # SOUND_MULTIROOM_LATENCY: latency in milliseconds to compensate for speaker hardware sync issues diff --git a/core/multiroom/server/start.sh b/core/multiroom/server/start.sh index 1203c48b..c4d7f820 100755 --- a/core/multiroom/server/start.sh +++ b/core/multiroom/server/start.sh @@ -8,7 +8,7 @@ while ! curl --silent --output /dev/null "$SOUND_SUPERVISOR/ping"; do sleep 5; e # Get mode from sound supervisor. # mode: default to MULTI_ROOM -MODE=$(curl --silent "$SOUND_SUPERVISOR/mode" || true) +MODE=$(curl -f --silent "$SOUND_SUPERVISOR/mode" || echo 'MULTI_ROOM') # Multi-room server can't run properly in some platforms because of resource constraints, so we disable them declare -A blacklisted=(