package com.foxx.androidcast.receiver.av;

/** Ordered PCM filters (decoder → chain → AudioTrack). */
public final class AudioFilterChain {
    private final AudioFilter[] filters;
    private final int intensity;

    public AudioFilterChain(AudioFilter[] filters, int intensity) {
        this.filters = filters != null ? filters : new AudioFilter[0];
        this.intensity = Math.max(0, Math.min(10, intensity));
    }

    public static AudioFilterChain passthrough() {
        return new AudioFilterChain(new AudioFilter[] {new PassthroughAudioFilter()}, 0);
    }

    public void reset(int sampleRate, int channels) {
        for (AudioFilter f : filters) {
            f.reset(sampleRate, channels);
        }
    }

    public void process(byte[] pcm, int bytes, int sampleRate, int channels) {
        if (pcm == null || bytes <= 0) {
            return;
        }
        for (AudioFilter f : filters) {
            f.process(pcm, bytes, sampleRate, channels, intensity);
        }
    }
}
