Audio Interface
概述
Audio Interface (audio_intf) 是 audio 子系统的顶层控制模块,所控制的模块包含 ASRC、ANC、TXDFE、RXDFE、I2S、PDM、Audio timer 等,还包括一些功能控制,如能量估计和饱和检测、啸叫检测、超声检测等功能的控制,其结构如下图所示。
音频接口模块框图
功能特性
Audio Interface 支持如下特性:
支持 16 MHz 和 32MHz 两种 XTAL Clock,默认为 32 MHz
支持 audio PLL 时钟,此时 audio 工作时钟为 15.36 MHz
支持立体声混音
最大支持对 4 路 ASRC 音量独立调节
支持 audio 子系统和 timer 计数和半 us 级同步控制
支持硬件啸叫检测
支持对音频通路的能量估计和饱和监测
支持硬件超声入耳检测
API 介绍
-
struct wq_audio_intf_power_monitor_cfg
Typedefs
-
typedef enum _WQ_AUDIO_OUT_FROM WQ_AUDIO_OUT_FROM
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_TIMER_ID WQ_AUDIO_TIMER_ID
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_RXFIFO_LINK_ASRC WQ_AUDIO_RXFIFO_LINK_ASRC
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_ADC_CHN_MODULE WQ_AUDIO_ADC_CHN_MODULE
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_RX_FIFO_DATA_FORMAT WQ_AUDIO_RX_FIFO_DATA_FORMAT
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_RX_FIFO_HWORD_RST_SRC WQ_AUDIO_RX_FIFO_HWORD_RST_SRC
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_INTF_INTC_ID WQ_AUDIO_INTF_INTC_ID
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_INTF_POWER_MONITOR_SRC WQ_AUDIO_INTF_POWER_MONITOR_SRC
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_INTF_HOWL_DETECT_MODULE WQ_AUDIO_INTF_HOWL_DETECT_MODULE
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_INTF_HOWL_DETECT_SRC WQ_AUDIO_INTF_HOWL_DETECT_SRC
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef enum _WQ_AUDIO_HOWL_DETECT_SRC_RXDFE WQ_AUDIO_HOWL_DETECT_SRC_RXDFE
For specific definitions, please refer to the header file wq_audio_resource.h.
-
typedef void (*wq_audio_inf_timer_callback)(uint32_t id, void *param)
This function is the audio_timer interrupt callback function.
- Param id:
The ID of audio_timer
- Param param:
The param of audio_timer interrupt callback function
-
typedef void (*wq_audio_intf_monitor_power_irq_callback)(uint32_t src)
This function is the power monitor interrupt callback function, e.g: txdfe power saturation irq.
- Param src:
The source of power monitor interrupt
-
typedef void (*wq_audio_intf_howl_detected_callback)(uint32_t id)
This function is the howling detect interrupt callback function.
- Param id:
The id of howling detect module, e.g: id=0 is detect MIC hoeling, id=1, isdetect SPK howling
-
typedef uint8_t (*wq_audio_intf_int_hook)(uint32_t id)
This function is the audio intf interrupt callback function.
- Param id:
The id of audio intf irq id
-
typedef struct wq_audio_intf_howl_detect_config wq_audio_intf_howl_detect_config_t
For specific definitions, please refer to the header file wq_audio_intf.h.
-
typedef struct wq_audio_intf_power_monitor_cfg wq_audio_intf_aud_power_monitor_cfg_t
For specific definitions, please refer to the header file wq_audio_intf.h.
Functions
-
void wq_audio_intf_start_all(void)
This function is to start all the opened moudle by audio intf.
-
WQ_RET wq_audio_fifo_init(void)
This function is to initailize audio rxfifo and txfifo.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_fifo_deinit(void)
This function is to deinitailize audio rxfifo and txfifo.
- 返回:
WQ_RET_OK - success, other - failed
-
uint32_t wq_audio_intf_get_global_clk_status(void)
This function is to obtain the clk enable status of all modules in audio intf.
- 返回:
uitn32_t global clk register enable status
-
WQ_RET wq_audio_rx_fifo_half_word(bool enable)
This function is to configure if audio rx fifo works in half word mode.
- 参数:
enable -- judge audio rx fifo if in half word mode.
- 返回:
WQ_RET_OK - success, other - failed
-
void wq_audio_rx_fifo_half_word_reset(WQ_AUDIO_RX_FIFO_HWORD_RST_SRC src)
This function is to reset half word process, will clear the residual data.
- 参数:
src -- is the half word reset source.
-
void wq_audio_rx_fifo_half_word_reset_multi_src(WQ_AUDIO_RX_FIFO_HWORD_RST_SRC id)
Add RX-FIFO half word source need to sync reset, then use
wq_audio_rx_fifo_half_word_reset_allto reset all source.- 参数:
id -- RX-FIFO half word reset source.
-
void wq_audio_rx_fifo_half_word_reset_all(void)
Sync reset all RX-FIFO half word source, use
wq_audio_rx_fifo_half_word_reset_multi_srcadd source need to sync reset.备注
If half word source is started before RX-FIFO starting, we have to sync reset these source to make sure the multi RX-FIFO data is synchronous.
-
WQ_RET wq_audio_rx_fifo_open(uint8_t id)
This function is to configure dma channel for audio tx fifo and enable.
- 参数:
id -- is audio rx fifo id.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_rx_fifo_close(uint32_t bitmap)
This function is to disable audio rx fifo and free dma channel.
- 参数:
bitmap -- is audio rx fifo id Bit.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_rx_fifo_to_mem_mount_dma(uint8_t id, char *dst, uint32_t size, wq_dma_peri_done_cb cb, void *data)
This function is to mount dma from audio rx fifo to mem buffer.
- 参数:
id -- is audio rx fifo id.
dst -- is pointer of data ready for pull.
size -- is size of data need to pull.
cb -- is callback function called when data transfer done.
data -- is callback function param
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_rx_fifo_link_i2s(uint8_t id, uint8_t i2s_chan)
This function is to configure rx fifo data source from i2s rx channel.
- 参数:
id -- is audio rx fifo id.
i2s_chan -- is audio i2s rx channel.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_rx_fifo_dislink_i2s(uint8_t id)
This function is to dislink rx fifo data source from i2s rx channel.
- 参数:
id -- is audio rx fifo id.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_rx_fifo_link_asrc(uint8_t fifo_id, uint8_t asrc_chn, bool en_multi_link)
This function is to configure rx fifo data source from asrc channel.
- 参数:
fifo_id -- is audio rx fifo start id.
asrc_chn -- is audio asrc channel: 0, 1 or 2, 2 refers to two channels, not asrc_2
en_multi_link -- true is enable multiple link, false is direct link
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_rx_fifo_link_adc(uint8_t id)
This function is to configure rx fifo data source from adc digital.
- 参数:
id -- is audio rx fifo id.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_rx_fifo_link_dfe(uint8_t id, WQ_AUDIO_ADC_CHN_MODULE module)
This function is to configure rx fifo data source from dfe channel.
- 参数:
id -- is audio rx fifo id.
module -- rx dfe module or rxdfe lite module
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_rx_fifo_dislink_dfe(uint8_t id)
This function is to dislink rx fifo and dfe.
- 参数:
id -- is audio rx fifo id.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_rx_fifo_link_asrc_multipath(void)
This function is to multiway rx fifo link asrc.
备注
In some cases, it is necessary to simultaneously link multiple rxfifo links to the corresponding ASRC. Therefore, the link bitmap will be configured in advance, and finally, the unified operation register can achieve multiple simultaneous links
- 返回:
uint8_t WQ_RTE_OK for success else error.
-
void wq_audio_rx_fifo_dislink_asrc_multipath(void)
This function is to multiway rx fifo dislink asrc.
备注
In some cases, it is necessary to simultaneously unlink multiple rxfifo and corresponding asrc. Therefore, based on the link bitmap saved in the software, unified operation registers can be used to achieve simultaneous unlink of multiple channels
-
WQ_RET wq_audio_rx_fifo_link_meter_adc(uint8_t id)
This function is to configure rx fifo data source from meter adc.
- 参数:
id -- is audio rx fifo id.
- 返回:
WQ_RET_OK - success, other - failed
-
void wq_audio_rx_fifo_link_adc_multipath(void)
This function is to multiway rx fifo link adc.
-
void wq_audio_rx_fifo_dislink_adc_multipath(void)
This function is to multiway rx fifo dislink adc.
-
void wq_audio_rx_fifo_link_pdm_multipath(void)
This function is to multiway rx fifo link pdm.
-
void wq_audio_rx_fifo_dislink_pdm_multipath(void)
This function is to multiway rx fifo dislink pdm.
-
void wq_audio_intf_rx_fifo_link_dfe_multipath(void)
This function is to multiway rx fifo link rx dfe.
-
WQ_RET wq_audio_tx_fifo_open(uint8_t id)
This function is to configure dma channel for audio tx fifo and enable.
- 参数:
id -- is audio tx fifo id.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_tx_fifo_push_data(uint8_t id, const char *src, uint32_t size, wq_dma_peri_done_cb cb)
This function is to push data to audio tx fifo.
- 参数:
id -- is audio rx fifo id.
src -- is pointer of data need to push.
size -- is size of data need to push.
cb -- is callback function called when data transfer done.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_tx_fifo_close(uint8_t bitmap)
This function is to stop audio tx fifo and free dma channel.
- 参数:
bitmap -- is audio tx fifo id bitmap
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_tx_fifo_link_i2s(uint8_t id, uint8_t i2s_chan)
This function is to configure tx fifo data to i2s tx channel.
- 参数:
id -- is audio tx fifo id.
i2s_chan -- is audio i2s tx channel
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_tx_fifo_link_asrc(uint8_t id, uint8_t asrc_chan)
This function is to configure tx fifo data to asrc tx channel.
- 参数:
id -- is audio tx fifo id.
asrc_chan -- is audio asrc tx channel
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_tx_fifo_link_anc(uint8_t id)
This function is to configure tx fifo data to anc.
- 参数:
id -- is audio tx fifo id.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_tx_fifo_dislink_i2s(uint8_t id)
This function is to disconnect tx fifo data source from i2s tx channel.
- 参数:
id -- is audio tx fifo id.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_tx_fifo_link_dfe(uint8_t id, uint8_t dfe_chan)
This function is to configure tx fifo data source from tx dfe channel.
- 参数:
id -- is audio tx fifo id.
dfe_chan -- is audio tx dfe channel.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_intf_set_out_from(WQ_AUDIO_OUT_FROM out_from)
This function is to configure audio out from rx dfe or i2s.
- 参数:
out_from -- is audio out from id,range 0~5: from Rx dfe 0~5; 6~13: from I2S 0~7; otherwise zero output.
- 返回:
WQ_RET_OK - success, other - failed
-
void wq_audio_intf_timer_enable(WQ_AUDIO_TIMER_ID timer_id)
This function is to enable audio timer.
- 参数:
timer_id -- is audio timer id.
-
void wq_audio_intf_timer_disable(WQ_AUDIO_TIMER_ID timer_id)
This function is to disable audio timer.
- 参数:
timer_id -- is audio timer id.
-
WQ_RET wq_audio_intf_timer_start(WQ_AUDIO_TIMER_ID timer_id, uint64_t target_half_us, wq_audio_inf_timer_callback cb, void *param)
This function is to start audio timer.
- 参数:
timer_id -- is audio timer id.
target_half_us -- half_microsecond; trigger happen when the timer equal this count
cb -- audio timer done callback
param -- callback information
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_intf_timer_stop(WQ_AUDIO_TIMER_ID timer_id)
This function is to stop audio timer.
- 参数:
timer_id -- is audio timer id
- 返回:
WQ_RET_OK - success, other - failed
-
uint8_t wq_audio_intf_get_current_timer(void)
This function is to get an unused audio timer.
- 返回:
uint8_t currently unused timer id
-
void wq_audio_intf_timer_release(uint8_t timer_id)
This function is to release the currently used timer id.
- 参数:
timer_id -- is audio timer id
-
uint64_t wq_audio_intf_get_timer_freerun_half_us(WQ_AUDIO_TIMER_ID timer_id)
This function is to get audio timer freerun tick. The audio timer is always running if enabled.
- 参数:
timer_id -- is audio_timer id
- 返回:
uint64_t audio timer freerun half_microsecond.
-
uint64_t wq_audio_intf_get_timer_latched_half_us(WQ_AUDIO_TIMER_ID timer_id)
This function is to get audio timer tick when BT latch happened.
- 返回:
uint64_t audio timer freerun half_microsecond.
-
WQ_RET wq_audio_intf_init(void)
This function is to init audio interface. Mainly complete the registration of audio intf interrupt.
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_intf_deinit(void)
This function is to deinit audio interface.
- 返回:
WQ_RET_OK - success, other - failed
-
void wq_audio_intf_register_irq_hook(WQ_AUDIO_INTF_INTC_ID id, wq_audio_intf_int_hook hook)
This function is to register the audio intereface interrupted hook function.
- 参数:
id -- audio intf interrupt id
hook -- callback function
-
int32_t wq_audio_intf_drc_limiter_threshold_cal(float db)
This function is to calculate drc limiter threshold.
- 参数:
db -- value to be converted
- 返回:
int32_t drc limiter threshold.
-
int32_t wq_audio_intf_drc_filter_coeff_cal(uint32_t fs, int32_t time_us)
This function is to calculate drc filter coeff.
备注
The attack time refers to the time from when the DRC gain coefficient takes effect to when the gain coefficient stabilizes to the target level; The release time is the time it takes for the DRC gain coefficient to start releasing and for the gain coefficient to return to normal levels
- 参数:
fs -- is drc input/output sampling rate
time_us -- is LM module attack time or release time, unit is us.
- 返回:
int32_t drc filter coeff
-
void wq_audio_intf_pwr_on(uint8_t audio_intf)
This function is to set audio interface power vote.
- 参数:
audio_intf -- is audio interface id.
-
void wq_audio_intf_pwr_off(uint8_t audio_intf)
This function is to clear audio interface power vote.
- 参数:
audio_intf -- is audio interface id.
-
uint64_t wq_audio_intf_pwr_get_mask(void)
This function is to get audio interface power vote mask.
- 返回:
uint64_t current power vote mask bit.
-
WQ_RET wq_audio_intf_power_monitor_start(WQ_AUDIO_INTF_POWER_MONITOR_SRC src, const wq_audio_intf_aud_power_monitor_cfg_t *cfg)
This function is to start power monitor,start src channel.
- 参数:
src -- sources that require power monitor
cfg -- power monitor config parameter
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_intf_power_monitor_stop(WQ_AUDIO_INTF_POWER_MONITOR_SRC src)
This function is to stop power monitor,stop src channel.
- 参数:
src -- power monitor config parameter
- 返回:
WQ_RET_OK - success, other - failed
-
uint32_t wq_audio_intf_power_monitor_avg_power_get(WQ_AUDIO_INTF_POWER_MONITOR_SRC src)
This function is to get estimation average power.
备注
1. The RMS can be calculated by average power: RMS = sqrt(avg_power * (2^15))
All DFE channels power estimation can be performed simultaneously, so we can call this interface to get multiple channels average power when power estimation is done
This is a hardware bug in power estimation of RXDFE4 and RXDFE5, so please avoid use RXDFE4 and RXDFE5 to do power estimation
- 参数:
src -- sources that require power monitor
- 返回:
Average power value
-
uint32_t wq_audio_intf_howl_detect_get_howl_freq(WQ_AUDIO_INTF_HOWL_DETECT_MODULE hd_module)
This function is to get howling frequency.
- 参数:
hd_module -- howling detection module
- 返回:
uint32_t howling frequency (Hz)
-
uint32_t wq_audio_intf_howl_detect_get_howl_energy_ratio(WQ_AUDIO_INTF_HOWL_DETECT_MODULE hd_module)
This function is to get howling energy ratio.
- 参数:
hd_module -- howling detection module
- 返回:
uint32_t howling energy ratio
-
void wq_audio_intf_howl_detect_soft_reset(WQ_AUDIO_INTF_HOWL_DETECT_MODULE hd_module)
This function is to soft reset howling detection module.
- 参数:
hd_module -- howling detection module
-
WQ_RET wq_audio_intf_howl_detect_start(WQ_AUDIO_INTF_HOWL_DETECT_MODULE hd_module, wq_audio_intf_howl_detect_config_t *cfg)
This function is to start howling detection module.
- 参数:
hd_module -- howling detection module
cfg -- howl detect config parameter
- 返回:
WQ_RET_OK - success, other - failed
-
WQ_RET wq_audio_intf_howl_detect_stop(WQ_AUDIO_INTF_HOWL_DETECT_MODULE hd_module)
This function is to stop howling detection module.
- 参数:
hd_module -- howling detection module
- 返回:
WQ_RET_OK - success, other - failed
-
void wq_audio_intf_meter_dfe_timer_select(uint8_t timer_id)
meter dfe select audio timer id
- 参数:
timer_id -- audio timer id
-
void wq_audio_intf_meter_dfe_enable(bool en)
Sync enable meter dfe by aud_inf_glb_en.
- 参数:
en -- enable sync start by aud_inf_glb_en.
-
uint32_t wq_audio_intf_get_anc_fs(void)
get the audio anc, adc rxdfe stg0,dac txdfe stg0 frequency of sample
- 返回:
uint32_t anc sample rate