[GH-ISSUE #864] Tracks pauses constantly on first play #433

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

Originally created by @jessicah on GitHub (Oct 11, 2021).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/864

Originally assigned to: @roderickvd on GitHub.

Once cached, it's fine, but the first time playing a track, it always has pauses.

Originally created by @jessicah on GitHub (Oct 11, 2021). Original GitHub issue: https://github.com/librespot-org/librespot/issues/864 Originally assigned to: @roderickvd on GitHub. Once cached, it's fine, but the first time playing a track, it always has pauses.
kerem 2026-02-27 19:30:35 +03:00
  • closed this issue
  • added the
    audio
    label
Author
Owner

@roderickvd commented on GitHub (Oct 11, 2021):

Well that's something that myself and most others can't reproduce, or we would be swamped with such issues.
Are you sure that your network connection is in order (so that it can buffer fast enough?)
Does it also happen with cache disabled?

<!-- gh-comment-id:939870024 --> @roderickvd commented on GitHub (Oct 11, 2021): Well that's something that myself and most others can't reproduce, or we would be swamped with such issues. Are you sure that your network connection is in order (so that it can buffer fast enough?) Does it also happen with cache disabled?
Author
Owner

@jessicah commented on GitHub (Oct 11, 2021):

Actually, I noticed one error message on screen before disappearing of a buffer underrun. Am using the ALSA back-end. I don't have this with other apps, such as Kodi.

<!-- gh-comment-id:940469828 --> @jessicah commented on GitHub (Oct 11, 2021): Actually, I noticed one error message on screen before disappearing of a buffer underrun. Am using the ALSA back-end. I don't have this with other apps, such as Kodi.
Author
Owner

@roderickvd commented on GitHub (Oct 12, 2021):

Could you provide the full verbose logs as well as answers to my questions above?

<!-- gh-comment-id:940879703 --> @roderickvd commented on GitHub (Oct 12, 2021): Could you provide the full verbose logs as well as answers to my questions above?
Author
Owner

@jessicah commented on GitHub (Oct 12, 2021):

The error was persistent with ncspot. I hadn't had the issue for librespot for about an hour or so, but now it's started happening in librespot too. Unfortunately, I'm not getting any ALSA specific errors from librespot.

[2021-10-12T23:38:05Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-12T23:38:05Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay
[2021-10-12T23:38:34Z DEBUG librespot_connect::spirc] kMessageTypeLoad "DESKTOP-BL668O1" 5085a11d69a82ef6508945200b87c9ef8c7a1a22 1994342217 1634081885734 kPlayStatusPlay
[2021-10-12T23:38:34Z DEBUG librespot_connect::spirc] State: context_uri: "spotify:playlist:6IixR1SzultezaQQhtJjXU" index: 0 position_ms: 0 status: kPlayStatusPlay position_measured_at: 1634081914005 context_description: "The Yellow Nimbus \342\200\223 Pt. 2 \342\200\223 Chick Corea" shuffle: false repeat: false playing_from_fallback: true row: 0 playing_track_index: 0 track {gid: "e\220\000\014\262\217K\264\261\241`\212\022\r\235 "}
[2021-10-12T23:38:34Z DEBUG librespot_connect::spirc] Frame has 1 tracks
[2021-10-12T23:38:34Z INFO  librespot_connect::spirc] Fetching autoplay context uri
[2021-10-12T23:38:34Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-12T23:38:34Z DEBUG librespot_playback::player] command=SetAutoNormaliseAsAlbum(false)
[2021-10-12T23:38:34Z DEBUG librespot_playback::player] command=Load(SpotifyId { id: 134999719327905034164069036140442524960, audio_type: Track }, true, 0)
[2021-10-12T23:38:34Z TRACE librespot_playback::player] == Stopping sink ==
[2021-10-12T23:38:34Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-12T23:38:34Z INFO  librespot_connect::spirc] Autoplay uri resolved to <"spotify:station:playlist:6IixR1SzultezaQQhtJjXU">
[2021-10-12T23:38:34Z INFO  librespot_playback::player] Loading <The Yellow Nimbus – Pt. 2> with Spotify URI <spotify:track:35E23ZSjnMqeVbV8g6tZWE>
[2021-10-12T23:38:35Z DEBUG librespot_audio::fetch] Downloading file ef93f4e323762ea2ccbcd9dd569c9daae1e8425a
[2021-10-12T23:38:35Z INFO  librespot_connect::spirc] Resolved 50 tracks from <"spotify:playlist:6IixR1SzultezaQQhtJjXU">
[2021-10-12T23:38:36Z INFO  librespot_playback::player] <The Yellow Nimbus – Pt. 2> (355386 ms) loaded
[2021-10-12T23:38:36Z TRACE librespot_playback::player] == Starting sink ==
[2021-10-12T23:38:36Z TRACE librespot_playback::audio_backend::alsa] Frames per Buffer: 4096
[2021-10-12T23:38:36Z TRACE librespot_playback::audio_backend::alsa] Frames per Period: 1024
[2021-10-12T23:38:36Z TRACE librespot_playback::audio_backend::alsa] Period Buffer size in bytes: 4096
[2021-10-12T23:38:36Z TRACE librespot_playback::audio_backend::alsa] Period Buffer capacity: 4096
[2021-10-12T23:38:36Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-12T23:38:36Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay
[2021-10-12T23:38:44Z DEBUG librespot_core::session] Session[0] strong=5 weak=4
[2021-10-12T23:40:39Z DEBUG librespot_audio::fetch] File ef93f4e323762ea2ccbcd9dd569c9daae1e8425a complete, saving to cache
[2021-10-12T23:40:44Z DEBUG librespot_core::session] Session[0] strong=3 weak=4

And the buffer underruns are occurring after the saving to cache message.

I've just tried playing the same track with --disable-audio-cache and the buffer underruns are continuing with this particular track.

And now it's gone from no buffer underruns to an underrun storm :-/ Also, both ncspot and librespot consistently use around 50% of a CPU core on my system, which seems excessive, is that normal?

<!-- gh-comment-id:941748661 --> @jessicah commented on GitHub (Oct 12, 2021): The error was persistent with `ncspot`. I hadn't had the issue for librespot for about an hour or so, but now it's started happening in librespot too. Unfortunately, I'm not getting any ALSA specific errors from librespot. ``` [2021-10-12T23:38:05Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-12T23:38:05Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay [2021-10-12T23:38:34Z DEBUG librespot_connect::spirc] kMessageTypeLoad "DESKTOP-BL668O1" 5085a11d69a82ef6508945200b87c9ef8c7a1a22 1994342217 1634081885734 kPlayStatusPlay [2021-10-12T23:38:34Z DEBUG librespot_connect::spirc] State: context_uri: "spotify:playlist:6IixR1SzultezaQQhtJjXU" index: 0 position_ms: 0 status: kPlayStatusPlay position_measured_at: 1634081914005 context_description: "The Yellow Nimbus \342\200\223 Pt. 2 \342\200\223 Chick Corea" shuffle: false repeat: false playing_from_fallback: true row: 0 playing_track_index: 0 track {gid: "e\220\000\014\262\217K\264\261\241`\212\022\r\235 "} [2021-10-12T23:38:34Z DEBUG librespot_connect::spirc] Frame has 1 tracks [2021-10-12T23:38:34Z INFO librespot_connect::spirc] Fetching autoplay context uri [2021-10-12T23:38:34Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-12T23:38:34Z DEBUG librespot_playback::player] command=SetAutoNormaliseAsAlbum(false) [2021-10-12T23:38:34Z DEBUG librespot_playback::player] command=Load(SpotifyId { id: 134999719327905034164069036140442524960, audio_type: Track }, true, 0) [2021-10-12T23:38:34Z TRACE librespot_playback::player] == Stopping sink == [2021-10-12T23:38:34Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-12T23:38:34Z INFO librespot_connect::spirc] Autoplay uri resolved to <"spotify:station:playlist:6IixR1SzultezaQQhtJjXU"> [2021-10-12T23:38:34Z INFO librespot_playback::player] Loading <The Yellow Nimbus – Pt. 2> with Spotify URI <spotify:track:35E23ZSjnMqeVbV8g6tZWE> [2021-10-12T23:38:35Z DEBUG librespot_audio::fetch] Downloading file ef93f4e323762ea2ccbcd9dd569c9daae1e8425a [2021-10-12T23:38:35Z INFO librespot_connect::spirc] Resolved 50 tracks from <"spotify:playlist:6IixR1SzultezaQQhtJjXU"> [2021-10-12T23:38:36Z INFO librespot_playback::player] <The Yellow Nimbus – Pt. 2> (355386 ms) loaded [2021-10-12T23:38:36Z TRACE librespot_playback::player] == Starting sink == [2021-10-12T23:38:36Z TRACE librespot_playback::audio_backend::alsa] Frames per Buffer: 4096 [2021-10-12T23:38:36Z TRACE librespot_playback::audio_backend::alsa] Frames per Period: 1024 [2021-10-12T23:38:36Z TRACE librespot_playback::audio_backend::alsa] Period Buffer size in bytes: 4096 [2021-10-12T23:38:36Z TRACE librespot_playback::audio_backend::alsa] Period Buffer capacity: 4096 [2021-10-12T23:38:36Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-12T23:38:36Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay [2021-10-12T23:38:44Z DEBUG librespot_core::session] Session[0] strong=5 weak=4 [2021-10-12T23:40:39Z DEBUG librespot_audio::fetch] File ef93f4e323762ea2ccbcd9dd569c9daae1e8425a complete, saving to cache [2021-10-12T23:40:44Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 ``` And the buffer underruns are occurring after the `saving to cache` message. I've just tried playing the same track with `--disable-audio-cache` and the buffer underruns are continuing with this particular track. And now it's gone from no buffer underruns to an underrun storm :-/ Also, both `ncspot` and `librespot` consistently use around 50% of a CPU core on my system, which seems excessive, is that normal?
Author
Owner

@roderickvd commented on GitHub (Oct 13, 2021):

And now it's gone from no buffer underruns to an underrun storm :-/ Also, both ncspot and librespot consistently use around 50% of a CPU core on my system, which seems excessive, is that normal?

No. Find the cause of this issue and you will likely find your solution. Your system is bogged and this is causing I/O underruns.

First to be sure, was this compiled with the --release flag?

Second the Alsa period size of 4096 seems very small, doesn't it @JasonLG1979?
What is your Alsa output device?

Please post:

  1. the full command line you are launching librespot with
  2. your Alsa configuration file
  3. the full verbose log from the point you launched librespot
<!-- gh-comment-id:942049696 --> @roderickvd commented on GitHub (Oct 13, 2021): > And now it's gone from no buffer underruns to an underrun storm :-/ Also, both `ncspot` and `librespot` consistently use around 50% of a CPU core on my system, which seems excessive, is that normal? No. Find the cause of this issue and you will likely find your solution. Your system is bogged and this is causing I/O underruns. First to be sure, was this compiled with the `--release` flag? Second the Alsa period size of 4096 seems very small, doesn't it @JasonLG1979? What is your Alsa output device? Please post: 1. the full command line you are launching `librespot` with 2. your Alsa configuration file 3. the full verbose log from the point you launched `librespot`
Author
Owner

@JasonLG1979 commented on GitHub (Oct 13, 2021):

Second the Alsa period size of 4096 seems very small, doesn't it @JasonLG1979?

@jessicah your log messages say 1024 frames per period and a 4096 frame total buffer size. That's your problem. It's either a driver or configuration issue. Librespot by default asks for 5, 100ms periods (4410 frames a period for a total buffer size of 22050 frames). Asks being the operative word. Your system for some reason is providing less than a 1/4 of the buffer that librespot is asking for.

<!-- gh-comment-id:942347406 --> @JasonLG1979 commented on GitHub (Oct 13, 2021): > Second the Alsa period size of 4096 seems very small, doesn't it @JasonLG1979? @jessicah your log messages say 1024 frames per period and a 4096 frame total buffer size. That's your problem. It's either a driver or configuration issue. Librespot by default asks for 5, 100ms periods (4410 frames a period for a total buffer size of 22050 frames). Asks being the operative word. Your system for some reason is providing less than a 1/4 of the buffer that librespot is asking for.
Author
Owner

@JasonLG1979 commented on GitHub (Oct 13, 2021):

In addition to what @roderickvd is asking for I'd also like to see the output of:

aplay -Dxxx --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav

Where -Dxxx is the output you've specified for librespot so for example -Dhw:0,0. If you haven't specified an output you can omit -D so it would just be aplay --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav

<!-- gh-comment-id:942357253 --> @JasonLG1979 commented on GitHub (Oct 13, 2021): In addition to what @roderickvd is asking for I'd also like to see the output of: `aplay -Dxxx --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav` Where `-Dxxx` is the output you've specified for librespot so for example `-Dhw:0,0`. If you haven't specified an output you can omit `-D` so it would just be `aplay --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav`
Author
Owner

@jessicah commented on GitHub (Oct 13, 2021):

It's highly probable that my ALSA config needs tweaking, I copied from some help page as it didn't work out of the box when setting up Kodi, and it's a headless Ubuntu install.

launch: /home/jessica/source/librespot/target/debug/librespot -n Librespot -b 320 -c ./cache --device-type avr --verbose --autoplay

ALSA config:

pcm.!default {
        type plug
        slave.pcm "dmixer"
}

pcm.dmixer  {
        type dmix
        ipc_key 1024
        slave {
                pcm "hw:0,3"
                period_time 0
                period_size 1024
                buffer_size 4096
                rate 44100
        }
        bindings {
                0 0
                1 1
        }
}

ctl.dmixer {
        type hw
        card 0
}

librespot log:

[2021-10-13T19:49:45Z INFO  librespot] librespot 0.2.0 2c95645 (Built on 2021-10-12, Build ID: lMmg0tr6)
[2021-10-13T19:49:45Z DEBUG librespot_playback::mixer::mappings] Volume control is now Log(60.0)
[2021-10-13T19:49:45Z DEBUG librespot_discovery::server] Zeroconf server listening on 0.0.0.0:34823
[2021-10-13T19:49:46Z INFO  librespot_core::session] Connecting to AP "gae2-accesspoint-a-6vnx.ap.spotify.com:4070"
[2021-10-13T19:49:48Z INFO  librespot_core::session] Authenticated as "1129990417" !
[2021-10-13T19:49:48Z DEBUG librespot_core::session] new Session[0]
[2021-10-13T19:49:48Z INFO  librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0)
[2021-10-13T19:49:48Z DEBUG librespot_connect::spirc] new Spirc[0]
[2021-10-13T19:49:48Z DEBUG librespot_connect::spirc] canonical_username: 1129990417
[2021-10-13T19:49:48Z DEBUG librespot_playback::player] new Player[0]
[2021-10-13T19:49:48Z DEBUG librespot_core::mercury] new MercuryManager
[2021-10-13T19:49:48Z INFO  librespot_playback::convert] Converting with ditherer: tpdf
[2021-10-13T19:49:48Z INFO  librespot_playback::audio_backend::alsa] Using AlsaSink with format: S16
[2021-10-13T19:49:48Z DEBUG librespot_playback::player] command=AddEventSender
[2021-10-13T19:49:48Z DEBUG librespot_playback::player] command=VolumeSet(65535)
[2021-10-13T19:49:48Z DEBUG librespot_core::session] Session[0] strong=3 weak=2
[2021-10-13T19:49:48Z INFO  librespot_core::session] Country: "NZ"
[2021-10-13T19:49:48Z DEBUG librespot_core::mercury] subscribed uri=hm://remote/user/1129990417/ count=0
[2021-10-13T19:49:48Z DEBUG librespot_connect::spirc] kMessageTypeNotify "DESKTOP-BL668O1" 5085a11d69a82ef6508945200b87c9ef8c7a1a22 2067016453 1634154588173 kPlayStatusPlay
[2021-10-13T19:49:48Z DEBUG librespot_connect::spirc] kMessageTypeNotify "Nokia 8" 397aaaac11db6028063a2403681f8a854dc796b0 2067016453 1634154588173 kPlayStatusStop

aplay hardware params (default):

$ aplay --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav
Playing WAVE '/usr/share/sounds/alsa/Front_Right.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
HW Params of device "default":
--------------------
ACCESS:  MMAP_INTERLEAVED MMAP_NONINTERLEAVED MMAP_COMPLEX RW_INTERLEAVED RW_NONINTERLEAVED
FORMAT:  S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE MU_LAW A_LAW IMA_ADPCM S20_LE S20_BE U20_LE U20_BE S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE U18_3BE
SUBFORMAT:  STD
SAMPLE_BITS: [4 64]
FRAME_BITS: [4 640000]
CHANNELS: [1 10000]
RATE: [4000 4294967295)
PERIOD_TIME: (23219 23220)
PERIOD_SIZE: (92 99729141)
PERIOD_BYTES: (46 4294967295)
PERIODS: (0 4336042)
BUFFER_TIME: [1 4294967295]
BUFFER_SIZE: [185 398915783]
BUFFER_BYTES: [93 4294967295]
TICK_TIME: ALL
--------------------

aplay hardware params (actual device):

$ aplay -Dhw:0,3 --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav
Playing WAVE '/usr/share/sounds/alsa/Front_Right.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
HW Params of device "hw:0,3":
--------------------
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE S32_LE
SUBFORMAT:  STD
SAMPLE_BITS: [16 32]
FRAME_BITS: [32 256]
CHANNELS: [2 8]
RATE: [32000 192000]
PERIOD_TIME: (20 256000]
PERIOD_SIZE: [4 8192]
PERIOD_BYTES: [128 262144]
PERIODS: [2 32]
BUFFER_TIME: (41 512000]
BUFFER_SIZE: [8 16384]
BUFFER_BYTES: [128 65536]
TICK_TIME: ALL
--------------------
aplay: set_params:1374: Channels count non available
<!-- gh-comment-id:942667603 --> @jessicah commented on GitHub (Oct 13, 2021): It's highly probable that my ALSA config needs tweaking, I copied from some help page as it didn't work out of the box when setting up Kodi, and it's a headless Ubuntu install. launch: `/home/jessica/source/librespot/target/debug/librespot -n Librespot -b 320 -c ./cache --device-type avr --verbose --autoplay` ALSA config: ``` pcm.!default { type plug slave.pcm "dmixer" } pcm.dmixer { type dmix ipc_key 1024 slave { pcm "hw:0,3" period_time 0 period_size 1024 buffer_size 4096 rate 44100 } bindings { 0 0 1 1 } } ctl.dmixer { type hw card 0 } ``` librespot log: ``` [2021-10-13T19:49:45Z INFO librespot] librespot 0.2.0 2c95645 (Built on 2021-10-12, Build ID: lMmg0tr6) [2021-10-13T19:49:45Z DEBUG librespot_playback::mixer::mappings] Volume control is now Log(60.0) [2021-10-13T19:49:45Z DEBUG librespot_discovery::server] Zeroconf server listening on 0.0.0.0:34823 [2021-10-13T19:49:46Z INFO librespot_core::session] Connecting to AP "gae2-accesspoint-a-6vnx.ap.spotify.com:4070" [2021-10-13T19:49:48Z INFO librespot_core::session] Authenticated as "1129990417" ! [2021-10-13T19:49:48Z DEBUG librespot_core::session] new Session[0] [2021-10-13T19:49:48Z INFO librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0) [2021-10-13T19:49:48Z DEBUG librespot_connect::spirc] new Spirc[0] [2021-10-13T19:49:48Z DEBUG librespot_connect::spirc] canonical_username: 1129990417 [2021-10-13T19:49:48Z DEBUG librespot_playback::player] new Player[0] [2021-10-13T19:49:48Z DEBUG librespot_core::mercury] new MercuryManager [2021-10-13T19:49:48Z INFO librespot_playback::convert] Converting with ditherer: tpdf [2021-10-13T19:49:48Z INFO librespot_playback::audio_backend::alsa] Using AlsaSink with format: S16 [2021-10-13T19:49:48Z DEBUG librespot_playback::player] command=AddEventSender [2021-10-13T19:49:48Z DEBUG librespot_playback::player] command=VolumeSet(65535) [2021-10-13T19:49:48Z DEBUG librespot_core::session] Session[0] strong=3 weak=2 [2021-10-13T19:49:48Z INFO librespot_core::session] Country: "NZ" [2021-10-13T19:49:48Z DEBUG librespot_core::mercury] subscribed uri=hm://remote/user/1129990417/ count=0 [2021-10-13T19:49:48Z DEBUG librespot_connect::spirc] kMessageTypeNotify "DESKTOP-BL668O1" 5085a11d69a82ef6508945200b87c9ef8c7a1a22 2067016453 1634154588173 kPlayStatusPlay [2021-10-13T19:49:48Z DEBUG librespot_connect::spirc] kMessageTypeNotify "Nokia 8" 397aaaac11db6028063a2403681f8a854dc796b0 2067016453 1634154588173 kPlayStatusStop ``` aplay hardware params (default): ``` $ aplay --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav Playing WAVE '/usr/share/sounds/alsa/Front_Right.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono HW Params of device "default": -------------------- ACCESS: MMAP_INTERLEAVED MMAP_NONINTERLEAVED MMAP_COMPLEX RW_INTERLEAVED RW_NONINTERLEAVED FORMAT: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE MU_LAW A_LAW IMA_ADPCM S20_LE S20_BE U20_LE U20_BE S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE U18_3BE SUBFORMAT: STD SAMPLE_BITS: [4 64] FRAME_BITS: [4 640000] CHANNELS: [1 10000] RATE: [4000 4294967295) PERIOD_TIME: (23219 23220) PERIOD_SIZE: (92 99729141) PERIOD_BYTES: (46 4294967295) PERIODS: (0 4336042) BUFFER_TIME: [1 4294967295] BUFFER_SIZE: [185 398915783] BUFFER_BYTES: [93 4294967295] TICK_TIME: ALL -------------------- ``` aplay hardware params (actual device): ``` $ aplay -Dhw:0,3 --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav Playing WAVE '/usr/share/sounds/alsa/Front_Right.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono HW Params of device "hw:0,3": -------------------- ACCESS: MMAP_INTERLEAVED RW_INTERLEAVED FORMAT: S16_LE S32_LE SUBFORMAT: STD SAMPLE_BITS: [16 32] FRAME_BITS: [32 256] CHANNELS: [2 8] RATE: [32000 192000] PERIOD_TIME: (20 256000] PERIOD_SIZE: [4 8192] PERIOD_BYTES: [128 262144] PERIODS: [2 32] BUFFER_TIME: (41 512000] BUFFER_SIZE: [8 16384] BUFFER_BYTES: [128 65536] TICK_TIME: ALL -------------------- aplay: set_params:1374: Channels count non available ```
Author
Owner

@jessicah commented on GitHub (Oct 13, 2021):

Using the hw:0,3 device directly improves the situation a bit, but am still running into what I presume are still buffer underruns.

Latest output:

[2021-10-13T21:38:48Z INFO  librespot_connect::spirc] Autoplay uri resolved to <"spotify:station:playlist:79ruP7JAmXE3igABq0C38f">
[2021-10-13T21:38:48Z INFO  librespot_playback::player] Loading <The Saint> with Spotify URI <spotify:track:7BKHAnROrnOrhkDb4lBViI>
[2021-10-13T21:38:49Z DEBUG librespot_audio::fetch] Downloading file 7d863bcc40df033f0bfae71df1f6f8586f3959da
[2021-10-13T21:38:49Z INFO  librespot_connect::spirc] Resolved 50 tracks from <"spotify:playlist:79ruP7JAmXE3igABq0C38f">
[2021-10-13T21:38:49Z INFO  librespot_playback::player] <The Saint> (272906 ms) loaded
[2021-10-13T21:38:49Z TRACE librespot_playback::player] == Starting sink ==
[2021-10-13T21:38:49Z TRACE librespot_playback::audio_backend::alsa] Frames per Buffer: 16384
[2021-10-13T21:38:49Z TRACE librespot_playback::audio_backend::alsa] Frames per Period: 8192
[2021-10-13T21:38:49Z TRACE librespot_playback::audio_backend::alsa] Period Buffer size in bytes: 32768
[2021-10-13T21:38:49Z TRACE librespot_playback::audio_backend::alsa] Period Buffer capacity: 32768
[2021-10-13T21:38:49Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-13T21:38:49Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay
[2021-10-13T21:40:12Z DEBUG librespot_audio::fetch] File 7d863bcc40df033f0bfae71df1f6f8586f3959da complete, saving to cache
[2021-10-13T21:40:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4
[2021-10-13T21:42:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4
[2021-10-13T21:42:52Z DEBUG librespot_playback::player] command=Preload(SpotifyId { id: 61479140210186197434646834358328784244, audio_type: Track })
[2021-10-13T21:42:52Z DEBUG librespot_playback::player] Preloading track
[2021-10-13T21:42:52Z INFO  librespot_playback::player] Loading <Bones> with Spotify URI <spotify:track:1ph6ini03Nknj24Hp0UR7e>
[2021-10-13T21:42:52Z DEBUG librespot_audio::fetch] Downloading file da0df2bfeb17acb579c0d9415ef782380a067b61
[2021-10-13T21:42:53Z INFO  librespot_playback::player] <Bones> (451480 ms) loaded
[2021-10-13T21:43:22Z DEBUG librespot_connect::spirc] At track 1 of 58 <"spotify:playlist:79ruP7JAmXE3igABq0C38f"> update [false]
[2021-10-13T21:43:22Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-13T21:43:22Z DEBUG librespot_playback::player] command=Load(SpotifyId { id: 61479140210186197434646834358328784244, audio_type: Track }, true, 0)
[2021-10-13T21:43:22Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-13T21:43:22Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay
[2021-10-13T21:44:23Z DEBUG librespot_core::session] Session[0] strong=5 weak=4
[2021-10-13T21:45:07Z DEBUG librespot_audio::fetch] File da0df2bfeb17acb579c0d9415ef782380a067b61 complete, saving to cache
[2021-10-13T21:46:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4
[2021-10-13T21:48:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4
[2021-10-13T21:50:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4
[2021-10-13T21:50:23Z DEBUG librespot_playback::player] command=Preload(SpotifyId { id: 302010519196267238030426068223719692867, audio_type: Track })
[2021-10-13T21:50:23Z DEBUG librespot_playback::player] Preloading track
[2021-10-13T21:50:24Z INFO  librespot_playback::player] Loading <Tomorrow Never Comes> with Spotify URI <spotify:track:6UJwQ4svz6ARAm6Ml2zivh>
[2021-10-13T21:50:24Z DEBUG librespot_audio::fetch] Downloading file 18482e5362a09a5d8de681ea28f800da7e561d8d
[2021-10-13T21:50:25Z INFO  librespot_playback::player] <Tomorrow Never Comes> (378573 ms) loaded
[2021-10-13T21:50:53Z DEBUG librespot_connect::spirc] At track 2 of 58 <"spotify:playlist:79ruP7JAmXE3igABq0C38f"> update [false]
[2021-10-13T21:50:53Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-13T21:50:53Z DEBUG librespot_playback::player] command=Load(SpotifyId { id: 302010519196267238030426068223719692867, audio_type: Track }, true, 0)
[2021-10-13T21:50:53Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-13T21:50:53Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay
[2021-10-13T21:52:14Z DEBUG librespot_audio::fetch] File 18482e5362a09a5d8de681ea28f800da7e561d8d complete, saving to cache
[2021-10-13T21:52:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4
[2021-10-13T21:54:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4
[2021-10-13T21:56:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4
[2021-10-13T21:56:42Z DEBUG librespot_playback::player] command=Preload(SpotifyId { id: 277242787359524526791464692348083120266, audio_type: Track })
[2021-10-13T21:56:42Z DEBUG librespot_playback::player] Preloading track
[2021-10-13T21:56:42Z INFO  librespot_playback::player] Loading <Low to the Street> with Spotify URI <spotify:track:6lzAGvpGoMJq3Y601qvqUa>
[2021-10-13T21:56:42Z DEBUG librespot_audio::fetch] Downloading file b22651c1c1c490df1eba81700ad7de142a4f77ef
[2021-10-13T21:56:43Z INFO  librespot_playback::player] <Low to the Street> (308989 ms) loaded
[2021-10-13T21:57:12Z DEBUG librespot_connect::spirc] At track 3 of 58 <"spotify:playlist:79ruP7JAmXE3igABq0C38f"> update [false]
[2021-10-13T21:57:12Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-13T21:57:12Z DEBUG librespot_playback::player] command=Load(SpotifyId { id: 277242787359524526791464692348083120266, audio_type: Track }, true, 0)
[2021-10-13T21:57:12Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay]
[2021-10-13T21:57:12Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay
[2021-10-13T21:57:41Z DEBUG librespot_audio::fetch] File b22651c1c1c490df1eba81700ad7de142a4f77ef complete, saving to cache
[2021-10-13T21:58:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4
<!-- gh-comment-id:942754200 --> @jessicah commented on GitHub (Oct 13, 2021): Using the `hw:0,3` device directly improves the situation a bit, but am still running into what I presume are still buffer underruns. Latest output: ``` [2021-10-13T21:38:48Z INFO librespot_connect::spirc] Autoplay uri resolved to <"spotify:station:playlist:79ruP7JAmXE3igABq0C38f"> [2021-10-13T21:38:48Z INFO librespot_playback::player] Loading <The Saint> with Spotify URI <spotify:track:7BKHAnROrnOrhkDb4lBViI> [2021-10-13T21:38:49Z DEBUG librespot_audio::fetch] Downloading file 7d863bcc40df033f0bfae71df1f6f8586f3959da [2021-10-13T21:38:49Z INFO librespot_connect::spirc] Resolved 50 tracks from <"spotify:playlist:79ruP7JAmXE3igABq0C38f"> [2021-10-13T21:38:49Z INFO librespot_playback::player] <The Saint> (272906 ms) loaded [2021-10-13T21:38:49Z TRACE librespot_playback::player] == Starting sink == [2021-10-13T21:38:49Z TRACE librespot_playback::audio_backend::alsa] Frames per Buffer: 16384 [2021-10-13T21:38:49Z TRACE librespot_playback::audio_backend::alsa] Frames per Period: 8192 [2021-10-13T21:38:49Z TRACE librespot_playback::audio_backend::alsa] Period Buffer size in bytes: 32768 [2021-10-13T21:38:49Z TRACE librespot_playback::audio_backend::alsa] Period Buffer capacity: 32768 [2021-10-13T21:38:49Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-13T21:38:49Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay [2021-10-13T21:40:12Z DEBUG librespot_audio::fetch] File 7d863bcc40df033f0bfae71df1f6f8586f3959da complete, saving to cache [2021-10-13T21:40:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 [2021-10-13T21:42:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 [2021-10-13T21:42:52Z DEBUG librespot_playback::player] command=Preload(SpotifyId { id: 61479140210186197434646834358328784244, audio_type: Track }) [2021-10-13T21:42:52Z DEBUG librespot_playback::player] Preloading track [2021-10-13T21:42:52Z INFO librespot_playback::player] Loading <Bones> with Spotify URI <spotify:track:1ph6ini03Nknj24Hp0UR7e> [2021-10-13T21:42:52Z DEBUG librespot_audio::fetch] Downloading file da0df2bfeb17acb579c0d9415ef782380a067b61 [2021-10-13T21:42:53Z INFO librespot_playback::player] <Bones> (451480 ms) loaded [2021-10-13T21:43:22Z DEBUG librespot_connect::spirc] At track 1 of 58 <"spotify:playlist:79ruP7JAmXE3igABq0C38f"> update [false] [2021-10-13T21:43:22Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-13T21:43:22Z DEBUG librespot_playback::player] command=Load(SpotifyId { id: 61479140210186197434646834358328784244, audio_type: Track }, true, 0) [2021-10-13T21:43:22Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-13T21:43:22Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay [2021-10-13T21:44:23Z DEBUG librespot_core::session] Session[0] strong=5 weak=4 [2021-10-13T21:45:07Z DEBUG librespot_audio::fetch] File da0df2bfeb17acb579c0d9415ef782380a067b61 complete, saving to cache [2021-10-13T21:46:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 [2021-10-13T21:48:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 [2021-10-13T21:50:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 [2021-10-13T21:50:23Z DEBUG librespot_playback::player] command=Preload(SpotifyId { id: 302010519196267238030426068223719692867, audio_type: Track }) [2021-10-13T21:50:23Z DEBUG librespot_playback::player] Preloading track [2021-10-13T21:50:24Z INFO librespot_playback::player] Loading <Tomorrow Never Comes> with Spotify URI <spotify:track:6UJwQ4svz6ARAm6Ml2zivh> [2021-10-13T21:50:24Z DEBUG librespot_audio::fetch] Downloading file 18482e5362a09a5d8de681ea28f800da7e561d8d [2021-10-13T21:50:25Z INFO librespot_playback::player] <Tomorrow Never Comes> (378573 ms) loaded [2021-10-13T21:50:53Z DEBUG librespot_connect::spirc] At track 2 of 58 <"spotify:playlist:79ruP7JAmXE3igABq0C38f"> update [false] [2021-10-13T21:50:53Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-13T21:50:53Z DEBUG librespot_playback::player] command=Load(SpotifyId { id: 302010519196267238030426068223719692867, audio_type: Track }, true, 0) [2021-10-13T21:50:53Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-13T21:50:53Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay [2021-10-13T21:52:14Z DEBUG librespot_audio::fetch] File 18482e5362a09a5d8de681ea28f800da7e561d8d complete, saving to cache [2021-10-13T21:52:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 [2021-10-13T21:54:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 [2021-10-13T21:56:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 [2021-10-13T21:56:42Z DEBUG librespot_playback::player] command=Preload(SpotifyId { id: 277242787359524526791464692348083120266, audio_type: Track }) [2021-10-13T21:56:42Z DEBUG librespot_playback::player] Preloading track [2021-10-13T21:56:42Z INFO librespot_playback::player] Loading <Low to the Street> with Spotify URI <spotify:track:6lzAGvpGoMJq3Y601qvqUa> [2021-10-13T21:56:42Z DEBUG librespot_audio::fetch] Downloading file b22651c1c1c490df1eba81700ad7de142a4f77ef [2021-10-13T21:56:43Z INFO librespot_playback::player] <Low to the Street> (308989 ms) loaded [2021-10-13T21:57:12Z DEBUG librespot_connect::spirc] At track 3 of 58 <"spotify:playlist:79ruP7JAmXE3igABq0C38f"> update [false] [2021-10-13T21:57:12Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-13T21:57:12Z DEBUG librespot_playback::player] command=Load(SpotifyId { id: 277242787359524526791464692348083120266, audio_type: Track }, true, 0) [2021-10-13T21:57:12Z TRACE librespot_connect::spirc] Sending status to server: [kPlayStatusPlay] [2021-10-13T21:57:12Z TRACE librespot_connect::spirc] ==> kPlayStatusPlay [2021-10-13T21:57:41Z DEBUG librespot_audio::fetch] File b22651c1c1c490df1eba81700ad7de142a4f77ef complete, saving to cache [2021-10-13T21:58:23Z DEBUG librespot_core::session] Session[0] strong=3 weak=4 ```
Author
Owner

@roderickvd commented on GitHub (Oct 14, 2021):

I'm inclined to close this issue, because it's likely a system configuration issue and not a librespot bug. Your Alsa dmix configuration is what specifies the low 4096 period size, so that's not right.

It was good idea to test with the direct hardware device. Did you compile with --release? Otherwise debug code will be enabled, and the performance impact with dithering enabled is huge to the point that it drags platforms like Raspberry Pi's down.

Note to self: should check for #[cfg(debug_assertions)] to have the verbose log print whether we're in debug or release.

<!-- gh-comment-id:943133340 --> @roderickvd commented on GitHub (Oct 14, 2021): I'm inclined to close this issue, because it's likely a system configuration issue and not a `librespot` bug. Your Alsa `dmix` configuration is what specifies the low 4096 period size, so that's not right. It was good idea to test with the direct hardware device. Did you compile with `--release`? Otherwise debug code will be enabled, and the performance impact with dithering enabled is huge to the point that it drags platforms like Raspberry Pi's down. Note to self: should check for `#[cfg(debug_assertions)]` to have the verbose log print whether we're in debug or release.
Author
Owner

@JasonLG1979 commented on GitHub (Oct 14, 2021):

It's highly probable that my ALSA config needs tweaking, I copied from some help page as it didn't work out of the box when setting up Kodi, and it's a headless Ubuntu install.

Yep, that's your problem for sure. You may be able to get away with a buffer that small on an x86-64 system but that will hammer a Raspberry Pi, and for no good reason either. Buffers that small are really only needed for multi-track recording. You really don't need super low latency just for playback. Worst case with a good sized buffer during playback is that you need to delay video to match the audio a little bit. Kodi has something in it's settings I'm sure somewhere for syncing the audio.

Try this and see if it works:

pcm.!default {
    type plug
    slave.pcm {
        type dmix
        ipc_key {
            @func refer
            name defaults.pcm.ipc_key
        }
        ipc_gid {
            @func refer
            name defaults.pcm.ipc_gid
        }
        ipc_perm {
            @func refer
            name defaults.pcm.ipc_perm
        }
        slave {
            pcm "hw:0,3"
            channels 2
            period_size 4410
            buffer_size 22050
            buffer_time 500000
            period_time 100000
            periods 5
            rate 44100
            format S32_LE
        }
        bindings {
            0 0
            1 1
        }
    }
}

ctl.!default {
    type hw
    card 0
}

hw:0,3 says it can do S32_LE so I'd use that. Librespot will output S32_LE if you add --format S32 the main advantage of 32 bit is that you get more or less lossless software volume control. Anything that not 32 bit will just get padded with zeros at pretty much no performance cost and no audio quality cost.

Using the hw:0,3 device directly improves the situation a bit, but am still running into what I presume are still buffer underruns.

If you were getting underruns it would say so in the logs. Debug builds tend to run pretty poorly on a Raspberry Pi. Unless you're developing and you want to test something real quick you should be using the --release flag so the binary is optimized. What you want is:

cargo build --release --no-default-features --features alsa-backend

<!-- gh-comment-id:943393184 --> @JasonLG1979 commented on GitHub (Oct 14, 2021): > It's highly probable that my ALSA config needs tweaking, I copied from some help page as it didn't work out of the box when setting up Kodi, and it's a headless Ubuntu install. Yep, that's your problem for sure. You may be able to get away with a buffer that small on an x86-64 system but that will hammer a Raspberry Pi, and for no good reason either. Buffers that small are really only needed for multi-track recording. You really don't need super low latency just for playback. Worst case with a good sized buffer during playback is that you need to delay video to match the audio a little bit. Kodi has something in it's settings I'm sure somewhere for syncing the audio. Try this and see if it works: ``` pcm.!default { type plug slave.pcm { type dmix ipc_key { @func refer name defaults.pcm.ipc_key } ipc_gid { @func refer name defaults.pcm.ipc_gid } ipc_perm { @func refer name defaults.pcm.ipc_perm } slave { pcm "hw:0,3" channels 2 period_size 4410 buffer_size 22050 buffer_time 500000 period_time 100000 periods 5 rate 44100 format S32_LE } bindings { 0 0 1 1 } } } ctl.!default { type hw card 0 } ``` `hw:0,3` says it can do `S32_LE` so I'd use that. Librespot will output `S32_LE` if you add `--format S32` the main advantage of 32 bit is that you get more or less lossless software volume control. Anything that not 32 bit will just get padded with zeros at pretty much no performance cost and no audio quality cost. > Using the hw:0,3 device directly improves the situation a bit, but am still running into what I presume are still buffer underruns. If you were getting underruns it would say so in the logs. Debug builds tend to run pretty poorly on a Raspberry Pi. Unless you're developing and you want to test something real quick you should be using the `--release` flag so the binary is optimized. What you want is: `cargo build --release --no-default-features --features alsa-backend`
Author
Owner

@jessicah commented on GitHub (Oct 15, 2021):

Even with @JasonLG1979's config, I'm still getting playback issues (with release build), seems buffers are still small?

2021-10-15T00:12:00Z TRACE librespot_playback::player] == Starting sink ==
[2021-10-15T00:12:00Z TRACE librespot_playback::audio_backend::alsa] Frames per Buffer: 8192
[2021-10-15T00:12:00Z TRACE librespot_playback::audio_backend::alsa] Frames per Period: 4096
[2021-10-15T00:12:00Z TRACE librespot_playback::audio_backend::alsa] Period Buffer size in bytes: 32768
[2021-10-15T00:12:00Z TRACE librespot_playback::audio_backend::alsa] Period Buffer capacity: 32768

<!-- gh-comment-id:943856547 --> @jessicah commented on GitHub (Oct 15, 2021): Even with @JasonLG1979's config, I'm still getting playback issues (with release build), seems buffers are still small? 2021-10-15T00:12:00Z TRACE librespot_playback::player] == Starting sink == [2021-10-15T00:12:00Z TRACE librespot_playback::audio_backend::alsa] Frames per Buffer: 8192 [2021-10-15T00:12:00Z TRACE librespot_playback::audio_backend::alsa] Frames per Period: 4096 [2021-10-15T00:12:00Z TRACE librespot_playback::audio_backend::alsa] Period Buffer size in bytes: 32768 [2021-10-15T00:12:00Z TRACE librespot_playback::audio_backend::alsa] Period Buffer capacity: 32768
Author
Owner

@JasonLG1979 commented on GitHub (Oct 15, 2021):

Try changing it to:

            period_size 0
            buffer_size 0
            buffer_time 0
            period_time 125000
            periods 4
<!-- gh-comment-id:943948755 --> @JasonLG1979 commented on GitHub (Oct 15, 2021): Try changing it to: ``` period_size 0 buffer_size 0 buffer_time 0 period_time 125000 periods 4 ```
Author
Owner

@JasonLG1979 commented on GitHub (Oct 15, 2021):

@roderickvd it may be time to make period size and the number of periods user configurable. It could default to what we have which is 5 periods at 100ms and have a reasonable range, say 2 - 10 periods (there has to be at least 2 periods per buffer) and 10 - 200ms periods. It could be --alsa-buffer-periods and --alsa-buffer-period-size

What we have works for 99% of people but this is the 2nd edge case in a couple months.

<!-- gh-comment-id:944300561 --> @JasonLG1979 commented on GitHub (Oct 15, 2021): @roderickvd it may be time to make period size and the number of periods user configurable. It could default to what we have which is 5 periods at 100ms and have a reasonable range, say 2 - 10 periods (there has to be at least 2 periods per buffer) and 10 - 200ms periods. It could be `--alsa-buffer-periods` and `--alsa-buffer-period-size` What we have works for 99% of people but this is the 2nd edge case in a couple months.
Author
Owner

@roderickvd commented on GitHub (Oct 15, 2021):

aplay output indicates that the hw:0,3 device supports the right range of periods.
So I still don't understand what's going on here.

  • Why doesn't it give the buffers that it's asked for? (was Alsa properly reloaded or the system rebooted?)
  • What if this Alsa configuration is passed to dmix and that's used as the output device?
  • What if it's plughw?
  • What if dithering is disabled?
  • Are we in S16 or S32 here? Please continue to post full command lines and verbose logs, not excerpts.
  • What hardware is this running on?

Would like to see more debugging before we overhaul anything or introduce more command line options. In fact I'm still not convinced that it's librespot and not the host platform.

<!-- gh-comment-id:944314308 --> @roderickvd commented on GitHub (Oct 15, 2021): `aplay` output indicates that the `hw:0,3` device supports the right range of periods. So I still don't understand what's going on here. - Why doesn't it give the buffers that it's asked for? (was Alsa properly reloaded or the system rebooted?) - What if this Alsa configuration is passed to `dmix` and that's used as the output device? - What if it's `plughw`? - What if dithering is disabled? - Are we in `S16` or `S32` here? Please continue to post full command lines and verbose logs, not excerpts. - What hardware is this running on? Would like to see more debugging before we overhaul anything or introduce more command line options. In fact I'm still not convinced that it's `librespot` and not the host platform.
Author
Owner

@JasonLG1979 commented on GitHub (Oct 15, 2021):

aplay output indicates that the hw:0,3 device supports the right range of periods.
So I still don't understand what's going on here.

Why doesn't it give the buffers that it's asked for? (was Alsa properly reloaded or the system rebooted?)

That just tells us a range of number of periods and sizes it doesn't tell us which actually work together. Not all number of periods work with all period sizes.

<!-- gh-comment-id:944319463 --> @JasonLG1979 commented on GitHub (Oct 15, 2021): > aplay output indicates that the hw:0,3 device supports the right range of periods. So I still don't understand what's going on here. > Why doesn't it give the buffers that it's asked for? (was Alsa properly reloaded or the system rebooted?) That just tells us a range of number of periods and sizes it doesn't tell us which actually work together. Not all number of periods work with all period sizes.
Author
Owner

@JasonLG1979 commented on GitHub (Oct 15, 2021):

If I knew what the device was (I think it might be one of the HDMI ports given that it's hw:0,3) we could look at the driver source and see what the deal is maybe?

<!-- gh-comment-id:944320802 --> @JasonLG1979 commented on GitHub (Oct 15, 2021): If I knew what the device was (I think it might be one of the HDMI ports given that it's `hw:0,3`) we could look at the driver source and see what the deal is maybe?
Author
Owner

@JasonLG1979 commented on GitHub (Oct 15, 2021):

What if this Alsa configuration is passed to dmix and that's used as the output device?

Both her and I's configs already use dmix.

What hardware is this running on?

I guess I assumed a Raspberry Pi of some kind?

<!-- gh-comment-id:944325455 --> @JasonLG1979 commented on GitHub (Oct 15, 2021): > What if this Alsa configuration is passed to dmix and that's used as the output device? Both her and I's configs already use dmix. > What hardware is this running on? I guess I assumed a Raspberry Pi of some kind?
Author
Owner

@roderickvd commented on GitHub (Oct 15, 2021):

That just tells us a range of number of periods and sizes it doesn't tell us which actually work together. Not all number of periods work with all period sizes.

That's certainly true.

Both her and I's configs already use dmix.

It's not clear to me whether librespot is now launched with --device dmix or --device hw:0,3.

<!-- gh-comment-id:944327592 --> @roderickvd commented on GitHub (Oct 15, 2021): > That just tells us a range of number of periods and sizes it doesn't tell us which actually work together. Not all number of periods work with all period sizes. That's certainly true. > Both her and I's configs already use dmix. It's not clear to me whether `librespot` is now launched with `--device dmix` or `--device hw:0,3`.
Author
Owner

@JasonLG1979 commented on GitHub (Oct 15, 2021):

It's not clear to me whether librespot is now launched with --device dmix or --device hw:0,3.

She said:

Even with @JasonLG1979's config, I'm still getting playback issues (with release build), seems buffers are still small?

I think her device may just be finicky. It seems to be able to do a 0.5 sec buffer with 2 periods and a 4 period buffer with really small periods. Neither of which seems to work very well. It may just be a matter of trial and error to see if we can come up with something that works?

<!-- gh-comment-id:944333069 --> @JasonLG1979 commented on GitHub (Oct 15, 2021): > It's not clear to me whether `librespot` is now launched with `--device dmix` or `--device hw:0,3`. She said: > Even with @JasonLG1979's config, I'm still getting playback issues (with release build), seems buffers are still small? I think her device may just be finicky. It seems to be able to do a 0.5 sec buffer with 2 periods and a 4 period buffer with really small periods. Neither of which seems to work very well. It may just be a matter of trial and error to see if we can come up with something that works?
Author
Owner

@kingosticks commented on GitHub (Oct 15, 2021):

Librespot by default asks for 5, 100ms periods (4410 frames a period for a total buffer size of 22050 frames).

I think (not 100% sure) that

period_size 4410
buffer_size 22050

in the first suggested config are actually specifying bytes (not frames, like I think you wanted. And yes this is at odds with the terminology used by --dump-hw-params). Perhaps that explains why it cannot comply with what librespot is asking for?

<!-- gh-comment-id:944333916 --> @kingosticks commented on GitHub (Oct 15, 2021): > Librespot by default asks for 5, 100ms periods (4410 frames a period for a total buffer size of 22050 frames). I think (not 100% sure) that >period_size 4410 buffer_size 22050 in the first suggested config are actually specifying bytes (not frames, like I think you wanted. And yes this is at odds with the terminology used by --dump-hw-params). Perhaps that explains why it cannot comply with what librespot is asking for?
Author
Owner

@JasonLG1979 commented on GitHub (Oct 15, 2021):

in the first suggested config are actually specifying bytes (not frames, like I think you wanted. And yes this is at odds with the terminology used by --dump-hw-params). Perhaps that explains why it cannot comply with what librespot is asking for?

Derp de derp. You're right... 🤦

<!-- gh-comment-id:944336293 --> @JasonLG1979 commented on GitHub (Oct 15, 2021): > in the first suggested config are actually specifying bytes (not frames, like I think you wanted. And yes this is at odds with the terminology used by --dump-hw-params). Perhaps that explains why it cannot comply with what librespot is asking for? Derp de derp. You're right... :facepalm:
Author
Owner

@JasonLG1979 commented on GitHub (Oct 15, 2021):

Then I would maybe suggest:

pcm.!default {
    type plug
    slave.pcm {
        type dmix
        ipc_key {
            @func refer
            name defaults.pcm.ipc_key
        }
        ipc_gid {
            @func refer
            name defaults.pcm.ipc_gid
        }
        ipc_perm {
            @func refer
            name defaults.pcm.ipc_perm
        }
        slave {
            pcm "hw:0,3"
            channels 2
            period_size 0
            buffer_size 0
            buffer_time 0
            period_time 100000
            periods 5
            rate 44100
            format S32_LE
        }
        bindings {
            0 0
            1 1
        }
    }
}

ctl.!default {
    type hw
    card 0
}

And change:

            period_time xxx
            periods x

Until you find something that works.

<!-- gh-comment-id:944340559 --> @JasonLG1979 commented on GitHub (Oct 15, 2021): Then I would maybe suggest: ``` pcm.!default { type plug slave.pcm { type dmix ipc_key { @func refer name defaults.pcm.ipc_key } ipc_gid { @func refer name defaults.pcm.ipc_gid } ipc_perm { @func refer name defaults.pcm.ipc_perm } slave { pcm "hw:0,3" channels 2 period_size 0 buffer_size 0 buffer_time 0 period_time 100000 periods 5 rate 44100 format S32_LE } bindings { 0 0 1 1 } } } ctl.!default { type hw card 0 } ``` And change: ``` period_time xxx periods x ``` Until you find something that works.
Author
Owner

@roderickvd commented on GitHub (Oct 15, 2021):

Good catch. Not surprised about yet another Alsa idiosyncrasy!

<!-- gh-comment-id:944347210 --> @roderickvd commented on GitHub (Oct 15, 2021): Good catch. Not surprised about yet another Alsa idiosyncrasy!
Author
Owner

@JasonLG1979 commented on GitHub (Oct 15, 2021):

Good catch. Not surprised about yet another Alsa idiosyncrasy!

I should have caught that. That's my bad. The derp is strong with this one...

<!-- gh-comment-id:944350761 --> @JasonLG1979 commented on GitHub (Oct 15, 2021): > Good catch. Not surprised about yet another Alsa idiosyncrasy! I should have caught that. That's my bad. The derp is strong with this one...
Author
Owner

@kingosticks commented on GitHub (Oct 15, 2021):

To be honest I am still not sure, the online alsa docs and the source code have conflicting comments! Probably safest to avoid using it if possible and go with buffer_time instead, if you have to specify it for some reason.

<!-- gh-comment-id:944354968 --> @kingosticks commented on GitHub (Oct 15, 2021): To be honest I am still not sure, the online alsa docs and the source code have conflicting comments! Probably safest to avoid using it if possible and go with buffer_time instead, if you have to specify it for some reason.
Author
Owner

@roderickvd commented on GitHub (Oct 21, 2021):

Any progress on this @jessicah?

<!-- gh-comment-id:948323391 --> @roderickvd commented on GitHub (Oct 21, 2021): Any progress on this @jessicah?
Author
Owner

@jessicah commented on GitHub (Nov 3, 2021):

Sorry, I'll give the suggestions a go now, been moving stuff, and haven't had a chance to retest. It's an Intel NUC i3-4010U, audio via HDMI.

<!-- gh-comment-id:959966887 --> @jessicah commented on GitHub (Nov 3, 2021): Sorry, I'll give the suggestions a go now, been moving stuff, and haven't had a chance to retest. It's an Intel NUC i3-4010U, audio via HDMI.
Author
Owner

@jessicah commented on GitHub (Nov 3, 2021):

Well, it seems it's a weird ALSA bug. Running aplay -D hw:0,3 --verbose ~/test.wav gives the same issues, so I don't understand how Kodi can play audio without any hiccups. I tried passing several parameters for buffer/period size/time, but they all seem to get ignored by aplay.

For reference, here is output from aply with the last suggested configuration:

jessica@homecloud:~/source/librespot$ aplay -D hw:0,3 --verbose ~/test.wav
Playing WAVE '/home/jessica/test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
Hardware PCM card 0 'HDA Intel HDMI' device 3 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 16384
  period_size  : 4096
  period_time  : 85333
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 4096
  period_event : 0
  start_threshold  : 16384
  stop_threshold   : 16384
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
  appl_ptr     : 0
  hw_ptr       : 0

And without specifying a device explicitly:

jessica@homecloud:~/source/librespot$ aplay --verbose ~/test.wav
Playing WAVE '/home/jessica/test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
Plug PCM: Linear conversion PCM (S32_LE)
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 16
  buffer_size  : 8192
  period_size  : 4096
  period_time  : 85333
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 4096
  period_event : 0
  start_threshold  : 8192
  stop_threshold   : 8192
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
Slave: Direct Stream Mixing PCM
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S32_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 32
  buffer_size  : 8192
  period_size  : 4096
  period_time  : 85333
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 4096
  period_event : 0
  start_threshold  : 8192
  stop_threshold   : 8192
  silence_threshold: 0
  silence_size : 0
  boundary     : 4611686018427387904
Hardware PCM card 0 'HDA Intel HDMI' device 3 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : MMAP_INTERLEAVED
  format       : S32_LE
  subformat    : STD
  channels     : 2
  rate         : 48000
  exact rate   : 48000 (48000/1)
  msbits       : 32
  buffer_size  : 8192
  period_size  : 4096
  period_time  : 85333
  tstamp_mode  : ENABLE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 4096
  period_event : 0
  start_threshold  : 1
  stop_threshold   : 4611686018427387904
  silence_threshold: 0
  silence_size : 4611686018427387904
  boundary     : 4611686018427387904
  appl_ptr     : 0
  hw_ptr       : 0

So I guess may as well close this? I'm not sure what else I can do, especially when Kodi doesn't have any issues :-/

<!-- gh-comment-id:960043492 --> @jessicah commented on GitHub (Nov 3, 2021): Well, it seems it's a weird ALSA bug. Running `aplay -D hw:0,3 --verbose ~/test.wav` gives the same issues, so I don't understand how Kodi can play audio without any hiccups. I tried passing several parameters for buffer/period size/time, but they all seem to get ignored by `aplay`. For reference, here is output from aply with the last suggested configuration: ``` jessica@homecloud:~/source/librespot$ aplay -D hw:0,3 --verbose ~/test.wav Playing WAVE '/home/jessica/test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo Hardware PCM card 0 'HDA Intel HDMI' device 3 subdevice 0 Its setup is: stream : PLAYBACK access : RW_INTERLEAVED format : S16_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 16 buffer_size : 16384 period_size : 4096 period_time : 85333 tstamp_mode : NONE tstamp_type : MONOTONIC period_step : 1 avail_min : 4096 period_event : 0 start_threshold : 16384 stop_threshold : 16384 silence_threshold: 0 silence_size : 0 boundary : 4611686018427387904 appl_ptr : 0 hw_ptr : 0 ``` And without specifying a device explicitly: ``` jessica@homecloud:~/source/librespot$ aplay --verbose ~/test.wav Playing WAVE '/home/jessica/test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo Plug PCM: Linear conversion PCM (S32_LE) Its setup is: stream : PLAYBACK access : RW_INTERLEAVED format : S16_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 16 buffer_size : 8192 period_size : 4096 period_time : 85333 tstamp_mode : NONE tstamp_type : MONOTONIC period_step : 1 avail_min : 4096 period_event : 0 start_threshold : 8192 stop_threshold : 8192 silence_threshold: 0 silence_size : 0 boundary : 4611686018427387904 Slave: Direct Stream Mixing PCM Its setup is: stream : PLAYBACK access : MMAP_INTERLEAVED format : S32_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 32 buffer_size : 8192 period_size : 4096 period_time : 85333 tstamp_mode : NONE tstamp_type : MONOTONIC period_step : 1 avail_min : 4096 period_event : 0 start_threshold : 8192 stop_threshold : 8192 silence_threshold: 0 silence_size : 0 boundary : 4611686018427387904 Hardware PCM card 0 'HDA Intel HDMI' device 3 subdevice 0 Its setup is: stream : PLAYBACK access : MMAP_INTERLEAVED format : S32_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 32 buffer_size : 8192 period_size : 4096 period_time : 85333 tstamp_mode : ENABLE tstamp_type : MONOTONIC period_step : 1 avail_min : 4096 period_event : 0 start_threshold : 1 stop_threshold : 4611686018427387904 silence_threshold: 0 silence_size : 4611686018427387904 boundary : 4611686018427387904 appl_ptr : 0 hw_ptr : 0 ``` So I guess may as well close this? I'm not sure what else I can do, especially when Kodi doesn't have any issues :-/
Author
Owner

@roderickvd commented on GitHub (Nov 4, 2021):

One last thing you could check is version 0.1.6 and 0.2.0. Those versions approached the Alsa buffers slightly different. If either one of those work, then it's worth a discussion whether we should go back to that -- although I'd prefer not to. Anyway before we get there, it'd be nice if you could report back on that.

<!-- gh-comment-id:961377239 --> @roderickvd commented on GitHub (Nov 4, 2021): One last thing you could check is version `0.1.6` and `0.2.0`. Those versions approached the Alsa buffers slightly different. If either one of those work, then it's worth a discussion whether we should go back to that -- although I'd prefer not to. Anyway before we get there, it'd be nice if you could report back on that.
Author
Owner

@JasonLG1979 commented on GitHub (Nov 4, 2021):

One last thing you could check is version 0.1.6 and 0.2.0. Those versions approached the Alsa buffers slightly different. If either one of those work, then it's worth a discussion whether we should go back to that -- although I'd prefer not to. Anyway before we get there, it'd be nice if you could report back on that.

I think it may be a case of the device only accepting a very small set of a combination of buffer size, period size, number of periods parameters as even aplay is having trouble with it. As I've said it may just be a matter of experimenting with different values.

I'll see if I can't have a look at Kodi's source and see what they're doing.

<!-- gh-comment-id:961417810 --> @JasonLG1979 commented on GitHub (Nov 4, 2021): > One last thing you could check is version `0.1.6` and `0.2.0`. Those versions approached the Alsa buffers slightly different. If either one of those work, then it's worth a discussion whether we should go back to that -- although I'd prefer not to. Anyway before we get there, it'd be nice if you could report back on that. I think it may be a case of the device only accepting a very small set of a combination of buffer size, period size, number of periods parameters as even `aplay` is having trouble with it. As I've said it may just be a matter of experimenting with different values. I'll see if I can't have a look at Kodi's source and see what they're doing.
Author
Owner

@JasonLG1979 commented on GitHub (Nov 4, 2021):

Yep, they seem to iterate though buffer and period size combinations.
github.com/xbmc/xbmc@a0d424ec8f/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp (L758-L793)

We can do the same. Basically start at a desired buffer and period size and loop though until we get something that sticks.

<!-- gh-comment-id:961436330 --> @JasonLG1979 commented on GitHub (Nov 4, 2021): Yep, they seem to iterate though buffer and period size combinations. https://github.com/xbmc/xbmc/blob/a0d424ec8f1050b29c2233e57952c20f1c63c993/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp#L758-L793 We can do the same. Basically start at a desired buffer and period size and loop though until we get something that sticks.
Author
Owner

@roderickvd commented on GitHub (Nov 4, 2021):

Good catch. Just some more lines to work around Alsa weirdness! Fondly remember the Alsa mixer rewrite. 🤭

<!-- gh-comment-id:961441506 --> @roderickvd commented on GitHub (Nov 4, 2021): Good catch. Just some more lines to work around Alsa weirdness! Fondly remember the Alsa mixer rewrite. 🤭
Author
Owner

@JasonLG1979 commented on GitHub (Nov 4, 2021):

@roderickvd This monstrosity seems to do the trick:

const MAX_BUFFER: Frames = (SAMPLE_RATE / 2) as Frames;
const MIN_BUFFER: Frames = (SAMPLE_RATE / 10) as Frames;

const MAX_PERIOD_DIVISOR: Frames = 4;
const MIN_PERIOD_DIVISOR: Frames = 10;

...
        // At a sampling rate of 44100:
        // The largest buffer is 22050 Frames (500ms) with 5512 Frame periods (125ms).
        // The smallest buffer is 4410 Frames (100ms) with 441 Frame periods (10ms).
        // Actual values may vary.
        //
        // Larger buffer and period sizes are preferred as extremely small values
        // will cause high CPU useage.
        //
        // If no buffer or period size is in those ranges use the device's default.
        //
        // This ofc depends on devices reporting correct/logical min/max values.
        // If not all bets are off...
        
        let max_size = hwp.get_buffer_size_max().map_err(AlsaError::HwParams)?;
        let min_size = hwp.get_buffer_size_min().map_err(AlsaError::HwParams)?;

        if max_size > 0 && min_size > 0 && max_size > min_size {
            if let Some(buffer_size) = (MIN_BUFFER..=MAX_BUFFER)
                .rev()
                .find(|f| (min_size..=max_size).contains(f))
            {
                if buffer_size > 0 {
                    let actual = hwp
                        .set_buffer_size_near(buffer_size)
                        .map_err(AlsaError::HwParams)?;

                    if actual > 0 {
                        let max_size = hwp.get_period_size_max().map_err(AlsaError::HwParams)?;
                        let min_size = hwp.get_period_size_min().map_err(AlsaError::HwParams)?;

                        if max_size > 0 && min_size > 0 && max_size > min_size {
                            let max_period = actual / MAX_PERIOD_DIVISOR;
                            let min_period = actual / MIN_PERIOD_DIVISOR;

                            if max_period > 0 && min_period > 0 && max_period > min_period {
                                if let Some(period_size) = (min_period..=max_period)
                                    .rev()
                                    .find(|f| (min_size..=max_size).contains(f))
                                {
                                    if period_size > 0 {
                                        hwp.set_period_size_near(period_size, ValueOr::Nearest)
                                            .map_err(AlsaError::HwParams)?;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
<!-- gh-comment-id:961479370 --> @JasonLG1979 commented on GitHub (Nov 4, 2021): @roderickvd This monstrosity seems to do the trick: ```rust const MAX_BUFFER: Frames = (SAMPLE_RATE / 2) as Frames; const MIN_BUFFER: Frames = (SAMPLE_RATE / 10) as Frames; const MAX_PERIOD_DIVISOR: Frames = 4; const MIN_PERIOD_DIVISOR: Frames = 10; ... // At a sampling rate of 44100: // The largest buffer is 22050 Frames (500ms) with 5512 Frame periods (125ms). // The smallest buffer is 4410 Frames (100ms) with 441 Frame periods (10ms). // Actual values may vary. // // Larger buffer and period sizes are preferred as extremely small values // will cause high CPU useage. // // If no buffer or period size is in those ranges use the device's default. // // This ofc depends on devices reporting correct/logical min/max values. // If not all bets are off... let max_size = hwp.get_buffer_size_max().map_err(AlsaError::HwParams)?; let min_size = hwp.get_buffer_size_min().map_err(AlsaError::HwParams)?; if max_size > 0 && min_size > 0 && max_size > min_size { if let Some(buffer_size) = (MIN_BUFFER..=MAX_BUFFER) .rev() .find(|f| (min_size..=max_size).contains(f)) { if buffer_size > 0 { let actual = hwp .set_buffer_size_near(buffer_size) .map_err(AlsaError::HwParams)?; if actual > 0 { let max_size = hwp.get_period_size_max().map_err(AlsaError::HwParams)?; let min_size = hwp.get_period_size_min().map_err(AlsaError::HwParams)?; if max_size > 0 && min_size > 0 && max_size > min_size { let max_period = actual / MAX_PERIOD_DIVISOR; let min_period = actual / MIN_PERIOD_DIVISOR; if max_period > 0 && min_period > 0 && max_period > min_period { if let Some(period_size) = (min_period..=max_period) .rev() .find(|f| (min_size..=max_size).contains(f)) { if period_size > 0 { hwp.set_period_size_near(period_size, ValueOr::Nearest) .map_err(AlsaError::HwParams)?; } } } } } } } } ```
Author
Owner

@JasonLG1979 commented on GitHub (Nov 4, 2021):

@jessicah try this branch and see how it works. It kinda sorta emulates what Kodi does.

<!-- gh-comment-id:961485469 --> @JasonLG1979 commented on GitHub (Nov 4, 2021): @jessicah try [this branch](https://github.com/JasonLG1979/librespot/tree/dynamic-alsa-buffer) and see how it works. It kinda sorta emulates what Kodi does.
Author
Owner

@roderickvd commented on GitHub (Nov 5, 2021):

The Kodi code seems to loop back though if that fails and then tries to set the period size 1st and then the buffer size. My though on that is if that's what it takes whoever wrote the damn drivers needs a kick in the butt,lol!!!

Either that or the hardware device (Intel?) is really iffy. What bothers me about Alsa is that it doesn't help you making these hardware idiosyncracies transparent, that you have to solve them yourself in userspace. Just blowing off steam though, it's the best thing we have in terms of bare metal performance... which means you also have to deal with bare metal.

Thanks for that patch. If it checks out with @jessicah we should vet it against various hardware configurations. Who knows, some Alsa drivers may incorrectly report MAX as 0 or other weird stuff we haven't thought of.

<!-- gh-comment-id:961892000 --> @roderickvd commented on GitHub (Nov 5, 2021): > The Kodi code seems to loop back though if that fails and then tries to set the period size 1st and then the buffer size. My though on that is if that's what it takes whoever wrote the damn drivers needs a kick in the butt,lol!!! Either that or the hardware device (Intel?) is really iffy. What bothers me about Alsa is that it doesn't help you making these hardware idiosyncracies transparent, that you have to solve them yourself in userspace. Just blowing off steam though, it's the best thing we have in terms of bare metal performance... which means you also have to deal with bare metal. Thanks for that patch. If it checks out with @jessicah we should vet it against various hardware configurations. Who knows, some Alsa drivers may incorrectly report MAX as 0 or other weird stuff we haven't thought of.
Author
Owner

@JasonLG1979 commented on GitHub (Nov 5, 2021):

Who knows, some Alsa drivers may incorrectly report MAX as 0 or other weird stuff we haven't thought of.

That would be extremely broken and wouldn't work at all as ALSA sits on the bottom of every Linux audio stack be it Jack, PulseAudio or PipeWire or any app or framework that sits on top of those. ALSA is the bottom of the bottom layer unless you're really dealing with real bare metal on like an embedded system like a micro controller or something.

<!-- gh-comment-id:962193697 --> @JasonLG1979 commented on GitHub (Nov 5, 2021): > Who knows, some Alsa drivers may incorrectly report MAX as 0 or other weird stuff we haven't thought of. That would be extremely broken and wouldn't work at all as ALSA sits on the bottom of every Linux audio stack be it Jack, PulseAudio or PipeWire or any app or framework that sits on top of those. ALSA is the bottom of the bottom layer unless you're really dealing with real bare metal on like an embedded system like a micro controller or something.
Author
Owner

@JasonLG1979 commented on GitHub (Nov 8, 2021):

@jessicah Still waiting for you to test out that branch. You're the only one that can tell us if it works on your hardware as it represents an edge case that is impossible for someone without that specific hardware to reproduce. I can confirm that it works for me on everything I own but then again the current code in the master and dev branches work just fine too so that doesn't really say anything besides that my experimental changes don't break anything on my specific hardware.

<!-- gh-comment-id:963462512 --> @JasonLG1979 commented on GitHub (Nov 8, 2021): @jessicah Still waiting for you to test out [that branch](https://github.com/JasonLG1979/librespot/tree/dynamic-alsa-buffer). You're the only one that can tell us if it works on your hardware as it represents an edge case that is impossible for someone without that specific hardware to reproduce. I can confirm that it works for me on everything I own but then again the current code in the master and dev branches work just fine too so that doesn't really say anything besides that my experimental changes don't break anything on my specific hardware.
Author
Owner

@JasonLG1979 commented on GitHub (Dec 4, 2021):

Just going to bump this issue one last time to make sure it didn't fall though the cracks @jessicah?

@roderickvd I'd say this is very similar to https://github.com/librespot-org/librespot/issues/895 in that they both seem to be misbehaving devices, misbehaving in different ways but still misbehaving.

https://github.com/librespot-org/librespot/pull/896 would probably be about as close as we can get to "fixing" this issue also. When I say "fixing" I mean do our best and if that's not good enough use the device's default. Which is basically what Kodi does.

In any event I'd close this after whatever amount of time you decide is appropriate after this comment if @jessicah for whatever reason has not responded to requests to test possible solutions.

<!-- gh-comment-id:986098562 --> @JasonLG1979 commented on GitHub (Dec 4, 2021): Just going to bump this issue one last time to make sure it didn't fall though the cracks @jessicah? @roderickvd I'd say this is very similar to https://github.com/librespot-org/librespot/issues/895 in that they both seem to be misbehaving devices, misbehaving in different ways but still misbehaving. https://github.com/librespot-org/librespot/pull/896 would probably be about as close as we can get to "fixing" this issue also. When I say "fixing" I mean do our best and if that's not good enough use the device's default. Which is basically what Kodi does. In any event I'd close this after whatever amount of time you decide is appropriate after this comment if @jessicah for whatever reason has not responded to requests to test possible solutions.
Author
Owner

@roderickvd commented on GitHub (Jan 12, 2022):

No feedback and probably fixed; closing.

<!-- gh-comment-id:1011325052 --> @roderickvd commented on GitHub (Jan 12, 2022): No feedback and probably fixed; closing.
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#433
No description provided.