-
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: "Ramp" sound source for testing and debugging
- Loading branch information
anon
committed
Feb 17, 2021
1 parent
07a2be6
commit c7d8c8a
Showing
2 changed files
with
53 additions
and
2 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 |
---|---|---|
@@ -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; |
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,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 | ||
} | ||
} |