This commit is contained in:
huxi
2025-12-03 11:12:34 +08:00
parent c23ae4f24c
commit bc195654bf
8163 changed files with 3799544 additions and 92 deletions
+193
View File
@@ -0,0 +1,193 @@
#ifndef __ICSD_ADT_APP_H_
#define __ICSD_ADT_APP_H_
#include "typedef.h"
#include "icsd_anc_user.h"
// #include "icsd_adt_client_board.h"
#define SPEAK_TO_CHAT_TASK_NAME "speak_to_chat"
/*智能免摘检测到声音和退出通透是否播放提示音*/
#define SPEAK_TO_CHAT_PLAY_TONE_EN 1
/*智能免摘每次检测到声音的测试提示音*/
#define SPEAK_TO_CHAT_TEST_TONE_EN 0
/* 通过蓝牙spp发送风噪信息
* 需要同时打开USER_SUPPORT_PROFILE_SPP和APP_ONLINE_DEBUG*/
#define ICSD_ADT_WIND_INFO_SPP_DEBUG_EN 0
/*串口写卡导出MIC的数据,需要先打开宏AUDIO_PCM_DEBUG*/
#define ICSD_ADT_MIC_DATA_EXPORT_EN 0
enum {
AUDIO_ADT_CLOSE = 0, //关闭关闭
AUDIO_ADT_OPEN, //打开状态
AUDIO_ADT_CHAT, //免摘状态
};
enum {
ANC_WIND_NOISE_LVL0 = 1,
ANC_WIND_NOISE_LVL1,
ANC_WIND_NOISE_LVL2,
ANC_WIND_NOISE_LVL3,
ANC_WIND_NOISE_LVL4,
ANC_WIND_NOISE_LVL5,
};
enum {
WIND_AREA_TAP_DOUBLE_CLICK = 2, //双击
WIND_AREA_TAP_THIRD_CLICK, //三击
WIND_AREA_TAP_MULTIPLE_CLICK, //大于3次多次连击
};
enum {
ADT_MODE_CLOSE = 0,
ADT_SPEAK_TO_CHAT_MODE = BIT(0), //智能免摘
ADT_WIND_NOISE_DET_MODE = BIT(1),//风噪检测
ADT_WIDE_AREA_TAP_MODE = BIT(2), //广域点击
};
enum {
/*任务消息*/
ICSD_ADT_VOICE_STATE = 1,
ICSD_ADT_WIND_LVL,
ICSD_ADT_WAT_RESULT,
ICSD_ADT_TONE_PLAY,
SPEAK_TO_CHAT_TASK_KILL,
ICSD_ANC_MODE_SWITCH,
ICSD_ADT_STATE_SYNC,
ICSD_ADT_EXPORT_DATA_WRITE,
/*对耳信息同步*/
SYNC_ICSD_ADT_VOICE_STATE,
SYNC_ICSD_ADT_WIND_LVL_CMP,
SYNC_ICSD_ADT_WAT_RESULT,
SYNC_ICSD_ADT_WIND_LVL_RESULT,
SYNC_ICSD_ADT_SUSPEND,
SYNC_ICSD_ADT_OPEN,
SYNC_ICSD_ADT_CLOSE,
SYNC_ICSD_ADT_SET_ANC_FADE_GAIN,
};
/*打开智能免摘*/
int audio_speak_to_chat_open();
/*关闭智能免摘*/
int audio_speak_to_chat_close();
void audio_speak_to_chat_demo();
/*设置免摘定时结束的时间,单位ms*/
int audio_speak_to_char_end_time_set(u16 time);
/*设置智能免摘检测的灵敏度*/
int audio_speak_to_chat_sensitivity_set(u8 sensitivity);
/*获取是否需要先开anc再开免摘的状态*/
u8 get_adt_open_in_anc_state();
void audio_anc_mode_switch_in_adt(u8 anc_mode);
/*打开声音检测*/
int audio_acoustic_detector_open();
/*关闭声音检测*/
int audio_acoustic_detector_close();
int audio_speak_to_chat_open_in_anc_done();
void audio_icsd_adt_resume();
void audio_icsd_adt_suspend();
/*char 定时结束后从通透同步恢复anc on /anc off*/
void audio_speak_to_char_suspend(void);
void audio_speak_to_char_sync_suspend(void);
/*获取智能免摘是否打开*/
u8 audio_speak_to_chat_is_running();
/*获取智能免摘状态*/
u8 get_speak_to_chat_state();
/*获取adt的模式*/
u8 get_icsd_adt_mode();
/*同步tws配对时,同步adt的状态*/
void audio_anc_icsd_adt_state_sync(u8 *data);
void audio_icsd_adt_state_sync_done(u8 adt_mode, u8 speak_to_chat_state);
/*检测到讲话状态同步*/
void set_speak_to_chat_voice_state(u8 state);
void audio_speak_to_chat_voice_state_sync(void);
int anc_adt_init();
int audio_icsd_adt_open(u8 adt_mode);
int audio_icsd_adt_sync_open(u8 adt_mode);
/*打开所有模块*/
int audio_icsd_adt_open_all();
int audio_icsd_adt_sync_close(u8 adt_mode, u8 suspend);
int audio_icsd_adt_close(u8 adt_mode, u8 suspend);
int audio_icsd_adt_res_close(u8 adt_mode, u8 suspend);
/*关闭所有模块*/
int audio_icsd_adt_close_all();
u8 audio_icsd_adt_is_running();
/*打开广域点击*/
int audio_wat_click_open();
/*关闭广域点击*/
int audio_wat_click_close();
/*设置是否忽略广域点击
* ingore: 1 忽略点击,0 响应点击
* 忽略点击的时间,单位ms*/
int audio_wide_area_tap_ignore_flag_set(u8 ignore, u16 time);
/*广域点击开关demo*/
void audio_wat_click_demo();
/*广域点击事件处理*/
void audio_wat_area_tap_event_handle(u8 wat_result);
/*打开风噪检测*/
int audio_icsd_wind_detect_open();
/*关闭风噪检测*/
int audio_icsd_wind_detect_close();
/*获取风噪等级*/
u8 get_audio_icsd_wind_lvl();
/*风噪检测开关demo*/
void audio_icsd_wind_detect_demo();
/*风噪检测处理*/
void audio_anc_wind_noise_process(u8 wind_lvl);
/*参数更新接口*/
int audio_acoustic_detector_updata();
void set_icsd_adt_param_updata();
/*获取免摘需要多少个mic*/
u8 get_icsd_adt_mic_num();
extern void set_anc_adt_state(u8 state);
extern void *get_anc_lfb_coeff();
extern void *get_anc_lff_coeff();
extern void *get_anc_ltrans_coeff();
extern void *get_anc_ltrans_fb_coeff();
extern float get_anc_gains_l_fbgain();
extern float get_anc_gains_l_ffgain();
extern float get_anc_gains_l_transgain();
extern float get_anc_gains_lfb_transgain();
extern u8 get_anc_l_fbyorder();
extern u8 get_anc_l_ffyorder();
extern u8 get_anc_l_transyorder();
extern u8 get_anc_lfb_transyorder();
extern u32 get_anc_gains_alogm();
extern u32 get_anc_gains_trans_alogm();
#endif
+457
View File
@@ -0,0 +1,457 @@
#ifndef _SD_ANC_LIB_H
#define _SD_ANC_LIB_H
#include "asm/anc.h"
#include "timer.h"
#include "math.h"
#include "icsd_common.h"
#if 0
#define _anc_printf printf //打开自适应ANC参数调试信息
#else
extern int anc_printf_off(const char *format, ...);
#define _anc_printf anc_printf_off
#endif
#if 0
#define icsd_printf printf
#else
#define icsd_printf(...)
#endif
#define ANC_TRAIN_TIMEOUT_S 5//10//秒
#define TWS_STA_SIBLING_CONNECTED 0x00000002//tws已连接
#define ANC_USER_TRAIN_DMA_LEN 16384
#define TEST_JT_OFF 0
#define ANC_DEBUG_OFF 0
#define ANC_DEBUG_TONEL_SZ_DATA 1
#define ANC_DEBUG_TONER_SZ_DATA 2
#define ANC_DEBUG_PZ_DATA 3
#define ANC_DEBUG_BYPASS_SIGN 4
extern const u8 ICSD_ANC_DEBUG;
#define ANC_FUN_TARGET_SYNC BIT(0)
extern const u16 ICSD_ANC_FUN;
//FF_FB_EN
#define ICSD_DFF_AFB_EN BIT(7)
#define ICSD_AFF_DFB_EN BIT(6)
#define ICSD_FB_TRAIN_OFF BIT(5)
#define ICSD_FB_TRAIN_NEW BIT(4)
//TEST_ANC_COMBINATION
#define TEST_ANC_COMBINATION_OFF 0x00
#define TEST_TFF_TFB_TONE 0x01 // bypassl强制失败
#define TEST_TFF_TFB_BYPASS 0x02 // tonel强制失败
#define TEST_TFF_DFB 0x03 // FB训练强制失败
#define TEST_DFF_TFB 0x04 // PZ强制失败
#define TEST_DFF_DFB 0x05 // tonel,bypassl,PZ强制失败
#define TEST_DFF_DFB_2 0x06 // tonel,PZ强制失败
//TEST_ANC_TRAIN
#define TEST_ANC_TRAIN_OFF 0x01
#define TEST_FF_TRAIN_PASS 0x02 // 强制每次训练都成功
#define TEST_TRAIN_FAIL 0x03 // 强制每次训练都失败
#define TWS_TONE_BYPASS_MODE 1
#define TWS_BYPASS_MODE 2
#define HEADSET_TONE_BYPASS_MODE 3
#define HEADSET_BYPASS_MODE 4
#define HEADSET_TONES_MODE 5
#define TWS_TONE_MODE 6
//user_train_state------------------------
#define ANC_USER_TRAIN_DMA_READY BIT(0)
#define ANC_USER_TRAIN_TOOL_DATA BIT(1)
#define ANC_DAC_MODE_H1_DIFF BIT(2)
#define ANC_USER_TRAIN_DMA_EN BIT(3)
#define ANC_USER_TRAIN_TONEMODE BIT(4)
#define ANC_TRAIN_TONE_PLAY BIT(5)
#define ANC_TRAIN_TONE_END BIT(6)
#define ANC_TRAIN_TONE_FIRST BIT(7)
#define ANC_TRAIN_IIR_READY BIT(8)
#define ANC_MASTER_RX_PZSYNC BIT(9)
#define ANC_FB_IIR_AB_DONE BIT(10)
#define ANC_FF_IIR_AB_DONE BIT(11)
#define ANC_PZOUT_INITED BIT(12)
#define ANC_SZOUT_INITED BIT(13)
#define ANC_USER_TRAIN_RUN BIT(14)
#define ANC_TRAIN_TIMEOUT BIT(15)
#define ANC_TRAIN_DMA_ON BIT(16)
#define ANC_TONE_DAC_ON BIT(17)
#define ANC_TONE_ANC_READY BIT(18)
#define ANC_TONESMODE_BYPASS_OFF BIT(19)
#define ANC_RX_TARGET BIT(20)
#define ANC_TARGET_DONE BIT(21)
//icsd_anc_contral
#define ICSD_ANC_FORCED_EXIT BIT(0)
#define ICSD_ANC_SUSPENDED BIT(1)
#define ICSD_ANC_FADE_GAIN_RESUME BIT(2)
#define ICSD_ANC_TONE_END BIT(3)
#define ICSD_ANC_INITED BIT(4)
#define ICSD_ANC_FORCED_BEFORE_INIT BIT(5)
//anctask cmd
enum {
ANC_CMD_FORCED_EXIT = 0,
ANC_CMD_TONE_MODE_START,
ANC_CMD_TONEL_START,
ANC_CMD_TONER_START,
ANC_CMD_PZL_START,
ANC_CMD_PZR_START,
ANC_CMD_TONE_DACON,
ANC_CMD_TRAIN_AFTER_TONE,
ANC_CMD_TARGET_END,
ANC_CMD_TARGET_HANDLE,
};
//SZPZ->anc_err---------------------------
#define ANC_ERR_LR_BALANCE BIT(0)//左右耳不平衡
#define ANC_ERR_SOUND_PRESSURE BIT(1)//低声压
#define ANC_ERR_SHAKE BIT(2)//抖动
//icsd_anc_function-----------------------
#define ANC_ADAPTIVE_CMP BIT(0)
#define ANC_EARPHONE_CHECK BIT(1)
#define TARLEN 120
#define TARLEN_L 40
#define DRPPNT 10
#define ANC_FBANC_OUT_SEL_L 13
#define ANC_FFANC_OUT_SEL_L 12
struct icsd_anc_tws_packet {
s8 *data;
u16 len;
};
struct icsd_anc_board_param {
u8 iir_mode;
void *anc_db;
void *anc_data_l;
void *anc_data_r;
void *anc_double_data_l;
void *anc_double_data_r;
u8 default_ff_gain;
u8 default_fb_gain;
s8 tool_ffgain_sign;
s8 tool_fbgain_sign;
s8 tool_target_sign;
s8 tfb_sign;
s8 tff_sign;
s8 bfb_sign;
s8 bff_sign;
s8 bypass_sign;
float m_value_l; //80 ~ 200 //135 最深点位置中心值
float sen_l; //12 ~ 22 //18 最深点深度
float in_q_l; //0.4 ~ 1.2 //0.6 最深点降噪宽度
float m_value_r; //80 ~ 200 //135 最深点位置中心值
float sen_r; //12 ~ 22 //18 最深点深度
float in_q_r; //0.4 ~ 1.2 //0.6 最深点降噪宽度
float *mse_tar;
int gold_curve_en;
float gain_a_param;
u8 gain_a_en;
u8 cmp_abs_en;
u8 jt_en;
int idx_begin;
int idx_end;
u8 FB_NFIX;
u16 fb_w2r;
float sen_offset_l;
float sen_offset_r;
u8 gain_min_offset;
u8 gain_max_offset;
u8 ff_target_fix_num_l;
u8 ff_target_fix_num_r;
u8 pz_max_times;
u8 bypass_max_times;
u8 ff_yorder;
u8 fb_yorder;
u8 cmp_yorder;
int cmp_type[8];
float cmp_thd_low;
float cmp_thd_high;
float bypass_volume;
float minvld;
//ctl
u8 mode;
u8 FF_FB_EN;
u8 dma_belong_to;
u32 tone_jiff;
int IIR_NUM;// 4 3
int IIR_NUM_FIX;// 4 8-IIR_NUM
int IIR_COEF; //(IIR_NUM * 3+1)
u8 JT_MODE;
float *anc_szl_out;
float *anc_szr_out;
float sz_priority_thr;
};
extern struct icsd_anc_board_param *ANC_BOARD_PARAM;
struct icsd_anc_backup {
int gains_alogm;
u8 gains_l_ffmic_gain;
u8 gains_l_fbmic_gain;
u8 gains_r_ffmic_gain;
u8 gains_r_fbmic_gain;
float gains_l_ffgain;
float gains_l_fbgain;
float gains_r_ffgain;
float gains_r_fbgain;
double *lff_coeff;
double *lfb_coeff;
double *rff_coeff;
double *rfb_coeff;
u8 lff_yorder;
u8 lfb_yorder;
u8 rff_yorder;
u8 rfb_yorder;
u8 ff_1st_dcc;
u8 fb_1st_dcc;
u8 ff_2nd_dcc;
u8 fb_2nd_dcc;
u8 gains_drc_en;
};
extern volatile struct icsd_anc_backup *CFG_BACKUP;
struct icsd_anc {
audio_anc_t *param;
u16 *anc_fade_gain;
u8 mode;
u8 train_index;
u8 adaptive_run_busy; //自适应训练中
int *gains_alogm;
u8 *gains_l_ffmic_gain;
u8 *gains_l_fbmic_gain;
u8 *gains_r_ffmic_gain;
u8 *gains_r_fbmic_gain;
float *gains_l_ffgain;
float *gains_l_fbgain;
float *gains_l_cmpgain;
float *gains_r_ffgain;
float *gains_r_fbgain;
float *gains_r_cmpgain;
double **lff_coeff;
double **lfb_coeff;
double **lcmp_coeff;
double **rff_coeff;
double **rfb_coeff;
double **rcmp_coeff;
u8 *lff_yorder;
u8 *lfb_yorder;
u8 *lcmp_yorder;
u8 *rff_yorder;
u8 *rfb_yorder;
u8 *rcmp_yorder;
u8 *ff_1st_dcc;
u8 *fb_1st_dcc;
u8 *ff_2nd_dcc;
u8 *fb_2nd_dcc;
u8 *gains_drc_en;
void *src_hdl;
u32 dac_on_jiff;
u32 dac_on_slience;
int tone_delay;
};
extern volatile struct icsd_anc ICSD_ANC;
struct icsd_anc_tool_data {
int h_len;
int yorderb;//int fb_yorder;
int yorderf;//int ff_yorder;
int yorderc;//int cmp_yorder;
float *h_freq;
float *data_out1;//float *hszpz_out_l;
float *data_out2;//float *hpz_out_l;
float *data_out3;//float *htarget_out_l;
float *data_out4;//float *fb_fgq_l;
float *data_out5;//float *ff_fgq_l;
float *data_out6;//float *hszpz_out_r;
float *data_out7;//float *hpz_out_r;
float *data_out8;//float *htarget_out_r;
float *data_out9;//float *fb_fgq_r;,
float *data_out10;//float *ff_fgq_r;
float *data_out11;//float *cmp_fgq_l;
float *data_out12;//float *cmp_fgq_r;
float *data_out13;//float *tool_target_out_l;
float *data_out14;//float *tool_target_out_r;
float *wz_temp;
u8 result;
u8 anc_err;
u8 save_idx;
u8 use_idx;
u8 tws_use_idx;
u8 anc_combination;
u8 cmp_result;
};
extern volatile struct icsd_anc_tool_data *TOOL_DATA;
enum {
TFF_TFB = 0,
TFF_DFB,
DFF_TFB,
DFF_DFB,
};
enum {
ICSD_FULL_INEAR = 0,
ICSD_HALF_INEAR,
ICSD_HEADSET,
};
extern const u8 ICSD_EP_TYPE;
extern int (*anc_printf)(const char *format, ...);
extern int icsd_anc_id;
extern volatile u8 icsd_anc_function;
extern volatile u8 icsd_anc_contral;
extern volatile int user_train_state;
extern u32 train_time;
extern u16 icsd_time_out_hdl;
extern u8 icsd_anc_combination_test;
extern u8 icsd_anc_train_test;
extern const u8 TWS_MODE;
extern const u8 HEADSET_MODE;
extern const u8 NEW_PRE_TREAT;
extern const u8 icsd_dcc[4];
extern const u8 FF_VERSION;
extern const u8 cmp_iir_type[];
extern const u8 ff_iir_type[];
extern const u8 fb_iir_type[];
//LIB调用的算术函数
extern float complex_abs_float(float x, float y);
extern float sin_float(float x);
extern float cos_float(float x);
extern float cos_hq(float x);
extern float sin_hq(float x);
extern float log10_float(float x);
extern float exp_float(float x);
extern float root_float(float x);
extern float anc_pow10(float n);
extern float angle_float(float x, float y);
extern void icsd_anc_save_with_idx(u8 save_idx);
extern void audio_adc_mic_demo_close(void);
extern void icsd_anc_board_config();
//SDK调用的SDANC APP函数
extern void icsd_anc_dma_done();
extern void icsd_anc_end(audio_anc_t *param);
extern void icsd_anc_run();
extern void icsd_anc_setparam();
extern void icsd_anc_timeout_handler();
extern void icsd_anc_init(audio_anc_t *param, u8 mode, u8 seq, int tone_delay, u8 tws_balance_en);
extern u16 sys_timeout_add(void *priv, void (*func)(void *priv), u32 msec);
extern void icsd_anc_tone_play_start();
extern void icsd_anctone_dacon(u32 slience_frames, u16 sample_rate);
extern u8 icsd_anc_train_result_get(struct icsd_anc_tool_data *TOOL_DATA);
//SDANC APP调用的库函数
extern void icsd_anc_cmd_packet(s8 *data, u8 cmd);
extern void icsd_anc_tws_sync_cmd(void *_data, u16 len, bool rx);
extern void icsd_anc_version();
extern void icsd_anc_lib_init();
extern void icsd_anc_htarget_data_send_end();
extern void icsd_anc_mode_init(int tone_delay);
extern void icsd_anc_train_after_tone();
extern void icsd_anc_m2s_packet(s8 *data, u8 cmd);
extern void icsd_anc_s2m_packet(s8 *data, u8 cmd);
extern void icsd_anc_msync_packet(struct icsd_anc_tws_packet *packet, u8 cmd);
extern void icsd_anc_ssync_packet(struct icsd_anc_tws_packet *packet, u8 cmd);
extern void icsd_anc_m2s_cb(void *_data, u16 len, bool rx);
extern void icsd_anc_s2m_cb(void *_data, u16 len, bool rx);
extern void icsd_anc_msync_cb(void *_data, u16 len, bool rx);
extern void icsd_anc_ssync_cb(void *_data, u16 len, bool rx);
extern void cal_wz(double *ab, float gain, int tap, float *freq, float fs, float *wz, int len);
extern void ff_fgq_2_aabb(double *iir_ab, float *ff_fgq);
extern float icsd_anc_vmdata_match(float *_vmdata, float gain);
extern void icsd_anc_tonemode_start();
extern float icsd_anc_default_match();
extern void icsd_anc_anctask_cmd_handle(u8 cmd);
extern void icsd_anc_board_param_init();
extern void icsd_anc_tool_data_init();
//SDANC APP调用的SDK函数
extern void icsd_biquad2ab_out(float gain, float f, float fs, float q, double *a0, double *a1, double *a2, double *b0, double *b1, double *b2, int type);
extern void biquad2ab_double(float gain, float f, float q, double *a0, double *a1, double *a2, double *b0, double *b1, double *b2, int type);
extern int tws_api_get_role(void);
extern int tws_api_get_tws_state();
extern void anc_dma_on(u8 out_sel, int *buf, int len);
extern void audio_anc_fade2(int gain, u8 en, u8 step, u8 slow);
extern void anc_user_train_process(audio_anc_t *param);
extern void audio_anc_post_msg_user_train_run(void);
extern void audio_anc_post_msg_user_train_setparam(void);
extern void audio_anc_post_msg_user_train_timeout(void);
extern unsigned int hw_fft_config(int N, int log2N, int is_same_addr, int is_ifft, int is_real);
extern void hw_fft_run(unsigned int fft_config, const int *in, int *out);
extern void anc_user_train_cb(u8 mode, u8 result, u8 forced_exit);
//库调用的SDANC APP函数
extern void icsd_anc_set_alogm(void *_param, int alogm);
extern void icsd_anc_set_micgain(void *_param, int lff_gain, int lfb_gain);
extern void icsd_anc_fade(void *_param);
extern void icsd_anc_long_fade(void *_param);
extern void icsd_anc_user_train_dma_on(u8 out_sel, u32 len, int *buf);
extern void icsd_anc_htarget_data_send();
extern void icsd_anc_fft(int *in, int *out);
extern u32 icsd_anc_get_role();
extern u32 icsd_anc_get_tws_state();
extern void icsd_anc_tws_m2s(u8 cmd);
extern void icsd_anc_tws_s2m(u8 cmd);
extern void icsd_anc_tws_msync(u8 cmd);
extern void icsd_anc_tws_ssync(u8 cmd);
extern void icsd_anc_train_timeout();
extern void icsd_anc_src_init(int in_rate, int out_rate, int (*handler)(void *, void *, int));
extern void icsd_anc_src_write(void *data, int len);
extern u8 icsd_anc_get_save_idx();
extern void icsd_anc_vmdata_num_reset();
extern u8 icsd_anc_get_vmdata_num();
extern u8 icsd_anc_min_diff_idx();
extern void icsd_anc_fgq_printf(float *ptr);
extern void icsd_anc_aabb_printf(double *iir_ab);
extern void icsd_anc_vmdata_by_idx(double *ff_ab, float *ff_gain, u8 idx);
extern void icsd_anc_vmdatar_by_idx(double *ff_ab, float *ff_gain, u8 idx);
extern void icsd_anc_config_inf();
extern void icsd_anc_ear_record_printf();
extern u8 icsd_anc_tooldata_select_vmdata(float *ff_fgq);
extern u8 icsd_anc_tooldata_select_vmdata_headset(float *ff_fgq_l, float *ff_fgq_r);
extern void icsd_audio_adc_mic_open(u8 mic_idx, u8 gain, u16 sr, u8 mic_2_dac);
extern void icsd_audio_adc_mic_close();
extern void sd_anc_exit();
extern void icsd_anc_tonel_start(void *priv);
extern void icsd_anc_toner_start(void *priv);
extern void icsd_anc_pzl_start(void *priv);
extern void icsd_anc_pzr_start(void *priv);
extern void anc_dmadata_debug();
extern void icsd_anc_fft256(int *in, int *out);
extern void icsd_anc_src_push();
extern void anc_core_dma_stop(void);
extern void anc_core_dma_ie(u8 en);
extern void icsd_anc_forced_exit();
extern void audio_anc_post_msg_icsd_anc_cmd(u8 cmd);
extern void icsd_anctone_dacon_handler();
extern void icsd_anc_forced_exit_end();
extern float anc_pow10(float n);
enum {
SD_ANC_TWS = 0,
SD_ANC_HEADSET,
};
struct icsd_anc_libfmt {
int lib_alloc_size; //算法ram需求大小
};
struct icsd_anc_infmt {
void *alloc_ptr; //外部申请的ram地址
};
extern void icsd_anc_set_infmt(struct icsd_anc_infmt *fmt);
extern void icsd_anc_get_libfmt(struct icsd_anc_libfmt *libfmt, u8 type);
extern const float THD_JT;
extern const float THD_JT_SAVE;
extern const float THD_JT2;
extern const float spl_tb [21];
extern const float spl_freq_tb [21];
extern const float target_cmp_dat[];
#endif
+154
View File
@@ -0,0 +1,154 @@
#ifndef _ICSD_ANC_APP_H
#define _ICSD_ANC_APP_H
/*===========接口说明=============================================
一. void sd_anc_init(audio_anc_t *param,u8 mode)
1.调用该函数启动sd anc训练
2.param为ANC ON模式下的audio_anc_t参数指针
3.mode0. 普通模式 1. htarget 数据上传模式
二. void sd_anc_htarget_data_send(float *h_freq,float *hszpz_out,float *hpz_out, float *htarget_out,int len)
1.htarget数据上传模式下,当数据准备好后会自动调用该函数
三. void sd_anc_htarget_data_end()
1.htarget数据上传模式下,当数据上传完成后需要调用该函数进入训练后的ANC ON模式
四. void anc_user_train_tone_play_cb()
1.当前ANC ON提示音结束时回调该函数进入 SD ANC 训练
2.SD ANC训练结束后会切换到ANC ON模式
1:rdout + lout 2:rdout + rerrmic
3:rdout + rrefmic 4:ldout + lerrmic
5:ldout + lrefmic 6:rerrmic + rrefmic
7:lerrmic + lrefmic
anc_sr, 0: 11.7k 1: 23.4k 2: 46.9k 3: 93.8k 4: 187.5k 5: 375k 6: 750k 7: 1.5M
================================================================*/
#include "asm/anc.h"
#include "asm/dac.h"
#include "app_config.h"
#include "icsd_anc.h"
// #include "icsd_anc_client_board.h"
#ifndef ADAPTIVE_CLIENT_BOARD
#define ICSD_ANC_MODE TWS_TONE_BYPASS_MODE
#define ANC_ADAPTIVE_FF_ORDER 8 /*ANC自适应FF滤波器阶数, 原厂指定*/
#define ANC_ADAPTIVE_FB_ORDER 5 /*ANC自适应FB滤波器阶数,原厂指定*/
#define ANC_ADAPTIVE_CMP_ORDER 8 /*ANC自适应CMP滤波器阶数,原厂指定*/
#define ANC_ADAPTIVE_RECORD_FF_ORDER 8 /*ANC自适应耳道记忆FF滤波器阶数,原厂指定*/
#define ANC_FB_TRAIN_OFF 1
#define ANC_FB_TRAIN_NEW 0
#define ANC_EARPHONE_CHECK_EN 0
#define ANC_ADAPTIVE_CMP_EN 1 //自适应CMP补偿
#define ANC_ADAPTIVE_TONE_DELAY 1570
#endif/*ADAPTIVE_CLIENT_BOARD*/
#define ANC_HEADSET_TONE_00 0
#define ANC_HEADSET_TONE_01 1
#define ANC_HEADSET_TONE ANC_HEADSET_TONE_00
#if ANC_HEADSET_TONE == ANC_HEADSET_TONE_00
#define TONEL_DELAY 50
#define TONER_DELAY 2400
#define PZL_DELAY 900
#define PZR_DELAY 3300
#else
#define TONEL_DELAY 50
#define TONER_DELAY 1000
#define PZL_DELAY 1900
#define PZR_DELAY 3200
#endif
#define TEST_EAR_RECORD_EN 0
#define TEST_ANC_COMBINATION TEST_ANC_COMBINATION_OFF
#define TEST_ANC_TRAIN TEST_ANC_TRAIN_OFF
#define ICSD_ANC_DEBUG_TYPE ANC_DEBUG_OFF
#define ANC_USER_TRAIN_EN 1
#if ICSD_ANC_MODE == HEADSET_BYPASS_MODE
#define ANC_USER_TRAIN_TONE_MODE 0
#define BYPASS_MAXTIME 4
#define PZ_MAXTIME 4
#elif ICSD_ANC_MODE == HEADSET_TONES_MODE
#define ANC_USER_TRAIN_TONE_MODE 1
#define BYPASS_MAXTIME 2
#define PZ_MAXTIME 3
#elif ICSD_ANC_MODE == TWS_BYPASS_MODE
#define ANC_USER_TRAIN_TONE_MODE 0
#define BYPASS_MAXTIME 4
#define PZ_MAXTIME 4
#elif ICSD_ANC_MODE == TWS_TONE_BYPASS_MODE
#define ANC_USER_TRAIN_TONE_MODE 1
#define BYPASS_MAXTIME 2
#define PZ_MAXTIME 3
#elif ICSD_ANC_MODE == TWS_TONE_MODE
#define ANC_USER_TRAIN_TONE_MODE 1
#define BYPASS_MAXTIME 2
#define PZ_MAXTIME 3
#elif ICSD_ANC_MODE == HEADSET_TONE_BYPASS_MODE
#define ANC_USER_TRAIN_TONE_MODE 1
#define BYPASS_MAXTIME 2
#define PZ_MAXTIME 3
#else
#define ANC_USER_TRAIN_TONE_MODE 0
#define BYPASS_MAXTIME 4
#define PZ_MAXTIME 4
#endif
#define ANC_USER_TRAIN_MODE 2//0:FF 1:FB 2:HY
#define ANC_USER_TRAIN_SR_SEL 2//46.9k
#define ANC_EAR_RECORD_EN 1 //耳道记忆
#define EAR_RECORD_MAX 5
#define ANC_DFF_AFB_EN 1//默认FF + 自适应FB 1:判断为自适应成功 0:判断为自适应失败
#define ANC_AFF_DFB_EN 1//默认FB + 自适应FF 1:判断为自适应成功 0:判断为自适应失败
#define ANC_SZ_OUT_EN 0//自适应SZ输出使能
#define HEADSET_TONES_MODE_BYPASS_OFF 0
//耳道记忆滤波器保存大小,滤波器组 * 3 + 总增益
#define ANC_VMDATA_FF_RECORD_SIZE ((ANC_ADAPTIVE_RECORD_FF_ORDER * 3) + 1)
extern float (*vmdata_FL)[ANC_VMDATA_FF_RECORD_SIZE];//ff fgq
extern float (*vmdata_FR)[ANC_VMDATA_FF_RECORD_SIZE];//ff fgq
extern int *vmdata_num;
extern const s8 ANC_s8_DATA[];
extern const double ICSD_ANC_DOUBLE_DATA[];
extern const float ICSD_ANC_DATA[];
#define ANC_USE_RECORD 1 //ANC自适应失败使用耳道记忆参数
#define ANC_SUCCESS 2 //ANC自适应成功
#define ANC_USE_DEFAULT 3 //ANC自适应使用ICSD内部默认参数,目前不用;
//自适应训练结果 u8
#define ANC_ADAPTIVE_RESULT_LFF BIT(0) //使用LFF自适应or记忆参数
#define ANC_ADAPTIVE_RESULT_LFB BIT(1) //使用LFB自适应参数
#define ANC_ADAPTIVE_RESULT_LCMP BIT(2) //使用LCMP自适应参数
#define ANC_ADAPTIVE_RESULT_RFF BIT(3) //使用RFF自适应or记忆参数
#define ANC_ADAPTIVE_RESULT_RFB BIT(4) //使用RFB自适应参数
#define ANC_ADAPTIVE_RESULT_RCMP BIT(5) //使用RCMP自适应参数
struct icsd_fb_ref {
float m_value;
float sen;
float in_q;
};
struct icsd_ff_ref {
float fre[75];
float db[75];
};
extern void icsd_anc_vmdata_init(float (*FL)[ANC_VMDATA_FF_RECORD_SIZE], float (*FR)[ANC_VMDATA_FF_RECORD_SIZE], int *num);
#endif/*_ICSD_ANC_APP_H*/
+144
View File
@@ -0,0 +1,144 @@
#ifndef _ICSD_COMMON_H
#define _ICSD_COMMON_H
#include "generic/typedef.h"
#include "math.h"
//#define abs(x) ((x)>0?(x):-(x) )
//#define fabs(x) ((x) < 0 ? -(x) : (x))
#define SWARM_NUM 60
#define ICSD_TARLEN 120//120
#define ICSD_TARLEN_L 40//8+32
#define ICSD_DRPPNT 10// 0,46,92,138,184
#define ICSD_FLEN ((ICSD_TARLEN+ICSD_TARLEN_L-ICSD_DRPPNT)/2) //96
struct icsd_anc_buf {
float Wz_fd_init[ICSD_FLEN * 2];
float Wz_fd_g[ICSD_FLEN * 2];
float perfm[ICSD_FLEN];
float mse[ICSD_FLEN * 2];
float a_fd[ICSD_FLEN * 2];
float b_fd[ICSD_FLEN * 2];
float fitness_sv[60];
float biquad_coef_g[25];
float biquad_coef_co_g[25];
float biquad_coef_List_i[SWARM_NUM][25];
};
struct icsd_De_param {
float Vrange[50];
float target[ICSD_FLEN * 2];
float weight[ICSD_FLEN];
float exp_w1[ICSD_FLEN * 2];
float exp_w2[ICSD_FLEN * 2];
float biquad_init_lcl[25];
int fstop_idx1;
int fstop_idx2;
int iter_max;
int iir_coef;
int iir_num;
int ObjFunc_type;
int type_anc[8];
float mse_tar[ICSD_FLEN];
};
typedef struct icsd_nmss_config_inst {
int flex_seq[6];
int n;
float rho;
float chi;
float psi;
float sigma;
int maxnum;
float usual_delta;
float zero_term_delta;
} icsd_nmss_conf;
typedef struct icsd_nmss_cost_inst {
float J;
float param[6];
} icsd_nmss_cost;
typedef struct icsd_filter_param_inst {
float b[3];
float a[3];
} icsd_biquad_filter;
extern float cos_float(float x);
extern float sin_float(float x);
extern float log10_float(float x);
extern float exp_float(float x);
extern float root_float(float n);
extern float angle_float(float x, float y);
extern unsigned int hw_fft_config(int N, int log2N, int is_same_addr, int is_ifft, int is_real);
extern void hw_fft_run(unsigned int fft_config, const int *in, int *out);
extern float icsd_pow10(float n);
extern float icsd_cos_hq(float x);
extern float icsd_sin_hq(float x);
extern void icsd_complex_div(float *input1, float *input2, float *out, int len);
extern void icsd_biquad2ab_double(float gain, float f, float q, double *a0, double *a1, double *a2, double *b0, double *b1, double *b2, int type);
extern void icsd_DeAlorithm(struct icsd_De_param *e_param, float *biquad_coef_best, float *fitness, int iir_dim, int swarm_num, int flen, struct icsd_anc_buf *_ANC_BUF);
extern void icsd_calObjFitness(float *biquad_coef, int flen, struct icsd_De_param *de_param, float *fitness, struct icsd_anc_buf *_ANC_BUF);
extern void icsd_nmss_music_cmp(float *xfix, icsd_nmss_conf *nmss_config, struct icsd_De_param *de_param, int flen, int iir_num, float *nmss_out, struct icsd_anc_buf *_ANC_BUF);
extern void icsd_FFT_radix1024(int *in, int *out);
extern void icsd_HanningWin_pwr(s16 *input, int *output, int len);
extern void icsd_common_version();
//
extern float abs_float(float f);
extern void HanningWin_pwr(s16 *input, int *output, int len);
extern void FFT_radix1024(int *in_cur, int *out);
extern void FFT_radix256(int *in_cur, int *out);
extern void FFT_lowfreq4096(s16 *in_cur, float *out, int len);
//---------------------------
// multi float conj
//---------------------------
extern void complex_mulf(float *input1, float *input2, float *out, int len);
//---------------------------
// multi conj
//---------------------------
extern void complex_mul(int *input1, float *input2, float *out, int len);
extern void unwrap(float *pha1, float *pha2);
//---------------------------
// div
//---------------------------
extern float mean_cal(float *data0, u8 len);
extern float min_cal(float *data, u8 len);
extern double devide_float(float data_0, float data_1);
extern double devide_double(double data_0, double data_1);
extern void complex_muln_2(float *input1, float *input2, float *input3, float *out, int len, float alpha);
extern void complex_div(float *input1, float *input2, float *out, int len);
extern void biquad2ab(float gain, float f, float q, float *a0, float *a1, float *a2, float *b0, float *b1, float *b2, int type);
extern void biquad2ab_double(float gain, float f, float q, double *a0, double *a1, double *a2, double *b0, double *b1, double *b2, int type);
extern void icsd_biquad2ab_out(float gain, float f, float fs, float q, double *a0, double *a1, double *a2, double *b0, double *b1, double *b2, int type);
extern void biquad2ab_double_pn(float gain, float f, float q, double *a0, double *a1, double *a2,
double *b0, double *b1, double *b2, int type);
//extern void calWz_double(float *biquad_coef, int flen, int iir_num, struct De_param *de_param, float *Wz_fd, int *type);
//extern void calWz_ab_double(double *iir_ab, int flen, int iir_num, struct De_param *de_param, float *Wz_fd, int *type);
//extern void calWz(float *biquad_coef, int flen, int iir_num, struct De_param *de_param, float *Wz_fd, int *type);
extern void icsd_data_dsfn(s16 *input, s16 *output, int len, u8 n);
//hard upspeed
extern float anc_pow10(float n);
extern double log10_anc(double x);
extern void icsd_anc_fft(int *in, int *out);
extern void icsd_anc_fft256(int *in, int *out);
extern float cos_hq(float x);
extern float sin_hq(float x);
extern void complex_muln(float *input1, float *input2, float *out, int len);
extern void icsd_complex_mul(int *input1, float *input2, float *out, int len);
#endif