Struct usfx::Mixer

source ·
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

source

pub fn new(sample_rate: usize) -> Self

Create a new mixer object.

source

pub fn play(&mut self, sample: Sample)

Play a sample.

source

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§

source§

impl Debug for Mixer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Mixer

source§

fn default() -> Self

The default sample rate is 44100.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.