[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

Hi

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


To check that the alsa is outputting the correct sample-rate and bit depth check in /proc/asound/card0/pcm0p/sub0/hw_params (see edit below)

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


----

EDIT:

I have disabled the Pi's internal soundcard so my DAC shows up in /proc/asound/card0. If you still have the internal card enabled your DAC will most likely be in /proc/asound/card1, but you can check in terminal with
Code: Select all
aplay -l


root@runeaudio(rw):~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0 []
Subdevices: 0/1
Subdevice #0: subdevice #0


----

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.

Enjoy!
Last edited by andfor on 20 Oct 2017, 20:15, edited 4 times in total.
User avatar
andfor
 
Posts: 57
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.
grofweg
 
Posts: 18
Joined: 30 Sep 2017, 11:37

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

Postby perryni » 17 Oct 2017, 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?
perryni
 
Posts: 14
Joined: 01 Mar 2016, 17:28

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

Postby janui » 18 Oct 2017, 22:39

Hi andfor,

Great guide, you may find this interesting: http://archimago.blogspot.nl/2016/10/me ... m5122.html

janui
User avatar
janui
 
Posts: 323
Joined: 20 Dec 2014, 12:55
Location: Ollanda

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

Postby andfor » 19 Oct 2017, 07:39

Hi perryni and janui,

Glad you found the guide useful. I'd be interested to know how you think the changes affected the sound, if at all. Positive or negative.

perryni wrote: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?


Have you got music playing when you check this file? If alsa is not running the file will just report that it is closed.


janui wrote:Hi andfor,

Great guide, you may find this interesting: http://archimago.blogspot.nl/2016/10/me ... m5122.html

janui


I have come across this blog before and it is very interesting. As to alsamixer settings, I have played around with them a little and I do notice a difference with the various DSP options. I think it's just down to personal preference really. As with all these fine adjustments, when the measured differences are so slight you're into territory where having a rug on the floor or not will make a difference. It's less about audio quality than about fine-tuning. And we all know where the devil lies..... :twisted:

In relation to resampling, I am more interested in whether there is a need to reduce the 'Analogue' or 'Digital' sliders by a few dB. Some articles mention that resampling could introduce a small amount of clipping for various technical reasons. I'm not sure which of the sliders would be best to use, or both? Any ideas?

Also, I have noticed small artefacts in the sound when changing tracks. Just a brief noise as one track changes to the other. It's almost like the last 1/10th of a second of audio gets repeated before playing the next track. Does anyone else hear anything similar? It's not a huge problem, just annoying.

Thanks for the feedback.
User avatar
andfor
 
Posts: 57
Joined: 26 Jun 2017, 15:48
Location: Birmingham, UK

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

Postby perryni » 19 Oct 2017, 15:39

Yes I have music playing while looking at the file which is why i find it strange that is states closed?

To me it sounds better although that could be positive bias?
perryni
 
Posts: 14
Joined: 01 Mar 2016, 17:28

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

Postby janui » 19 Oct 2017, 16:38

Hi andfor,
Glad you found the guide useful. I'd be interested to know how you think the changes affected the sound, if at all. Positive or negative.
Working on something else at the moment, I will post details of any sound changes later.
I agree with your remarks concerning personal preferences. The changes are just about measurable, which can only result in very subtle and difficult to hear changes.
In relation to resampling, I am more interested in whether there is a need to reduce the 'Analogue' or 'Digital' sliders by a few dB. Some articles mention that resampling could introduce a small amount of clipping for various technical reasons. I'm not sure which of the sliders would be best to use, or both? Any ideas?
There are two aspect here clipping and compression, this is interesting: http://archimago.blogspot.nl/2017/08/mu ... ge-of.html. I have been using MP3gain to reduce clipping (see: post21642.html?hilit=mp3gain#p21642), this works well for some music. Recently recorded classical music is great, but has little effect on anything old or compressed (remastered).
janui
User avatar
janui
 
Posts: 323
Joined: 20 Dec 2014, 12:55
Location: Ollanda

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

Postby perryni » 19 Oct 2017, 17:05

Hi andfor

Aplogies for my stupidity I was looking at the wrong card. My iqAudio DAC+ is card1 not card0 here is my output which confirms that resampling is happening.

Thanks again for the guide

Code: Select all
root@Ruark(rw):~# cat /proc/asound/card1/pcm0p/sub0/hw_params
access: RW_INTERLEAVED
format: S24_LE
subformat: STD
channels: 2
rate: 176400 (176400/1)
period_size: 16384
buffer_size: 65536
perryni
 
Posts: 14
Joined: 01 Mar 2016, 17:28

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

Postby andfor » 19 Oct 2017, 22:44

perryni wrote:Hi andfor

Aplogies for my stupidity I was looking at the wrong card. My iqAudio DAC+ is card1 not card0 here is my output which confirms that resampling is happening.

Thanks again for the guide

Code: Select all
root@Ruark(rw):~# cat /proc/asound/card1/pcm0p/sub0/hw_params
access: RW_INTERLEAVED
format: S24_LE
subformat: STD
channels: 2
rate: 176400 (176400/1)
period_size: 16384
buffer_size: 65536


Not stupid at all. My fault in fact. I had forgotten that I have disabled the internal soundcard on my pi, which means that the external DAC shows up as card 0 in that proc file. I will edit the guide to account for this.

By the way, to disable the internal card add (or edit) the line

Code: Select all
dtparam=audio=off


in /boot/config.txt.

janui wrote: There are two aspect here clipping and compression, this is interesting: http://archimago.blogspot.nl/2017/08/mu ... ge-of.html. I have been using MP3gain to reduce clipping (see: post21642.html?hilit=mp3gain#p21642), this works well for some music. Recently recorded classical music is great, but has little effect on anything old or compressed (remastered).
janui


Yes, the famous problem of dynamic range compression being favoured by some modern music production and mastering. Another bugbear to add to the list. :x This wasn't what I had in mind, though.

I had read somewhere that the resampling process itself requires some headroom and the resulting output might clip slightly in certain situations. I'll try and dig up the article if I can. For now I'm going to try a slight reduction in output dB and see if it makes any difference.

There are lots of other settings within the sox utility. Not sure if I want to open this particular can of snakes, but the documentation is worth a read: http://sox.sourceforge.net/sox.html
User avatar
andfor
 
Posts: 57
Joined: 26 Jun 2017, 15:48
Location: Birmingham, UK

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

Postby janui » 20 Oct 2017, 12:18

Hi andfor,
I had read somewhere that the resampling process itself requires some headroom and the resulting output might clip slightly in certain situations. I'll try and dig up the article if I can. For now I'm going to try a slight reduction in output dB and see if it makes any difference.
Shame SoX parameters cannot be set when it is used by MPD, it would be able to log clipping for you. Personally I wouldn’t worry too much about any clipping introduced by resampling. More important is that the music source is (reasonably) clipping-free. Again SoX is able to automatically change the volume/gain on the basis of content in order to minimise (or eliminate) clipping and again these features are not available when SoX is used by MPD. There are some really interesting SoX features which could be of interest as part of MPD, but I am also reluctant to open this "can of snakes" ;)
janui
User avatar
janui
 
Posts: 323
Joined: 20 Dec 2014, 12:55
Location: Ollanda

support RuneAudio Donate with PayPal

Next

Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 4 guests
cron