35 lines
872 B
TypeScript
35 lines
872 B
TypeScript
import type { AudioProcessor, ProcessorCategory } from './AudioProcessor';
|
|
|
|
export class PanLeftToRight implements AudioProcessor {
|
|
getName(): string {
|
|
return 'Pan L→R';
|
|
}
|
|
|
|
getDescription(): string {
|
|
return 'Gradually pans the sound from left to right';
|
|
}
|
|
|
|
getCategory(): ProcessorCategory {
|
|
return 'Space';
|
|
}
|
|
|
|
process(leftIn: Float32Array, rightIn: Float32Array): [Float32Array, Float32Array] {
|
|
const length = leftIn.length;
|
|
const leftOut = new Float32Array(length);
|
|
const rightOut = new Float32Array(length);
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
const t = i / length;
|
|
const panAngle = t * Math.PI * 0.5;
|
|
const leftGain = Math.cos(panAngle);
|
|
const rightGain = Math.sin(panAngle);
|
|
|
|
const mono = (leftIn[i] + rightIn[i]) * 0.5;
|
|
leftOut[i] = mono * leftGain;
|
|
rightOut[i] = mono * rightGain;
|
|
}
|
|
|
|
return [leftOut, rightOut];
|
|
}
|
|
}
|