View previous topic :: View next topic |
Author |
Message |
manywele l33t
Joined: 12 Jul 2003 Posts: 743 Location: Inside
|
Posted: Sat Sep 21, 2024 8:45 pm Post subject: libao audio playback at 48000 instead of 44100 |
|
|
On my desktop gentoo machine using flac123 to play a flac file plays through alsa at a sample rate of 44100 which is correct.
On my laptop gentoo machine using flac123 to play a flac file plays through alsa at a sample rate of 48000 which is not correct. However decoding a flac file and piping it through aplay uses the correct sample rate.
Code: |
flac123 some_flac_file.flac
flac123 version 2.1.1 'flac123 --help' for more info
ao_alsa WARNING: sample rate 44100 not supported by the hardware, using 48000
|
but doing the following works as expected and plays at 44100
Code: |
flac -cd some_flac_file.flac | aplay
|
I'm using pure alsa, no systemd, pipewire is installed but I haven't configured it and as far as I can tell it isn't controlling audio. All other audio sources seem to be fine, it's just libao that giving the problem. How do I make it behave and play audio at the correct sample rate of 44100? |
|
Back to top |
|
|
manywele l33t
Joined: 12 Jul 2003 Posts: 743 Location: Inside
|
Posted: Thu Sep 26, 2024 1:41 am Post subject: |
|
|
In an attempt to solve my problem I installed and configured pipewire.
Code: | bob@Gilgamesh ~ $ lspci | grep Audio
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)
|
Code: | bob@Gilgamesh ~ $ pw-metadata -n settings
Found "settings" metadata 31
update: id:0 key:'log.level' value:'2' type:''
update: id:0 key:'clock.rate' value:'44100' type:''
update: id:0 key:'clock.allowed-rates' value:'[ 44100 ]' type:''
update: id:0 key:'clock.quantum' value:'1024' type:''
update: id:0 key:'clock.min-quantum' value:'32' type:''
update: id:0 key:'clock.max-quantum' value:'2048' type:''
update: id:0 key:'clock.force-quantum' value:'0' type:''
update: id:0 key:'clock.force-rate' value:'0' type:''
|
If I play a flac file using pw-play it plays at the correct sample rate but if I use anything libao related it plays at 48000 making the audio sound too high.
I thought pipewire was supposed to force the sample rate to the value in settings. Am I wrong? Do I need to configure something else to force all audio output through pipewire? My .asoundrc is empty and I have no libao.conf. |
|
Back to top |
|
|
lars_the_bear Guru
Joined: 05 Jun 2024 Posts: 517
|
Posted: Thu Sep 26, 2024 7:20 am Post subject: |
|
|
What specific ALSA PCM are you opening, in these different situations?
If your hardware genuinely can't support 44100 -- and most built-in stuff can't -- then the player will have to either (a) resample, or (b) send it to something in ALSA that can resample, or (c) say 'to hell with it' and choose the nearest alternative.
In my experience, a conventional ALSA set-up (not fiddled about with by Pulse or Pipewire) can resample accurately if you use the 'plughw' protocol, regardless of the device. Using 'hw' will generally fail, if the hardware can't match the required audio parameters. In that case, the player software _might_ try to take matters into its own hands. My guess is that that's what's happening here.
I don't know much about libao, but I recall that it has a way to choose the ALSA PCM to use. Are you doing that, or just hoping its defaults are OK?
BR, Lars. |
|
Back to top |
|
|
manywele l33t
Joined: 12 Jul 2003 Posts: 743 Location: Inside
|
Posted: Thu Sep 26, 2024 2:54 pm Post subject: |
|
|
Quote: | What specific ALSA PCM are you opening, in these different situations? |
Good question. I had no idea there were more than one for simple onboard Intel audio. How do I tell?
Yeah, I assume the error message is correct and the hw can't support 44100 (my desktop has a nice soundcard that can) so I was expecting some software resampling. Clearly some other programs are doing that correctly. I tried to get alsa to use libsamplerate plugin to resample it but after a couple of days of reading docs and messing with configs I couldn't get it to work. I'll look into 'plughw' when I get a free moment.
The only config options available for libao seem to be default_driver, debug, quiet and verbose and default_driver is just alsa. Not much to work with there. |
|
Back to top |
|
|
lars_the_bear Guru
Joined: 05 Jun 2024 Posts: 517
|
Posted: Fri Sep 27, 2024 7:55 am Post subject: |
|
|
Hi
I find that I can control the libao ALSA device by creating a ~/.libao file with the following:
plughw:CARD=PCH,DEV=0
'CARD=PCH' is the motherboard sound device. You can get a list of PCM devices using 'aplay --list-pcms'.
But, in fact, I don't need to do any of this. I tried flac123 and it was fine without specifying anything: libao just (for me) uses whatever settings I have in ~/.asoundrc. Because I have an ALSA-only installation, the default ALSA device is already configured with resampling support and all that stuff. flac123 just works, even though my motherboard sound device can't resample.
The fact that flac123 struggles as it does, kind-of points to a broken ALSA or libao set-up. But if you've ever installed Pulse or Pipewire, I suspect you'll have a 'broken' ALSA set-up anyway, because the installers for these things overwrite the standard ALSA settings with stuff that make it work better with Pulse/Pipewire.
If you do have Pulse or Pipewire, libao needs to be built with Pulse support. With that in place it makes no sense to fiddle with the ALSA settings at all. But having Pulse/Pipewire running, and libao built _without_ Pulse support, will just lead to a mess. That you will have a specify an ALSA device explicitly, and it will have to be capable of resampling.
BR, Lars. |
|
Back to top |
|
|
manywele l33t
Joined: 12 Jul 2003 Posts: 743 Location: Inside
|
Posted: Thu Oct 03, 2024 9:38 pm Post subject: |
|
|
I removed pipewire, left ~/.asound blank, no ~/.libao, nothing is built with pulseaudio or pipewire support and I get the same results (i.e. it plays at 48,000).
Tried adding the ~/.libao file Code: | plughw:CARD=PCH,DEV=0 | after verifying that those were the correct parameters and that did nothing.
Tried the following ~/.asound and I think I found the problem of why it's not resampling but I still can't find the solution.
Code: | pcm.digital
{
type plughw
card 0
device 0
}
pcm.!default {
type plug
slave.pcm digital
} |
Trying to play a flac using flac123 with that ~/.asound results in the following error
Code: | ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.2.12/work/alsa-lib-1.2.12/src/dlmisc.c:339:(snd_dlobj_cache_get0) Cannot open shared library libasound_module_pcm_plughw.so (/usr/lib64/alsa-lib/libasound_module_pcm_plughw.so: cannot open shared object file: No such file or directory)
No fallback libao driver found, exiting. |
It's true, I don't have that file. I can not figure out what's supposed to give it to me though. I have alsa-lib, alsa-utils and alsa-pulgins installed. Or am I using plughw wrong? I gotta say I find alsa the most confusing thing to configure. |
|
Back to top |
|
|
|
|
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
|
|