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.

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

Returns an OscillatorNode

Arguments:
  • context - The AudioContext
  • options - The OscillatorOptions

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)

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)

Returns the oscillator type

Set the oscillator type

Arguments
  • type_ - oscillator type (sine, square, triangle, sawtooth)
Panics

if type_ is OscillatorType::Custom

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

OscillatorNode is a source node. A source node is by definition with no input

OscillatorNode is a mono source node.

The BaseAudioContext which owns this AudioNode.

Connect the output of this AudioNode to the input of another node. Read more

Connect a specific output of this AudioNode to a specific input of another node. Read more

Disconnects all outputs of the AudioNode that go to a specific destination AudioNode.

Disconnects all outgoing connections from the AudioNode.

Represents an enumerated value describing the way channels must be matched between the node’s inputs and outputs. Read more

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

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

Play immediately Read more

Schedule playback start at given timestamp Read more

Stop immediately Read more

Schedule playback stop at given timestamp Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.