// Copyright 2022-2026 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifndef AGC_PROFILES_H
#define AGC_PROFILES_H

#include "xmath/xmath.h"

/**
 * @defgroup agc_profiles   Pre-defined AGC configuration profiles
 */

/**
 * @brief AGC profile tuned for Automatic Speech Recognition (ASR).
 *
 * @ingroup agc_profiles
 */
#define AGC_PROFILE_ASR (agc_config_t){ \
    .adapt = 1, \
    .adapt_on_vnr = 1, \
    .soft_clipping = 1, \
    .gain = f32_to_float_s32(500), \
    .max_gain = f32_to_float_s32(1000), \
    .min_gain = f32_to_float_s32(0.00001), \
    .upper_threshold = f32_to_float_s32(0.9999), \
    .lower_threshold = f32_to_float_s32(0.7000), \
    .gain_inc = f32_to_float_s32(1.197), \
    .gain_dec = f32_to_float_s32(0.87), \
    .lc_enabled = 0, \
    .lc_n_frame_far = 0, \
    .lc_n_frame_near = 0, \
    .lc_corr_threshold = f32_to_float_s32(0), \
    .lc_bg_power_gamma = f32_to_float_s32(0), \
    .lc_gamma_inc = f32_to_float_s32(0), \
    .lc_gamma_dec = f32_to_float_s32(0), \
    .lc_far_delta = f32_to_float_s32(0), \
    .lc_near_delta = f32_to_float_s32(0), \
    .lc_near_delta_far_active = f32_to_float_s32(0), \
    .lc_gain_max = f32_to_float_s32(0), \
    .lc_gain_double_talk = f32_to_float_s32(0), \
    .lc_gain_silence = f32_to_float_s32(0), \
    .lc_gain_min = f32_to_float_s32(0), \
    .vnr_threshold = f32_to_float_s32(0.5),\
    .lc_vnr_low = f32_to_float_s32(0.2),\
    .lc_vnr_low_count_limit = 17, \
    .startup_delay = 0, \
    }

/**
 * @brief AGC profile tuned to apply a fixed gain.
 *
 * @ingroup agc_profiles
 */
#define AGC_PROFILE_FIXED_GAIN (agc_config_t){ \
    .adapt = 0, \
    .adapt_on_vnr = 0, \
    .soft_clipping = 0, \
    .gain = f32_to_float_s32(25), \
    .max_gain = f32_to_float_s32(0), \
    .min_gain = f32_to_float_s32(0), \
    .upper_threshold = f32_to_float_s32(0), \
    .lower_threshold = f32_to_float_s32(0), \
    .gain_inc = f32_to_float_s32(0), \
    .gain_dec = f32_to_float_s32(0), \
    .lc_enabled = 0, \
    .lc_n_frame_far = 0, \
    .lc_n_frame_near = 0, \
    .lc_corr_threshold = f32_to_float_s32(0), \
    .lc_bg_power_gamma = f32_to_float_s32(0), \
    .lc_gamma_inc = f32_to_float_s32(0), \
    .lc_gamma_dec = f32_to_float_s32(0), \
    .lc_far_delta = f32_to_float_s32(0), \
    .lc_near_delta = f32_to_float_s32(0), \
    .lc_near_delta_far_active = f32_to_float_s32(0), \
    .lc_gain_max = f32_to_float_s32(0), \
    .lc_gain_double_talk = f32_to_float_s32(0), \
    .lc_gain_silence = f32_to_float_s32(0), \
    .lc_gain_min = f32_to_float_s32(0), \
    .vnr_threshold = f32_to_float_s32(0.5),\
    .lc_vnr_low = f32_to_float_s32(0.2),\
    .lc_vnr_low_count_limit = 17, \
    .startup_delay = 0, \
    }


/**
 * @brief AGC profile tuned for human to human communications.
 *
 * @ingroup agc_profiles
 */
#define AGC_PROFILE_XCV_COMMS (agc_config_t){ \
    .gain_dec = f32_to_float_s32(0.98804), \
    .max_gain = f32_to_float_s32(1000), \
    .min_gain = f32_to_float_s32(0.00001), \
    .gain_inc = f32_to_float_s32(1.0034), \
    .adapt = 1, \
    .adapt_on_vnr = 1, \
    .soft_clipping = 1, \
    .vnr_threshold = f32_to_float_s32(0.7), \
    .gain = f32_to_float_s32(100), \
    .upper_threshold = f32_to_float_s32(0.5), \
    .lower_threshold = f32_to_float_s32(0.5), \
    .lc_enabled = 1, \
    .lc_n_frame_near = 10, \
    .lc_n_frame_far = 2, \
    .lc_corr_threshold = f32_to_float_s32(0.9), \
    .lc_gamma_inc = f32_to_float_s32(1.005), \
    .lc_gamma_dec = f32_to_float_s32(0.999), \
    .lc_bg_power_gamma = f32_to_float_s32(1.01), \
    .lc_near_delta_far_active = f32_to_float_s32(4000), \
    .lc_near_delta = f32_to_float_s32(20), \
    .lc_far_delta = f32_to_float_s32(10), \
    .lc_gain_max = f32_to_float_s32(1.0f), \
    .lc_gain_double_talk = f32_to_float_s32(0.25), \
    .lc_gain_silence = f32_to_float_s32(0.05), \
    .lc_gain_min = f32_to_float_s32(0.01), \
    .lc_vnr_low = f32_to_float_s32(0.2), \
    .lc_vnr_low_count_limit = 17, \
    .startup_delay = 0, \
    }

#endif
