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 mut 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 fundamental 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(&mut self, type_: OscillatorType)
 
pub fn set_type(&mut self, type_: OscillatorType)
Sourcepub fn set_periodic_wave(&mut self, periodic_wave: PeriodicWave)
 
pub fn set_periodic_wave(&mut 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.
Source§fn registration(&self) -> &AudioContextRegistration
 
fn registration(&self) -> &AudioContextRegistration
BaseAudioContext. Read moreSource§fn channel_config(&self) -> &ChannelConfig
 
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_from_output_to_input<'a>(
    &self,
    dest: &'a dyn AudioNode,
    output: usize,
    input: usize,
) -> &'a dyn AudioNode
 
fn connect_from_output_to_input<'a>( &self, dest: &'a dyn AudioNode, output: usize, input: usize, ) -> &'a dyn AudioNode
Source§fn disconnect(&self)
 
fn disconnect(&self)
Source§fn disconnect_dest(&self, dest: &dyn AudioNode)
 
fn disconnect_dest(&self, dest: &dyn AudioNode)
Source§fn disconnect_output(&self, output: usize)
 
fn disconnect_output(&self, output: usize)
Source§fn disconnect_dest_from_output(&self, dest: &dyn AudioNode, output: usize)
 
fn disconnect_dest_from_output(&self, dest: &dyn AudioNode, output: usize)
Source§fn disconnect_dest_from_output_to_input(
    &self,
    dest: &dyn AudioNode,
    output: usize,
    input: usize,
)
 
fn disconnect_dest_from_output_to_input( &self, dest: &dyn AudioNode, output: usize, input: usize, )
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