-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: "Constant" sound source for testing and debugging
- Loading branch information
anon
committed
Feb 17, 2021
1 parent
f2089f6
commit 07a2be6
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |