diff --git a/Cargo.lock b/Cargo.lock index 31018365..82a9d460 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1288,7 +1288,6 @@ dependencies = [ "portaudio-rs", "rand", "rand_distr", - "rand_xoshiro", "rodio", "sdl2", "shell-words", @@ -1899,15 +1898,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "rand_xoshiro" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" -dependencies = [ - "rand_core", -] - [[package]] name = "redox_syscall" version = "0.2.10" diff --git a/playback/Cargo.toml b/playback/Cargo.toml index b3b39559..911800db 100644 --- a/playback/Cargo.toml +++ b/playback/Cargo.toml @@ -47,9 +47,8 @@ lewton = "0.10" ogg = "0.8" # Dithering -rand = "0.8" +rand = { version = "0.8", features = ["small_rng"] } rand_distr = "0.4" -rand_xoshiro = "0.6" [features] alsa-backend = ["alsa"] diff --git a/playback/src/dither.rs b/playback/src/dither.rs index a44acf21..0f667917 100644 --- a/playback/src/dither.rs +++ b/playback/src/dither.rs @@ -1,3 +1,4 @@ +use rand::rngs::SmallRng; use rand::SeedableRng; use rand_distr::{Distribution, Normal, Triangular, Uniform}; use std::fmt; @@ -41,29 +42,12 @@ impl fmt::Display for dyn Ditherer { } } -// `SmallRng` is 33% faster than `ThreadRng`, but we can do even better. -// `SmallRng` defaults to `Xoshiro256PlusPlus` on 64-bit platforms and -// `Xoshiro128PlusPlus` on 32-bit platforms. These are excellent for the -// general case. In our case of just 64-bit floating points, we can make -// some optimizations. Compared to `SmallRng`, these hand-picked generators -// improve performance by another 9% on 64-bit platforms and 2% on 32-bit -// platforms. -// -// For reference, see https://prng.di.unimi.it. Note that we do not use -// `Xoroshiro128Plus` or `Xoshiro128Plus` because they display low linear -// complexity in the lower four bits, which is not what we want: -// linearization is the very point of dithering. -#[cfg(target_pointer_width = "64")] -type Rng = rand_xoshiro::Xoshiro256Plus; -#[cfg(not(target_pointer_width = "64"))] -type Rng = rand_xoshiro::Xoshiro128StarStar; - -fn create_rng() -> Rng { - Rng::from_entropy() +fn create_rng() -> SmallRng { + SmallRng::from_entropy() } pub struct TriangularDitherer { - cached_rng: Rng, + cached_rng: SmallRng, distribution: Triangular, } @@ -90,7 +74,7 @@ impl TriangularDitherer { } pub struct GaussianDitherer { - cached_rng: Rng, + cached_rng: SmallRng, distribution: Normal, } @@ -119,7 +103,7 @@ impl GaussianDitherer { pub struct HighPassDitherer { active_channel: usize, previous_noises: [f64; NUM_CHANNELS], - cached_rng: Rng, + cached_rng: SmallRng, distribution: Uniform, }