Struct Waveform

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

A structure that represent a waveform.

Implementations§

Source§

impl<BitDepth: Clone> Waveform<BitDepth>

Source

pub fn new(sample_rate: f32) -> Self

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

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

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

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

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

pub fn normalize_amplitudes(&mut self) -> &mut Self

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

pub fn iter(&self) -> WaveformIterator<'_, BitDepth>

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§

Source§

impl<BitDepth: Clone + Clone> Clone for Waveform<BitDepth>

Source§

fn clone(&self) -> Waveform<BitDepth>

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

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

Performs copy-assignment from source. Read more
Source§

impl<BitDepth: Debug + Clone> Debug for Waveform<BitDepth>

Source§

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

Formats the value using the given formatter. Read more
Source§

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

Source§

type Item = BitDepth

The type of the elements being iterated over.
Source§

type IntoIter = WaveformIterator<'a, BitDepth>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<BitDepth> Freeze for Waveform<BitDepth>

§

impl<BitDepth> RefUnwindSafe for Waveform<BitDepth>
where BitDepth: RefUnwindSafe,

§

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

§

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

§

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

§

impl<BitDepth> UnwindSafe for Waveform<BitDepth>
where BitDepth: UnwindSafe,

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.