Skip to content

Commit

Permalink
feat: "Ramp" sound source for testing and debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
anon committed Feb 17, 2021
1 parent 07a2be6 commit c7d8c8a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/sources/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Useful implementations of `rodio::Source`

mod noise;
mod constant;
mod noise;
mod ramp;

pub use self::noise::Noise;
pub use self::constant::Constant;
pub use self::noise::Noise;
pub use self::ramp::Ramp;
49 changes: 49 additions & 0 deletions src/sources/ramp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use rodio::Source;
use std::time::Duration;

/// Constant source
pub struct Ramp {
sample_rate: u32,
value: f32,
}

impl Ramp {
pub fn new(sample_rate: u32) -> Self {
Ramp {
sample_rate,
value: 0.0,
}
}
}

impl Iterator for Ramp {
type Item = f32;

fn next(&mut self) -> Option<f32> {
let x = self.value;
self.value += 1.0 / self.sample_rate as f32;
Some(x)
}
}

impl Source for Ramp {
#[inline(always)]
fn current_frame_len(&self) -> Option<usize> {
None
}

#[inline(always)]
fn channels(&self) -> u16 {
1
}

#[inline(always)]
fn sample_rate(&self) -> u32 {
self.sample_rate
}

#[inline(always)]
fn total_duration(&self) -> Option<Duration> {
None
}
}

0 comments on commit c7d8c8a

Please sign in to comment.