Working on processors a tiny bit
This commit is contained in:
34
src/lib/audio/processors/PanLeftToRight.ts
Normal file
34
src/lib/audio/processors/PanLeftToRight.ts
Normal file
@ -0,0 +1,34 @@
|
||||
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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user