first
This commit is contained in:
503
apps/common/icsd/adt/icsd_adt.c
Normal file
503
apps/common/icsd/adt/icsd_adt.c
Normal file
@ -0,0 +1,503 @@
|
||||
#include "app_config.h"
|
||||
#if ((defined TCFG_AUDIO_ANC_ACOUSTIC_DETECTOR_EN) && TCFG_AUDIO_ANC_ACOUSTIC_DETECTOR_EN && \
|
||||
TCFG_AUDIO_ANC_ENABLE)
|
||||
#include "system/task.h"
|
||||
#include "icsd_adt.h"
|
||||
#include "icsd_adt_app.h"
|
||||
#include "classic/tws_api.h"
|
||||
#include "icsd_anc.h"
|
||||
#include "tone_player.h"
|
||||
#include "icsd_anc_user.h"
|
||||
|
||||
#define ICSD_ADT_TASK_NAME "icsd_adt"
|
||||
|
||||
const u8 VDT_TRAIN_EN = 0;
|
||||
|
||||
u8 adt_task = 0;
|
||||
u8 src_task = 0;
|
||||
int (*adt_printf)(const char *format, ...);
|
||||
int (*wat_printf)(const char *format, ...);
|
||||
int (*ein_printf)(const char *format, ...);
|
||||
int printf_off(const char *format, ...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define ADT_DATA_DEBUG 0
|
||||
void icsd_adt_run_output(__adt_result *adt_result)
|
||||
{
|
||||
u8 voice_state = adt_result->voice_state;
|
||||
u8 wind_lvl = adt_result->wind_lvl;
|
||||
u8 wat_result = adt_result->wat_result;
|
||||
u8 ein_state = adt_result->ein_state;
|
||||
|
||||
#if ADT_DATA_DEBUG
|
||||
extern void icsd_adt_output_demo(__adt_result * adt_result);
|
||||
icsd_adt_output_demo(adt_result);
|
||||
#else
|
||||
void audio_acoustic_detector_output_hdl(u8 voice_state, u8 wind_lvl, u8 wat_result);
|
||||
audio_acoustic_detector_output_hdl(voice_state, wind_lvl, wat_result);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define AUDIO_ADC_CH0 BIT(0)
|
||||
#define AUDIO_ADC_CH1 BIT(1)
|
||||
#define AUDIO_ADC_CH2 BIT(2)
|
||||
#define AUDIO_ADC_CH3 BIT(3)
|
||||
void icsd_adt_mic_ch_analog_open(u32 ch)
|
||||
{
|
||||
if (ch & AUDIO_ADC_CH0) {
|
||||
/*close mic0 analog config*/
|
||||
SFR(JL_ADDA->ADA_CON4, 15, 1, 0); // AUDADC_MICA_BUFP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON4, 14, 1, 0); // AUDADC_MICA_BUFN_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON4, 4, 1, 1); // AUDADC_MICA_AMP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 8, 1, 1); // AUDADC_CHA_S2_RSTB_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 7, 1, 1); // AUDADC_CHA_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 6, 1, 1); // AUDADC_CHA_BIAS_EN_10v
|
||||
}
|
||||
if (ch & AUDIO_ADC_CH1) {
|
||||
/*close mic1 analog config*/
|
||||
SFR(JL_ADDA->ADA_CON5, 15, 1, 0); // AUDADC_MICB_BUFP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON5, 14, 1, 0); // AUDADC_MICB_BUFN_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON5, 4, 1, 1); // AUDADC_MICB_AMP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 11, 1, 1); // AUDADC_CHB_S2_RSTB_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 10, 1, 1); // AUDADC_CHB_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 9, 1, 1); // AUDADC_CHB_BIAS_EN_10v
|
||||
}
|
||||
if (ch & AUDIO_ADC_CH2) {
|
||||
/*close mic2 analog config*/
|
||||
SFR(JL_ADDA->ADA_CON6, 15, 1, 0); // AUDADC_MICC_BUFP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON6, 14, 1, 0); // AUDADC_MICC_BUFN_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON6, 4, 1, 1); // AUDADC_MICC_AMP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 14, 1, 1); // AUDADC_CHC_S2_RSTB_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 13, 1, 1); // AUDADC_CHC_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 12, 1, 1); // AUDADC_CHC_BIAS_EN_10v
|
||||
}
|
||||
if (ch & AUDIO_ADC_CH3) {
|
||||
/*close mic3 analog config*/
|
||||
SFR(JL_ADDA->ADA_CON7, 15, 1, 0); // AUDADC_MICD_BUFP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON7, 14, 1, 0); // AUDADC_MICD_BUFN_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON7, 4, 1, 1); // AUDADC_MICD_AMP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 17, 1, 1); // AUDADC_CHD_S2_RSTB_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 16, 1, 1); // AUDADC_CHD_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 15, 1, 1); // AUDADC_CHD_BIAS_EN_10v
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_adt_mic_ch_analog_close(u32 ch)
|
||||
{
|
||||
if (ch & AUDIO_ADC_CH0) {
|
||||
/*close mic0 analog config*/
|
||||
SFR(JL_ADDA->ADA_CON4, 15, 1, 0); // AUDADC_MICA_BUFP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON4, 14, 1, 0); // AUDADC_MICA_BUFN_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON4, 4, 1, 0); // AUDADC_MICA_AMP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 8, 1, 0); // AUDADC_CHA_S2_RSTB_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 7, 1, 0); // AUDADC_CHA_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 6, 1, 0); // AUDADC_CHA_BIAS_EN_10v
|
||||
}
|
||||
if (ch & AUDIO_ADC_CH1) {
|
||||
/*close mic1 analog config*/
|
||||
SFR(JL_ADDA->ADA_CON5, 15, 1, 0); // AUDADC_MICB_BUFP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON5, 14, 1, 0); // AUDADC_MICB_BUFN_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON5, 4, 1, 0); // AUDADC_MICB_AMP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 11, 1, 0); // AUDADC_CHB_S2_RSTB_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 10, 1, 0); // AUDADC_CHB_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 9, 1, 0); // AUDADC_CHB_BIAS_EN_10v
|
||||
}
|
||||
if (ch & AUDIO_ADC_CH2) {
|
||||
/*close mic2 analog config*/
|
||||
SFR(JL_ADDA->ADA_CON6, 15, 1, 0); // AUDADC_MICC_BUFP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON6, 14, 1, 0); // AUDADC_MICC_BUFN_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON6, 4, 1, 0); // AUDADC_MICC_AMP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 14, 1, 0); // AUDADC_CHC_S2_RSTB_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 13, 1, 0); // AUDADC_CHC_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 12, 1, 0); // AUDADC_CHC_BIAS_EN_10v
|
||||
}
|
||||
if (ch & AUDIO_ADC_CH3) {
|
||||
/*close mic3 analog config*/
|
||||
SFR(JL_ADDA->ADA_CON7, 15, 1, 0); // AUDADC_MICD_BUFP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON7, 14, 1, 0); // AUDADC_MICD_BUFN_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON7, 4, 1, 0); // AUDADC_MICD_AMP_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 17, 1, 0); // AUDADC_CHD_S2_RSTB_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 16, 1, 0); // AUDADC_CHD_EN_10v
|
||||
SFR(JL_ADDA->ADA_CON1, 15, 1, 0); // AUDADC_CHD_BIAS_EN_10v
|
||||
}
|
||||
}
|
||||
|
||||
u8 talk_mic_analog_close = 0;
|
||||
u8 audio_adt_talk_mic_analog_close()
|
||||
{
|
||||
if (talk_mic_analog_close == 0) {
|
||||
printf("-----------audio_adt_talk_mic_analog_close\n");
|
||||
u8 talk_mic_ch = icsd_get_talk_mic_ch();
|
||||
icsd_adt_mic_ch_analog_close(talk_mic_ch);
|
||||
talk_mic_analog_close = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 audio_adt_talk_mic_analog_open()
|
||||
{
|
||||
if (talk_mic_analog_close) {
|
||||
printf("-----------audio_adt_talk_mic_analog_open\n");
|
||||
u8 talk_mic_ch = icsd_get_talk_mic_ch();
|
||||
icsd_adt_mic_ch_analog_open(talk_mic_ch);
|
||||
talk_mic_analog_close = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
float adt_pow10(float n)
|
||||
{
|
||||
float pow10n = exp_float((float)n / log10_float(exp_float((float)1.0)));
|
||||
return pow10n;
|
||||
}
|
||||
|
||||
u32 icsd_adt_get_role()
|
||||
{
|
||||
return tws_api_get_role();
|
||||
}
|
||||
|
||||
u32 icsd_adt_get_tws_state()
|
||||
{
|
||||
return tws_api_get_tws_state();
|
||||
}
|
||||
|
||||
#define TWS_FUNC_ID_SDADT_M2S TWS_FUNC_ID('A', 'D', 'T', 'M')
|
||||
REGISTER_TWS_FUNC_STUB(icsd_adt_m2s) = {
|
||||
.func_id = TWS_FUNC_ID_SDADT_M2S,
|
||||
.func = icsd_adt_m2s_cb,
|
||||
};
|
||||
#define TWS_FUNC_ID_SDADT_S2M TWS_FUNC_ID('A', 'D', 'T', 'S')
|
||||
REGISTER_TWS_FUNC_STUB(icsd_adt_s2m) = {
|
||||
.func_id = TWS_FUNC_ID_SDADT_S2M,
|
||||
.func = icsd_adt_s2m_cb,
|
||||
};
|
||||
|
||||
void icsd_adt_tws_m2s(u8 cmd)
|
||||
{
|
||||
local_irq_disable();
|
||||
s8 data[8];
|
||||
icsd_adt_m2s_packet(data, cmd);
|
||||
int ret = tws_api_send_data_to_sibling(data, 8, TWS_FUNC_ID_SDADT_M2S);
|
||||
local_irq_enable();
|
||||
}
|
||||
|
||||
void icsd_adt_tws_s2m(u8 cmd)
|
||||
{
|
||||
local_irq_disable();
|
||||
s8 data[8];
|
||||
icsd_adt_s2m_packet(data, cmd);
|
||||
int ret = tws_api_send_data_to_sibling(data, 8, TWS_FUNC_ID_SDADT_S2M);
|
||||
local_irq_enable();
|
||||
}
|
||||
|
||||
void icsd_adt_anc_dma_on(u8 out_sel, int *buf, int len)
|
||||
{
|
||||
anc_dma_on_double(out_sel, buf, len);
|
||||
}
|
||||
|
||||
void icsd_adt_dma_done()
|
||||
{
|
||||
icsd_acoustic_detector_ancdma_done();
|
||||
}
|
||||
|
||||
void icsd_adt_hw_suspend()
|
||||
{
|
||||
anc_core_dma_ie(0);
|
||||
anc_core_dma_stop();
|
||||
}
|
||||
|
||||
void icsd_adt_hw_resume()
|
||||
{
|
||||
audio_acoustic_detector_updata();
|
||||
icsd_adt_szout_init();
|
||||
}
|
||||
|
||||
void icsd_adt_FFT_radix256(int *in_cur, int *out)
|
||||
{
|
||||
u32 fft_config;
|
||||
fft_config = hw_fft_config(256, 8, 1, 0, 1);
|
||||
hw_fft_run(fft_config, in_cur, out);
|
||||
}
|
||||
|
||||
void icsd_adt_FFT_radix128(int *in_cur, int *out)
|
||||
{
|
||||
u32 fft_config;
|
||||
fft_config = hw_fft_config(128, 7, 1, 0, 1);
|
||||
hw_fft_run(fft_config, in_cur, out);
|
||||
}
|
||||
|
||||
void icsd_adt_FFT_radix64(int *in_cur, int *out)
|
||||
{
|
||||
u32 fft_config;
|
||||
fft_config = hw_fft_config(64, 6, 1, 0, 1);
|
||||
hw_fft_run(fft_config, in_cur, out);
|
||||
}
|
||||
|
||||
void icsd_post_anctask_msg(u8 cmd)
|
||||
{
|
||||
audio_anc_post_msg_adt(cmd);
|
||||
}
|
||||
|
||||
void icsd_post_adttask_msg(u8 cmd)
|
||||
{
|
||||
if (adt_task == 1) {
|
||||
os_taskq_post_msg("icsd_adt", 1, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_post_srctask_msg(u8 cmd)
|
||||
{
|
||||
if (src_task == 1) {
|
||||
os_taskq_post_msg("icsd_src", 1, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_adt_task(void *priv)
|
||||
{
|
||||
int res = 0;
|
||||
int msg[30];
|
||||
while (1) {
|
||||
res = os_taskq_pend(NULL, msg, ARRAY_SIZE(msg));
|
||||
if (res == OS_TASKQ) {
|
||||
icsd_adt_task_handler(msg[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_adt_task_create()
|
||||
{
|
||||
if (adt_task == 0) {
|
||||
task_create(icsd_adt_task, NULL, ICSD_ADT_TASK_NAME);
|
||||
adt_task = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_adt_task_kill()
|
||||
{
|
||||
if (adt_task == 1) {
|
||||
task_kill(ICSD_ADT_TASK_NAME);
|
||||
adt_task = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_src_task(void *priv)
|
||||
{
|
||||
int res = 0;
|
||||
int msg[30];
|
||||
while (1) {
|
||||
res = os_taskq_pend(NULL, msg, ARRAY_SIZE(msg));
|
||||
if (res == OS_TASKQ) {
|
||||
icsd_src_task_handler(msg[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_src_task_create()
|
||||
{
|
||||
if (src_task == 0) {
|
||||
task_create(icsd_src_task, NULL, "icsd_src");
|
||||
src_task = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_src_task_kill()
|
||||
{
|
||||
if (src_task == 1) {
|
||||
task_kill("icsd_src");
|
||||
src_task = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_adt_start()
|
||||
{
|
||||
adt_printf = _adt_printf;
|
||||
wat_printf = _wat_printf;
|
||||
ein_printf = _ein_printf;
|
||||
printf("icsd_adt_start====================================\n");
|
||||
}
|
||||
|
||||
void icsd_adt_szout_init()
|
||||
{
|
||||
#if ADT_USE_ADAPTIVE_SZ
|
||||
extern float icsd_anc_sz_data[120 + 40];
|
||||
extern float icsd_anc_pz_data[120 + 40];
|
||||
extern u8 sz_out_exist;//需要打开自适应ANC库中的 自适应SZ输出使能:ANC_SZ_OUT_EN
|
||||
icsd_adt_szout_set(icsd_anc_sz_data, icsd_anc_pz_data, sz_out_exist);
|
||||
#else
|
||||
icsd_adt_szout_set(0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
const u16 ADT_DEBUG_INF = 0;//ADT_INF_1;//state
|
||||
//state = 1, pwr = 7, dov = 8, angle_err = 7, angle_tlk = 3
|
||||
const u8 adt_errpxx_dB_thr = 80;//60;
|
||||
const u8 adt_err_zcv_thr = 10;//12;
|
||||
const u8 pwr_inside_even_flag0_thr = 5; //pwr
|
||||
const u8 angle_err_even_flag0_thr = 3;//4; //angle_err
|
||||
const u8 angle_talk_even_flag0_thr = 2; //angle_tlk
|
||||
const u16 f1f2_angsum_thr = 200;
|
||||
#ifndef ADT_CLIENT_BOARD
|
||||
const u8 final_speech_even_thr = 4; //dov
|
||||
|
||||
|
||||
const u8 ADT_TWS_MODE = 1;
|
||||
const u8 ADT_DET_VER = 6;
|
||||
const u8 ADT_PATH_CONFIG = ADT_PATH_DAC_SRC_EN | ADT_PATH_3M_EN;
|
||||
const u8 ADT_EIN_VER = ADT_EIN_TWS_V0;
|
||||
const float ref_gain_sel = 3;
|
||||
const float err_gain_sel = 3;
|
||||
u8 pnc_ref_pwr_thr = 160;
|
||||
u8 pnc_err_pwr_thr = 100;
|
||||
u8 tpc_ref_pwr_thr = 120;
|
||||
u8 tpc_err_pwr_thr = 100;
|
||||
u8 anc_ref_pwr_thr = 120;
|
||||
u8 anc_err_pwr_thr = 100;
|
||||
|
||||
const float wat_pn_gain = 0.22;
|
||||
const float wat_bypass_gain = 16;
|
||||
const float wat_anc_gain = 0.22;
|
||||
|
||||
const float wdac_senc = 0.7; //越小播音乐时灵敏度越高
|
||||
const float wdac[8] = { 0.35, 0.54, 0.57, 0.48, 0.37, 0.22, 0.38, 0.37};//播放音乐/100
|
||||
const float wref[8] = {1.62, 0.90, 0.71, 0.60, 0.54, 0.50, 0.47, 0.46};//播放外部噪声
|
||||
const float wref_tran[8] = {1.82, 1.80, 1.58, 1.30, 1.16, 1.12, 1.11, 1.12};
|
||||
const float wref_ancs[8] = {1.92, 0.48, 0.07, 0.03, 0.05, 0.06, 0.06, 0.04 };
|
||||
const float fdac[8] = {0.18, 0.051, 0.02, 0.02, 0.02, 0.02, 0.02, 0.05};//播放音乐/1000
|
||||
u8 icsd_get_ang_flag(float *_target_angle)
|
||||
{
|
||||
u8 af1 = _target_angle[1] > 15 || _target_angle[1] < -130;
|
||||
u8 af2 = _target_angle[2] > 15 || _target_angle[2] < -130;
|
||||
u8 af3 = _target_angle[3] > 15 || _target_angle[3] < -130;
|
||||
u8 ang_flag = af1 && af2 && af3;
|
||||
/* printf("get ang flag:%d\n", ang_flag); */
|
||||
return ang_flag;
|
||||
}
|
||||
|
||||
void icsd_adt_ein_parm_HT03(__icsd_adt_parm *_ADT_PARM)
|
||||
{
|
||||
_ADT_PARM->anc_in_pz_sum = -80;
|
||||
_ADT_PARM->anc_out_pz_sum = 0;
|
||||
_ADT_PARM->anc_in_sz_mean = 1;
|
||||
_ADT_PARM->anc_out_sz_mean = -12;
|
||||
_ADT_PARM->anc_in_fb_sum = 60;
|
||||
_ADT_PARM->anc_out_fb_sum = 30;
|
||||
|
||||
_ADT_PARM->pnc_in_pz_sum = -80;
|
||||
_ADT_PARM->pnc_out_pz_sum = 0;
|
||||
_ADT_PARM->pnc_in_sz_mean = 1;
|
||||
_ADT_PARM->pnc_out_sz_mean = -12;
|
||||
_ADT_PARM->pnc_in_fb_sum = 60;
|
||||
_ADT_PARM->pnc_out_fb_sum = 30;
|
||||
|
||||
_ADT_PARM->trans_in_pz_sum = 2;
|
||||
_ADT_PARM->trans_out_pz_sum = 26;
|
||||
_ADT_PARM->trans_in_sz_mean = 2;
|
||||
_ADT_PARM->trans_out_sz_mean = -7;
|
||||
_ADT_PARM->trans_in_fb_sum = 20;
|
||||
_ADT_PARM->trans_out_fb_sum = -20;
|
||||
}
|
||||
|
||||
void icsd_adt_voice_board_data()
|
||||
{
|
||||
__icsd_adt_parm *ADT_PARM;
|
||||
ADT_PARM = zalloc(sizeof(__icsd_adt_parm));
|
||||
|
||||
extern const float HT03_ADT_FLOAT_DATA[];
|
||||
extern const float HT03_sz_out_data[28];
|
||||
extern const float HT03_pz_out_data[28];
|
||||
ADT_PARM->adt_float_data = (void *)HT03_ADT_FLOAT_DATA;
|
||||
ADT_PARM->sz_inptr = (float *)HT03_sz_out_data;
|
||||
ADT_PARM->pz_inptr = (float *)HT03_pz_out_data;
|
||||
icsd_adt_ein_parm_HT03(ADT_PARM);
|
||||
|
||||
icsd_adt_parm_set(ADT_PARM);
|
||||
free(ADT_PARM);
|
||||
|
||||
icsd_adt_szout_init();
|
||||
}
|
||||
#else
|
||||
|
||||
#include "icsd_adt_client_board.c"
|
||||
|
||||
#endif/*ADC_CLIENT_BOARD*/
|
||||
|
||||
|
||||
//=======================================================================================================
|
||||
|
||||
#if ADT_DATA_DEBUG
|
||||
|
||||
void icsd_play_num0()
|
||||
{
|
||||
icsd_adt_tone_play(ICSD_ADT_TONE_NUM0);
|
||||
}
|
||||
void icsd_play_num1()
|
||||
{
|
||||
icsd_adt_tone_play(ICSD_ADT_TONE_NUM1);
|
||||
}
|
||||
void icsd_play_num2()
|
||||
{
|
||||
icsd_adt_tone_play(ICSD_ADT_TONE_NUM2);
|
||||
}
|
||||
void icsd_play_num3()
|
||||
{
|
||||
icsd_adt_tone_play(ICSD_ADT_TONE_NUM3);
|
||||
}
|
||||
void icsd_play_normal()
|
||||
{
|
||||
icsd_adt_tone_play(ICSD_ADT_TONE_NORMAL);
|
||||
}
|
||||
|
||||
void icsd_adt_output_demo(__adt_result *adt_result)
|
||||
{
|
||||
#if ADT_EAR_IN_EN
|
||||
static u8 hold = 0;
|
||||
static u8 hold_flg = 0;
|
||||
static int hold_time = 0;
|
||||
if (adt_result->ein_state == 0) {
|
||||
hold = 1;
|
||||
hold_flg = 1;
|
||||
hold_time = 0;
|
||||
printf("------------------------------------------------------------------ein state:0\n");
|
||||
} else {
|
||||
if (hold_flg) {
|
||||
hold_flg = 0;
|
||||
hold_time = jiffies;
|
||||
printf("set hold time:%d\n", hold_time);
|
||||
}
|
||||
if ((hold_time > 0) && (hold)) {
|
||||
if (jiffies > (hold_time + 100)) {
|
||||
printf("hold time out:%d\n", jiffies);
|
||||
hold = 0;
|
||||
}
|
||||
}
|
||||
printf("--------------------------------ein state:1\n");
|
||||
}
|
||||
if (hold) {
|
||||
//return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (adt_result->wind_lvl) {
|
||||
printf("------wind lvl:%d\n", adt_result->wind_lvl);
|
||||
}
|
||||
if (adt_result->voice_state) {
|
||||
icsd_play_normal();
|
||||
}
|
||||
switch (adt_result->wat_result) {
|
||||
case 2:
|
||||
icsd_play_num2();
|
||||
break;
|
||||
case 3:
|
||||
icsd_play_num3();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /*ADT_DATA_DEBUG*/
|
||||
|
||||
#endif /*(defined TCFG_AUDIO_ANC_ACOUSTIC_DETECTOR_EN) && TCFG_AUDIO_ANC_ACOUSTIC_DETECTOR_EN*/
|
||||
|
||||
306
apps/common/icsd/adt/icsd_adt.h
Normal file
306
apps/common/icsd/adt/icsd_adt.h
Normal file
@ -0,0 +1,306 @@
|
||||
#ifndef _ICSD_ADT_H
|
||||
#define _ICSD_ADT_H
|
||||
|
||||
#include "generic/typedef.h"
|
||||
#include "os/os_type.h"
|
||||
#include "os/os_api.h"
|
||||
#include "classic/tws_api.h"
|
||||
#include "math.h"
|
||||
|
||||
#if 0
|
||||
#define _adt_printf printf //打开智能免摘库打印信息
|
||||
#else
|
||||
extern int printf_off(const char *format, ...);
|
||||
#define _adt_printf printf_off
|
||||
#endif/*log_en*/
|
||||
|
||||
#if 0
|
||||
#define _wat_printf printf //打开广域点击库打印信息
|
||||
#else
|
||||
extern int printf_off(const char *format, ...);
|
||||
#define _wat_printf printf_off
|
||||
#endif/*log_en*/
|
||||
|
||||
#if 0
|
||||
#define _wind_printf printf //打开风噪检测库打印信息
|
||||
#else
|
||||
extern int printf_off(const char *format, ...);
|
||||
#define _wind_printf printf_off
|
||||
#endif/*log_en*/
|
||||
|
||||
#if 0
|
||||
#define _ein_printf printf //打开入耳检测库打印信息
|
||||
#else
|
||||
extern int printf_off(const char *format, ...);
|
||||
#define _ein_printf printf_off
|
||||
#endif/*log_en*/
|
||||
|
||||
#define ADT_CALIBRATION_EN 0
|
||||
#define ADT_USE_ADAPTIVE_SZ 0//使用自适应SZ
|
||||
#define ADT_EAR_IN_EN 0
|
||||
|
||||
#define ADT_VDT_EN BIT(0) //智能免摘
|
||||
#define ADT_WDT_EN BIT(1) //风噪检测
|
||||
#define ADT_WAT_EN BIT(2) //广域点击
|
||||
#define ADT_EIN_EN BIT(3) //入耳检测
|
||||
|
||||
#define ADT_PATH_VDT_ANCL_ON BIT(0) //智能免摘使用ancl通路数据
|
||||
#define ADT_PATH_WAT_EMIC_ON BIT(1) //广域点击使用errmic数据通路
|
||||
#define ADT_PATH_VAD_ON BIT(2) //通过VAD检测降低功耗
|
||||
#define ADT_PATH_DAC_SRC_EN BIT(3)
|
||||
#define ADT_PATH_3M_EN BIT(4)
|
||||
|
||||
|
||||
#define ADT_INF_1 BIT(0)
|
||||
#define ADT_INF_2 BIT(1)
|
||||
#define ADT_INF_3 BIT(2)
|
||||
|
||||
extern const u8 ADT_PATH_CONFIG;
|
||||
#define ICSD_TWS_STA_SIBLING_CONNECTED TWS_STA_SIBLING_CONNECTED//tws已连接
|
||||
|
||||
typedef struct {
|
||||
u8 voice_state;
|
||||
u8 wind_lvl;
|
||||
u8 wat_result;
|
||||
u8 ein_state;
|
||||
} __adt_result;
|
||||
|
||||
struct icsd_acoustic_detector_infmt {
|
||||
u16 sample_rate; //当前播放采样率
|
||||
u8 ff_gain;
|
||||
u8 fb_gain;
|
||||
u8 adt_mode; // TWS: 0 HEADSET: 1
|
||||
u8 dac_mode; //低压0 高压1
|
||||
u8 mic0_type; // MIC0 类型
|
||||
u8 mic1_type; // MIC1 类型
|
||||
u8 mic2_type; // MIC2 类型
|
||||
u8 mic3_type; // MIC3 类型
|
||||
u8 sensitivity; //智能免摘灵敏度设置
|
||||
void *lfb_coeff;
|
||||
void *lff_coeff;
|
||||
void *ltrans_coeff;
|
||||
void *ltransfb_coeff;
|
||||
float gains_l_fbgain;
|
||||
float gains_l_ffgain;
|
||||
float gains_l_transgain;
|
||||
float gains_l_transfbgain;
|
||||
u8 gain_sign;
|
||||
u8 lfb_yorder;
|
||||
u8 lff_yorder;
|
||||
u8 ltrans_yorder;
|
||||
u8 ltransfb_yorder;
|
||||
u32 trans_alogm;
|
||||
u32 alogm;
|
||||
|
||||
void *alloc_ptr; //外部申请的ram地址
|
||||
/*
|
||||
算法结果输出
|
||||
voice_state: 0 无讲话; 1 有讲话
|
||||
wind_lvl: 0-70 风噪等级
|
||||
*/
|
||||
void (*output_hdl)(u8 voice_state, u8 wind_lvl); //算法结果输出
|
||||
void (*anc_dma_post_msg)(void); //ANC task dma 抄数回调接口
|
||||
void (*anc_dma_output_callback); //ANC DMA下采样数据输出回调,用于写卡分析
|
||||
};
|
||||
|
||||
struct icsd_acoustic_detector_libfmt {
|
||||
int adc_isr_len; //ADC中断长度
|
||||
int adc_sr; //ADC 采样率
|
||||
int lib_alloc_size; //算法ram需求大小
|
||||
u8 mic_num; //需要打开的mic个数
|
||||
};
|
||||
|
||||
enum {
|
||||
ICSD_ANC_LFF_MIC = 0,
|
||||
ICSD_ANC_LFB_MIC = 1,
|
||||
ICSD_ANC_RFF_MIC = 2,
|
||||
ICSD_ANC_RFB_MIC = 3,
|
||||
ICSD_ANC_TALK_MIC = 4,
|
||||
ICSD_ANC_MIC_NULL = 0XFF, //对应的MIC没有数值,则表示这个MIC没有开启
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
void *adt_float_data;
|
||||
float *sz_inptr;
|
||||
float *pz_inptr;
|
||||
s16 anc_in_pz_sum;
|
||||
s16 anc_in_sz_mean;
|
||||
s16 anc_in_fb_sum;
|
||||
s16 anc_out_pz_sum;
|
||||
s16 anc_out_sz_mean;
|
||||
s16 anc_out_fb_sum;
|
||||
|
||||
s16 pnc_in_pz_sum;
|
||||
s16 pnc_in_sz_mean;
|
||||
s16 pnc_in_fb_sum;
|
||||
s16 pnc_out_pz_sum;
|
||||
s16 pnc_out_sz_mean;
|
||||
s16 pnc_out_fb_sum;
|
||||
|
||||
s16 trans_in_pz_sum;
|
||||
s16 trans_in_sz_mean;
|
||||
s16 trans_in_fb_sum;
|
||||
s16 trans_out_pz_sum;
|
||||
s16 trans_out_sz_mean;
|
||||
s16 trans_out_fb_sum;
|
||||
} __icsd_adt_parm;
|
||||
|
||||
enum {
|
||||
RESUME_ANCMODE = 0,
|
||||
RESUME_BYPASSMODE,
|
||||
};
|
||||
enum {
|
||||
ADT_DACMODE_LOW = 0,
|
||||
ADT_DACMODE_HIGH,
|
||||
};
|
||||
enum {
|
||||
ADT_TWS = 0,
|
||||
ADT_HEADSET,
|
||||
};
|
||||
enum {
|
||||
ADT_ANC_ON = 0,
|
||||
ADT_ANC_OFF,
|
||||
};
|
||||
enum {
|
||||
ADT_VOICE_WIND_MODE = 0, //智能免摘 + 风噪
|
||||
ADT_WAT_MODE, //广域点击
|
||||
ADT_VW_WAT_MODE, //智能免摘 + 风噪检测 + 广域点击
|
||||
};
|
||||
enum {
|
||||
ADT_EIN_UNSUPPORT = 0,
|
||||
ADT_EIN_TWS_V0,
|
||||
ADT_EIN_HEADSET_V0,
|
||||
};
|
||||
|
||||
extern const float wat_pn_gain;
|
||||
extern const float wat_anc_gain;
|
||||
extern const float wat_bypass_gain;
|
||||
extern const u8 final_speech_even_thr;
|
||||
extern const u8 VDT_TRAIN_EN;
|
||||
extern const float ref_gain_sel;
|
||||
extern const float err_gain_sel;
|
||||
extern u8 pnc_ref_pwr_thr;
|
||||
extern u8 pnc_err_pwr_thr;
|
||||
extern u8 tpc_ref_pwr_thr;
|
||||
extern u8 tpc_err_pwr_thr;
|
||||
extern u8 anc_ref_pwr_thr;
|
||||
extern u8 anc_err_pwr_thr;
|
||||
extern const float wref[8];
|
||||
extern const float wref_tran[8];
|
||||
extern const float wref_ancs[8];
|
||||
extern const float wdac_senc;
|
||||
extern const float wdac[8];
|
||||
extern const float fdac[8];
|
||||
extern const u8 ADT_DET_VER;
|
||||
extern const u8 ADT_TWS_MODE;
|
||||
extern const u8 ADT_EIN_VER;
|
||||
extern float anc_trans_lfb_gain;
|
||||
extern float anc_trans_rfb_gain;
|
||||
extern const double anc_trans_lfb_coeff[];
|
||||
extern const double anc_trans_rfb_coeff[];
|
||||
|
||||
extern int (*adt_printf)(const char *format, ...);
|
||||
extern int (*wat_printf)(const char *format, ...);
|
||||
extern int (*ein_printf)(const char *format, ...);
|
||||
|
||||
extern void icsd_adt_tws_m2s(u8 cmd);
|
||||
extern void icsd_adt_tws_s2m(u8 cmd);
|
||||
//LIB调用的算术函数
|
||||
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 pow10(float n);
|
||||
extern float adt_pow10(float n);
|
||||
extern float angle_float(float x, float y);
|
||||
//ADT调用的APP函数
|
||||
|
||||
extern int audio_dac_read_anc_reset(void);
|
||||
extern int audio_acoustic_detector_updata();
|
||||
extern void tws_tx_unsniff_req(void);
|
||||
extern int tws_api_get_role(void);
|
||||
extern int tws_api_get_tws_state();
|
||||
extern u8 anc_dma_done_ppflag();
|
||||
extern void anc_core_dma_ie(u8 en);
|
||||
extern void anc_core_dma_stop(void);
|
||||
extern int os_task_create(void (*task_func)(void *p_arg), void *p_arg, u8 prio, u32 stksize, int qsize, const char *name);
|
||||
extern int os_task_del(const char *name);
|
||||
extern int os_taskq_post_msg(const char *name, int argc, ...);
|
||||
extern int os_taskq_pend(const char *fmt, int *argv, int argc);
|
||||
extern void anc_dma_on_double(u8 out_sel, int *buf, int len);
|
||||
extern int audio_resample_hw_push_data_out(void *resample);
|
||||
extern void audio_resample_hw_close(void *resample);
|
||||
extern void *audio_resample_hw_open(u8 channel, int in_rate, int out_rate, u8 type);
|
||||
extern int audio_resample_hw_set_output_handler(void *resample, void *priv, int (*handler)(void *, void *, int));
|
||||
extern int audio_resample_hw_write(void *resample, void *data, int len);
|
||||
extern void audio_anc_post_msg_adt(u8 cmd);
|
||||
extern void hw_fft_run(unsigned int fft_config, const int *in, int *out);
|
||||
extern unsigned int hw_fft_config(int N, int log2N, int is_same_addr, int is_ifft, int is_real);
|
||||
//APP调用的ADT函数
|
||||
extern void icsd_adt_start();
|
||||
extern void icsd_adt_anctask_handle(u8 cmd);
|
||||
//APP调用的LIB函数
|
||||
extern void icsd_acoustic_detector_get_libfmt(struct icsd_acoustic_detector_libfmt *libfmt, u8 function);
|
||||
extern void icsd_acoustic_detector_set_infmt(struct icsd_acoustic_detector_infmt *fmt);
|
||||
extern void icsd_acoustic_detector_infmt_updata(struct icsd_acoustic_detector_infmt *fmt);
|
||||
extern void icsd_acoustic_detector_open(void);
|
||||
extern void icsd_acoustic_detector_close();
|
||||
extern void icsd_acoustic_detector_resume(u8 mode, u8 anc_onoff);
|
||||
extern void icsd_acoustic_detector_suspend();
|
||||
extern void icsd_acoustic_detector_ancdma_done();//ancdma done回调
|
||||
extern void icsd_acoustic_detector_mic_input_hdl(void *priv, s16 *buf, int len);
|
||||
extern void icsd_adt_set_audio_sample_rate(u16 sample_rate);
|
||||
//LIB调用的ADT函数
|
||||
extern void icsd_adt_FFT_radix256(int *in_cur, int *out);
|
||||
extern void icsd_adt_FFT_radix128(int *in_cur, int *out);
|
||||
extern void icsd_adt_FFT_radix64(int *in_cur, int *out);
|
||||
extern void icsd_adt_anc_dma_on(u8 out_sel, int *buf, int len);
|
||||
extern void icsd_adt_hw_suspend();
|
||||
extern void icsd_adt_hw_resume();
|
||||
extern void icsd_post_adttask_msg(u8 cmd);
|
||||
extern void icsd_post_srctask_msg(u8 cmd);
|
||||
extern void icsd_adt_src_close(void *resample);
|
||||
extern void *icsd_adt_src_init(int in_rate, int out_rate, int (*handler)(void *, void *, int));
|
||||
extern void icsd_adt_src_push(void *resample);
|
||||
extern void icsd_adt_src_write(void *data, int len, void *resample);
|
||||
extern void icsd_adt_run_output(__adt_result *adt_result);
|
||||
extern void icsd_post_anctask_msg(u8 cmd);
|
||||
extern void icsd_adt_voice_board_data();
|
||||
extern void icsd_adt_tx_unsniff_req();
|
||||
extern u32 icsd_adt_get_tws_state();
|
||||
extern u32 icsd_adt_get_role();
|
||||
extern u8 icsd_get_ang_flag(float *_target_angle);
|
||||
//ADT调用的LIB函数
|
||||
extern void icsd_adt_version();
|
||||
extern void icsd_adt_parm_set(__icsd_adt_parm *_ADT_PARM);
|
||||
extern void icsd_adt_szout_set(float *anc_sz_data, float *anc_pz_data, u8 sz_out_exist);
|
||||
extern void icsd_adt_task_handler(int msg);
|
||||
extern void icsd_src_task_handler(int msg);
|
||||
extern void icsd_adt_s2m_packet(s8 *data, u8 cmd);
|
||||
extern void icsd_adt_m2s_packet(s8 *data, u8 cmd);
|
||||
|
||||
extern void icsd_adt_szout_init();
|
||||
extern void icsd_adt_dma_done();
|
||||
extern void icsd_adt_task_create();
|
||||
extern void icsd_adt_task_kill();
|
||||
extern void icsd_src_task_create();
|
||||
extern void icsd_src_task_kill();
|
||||
extern void icsd_adt_m2s_cb(void *_data, u16 len, bool rx);
|
||||
extern void icsd_adt_s2m_cb(void *_data, u16 len, bool rx);
|
||||
|
||||
extern u8 audio_adt_talk_mic_analog_close();
|
||||
extern u8 audio_adt_talk_mic_analog_open();
|
||||
extern u8 talk_mic_analog_close;
|
||||
|
||||
extern u8 oral_function;
|
||||
extern const u8 adt_errpxx_dB_thr;
|
||||
extern const u8 adt_err_zcv_thr;
|
||||
extern const u8 pwr_inside_even_flag0_thr;
|
||||
extern const u8 angle_err_even_flag0_thr;
|
||||
extern const u8 angle_talk_even_flag0_thr;
|
||||
extern const u16 f1f2_angsum_thr;
|
||||
extern const u16 ADT_DEBUG_INF;
|
||||
#endif
|
||||
1955
apps/common/icsd/adt/icsd_adt_app.c
Normal file
1955
apps/common/icsd/adt/icsd_adt_app.c
Normal file
File diff suppressed because it is too large
Load Diff
189
apps/common/icsd/adt/icsd_adt_app.h
Normal file
189
apps/common/icsd/adt/icsd_adt_app.h
Normal file
@ -0,0 +1,189 @@
|
||||
#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
|
||||
|
||||
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,
|
||||
|
||||
/*对耳信息同步*/
|
||||
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);
|
||||
int audio_icsd_adt_close(u8 adt_mode);
|
||||
int audio_icsd_adt_res_close(u8 adt_mode);
|
||||
/*关闭所有模块*/
|
||||
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
|
||||
296
apps/common/icsd/adt/icsd_adt_client_board.c
Normal file
296
apps/common/icsd/adt/icsd_adt_client_board.c
Normal file
@ -0,0 +1,296 @@
|
||||
#if ADT_CLIENT_BOARD == HT03_HYBRID_6G
|
||||
const u8 ADT_TWS_MODE = 1;
|
||||
//const u8 ADT_DET_VER = 2;
|
||||
//const u8 ADT_PATH_CONFIG = 0;
|
||||
const u8 ADT_DET_VER = 4;
|
||||
const u8 ADT_PATH_CONFIG = ADT_PATH_DAC_SRC_EN;
|
||||
const u8 ADT_EIN_VER = ADT_EIN_TWS_V0;
|
||||
const float ref_gain_sel = 3;
|
||||
const float err_gain_sel = 3;
|
||||
u8 pnc_ref_pwr_thr = 160;
|
||||
u8 pnc_err_pwr_thr = 100;
|
||||
u8 tpc_ref_pwr_thr = 120;
|
||||
u8 tpc_err_pwr_thr = 100;
|
||||
u8 anc_ref_pwr_thr = 120;
|
||||
u8 anc_err_pwr_thr = 100;
|
||||
const float wat_pn_gain = 1;
|
||||
const float wat_bypass_gain = 16;
|
||||
const float wat_anc_gain = 1;
|
||||
const u8 final_speech_even_thr = 4;
|
||||
const float wdac_senc = 1;
|
||||
const float wdac[8] = {1, 1, 0.92, 0.80, 0.67, 0.62, 0.7, 0.7};//播放一笑江湖DJ /100
|
||||
const float wref[8] = {6.78, 3.66, 0.58, 0.37, 0.31, 0.29, 0.28, 0.27};//播放外部噪声
|
||||
const float wref_tran[8] = {1.26, 1.06, 1.06, 1.00, 1.00, 1.18, 1.16, 1.03 };
|
||||
const float wref_ancs[8] = {2.06, 2.00, 0.011, 0.006, 0.009, 0.012, 0.014, 0.018 };
|
||||
const float fdac[8] = {0.18, 0.051, 0.02, 0.02, 0.02, 0.02, 0.02, 0.05};//播放一笑江湖DJ /1000
|
||||
u8 icsd_get_ang_flag(float *_target_angle)
|
||||
{
|
||||
u8 af1 = _target_angle[1] > 15 || _target_angle[1] < -130;
|
||||
u8 af2 = _target_angle[2] > 15 || _target_angle[2] < -130;
|
||||
u8 af3 = _target_angle[3] > 15 || _target_angle[3] < -130;
|
||||
u8 ang_flag = af1 && af2 && af3;
|
||||
return ang_flag;
|
||||
}
|
||||
|
||||
#elif ADT_CLIENT_BOARD == G96_HYBRID
|
||||
const u8 ADT_TWS_MODE = 1;
|
||||
//const u8 ADT_DET_VER = 5;
|
||||
//const u8 ADT_PATH_CONFIG = 0;
|
||||
const u8 ADT_DET_VER = 4;
|
||||
const u8 ADT_PATH_CONFIG = ADT_PATH_DAC_SRC_EN;
|
||||
const u8 ADT_EIN_VER = ADT_EIN_TWS_V0;
|
||||
const float ref_gain_sel = 4;
|
||||
const float err_gain_sel = 1;
|
||||
u8 pnc_ref_pwr_thr = 160;
|
||||
u8 pnc_err_pwr_thr = 100;
|
||||
u8 tpc_ref_pwr_thr = 120;
|
||||
u8 tpc_err_pwr_thr = 100;
|
||||
u8 anc_ref_pwr_thr = 120;
|
||||
u8 anc_err_pwr_thr = 135;
|
||||
const float wat_pn_gain = 2.4;
|
||||
const float wat_bypass_gain = 16;
|
||||
const float wat_anc_gain = 2.5;
|
||||
const u8 final_speech_even_thr = 4;
|
||||
const float wdac_senc = 1;
|
||||
const float wdac[8] = {2.98, 2.29, 1.94, 1.95, 1.76, 1.54, 1.44, 1.29};
|
||||
const float wref[8] = {6.76, 1.98, 1.57, 1.50, 1.41, 1.32, 1.16, 1.02};
|
||||
const float wref_tran[8] = {4.26, 2.36, 2.36, 2.79, 3.00, 3.18, 3.16, 3.03 };
|
||||
const float wref_ancs[8] = {2.06, 2.00, 0.11, 0.06, 0.09, 0.12, 0.14, 0.18 };
|
||||
const float fdac[8] = {0.008, 0.008, 0.008, 0.008, 0.01, 0.01, 0.01, 0.01};
|
||||
u8 icsd_get_ang_flag(float *_target_angle)
|
||||
{
|
||||
u8 af1 = _target_angle[4] < 15 && _target_angle[4] > -150;
|
||||
u8 af2 = _target_angle[2] < 15 && _target_angle[2] > -150;
|
||||
u8 af3 = _target_angle[3] < 15 && _target_angle[3] > -150;
|
||||
u8 ang_flag = af1 && af2 && af3;
|
||||
return ang_flag;
|
||||
}
|
||||
|
||||
#elif ADT_CLIENT_BOARD == G97_HYBRID
|
||||
const u8 ADT_TWS_MODE = 1;
|
||||
const u8 ADT_DET_VER = 3;
|
||||
const u8 ADT_PATH_CONFIG = 0;
|
||||
//const u8 ADT_DET_VER = 4;
|
||||
//const u8 ADT_PATH_CONFIG = ADT_PATH_DAC_SRC_EN;
|
||||
const u8 ADT_EIN_VER = ADT_EIN_UNSUPPORT;
|
||||
const float ref_gain_sel = 2;
|
||||
const float err_gain_sel = 1;
|
||||
u8 pnc_ref_pwr_thr = 160;
|
||||
u8 pnc_err_pwr_thr = 100;
|
||||
u8 tpc_ref_pwr_thr = 120;
|
||||
u8 tpc_err_pwr_thr = 100;
|
||||
u8 anc_ref_pwr_thr = 120;
|
||||
u8 anc_err_pwr_thr = 135;
|
||||
const float wat_pn_gain = 2.88;
|
||||
const float wat_bypass_gain = 19.2;
|
||||
const float wat_anc_gain = 3;
|
||||
const u8 final_speech_even_thr = 4;
|
||||
const float wdac_senc = 1;
|
||||
const float wdac[8] = {10.43, 4.85, 1.36, 1.09, 0.87, 0.71, 0.63, 0.59};
|
||||
const float wref[8] = {7.31, 1.90, 0.43, 0.33, 0.28, 0.25, 0.22, 0.20};
|
||||
const float wref_tran[8] = {8.23, 3.33, 1.72, 1.64, 1.48, 1.30, 1.12, 1.04};
|
||||
const float wref_ancs[8] = {4.62, 1.32, 0.09, 0.06, 0.07, 0.10, 0.13, 0.15 };
|
||||
const float fdac[8] = {0.18, 0.051, 0.02, 0.02, 0.02, 0.02, 0.02, 0.05};
|
||||
u8 icsd_get_ang_flag(float *_target_angle)
|
||||
{
|
||||
u8 af1 = _target_angle[1] < -120 || _target_angle[1] > 20;
|
||||
u8 af2 = _target_angle[2] < -120 || _target_angle[2] > 20;
|
||||
u8 af3 = _target_angle[3] < -120 || _target_angle[3] > 20;
|
||||
u8 ang_flag = af1 && af2 && af3;
|
||||
|
||||
printf("ang:%d %d %d af:%d %d %d\n", (int)_target_angle[1], (int)_target_angle[2], (int)_target_angle[3], af1, af2, af3);
|
||||
return ang_flag;
|
||||
}
|
||||
|
||||
#elif ADT_CLIENT_BOARD == H3_HYBRID
|
||||
const u8 ADT_TWS_MODE = 0;
|
||||
const u8 ADT_DET_VER = 1;
|
||||
const u8 ADT_PATH_CONFIG = 0;
|
||||
const u8 ADT_EIN_VER = ADT_EIN_HEADSET_V0;
|
||||
const float ref_gain_sel = 3;
|
||||
const float err_gain_sel = 3;
|
||||
u8 pnc_ref_pwr_thr = 160;
|
||||
u8 pnc_err_pwr_thr = 100;
|
||||
u8 tpc_ref_pwr_thr = 120;
|
||||
u8 tpc_err_pwr_thr = 100;
|
||||
u8 anc_ref_pwr_thr = 120;
|
||||
u8 anc_err_pwr_thr = 135;
|
||||
const float wat_pn_gain = 1;
|
||||
const float wat_bypass_gain = 16;
|
||||
const float wat_anc_gain = 1;
|
||||
const u8 final_speech_even_thr = 4;
|
||||
const float wdac_senc = 1;
|
||||
const float wref[8] = {6.78, 3.66, 0.58, 0.37, 0.31, 0.29, 0.28, 0.27};
|
||||
const float wdac[8] = {1, 1, 0.92, 0.80, 0.67, 0.62, 0.7, 0.7};
|
||||
const float wref_tran[8] = {4.26, 2.36, 2.36, 2.79, 3.00, 3.18, 3.16, 3.03 };
|
||||
const float wref_ancs[8] = {2.06, 2.00, 0.011, 0.006, 0.009, 0.012, 0.014, 0.018 };
|
||||
const float fdac[8] = {0.18, 0.051, 0.02, 0.02, 0.02, 0.02, 0.02, 0.05};
|
||||
|
||||
#elif ADT_CLIENT_BOARD == ANC05_HYBRID
|
||||
const u8 ADT_TWS_MODE = 0;
|
||||
const u8 ADT_DET_VER = 1;
|
||||
const u8 ADT_PATH_CONFIG = 0;
|
||||
const u8 ADT_EIN_VER = ADT_EIN_UNSUPPORT;
|
||||
const float ref_gain_sel = 3;
|
||||
const float err_gain_sel = 3;
|
||||
u8 pnc_ref_pwr_thr = 160;
|
||||
u8 pnc_err_pwr_thr = 100;
|
||||
u8 tpc_ref_pwr_thr = 120;
|
||||
u8 tpc_err_pwr_thr = 100;
|
||||
u8 anc_ref_pwr_thr = 120;
|
||||
u8 anc_err_pwr_thr = 135;
|
||||
const float wat_pn_gain = 1;
|
||||
const float wat_bypass_gain = 16;
|
||||
const float wat_anc_gain = 1;
|
||||
const u8 final_speech_even_thr = 4;
|
||||
const float wdac_senc = 1;
|
||||
const float wref[8] = {6.78, 3.66, 0.58, 0.37, 0.31, 0.29, 0.28, 0.27};
|
||||
const float wdac[8] = {1, 1, 0.92, 0.80, 0.67, 0.62, 0.7, 0.7};
|
||||
const float wref_tran[8] = {4.26, 2.36, 2.36, 2.79, 3.00, 3.18, 3.16, 3.03 };
|
||||
const float wref_ancs[8] = {2.06, 2.00, 0.011, 0.006, 0.009, 0.012, 0.014, 0.018 };
|
||||
const float fdac[8] = {0.18, 0.051, 0.02, 0.02, 0.02, 0.02, 0.02, 0.05};
|
||||
|
||||
#else
|
||||
const float wdac_senc = 1;
|
||||
const u8 ADT_TWS_MODE = 1;
|
||||
const u8 ADT_DET_VER = 0;
|
||||
const u8 ADT_PATH_CONFIG = 0;
|
||||
const u8 ADT_EIN_VER = ADT_EIN_UNSUPPORT;
|
||||
const float ref_gain_sel = 3;
|
||||
const float err_gain_sel = 3;
|
||||
u8 pnc_ref_pwr_thr = 160;
|
||||
u8 pnc_err_pwr_thr = 100;
|
||||
u8 tpc_ref_pwr_thr = 120;
|
||||
u8 tpc_err_pwr_thr = 100;
|
||||
u8 anc_ref_pwr_thr = 120;
|
||||
u8 anc_err_pwr_thr = 135;
|
||||
const float wat_pn_gain = 1;
|
||||
const float wat_bypass_gain = 16;
|
||||
const float wat_anc_gain = 1;
|
||||
const u8 final_speech_even_thr = 4;
|
||||
const float wref[8] = {6.78, 3.66, 0.58, 0.37, 0.31, 0.29, 0.28, 0.27};
|
||||
const float wdac[8] = {1, 1, 0.92, 0.80, 0.67, 0.62, 0.7, 0.7};
|
||||
const float wref_tran[8] = {4.26, 2.36, 2.36, 2.79, 3.00, 3.18, 3.16, 3.03 };
|
||||
const float wref_ancs[8] = {2.06, 2.00, 0.011, 0.006, 0.009, 0.012, 0.014, 0.018 };
|
||||
const float fdac[8] = {0.18, 0.051, 0.02, 0.02, 0.02, 0.02, 0.02, 0.05};
|
||||
|
||||
#endif
|
||||
|
||||
void icsd_adt_ein_parm_HT03(__icsd_adt_parm *_ADT_PARM)
|
||||
{
|
||||
_ADT_PARM->anc_in_pz_sum = -80;
|
||||
_ADT_PARM->anc_out_pz_sum = 0;
|
||||
_ADT_PARM->anc_in_sz_mean = 1;
|
||||
_ADT_PARM->anc_out_sz_mean = -12;
|
||||
_ADT_PARM->anc_in_fb_sum = 60;
|
||||
_ADT_PARM->anc_out_fb_sum = 30;
|
||||
|
||||
_ADT_PARM->pnc_in_pz_sum = -80;
|
||||
_ADT_PARM->pnc_out_pz_sum = 0;
|
||||
_ADT_PARM->pnc_in_sz_mean = 1;
|
||||
_ADT_PARM->pnc_out_sz_mean = -12;
|
||||
_ADT_PARM->pnc_in_fb_sum = 60;
|
||||
_ADT_PARM->pnc_out_fb_sum = 30;
|
||||
|
||||
_ADT_PARM->trans_in_pz_sum = 2;
|
||||
_ADT_PARM->trans_out_pz_sum = 26;
|
||||
_ADT_PARM->trans_in_sz_mean = 2;
|
||||
_ADT_PARM->trans_out_sz_mean = -7;
|
||||
_ADT_PARM->trans_in_fb_sum = 20;
|
||||
_ADT_PARM->trans_out_fb_sum = -20;
|
||||
}
|
||||
|
||||
void icsd_adt_ein_parm(__icsd_adt_parm *_ADT_PARM)
|
||||
{
|
||||
_ADT_PARM->anc_in_pz_sum = -80;
|
||||
_ADT_PARM->anc_out_pz_sum = 0;
|
||||
_ADT_PARM->anc_in_sz_mean = 1;
|
||||
_ADT_PARM->anc_out_sz_mean = -12;
|
||||
_ADT_PARM->anc_in_fb_sum = 60;
|
||||
_ADT_PARM->anc_out_fb_sum = 30;
|
||||
|
||||
_ADT_PARM->pnc_in_pz_sum = -80;
|
||||
_ADT_PARM->pnc_out_pz_sum = 0;
|
||||
_ADT_PARM->pnc_in_sz_mean = 1;
|
||||
_ADT_PARM->pnc_out_sz_mean = -12;
|
||||
_ADT_PARM->pnc_in_fb_sum = 60;
|
||||
_ADT_PARM->pnc_out_fb_sum = 30;
|
||||
|
||||
_ADT_PARM->trans_in_pz_sum = 2;
|
||||
_ADT_PARM->trans_out_pz_sum = 26;
|
||||
_ADT_PARM->trans_in_sz_mean = 2;
|
||||
_ADT_PARM->trans_out_sz_mean = -7;
|
||||
_ADT_PARM->trans_in_fb_sum = 20;
|
||||
_ADT_PARM->trans_out_fb_sum = -20;
|
||||
}
|
||||
|
||||
void icsd_adt_voice_board_data()
|
||||
{
|
||||
__icsd_adt_parm *ADT_PARM;
|
||||
|
||||
ADT_PARM = zalloc(sizeof(__icsd_adt_parm));
|
||||
#if ADT_CLIENT_BOARD == HT03_HYBRID_6G
|
||||
adt_printf("ADT HT03\n");
|
||||
extern const float HT03_ADT_FLOAT_DATA[];
|
||||
extern const float HT03_sz_out_data[28];
|
||||
extern const float HT03_pz_out_data[28];
|
||||
ADT_PARM->adt_float_data = (void *)HT03_ADT_FLOAT_DATA;
|
||||
ADT_PARM->sz_inptr = (float *)HT03_sz_out_data;
|
||||
ADT_PARM->pz_inptr = (float *)HT03_pz_out_data;
|
||||
icsd_adt_ein_parm_HT03(ADT_PARM);
|
||||
|
||||
#elif ADT_CLIENT_BOARD == G96_HYBRID
|
||||
adt_printf("ADT G96\n");
|
||||
extern const float G96_ADT_FLOAT_DATA[];
|
||||
extern const float G96_sz_out_data[28];
|
||||
extern const float G96_pz_out_data[28];
|
||||
ADT_PARM->adt_float_data = (void *)G96_ADT_FLOAT_DATA;
|
||||
ADT_PARM->sz_inptr = (float *)G96_sz_out_data;
|
||||
ADT_PARM->pz_inptr = (float *)G96_pz_out_data;
|
||||
icsd_adt_ein_parm(ADT_PARM);
|
||||
|
||||
#elif ADT_CLIENT_BOARD == G97_HYBRID
|
||||
adt_printf("ADT G97\n");
|
||||
extern const float G97_ADT_FLOAT_DATA[];
|
||||
extern const float G97_sz_out_data[28];
|
||||
extern const float G97_pz_out_data[28];
|
||||
ADT_PARM->adt_float_data = (void *)G97_ADT_FLOAT_DATA;
|
||||
ADT_PARM->sz_inptr = (float *)G97_sz_out_data;
|
||||
ADT_PARM->pz_inptr = (float *)G97_pz_out_data;
|
||||
icsd_adt_ein_parm(ADT_PARM);
|
||||
|
||||
#elif ADT_CLIENT_BOARD == H3_HYBRID
|
||||
adt_printf("ADT H3\n");
|
||||
extern const float H3_ADT_FLOAT_DATA[];
|
||||
extern const float H3_sz_out_data[28];
|
||||
extern const float H3_pz_out_data[28];
|
||||
ADT_PARM->adt_float_data = (void *)H3_ADT_FLOAT_DATA;
|
||||
ADT_PARM->sz_inptr = (float *)H3_sz_out_data;
|
||||
ADT_PARM->pz_inptr = (float *)H3_pz_out_data;
|
||||
icsd_adt_ein_parm(ADT_PARM);
|
||||
|
||||
#elif ADT_CLIENT_BOARD == ANC05_HYBRID
|
||||
adt_printf("ADT ANC05\n");
|
||||
extern const float ANC05_ADT_FLOAT_DATA[];
|
||||
extern const float ANC05_sz_out_data[28];
|
||||
extern const float ANC05_pz_out_data[28];
|
||||
ADT_PARM->adt_float_data = (void *)ANC05_ADT_FLOAT_DATA;
|
||||
ADT_PARM->sz_inptr = (float *)ANC05_sz_out_data;
|
||||
ADT_PARM->pz_inptr = (float *)ANC05_pz_out_data;
|
||||
icsd_adt_ein_parm(ADT_PARM);
|
||||
|
||||
#else
|
||||
adt_printf("ADT XXX\n");
|
||||
#endif
|
||||
|
||||
icsd_adt_parm_set(ADT_PARM);
|
||||
free(ADT_PARM);
|
||||
|
||||
icsd_adt_szout_init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
457
apps/common/icsd/anc/icsd_anc.h
Normal file
457
apps/common/icsd/anc/icsd_anc.h
Normal 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"
|
||||
|
||||
#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
|
||||
756
apps/common/icsd/anc/icsd_anc_app.c
Normal file
756
apps/common/icsd/anc/icsd_anc_app.c
Normal file
@ -0,0 +1,756 @@
|
||||
#include "icsd_anc_app.h"
|
||||
#include "classic/tws_api.h"
|
||||
#include "board_config.h"
|
||||
#include "tone_player.h"
|
||||
#include "adv_adaptive_noise_reduction.h"
|
||||
#include "audio_anc.h"
|
||||
#include "asm/audio_src.h"
|
||||
#include "icsd_anc_user.h"
|
||||
|
||||
#if 1
|
||||
#define icsd_anc_log printf
|
||||
#else
|
||||
#define icsd_anc_log(...)
|
||||
#endif/*log_en*/
|
||||
|
||||
#if TCFG_AUDIO_ANC_EAR_ADAPTIVE_EN
|
||||
|
||||
#if (ICSD_ANC_MODE == TWS_TONE_BYPASS_MODE) || \
|
||||
(ICSD_ANC_MODE == TWS_TONE_MODE) || \
|
||||
(ICSD_ANC_MODE == TWS_BYPASS_MODE)
|
||||
const u8 TWS_MODE = 1;
|
||||
#else
|
||||
const u8 TWS_MODE = 0;
|
||||
#endif/**/
|
||||
#if (ICSD_ANC_MODE == HEADSET_TONE_BYPASS_MODE) || \
|
||||
(ICSD_ANC_MODE == HEADSET_BYPASS_MODE) || \
|
||||
(ICSD_ANC_MODE == HEADSET_TONES_MODE)
|
||||
const u8 HEADSET_MODE = 1;
|
||||
#else
|
||||
const u8 HEADSET_MODE = 0;
|
||||
#endif/**/
|
||||
|
||||
const u8 ICSD_ANC_DEBUG = ICSD_ANC_DEBUG_TYPE;
|
||||
u32 train_time;
|
||||
struct icsd_anc_board_param *ANC_BOARD_PARAM = NULL;
|
||||
volatile struct icsd_anc_tool_data *TOOL_DATA = NULL;
|
||||
volatile struct icsd_anc_backup *CFG_BACKUP = NULL;
|
||||
volatile struct icsd_anc ICSD_ANC;
|
||||
volatile u8 icsd_anc_contral = 0;
|
||||
volatile u8 icsd_anc_function = 0;
|
||||
int *user_train_buf = 0;
|
||||
volatile int user_train_state = 0;
|
||||
u16 icsd_time_out_hdl = 0;
|
||||
u8 icsd_anc_combination_test;
|
||||
u8 icsd_anc_train_test;
|
||||
int icsd_anc_id = 0;
|
||||
u8 icsd_anc_tws_balance_en = 0;
|
||||
|
||||
|
||||
int (*anc_printf)(const char *format, ...);
|
||||
int anc_printf_off(const char *format, ...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define TWS_FUNC_ID_SDANC_M2S TWS_FUNC_ID('I', 'C', 'M', 'S')
|
||||
REGISTER_TWS_FUNC_STUB(icsd_anc_m2s) = {
|
||||
.func_id = TWS_FUNC_ID_SDANC_M2S,
|
||||
.func = icsd_anc_m2s_cb,
|
||||
};
|
||||
|
||||
#define TWS_FUNC_ID_SDANC_S2M TWS_FUNC_ID('I', 'C', 'S', 'M')
|
||||
REGISTER_TWS_FUNC_STUB(icsd_anc_s2m) = {
|
||||
.func_id = TWS_FUNC_ID_SDANC_S2M,
|
||||
.func = icsd_anc_s2m_cb,
|
||||
};
|
||||
|
||||
#define TWS_FUNC_ID_SDANC_MSYNC TWS_FUNC_ID('I', 'C', 'M', 'N')
|
||||
REGISTER_TWS_FUNC_STUB(icsd_anc_msync) = {
|
||||
.func_id = TWS_FUNC_ID_SDANC_MSYNC,
|
||||
.func = icsd_anc_msync_cb,
|
||||
};
|
||||
|
||||
#define TWS_FUNC_ID_SDANC_SSYNC TWS_FUNC_ID('I', 'C', 'S', 'N')
|
||||
REGISTER_TWS_FUNC_STUB(icsd_anc_ssync) = {
|
||||
.func_id = TWS_FUNC_ID_SDANC_SSYNC,
|
||||
.func = icsd_anc_ssync_cb,
|
||||
};
|
||||
|
||||
void icsd_anc_tws_msync(u8 cmd)
|
||||
{
|
||||
struct icsd_anc_tws_packet packet;
|
||||
icsd_anc_msync_packet(&packet, cmd);
|
||||
anc_printf("msync:%d %d\n", packet.len, packet.data[0]);
|
||||
int ret = tws_api_send_data_to_sibling(packet.data, packet.len, TWS_FUNC_ID_SDANC_MSYNC);
|
||||
}
|
||||
|
||||
void icsd_anc_tws_ssync(u8 cmd)
|
||||
{
|
||||
struct icsd_anc_tws_packet packet;
|
||||
icsd_anc_ssync_packet(&packet, cmd);
|
||||
anc_printf("ssync:%d %d\n", packet.len, packet.data[0]);
|
||||
int ret = tws_api_send_data_to_sibling(packet.data, packet.len, TWS_FUNC_ID_SDANC_SSYNC);
|
||||
}
|
||||
|
||||
void icsd_anc_tws_m2s(u8 cmd)
|
||||
{
|
||||
s8 data[16];
|
||||
icsd_anc_m2s_packet(data, cmd);
|
||||
int ret = tws_api_send_data_to_sibling(data, 16, TWS_FUNC_ID_SDANC_M2S);
|
||||
}
|
||||
|
||||
void icsd_anc_tws_s2m(u8 cmd)
|
||||
{
|
||||
s8 data[16];
|
||||
icsd_anc_s2m_packet(data, cmd);
|
||||
int ret = tws_api_send_data_to_sibling(data, 16, TWS_FUNC_ID_SDANC_S2M);
|
||||
}
|
||||
|
||||
float anc_pow10(float n)
|
||||
{
|
||||
float pow10n = exp_float((float)n / log10_float(exp_float((float)1.0)));
|
||||
return pow10n;
|
||||
}
|
||||
|
||||
void icsd_anc_fgq_printf(float *ptr)
|
||||
{
|
||||
icsd_anc_log("icsd_anc_fgq\n");
|
||||
for (int i = 0; i < ANC_VMDATA_FF_RECORD_SIZE; i++) {
|
||||
icsd_anc_log("%d\n", (int)((*ptr++) * 1000));
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_anc_aabb_printf(double *iir_ab)
|
||||
{
|
||||
icsd_anc_log("icsd_anc_aabb\n");
|
||||
for (int i = 0; i < ANC_BOARD_PARAM->fb_yorder; i++) {
|
||||
icsd_anc_log("AB:%d %d %d %d %d\n", (int)(iir_ab[i * 5] * 100000000),
|
||||
(int)(iir_ab[i * 5 + 1] * 100000000),
|
||||
(int)(iir_ab[i * 5 + 2] * 100000000),
|
||||
(int)(iir_ab[i * 5 + 3] * 100000000),
|
||||
(int)(iir_ab[i * 5 + 4] * 100000000));
|
||||
}
|
||||
//put_buf(iir_ab, 8 * 40);
|
||||
}
|
||||
|
||||
void icsd_anc_forced_exit()
|
||||
{
|
||||
if (!(icsd_anc_contral & ICSD_ANC_FORCED_EXIT)) {
|
||||
icsd_printf("icsd_anc_forced_exit----------------------------\n");
|
||||
if (icsd_anc_contral & ICSD_ANC_INITED) {
|
||||
icsd_anc_contral |= ICSD_ANC_FORCED_EXIT;
|
||||
audio_anc_post_msg_icsd_anc_cmd(ANC_CMD_FORCED_EXIT);
|
||||
} else {
|
||||
icsd_anc_contral |= ICSD_ANC_FORCED_BEFORE_INIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_anc_train_timeout()
|
||||
{
|
||||
icsd_anc_log("icsd_anc_train_timeout\n");
|
||||
user_train_state &= ~ANC_USER_TRAIN_RUN;
|
||||
user_train_state |= ANC_TRAIN_TIMEOUT;
|
||||
audio_anc_post_msg_user_train_timeout();
|
||||
}
|
||||
|
||||
u32 icsd_anc_get_role()
|
||||
{
|
||||
return tws_api_get_role();
|
||||
}
|
||||
|
||||
u32 icsd_anc_get_tws_state()
|
||||
{
|
||||
if (icsd_anc_tws_balance_en) {
|
||||
return tws_api_get_tws_state();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void icsd_anc_set_alogm(void *_param, int alogm)
|
||||
{
|
||||
audio_anc_t *param = _param;
|
||||
param->gains.alogm = alogm;
|
||||
}
|
||||
|
||||
void icsd_anc_set_micgain(void *_param, int lff_gain, int lfb_gain)
|
||||
{
|
||||
//0 ~ 15
|
||||
audio_anc_t *param = _param;
|
||||
icsd_anc_log("mic gain set:%d %d-->%d %d\n", param->gains.l_ffmic_gain, param->gains.l_fbmic_gain, lff_gain, lfb_gain);
|
||||
param->gains.l_ffmic_gain = lff_gain;
|
||||
param->gains.l_fbmic_gain = lfb_gain;
|
||||
audio_anc_mic_management(param);
|
||||
audio_anc_mic_gain(param->mic_param, 0);
|
||||
}
|
||||
|
||||
void icsd_anc_fft(int *in, int *out)
|
||||
{
|
||||
u32 fft_config;
|
||||
fft_config = hw_fft_config(1024, 10, 1, 0, 1);
|
||||
hw_fft_run(fft_config, in, out);
|
||||
}
|
||||
void icsd_anc_fft256(int *in, int *out)
|
||||
{
|
||||
u32 fft_config;
|
||||
fft_config = hw_fft_config(256, 8, 1, 0, 1);
|
||||
hw_fft_run(fft_config, in, out);
|
||||
}
|
||||
void icsd_anc_fade(void *_param)
|
||||
{
|
||||
audio_anc_t *param = _param;
|
||||
audio_anc_fade2(param->anc_fade_gain, param->anc_fade_en, 1, 0);
|
||||
}
|
||||
|
||||
void icsd_anc_long_fade(void *_param)
|
||||
{
|
||||
audio_anc_t *param = _param;
|
||||
audio_anc_fade2(0, param->anc_fade_en, 4, 0); //增益先淡出到0
|
||||
os_time_dly(10);//10
|
||||
}
|
||||
|
||||
void icsd_anc_user_train_dma_on(u8 out_sel, u32 len, int *buf)
|
||||
{
|
||||
user_train_state |= ANC_TRAIN_DMA_ON;
|
||||
anc_dma_on(out_sel, buf, len);
|
||||
}
|
||||
|
||||
void icsd_anc_dma_done()
|
||||
{
|
||||
if (ICSD_ANC.adaptive_run_busy) {
|
||||
if (user_train_state & ANC_USER_TRAIN_DMA_EN) {
|
||||
if (user_train_state & ANC_USER_TRAIN_DMA_READY) {
|
||||
user_train_state &= ~ANC_USER_TRAIN_DMA_READY;
|
||||
anc_core_dma_stop();
|
||||
audio_anc_post_msg_user_train_run();
|
||||
} else {
|
||||
user_train_state |= ANC_USER_TRAIN_DMA_READY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void *anc_ram_addr = 0;
|
||||
void sd_anc_exit()
|
||||
{
|
||||
if (anc_ram_addr) {
|
||||
free(anc_ram_addr);
|
||||
anc_ram_addr = 0;
|
||||
}
|
||||
printf("sd_anc_exit");
|
||||
mem_stats();
|
||||
}
|
||||
void sd_anc_init()
|
||||
{
|
||||
anc_printf = _anc_printf;
|
||||
printf("sd anc init\n");
|
||||
mem_stats();
|
||||
struct icsd_anc_libfmt libfmt;
|
||||
icsd_anc_get_libfmt(&libfmt, SD_ANC_TWS);
|
||||
if (anc_ram_addr == 0) {
|
||||
anc_ram_addr = zalloc(libfmt.lib_alloc_size);
|
||||
}
|
||||
struct icsd_anc_infmt infmt;
|
||||
infmt.alloc_ptr = anc_ram_addr;
|
||||
icsd_anc_set_infmt(&infmt);
|
||||
printf("ram init:%d\n", libfmt.lib_alloc_size);
|
||||
}
|
||||
|
||||
void icsd_anc_init(audio_anc_t *param, u8 mode, u8 seq, int tone_delay, u8 tws_balance_en)
|
||||
{
|
||||
sd_anc_init();
|
||||
anc_printf = _anc_printf;
|
||||
icsd_anc_contral |= ICSD_ANC_INITED;
|
||||
if (icsd_anc_contral & ICSD_ANC_FORCED_BEFORE_INIT) {
|
||||
icsd_anc_contral &= ~ICSD_ANC_FORCED_BEFORE_INIT;
|
||||
icsd_anc_forced_exit();
|
||||
}
|
||||
if (icsd_anc_contral & ICSD_ANC_FORCED_EXIT) {
|
||||
icsd_printf("icsd_anc_init FORCED EXIT\n");
|
||||
return;
|
||||
}
|
||||
icsd_anc_id = seq;
|
||||
icsd_anc_tws_balance_en = tws_balance_en;
|
||||
icsd_anc_log("sd anc init:%d, seq %d, tone_delay %d, tws_balance %d ======================================\n", seq, tone_delay, icsd_anc_id, tws_balance_en);
|
||||
mem_stats();
|
||||
user_train_state = 0;
|
||||
icsd_anc_function = 0;
|
||||
if (mode == 1) {
|
||||
user_train_state |= ANC_USER_TRAIN_TOOL_DATA;
|
||||
icsd_anc_tool_data_init();
|
||||
}
|
||||
user_train_state |= ANC_TRAIN_TONE_PLAY;
|
||||
icsd_anc_combination_test = TEST_ANC_COMBINATION;
|
||||
icsd_anc_train_test = TEST_ANC_TRAIN;
|
||||
#if ANC_USER_TRAIN_TONE_MODE
|
||||
user_train_state |= ANC_USER_TRAIN_TONEMODE;
|
||||
#endif
|
||||
#if HEADSET_TONES_MODE_BYPASS_OFF
|
||||
user_train_state |= ANC_TONESMODE_BYPASS_OFF;
|
||||
#endif
|
||||
#if ANC_ADAPTIVE_CMP_EN
|
||||
icsd_anc_function |= ANC_ADAPTIVE_CMP;
|
||||
#endif
|
||||
#if ANC_EARPHONE_CHECK_EN
|
||||
icsd_anc_function |= ANC_EARPHONE_CHECK;
|
||||
#endif
|
||||
|
||||
ICSD_ANC.param = param;
|
||||
ICSD_ANC.adaptive_run_busy = 1;
|
||||
ICSD_ANC.anc_fade_gain = ¶m->anc_fade_gain;
|
||||
ICSD_ANC.gains_l_ffgain = ¶m->gains.l_ffgain;
|
||||
ICSD_ANC.gains_l_fbgain = ¶m->gains.l_fbgain;
|
||||
ICSD_ANC.gains_l_cmpgain = ¶m->gains.l_cmpgain;
|
||||
ICSD_ANC.gains_r_ffgain = ¶m->gains.r_ffgain;
|
||||
ICSD_ANC.gains_r_fbgain = ¶m->gains.r_fbgain;
|
||||
ICSD_ANC.gains_r_cmpgain = ¶m->gains.r_cmpgain;
|
||||
ICSD_ANC.lff_yorder = ¶m->lff_yorder;
|
||||
ICSD_ANC.lfb_yorder = ¶m->lfb_yorder;
|
||||
ICSD_ANC.lcmp_yorder = ¶m->lcmp_yorder;
|
||||
ICSD_ANC.rff_yorder = ¶m->rff_yorder;
|
||||
ICSD_ANC.rfb_yorder = ¶m->rfb_yorder;
|
||||
ICSD_ANC.rcmp_yorder = ¶m->rcmp_yorder;
|
||||
ICSD_ANC.lff_coeff = ¶m->lff_coeff;
|
||||
ICSD_ANC.lfb_coeff = ¶m->lfb_coeff;
|
||||
ICSD_ANC.lcmp_coeff = ¶m->lcmp_coeff;
|
||||
ICSD_ANC.rff_coeff = ¶m->rff_coeff;
|
||||
ICSD_ANC.rfb_coeff = ¶m->rfb_coeff;
|
||||
ICSD_ANC.rcmp_coeff = ¶m->rcmp_coeff;
|
||||
ICSD_ANC.gains_l_ffmic_gain = ¶m->gains.l_ffmic_gain;
|
||||
ICSD_ANC.gains_l_fbmic_gain = ¶m->gains.l_fbmic_gain;
|
||||
ICSD_ANC.gains_r_ffmic_gain = ¶m->gains.r_ffmic_gain;
|
||||
ICSD_ANC.gains_r_fbmic_gain = ¶m->gains.r_fbmic_gain;
|
||||
ICSD_ANC.gains_alogm = (int *)(¶m->gains.alogm);
|
||||
ICSD_ANC.ff_1st_dcc = ¶m->gains.ff_1st_dcc;
|
||||
ICSD_ANC.fb_1st_dcc = ¶m->gains.fb_1st_dcc;
|
||||
ICSD_ANC.ff_2nd_dcc = ¶m->gains.ff_2nd_dcc;
|
||||
ICSD_ANC.fb_2nd_dcc = ¶m->gains.fb_2nd_dcc;
|
||||
ICSD_ANC.gains_drc_en = ¶m->gains.drc_en;
|
||||
|
||||
ICSD_ANC.mode = ANC_USER_TRAIN_MODE;
|
||||
ICSD_ANC.train_index = 0;
|
||||
ICSD_ANC.adaptive_run_busy = 1;
|
||||
|
||||
icsd_anc_board_config();
|
||||
user_train_state |= ANC_USER_TRAIN_DMA_EN;
|
||||
TOOL_DATA->save_idx = 0xff;
|
||||
ANC_BOARD_PARAM->iir_mode = ANC_USER_TRAIN_MODE;
|
||||
ANC_BOARD_PARAM->tool_ffgain_sign = 1;
|
||||
ANC_BOARD_PARAM->tool_fbgain_sign = 1;
|
||||
if (param->gains.gain_sign & ANCL_FF_SIGN) {
|
||||
ANC_BOARD_PARAM->tool_ffgain_sign = -1;
|
||||
}
|
||||
if (param->gains.gain_sign & ANCL_FB_SIGN) {
|
||||
ANC_BOARD_PARAM->tool_fbgain_sign = -1;
|
||||
}
|
||||
|
||||
//金机曲线功能==================================
|
||||
#if 1
|
||||
icsd_anc_log("ref en:%d----------------------\n", param->gains.adaptive_ref_en);
|
||||
struct icsd_fb_ref *fb_parm = NULL;
|
||||
struct icsd_ff_ref *ff_parm = NULL;
|
||||
if (param->gains.adaptive_ref_en) {
|
||||
icsd_anc_log("get ref data\n");
|
||||
anc_adaptive_fb_ref_data_get((u8 **)(&fb_parm));
|
||||
anc_adaptive_ff_ref_data_get((u8 **)(&ff_parm));
|
||||
ANC_BOARD_PARAM->m_value_l = fb_parm->m_value;
|
||||
ANC_BOARD_PARAM->sen_l = fb_parm->sen;
|
||||
ANC_BOARD_PARAM->in_q_l = fb_parm->in_q;
|
||||
icsd_anc_log("fb_parm:%d %d %d\n", (int)(fb_parm->m_value * 1000), (int)(fb_parm->sen * 1000), (int)(fb_parm->in_q * 1000));
|
||||
}
|
||||
if (ff_parm) {
|
||||
icsd_anc_log("use gold curve==========================================================\n");
|
||||
ANC_BOARD_PARAM->gold_curve_en = param->gains.adaptive_ref_en;
|
||||
ANC_BOARD_PARAM->mse_tar = ff_parm->db;
|
||||
}
|
||||
#endif
|
||||
//==============================================
|
||||
icsd_anc_config_inf();
|
||||
icsd_anc_lib_init();
|
||||
icsd_anc_set_alogm(param, ANC_USER_TRAIN_SR_SEL);
|
||||
ICSD_ANC.tone_delay = tone_delay;
|
||||
icsd_anc_mode_init(tone_delay);
|
||||
|
||||
}
|
||||
|
||||
void icsd_anc_init_cmd()
|
||||
{
|
||||
icsd_anc_log("icsd_anc_init_cmd\n");
|
||||
extern void audio_anc_post_msg_user_train_init(u8 mode);
|
||||
audio_anc_post_msg_user_train_init(ANC_ON);
|
||||
}
|
||||
|
||||
|
||||
u32 icsd_slience_frames;
|
||||
u16 icsd_sample_rate;
|
||||
void icsd_anctone_dacon_handler()
|
||||
{
|
||||
u32 slience_frames = icsd_slience_frames;
|
||||
u16 sample_rate = icsd_sample_rate;
|
||||
if (icsd_anc_contral & ICSD_ANC_FORCED_EXIT) {
|
||||
icsd_printf("icsd_anctone_dacon FORCED EXIT\n");
|
||||
return;
|
||||
}
|
||||
if (user_train_state & ANC_TRAIN_TONE_PLAY) {
|
||||
icsd_anc_board_param_init();
|
||||
ANC_BOARD_PARAM->mode = ICSD_ANC_MODE;
|
||||
icsd_anc_log("icsd_anctone_dacon 1:%d %d %d\n", (int)jiffies, slience_frames, sample_rate);
|
||||
user_train_state |= ANC_TONE_DAC_ON;
|
||||
user_train_state &= ~ANC_TRAIN_TONE_PLAY;
|
||||
u32 slience_ms = 0;
|
||||
if ((slience_frames != 0) && (sample_rate != 0)) {
|
||||
slience_ms = (slience_frames * 1000 / sample_rate) + 1;
|
||||
icsd_anc_log("icsd_anctone_dacon 2:%d %d %d\n", slience_frames, sample_rate, slience_ms);
|
||||
}
|
||||
ANC_BOARD_PARAM->tone_jiff = jiffies + (slience_ms / 10) + 1;
|
||||
ICSD_ANC.dac_on_jiff = jiffies;
|
||||
ICSD_ANC.dac_on_slience = slience_ms;
|
||||
if (user_train_state & ANC_TONE_ANC_READY) {
|
||||
icsd_anc_log("dac on set tonemode start timeout:%d %d\n", slience_ms, ANC_BOARD_PARAM->tone_jiff);
|
||||
switch (ANC_BOARD_PARAM->mode) {
|
||||
case HEADSET_TONES_MODE:
|
||||
sys_hi_timeout_add((void *)icsd_anc_id, icsd_anc_tonel_start, slience_ms + TONEL_DELAY);
|
||||
sys_hi_timeout_add((void *)icsd_anc_id, icsd_anc_toner_start, slience_ms + TONER_DELAY);
|
||||
sys_hi_timeout_add((void *)icsd_anc_id, icsd_anc_pzl_start, slience_ms + PZL_DELAY);
|
||||
sys_hi_timeout_add((void *)icsd_anc_id, icsd_anc_pzr_start, slience_ms + PZR_DELAY);
|
||||
break;
|
||||
default:
|
||||
sys_hi_timeout_add((void *)icsd_anc_id, icsd_anc_tonemode_start, slience_ms + ICSD_ANC.tone_delay);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
icsd_anc_log("dac on wait anc ready\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_anctone_dacon(u32 slience_frames, u16 sample_rate)
|
||||
{
|
||||
icsd_slience_frames = slience_frames;
|
||||
icsd_sample_rate = sample_rate;
|
||||
audio_anc_post_msg_icsd_anc_cmd(ANC_CMD_TONE_DACON);
|
||||
}
|
||||
|
||||
void icsd_anc_tone_play_start()
|
||||
{
|
||||
#if ANC_USER_TRAIN_TONE_MODE
|
||||
icsd_anc_log("icsd_anc_tone_play_start\n");
|
||||
user_train_state |= ANC_TRAIN_TONE_PLAY;
|
||||
icsd_anc_init_cmd();
|
||||
os_time_dly(20);
|
||||
#endif
|
||||
}
|
||||
|
||||
u8 icsd_anc_adaptive_busy_flag_get(void)
|
||||
{
|
||||
return ICSD_ANC.adaptive_run_busy;
|
||||
}
|
||||
|
||||
#if ANC_EAR_RECORD_EN
|
||||
/* float vmdata_FL[EAR_RECORD_MAX][25]; */
|
||||
/* float vmdata_FR[EAR_RECORD_MAX][25]; */
|
||||
float (*vmdata_FL)[ANC_VMDATA_FF_RECORD_SIZE] = NULL;
|
||||
float (*vmdata_FR)[ANC_VMDATA_FF_RECORD_SIZE] = NULL;
|
||||
int *vmdata_num;
|
||||
|
||||
void icsd_anc_vmdata_init(float (*FL)[ANC_VMDATA_FF_RECORD_SIZE], float (*FR)[ANC_VMDATA_FF_RECORD_SIZE], int *num)
|
||||
{
|
||||
//读取耳道记忆 VM数据地址
|
||||
vmdata_FL = FL;
|
||||
vmdata_FR = FR;
|
||||
vmdata_num = num;
|
||||
/* icsd_anc_log("vmdata_num %d\n", *vmdata_num); */
|
||||
/* put_buf((u8*)vmdata_FL, EAR_RECORD_MAX*ANC_VMDATA_FF_RECORD_SIZE*4); */
|
||||
/* put_buf((u8*)vmdata_FR, EAR_RECORD_MAX*ANC_VMDATA_FF_RECORD_SIZE*4); */
|
||||
}
|
||||
|
||||
void icsd_anc_vmdata_num_reset()
|
||||
{
|
||||
if ((!vmdata_FL) || (!vmdata_FR)) {
|
||||
return;
|
||||
}
|
||||
*vmdata_num = 0;
|
||||
memset(vmdata_FL, 0, EAR_RECORD_MAX * 4 * ANC_VMDATA_FF_RECORD_SIZE);
|
||||
}
|
||||
|
||||
u8 icsd_anc_get_vmdata_num()
|
||||
{
|
||||
return *vmdata_num;
|
||||
}
|
||||
|
||||
void icsd_anc_ear_record_printf()
|
||||
{
|
||||
int i;
|
||||
if ((!vmdata_FL) || (!vmdata_FR)) {
|
||||
return;
|
||||
}
|
||||
icsd_anc_log("vmdata_num:%d\n", *vmdata_num);
|
||||
for (i = 0; i < EAR_RECORD_MAX; i++) {
|
||||
icsd_anc_log("vmdata_FL[%d]\n", i);
|
||||
icsd_anc_fgq_printf(&vmdata_FL[i][0]);
|
||||
}
|
||||
for (i = 0; i < EAR_RECORD_MAX; i++) {
|
||||
icsd_anc_log("vmdata_FR[%d]\n", i);
|
||||
icsd_anc_fgq_printf(&vmdata_FR[i][0]);
|
||||
}
|
||||
}
|
||||
|
||||
u8 icsd_anc_max_diff_idx()
|
||||
{
|
||||
u8 max_diff_idx = 0;
|
||||
if ((!vmdata_FL) || (!vmdata_FR)) {
|
||||
return max_diff_idx;
|
||||
}
|
||||
if (*vmdata_num > 0) {
|
||||
float diff;
|
||||
float max_diff = icsd_anc_vmdata_match(&vmdata_FL[0][0], vmdata_FL[0][0]);
|
||||
max_diff_idx = 0;
|
||||
for (int i = 1; i < *vmdata_num; i++) {
|
||||
diff = icsd_anc_vmdata_match(&vmdata_FL[i][0], vmdata_FL[i][0]);
|
||||
if (diff > max_diff) {
|
||||
max_diff = diff;
|
||||
max_diff_idx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
icsd_anc_log("max diff idx:%d\n", max_diff_idx);
|
||||
return max_diff_idx;
|
||||
}
|
||||
|
||||
u8 icsd_anc_min_diff_idx()
|
||||
{
|
||||
float diff;
|
||||
float min_diff;
|
||||
u8 min_diff_idx = 0xff;
|
||||
|
||||
if ((!vmdata_FL) || (!vmdata_FR)) {
|
||||
return min_diff_idx;
|
||||
}
|
||||
if (*vmdata_num > 0) {
|
||||
min_diff = icsd_anc_vmdata_match(&vmdata_FL[0][0], vmdata_FL[0][0]);
|
||||
min_diff_idx = 0;
|
||||
icsd_anc_log("DIFF[0]:%d\n", (int)(min_diff * 1000));
|
||||
for (int i = 1; i < *vmdata_num; i++) {
|
||||
diff = icsd_anc_vmdata_match(&vmdata_FL[i][0], vmdata_FL[i][0]);
|
||||
if (diff < min_diff) {
|
||||
min_diff = diff;
|
||||
min_diff_idx = i;
|
||||
}
|
||||
icsd_anc_log("DIFF[%d]:%d %d %d\n", i, (int)(diff * 1000), min_diff_idx, (int)(min_diff * 1000));
|
||||
}
|
||||
diff = icsd_anc_default_match();
|
||||
icsd_anc_log("default diff:%d vmmin diff:%d\n", (int)(diff * 100), (int)(min_diff * 100));
|
||||
if (diff < min_diff) {
|
||||
icsd_anc_log("use default\n");
|
||||
min_diff_idx = 0xff;
|
||||
} else {
|
||||
icsd_anc_log("select vmdata_FL[%d]\n", min_diff_idx);
|
||||
}
|
||||
}
|
||||
return min_diff_idx;
|
||||
}
|
||||
|
||||
u8 icsd_anc_get_save_idx()
|
||||
{
|
||||
u8 save_idx = 0;
|
||||
if (*vmdata_num < EAR_RECORD_MAX) {
|
||||
save_idx = *vmdata_num;
|
||||
} else {
|
||||
save_idx = icsd_anc_max_diff_idx();
|
||||
}
|
||||
icsd_anc_log("icsd_anc_get_save_idx:%d\n", save_idx);
|
||||
return save_idx;
|
||||
}
|
||||
|
||||
void icsd_anc_save_with_idx(u8 save_idx)
|
||||
{
|
||||
anc_printf("save try:%d %d\n", save_idx, *vmdata_num);
|
||||
if ((!vmdata_FL) || (!vmdata_FR)) {
|
||||
return;
|
||||
}
|
||||
if (save_idx > *vmdata_num) {
|
||||
return;
|
||||
}
|
||||
if ((save_idx >= 0) && (save_idx < EAR_RECORD_MAX)) {
|
||||
if (*vmdata_num < EAR_RECORD_MAX) {
|
||||
(*vmdata_num)++;
|
||||
}
|
||||
anc_printf("icsd_anc_save_with_idx:%d %d====================================================\n", save_idx, *vmdata_num);
|
||||
switch (ANC_BOARD_PARAM->mode) {
|
||||
case HEADSET_TONE_BYPASS_MODE:
|
||||
case HEADSET_TONES_MODE:
|
||||
case HEADSET_BYPASS_MODE:
|
||||
memcpy(&vmdata_FL[save_idx][0], TOOL_DATA->data_out5, 4 * ANC_VMDATA_FF_RECORD_SIZE);
|
||||
memcpy(&vmdata_FR[save_idx][0], TOOL_DATA->data_out10, 4 * ANC_VMDATA_FF_RECORD_SIZE);
|
||||
break;
|
||||
default:
|
||||
memcpy(&vmdata_FL[save_idx][0], TOOL_DATA->data_out5, 4 * ANC_VMDATA_FF_RECORD_SIZE);
|
||||
break;
|
||||
}
|
||||
#if TEST_EAR_RECORD_EN
|
||||
icsd_anc_log("EAR RECORD SAVE:%d\n", save_idx);
|
||||
icsd_anc_ear_record_printf();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_anc_vmdata_by_idx(double *ff_ab, float *ff_gain, u8 idx)
|
||||
{
|
||||
u8 num = icsd_anc_get_vmdata_num();
|
||||
if ((!vmdata_FL) || (!vmdata_FR)) {
|
||||
return;
|
||||
}
|
||||
if ((num == 0) || (idx == 0xff) || ((num - 1) < idx)) {
|
||||
return;
|
||||
}
|
||||
#if TEST_EAR_RECORD_EN
|
||||
icsd_anc_log("EAR RECORD USED RECORD L\n");
|
||||
icsd_anc_fgq_printf(&vmdata_FL[idx][0]);
|
||||
#endif
|
||||
ff_fgq_2_aabb(ff_ab, &vmdata_FL[idx][0]);
|
||||
*ff_gain = vmdata_FL[idx][0];
|
||||
}
|
||||
|
||||
void icsd_anc_vmdatar_by_idx(double *ff_ab, float *ff_gain, u8 idx)
|
||||
{
|
||||
u8 num = icsd_anc_get_vmdata_num();
|
||||
if ((!vmdata_FL) || (!vmdata_FR)) {
|
||||
return;
|
||||
}
|
||||
if ((num == 0) || (idx == 0xff) || ((num - 1) < idx)) {
|
||||
return;
|
||||
}
|
||||
#if TEST_EAR_RECORD_EN
|
||||
icsd_anc_log("EAR RECORD USED RECORD R\n");
|
||||
icsd_anc_fgq_printf(&vmdata_FR[idx][0]);
|
||||
#endif
|
||||
ff_fgq_2_aabb(ff_ab, &vmdata_FR[idx][0]);
|
||||
*ff_gain = vmdata_FR[idx][0];
|
||||
}
|
||||
|
||||
u8 icsd_anc_tooldata_select_vmdata_headset(float *ff_fgq_l, float *ff_fgq_r)
|
||||
{
|
||||
icsd_anc_log("headset train time vm select start:%d\n", (int)((jiffies - train_time) * 10));
|
||||
u8 min_idx = icsd_anc_min_diff_idx();
|
||||
extern void icsd_set_min_idx(u8 minidx);
|
||||
icsd_set_min_idx(min_idx);
|
||||
u8 num = icsd_anc_get_vmdata_num();
|
||||
if ((!vmdata_FL) || (!vmdata_FR)) {
|
||||
return 0;
|
||||
}
|
||||
//icsd_anc_log("icsd_anc_tooldata_select_vmdata:%d %d\n", num, min_idx);
|
||||
if ((num == 0) || (min_idx == 0xff) || ((num - 1) < min_idx)) {
|
||||
icsd_anc_log("use default\n");
|
||||
return 0;
|
||||
}
|
||||
memcpy(ff_fgq_l, &vmdata_FL[min_idx][0], 4 * ANC_VMDATA_FF_RECORD_SIZE);
|
||||
memcpy(ff_fgq_r, &vmdata_FR[min_idx][0], 4 * ANC_VMDATA_FF_RECORD_SIZE);
|
||||
|
||||
#if TEST_EAR_RECORD_EN
|
||||
icsd_anc_log("EAR RECORD TOOL_DATA RECORD\n");
|
||||
icsd_anc_fgq_printf(ff_fgq_l);
|
||||
icsd_anc_fgq_printf(ff_fgq_r);
|
||||
#endif
|
||||
|
||||
icsd_anc_log("train time vm select end:%d\n", (int)((jiffies - train_time) * 10));
|
||||
icsd_anc_log("headset use record:%d\n", min_idx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
u8 icsd_anc_tooldata_select_vmdata(float *ff_fgq)
|
||||
{
|
||||
|
||||
icsd_anc_log("train time vm select start:%d\n", (int)((jiffies - train_time) * 10));
|
||||
//u8 min_idx = icsd_anc_min_diff_idx();
|
||||
u8 min_idx = TOOL_DATA->use_idx;
|
||||
icsd_printf("use record idx:%d\n", TOOL_DATA->use_idx);
|
||||
extern void icsd_set_min_idx(u8 minidx);
|
||||
icsd_set_min_idx(min_idx);
|
||||
u8 num = icsd_anc_get_vmdata_num();
|
||||
if ((!vmdata_FL) || (!vmdata_FR)) {
|
||||
return 0;
|
||||
}
|
||||
//icsd_anc_log("icsd_anc_tooldata_select_vmdata:%d %d\n", num, min_idx);
|
||||
if ((num == 0) || (min_idx == 0xff) || ((num - 1) < min_idx)) {
|
||||
icsd_anc_log("use default\n");
|
||||
return 0;
|
||||
}
|
||||
memcpy(ff_fgq, &vmdata_FL[min_idx][0], 4 * ANC_VMDATA_FF_RECORD_SIZE);
|
||||
|
||||
#if TEST_EAR_RECORD_EN
|
||||
icsd_anc_log("EAR RECORD TOOL_DATA RECORD\n");
|
||||
icsd_anc_fgq_printf(ff_fgq);
|
||||
#endif
|
||||
|
||||
icsd_anc_log("train time vm select end:%d\n", (int)((jiffies - train_time) * 10));
|
||||
icsd_anc_log("use record:%d\n", min_idx);
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
u8 icsd_anc_min_diff_idx()
|
||||
{
|
||||
return 0xff;
|
||||
}
|
||||
u8 icsd_anc_get_save_idx()
|
||||
{
|
||||
return 0xff;
|
||||
}
|
||||
u8 icsd_anc_get_vmdata_num()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void icsd_anc_vmdata_num_reset()
|
||||
{}
|
||||
void icsd_anc_save_with_idx(u8 save_idx)
|
||||
{}
|
||||
void icsd_anc_vmdata_by_idx(double *ff_ab, float *ff_gain, u8 idx)
|
||||
{}
|
||||
void icsd_anc_vmdatar_by_idx(double *ff_ab, float *ff_gain, u8 idx)
|
||||
{}
|
||||
void icsd_anc_ear_record_printf()
|
||||
{}
|
||||
u8 icsd_anc_tooldata_select_vmdata(float *ff_fgq)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
u8 icsd_anc_tooldata_select_vmdata_headset(float *ff_fgq_l, float *ff_fgq_r)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ANC_SZ_OUT_EN
|
||||
|
||||
float icsd_anc_sz_data[TARLEN + TARLEN_L];
|
||||
float icsd_anc_pz_data[TARLEN + TARLEN_L];
|
||||
u8 sz_out_exist = 0;
|
||||
|
||||
void icsd_anc_sz_out(float *hz_in)
|
||||
{
|
||||
printf("icsd_anc_sz_out\n");
|
||||
memcpy(icsd_anc_sz_data, hz_in, 4 * (TARLEN + TARLEN_L));
|
||||
sz_out_exist = 1;
|
||||
extern void icsd_aeq_demo();
|
||||
icsd_aeq_demo();
|
||||
icsd_printf("train time aeq end:%dms\n", (int)((jiffies - train_time) * 10));
|
||||
}
|
||||
|
||||
void icsd_anc_pz_out(float *hz_in)
|
||||
{
|
||||
printf("icsd_anc_pz_out\n");
|
||||
memcpy(icsd_anc_pz_data, hz_in, 4 * (TARLEN + TARLEN_L));
|
||||
sz_out_exist = 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif/*TCFG_AUDIO_ANC_EAR_ADAPTIVE_EN*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
151
apps/common/icsd/anc/icsd_anc_app.h
Normal file
151
apps/common/icsd/anc/icsd_anc_app.h
Normal file
@ -0,0 +1,151 @@
|
||||
#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.mode:0. 普通模式 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;
|
||||
|
||||
#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*/
|
||||
422
apps/common/icsd/anc/icsd_anc_board.c
Normal file
422
apps/common/icsd/anc/icsd_anc_board.c
Normal file
@ -0,0 +1,422 @@
|
||||
#include "board_config.h"
|
||||
#include "icsd_anc_app.h"
|
||||
#include "tone_player.h"
|
||||
#include "audio_anc.h"
|
||||
#include "icsd_anc_user.h"
|
||||
|
||||
#if 1
|
||||
#define icsd_board_log printf
|
||||
#else
|
||||
#define icsd_board_log(...)
|
||||
#endif/*log_en*/
|
||||
|
||||
#if TCFG_AUDIO_ANC_EAR_ADAPTIVE_EN
|
||||
|
||||
u8 anc_train_result = 0; //ANC自适应训练结果返回值
|
||||
u8 IIR_NUM;// 4 3
|
||||
u8 IIR_NUM_FIX;// 4 8-IIR_NUM
|
||||
u8 IIR_COEF; //(IIR_NUM * 3+1)
|
||||
|
||||
/*
|
||||
typedef enum {
|
||||
ANC_IIR_HIGH_PASS = 0,
|
||||
ANC_IIR_LOW_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_HIGH_SHELF,
|
||||
ANC_IIR_LOW_SHELF,
|
||||
} ANC_iir_type;
|
||||
*/
|
||||
|
||||
#ifndef ADAPTIVE_CLIENT_BOARD
|
||||
const u8 cmp_iir_type[] = {
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_HIGH_SHELF,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
};
|
||||
|
||||
const u8 ff_iir_type[] = {
|
||||
ANC_IIR_LOW_SHELF,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
};
|
||||
|
||||
const u8 fb_iir_type[] = {
|
||||
ANC_IIR_HIGH_SHELF,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
ANC_IIR_BAND_PASS,
|
||||
};
|
||||
|
||||
const u8 FF_VERSION = 1;
|
||||
const u8 NEW_PRE_TREAT = 0;
|
||||
const u8 ICSD_EP_TYPE = ICSD_FULL_INEAR;
|
||||
const u8 icsd_dcc[4] = {1, 4, 1, 1}; //ff1st,ff2nd,fb12t,fb2nd
|
||||
const u16 ICSD_ANC_FUN = 0;
|
||||
|
||||
void icsd_xtmp_handler(float *xtmp, float gain_min, float gain_max)
|
||||
{
|
||||
if (xtmp[1] < gain_min) {
|
||||
xtmp[1] = (float)gain_min;
|
||||
}
|
||||
if (xtmp[1] > gain_max) {
|
||||
xtmp[1] = (float)gain_max;
|
||||
}
|
||||
}
|
||||
|
||||
void icsd_anc_board_config()
|
||||
{
|
||||
icsd_anc_board_param_init();
|
||||
ANC_BOARD_PARAM->ff_yorder = ANC_ADAPTIVE_FF_ORDER;
|
||||
ANC_BOARD_PARAM->fb_yorder = ANC_ADAPTIVE_FB_ORDER;
|
||||
ANC_BOARD_PARAM->cmp_yorder = ANC_ADAPTIVE_CMP_ORDER;
|
||||
|
||||
#define DEFAULT_FF_GAIN 3
|
||||
#define DEFAULT_FB_GAIN 3
|
||||
extern const float E108D_DATA[];
|
||||
extern const s8 E108D_s8_DATA[];
|
||||
extern const float E108D_DOUBLE_DATA[];
|
||||
ANC_BOARD_PARAM->anc_data_l = (void *)E108D_DATA;
|
||||
ANC_BOARD_PARAM->anc_data_r = (void *)E108D_DATA;
|
||||
ANC_BOARD_PARAM->anc_db = (void *)E108D_s8_DATA;
|
||||
ANC_BOARD_PARAM->anc_double_data_l = (void *)E108D_DOUBLE_DATA;
|
||||
ANC_BOARD_PARAM->anc_double_data_r = (void *)E108D_DOUBLE_DATA;
|
||||
ANC_BOARD_PARAM->m_value_l = 120.0; //80 ~ 200 最深点位置中心值
|
||||
ANC_BOARD_PARAM->sen_l = 15.0; //12 ~ 22 最深点深度
|
||||
ANC_BOARD_PARAM->in_q_l = 0.4; //0.4 ~ 1.2 最深点降噪宽度
|
||||
ANC_BOARD_PARAM->m_value_r = 120.0; //80 ~ 200 最深点位置中心值
|
||||
ANC_BOARD_PARAM->sen_r = 15.0; //12 ~ 22 最深点深度
|
||||
ANC_BOARD_PARAM->in_q_r = 0.4; //0.4 ~ 1.2 最深点降噪宽度
|
||||
ANC_BOARD_PARAM->sen_offset_l = 11.0 - 18.0;
|
||||
ANC_BOARD_PARAM->sen_offset_r = 11.0 - 18.0;
|
||||
ANC_BOARD_PARAM->ff_target_fix_num_l = 18;
|
||||
ANC_BOARD_PARAM->ff_target_fix_num_r = 18;
|
||||
ANC_BOARD_PARAM->gain_a_param = 25.0;
|
||||
ANC_BOARD_PARAM->gain_a_en = 0;
|
||||
ANC_BOARD_PARAM->cmp_abs_en = 0;
|
||||
ANC_BOARD_PARAM->idx_begin = 18;
|
||||
ANC_BOARD_PARAM->idx_end = 60;
|
||||
ANC_BOARD_PARAM->fb_w2r = 1000;
|
||||
ANC_BOARD_PARAM->FB_NFIX = 3;
|
||||
ANC_BOARD_PARAM->gain_min_offset = 11;
|
||||
ANC_BOARD_PARAM->gain_max_offset = 18;
|
||||
ANC_BOARD_PARAM->minvld = -10.0;
|
||||
|
||||
ANC_BOARD_PARAM->bypass_max_times = BYPASS_MAXTIME;
|
||||
ANC_BOARD_PARAM->pz_max_times = PZ_MAXTIME;
|
||||
ANC_BOARD_PARAM->jt_en = 2;
|
||||
ANC_BOARD_PARAM->tff_sign = 1;
|
||||
ANC_BOARD_PARAM->tfb_sign = -1;
|
||||
ANC_BOARD_PARAM->bff_sign = 1;
|
||||
ANC_BOARD_PARAM->bfb_sign = 1;
|
||||
ANC_BOARD_PARAM->bypass_sign = -1;
|
||||
ANC_BOARD_PARAM->bypass_volume = 0.6; //0.6
|
||||
|
||||
ANC_BOARD_PARAM->tool_target_sign = -1;
|
||||
ANC_BOARD_PARAM->cmp_type[0] = 1;
|
||||
ANC_BOARD_PARAM->cmp_type[1] = 1;
|
||||
ANC_BOARD_PARAM->cmp_type[2] = 0;
|
||||
ANC_BOARD_PARAM->cmp_type[3] = 1;
|
||||
ANC_BOARD_PARAM->cmp_type[4] = 1;
|
||||
ANC_BOARD_PARAM->cmp_type[5] = 1;
|
||||
ANC_BOARD_PARAM->cmp_type[6] = 1;
|
||||
ANC_BOARD_PARAM->cmp_type[7] = 1;
|
||||
ANC_BOARD_PARAM->cmp_thd_low = -40.0;
|
||||
ANC_BOARD_PARAM->cmp_thd_high = 40.0;
|
||||
|
||||
ANC_BOARD_PARAM->IIR_NUM = 3;
|
||||
ANC_BOARD_PARAM->IIR_NUM_FIX = 8 - ANC_BOARD_PARAM->IIR_NUM;
|
||||
ANC_BOARD_PARAM->IIR_COEF = ANC_BOARD_PARAM->IIR_NUM * 3 + 1;
|
||||
|
||||
ANC_BOARD_PARAM->sz_priority_thr = 60;
|
||||
ANC_BOARD_PARAM->JT_MODE = 0;
|
||||
|
||||
if (ANC_BOARD_PARAM->pz_max_times < 3) {
|
||||
ANC_BOARD_PARAM->pz_max_times = 3;
|
||||
}
|
||||
|
||||
if (ANC_BOARD_PARAM->bypass_max_times < 2) {
|
||||
ANC_BOARD_PARAM->pz_max_times = 2;
|
||||
}
|
||||
|
||||
ANC_BOARD_PARAM->mode = ICSD_ANC_MODE;
|
||||
if (ANC_DFF_AFB_EN) {
|
||||
icsd_board_log("ANC_DFF_AFB_EN ON\n");
|
||||
ANC_BOARD_PARAM->FF_FB_EN |= ICSD_DFF_AFB_EN;//BIT(7);
|
||||
}
|
||||
if (ANC_AFF_DFB_EN) {
|
||||
icsd_board_log("ANC_AFF_DFB_EN ON\n");
|
||||
ANC_BOARD_PARAM->FF_FB_EN |= ICSD_AFF_DFB_EN;//BIT(6);
|
||||
}
|
||||
if (ANC_FB_TRAIN_OFF) {
|
||||
ANC_BOARD_PARAM->FF_FB_EN |= ICSD_FB_TRAIN_OFF;//BIT(5);
|
||||
}
|
||||
if (ANC_FB_TRAIN_NEW) {
|
||||
ANC_BOARD_PARAM->FF_FB_EN |= ICSD_FB_TRAIN_NEW;//BIT(4);
|
||||
}
|
||||
ANC_BOARD_PARAM->default_ff_gain = DEFAULT_FF_GAIN;
|
||||
ANC_BOARD_PARAM->default_fb_gain = DEFAULT_FB_GAIN;
|
||||
|
||||
if (TCFG_AUDIO_DAC_MODE == DAC_MODE_H1_DIFF) {
|
||||
user_train_state |= ANC_DAC_MODE_H1_DIFF;
|
||||
} else {
|
||||
user_train_state &= ~ANC_DAC_MODE_H1_DIFF;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#include "icsd_anc_client_board.c"
|
||||
|
||||
#endif/*ADAPTIVE_CLIENT_BOARD*/
|
||||
|
||||
void icsd_anc_config_inf()
|
||||
{
|
||||
icsd_board_log("\n=============ANC COMFIG INF================\n");
|
||||
|
||||
icsd_anc_version();
|
||||
switch (ICSD_ANC_MODE) {
|
||||
case TWS_TONE_BYPASS_MODE:
|
||||
icsd_board_log("TWS_TONE_BYPASS_MODE\n");
|
||||
break;
|
||||
case TWS_TONE_MODE:
|
||||
icsd_board_log("TWS_TONE_MODE\n");
|
||||
break;
|
||||
case TWS_BYPASS_MODE:
|
||||
icsd_board_log("TWS_BYPASS_MODE\n");
|
||||
break;
|
||||
case HEADSET_TONE_BYPASS_MODE:
|
||||
icsd_board_log("HEADSET_TONE_BYPASS_MODE\n");
|
||||
break;
|
||||
case HEADSET_TONES_MODE:
|
||||
icsd_board_log("HEADSET_TONES_MODE\n");
|
||||
break;
|
||||
case HEADSET_BYPASS_MODE:
|
||||
icsd_board_log("HEADSET_BYPASS_MODE\n");
|
||||
break;
|
||||
default:
|
||||
icsd_board_log("NEW MODE\n");
|
||||
break;
|
||||
}
|
||||
icsd_board_log("TEST_ANC_COMBINATION:%d\n", TEST_ANC_COMBINATION);
|
||||
icsd_board_log("ANC_ADAPTIVE_CMP_EN:%d\n", ANC_ADAPTIVE_CMP_EN);
|
||||
icsd_board_log("ANC_EAR_RECORD_EN:%d\n", ANC_EAR_RECORD_EN);
|
||||
icsd_board_log("TEST_EAR_RECORD_EN:%d\n", TEST_EAR_RECORD_EN);
|
||||
icsd_board_log("BYPASS_TIMES MIN:2 MAX:%d\n", BYPASS_MAXTIME);
|
||||
icsd_board_log("PZ_TIMES MIN:3 MAX:%d\n", PZ_MAXTIME);
|
||||
icsd_board_log("\n");
|
||||
|
||||
#if TEST_EAR_RECORD_EN
|
||||
icsd_board_log("EAR RECORD CURRENT RECORD\n");
|
||||
//icsd_anc_ear_record_icsd_board_log();
|
||||
#endif
|
||||
}
|
||||
|
||||
//训练结果获取API,用于通知应用层当前使用自适应参数还是默认参数
|
||||
u8 icsd_anc_train_result_get(struct icsd_anc_tool_data *TOOL_DATA)
|
||||
{
|
||||
u8 result = 0;
|
||||
if (TOOL_DATA) {
|
||||
switch (TOOL_DATA->anc_combination) {
|
||||
case TFF_TFB://使用自适应FF,自适应FB
|
||||
result = ANC_ADAPTIVE_RESULT_LFF | ANC_ADAPTIVE_RESULT_LFB | ANC_ADAPTIVE_RESULT_RFF | ANC_ADAPTIVE_RESULT_RFB;
|
||||
break;
|
||||
case TFF_DFB://使用自适应FF,默认FB
|
||||
result = ANC_ADAPTIVE_RESULT_LFF | ANC_ADAPTIVE_RESULT_RFF;
|
||||
break;
|
||||
case DFF_TFB://result:1 使用记忆FF,自适应FB :3 使用默认FF,自适应FB
|
||||
result = ANC_ADAPTIVE_RESULT_LFB | ANC_ADAPTIVE_RESULT_RFB;
|
||||
break;
|
||||
case DFF_DFB://result:1 使用记忆FF,默认FB :3 使用默认FF,默认FB
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//使用耳道记忆的FF参数
|
||||
if (TOOL_DATA->result == ANC_USE_RECORD) {
|
||||
result |= (ANC_ADAPTIVE_RESULT_LFF | ANC_ADAPTIVE_RESULT_RFF);
|
||||
}
|
||||
//CMP成功,使用自适应CMP参数
|
||||
if (TOOL_DATA->cmp_result) {
|
||||
result |= (ANC_ADAPTIVE_RESULT_LCMP | ANC_ADAPTIVE_RESULT_RCMP);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
extern int tone_play_index(u8 index, u8 preemption);
|
||||
void icsd_anc_htarget_data_end(u8 result)
|
||||
{
|
||||
user_train_state &= ~ANC_USER_TRAIN_TOOL_DATA;
|
||||
ICSD_ANC.adaptive_run_busy = 0;
|
||||
/*
|
||||
训练结果播放提示音
|
||||
result = 1 训练成功
|
||||
result = 0 训练失败
|
||||
*/
|
||||
anc_train_result = result;
|
||||
printf("ICSD ANC RESULT:%d================\n", result);
|
||||
|
||||
switch (result) {
|
||||
case 1:
|
||||
anc_printf("FF USE RECORD\n");
|
||||
break;
|
||||
case 2:
|
||||
anc_printf("FF USE TRAIN\n");
|
||||
break;
|
||||
case 3:
|
||||
anc_printf("FF USE DEFAULT\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (TOOL_DATA->anc_combination) {
|
||||
case TFF_TFB://使用自适应FF,自适应FB
|
||||
anc_printf("TFF_TFB\n");
|
||||
break;
|
||||
case TFF_DFB://使用自适应FF,默认FB
|
||||
anc_printf("TFF_DFB\n");
|
||||
#if ANC_DEVELOPER_MODE_EN
|
||||
icsd_adt_tone_play(ICSD_ADT_TONE_NUM2);
|
||||
#endif/*ANC_DEVELOPER_MODE_EN*/
|
||||
break;
|
||||
case DFF_TFB://result:1 使用记忆FF,自适应FB :3 使用默认FF,自适应FB
|
||||
anc_printf("DFF_TFB\n");
|
||||
#if ANC_DEVELOPER_MODE_EN
|
||||
icsd_adt_tone_play(ICSD_ADT_TONE_NUM1);
|
||||
#endif/*ANC_DEVELOPER_MODE_EN*/
|
||||
break;
|
||||
case DFF_DFB://result:1 使用记忆FF,默认FB :3 使用默认FF,默认FB
|
||||
anc_printf("DFF_DFB\n");
|
||||
#if ANC_DEVELOPER_MODE_EN
|
||||
icsd_adt_tone_play(ICSD_ADT_TONE_NUM0);
|
||||
#endif/*ANC_DEVELOPER_MODE_EN*/
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
audio_anc_adaptive_fail_callback(TOOL_DATA->anc_err);
|
||||
icsd_board_log("train time tool data end:%d\n", (int)((jiffies - train_time) * 10));
|
||||
icsd_anc_htarget_data_send_end();
|
||||
}
|
||||
|
||||
extern void audio_anc_adaptive_data_packet(struct icsd_anc_tool_data *TOOL_DATA);
|
||||
void icsd_anc_htarget_data_send()
|
||||
{
|
||||
|
||||
#if ANC_SZ_OUT_EN
|
||||
extern void icsd_anc_sz_out(float * hz_in);
|
||||
extern void icsd_anc_pz_out(float * hz_in);
|
||||
if (HEADSET_MODE) {
|
||||
if ((TOOL_DATA->result == 2) || (TOOL_DATA->anc_combination == TFF_DFB)) {
|
||||
icsd_anc_sz_out(TOOL_DATA->data_out1);
|
||||
icsd_anc_pz_out(TOOL_DATA->data_out2);
|
||||
}
|
||||
} else {
|
||||
if (TOOL_DATA->result == 2) {
|
||||
icsd_anc_sz_out(TOOL_DATA->data_out1);
|
||||
icsd_anc_pz_out(TOOL_DATA->data_out2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (TOOL_DATA->cmp_result) {
|
||||
anc_printf("CMP RESULT:success\n");
|
||||
} else {
|
||||
anc_printf("CMP RESULT:fail\n");
|
||||
}
|
||||
|
||||
icsd_board_log("train time tool data start:%d\n", (int)((jiffies - train_time) * 10));
|
||||
//TOOL_DATA->result 0:失败使用默认参数 1:耳道记忆参数 2:成功
|
||||
printf("save check:%d %d----------------\n", TOOL_DATA->result, HEADSET_MODE);
|
||||
if (HEADSET_MODE) {
|
||||
if ((TOOL_DATA->result == 2) || (TOOL_DATA->anc_combination == TFF_DFB)) {
|
||||
//成功时进行耳道记忆
|
||||
icsd_anc_save_with_idx(TOOL_DATA->save_idx);
|
||||
}
|
||||
} else {
|
||||
if (TOOL_DATA->result == 2) {
|
||||
//成功时进行耳道记忆
|
||||
icsd_anc_save_with_idx(TOOL_DATA->save_idx);
|
||||
}
|
||||
}
|
||||
audio_anc_adaptive_data_packet((struct icsd_anc_tool_data *)TOOL_DATA);
|
||||
icsd_anc_htarget_data_end(TOOL_DATA->result);
|
||||
}
|
||||
|
||||
void icsd_anc_end(audio_anc_t *param)
|
||||
{
|
||||
icsd_board_log("train time finish:%dms\n", (int)((jiffies - train_time) * 10));
|
||||
user_train_state &= ~ANC_USER_TRAIN_DMA_EN;
|
||||
if (icsd_time_out_hdl) {
|
||||
sys_timeout_del(icsd_time_out_hdl);
|
||||
icsd_time_out_hdl = 0;
|
||||
}
|
||||
icsd_anc_contral = 0;
|
||||
anc_user_train_cb(ANC_ON, anc_train_result, 0);
|
||||
}
|
||||
|
||||
void icsd_anc_forced_exit_end()
|
||||
{
|
||||
if (icsd_anc_contral & ICSD_ANC_TONE_END) {
|
||||
printf("icsd_anc_forced_exit_end cb-----------------------------\n");
|
||||
icsd_anc_contral &= ~ICSD_ANC_FORCED_EXIT;
|
||||
icsd_anc_contral &= ~ICSD_ANC_SUSPENDED;
|
||||
icsd_anc_contral &= ~ICSD_ANC_TONE_END;
|
||||
icsd_anc_contral &= ~ICSD_ANC_INITED;
|
||||
icsd_anc_contral &= ~ICSD_ANC_FORCED_BEFORE_INIT;
|
||||
if (icsd_time_out_hdl) {
|
||||
sys_timeout_del(icsd_time_out_hdl);
|
||||
icsd_time_out_hdl = 0;
|
||||
}
|
||||
anc_user_train_cb(ANC_ON, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void anc_user_train_tone_play_cb()
|
||||
{
|
||||
icsd_board_log("anc_user_train_tone_play_cb:%d========================================\n", (int)jiffies);
|
||||
train_time = jiffies;
|
||||
#if ANC_USER_TRAIN_EN
|
||||
icsd_anc_contral |= ICSD_ANC_TONE_END;
|
||||
if (icsd_anc_contral & ICSD_ANC_SUSPENDED) {
|
||||
printf("FORCED EXIT END================================\n");
|
||||
user_train_state |= ANC_TRAIN_TONE_END;
|
||||
icsd_anc_forced_exit_end();
|
||||
return;
|
||||
}
|
||||
#if ANC_USER_TRAIN_TONE_MODE
|
||||
icsd_board_log("TONE MODE tone play cb~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
|
||||
if (user_train_state & ANC_TRAIN_TONE_FIRST) {
|
||||
user_train_state |= ANC_TRAIN_TONE_END;
|
||||
} else {
|
||||
icsd_board_log("second train at cb~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
|
||||
user_train_state |= ANC_TRAIN_TONE_END;
|
||||
audio_anc_post_msg_icsd_anc_cmd(ANC_CMD_TRAIN_AFTER_TONE);
|
||||
}
|
||||
#else
|
||||
extern void audio_anc_post_msg_user_train_init(u8 mode);
|
||||
audio_anc_post_msg_user_train_init(ANC_ON);
|
||||
#endif/*ANC_USER_TRAIN_TONE_MODE*/
|
||||
|
||||
#else
|
||||
anc_user_train_cb(ANC_ON, anc_train_result, 0);
|
||||
#endif/*ANC_USER_TRAIN_EN*/
|
||||
}
|
||||
|
||||
#endif/*TCFG_AUDIO_ANC_EAR_ADAPTIVE_EN*/
|
||||
1024
apps/common/icsd/anc/icsd_anc_client_board.c
Normal file
1024
apps/common/icsd/anc/icsd_anc_client_board.c
Normal file
File diff suppressed because it is too large
Load Diff
158
apps/common/icsd/anc/icsd_anc_client_board.h
Normal file
158
apps/common/icsd/anc/icsd_anc_client_board.h
Normal file
@ -0,0 +1,158 @@
|
||||
|
||||
/*********************************************************************
|
||||
|
||||
ANC 耳道自适应配置文件
|
||||
|
||||
*********************************************************************/
|
||||
|
||||
#include "icsd_anc.h"
|
||||
|
||||
#define DEVE_BOARD 0x00 //开发板
|
||||
#define HT03_HYBRID_6F 0x01 //CUSTOM1_CFG
|
||||
#define HT03_HYBRID_6G 0x02 //CUSTOM2_CFG
|
||||
#define A896_HYBRID_6G 0x03 //CUSTOM3_CFG
|
||||
#define HT05_6G 0x04 //CUSTOM4_CFG
|
||||
#define ANC05_HYBRID 0x05 //CUSTOM5_CFG
|
||||
#define G02_HYBRID_6G 0x06 //CUSTOM6_CFG
|
||||
#define AC098_HYBRID_6G 0x07 //CUSTOM7_CFG
|
||||
#define G96_HYBRID 0x08 //CUSTOM8_CFG
|
||||
#define H3_HYBRID 0x09 //CUSTOM9_CFG
|
||||
#define P90_HYBRID 0x0a //CUSTOM10_CFG
|
||||
#define JH4006_HYBRID 0x0d //CUSTOM10_CFG
|
||||
|
||||
#define D28_HYBRID 0x80
|
||||
#define H3_TOZO_HYBIRD 0x81
|
||||
|
||||
//自适应板级配置,适配不同样机
|
||||
//#define ADAPTIVE_CLIENT_BOARD HT03_HYBRID_6G
|
||||
//#define ADAPTIVE_CLIENT_BOARD G96_HYBRID
|
||||
//#define ADAPTIVE_CLIENT_BOARD P90_HYBRID
|
||||
//#define ADAPTIVE_CLIENT_BOARD G02_HYBRID_6G
|
||||
//#define ADAPTIVE_CLIENT_BOARD JH4006_HYBRID
|
||||
#define ADAPTIVE_CLIENT_BOARD D28_HYBRID
|
||||
//#define ADAPTIVE_CLIENT_BOARD H3_TOZO_HYBIRD
|
||||
//#define ADAPTIVE_CLIENT_BOARD H3_HYBIRD
|
||||
|
||||
#if ADAPTIVE_CLIENT_BOARD == HT03_HYBRID_6G
|
||||
#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 0
|
||||
#define ANC_FB_TRAIN_NEW 0
|
||||
#define ANC_EARPHONE_CHECK_EN 1
|
||||
#define ANC_ADAPTIVE_CMP_EN 1 //自适应CMP补偿
|
||||
#define ANC_ADAPTIVE_TONE_DELAY 700
|
||||
|
||||
#elif ADAPTIVE_CLIENT_BOARD == G02_HYBRID_6G
|
||||
#define ICSD_ANC_MODE TWS_TONE_BYPASS_MODE
|
||||
#define ANC_ADAPTIVE_FF_ORDER 8 /*ANC自适应FF滤波器阶数, 原厂指定*/
|
||||
#define ANC_ADAPTIVE_FB_ORDER 6 /*ANC自适应FB滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_CMP_ORDER 4 /*ANC自适应CMP滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_RECORD_FF_ORDER 8 /*ANC自适应耳道记忆FF滤波器阶数,原厂指定*/
|
||||
#define ANC_FB_TRAIN_OFF 0
|
||||
#define ANC_FB_TRAIN_NEW 0
|
||||
#define ANC_EARPHONE_CHECK_EN 0
|
||||
#define ANC_ADAPTIVE_CMP_EN 0 //自适应CMP补偿
|
||||
#define ANC_ADAPTIVE_TONE_DELAY 700
|
||||
|
||||
#elif ADAPTIVE_CLIENT_BOARD == ANC05_HYBRID
|
||||
#define ICSD_ANC_MODE HEADSET_TONES_MODE //HEADSET_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 0
|
||||
#define ANC_FB_TRAIN_NEW 0
|
||||
#define ANC_EARPHONE_CHECK_EN 0
|
||||
#define ANC_ADAPTIVE_CMP_EN 1 //自适应CMP补偿
|
||||
#define ANC_ADAPTIVE_TONE_DELAY 700
|
||||
|
||||
#elif ADAPTIVE_CLIENT_BOARD == H3_HYBRID
|
||||
#define ICSD_ANC_MODE HEADSET_TONES_MODE //HEADSET_TONE_BYPASS_MODE
|
||||
#define ANC_ADAPTIVE_FF_ORDER 8 /*ANC自适应FF滤波器阶数, 原厂指定*/
|
||||
#define ANC_ADAPTIVE_FB_ORDER 6 /*ANC自适应FB滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_CMP_ORDER 8 /*ANC自适应CMP滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_RECORD_FF_ORDER 8 /*ANC自适应耳道记忆FF滤波器阶数,原厂指定*/
|
||||
#define ANC_FB_TRAIN_OFF 0
|
||||
#define ANC_FB_TRAIN_NEW 0
|
||||
#define ANC_EARPHONE_CHECK_EN 1
|
||||
#define ANC_ADAPTIVE_CMP_EN 1 //自适应CMP补偿
|
||||
#define ANC_ADAPTIVE_TONE_DELAY 700
|
||||
|
||||
#elif ADAPTIVE_CLIENT_BOARD == H3_TOZO_HYBIRD
|
||||
#define ICSD_ANC_MODE HEADSET_TONES_MODE //HEADSET_TONE_BYPASS_MODE
|
||||
#define ANC_ADAPTIVE_FF_ORDER 8 /*ANC自适应FF滤波器阶数, 原厂指定*/
|
||||
#define ANC_ADAPTIVE_FB_ORDER 6 /*ANC自适应FB滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_CMP_ORDER 8 /*ANC自适应CMP滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_RECORD_FF_ORDER 8 /*ANC自适应耳道记忆FF滤波器阶数,原厂指定*/
|
||||
#define ANC_FB_TRAIN_OFF 0
|
||||
#define ANC_FB_TRAIN_NEW 0
|
||||
#define ANC_EARPHONE_CHECK_EN 1
|
||||
#define ANC_ADAPTIVE_CMP_EN 1 //自适应CMP补偿
|
||||
#define ANC_ADAPTIVE_TONE_DELAY 700
|
||||
|
||||
#elif ADAPTIVE_CLIENT_BOARD == G96_HYBRID
|
||||
#define ICSD_ANC_MODE TWS_TONE_BYPASS_MODE //HEADSET_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 0
|
||||
#define ANC_FB_TRAIN_NEW 1
|
||||
#define ANC_EARPHONE_CHECK_EN 1
|
||||
#define ANC_ADAPTIVE_CMP_EN 0 //自适应CMP补偿
|
||||
#define ANC_ADAPTIVE_TONE_DELAY 700
|
||||
|
||||
#elif ADAPTIVE_CLIENT_BOARD == P90_HYBRID
|
||||
//#define ICSD_ANC_MODE TWS_TONE_BYPASS_MODE
|
||||
#define ICSD_ANC_MODE TWS_TONE_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 1600//700
|
||||
|
||||
#elif ADAPTIVE_CLIENT_BOARD == D28_HYBRID
|
||||
#define ICSD_ANC_MODE TWS_TONE_MODE
|
||||
#define ANC_ADAPTIVE_FF_ORDER 10 /*ANC自适应FF滤波器阶数, 原厂指定*/
|
||||
#define ANC_ADAPTIVE_FB_ORDER 5 /*ANC自适应FB滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_CMP_ORDER 8 /*ANC自适应CMP滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_RECORD_FF_ORDER 10 /*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 1600//700
|
||||
|
||||
#elif ADAPTIVE_CLIENT_BOARD == JH4006_HYBRID
|
||||
#define ICSD_ANC_MODE HEADSET_TONES_MODE //HEADSET_TONE_BYPASS_MODE
|
||||
#define ANC_ADAPTIVE_FF_ORDER 8 /*ANC自适应FF滤波器阶数, 原厂指定*/
|
||||
#define ANC_ADAPTIVE_FB_ORDER 6 /*ANC自适应FB滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_CMP_ORDER 8 /*ANC自适应CMP滤波器阶数,原厂指定*/
|
||||
#define ANC_ADAPTIVE_RECORD_FF_ORDER 8 /*ANC自适应耳道记忆FF滤波器阶数,原厂指定*/
|
||||
#define ANC_FB_TRAIN_OFF 0
|
||||
#define ANC_FB_TRAIN_NEW 0
|
||||
#define ANC_EARPHONE_CHECK_EN 0
|
||||
#define ANC_ADAPTIVE_CMP_EN 0 //自适应CMP补偿
|
||||
#define ANC_ADAPTIVE_TONE_DELAY 700
|
||||
|
||||
#else
|
||||
#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 4 /*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 0 //自适应CMP补偿
|
||||
#define ANC_ADAPTIVE_TONE_DELAY 700
|
||||
#endif/*ADAPTIVE_CLIENT_BOARD*/
|
||||
|
||||
|
||||
266
apps/common/icsd/anc/icsd_anc_data.c
Normal file
266
apps/common/icsd/anc/icsd_anc_data.c
Normal file
@ -0,0 +1,266 @@
|
||||
#include "audio_anc.h"
|
||||
|
||||
const float THD_JT = 6;
|
||||
const float THD_JT_SAVE = 4;
|
||||
const float THD_JT2 = 7;
|
||||
|
||||
const s8 ANC_s8_DATA[] = {
|
||||
6,//P_PARAM_01
|
||||
-12,//P_PARAM_02
|
||||
4,//SP_PARAM_01
|
||||
-12,//SP_PARAM_01
|
||||
28,//ANC_ERRMIC_SPL_DB
|
||||
12,//ANC_SZ_DB
|
||||
-10,//EAR_CHECK_VLD1
|
||||
-9,//EAR_CHECK_VLD2
|
||||
40,//FSTOP_IDX
|
||||
58,//FSTOP_IDX2
|
||||
41,//_ANC_REFMIC_SPL_DB
|
||||
-4,//B_PARM1_THR_L
|
||||
4,//B_PARM1_THR_H
|
||||
-6,//B_PARM2_THR_L
|
||||
6,//B_PARM2_THR_H
|
||||
-4,//B_PARM3_THR_L
|
||||
4,//B_PARM3_THR_H
|
||||
};
|
||||
|
||||
const double ICSD_ANC_DOUBLE_DATA[] = {
|
||||
//double cmp_iir_ab[10] //
|
||||
1.000496069900691509246826171875, -1.998426330275833606719970703125, 0.997930623590946197509765625, -1.998426330275833606719970703125, 0.9984266944229602813720703125,
|
||||
0.9998088735155761241912841796875, -1.999607323668897151947021484375, 0.9997985516674816608428955078125, -1.999607323668897151947021484375, 0.9996074251830577850341796875,
|
||||
};
|
||||
|
||||
const float spl_tb [21] = {
|
||||
17, //134.765625000000
|
||||
19, //179.687500000000
|
||||
21, //224.609375000000
|
||||
22, //269.531250000000
|
||||
23, //314.453125000000
|
||||
23, //359.375000000000
|
||||
24, //404.296875000000
|
||||
26, //449.218750000000
|
||||
23, //494.140625000000
|
||||
24, //539.062500000000
|
||||
25, //583.984375000000
|
||||
25, //628.906250000000
|
||||
24, //673.828125000000
|
||||
22, //718.750000000000
|
||||
22, //763.671875000000
|
||||
23, //808.593750000000
|
||||
24, //853.515625000000
|
||||
25, //898.437500000000
|
||||
25, //943.359375000000
|
||||
24, //988.281250000000
|
||||
24, //1033.20312500000
|
||||
};
|
||||
|
||||
const float spl_freq_tb [21] = {
|
||||
134.765625000000,
|
||||
179.687500000000,
|
||||
224.609375000000,
|
||||
269.531250000000,
|
||||
314.453125000000,
|
||||
359.375000000000,
|
||||
404.296875000000,
|
||||
449.218750000000,
|
||||
494.140625000000,
|
||||
539.062500000000,
|
||||
583.984375000000,
|
||||
628.906250000000,
|
||||
673.828125000000,
|
||||
718.750000000000,
|
||||
763.671875000000,
|
||||
808.593750000000,
|
||||
853.515625000000,
|
||||
898.437500000000,
|
||||
943.359375000000,
|
||||
988.281250000000,
|
||||
1033.20312500000
|
||||
};
|
||||
|
||||
const float ICSD_ANC_DATA[] = {
|
||||
//float ff_fgq[25]
|
||||
1,//gain
|
||||
10000, 20.000, 1.000, //F G Q
|
||||
1200, -3.500, 1.000,
|
||||
2000, -4.000, 1.000,
|
||||
6500, -6.000, 1.000,
|
||||
10000, -30.000, 1.500,
|
||||
75, 2.000, 2.000,
|
||||
385, -4.260, 0.505,
|
||||
620, 1.600, 1.500,
|
||||
//float fb_fgq[25]
|
||||
0.707945,//gain
|
||||
3500.0, -6.000, 0.900, //F G Q
|
||||
1510.0, -2, 0.800,
|
||||
5289.0, -11, 0.800,
|
||||
120.0, 18.000, 0.600,
|
||||
45.0, 3.000, 1.000,
|
||||
20.0, 0.0, 1.000,
|
||||
20.0, 0.0, 1.000,
|
||||
20.0, 0.0, 1.000,
|
||||
//float ff_weight_HT03[75]
|
||||
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 10.00, 10.00, 10.00,
|
||||
10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00,
|
||||
5.100, 5.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100,
|
||||
0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100,
|
||||
0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100, 0.100,
|
||||
//float best_param_fix[13]
|
||||
-3.00,
|
||||
0.900, -6.000, 3500.0, // Q G F
|
||||
0.800, -2, 1510.0,
|
||||
0.800, -11, 5289.0,
|
||||
1.000, 0.0, 20.0,
|
||||
//float best_param_flex[6]
|
||||
0.600, 18.000, 120.0,
|
||||
1.000, 3.000, 45.0,
|
||||
//float biquad_init_lcl[10]
|
||||
-1, 150, 0.5,
|
||||
-3, 500, 1,
|
||||
-7, 1200, 0.8,
|
||||
-1,
|
||||
//float biquad_fix[15]
|
||||
8, 60, 1.8,
|
||||
-10, 15, 1.5,
|
||||
4.5, 4500, 0.8,
|
||||
-8, 7500, 2,
|
||||
-25, 14000, 1.2,
|
||||
//float Vrange[26]
|
||||
-5.0, 5.0, 130, 400, 0.3, 1,
|
||||
-5.0, 5.0, 400, 900, 0.3, 1,
|
||||
-10.0, -5.0, 900, 1400, 0.7, 0.9,
|
||||
-1.1, -0.9,
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, //没有使用
|
||||
//float biquad_init_data[7]
|
||||
1.0,//highshlef_N
|
||||
4.0,//peak_N
|
||||
5.0,//N
|
||||
1.0,//h_fix
|
||||
2.0,//p_fix
|
||||
3.0,//n_fix
|
||||
2.0,//n_flex
|
||||
//float fb_std[3]
|
||||
1.414,
|
||||
0.707,
|
||||
20.0,
|
||||
//float k_cmp[75*2]
|
||||
0.355735, 0.000000,
|
||||
0.406650, 0.009267,
|
||||
0.540936, 0.013891,
|
||||
0.677297, 0.006987,
|
||||
0.661146, -0.122581,
|
||||
0.762457, -0.082076,
|
||||
0.845315, -0.032340,
|
||||
0.922015, 0.001376,
|
||||
0.983304, 0.017571,
|
||||
1.003132, 0.021645,
|
||||
1.013473, 0.016530,
|
||||
1.014149, 0.007091,
|
||||
1.005985, -0.001269,
|
||||
0.992157, -0.002376,
|
||||
0.982547, 0.008197,
|
||||
0.987876, 0.019249,
|
||||
0.993822, 0.015540,
|
||||
0.984279, 0.010513,
|
||||
0.969368, 0.020658,
|
||||
0.970804, 0.034582,
|
||||
0.996935, 0.025907,
|
||||
0.985948, 0.031042,
|
||||
0.935211, 0.022464,
|
||||
0.953423, 0.025235,
|
||||
0.961401, 0.012630,
|
||||
0.929649, 0.025147,
|
||||
0.916033, 0.070842,
|
||||
0.908546, 0.113489,
|
||||
0.890224, 0.146915,
|
||||
0.880289, 0.170188,
|
||||
0.897130, 0.177176,
|
||||
0.899322, 0.215329,
|
||||
0.902587, 0.219978,
|
||||
0.901702, 0.301843,
|
||||
0.930309, 0.364164,
|
||||
0.958195, 0.421897,
|
||||
1.015677, 0.431439,
|
||||
1.046609, 0.453263,
|
||||
1.089167, 0.435698,
|
||||
1.112152, 0.445592,
|
||||
1.149376, 0.458663,
|
||||
1.143086, 0.467994,
|
||||
1.178618, 0.494142,
|
||||
1.178230, 0.490062,
|
||||
1.202727, 0.519448,
|
||||
1.264703, 0.538896,
|
||||
1.300802, 0.571430,
|
||||
1.309515, 0.629530,
|
||||
1.383454, 0.672111,
|
||||
1.433505, 0.684519,
|
||||
1.510080, 0.676279,
|
||||
1.680950, 0.720572,
|
||||
1.649127, 0.726221,
|
||||
1.787352, 0.769206,
|
||||
1.911621, 0.671973,
|
||||
1.936819, 0.780815,
|
||||
2.111839, 0.570215,
|
||||
2.236738, 0.596179,
|
||||
2.329324, 0.556353,
|
||||
2.423803, 0.479938,
|
||||
2.548114, 0.379554,
|
||||
2.495549, 0.279278,
|
||||
2.675386, -0.007060,
|
||||
2.512869, -0.084337,
|
||||
2.723908, -0.190948,
|
||||
2.353746, -0.626941,
|
||||
2.550212, -0.385014,
|
||||
2.369031, -0.435515,
|
||||
2.333464, -0.795883,
|
||||
1.912714, -0.841469,
|
||||
1.844244, -1.095402,
|
||||
1.741950, -1.333718,
|
||||
1.919448, -1.361989,
|
||||
1.672145, -1.309203,
|
||||
1.559095, -0.326499,
|
||||
//cmp_fix_biquad
|
||||
-31.603, 19, 5,
|
||||
4.247, 36, 0.3,
|
||||
-12.149, 9046, 0.9,
|
||||
11.905, 6464, 1.2,
|
||||
//cmp_flex_vrange
|
||||
-8, 8, 100, 300, 0.6, 1,
|
||||
-8, 8, 400, 800, 0.5, 1,
|
||||
-8, 8, 800, 1000, 0.5, 1,
|
||||
-5, 5, 1000, 1500, 0.8, 1.5,
|
||||
0.35481, 0.35481,
|
||||
//cmp_flex_init
|
||||
4.985, 193, 0.8,
|
||||
0, 500, 1,
|
||||
6.1, 900, 0.57,
|
||||
0, 1200, 0.5,
|
||||
//cmp_weight
|
||||
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 10.00, 10.00, 10.00, 10.00,
|
||||
10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00,
|
||||
10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 3.000, 3.000, 3.000,
|
||||
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
|
||||
0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000,
|
||||
//cmp_iir_ab_idx
|
||||
2,
|
||||
//nmss_config
|
||||
1,//flex_seq[0]
|
||||
2,//flex_seq[1]
|
||||
0,//flex_seq[2]
|
||||
0,//flex_seq[3]
|
||||
0,//flex_seq[4]
|
||||
0,//flex_seq[5]
|
||||
2,//n
|
||||
1.0,//rho
|
||||
2.0,//chi
|
||||
0.5,//psi
|
||||
0.5,//sigma
|
||||
250,//maxnum
|
||||
0.10,//usual_delta
|
||||
5.0,//zero_term_delta
|
||||
//lowshelf_config
|
||||
0, //en
|
||||
26, //f
|
||||
-8.0,//g
|
||||
1.0, //q
|
||||
};
|
||||
Reference in New Issue
Block a user