[−][src]Struct usfx::Sample
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]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,