[Guide] Using Soxr Resampling with Rune 0.4 Beta

Raspberry Pi related support

[Guide] Using Soxr Resampling with Rune 0.4 Beta

Postby andfor » 12 Oct 2017, 16:22


I thought I would share how I got Soxr resampling working on Rpi3 with Rune 0.4 Beta so you can resample audio to higher (or lower!) sample-rates before sending to a DAC. Whether or not this is a good thing in terms of audio quality is debatable, some people want bit-perfection at all costs, some are flexible as long as the sound is good, but if you're anything like me you won't be able to resist messing around with settings! :) I use a home-made amp that is very transparent. Resampling seems to add a little colour to the sound and stops the audio appearing too harsh. The quality is still excellent. You'll have to try it for yourself to see if it has any positive or negative impact on your system.

Obviously I can't guarantee that doing this won't break your installation so back up your SD image. It has worked fine for me and I am currently resampling all audio to 24bit 176.4kHz (with Hifiberry DAC+ PRO). I chose this sample-rate because most of my audio is ripped CDs and radio streams which are predominantly 44.1khz and there is some opinion online that whole number conversion ratios are better (4 x 44.1 = 176.4). You can chose any sample rate and bit-depth that your setup can handle.

I originally came across the possibility of doing this here: tweaking-the-audio-performance-rpi3-t4301.html?hilit=audio%20tweaks and this thread is well worth a read through. I have implemented many of the recommended tweaks and have seen a definite improvement in sound. The only issue I had was that soxr didn't seem to be working.

I finally realised that 0.4 Beta uses MPD version 0.19.19, but MPD did not have support for soxr until version 0.20. So if you want to use soxr you need to update MPD to version 0.20.6 as desribed in gearhead's post here: runeaudio-0-4-beta-for-raspberry-pi2-3-t4434-150.html#p20574

The post is a bit confusing (at least for a neophyte like me) so here's how to do the update and set soxr sample-rate and bit-depth:

1) Download the file 'mpd-20_6-rune.tar.gz' from https://drive.google.com/open?id=0B7NZO ... UFyd19ENE0

2) Put this file on your pi somewhere. For ease I just put it in the root folder. I use WinSCP for this (see adding-folders-by-ftp-t5381.html#p22411). Root folder is at /home/root/

3) Unpack the archive. This can be done either inside WinSCP (Right-click archive file, 'File Custom Commands', 'UnTar/GZip' Click the OK button twice). Or you can do it in terminal with:
Code: Select all
tar xvzf mpd-20_6-rune.tar.gz

(note: this is if you put the archive in the root folder. If not, specify the path: 'tar xvzf your/path/to/the/archive/mpd-20_6-rune.tar.gz')

4) Install the package with:
Code: Select all
pacman -U mpd-rune/mpd-rune-0.20.6-1-armv7h.pkg.tar.xz

(note: again this is if you unpacked the archive in the root folder. If not, specify: pacman -U your/path/to/the/folder/mpd-rune/mpd-rune-0.20.6-1-armv7h.pkg.tar.xz )

5) Check MPD has been updated with:
Code: Select all
pacman -Q | grep mpd-rune

root@runeaudio(rw):~# pacman -Q | grep mpd-rune
mpd-rune 0.20.6-1

6) Now edit the file /etc/mpd.conf. I would advise making a backup copy of this file just in case anything goes wrong. The package installation will have created a file called mpd.conf.pacnew, but you can ignore this or delete it.

To edit mpd.conf you first have to make it modifiable with:
Code: Select all
 chattr -i /etc/mpd.conf

Below is my mpd.conf with the additional/modified lines highlighted. Don't copy/paste this whole text, just add/alter the lines in the relevant places. (Verbose logging is just for checking that soxr is enabled. You can change this back to default after checking.)

log_level "verbose"
log_file "/var/log/runeaudio/mpd.log"
state_file "/var/lib/mpd/mpdstate"
zeroconf_enabled "yes"
zeroconf_name "runeaudio"
bind_to_address "/run/mpd.sock"
bind_to_address "any"
port "6600"
max_connections "20"
user "mpd"
group "audio"
db_file "/var/lib/mpd/mpd.db"
sticker_file "/var/lib/mpd/sticker.sql"
pid_file "/var/run/mpd/pid"
music_directory "/mnt/MPD"
playlist_directory "/var/lib/mpd/playlists"
follow_outside_symlinks "yes"
follow_inside_symlinks "yes"
auto_update "no"
filesystem_charset "UTF-8"
id3v1_encoding "UTF-8"
volume_normalization "no"
audio_buffer_size "4096"
buffer_before_play "20%"
gapless_mp3_playback "yes"
mixer_type "disabled"
replaygain "off"

input {
plugin "curl"

decoder {
plugin "ffmpeg"
enabled "yes"

resampler {
plugin "soxr"
quality "very high"

audio_output {
name "snd_rpi_hifiberry_dacplus"
type "alsa"
device "hw:0,0"
format "176400:24:2"
auto_resample "no"
auto_format "no"
enabled "yes"

To select a different sample-rate and bit-depth alter the line:
format "176400:24:2"

eg for 192KHz 24bit you would enter:
format "192000:24:2"

If you want MPD to preserve the file's original bit-depth or sample-rate use an asterisk. For example:
format "48000:*:2"
will not change the bit-depth, but resample every file to 48KHz.

You can also enable multi-threading to allow soxr to utilise multiple CPU cores for a possible speed boost. I haven't tried this yet so can't verify that it works. This is not enabled by default in MPD. I don't have this enabled because I have isolated MPD to a single core of the CPU, but if you want to try it alter the following:

resampler {
plugin "soxr"
quality "very high"
threads "0"

VERY IMPORTANT: when you are done editing mpd.conf make it unmodifiable again with:
Code: Select all
chattr +i /etc/mpd.conf

7) Reboot. Cross fingers.

Assuming your system reboots ok start some music playing and check your MPD log file at /var/log/runeaudio/mpd.log to see that MPD is using soxr to resample. You are looking for something like the lines below:

Oct 12 13:36 : alsa_output: format=S24_LE (Signed 24 bit Little Endian)
Oct 12 13:36 : alsa_output: buffer_size=65536 period_size=16384
Oct 12 13:36 : output: opened plugin=alsa name="snd_rpi_hifiberry_dacplus" audio_format=176400:24:2
Oct 12 13:36 : soxr: soxr engine 'double-precision'
Oct 12 13:36 : soxr: samplerate conversion ratio to 4.00
Oct 12 13:36 : output: converting in=44100:16:2 -> f=44100:16:2 -> out=176400:24:2

Also check that the alsa is outputting the correct sample-rate and bit depth in /proc/asound/card0/pcm0p/sub0/hw_params:

format: S24_LE
subformat: STD
channels: 2
rate: 176400 (352800/2)
period_size: 16384
buffer_size: 65536

After checking change the log level back to default in mpd.conf (don't forget to make the file modifiable as above and unmodifiable when you're done!):
log_level "default"

That's it! On my system MPD is using 10 - 15% of CPU and running without problems so far.

Last edited by andfor on 12 Oct 2017, 17:25, edited 2 times in total.
User avatar
Posts: 13
Joined: 26 Jun 2017, 15:48
Location: Birmingham, UK

Re: [Guide] Using Soxr Resampling with Rune 0.4 Beta

Postby grofweg » 12 Oct 2017, 16:49

Thanks! Good read. After my vacation I will definitely try this in combination with my Allo Boss.
Posts: 6
Joined: 30 Sep 2017, 11:37

Re: [Guide] Using Soxr Resampling with Rune 0.4 Beta

Postby perryni » Yesterday, 15:54

Thanks for the info.

All has gone smooth for me except trying to check the hw_params, all I get is the answer Closed?

My command is
Code: Select all
cat /proc/asound/card0/pcm0p/sub0/hw_params

Is there something missing?
Posts: 12
Joined: 01 Mar 2016, 17:28

support RuneAudio Donate with PayPal

Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 3 guests