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

export class ExpFadeOut implements AudioProcessor {
	getName(): string {
		return 'Fade Out (Exp)';
	}

	getDescription(): string {
		return 'Applies an exponential fade from current level to silence';
	}

	getCategory(): ProcessorCategory {
		return 'Amplitude';
	}

	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 gain = Math.exp(-5.0 * t);
			leftOut[i] = leftIn[i] * gain;
			rightOut[i] = rightIn[i] * gain;
		}

		return [leftOut, rightOut];
	}
}
