pub struct Mixer { /* private fields */ }
Expand description
Manage samples and mix the volume output of each.
// Instantiate a new mixer with a sample rate of 44100
let mut mixer = usfx::Mixer::new(44_100);
// Create a default sample as the sinewave
let sample = usfx::Sample::default();
// Create another sample with a trianglewave
let mut other_sample = usfx::Sample::default();
other_sample.osc_type(usfx::OscillatorType::Triangle);
// Play two oscillators at the same time
mixer.play(sample);
mixer.play(other_sample);
// This buffer should be passed by the audio library.
let mut buffer = [0.0; 44_100];
// Fill the buffer with procedurally generated sound.
mixer.generate(&mut buffer);
Implementations§
source§impl Mixer
impl Mixer
sourcepub fn generate(&mut self, output: &mut [f32])
pub fn generate(&mut self, output: &mut [f32])
Generate a frame for the sample.
The output buffer can be smaller but not bigger than the sample size.
// Instantiate a new mixer
let mut mixer = usfx::Mixer::default();
// Create a default sample as the sinewave
mixer.play(usfx::Sample::default());
// This buffer should be passed by the audio library
let mut buffer = [0.0; 44_100];
// Fill the buffer with procedurally generated sound
mixer.generate(&mut buffer);
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Mixer
impl Send for Mixer
impl !Sync for Mixer
impl Unpin for Mixer
impl UnwindSafe for Mixer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more