Skip to content

Commit 19c2ab5

Browse files
implemented reverb. All effects now have getters and setters for drygain and wetgain, and the actual nodes have been renamed dryGainNode and wetGainNode
1 parent c39bb24 commit 19c2ab5

5 files changed

Lines changed: 60 additions & 11 deletions

File tree

src/effects/BiquadFilter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class BiquadFilter extends Effect {
6767
this.detune = detune;
6868

6969
this.effectBus.connect(this.filterNode);
70-
this.filterNode.connect(this.wetGain);
70+
this.filterNode.connect(this.wetGainNode);
7171
}
7272
}
7373

src/effects/Effect.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
import Sound from "../Sound"
22

33
export default class Effect {
4+
5+
set dryGain(val) {
6+
this.dryGainNode.gain.value = val;
7+
}
8+
9+
get dryGain() {
10+
return this.dryGainNode.gain.value;
11+
}
12+
13+
set wetGain(val){
14+
this.wetGainNode.gain.value = val;
15+
}
16+
17+
get wetGain(){
18+
return this.wetGainNode.gain.value;
19+
}
20+
421
constructor(){
522

623
// Set up the filter's internal audio graph here. At minimum, all filters need an input node and an output node
@@ -9,16 +26,16 @@ export default class Effect {
926
this.inputNode = Sound.context.createGain(); // The node external sources will connect to
1027
this.effectBus = Sound.context.createGain(); // The node that connects up to the effects chain.
1128
this.outputNode = Sound.context.createGain();// The node that will connect to external destinations
12-
this.dryGain = Sound.context.createGain(); // The amount of dry signal included in the output
13-
this.wetGain = Sound.context.createGain(); // The amount of wet signal included in the output
29+
this.dryGainNode = Sound.context.createGain(); // The amount of dry signal included in the output
30+
this.wetGainNode = Sound.context.createGain(); // The amount of wet signal included in the output
1431

1532
this.inputNode.connect(this.effectBus);
16-
this.inputNode.connect(this.dryGain);
33+
this.inputNode.connect(this.dryGainNode);
1734

18-
this.wetGain.connect(this.outputNode);
19-
this.dryGain.connect(this.outputNode);
35+
this.wetGainNode.connect(this.outputNode);
36+
this.dryGainNode.connect(this.outputNode);
2037

21-
this.dryGain.gain.value = 0;
38+
this.dryGainNode.gain.value = 0;
2239

2340
this._enabled = true;
2441
this.owner = null; // The Sample, Playback or Group that owns this effect - used for checking when adding an effect to prevent being added to multiple locations
@@ -55,7 +72,7 @@ export default class Effect {
5572
}
5673

5774
this.inputNode.disconnect(this.effectBus);
58-
this.inputNode.disconnect(this.dryGain);
75+
this.inputNode.disconnect(this.dryGainNode);
5976
this.inputNode.connect(this.outputNode);
6077
this._enabled = false;
6178
}
@@ -67,7 +84,7 @@ export default class Effect {
6784

6885
this.inputNode.disconnect(this.outputNode);
6986
this.inputNode.connect(this.effectBus);
70-
this.inputNode.connect(this.dryGain);
87+
this.inputNode.connect(this.dryGainNode);
7188
this._enabled = true;
7289
}
7390
}

src/effects/HighPassFilter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class HighPassFilter extends Effect {
2929
this.Q = Q;
3030

3131
this.effectBus.connect(this.filterNode);
32-
this.filterNode.connect(this.wetGain);
32+
this.filterNode.connect(this.wetGainNode);
3333
}
3434

3535

src/effects/LowPassFilter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class LowPassFilter extends Effect {
2929
this.Q = Q;
3030

3131
this.effectBus.connect(this.filterNode);
32-
this.filterNode.connect(this.wetGain);
32+
this.filterNode.connect(this.wetGainNode);
3333
}
3434

3535

src/effects/Reverb.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Sound from "../Sound";
2+
import Effect from "./Effect"
3+
4+
5+
export default class Reverb extends Effect {
6+
7+
constructor(length = 1){
8+
super();
9+
10+
this.reverbNode = Sound.context.createConvolver();
11+
this.reverbNode.buffer = this.generateReverbSignal(length);
12+
13+
this.effectBus.connect(this.reverbNode);
14+
this.reverbNode.connect(this.wetGainNode);
15+
}
16+
17+
generateReverbSignal(length){
18+
let bufferLength = length * createjs.Sound.context.sampleRate;
19+
let numChannels = 1;
20+
let buffer = createjs.Sound.context.createBuffer(numChannels, bufferLength, createjs.Sound.context.sampleRate );
21+
22+
let bufferData = buffer.getChannelData(0);
23+
for(let i = 0; i < bufferData.length; i++){
24+
bufferData[i] = (Math.random() * 2 - 1) * Math.pow((1 - (i/bufferData.length)),3);
25+
}
26+
27+
this.buffer = buffer;
28+
return buffer;
29+
30+
}
31+
32+
}

0 commit comments

Comments
 (0)