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

export class Tremolo implements AudioProcessor {
  getName(): string {
    return 'Tremolo';
  }

  getDescription(): string {
    return 'Applies rhythmic volume modulation';
  }

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

  process(
    leftChannel: Float32Array,
    rightChannel: Float32Array
  ): [Float32Array, Float32Array] {
    const length = leftChannel.length;
    const sampleRate = 44100;

    const lfoFreq = Math.random() * 8 + 2;
    const depth = 1.0;

    const outputLeft = new Float32Array(length);
    const outputRight = new Float32Array(length);

    for (let i = 0; i < length; i++) {
      const t = i / sampleRate;
      const lfo = Math.sin(2 * Math.PI * lfoFreq * t);
      const gain = 0.5 + (depth * 0.5) * lfo;

      outputLeft[i] = leftChannel[i] * gain;
      outputRight[i] = rightChannel[i] * gain;
    }

    return [outputLeft, outputRight];
  }
}
