Skip to content

Instantly share code, notes, and snippets.

@zudljk
Last active January 27, 2019 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zudljk/91e4222ee9d7a3fbb5e70d9ebc99cadb to your computer and use it in GitHub Desktop.
Save zudljk/91e4222ee9d7a3fbb5e70d9ebc99cadb to your computer and use it in GitHub Desktop.
Raspberry bluetooth audio device
# http://alsa.opensrc.org/SurroundSound
# http://alsa.opensrc.org/Low-pass_filter_for_subwoofer_channel_%28HOWTO%29
# Arch Linux: pacman -S ladspa blop swh-plugins libsamplerate tap-plugins cmt
# speaker-test -D upmix_20to51 -c 2 -t wav
# listplugins
# analyseplugin cmt
# http://plugin.org.uk/ladspa-swh/docs/ladspa-swh.html
pcm.lowpass_21to21 {
type ladspa
slave.pcm upmix_21to51
path "/usr/lib/ladspa"
channels 3
plugins {
0 {
id 1098 # Identity (Audio) (1098/identity_audio)
policy duplicate
input.bindings.0 "Input";
output.bindings.0 "Output";
}
1 {
id 1052 # High-pass filter
policy none
input.bindings.0 "Input";
output.bindings.0 "Output";
input {
controls [ 100 ]
}
}
2 {
id 1052 # High-pass filter
policy none
input.bindings.1 "Input";
output.bindings.1 "Output";
input {
controls [ 100 ]
}
}
3 {
id 1051 # Low-pass filter
policy none
input.bindings.2 "Input";
output.bindings.2 "Output";
input {
controls [ 100 ]
}
}
}
}
pcm.upmix_20to51 {
type plug
slave.pcm "lowpass_21to21"
slave.channels 3
ttable {
0.0 1 # left channel
1.1 1 # right channel
0.2 0.5 # mix left and right ...
1.2 0.5 # ... channel for subwoofer
}
}
pcm.upmix_21to51 {
type plug
slave.pcm surround51
slave.channels 6
ttable {
0.0 1 # front left
1.1 1 # front right
0.2 1 # rear left
1.3 1 # rear right
# Front left/right to center.
0.4 0.5
1.4 0.5
# Subwoofer, more powerful to compensate for bass-removal from other speakers.
# Would normally be 1.
2.5 2
}
}
#!/usr/bin/env ansible-playbook -i ../inventory -k -K
#
# Prerequisites:
# - Download Raspbian Stretch Lite
# - Write the image to an SD card
# - Start the Raspberry Pi with the SD card
# - Boot the Pi and set up the SSHD
#
---
- hosts: mizar.fritz.box
become: yes
become_user: root
become_method: sudo
tasks:
- name: upgrade dist
apt: upgrade=dist update_cache=yes
- name: install required packages
apt: name={{item}} state=present update_cache=yes install_recommends=no
with_items:
- bluealsa
- python-dbus
- python-gobject
- tmux
- bluez
- git
- blop
- cmt
- name: securing SSHD
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^PermitRootLogin.*'
line: 'PermitRootLogin no'
- name: switch off integrated sound
lineinfile:
path: /boot/config.txt
regexp: '^dtparam=audio=.*'
line: 'dtparam=audio=off'
- name: configure bluetooth class
lineinfile:
path: /etc/bluetooth/main.conf
regexp: '.*Class = .*'
line: 'Class = 0x240428'
- name: configure bluetooth discoverable timeout
lineinfile:
path: /etc/bluetooth/main.conf
regexp: '.*DiscoverableTimeout = .*'
line: 'DiscoverableTimeout = 0'
- name: configure bluetooth pairable timeout
lineinfile:
path: /etc/bluetooth/main.conf
regexp: '.*PairableTimeout = .*'
line: 'PairableTimeout = 0'
- name: configure bluetooth audio (1)
lineinfile:
create: yes
path: /etc/bluetooth/audio.conf
insertbefore: BOF
line: '[General]'
- name: configure bluetooth audio (2)
lineinfile:
create: yes
path: /etc/bluetooth/audio.conf
regexp: '.*Enable=.*'
line: 'Enable=Source,Sink,Media,Socket'
- name: get ct scripts from Michael Schmidt
git: dest=/root/ctscripts repo=https://github.com/ct-Open-Source/ct-Raspi-Bluetooth-Receiver/
- name: modify service to use upmixed audio (see below)
lineinfile:
path: /root/ctscripts/bluealsa-aplay@.service
regexp: 'ExecStart=/usr/bin/bluealsa-aplay %I'
line: 'ExecStart=/usr/bin/bluealsa-aplay -dupmix_20to51 %I
- name: install agent and autoconnect
command: install -m 755 /root/ctscripts/{{item}} /usr/local/bin
with_items:
- a2dp-autoconnect
- simple-agent
- name: install services
shell: 'install /root/ctscripts/*.service /etc/systemd/system'
- name: fix issue created by bluealsa update
lineinfile:
path: /lib/systemd/system/bluealsa.service
regexp: ExecStart=/usr/bin/bluealsa.*
line: ExecStart=/usr/bin/bluealsa -p a2dp-sink -p hfp-hf -p hsp-hs --a2dp-volume
- name: modify modprobe to make USB default audio
lineinfile:
create: yes
path: /etc/modprobe.d/alsa-base.conf
line: 'options snd_usb_audio index=0'
- name: create alsa config file for stereo upmix
copy:
src: ./asound.conf
dest: /etc/asound.conf
- name: enable services
command: systemctl enable {{item}}
with_items:
- simple-agent
- name: create bluetooth udev rule
lineinfile:
create: yes
path: /etc/udev/rules.d/99-bluetooth-input.rules
line: 'KERNEL=="input[0-9]*", RUN+="/usr/local/bin/a2dp-autoconnect"'
- name: reboot
shell: "sleep 5 && reboot"
async: 1
poll: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment