Tauon icon indicating copy to clipboard operation
Tauon copied to clipboard

Sample rate is fixed to 48000Hz

Open iamalexei opened this issue 2 years ago • 12 comments

Tauon version: 7.7.1 Platform: Flatpak Tauon settings: "Avoid Resampling" is ON

Audio server: Pipewire 1.0.3 pipewire.conf: default.clock.allowed-rates = [ 44100 48000 ]

Tauon doesn't dynamically change sample rate depending on an audio file played despite reporting that it does:

$ flatpak run com.github.taiko2k.tauonmb
    ...
ph: Connected using samplerate 48000hz
ph: The samplerate changed, rewinding
ph: Connected using samplerate 44100hz
$ pw-cli ls
    ...
id 70, type PipeWire:Interface:Node/3
            object.serial = "654"
            factory.id = "6"
            client.id = "73"
            client.api = "pipewire-pulse"
            application.name = "tauon.py"
            node.name = "tauon.py"
            media.class = "Stream/Output/Audio"
            media.category = "Manager"
    ...
  • File 1 (44100hz) played:
$ pw-cli i 70 | grep node.rate
*               node.rate = "1/48000"
  • File 2 (48000hz) played:
$ pw-cli i 70 | grep node.rate
*               node.rate = "1/48000"

I've tried to play the same files with pw-play and mpv (--ao=pipewire and --ao=pulse) to check if something is wrong with my system/configuration, luckily it's not the case: pw-cli reports correct node.rate for each file.

iamalexei avatar Feb 16 '24 23:02 iamalexei

Ah not this again. Unfortunately Ive already spent too much time trying to fix this bug than makes sense. I thought it was fixed but yeah its kind of a known issue.

Taiko2k avatar Feb 17 '24 00:02 Taiko2k

@Taiko2k Such a stubborn backend. What advantages it has for you compared to alternatives like libmpv or libVLC?

iamalexei avatar Feb 18 '24 01:02 iamalexei

The related library here is miniaudio. I was hoping that the developers of that library would impliment a native pipewire backend by now as opposed to using puleaudio that would have hopefully solved such issues. Otherwise the library is a good fit for Tauon. I don't think changing library now would be worth the development effort though.

Taiko2k avatar Feb 18 '24 01:02 Taiko2k

@Taiko2k In general, I don't mind using PulseAudio output plugins with PipeWire. They are capable to change sample rate of the node per audio track, but the miniaudio's one is the first exception I've stumbled upon.

I don't think changing library now would be worth the development effort though.

I hope you're right and it won't turn out to be the sunk cost fallacy.

iamalexei avatar Feb 18 '24 04:02 iamalexei

Actually the version of miniaudio currently used is a few versions out of date, its possible a fix exists in a newer version. Ive built a new flatpak with the most up to date version, if you'd like to test it.

You can install this test flatpak using this command: (Uninstall the stable version first. When you want to switch back to stable, uninstall this test version first)

flatpak install --user https://dl.flathub.org/build-repo/83617/com.github.taiko2k.tauonmb.flatpakref

Taiko2k avatar Feb 18 '24 05:02 Taiko2k

@Taiko2k still no luck

iamalexei avatar Feb 18 '24 10:02 iamalexei

Ironically, VLC's and Audacious' PipeWire plugins are not able to change the sample rate of the driver--they only set it for the player itself, ergo making the 44.1 kHz sample rate passthrough unachievable.

iamalexei avatar Feb 19 '24 02:02 iamalexei

That's how it should work, apps should be able to send whatever format to the sound server and it's up to the sound server how it handles that.

I think what miniaudio is doing is introducing resampling for "compatibility" reasons with pulseaudio. I thought a PR I sent fixed that but I can't remember the details.

Taiko2k avatar Feb 19 '24 03:02 Taiko2k

That's how it should work, apps should be able to send whatever format to the sound server and it's up to the sound server how it handles that.

When I play 44.1 audio with mpv (pipewire/pulse), pw-play, VLC (pulse) or Audacious (pulse), I get:

$ cat /proc/asound/card0/pcm0p/sub0/hw_params | grep rate
rate: 44100 (44100/1)

But the same track with Audacious (pipewire) or VLC (pipewire) shows:

$ cat /proc/asound/card0/pcm0p/sub0/hw_params | grep rate
rate: 48000 (48000/1)

iamalexei avatar Feb 19 '24 03:02 iamalexei

I think I've found something.

  • Audacious (44.1 file, pulse): pw-cli i shows both node.rate = "1/44100" and node.latency = "8192/44100" properties of the node
  • Audacious (44.1 file, pipewire): pw-cli i shows only the node.latency = "1882/44100" property.
  • VLC (44.1 file, pipewire): both properties are absent
  • pw-play (44.1 file): both node.latency = "4410/44100" and node.rate = "1/44100" are present

My guess is that the PipeWire plugin of Audacious/VLC does not explicitly set node.rate and that is not the correct behavior, assuming pw-play as a reference because it's a part of PipeWire.

Am I right in my conclusion? Hope it somehow can be helpful for Tauon's development.

iamalexei avatar Feb 19 '24 10:02 iamalexei

Hi all , Arch user , latest software... I tried to use only pulseaudio and removed entirely pipewire but no luck. Even tried to use just the alsa without pulse and pipewire. Audacious player switch between frequencies using any output plugin (pipewire , pulseaudio , alsa) . Unfortunately Tauon do not switch at all. In any possible combination. (avoid resampling enabled) This is really frustrating because this player is one of the best around. My audio chain is good enough to let clearly ear the difference between a 44.1 file vs a 192 file (natively registered/converted at those frequencies). And this sadly induce me to try other solutions. Hopefully something will change in future... Anyway thanks a lot for your amazing work ...

Edit: Nothing to do... I love this player. So I found a compromise. My Gustard X26pro have a NOS function that bypass the use of a inside filter when sample rates have frequencies >=192khz. This is interesting because seems to make some small upgrade to low frequencies. So I forced to resample all the sound in /etc/pipewire/pipewire.conf default.clock.rate = 352800 default.clock.allowed-rates = [ 44100 48000 88200 96000 176400 192000 352800 384000 705600 768000 ] I can stay like this for now...lets see the future what will bring.

giostark avatar Feb 24 '24 20:02 giostark

(edit1) All seems fixed now. Is possible to set a fixed rate or let the sample rate change with the source. Patience and time is mandatory...Thanks to all for your hard work.

Just an update... Under Arch the funny part is that now this work exactly the opposite :-) (after updates) The sample rate change always despite you tell it to stay fixed !!! Hahaha ... Then , after an update wireplumber killed ALL the audio devices (3 audio devices disappeared) and I had to switch back to pipewire-media-session to have sound back again. Fine , I'll disable the NOS function and I'll wait that both the possibilities will be available.

giostark avatar Apr 06 '24 22:04 giostark