mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-12 14:18:31 +00:00
Merge pull request #236 from tidalcycles/fix-mono
fx on stereo speakers
This commit is contained in:
commit
ae6da0d6ef
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user