[PR #811] [MERGED] Improve Alsa backend buffer slightly #1094

Closed
opened 2026-02-27 20:01:08 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/811
Author: @JasonLG1979
Created: 6/23/2021
Status: Merged
Merged: 7/6/2021
Merged by: @roderickvd

Base: devHead: reuse-buffer-alsa-backend


📝 Commits (10+)

  • 1b4d5eb Reuse the buffer for the life of the alsa sink
  • 365a21b Don't depend on capacity being exact when sizing the buffer.
  • 4f598a1 Refactor Buffer in alsa.rs
  • f5abd48 Merge branch 'librespot-org:dev' into reuse-buffer-alsa-backend
  • 85bccdd Use const in place of magic numbers
  • 921d703 Undo a bunch of things
  • 09cf255 Merge branch 'librespot-org:dev' into reuse-buffer-alsa-backend
  • e1ca981 Remove unnecessary nesting and edit comment
  • e5a5115 Merge branch 'librespot-org:dev' into reuse-buffer-alsa-backend
  • 85fb588 Merge branch 'librespot-org:dev' into reuse-buffer-alsa-backend

📊 Changes

1 file changed (+52 additions, -27 deletions)

View changed files

📝 playback/src/audio_backend/alsa.rs (+52 -27)

📄 Description

Reuse the period buffer.
Vec.shrink_to_fit and Vec.reserve_exact have proven to be reliable well past our needs. (https://gist.github.com/JasonLG1979/69ed65d91c64f39de4435b3720258d02)

There's no reason to not reuse the buffer and avoid unnecessary allocations.

Use a loop expression instead of a while loop to chew though the bytes because it's faster.
(https://gist.github.com/JasonLG1979/3efb5646e4bb42309bdda6d83a3da54e)

Always give the PCM a period's worth of audio even when draining the buffer.
This makes for more consistent stop to start latency (pause to play, manually changing tracks) and helps to prevent jarring, "chopped off" sounding transition when changing tracks manually. Overall resulting in a slightly smoother user experience.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/librespot-org/librespot/pull/811 **Author:** [@JasonLG1979](https://github.com/JasonLG1979) **Created:** 6/23/2021 **Status:** ✅ Merged **Merged:** 7/6/2021 **Merged by:** [@roderickvd](https://github.com/roderickvd) **Base:** `dev` ← **Head:** `reuse-buffer-alsa-backend` --- ### 📝 Commits (10+) - [`1b4d5eb`](https://github.com/librespot-org/librespot/commit/1b4d5eb7cb96a705ee861614c3afce6ba86adae4) Reuse the buffer for the life of the alsa sink - [`365a21b`](https://github.com/librespot-org/librespot/commit/365a21b4da355c7d4bd8149f771b42a2dbf039c9) Don't depend on capacity being exact when sizing the buffer. - [`4f598a1`](https://github.com/librespot-org/librespot/commit/4f598a185d0eaf811c5174fb8e5dbe9f1a6ac6da) Refactor Buffer in alsa.rs - [`f5abd48`](https://github.com/librespot-org/librespot/commit/f5abd4874c17e7c8c2acd1f4e41ccaf869c11158) Merge branch 'librespot-org:dev' into reuse-buffer-alsa-backend - [`85bccdd`](https://github.com/librespot-org/librespot/commit/85bccddac8c0f35f3bc855c7c6e85fbe926ca2aa) Use const in place of magic numbers - [`921d703`](https://github.com/librespot-org/librespot/commit/921d7035032e36171a6e51495e58592c3ef18327) Undo a bunch of things - [`09cf255`](https://github.com/librespot-org/librespot/commit/09cf2553939a5c8c22502bbc88b1c82b83f4b7a2) Merge branch 'librespot-org:dev' into reuse-buffer-alsa-backend - [`e1ca981`](https://github.com/librespot-org/librespot/commit/e1ca9816baa5a220d1e74380795ba4c9134d7f59) Remove unnecessary nesting and edit comment - [`e5a5115`](https://github.com/librespot-org/librespot/commit/e5a511512e777f07029d44d200bc9347bbb5fc6a) Merge branch 'librespot-org:dev' into reuse-buffer-alsa-backend - [`85fb588`](https://github.com/librespot-org/librespot/commit/85fb588f743fd2818c9f6bd1f11fe384b71cfd35) Merge branch 'librespot-org:dev' into reuse-buffer-alsa-backend ### 📊 Changes **1 file changed** (+52 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `playback/src/audio_backend/alsa.rs` (+52 -27) </details> ### 📄 Description **Reuse the period buffer.** `Vec.shrink_to_fit` and `Vec.reserve_exact` have proven to be reliable well past our needs. (https://gist.github.com/JasonLG1979/69ed65d91c64f39de4435b3720258d02) There's no reason to not reuse the buffer and avoid unnecessary allocations. **Use a loop expression instead of a while loop to chew though the bytes because it's faster.** (https://gist.github.com/JasonLG1979/3efb5646e4bb42309bdda6d83a3da54e) **Always give the PCM a period's worth of audio even when draining the buffer.** This makes for more consistent stop to start latency (pause to play, manually changing tracks) and helps to prevent jarring, "chopped off" sounding transition when changing tracks manually. Overall resulting in a slightly smoother user experience. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:01:08 +03:00
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#1094
No description provided.