import type { AudioProcessor, ProcessorCategory } from './AudioProcessor';

export class PanRightToLeft implements AudioProcessor {
	getName(): string {
		return 'Pan R→L';
	}

	getDescription(): string {
		return 'Gradually pans the sound from right to left';
	}

	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 = (1.0 - 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];
	}
}
