Volumio2 on RPi Zero W with PhatBeat DAC and PulseAudio!

Hi everyone,

I would like to introduce you to my little achievement that was sparkled by a Christmas gift of Pimoroni Pirate Radio - a cool DIY music player project based on RPi Zero W and PhatBeat DAC.

You can find my new project details there: Pimoroni Pirate Radio Project Enhanced, together with my short reviews of some of music-oriented OSes and software for this combination.

To the point. I’ve managed to successfully replace ALSA with PulseAudio in Volumio2! :slight_smile:

As some of you may know, Volumio is tighly coupled with ALSA, and the trouble in my case is, PhatBeat DAC does not really work well with ALSA. While sound quality is ok, the volume is about 20% of what the hardware is capable of, and any attempt to amplify the volume failed. Therefore, I decided to try to modify the PhatBeat library installer so that it performs the complete installation on Volumio2.

In short, instead of running the proposed command that automatically executes the installer after download, just download the script from get.pimoroni.com/phatbeat and edit it before execution, changes are:

  1. replace OS_NAME=“Volumio” with OS_NAME=“Raspbian” to fool the script (line 232)
  2. comment out raspbian_check function execution (line 571)
  3. replace line curl -sS $GETPOOL/pulseaudio | bash -s - “-y” with bash ./pulseaudio.sh -y (line 1109), download get.pimoroni.com/pulseaudio script and name it pulseaudio.sh, place it next to phatbeat installer script, and make similiar changes:
    [list=a]
    [*] replace raspbianonly=“yes” with raspbianonly=“no” (line 43)
  4. replace OS_NAME=“Volumio” with OS_NAME=“Raspbian” to fool the script (line 232)
  5. comment out raspbian_check function execution (line 571)
    [/*:m][/list:o]

That should do it, now give exec rights to both files (chmod +x phatbeat.sh pulseaudio.sh) and run phatbeat.sh. During installation, you may skip download of documentation and examples, and I’ve agreed to install Python 3, however not sure if it’s required.

After installation, go to /etc/mpd.conf and in audio_output node comment out the line device “hw:0,0” (#-style comments), then save it.

Now, restart Volumio, and after bootup (the startup sound might be gone), go to the UI, then “Playback Options”, and choose “Hifiberry DAC” as your Output Device. That’s all. Do not tick “I2S DAC”, do not change anything else (unless you are up for trouble) :slight_smile:

Done! Time to play some music :slight_smile:

Now, to the current limitations (I’m working on them):

  • you cannot change volume from the UI. To change volume, you need to use terminal command pactl set-sink-volume 0 100% (replace 100% with your desired value, you may set values >100%, I found 150-180% to be the maximum for the hardware). I’m currently working on a Volumio plugin to fix that issue, stay tuned.
  • volume of the sound depends on the source type. Not sure if it’s PulseAudio fault, but you may enable volume normalization in [i]/etc/mpd.conf[i] - just replace line volume_normalization “no” with volume_normalization “yes” (line 79). It works quite OK, however sometimes I notice the volume get’s a little up or down, even in the middle of a song… Weird, but not solved yet.
  • startup sound is gone - it’s not important for me now, but I will look into it soon

When I make things steady, I may do a pull request to PhatBeat repo to make the installer work for Volumio by default :wink:

That’s all I wanted to share. Let me know if case of any questions or problems!

Cheers!

Great achievement mate. Especially because Pulseaudio could allow the so hoped synced multiroom playback tight into Volumio.

What about performance? Is the PI0 enough for PA?

-j

I haven’t noticed any performance degradation since switching from ALSA to PulseAudio. In the mean time, I also solved a few issues. First of all, I finished first version of plugin to enable volume control after switching to PA, however I probably will not publish it soon as Volumio took a few weeks trip with my girlfriend so I cannot fine-tune it. Then, I’ve also fixed the startup sound, the problem was due to the fact how it’s played - by command: /usr/bin/aplay --device=plughw:0,0 /volumio/app/startup.wav. I removed the “device” part, and now it works well, as then the default device is chosen, which is our DAC in PA :wink: And last thing, in the end, I’ve turned off volume normalization in MPD as it was something else that I throught it is - you can read about the used algorithm there: beesbuzz.biz/code/audiocompress.php . Now, since it still bothers me that tracks from Youtube are about 20% louder than BBC R1 internet radio, I’m thinking of developing a plugin that would allow dynamic volume change depending on audio source…

Hi Micx,
currently rebuilding the Pirate Radio (Pi Zero W and Phat BEAT) to Volumio.
I am interested to find out if you managed to use the VU-meter. I could not really find it in your first post.
Best regards,
Wilco

Hello, can I use bluetooth?The phone’s bluetooth connection to the raspberry pie makes it play through I2S

Hi micx,

Would you be willing to share that volume plugin? I’m trying to get volumio running on my Pirate Radio too and this 100% volume is quite annoying.

Just for extra info:
I tried to implement the fix for the start-up sound…
The method I found was to correct a line in the /volumio/app/platformSpecific.js
Changing it from
execSync(’/usr/bin/aplay ’ + hwdev + ’ /volumio/app/startup.wav’);
to
execSync(’/usr/bin/aplay ’ + ’ /volumio/app/startup.wav’);

This should remove “–device=plughw:0,0” from the command, hopefully correcting it as you indicated.

I’ve Tested this now, it works on the next restart just fine! :slight_smile:

Another note on this step: Volumio will (now?) overwrite the changes to the alsa config, any time you change the audio device settings. - So you should check if you need to repeat this step again, after correcting the Volumio settings to use the Hifiberry DAC as your output device.

If like me you have issues getting sound working… here’s a tip… volumio save’s it’s logs to journalctl - so use “sudo journalctl -f” to see if it’s reporting issues:

In my case it very quickly identified a typo in my /etc/mdp.conf file that i’d been messing with.

Nov 14 01:20:16 volumio systemd[1]: Starting Music Player Daemon...
Nov 14 01:20:16 volumio volumio[1395]: error: Upnp client error: Error: connect ETIMEDOUT 127.0.0.1:6600
Nov 14 01:20:21 volumio mpd[2642]: Nov 14 01:20 : exception: Failed to configure output in line 61
Nov 14 01:20:21 volumio mpd[2642]: Nov 14 01:20 : exception: nested: No such audio output plugin: pulse
Nov 14 01:20:21 volumio systemd[1]: mpd.service: main process exited, code=exited, status=1/FAILURE
Nov 14 01:20:21 volumio systemd[1]: Failed to start Music Player Daemon.*

Try this: https://github.com/pimoroni/pivumeter
Install the pivumeter package on it’s own… then you can the instructions for setting up the vumeter here: https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-phat-beat
Which are basically add it to your Alsa setup:
The ALSA configuration file is located at /etc/asound.conf . You can edit it, in the terminal, by typing sudo nano /etc/asound.conf .

pcm_scope.pivumeter {
    type pivumeter
    decay_ms 500
    peak_ms 400
    brightness 128
    output_device phat-beat
}

I have to admit… I did a lot of things to try to get it to work, while I was following micx’s instructions to migrate from asla to pulse audio… and I’m not sure if these were the magic steps that made it work… and I know that it’s still pretty flakey - let me know if it works!