From 576debf2617345daf5255ff30b6ff9ef56c9036c Mon Sep 17 00:00:00 2001 From: Talon Date: Tue, 9 Nov 2021 13:24:45 +0100 Subject: [PATCH] Fix glitch when fading in sounds --- src/framework/resonator/sources/audio-source.js | 4 ++-- src/framework/resonator/sources/streaming-source.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/framework/resonator/sources/audio-source.js b/src/framework/resonator/sources/audio-source.js index fb7a507..fa61c97 100644 --- a/src/framework/resonator/sources/audio-source.js +++ b/src/framework/resonator/sources/audio-source.js @@ -131,18 +131,18 @@ export default class AudioSource { } } fadeOut(time) { + this.gain.gain.setValueAtTime(this.getVolume(), this.context.getContext().currentTime); if (!this.node) { return; } - this.gain.gain.setValueAtTime(this.getVolume(), this.context.getContext().currentTime); this.gain.gain.exponentialRampToValueAtTime(0.0001, this.context.getContext().currentTime + time); setTimeout(() => this.stop(), time * 1000); } fadeIn(time) { + this.gain.gain.setValueAtTime(0.0001, this.context.getContext().currentTime); if (!this.node) { this.play(); } - this.gain.gain.setValueAtTime(0.0001, this.context.getContext().currentTime); this.gain.gain.exponentialRampToValueAtTime(this.volume, this.context.getContext().currentTime + time); } } diff --git a/src/framework/resonator/sources/streaming-source.js b/src/framework/resonator/sources/streaming-source.js index 5f26d46..6d0dc34 100644 --- a/src/framework/resonator/sources/streaming-source.js +++ b/src/framework/resonator/sources/streaming-source.js @@ -82,17 +82,17 @@ export class StreamingSource { this.element.loop = true; } fadeIn(time) { + this.gain.gain.setValueAtTime(0.0001, this.context.getContext().currentTime); if (!this.node) { this.play(); } - this.gain.gain.setValueAtTime(0.0001, this.context.getContext().currentTime); this.gain.gain.exponentialRampToValueAtTime(this.getVolume(), this.context.getContext().currentTime + time); } fadeOut(time) { + this.gain.gain.setValueAtTime(this.getVolume(), this.context.getContext().currentTime); if (!this.node) { return; } - this.gain.gain.setValueAtTime(this.getVolume(), this.context.getContext().currentTime); this.gain.gain.exponentialRampToValueAtTime(0.0001, this.context.getContext().currentTime + time); setTimeout(() => this.stop(), time * 1000); }