Fixing more bugs

This commit is contained in:
2025-09-30 22:21:53 +02:00
parent d1ff3daae1
commit 79ad69275f
10 changed files with 398 additions and 201 deletions

View File

@ -6,10 +6,10 @@ export class ReverbEffect implements Effect {
private audioContext: AudioContext
private inputNode: GainNode
private outputNode: GainNode
private finalOutputNode: GainNode
private convolverNode: ConvolverNode
private wetNode: GainNode
private dryNode: GainNode
private mixNode: GainNode
private pannerNode: StereoPannerNode
private panLfoNode: OscillatorNode
private panLfoGainNode: GainNode
@ -23,7 +23,7 @@ export class ReverbEffect implements Effect {
this.audioContext = audioContext
this.inputNode = audioContext.createGain()
this.outputNode = audioContext.createGain()
this.finalOutputNode = audioContext.createGain()
this.mixNode = audioContext.createGain()
this.convolverNode = audioContext.createConvolver()
this.wetNode = audioContext.createGain()
this.dryNode = audioContext.createGain()
@ -43,14 +43,26 @@ export class ReverbEffect implements Effect {
this.inputNode.connect(this.dryNode)
this.inputNode.connect(this.convolverNode)
this.convolverNode.connect(this.wetNode)
this.dryNode.connect(this.outputNode)
this.wetNode.connect(this.outputNode)
this.outputNode.connect(this.pannerNode)
this.pannerNode.connect(this.finalOutputNode)
this.dryNode.connect(this.mixNode)
this.wetNode.connect(this.mixNode)
this.mixNode.connect(this.pannerNode)
this.pannerNode.connect(this.outputNode)
this.convolverNode.buffer = this.createDummyBuffer()
this.generateReverb(this.currentDecay, this.currentDamping)
}
private createDummyBuffer(): AudioBuffer {
const buffer = this.audioContext.createBuffer(2, this.audioContext.sampleRate * 0.1, this.audioContext.sampleRate)
for (let i = 0; i < 2; i++) {
const data = buffer.getChannelData(i)
for (let j = 0; j < data.length; j++) {
data[j] = (Math.random() * 2 - 1) * Math.exp(-j / (this.audioContext.sampleRate * 0.05))
}
}
return buffer
}
private generateReverb(decayTime: number, damping: number): void {
const sampleRate = this.audioContext.sampleRate
const numChannels = 2
@ -127,7 +139,7 @@ export class ReverbEffect implements Effect {
}
getOutputNode(): AudioNode {
return this.finalOutputNode
return this.outputNode
}
setBypass(bypass: boolean): void {
@ -194,7 +206,7 @@ export class ReverbEffect implements Effect {
this.panLfoGainNode.disconnect()
this.inputNode.disconnect()
this.outputNode.disconnect()
this.finalOutputNode.disconnect()
this.mixNode.disconnect()
this.convolverNode.disconnect()
this.wetNode.disconnect()
this.dryNode.disconnect()