From f8aaf553f83ddcb6f3d0f52c200a62159d700f68 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 25 Oct 2016 22:00:34 -0400 Subject: [PATCH] set volume and change volume --- src/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/index.js b/src/index.js index feb5a4c..cab8c5e 100644 --- a/src/index.js +++ b/src/index.js @@ -207,6 +207,18 @@ AudioEngine.prototype.clearEffects = function () { this.reverb.wet.value = 0; }; +AudioEngine.prototype.setVolume = function (value) { + var vol = this._clamp(value, 0, 100); + vol /= 100; + this.effectsNode.gain.value = vol; +}; + +AudioEngine.prototype.changeVolume = function (value) { + value /= 100; + var newVol = this.effectsNode.gain.value + value; + this.effectsNode.gain.value = this._clamp(newVol, 0, 1); +}; + AudioEngine.prototype._clamp = function (input, min, max) { return Math.min(Math.max(input, min), max); };