Struct VPSOscillator

Source
pub struct VPSOscillator { /* private fields */ }
Expand description

Vector Phase Shaping Oscillator. The parameters d and v control the shape of the sinus wave. This leads to interesting modulation properties of those control values.

 use synfx_dsp::*;

 // Randomize the initial phase to make cancellation on summing less
 // likely:
 let mut osc =
     VPSOscillator::new(rand_01() * 0.25);


 let freq   = 440.0; // Hz
 let israte = 1.0 / 44100.0; // Seconds per Sample
 let d      = 0.5;   // Range: 0.0 to 1.0
 let v      = 0.75;  // Range: 0.0 to 1.0

 let mut block_of_samples = [0.0; 128];
 // in your process function:
 for output_sample in block_of_samples.iter_mut() {
     // It is advised to limit the `v` value, because with certain
     // `d` values the combination creates just a DC offset.
     let v = VPSOscillator::limit_v(d, v);
     *output_sample = osc.next(freq, israte, d, v);
 }

It can be beneficial to apply distortion and oversampling. Especially oversampling can be important for some d and v combinations, even without distortion.

 use synfx_dsp::{VPSOscillator, rand_01, apply_distortion};
 use synfx_dsp::Oversampling;

 let mut osc = VPSOscillator::new(rand_01() * 0.25);
 let mut ovr : Oversampling<4> = Oversampling::new();

 let freq   = 440.0; // Hz
 let israte = 1.0 / 44100.0; // Seconds per Sample
 let d      = 0.5;   // Range: 0.0 to 1.0
 let v      = 0.75;  // Range: 0.0 to 1.0

 let mut block_of_samples = [0.0; 128];
 // in your process function:
 for output_sample in block_of_samples.iter_mut() {
     // It is advised to limit the `v` value, because with certain
     // `d` values the combination creates just a DC offset.
     let v = VPSOscillator::limit_v(d, v);

     let overbuf = ovr.resample_buffer();
     for b in overbuf {
         *b = apply_distortion(osc.next(freq, israte, d, v), 0.9,  1);
     }
     *output_sample = ovr.downsample();
 }

Implementations§

Source§

impl VPSOscillator

Source

pub fn new(init_phase: f32) -> Self

Create a new instance of VPSOscillator.

  • init_phase - The initial phase of the oscillator.
Source

pub fn reset(&mut self)

Reset the phase of the oscillator to the initial phase.

Source

pub fn limit_v(d: f32, v: f32) -> f32

This rather complicated function blends out some combinations of ‘d’ and ‘v’ that just lead to a constant DC offset. Which is not very useful in an audio oscillator context.

Call this before passing v to VPSOscillator::next.

Source

pub fn next(&mut self, freq: f32, israte: f32, d: f32, v: f32) -> f32

Creates the next sample of this oscillator.

  • freq - The frequency in Hz.
  • israte - The inverse sampling rate, or seconds per sample as in eg. 1.0 / 44100.0.
  • d - The phase distortion parameter d which must be in the range 0.0 to 1.0.
  • v - The phase distortion parameter v which must be in the range 0.0 to 1.0.

It is advised to limit the v using the VPSOscillator::limit_v function before calling this function. To prevent DC offsets when modulating the parameters.

Trait Implementations§

Source§

impl Clone for VPSOscillator

Source§

fn clone(&self) -> VPSOscillator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VPSOscillator

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.