#ifndef _EQ_CONFIG_H_ #define _EQ_CONFIG_H_ #include "media/audio_eq.h" #include "media/audio_drc.h" #include "spinlock.h" #include "math.h" #if 0 /*-----------------------------------------------------------*/ /*eq online cmd*/ enum { EQ_ONLINE_CMD_SECTION = 1, EQ_ONLINE_CMD_GLOBAL_GAIN, EQ_ONLINE_CMD_LIMITER, EQ_ONLINE_CMD_INQUIRE, EQ_ONLINE_CMD_GETVER, EQ_ONLINE_CMD_GET_SOFT_SECTION,//br22专用 EQ_ONLINE_CMD_GET_SECTION_NUM = 0x7,//工具查询 小机需要的eq段数 EQ_ONLINE_CMD_GLOBAL_GAIN_SUPPORT_FLOAT = 0x8, EQ_ONLINE_CMD_PASSWORD = 0x9, EQ_ONLINE_CMD_VERIFY_PASSWORD = 0xA, EQ_ONLINE_CMD_FILE_SIZE = 0xB, EQ_ONLINE_CMD_FILE = 0xC, EQ_EQ_ONLINE_CMD_GET_SECTION_NUM = 0xD,//该命令新加与 0x7功能一样 EQ_EQ_ONLINE_CMD_CHANGE_MODE = 0xE,//切模式 EQ_ONLINE_CMD_MODE_COUNT = 0x100,//模式个数a 1 EQ_ONLINE_CMD_MODE_NAME = 0x101,//模式的名字a eq EQ_ONLINE_CMD_MODE_GROUP_COUNT = 0x102,//模式下组的个数,4个字节 1 EQ_ONLINE_CMD_MODE_GROUP_RANGE = 0x103,//模式下组的id内容 0x11 EQ_ONLINE_CMD_EQ_GROUP_COUNT = 0x104,//eq组的id个数 1 EQ_ONLINE_CMD_EQ_GROUP_RANGE = 0x105,//eq组的id内容 0x11 EQ_ONLINE_CMD_MODE_SEQ_NUMBER = 0x106,//mode的编号 magic num EQ_ONLINE_CMD_PARAMETER_SEG = 0x11, EQ_ONLINE_CMD_PARAMETER_TOTAL_GAIN, EQ_ONLINE_CMD_PARAMETER_LIMITER, EQ_ONLINE_CMD_PARAMETER_DRC, EQ_ONLINE_CMD_PARAMETER_CHANNEL,//通道切换 EQ_ONLINE_CMD_WRITE_FILE_SIZE = 0x20, //准备写入文件 EQ_ONLINE_CMD_WRITE_FILE_CHANNEL = 0x21, EQ_ONLINE_CMD_SONG_EQ_SEG = 0x2001, EQ_ONLINE_CMD_CALL_EQ_SEG = 0x2002, EQ_ONLINE_CMD_AEC_EQ_SEG = 0x2003, EQ_ONLINE_CMD_SONG_EQ_V1_SEG = 0x2011,// float gain, float q EQ_ONLINE_CMD_CALL_EQ_V1_SEG = 0x2012, EQ_ONLINE_CMD_AEC_EQ_V1_SEG = 0x2013, EQ_ONLINE_CMD_SONG_DRC = 0x2101, EQ_ONLINE_CMD_SONG_WDRC = 0x2102, //add xx here EQ_ONLINE_CMD_MAX,//最后一个 }; #define CONSTRAINT_OP_DRC_L_R_CH 0x01 #define CONSTRAINT_OP_DRC_WDRC_SINGLE_CH 0x02 #define CONSTRAINT_OP_DRC_WDRC_DUAL_CH 0x03 /*eq online packet*/ typedef struct { int cmd; ///eq_seg_tab) { int size = sizeof(your_audio_out_eq_tab); eq->eq_seg_tab = zalloc(size); memcpy(eq->eq_seg_tab, your_audio_out_eq_tab, size); } if (!eq->eq_coeff_tab) { eq->eq_coeff_tab = zalloc(sizeof(int) * 5 * nsection); } for (int i = 0; i < nsection; i++) { eq_seg_design(&eq->eq_seg_tab[i], sr, &eq->eq_coeff_tab[5 * i]); } local_irq_enable(); info->L_coeff = info->R_coeff = (void *)eq->eq_coeff_tab; info->L_gain = info->R_gain = 0; info->nsection = nsection; #else local_irq_disable(); u8 nsection = ARRAY_SIZE(your_audio_out_eq_tab); for (int i = 0; i < nsection; i++) { eq_seg_design(&your_audio_out_eq_tab[i], sr, &your_eq_coeff_tab[i]); } local_irq_enable(); info->L_coeff = info->R_coeff = (void *)your_eq_coeff_tab;//系数指针赋值 info->L_gain = info->R_gain = 0;//总增益填写,用户可修改(-20~20db) info->nsection = nsection;//eq段数,根据提供给的系数表来填写,例子是2 #endif return 0; } struct drc_ch drc_fliter = {0}; #define your_threshold (0) /*----------------------------------------------------------------------------*/ /**@brief 自定义限幅器系数回调 @param *drc: 句柄 @param *info: 系数结构地址 @return @note */ /*----------------------------------------------------------------------------*/ int drc_get_filter_info_demo(void *drc, struct audio_drc_filter_info *info) { int th = your_threshold;//-60 ~0db int threshold = round(pow(10.0, th / 20.0) * 32768); // 0db:32768, -60db:33 drc_fliter.nband = 1; drc_fliter.type = 1; drc_fliter._p.limiter[0].attacktime = 5; drc_fliter._p.limiter[0].releasetime = 300; drc_fliter._p.limiter[0].threshold[0] = threshold; drc_fliter._p.limiter[0].threshold[1] = 32768; info->pch = info->R_pch = &drc_fliter; return 0; } struct drc_ch drc_fliter2 = {0}; #define your_threshold1 (0) #define your_threshold2 (0) /*----------------------------------------------------------------------------*/ /**@brief 自定义压缩器系数回调 @param *drc: 句柄 @param *info: 系数结构地址 @return @note */ /*----------------------------------------------------------------------------*/ int drc_get_filter_info_demo2(void *drc, struct audio_drc_filter_info *info) { int th1 = your_threshold1;//-60 ~0db int th2 = your_threshold2;//-60 ~0db int your_ratio0 = 800;//100~1000 int your_ratio1 = 900;//100~1000 if (th2 < th1) { //阈值2需大于等于阈值1 th2 = th1; } if (your_ratio1 < your_ratio0) { //压缩比2需要大于等于压缩比1 your_ratio1 = your_ratio0; } int threshold0 = round(pow(10.0, th1 / 20.0) * 32768); // 0db:32768, -60db:33 int threshold1 = round(pow(10.0, th2 / 20.0) * 32768); // 0db:32768, -60db:33 drc_fliter2.nband = 1;//全带 drc_fliter2.type = 2;//压缩器 drc_fliter2._p.compressor[0].attacktime = 5; drc_fliter2._p.compressor[0].releasetime = 300; drc_fliter2._p.compressor[0].threshold[0] = threshold0; drc_fliter2._p.compressor[0].threshold[1] = threshold1; drc_fliter2._p.compressor[0].threshold[2] = 32768; drc_fliter2._p.compressor[0].ratio[0] = 100; drc_fliter2._p.compressor[0].ratio[1] = your_ratio0; drc_fliter2._p.compressor[0].ratio[2] = your_ratio1; info->pch = info->R_pch = &drc_fliter2; return 0; } //修改自定义模式eq系数表,更新系数到eq 方法 // 板极头文件中 这两宏 配0 #define TCFG_EQ_ONLINE_ENABLE 0 //支持在线EQ调试, #define TCFG_USE_EQ_FILE 0 //离线eq使用配置文件还是默认系数表 1:使用文件 0 使用默认系数表 // 在sdk中实现以下接函数 /*----------------------------------------------------------------------------*/ /**@brief 设置用户自定义模式每段eq信息 @param @param @return @note */ /*----------------------------------------------------------------------------*/ int eq_mode_set_custom_info_user(struct eq_seg_info *seg) { if (!config_audio_eq_file_en) { if (!seg) { return 0; } u16 index = seg->index; //第几段eq EQ_CFG *eq_cfg = get_eq_cfg_hdl(); if (index >= eq_cfg->section_max) { return 0; } int *tmp = (int *)eq_cfg->eq_type_tab; EQ_CFG_SEG *tab_custom = (EQ_CFG_SEG *)tmp[EQ_MODE_CUSTOM]; index = eq_cfg->eq_mode_use_idx[index]; memcpy(&tab_custom[index], seg, sizeof(struct eq_seg_info));//更新参数到自定义模式系数表 /* log_debug("idx:%d, iir:%d, freq:%d, gain:%d, q:%d ", seg->index, seg->iir_type, seg->freq, seg->gain, seg->q); */ } return 0; } /*----------------------------------------------------------------------------*/ /**@brief 获取某个模式eq表内,某一段eq的信息 @param @param @return 返回eq信息 @note */ /*----------------------------------------------------------------------------*/ struct eq_seg_info *eq_mode_get_custom_info_user(EQ_MODE mode, u8 index) { if (!config_audio_eq_file_en) { EQ_CFG *eq_cfg = get_eq_cfg_hdl(); if (index >= eq_cfg->section_max) { return 0; } int *tmp = (int *)eq_cfg->eq_type_tab; EQ_CFG_SEG *seg = (EQ_CFG_SEG *)tmp[mode]; index = eq_cfg->eq_mode_use_idx[index]; /* log_debug("idx:%d, iir:%d, freq:%d, gain:%d, q:%d ", seg->index, seg->iir_type, seg->freq, seg->gain, seg->q); */ return &seg[index]; } return 0; } /*设置总增益后,需要设置更新*/ void update_global_gain_demo(float global_gain) { EQ_CFG *eq_cfg = get_eq_cfg_hdl(); set_global_gain(eq_cfg, song_eq_mode, global_gain);//设置总增益, eq_mode_set(EQ_MODE_CUSTOM);//设置自定义模式、更新系数以及总增益 } /*设置参数后,需要设置更新*/ void update_eq_seg_info_demo(struct eq_seg_info *seg) { eq_mode_set_custom_info_user(seg);//更新参数到自定义模式系数表 eq_mode_set(EQ_MODE_CUSTOM);//设置自定义模式、更新系数以及总增益 } void update_custom_info_demo2(u16 index, int freq, int gain) { eq_mode_set_custom_info(index, freq, gain);/*改某一段eq的的中心截止频率 以及增益*/ eq_mode_set(EQ_MODE_CUSTOM);//设置自定义模式、更新系数以及总增益 } #endif #endif #endif