[][src]Struct waver::Waveform

pub struct Waveform<BitDepth: Clone> { /* fields omitted */ }

A structure that represent a waveform.

Methods

impl<BitDepth: Clone> Waveform<BitDepth>[src]

pub fn new(sample_rate: f32) -> Self[src]

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);

pub fn with_wave(sample_rate: f32, wave: Wave) -> Self[src]

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() });

pub fn superpose(&mut self, wave: Wave) -> &mut Self[src]

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() });

pub fn normalize_amplitudes(&mut self) -> &mut Self[src]

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();

Important traits for WaveformIterator<'a, BitDepth>
pub fn iter(&self) -> WaveformIterator<BitDepth>[src]

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

impl<BitDepth: Debug + Clone> Debug for Waveform<BitDepth>[src]

impl<'a, BitDepth: Bounded + NumCast + AsPrimitive<f32>> IntoIterator for &'a Waveform<BitDepth>[src]

type Item = BitDepth

The type of the elements being iterated over.

type IntoIter = WaveformIterator<'a, BitDepth>

Which kind of iterator are we turning this into?

impl<BitDepth: Clone> Clone for Waveform<BitDepth>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<BitDepth> Unpin for Waveform<BitDepth> where
    BitDepth: Unpin

impl<BitDepth> Send for Waveform<BitDepth> where
    BitDepth: Send

impl<BitDepth> Sync for Waveform<BitDepth> where
    BitDepth: Sync

Blanket Implementations

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.