2022-08-15 04:20:27 -05:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2015-2019 BES.
|
|
|
|
* All rights reserved. All unpublished rights reserved.
|
|
|
|
*
|
|
|
|
* No part of this work may be used or reproduced in any form or by any
|
|
|
|
* means, or stored in a database or retrieval system, without prior written
|
|
|
|
* permission of BES.
|
|
|
|
*
|
|
|
|
* Use of this work is governed by a license granted by BES.
|
|
|
|
* This work contains confidential and proprietary information of
|
|
|
|
* BES. which is protected by copyright, trade secret,
|
|
|
|
* trademark and other intellectual property rights.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
/*******************************************************************************
|
|
|
|
** namer : Audio Process
|
2023-02-01 14:52:54 -06:00
|
|
|
** description : Manage auido process algorithms, include :hw iir eq, sw iir
|
|
|
|
*eq,
|
2022-08-15 04:20:27 -05:00
|
|
|
** hw fir eq, drc...
|
|
|
|
** version : V1.0
|
|
|
|
** author : Yunjie Huo
|
|
|
|
** modify : 2018.12.4
|
|
|
|
** todo : NULL
|
|
|
|
** MIPS : NO PROCESS: 34M(TWS, one ear, Mono, AAC, 48k)
|
|
|
|
** DRC1: 36M(3 bands)
|
|
|
|
** DRC2: 12M
|
|
|
|
*******************************************************************************/
|
|
|
|
/*
|
|
|
|
Audio Flow:
|
|
|
|
DECODE --> SW IIR EQ --> DRC --> LIMTER --> VOLUME --> HW IIR EQ --> SPK
|
|
|
|
|
|
|
|
+-----------------------------+
|
2023-02-01 14:52:54 -06:00
|
|
|
| DAC | | |
|
|
|
|
+--------+ +-----------+ +-----+ +--------+ | +--------+
|
|
|
|
+-----------+ | +-----+ | | PCM | | | | | |
|
|
|
|
| | | | | | | | | DECODE +---->+ SW IIR EQ +--->+ DRC
|
|
|
|
+--->+ LIMTER +--->+ VOLUME +--->+ HW IIR EQ +--->+ SPK | | | | | |
|
|
|
|
| | | | | | | | | | |
|
|
|
|
+--------+ +-----------+ +-----+ +--------+ | +--------+
|
|
|
|
+-----------+ | +-----+
|
2022-08-15 04:20:27 -05:00
|
|
|
+-----------------------------+
|
|
|
|
|
|
|
|
| ------------ | ------------------------- | -------- | ----------- |
|
|
|
|
| Algorithm | description | MIPS(M) | RAM(kB) |
|
|
|
|
| ------------ | ------------------------- | -------- | ----------- |
|
|
|
|
| DRC | Dynamic Range Compression | 12M/band | 13 |
|
|
|
|
| Limiter/DRC2 | Limiter | 12M | 5 |
|
|
|
|
| EQ | Equalizer | 1M/band | Almost zero |
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "audio_process.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "audio_cfg.h"
|
|
|
|
#include "drc.h"
|
|
|
|
#include "hal_cmu.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "hal_location.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "hal_timer.h"
|
|
|
|
#include "hal_trace.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "hw_codec_iir_process.h"
|
|
|
|
#include "hw_iir_process.h"
|
|
|
|
#include "limiter.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "stdbool.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "tgt_hardware.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#if defined(USB_EQ_TUNING)
|
|
|
|
#if !defined(__HW_DAC_IIR_EQ_PROCESS__) && !defined(__SW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
#error \
|
|
|
|
"Either HW_DAC_IIR_EQ_PROCESS or SW_IIR_EQ_PROCESS should be defined when enabling USB_EQ_TUNING"
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__PC_CMD_UART__) || defined(USB_EQ_TUNING)
|
|
|
|
#include "hal_cmd.h"
|
|
|
|
|
|
|
|
#if defined(__SW_IIR_EQ_PROCESS__)
|
|
|
|
#define AUDIO_EQ_SW_IIR_UPDATE_CFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_DAC_IIR_EQ_PROCESS__)
|
|
|
|
#define AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_IIR_EQ_PROCESS__)
|
|
|
|
#define AUDIO_EQ_HW_IIR_UPDATE_CFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_FIR_EQ_PROCESS__
|
|
|
|
#define AUDIO_EQ_HW_FIR_UPDATE_CFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC__
|
|
|
|
#define AUDIO_DRC_UPDATE_CFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC2__
|
|
|
|
#define AUDIO_DRC2_UPDATE_CFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__SW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
extern const IIR_CFG_T *const audio_eq_sw_iir_cfg_list[EQ_SW_IIR_LIST_NUM];
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_DAC_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
extern const IIR_CFG_T *const POSSIBLY_UNUSED
|
|
|
|
audio_eq_hw_dac_iir_cfg_list[EQ_HW_DAC_IIR_LIST_NUM];
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
extern const IIR_CFG_T *const POSSIBLY_UNUSED
|
|
|
|
audio_eq_hw_iir_cfg_list[EQ_HW_IIR_LIST_NUM];
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_FIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
extern const FIR_CFG_T *const audio_eq_hw_fir_cfg_list[EQ_HW_FIR_LIST_NUM];
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC__
|
|
|
|
extern const DrcConfig audio_drc_cfg;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC2__
|
|
|
|
extern const LimiterConfig audio_drc2_cfg;
|
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
#if defined(AUDIO_EQ_SW_IIR_UPDATE_CFG) || \
|
|
|
|
defined(AUDIO_EQ_HW_FIR_UPDATE_CFG) || \
|
|
|
|
defined(AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG) || \
|
|
|
|
defined(AUDIO_EQ_HW_IIR_UPDATE_CFG) || defined(AUDIO_DRC_UPDATE_CFG) || \
|
|
|
|
defined(AUDIO_DRC2_UPDATE_CFG)
|
2022-08-15 04:20:27 -05:00
|
|
|
#define AUDIO_UPDATE_CFG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC__
|
2023-02-01 14:52:54 -06:00
|
|
|
#define AUDIO_DRC_NEEDED_SIZE (1024 * 13)
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
|
|
|
#define AUDIO_DRC_NEEDED_SIZE (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC2__
|
2023-02-01 14:52:54 -06:00
|
|
|
#define AUDIO_DRC2_NEEDED_SIZE (1024 * 5)
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
|
|
|
#define AUDIO_DRC2_NEEDED_SIZE (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define AUDIO_MEMORY_SIZE (AUDIO_DRC_NEEDED_SIZE + AUDIO_DRC2_NEEDED_SIZE)
|
|
|
|
|
|
|
|
#if AUDIO_MEMORY_SIZE > 0
|
|
|
|
#include "audio_memory.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CODEC_OUTPUT_DEV
|
2023-02-01 14:52:54 -06:00
|
|
|
#define CODEC_OUTPUT_DEV CFG_HW_AUD_OUTPUT_PATH_SPEAKER_DEV
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
typedef signed int pcm_24bits_t;
|
|
|
|
typedef signed short int pcm_16bits_t;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
typedef struct {
|
|
|
|
enum AUD_BITS_T sample_bits;
|
|
|
|
enum AUD_SAMPRATE_T sample_rate;
|
|
|
|
enum AUD_CHANNEL_NUM_T sw_ch_num;
|
|
|
|
enum AUD_CHANNEL_NUM_T hw_ch_num;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#if defined(__SW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
bool sw_iir_enable;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_DAC_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
bool hw_dac_iir_enable;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
bool hw_iir_enable;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_FIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
bool hw_fir_enable;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AUDIO_MEMORY_SIZE > 0
|
2023-02-01 14:52:54 -06:00
|
|
|
uint8_t *audio_heap;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC__
|
2023-02-01 14:52:54 -06:00
|
|
|
DrcState *drc_st;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC2__
|
2023-02-01 14:52:54 -06:00
|
|
|
LimiterState *drc2_st;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
bool update_cfg;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USB_EQ_TUNING
|
2023-02-01 14:52:54 -06:00
|
|
|
bool eq_updated_cfg;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_SW_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
IIR_CFG_T sw_iir_cfg;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
IIR_CFG_T hw_dac_iir_cfg;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
IIR_CFG_T hw_iir_cfg;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_FIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
FIR_CFG_T hw_fir_cfg;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
bool drc_update;
|
|
|
|
DrcConfig drc_cfg;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC2_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
bool drc2_update;
|
|
|
|
LimiterConfig drc2_cfg;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
} AUDIO_PROCESS_T;
|
|
|
|
|
|
|
|
static AUDIO_PROCESS_T audio_process = {
|
|
|
|
.sample_bits = AUD_BITS_NULL,
|
|
|
|
.sample_rate = AUD_SAMPRATE_NULL,
|
|
|
|
.sw_ch_num = AUD_CHANNEL_NUM_NULL,
|
|
|
|
.hw_ch_num = AUD_CHANNEL_NUM_NULL,
|
|
|
|
|
|
|
|
#if defined(__SW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
.sw_iir_enable = false,
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_DAC_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
.hw_dac_iir_enable = false,
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
.hw_iir_enable = false,
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_FIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
.hw_fir_enable = false,
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_UPDATE_CFG
|
|
|
|
.update_cfg = false,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_SW_IIR_UPDATE_CFG
|
|
|
|
.sw_iir_cfg = {.num = 0},
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG
|
|
|
|
.hw_dac_iir_cfg = {.num = 0},
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_IIR_UPDATE_CFG
|
|
|
|
.hw_iir_cfg = {.num = 0},
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_FIR_UPDATE_CFG
|
|
|
|
.hw_fir_cfg = {.len = 0},
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC_UPDATE_CFG
|
|
|
|
.drc_update = false,
|
2023-02-01 14:52:54 -06:00
|
|
|
.drc_cfg = {.knee = 0,
|
|
|
|
.filter_type = {-1, -1},
|
|
|
|
.band_num = 1,
|
|
|
|
.look_ahead_time = 0,
|
|
|
|
.band_settings =
|
|
|
|
{
|
|
|
|
{0, 0, 1, 1, 1, 1},
|
|
|
|
{0, 0, 1, 1, 1, 1},
|
|
|
|
}},
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC2_UPDATE_CFG
|
|
|
|
.drc2_update = false,
|
2023-02-01 14:52:54 -06:00
|
|
|
.drc2_cfg =
|
|
|
|
{
|
|
|
|
.knee = 0,
|
|
|
|
.look_ahead_time = 0,
|
|
|
|
.threshold = 0,
|
|
|
|
.makeup_gain = 0,
|
|
|
|
.ratio = 1000,
|
|
|
|
.attack_time = 1,
|
|
|
|
.release_time = 1,
|
|
|
|
},
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_eq_set_cfg(const FIR_CFG_T *fir_cfg, const IIR_CFG_T *iir_cfg,
|
|
|
|
AUDIO_EQ_TYPE_T audio_eq_type) {
|
|
|
|
#if defined(__SW_IIR_EQ_PROCESS__) || defined(__HW_FIR_EQ_PROCESS__) || \
|
|
|
|
defined(__HW_DAC_IIR_EQ_PROCESS__) || defined(__HW_IIR_EQ_PROCESS__)
|
|
|
|
switch (audio_eq_type) {
|
2022-08-15 04:20:27 -05:00
|
|
|
#if defined(__SW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
case AUDIO_EQ_TYPE_SW_IIR: {
|
|
|
|
if (iir_cfg) {
|
|
|
|
audio_process.sw_iir_enable = false;
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef USB_EQ_TUNING
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.eq_updated_cfg) {
|
|
|
|
iir_set_cfg(&audio_process.sw_iir_cfg);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
iir_set_cfg(iir_cfg);
|
|
|
|
}
|
|
|
|
audio_process.sw_iir_enable = true;
|
|
|
|
} else {
|
|
|
|
audio_process.sw_iir_enable = false;
|
|
|
|
}
|
|
|
|
} break;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_FIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
case AUDIO_EQ_TYPE_HW_FIR: {
|
|
|
|
if (fir_cfg) {
|
|
|
|
audio_process.hw_fir_enable = false;
|
|
|
|
fir_set_cfg(fir_cfg);
|
|
|
|
audio_process.hw_fir_enable = true;
|
|
|
|
} else {
|
|
|
|
audio_process.hw_fir_enable = false;
|
|
|
|
}
|
|
|
|
} break;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_DAC_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
case AUDIO_EQ_TYPE_HW_DAC_IIR: {
|
|
|
|
if (iir_cfg) {
|
|
|
|
HW_CODEC_IIR_CFG_T *hw_iir_cfg_dac = NULL;
|
|
|
|
enum AUD_SAMPRATE_T sample_rate_hw_dac_iir;
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __AUDIO_RESAMPLE__
|
2023-02-01 14:52:54 -06:00
|
|
|
int i;
|
|
|
|
for (i = 1; i < 129; i++) {
|
|
|
|
if (audio_process.sample_rate == AUD_SAMPRATE_7350 * i)
|
|
|
|
break;
|
|
|
|
if (audio_process.sample_rate == AUD_SAMPRATE_8000 * i)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TRACE(1, "audio_process.sample_rate i:%d", i);
|
|
|
|
if (i == 129)
|
|
|
|
i = 6; // set default eq parameter;
|
|
|
|
sample_rate_hw_dac_iir = i * 8463.541666f; // AUD_SAMPRATE_8463
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
sample_rate_hw_dac_iir = audio_process.sample_rate;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.hw_dac_iir_enable = false;
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef USB_EQ_TUNING
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.eq_updated_cfg) {
|
|
|
|
hw_iir_cfg_dac = hw_codec_iir_get_cfg(sample_rate_hw_dac_iir,
|
|
|
|
&audio_process.hw_dac_iir_cfg);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
hw_iir_cfg_dac = hw_codec_iir_get_cfg(sample_rate_hw_dac_iir, iir_cfg);
|
|
|
|
}
|
|
|
|
ASSERT(hw_iir_cfg_dac != NULL, "[%s] codec IIR parameter error!",
|
|
|
|
__func__);
|
|
|
|
hw_codec_iir_set_cfg(hw_iir_cfg_dac, sample_rate_hw_dac_iir,
|
|
|
|
HW_CODEC_IIR_DAC);
|
|
|
|
audio_process.hw_dac_iir_enable = true;
|
|
|
|
} else {
|
|
|
|
audio_process.hw_dac_iir_enable = false;
|
|
|
|
}
|
|
|
|
} break;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__HW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
case AUDIO_EQ_TYPE_HW_IIR: {
|
|
|
|
if (iir_cfg) {
|
|
|
|
HW_IIR_CFG_T *hw_iir_cfg = NULL;
|
|
|
|
audio_process.hw_iir_enable = false;
|
|
|
|
hw_iir_cfg = hw_iir_get_cfg(audio_process.sample_rate, iir_cfg);
|
|
|
|
ASSERT(hw_iir_cfg != NULL, "[%s] 0x%x codec IIR parameter error!",
|
|
|
|
__func__, (unsigned int)hw_iir_cfg);
|
|
|
|
hw_iir_set_cfg(hw_iir_cfg);
|
|
|
|
audio_process.hw_iir_enable = true;
|
|
|
|
} else {
|
|
|
|
audio_process.hw_iir_enable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
default: {
|
|
|
|
ASSERT(false, "[%s]Error eq type!", __func__);
|
|
|
|
}
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
int SRAM_TEXT_LOC audio_process_run(uint8_t *buf, uint32_t len) {
|
|
|
|
int POSSIBLY_UNUSED pcm_len = 0;
|
|
|
|
|
|
|
|
if (audio_process.sample_bits == AUD_BITS_16) {
|
|
|
|
pcm_len = len / sizeof(pcm_16bits_t);
|
|
|
|
} else if (audio_process.sample_bits == AUD_BITS_24) {
|
|
|
|
pcm_len = len / sizeof(pcm_24bits_t);
|
|
|
|
} else {
|
|
|
|
ASSERT(0, "[%s] bits(%d) is invalid", __func__, audio_process.sample_bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audio_process.sw_ch_num == audio_process.hw_ch_num) {
|
|
|
|
// do nothing
|
|
|
|
} else if (audio_process.sw_ch_num == AUD_CHANNEL_NUM_1 &&
|
|
|
|
audio_process.hw_ch_num == AUD_CHANNEL_NUM_2) {
|
|
|
|
if (audio_process.sample_bits == AUD_BITS_16) {
|
|
|
|
int16_t *pcm_buf = (int16_t *)buf;
|
|
|
|
for (uint32_t i = 0, j = 0; i < pcm_len; i += 2, j++) {
|
|
|
|
pcm_buf[j] = pcm_buf[i];
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
} else {
|
2023-02-01 14:52:54 -06:00
|
|
|
int32_t *pcm_buf = (int32_t *)buf;
|
|
|
|
for (uint32_t i = 0, j = 0; i < pcm_len; i += 2, j++) {
|
|
|
|
pcm_buf[j] = pcm_buf[i];
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
pcm_len /= 2;
|
|
|
|
} else {
|
|
|
|
ASSERT(0, "[%s] sw_ch_num(%d) or hw_ch_num(%d) is invalid", __FUNCTION__,
|
|
|
|
audio_process.sw_ch_num, audio_process.hw_ch_num);
|
|
|
|
}
|
|
|
|
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_PROCESS_DUMP
|
2023-02-01 14:52:54 -06:00
|
|
|
int *buf32 = (int *)buf;
|
|
|
|
for (int i = 0; i < 1024; i++)
|
|
|
|
dump_buf[i] = buf32[2 * i] >> 8;
|
|
|
|
audio_dump_clear_up();
|
|
|
|
audio_dump_add_channel_data(0, dump_buf, 1024);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// int32_t s_time,e_time;
|
|
|
|
// s_time = hal_fast_sys_timer_get();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef __SW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.sw_iir_enable) {
|
|
|
|
iir_run(buf, pcm_len);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_FIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.hw_fir_enable) {
|
|
|
|
fir_run(buf, pcm_len);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC__
|
|
|
|
#ifdef AUDIO_DRC_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.drc_update) {
|
|
|
|
drc_set_config(audio_process.drc_st, &audio_process.drc_cfg);
|
|
|
|
audio_process.drc_update = false;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
drc_process(audio_process.drc_st, buf, pcm_len);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// int32_t m_time = hal_fast_sys_timer_get();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC2__
|
|
|
|
#ifdef AUDIO_DRC2_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.drc2_update) {
|
|
|
|
limiter_set_config(audio_process.drc2_st, &audio_process.drc2_cfg);
|
|
|
|
audio_process.drc2_update = false;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
limiter_process(audio_process.drc2_st, buf, pcm_len);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.hw_iir_enable) {
|
|
|
|
hw_iir_run(buf, pcm_len);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (audio_process.sw_ch_num == audio_process.hw_ch_num) {
|
|
|
|
// do nothing
|
|
|
|
} else if (audio_process.sw_ch_num == AUD_CHANNEL_NUM_1 &&
|
|
|
|
audio_process.hw_ch_num == AUD_CHANNEL_NUM_2) {
|
|
|
|
if (audio_process.sample_bits == AUD_BITS_16) {
|
|
|
|
int16_t *pcm_buf = (int16_t *)buf;
|
|
|
|
for (int32_t i = pcm_len - 1, j = 2 * pcm_len - 1; i >= 0; i--, j -= 2) {
|
|
|
|
pcm_buf[j + 1] = pcm_buf[i];
|
|
|
|
pcm_buf[j + 0] = pcm_buf[i];
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
} else {
|
2023-02-01 14:52:54 -06:00
|
|
|
int32_t *pcm_buf = (int32_t *)buf;
|
|
|
|
for (int32_t i = pcm_len - 1, j = 2 * pcm_len - 2; i >= 0; i--, j -= 2) {
|
|
|
|
pcm_buf[j + 1] = pcm_buf[i];
|
|
|
|
pcm_buf[j + 0] = pcm_buf[i];
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
pcm_len *= 2;
|
|
|
|
} else {
|
|
|
|
ASSERT(0, "[%s] sw_ch_num(%d) or hw_ch_num(%d) is invalid", __FUNCTION__,
|
|
|
|
audio_process.sw_ch_num, audio_process.hw_ch_num);
|
|
|
|
}
|
|
|
|
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_PROCESS_DUMP
|
2023-02-01 14:52:54 -06:00
|
|
|
// for(int i=0;i<1024;i++)
|
|
|
|
// dump_buf[i] = buf32[2 * i+0]>>8;
|
|
|
|
// audio_dump_add_channel_data(1, dump_buf, 1024);
|
|
|
|
audio_dump_run();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// e_time = hal_fast_sys_timer_get();
|
|
|
|
// TRACE(4,"[%s] Sample len = %d, drc1 %d us, drc2 %d us",
|
|
|
|
// __func__, pcm_len, FAST_TICKS_TO_US(m_time - s_time),
|
|
|
|
// FAST_TICKS_TO_US(e_time - m_time));
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* frame_size stands for samples per channel
|
|
|
|
*/
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_process_open(enum AUD_SAMPRATE_T sample_rate,
|
|
|
|
enum AUD_BITS_T sample_bits,
|
|
|
|
enum AUD_CHANNEL_NUM_T sw_ch_num,
|
|
|
|
enum AUD_CHANNEL_NUM_T hw_ch_num, int32_t frame_size,
|
|
|
|
void *eq_buf, uint32_t len) {
|
|
|
|
TRACE(
|
|
|
|
5,
|
|
|
|
"[%s] sample_rate = %d, sample_bits = %d, sw_ch_num = %d, hw_ch_num = %d",
|
|
|
|
__func__, sample_rate, sample_bits, sw_ch_num, hw_ch_num);
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_PROCESS_DUMP
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_dump_init(1024, sizeof(short), 2);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.sample_rate = sample_rate;
|
|
|
|
audio_process.sample_bits = sample_bits;
|
|
|
|
audio_process.sw_ch_num = sw_ch_num;
|
|
|
|
audio_process.hw_ch_num = hw_ch_num;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#if defined(__HW_FIR_EQ_PROCESS__) && defined(__HW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
void *fir_eq_buf = eq_buf;
|
|
|
|
uint32_t fir_len = len / 2;
|
|
|
|
void *iir_eq_buf = (uint8_t *)eq_buf + fir_len;
|
|
|
|
uint32_t iir_len = len / 2;
|
2022-08-15 04:20:27 -05:00
|
|
|
#elif defined(__HW_FIR_EQ_PROCESS__) && !defined(__HW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
void *fir_eq_buf = eq_buf;
|
|
|
|
uint32_t fir_len = len;
|
2022-08-15 04:20:27 -05:00
|
|
|
#elif !defined(__HW_FIR_EQ_PROCESS__) && defined(__HW_IIR_EQ_PROCESS__)
|
2023-02-01 14:52:54 -06:00
|
|
|
void *iir_eq_buf = eq_buf;
|
|
|
|
uint32_t iir_len = len;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __SW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
iir_open(sample_rate, sample_bits, sw_ch_num);
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_EQ_SW_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_eq_set_cfg(NULL, &audio_process.sw_iir_cfg, AUDIO_EQ_TYPE_SW_IIR);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_DAC_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
enum AUD_SAMPRATE_T sample_rate_hw_dac_iir;
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __AUDIO_RESAMPLE__
|
2023-02-01 14:52:54 -06:00
|
|
|
int i;
|
|
|
|
for (i = 1; i < 129; i++) {
|
|
|
|
if (audio_process.sample_rate == AUD_SAMPRATE_7350 * i)
|
|
|
|
break;
|
|
|
|
if (audio_process.sample_rate == AUD_SAMPRATE_8000 * i)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TRACE(1, "sample_rate i:%d", i);
|
|
|
|
if (i == 129)
|
|
|
|
i = 6; // set default eq parameter;
|
|
|
|
sample_rate_hw_dac_iir = i * 8463.541666f; // AUD_SAMPRATE_8463
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
sample_rate_hw_dac_iir = audio_process.sample_rate;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hw_codec_iir_open(sample_rate_hw_dac_iir, HW_CODEC_IIR_DAC, CODEC_OUTPUT_DEV);
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_eq_set_cfg(NULL, &audio_process.hw_dac_iir_cfg,
|
|
|
|
AUDIO_EQ_TYPE_HW_DAC_IIR);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
hw_iir_open(sample_rate, sample_bits, sw_ch_num, iir_eq_buf, iir_len);
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_EQ_HW_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_eq_set_cfg(NULL, &audio_process.hw_iir_cfg, AUDIO_EQ_TYPE_HW_IIR);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_FIR_EQ_PROCESS__
|
|
|
|
#if defined(CHIP_BEST1000) && defined(FIR_HIGHSPEED)
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmu_fir_high_speed_enable(HAL_CMU_FIR_USER_EQ);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
fir_open(sample_rate, sample_bits, sw_ch_num, fir_eq_buf, fir_len);
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_EQ_HW_FIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_eq_set_cfg(&audio_process.hw_fir_cfg, NULL, AUDIO_EQ_TYPE_HW_FIR);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AUDIO_MEMORY_SIZE > 0
|
2023-02-01 14:52:54 -06:00
|
|
|
syspool_get_buff(&audio_process.audio_heap, AUDIO_MEMORY_SIZE);
|
|
|
|
audio_heap_init(audio_process.audio_heap, AUDIO_MEMORY_SIZE);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC__
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.drc_st =
|
|
|
|
drc_create(sample_rate, frame_size, sample_bits, sw_ch_num,
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_DRC_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
&audio_process.drc_cfg
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
&audio_drc_cfg
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
);
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_DRC_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.drc_update = false;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC2__
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.drc2_st =
|
|
|
|
limiter_create(sample_rate, frame_size, sample_bits, sw_ch_num,
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_DRC2_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
&audio_process.drc2_cfg
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
&audio_drc2_cfg
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
);
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_DRC2_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.drc2_update = false;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__PC_CMD_UART__) && defined(USB_AUDIO_APP)
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_open();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_process_close(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __SW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.sw_iir_enable = false;
|
|
|
|
iir_close();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_DAC_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.hw_dac_iir_enable = false;
|
|
|
|
hw_codec_iir_close(HW_CODEC_IIR_DAC);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.hw_iir_enable = false;
|
|
|
|
hw_iir_close();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __HW_FIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.hw_fir_enable = false;
|
|
|
|
fir_close();
|
2022-08-15 04:20:27 -05:00
|
|
|
#if defined(CHIP_BEST1000) && defined(FIR_HIGHSPEED)
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmu_fir_high_speed_disable(HAL_CMU_FIR_USER_EQ);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC__
|
|
|
|
#ifdef AUDIO_DRC_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.drc_update = false;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
drc_destroy(audio_process.drc_st);
|
|
|
|
audio_process.drc_st = NULL;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __AUDIO_DRC2__
|
|
|
|
#ifdef AUDIO_DRC2_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.drc2_update = false;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
limiter_destroy(audio_process.drc2_st);
|
|
|
|
audio_process.drc2_st = NULL;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AUDIO_MEMORY_SIZE > 0
|
2023-02-01 14:52:54 -06:00
|
|
|
size_t total = 0, used = 0, max_used = 0;
|
|
|
|
audio_memory_info(&total, &used, &max_used);
|
|
|
|
TRACE(3, "AUDIO MALLOC MEM: total - %d, used - %d, max_used - %d.", total,
|
|
|
|
used, max_used);
|
|
|
|
ASSERT(used == 0, "[%s] used != 0", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__PC_CMD_UART__) && defined(USB_AUDIO_APP)
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_close();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(__PC_CMD_UART__) || defined(USB_EQ_TUNING)
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_ping_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
// TRACE(0,"");
|
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_SW_IIR_UPDATE_CFG) && !defined(USB_EQ_TUNING)
|
|
|
|
#ifndef USB_AUDIO_APP
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_eq_sw_iir_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
TRACE(3, "[%s] len = %d, sizeof(struct) = %d", __func__, len,
|
|
|
|
sizeof(IIR_CFG_T));
|
|
|
|
|
|
|
|
if (len != sizeof(IIR_CFG_T)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&audio_process.sw_iir_cfg, buf, sizeof(IIR_CFG_T));
|
|
|
|
TRACE(3, "band num:%d gain0:%d, gain1:%d",
|
|
|
|
(int32_t)audio_process.sw_iir_cfg.num,
|
|
|
|
(int32_t)(audio_process.sw_iir_cfg.gain0 * 10),
|
|
|
|
(int32_t)(audio_process.sw_iir_cfg.gain1 * 10));
|
|
|
|
for (uint8_t i = 0; i < audio_process.sw_iir_cfg.num; i++) {
|
|
|
|
TRACE(5, "band num:%d type %d gain:%d fc:%d q:%d", i,
|
|
|
|
(int32_t)(audio_process.sw_iir_cfg.param[i].type),
|
|
|
|
(int32_t)(audio_process.sw_iir_cfg.param[i].gain * 10),
|
|
|
|
(int32_t)(audio_process.sw_iir_cfg.param[i].fc * 10),
|
|
|
|
(int32_t)(audio_process.sw_iir_cfg.param[i].Q * 10));
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef __SW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
{
|
|
|
|
iir_set_cfg(&audio_process.sw_iir_cfg);
|
|
|
|
audio_process.sw_iir_enable = true;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_eq_sw_iir_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
// IIR_CFG_T *rx_iir_cfg = NULL;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// rx_iir_cfg = (IIR_CFG_T *)buf;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// TRACE(3,"[%s] left gain = %f, right gain = %f", __func__,
|
|
|
|
// rx_iir_cfg->gain0, rx_iir_cfg->gain1);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// for(int i=0; i<rx_iir_cfg->num; i++)
|
|
|
|
// {
|
|
|
|
// TRACE(5,"[%s] iir[%d] gain = %f, f = %f, Q = %f", __func__, i,
|
|
|
|
// rx_iir_cfg->param[i].gain, rx_iir_cfg->param[i].fc,
|
|
|
|
// rx_iir_cfg->param[i].Q);
|
|
|
|
// }
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// audio_eq_set_cfg(NULL,(const IIR_CFG_T *)rx_iir_cfg,AUDIO_EQ_TYPE_SW_IIR);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
iir_update_cfg_tbl(buf, len);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_FIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_eq_hw_fir_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
TRACE(3, "[%s] len = %d, sizeof(struct) = %d", __func__, len,
|
|
|
|
sizeof(FIR_CFG_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (len != sizeof(FIR_CFG_T)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
FIR_CFG_T *rx_fir_cfg = NULL;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
rx_fir_cfg = (FIR_CFG_T *)buf;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(3, "[%s] left gain = %d, right gain = %d", __func__, rx_fir_cfg->gain0,
|
|
|
|
rx_fir_cfg->gain1);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(6, "[%s] len = %d, coef: %d, %d......%d, %d", __func__, rx_fir_cfg->len,
|
|
|
|
rx_fir_cfg->coef[0], rx_fir_cfg->coef[1],
|
|
|
|
rx_fir_cfg->coef[rx_fir_cfg->len - 2],
|
|
|
|
rx_fir_cfg->coef[rx_fir_cfg->len - 1]);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
rx_fir_cfg->gain0 = 6;
|
|
|
|
rx_fir_cfg->gain1 = 6;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (rx_fir_cfg) {
|
|
|
|
memcpy(&audio_process.fir_cfg, rx_fir_cfg, sizeof(audio_process.fir_cfg));
|
|
|
|
audio_process.fir_enable = true;
|
|
|
|
fir_set_cfg(&audio_process.fir_cfg);
|
|
|
|
} else {
|
|
|
|
audio_process.fir_enable = false;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_drc_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
TRACE(3, "[%s] len = %d, sizeof(struct) = %d", __func__, len,
|
|
|
|
sizeof(DrcConfig));
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (len != sizeof(DrcConfig)) {
|
|
|
|
TRACE(1, "[%s] WARNING: Length is different", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.drc_st == NULL) {
|
|
|
|
TRACE(1, "[%s] WARNING: audio_process.drc2_st = NULL", __func__);
|
|
|
|
TRACE(1, "[%s] WARNING: Please Play music, then tuning Limiter", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 2;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
memcpy(&audio_process.drc_cfg, buf, sizeof(DrcConfig));
|
|
|
|
audio_process.drc_update = true;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC2_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_drc2_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
TRACE(3, "[%s] len = %d, sizeof(struct) = %d", __func__, len,
|
|
|
|
sizeof(LimiterConfig));
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (len != sizeof(LimiterConfig)) {
|
|
|
|
TRACE(1, "[%s] WARNING: Length is different", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.drc2_st == NULL) {
|
|
|
|
TRACE(1, "[%s] WARNING: audio_process.drc2_st = NULL", __func__);
|
|
|
|
TRACE(1, "[%s] WARNING: Please Play music, then tuning Limiter", __func__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 2;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
memcpy(&audio_process.drc2_cfg, buf, sizeof(LimiterConfig));
|
|
|
|
audio_process.drc2_update = true;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG) && !defined(USB_EQ_TUNING)
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_eq_hw_dac_iir_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
TRACE(3, "[%s] len = %d, sizeof(struct) = %d", __func__, len,
|
|
|
|
sizeof(IIR_CFG_T));
|
|
|
|
|
|
|
|
if (len != sizeof(IIR_CFG_T)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&audio_process.hw_dac_iir_cfg, buf, sizeof(IIR_CFG_T));
|
|
|
|
TRACE(3, "band num:%d gain0:%d, gain1:%d",
|
|
|
|
(int32_t)audio_process.hw_dac_iir_cfg.num,
|
|
|
|
(int32_t)(audio_process.hw_dac_iir_cfg.gain0 * 10),
|
|
|
|
(int32_t)(audio_process.hw_dac_iir_cfg.gain1 * 10));
|
|
|
|
for (uint8_t i = 0; i < audio_process.hw_dac_iir_cfg.num; i++) {
|
|
|
|
TRACE(5, "band num:%d type %d gain:%d fc:%d q:%d", i,
|
|
|
|
(int32_t)(audio_process.hw_dac_iir_cfg.param[i].type),
|
|
|
|
(int32_t)(audio_process.hw_dac_iir_cfg.param[i].gain * 10),
|
|
|
|
(int32_t)(audio_process.hw_dac_iir_cfg.param[i].fc * 10),
|
|
|
|
(int32_t)(audio_process.hw_dac_iir_cfg.param[i].Q * 10));
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef __HW_DAC_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
{
|
|
|
|
HW_CODEC_IIR_CFG_T *hw_iir_cfg_dac = NULL;
|
|
|
|
enum AUD_SAMPRATE_T sample_rate_hw_dac_iir;
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __AUDIO_RESAMPLE__
|
2023-02-01 14:52:54 -06:00
|
|
|
int i;
|
|
|
|
for (i = 1; i < 129; i++) {
|
|
|
|
if (audio_process.sample_rate == AUD_SAMPRATE_7350 * i)
|
|
|
|
break;
|
|
|
|
if (audio_process.sample_rate == AUD_SAMPRATE_8000 * i)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TRACE(1, "audio_process.sample_rate i:%d", i);
|
|
|
|
if (i == 129)
|
|
|
|
i = 6; // set default eq parameter;
|
|
|
|
sample_rate_hw_dac_iir = i * 8463.541666f; // AUD_SAMPRATE_8463
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
sample_rate_hw_dac_iir = audio_process.sample_rate;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
hw_iir_cfg_dac = hw_codec_iir_get_cfg(sample_rate_hw_dac_iir,
|
|
|
|
&audio_process.hw_dac_iir_cfg);
|
|
|
|
ASSERT(hw_iir_cfg_dac != NULL, "[%s] %d codec IIR parameter error!",
|
|
|
|
__func__, (uint32_t)hw_iir_cfg_dac);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// hal_codec_iir_dump(hw_iir_cfg_dac);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hw_codec_iir_set_cfg(hw_iir_cfg_dac, sample_rate_hw_dac_iir,
|
|
|
|
HW_CODEC_IIR_DAC);
|
|
|
|
audio_process.hw_dac_iir_enable = true;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_eq_hw_iir_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
TRACE(3, "[%s] len = %d, sizeof(struct) = %d", __func__, len,
|
|
|
|
sizeof(IIR_CFG_T));
|
|
|
|
|
|
|
|
if (len != sizeof(IIR_CFG_T)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&audio_process.hw_iir_cfg, buf, sizeof(IIR_CFG_T));
|
|
|
|
TRACE(3, "band num:%d gain0:%d, gain1:%d",
|
|
|
|
(int32_t)audio_process.hw_iir_cfg.num,
|
|
|
|
(int32_t)(audio_process.hw_iir_cfg.gain0 * 10),
|
|
|
|
(int32_t)(audio_process.hw_iir_cfg.gain1 * 10));
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < audio_process.hw_iir_cfg.num; i++) {
|
|
|
|
TRACE(5, "band num:%d type %d gain:%d fc:%d q:%d", i,
|
|
|
|
(int32_t)(audio_process.hw_iir_cfg.param[i].type),
|
|
|
|
(int32_t)(audio_process.hw_iir_cfg.param[i].gain * 10),
|
|
|
|
(int32_t)(audio_process.hw_iir_cfg.param[i].fc * 10),
|
|
|
|
(int32_t)(audio_process.hw_iir_cfg.param[i].Q * 10));
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef __HW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
{
|
|
|
|
HW_IIR_CFG_T *hw_iir_cfg = NULL;
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __AUDIO_RESAMPLE__
|
2023-02-01 14:52:54 -06:00
|
|
|
enum AUD_SAMPRATE_T sample_rate_hw_iir = AUD_SAMPRATE_50781;
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
enum AUD_SAMPRATE_T sample_rate_hw_iir = audio_process.sample_rate;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
hw_iir_cfg = hw_iir_get_cfg(sample_rate_hw_iir, &audio_process.hw_iir_cfg);
|
|
|
|
ASSERT(hw_iir_cfg != NULL, "[%s] %d codec IIR parameter error!", __func__,
|
|
|
|
hw_iir_cfg);
|
|
|
|
hw_iir_set_cfg(hw_iir_cfg);
|
|
|
|
audio_process.hw_iir_enable = true;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif // #ifdef __PC_CMD_UART__
|
|
|
|
|
|
|
|
#ifdef USB_EQ_TUNING
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_eq_usb_iir_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
IIR_CFG_T *cur_cfg;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(2, "usb_iir_cb: len=[%d - %d]", len, sizeof(IIR_CFG_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (len != sizeof(IIR_CFG_T)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
cur_cfg = (IIR_CFG_T *)buf;
|
|
|
|
TRACE(2, "-> sample_rate[%d], num[%d]",
|
|
|
|
/*cur_cfg->samplerate,*/ audio_process.sample_rate, cur_cfg->num);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_SW_IIR_UPDATE_CFG)
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.sw_iir_cfg.gain0 = cur_cfg->gain0;
|
|
|
|
audio_process.sw_iir_cfg.gain1 = cur_cfg->gain1;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG)
|
|
|
|
#if defined(AUDIO_EQ_SW_IIR_UPDATE_CFG)
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.hw_dac_iir_cfg.gain0 = 0;
|
|
|
|
audio_process.hw_dac_iir_cfg.gain1 = 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.hw_dac_iir_cfg.gain0 = cur_cfg->gain0;
|
|
|
|
audio_process.hw_dac_iir_cfg.gain1 = cur_cfg->gain1;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG)
|
2023-02-01 14:52:54 -06:00
|
|
|
if (cur_cfg->num > AUD_DAC_IIR_NUM_EQ) {
|
|
|
|
audio_process.hw_dac_iir_cfg.num = AUD_DAC_IIR_NUM_EQ;
|
|
|
|
} else {
|
|
|
|
audio_process.hw_dac_iir_cfg.num = cur_cfg->num;
|
|
|
|
}
|
|
|
|
TRACE(1, "-> hw_dac_iir_num[%d]", audio_process.hw_dac_iir_cfg.num);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_SW_IIR_UPDATE_CFG)
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.sw_iir_cfg.num =
|
|
|
|
cur_cfg->num - audio_process.hw_dac_iir_cfg.num;
|
|
|
|
TRACE(1, "-> sw_iir_num[%d]", audio_process.sw_iir_cfg.num);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
// TRACE(2,"-> iir_num[%d - %d]", audio_process.hw_dac_iir_cfg.num,
|
|
|
|
// audio_process.sw_iir_cfg.num);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG)
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.hw_dac_iir_cfg.num) {
|
|
|
|
memcpy((void *)(&audio_process.hw_dac_iir_cfg.param[0]),
|
|
|
|
(void *)(&cur_cfg->param[0]),
|
|
|
|
audio_process.hw_dac_iir_cfg.num * sizeof(IIR_PARAM_T));
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_SW_IIR_UPDATE_CFG)
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.sw_iir_cfg.num) {
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
memcpy((void *)(&audio_process.sw_iir_cfg.param[0]),
|
|
|
|
(void *)(&cur_cfg->param[audio_process.hw_dac_iir_cfg.num]),
|
|
|
|
audio_process.sw_iir_cfg.num * sizeof(IIR_PARAM_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
} else {
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// set a default filter
|
|
|
|
audio_process.sw_iir_cfg.num = 1;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.sw_iir_cfg.param[0].fc = 1000.0;
|
|
|
|
audio_process.sw_iir_cfg.param[0].gain = 0.0;
|
|
|
|
audio_process.sw_iir_cfg.param[0].type = IIR_TYPE_PEAK;
|
|
|
|
audio_process.sw_iir_cfg.param[0].Q = 1.0;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.sample_rate) {
|
|
|
|
audio_process.update_cfg = true;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.eq_updated_cfg = true;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void audio_eq_usb_eq_update(void) {
|
|
|
|
if (audio_process.update_cfg) {
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG)
|
2023-02-01 14:52:54 -06:00
|
|
|
HW_CODEC_IIR_CFG_T *hw_iir_cfg_dac = NULL;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (audio_process.hw_dac_iir_cfg.num) {
|
|
|
|
enum AUD_SAMPRATE_T sample_rate_hw_dac_iir;
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __AUDIO_RESAMPLE__
|
2023-02-01 14:52:54 -06:00
|
|
|
int i;
|
|
|
|
for (i = 1; i < 129; i++) {
|
|
|
|
if (audio_process.sample_rate == AUD_SAMPRATE_7350 * i)
|
|
|
|
break;
|
|
|
|
if (audio_process.sample_rate == AUD_SAMPRATE_8000 * i)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TRACE(1, "audio_process.sample_rate i:%d", i);
|
|
|
|
if (i == 129)
|
|
|
|
i = 6; // set default eq parameter;
|
|
|
|
sample_rate_hw_dac_iir = i * 8463.541666f; // AUD_SAMPRATE_8463
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
sample_rate_hw_dac_iir = audio_process.sample_rate;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
hw_iir_cfg_dac = hw_codec_iir_get_cfg(sample_rate_hw_dac_iir,
|
|
|
|
&audio_process.hw_dac_iir_cfg);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hw_codec_iir_set_cfg(hw_iir_cfg_dac, sample_rate_hw_dac_iir,
|
|
|
|
HW_CODEC_IIR_DAC);
|
|
|
|
audio_process.hw_dac_iir_enable = true;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
} else {
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.hw_dac_iir_enable = false;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(AUDIO_EQ_SW_IIR_UPDATE_CFG)
|
2023-02-01 14:52:54 -06:00
|
|
|
iir_set_cfg(&audio_process.sw_iir_cfg);
|
|
|
|
audio_process.sw_iir_enable = true;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_process.update_cfg = false;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
/*
|
|
|
|
TRACE(4,"USB EQ Update: en[%d-%d], num[%d-%d]",
|
|
|
|
audio_process.hw_dac_iir_enable,
|
|
|
|
audio_process.sw_iir_enable, audio_process.hw_dac_iir_cfg.num,
|
|
|
|
audio_process.sw_iir_cfg.num);
|
|
|
|
*/
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
#endif // USB_EQ_TUNING
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
typedef struct {
|
2023-02-01 14:52:54 -06:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t maxEqBandNum;
|
|
|
|
uint16_t sample_rate_num;
|
|
|
|
uint8_t sample_rate[50];
|
2022-08-15 04:20:27 -05:00
|
|
|
} query_eq_info_t;
|
|
|
|
|
|
|
|
extern int getMaxEqBand(void);
|
2023-02-01 14:52:54 -06:00
|
|
|
extern int getSampleArray(uint8_t *buf, uint16_t *num);
|
|
|
|
|
|
|
|
extern void hal_cmd_set_res_playload(uint8_t *data, int len);
|
|
|
|
#define CMD_TYPE_QUERY_DUT_EQ_INFO 0x00
|
|
|
|
int audio_cmd_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
uint8_t type;
|
|
|
|
// uint32_t* sample_rate;
|
|
|
|
// uint8_t* p;
|
|
|
|
query_eq_info_t info;
|
|
|
|
|
|
|
|
type = buf[0];
|
|
|
|
// p = buf + 1;
|
|
|
|
|
|
|
|
TRACE(2, "%s type: %d", __func__, type);
|
|
|
|
switch (type) {
|
|
|
|
case CMD_TYPE_QUERY_DUT_EQ_INFO:
|
|
|
|
info.type = CMD_TYPE_QUERY_DUT_EQ_INFO;
|
|
|
|
info.maxEqBandNum = getMaxEqBand();
|
|
|
|
getSampleArray(info.sample_rate, &info.sample_rate_num);
|
|
|
|
|
|
|
|
hal_cmd_set_res_playload((uint8_t *)&info, 4 + info.sample_rate_num * 4);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef AUDIO_SECTION_ENABLE
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_cfg_burn_callback(uint8_t *buf, uint32_t len) {
|
|
|
|
TRACE(3, "[%s] len = %d, sizeof(struct) = %d", __func__, len,
|
|
|
|
sizeof_audio_cfg());
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (len != sizeof_audio_cfg()) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
int res = 0;
|
|
|
|
res = store_audio_cfg_into_audio_section((AUDIO_CFG_T *)buf);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (res) {
|
|
|
|
TRACE(2, "[%s] ERROR: res = %d", __func__, res);
|
|
|
|
res += 100;
|
|
|
|
} else {
|
|
|
|
TRACE(1, "[%s] Store audio cfg into audio section!!!", __func__);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return res;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_process_init(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __PC_CMD_UART__
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_init();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_SW_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_register("iir_eq", audio_eq_sw_iir_callback); // Will be removed
|
|
|
|
hal_cmd_register("sw_iir_eq", audio_eq_sw_iir_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_register("iir_eq", audio_eq_hw_dac_iir_callback); // Will be removed
|
|
|
|
hal_cmd_register("dac_iir_eq", audio_eq_hw_dac_iir_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_register("iir_eq", audio_eq_hw_iir_callback); // Will be removed
|
|
|
|
hal_cmd_register("hw_iir_eq", audio_eq_hw_iir_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_FIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_register("fir_eq", audio_eq_hw_fir_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_register("drc", audio_drc_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC2_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_register("limiter", audio_drc2_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_SECTION_ENABLE
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_register("burn", audio_cfg_burn_callback);
|
|
|
|
hal_cmd_register("audio_burn", audio_cfg_burn_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_register("cmd", audio_cmd_callback);
|
|
|
|
hal_cmd_register("ping", audio_ping_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USB_EQ_TUNING
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_init();
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
#if defined(AUDIO_EQ_SW_IIR_UPDATE_CFG) || \
|
|
|
|
defined(AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG)
|
|
|
|
hal_cmd_register("iir_eq", audio_eq_usb_iir_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
hal_cmd_register("cmd", audio_cmd_callback);
|
|
|
|
hal_cmd_register("ping", audio_ping_callback);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// load default cfg
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef AUDIO_EQ_SW_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
memcpy(&audio_process.sw_iir_cfg, audio_eq_sw_iir_cfg_list[0],
|
|
|
|
sizeof(IIR_CFG_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_DAC_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
memcpy(&audio_process.hw_dac_iir_cfg, audio_eq_hw_dac_iir_cfg_list[0],
|
|
|
|
sizeof(IIR_CFG_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_IIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
memcpy(&audio_process.hw_iir_cfg, audio_eq_hw_iir_cfg_list[0],
|
|
|
|
sizeof(IIR_CFG_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_EQ_HW_FIR_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
memcpy(&audio_process.hw_fir_cfg, audio_eq_hw_fir_cfg_list[0],
|
|
|
|
sizeof(FIR_CFG_T));
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
memcpy(&audio_process.drc_cfg, &audio_drc_cfg, sizeof(DrcConfig));
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef AUDIO_DRC2_UPDATE_CFG
|
2023-02-01 14:52:54 -06:00
|
|
|
memcpy(&audio_process.drc2_cfg, &audio_drc2_cfg, sizeof(LimiterConfig));
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|