KT24-1110_65E-HA-651B/cpu/br25/audio_effect/eq_config.c

363 lines
12 KiB
C
Raw Permalink Normal View History

2024-11-10 10:44:17 +00:00
#include "system/includes.h"
#include "media/includes.h"
#include "media/effects_adj.h"
#include "app_config.h"
#include "app_online_cfg.h"
#include "online_db/online_db_deal.h"
#include "media/audio_eq_drc_apply.h"
#include "config/config_interface.h"
#include "audio_eff_default_parm.h"
//eq_cfg_hw.bin中播歌eq曲线当作用户自定义模式参与效果切换.
#define EQ_FILE_CP_TO_CUSTOM 0
#if defined(TCFG_EQ_ENABLE) && TCFG_EQ_ENABLE
const struct eq_seg_info eq_tab_normal[] = {
{0, EQ_IIR_TYPE_BAND_PASS, 31, 0, 0.7f},
{1, EQ_IIR_TYPE_BAND_PASS, 62, 0, 0.7f},
{2, EQ_IIR_TYPE_BAND_PASS, 125, 0, 0.7f},
{3, EQ_IIR_TYPE_BAND_PASS, 250, 0, 0.7f},
{4, EQ_IIR_TYPE_BAND_PASS, 500, 0, 0.7f},
{5, EQ_IIR_TYPE_BAND_PASS, 1000, 0, 0.7f},
{6, EQ_IIR_TYPE_BAND_PASS, 2000, 0, 0.7f},
{7, EQ_IIR_TYPE_BAND_PASS, 4000, 0, 0.7f},
{8, EQ_IIR_TYPE_BAND_PASS, 8000, 0, 0.7f},
{9, EQ_IIR_TYPE_BAND_PASS, 16000, 0, 0.7f},
};
const struct eq_seg_info eq_tab_rock[] = {
{0, EQ_IIR_TYPE_BAND_PASS, 31, -2, 0.7f},
{1, EQ_IIR_TYPE_BAND_PASS, 62, 0, 0.7f},
{2, EQ_IIR_TYPE_BAND_PASS, 125, 2, 0.7f},
{3, EQ_IIR_TYPE_BAND_PASS, 250, 4, 0.7f},
{4, EQ_IIR_TYPE_BAND_PASS, 500, -2, 0.7f},
{5, EQ_IIR_TYPE_BAND_PASS, 1000, -2, 0.7f},
{6, EQ_IIR_TYPE_BAND_PASS, 2000, 0, 0.7f},
{7, EQ_IIR_TYPE_BAND_PASS, 4000, 0, 0.7f},
{8, EQ_IIR_TYPE_BAND_PASS, 8000, 4, 0.7f},
{9, EQ_IIR_TYPE_BAND_PASS, 16000, 4, 0.7f},
};
const struct eq_seg_info eq_tab_pop[] = {
{0, EQ_IIR_TYPE_BAND_PASS, 31, 3, 0.7f},
{1, EQ_IIR_TYPE_BAND_PASS, 62, 1, 0.7f},
{2, EQ_IIR_TYPE_BAND_PASS, 125, 0, 0.7f},
{3, EQ_IIR_TYPE_BAND_PASS, 250, -2, 0.7f},
{4, EQ_IIR_TYPE_BAND_PASS, 500, -4, 0.7f},
{5, EQ_IIR_TYPE_BAND_PASS, 1000, -4, 0.7f},
{6, EQ_IIR_TYPE_BAND_PASS, 2000, -2, 0.7f},
{7, EQ_IIR_TYPE_BAND_PASS, 4000, 0, 0.7f},
{8, EQ_IIR_TYPE_BAND_PASS, 8000, 1, 0.7f},
{9, EQ_IIR_TYPE_BAND_PASS, 16000, 2, 0.7f},
};
const struct eq_seg_info eq_tab_classic[] = {
{0, EQ_IIR_TYPE_BAND_PASS, 31, 0, 0.7f},
{1, EQ_IIR_TYPE_BAND_PASS, 62, 8, 0.7f},
{2, EQ_IIR_TYPE_BAND_PASS, 125, 8, 0.7f},
{3, EQ_IIR_TYPE_BAND_PASS, 250, 4, 0.7f},
{4, EQ_IIR_TYPE_BAND_PASS, 500, 0, 0.7f},
{5, EQ_IIR_TYPE_BAND_PASS, 1000, 0, 0.7f},
{6, EQ_IIR_TYPE_BAND_PASS, 2000, 0, 0.7f},
{7, EQ_IIR_TYPE_BAND_PASS, 4000, 0, 0.7f},
{8, EQ_IIR_TYPE_BAND_PASS, 8000, 2, 0.7f},
{9, EQ_IIR_TYPE_BAND_PASS, 16000, 2, 0.7f},
};
const struct eq_seg_info eq_tab_country[] = {
{0, EQ_IIR_TYPE_BAND_PASS, 31, -2, 0.7f},
{1, EQ_IIR_TYPE_BAND_PASS, 62, 0, 0.7f},
{2, EQ_IIR_TYPE_BAND_PASS, 125, 0, 0.7f},
{3, EQ_IIR_TYPE_BAND_PASS, 250, 2, 0.7f},
{4, EQ_IIR_TYPE_BAND_PASS, 500, 2, 0.7f},
{5, EQ_IIR_TYPE_BAND_PASS, 1000, 0, 0.7f},
{6, EQ_IIR_TYPE_BAND_PASS, 2000, 0, 0.7f},
{7, EQ_IIR_TYPE_BAND_PASS, 4000, 0, 0.7f},
{8, EQ_IIR_TYPE_BAND_PASS, 8000, 4, 0.7f},
{9, EQ_IIR_TYPE_BAND_PASS, 16000, 4, 0.7f},
};
const struct eq_seg_info eq_tab_jazz[] = {
{0, EQ_IIR_TYPE_BAND_PASS, 31, 0, 0.7f},
{1, EQ_IIR_TYPE_BAND_PASS, 62, 0, 0.7f},
{2, EQ_IIR_TYPE_BAND_PASS, 125, 0, 0.7f},
{3, EQ_IIR_TYPE_BAND_PASS, 250, 4, 0.7f},
{4, EQ_IIR_TYPE_BAND_PASS, 500, 4, 0.7f},
{5, EQ_IIR_TYPE_BAND_PASS, 1000, 4, 0.7f},
{6, EQ_IIR_TYPE_BAND_PASS, 2000, 0, 0.7f},
{7, EQ_IIR_TYPE_BAND_PASS, 4000, 2, 0.7f},
{8, EQ_IIR_TYPE_BAND_PASS, 8000, 3, 0.7f},
{9, EQ_IIR_TYPE_BAND_PASS, 16000, 4, 0.7f},
};
struct eq_seg_info eq_tab_custom[] = {
{0, EQ_IIR_TYPE_BAND_PASS, 31, 0, 0.7f},
{1, EQ_IIR_TYPE_BAND_PASS, 62, 0, 0.7f},
{2, EQ_IIR_TYPE_BAND_PASS, 125, 0, 0.7f},
{3, EQ_IIR_TYPE_BAND_PASS, 250, 0, 0.7f},
{4, EQ_IIR_TYPE_BAND_PASS, 500, 0, 0.7f},
{5, EQ_IIR_TYPE_BAND_PASS, 1000, 0, 0.7f},
{6, EQ_IIR_TYPE_BAND_PASS, 2000, 0, 0.7f},
{7, EQ_IIR_TYPE_BAND_PASS, 4000, 0, 0.7f},
{8, EQ_IIR_TYPE_BAND_PASS, 8000, 0, 0.7f},
{9, EQ_IIR_TYPE_BAND_PASS, 16000, 0, 0.7f},
};
// 默认系数表,用户可修改
const struct eq_seg_info *eq_type_tab[EQ_MODE_MAX] = {
eq_tab_normal, eq_tab_rock, eq_tab_pop, eq_tab_classic, eq_tab_jazz, eq_tab_country, eq_tab_custom
};
// 默认系数表,每个表对应的总增益,用户可修改
float global_gain_tab[EQ_MODE_MAX] = {0, 0, 0, 0, 0, 0, 0};
static const u8 tab_section_num[] = {
ARRAY_SIZE(eq_tab_normal), ARRAY_SIZE(eq_tab_rock),
ARRAY_SIZE(eq_tab_pop), ARRAY_SIZE(eq_tab_classic),
ARRAY_SIZE(eq_tab_jazz), ARRAY_SIZE(eq_tab_country),
ARRAY_SIZE(eq_tab_custom)
};
/*
*mode:EQ_MODE
*return
* */
u8 eq_get_table_nsection(EQ_MODE mode)
{
if (mode >= ARRAY_SIZE(eq_type_tab)) {
log_e("mode error %d\n", mode);
return 0;
}
if (mode >= ARRAY_SIZE(tab_section_num)) {
log_e("mode error %d\n", mode);
return 0;
}
return tab_section_num[mode];
}
static u8 eq_mode = 0;
//eq效果表切换
int eq_mode_sw(void)
{
eq_mode++;
if (eq_mode >= ARRAY_SIZE(eq_type_tab)) {
eq_mode = 0;
}
struct eq_seg_info *seg = (struct eq_seg_info *)eq_type_tab[eq_mode];
u8 nsection = ARRAY_SIZE(eq_tab_normal);
if (nsection > mSECTION_MAX) {
log_e("ERROR nsection:%d > mSECTION_MAX:%d ", nsection, mSECTION_MAX);
return -1;//
}
struct audio_eq *eq = get_cur_eq_hdl_by_name(AEID_MUSIC_EQ);
if (!eq) {
//eq未运行时覆盖music eq的系数buf
music_mode[nor_label].eq_parm.seg_num = nsection;
music_mode[nor_label].eq_parm.global_gain = global_gain_tab[eq_mode];
memcpy(music_mode[nor_label].eq_parm.seg, seg, sizeof(struct eq_seg_info)*nsection);
}
//music eq运行时直接设置更新
cur_eq_set_global_gain(AEID_MUSIC_EQ, global_gain_tab[eq_mode]);
for (int i = 0; i < nsection; i++) {
cur_eq_set_update(AEID_MUSIC_EQ, &seg[i], nsection, 0);
}
return 0;
}
//指定设置某个eq效果表
int eq_mode_set(EQ_MODE mode)
{
if (mode >= ARRAY_SIZE(eq_type_tab)) {
log_e("mode err %d\n", mode);
return -1;//
}
eq_mode = mode;
struct eq_seg_info *seg = (struct eq_seg_info *)eq_type_tab[eq_mode];
u8 nsection = ARRAY_SIZE(eq_tab_normal);
if (nsection > mSECTION_MAX) {
log_e("ERROR nsection:%d > mSECTION_MAX:%d ", nsection, mSECTION_MAX);
return -1;//
}
struct audio_eq *eq = get_cur_eq_hdl_by_name(AEID_MUSIC_EQ);
if (!eq) {
//eq未运行时覆盖music eq的系数buf
music_mode[nor_label].eq_parm.seg_num = nsection;
music_mode[nor_label].eq_parm.global_gain = global_gain_tab[eq_mode];
memcpy(music_mode[nor_label].eq_parm.seg, seg, sizeof(struct eq_seg_info)*nsection);
}
//music eq运行时直接设置更新
cur_eq_set_global_gain(AEID_MUSIC_EQ, global_gain_tab[eq_mode]);
for (int i = 0; i < nsection; i++) {
cur_eq_set_update(AEID_MUSIC_EQ, &seg[i], nsection, 0);
}
return 0;
}
//返回某个eq效果模式标号
EQ_MODE eq_mode_get_cur(void)
{
return eq_mode;
}
/*----------------------------------------------------------------------------*/
/**@brief 设置custom系数表的某一段系数
@param seg->index(0)
@param seg->iir_type:(EQ_IIR_TYPE_HIGH_PASS, EQ_IIR_TYPE_LOW_PASS, EQ_IIR_TYPE_BAND_PASS, EQ_IIR_TYPE_HIGH_SHELF,EQ_IIR_TYPE_LOW_SHELF)
@param seg->freq:(20~22kHz)
@param seg->gain:(-18~18)
@param seg->q : q值0.3~30
@return
@note 使
*/
/*----------------------------------------------------------------------------*/
int eq_mode_set_custom_seg(struct eq_seg_info *seg)
{
struct eq_seg_info *tar_seg = eq_tab_custom;
u8 index = seg->index;
if (index > ARRAY_SIZE(eq_tab_custom)) {
log_e("index %d > max_nsection %d", index, ARRAY_SIZE(eq_tab_custom));
return -1;
}
memcpy(&tar_seg[index], seg, sizeof(struct eq_seg_info));
return 0;
}
/*----------------------------------------------------------------------------*/
/**@brief 获取某个模式eq表内某一段eq的信息
@param
@param
@return eq信息
@note
*/
/*----------------------------------------------------------------------------*/
struct eq_seg_info *eq_mode_get_seg(EQ_MODE mode, u8 index)
{
if (mode >= ARRAY_SIZE(eq_type_tab)) {
log_e("mode error %d\n", mode);
return NULL;
}
if (index >= eq_get_table_nsection(mode)) {
log_e("index error %d\n", index);
return NULL;
}
struct eq_seg_info *seg = (struct eq_seg_info *)eq_type_tab[mode];
return &seg[index];
}
/*----------------------------------------------------------------------------*/
/**@brief 获取custom系数表的增益、频率
@param index:
@param freq:
@param gain:
@return
@note 使
*/
/*----------------------------------------------------------------------------*/
int eq_mode_set_custom_info(u16 index, int freq, float gain)
{
struct eq_seg_info *seg = eq_mode_get_seg(EQ_MODE_CUSTOM, index);//获取某段eq系数
if (!seg) {
return -1;
}
seg->freq = freq;//修改freq gain
seg->gain = gain;
eq_mode_set_custom_seg(seg);//重设系数
eq_mode_set(EQ_MODE_CUSTOM);//设置更新系数
return 0;
}
/*----------------------------------------------------------------------------*/
/**@brief 设置用custom系数表一段eq的增益
@param index:
@param gain:
@return
@note 使
*/
/*----------------------------------------------------------------------------*/
int eq_mode_set_custom_param(u16 index, int gain)
{
struct eq_seg_info *seg = eq_mode_get_seg(EQ_MODE_CUSTOM, index);//获取某段eq系数
if (!seg) {
return -1;
}
seg->gain = gain;
eq_mode_set_custom_seg(seg);//重设系数
eq_mode_set(EQ_MODE_CUSTOM);//设置更新系数
return 0;
}
void cp_eq_file_seg_to_custom_tab()
{
#if EQ_FILE_CP_TO_CUSTOM
u8 nsection = music_mode[nor_label].eq_parm.seg_num;
struct eq_seg_info *seg = eq_tab_custom;
if (nsection > ARRAY_SIZE(eq_tab_custom)) {
log_e("music nsection:%d > custom nsection:%d\n", nsection, ARRAY_SIZE(eq_tab_custom));
return ;
}
global_gain_tab[EQ_MODE_CUSTOM] = music_mode[nor_label].eq_parm.global_gain;
memcpy(seg, music_mode[nor_label].eq_parm.seg, sizeof(struct eq_seg_info)*nsection);
#endif
}
s8 eq_mode_get_gain(EQ_MODE mode, u16 index)
{
struct eq_seg_info *seg = eq_mode_get_seg(mode, index);
if (!seg) {
return 0;
}
return seg->gain;
}
/*----------------------------------------------------------------------------*/
/**@brief 获取某eq系数表一段eq的中心截止频率
@param mode:EQ_MODE_NORMAL, EQ_MODE_ROCK,EQ_MODE_POP,EQ_MODE_CLASSIC,EQ_MODE_JAZZ,EQ_MODE_COUNTRY, EQ_MODE_CUSTOM
@param index:
@return
@note 使
*/
/*----------------------------------------------------------------------------*/
int eq_mode_get_freq(EQ_MODE mode, u16 index)
{
struct eq_seg_info *seg = eq_mode_get_seg(mode, index);
if (!seg) {
return 0;
}
return seg->freq;
}
/*----------------------------------------------------------------------------*/
/**@brief 设置用custom系数表一段eq的增益
@param index:
@param gain:
@return
@note 使
*/
/*----------------------------------------------------------------------------*/
void set_global_gain(EQ_MODE mode, float global_gain)
{
global_gain_tab[mode] = global_gain;
cur_eq_set_global_gain(AEID_MUSIC_EQ, global_gain);
}
int eq_init(void)
{
audio_eq_init();
return 0;
}
__initcall(eq_init);
#endif