pub struct Sample { /* private fields */ }
Expand description
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);
Implementations§
source§impl Sample
impl Sample
sourcepub fn volume(&mut self, volume: f32) -> &mut Self
pub fn volume(&mut self, volume: f32) -> &mut Self
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.
sourcepub fn osc_frequency(&mut self, frequency: usize) -> &mut Self
pub fn osc_frequency(&mut self, frequency: usize) -> &mut Self
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.
sourcepub fn osc_type(&mut self, oscillator: OscillatorType) -> &mut Self
pub fn osc_type(&mut self, oscillator: OscillatorType) -> &mut Self
Set the type of the oscillator.
See the OscillatorType
enum for supported wave types.
sourcepub fn osc_duty_cycle(&mut self, duty_cycle: DutyCycle) -> &mut Self
pub fn osc_duty_cycle(&mut self, duty_cycle: DutyCycle) -> &mut Self
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.
sourcepub fn env_attack(&mut self, attack: f32) -> &mut Self
pub fn env_attack(&mut self, attack: f32) -> &mut Self
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.
sourcepub fn env_decay(&mut self, decay: f32) -> &mut Self
pub fn env_decay(&mut self, decay: f32) -> &mut Self
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.
sourcepub fn env_sustain(&mut self, sustain: f32) -> &mut Self
pub fn env_sustain(&mut self, sustain: f32) -> &mut Self
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.
sourcepub fn env_release(&mut self, release: f32) -> &mut Self
pub fn env_release(&mut self, release: f32) -> &mut Self
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.
sourcepub fn dis_crunch(&mut self, crunch: f32) -> &mut Self
pub fn dis_crunch(&mut self, crunch: f32) -> &mut Self
Overdrive that adds hard clipping.
A range from 0.0-1.0 will result in proper behavior, but you can experiment with other values.