diff --git a/packages/webaudio/reverb.mjs b/packages/webaudio/reverb.mjs index 341731e4..e6d31f6a 100644 --- a/packages/webaudio/reverb.mjs +++ b/packages/webaudio/reverb.mjs @@ -1,7 +1,7 @@ if (typeof AudioContext !== 'undefined') { - AudioContext.prototype.impulseResponse = function (duration) { + AudioContext.prototype.impulseResponse = function (duration, channels = 1) { const length = this.sampleRate * duration; - const impulse = this.createBuffer(2, length, this.sampleRate); + const impulse = this.createBuffer(channels, length, this.sampleRate); const IR = impulse.getChannelData(0); for (let i = 0; i < length; i++) IR[i] = (2 * Math.random() - 1) * Math.pow(1 - i / length, duration); return impulse; diff --git a/packages/webaudio/worklets.mjs b/packages/webaudio/worklets.mjs index c5306c45..7bb43f87 100644 --- a/packages/webaudio/worklets.mjs +++ b/packages/webaudio/worklets.mjs @@ -22,8 +22,9 @@ class CoarseProcessor extends AudioWorkletProcessor { this.notStarted = false; output[0][0] = input[0][0]; for (let n = 1; n < blockSize; n++) { - if (n % coarse == 0) output[0][n] = input[0][n]; - else output[0][n] = output[0][n - 1]; + for (let o = 0; o < output.length; o++) { + output[o][n] = n % coarse == 0 ? input[0][n] : output[o][n - 1]; + } } } return this.notStarted || hasInput; @@ -52,11 +53,19 @@ class CrushProcessor extends AudioWorkletProcessor { this.notStarted = false; if (crush.length === 1) { const x = Math.pow(2, crush[0] - 1); - for (let n = 0; n < blockSize; n++) output[0][n] = Math.round(input[0][n] * x) / x; + for (let n = 0; n < blockSize; n++) { + const value = Math.round(input[0][n] * x) / x; + for (let o = 0; o < output.length; o++) { + output[o][n] = value; + } + } } else { for (let n = 0; n < blockSize; n++) { let x = Math.pow(2, crush[n] - 1); - output[0][n] = Math.round(input[0][n] * x) / x; + const value = Math.round(input[0][n] * x) / x; + for (let o = 0; o < output.length; o++) { + output[o][n] = value; + } } } } @@ -86,7 +95,10 @@ class ShapeProcessor extends AudioWorkletProcessor { if (hasInput) { this.notStarted = false; for (let n = 0; n < blockSize; n++) { - output[0][n] = ((1 + shape) * input[0][n]) / (1 + shape * Math.abs(input[0][n])); + const value = ((1 + shape) * input[0][n]) / (1 + shape * Math.abs(input[0][n])); + for (let o = 0; o < output.length; o++) { + output[o][n] = value; + } } } return this.notStarted || hasInput;