mirror of
https://github.com/RustAudio/rodio
synced 2024-11-10 06:04:16 +00:00
add EmptyCallback
source (#430)
Co-authored-by: est31 <est31@users.noreply.github.com>
This commit is contained in:
parent
d5b9ae3467
commit
3d1a5ac54c
2 changed files with 57 additions and 0 deletions
55
src/source/empty_callback.rs
Normal file
55
src/source/empty_callback.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::{Sample, Source};
|
||||
|
||||
/// An empty source which executes a callback function
|
||||
pub struct EmptyCallback<S> {
|
||||
pub phantom_data: PhantomData<S>,
|
||||
pub callback: Box<dyn Send + Fn()>,
|
||||
}
|
||||
|
||||
impl<S> EmptyCallback<S> {
|
||||
#[inline]
|
||||
pub fn new(callback: Box<dyn Send + Fn()>) -> EmptyCallback<S> {
|
||||
EmptyCallback {
|
||||
phantom_data: PhantomData,
|
||||
callback,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Iterator for EmptyCallback<S> {
|
||||
type Item = S;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<S> {
|
||||
(self.callback)();
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for EmptyCallback<S>
|
||||
where
|
||||
S: Sample,
|
||||
{
|
||||
#[inline]
|
||||
fn current_frame_len(&self) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn channels(&self) -> u16 {
|
||||
1
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn sample_rate(&self) -> u32 {
|
||||
48000
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn total_duration(&self) -> Option<Duration> {
|
||||
Some(Duration::new(0, 0))
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ use crate::Sample;
|
|||
pub use self::amplify::Amplify;
|
||||
pub use self::blt::BltFilter;
|
||||
pub use self::buffered::Buffered;
|
||||
pub use self::empty_callback::EmptyCallback;
|
||||
pub use self::channel_volume::ChannelVolume;
|
||||
pub use self::crossfade::Crossfade;
|
||||
pub use self::delay::Delay;
|
||||
|
@ -35,6 +36,7 @@ pub use self::zero::Zero;
|
|||
mod amplify;
|
||||
mod blt;
|
||||
mod buffered;
|
||||
mod empty_callback;
|
||||
mod channel_volume;
|
||||
mod crossfade;
|
||||
mod delay;
|
||||
|
|
Loading…
Reference in a new issue