mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 21:52:38 +00:00
Add source::Empty and source::Zero
This commit is contained in:
parent
e8bb880c42
commit
668a215d8b
3 changed files with 104 additions and 0 deletions
46
src/source/empty.rs
Normal file
46
src/source/empty.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::time::Duration;
|
||||
use Sample;
|
||||
use Source;
|
||||
|
||||
/// An empty source.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Empty<S>(PhantomData<S>);
|
||||
|
||||
impl<S> Empty<S> {
|
||||
#[inline]
|
||||
pub fn new() -> Empty<S> {
|
||||
Empty(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Iterator for Empty<S> {
|
||||
type Item = S;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<S> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for Empty<S> where S: Sample {
|
||||
#[inline]
|
||||
fn get_current_frame_len(&self) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_channels(&self) -> u16 {
|
||||
1
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_samples_rate(&self) -> u32 {
|
||||
48000
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_total_duration(&self) -> Option<Duration> {
|
||||
Some(Duration::new(0, 0))
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ use Sample;
|
|||
pub use self::amplify::Amplify;
|
||||
pub use self::buffered::Buffered;
|
||||
pub use self::delay::Delay;
|
||||
pub use self::empty::Empty;
|
||||
pub use self::fadein::FadeIn;
|
||||
pub use self::mix::Mix;
|
||||
pub use self::pauseable::Pauseable;
|
||||
|
@ -14,10 +15,12 @@ pub use self::speed::Speed;
|
|||
pub use self::take::TakeDuration;
|
||||
pub use self::uniform::UniformSourceIterator;
|
||||
pub use self::volume_filter::VolumeFilter;
|
||||
pub use self::zero::Zero;
|
||||
|
||||
mod amplify;
|
||||
mod buffered;
|
||||
mod delay;
|
||||
mod empty;
|
||||
mod fadein;
|
||||
mod mix;
|
||||
mod pauseable;
|
||||
|
@ -27,6 +30,7 @@ mod speed;
|
|||
mod take;
|
||||
mod uniform;
|
||||
mod volume_filter;
|
||||
mod zero;
|
||||
|
||||
/// A source of samples.
|
||||
pub trait Source: Iterator
|
||||
|
|
54
src/source/zero.rs
Normal file
54
src/source/zero.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::time::Duration;
|
||||
use Sample;
|
||||
use Source;
|
||||
|
||||
/// An infinite source that produces zero.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Zero<S> {
|
||||
channels: u16,
|
||||
samples_rate: u32,
|
||||
marker: PhantomData<S>,
|
||||
}
|
||||
|
||||
impl<S> Zero<S> {
|
||||
#[inline]
|
||||
pub fn new(channels: u16, samples_rate: u32) -> Zero<S> {
|
||||
Zero {
|
||||
channels: channels,
|
||||
samples_rate: samples_rate,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Iterator for Zero<S> where S: Sample {
|
||||
type Item = S;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<S> {
|
||||
Some(S::zero_value())
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for Zero<S> where S: Sample {
|
||||
#[inline]
|
||||
fn get_current_frame_len(&self) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_channels(&self) -> u16 {
|
||||
self.channels
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_samples_rate(&self) -> u32 {
|
||||
self.samples_rate
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_total_duration(&self) -> Option<Duration> {
|
||||
None
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue