[GH-ISSUE #812] alsa dmixer device breaks librespot #414

Closed
opened 2026-02-27 19:30:28 +03:00 by kerem · 15 comments
Owner

Originally created by @Mitschmaster on GitHub (Jun 25, 2021).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/812

Originally assigned to: @JasonLG1979 on GitHub.

I have configured a mixer device via asound.conf to allow multiple programs to play audio simultanially through my raspberry equipped with a optical audio out hat. that used to work fine but recently i did a git pull and rebuild librespot. now i get the following error when playing something via librespot:
librespot_playback::player] Fatal error, could not start audio sink: AlsaSink Hardware Parameters Error, ALSA function 'snd_pcm_hw_params_set_periods' failed with error 'EINVAL: Invalid argument'
when i remove the dmixer plugin it works fine. i dont know what commit i was on when it worked. it was something in january or febuary i think.
thanks for help

Originally created by @Mitschmaster on GitHub (Jun 25, 2021). Original GitHub issue: https://github.com/librespot-org/librespot/issues/812 Originally assigned to: @JasonLG1979 on GitHub. I have configured a mixer device via asound.conf to allow multiple programs to play audio simultanially through my raspberry equipped with a optical audio out hat. that used to work fine but recently i did a git pull and rebuild librespot. now i get the following error when playing something via librespot: librespot_playback::player] Fatal error, could not start audio sink: AlsaSink Hardware Parameters Error, ALSA function 'snd_pcm_hw_params_set_periods' failed with error 'EINVAL: Invalid argument' when i remove the dmixer plugin it works fine. i dont know what commit i was on when it worked. it was something in january or febuary i think. thanks for help
kerem 2026-02-27 19:30:28 +03:00
Author
Owner

@roderickvd commented on GitHub (Jun 25, 2021):

@JasonLG1979 could you take a look at this, it might have been introduced by #789.

<!-- gh-comment-id:868500981 --> @roderickvd commented on GitHub (Jun 25, 2021): @JasonLG1979 could you take a look at this, it might have been introduced by #789.
Author
Owner

@JasonLG1979 commented on GitHub (Jun 25, 2021):

@Mitschmaster What does your asound.conf look like?

That function really should not fail. We ask for a buffer with 4 periods, worse case it should set it the closest thing to 4 or in the case of dmix whatever you have dmix configured to as far as the buffer setting. I can't reproduce on real hardware or going though dmix either though the default or with a custom asound.conf

Could you also provide the output of aplay -Dhw:x,x --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav Where hw:x,x is the actual device you're trying to use. It will probability throw an error but it will give us the device's capabilities.

<!-- gh-comment-id:868745898 --> @JasonLG1979 commented on GitHub (Jun 25, 2021): @Mitschmaster What does your `asound.conf` look like? That function really should not fail. We ask for a buffer with 4 periods, worse case it should set it the closest thing to 4 or in the case of `dmix` whatever you have `dmix` configured to as far as the buffer setting. I can't reproduce on real hardware or going though `dmix` either though the default or with a [custom `asound.conf`]( https://gist.github.com/JasonLG1979/f29cb0f14218a3b20db5d32c2cfae5ed) Could you also provide the output of `aplay -Dhw:x,x --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav` Where `hw:x,x` is the actual device you're trying to use. It will probability throw an error but it will give us the device's capabilities.
Author
Owner

@JasonLG1979 commented on GitHub (Jun 25, 2021):

@Mitschmaster Well I guess I can reproduce if I set the periods to under 4 in dmix. I'm pretty sure I know how to fix it. I'll be back with a test branch and if it works for you I'll put in a PR.

<!-- gh-comment-id:868753963 --> @JasonLG1979 commented on GitHub (Jun 25, 2021): @Mitschmaster Well I guess I can reproduce if I set the periods to under 4 in `dmix`. I'm pretty sure I know how to fix it. I'll be back with a test branch and if it works for you I'll put in a PR.
Author
Owner

@JasonLG1979 commented on GitHub (Jun 25, 2021):

Still curious what your asound.conf looks like though.

<!-- gh-comment-id:868766410 --> @JasonLG1979 commented on GitHub (Jun 25, 2021): Still curious what your `asound.conf` looks like though.
Author
Owner

@JasonLG1979 commented on GitHub (Jun 25, 2021):

@Mitschmaster try this branch I'm pretty sure it will fix the issue. If it does I will put in a PR and I'm sure @roderickvd will merge it pretty quickly.

<!-- gh-comment-id:868783305 --> @JasonLG1979 commented on GitHub (Jun 25, 2021): @Mitschmaster try [this branch](https://github.com/JasonLG1979/librespot/tree/alsa_buffer_hot_fix) I'm pretty sure it will fix the issue. If it does I will put in a PR and I'm sure @roderickvd will merge it pretty quickly.
Author
Owner

@JasonLG1979 commented on GitHub (Jun 25, 2021):

@roderickvd I'm going to go ahead and put in a PR. I tested this by setting a ridiculously small buffer as far as period time and period count and were it crashed before, with that very small change in that branch it does not.

I think my mistake was explicitly asking for 4 periods and assuming people would not do weird things in their asound.conf,lol!!!

<!-- gh-comment-id:868789140 --> @JasonLG1979 commented on GitHub (Jun 25, 2021): @roderickvd I'm going to go ahead and put in a PR. I tested this by setting a ridiculously small buffer as far as period time and period count and were it crashed before, with that very small change in that branch it does not. I think my mistake was explicitly asking for 4 periods and assuming people would not do weird things in their `asound.conf`,lol!!!
Author
Owner

@Mitschmaster commented on GitHub (Jun 25, 2021):

The fix from @JasonLG1979 works for me. Thank you very much.
Besides, my asound.conf is not that weird. i just have a dmixer plugin. i dont even set buffer sizes or so. (maybe i should)

pcm.hifiberry {
  type hw card 0
}
pcm.!default {
  type plug
  slave.pcm "dmixer"
}
pcm.dmixer {
  type dmix
  ipc_key 1024
  slave {
    pcm "hifiberry"
    channels 2
  }
}
ctl.dmixer {
  type hw
  card 0
}
<!-- gh-comment-id:868806517 --> @Mitschmaster commented on GitHub (Jun 25, 2021): The fix from @JasonLG1979 works for me. Thank you very much. Besides, my asound.conf is not that weird. i just have a dmixer plugin. i dont even set buffer sizes or so. (maybe i should) ``` pcm.hifiberry { type hw card 0 } pcm.!default { type plug slave.pcm "dmixer" } pcm.dmixer { type dmix ipc_key 1024 slave { pcm "hifiberry" channels 2 } } ctl.dmixer { type hw card 0 } ```
Author
Owner

@JasonLG1979 commented on GitHub (Jun 25, 2021):

my asound.conf is not that weird. i just have a dmixer plugin.

Strange that it would set the period size/count to be less than 4 by default? That seems broken to me.

i dont even set buffer sizes or so. (maybe i should)

If it ain't broke don't fix it.

But generally the safe norm is around 4 125ms periods for a total buffer size of around 500ms. A really small buffer will hammer your CPU and really huge buffer will lead to a noticeable delay between pausing and unpausing and manually changing tracks because the PCM has to play out what's in it's buffer before it can do what you actually want it to.

If you notice underruns, distortion or glitches I'd up the period count until it goes away. But I'd keep the buffer under 1000ms otherwise you'll notice that delay I was talking about.

<!-- gh-comment-id:868816481 --> @JasonLG1979 commented on GitHub (Jun 25, 2021): > my asound.conf is not that weird. i just have a dmixer plugin. Strange that it would set the period size/count to be less than 4 by default? That seems broken to me. > i dont even set buffer sizes or so. (maybe i should) If it ain't broke don't fix it. But generally the safe norm is around 4 125ms periods for a total buffer size of around 500ms. A really small buffer will hammer your CPU and really huge buffer will lead to a noticeable delay between pausing and unpausing and manually changing tracks because the PCM has to play out what's in it's buffer before it can do what you actually want it to. If you notice underruns, distortion or glitches I'd up the period count until it goes away. But I'd keep the buffer under 1000ms otherwise you'll notice that delay I was talking about.
Author
Owner

@JasonLG1979 commented on GitHub (Jun 25, 2021):

There's your problem. If you don't specify any buffer setting I'm pretty sure it defaults to the device's min.

<!-- gh-comment-id:868817391 --> @JasonLG1979 commented on GitHub (Jun 25, 2021): There's your problem. If you don't specify any buffer setting I'm pretty sure it defaults to the device's min.
Author
Owner

@roderickvd commented on GitHub (Jun 25, 2021):

I've done nothing with my dmix and it gives me a period size of 1024 and buffer size of 16384 regardless of your PR.

<!-- gh-comment-id:868817530 --> @roderickvd commented on GitHub (Jun 25, 2021): I've done nothing with my dmix and it gives me a period size of 1024 and buffer size of 16384 regardless of your PR.
Author
Owner

@JasonLG1979 commented on GitHub (Jun 25, 2021):

I've done nothing with my dmix and it gives me a period size of 1024 and buffer size of 16384 regardless of your PR.

See the above comment.

<!-- gh-comment-id:868817770 --> @JasonLG1979 commented on GitHub (Jun 25, 2021): > I've done nothing with my dmix and it gives me a period size of 1024 and buffer size of 16384 regardless of your PR. See the above comment.
Author
Owner

@JasonLG1979 commented on GitHub (Jun 25, 2021):

I've done nothing with my dmix and it gives me a period size of 1024 and buffer size of 16384 regardless of your PR.

So it did not change since the PR or not?

<!-- gh-comment-id:868818204 --> @JasonLG1979 commented on GitHub (Jun 25, 2021): > I've done nothing with my dmix and it gives me a period size of 1024 and buffer size of 16384 regardless of your PR. So it did not change since the PR or not?
Author
Owner

@roderickvd commented on GitHub (Jun 25, 2021):

That's right it was working before, and is working after, with no effect on the period and buffer sizes. But see my other comment over at the PR because it does do something to the sizes for hw and plughw.

<!-- gh-comment-id:868819404 --> @roderickvd commented on GitHub (Jun 25, 2021): That's right it was working before, and is working after, with no effect on the period and buffer sizes. But see my other comment over at the PR because it does do something to the sizes for `hw` and `plughw`.
Author
Owner

@JasonLG1979 commented on GitHub (Jun 26, 2021):

@Mitschmaster I forgot to say thank you for shaking that bug out.

<!-- gh-comment-id:869058458 --> @JasonLG1979 commented on GitHub (Jun 26, 2021): @Mitschmaster I forgot to say thank you for shaking that bug out.
Author
Owner

@Mitschmaster commented on GitHub (Jun 30, 2021):

Thanks for fixing it.

<!-- gh-comment-id:871641305 --> @Mitschmaster commented on GitHub (Jun 30, 2021): Thanks for fixing it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#414
No description provided.