From e74255cf107e5450f6be6baa1a805191ccdd7fb1 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Mon, 22 Jul 2019 15:07:34 -0400 Subject: [PATCH] Use static getters for echo params --- src/lib/audio/audio-effects.js | 4 ++-- src/lib/audio/effects/echo-effect.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib/audio/audio-effects.js b/src/lib/audio/audio-effects.js index b6b78f5b0..7460055bb 100644 --- a/src/lib/audio/audio-effects.js +++ b/src/lib/audio/audio-effects.js @@ -38,7 +38,7 @@ class AudioEffects { this.playbackRate = 1; switch (name) { case effectTypes.ECHO: - sampleCount = Math.max(sampleCount, Math.floor((this.trimEndSeconds + 0.75) * buffer.sampleRate)); + sampleCount = Math.max(sampleCount, Math.floor((this.trimEndSeconds + EchoEffect.TAIL_SECONDS) * buffer.sampleRate)); break; case effectTypes.FASTER: this.playbackRate = pitchRatio; @@ -115,7 +115,7 @@ class AudioEffects { this.adjustedTrimStartSeconds, this.adjustedTrimEndSeconds)); break; case effectTypes.ECHO: - ({input, output} = new EchoEffect(this.audioContext, 0.25, + ({input, output} = new EchoEffect(this.audioContext, this.adjustedTrimStartSeconds, this.adjustedTrimEndSeconds)); break; case effectTypes.ROBOT: diff --git a/src/lib/audio/effects/echo-effect.js b/src/lib/audio/effects/echo-effect.js index 182722adf..0ef4b93c2 100644 --- a/src/lib/audio/effects/echo-effect.js +++ b/src/lib/audio/effects/echo-effect.js @@ -1,7 +1,12 @@ class EchoEffect { - constructor (audioContext, delayTime, startTime, endTime) { + static get DELAY_TIME () { + return 0.25; + } + static get TAIL_SECONDS () { + return 0.75; + } + constructor (audioContext, startTime, endTime) { this.audioContext = audioContext; - this.delayTime = delayTime; this.input = this.audioContext.createGain(); this.output = this.audioContext.createGain(); @@ -12,7 +17,7 @@ class EchoEffect { this.effectInput.gain.setValueAtTime(0, endTime); this.delay = this.audioContext.createDelay(1); - this.delay.delayTime.value = delayTime; + this.delay.delayTime.value = EchoEffect.DELAY_TIME; this.decay = this.audioContext.createGain(); this.decay.gain.value = 0.3;