I did some updates:
-- redid everything into a single script run at startup and on
squeezelite power on, actions dependent on current track title
-- got rid of the three separate json queries. Finally figured out how
to do it once and assign to a variable, just need a space after the
opening $(
-- simplified the json query to just get current song title, previously
I recycled a query from another thread which had a bunch of tags I
didn't need for this
-- had to add back in some buffer settings into /etc/asound.conf (I'd
removed them completely) because bluealsa-aplay dies without them.
-- I tried a few different alsa utils to see if I could programmatically
determine the delay between the onboard audio and bluetooth speaker but
failed. Have added a manual sync method where every time you toggle the
power on squeezelite it increases the latency to the onboard audio. You
just keep doing it until it sounds right.
-- got rid of a useless use of cat
I've tested everything again and it's all working well. I paired my
headphones, my phone, and my wife's phone and was able to play prime
music from my phone, youtube audio from my wife's phone, music from
squeezelite all at the same time streamed to my bluetooth headset
synchronized with the onboard audio. Not that you'd ever want to do
that, but it worked.
Next I need to see if I can determine and then send sync settings to LMS
so the squeezelite player on this box is in sync with the rest of the
players in the house, currently it is not, because of the various buffer
settings.
/etc/asound.conf
Code:
--------------------
# duplicate audio to all Loopback channels
pcm.!default plug:aloopx
pcm.aloopx {
type route;
slave.pcm {
type multi;
slaves.a.pcm "aloop0";
slaves.b.pcm "aloop1";
slaves.c.pcm "aloop2";
slaves.d.pcm "aloop3";
slaves.e.pcm "aloop4";
slaves.f.pcm "aloop5";
slaves.g.pcm "aloop6";
slaves.h.pcm "aloop7";
slaves.a.channels 2;
slaves.b.channels 2;
slaves.c.channels 2;
slaves.d.channels 2;
slaves.e.channels 2;
slaves.f.channels 2;
slaves.g.channels 2;
slaves.h.channels 2;
bindings.0.slave a;
bindings.0.channel 0;
bindings.1.slave a;
bindings.1.channel 1;
bindings.2.slave b;
bindings.2.channel 0;
bindings.3.slave b;
bindings.3.channel 1;
bindings.4.slave c;
bindings.4.channel 0;
bindings.5.slave c;
bindings.5.channel 1;
bindings.6.slave d;
bindings.6.channel 0;
bindings.7.slave d;
bindings.7.channel 1;
bindings.8.slave e;
bindings.8.channel 0;
bindings.9.slave e;
bindings.9.channel 1;
bindings.10.slave f;
bindings.10.channel 0;
bindings.11.slave f;
bindings.11.channel 1;
bindings.12.slave g;
bindings.12.channel 0;
bindings.13.slave g;
bindings.13.channel 1;
bindings.14.slave h;
bindings.14.channel 0;
bindings.15.slave h;
bindings.15.channel 1;
}
ttable.0.0 1;
ttable.1.1 1;
ttable.0.2 1;
ttable.1.3 1;
ttable.0.4 1;
ttable.1.5 1;
ttable.0.6 1;
ttable.1.7 1;
ttable.0.8 1;
ttable.1.9 1;
ttable.0.10 1;
ttable.1.11 1;
ttable.0.12 1;
ttable.1.13 1;
ttable.0.14 1;
ttable.1.15 1;
}
pcm.aloop0 {
type dmix
ipc_key 1024
slave {
pcm "hw:Loopback,0,0"
rate 48000
channels 2
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
}
}
pcm.aloop1 {
type dmix
ipc_key 2048
slave {
pcm "hw:Loopback,0,1"
rate 48000
channels 2
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
}
}
pcm.aloop2 {
type dmix
ipc_key 4096
slave {
pcm "hw:Loopback,0,2"
rate 48000
channels 2
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
}
}
pcm.aloop3 {
type dmix
ipc_key 8092
slave {
pcm "hw:Loopback,0,3"
rate 48000
channels 2
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
}
}
pcm.aloop4 {
type dmix
ipc_key 16184
slave {
pcm "hw:Loopback,0,4"
rate 48000
channels 2
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
}
}
pcm.aloop5 {
type dmix
ipc_key 32368
slave {
pcm "hw:Loopback,0,5"
rate 48000
channels 2
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
}
}
pcm.aloop6 {
type dmix
ipc_key 64736
slave {
pcm "hw:Loopback,0,6"
rate 48000
channels 2
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
}
}
pcm.aloop7 {
type dmix
ipc_key 129472
slave {
pcm "hw:Loopback,0,7"
rate 48000
channels 2
period_size 1024
buffer_size 8192
}
bindings {
0 0
1 1
}
}
--------------------
/etc/local.d/AudioConfig.start
Code:
--------------------
su - squeezelite -s /bin/sh -c '/home/sodface/AudioConfig.sh boot &'
--------------------
/home/sodface/AudioConfig.sh
Code:
--------------------
#!/bin/sh
lcard=15000
lbt=15000
lstep=1500
__start_cards()
{
if [ $1 ]
then
lcard=$1
fi
for card in $(cat /proc/asound/cards | cut -d' ' -f3 | tr -d '[' | grep -v
Loopback | tr -s '\n')
do
for i in $(seq 0 7)
do
if ! ps | grep -q "[L]oopback,1,${i}"
then
break
fi
done
alsaloop -d -C hw:Loopback,1,${i} -P "hw:${card},0" -S5 -l ${lcard}
done
}
__watch_bluetooth()
{
while :
do
if inotifywait -qq -r -e create /dev/input/
then
pdevs=$(bluetoothctl paired-devices | cut -d' ' -f2)
for pdev in ${pdevs}
do
if bluetoothctl info "${pdev}" | tr -d '\n' | grep -Eq 'Connected: yes.*Audio
Sink'
then
if ! ps | grep "[D]EV=${pdev}"
then
for i in $(seq 0 7)
do
if ! ps | grep -q "[L]oopback,1,${i}"
then
break
fi
done
alsaloop -d -C hw:Loopback,1,${i} -P
bluealsa:SRV=org.bluealsa,DEV=${pdev},PROFILE=a2dp -S5 -l ${lbt}
fi
fi
done
fi
done
}
if [ "$1" = "boot" ]
then
bluetoothctl discoverable off
bluealsa-aplay 00:00:00:00:00:00 &
__start_cards
__watch_bluetooth
elif [ $1 -eq 0 ]
then
exit
fi
uptime=$(cut -d'.' -f1 /proc/uptime)
if [ ${uptime} -le 60 ]
then
exit
fi
lmsip=$(netstat -tn | grep 3483 | tr -s ' ' | cut -d ' ' -f5 | cut -d ':' -f1)
iface=$(arp -an | grep ${lmsip} | tr -s ' ' | cut -d' ' -f7)
read mac < /sys/class/net/${iface}/address
btplayer="bluetooth-player"
btspeaker="bluetooth-speaker"
btsync="bluetooth-sync"
lstep="1500"
rssi="-60"
post=$(cat <<END_HEREDOC
POST /jsonrpc.js HTTP/1.1
HOST: ${lmsip}:9000
Content-Type: application/json; charset=utf-8
Content-Length: 77
{"id":1,"method":"slim.request","params":["${mac}",["title","?"]]}
END_HEREDOC
)
response=$( (echo -e "${post}"; sleep .2) | nc ${lmsip} 9000 )
if printf "${response}" | grep -q "${btplayer}"
then
i=0
bluetoothctl discoverable on
prepair=$(bluetoothctl paired-devices | cut -d' ' -f2)
while [ $i -le 30 ]
do
sleep 2
newpair=$(bluetoothctl paired-devices | cut -d' ' -f2)
newdev=$(printf "${prepair}\n${newpair}\n" | sort | uniq -u)
if [ "${newdev}" ]
then
#bluetoothctl pair ${newdev}
bluetoothctl trust ${newdev}
bluetoothctl connect ${newdev}
break
else
i=$(( $i +1 ))
fi
done
bluetoothctl discoverable off
elif printf "${response}" | grep -q "${btspeaker}"
then
i=0
prescan=$(bluetoothctl devices)
while [ $i -le 6 ]
do
(printf "scan.rssi ${rssi}\nscan.rssi\nscan on\n"; sleep 10) | bluetoothctl
sleep .2
newscan=$(bluetoothctl devices)
newdev=$(printf "${prescan}\n${newscan}\n" | sort | uniq -u | cut -d' ' -f2)
if [ "${newdev}" ]
then
bluetoothctl pair ${newdev}
bluetoothctl trust ${newdev}
bluetoothctl connect ${newdev}
break
fi
i=$(( $i +1 ))
done
elif printf "${response}" | grep -q "${btsync}"
then
lcardtmp=$(pgrep -fa hw:Loopback | grep -m1 -v bluealsa | rev | cut -d' ' -f1
| rev)
lcard=$(( ${lcardtmp} + ${lstep} ))
pids=$(pgrep -fa hw:Loopback | grep -v bluealsa | cut -d' ' -f1 | tr '\n' ' ')
kill ${pids}
__start_cards ${lcard}
fi
--------------------
------------------------------------------------------------------------
sodface's Profile: http://forums.slimdevices.com/member.php?userid=19057
View this thread: http://forums.slimdevices.com/showthread.php?t=112536
_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix