Skip to main content

AudioWorkletNode

Struct AudioWorkletNode 

Source
pub struct AudioWorkletNode { /* private fields */ }

Implementations§

Source§

impl AudioWorkletNode

Source

pub fn parameter(&self, name: &str) -> Option<AudioParamHandle>

Source

pub fn param(&self, name: &str) -> Option<AudioParamHandle>

Examples found in repository?
examples/worklet_instrument.rs (line 136)
90fn build_worklet_patch(
91    context: &mut AudioContext,
92    stop_time: f64,
93) -> Result<AudioWorkletNode, Box<dyn Error>> {
94    let osc = context.create_oscillator();
95    osc.set_type(Waveform::Sawtooth);
96    osc.frequency().set_value(165.0)?;
97    osc.frequency()
98        .linear_ramp_to_value_at_time(220.0, stop_time)?;
99    osc.try_start(0.0)?;
100    osc.try_stop(stop_time)?;
101
102    let mut parameter_data = HashMap::new();
103    parameter_data.insert("depth".to_owned(), 0.65);
104    parameter_data.insert("mix".to_owned(), 0.55);
105    let mut processor_options = HashMap::new();
106    processor_options.insert("rate_hz".to_owned(), "5.5".to_owned());
107    processor_options.insert("drive".to_owned(), "1.35".to_owned());
108    processor_options.insert("stop_after".to_owned(), stop_time.to_string());
109    let worklet = context.try_create_audio_worklet_node(
110        FoldbackTremolo { phase: 0.0 },
111        AudioWorkletNodeOptions {
112            number_of_inputs: 1,
113            number_of_outputs: 1,
114            output_channel_count: Some(vec![2]),
115            parameter_descriptors: vec![
116                AudioWorkletParameterDescriptor {
117                    name: "depth".to_owned(),
118                    default_value: 0.5,
119                    min_value: 0.0,
120                    max_value: 1.0,
121                    automation_rate: AutomationRate::ARate,
122                },
123                AudioWorkletParameterDescriptor {
124                    name: "mix".to_owned(),
125                    default_value: 0.6,
126                    min_value: 0.0,
127                    max_value: 1.0,
128                    automation_rate: AutomationRate::KRate,
129                },
130            ],
131            parameter_data,
132            processor_options,
133        },
134    )?;
135    worklet
136        .param("depth")
137        .expect("depth parameter")
138        .linear_ramp_to_value_at_time(0.15, stop_time)?;
139    worklet
140        .param("mix")
141        .expect("mix parameter")
142        .set_target_at_time(0.85, 1.25, 0.5)?;
143    let output = context.create_gain();
144    output.gain().set_value(0.18)?;
145    context.connect(osc, &worklet)?;
146    context.connect(&worklet, &output)?;
147    context.connect(&output, context.destination())?;
148    Ok(worklet)
149}
Source§

impl AudioWorkletNode

Source

pub fn channel_count(&self) -> usize

Source

pub fn channel_count_mode(&self) -> ChannelCountMode

Source

pub fn channel_interpretation(&self) -> ChannelInterpretation

Source

pub fn try_set_channel_config( &self, channel_count: usize, channel_count_mode: ChannelCountMode, channel_interpretation: ChannelInterpretation, ) -> Result<(), GraphError>

Trait Implementations§

Source§

impl Clone for AudioWorkletNode

Source§

fn clone(&self) -> AudioWorkletNode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AudioWorkletNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AudioNodeHandle for T
where T: AudioNodeHandlePrivate + ?Sized,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.