IPB

Welcome Guest ( Log In | Register )

ALSA sample rate conversion, ALSA uses a poor-quality linear interpolator
cabbagerat
post Aug 21 2006, 10:56
Post #1





Group: Members
Posts: 1018
Joined: 27-September 03
From: Cape Town
Member No.: 9042



The newer versions of ALSA (the Advanced Linux Sound Architecture) enable software mixing by default. All sounds which are played are converted to 48kHz (by default) and mixed in software. When I installed the new Ubuntu and it was set up this way, I was somewhat concerned about the sound quality implications of this setup. I dove into the ALSA source and discovered some very interesting things.

The first issue is the actual mixing. This is done with 24 bits of precision (32 bits are used internally, but the lowest 8 are used for saturation). The algorithm seems to be fairly good and I don't see any major quality implications are using it.

The second (and much bigger) issue is sample rate conversion. Obviously for software mixing all the signals need to be converted to a single rate. This rate, by default, is 48kHz. The algorithm used by default is a very rudimentry linear interpolation algorithm. This algorithm is fast but very low quality and is likely to audibly degrade the sound quality of 44100 material played through a mixed device. I tested this SRC using a loopback cable and some generated square, sine and triangle waves of various frequencies. It appears to add harmonic distortion of around -10dB in some cases and about -20dB on music. I'll post some graphs when I get home this afternoon.

There are a number of solutions to this problem.

1) Install the libasound_module_rate plugin and set defaults.pcm.rate_converter "samplerate_best" in your .asoundrc. This plugin uses the SRC_SINC_BEST_QUALITY algorithm from libsamplerate and seems to offer excellent quality. The problem here is that most distributions don't package this plugin and it is only included with very new versions of ALSA. I would say this is the ideal solution and it would be nice if the ALSA developers would make this (or at least libsamplerate's SRC_SINC_FASTEST algorithm) the default.

2) Set the dmix plug to use 44.1kHz. This is great if you are mostly listening to 44.1kHz material, but not so useful if you are listening to a mixture of 48kHz and 44.1kHz material.

3) Create seperate plugs for 44.1kHz and 48kHz material. This works fine if you don't want software mixing to work when playing both types of material simultaneously. A good setup here would be a 44.1kHz plug for used by default and by your MP3 player and a 48kHz plug used by your movie player. System sounds and other stuff can use either (I don't generally care about sound quality when watching Google Video content, for example).

ALSA by default seems to offer very dissapointing sound quality, but it is possible to set it up to offer much better quality. I will post a detailed guide in the next couple of days to explain how to set up your Linux machine for better playback and capture quality.


--------------------
Simulate your radar: http://www.brooker.co.za/fers/
Go to the top of the page
+Quote Post
 
Start new topic
Replies
CyberFoxx
post Aug 24 2006, 10:11
Post #2





Group: Members
Posts: 62
Joined: 15-August 02
Member No.: 3062



Well, I just did a quick test of udial, before I get around to ABXng with it. Man, playing that through hw is havoc with my SB Live!, there's a weird sweeping noise that starts after the third tone. And, I'm getting the same sound with the default device as well. Using samplerate_linear and dmix the sound is quite a bit different, more smoother I guess.

... OK, samplerate_order sounds exactly the same as hw, just the weird noise is a tiny bit louder.

And, I can tell right away that samplerate sounds better on udial than samplerate_best. samplerate_best has some added freqs on the last four tones. Same with samplerate_medium. What I find odd is that the default device is supposed to use dmix, or so that's what the ALSA docs have been saying. But clearly by the sounds of it, it's just be an alias to hw. Maybe the ALSA setup under Gentoo is different, not sure...


--------------------
"It's the panties fault! The panties made me a pervert!"
Go to the top of the page
+Quote Post

Posts in this topic
- cabbagerat   ALSA sample rate conversion   Aug 21 2006, 10:56
- - iGold   At least for Creative game soundcards with only on...   Aug 21 2006, 11:38
- - cabbagerat   QUOTE (iGold @ Aug 21 2006, 02:38) At lea...   Aug 21 2006, 12:13
- - seanyseansean   Thanks for the info. I'm replacing amarok and ...   Aug 21 2006, 12:34
- - iGold   After quick look at sources of ALSA I can say what...   Aug 21 2006, 12:47
- - cabbagerat   QUOTE (seanyseansean @ Aug 21 2006, 03:34...   Aug 21 2006, 13:03
|- - seanyseansean   QUOTE (cabbagerat @ Aug 21 2006, 13:03) Q...   Aug 21 2006, 16:15
|- - iGold   QUOTE (cabbagerat @ Aug 21 2006, 18:03) I...   Sep 11 2006, 15:46
- - cabbagerat   Update: I have posted about this issue to the alsa...   Aug 21 2006, 16:13
|- - iGold   QUOTE (cabbagerat @ Aug 21 2006, 21:13) I...   Aug 21 2006, 16:52
- - cabbagerat   QUOTE (iGold @ Aug 21 2006, 07:52) Is thi...   Aug 21 2006, 16:57
- - CyberFoxx   Don't forget that there's the hw devices a...   Aug 21 2006, 18:35
- - cabbagerat   QUOTE (CyberFoxx @ Aug 21 2006, 09:35) Do...   Aug 21 2006, 19:52
- - CyberFoxx   Hmm, thought I'd give this a try. CODEpcm.48k...   Aug 21 2006, 21:54
|- - eido   QUOTE (CyberFoxx @ Aug 21 2006, 16:54) I ...   Aug 22 2006, 00:19
- - cabbagerat   QUOTE (CyberFoxx @ Aug 21 2006, 12:54) Hm...   Aug 21 2006, 22:28
- - CyberFoxx   QUOTE (cabbagerat @ Aug 21 2006, 16:28) W...   Aug 21 2006, 22:48
- - CyberFoxx   QUOTE (eido @ Aug 21 2006, 18:19) What di...   Aug 22 2006, 01:12
- - cabbagerat   QUOTE (CyberFoxx @ Aug 21 2006, 16:12) QU...   Aug 22 2006, 07:37
- - CyberFoxx   Hmm, well, I tried playing a wave of the first tra...   Aug 22 2006, 22:12
- - cabbagerat   QUOTE (CyberFoxx @ Aug 22 2006, 13:12) Se...   Aug 22 2006, 22:53
- - CyberFoxx   Well, I managed to do a simple form of ABX'ng....   Aug 23 2006, 22:34
- - iGold   If I understand correct input audio data for my SB...   Aug 24 2006, 04:39
- - CyberFoxx   QUOTE (iGold @ Aug 23 2006, 22:39) If I u...   Aug 24 2006, 06:20
|- - iGold   QUOTE (CyberFoxx @ Aug 24 2006, 11:20) No...   Aug 24 2006, 06:52
- - Patsoe   hi iGold: here's some more hints about resampl...   Aug 24 2006, 08:21
- - cabbagerat   QUOTE (CyberFoxx @ Aug 23 2006, 13:34) We...   Aug 24 2006, 09:07
- - CyberFoxx   Well, I just did a quick test of udial, before I g...   Aug 24 2006, 10:11
- - cabbagerat   QUOTE (CyberFoxx @ Aug 24 2006, 01:11) An...   Aug 24 2006, 10:46
- - iGold   Now I also have tested different samplerate_* mode...   Aug 24 2006, 10:48
- - Matyas   Sorry guys for this Off-topic, but does have anyon...   Aug 24 2006, 11:05
|- - askoff   QUOTE (Matyas @ Aug 24 2006, 13:05) Sorry...   Aug 24 2006, 21:23
||- - Matyas   QUOTE (askoff @ Aug 24 2006, 21:23) The r...   Aug 26 2006, 02:37
|- - cheuschober   QUOTE (Matyas @ Aug 24 2006, 04:05) Sorry...   Sep 13 2006, 00:06
- - CyberFoxx   QUOTE (cabbagerat @ Aug 24 2006, 04:46) d...   Aug 24 2006, 11:45
- - iGold   As I know at least Live! 24bit on windows has ...   Aug 24 2006, 11:49
- - cabbagerat   QUOTE (CyberFoxx @ Aug 24 2006, 02:45) We...   Aug 24 2006, 12:02
- - iGold   Today I had a quick try to compile alsa-lib 1.0.11...   Aug 25 2006, 04:28
- - cabbagerat   QUOTE (iGold @ Aug 24 2006, 19:28) As con...   Aug 25 2006, 08:02
- - iGold   After successful upgrade of alsa{-driver,lib,util,...   Aug 25 2006, 15:36
- - iGold   Maybe your card support 44100 Hz natively and no r...   Aug 26 2006, 09:46
- - Matyas   This is what the data sheet says: Front DAC PCM Ra...   Aug 26 2006, 10:25
- - KikeG   http://www.kikeg.arrakis.es/lowpass/Chenoa_16KHz.a...   Sep 11 2006, 16:07
- - KikeG   kmixer doesn't do that bad at the default sett...   Sep 13 2006, 07:52
- - cabbagerat   QUOTE (KikeG @ Sep 12 2006, 22:52) See km...   Sep 13 2006, 08:46
|- - towolf   I tried to build kasound on Ubuntu Edgy and it ask...   Sep 13 2006, 14:22
- - askoff   does anyone know if the sample perioid issue has b...   Nov 10 2006, 23:35
- - Gigapod   Hi cabbagerat, Thanks for starting this excellent...   Nov 14 2006, 11:43
- - damaki   I have just read the piece of news about the debia...   Nov 14 2006, 12:04
- - profoX   This is a bit offtopic maybe, but do you guys know...   Nov 14 2006, 12:47
- - cabbagerat   QUOTE (Gigapod @ Nov 14 2006, 02:43) Can ...   Nov 15 2006, 15:30
|- - Gigapod   QUOTE (cabbagerat @ Nov 15 2006, 15:30) W...   Nov 16 2006, 00:18
- - cabbagerat   QUOTE (Gigapod @ Nov 15 2006, 15:18) QUOT...   Nov 16 2006, 06:57
- - wizkid   Has anyone gotten this to work on Fedora Core 6? I...   Apr 23 2007, 09:49
|- - seeker010   QUOTE (wizkid @ Apr 23 2007, 00:49) Has a...   May 7 2007, 06:56
- - wizkid   Scratch that, i got it working in Ubunty 7.04 ......   Apr 26 2007, 18:13
|- - askoff   QUOTE (wizkid @ Apr 26 2007, 19:13) Scrat...   Apr 26 2007, 18:37
|- - wizkid   QUOTE (askoff @ Apr 26 2007, 09:37) QUOTE...   Apr 26 2007, 23:04
- - samtek   I'm resurrecting an old thread (again) but I w...   May 27 2008, 11:39
- - cabbagerat   QUOTE (samtek @ May 27 2008, 02:39) I...   May 27 2008, 12:50
- - samtek   Interesting. I think you might be right about it b...   May 27 2008, 12:59
- - cabbagerat   While ALSA device is your mplayer using? It seems...   May 27 2008, 14:49
- - samtek   Thanks. I have no idea what device mplayer is usin...   May 27 2008, 14:51
- - gkmeyer   I had this whole thing figured out a while back wh...   Jun 8 2008, 16:30
- - Samizdat   I'm running Ubuntu Hardy 8.04 on a 32-bit Athl...   Sep 4 2008, 16:25


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: 29th July 2014 - 12:57