Waveform

Struct Waveform 

Source
pub struct Waveform<T: SampleType, P: Precision = f32> { /* private fields */ }
Expand description

Struct representing a waveform, consisting of output numeric type, sampling rate and a vector of PeriodicFunctions.

Implementations§

Source§

impl<T: SampleType, P: Precision> Waveform<T, P>

Source

pub fn new(sample_rate: impl Into<P>) -> Self

Initializes new empty Waveform

§Panics

This method will panic if sample_rate is not a finite, positive, non-zero number.

§Examples
use wavegen::Waveform;

let wf = Waveform::<f32>::new(500.0);

assert!(wf.iter().take(100).all(|y| y == 0.0));
Source

pub fn with_components( sample_rate: impl Into<P>, components: Vec<PeriodicFunction<P>>, ) -> Self

Initializes new Waveform with predefined components

§Panics

This method will panic if sample_rate is not a finite, positive, non-zero number.

§Examples
use wavegen::{Waveform, sine, dc_bias};

let wf = Waveform::<f32>::with_components(100.0, vec![sine!(1.), dc_bias!(-50.)]);
Source

pub fn add_component(&mut self, component: PeriodicFunction<P>)

Ads a new component to existing Waveform.

§Examples
use wavegen::{Waveform, sine, dc_bias};

let mut wf = Waveform::<f32>::new(100.0);
wf.add_component(sine!(10.));
wf.add_component(dc_bias!(5.));

assert_eq!(2, wf.components().len());
Source

pub fn sample_rate(&self) -> &P

Gets sample rate of this Waveform.

§Examples
use wavegen::Waveform;

let wf = Waveform::<f32>::new(42.0);

assert_eq!(42.0, *wf.sample_rate());
Source

pub fn components(&self) -> &Vec<PeriodicFunction<P>>

Returns list of components this Waveform consists of.

§Examples
use wavegen::{Waveform, sine, dc_bias};

let wf = Waveform::<f32>::with_components(42.0, vec![sine!(1.), dc_bias!(5.)]);

assert_eq!(2, wf.components().len());
Source

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

Returns an iterator over this Waveform samples.

§Examples
use wavegen::{Waveform, sine};

let wf = Waveform::<f32>::with_components(42.0, vec![sine!(1.)]);
let samples = wf.iter().take(100).collect::<Vec<_>>();

Trait Implementations§

Source§

impl<'a, T: SampleType, P: Precision> IntoIterator for &'a Waveform<T, P>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = WaveformIterator<'a, T, P>

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<T, P> Freeze for Waveform<T, P>
where P: Freeze,

§

impl<T, P = f32> !RefUnwindSafe for Waveform<T, P>

§

impl<T, P> Send for Waveform<T, P>
where T: Send,

§

impl<T, P> Sync for Waveform<T, P>
where T: Sync,

§

impl<T, P> Unpin for Waveform<T, P>
where P: Unpin, T: Unpin,

§

impl<T, P = f32> !UnwindSafe for Waveform<T, P>

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