Skip to content

Conversation

@SapiensAnatis
Copy link
Contributor

@SapiensAnatis SapiensAnatis commented Dec 19, 2025

Adds the ability for the player to change its sample rate, to be able to accurately play back local files that aren't sampled at 44.1 kHz.

The functionality to change sample rate must be implemented individually by each sink. In this PR, I have only implemented support in the ALSA sink. I wanted to get some feedback on the general approach before I went and updated + tested every single sink. I may not actually be able to do every sink myself depending on if some of them have particular hardware/software requirements.

Testing this by swapping between a 48.0 kHz local file and a 44.1 kHz Spotify song appears to play back both without any distortion of sound.

@SapiensAnatis SapiensAnatis force-pushed the feature/local-files-resample branch from ab68e46 to 9e8e471 Compare December 19, 2025 00:11
Adds the ability for the player to change its sample rate, to be able to
accurately play back local files that aren't sampled at 44.1 kHz.

The functionality to change sample rate must be implemented individually
by each sink. In this commit, support for this has only been added to
the alsa sink.

Testing this by swapping between a 48.0 kHz local file and a 44.1 kHz
Spotify song appears to play back both without any distortion of sound.
@SapiensAnatis SapiensAnatis force-pushed the feature/local-files-resample branch from 9e8e471 to a1af6bb Compare December 19, 2025 00:19
Comment on lines +1920 to +1923
if let Err(e) = self.sink.update_sample_rate(loaded_track.sample_rate) {
error!(
"Failed to update sink sample rate: {e}. Track playback may be distorted."
);
Copy link
Contributor Author

@SapiensAnatis SapiensAnatis Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sinks which can't update sample rate yet, this is a change in behaviour; previously we would not allow a track with a different sample rate to play in a distorted way. I have changed this just now because I couldn't immediately see a nice way of signalling an error and stopping playback in start_playback.

Ideally I think we should refuse to play the track otherwise it could get reported as a bug by a well-meaning user not keeping their eye on the logs. What would be the best way to do this here? If I add this to the block, it seems to do the trick, but I don't know if that's desirable.

self.state = PlayerState::Stopped;
return;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I don't know if that's desirable.

you can look into ensure_sink_running() and ensure_sink_stopped(), both seem to change the state. So I would think changing the state by that is the expected usage/behavior here.

Tho I would probably expect librespot to skip the track and not stop when we can't play a track (without distortion).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants