GBD and BlueAlsa PCM - andy3471/GBD GitHub Wiki

Advanced Audio Distribution Profile (A2DP)

A2DP defines how multimedia audio can be streamed from one BT device to another. It supports transfers of an audio stream of up to 2 channels (stereo). The underlying and mandatory low-complexity Sub Band Codec (SBC) supports a maximum sample rate of 48 kHz.

Recall that GBD works optimally with audio signals whose PCM parameters correspond to CD quality sound (i.e. 44100Hz sample rate and 16-bit PCM), and it currently only supports stereo signals.

To explicitly configure BlueALSA for these PCM parameters, the following modification is made to its systemd service unit file:

$ cat /lib/systemd/system/bluealsa.service
...
ExecStart=/usr/bin/bluealsa --a2dp-force-audio-cd
...

For this change to take effect, either reboot (safest), or reload the systemd manager configuration (required since a unit file was modified) and then restart the BlueALSA daemon:

$ sudo systemctl daemon-reload      ## required since unit file was modified
$ sudo systemctl restart bluealsa.service
$ systemctl is-active bluealsa
active
$ systemctl status bluealsa
● bluealsa.service - BluezALSA proxy
   Loaded: loaded (/lib/[...]bluealsa.service; enabled; [...]
   Active: active (running) sinc ... 1min 11s ago
   Main PID: 15529 (bluealsa)
	CGroup: /system.slice/bluealsa.service
		   └─15529 /usr/bin/bluealsa --a2dp-force-audio-cd


$ ps ax | grep bluealsa
15529 ?        Ssl    0:00 /usr/bin/bluealsa --a2dp-force-audio-cd

$ journalctl -xf -u bluealsa

ALSA Period Size

The BlueALSA framework graciously includes a playback utility, bluealsa-aplay, which accepts streams from the BlueALSA PCM plugin and allows the user to redirect the signals to an ALSA virtual PCM device.

Recall that the GBD beat detection DSP algorithm expects ALSA period sizes of 1024 ALSA frames. The dmix based configurations for the gbd virtual PCM device presented in section Controlling ALSA Period Sizes via DMIX force most applications (including bluealsa-aplay) to use the required ALSA period size. Those configurations are especially useful if an audio player does not export switches that allow the user to specify/control the ALSA period size of its PCM output.

Now, depending on whether the GBD setup is economy or standalone RPi (see GBD Architecture), the ipaddr parameter will either point to the IP address of the remote RPi (economy setups) or the loopback IP address (standalone RPi models).

NOTE: As discussed in section Controlling ALSA Period Sizes via DMIX, RPi has had a history of issues with dmix -- but mainly when using the on-board audio interfaces. This problem may not exist with the PiHat soundcard addons. Nevertheless, if you still experience problems with dmix, then the basic plughw based gbd virtual PCM device presented in Basic (PCM Device) can alternatively be used with bluealsa-aplay since this utility exports a commandline switch that allows controlling its ALSA output latency (and therefore the ALSA period size of its PCM output). An example is illustrated in GBD and BlueALSA Playback.