Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
388
sdk/app/audio_msi/audio_adc.c
Normal file
388
sdk/app/audio_msi/audio_adc.c
Normal file
@@ -0,0 +1,388 @@
|
||||
#include "basic_include.h"
|
||||
#include "csi_kernel.h"
|
||||
#include "lib/multimedia/msi.h"
|
||||
#include "lib/multimedia/framebuff.h"
|
||||
#include "audio_adc.h"
|
||||
#include "lib/audio/audio_proc/audio_proc.h"
|
||||
|
||||
#define LIMIT(x,y,z) ({\
|
||||
int16_t tmp16;\
|
||||
if(x>y) tmp16=y;\
|
||||
else if(x<z) tmp16=z;\
|
||||
else tmp16=x;\
|
||||
tmp16;\
|
||||
})
|
||||
|
||||
#if AUADC_OUTPUT_SIN
|
||||
static const int16_t sin1khz_table[8] = {
|
||||
5792,8191,5792,0,-5792,-8191,-5792,0,
|
||||
};
|
||||
#endif
|
||||
|
||||
AUPROC_HDL *global_auproc_hdl = NULL;
|
||||
|
||||
struct auadc_struct
|
||||
{
|
||||
uint8_t auadc_stop;
|
||||
uint8_t channels;
|
||||
uint16_t soft_gain;
|
||||
uint32_t data_len;
|
||||
uint32_t sampleRate;
|
||||
uint32_t energy;
|
||||
struct msi *msi;
|
||||
struct os_msgqueue msg;
|
||||
struct os_task *task_hdl;
|
||||
struct fbpool tx_pool;
|
||||
type_ausys_ad_user_cb callback_func;
|
||||
enum ausys_ad_platform platform;
|
||||
#if AUDIO_PROCESS
|
||||
AUPROC_HDL *auproc_hdl;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern uint32_t auadc_calc_energy_asm(volatile int16_t *data, uint16_t soft_gain, uint32_t nsamples);
|
||||
|
||||
void auadc_deal_task(void *d)
|
||||
{
|
||||
volatile int16_t *data = NULL;
|
||||
int32_t ret = 0;
|
||||
uint32_t samples_len;
|
||||
struct framebuff *frame_buf = NULL;
|
||||
struct auadc_struct *auadc_s = (struct auadc_struct*)d;
|
||||
struct ausys_ad_msg ausys_msg;
|
||||
|
||||
auadc_s->auadc_stop = 0;
|
||||
while(1) {
|
||||
if(auadc_s->auadc_stop)
|
||||
break;
|
||||
ret = ausys_ad_get_msg(auadc_s->platform, &ausys_msg, osWaitForever);
|
||||
if((ret == RET_OK) && (ausys_msg.type == AUSYS_AD_MSG_PLAY_DONE)) {
|
||||
get_frame_buf:
|
||||
frame_buf = fbpool_get(&auadc_s->tx_pool, 0, auadc_s->msi);
|
||||
if(frame_buf) {
|
||||
data = (volatile int16_t *)frame_buf->data;
|
||||
os_memcpy((void*)data, (const void*)(ausys_msg.ad_content.fifo_cur_addr), ausys_msg.ad_content.fifo_cur_len);
|
||||
frame_buf->len = ausys_msg.ad_content.fifo_cur_len;
|
||||
frame_buf->time = os_jiffies();
|
||||
samples_len = frame_buf->len/2;
|
||||
#if AUADC_OUTPUT_SIN
|
||||
for(uint32_t i=0; i<samples_len; i++) {
|
||||
*(data+i) = sin1khz_table[i%8];
|
||||
}
|
||||
#else
|
||||
#if AUDIO_PROCESS
|
||||
if(auadc_s->auproc_hdl) {
|
||||
audio_process_data(auadc_s->auproc_hdl, (int16_t*)data, samples_len);
|
||||
}
|
||||
#endif
|
||||
auadc_s->energy = auadc_calc_energy_asm(data, auadc_s->soft_gain, samples_len);
|
||||
#endif
|
||||
frame_buf->mtype = F_AUDIO;
|
||||
frame_buf->stype = FSTYPE_AUDIO_ADC;
|
||||
AUADC_DEBUG("auadc send framebuff:%p\r\n",frame_buf);
|
||||
msi_output_fb(auadc_s->msi, frame_buf);
|
||||
}
|
||||
else {
|
||||
os_sleep_ms(1);
|
||||
goto get_frame_buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
auadc_s->auadc_stop = 2;
|
||||
}
|
||||
|
||||
int32_t auadc_start(struct auadc_struct *s, uint32_t auproc_enable)
|
||||
{
|
||||
struct auadc_struct *auadc_s = (struct auadc_struct*)s;
|
||||
struct framebuff *frame_buf;
|
||||
uint8_t *data;
|
||||
uint32_t data_size;
|
||||
int32_t ret = 0;
|
||||
|
||||
fbpool_init(&auadc_s->tx_pool, MAX_AUADC_TXBUF);
|
||||
data_size = auadc_s->data_len;
|
||||
for(uint32_t i=0; i<MAX_AUADC_TXBUF; i++) {
|
||||
data = (uint8_t*)AUADC_MALLOC(data_size * sizeof(uint8_t));
|
||||
if(!data) {
|
||||
AUADC_INFO("auadc malloc framebuff data fail!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
frame_buf = (auadc_s->tx_pool.pool)+i;
|
||||
frame_buf->data = data;
|
||||
}
|
||||
ausys_ad_record(auadc_s->platform);
|
||||
ret = os_msgq_init(&auadc_s->msg, MAX_AUADC_TXBUF);
|
||||
if(ret != RET_OK) {
|
||||
AUADC_INFO("auadc create msg fail!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
#if AUDIO_PROCESS
|
||||
if(auproc_enable && global_auproc_hdl == NULL) {
|
||||
auadc_s->auproc_hdl = audio_process_init(auadc_s->sampleRate, 1, (auadc_s->sampleRate/1000*AUPROC_FRAME_MS));
|
||||
if(auadc_s->auproc_hdl == NULL) {
|
||||
AUADC_INFO("audio_process_init fail!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
global_auproc_hdl = auadc_s->auproc_hdl;
|
||||
}
|
||||
#endif
|
||||
ausys_ad_register_msg(auadc_s->platform,AUSYS_AD_MSG_PLAY_DONE);
|
||||
auadc_s->task_hdl = os_task_create("auadc_deal_task", auadc_deal_task, auadc_s, AUADC_TASK_PRIORITY, 0, NULL, 1024);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t auadc_msi_action(struct msi *msi, uint32_t cmd_id, uint32_t param1, uint32_t param2)
|
||||
{
|
||||
int32_t ret = RET_OK;
|
||||
struct auadc_struct *auadc_s = (struct auadc_struct*)msi->priv;
|
||||
switch(cmd_id) {
|
||||
case MSI_CMD_FREE_FB:
|
||||
{
|
||||
ret = RET_ERR;
|
||||
if(auadc_s) {
|
||||
struct framebuff *frame_buf = (struct framebuff *)param1;
|
||||
fbpool_put(&auadc_s->tx_pool, frame_buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSI_CMD_POST_DESTROY:
|
||||
{
|
||||
if(auadc_s) {
|
||||
for(uint32_t i=0; i<MAX_AUADC_TXBUF; i++) {
|
||||
struct framebuff *frame_buf = (auadc_s->tx_pool.pool)+i;
|
||||
if(frame_buf->data) {
|
||||
AUADC_FREE(frame_buf->data);
|
||||
frame_buf->data = NULL;
|
||||
}
|
||||
}
|
||||
fbpool_destroy(&auadc_s->tx_pool);
|
||||
if(auadc_s->msg.hdl)
|
||||
os_msgq_del(&auadc_s->msg);
|
||||
#if AUDIO_PROCESS
|
||||
if(auadc_s->auproc_hdl) {
|
||||
audio_process_deinit(auadc_s->auproc_hdl);
|
||||
global_auproc_hdl = NULL;
|
||||
}
|
||||
#endif
|
||||
AUADC_FREE(auadc_s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct msi *get_auadc_msi(enum ausys_ad_platform platform)
|
||||
{
|
||||
struct msi *msi = NULL;
|
||||
|
||||
switch(platform) {
|
||||
case AUSYS_AUAD:msi = msi_find("S_AUADC", 1);break;
|
||||
case AUSYS_PDM:msi = msi_find("S_AUPDM", 1);break;
|
||||
case AUSYS_IIS_SLAVER0:msi = msi_find("S_AUIIS0", 1);break;
|
||||
case AUSYS_IIS_SLAVER1:msi = msi_find("S_AUIIS1", 1);break;
|
||||
default:break;
|
||||
}
|
||||
if(msi) {
|
||||
msi_put(msi);
|
||||
}
|
||||
return msi;
|
||||
}
|
||||
|
||||
int32_t auadc_msi_add_output(enum ausys_ad_platform platform, const char *msi_name)
|
||||
{
|
||||
int32_t ret = RET_ERR;
|
||||
struct msi *msi = NULL;
|
||||
|
||||
switch(platform) {
|
||||
case AUSYS_AUAD:msi = msi_find("S_AUADC", 1);break;
|
||||
case AUSYS_PDM:msi = msi_find("S_AUPDM", 1);break;
|
||||
case AUSYS_IIS_SLAVER0:msi = msi_find("S_AUIIS0", 1);break;
|
||||
case AUSYS_IIS_SLAVER1:msi = msi_find("S_AUIIS1", 1);break;
|
||||
default:break;
|
||||
}
|
||||
if(msi) {
|
||||
msi_put(msi);
|
||||
}
|
||||
else {
|
||||
AUADC_INFO("auadc msi add output fail,auadc msi is null\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
ret = msi_add_output(msi, NULL, msi_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t auadc_msi_del_output(enum ausys_ad_platform platform, const char *msi_name)
|
||||
{
|
||||
int32_t ret = RET_ERR;
|
||||
struct msi *msi = NULL;
|
||||
|
||||
switch(platform) {
|
||||
case AUSYS_AUAD:msi = msi_find("S_AUADC", 1);break;
|
||||
case AUSYS_PDM:msi = msi_find("S_AUPDM", 1);break;
|
||||
case AUSYS_IIS_SLAVER0:msi = msi_find("S_AUIIS0", 1);break;
|
||||
case AUSYS_IIS_SLAVER1:msi = msi_find("S_AUIIS1", 1);break;
|
||||
default:break;
|
||||
}
|
||||
if(msi) {
|
||||
msi_put(msi);
|
||||
}
|
||||
else {
|
||||
AUADC_INFO("auadc msi add output fail,auadc msi is null\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
ret = msi_del_output(msi, NULL, msi_name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t audio_adc_get_samplerate(enum ausys_ad_platform platform)
|
||||
{
|
||||
uint32_t samplerate = 8000;
|
||||
struct msi *msi = NULL;
|
||||
struct auadc_struct *auadc_s = NULL;
|
||||
|
||||
switch(platform) {
|
||||
case AUSYS_AUAD:msi = msi_find("S_AUADC", 1);break;
|
||||
case AUSYS_PDM:msi = msi_find("S_AUPDM", 1);break;
|
||||
case AUSYS_IIS_SLAVER0:msi = msi_find("S_AUIIS0", 1);break;
|
||||
case AUSYS_IIS_SLAVER1:msi = msi_find("S_AUIIS1", 1);break;
|
||||
default:break;
|
||||
}
|
||||
if(msi) {
|
||||
msi_put(msi);
|
||||
auadc_s = (struct auadc_struct*)msi->priv;
|
||||
}
|
||||
if(auadc_s) {
|
||||
samplerate = auadc_s->sampleRate;
|
||||
}
|
||||
return samplerate;
|
||||
}
|
||||
|
||||
int32_t audio_adc_set_soft_gain(enum ausys_ad_platform platform, uint32_t soft_gain)
|
||||
{
|
||||
int32_t ret = RET_ERR;
|
||||
struct msi *msi = NULL;
|
||||
struct auadc_struct *auadc_s = NULL;
|
||||
|
||||
switch(platform) {
|
||||
case AUSYS_AUAD:msi = msi_find("S_AUADC", 1);break;
|
||||
case AUSYS_PDM:msi = msi_find("S_AUPDM", 1);break;
|
||||
case AUSYS_IIS_SLAVER0:msi = msi_find("S_AUIIS0", 1);break;
|
||||
case AUSYS_IIS_SLAVER1:msi = msi_find("S_AUIIS1", 1);break;
|
||||
default:break;
|
||||
}
|
||||
if(msi) {
|
||||
msi_put(msi);
|
||||
auadc_s = (struct auadc_struct*)msi->priv;
|
||||
}
|
||||
if(auadc_s) {
|
||||
auadc_s->soft_gain = soft_gain;
|
||||
ret = RET_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t audio_adc_get_energy(enum ausys_ad_platform platform)
|
||||
{
|
||||
struct msi *msi = NULL;
|
||||
struct auadc_struct *auadc_s = NULL;
|
||||
|
||||
switch(platform) {
|
||||
case AUSYS_AUAD:msi = msi_find("S_AUADC", 1);break;
|
||||
case AUSYS_PDM:msi = msi_find("S_AUPDM", 1);break;
|
||||
case AUSYS_IIS_SLAVER0:msi = msi_find("S_AUIIS0", 1);break;
|
||||
case AUSYS_IIS_SLAVER1:msi = msi_find("S_AUIIS1", 1);break;
|
||||
default:break;
|
||||
}
|
||||
if(msi) {
|
||||
msi_put(msi);
|
||||
auadc_s = (struct auadc_struct*)msi->priv;
|
||||
}
|
||||
if(auadc_s) {
|
||||
return auadc_s->energy;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t audio_adc_init(enum ausys_ad_platform platform, uint32_t sampleRate, uint32_t channels, uint32_t soft_gain, uint32_t auproc_enable)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
struct msi *msi = NULL;
|
||||
|
||||
switch(platform) {
|
||||
case AUSYS_AUAD:msi = msi_new("S_AUADC", 0, NULL);break;
|
||||
case AUSYS_PDM:msi = msi_new("S_AUPDM", 0, NULL);break;
|
||||
case AUSYS_IIS_SLAVER0:msi = msi_new("S_AUIIS0", 0, NULL);break;
|
||||
case AUSYS_IIS_SLAVER1:msi = msi_new("S_AUIIS1", 0, NULL);break;
|
||||
default:break;
|
||||
}
|
||||
if(msi) {
|
||||
struct auadc_struct *auadc_s = (struct auadc_struct*)AUADC_ZALLOC(sizeof(struct auadc_struct));
|
||||
if(!auadc_s) {
|
||||
AUADC_INFO("malloc auadc_struct fail!\r\n");
|
||||
msi_destroy(msi);
|
||||
return RET_ERR;
|
||||
}
|
||||
msi->enable = 1;
|
||||
msi->action = (msi_action)auadc_msi_action;
|
||||
msi->priv = auadc_s;
|
||||
auadc_s->msi = msi;
|
||||
auadc_s->channels = channels;
|
||||
auadc_s->soft_gain = soft_gain;
|
||||
auadc_s->sampleRate = sampleRate;
|
||||
auadc_s->data_len = sampleRate/1000*channels*2*AUADC_TIME_INTERVAL;
|
||||
auadc_s->platform = platform;
|
||||
ausys_ad_init(
|
||||
auadc_s->platform,
|
||||
auadc_s->sampleRate,
|
||||
16,
|
||||
auadc_s->channels,
|
||||
auadc_s->data_len*AUADC_QUEUE_NUM,
|
||||
auadc_s->data_len,
|
||||
NULL,
|
||||
(uint32_t)auadc_s
|
||||
);
|
||||
ret = auadc_start(auadc_s, auproc_enable);
|
||||
if(ret != RET_OK) {
|
||||
msi_destroy(msi);
|
||||
ausys_ad_deinit(auadc_s->platform);
|
||||
return RET_ERR;
|
||||
}
|
||||
AUADC_INFO("auadc init success!\r\n");
|
||||
return RET_OK;
|
||||
}
|
||||
else {
|
||||
AUADC_INFO("create auadc msi fail!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t audio_adc_deinit(enum ausys_ad_platform platform)
|
||||
{
|
||||
struct msi *msi = NULL;
|
||||
struct auadc_struct *auadc_s = NULL;
|
||||
|
||||
switch(platform) {
|
||||
case AUSYS_AUAD:msi = msi_find("S_AUADC", 1);break;
|
||||
case AUSYS_PDM:msi = msi_find("S_AUPDM", 1);break;
|
||||
case AUSYS_IIS_SLAVER0:msi = msi_find("S_AUIIS0", 1);break;
|
||||
case AUSYS_IIS_SLAVER1:msi = msi_find("S_AUIIS1", 1);break;
|
||||
default:break;
|
||||
}
|
||||
if(msi) {
|
||||
msi_put(msi);
|
||||
auadc_s = (struct auadc_struct*)msi->priv;
|
||||
}
|
||||
if(!auadc_s) {
|
||||
AUADC_INFO("auadc deinit fail,auadc_s is null!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
auadc_s->auadc_stop = 1;
|
||||
while(auadc_s->auadc_stop != 2)
|
||||
os_sleep_ms(1);
|
||||
ausys_ad_deinit(auadc_s->platform);
|
||||
msi_destroy(msi);
|
||||
return RET_OK;
|
||||
}
|
||||
40
sdk/app/audio_msi/audio_adc.h
Normal file
40
sdk/app/audio_msi/audio_adc.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef _AUDIO_ADC_H_
|
||||
#define _AUDIO_ADC_H_
|
||||
|
||||
#include "basic_include.h"
|
||||
#include "dev/audio/ausys.h"
|
||||
#include "lib/heap/av_heap.h"
|
||||
#include "lib/heap/av_psram_heap.h"
|
||||
|
||||
#ifdef PSRAM_HEAP
|
||||
#define AUADC_MALLOC av_psram_malloc
|
||||
#define AUADC_ZALLOC av_psram_zalloc
|
||||
#define AUADC_FREE av_psram_free
|
||||
#else
|
||||
#define AUADC_MALLOC av_malloc
|
||||
#define AUADC_ZALLOC av_zalloc
|
||||
#define AUADC_FREE av_free
|
||||
#endif
|
||||
|
||||
#define AUADC_DEBUG(fmt, args...) //os_printf(fmt, ##args)
|
||||
#define AUADC_INFO os_printf
|
||||
|
||||
#define AUADC_QUEUE_NUM 3
|
||||
|
||||
#define AUADC_TIME_INTERVAL 20
|
||||
#define AUPROC_FRAME_MS 10
|
||||
#define MAX_AUADC_TXBUF 4
|
||||
#define AUADC_TASK_PRIORITY (OS_TASK_PRIORITY_ABOVE_NORMAL-1)
|
||||
|
||||
#define AUADC_OUTPUT_SIN 0
|
||||
#define AUDIO_PROCESS 1
|
||||
|
||||
int32_t audio_adc_init(enum ausys_ad_platform platform, uint32_t sampleRate, uint32_t channels, uint32_t soft_gain, uint32_t auproc_enable);
|
||||
int32_t audio_adc_deinit(enum ausys_ad_platform platform);
|
||||
int32_t audio_adc_get_samplerate(enum ausys_ad_platform platform);
|
||||
struct msi *get_auadc_msi(enum ausys_ad_platform platform);
|
||||
int32_t auadc_msi_add_output(enum ausys_ad_platform platform, const char *msi_name);
|
||||
int32_t auadc_msi_del_output(enum ausys_ad_platform platform, const char *msi_name);
|
||||
int32_t audio_adc_set_soft_gain(enum ausys_ad_platform platform, uint32_t soft_gain);
|
||||
uint32_t audio_adc_get_energy(enum ausys_ad_platform platform);
|
||||
#endif
|
||||
21
sdk/app/audio_msi/audio_bloop_calc.S
Normal file
21
sdk/app/audio_msi/audio_bloop_calc.S
Normal file
@@ -0,0 +1,21 @@
|
||||
.global auadc_calc_energy_asm
|
||||
|
||||
.align 2
|
||||
|
||||
.type auadc_calc_energy_asm, %function
|
||||
auadc_calc_energy_asm:
|
||||
push r4-r9, r15
|
||||
mov r4, r0
|
||||
mov r5, r1
|
||||
mov r6, r2
|
||||
movi r7, 0
|
||||
calc:
|
||||
ld.hs r8, (r4,0)
|
||||
mulll.s16 r8, r5,r8
|
||||
clipi.s32 r8, r8,16
|
||||
st.h r8, (r4,0)
|
||||
mulall.s16.s r7, r8,r8
|
||||
addi r4, 2
|
||||
bloop r6, calc
|
||||
mov r0, r7
|
||||
pop r4-r9, r15
|
||||
629
sdk/app/audio_msi/audio_dac.c
Normal file
629
sdk/app/audio_msi/audio_dac.c
Normal file
@@ -0,0 +1,629 @@
|
||||
#include "basic_include.h"
|
||||
#include "csi_kernel.h"
|
||||
#include "lib/multimedia/msi.h"
|
||||
#include "lib/multimedia/framebuff.h"
|
||||
#include "audio_dac.h"
|
||||
#include "dev/audio/ausys.h"
|
||||
#include "dev/audio/ausys_da.h"
|
||||
#include "lib/audio/wsola/wsola_process.h"
|
||||
#include "lib/audio/audio_proc/audio_proc.h"
|
||||
#include "audio_media_ctrl/audio_code_ctrl.h"
|
||||
|
||||
extern AUPROC_HDL *global_auproc_hdl;
|
||||
|
||||
typedef int32_t (*audac_write_func)(int16_t *audac_buf, uint32_t len);
|
||||
|
||||
enum {
|
||||
end_msg = 1,
|
||||
clear_msg,
|
||||
};
|
||||
struct filter_track_struct {
|
||||
AUDIO_TRACK *audio_track[15];
|
||||
uint32_t audio_track_num;
|
||||
struct os_mutex mutex;
|
||||
};
|
||||
struct audac_cache_struct {
|
||||
int16_t *buf;
|
||||
uint32_t s_offset;
|
||||
uint32_t d_offset;
|
||||
uint32_t res_nsamples;
|
||||
struct os_msgqueue cache_msg;
|
||||
};
|
||||
struct audac_struct
|
||||
{
|
||||
uint8_t is_empty;
|
||||
uint8_t hold_empty;
|
||||
uint8_t delete_mode;
|
||||
uint8_t audac_stop;
|
||||
int16_t *empty_buf;
|
||||
int16_t *resample_buf;
|
||||
uint32_t data_nbytes;
|
||||
uint32_t data_nsamples;
|
||||
uint32_t filter_type;
|
||||
uint32_t sampleRate;
|
||||
uint32_t audac_volume;
|
||||
uint32_t call_volume;
|
||||
uint32_t media_volume;
|
||||
uint32_t bell_volume;
|
||||
uint32_t target_volume;
|
||||
float cur_soft_volume;
|
||||
struct msi *msi;
|
||||
struct audac_cache_struct cache_struct;
|
||||
struct filter_track_struct filter_track_s;
|
||||
audac_write_func write_func;
|
||||
struct os_task deal_task_hdl;
|
||||
struct os_task msg_task_hdl;
|
||||
};
|
||||
static struct audac_struct *audac_s = NULL;
|
||||
|
||||
void audac_cache_s_clear(struct audac_cache_struct *audac_cache_s)
|
||||
{
|
||||
audac_cache_s->res_nsamples = audac_s->data_nsamples;
|
||||
audac_cache_s->d_offset = 0;
|
||||
audac_cache_s->s_offset = 0;
|
||||
}
|
||||
|
||||
void set_audac_filter_track(struct audac_struct *audac_s, uint8_t fiter_none, AUDIO_TRACK *audio_track)
|
||||
{
|
||||
struct filter_track_struct *filter_track_s = &(audac_s->filter_track_s);
|
||||
uint32_t wait_empty_cnt = 0;
|
||||
os_mutex_lock(&filter_track_s->mutex, osWaitForever);
|
||||
if(fiter_none == 1) {
|
||||
audac_s->filter_type = FSTYPE_NONE;
|
||||
os_mutex_unlock(&filter_track_s->mutex);
|
||||
return;
|
||||
}
|
||||
if((fiter_none==0) && (audio_track==NULL)) {
|
||||
goto set_audac_filter_type_end;
|
||||
}
|
||||
if((audio_track->priority&0xC0) == play_disabled) {
|
||||
uint8_t del_priority = audio_track->priority;
|
||||
for(uint32_t i=0; i<filter_track_s->audio_track_num; i++) {
|
||||
AUDIO_TRACK *cur_audio_track = filter_track_s->audio_track[i];
|
||||
if(cur_audio_track == audio_track) {
|
||||
os_memmove(&(filter_track_s->audio_track[i]), &(filter_track_s->audio_track[i+1]), (filter_track_s->audio_track_num-(i+1))*sizeof(AUDIO_TRACK*));
|
||||
cur_audio_track = filter_track_s->audio_track[i];
|
||||
}
|
||||
if(((cur_audio_track->priority&0x30)==del_priority) && (cur_audio_track->priority>del_priority)) {
|
||||
cur_audio_track->priority--;
|
||||
}
|
||||
}
|
||||
if(filter_track_s->audio_track[filter_track_s->audio_track_num-1] == audio_track) {
|
||||
audac_s->filter_type = FSTYPE_NONE;
|
||||
while((!audac_s->is_empty) && (wait_empty_cnt++<1000))
|
||||
os_sleep_ms(1);
|
||||
}
|
||||
filter_track_s->audio_track_num--;
|
||||
}
|
||||
else if((audio_track->priority&0xC0) == play_interruptible) {
|
||||
if(filter_track_s->audio_track_num) {
|
||||
for(uint32_t i=(filter_track_s->audio_track_num-1); i>=0; i--) {
|
||||
AUDIO_TRACK *cur_audio_track = filter_track_s->audio_track[i];
|
||||
if((cur_audio_track->priority&0x30) == 0x10) {
|
||||
os_memmove(&(filter_track_s->audio_track[i+2]), &(filter_track_s->audio_track[i+1]), (filter_track_s->audio_track_num-(i+1))*sizeof(AUDIO_TRACK*));
|
||||
filter_track_s->audio_track[i+1] = audio_track;
|
||||
AUDIO_TRACK *new_audio_track = filter_track_s->audio_track[i+1];
|
||||
new_audio_track->priority = cur_audio_track->priority+1;
|
||||
filter_track_s->audio_track_num++;
|
||||
goto set_audac_filter_type_end;
|
||||
}
|
||||
else if(i == 0) {
|
||||
os_memmove(&(filter_track_s->audio_track[1]), &(filter_track_s->audio_track[0]), (filter_track_s->audio_track_num)*sizeof(AUDIO_TRACK*));
|
||||
filter_track_s->audio_track[0] = audio_track;
|
||||
AUDIO_TRACK *new_audio_track = filter_track_s->audio_track[0];
|
||||
new_audio_track->priority = 0x11;
|
||||
filter_track_s->audio_track_num++;
|
||||
goto set_audac_filter_type_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
filter_track_s->audio_track[0] = audio_track;
|
||||
AUDIO_TRACK *new_audio_track = filter_track_s->audio_track[0];
|
||||
new_audio_track->priority = 0x11;
|
||||
filter_track_s->audio_track_num++;
|
||||
}
|
||||
else if((audio_track->priority&0xC0) == play_nonInterruptible) {
|
||||
for(uint32_t i=0; i<filter_track_s->audio_track_num; i++) {
|
||||
AUDIO_TRACK *cur_audio_track = filter_track_s->audio_track[i];
|
||||
if((cur_audio_track->priority&0x30) == 0x20) {
|
||||
os_memmove(&(filter_track_s->audio_track[i+1]), &(filter_track_s->audio_track[i]), (filter_track_s->audio_track_num-i)*sizeof(AUDIO_TRACK*));
|
||||
filter_track_s->audio_track[i] = audio_track;
|
||||
AUDIO_TRACK *new_audio_track = filter_track_s->audio_track[i];
|
||||
new_audio_track->priority = 0x21;
|
||||
filter_track_s->audio_track_num++;
|
||||
for(uint32_t j=(i+1); j<filter_track_s->audio_track_num; j++) {
|
||||
cur_audio_track = filter_track_s->audio_track[i];
|
||||
cur_audio_track->priority++;
|
||||
}
|
||||
goto set_audac_filter_type_end;
|
||||
}
|
||||
else if(i == (filter_track_s->audio_track_num-1)) {
|
||||
filter_track_s->audio_track[i+1] = audio_track;
|
||||
AUDIO_TRACK *new_audio_track = filter_track_s->audio_track[i];
|
||||
new_audio_track->priority = 0x21;
|
||||
filter_track_s->audio_track_num++;
|
||||
goto set_audac_filter_type_end;
|
||||
}
|
||||
}
|
||||
filter_track_s->audio_track[0] = audio_track;
|
||||
AUDIO_TRACK *new_audio_track = filter_track_s->audio_track[0];
|
||||
new_audio_track->priority = 0x21;
|
||||
filter_track_s->audio_track_num++;
|
||||
}
|
||||
set_audac_filter_type_end:
|
||||
|
||||
if(filter_track_s->audio_track_num) {
|
||||
audac_s->filter_type = FSTYPE_AUDIO_PCM;
|
||||
}
|
||||
os_mutex_unlock(&filter_track_s->mutex);
|
||||
}
|
||||
|
||||
AUDIO_TRACK *get_audac_filter_track(struct audac_struct *audac_s)
|
||||
{
|
||||
struct filter_track_struct *filter_track_s = &(audac_s->filter_track_s);
|
||||
if(filter_track_s->audio_track_num && (audac_s->filter_type!=FSTYPE_NONE)) {
|
||||
return filter_track_s->audio_track[filter_track_s->audio_track_num-1];
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void set_audac_samplingrate(struct audac_struct *audac_s, uint32_t sampling_rate)
|
||||
{
|
||||
uint32_t wait_empty_cnt = 0;
|
||||
int32_t ret = 0;
|
||||
|
||||
AUDAC_INFO("change audio dac samplingRate,last:%d,current:%d\r\n",audac_s->sampleRate,sampling_rate);
|
||||
if((sampling_rate == audac_s->sampleRate) || (sampling_rate < 0))
|
||||
return;
|
||||
set_audac_filter_track(audac_s, 1, NULL);
|
||||
while((!audac_s->is_empty) && (wait_empty_cnt++<5000))
|
||||
os_sleep_ms(1);
|
||||
if(global_auproc_hdl && global_auproc_hdl->aec) {
|
||||
ret = audio_resample_config(global_auproc_hdl, sampling_rate, AUDAC_SAMPLERATE);
|
||||
if(ret == RET_OK) {
|
||||
audac_s->sampleRate = sampling_rate;
|
||||
}
|
||||
os_printf("audio_resample_config:%d\n",ret);
|
||||
}
|
||||
else {
|
||||
ret = ausys_da_change_sample_rate(sampling_rate);
|
||||
if(ret == RET_OK) {
|
||||
audac_s->sampleRate = sampling_rate;
|
||||
}
|
||||
}
|
||||
audac_s->data_nbytes = sampling_rate*AUDAC_TIME_INTERVAL*2/1000;
|
||||
audac_s->data_nsamples = audac_s->data_nbytes / 2;
|
||||
set_audac_filter_track(audac_s, 0, NULL);
|
||||
}
|
||||
|
||||
uint32_t get_audac_samplingrate(struct audac_struct *audac_s)
|
||||
{
|
||||
return audac_s->sampleRate;
|
||||
}
|
||||
|
||||
void set_audac_volume(struct audac_struct *audac_s, uint32_t volume)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
if(audac_s->audac_volume == volume)
|
||||
return;
|
||||
ret = ausys_da_change_volume(volume);
|
||||
if(ret == RET_OK)
|
||||
audac_s->audac_volume = volume;
|
||||
}
|
||||
|
||||
uint32_t get_audac_volume(struct audac_struct *audac_s)
|
||||
{
|
||||
return audac_s->audac_volume;
|
||||
}
|
||||
|
||||
void audac_soft_volume_adjust(struct audac_struct *audac_s, int16_t *buf, uint32_t nsamples)
|
||||
{
|
||||
for(uint32_t i=0; i<nsamples; i++) {
|
||||
buf[i] = (int16_t)(((float)buf[i]) * audac_s->cur_soft_volume);
|
||||
if(((uint32_t)(audac_s->cur_soft_volume * 100.0f)) > audac_s->target_volume) {
|
||||
audac_s->cur_soft_volume -= 0.01;
|
||||
}
|
||||
else if(((uint32_t)(audac_s->cur_soft_volume * 100.0f)) < audac_s->target_volume) {
|
||||
audac_s->cur_soft_volume += 0.01;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t audac_write_data(struct audac_struct *audac_s, void* buf, uint32_t nbytes)
|
||||
{
|
||||
int32_t ret = ausys_da_put(buf, nbytes);
|
||||
audac_s->hold_empty = 1;
|
||||
audac_s->is_empty = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void audac_deal_task(void *d)
|
||||
{
|
||||
uint8_t end_stream = 0;
|
||||
uint8_t clear_finish = 1;
|
||||
int16_t *data = NULL;
|
||||
int32_t ret = 0;
|
||||
uint32_t data_nsamples = 0;
|
||||
uint32_t resample_nsamples = 0;
|
||||
uint32_t cache_msg = 0;
|
||||
|
||||
struct framebuff *frame_buf = NULL;
|
||||
struct audac_struct *audac_s = (struct audac_struct*)d;
|
||||
struct audac_cache_struct *audac_cache_s = &audac_s->cache_struct;
|
||||
|
||||
audac_s->audac_stop = 0;
|
||||
audac_cache_s_clear(audac_cache_s);
|
||||
ausys_da_play();
|
||||
while(1) {
|
||||
if(audac_s->audac_stop)
|
||||
break;
|
||||
cache_msg = os_msgq_get2(&audac_cache_s->cache_msg, 0, &ret);
|
||||
if(ret)
|
||||
cache_msg = 0;
|
||||
if(cache_msg == end_msg)
|
||||
end_stream = 1;
|
||||
else if(cache_msg == clear_msg) {
|
||||
clear_finish = 0;
|
||||
audac_cache_s_clear(audac_cache_s);
|
||||
}
|
||||
|
||||
if(!(global_auproc_hdl && global_auproc_hdl->aec)) {
|
||||
if(get_audac_volume(audac_s) != audac_s->target_volume) {
|
||||
set_audac_volume(audac_s, audac_s->target_volume);
|
||||
}
|
||||
}
|
||||
|
||||
frame_buf = msi_get_fb(audac_s->msi,0);
|
||||
if(frame_buf) {
|
||||
data = (int16_t*)frame_buf->data;
|
||||
data_nsamples = (frame_buf->len)/2;
|
||||
audac_cache_s->s_offset = 0;
|
||||
while(data_nsamples >= audac_cache_s->res_nsamples) {
|
||||
if(!clear_finish) {
|
||||
data_nsamples = 0;
|
||||
break;
|
||||
}
|
||||
os_memcpy(audac_cache_s->buf + audac_cache_s->d_offset,
|
||||
data + audac_cache_s->s_offset, audac_cache_s->res_nsamples * sizeof(int16_t));
|
||||
data_nsamples -= audac_cache_s->res_nsamples;
|
||||
audac_cache_s->s_offset += audac_cache_s->res_nsamples;
|
||||
if(global_auproc_hdl && global_auproc_hdl->aec) {
|
||||
audio_resample_data(global_auproc_hdl, audac_cache_s->buf, audac_s->data_nsamples, audac_s->resample_buf, &resample_nsamples);
|
||||
audac_soft_volume_adjust(audac_s, audac_s->resample_buf, resample_nsamples);
|
||||
audac_write_data(audac_s, audac_s->resample_buf, (resample_nsamples << 1));
|
||||
}
|
||||
else {
|
||||
audac_write_data(audac_s, audac_cache_s->buf, audac_s->data_nbytes);
|
||||
}
|
||||
audac_cache_s->res_nsamples = audac_s->data_nsamples;
|
||||
audac_cache_s->d_offset = 0;
|
||||
}
|
||||
if(data_nsamples) {
|
||||
os_memcpy(audac_cache_s->buf + audac_cache_s->d_offset,
|
||||
data + audac_cache_s->s_offset, data_nsamples * sizeof(int16_t));
|
||||
audac_cache_s->res_nsamples -= data_nsamples;
|
||||
audac_cache_s->d_offset += data_nsamples;
|
||||
audac_cache_s->s_offset = 0;
|
||||
data_nsamples = 0;
|
||||
}
|
||||
AUDAC_DEBUG("audac delete framebuff:%p,len:%d\r\n",frame_buf, frame_buf->len);
|
||||
msi_delete_fb(audac_s->msi, frame_buf);
|
||||
frame_buf = NULL;
|
||||
}
|
||||
else {
|
||||
clear_finish = 1;
|
||||
if((audac_cache_s->d_offset > 0) && end_stream) {
|
||||
os_memset(audac_cache_s->buf + audac_cache_s->d_offset, 0,
|
||||
(audac_s->data_nsamples - audac_cache_s->d_offset) * sizeof(int16_t));
|
||||
if(global_auproc_hdl && global_auproc_hdl->aec) {
|
||||
audio_resample_data(global_auproc_hdl, audac_cache_s->buf, audac_s->data_nsamples, audac_s->resample_buf, &resample_nsamples);
|
||||
audac_soft_volume_adjust(audac_s, audac_s->resample_buf, resample_nsamples);
|
||||
audac_write_data(audac_s, audac_s->resample_buf, (resample_nsamples << 1));
|
||||
}
|
||||
else {
|
||||
audac_write_data(audac_s, audac_cache_s->buf, audac_s->data_nbytes);
|
||||
}
|
||||
audac_cache_s_clear(audac_cache_s);
|
||||
data_nsamples = 0;
|
||||
}
|
||||
else
|
||||
os_sleep_ms(1);
|
||||
end_stream = 0;
|
||||
}
|
||||
}
|
||||
audac_s->audac_stop = 2;
|
||||
}
|
||||
|
||||
void audac_msg_task(void *d)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
struct ausys_da_msg ausys_msg;
|
||||
|
||||
while(1) {
|
||||
if(audac_s->audac_stop == 2)
|
||||
break;
|
||||
ret = ausys_da_get_msg(&ausys_msg, osWaitForever);
|
||||
if((ret == RET_OK) && (ausys_msg.type & AUSYS_DA_MSG_FIFO_EMPTY)) {
|
||||
audac_s->is_empty = 1;
|
||||
}
|
||||
if((ret == RET_OK) && (ausys_msg.type & AUSYS_DA_MSG_PLAY_HALF)) {
|
||||
if(ausys_msg.da_content.fifo_next_len == 0)
|
||||
audio_process_fardata(global_auproc_hdl, audac_s->empty_buf, audac_s->data_nsamples);
|
||||
else
|
||||
audio_process_fardata(global_auproc_hdl, (int16_t*)(ausys_msg.da_content.fifo_next_addr),
|
||||
ausys_msg.da_content.fifo_next_len / 2);
|
||||
}
|
||||
}
|
||||
audac_s->audac_stop = 3;
|
||||
}
|
||||
|
||||
int32_t audac_start(struct audac_struct *s)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
struct audac_struct *audac_s = (struct audac_struct*)s;
|
||||
struct audac_cache_struct *audac_cache_s = &audac_s->cache_struct;
|
||||
struct filter_track_struct *filter_track_s = &audac_s->filter_track_s;
|
||||
|
||||
audac_cache_s->buf = (int16_t *)AUDAC_ZALLOC(AUDAC_LEN);
|
||||
if(!audac_cache_s->buf) {
|
||||
AUDAC_INFO("audac malloc cache_s buf fail!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
ret = os_msgq_init(&audac_cache_s->cache_msg, 1);
|
||||
if(ret != RET_OK) {
|
||||
AUDAC_INFO("audac create cache_s msg fail!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
ret = os_mutex_init(&filter_track_s->mutex);
|
||||
if(ret != RET_OK) {
|
||||
AUDAC_INFO("audac create filter_track_s mutex fail!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
ausys_da_register_msg(AUSYS_DA_MSG_PLAY_HALF | AUSYS_DA_MSG_FIFO_EMPTY);
|
||||
OS_TASK_INIT("audac_deal_task", &audac_s->deal_task_hdl, audac_deal_task, audac_s, AUDAC_TASK_PRIORITY, NULL, 1024);
|
||||
OS_TASK_INIT("audac_msg_task", &audac_s->msg_task_hdl, audac_msg_task, audac_s, AUDAC_TASK_PRIORITY, NULL, 512);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t audac_msi_action(struct msi *msi,uint32_t cmd_id,uint32_t param1,uint32_t param2)
|
||||
{
|
||||
int32_t ret = RET_OK;
|
||||
switch(cmd_id) {
|
||||
case MSI_CMD_TRANS_FB:
|
||||
{
|
||||
ret = RET_ERR;
|
||||
struct framebuff *frame_buf = (struct framebuff*)param1;
|
||||
if(audac_s && (frame_buf->mtype == F_AUDIO)) {
|
||||
AUDIO_TRACK *audac_filter_track = get_audac_filter_track(audac_s);
|
||||
AUDIO_TRACK *audio_track = (AUDIO_TRACK*)(frame_buf->priv);
|
||||
if(audac_filter_track == audio_track) {
|
||||
switch(audio_track->track_type) {
|
||||
case CALL_TRACK:audac_s->target_volume = audac_s->call_volume;break;
|
||||
case MEDIA_TRACK:audac_s->target_volume = audac_s->media_volume;break;
|
||||
case BELL_TRACK:audac_s->target_volume = audac_s->bell_volume;break;
|
||||
default:break;
|
||||
}
|
||||
if(audio_track->samplerate != get_audac_samplingrate(audac_s)) {
|
||||
set_audac_samplingrate(audac_s, audio_track->samplerate);
|
||||
}
|
||||
ret = RET_OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSI_CMD_TRANS_FB_END:
|
||||
{
|
||||
struct framebuff *frame_buf = (struct framebuff *)param1;
|
||||
if(audac_s->delete_mode) {
|
||||
frame_buf = msi_get_fb(msi, 0);
|
||||
msi_delete_fb(msi, frame_buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSI_CMD_AUDAC:
|
||||
{
|
||||
ret = RET_ERR;
|
||||
if(!audac_s) {
|
||||
AUDAC_INFO("audac do cmd:%d fail!\r\n",param1);
|
||||
break;
|
||||
}
|
||||
uint32_t cmd_self = (uint32_t)param1;
|
||||
switch(cmd_self) {
|
||||
case MSI_AUDAC_SET_FILTER_TRACK:
|
||||
{
|
||||
AUDIO_TRACK *audio_track = (AUDIO_TRACK*)param2;
|
||||
set_audac_filter_track(audac_s, 0, audio_track);
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_GET_FILTER_TRACK:
|
||||
{
|
||||
*((uint32_t*)param2) = (uint32_t)get_audac_filter_track(audac_s);
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_SET_CALL_VOLUME:
|
||||
{
|
||||
audac_s->call_volume = param2;
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_GET_CALL_VOLUME:
|
||||
{
|
||||
*((uint32_t*)param2) = audac_s->call_volume;
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_SET_MEDIA_VOLUME:
|
||||
{
|
||||
audac_s->media_volume = param2;
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_GET_MEDIA_VOLUME:
|
||||
{
|
||||
*((uint32_t*)param2) = audac_s->media_volume;
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_SET_BELL_VOLUME:
|
||||
{
|
||||
audac_s->bell_volume = param2;
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_GET_BELL_VOLUME:
|
||||
{
|
||||
*((uint32_t*)param2) = audac_s->bell_volume;
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_CLEAR_STREAM:
|
||||
{
|
||||
if(param2 == (uint32_t)get_audac_filter_track(audac_s)) {
|
||||
os_msgq_put(&audac_s->cache_struct.cache_msg, clear_msg, osWaitForever);
|
||||
ret = RET_OK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_END_STREAM:
|
||||
{
|
||||
if(param2 == (uint32_t)get_audac_filter_track(audac_s)) {
|
||||
os_msgq_put(&audac_s->cache_struct.cache_msg, end_msg, osWaitForever);
|
||||
ret = RET_OK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_DELETE_MODE:
|
||||
{
|
||||
audac_s->delete_mode = (uint8_t)param2;
|
||||
}
|
||||
case MSI_AUDAC_GET_EMPTY:
|
||||
{
|
||||
*((uint32_t*)param2) = (uint32_t)(audac_s->is_empty && audac_s->hold_empty);
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_HOLD_EMPTY:
|
||||
{
|
||||
audac_s->hold_empty = (uint8_t)param2;
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
case MSI_AUDAC_TEST_MODE:
|
||||
{
|
||||
if(param2 == 1) {
|
||||
set_audac_filter_track(audac_s, 1, NULL);
|
||||
set_audac_samplingrate(audac_s, 48000);
|
||||
ausys_da_test_mode(AUSYS_DA_TEST_OPEN, 0, 0, 0);
|
||||
ausys_da_test_mode(AUSYS_DA_TEST_PLAY_SINE, 0, 0, 0);
|
||||
}
|
||||
else if(param2 == 0) {
|
||||
ausys_da_test_mode(AUSYS_DA_TEST_CLOSE, 0, 0, 0);
|
||||
}
|
||||
ret = RET_OK;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
AUDAC_INFO("audac invalid commond!\r\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSI_CMD_POST_DESTROY:
|
||||
{
|
||||
if(audac_s) {
|
||||
if(audac_s->cache_struct.buf)
|
||||
AUDAC_FREE(audac_s->cache_struct.buf);
|
||||
if(audac_s->cache_struct.cache_msg.hdl)
|
||||
os_msgq_del(&audac_s->cache_struct.cache_msg);
|
||||
if(audac_s->filter_track_s.mutex.hdl)
|
||||
os_mutex_del(&audac_s->filter_track_s.mutex);
|
||||
if(audac_s->empty_buf) {
|
||||
AUDAC_FREE(audac_s->empty_buf);
|
||||
}
|
||||
if(audac_s->resample_buf) {
|
||||
AUDAC_FREE(audac_s->resample_buf);
|
||||
}
|
||||
AUDAC_FREE(audac_s);
|
||||
audac_s = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t audio_dac_init(void)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
struct msi *msi = msi_new("R_AUDAC", MAX_AUDAC_RXBUF,NULL);
|
||||
if(msi)
|
||||
{
|
||||
audac_s = (struct audac_struct *)AUDAC_ZALLOC(sizeof(struct audac_struct));
|
||||
if(!audac_s) {
|
||||
AUDAC_INFO("malloc audac_struct fail!\r\n");
|
||||
msi_destroy(msi);
|
||||
return RET_ERR;
|
||||
}
|
||||
msi->enable = 1;
|
||||
msi->action = (msi_action)audac_msi_action;
|
||||
audac_s->msi = msi;
|
||||
audac_s->sampleRate = AUDAC_SAMPLERATE;
|
||||
audac_s->data_nbytes = audac_s->sampleRate*AUDAC_TIME_INTERVAL*2/1000;
|
||||
audac_s->data_nsamples = audac_s->data_nbytes / 2;
|
||||
audac_s->empty_buf = (int16_t*)AUDAC_ZALLOC(sizeof(int16_t) * audac_s->data_nsamples);
|
||||
audac_s->resample_buf = (int16_t*)AUDAC_ZALLOC(sizeof(int16_t) * audac_s->data_nsamples);
|
||||
if((audac_s->empty_buf==NULL) || (audac_s->resample_buf==NULL)) {
|
||||
AUDAC_INFO("malloc audac empty_buf fail!\r\n");
|
||||
msi_destroy(audac_s->msi);
|
||||
return RET_ERR;
|
||||
}
|
||||
audac_s->is_empty = 1;
|
||||
audac_s->hold_empty = 1;
|
||||
audac_s->call_volume = 100;
|
||||
audac_s->media_volume = 100;
|
||||
audac_s->bell_volume = 100;
|
||||
audac_s->target_volume = 100;
|
||||
audac_s->audac_volume = 100;
|
||||
ausys_da_init(
|
||||
audac_s->sampleRate,
|
||||
16,
|
||||
1,
|
||||
AUSYS_AUDA,
|
||||
AUDAC_LEN*AUDAC_QUEUE_NUM,
|
||||
AUDAC_LEN,
|
||||
audac_s->data_nbytes
|
||||
);
|
||||
ret = audac_start(audac_s);
|
||||
if(ret != RET_OK) {
|
||||
ausys_da_deinit();
|
||||
msi_destroy(audac_s->msi);
|
||||
return RET_ERR;
|
||||
}
|
||||
AUDAC_INFO("audio dac msi init!\r\n");
|
||||
return RET_OK;
|
||||
}
|
||||
else {
|
||||
AUDAC_INFO("create auadc msi fail!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t audio_dac_deinit(void)
|
||||
{
|
||||
if(!audac_s) {
|
||||
AUDAC_INFO("audac deinit fail,auadc_s is null!\r\n");
|
||||
return RET_ERR;
|
||||
}
|
||||
audac_s->audac_stop = 1;
|
||||
while(audac_s->audac_stop != 3)
|
||||
os_sleep_ms(1);
|
||||
ausys_da_deinit();
|
||||
msi_destroy(audac_s->msi);
|
||||
return RET_OK;
|
||||
}
|
||||
47
sdk/app/audio_msi/audio_dac.h
Normal file
47
sdk/app/audio_msi/audio_dac.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef _AUDIO_DAC_H_
|
||||
#define _AUDIO_DAC_H_
|
||||
|
||||
#include "basic_include.h"
|
||||
#include "lib/heap/av_heap.h"
|
||||
#include "lib/heap/av_psram_heap.h"
|
||||
|
||||
#ifdef PSRAM_HEAP
|
||||
#define AUDAC_MALLOC av_psram_malloc
|
||||
#define AUDAC_ZALLOC av_psram_zalloc
|
||||
#define AUDAC_FREE av_psram_free
|
||||
#else
|
||||
#define AUDAC_MALLOC av_malloc
|
||||
#define AUDAC_ZALLOC av_zalloc
|
||||
#define AUDAC_FREE av_free
|
||||
#endif
|
||||
|
||||
#define AUDAC_DEBUG(fmt, args...) //os_printf(fmt, ##args)
|
||||
#define AUDAC_INFO os_printf
|
||||
/*support cmd*/
|
||||
/*
|
||||
MSI_AUDAC_SET_FILTER_TRACK,
|
||||
MSI_AUDAC_GET_FILTER_TRACK,
|
||||
MSI_AUDAC_SET_CALL_VOLUME,
|
||||
MSI_AUDAC_GET_CALL_VOLUME,
|
||||
MSI_AUDAC_SET_MEDIA_VOLUME,
|
||||
MSI_AUDAC_GET_MEDIA_VOLUME,
|
||||
MSI_AUDAC_SET_BELL_VOLUME,
|
||||
MSI_AUDAC_GET_BELL_VOLUME,
|
||||
MSI_AUDAC_CLEAR_STREAM,
|
||||
MSI_AUDAC_END_STREAM,
|
||||
MSI_AUDAC_GET_EMPTY,
|
||||
MSI_AUDAC_HOLD_EMPTY,
|
||||
MSI_AUDAC_TEST_MODE,
|
||||
*/
|
||||
|
||||
#define AUDAC_SAMPLERATE 8000
|
||||
#define AUDAC_QUEUE_NUM 3
|
||||
|
||||
#define AUDAC_TIME_INTERVAL 20
|
||||
#define AUDAC_LEN 1920 //按48k、20ms为最大长度配置
|
||||
#define MAX_AUDAC_RXBUF 24
|
||||
#define AUDAC_TASK_PRIORITY OS_TASK_PRIORITY_ABOVE_NORMAL
|
||||
|
||||
extern int32_t audio_dac_init(void);
|
||||
extern int32_t audio_dac_deinit(void);
|
||||
#endif
|
||||
Reference in New Issue
Block a user