/*
 * audio/apm_processor.h, Send-side audio processing module (AEC/NS/AGC/VAD).

 */
#ifndef VOICECAT_AUDIO_APM_PROCESSOR_H
#define VOICECAT_AUDIO_APM_PROCESSOR_H

#include <cstdint>
#include <memory>

namespace voicecat::audio {

class ApmProcessor {
   public:
    virtual ~ApmProcessor() = default;

    // Feed the most recent playback reference (for AEC). Call before process_capture().
    virtual void process_render(const int16_t* pcm, int samples, int sample_rate) = 0;

    // Process one capture frame in-place (AEC, NS, AGC).
    // Returns true if VAD detects speech (or always true in passthrough mode).
    // Returns false  caller should skip encode/send (silence gate).
    virtual bool process_capture(int16_t* pcm, int samples, int sample_rate) = 0;

    // Update the VAD RMS threshold in-place (used by EnergyVadProcessor; no-op in passthrough).
    // Safe to call from any thread — EnergyVadProcessor stores it atomically.
    virtual void set_threshold(float) {}

    // Factory for the noise-suppression backend 
    static std::unique_ptr<ApmProcessor> create();

    // Factory for the send-side input gate 
    //   rms_threshold: normalized 0.0-1.0 RMS-of-int16-range; default ~0.025.
    //   hang_time_ms:  how long the gate stays open after the last loud frame; default 300 ms
    //                  (matches AudioEngine's kTalkHangoverMs so "talking" and "gate open" agree).
    static std::unique_ptr<ApmProcessor> create_vad(float rms_threshold = 0.025f,
                                                     int64_t hang_time_ms = 300);
};

}  // namespace voicecat::audio

#endif  // VOICECAT_AUDIO_APM_PROCESSOR_H
