Skip to content

Commit

Permalink
[Feature] Allow using default audio card #22
Browse files Browse the repository at this point in the history
  • Loading branch information
GioF71 committed Sep 4, 2023
1 parent 43e56a6 commit 85bd7e7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ From the repository directory, just run the `configure.sh` bash script, specifyi

PARAM|DESCRIPTION
:---|:---
-n|Sound card name (e.g. DAC), used if card index is not specified
-i|Sound card index. Not recommended. If not specified and also card name isn't, it defaults to `-1`
-n|Sound card name (e.g. DAC), if not specified and also card index isn't, `sysdefault` is used.
-i|Sound card index, not recommended: if not specified and also card name isn't, `sysdefault` is used.
-f|Friendly name, defaults to `TIDAL connect`
-m|Model name, defaults to `Audio Streamer`
-c|MQA Codec, defaults to `false`
Expand Down Expand Up @@ -64,8 +64,8 @@ The container can be entirely configured using the environment variables listed

VARIABLE|DESCRIPTION
:---|:---
CARD_NAME|Alsa name of the audio card. Example for xmos dac might be `DAC` while e.g. it is `D10` for a Topping D10. Defaults to an empty string.
CARD_INDEX|Alsa index of the audio card, defaults to `-1`.
CARD_NAME|Alsa name of the audio card. Example for xmos dac might be `DAC` while e.g. it is `D10` for a Topping D10
CARD_INDEX|Alsa index of the audio card
FRIENDLY_NAME|Friendly name of the device, will be shown on Tidal Apps. Defaults to `TIDAL connect`.
MODEL_NAME|Model name of the device. Defaults to `Audio Streamer`.
MQA_CODEC|Can't comment a lot on this, defaults to `false`.
Expand All @@ -75,6 +75,9 @@ RESTART_ON_FAIL|Enables auto restart (see issue [#16](https://github.com/GioF71/
RESTART_WAIT_SEC|Wait time in seconds before trying restart (see RESTART_ON_FAIL), defaults to 30.
DNS_SERVER_LIST|The DNS serves to be used, defaults to `8.8.8.8 8.8.4.4` (Google's DNS servers).

Please not that if both CARD_NAME and CARD_INDEX are specified, only CARD_NAME will be considered.
Also, if both CARD_NAME and CARD_INDEX are not specified, `sysdefault` (the system default audio device) will be used.

## Moode Audio

It is possible to use this solution for easy installation of Tidal Connect on [Moode Audio](https://moodeaudio.org/).
Expand Down Expand Up @@ -138,6 +141,7 @@ An already started tidal-connect container should start working immediately, at

Date|Comment
:---|:---
2023-09-04|Allow default audio card selection, see issue [#22](https://github.com/GioF71/tidal-connect/issues/22)
2023-07-18|Allow user-specified dns server(s), see issue [#13](https://github.com/GioF71/tidal-connect/issues/13)
2023-07-07|Fixed asound.conf generation from card index, see issue [#2](https://github.com/GioF71/tidal-connect/issues/2)
2023-06-02|First unfolding seems to be working
Expand Down
55 changes: 47 additions & 8 deletions bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ write_audio_config() {
echo "Sound configuration file created."
}

DEFAULT_FRIENDLY_NAME="Tidal connect"
DEFAULT_MODE_NAME="Audio Streamer"
DEFAULT_MQA_CODEC="false"
DEFAULT_MQA_PASSTHROUGH="false"

if [[ -z "${FRIENDLY_NAME}" ]]; then
FRIENDLY_NAME="${DEFAULT_FRIENDLY_NAME}"
fi

if [[ -z "${MODEL_NAME}" ]]; then
MODEL_NAME="${DEFAULT_MODE_NAME}"
fi

if [[ -z "${MQA_CODEC}" ]]; then
MQA_CODEC="${DEFAULT_MQA_CODEC}"
fi

if [[ -z "${MQA_PASSTHROUGH}" ]]; then
MQA_PASSTHROUGH="${DEFAULT_MQA_PASSTHROUGH}"
fi

echo "FRIENDLY_NAME=$FRIENDLY_NAME"
echo "MODEL_NAME=$MODEL_NAME"
echo "MQA_CODEC=$MQA_CODEC"
Expand All @@ -29,7 +50,10 @@ if test -f /etc/asound.conf; then
cat /etc/asound.conf
fi

if [[ "${card_index}" == "-1" && -n "${card_name}" ]]; then
PLAYBACK_DEVICE=default
if [[ -z "${card_index}" || "${card_index}" == "-1" ]] && [[ -n "${card_name}" ]]; then
# card name is set
echo "Specified CARD_NAME=[$card_name]"
aplay -l | sed 1d | \
while read i
do
Expand All @@ -45,15 +69,30 @@ if [[ "${card_index}" == "-1" && -n "${card_name}" ]]; then
fi
fi
done
elif [[ -n "${card_index}" ]]; then
echo "Set card_index=[$card_index]"
write_audio_config $card_index
elif [[ -n "${card_index}" && ! "${card_index}" == "-1" ]]; then
# card index is set
echo "Specified CARD_INDEX=[$card_index]"
echo "Set card_index=[$card_index]"
write_audio_config $card_index
else
# leave default, so I delete asound.conf if found, as it is not needed
echo "Using default audio ..."
if [[ -f /etc/asound.conf ]]; then
echo "Removing asound.conf ..."
rm /etc/asound.conf
fi
echo "using sysdefault ..."
PLAYBACK_DEVICE=sysdefault
echo ". done."
fi

if [[ -f /etc/asound.conf ]]; then
cat /etc/asound.conf
else
echo "Set default card_index=[$DEFAULT_CARD_INDEX]"
write_audio_config $DEFAULT_CARD_INDEX
echo "asound.conf not found, using default audio"
fi

cat /etc/asound.conf
echo "PLAYBACK_DEVICE=[${PLAYBACK_DEVICE}]"

echo "Starting Speaker Application in Background (TMUX)"
/usr/bin/tmux new-session -d -s speaker_controller_application '/app/ifi-tidal-release/bin/speaker_controller_application'
Expand All @@ -66,7 +105,7 @@ do
echo "Starting TIDAL Connect ..."
/app/ifi-tidal-release/bin/tidal_connect_application \
--tc-certificate-path "/app/ifi-tidal-release/id_certificate/IfiAudio_ZenStream.dat" \
--playback-device "default" \
--playback-device ${PLAYBACK_DEVICE} \
-f "${FRIENDLY_NAME}" \
--codec-mpegh true \
--codec-mqa ${MQA_CODEC} \
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ services:
devices:
- /dev/snd
environment:
- CARD_NAME=${CARD_NAME}
- CARD_INDEX=${CARD_INDEX:--1}
- CARD_NAME=${CARD_NAME:-}
- CARD_INDEX=${CARD_INDEX:-}
- FRIENDLY_NAME=${FRIENDLY_NAME:-TIDAL connect}
- MODEL_NAME=${MODEL_NAME:-Audio Streamer}
- MQA_CODEC=${MQA_CODEC:-false}
Expand Down

0 comments on commit 85bd7e7

Please sign in to comment.