Skip to content

Commit

Permalink
feat: "Constant" 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 f2089f6 commit 07a2be6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/sources/constant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use rodio::Source;
use std::time::Duration;

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

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

impl Iterator for Constant {
type Item = f32;

fn next(&mut self) -> Option<f32> {
Some(self.value)
}
}

impl Source for Constant {
#[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
}
}
2 changes: 2 additions & 0 deletions src/sources/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Useful implementations of `rodio::Source`

mod noise;
mod constant;

pub use self::noise::Noise;
pub use self::constant::Constant;

0 comments on commit 07a2be6

Please sign in to comment.