Skip to main content

Topic: ALSA sample rate conversion (Read 87301 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • cabbagerat
  • [*][*][*][*][*]
ALSA sample rate conversion
Reply #50
Can you help me? I am using an old Linux distribution that only has ALSA 1.0.8, and i don't really want to upgrade this machine for the moment.
Which distribution? Some are more easy than others to graft new parts onto old systems.

I have just read the piece of news about the debian update; this is great.
I am trying to figure out how I could alter /usr/share/alsa/pcm/dmix.conf so that it would use the samplerate_best plugin. It would probably the best way to modify the debian package, because the default configurations in /usr/share/alsa/cards/ would all be affected.
From the documentation included with the source of ALSA plugins 1.0.11:

Quote
You can use this rate converter plugin by defining a rate PCM with "converter" parameter, such as:

   pcm.my_rate {
      type rate
      slave.pcm "hw"
      converter "samplerate"
   }

The plug plugin has also a similar field, "rate_converter".

Or, more easily, define a global variable "defaults.pcm.rate_converter",
which is used as the default converter type by plug and rate plugins:

   defaults.pcm.rate_converter "samplerate"

Write the above in your ~/.asoundrc or /etc/asound.conf.

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
I agree that modifying the defaults might be a good idea. The problem is finding a default that both those with old hardware and those with strict quality requirements will find acceptable. I think SRC_SINC_FASTEST is about right - but there are a lot of factors to consider.
Simulate your radar: http://www.brooker.co.za/fers/

  • Gigapod
  • [*][*][*]
ALSA sample rate conversion
Reply #51
Which distribution? Some are more easy than others to graft new parts onto old systems.

Hi cabbagerat,
Thanks for taking the time to help. It's a Mandriva 2005, which I have promised myself to upgrade some day to Debian Etch or Ubuntu, but right now it has to stay that way. 
What do you recommend?

  • cabbagerat
  • [*][*][*][*][*]
ALSA sample rate conversion
Reply #52

Which distribution? Some are more easy than others to graft new parts onto old systems.

Hi cabbagerat,
Thanks for taking the time to help. It's a Mandriva 2005, which I have promised myself to upgrade some day to Debian Etch or Ubuntu, but right now it has to stay that way. 
What do you recommend?
Unfortunately I have no experience with Mandriva whatsoever - I haven't used an RPM distro since RedHat 5, so I don't know what to advise. The short answer is that you need to update to ALSA lib 1.0.11 or later - but this might require more complex upgrades. You might successfully build ALSA-lib and ALSA-plugins from source and "make install" them, but I'm not sure.

It would probably be easier (if this is a home PC and not a server or something) to upgrade to Ubuntu 6.10 or the latest Fedora.
Simulate your radar: http://www.brooker.co.za/fers/

  • wizkid
  • [*]
ALSA sample rate conversion
Reply #53
Has anyone gotten this to work on Fedora Core 6? I have alsa version 1.0.14rc (i think, i'm not at home right now) but i do not have the samplerate files in my /usr/lib/alsa-lib. Either Fedora puts them somewhere else, or they don't include them at all. Any ideas?

  • wizkid
  • [*]
ALSA sample rate conversion
Reply #54
Scratch that, i got it working in Ubunty 7.04  ... now if i could only find a way to kill this insane popping/crackling  on trackchange...

  • askoff
  • [*][*][*][*]
ALSA sample rate conversion
Reply #55
Scratch that, i got it working in Ubunty 7.04  ... now if i could only find a way to kill this insane popping/crackling  on trackchange...

Yes. That's very anoying issue. I hope it gets resolved soon.

  • wizkid
  • [*]
ALSA sample rate conversion
Reply #56

Scratch that, i got it working in Ubunty 7.04  ... now if i could only find a way to kill this insane popping/crackling  on trackchange...

Yes. That's very anoying issue. I hope it gets resolved soon.


Seems to be alsa related too, since it happends no matter what player i'm using. Tried changing buffers and some other settings but to no avail... 

  • seeker010
  • [*]
ALSA sample rate conversion
Reply #57
Has anyone gotten this to work on Fedora Core 6? I have alsa version 1.0.14rc (i think, i'm not at home right now) but i do not have the samplerate files in my /usr/lib/alsa-lib. Either Fedora puts them somewhere else, or they don't include them at all. Any ideas?

yes. this is quite a good thread, I'm glad I found it!

for those that care
Code: [Select]
yum install libsamplerate-devel

then download alsa-plugins-1.0.14rc1a.tar.bz2     
go to downloaded directory and do
Code: [Select]
tar -jxvf alsa-plugins-1.0.14rc1a.tar.bz2
cd alsa-plugins-1.0.14rc1
./configure --prefix=/usr
make
make install
  • Last Edit: 07 May, 2007, 01:56:41 AM by seeker010

  • samtek
  • [*]
ALSA sample rate conversion
Reply #58
I'm resurrecting an old thread (again) but I wanted to add something important. Amarok by default does not seem to obey .asoundrc or resamples by itself or something..... Either way it makes the udial sample sound terrible whereas mplayer (using alsa) and aplay sound fine. I have spent hours trying to fix this and I have finally succeeded. I am using arch linux. Here are my steps:

1. Install libsamplerate and alsa-plugins
2. Put "defaults.pcm.rate_converter "samplerate_best"" in .asoundrc (without the first and last "s)
3. Go to the amarok configuration, Engine tab, select alsa as the output plugin.
4. (This is the one that took me hours to figure out) Under 'ALSA Device Configuration' in the 'Mono' and 'Stereo' boxes put "hw:0" (again without the "s). This made the udial sample sound the same as with mplayer and I'm sure my music sounds more crisp

  • cabbagerat
  • [*][*][*][*][*]
ALSA sample rate conversion
Reply #59
I'm resurrecting an old thread (again) but I wanted to add something important. Amarok by default does not seem to obey .asoundrc or resamples by itself or something..... Either way it makes the udial sample sound terrible whereas mplayer (using alsa) and aplay sound fine. I have spent hours trying to fix this and I have finally succeeded. I am using arch linux. Here are my steps:

1. Install libsamplerate and alsa-plugins
2. Put "defaults.pcm.rate_converter "samplerate_best"" in .asoundrc (without the first and last "s)
3. Go to the amarok configuration, Engine tab, select alsa as the output plugin.
4. (This is the one that took me hours to figure out) Under 'ALSA Device Configuration' in the 'Mono' and 'Stereo' boxes put "hw:0" (again without the "s). This made the udial sample sound the same as with mplayer and I'm sure my music sounds more crisp
On most ALSA configurations, using the "hw:0" devices bypasses dmix and resampling. I don't know what ArchLinux does, but I think the reason you don't hear the problem is that your card is playing udial at the native 44100Hz. What sound card do you have?

For the record, resampling to 48000 using samplerate_medium and samplerate_best with the newest libsamplerate sound absolutely perfect on udial.
Simulate your radar: http://www.brooker.co.za/fers/

  • samtek
  • [*]
ALSA sample rate conversion
Reply #60
Interesting. I think you might be right about it bypassing dmix. Any ideas what I could change to get it to resample properly and go through my alsa settings? My CPU usage is lower when I use amarok than with mplayer which suggests it isn't using the samplerate_best setting I set. Why on earth do the default settings for alsa in amarok not use my .asoundrc?

I am using the onboard sound (AD1988 Chip) on my Asus P5B. I have no idea if it can play at 44100 but I would have thought that it doesn't.

edit: So...using "aplay -D plug:pcm.48khq *.wav" I get:
Quote
Playing WAVE 'udial.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
ALSA lib pcm_rate.c:1369:(snd_pcm_rate_open) Cannot find rate converter
Segmentation fault


I was using this .asoundrc:
Quote
pcm.48khq {
        type plug
        slave {
                pcm "hw:0,0"
                rate 48000
        }
        rate_converter "samplerate_best"
}


However if I use "defaults.pcm.rate_converter "samplerate_best"" in .asoundrc I get higher cpu usage than with no .asoundrc so the rate_converter is working. This is great (when using mplayer or aplay) but when I try to play flash videos in firefox, flash crashes with something like:
Quote
npviewer.bin[26668]: segfault at 0 ip f49fac14 sp ffab39d0 error 4 in libasound.so.2.0.0[f49ad000+c1000]


Forgetting my flash woes for a moment. If I set amarok alsa output to front (rather than hw:0) it also works with no distortion. Is this also bypassing dmix or something?
  • Last Edit: 27 May, 2008, 09:03:18 AM by samtek

  • cabbagerat
  • [*][*][*][*][*]
ALSA sample rate conversion
Reply #61
While ALSA device is your mplayer using?

It seems that by default the front device has "softvol" enabled but not dmix. Only the "default" device seems to have dmix enabled out of the box. If you use this device for everything, everything should get resampled and mixed with the default rate converter. If you set that to samplerate_whatever it should use that.

You might need to ask these questions on one of the ALSA mailing lists to get a sensible answer.
  • Last Edit: 27 May, 2008, 12:56:06 PM by cabbagerat
Simulate your radar: http://www.brooker.co.za/fers/

  • samtek
  • [*]
ALSA sample rate conversion
Reply #62
Thanks. I have no idea what device mplayer is using...it's just using -ao alsa. I shall post on the alsa list.
  • Last Edit: 27 May, 2008, 09:52:03 AM by samtek

  • gkmeyer
  • [*]
ALSA sample rate conversion
Reply #63
I had this whole thing figured out a while back when I was trying to get my old Chaintech AV-710 working with no resampling in software.  I don't have time this minute, but I'll go back into my notes and settings to see if I can help. 

I'm on Arch too btw.

  • Samizdat
  • [*]
ALSA sample rate conversion
Reply #64
I'm running Ubuntu Hardy 8.04 on a 32-bit Athlon and an A7N8XE mobo.  My sound software is ALSA and the sound card ID follows:
00:05.0 Multimedia audio controller: nVidia Corporation nForce Audio Processing Unit (rev a2)
00:06.0 Multimedia audio controller: nVidia Corporation nForce2 AC97 Audio Controler (MCP) (rev a1)
   Subsystem: ASUSTeK Computer Inc. nForce2 AC97 Audio Controler (MCP)

Can anyone help me with the following Internet Archive show: Brahms - Tragic Overture in D Minor, Op. 81

The original FLAC file has a sample rate of 48 KHz, which file I will temporarily keep in the show till I resolve the problem: the playback speed is too fast.

As you can see, the solution I have applied is to resample the performance at 44.1 KHz.

First of all, is my diagnosis of too-fast playback correct, or is there something wrong with my hardware and/or software?

Secondly, if resampling is not the solution, what is?