Struct waver::Waveform

source ·
pub struct Waveform<BitDepth: Clone> { /* private fields */ }
Expand description

A structure that represent a waveform.

Implementations§

Construct a new empty waveform.

At construction the sampling rate of the waveform must be specified.

Examples
use waver::Waveform;

let wf = Waveform::<i16>::new(44100.0);
Examples found in repository?
src/waveform.rs (line 66)
65
66
67
    pub fn with_wave(sample_rate: f32, wave: Wave) -> Self {
        Self::new(sample_rate).superpose(wave).clone()
    }

Construct a new waveform with a single underlying wave component.

This is identical to using new() and then superpose().

Examples
use waver::{Waveform, Wave};

let wf = Waveform::<i16>::with_wave(44100.0,
    Wave { frequency: 4000.0, ..Default::default() });

Add a wave component.

Examples
use waver::{Waveform, Wave};

let mut wf = Waveform::<i16>::new(44100.0);
wf.superpose(Wave { frequency: 6000.0, amplitude: 0.25, ..Default::default() })
    .superpose(Wave { frequency: 5500.0, amplitude: 0.75, ..Default::default() });
Examples found in repository?
src/waveform.rs (line 66)
65
66
67
    pub fn with_wave(sample_rate: f32, wave: Wave) -> Self {
        Self::new(sample_rate).superpose(wave).clone()
    }

Normalize amplitude weights of all underlying waves.

When superposing waves with a combined amplitude-weights that exceed 100% normally waves would be clipped at the highest quantization level.

In waver, overshoot causes quantization to become numerically unstable which manifests in an iterator stop.

Use this method to normalize all weights to equal shares of the amplitude.

Examples
use waver::{Waveform, Wave};

// Two waves with an amplitude weights of 150%.
let mut wf = Waveform::<i16>::with_wave(44100.0,
    Wave { frequency: 3000.0, amplitude: 1.0, ..Default::default() });
wf.superpose(Wave { frequency: 4000.0, amplitude: 0.5, ..Default::default() }).normalize_amplitudes();

An infinite iterator for the superposition of all underlying waveform components.

The iterator will produce a quantization of the superposition of waveform components at the waveform sampling frequency.

Examples
use std::f32::consts::PI;
use std::vec::Vec;
use waver::{Waveform, Wave};

let mut wf = Waveform::<i16>::new(44100.0);
let res: Vec<i16> = wf.superpose(Wave { frequency: 4000.0, phase: PI / 2.0, ..Default::default() })
    .iter().take(10).collect();

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.