File size: 810 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
class FadeEffect {
    constructor (audioContext, fadeIn, startSeconds, endSeconds) {
        this.audioContext = audioContext;

        this.input = this.audioContext.createGain();
        this.output = this.audioContext.createGain();

        this.gain = this.audioContext.createGain();

        this.gain.gain.setValueAtTime(1, 0);

        if (fadeIn) {
            this.gain.gain.setValueAtTime(0, startSeconds);
            this.gain.gain.linearRampToValueAtTime(1, endSeconds);
        } else {
            this.gain.gain.setValueAtTime(1, startSeconds);
            this.gain.gain.linearRampToValueAtTime(0, endSeconds);
        }

        this.gain.gain.setValueAtTime(1, endSeconds);

        this.input.connect(this.gain);
        this.gain.connect(this.output);
    }
}

export default FadeEffect;