assassin-bug/src/framework/resonator/effects/convolver.js

38 lines
1.6 KiB
JavaScript

import BaseEffect from './base-effect';
export default class Convolver extends BaseEffect {
constructor(context, graph, params) {
super(context, graph, params);
this.volume = 0.25;
console.log(`Creating convolver`);
this.effectNode = this.context.getContext().createConvolver();
this.effectNode.normalize = true;
this.effectNode.buffer = this.effectParams.buffer;
}
setBuffer(buffer) {
this.buffer = buffer;
if (this.effectNode) {
this.effectNode.buffer = buffer;
}
}
setVolume(volume) {
this.volume = volume;
if (this.outputGain) {
this.outputGain.gain.setValueAtTime(this.volume, this.context.getContext().currentTime);
}
}
connectInput(node) {
this.channelSplitter = this.context.getContext().createChannelSplitter(2);
this.channelMerger = this.context.getContext().createChannelMerger(2);
this.channelSplitter.connect(this.channelMerger, 0, 0);
this.channelSplitter.connect(this.channelMerger, 1, 0);
this.channelSplitter.connect(this.channelMerger, 0, 1);
this.channelSplitter.connect(this.channelMerger, 1, 1);
this.outputGain = this.context.getContext().createGain();
this.outputGain.gain.setValueAtTime(this.volume, this.context.getContext().currentTime);
node.connect(this.channelSplitter);
this.channelMerger.connect(this.outputGain);
this.outputGain.connect(this.effectNode);
this.inputNode = node;
}
}