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§
source§impl Wave
impl Wave
sourcepub fn iter(&self) -> WaveIterator<'_> ⓘ
pub fn iter(&self) -> WaveIterator<'_> ⓘ
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(),
}
}