Taiko2k / Tauon

The music player of today! :city_sunrise:
https://tauonmusicbox.rocks
GNU General Public License v3.0
1.64k stars 64 forks source link

Sample rate is fixed to 48000Hz #1093

Open iamalexei opened 4 months ago

iamalexei commented 4 months ago

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"
    ...
$ pw-cli i 70 | grep node.rate
*               node.rate = "1/48000"
$ 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.

Taiko2k commented 4 months ago

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.

iamalexei commented 4 months ago

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

Taiko2k commented 4 months ago

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.

iamalexei commented 4 months ago

@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.

Taiko2k commented 4 months ago

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

iamalexei commented 4 months ago

@Taiko2k still no luck

iamalexei commented 4 months ago

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.

Taiko2k commented 4 months ago

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.

iamalexei commented 4 months ago

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 commented 4 months ago

I think I've found something.

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.

giostark commented 4 months ago

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 commented 2 months ago

(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.