[PR #694] [MERGED] Implement dithering #1024

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

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/694
Author: @roderickvd
Created: 4/13/2021
Status: Merged
Merged: 5/26/2021
Merged by: @roderickvd

Base: devHead: dithering-and-noise-shaping


📝 Commits (10+)

  • c8ec268 Implement dithering and noise shaping
  • f3553e1 cargo fmt
  • fde697b Fix example
  • 977dbed Correct dithering noise powers
  • 6ea089c Disable noise shaping by default
  • 00b36be Document default ditherer and noise shaper
  • f7ac001 Fix panic when no noise shaper is specified
  • 636d181 Implement fmt::Display for Ditherer and NoiseShaper
  • 2f11bbc Refactor name() into &'static str
  • 34abd0d Merge remote-tracking branch 'upstream/dev' into dithering-and-noise-shaping

📊 Changes

20 files changed (+339 additions, -100 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 Cargo.lock (+19 -2)
📝 playback/Cargo.toml (+4 -0)
📝 playback/src/audio_backend/alsa.rs (+1 -0)
📝 playback/src/audio_backend/gstreamer.rs (+3 -2)
📝 playback/src/audio_backend/jackaudio.rs (+2 -3)
📝 playback/src/audio_backend/mod.rs (+16 -22)
📝 playback/src/audio_backend/pipe.rs (+1 -1)
📝 playback/src/audio_backend/portaudio.rs (+8 -11)
📝 playback/src/audio_backend/pulseaudio.rs (+1 -0)
📝 playback/src/audio_backend/rodio.rs (+3 -5)
📝 playback/src/audio_backend/sdl.rs (+4 -4)
📝 playback/src/audio_backend/subprocess.rs (+1 -0)
📝 playback/src/config.rs (+11 -4)
📝 playback/src/convert.rs (+86 -39)
📝 playback/src/decoder/libvorbis_decoder.rs (+1 -4)
playback/src/dither.rs (+138 -0)
📝 playback/src/lib.rs (+1 -0)
📝 playback/src/player.rs (+6 -1)
📝 src/main.rs (+32 -2)

📄 Description

Dithering lowers digital-to-analog conversion ("requantization") error, linearizing output, lowering distortion and replacing it with a constant, fixed noise level, which is more pleasant to the ear than the distortion.

Guidance:

  • On S24, S24_3 and S24, the default is to use triangular dithering. Depending on personal preference you may use Gaussian dithering instead; it's not as good objectively, but it may be preferred subjectively if you are looking for a more "analog" sound akin to tape hiss.

  • Advanced users who know that they have a DAC without noise shaping have a third option: high-passed dithering, which is like triangular dithering except that it moves dithering noise up in frequency where it is less audible. Note: 99% of DACs are of delta-sigma design with noise shaping, so unless you have a multibit / R2R DAC, or otherwise know what you are doing, this is not for you.

  • Don't dither or shape noise on S32 or F32. On F32 it's not supported anyway (there are no integer conversions and so no rounding errors) and on S32 the noise level is so far down that it is simply inaudible even after volume normalisation and control.

New command line option:

--dither DITHER Specify the dither algorithm to use - [none, gpdf,
                tpdf, tpdf_hp]. Defaults to 'tpdf' for formats S16
                S24, S24_3 and 'none' for other formats.

Notes:

This PR also features some opportunistic improvements. Worthy of mention are:

  1. matching reference Vorbis sample conversion techniques for lower noise
  2. a cleanup of the convert API

🔄 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/694 **Author:** [@roderickvd](https://github.com/roderickvd) **Created:** 4/13/2021 **Status:** ✅ Merged **Merged:** 5/26/2021 **Merged by:** [@roderickvd](https://github.com/roderickvd) **Base:** `dev` ← **Head:** `dithering-and-noise-shaping` --- ### 📝 Commits (10+) - [`c8ec268`](https://github.com/librespot-org/librespot/commit/c8ec26831c76cfe91697f758314d4257b8fe4be8) Implement dithering and noise shaping - [`f3553e1`](https://github.com/librespot-org/librespot/commit/f3553e12c911a18814a7052da93a0054f749c7ce) cargo fmt - [`fde697b`](https://github.com/librespot-org/librespot/commit/fde697b7db4c671095f58cb49aacb269bf52ff1b) Fix example - [`977dbed`](https://github.com/librespot-org/librespot/commit/977dbede1ae46c5ced49f4ed699409aa33e5cfae) Correct dithering noise powers - [`6ea089c`](https://github.com/librespot-org/librespot/commit/6ea089cb3323d46ae2ed80b81c13fc912aa4a49d) Disable noise shaping by default - [`00b36be`](https://github.com/librespot-org/librespot/commit/00b36be390c5f30edda56334b771f2995c8bde0a) Document default ditherer and noise shaper - [`f7ac001`](https://github.com/librespot-org/librespot/commit/f7ac00106c2cad068f67fa15eb6c5ad412db93fa) Fix panic when no noise shaper is specified - [`636d181`](https://github.com/librespot-org/librespot/commit/636d1812fe7e7f04a09386c3cff815312aad9ee9) Implement fmt::Display for Ditherer and NoiseShaper - [`2f11bbc`](https://github.com/librespot-org/librespot/commit/2f11bbc3e57f79c52d299b9e7083600a414d1824) Refactor name() into &'static str - [`34abd0d`](https://github.com/librespot-org/librespot/commit/34abd0dcac9339346e16e9a58905dd5cb21bfe7e) Merge remote-tracking branch 'upstream/dev' into dithering-and-noise-shaping ### 📊 Changes **20 files changed** (+339 additions, -100 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `Cargo.lock` (+19 -2) 📝 `playback/Cargo.toml` (+4 -0) 📝 `playback/src/audio_backend/alsa.rs` (+1 -0) 📝 `playback/src/audio_backend/gstreamer.rs` (+3 -2) 📝 `playback/src/audio_backend/jackaudio.rs` (+2 -3) 📝 `playback/src/audio_backend/mod.rs` (+16 -22) 📝 `playback/src/audio_backend/pipe.rs` (+1 -1) 📝 `playback/src/audio_backend/portaudio.rs` (+8 -11) 📝 `playback/src/audio_backend/pulseaudio.rs` (+1 -0) 📝 `playback/src/audio_backend/rodio.rs` (+3 -5) 📝 `playback/src/audio_backend/sdl.rs` (+4 -4) 📝 `playback/src/audio_backend/subprocess.rs` (+1 -0) 📝 `playback/src/config.rs` (+11 -4) 📝 `playback/src/convert.rs` (+86 -39) 📝 `playback/src/decoder/libvorbis_decoder.rs` (+1 -4) ➕ `playback/src/dither.rs` (+138 -0) 📝 `playback/src/lib.rs` (+1 -0) 📝 `playback/src/player.rs` (+6 -1) 📝 `src/main.rs` (+32 -2) </details> ### 📄 Description Dithering lowers digital-to-analog conversion ("requantization") error, linearizing output, lowering distortion and replacing it with a constant, fixed noise level, which is more pleasant to the ear than the distortion. ### Guidance: * On S24, S24_3 and S24, the default is to use triangular dithering. Depending on personal preference you may use Gaussian dithering instead; it's not as good objectively, but it may be preferred subjectively if you are looking for a more "analog" sound akin to tape hiss. * Advanced users who know that they have a DAC without noise shaping have a third option: high-passed dithering, which is like triangular dithering except that it moves dithering noise up in frequency where it is less audible. Note: 99% of DACs are of delta-sigma design with noise shaping, so unless you have a multibit / R2R DAC, or otherwise know what you are doing, this is not for you. * Don't dither or shape noise on S32 or F32. On F32 it's not supported anyway (there are no integer conversions and so no rounding errors) and on S32 the noise level is so far down that it is simply inaudible even after volume normalisation and control. ### New command line option: ``` --dither DITHER Specify the dither algorithm to use - [none, gpdf, tpdf, tpdf_hp]. Defaults to 'tpdf' for formats S16 S24, S24_3 and 'none' for other formats. ``` ### Notes: This PR also features some opportunistic improvements. Worthy of mention are: 1. matching reference Vorbis sample conversion techniques for lower noise 2. a cleanup of the `convert` API --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:00:51 +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#1024
No description provided.