[][src]Struct usfx::Sample

pub struct Sample { /* fields omitted */ }

Audio sample that procedurally generates it's sound.

Plug this into the Mixer object to play the sound.

// Generate a sine wave at 2khz
let mut sine_wave = usfx::Sample::default();
sine_wave.osc_frequency(2000);
sine_wave.osc_type(usfx::OscillatorType::Sine);

// Add it to the mixer
let mut mixer = usfx::Mixer::default();
mixer.play(sine_wave);

// Plug it into a audio library, see the examples for a cpal & SDL2 implementation
// ...
// Call the generator to get a buffer for the audio library
mixer.generate(&mut buffer);

Methods

impl Sample[src]

pub fn volume(&mut self, volume: f32) -> &mut Self[src]

Set the volume which is a multiplier of the result.

A range from 0.0-1.0 will result in proper behavior, but you can experiment with other values.

pub fn osc_frequency(&mut self, frequency: usize) -> &mut Self[src]

Set the frequency of the oscillator in hertz.

When using the noise oscillator type this will be the seed. A range from 1-20000 is allowed.

pub fn osc_type(&mut self, oscillator: OscillatorType) -> &mut Self[src]

Set the type of the oscillator.

See the OscillatorType enum for supported wave types.

pub fn osc_duty_cycle(&mut self, duty_cycle: DutyCycle) -> &mut Self[src]

Set the length of the pulse, this only applies when you use a square wave.

Changing of the duty cycle mainly results in a different timbre. A range from 0.0-1.0 will have results, other values won't do anything.

pub fn env_attack(&mut self, attack: f32) -> &mut Self[src]

Set the time until the first envelope slope reaches it's maximum height.

A range from 0.0-1.0 will result in proper behavior, but you can experiment with other values.

pub fn env_decay(&mut self, decay: f32) -> &mut Self[src]

Set the time it takes from the maximum height to go into the main plateau.

A range from 0.0-1.0 will result in proper behavior, but you can experiment with other values.

pub fn env_sustain(&mut self, sustain: f32) -> &mut Self[src]

Set the height of the main plateau.

A range from 0.0-1.0 will result in proper behavior, but you can experiment with other values.

pub fn env_release(&mut self, release: f32) -> &mut Self[src]

Set the time it takes to go from the end of the plateau to zero.

A range from 0.0-1.0 will result in proper behavior, but you can experiment with other values.

pub fn dis_crunch(&mut self, crunch: f32) -> &mut Self[src]

Overdrive that adds hard clipping.

A range from 0.0-1.0 will result in proper behavior, but you can experiment with other values.

pub fn dis_drive(&mut self, drive: f32) -> &mut Self[src]

Overdrive with soft clipping.

A range from 0.0-1.0 will result in proper behavior, but you can experiment with other values.

Trait Implementations

impl Clone for Sample[src]

impl Copy for Sample[src]

impl Debug for Sample[src]

impl Default for Sample[src]

fn default() -> Self[src]

The default is a sinewave of 441 hz.

Auto Trait Implementations

impl RefUnwindSafe for Sample

impl Send for Sample

impl Sync for Sample

impl Unpin for Sample

impl UnwindSafe for Sample

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.