XCORE SDK
XCORE Software Development Kit
aec_api.h
1 // Copyright 2022 XMOS LIMITED.
2 // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 #ifndef AEC_API_H
4 #define AEC_API_H
5 
6 #include <stdio.h>
7 #include <string.h>
8 #include "bfp_math.h"
9 #include "xs3_math.h"
10 #include "aec_state.h"
11 
71 void aec_init(
72  aec_state_t *main_state,
73  aec_state_t *shadow_state,
74  aec_shared_state_t *shared_state,
75  uint8_t *main_mem_pool,
76  uint8_t *shadow_mem_pool,
77  unsigned num_y_channels,
78  unsigned num_x_channels,
79  unsigned num_main_filter_phases,
80  unsigned num_shadow_filter_phases);
81 
82 
103  aec_state_t *main_state,
104  aec_state_t *shadow_state,
105  const int32_t (*y_data)[AEC_FRAME_ADVANCE],
106  const int32_t (*x_data)[AEC_FRAME_ADVANCE]);
107 
119  float_s32_t *fd_energy,
120  const bfp_complex_s32_t *input);
121 
138  float_s32_t *ema_energy,
139  const bfp_s32_t *input,
140  unsigned start_offset,
141  unsigned length,
142  const aec_config_params_t *conf);
143 
164  bfp_complex_s32_t *output,
165  bfp_s32_t *input);
166 
184  bfp_s32_t *output,
185  bfp_complex_s32_t *input
186  );
187 
209  aec_state_t *state,
210  unsigned ch,
211  unsigned recalc_bin);
212 
225  aec_state_t *state,
226  unsigned ch);
227 
241  aec_state_t *state,
242  unsigned ch);
243 
257  aec_state_t *state,
258  unsigned ch);
259 
274  aec_state_t *state,
275  int32_t (*output)[AEC_FRAME_ADVANCE],
276  unsigned ch);
277 
293  aec_state_t *state,
294  unsigned ch,
295  unsigned is_shadow);
296 
310  aec_state_t *main_state,
311  aec_state_t *shadow_state);
312 
326  aec_state_t *state,
327  unsigned y_ch,
328  unsigned x_ch);
329 
342  aec_state_t *state,
343  unsigned y_ch);
344 
357  aec_state_t *state);
358 
373  aec_state_t *state,
374  unsigned ch);
375 
389  const int32_t (*input_data)[AEC_FRAME_ADVANCE],
390  int num_channels);
391 
401 void aec_reset_state(aec_state_t *main_state, aec_state_t *shadow_state);
402 
415 uint32_t aec_detect_input_activity(const int32_t (*input_data)[AEC_FRAME_ADVANCE], float_s32_t active_threshold, int32_t num_channels);
416 
417 //TODO pending documentation and examples for L2 APIs
424  bfp_complex_s32_t *Error,
425  bfp_complex_s32_t *Y_hat,
426  const bfp_complex_s32_t *Y,
427  const bfp_complex_s32_t *X_fifo,
428  const bfp_complex_s32_t *H_hat,
429  unsigned num_x_channels,
430  unsigned num_phases,
431  unsigned start_offset,
432  unsigned length,
433  int32_t bypass_enabled);
434 
441  bfp_complex_s32_t *H_hat_ph,
442  const bfp_complex_s32_t *X_fifo_ph,
443  const bfp_complex_s32_t *T_ph
444  );
445 
452  bfp_complex_s32_t *chunks,
453  int32_t *final_exp,
454  uint32_t *final_hr,
455  const uint32_t *mapping,
456  uint32_t array_len,
457  uint32_t desired_index,
458  uint32_t min_headroom);
459 
466  bfp_s32_t *chunks,
467  int32_t *final_exp,
468  uint32_t *final_hr,
469  const uint32_t *mapping,
470  uint32_t array_len,
471  uint32_t desired_index,
472  uint32_t min_headroom);
473 #endif
#define AEC_FRAME_ADVANCE
AEC frame size This is the number of samples of new data that the AEC works on every frame....
Definition: aec_defines.h:53
void aec_calc_output(aec_state_t *state, int32_t(*output)[AEC_FRAME_ADVANCE], unsigned ch)
Calculate AEC filter output signal.
void aec_calc_normalisation_spectrum(aec_state_t *state, unsigned ch, unsigned is_shadow)
Calculate normalisation specturm.
void aec_update_X_fifo_1d(aec_state_t *state)
Update the X FIFO alternate BFP structure.
void aec_calc_T(aec_state_t *state, unsigned y_ch, unsigned x_ch)
Calculate the parameter T
void aec_inverse_fft(bfp_s32_t *output, bfp_complex_s32_t *input)
Calculate inverse Discrete Fourier Transform (DFT) of an input spectrum.
void aec_frame_init(aec_state_t *main_state, aec_state_t *shadow_state, const int32_t(*y_data)[AEC_FRAME_ADVANCE], const int32_t(*x_data)[AEC_FRAME_ADVANCE])
Initialise AEC data structures for processing a new frame.
void aec_reset_state(aec_state_t *main_state, aec_state_t *shadow_state)
Reset parts of aec state structure.
void aec_calc_time_domain_ema_energy(float_s32_t *ema_energy, const bfp_s32_t *input, unsigned start_offset, unsigned length, const aec_config_params_t *conf)
Calculate exponential moving average (EMA) energy of a time domain (TD) vector.
void aec_init(aec_state_t *main_state, aec_state_t *shadow_state, aec_shared_state_t *shared_state, uint8_t *main_mem_pool, uint8_t *shadow_mem_pool, unsigned num_y_channels, unsigned num_x_channels, unsigned num_main_filter_phases, unsigned num_shadow_filter_phases)
Initialise AEC data structures.
void aec_filter_adapt(aec_state_t *state, unsigned y_ch)
Update filter.
void aec_calc_Error_and_Y_hat(aec_state_t *state, unsigned ch)
Calculate error spectrum and estimated mic signal spectrum.
void aec_update_X_fifo_and_calc_sigmaXX(aec_state_t *state, unsigned ch)
Update X FIFO with the current X frame.
void aec_calc_X_fifo_energy(aec_state_t *state, unsigned ch, unsigned recalc_bin)
Calculate total energy of the X FIFO.
void aec_compare_filters_and_calc_mu(aec_state_t *main_state, aec_state_t *shadow_state)
Compare and update filters. Calculate the adaption step size mu.
uint32_t aec_detect_input_activity(const int32_t(*input_data)[AEC_FRAME_ADVANCE], float_s32_t active_threshold, int32_t num_channels)
Detect activity on input channels.
float_s32_t aec_calc_corr_factor(aec_state_t *state, unsigned ch)
Calculate a correlation metric between the microphone input and estimated microphone signal.
void aec_calc_freq_domain_energy(float_s32_t *fd_energy, const bfp_complex_s32_t *input)
Calculate energy in the spectrum.
void aec_calc_coherence(aec_state_t *state, unsigned ch)
Calculate coherence.
float_s32_t aec_calc_max_input_energy(const int32_t(*input_data)[AEC_FRAME_ADVANCE], int num_channels)
Calculate the energy of the input signal.
void aec_forward_fft(bfp_complex_s32_t *output, bfp_s32_t *input)
Calculate Discrete Fourier Transform (DFT) spectrum of an input time domain vector.
void aec_l2_calc_Error_and_Y_hat(bfp_complex_s32_t *Error, bfp_complex_s32_t *Y_hat, const bfp_complex_s32_t *Y, const bfp_complex_s32_t *X_fifo, const bfp_complex_s32_t *H_hat, unsigned num_x_channels, unsigned num_phases, unsigned start_offset, unsigned length, int32_t bypass_enabled)
Calculate Error and Y_hat for a channel over a range of bins.
void aec_l2_adapt_plus_fft_gc(bfp_complex_s32_t *H_hat_ph, const bfp_complex_s32_t *X_fifo_ph, const bfp_complex_s32_t *T_ph)
Adapt one phase of the adaptive filter.
void aec_l2_bfp_s32_unify_exponent(bfp_s32_t *chunks, int32_t *final_exp, uint32_t *final_hr, const uint32_t *mapping, uint32_t array_len, uint32_t desired_index, uint32_t min_headroom)
Unify bfp_s32_t chunks into a single exponent and headroom.
void aec_l2_bfp_complex_s32_unify_exponent(bfp_complex_s32_t *chunks, int32_t *final_exp, uint32_t *final_hr, const uint32_t *mapping, uint32_t array_len, uint32_t desired_index, uint32_t min_headroom)
Unify bfp_complex_s32_t chunks into a single exponent and headroom.
AEC control parameters.
Definition: aec_state.h:128
AEC shared state structure.
Definition: aec_state.h:168
[aec_shared_state_t]
Definition: aec_state.h:259
[bfp_s16_t]
Definition: xs3_math_types.h:340
A block floating-point vector of 32-bit elements.
Definition: xs3_math_types.h:276
A floating-point scalar with a 32-bit mantissa.
Definition: xs3_math_types.h:167