Struct waver::Wave

source ·
pub struct Wave {
    pub sample_rate: f32,
    pub frequency: f32,
    pub phase: f32,
    pub amplitude: f32,
    pub func: WaveFunc,
}
Expand description

A structure that represent a sinusoidal wave.

The default value for a wave values is 0.0 except for the amplitude weight which is 1.0 (100% of available amplitude).

Fields§

§sample_rate: f32

The sampling rate of this wave.

§frequency: f32

The frequency of this wave.

§phase: f32

The phase of this wave.

§amplitude: f32

The amplitude as a percentage [0.0 - 1.0].

§func: WaveFunc

The trignomic function to express the wave.

Implementations§

An infinite iterator for the Wave structure.

The iterator will produce an infinite number of wave samples at the specified sampling rate and frequency.

Examples
use std::vec::Vec;
use waver::Wave;

let wave = Wave { sample_rate: 10000.0, frequency: 2000.0, ..Default::default() };
let res: Vec<f32> = wave.iter().take(10).collect();
Examples found in repository?
src/waveform.rs (line 135)
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
    pub fn iter(&self) -> WaveformIterator<BitDepth> {
        WaveformIterator {
            _inner: self,
            iters: self.components.iter().map(|c| c.iter()).collect(),
        }
    }
}

impl<'a, BitDepth: Bounded + NumCast + AsPrimitive<f32>> IntoIterator for &'a Waveform<BitDepth> {
    type Item = BitDepth;
    type IntoIter = WaveformIterator<'a, BitDepth>;

    fn into_iter(self) -> Self::IntoIter {
        WaveformIterator {
            _inner: self,
            iters: self.components.iter().map(|c| c.iter()).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
Returns the “default value” for a type. 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
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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
Converts the given value to a String. 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.