Struct web_audio_api::PeriodicWave
source · pub struct PeriodicWave { /* private fields */ }
Expand description
PeriodicWave
represents an arbitrary periodic waveform to be used with an OscillatorNode
.
- MDN documentation: https://developer.mozilla.org/en-US/docs/Web/API/PeriodicWave
- specification: https://webaudio.github.io/web-audio-api/#PeriodicWave
- see also:
BaseAudioContext::create_periodic_wave
- see also:
OscillatorNode
Usage
use web_audio_api::context::{BaseAudioContext, AudioContext};
use web_audio_api::{PeriodicWave, PeriodicWaveOptions};
use web_audio_api::node::{AudioNode, AudioScheduledSourceNode};
let context = AudioContext::default();
// generate a simple waveform with 2 harmonics
let options = PeriodicWaveOptions {
real: Some(vec![0., 0., 0.]),
imag: Some(vec![0., 0.5, 0.5]),
disable_normalization: false,
};
let periodic_wave = PeriodicWave::new(&context, options);
let osc = context.create_oscillator();
osc.set_periodic_wave(periodic_wave);
osc.connect(&context.destination());
osc.start();
Examples
cargo run --release --example oscillators
Implementations§
source§impl PeriodicWave
impl PeriodicWave
sourcepub fn new<C: BaseAudioContext>(
_context: &C,
options: PeriodicWaveOptions
) -> Self
pub fn new<C: BaseAudioContext>(
_context: &C,
options: PeriodicWaveOptions
) -> Self
Returns a PeriodicWave
Arguments
real
- The real parameter represents an array of cosine terms of Fourrier series.imag
- The imag parameter represents an array of sine terms of Fourrier series.constraints
- The constraints parameter specifies the normalization mode of thePeriodicWave
Panics
Will panic if:
real
is defined and its length is less than 2imag
is defined and its length is less than 2real
andimag
are defined and theirs lengths are not equalPeriodicWave
is more than 8192 components
Trait Implementations§
source§impl Clone for PeriodicWave
impl Clone for PeriodicWave
source§fn clone(&self) -> PeriodicWave
fn clone(&self) -> PeriodicWave
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more