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

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

	getDescription(): string {
		return 'Applies a linear 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 gain = 1.0 - i / length;
			leftOut[i] = leftIn[i] * gain;
			rightOut[i] = rightIn[i] * gain;
		}

		return [leftOut, rightOut];
	}
}
