A few more changes to the script:

-- switched from json to regular cli on 9090, simpler to parse, at least
for this
-- changed back to using the -t latency in usec argument for alsaloop
-- changed the bt sync logic to get the elapsed track time and use that
as the basis for the latency adjustment, that way you can go up and down
instead of just up, but no lower than the starting -t latency, so pause
the track, set the time slider and power squeezelite on and off to set
the new latency setting for the onboard cards


Code:
--------------------
    
  #!/bin/sh
  
  tcard=300000
  tbt=375000
  btplayer="bluetooth-player"
  btspeaker="bluetooth-speaker"
  btsync="bluetooth-sync"
  rssi="-60"
  
  __start_cards()
  {
  if [ $1 ]
  then
  tcard=$1
  fi
  for card in $(cut -d' ' -f3 /proc/asound/cards | 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 -t ${tcard}
  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 -t ${tbt}
  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
  
  response=$( (echo -e "${mac} title ?"; sleep .2) | nc ${lmsip} 9090 | cut -d' 
' -f3 )
  i=0
  
  case "${response}" in
  "${btplayer}" )
  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 trust ${newdev}
  bluetoothctl connect ${newdev}
  break
  fi  
  i=$(( $i +1 ))
  done
  bluetoothctl discoverable off ;;
  "${btspeaker}" )
  prescan=$(bluetoothctl devices)
  while [ $i -le 6 ]
  do
  (printf "scan.rssi ${rssi}\nscan on\n"; sleep 5) | 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 ;;
  "${btsync}" )
  response=$( (echo -e "${mac} time ?"; sleep .2) | nc ${lmsip} 9090 | cut -d' 
' -f3 )
  response=${response%.*}
  tadd=$(( ${response} * 10000 ))
  tcard=$(( ${tcard} + ${tadd} ))
  pids=$(pgrep -fa hw:Loopback | grep -v bluealsa | cut -d' ' -f1 | tr '\n' ' ')
  kill ${pids}
  __start_cards ${tcard} ;;
  esac
  
--------------------


------------------------------------------------------------------------
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

Reply via email to