From 826619870f4cb043663530c8c6a60e486aa5b2b7 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Wed, 26 Sep 2018 10:37:12 -0700 Subject: [PATCH] examples(webaudio): allow turning the noise off again --- examples/webaudio/index.html | 2 +- examples/webaudio/index.js | 3 +++ examples/webaudio/src/lib.rs | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/webaudio/index.html b/examples/webaudio/index.html index 23a1ed93..4ae95001 100644 --- a/examples/webaudio/index.html +++ b/examples/webaudio/index.html @@ -3,7 +3,7 @@ - + (headphone users, please make sure your volume is not too loud!)
diff --git a/examples/webaudio/index.js b/examples/webaudio/index.js index 98be8c0c..3801959e 100644 --- a/examples/webaudio/index.js +++ b/examples/webaudio/index.js @@ -9,6 +9,9 @@ import('./webaudio').then(rust_module => { fm.set_fm_frequency(0); fm.set_fm_amount(0); fm.set_gain(0.8); + } else { + fm.free(); + fm = null; } }); diff --git a/examples/webaudio/src/lib.rs b/examples/webaudio/src/lib.rs index 73d17c6a..9cbc3836 100644 --- a/examples/webaudio/src/lib.rs +++ b/examples/webaudio/src/lib.rs @@ -36,6 +36,12 @@ pub struct FmOsc { fm_gain_ratio: f32, } +impl Drop for FmOsc { + fn drop(&mut self) { + let _ = self.ctx.close(); + } +} + #[wasm_bindgen] impl FmOsc { #[wasm_bindgen(constructor)]