Skip to main content

Topic: Configuring Linux ALSA/Pulseaudio for best sound (Read 24586 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
Configuring Linux ALSA/Pulseaudio for best sound
So I have been listening to a bunch of hokum and voodoo at some other head hifi forum where abx testing is banned and I need some reeducation. 

I run linux at home and I use kde.  As I understand little about sound and how all the parts of the linux sound system work together, I would like to help to make sure that my sound is being output in the best fidelity possible.

So I used KDE that means I have the phonon sound system on top of the pulseaudio sound server on top of the ALSA sound system (whew!).

My onboard soundcard is an HDA-Intel Realtek ALC275 that does 16/24 bitrate and 44.1-192 sampling.

So most of my music is in 16/44.1 FLAC format, but some is 24/96 FLAC.

I use amarok and deadbeef to play my music.

I just want to make sure that I am not doing any resampling that will introduce any distortion or noise.

Sorry if this a topic that has been answered numerous times, but I searched and couldn't find anything that helped answer this.

Thanks for the input.

Configuring Linux ALSA/Pulseaudio for best sound
Reply #1
Wow, lots of viewers, but few posters, I'll take that as a gentle indication that I am asking a stupid or confusing question. 

Am I mistaken that upsampling causes unwelcome and audible distortion and other undesirable effects?

Does anyone know what the ALSA and Pulseaudio defaults with respect to bit depth and sample rate are?  I haven't touched either configuration since a vanilla install.  I am just concerned that I would prefer all data to either be handled at its actual bit/sample rate or alternatively be downsampled to 16/44.1 (which if I am not mistaken, will cause almost no audible loss/nasties given a good downsampling mechanism/function). 

I am really concerned about ALSA or Pulseaudio deciding to upsample my music as I am led to believe that such upsampling is undesirable if avoidable.  Any help is appreciated.

  • skamp
  • [*][*][*][*][*]
  • Developer
Configuring Linux ALSA/Pulseaudio for best sound
Reply #2
In order to be able to play several sounds at the same time (like, music coming from your player + system sounds, or the ability to pause your music and watch a YouTube video), you have to use a common sampling rate, there's no getting around it. At best, you can stop using Pulse Audio (i.e. have all your software output to an ALSA device directly), and any software playing sound will be blocking the device for the duration of playback (no resampling involved unless your sound card doesn't support the sampling rate that your software is outputting).

If you choose to use Pulse Audio (or ALSA's dmixer, or jackd or whatever) and thus have to resort to resampling (defaults to 48kHz IIRC, but don't quote me on that), you can set the quality of the resampling algorithm to something that doesn't suck (i.e. that doesn't introduce any audible distortion). One way to do that is to install libsamplerate and alsa-plugins, and add the following line at the top of your /etc/asound.conf or ~/.asoundrc file:

Code: [Select]
defaults.pcm.rate_converter "samplerate"


You can change the quoted value to "samplerate_medium" or "samplerate_best", which will give you increasing levels of quality at the expense of CPU usage, but "samplerate" should be sufficient. To make sure that your system is indeed taking your configuration into account, you may set the quoted value to "samplerate_best" and watch your CPU usage while playing some music or a movie, it should be significant.

Hope that helps. If you require more help, I refer you to #alsa on Freenode (IRC).
  • Last Edit: 19 March, 2012, 02:49:46 PM by skamp
See my profile for measurements, tools and recommendations.

Configuring Linux ALSA/Pulseaudio for best sound
Reply #3
Hey thanks, that's perfect.  I think you are correct concerning the 48kHz default by the way, I seem to recall reading this somewhere as well.  It was for this reason that I was asking as I imagined that my sound system was upsampling my 16/44.1 music to 48kHz.  I will add an /etc/asound.conf entry and get that to work.  Thanks for the help!
  • Last Edit: 09 April, 2012, 02:24:13 PM by db1989

Configuring Linux ALSA/Pulseaudio for best sound
Reply #4
I don't think ALSA does any samplerate conversion if PulseAudio (or especially Jackd) is being used, as PulseAudio uses direct access to the card

but Pulse has a few audio settings that change the sample-rate conversion algorithm, and default sample rate

Not in Linux at the moment so bare with me, /etc/pulse/daemon.conf should have settings in it

man pulse-daemon.conf should list the possible resample algorithms (and bit depth there)

there's a few options which are well documented in other parts of the internet, the 'src' ones are of good quality, Google "Secret Rabbit Code"

for the finer details, but generally the 'sinc' algorithms are the only good subset, and the "fastest" setting starts cutting off frequencies at 80% (17.5kHz*), the "medium" does so at 90% (19.8Khz*), and the "best" one does 97%(21.4kHz*), each one uses more CPU so if you're on a laptop I would avoid the "best" options as it uses about 40% CPU last time I tried, and all have a SNR of 97dB.

not sure about the speex-float or other speex algorithms, but the speex-float of quality 10 looks OK but maybe be very CPU intensive like the secret rabbit code's 'best' setting.

you should also try the SoX utility to covert the 24/96 to 16/44.1 for portable players etc, and has the ability to use SRC if you want to ABX.

* (based on the base rate of 44.1kHz)

hopefully this is useful info (also my first post    )

Configuring Linux ALSA/Pulseaudio for best sound
Reply #5
I just want to make sure that I am not doing any resampling that will introduce any distortion or noise.

As I understand things.  You have two options. One is to find a player that enables "passthrough" which effectively by-passes any re-sampling.  The other is to use a dlna streamer (assuming you have a dlna enabled receiver). Linux is not (yet anyway) well served on the audio front.  It all depends on what sort of music you play. If, like me, you have a need for gapless playing, then finding a solution that is both gapless and avoids resampling is quite hard (I haven't found one yet that will cope with all the different file resolutions that I have).  I understand it's possible to run Windows players in Virtualbox, but I'm not keen to go down that route.

  • phofman
  • [*][*][*][*]
Configuring Linux ALSA/Pulseaudio for best sound
Reply #6
If, like me, you have a need for gapless playing, then finding a solution that is both gapless and avoids resampling is quite hard (I haven't found one yet that will cope with all the different file resolutions that I have).  I understand it's possible to run Windows players in Virtualbox, but I'm not keen to go down that route.


Hmm, it would appear to me that gapless and bit-perfect are two independent features.  The first depends on the player itself, the second on the output device setup of the player. What specific problems did you encounter, in which software?

  • Kohlrabi
  • [*][*][*][*][*]
  • Global Moderator
Configuring Linux ALSA/Pulseaudio for best sound
Reply #7
I understand it's possible to run Windows players in Virtualbox, but I'm not keen to go down that route.

What about wine + foobar2000?
It's only audiophile if it's inconvenient.

  • skamp
  • [*][*][*][*][*]
  • Developer
Configuring Linux ALSA/Pulseaudio for best sound
Reply #8
If, like me, you have a need for gapless playing, then finding a solution that is both gapless and avoids resampling is quite hard


Deadbeef is one player that's gapless and can play without resampling. Whether your sound card supports the sample rates you throw at it, is another story.

What about wine + foobar2000?


On my setup, wine + foobar2000 resamples at 44.1 kHz, I haven't figured out why yet.
See my profile for measurements, tools and recommendations.

  • cpchan
  • [*][*][*][*]
Configuring Linux ALSA/Pulseaudio for best sound
Reply #9
I don't think ALSA does any samplerate conversion if PulseAudio (or especially Jackd) is being used, as PulseAudio uses direct access to the card


No, Pulseaudio actually outputs to hardware through ALSA, but it will resample because one of its function is to act as a software mixer. However, if you use ALSA directly and set it up to output to hardware (instead of going through dmix)- it will not resample.
  • Last Edit: 11 April, 2012, 03:57:03 PM by cpchan

  • cpchan
  • [*][*][*][*]
Configuring Linux ALSA/Pulseaudio for best sound
Reply #10
If, like me, you have a need for gapless playing, then finding a solution that is both gapless and avoids resampling is quite hard (I haven't found one yet that will cope with all the different file resolutions that I have).  I understand it's possible to run Windows players in Virtualbox, but I'm not keen to go down that route.


Huh, all you have to do is to:

  • Setup ALSA to output to hardware instead of dmix. Dmix is used by default for all non-multichannelled cards. Here is a sample /etc/asound.conf or ~/.asoundrc for harware ouput:

    Code: [Select]
    pcm.!default {
        type hw
        card 0
    }

    ctl.!default {
        type hw          
        card 0
    }

  • Use a player that supports gapless playback. I personally use mpd.


I don't understand your problem.
  • Last Edit: 11 April, 2012, 03:48:30 PM by cpchan

Configuring Linux ALSA/Pulseaudio for best sound
Reply #11
I just want to make sure that I am not doing any resampling that will introduce any distortion or noise.

As I understand things.  You have two options. One is to find a player that enables "passthrough" which effectively by-passes any re-sampling.  The other is to use a dlna streamer (assuming you have a dlna enabled receiver). Linux is not (yet anyway) well served on the audio front.  It all depends on what sort of music you play. If, like me, you have a need for gapless playing, then finding a solution that is both gapless and avoids resampling is quite hard (I haven't found one yet that will cope with all the different file resolutions that I have).  I understand it's possible to run Windows players in Virtualbox, but I'm not keen to go down that route.


So this "passthrough" you speak of, is this something that works with pulseaudio or is it something that talks to ALSA directly? I ask because I plan to build a networked pulseaudio server out of a router and a DAC so that I don't have to have any wires attached to my laptop. However, I'm not willing to sacrifice sound quality to do it...

  • skamp
  • [*][*][*][*][*]
  • Developer
Configuring Linux ALSA/Pulseaudio for best sound
Reply #12
You can't have software mixing without resampling, unless every software uses the same sampling rate (which they don't): a music player will output at 44.1 kHz (if you're listening to CD-DA material) while a movie player will output at 48 kHz. There's no way around that.

If you're gonna use PulseAudio, there will be resampling, by design. With ALSA (and presumably with PulseAudio) you can set the quality of the resampling, though, to something that doesn't suck.
See my profile for measurements, tools and recommendations.

  • beatgeek
  • [*]
Configuring Linux ALSA/Pulseaudio for best sound
Reply #13
I know this is an old thread, but for people searching for information on configuring their linux boxes for best sound quality, this is the first thread to pop up.

Anyway, I'd like to give another shoutout for deadbeef as an audio player. By default most linux distributions ship with alsa and pulse audio set up to do mixing, and if you really want to mess with config files, see the above posts, or have a look at this wiki. This all assumes you'd be uninstalling pulse audio, which is kind of a hassle, may break stuff, and you lose the features of pulse. However, for me, the simplest, most elegant solution was to simply install deadbeef and change the output plugin to ALSA, the output device to my "direct hardware device without any conversions", remove the resampling DSP, and configure the ALSA output plugin to uncheck "use ALSA resampling".

That way, when I want to listen to quality music, I can do so uninterrupted by system sounds or singing webpages, because deadbeef monopolizes your sound device. Then, when I want to listen to youtube or whatever, I still get the benefits of software mixing while not caring about the quality because, uh, it's youtube. And when I want to watch DVD's, they're already at 48 kHz so there's no resampling. And I don't have to futz with ALSA or pulse. Win, win, win.


  • phofman
  • [*][*][*][*]
Configuring Linux ALSA/Pulseaudio for best sound
Reply #14
Until something (most likely pulseaudio, or stuck flashplayer) monopolizes your soundcard first, before deadbeat gets its chance 

Then you have to find the culprit and kill it. Not many other options though if the requirement is no mixing and only one soundcard.
  • Last Edit: 21 February, 2013, 11:31:08 PM by phofman