I've changed the desktop environment in Raspbian Buster (running on the Raspberry Pi 4B) from PIXEL (based on LXDE) to Mate. I had several issues with the sound:
1. When I installed PulseAudio, I realized that the sound that was stereo under pure ALSA became mono after PulseAudio was installed.
2. Because of the mono sound, I decided to uninstall PulseAudio and run on pure ALSA. Therefore, I had to install blueasla from the Raspbian repository. I'm not sure now if bluealsa is installed in the standard Raspbian distribution with the PIXEL desktop. In any case, at least under Mate, bluealsa is mandatory to be able to stream audio to a Bluetooth audio device without PulseAudio.
3. The switcher applet that the Raspbian developers created as a plugin for lxpanel in PIXEL doesn't load in Mate desktop because this plugin is for lxpanel's system tray, and Mate has its own system tray. Hence, there's a conflict. So, I couldn't figure out a way to switch audio from the on-board audio controller to a Bluetooth audio device when running pure ALSA with bluealsa.
4. I tried many different .asoundrc configurations and tried to use pnmixer, but I could either stream to the Bluetooth headphones or to the on-board audio controller - based on the .asoundrc. I couldn't figure out a way to keep the same .asoundrc and switch audio outputs with a GUI utility. I posted a question on the bluealsa page on github, and there was a nice user @borine answered my question in a very easy to understand way. Basically, according to @borine, ALSA understands only the "default" device. Depending on the .asoundrc configuration, "default" can be defined a bluealsa pcm or the hardware pcm, but there is no easy way to switch from one to the other. Additionally, most applications that do not have a way to switch audio outputs diagrammatically within the application itself, send sound to "default". Therefore, if you are playing a video in Chromium from Youtube, the audio is sent to "default". The .asoundrc file can define what "default" is, but again, there is no way to switch from one device to another. I believe the lxpanel system tray plugin that Raspbian developers created rewrites the .asoundrc file depending on which device is selected in the plugin's GUI with a pointing device. That plugin also restarts ALSA and probably some other services to be able to redirect the sound from one device to the other. This was a proprietary solution created by Raspbian developers in the PIXEL desktop in Buster (and perhaps in Stretch - I don't know, as I was not a Raspberry user back then).
5. The only way to be able to switch audio output from the on-board audio controller to the Bluetooth audio device and back without having to overwrite the .asoundrc file is to use PulseAudio. I ended up having to install PulseAudio in order to be able to switch audio output from one device to another in GUI in Raspbian running Mate DE. PulseAudio, when installed in Raspbian, causes the sound directed out of the on-board analog jack to be mono. I'm not just talking about what shows in the audio mixers like alsamixer, alsamixergui, pnmixer, etc. I'm actually talking about playing a stereo test in Youtube and witnessing that when the video says that the audio should be playing out of the left speaker only, in reality, the audio is playing out of both speakers; same goes for when the audio should be playing out of the right speaker - in reality it plays out of both speakers.
6. It turns out that the fix for the mono audio out of the analog jack in Raspberry Pi 4B running Raspbian Buster with PulseAudio is very simple. All you have to do is to comment out one section in the file /usr/share/pulseaudio/alsa-mixer/profile-sets/default.conf
, as follows:
;device-strings = hw:%f
;channel-map = mono
;paths-output = analog-output analog-output-lineout analog-output-speaker analog-output-headphones analog-output-headphones-2 analog-output-mono
;paths-input = analog-input-front-mic analog-input-rear-mic analog-input-internal-mic analog-input-dock-mic analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line analog-input-headset-mic
;priority = 7
Then, reboot your Raspberry Pi, and you get stereo sound from the analog jack out of the on-board audio controller even with PulseAudio installed.
7. The remaining steps are:
a. Install PulseAudio from the Raspbian repository (if not installed):
Note: Don't forget to implement the fix to restore stereo sound, as described in Step 6 above.
b. Uninstall the bluealsa
package (if it's installed).
c. Install the pi-bluetooth
package (if it's not installed):
d. Install the blueman
package (if it's not installed):
e. Uninstall pnmixer
(if you installed it before because pnmixer doesn't see the Bluetooth audio device under PulseAudio):
f. Install pavucontrol
(Pulse Audio Volume Control). In Mate desktop, there's a default volume control plugin in system tray called mate-volume-control
. It is a stripped down version of pavucontrol
. However, I recommend installing pavucontrol
as well. pavucontrol
doesn't have a plugin in system tray, so you have to run it in a window. pavucontrol
has more features than mate-volume-control, and these features may come in handy.
g. Install Sound Switcher Indicator from this site
. This utility allows you to switch audio output from one device to another in real time (while audio is playing). You don't have to kill the application playing audio to switch the audio device where the audio is sent - as long as you are running PulseAudio on top of ALSA. This utility installs in the system tray (at least in Mate it does) upon reboot. Sound Switcher Indicator only works when PulseAudio is installed. If PulseAudio is not installed, then this utility reports an error and fails to start.
h. Reboot the Raspberry Pi.
8. At this point, you can pair a new Bluetooth audio device using the Blueman plugin (icon) in system tray. Then, you can use the Sound Switcher Indicator icon (plugin) that is automatically installed in system tray to switch audio devices from the on-board audio, to the HDMI audio, to the Bluetooth audio device in real time (while the audio is playing).
9. If you find that the volume coming out of the analog speakers (or another audio device) is too low with PulseAudio running over ALSA, all you have to do is to open pavucontrol
(Pulse Audio Volume Control) either from the shell typing pavucontrol
or from Applications -> Sound and Video
. You can do two things:
a. You can boost the volume of the particular application - under the Playback
tab of this utility (for example, you can adjust volume for just Chromium if you are playing something in a Chromium tab).
b. Alternatively, you can boost boost the volume above 100% (0 dB) for the entire system out of a particular audio device (on the Output tab), such as Analog Output
or Bluetooth Headphones.
Be careful and don't go too high, though, because you will cause distortion. You can safely go to 110% (2.49 dB) without extortion, which should give you loud enough volume comparable with what you get without PulseAudio when using ALSA directly.
After a month of tinkering with the sound and trying to get Bluetooth audio working and be able to easily switch between analog audio and Bluetooth audio, I have finally got it working. I can tell you that I'm very impressed with the sound quality: both out of the analog audio jack and via my Bluetooth Bose headphones. I'm using a cheap $20 set of Creative Pebble 2.0 speakers (powered by USB) with the Raspberry Pi 4B. The the sound quality is AMAZING with PulseAudio. It's unbelievable that I can get this quality out of a $50 computer and $20 speakers.
One piece of advice: don't plug USB-powered speakers in a Raspberry PI's USB port (or USB hub connected to a Raspberry Pi) or you will have too much static out of the speakers when moving the mouse. I even got static when I was running a speed test from speedtest.net when the speakers were powered by the Raspberry PI's USB port. Once I connected USB to a regular iPhone charger, all the static disappeared.
I hope this post will help someone save time and get the sound working properly on the Raspberry Pi.