Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
A simple and dramatic improvement of sound quality
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
octoploid
n00b
n00b


Joined: 21 Oct 2006
Posts: 65

PostPosted: Wed Aug 15, 2007 6:29 am    Post subject: A simple and dramatic improvement of sound quality Reply with quote

This is a tip for all soundcards that internally resample everything to 48khz.
(e.g.:AC'97 onboard chipsets, all Creative Live and Audigy series, Hercules Fortissimo I/II/III)
Due to their limited power and flexibility, they perform quite crappy resampling on non-48khz material
like most music (44.1khz mp3s, flac , etc.).

The solution is to use Alsa's Dmix resampler with the "samplerate" plugin. This plugin offers
excellent quality and you can immediately hear the difference.

First emerge media-plugins/alsa-plugins with the "libsamplerate" USE flag.

Then create /etc/asound.conf :
Code:
defaults.pcm.rate_converter "samplerate_best"
pcm.!default {
       type plug
       slave.pcm "dmixer"
   }

   pcm.dmixer {
       type dmix
       ipc_key 1024
       slave {
           pcm "hw:0,1" #That's for my VIA 8237 on-board soundchip all others should use hw:0,0
           period_time 0
           period_size 1024
           buffer_size 16384
           rate 48000
       }                                                                                                                                   
       bindings {
           0 0
           1 1
       }
   }
   ctl.dmixer {
       type hw
       card 0
   }


The following converter types are available:

- samplerate_best Use SRC_SINC_BEST_QUALITY
- samplerate_medium Use SRC_SINC_MEDIUM_QUALITY
- samplerate Use SRC_SINC_FASTEST
- samplerate_order Use SRC_ZERO_ORDER_HOLD
- samplerate_linear Use SRC_LINEAR

samplerate_best uses ~10% of my CPU (Athlon64) when playing back music.
The other converters need less processing power. Just experiment a little with the converters.

Further reading:

http://www.mega-nerd.com/SRC/index.html
http://www.hydrogenaudio.org/forums/index.php?s=b6c927e64fdd78973cbe46f3408e88e2&showtopic=47591&st=0
http://ubuntuforums.org/showthread.php?t=344599
_________________
Myself and mine gymnastic ever
Back to top
View user's profile Send private message
swimmer
Veteran
Veteran


Joined: 15 Jul 2002
Posts: 1287
Location: Netherlands

PostPosted: Wed Aug 15, 2007 8:53 am    Post subject: Reply with quote

Since I'm not very fluent in asound.conf language I dare to ask you: how does such an asound.conf for 2 cards look like? ;-)

Greetz
swimmer
Back to top
View user's profile Send private message
Akkara
Administrator
Administrator


Joined: 28 Mar 2006
Posts: 4957
Location: &akkara

PostPosted: Wed Aug 15, 2007 12:09 pm    Post subject: Reply with quote

Thanks for the tip!

Something to try, if most of the music is 44.1 KHz files and your sound card supports it, try resampling to 88.2 KHz. I find I can get away with using samplerate_medium at that rate, while not constraining bandwidth for the 48KHz sources.

Something I've been wondering / hoping about: Is it possible to configure it so that when there's only one sound playing, alsa/dmix uses whatever native sampling rate that sound was recorded at, and only firing up the resampler when there's another concurrent sound with a different rate than the first? It seems most of the time there's only one sound playing and this would give the cleanest possible sound as well as use the least resources.

Edit: I just read your links. OMG! I can't believe the default dmix is to use linear "resampling". No wonder it had sounded so crappy (and I had not been using dmix on account of that). Linear resampling audio is like using bubblesort in a database app - it simply shouldn't be done, ever, IMHO.
Back to top
View user's profile Send private message
Insanity5902
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1228
Location: Fort Worth, Texas

PostPosted: Thu Aug 16, 2007 3:04 am    Post subject: Reply with quote

Question :: if I change the rate 44100 and everything still works, would it be better to leave it there, or continue to let it resample.

I have the newer HD Audo from the ICH7?

My initial thought it is, 48000 provide better sound, so why not use it if I have the horsepower (which I do)
_________________
GibbonsR.net | OpenLaptops.org

Join the adopt an unanswered post initiative today
Back to top
View user's profile Send private message
Akkara
Administrator
Administrator


Joined: 28 Mar 2006
Posts: 4957
Location: &akkara

PostPosted: Thu Aug 16, 2007 3:11 am    Post subject: Reply with quote

If most of your music is at 44100, having dmix operate at 44100 is probably a good idea.

You'll lose some of the extreme highs when playing 48KHz sources but if you don't listen to 48KHz material as much, it woun't matter that it's not optimized.
Back to top
View user's profile Send private message
octoploid
n00b
n00b


Joined: 21 Oct 2006
Posts: 65

PostPosted: Thu Aug 16, 2007 4:19 am    Post subject: Reply with quote

swimmer wrote:
Since I'm not very fluent in asound.conf language I dare to ask you: how does such an asound.conf for 2 cards look like? ;-)


I would duplicate the slave section with pcm "hw:1,0" ...

Quote:
Question :: if I change the rate 44100 and everything still works, would it be better to leave it there, or continue to let it resample.


It's always better not to resample if it is not necessary. So if your soundcard handles 44100 Hz fine then
just leave dmix there.
_________________
Myself and mine gymnastic ever
Back to top
View user's profile Send private message
Non_E
Apprentice
Apprentice


Joined: 17 Jan 2006
Posts: 160
Location: Czech Republic

PostPosted: Sun Aug 19, 2007 12:12 pm    Post subject: Reply with quote

Hi,

what was your former alsa-plugins use flag settings? This is mine:
Code:
media-plugins/alsa-plugins-1.0.14  USE="ffmpeg -debug -jack -libsamplerate -pulseaudio"


Will there be any gain in using libsamplerate instead of ffmpeg?
_________________
Only Sith deals in absolutes.
Back to top
View user's profile Send private message
octoploid
n00b
n00b


Joined: 21 Oct 2006
Posts: 65

PostPosted: Sun Aug 19, 2007 1:27 pm    Post subject: Reply with quote

Non_E wrote:
Hi,

what was your former alsa-plugins use flag settings? This is mine:
Code:
media-plugins/alsa-plugins-1.0.14  USE="ffmpeg -debug -jack -libsamplerate -pulseaudio"


Will there be any gain in using libsamplerate instead of ffmpeg?


Yes ffmpeg is another possibility. I haven't tested it myself yet, but I guess the plugin
is not so resource hungry as libsamplerate and the sound quality will be lower.


Update:

OK I've tested the plugin and cannot recommend it. It's quite awful. The resulting sound
is distorted. Playing back udial.wav produces strange artifacts. None of this happens if I use libsamplerate.

Update 2:

While I was testing the ffmpeg plugin I discoverd that there is another undocumented
resampler in the alsa library called speexrate. There are three settings avialable:
speexrate
speexrate_medium
speexrate_best
The quality seems to be excellent. I could not hear any difference compared to libsamplerate.
The CPU usage is also lower. I'm using speexrate as my new default converter now.
_________________
Myself and mine gymnastic ever
Back to top
View user's profile Send private message
fank
l33t
l33t


Joined: 16 Oct 2004
Posts: 794
Location: Minsk, Belarus

PostPosted: Tue Aug 28, 2007 3:12 pm    Post subject: Reply with quote

how to use lattest mentioned resampler e.g. "speexrate"
should I change "samplerate_best" to "speexrate_best" in asound.conf to test it?
Back to top
View user's profile Send private message
octoploid
n00b
n00b


Joined: 21 Oct 2006
Posts: 65

PostPosted: Tue Aug 28, 2007 3:43 pm    Post subject: Reply with quote

fank wrote:
how to use lattest mentioned resampler e.g. "speexrate"
should I change "samplerate_best" to "speexrate_best" in asound.conf to test it?


Yes :)
_________________
Myself and mine gymnastic ever
Back to top
View user's profile Send private message
Non_E
Apprentice
Apprentice


Joined: 17 Jan 2006
Posts: 160
Location: Czech Republic

PostPosted: Tue Aug 28, 2007 4:02 pm    Post subject: Reply with quote

I added the asound.conf with samplerate_best settings and the sound is not distorted with samplerate_best settings. I also noticed that my xine-lib can make udial.wav sound really ugly :-(
_________________
Only Sith deals in absolutes.
Back to top
View user's profile Send private message
Insanity5902
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1228
Location: Fort Worth, Texas

PostPosted: Tue Aug 28, 2007 11:39 pm    Post subject: Reply with quote

Yeah, I had to take it off b/c flash movies quiet playing and I haven't had time to look at it.
_________________
GibbonsR.net | OpenLaptops.org

Join the adopt an unanswered post initiative today
Back to top
View user's profile Send private message
Non_E
Apprentice
Apprentice


Joined: 17 Jan 2006
Posts: 160
Location: Czech Republic

PostPosted: Wed Aug 29, 2007 2:33 pm    Post subject: Reply with quote

Insanity5902 wrote:
Yeah, I had to take it off b/c flash movies quiet playing and I haven't had time to look at it.
Thanks for info, I did not know the reason flash movies stopped working for me.
_________________
Only Sith deals in absolutes.
Back to top
View user's profile Send private message
octoploid
n00b
n00b


Joined: 21 Oct 2006
Posts: 65

PostPosted: Fri Sep 14, 2007 4:04 pm    Post subject: Reply with quote

Insanity5902 wrote:
Yeah, I had to take it off b/c flash movies quiet playing and I haven't had time to look at it.


Yeah, I had the same problem, but I solved it by hand-installing a 32-bit version of
libasound_module_rate_speexrate.so .

Basically I just downloaded a 32-bit rpm version here.
Then I ran rpm2targz libalsa-plugins-1.0.14-1mamba.i586.rpm and copied
libasound_module_rate_speexrate.so
libasound_module_rate_speexrate.la
libasound_module_rate_speexrate_medium.so
libasound_module_rate_speexrate_best.so
from the tarball to /usr/lib32/alsa-lib .

Thats all. Sound works now for all 32-bit clients on my 64-bit machine.
_________________
Myself and mine gymnastic ever
Back to top
View user's profile Send private message
Insanity5902
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1228
Location: Fort Worth, Texas

PostPosted: Sat Sep 15, 2007 3:48 am    Post subject: Reply with quote

LOL, forgot flash is 32bit, oops :) Thanks for the fix.
_________________
GibbonsR.net | OpenLaptops.org

Join the adopt an unanswered post initiative today
Back to top
View user's profile Send private message
Thesee
Tux's lil' helper
Tux's lil' helper


Joined: 02 Jun 2004
Posts: 138
Location: Belgium

PostPosted: Mon Sep 24, 2007 9:34 pm    Post subject: Reply with quote

Hi,

I tried to follow this post, but I couldn't work with MPD anymore. I looked around, and found this from the alsa-lib ebuild:
Quote:
* Starting from alsa 1.0.11_rc3 the configuration for dmix is changed.
* Leaving around old asound.conf or ~/.asoundrc might make all apps
* using ALSA output crash.

So should I still try to make it work or not?

Thanks :)
_________________
How does a UNIX expert have sex?
Unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep.
Back to top
View user's profile Send private message
Cazzantonio
Bodhisattva
Bodhisattva


Joined: 20 Mar 2004
Posts: 4477
Location: In giro

PostPosted: Tue Sep 25, 2007 4:13 pm    Post subject: Reply with quote

libsamplerate can be compiled with fftw use flag.
I suppose that would mean that the library will use sci-libs/fftw to do the samplig...
Has anyone tried this out? Did you find any improvement over the non-fftw version?
_________________
Any man's death diminishes me, because I am involved in mankind, and therefore never send to know for whom the bell tolls; it tolls for thee
-John Donne
Back to top
View user's profile Send private message
octoploid
n00b
n00b


Joined: 21 Oct 2006
Posts: 65

PostPosted: Wed Sep 26, 2007 11:48 am    Post subject: Reply with quote

Thesee wrote:
Hi,

I tried to follow this post, but I couldn't work with MPD anymore. I looked around, and found this from the alsa-lib ebuild:
Quote:
* Starting from alsa 1.0.11_rc3 the configuration for dmix is changed.
* Leaving around old asound.conf or ~/.asoundrc might make all apps
* using ALSA output crash.

So should I still try to make it work or not?


You could check out the MPD wiki.
And also the Gentoo ALSA Howto.

Quote:
libsamplerate can be compiled with fftw use flag.
I suppose that would mean that the library will use sci-libs/fftw to do the samplig...
Has anyone tried this out? Did you find any improvement over the non-fftw version?


Libsamplerate needs sci-libs/fftw version 2, so you have to mask version 3 to give it a try.
I didn't bother with it myself, because I use the speexrate SRC.
_________________
Myself and mine gymnastic ever
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum