pub struct Oscillator { /* private fields */ }Expand description
A phase-continuous oscillator. Changing the waveform or frequency between samples keeps the phase, so note changes do not click.
The phase is a 32.32 fixed-point accumulator and every sample is computed with basic IEEE arithmetic only, so the output is identical on every platform.
Implementations§
Source§impl Oscillator
impl Oscillator
pub fn new(aliasing: Aliasing) -> Self
Sourcepub fn next(
&mut self,
waveform: Waveform,
frequency: f64,
sample_rate: u32,
) -> f64
pub fn next( &mut self, waveform: Waveform, frequency: f64, sample_rate: u32, ) -> f64
Returns the sample at the current phase, in -1..=1 for naive waveforms, then
advances by one frame. frequency is clamped to 0..=sample_rate / 2.
Sourcepub fn next_pulse(&mut self, duty: f64, frequency: f64, sample_rate: u32) -> f64
pub fn next_pulse(&mut self, duty: f64, frequency: f64, sample_rate: u32) -> f64
Like Oscillator::next for a pulse of any duty, clamped to 0.01..=0.99.
The four Duty values give the same samples as Waveform::Pulse.
Trait Implementations§
Source§impl Clone for Oscillator
impl Clone for Oscillator
Source§fn clone(&self) -> Oscillator
fn clone(&self) -> Oscillator
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for Oscillator
impl RefUnwindSafe for Oscillator
impl Send for Oscillator
impl Sync for Oscillator
impl Unpin for Oscillator
impl UnsafeUnpin for Oscillator
impl UnwindSafe for Oscillator
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