Files
rsgp/src/lib/audio/processors/StereoWidener.ts

36 lines
934 B
TypeScript

import type { AudioProcessor, ProcessorCategory } from "./AudioProcessor";
export class StereoWidener implements AudioProcessor {
getName(): string {
return "Stereo Widener";
}
getDescription(): string {
return "Expands stereo field using mid-side processing";
}
getCategory(): ProcessorCategory {
return 'Space';
}
async process(
leftChannel: Float32Array,
rightChannel: Float32Array
): Promise<[Float32Array, Float32Array]> {
const widthFactor = 1.5 + Math.random() * 1.5;
const newLeft = new Float32Array(leftChannel.length);
const newRight = new Float32Array(rightChannel.length);
for (let i = 0; i < leftChannel.length; i++) {
const mid = (leftChannel[i] + rightChannel[i]) * 0.5;
const side = (leftChannel[i] - rightChannel[i]) * 0.5 * widthFactor;
newLeft[i] = mid + side;
newRight[i] = mid - side;
}
return [newLeft, newRight];
}
}