[PR #771] [MERGED] Improve sample rounding and clean up noise shaping leftovers #1069

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

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/771
Author: @roderickvd
Created: 5/27/2021
Status: Merged
Merged: 5/29/2021
Merged by: @roderickvd

Base: devHead: round-and-cleanup-dithering


📝 Commits (3)

  • 4f20610 Round half away from zero and clean up noise shaping leftovers
  • b724603 Round ties to even for absolutely lowest error
  • 532ce83 Merge branch 'dev' into round-and-cleanup-dithering

📊 Changes

4 files changed (+89 additions, -24 deletions)

View changed files

📝 Cargo.lock (+74 -11)
📝 playback/Cargo.toml (+1 -0)
📝 playback/src/convert.rs (+10 -9)
📝 playback/src/dither.rs (+4 -4)

📄 Description

Two things:

  1. Remove unused parameter (leftover from scrapped noise shaping)
  2. Round half away from zero instead of truncating to lower quantisation error

I've been fighting with Rust over something as stupid as point 2 but am sure now:

assert_eq!( 0,  0.1_f32.round() as i16);
assert_eq!( 1,  0.5_f32.round() as i16);
assert_eq!( 1,  0.9_f32.round() as i16);
assert_eq!( 0, -0.1_f32.round() as i16);
assert_eq!(-1, -0.5_f32.round() as i16);
assert_eq!(-1, -0.9_f32.round() as i16);

Without round() this would all return 0.


🔄 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/771 **Author:** [@roderickvd](https://github.com/roderickvd) **Created:** 5/27/2021 **Status:** ✅ Merged **Merged:** 5/29/2021 **Merged by:** [@roderickvd](https://github.com/roderickvd) **Base:** `dev` ← **Head:** `round-and-cleanup-dithering` --- ### 📝 Commits (3) - [`4f20610`](https://github.com/librespot-org/librespot/commit/4f20610aaf31846500de3771e9b940ae75e513de) Round half away from zero and clean up noise shaping leftovers - [`b724603`](https://github.com/librespot-org/librespot/commit/b7246030dc3e2fcf049aafe9bf7c3398dfb2ddf6) Round ties to even for absolutely lowest error - [`532ce83`](https://github.com/librespot-org/librespot/commit/532ce832a70f5d90319df7ab637ff55960af4b66) Merge branch 'dev' into round-and-cleanup-dithering ### 📊 Changes **4 files changed** (+89 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+74 -11) 📝 `playback/Cargo.toml` (+1 -0) 📝 `playback/src/convert.rs` (+10 -9) 📝 `playback/src/dither.rs` (+4 -4) </details> ### 📄 Description Two things: 1. Remove unused parameter (leftover from scrapped noise shaping) 2. Round half away from zero instead of truncating to lower quantisation error I've been fighting with Rust over something as stupid as point 2 but am sure now: ```rust assert_eq!( 0, 0.1_f32.round() as i16); assert_eq!( 1, 0.5_f32.round() as i16); assert_eq!( 1, 0.9_f32.round() as i16); assert_eq!( 0, -0.1_f32.round() as i16); assert_eq!(-1, -0.5_f32.round() as i16); assert_eq!(-1, -0.9_f32.round() as i16); ``` Without `round()` this would all return `0`. --- <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:02 +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#1069
No description provided.