Here's my latest configs.  Removed all references to real hardware from
/etc/asound.conf and now have stereo audio duplicated across all 8
loopback channels.  Still not really sure about all the settings here
and my feeling is this could be greatly simplified somehow but for now
this is tested and works:


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"
  period_time 0
  period_size 2048
  buffer_size 65536
  buffer_time 0
  periods 128
  rate 48000
  channels 2
  }
  bindings {
  0 0
  1 1
  }
  }
  
  pcm.aloop1 {
  type dmix
  ipc_key 2048
  slave {
  pcm "hw:Loopback,0,1"
  period_time 0
  period_size 2048
  buffer_size 65536
  buffer_time 0
  periods 128
  rate 48000
  channels 2
  }
  bindings {
  0 0
  1 1
  }
  }
  
  pcm.aloop2 {
  type dmix
  ipc_key 4096
  slave {
  pcm "hw:Loopback,0,2"
  period_time 0
  period_size 2048
  buffer_size 65536
  buffer_time 0
  periods 128
  rate 48000
  channels 2
  }
  bindings {
  0 0
  1 1
  }
  }
  
  pcm.aloop3 {
  type dmix
  ipc_key 8092
  slave {
  pcm "hw:Loopback,0,3"
  period_time 0
  period_size 2048
  buffer_size 65536
  buffer_time 0
  periods 128
  rate 48000
  channels 2
  }
  bindings {
  0 0
  1 1
  }
  }
  
  pcm.aloop4 {
  type dmix
  ipc_key 16184
  slave {
  pcm "hw:Loopback,0,4"
  period_time 0
  period_size 2048
  buffer_size 65536
  buffer_time 0
  periods 128
  rate 48000
  channels 2
  }
  bindings {
  0 0
  1 1
  }
  }
  
  pcm.aloop5 {
  type dmix
  ipc_key 32368
  slave {
  pcm "hw:Loopback,0,5"
  period_time 0
  period_size 2048
  buffer_size 65536
  buffer_time 0
  periods 128
  rate 48000
  channels 2
  }
  bindings {
  0 0
  1 1
  }
  }
  
  pcm.aloop6 {
  type dmix
  ipc_key 64736
  slave {
  pcm "hw:Loopback,0,6"
  period_time 0
  period_size 2048
  buffer_size 65536
  buffer_time 0
  periods 128
  rate 48000
  channels 2
  }
  bindings {
  0 0
  1 1
  }
  }
  
  pcm.aloop7 {
  type dmix
  ipc_key 129472
  slave {
  pcm "hw:Loopback,0,7"
  period_time 0
  period_size 2048
  buffer_size 65536
  buffer_time 0
  periods 128
  rate 48000
  channels 2
  }
  bindings {
  0 0
  1 1
  }
  }
  
--------------------


These are the three commands I have under /etc/local.d/AudioConfig.start
to run at boot:

Code:
--------------------
    
  bluetoothctl discoverable off
  bluealsa-aplay 00:00:00:00:00:00 &
  /home/sodface/alsaloop.sh true &
  
--------------------


Contents of the alsaloop.sh script which starts an instance for each
sound card it finds except for the Loopback device then sits and waits
for bluetooth audio sink device connections and starts an alsaloop
instance for them as required:


Code:
--------------------
    
  #!/bin/sh
  
  if [ $1 ]
  then
  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" -t 250000
  done
  fi
  
  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 -S 1 -C hw:Loopback,1,${i} -P 
bluealsa:SRV=org.bluealsa,DEV=${pdev},PROFILE=a2dp -t 450000
  fi
  fi
  done
  fi
  done
  
--------------------


And the contents of the bt-pair.sh script which is fired on a
squeezelite power command and decides what to do based on the title of
the currently playing squeezelite track:


Code:
--------------------
    
  #!/bin/sh
  
  if [ $1 -eq 0 ]
  then
  exit
  fi
  
  echo "hello"
  
  uptime=$(cat /proc/uptime | cut -d'.' -f1)
  
  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"
  rssi="-60"
  
  post=$(cat <<END_HEREDOC
  POST /jsonrpc.js HTTP/1.1
  HOST: ${lmsip}:9000
  Content-Type: application/json; charset=utf-8
  Content-Length: 97
  
  
{"id":1,"method":"slim.request","params":["${mac}",["status","-","1","tags:acgltys"]]}
  END_HEREDOC
  )
  
  if (echo -e "${post}"; sleep .2) | nc ${lmsip} 9000 | 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 (echo -e "${post}"; sleep .2) | nc ${lmsip} 9000 | 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   
  fi       
  
--------------------


This is working ok for now.  Probably won't update this thread unless I
have any major changes but I'm going to continue to tinker with it. 
Only real "issue" now is the audio sync between the local sound card
outputs and a connected BT speaker.  I can tweak the alsaloop -t values
manually and dial them in pretty close but it seems to need adjustments
on every connect/disconnect.  Not really an issue for me since I'm using
a headset and not trying to listed to all the outputs at the same time.


------------------------------------------------------------------------
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
unix@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to