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::new(None);
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
sourceimpl 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
sourceimpl AudioNode for OscillatorNode
impl AudioNode for OscillatorNode
sourcefn number_of_inputs(&self) -> u32
fn number_of_inputs(&self) -> u32
OscillatorNode
is a source node. A source node is by definition with no input
sourcefn number_of_outputs(&self) -> u32
fn number_of_outputs(&self) -> u32
OscillatorNode
is a mono source node.
fn registration(&self) -> &AudioContextRegistration
fn channel_config_raw(&self) -> &ChannelConfig
fn id(&self) -> &AudioNodeId
fn channel_config_cloned(&self) -> ChannelConfig
sourcefn context(&self) -> &ConcreteBaseAudioContext
fn context(&self) -> &ConcreteBaseAudioContext
The BaseAudioContext which owns this AudioNode.
sourcefn connect<'a>(&self, dest: &'a dyn AudioNode) -> &'a dyn AudioNode
fn connect<'a>(&self, dest: &'a dyn AudioNode) -> &'a dyn AudioNode
Connect the output of this AudioNode to the input of another node. Read more
sourcefn connect_at<'a>(
&self,
dest: &'a dyn AudioNode,
output: u32,
input: u32
) -> &'a dyn AudioNode
fn connect_at<'a>(
&self,
dest: &'a dyn AudioNode,
output: u32,
input: u32
) -> &'a dyn AudioNode
Connect a specific output of this AudioNode to a specific input of another node. Read more
sourcefn disconnect_from<'a>(&self, dest: &'a dyn AudioNode) -> &'a dyn AudioNode
fn disconnect_from<'a>(&self, dest: &'a dyn AudioNode) -> &'a dyn AudioNode
Disconnects all outputs of the AudioNode that go to a specific destination AudioNode.
sourcefn disconnect(&self)
fn disconnect(&self)
Disconnects all outgoing connections from the AudioNode.
sourcefn channel_count_mode(&self) -> ChannelCountMode
fn channel_count_mode(&self) -> ChannelCountMode
Represents an enumerated value describing the way channels must be matched between the node’s inputs and outputs. Read more
fn set_channel_count_mode(&self, v: ChannelCountMode)
sourcefn channel_interpretation(&self) -> ChannelInterpretation
fn channel_interpretation(&self) -> ChannelInterpretation
Represents an enumerated value describing the meaning of the channels. This interpretation will define how audio up-mixing and down-mixing will happen. Read more
fn set_channel_interpretation(&self, v: ChannelInterpretation)
sourcefn channel_count(&self) -> usize
fn channel_count(&self) -> usize
Represents an integer used to determine how many channels are used when up-mixing and down-mixing connections to any inputs to the node. Read more
fn set_channel_count(&self, v: usize)
Auto Trait Implementations
impl RefUnwindSafe for OscillatorNode
impl Send for OscillatorNode
impl Sync for OscillatorNode
impl Unpin for OscillatorNode
impl UnwindSafe for OscillatorNode
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more