1
0
mirror of https://github.com/fluencelabs/wasm-bindgen synced 2025-07-30 03:21:57 +00:00
Files
.cargo
ci
crates
examples
add
canvas
char
closures
console_log
dom
duck-typed-interfaces
fetch
guide-supported-types-examples
hello_world
import_js
julia_set
paint
performance
raytrace-parallel
request-animation-frame
todomvc
wasm-in-wasm
wasm2js
webaudio
src
Cargo.toml
README.md
index.html
index.js
package.json
webpack.config.js
webgl
without-a-bundler
without-a-bundler-no-modules
.gitignore
README.md
guide
releases
src
tests
.gitattributes
.gitignore
CHANGELOG.md
CONTRIBUTING.md
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md
_package.json
azure-pipelines.yml
build.rs
publish.rs
wasm-bindgen/examples/webaudio/index.js
Andrew Chin 153acdb4fd Fix webaudio example
The rust set_* functions except numbers, not strings.
2019-01-28 23:54:40 -05:00

41 lines
1.0 KiB
JavaScript

import('./pkg/webaudio')
.then(rust_module => {
let fm = null;
const play_button = document.getElementById("play");
play_button.addEventListener("click", event => {
if (fm === null) {
fm = new rust_module.FmOsc();
fm.set_note(50);
fm.set_fm_frequency(0);
fm.set_fm_amount(0);
fm.set_gain(0.8);
} else {
fm.free();
fm = null;
}
});
const primary_slider = document.getElementById("primary_input");
primary_slider.addEventListener("input", event => {
if (fm) {
fm.set_note(parseInt(event.target.value));
}
});
const fm_freq = document.getElementById("fm_freq");
fm_freq.addEventListener("input", event => {
if (fm) {
fm.set_fm_frequency(parseFloat(event.target.value));
}
});
const fm_amount = document.getElementById("fm_amount");
fm_amount.addEventListener("input", event => {
if (fm) {
fm.set_fm_amount(parseFloat(event.target.value));
}
});
})
.catch(console.error);