mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-24 13:42:14 +00:00
Remove nll
feature from webaudio
example
This commit is contained in:
parent
d4297ad2d3
commit
305ecb7910
@ -1,5 +1,3 @@
|
|||||||
#![feature(nll)]
|
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
extern crate web_sys;
|
extern crate web_sys;
|
||||||
|
|
||||||
@ -45,13 +43,20 @@ impl FmOsc {
|
|||||||
// TODO, how to throw from a constructor?
|
// TODO, how to throw from a constructor?
|
||||||
|
|
||||||
let ctx = web_sys::AudioContext::new().unwrap();
|
let ctx = web_sys::AudioContext::new().unwrap();
|
||||||
let base: &BaseAudioContext = ctx.as_ref();
|
let primary;
|
||||||
|
let fm_osc;
|
||||||
|
let gain;
|
||||||
|
let fm_gain;
|
||||||
|
|
||||||
// create our web audio objects
|
{
|
||||||
let primary = base.create_oscillator().unwrap();
|
let base: &BaseAudioContext = ctx.as_ref();
|
||||||
let fm_osc = base.create_oscillator().unwrap();
|
|
||||||
let gain = base.create_gain().unwrap();
|
// create our web audio objects
|
||||||
let fm_gain = base.create_gain().unwrap();
|
primary = base.create_oscillator().unwrap();
|
||||||
|
fm_osc = base.create_oscillator().unwrap();
|
||||||
|
gain = base.create_gain().unwrap();
|
||||||
|
fm_gain = base.create_gain().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
// some initial settings:
|
// some initial settings:
|
||||||
primary.set_type(OscillatorType::Sine);
|
primary.set_type(OscillatorType::Sine);
|
||||||
@ -63,27 +68,30 @@ impl FmOsc {
|
|||||||
|
|
||||||
|
|
||||||
// Create base class references:
|
// Create base class references:
|
||||||
let primary_node: &AudioNode = primary.as_ref();
|
{
|
||||||
let gain_node: &AudioNode = gain.as_ref();
|
let primary_node: &AudioNode = primary.as_ref();
|
||||||
let fm_osc_node: &AudioNode = fm_osc.as_ref();
|
let gain_node: &AudioNode = gain.as_ref();
|
||||||
let fm_gain_node: &AudioNode = fm_gain.as_ref();
|
let fm_osc_node: &AudioNode = fm_osc.as_ref();
|
||||||
let destination = base.destination();
|
let fm_gain_node: &AudioNode = fm_gain.as_ref();
|
||||||
let destination_node: &AudioNode = destination.as_ref();
|
let base: &BaseAudioContext = ctx.as_ref();
|
||||||
|
let destination = base.destination();
|
||||||
|
let destination_node: &AudioNode = destination.as_ref();
|
||||||
|
|
||||||
|
|
||||||
// connect them up:
|
// connect them up:
|
||||||
|
|
||||||
// The primary oscillator is routed through the gain node, so that it can control the overall output volume
|
// The primary oscillator is routed through the gain node, so that it can control the overall output volume
|
||||||
primary_node.connect_with_destination_and_output_and_input_using_destination(gain.as_ref());
|
primary_node.connect_with_destination_and_output_and_input_using_destination(gain.as_ref());
|
||||||
// Then connect the gain node to the AudioContext destination (aka your speakers)
|
// Then connect the gain node to the AudioContext destination (aka your speakers)
|
||||||
gain_node.connect_with_destination_and_output_and_input_using_destination(destination_node);
|
gain_node.connect_with_destination_and_output_and_input_using_destination(destination_node);
|
||||||
|
|
||||||
// the FM oscillator is connected to its own gain node, so it can control the amount of modulation
|
// the FM oscillator is connected to its own gain node, so it can control the amount of modulation
|
||||||
fm_osc_node.connect_with_destination_and_output_and_input_using_destination(fm_gain.as_ref());
|
fm_osc_node.connect_with_destination_and_output_and_input_using_destination(fm_gain.as_ref());
|
||||||
|
|
||||||
// Connect the FM oscillator to the frequency parameter of the main oscillator, so that the
|
// Connect the FM oscillator to the frequency parameter of the main oscillator, so that the
|
||||||
// FM node can modulate its frequency
|
// FM node can modulate its frequency
|
||||||
fm_gain_node.connect_with_destination_and_output_using_destination(&primary.frequency());
|
fm_gain_node.connect_with_destination_and_output_using_destination(&primary.frequency());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// start the oscillators!
|
// start the oscillators!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user