Spaces:
Running
Running
File size: 1,403 Bytes
6bcb42f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
class EchoEffect {
static get DELAY_TIME () {
return 0.25;
}
static get TAIL_SECONDS () {
return 0.75;
}
constructor (audioContext, startTime, endTime) {
this.audioContext = audioContext;
this.input = this.audioContext.createGain();
this.output = this.audioContext.createGain();
this.effectInput = this.audioContext.createGain();
this.effectInput.gain.value = 0;
this.effectInput.gain.setValueAtTime(0.75, startTime);
this.effectInput.gain.setValueAtTime(0, endTime);
this.delay = this.audioContext.createDelay(1);
this.delay.delayTime.value = EchoEffect.DELAY_TIME;
this.decay = this.audioContext.createGain();
this.decay.gain.value = 0.3;
this.compressor = this.audioContext.createDynamicsCompressor();
this.compressor.threshold.value = -5;
this.compressor.knee.value = 15;
this.compressor.ratio.value = 12;
this.compressor.attack.value = 0;
this.compressor.release.value = 0.25;
this.input.connect(this.effectInput);
this.effectInput.connect(this.delay);
this.delay.connect(this.compressor);
this.input.connect(this.compressor);
this.delay.connect(this.decay);
this.decay.connect(this.delay);
this.compressor.connect(this.output);
}
}
export default EchoEffect;
|