Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
Toggle table of contents sidebar

# Stage1

## Stage1 API Functions

group Stage1 API

  Functions

  void stage1_init(
    stage1_t *state,
    aec_conf_t *de_conf,
    aec_conf_t *non_de_conf,
    adec_config_t *adec_config,
  )

    Initialise Stage1 processing.

    Sets up persistent state for Stage1, initialises ADEC, AEC (in non delay estimation mode) and the delay buffer. Also resets internal counters used to control AEC enable/disable behaviour in alt-arch mode.

    All pointers must be non-NULL. The stage1_t memory must persist for the lifetime of the stage 1 processing.

    Parameters:

      - state – [inout] Stage1 state to initialise.

      - de_conf – [in] AEC runtime configuration used when the delay estimator path is enabled.

      - non_de_conf – [in] AEC runtime configuration running in non delay estimation mode

      - adec_config – [in] ADEC configuration

  void stage1_process_frame(
    stage1_t *state,
    int32_t (*output_frame)[AEC_FRAME_ADVANCE],
    float_s32_t *max_ref_energy,
    float_s32_t *aec_corr_factor,
    int32_t *ref_active_flag,
    int32_t (*input_y)[AEC_FRAME_ADVANCE],
    int32_t (*input_x)[AEC_FRAME_ADVANCE],
  )

    Performs stage1 processing on a frame of input data.

    This function delays the input by the estimated delay, performs AEC processing on the input frame, updates metadata propagated to downstream pipeline stages, runs ADEC and applies ADEC result (e.g. switch AEC config, change applied delay).

    Supports standard or alternating-architecture mode controlled by the compile-time flag ALT_ARCH_MODE.

    Parameters:

      - state – [inout] Persistent Stage1 state.

      - output_frame – [out] Output frame buffer [Y channels][AEC_FRAME_ADVANCE] in Q31 format.

      - max_ref_energy – [out] Maximum reference-channel energy (float_s32_t) for this frame.

      - aec_corr_factor – [out] AEC correction factor (float_s32_t) computed for this frame.

      - ref_active_flag – [out] Set non-zero if reference is detected active this frame.

      - input_y – [in] Microphone (Y) input frame [Y channels][AEC_FRAME_ADVANCE] in Q31 format.

      - input_x – [in] Reference (X) input frame [X channels][AEC_FRAME_ADVANCE] in Q31 format.

## Stage1 defines and data structures

group Stage1 types

  Defines

  ALT_ARCH_MODE

    Enable stage1 alternative arch mode

  HOLD_AEC_LIMIT_SECONDS

    Limit in seconds for which AEC is kept enabled after detecting reference as inactive. Used only in alt arch configuration.

  struct aec_conf_t
    #include <stage1.h>

    AEC runtime configuration structure.

    Public Members

    uint8_t num_x_channels

      < Number of reference (X) input channels at runtime Number of microphone (Y) input channels at runtime

    uint8_t num_main_filt_phases

      Runtime main-filter phase count

    uint8_t num_shadow_filt_phases

      Runtime shadow-filter phase count

    const aec_task_distribution_t *tdist

      Pointer to the work distribution schedule to use (e.g., aec_tdist_chans2_threads1)

  struct stage1_t
    #include <stage1.h>

    Persistent state for stage1 processing.

    It aggregates AEC, ADEC and delay buffer state, AEC runtime configurations for delay and non-delay estimation mode and control flags used in stage1 processing.

    Public Members

    aec_state_t aec_state

      AEC state

    adec_state_t adec_state

      ADEC state

    delay_buf_state_t delay_state

      Delay buffer state

    aec_conf_t aec_de_mode_conf

      AEC config in delay estimation mode

    aec_conf_t aec_non_de_mode_conf

      AEC config in non delay estimation (regular) mode

    int32_t delay_estimator_enabled

      Flag indicating if AEC is running in delay estimation mode

    float_s32_t ref_active_threshold

      Threshold used for detecting activity on the reference audio channel

    int32_t hold_aec_count

      Number of consecutive frames reference has been inactive for. Used only in alt-arch mode

    int32_t hold_aec_limit

      Number of frames the reference must be inactive before AEC is disabled. Used only in alt-arch mode