spotifyd icon indicating copy to clipboard operation
spotifyd copied to clipboard

Specify Alsa sink format

Open sapristi opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe.

When running spotifyd on a raspberry pi 3 with an IQaudio soundcard, it fails as soon as I start playing a song with the following logs:

Loading config from ".config/spotifyd"
No proxy specified
Using software volume controller.
Connecting to AP "ap.spotify.com:443"
Authenticated as "ouglop" !
Country: "FR"
Using Alsa sink with format: S16
Loading <Fingertips> with Spotify URI <spotify:track:6JSRXcOTTwTGLeEhDX9OYa>
<Fingertips> (427617 ms) loaded
Alsa error PCM open ALSA function 'snd_pcm_hw_params_set_format' failed with error 'EINVAL: Invalid argument'
Could not start audio: Alsa error: PCM open failed
Alsa error PCM open ALSA function 'snd_pcm_hw_params_set_format' failed with error 'EINVAL: Invalid argument'
Could not start audio: Alsa error: PCM open failed
PANIC: Shutting down spotifyd. Error message: called `Option::unwrap()` on a `None` value
^CPlayer thread panicked!

Describe the solution you'd like

I managed to get librespot running by specifying the --format S32 option. It would be great if spotifyd would support using this option as well.

The logs above display Using Alsa sink with format: S16, so i guess librespot is using the S16 format by default ?

Describe alternatives you've considered

Using librespot works well, only I'd like to have mpris support for playback control.

sapristi avatar Apr 19 '22 18:04 sapristi

Thank you for the detailed feature request!

As you've already figured out correctly, spotifyd just uses the default that librespot provides. The relevant code would be

https://github.com/Spotifyd/spotifyd/blob/ae6dac7a54f899316674ba57ce4a0f9890cd2b1c/src/main_loop.rs#L161-L168

which makes use of the Default impl in librespot here.

So if you are looking for a quick workaround, you could replace AudioFormat::default() with AudioFormat::S32 (other possible values can be found here) and compile spotifyd from source yourself.

However, exposing a configuration parameter for this shouldn't be too difficult. (In particular probably quite similar to e.g. the bitrate (see config.rs) or the dbus_type option that I opened a PR for some time ago.)

Hope this helps!

eladyn avatar Apr 19 '22 20:04 eladyn

Thanks for the quick reply ! I made a PR, proposed version currently working as intended on my raspberry :tada:

sapristi avatar Apr 19 '22 22:04 sapristi