Skip to content

Normalizer stereo imaging and performance improvements#1485

Merged
roderickvd merged 3 commits into
librespot-org:devfrom
roderickvd:perf/normalizer-improvements
Aug 14, 2025
Merged

Normalizer stereo imaging and performance improvements#1485
roderickvd merged 3 commits into
librespot-org:devfrom
roderickvd:perf/normalizer-improvements

Conversation

@roderickvd

Copy link
Copy Markdown
Member

Previously, the normalizer integrator and peak were recalculated as if the samples were a mono stream. If actually one channel required limiting and the other not, this could cause nervousness in the stereo imaging.

This PR changes the normalizer to:

  • calculate the integrator and peak for each channel individually
  • then couple the left/right channel by using the limit gain of each interleaved pair of samples
  • be faster by optimizing the hot code path and reducing the number of branches

Again, please test this for me as I don't have a Spotify account anymore. I ported it from pleezer with my permission.
My "go to" track to test limiting is "Blumine" by Mahler on "Masterpieces in Miniature".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

playback/src/player.rs:1611

  • [nitpick] Consider renaming 'normalisation_channel' to something like 'current_channel' (or adding a clarifying comment) to better convey its purpose as a toggling index for stereo channels.
self.normalisation_channel ^= 1;

playback/src/player.rs:1758

  • Review the change in the state match pattern: switching from 'PlayerState::Invalid { .. }' to 'PlayerState::Invalid' may bypass handling of extra data previously matched; ensure that this change correctly covers all intended invalid states.
if matches!(self.state, PlayerState::Invalid) {

@photovoltex

Copy link
Copy Markdown
Member

So I used the state of the branch for a bit (with normalization enabled) and it seems to not have (at least for me) noticeable interference or audio spikes. I will test it for a day more and then we could probably get it merged :D

@photovoltex photovoltex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So, testing wise I would approve these changes. Just two small comments that didn't make quite a lot of sense to me.

Comment thread playback/src/player.rs Outdated
Comment thread playback/src/player.rs Outdated
photovoltex
photovoltex previously approved these changes Apr 28, 2025

@photovoltex photovoltex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah dang it, forgot to approve it sooner. After the conflict is resolved you can merge it :)

@roderickvd

Copy link
Copy Markdown
Member Author

No prob I'll make some minor changes anyway.

roderickvd added a commit that referenced this pull request Aug 14, 2025
- Add pre-computed knee factor to eliminate division in sample loop
- Replace if-else chain with match pattern for cleaner branching
- Use direct references to reduce repeated array indexing
- Maintain existing stereo imaging via channel coupling

Addresses review comments from #1485 and incorporates optimizations
inspired by Rodio's limiter implementation for improved performance
in the stereo case.
- Add pre-computed knee factor to eliminate division in sample loop
- Replace if-else chain with match pattern for cleaner branching
- Use direct references to reduce repeated array indexing
- Maintain existing stereo imaging via channel coupling

Addresses review comments from librespot-org#1485 and incorporates optimizations
inspired by Rodio's limiter implementation for improved performance
in the stereo case.
@roderickvd roderickvd force-pushed the perf/normalizer-improvements branch from 72718e2 to 56611d8 Compare August 14, 2025 09:34
@roderickvd roderickvd merged commit 9456a02 into librespot-org:dev Aug 14, 2025
13 checks passed
@roderickvd roderickvd deleted the perf/normalizer-improvements branch August 14, 2025 10:00
yanyaoer pushed a commit to yanyaoer/librespot that referenced this pull request Aug 19, 2025
…ibrespot-org#1485)

- Add pre-computed knee factor to eliminate division in sample loop
- Replace if-else chain with match pattern for cleaner branching
- Use direct references to reduce repeated array indexing
- Maintain existing stereo imaging via channel coupling

Addresses review comments from librespot-org#1485 and incorporates optimizations
inspired by Rodio's limiter implementation for improved performance
in the stereo case.
paulfariello pushed a commit to paulfariello/librespot that referenced this pull request Sep 23, 2025
…ibrespot-org#1485)

- Add pre-computed knee factor to eliminate division in sample loop
- Replace if-else chain with match pattern for cleaner branching
- Use direct references to reduce repeated array indexing
- Maintain existing stereo imaging via channel coupling

Addresses review comments from librespot-org#1485 and incorporates optimizations
inspired by Rodio's limiter implementation for improved performance
in the stereo case.
CreatorMetaSky pushed a commit to StreamMediaSpace/librespot-zig that referenced this pull request Feb 9, 2026
…ibrespot-org#1485)

- Add pre-computed knee factor to eliminate division in sample loop
- Replace if-else chain with match pattern for cleaner branching
- Use direct references to reduce repeated array indexing
- Maintain existing stereo imaging via channel coupling

Addresses review comments from librespot-org#1485 and incorporates optimizations
inspired by Rodio's limiter implementation for improved performance
in the stereo case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants