IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Configuring Linux ALSA/Pulseaudio for best sound
chickpea23
post Mar 18 2012, 21:27
Post #1





Group: Members
Posts: 3
Joined: 18-March 12
Member No.: 97891



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.
Go to the top of the page
+Quote Post
chickpea23
post Mar 19 2012, 18:40
Post #2





Group: Members
Posts: 3
Joined: 18-March 12
Member No.: 97891



Wow, lots of viewers, but few posters, I'll take that as a gentle indication that I am asking a stupid or confusing question. unsure.gif

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.
Go to the top of the page
+Quote Post
skamp
post Mar 19 2012, 19:47
Post #3





Group: Developer
Posts: 1440
Joined: 4-May 04
From: France
Member No.: 13875



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
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).

This post has been edited by skamp: Mar 19 2012, 19:49


--------------------
See my profile for measurements, tools and recommendations.
Go to the top of the page
+Quote Post
chickpea23
post Mar 19 2012, 21:20
Post #4





Group: Members
Posts: 3
Joined: 18-March 12
Member No.: 97891



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!

This post has been edited by db1989: Apr 9 2012, 19:24
Reason for edit: removing pointless full quote of above post
Go to the top of the page
+Quote Post
YellowOnion
post Apr 9 2012, 19:18
Post #5





Group: Members
Posts: 29
Joined: 9-April 12
Member No.: 98589



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 blink.gif )
Go to the top of the page
+Quote Post
Richard Kimber
post Apr 11 2012, 11:46
Post #6





Group: Members
Posts: 25
Joined: 10-April 12
Member No.: 98632



QUOTE (chickpea23 @ Mar 18 2012, 21:27) *
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.
Go to the top of the page
+Quote Post
phofman
post Apr 11 2012, 12:43
Post #7





Group: Members
Posts: 304
Joined: 14-February 12
Member No.: 97162



QUOTE (Richard Kimber @ Apr 11 2012, 11:46) *
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?
Go to the top of the page
+Quote Post
Kohlrabi
post Apr 11 2012, 15:51
Post #8





Group: Super Moderator
Posts: 1046
Joined: 12-March 05
From: Kiel, Germany
Member No.: 20561



QUOTE (Richard Kimber @ Apr 11 2012, 12:46) *
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?


--------------------
Ceterum censeo Masterdiskem esse delendam.
Go to the top of the page
+Quote Post
skamp
post Apr 11 2012, 16:24
Post #9





Group: Developer
Posts: 1440
Joined: 4-May 04
From: France
Member No.: 13875



QUOTE (Richard Kimber @ Apr 11 2012, 12:46) *
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.

QUOTE (Kohlrabi @ Apr 11 2012, 16:51) *
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.
Go to the top of the page
+Quote Post
cpchan
post Apr 11 2012, 20:39
Post #10





Group: Members
Posts: 299
Joined: 14-July 07
Member No.: 45304



QUOTE (YellowOnion @ Apr 9 2012, 14:18) *
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.

This post has been edited by cpchan: Apr 11 2012, 20:57
Go to the top of the page
+Quote Post
cpchan
post Apr 11 2012, 20:42
Post #11





Group: Members
Posts: 299
Joined: 14-July 07
Member No.: 45304



QUOTE (Richard Kimber @ Apr 11 2012, 06:46) *
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:

  1. 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
    pcm.!default {
        type hw
        card 0
    }

    ctl.!default {
        type hw          
        card 0
    }

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


I don't understand your problem.

This post has been edited by cpchan: Apr 11 2012, 20:48
Go to the top of the page
+Quote Post
AudioKitten
post Apr 11 2012, 20:44
Post #12





Group: Members
Posts: 18
Joined: 11-April 12
Member No.: 98656



QUOTE (Richard Kimber @ Apr 11 2012, 03:46) *
QUOTE (chickpea23 @ Mar 18 2012, 21:27) *
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...
Go to the top of the page
+Quote Post
skamp
post Apr 12 2012, 06:17
Post #13





Group: Developer
Posts: 1440
Joined: 4-May 04
From: France
Member No.: 13875



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.
Go to the top of the page
+Quote Post
beatgeek
post Feb 21 2013, 18:34
Post #14





Group: Members
Posts: 1
Joined: 21-February 13
Member No.: 106791



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.

Go to the top of the page
+Quote Post
phofman
post Feb 22 2013, 05:29
Post #15





Group: Members
Posts: 304
Joined: 14-February 12
Member No.: 97162



Until something (most likely pulseaudio, or stuck flashplayer) monopolizes your soundcard first, before deadbeat gets its chance smile.gif

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.

This post has been edited by phofman: Feb 22 2013, 05:31
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 16th September 2014 - 05:10