Struct web_audio_api::node::OscillatorNode
source · pub struct OscillatorNode { /* private fields */ }
Expand description
OscillatorNode
represents an audio source generating a periodic waveform.
It can generate a few common waveforms (i.e. sine, square, sawtooth, triangle),
or can be set to an arbitrary periodic waveform using a PeriodicWave
object.
- MDN documentation: https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode
- specification: https://webaudio.github.io/web-audio-api/#OscillatorNode
- see also:
BaseAudioContext::create_oscillator
- see also:
PeriodicWave
Usage
use web_audio_api::context::{BaseAudioContext, AudioContext};
use web_audio_api::node::{AudioNode, AudioScheduledSourceNode};
let context = AudioContext::default();
let osc = context.create_oscillator();
osc.frequency().set_value(200.);
osc.connect(&context.destination());
osc.start();
Examples
cargo run --release --example oscillators
cargo run --release --example many_oscillators_with_env
cargo run --release --example amplitude_modulation
Implementations§
source§impl OscillatorNode
impl OscillatorNode
sourcepub fn new<C: BaseAudioContext>(context: &C, options: OscillatorOptions) -> Self
pub fn new<C: BaseAudioContext>(context: &C, options: OscillatorOptions) -> Self
sourcepub fn frequency(&self) -> &AudioParam
pub fn frequency(&self) -> &AudioParam
A-rate AudioParam
that defines the fondamental frequency of the
oscillator, expressed in Hz
The final frequency is calculated as follow: frequency * 2^(detune/1200)
sourcepub fn detune(&self) -> &AudioParam
pub fn detune(&self) -> &AudioParam
A-rate AudioParam
that defines a transposition according to the
frequency, expressed in cents.
see https://en.wikipedia.org/wiki/Cent_(music)
The final frequency is calculated as follow: frequency * 2^(detune/1200)
sourcepub fn type_(&self) -> OscillatorType
pub fn type_(&self) -> OscillatorType
Returns the oscillator type
sourcepub fn set_type(&self, type_: OscillatorType)
pub fn set_type(&self, type_: OscillatorType)
sourcepub fn set_periodic_wave(&self, periodic_wave: PeriodicWave)
pub fn set_periodic_wave(&self, periodic_wave: PeriodicWave)
Sets a PeriodicWave
which describes a waveform to be used by the oscillator.
Calling this sets the oscillator type to custom
, once set to custom
the oscillator cannot be reverted back to a standard waveform.
Trait Implementations§
source§impl AudioNode for OscillatorNode
impl AudioNode for OscillatorNode
source§fn number_of_inputs(&self) -> usize
fn number_of_inputs(&self) -> usize
OscillatorNode
is a source node. A source node is by definition with no input
source§fn number_of_outputs(&self) -> usize
fn number_of_outputs(&self) -> usize
OscillatorNode
is a mono source node.
fn registration(&self) -> &AudioContextRegistration
fn channel_config(&self) -> &ChannelConfig
source§fn context(&self) -> &ConcreteBaseAudioContext
fn context(&self) -> &ConcreteBaseAudioContext
BaseAudioContext
concrete type which owns this
AudioNode.source§fn connect<'a>(&self, dest: &'a dyn AudioNode) -> &'a dyn AudioNode
fn connect<'a>(&self, dest: &'a dyn AudioNode) -> &'a dyn AudioNode
source§fn connect_at<'a>(
&self,
dest: &'a dyn AudioNode,
output: usize,
input: usize
) -> &'a dyn AudioNode
fn connect_at<'a>(
&self,
dest: &'a dyn AudioNode,
output: usize,
input: usize
) -> &'a dyn AudioNode
source§fn disconnect_from<'a>(&self, dest: &'a dyn AudioNode) -> &'a dyn AudioNode
fn disconnect_from<'a>(&self, dest: &'a dyn AudioNode) -> &'a dyn AudioNode
source§fn disconnect(&self)
fn disconnect(&self)
source§fn channel_count_mode(&self) -> ChannelCountMode
fn channel_count_mode(&self) -> ChannelCountMode
source§fn set_channel_count_mode(&self, v: ChannelCountMode)
fn set_channel_count_mode(&self, v: ChannelCountMode)
channel_count_mode
attributesource§fn channel_interpretation(&self) -> ChannelInterpretation
fn channel_interpretation(&self) -> ChannelInterpretation
source§fn set_channel_interpretation(&self, v: ChannelInterpretation)
fn set_channel_interpretation(&self, v: ChannelInterpretation)
channel_interpretation
attributesource§fn channel_count(&self) -> usize
fn channel_count(&self) -> usize
source§fn set_channel_count(&self, v: usize)
fn set_channel_count(&self, v: usize)
channel_count
attribute