Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPD and IR Control #665

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/balena-labs-projects/balena-sound>

## 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
9 changes: 7 additions & 2 deletions core/multiroom/client/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/multiroom/server/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version: "2"

volumes:
spotifycache:
mpd_db:
mpd_state:

services:
# Core services
Expand Down Expand Up @@ -56,6 +58,17 @@ services:
labels:
io.balena.features.dbus: 1

mpd:
build: ./plugins/mpd
restart: on-failure
network_mode: host
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
Expand Down
17 changes: 17 additions & 0 deletions plugins/mpd/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -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"]
25 changes: 25 additions & 0 deletions plugins/mpd/mpd.conf
Original file line number Diff line number Diff line change
@@ -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"
47 changes: 47 additions & 0 deletions plugins/mpd/start.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
Loading