Skip to content

Commit

Permalink
perf: update and optimize Noise struct
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornoc committed Oct 11, 2020
1 parent adfda3c commit e2540a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ keywords = ["audio", "ambisonics", "3D", "sound", "gamedev"]
[dependencies]
cpal = "0.8"
rodio = "0.9"
rand = "0.6"

rand = {version = "0.7.3", features = ["small_rng"]}
rand_distr = "0.3.0"
11 changes: 5 additions & 6 deletions src/sources/noise.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
use rand::{
distributions::{Distribution, StandardNormal},
thread_rng,
};
use rand::prelude::*;
use rand_distr::StandardNormal;
use rodio::Source;
use std::time::Duration;

/// Infinite white noise
pub struct Noise {
sample_rate: u32,
rng: SmallRng
}

impl Noise {
pub fn new(sample_rate: u32) -> Self {
Noise { sample_rate }
Noise { sample_rate, rng: SmallRng::from_entropy() }
}
}

impl Iterator for Noise {
type Item = f32;

fn next(&mut self) -> Option<f32> {
Some(StandardNormal.sample(&mut thread_rng()) as f32)
Some(StandardNormal.sample(&mut self.rng))
}
}

Expand Down

0 comments on commit e2540a6

Please sign in to comment.