GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
ifeq ($(CFG_XMEDIA_EXPORT_FLAG),)
|
||||
SDK_DIR := $(shell cd $(CURDIR)/../.. && /bin/pwd)
|
||||
endif
|
||||
|
||||
include $(SDK_DIR)/build/base.mk
|
||||
include $(SAMPLE_DIR)/sample_base.mk
|
||||
|
||||
LIBS := $(SAMPLE_LIBS) $(SAMPLE_COMMON_LIB)
|
||||
|
||||
INCLUDES += -I$(SDK_DIR)/sample/common
|
||||
INCLUDES += -I$(SDK_DIR)/source/gmp/include
|
||||
|
||||
SDK_USR_CFLAGS += $(SAMPLE_CFLAGS) $(LIBS) $(INCLUDES)
|
||||
|
||||
sample_audio_target = sample_audio_ai \
|
||||
sample_audio_ao \
|
||||
sample_audio_encoder \
|
||||
sample_audio_decoder \
|
||||
sample_audio_doubletalk_v1 \
|
||||
sample_audio_doubletalk_v2 \
|
||||
sample_audio_record_v1 \
|
||||
sample_audio_record_v2 \
|
||||
sample_audio_record_v3 \
|
||||
sample_audio_record_detect
|
||||
|
||||
audio_subdir_target := aq_utils
|
||||
audio_subdir_target_clean := $(addsuffix _clean, $(audio_subdir_target))
|
||||
|
||||
.PHONY: all clean $(audio_subdir_target) $(audio_subdir_target_clean)
|
||||
|
||||
all : $(sample_audio_target) $(audio_subdir_target)
|
||||
|
||||
$(audio_subdir_target):
|
||||
$(AT)$(MAKE) -C $@
|
||||
|
||||
$(audio_subdir_target_clean):
|
||||
$(AT)$(MAKE) -C $(patsubst %_clean, %, $@) clean
|
||||
|
||||
$(sample_audio_target): %: %.o
|
||||
$(AT)$(CONFIG_XMEDIA_USR_ARM_TOOLCHAINS)-gcc -o $@ $< $(SDK_USR_CFLAGS)
|
||||
|
||||
%.o : %.c
|
||||
$(AT)$(CONFIG_XMEDIA_USR_ARM_TOOLCHAINS)-gcc -c $< $(SDK_USR_CFLAGS)
|
||||
|
||||
clean : $(audio_subdir_target_clean)
|
||||
$(AT)rm -rf $(sample_audio_target) *.o
|
||||
@@ -0,0 +1,39 @@
|
||||
ifeq ($(CFG_XMEDIA_EXPORT_FLAG),)
|
||||
SDK_DIR := $(shell cd $(CURDIR)/../../.. && /bin/pwd)
|
||||
endif
|
||||
|
||||
include $(SDK_DIR)/build/base.mk
|
||||
include $(SAMPLE_DIR)/sample_base.mk
|
||||
|
||||
LIBS := $(SAMPLE_LIBS) $(SAMPLE_COMMON_LIB)
|
||||
|
||||
INCLUDES += -I$(SDK_DIR)/sample/common
|
||||
INCLUDES += -I$(SDK_DIR)/source/gmp/include
|
||||
|
||||
SDK_USR_CFLAGS += $(SAMPLE_CFLAGS) $(LIBS) $(INCLUDES)
|
||||
|
||||
sample_audio_target = aq_utils_test_speaker_vol \
|
||||
aq_utils_test_mic_vol \
|
||||
aq_utils_test_record \
|
||||
aq_utils_test_talk \
|
||||
aq_utils_test_aiao \
|
||||
aq_utils_test_detect
|
||||
|
||||
SAMPLE_AUDIDO_COMMON_SRCS := $(wildcard ./config_parameter/*.c)
|
||||
SAMPLE_AUDIDO_COMMON_OBJS := $(patsubst %.c, %.o, $(SAMPLE_AUDIDO_COMMON_SRCS))
|
||||
|
||||
.PHONY: all clean $(SAMPLE_AUDIDO_COMMON_OBJS)
|
||||
|
||||
all : $(sample_audio_target) $(SAMPLE_AUDIDO_COMMON_OBJS)
|
||||
|
||||
$(SAMPLE_AUDIDO_COMMON_OBJS): $(SAMPLE_AUDIDO_COMMON_SRCS)
|
||||
$(AT)$(CONFIG_XMEDIA_USR_ARM_TOOLCHAINS)-gcc -c $< -o $@ $(SDK_USR_CFLAGS)
|
||||
|
||||
$(sample_audio_target): %: %.o $(SAMPLE_AUDIDO_COMMON_OBJS)
|
||||
$(AT)$(CONFIG_XMEDIA_USR_ARM_TOOLCHAINS)-gcc -o $@ $(SAMPLE_AUDIDO_COMMON_OBJS) $< $(SDK_USR_CFLAGS)
|
||||
|
||||
%.o : %.c
|
||||
$(AT)$(CONFIG_XMEDIA_USR_ARM_TOOLCHAINS)-gcc -c $< $(SDK_USR_CFLAGS)
|
||||
|
||||
clean :
|
||||
$(AT)rm -rf $(sample_audio_target) *.o $(SAMPLE_AUDIDO_COMMON_OBJS)
|
||||
Executable
+315
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
#include "sample_comm_audio.h"
|
||||
#include "config_parameter/config_load_parameter.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
#define DEFAULT_AI_FRAME_NUM 50
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_bool binder_mode;
|
||||
audio_sample_rate file_samplerate;
|
||||
|
||||
char input_file_name[MAX_FILE_NAME_LEN];
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *input_fd[2];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static sample_ao_config g_ao_config;
|
||||
static xmedia_s32 g_codec_vol;
|
||||
static xmedia_s32 g_ao_vol;
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = g_user_input_args.sample_rate / 100;
|
||||
g_ai_config.dev_attr.pcm_frame_num = DEFAULT_AI_FRAME_NUM;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.chn_attr.interleaved = XMEDIA_TRUE;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_FALSE;
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ao_config_init(xmedia_void)
|
||||
{
|
||||
g_ao_config.dev = XMEDIA_AO_DEV_DAC0;
|
||||
|
||||
sample_comm_ao_get_default_attr(g_ao_config.dev, &g_ao_config.dev_attr);
|
||||
g_ao_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ao_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ao_config.dev_attr.pcm_samples_per_frame = g_user_input_args.sample_rate / 100;
|
||||
g_ao_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ao_config.vqe_enable = XMEDIA_FALSE;
|
||||
|
||||
g_ao_config.frame_info.frm_rate = g_user_input_args.sample_rate;
|
||||
g_ao_config.frame_info.frm_chn = g_user_input_args.channels;
|
||||
g_ao_config.frame_info.frm_bit = AUDIO_BIT_DEPTH_16;
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
ret = sample_comm_ai_create_output_thread_to_file(&g_ai_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_output_thread_to_file");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ao_config_init();
|
||||
CHECK_RET(ret, "sample_ao_config_init");
|
||||
|
||||
ret = sample_comm_ao_start(&g_ao_config);
|
||||
|
||||
sample_comm_ao_create_input_thread_from_file(&g_ao_config, g_user_input_args.input_fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
ret = sample_comm_ai_destroy_output_thread_to_file(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_data_thread");
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
ret = sample_comm_ao_destroy_input_thread_from_file(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_create_input_thread_from_file");
|
||||
|
||||
ret = sample_comm_ao_stop(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_audio_aiao(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ao();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AO;
|
||||
}
|
||||
|
||||
ret = sample_comm_ao_set_volume(&g_ao_config, g_ao_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&g_codec_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_SET_GAIN;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
int val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'sivXX' to set input vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'giv' to get input vol\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'sovXX' to set ao vqe vol to xx\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gov' to get ao vqe vol to xx\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'i' && input_cmd[2] == 'v') {
|
||||
val = atoi(input_cmd + 3);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet codec input volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'i' && input_cmd[2] == 'v') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet codec input volume(%d) return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'o' && input_cmd[2] == 'v') {
|
||||
val = atoi(input_cmd + 3);
|
||||
ret = sample_comm_ao_set_volume(&g_ao_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ao vqe volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'o' && input_cmd[2] == 'v') {
|
||||
ret = sample_comm_ao_get_volume(&g_ao_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ao vqe volume(%d) return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'q') {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
ERR_SET_GAIN:
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
sample_stop_ao();
|
||||
ERR_START_AO:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("Usage:./aq_utils_test_aiao [Samplerate] [Channel] [CodecInputVol] [AoVol] [MicFile] [SpkFile]\n");
|
||||
SAMPLE_AUDIO_DBG("Parameter comment as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" [Samplerate]: Work Samplerate, 8000 or 16000 \n");
|
||||
SAMPLE_AUDIO_DBG(" [Channel]: dev chn, 1 or 2 \n");
|
||||
SAMPLE_AUDIO_DBG(" [CodecInputVol]: audiocodec mic input volume, range:[-95~48] \n");
|
||||
SAMPLE_AUDIO_DBG(" [AoVol]: ao vqe volume, range:[-81~18] \n");
|
||||
SAMPLE_AUDIO_DBG(" [MicFile]: file for saving mic data\n");
|
||||
SAMPLE_AUDIO_DBG(" [SpkFile]: file for speaker playback\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("Examples as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" ./aq_utils_test_aiao 16000 1 20 0 /tmp/mic.pcm /tmp/test_signal_loopback_16k_1ch_16bit.pcm\n");
|
||||
SAMPLE_AUDIO_DBG(" ./aq_utils_test_aiao 8000 2 20 0 /tmp/mic.pcm /tmp/test_signal_loopback_8k_1ch_16bit.pcm\n");
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 7) {
|
||||
SAMPLE_AUDIO_DBG("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
user_in_args->sample_rate = atoi(argv[1]);
|
||||
user_in_args->channels = atoi(argv[2]);
|
||||
g_codec_vol = atoi(argv[3]);
|
||||
g_ao_vol = atoi(argv[4]);
|
||||
user_in_args->binder_mode = XMEDIA_TRUE;
|
||||
memcpy(user_in_args->output_file_name, argv[5], strlen(argv[5]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
SAMPLE_AUDIO_DBG("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(user_in_args->input_file_name, argv[6], strlen(argv[6]));
|
||||
if (strcmp(user_in_args->input_file_name, "null")) {
|
||||
user_in_args->input_fd[0] = fopen(user_in_args->input_file_name, "rb");
|
||||
if (user_in_args->input_fd[0] == NULL) {
|
||||
SAMPLE_AUDIO_DBG("Open %s failed\n", user_in_args->input_file_name);
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->input_fd[1] != NULL) {
|
||||
fclose(user_in_args->input_fd[1]);
|
||||
user_in_args->input_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->input_fd[0] != NULL) {
|
||||
fclose(user_in_args->input_fd[0]);
|
||||
user_in_args->input_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_aiao();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("sample_auido_ai failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
Executable
+325
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_bcd.h"
|
||||
#include "xmedia_audio_vqe_detect.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
#include "config_parameter/config_load_parameter.h"
|
||||
|
||||
static ai_vqe_attr_detect detect_attr;
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_bool binder_mode;
|
||||
xmedia_s32 codec_input_vol;
|
||||
xmedia_s32 ai_vqe_vol;
|
||||
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
char config_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static user_base_config base_config;
|
||||
|
||||
static xmedia_s32 cry_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("cry callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 gbd_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("gbd callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ssl_callback(xmedia_void* attr, xmedia_s32 out)
|
||||
{
|
||||
static xmedia_s32 ssl_out = 0;
|
||||
static xmedia_s32 call_times = 0;
|
||||
call_times++;
|
||||
|
||||
if (ssl_out != out) {
|
||||
printf("attr(0x%x), call_times(%d), out_angle(%d)\n", (xmedia_u32)attr, call_times, out);
|
||||
}
|
||||
ssl_out = out;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ved_callback(xmedia_void* private, xmedia_bool is_event, xmedia_bool is_mutation, xmedia_s32 out_db)
|
||||
{
|
||||
if (is_event) {
|
||||
printf("volume event detect out_db = %d\n",out_db);
|
||||
}
|
||||
if (is_mutation) {
|
||||
printf("volume mutation detect out_db = %d\n", out_db);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
|
||||
ret = load_base_parameter(g_user_input_args.config_file_name, &base_config);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
g_user_input_args.codec_input_vol = base_config.codec_input_vol;
|
||||
g_user_input_args.ai_vqe_vol = base_config.ai_vqe_vol;
|
||||
g_ai_config.dev_attr.channels = base_config.in_chn_cnt;
|
||||
g_ai_config.dev_attr.sample_rate = base_config.work_samplerate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = base_config.sample_per_frame;
|
||||
g_ai_config.dev_attr.pcm_frame_num = base_config.frame_nums;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = base_config.work_samplerate;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
g_ai_config.chn_attr.interleaved = XMEDIA_TRUE;
|
||||
if ((g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
if (base_config.vqe_version == AI_VQE_DETECT_ATTR_VERSION_1) {
|
||||
g_ai_config.vqe_attr.attr = &detect_attr;
|
||||
}
|
||||
g_ai_config.vqe_attr.version = base_config.vqe_version;
|
||||
g_ai_config.vqe_attr.work_sample_rate = base_config.work_samplerate;
|
||||
g_ai_config.vqe_attr.in_channels = base_config.in_chn_cnt;
|
||||
ret = load_aivqe_parameter(g_user_input_args.config_file_name, &g_ai_config.vqe_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
detect_attr.bcd_attr.bcd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr.bcd_attr.bcd_model.model_info.file.pathname = "../audio_xmm/bcd_neuron_network.xmm";
|
||||
detect_attr.bcd_attr.callback = (fn_bcd_callback)cry_callback;
|
||||
|
||||
detect_attr.gbd_attr.gbd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr.gbd_attr.gbd_model.model_info.file.pathname = "../audio_xmm/gbd_neuron_network.xmm";
|
||||
detect_attr.gbd_attr.callback = (fn_detect_gbd_callback)gbd_callback;
|
||||
|
||||
detect_attr.ssl_attr.callback = (fn_detect_ssl_callback)ssl_callback;
|
||||
detect_attr.ved_attr.callback = (fn_detect_ved_callback)ved_callback;
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_u32 mask = 0;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
mask = detect_attr.mask;
|
||||
|
||||
ret = sample_comm_ai_register(mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_dev_param failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
} else if (g_ai_config.dev == XMEDIA_AI_DEV_PDM0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_MIC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_dev_param failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, g_user_input_args.ai_vqe_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_volume failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
ret = sample_comm_ai_create_output_thread_to_file(&g_ai_config, g_user_input_args.output_fd);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_create_output_thread_to_file failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
ERR:
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
ret = sample_comm_ai_destroy_output_thread_to_file(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_data_thread");
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_audio_detect_vqe(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
int val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG(">>> Input 'scvXX' to set input vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG(">>> Input 'gcv' to get input vol\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'c' && input_cmd[2] == 'v') {
|
||||
val = atoi(input_cmd + 3);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet codec input volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'c' && input_cmd[2] == 'v') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet codec input volume(%d) return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'q') {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("Usage:./aq_utils_test_detect [Config] [OutFile]\n");
|
||||
SAMPLE_AUDIO_DBG("Parameter comment as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" Config : alg parameters config file\n");
|
||||
SAMPLE_AUDIO_DBG(" OutFile : vqe out file\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("Examples as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" ./aq_utils_test_detect ./config_parameter/record_ai_detect.ini /tmp/vqe_out.pcm\n");
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 3) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
user_in_args->binder_mode = XMEDIA_FALSE;
|
||||
|
||||
memcpy(user_in_args->config_file_name, argv[1], strlen(argv[1]));
|
||||
|
||||
memcpy(user_in_args->output_file_name, argv[2], strlen(argv[2]));
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_detect_vqe();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_audio_record_vqev1 failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
#define DEFAULT_AI_FRAME_NUM 50
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
ai_dev dev;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_bit_depth bit_depth;
|
||||
audio_channel channels;
|
||||
xmedia_s32 workmode;
|
||||
xmedia_u32 samples_per_frm;
|
||||
xmedia_s32 codec_input_vol;
|
||||
xmedia_bool binder_mode;
|
||||
|
||||
xmedia_u32 send_object;
|
||||
ao_dev send_object_dev;
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = g_user_input_args.dev;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.bit_depth = g_user_input_args.bit_depth;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = g_user_input_args.samples_per_frm;
|
||||
g_ai_config.dev_attr.pcm_frame_num = DEFAULT_AI_FRAME_NUM;
|
||||
g_ai_config.dev_attr.mode = g_user_input_args.workmode;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.chn_attr.interleaved = XMEDIA_TRUE;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_FALSE;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
if (g_user_input_args.send_object == 0) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_file(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_output_thread_to_file");
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
if (g_user_input_args.send_object == 0) {
|
||||
ret = sample_comm_ai_create_output_thread_to_file(&g_ai_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_output_thread_to_file");
|
||||
}
|
||||
|
||||
if (g_user_input_args.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_dev_param failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
ERR:
|
||||
sample_stop_ai();
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_audio_ai(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG(">>> Input 'scvXX' to set input vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG(">>> Input 'gcv' to get input vol\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'c' && input_cmd[2] == 'v') {
|
||||
val = atoi(input_cmd + 3);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet codec input volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'c' && input_cmd[2] == 'v') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet codec input volume(%d) return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'q') {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("Usage:./aq_utils_test_mic_vol [Samplerate] [Chn] [CodecInputVol] [MicFile]\n");
|
||||
SAMPLE_AUDIO_DBG("Parameter comment as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" [Samplerate]: Work Samplerate, 8000 or 16000\n");
|
||||
SAMPLE_AUDIO_DBG(" [Chn]: Channel, 1 or 2\n");
|
||||
SAMPLE_AUDIO_DBG(" [CodecInputVol]: audiocodec mic input volume, range:[-95~48]\n");
|
||||
SAMPLE_AUDIO_DBG(" [MicFile]: file for saving mic data\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("Examples as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" ./aq_utils_test_mic_vol 16000 1 20 /tmp/mic_gain.pcm\n");
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 5) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->dev = XMEDIA_AI_DEV_ADC0;
|
||||
user_in_args->sample_rate = atoi(argv[1]);
|
||||
user_in_args->usr_sample_rate = atoi(argv[1]);
|
||||
user_in_args->bit_depth = AUDIO_BIT_DEPTH_16;
|
||||
user_in_args->channels = atoi(argv[2]);
|
||||
user_in_args->workmode = 1; /*queue mode*/
|
||||
user_in_args->samples_per_frm = user_in_args->usr_sample_rate / 100;
|
||||
user_in_args->codec_input_vol = atoi(argv[3]);
|
||||
user_in_args->send_object = 0;
|
||||
user_in_args->binder_mode = XMEDIA_TRUE;
|
||||
|
||||
memcpy(user_in_args->output_file_name, argv[4], strlen(argv[4]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_auido_ai failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
printf("exit sample ai\n");
|
||||
return ret;
|
||||
}
|
||||
Executable
+350
@@ -0,0 +1,350 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
#include "xmedia_audio_vqe_enhance_v3.h"
|
||||
#include "sample_comm_audio.h"
|
||||
#include "config_parameter/config_load_parameter.h"
|
||||
|
||||
static ai_vqe_attr_v1 v1_attr;
|
||||
static ai_vqe_attr_v2 v2_attr;
|
||||
static ai_vqe_attr_v3 v3_attr;
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_bool binder_mode;
|
||||
xmedia_s32 codec_input_vol;
|
||||
xmedia_s32 ai_vqe_vol;
|
||||
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
char config_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static sample_aenc_config g_aenc_config;
|
||||
static user_base_config base_config;
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
|
||||
ret = load_base_parameter(g_user_input_args.config_file_name, &base_config);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
g_user_input_args.codec_input_vol = base_config.codec_input_vol;
|
||||
g_user_input_args.ai_vqe_vol = base_config.ai_vqe_vol;
|
||||
g_ai_config.dev_attr.channels = base_config.in_chn_cnt;
|
||||
g_ai_config.dev_attr.sample_rate = base_config.work_samplerate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = base_config.sample_per_frame;
|
||||
g_ai_config.dev_attr.pcm_frame_num = base_config.frame_nums;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = base_config.work_samplerate;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
if (base_config.vqe_version == AI_VQE_ENHANCE_ATTR_VERSION_1) {
|
||||
g_ai_config.vqe_attr.attr = &v1_attr;
|
||||
} else if (base_config.vqe_version == AI_VQE_ENHANCE_ATTR_VERSION_2) {
|
||||
g_ai_config.vqe_attr.attr = &v2_attr;
|
||||
} else if (base_config.vqe_version == AI_VQE_ENHANCE_ATTR_VERSION_3) {
|
||||
g_ai_config.vqe_attr.attr = &v3_attr;
|
||||
}
|
||||
g_ai_config.vqe_attr.version = base_config.vqe_version;
|
||||
g_ai_config.vqe_attr.work_sample_rate = base_config.work_samplerate;
|
||||
g_ai_config.vqe_attr.in_channels = base_config.in_chn_cnt;
|
||||
ret = load_aivqe_parameter(g_user_input_args.config_file_name, &g_ai_config.vqe_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_aenc_config_init(xmedia_void)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.output_file_name, &type, &format);
|
||||
g_aenc_config.sample_rate = base_config.work_samplerate;
|
||||
g_aenc_config.channels = base_config.out_chn_cnt;//g_user_input_args.channels;
|
||||
g_aenc_config.bit_depth = 16;
|
||||
g_aenc_config.chn = 0;
|
||||
g_aenc_config.type = type;
|
||||
g_aenc_config.format = format;
|
||||
g_aenc_config.binder_dev = g_ai_config.dev;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_aenc_config.binder_src = MOD_ID_AI;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_data_thread");
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_u32 mask = 0;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
if (g_ai_config.vqe_attr.version == AI_VQE_ENHANCE_ATTR_VERSION_1) {
|
||||
mask = v1_attr.mask;
|
||||
} else if (g_ai_config.vqe_attr.version == AI_VQE_ENHANCE_ATTR_VERSION_2) {
|
||||
mask = v2_attr.mask;
|
||||
} else if (g_ai_config.vqe_attr.version == AI_VQE_ENHANCE_ATTR_VERSION_3) {
|
||||
mask = v3_attr.mask;
|
||||
}
|
||||
ret = sample_comm_ai_register(mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_create_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_data_thread");
|
||||
}
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_dev_param failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
} else if (g_ai_config.dev == XMEDIA_AI_DEV_PDM0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_MIC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_dev_param failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, g_user_input_args.ai_vqe_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_volume failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
ERR:
|
||||
sample_stop_ai();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_aenc_config_init();
|
||||
CHECK_RET(ret, "sample_aenc_config_init");
|
||||
|
||||
ret = sample_comm_aenc_register(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_aenc_start(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_start");
|
||||
|
||||
ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_data_thread");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_out_to_file_thread");
|
||||
|
||||
ret = sample_comm_aenc_stop(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_stop");
|
||||
|
||||
ret = sample_comm_aenc_unregister(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_aenc_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
xmedia_s32 sample_audio_record_vqe(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
ret = sample_start_aenc();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AENC;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
int val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG(">>> Input 'scvXX' to set input vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG(">>> Input 'gcv' to get input vol\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'c' && input_cmd[2] == 'v') {
|
||||
val = atoi(input_cmd + 3);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet codec input volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'c' && input_cmd[2] == 'v') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet codec input volume(%d) return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'q') {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_aenc();
|
||||
ERR_START_AENC:
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("Usage:./aq_utils_test_record [Config] [OutFile]\n");
|
||||
SAMPLE_AUDIO_DBG("Parameter comment as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" Config : alg parameters config file\n");
|
||||
SAMPLE_AUDIO_DBG(" OutFile : vqe out file\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("Examples as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" ./aq_utils_test_record ./config_parameter/record_ai_vqev1_16k_1ch.ini /tmp/vqe_out.pcm\n");
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 3) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
user_in_args->binder_mode = XMEDIA_TRUE;
|
||||
|
||||
memcpy(user_in_args->config_file_name, argv[1], strlen(argv[1]));
|
||||
|
||||
memcpy(user_in_args->output_file_name, argv[2], strlen(argv[2]));
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_record_vqe();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_audio_record_vqev1 failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ao.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define SLEEP_TIME 10000 /* 5ms */
|
||||
#define INPUT_CMD_LENGTH 32
|
||||
|
||||
#define SEED_FRAME_TIME 10 /*10ms*/
|
||||
#define ACQUIRE_FRAME_STATUS 1
|
||||
#define SEND_FRAME_STATUS 0
|
||||
#define DEFAULT_AO_FRAME_NUM 30
|
||||
|
||||
#define SAMPLE_GET_INPUTCMD(input_cmd) fgets((char *)(input_cmd), (sizeof(input_cmd) - 1), stdin)
|
||||
static sample_ao_config g_ao_config = {0};
|
||||
static xmedia_s32 gain = 0;
|
||||
|
||||
typedef struct {
|
||||
xmedia_char *sample;
|
||||
xmedia_char *dev_rate;
|
||||
xmedia_char *dev_chn;
|
||||
xmedia_char *gain;
|
||||
xmedia_char *in_stream;
|
||||
} input_arg;
|
||||
|
||||
typedef struct {
|
||||
FILE *in_stream[2];
|
||||
ao_dev dev;
|
||||
ao_chn chn;
|
||||
xmedia_u32 vqe;
|
||||
xmedia_u32 frm_rate;
|
||||
xmedia_u32 frm_chn;
|
||||
xmedia_u32 dev_rate;
|
||||
xmedia_u32 dev_chn;
|
||||
xmedia_u32 frame_pcm_sample;
|
||||
audio_dev_work_mode mode;
|
||||
xmedia_u32 pcm_samples;
|
||||
} sample_ctx;
|
||||
|
||||
static xmedia_s32 sample_ctx_init(const input_arg *arg, sample_ctx *ctx)
|
||||
{
|
||||
xmedia_u32 i;
|
||||
|
||||
ctx->dev = XMEDIA_AO_DEV_DAC0;
|
||||
ctx->dev_rate = atoi(arg->dev_rate);
|
||||
ctx->dev_chn = atoi(arg->dev_chn);
|
||||
ctx->frm_rate = atoi(arg->dev_rate);
|
||||
ctx->frm_chn = atoi(arg->dev_chn);
|
||||
ctx->mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
ctx->frame_pcm_sample = ctx->dev_rate / 100;
|
||||
ctx->vqe = 0;
|
||||
gain = atoi(arg->gain);
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
ctx->in_stream[i] = fopen(arg->in_stream, "rb");
|
||||
if (ctx->in_stream[i] == XMEDIA_NULL) {
|
||||
SAMPLE_AUDIO_DBG("open file %s error!\n", arg->in_stream);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ctx_deinit(sample_ctx *ctx)
|
||||
{
|
||||
xmedia_u32 i;
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
if (ctx->in_stream[i] != XMEDIA_NULL) {
|
||||
fclose(ctx->in_stream[i]);
|
||||
ctx->in_stream[i] = XMEDIA_NULL;
|
||||
}
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ao_config_init(sample_ctx* ctx)
|
||||
{
|
||||
g_ao_config.dev = ctx->dev;
|
||||
|
||||
sample_comm_ao_get_default_attr(g_ao_config.dev, &g_ao_config.dev_attr);
|
||||
g_ao_config.dev_attr.pcm_frame_max_num = 10;
|
||||
g_ao_config.dev_attr.channels = ctx->dev_chn;
|
||||
g_ao_config.dev_attr.sample_rate = ctx->dev_rate;
|
||||
g_ao_config.dev_attr.pcm_samples_per_frame = ctx->frame_pcm_sample;
|
||||
g_ao_config.dev_attr.pcm_frame_max_num = DEFAULT_AO_FRAME_NUM;
|
||||
g_ao_config.dev_attr.mode = ctx->mode;
|
||||
|
||||
g_ao_config.frame_info.frm_rate = ctx->frm_rate;
|
||||
g_ao_config.frame_info.frm_chn = ctx->frm_chn;
|
||||
g_ao_config.frame_info.frm_bit = AUDIO_BIT_DEPTH_16;
|
||||
|
||||
g_ao_config.vqe_enable = ctx->vqe;
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ao(sample_ctx* ctx)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ao_config_init(ctx);
|
||||
CHECK_RET(ret, "sample_ao_config_init");
|
||||
|
||||
ret = sample_comm_ao_start(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_start");
|
||||
|
||||
sample_comm_ao_create_input_thread_from_file(&g_ao_config, ctx->in_stream);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
sample_comm_ao_destroy_input_thread_from_file(&g_ao_config);
|
||||
|
||||
ret = sample_comm_ao_stop(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void usage(input_arg *arg)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("Usage:./aq_utils_test_speaker_vol [Samplerate] [Chn] [AoVol] [SpkFile]\n");
|
||||
SAMPLE_AUDIO_DBG("Parameter comment as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" [Samplerate]: Work Samplerate, 8000 or 16000\n");
|
||||
SAMPLE_AUDIO_DBG(" [Chn]: channel, 1 or 2\n");
|
||||
SAMPLE_AUDIO_DBG(" [AoVol]: ao vqe volume, range:[-81~18]\n");
|
||||
SAMPLE_AUDIO_DBG(" [SpkFile]: file for speaker playback\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("Examples as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" ./aq_utils_test_speaker_vol 16000 1 0 test_signal_spk_volumn_16k_1ch_16bit.pcm\n");
|
||||
SAMPLE_AUDIO_DBG(" ./aq_utils_test_speaker_vol 8000 1 0 test_signal_spk_volumn_8k_1ch_16bit.pcm\n");
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
sample_ctx ctx;
|
||||
xmedia_s32 val = 0;
|
||||
|
||||
input_arg *arg = (input_arg *)argv;
|
||||
xmedia_char input_cmd[INPUT_CMD_LENGTH];
|
||||
|
||||
if (argc != sizeof(input_arg) / sizeof(xmedia_char *)) {
|
||||
usage(arg);
|
||||
return -1;
|
||||
}
|
||||
memset(&ctx, 0, sizeof(sample_ctx));
|
||||
|
||||
ret = sample_ctx_init(arg, &ctx);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("call sample_ctx_init failed(0x%x)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
sample_comm_audio_init();
|
||||
|
||||
ret = sample_start_ao(&ctx);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("call sample_start_ao failed(0x%x)\n", ret);
|
||||
goto START_AO_ERR;
|
||||
}
|
||||
ret = sample_comm_ao_set_volume(&g_ao_config, gain);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("call sample_start_ao failed(0x%x)\n", ret);
|
||||
goto SET_VOL_ERR;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ao vqe volume to xx\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ao vqe volume\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v' ) {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ao_set_volume(&g_ao_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ao vqe volume(%d) return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'v' ) {
|
||||
ret = sample_comm_ao_get_volume(&g_ao_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ao vqe volume(%d) return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'q') {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
SET_VOL_ERR:
|
||||
sample_stop_ao();
|
||||
START_AO_ERR:
|
||||
sample_comm_audio_exit();
|
||||
sample_ctx_deinit(&ctx);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", arg->sample);
|
||||
return ret;
|
||||
}
|
||||
Executable
+516
@@ -0,0 +1,516 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
#include "sample_comm_audio.h"
|
||||
#include "config_parameter/config_load_parameter.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_bool binder_mode;
|
||||
audio_sample_rate file_samplerate;
|
||||
|
||||
char input_file_name[MAX_FILE_NAME_LEN];
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
char aivqe_config_file_name[MAX_FILE_NAME_LEN];
|
||||
char aovqe_config_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *input_fd[2];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static sample_ao_config g_ao_config;
|
||||
static sample_adec_config g_adec_config;
|
||||
static sample_aenc_config g_aenc_config;
|
||||
|
||||
static user_base_config base_config;
|
||||
static ai_vqe_attr_v1 ai_v1_attr;
|
||||
static ai_vqe_attr_v2 ai_v2_attr;
|
||||
static ao_vqe_attr_v1 ao_v1_attr;
|
||||
static ao_vqe_attr_v2 ao_v2_attr;
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = base_config.in_chn_cnt;
|
||||
g_ai_config.dev_attr.sample_rate = base_config.work_samplerate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = base_config.sample_per_frame;
|
||||
g_ai_config.dev_attr.pcm_frame_num = base_config.frame_nums;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = base_config.work_samplerate;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
if (base_config.vqe_version == AI_VQE_ENHANCE_ATTR_VERSION_1) {
|
||||
g_ai_config.vqe_attr.attr = &ai_v1_attr;
|
||||
} else if (base_config.vqe_version == AI_VQE_ENHANCE_ATTR_VERSION_2) {
|
||||
g_ai_config.vqe_attr.attr = &ai_v2_attr;
|
||||
}
|
||||
g_ai_config.vqe_attr.version = base_config.vqe_version;
|
||||
g_ai_config.vqe_attr.work_sample_rate = base_config.work_samplerate;
|
||||
g_ai_config.vqe_attr.in_channels = base_config.in_chn_cnt;
|
||||
ret = load_aivqe_parameter(g_user_input_args.aivqe_config_file_name, &g_ai_config.vqe_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ao_config_init(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
g_ao_config.dev = XMEDIA_AO_DEV_DAC0;
|
||||
|
||||
sample_comm_ao_get_default_attr(g_ao_config.dev, &g_ao_config.dev_attr);
|
||||
g_ao_config.dev_attr.channels = base_config.out_chn_cnt;
|
||||
g_ao_config.dev_attr.sample_rate = base_config.work_samplerate;
|
||||
g_ao_config.dev_attr.pcm_samples_per_frame = base_config.sample_per_frame;
|
||||
g_ao_config.dev_attr.pcm_frame_max_num = base_config.frame_nums;
|
||||
g_ao_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
//AAC/MP3不知道输入采样率,默认注册重采样,其他格式根据输入采样率决定是否注册
|
||||
g_ao_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_adec_config.type == CODEC_TYPE_AAC || g_adec_config.type == CODEC_TYPE_MP3) ||
|
||||
(g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ao_config.frame_info.frm_rate != g_ao_config.dev_attr.sample_rate)) {
|
||||
g_ao_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
|
||||
g_ao_config.vqe_enable = XMEDIA_TRUE;
|
||||
g_ao_config.vqe_attr.version = base_config.vqe_version;
|
||||
if (base_config.vqe_version == AI_VQE_ENHANCE_ATTR_VERSION_1) {
|
||||
g_ao_config.vqe_attr.attr = &ao_v1_attr;
|
||||
} else if (base_config.vqe_version == AI_VQE_ENHANCE_ATTR_VERSION_2) {
|
||||
g_ao_config.vqe_attr.attr = &ao_v2_attr;
|
||||
}
|
||||
ret = load_aovqe_parameter(g_user_input_args.aovqe_config_file_name, &g_ao_config.vqe_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_ao_config.binder_src = MOD_ID_ADEC;
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_adec_config_init(xmedia_void)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.input_file_name, &type, &format);
|
||||
|
||||
g_adec_config.sample_rate = base_config.work_samplerate;
|
||||
g_adec_config.chn = 0;
|
||||
g_adec_config.type = type;
|
||||
g_adec_config.format = format;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_aenc_config_init(xmedia_void)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.output_file_name, &type, &format);
|
||||
g_aenc_config.sample_rate = base_config.work_samplerate;
|
||||
g_aenc_config.channels = base_config.out_chn_cnt;
|
||||
g_aenc_config.bit_depth = 16;
|
||||
g_aenc_config.chn = 0;
|
||||
g_aenc_config.type = type;
|
||||
g_aenc_config.format = format;
|
||||
g_aenc_config.binder_dev = g_ai_config.dev;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_aenc_config.binder_src = MOD_ID_AI;
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_data_thread");
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_register((g_ai_config.vqe_attr.version == AI_VQE_ENHANCE_ATTR_VERSION_1) ? ai_v1_attr.mask : ai_v2_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_create_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_data_thread");
|
||||
}
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&base_config.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_dev_param failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
} else if (g_ai_config.dev == XMEDIA_AI_DEV_PDM0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_MIC_GAIN, (xmedia_void*)&base_config.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_dev_param failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, base_config.ai_vqe_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_comm_ai_set_volume failed(0x%x)\n", ret);
|
||||
goto ERR;
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
ERR:
|
||||
sample_stop_ai();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ao_config_init();
|
||||
CHECK_RET(ret, "sample_ao_config_init");
|
||||
|
||||
ret = sample_comm_ao_register((g_ao_config.vqe_attr.version == AO_VQE_ENHANCE_ATTR_VERSION_1) ? ao_v1_attr.mask : ao_v2_attr.mask, g_ao_config.vqe_attr.version, g_ao_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ao_start(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_start");
|
||||
|
||||
ret = sample_comm_ao_set_volume(&g_ao_config, base_config.ao_vqe_vol);
|
||||
CHECK_RET(ret, "sample_comm_ao_set_volume");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_adec()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_adec_config_init();
|
||||
CHECK_RET(ret, "sample_adec_config_init");
|
||||
|
||||
ret = sample_comm_adec_register(g_adec_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_adec_start(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_start");
|
||||
|
||||
ret = sample_comm_adec_create_input_thread_from_file(&g_adec_config, g_user_input_args.input_fd);
|
||||
CHECK_RET(ret, "sample_comm_adec_create_out_to_ao_thread");
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_adec_create_output_thread_to_ao(&g_adec_config, g_ao_config.dev, g_adec_config.chn);
|
||||
CHECK_RET(ret, "sample_comm_adec_create_out_to_ao_thread");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_aenc_config_init();
|
||||
CHECK_RET(ret, "sample_aenc_config_init");
|
||||
|
||||
ret = sample_comm_aenc_register(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_aenc_start(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_start");
|
||||
|
||||
ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_data_thread");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_ao_stop(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_adec()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_adec_destroy_input_thread_from_file(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_destroy_input_thread_from_file");
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_adec_destroy_output_thread_to_ao(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_destroy_output_thread_to_ao");
|
||||
}
|
||||
|
||||
ret = sample_comm_adec_stop(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_stop");
|
||||
|
||||
ret = sample_comm_adec_unregister(g_adec_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_out_to_file_thread");
|
||||
|
||||
ret = sample_comm_aenc_stop(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_stop");
|
||||
|
||||
ret = sample_comm_aenc_unregister(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_aenc_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
xmedia_s32 sample_audio_doubletalk(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_adec();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_ADEC;
|
||||
}
|
||||
|
||||
ret = sample_start_ao();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
ret = sample_start_aenc();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AENC;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
int val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'sivXX' to set input vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'giv' to get input vol\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'sovXX' to set ao vqe vol to xx\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gov' to get ao vqe vol to xx\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'i' && input_cmd[2] == 'v') {
|
||||
val = atoi(input_cmd + 3);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet codec input volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'i' && input_cmd[2] == 'v') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet codec input volume(%d) return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'o' && input_cmd[2] == 'v') {
|
||||
val = atoi(input_cmd + 3);
|
||||
ret = sample_comm_ao_set_volume(&g_ao_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ao vqe volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'o' && input_cmd[2] == 'v') {
|
||||
ret = sample_comm_ao_get_volume(&g_ao_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ao vqe volume(%d) return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'q') {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_aenc();
|
||||
ERR_START_AENC:
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
sample_stop_ao();
|
||||
ERR_START_AO:
|
||||
sample_stop_adec();
|
||||
ERR_START_ADEC:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("Usage:./aq_utils_test_talk [AIvqeConfig] [AOvqeConfig] [RemoteFile] [OutFile]\n");
|
||||
SAMPLE_AUDIO_DBG("Parameter comment as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" [AIvqeConfig]: AI VQE config file\n");
|
||||
SAMPLE_AUDIO_DBG(" [AOvqeConfig]: AO VQE config file\n");
|
||||
SAMPLE_AUDIO_DBG(" [RemoteFile]: speaker playback file\n");
|
||||
SAMPLE_AUDIO_DBG(" [OutFile]: vqe out file\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("Examples as follows:\n");
|
||||
SAMPLE_AUDIO_DBG(" ./aq_utils_test_talk ./config_parameter/talk_ai_vqev2_16k_2ch.ini ./config_parameter/talk_ao_vqev2_16k_1ch.ini spk_play.pcm vqe_out.pcm\n");
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 5) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 5) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
memcpy(user_in_args->aivqe_config_file_name, argv[1], strlen(argv[1]));
|
||||
memcpy(user_in_args->aovqe_config_file_name, argv[2], strlen(argv[2]));
|
||||
|
||||
user_in_args->binder_mode = XMEDIA_TRUE;
|
||||
memcpy(user_in_args->input_file_name, argv[3], strlen(argv[3]));
|
||||
if (strcmp(user_in_args->input_file_name, "null")) {
|
||||
user_in_args->input_fd[0] = fopen(user_in_args->input_file_name, "rb");
|
||||
if (user_in_args->input_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->input_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
memcpy(user_in_args->output_file_name, argv[4], strlen(argv[4]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
fclose(user_in_args->input_fd[0]);
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
ret = load_base_parameter(g_user_input_args.aivqe_config_file_name, &base_config);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
fclose(user_in_args->input_fd[0]);
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
SAMPLE_AUDIO_DBG("load_base_parameter failed(0x%x)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->input_fd[1] != NULL) {
|
||||
fclose(user_in_args->input_fd[1]);
|
||||
user_in_args->input_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->input_fd[0] != NULL) {
|
||||
fclose(user_in_args->input_fd[0]);
|
||||
user_in_args->input_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_doubletalk();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_auido_ai failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#ifndef __CONFIG_LOAD_PARAMETER_H__
|
||||
#define __CONFIG_LOAD_PARAMETER_H__
|
||||
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ao.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
|
||||
typedef struct USER_BASE_CONFIG
|
||||
{
|
||||
audio_sample_rate work_samplerate;
|
||||
xmedia_u32 in_chn_cnt;
|
||||
xmedia_u32 out_chn_cnt;
|
||||
xmedia_u32 sample_per_frame;
|
||||
xmedia_u32 frame_nums;
|
||||
xmedia_u32 vqe_version;
|
||||
|
||||
xmedia_s32 codec_input_vol;
|
||||
xmedia_s32 ai_vqe_vol;
|
||||
xmedia_s32 ao_vqe_vol;
|
||||
} user_base_config;
|
||||
|
||||
xmedia_s32 load_base_parameter(xmedia_char* ini_name, user_base_config * base_config);
|
||||
xmedia_s32 load_aivqe_parameter(xmedia_char* ini_name, ai_vqe_attr* vqe_config);
|
||||
xmedia_s32 load_aovqe_parameter(xmedia_char* ini_name, ao_vqe_attr* vqe_config);
|
||||
#endif
|
||||
@@ -0,0 +1,87 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 16000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 2
|
||||
# 输出声道数
|
||||
outchnnum = 2
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 160
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 16: vqe detect v1
|
||||
vqe_version = 16
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
#目前bcd只支持sampleRate = 16000
|
||||
[BCD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
usr_mode = 1
|
||||
# 哭声概率,范围: [0, 100]
|
||||
alarm_threshold = 80
|
||||
# 冻结时间,范围: [0s, 120s]
|
||||
time_limit = 5
|
||||
# 激活次数,范围: [1, 5]
|
||||
time_limit_threshold_count = 3
|
||||
# 退出冻结噪声时间,范围: [0, 120]
|
||||
interval_time = 3
|
||||
|
||||
#目前GBD只支持sampleRate = 8000
|
||||
[GBD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
usr_mode = 1
|
||||
# 哭声概率,范围: [0, 100]
|
||||
alarm_threshold = 80
|
||||
# 冻结时间,范围: [0s, 120s]
|
||||
time_limit = 5
|
||||
# 激活次数,范围: [1, 5]
|
||||
time_limit_threshold_count = 1
|
||||
# 退出冻结噪声时间,范围: [0, 120]
|
||||
interval_time = 3
|
||||
|
||||
[SSL]
|
||||
# 使能模块 0: disable,1: enable,目前只支持2ch。inchnnum,outchnnum需要配置为2
|
||||
enable = 1
|
||||
# 麦克风间距,范围: [30mm, 150mm]
|
||||
mic_distance = 100
|
||||
# 灵敏度,范围:[0, 9]
|
||||
sensitivity_level = 5
|
||||
# 0表示线阵, 1表示环阵
|
||||
shape = 0
|
||||
|
||||
[VED]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 音量阈值,范围: [-80, 0]
|
||||
volume_threshold = 0
|
||||
# 突变使能检测使能标志,0:不使能,1:使能
|
||||
mutation_flag = 0
|
||||
# 快速突变阈值,范围: [10db, 80db]
|
||||
fast_change_threshold = 10
|
||||
# 平稳突变阈值,范围: [1db, 20db]
|
||||
slow_change_threshold = 2
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
@@ -0,0 +1,166 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 16000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 1
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 160
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 1
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
|
||||
[DEREVERB]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 去混响延时,范围:[5, 30]
|
||||
delay_offset = 6
|
||||
# 去混响延时偏移个数,范围:[3, 10]
|
||||
delay_count = 3
|
||||
|
||||
[VAD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 语音检测灵敏度,范围:[0, 9]
|
||||
sensitivity_level = 6
|
||||
|
||||
[WNS]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 降风噪等级,范围:[0, 4]
|
||||
suppress_level = 4
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,166 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 8000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 1
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 80
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 1
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
|
||||
[DEREVERB]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 去混响延时,范围:[5, 30]
|
||||
delay_offset = 6
|
||||
# 去混响延时偏移个数,范围:[3, 10]
|
||||
delay_count = 3
|
||||
|
||||
[VAD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 语音检测灵敏度,范围:[0, 9]
|
||||
sensitivity_level = 6
|
||||
|
||||
[WNS]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 降风噪等级,范围:[0, 4]
|
||||
suppress_level = 4
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,170 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 16000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 2
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 160
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 2
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
|
||||
[DEREVERB]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 去混响延时,范围:[5, 30]
|
||||
delay_offset = 6
|
||||
# 去混响延时偏移个数,范围:[3, 10]
|
||||
delay_count = 3
|
||||
|
||||
[VAD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 语音检测灵敏度,范围:[0, 9]
|
||||
sensitivity_level = 6
|
||||
|
||||
[BF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
|
||||
[WNS]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 降风噪等级,范围:[0, 4]
|
||||
suppress_level = 4
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,170 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 8000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 2
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 80
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 2
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
|
||||
[DEREVERB]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 去混响延时,范围:[5, 30]
|
||||
delay_offset = 6
|
||||
# 去混响延时偏移个数,范围:[3, 10]
|
||||
delay_count = 3
|
||||
|
||||
[VAD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 语音检测灵敏度,范围:[0, 9]
|
||||
sensitivity_level = 6
|
||||
|
||||
[BF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
|
||||
[WNS]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 降风噪等级,范围:[0, 4]
|
||||
suppress_level = 4
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,128 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 16000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 1
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 160
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2 3: vqe v2
|
||||
vqe_version = 3
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,180 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 16000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 1
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms
|
||||
frameSample = 160
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 1
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 舒适噪声开关, 0 : disable 1 : enable
|
||||
cng_enable = 1
|
||||
# 高低频分频点, range : [1500, 3800]
|
||||
freq_boundary = 1800
|
||||
# 低频回声消除等级, range : [0, 9]
|
||||
low_suppress_level = 7
|
||||
# 高频回声消除等级, range : [0, 9]
|
||||
high_suppress_level = 5
|
||||
# 低频语音保护等级, range : [0, 9]
|
||||
low_enhance_voice_protect_level = 0
|
||||
# 高频语音保护等级, range : [0, 9]
|
||||
high_enhance_voice_protect_level = 0
|
||||
|
||||
[DEREVERB]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 去混响延时,范围:[5, 30]
|
||||
delay_offset = 6
|
||||
# 去混响延时偏移个数,范围:[3, 10]
|
||||
delay_count = 3
|
||||
|
||||
[VAD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 语音检测灵敏度,范围:[0, 9]
|
||||
sensitivity_level = 6
|
||||
|
||||
[WNS]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 降风噪等级,范围:[0, 4]
|
||||
suppress_level = 4
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,180 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 8000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 1
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 80
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 1
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 舒适噪声开关, 0 : disable 1 : enable
|
||||
cng_enable = 1
|
||||
# 高低频分频点, range : [1500, 3800]
|
||||
freq_boundary = 1800
|
||||
# 低频回声消除等级, range : [0, 9]
|
||||
low_suppress_level = 7
|
||||
# 高频回声消除等级, range : [0, 9]
|
||||
high_suppress_level = 5
|
||||
# 低频语音保护等级, range : [0, 9]
|
||||
low_enhance_voice_protect_level = 0
|
||||
# 高频语音保护等级, range : [0, 9]
|
||||
high_enhance_voice_protect_level = 0
|
||||
|
||||
[DEREVERB]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 去混响延时,范围:[5, 30]
|
||||
delay_offset = 6
|
||||
# 去混响延时偏移个数,范围:[3, 10]
|
||||
delay_count = 3
|
||||
|
||||
[VAD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 语音检测灵敏度,范围:[0, 9]
|
||||
sensitivity_level = 6
|
||||
|
||||
[WNS]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 降风噪等级,范围:[0, 4]
|
||||
suppress_level = 4
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,184 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 16000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 2
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 160
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 2
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 舒适噪声开关, 0 : disable 1 : enable
|
||||
cng_enable = 1
|
||||
# 高低频分频点, range : [1500, 3800]
|
||||
freq_boundary = 1800
|
||||
# 低频回声消除等级, range : [0, 9]
|
||||
low_suppress_level = 7
|
||||
# 高频回声消除等级, range : [0, 9]
|
||||
high_suppress_level = 5
|
||||
# 低频语音保护等级, range : [0, 9]
|
||||
low_enhance_voice_protect_level = 0
|
||||
# 高频语音保护等级, range : [0, 9]
|
||||
high_enhance_voice_protect_level = 0
|
||||
|
||||
[DEREVERB]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 去混响延时,范围:[5, 30]
|
||||
delay_offset = 6
|
||||
# 去混响延时偏移个数,范围:[3, 10]
|
||||
delay_count = 3
|
||||
|
||||
[VAD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 语音检测灵敏度,范围:[0, 9]
|
||||
sensitivity_level = 6
|
||||
|
||||
[BF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
|
||||
[WNS]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 降风噪等级,范围:[0, 4]
|
||||
suppress_level = 4
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,184 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 8000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 2
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 80
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 2
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 舒适噪声开关, 0 : disable 1 : enable
|
||||
cng_enable = 1
|
||||
# 高低频分频点, range : [1500, 3800]
|
||||
freq_boundary = 1800
|
||||
# 低频回声消除等级, range : [0, 9]
|
||||
low_suppress_level = 7
|
||||
# 高频回声消除等级, range : [0, 9]
|
||||
high_suppress_level = 5
|
||||
# 低频语音保护等级, range : [0, 9]
|
||||
low_enhance_voice_protect_level = 0
|
||||
# 高频语音保护等级, range : [0, 9]
|
||||
high_enhance_voice_protect_level = 0
|
||||
|
||||
[DEREVERB]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 去混响延时,范围:[5, 30]
|
||||
delay_offset = 6
|
||||
# 去混响延时偏移个数,范围:[3, 10]
|
||||
delay_count = 3
|
||||
|
||||
[VAD]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 语音检测灵敏度,范围:[0, 9]
|
||||
sensitivity_level = 6
|
||||
|
||||
[BF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
|
||||
[WNS]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 降风噪等级,范围:[0, 4]
|
||||
suppress_level = 4
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,140 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 16000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 1
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 160
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 1
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,140 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 8000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 1
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 80
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 1
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [5, 40]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,140 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 16000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 1
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 160
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 2
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [1, 10]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,140 @@
|
||||
#
|
||||
# this is a test config para file.
|
||||
# !!! This parameters only use to test!!!
|
||||
#
|
||||
[basic]
|
||||
# 工作采样率 8000 or 16000,默认:8000
|
||||
sampleRate = 8000
|
||||
# 输入声道数[1,2] 1 for vqe v1, 2 for vqe v2
|
||||
inchnnum = 1
|
||||
# 输出声道数
|
||||
outchnnum = 1
|
||||
# 数据帧长 10ms:160(8k)、 320(16k)
|
||||
frameSample = 80
|
||||
# AI/AO Buffer帧数
|
||||
frameNums = 30
|
||||
# vqe 算法版本 [1~n] 1: vqe v1 2: vqe v2
|
||||
vqe_version = 2
|
||||
|
||||
[volume]
|
||||
# 麦克风Codec输入增益 范围:[-95~48]
|
||||
codec_input_vol = 20
|
||||
# AI后级Vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ai_vol = 0
|
||||
# AO 后级vqe音量 范围:[-81~18],默认:0
|
||||
vqe_ao_vol = 0
|
||||
|
||||
[ANR]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 用户场景,0:正常场景,1:音乐场景
|
||||
usr_scene = 0
|
||||
# 降噪模式,0:语音模式,偏向于保语音,1:降噪模式,偏向于降噪
|
||||
nr_mode = 0
|
||||
# 最大噪声压制增益,范围: [1, 10]
|
||||
max_suppress_gain = 6
|
||||
# 平稳噪声降噪等级,范围: [0, 9]
|
||||
suppress_level = 2
|
||||
# 非平稳噪声降噪等级,范围 : [0, 9]
|
||||
nonstationary_suppress_level = 0
|
||||
|
||||
[AGC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0:自动模式,1: 用户模式,2:高级模式
|
||||
mode = 1
|
||||
# 目标电平 范围:[-20, -1],默认:-6
|
||||
target_level = -6
|
||||
# 最大增益 范围:[0, 30],默认:20
|
||||
max_boost_gain = 20
|
||||
# 噪声底线 范围:[-120, -25],默认:-100
|
||||
noise_floor = -100
|
||||
# 调整速度 范围:[1, 100],默认:8
|
||||
attack_time = 8
|
||||
# 释放速度 范围:[1, 100],默认:20
|
||||
release_time = 20
|
||||
# 噪声压制比率,范围: [1, 100], 默认:12
|
||||
ratio = 12
|
||||
|
||||
[AEC]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 0
|
||||
|
||||
[HPF]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# 模式选择 0--自动模式 1--用户模式
|
||||
mode = 1
|
||||
# 高通滤波截至频率 范围:[80/120/150]
|
||||
freq = 80
|
||||
|
||||
[EQ]
|
||||
# 使能模块 0: disable,1: enable
|
||||
enable = 1
|
||||
# EQ 频段调节,范围:[-50~20]
|
||||
# 分别对应频率点:60, 100, 150, 200, 250, 350, 500, 800, 1.2k, 1.6k, 2k,
|
||||
# 2.4k, 2.5k, 2.8k, 3.1k, 3.4k, 3.6k, 3.8k, 3.9k, 4k,
|
||||
# 4.5k, 5k, 5.5k, 6k, 6.5k, 7k, 7.3k, 7.6k, 7.8k, 8k,
|
||||
# 其中,4.5k以上频率点只有在采样率为16k才生效
|
||||
# Freq: 60Hz
|
||||
gain_0 = 0
|
||||
# Freq: 100Hz
|
||||
gain_1 = 0
|
||||
# Freq: 150Hz
|
||||
gain_2 = 0
|
||||
# Freq: 200Hz
|
||||
gain_3 = 0
|
||||
# Freq: 250Hz
|
||||
gain_4 = 0
|
||||
# Freq: 350Hz
|
||||
gain_5 = 0
|
||||
# Freq: 500Hz
|
||||
gain_6 = 0
|
||||
# Freq: 800Hz
|
||||
gain_7 = 0
|
||||
# Freq: 1200Hz
|
||||
gain_8 = 0
|
||||
# Freq: 1600Hz
|
||||
gain_9 = 0
|
||||
# Freq: 2000Hz
|
||||
gain_10 = 0
|
||||
# Freq: 2400Hz
|
||||
gain_11 = 0
|
||||
# Freq: 2500Hz
|
||||
gain_12 = 0
|
||||
# Freq: 2800Hz
|
||||
gain_13 = 0
|
||||
# Freq: 3100Hz
|
||||
gain_14 = 0
|
||||
# Freq: 3400Hz
|
||||
gain_15 = 0
|
||||
# Freq: 3600Hz
|
||||
gain_16 = 0
|
||||
# Freq: 3800Hz
|
||||
gain_17 = 0
|
||||
# Freq: 3900Hz
|
||||
gain_18 = 0
|
||||
# Freq: 4000Hz
|
||||
gain_19 = 0
|
||||
# Freq: 4500Hz
|
||||
gain_20 = 0
|
||||
# Freq: 5000Hz
|
||||
gain_21 = 0
|
||||
# Freq: 5500Hz
|
||||
gain_22 = 0
|
||||
# Freq: 6000Hz
|
||||
gain_23 = 0
|
||||
# Freq: 6500Hz
|
||||
gain_24 = 0
|
||||
# Freq: 7000Hz
|
||||
gain_25 = 0
|
||||
# Freq: 7300Hz
|
||||
gain_26 = 0
|
||||
# Freq: 7600Hz
|
||||
gain_27 = 0
|
||||
# Freq: 7800Hz
|
||||
gain_28 = 0
|
||||
# Freq: 8000Hz
|
||||
gain_29 = 0
|
||||
@@ -0,0 +1,47 @@
|
||||
ifeq ($(CFG_XMEDIA_EXPORT_FLAG),)
|
||||
SDK_DIR := $(shell cd $(CURDIR)/../../.. && /bin/pwd)
|
||||
endif
|
||||
|
||||
include $(SDK_DIR)/build/base.mk
|
||||
include $(SAMPLE_DIR)/sample_base.mk
|
||||
|
||||
LIBS := $(SAMPLE_LIBS) $(SAMPLE_COMMON_LIB)
|
||||
|
||||
SAMPLE_AUDIO_AI_TARGET := ./sample_record_board_record
|
||||
SAMPLE_AUDIO_DETECT_TARGET := ./sample_record_board_detect
|
||||
|
||||
INCLUDES += -I$(SDK_DIR)/sample/common
|
||||
INCLUDES += -I$(SDK_DIR)/source/gmp/include
|
||||
INCLUDES += -I$(SDK_DIR)/sample/audio/record_board/drv
|
||||
|
||||
SDK_USR_CFLAGS += $(SAMPLE_CFLAGS) $(LIBS) $(INCLUDES)
|
||||
|
||||
SAMPLE_AUDIO_AI_SRCS := ./sample_record_board_record.c
|
||||
SAMPLE_AUDIO_AI_SRCS += ./drv/drv_i2c.c
|
||||
SAMPLE_AUDIO_AI_SRCS += ./drv/drv_codec_es7210.c
|
||||
|
||||
SAMPLE_AUDIO_AI_OBJS := $(patsubst %.c, %.o, $(SAMPLE_AUDIO_AI_SRCS))
|
||||
|
||||
|
||||
SAMPLE_AUDIO_DETECT_SRCS := ./sample_record_board_detect.c
|
||||
SAMPLE_AUDIO_DETECT_SRCS += ./drv/drv_i2c.c
|
||||
SAMPLE_AUDIO_DETECT_SRCS += ./drv/drv_codec_es7210.c
|
||||
|
||||
SAMPLE_AUDIO_DETECT_OBJS := $(patsubst %.c, %.o, $(SAMPLE_AUDIO_DETECT_SRCS))
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: sample_record_board_record sample_record_board_detect
|
||||
|
||||
sample_record_board_record: $(SAMPLE_AUDIO_AI_OBJS)
|
||||
$(AT)$(CONFIG_XMEDIA_USR_ARM_TOOLCHAINS)-gcc -o $(SAMPLE_AUDIO_AI_TARGET) $^ $(SDK_USR_CFLAGS)
|
||||
|
||||
sample_record_board_detect: $(SAMPLE_AUDIO_DETECT_OBJS)
|
||||
$(AT)$(CONFIG_XMEDIA_USR_ARM_TOOLCHAINS)-gcc -o $(SAMPLE_AUDIO_DETECT_TARGET) $^ $(SDK_USR_CFLAGS)
|
||||
|
||||
%.o : %.c
|
||||
$(AT)$(CONFIG_XMEDIA_USR_ARM_TOOLCHAINS)-gcc -c -o $@ $< $(SDK_USR_CFLAGS)
|
||||
|
||||
clean:
|
||||
$(AT)rm -rf $(SAMPLE_AUDIO_AI_OBJS) $(SAMPLE_AUDIO_AI_TARGET)
|
||||
$(AT)rm -rf $(SAMPLE_AUDIO_DETECT_OBJS) $(SAMPLE_AUDIO_DETECT_TARGET)
|
||||
@@ -0,0 +1,27 @@
|
||||
GK7206V100 EVB 单板接线:
|
||||
|
||||
I2C使用I2C2,GPIO需要复用为I2C功能,代码已默认配置。
|
||||
I2S使用J2座子引出的。
|
||||
|
||||
I2C:
|
||||
|
||||
麦克风采集板 RBB单板
|
||||
J1座子 J6座子
|
||||
=========================================================
|
||||
GND ---------------------------------------- J6-20脚
|
||||
SCL ---------------------------------------- 需要飞线
|
||||
SDA ---------------------------------------- 需要飞线
|
||||
PWR ---------------------------------------- J6-1脚
|
||||
|
||||
I2S:
|
||||
|
||||
麦克风采集板 RBB单板
|
||||
J2座子 J2座子
|
||||
=========================================================
|
||||
BCLK ---- JTAG_TCK ---- SDIO1_CDATA1 ---- 3
|
||||
WS ---- JTAG_TMS ---- SDIO1_CDATA0 ---- 5
|
||||
RX ---- JTAG_TDO ---- SDIO1_CCMD ---- 7
|
||||
TX ---- JATG_TDI ---- SDIO1_CCLK ---- 8
|
||||
MCLK ---- JTAG_TRSTN ---- SDIO1_CDATA3 ---- 1
|
||||
|
||||
注意:I2S所有的地线必须接,否则有概率出现杂音。
|
||||
@@ -0,0 +1,549 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
|
||||
#include "drv_codec_es7210.h"
|
||||
#include "drv_i2c.h"
|
||||
|
||||
/** 寄存器 */
|
||||
#define RESET_CONTROL 0x00
|
||||
#define CLOCK_CONTROL 0x01
|
||||
#define MAIN_CLOCK_CONTROL 0x02
|
||||
#define MASTER_CLOCK_CONTROL 0x03
|
||||
#define MASTER_LRCK_DIV1 0x04
|
||||
#define MASTER_LRCK_DIV0 0x05
|
||||
#define POWER 0x06
|
||||
#define ADC_OSR_CFG 0x07
|
||||
#define MODE_CFG 0x08
|
||||
#define CHIP_INIT_TIME_CONTROL0 0x09
|
||||
#define CHIP_INIT_TIME_CONTROL1 0x0A
|
||||
#define CHIP_STATUS 0x0B
|
||||
#define CHIP_INTERRUPT_CONTROL 0x0C
|
||||
#define MISR_CONTROL 0x0D
|
||||
#define DMIC_CONTROL 0x10
|
||||
#define SDP_INTERFACE_CFG1 0x11
|
||||
#define SDP_INTERFACE_CFG2 0x12
|
||||
#define ADC12_CONTROL 0x15
|
||||
#define ADC34_CONTROL 0x14
|
||||
#define ALC_SELECT 0x16
|
||||
#define ALC_COMMON_CFG1 0x17
|
||||
#define ALC_COMMON_CFG2 0x1A
|
||||
#define ADC34_ALC_LEVEL 0x18
|
||||
#define ADC12_ALC_LEVEL 0x19
|
||||
#define ADC4_MAX_GAIN 0x1B
|
||||
#define ADC3_MAX_GAIN 0x1C
|
||||
#define ADC2_MAX_GAIN 0x1D
|
||||
#define ADC1_MAX_GAIN 0x1E
|
||||
#define ADC34_HPF2 0x20
|
||||
#define ADC34_HPF1 0x21
|
||||
#define ADC12_HPF1 0x22
|
||||
#define ADC12_HPF2 0x23
|
||||
#define CHIP_ID1 0x3D
|
||||
#define CHIP_ID0 0x3E
|
||||
#define CHIP_VERSION 0x3F
|
||||
#define CHIP_ANALOG_SYSTEM 0x40
|
||||
#define MIC12_BIAS 0x41
|
||||
#define MIC34_BIAS 0x42
|
||||
#define MIC1_GAIN 0x43
|
||||
#define MIC2_GAIN 0x44
|
||||
#define MIC3_GAIN 0x45
|
||||
#define MIC4_GAIN 0x46
|
||||
#define MIC1_LP 0x47
|
||||
#define MIC2_LP 0x48
|
||||
#define MIC3_LP 0x49
|
||||
#define MIC4_LP 0x4A
|
||||
#define MIC12_PD 0x4B
|
||||
#define MIC34_PD 0x4C
|
||||
|
||||
typedef enum MIC_GAIN {
|
||||
GAIN_0_DB = 0,
|
||||
GAIN_3_DB,
|
||||
GAIN_6_DB,
|
||||
GAIN_9_DB,
|
||||
GAIN_12_DB,
|
||||
GAIN_15_DB,
|
||||
GAIN_18_DB,
|
||||
GAIN_21_DB,
|
||||
GAIN_24_DB,
|
||||
GAIN_27_DB,
|
||||
GAIN_30_DB,
|
||||
GAIN_33_DB,
|
||||
GAIN_34_5_DB,
|
||||
GAIN_36_DB,
|
||||
GAIN_37_5_DB,
|
||||
} MIC_GAIN_E;
|
||||
|
||||
typedef struct {
|
||||
unsigned int ratio;
|
||||
unsigned char main_clock_control_value;
|
||||
unsigned char main_clock_control_double_speed_value;
|
||||
unsigned char adc_osr_cfg_value;
|
||||
} ES7210_MCLKFS_RATIO_CFG_S;
|
||||
|
||||
static const ES7210_MCLKFS_RATIO_CFG_S es7210_mclkfs_ratio_cfg[] = {
|
||||
//Ratio main_clock_control_v main_clock_control_ds_v adc_osr_cfg_v
|
||||
{64, 0x41, 0x01, 0x20}, // 512fs
|
||||
{128, 0x01, 0xC1, 0x20},
|
||||
{192, 0x43, 0x03, 0x20},
|
||||
{256, 0xC1, 0x81, 0x20},
|
||||
{384, 0x03, 0xC3, 0x20},
|
||||
{400, 0xC1, 0x81, 0x32}, // 800fs
|
||||
{512, 0x81, 0x82, 0x20},
|
||||
{600, 0x05, 0xC5, 0x1E}, // 480fs
|
||||
{768, 0xC3, 0x83, 0x20},
|
||||
{800, 0x81, 0x82, 0x32},
|
||||
{1024, 0x82, 0x84, 0x20},
|
||||
{1200, 0xC5, 0x85, 0x1E},
|
||||
{1500, 0x4F, 0x0F, 0x32},
|
||||
{1600, 0x82, 0x84, 0x32},
|
||||
{2048, 0x84, 0x88, 0x20},
|
||||
{2400, 0x85, 0x8A, 0x1E},
|
||||
{3000, 0x0F, 0xCF, 0x32},
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int i2c_fd;
|
||||
ES7210_CHIP_NUMBER_E chip_number;
|
||||
} codec_state_s;
|
||||
|
||||
|
||||
#define ES7210_MAX_GAIN (68)
|
||||
|
||||
#define BCLK_DIV(mclk, sr, ch, bw) (mclk / sr / ch / bw)
|
||||
|
||||
static int open_i2c_fd(ES7210_I2C_CFG_S i2c_cfg)
|
||||
{
|
||||
int ret;
|
||||
int i2c_fd;
|
||||
|
||||
i2c_fd = open(i2c_cfg.dev_node, O_RDWR);
|
||||
if (i2c_fd < 0) {
|
||||
printf("open %s failed\n", i2c_cfg.dev_node);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ioctl(i2c_fd, I2C_SLAVE, i2c_cfg.addr);
|
||||
if (ret != 0) {
|
||||
printf("set i2c slave addr(0x%x) failed\n", i2c_cfg.addr);
|
||||
return -1;
|
||||
}
|
||||
return i2c_fd;
|
||||
}
|
||||
|
||||
static int es7210_i2c_write(codec_handle *h_codec, unsigned int addr, unsigned int data)
|
||||
{
|
||||
int ret;
|
||||
unsigned char buf[2];
|
||||
|
||||
codec_state_s *state = (codec_state_s*)h_codec;
|
||||
|
||||
if (state->i2c_fd < 0) {
|
||||
printf("not init i2c fd\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf[0] = addr;
|
||||
buf[1] = data;
|
||||
|
||||
ret = write(state->i2c_fd, buf, 2);
|
||||
if (ret < 0) {
|
||||
printf("i2c fd: %d write addr 0x%x data 0x%x failed\n", state->i2c_fd, addr, data);
|
||||
return -1;
|
||||
}
|
||||
// printf("i2c fd: %d write addr 0x%x data 0x%x\n", state->i2c_fd, addr, data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void close_i2c_fd(int fd)
|
||||
{
|
||||
if (fd) {
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static int get_mclkfs_ratio_cfg(int ratio)
|
||||
{
|
||||
for (int i = 0; i < sizeof(es7210_mclkfs_ratio_cfg); i++) {
|
||||
if (es7210_mclkfs_ratio_cfg[i].ratio == ratio) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static unsigned int get_bit_width(ES7210_BIT_WIDTH_E bit_width)
|
||||
{
|
||||
unsigned int cur_bit_width;
|
||||
|
||||
switch (bit_width) {
|
||||
case ES7210_BIT_WIDTH_16:
|
||||
cur_bit_width = 16;
|
||||
break;
|
||||
case ES7210_BIT_WIDTH_18:
|
||||
cur_bit_width = 18;
|
||||
break;
|
||||
case ES7210_BIT_WIDTH_20:
|
||||
cur_bit_width = 20;
|
||||
break;
|
||||
case ES7210_BIT_WIDTH_24:
|
||||
cur_bit_width = 24;
|
||||
break;
|
||||
case ES7210_BIT_WIDTH_32:
|
||||
cur_bit_width = 32;
|
||||
break;
|
||||
default:
|
||||
cur_bit_width = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
return cur_bit_width;
|
||||
}
|
||||
|
||||
static int es7210_master_clk_ctl(codec_handle *handle, int mclk, unsigned int samplerate, unsigned int double_speed)
|
||||
{
|
||||
int index;
|
||||
unsigned int ratio = 0;
|
||||
|
||||
ratio = mclk / samplerate;
|
||||
|
||||
es7210_i2c_write(handle, MASTER_LRCK_DIV1, ((ratio >> 8) & 0xFF));
|
||||
es7210_i2c_write(handle, MASTER_LRCK_DIV0, (ratio & 0xFF));
|
||||
|
||||
index = get_mclkfs_ratio_cfg(ratio);
|
||||
if (index == -1) {
|
||||
printf("get mclkfs ratio failed\n");
|
||||
return -1;
|
||||
}
|
||||
es7210_i2c_write(handle, MAIN_CLOCK_CONTROL, es7210_mclkfs_ratio_cfg[index].main_clock_control_value);
|
||||
if (double_speed) {
|
||||
es7210_i2c_write(handle, MAIN_CLOCK_CONTROL, es7210_mclkfs_ratio_cfg[index].main_clock_control_double_speed_value);
|
||||
}
|
||||
es7210_i2c_write(handle, ADC_OSR_CFG, es7210_mclkfs_ratio_cfg[index].adc_osr_cfg_value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int check_parameters(ES7210_CODEC_CFG_S cfg)
|
||||
{
|
||||
if (cfg.vdda < ES7210_VDDA_1V8 && cfg.vdda > ES7210_VDDA_3V3) {
|
||||
printf("check para vdda config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.micbias < ES7210_MICBIAS_2V18 && cfg.micbias > ES7210_MICBIAS_2V87) {
|
||||
printf("check para micbiad config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.chip_number < ES7210_CHIP_NUMBER_0 && cfg.chip_number > ES7210_CHIP_NUMBER_3) {
|
||||
printf("check para chip_number config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.chip_flag < ES7210_LAST && cfg.chip_flag > ES7210_NO_LAST) {
|
||||
printf("check para chip_flag config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.i2s_cfg.mode != ES7210_SLAVER && cfg.i2s_cfg.mode != ES7210_MASTER) {
|
||||
printf("check para i2s_cfg.mode config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.i2s_cfg.format < ES7210_I2S_STD && cfg.i2s_cfg.format > ES7210_TDM_NLRCK_DSPB) {
|
||||
printf("check para i2s_cfg.format config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.i2s_cfg.mclk_source < ES7210_MCLK_SOURCE_DEFAULT && cfg.i2s_cfg.mclk_source > ES7210_MCLK_SOURCE_BCLK) {
|
||||
printf("check para i2s_cfg.mclk_source config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.i2s_cfg.bclk_inv_mode < ES7210_BCLK_NORMAL && cfg.i2s_cfg.bclk_inv_mode > ES7210_BCLK_INV) {
|
||||
printf("check para i2s_cfg.bclk_inv_mode config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.channels < ES7210_CHANNELS_2 && cfg.channels > ES7210_CHANNELS_16) {
|
||||
printf("check para channels config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.samplerate < ES7210_SAMPLE_RATE_8000 && cfg.samplerate > ES7210_SAMPLE_RATE_96000) {
|
||||
printf("check para samplerate config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg.bitwidth < ES7210_BIT_WIDTH_24 && cfg.bitwidth > ES7210_BIT_WIDTH_32) {
|
||||
printf("check para bitwidth config error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int es7210_init(codec_handle *h_codec, ES7210_CODEC_CFG_S *cfg)
|
||||
{
|
||||
int ret = -1;
|
||||
int fd = -1;
|
||||
unsigned int max_channel = 2;
|
||||
unsigned int double_speed = 0;
|
||||
unsigned int temp_value = 0x00;
|
||||
codec_state_s *state = NULL;
|
||||
|
||||
ES7210_CODEC_CFG_S *init_cfg = cfg;
|
||||
|
||||
ret = check_parameters(*init_cfg);
|
||||
if (ret < 0) {
|
||||
printf("check parameters failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
init_cfg->i2c_cfg.i2c_gpio_map_cb();
|
||||
init_cfg->i2s_cfg.i2s_gpio_map_cb();
|
||||
|
||||
fd = open_i2c_fd(init_cfg->i2c_cfg);
|
||||
if (fd < 0) {
|
||||
printf("open i2c failed. fd=%d\n", fd);
|
||||
return -1;
|
||||
}
|
||||
printf("get i2c fd: %d, success.\n", fd);
|
||||
|
||||
state = (codec_state_s*)malloc(sizeof(codec_state_s));
|
||||
if (state == NULL) {
|
||||
printf("malloc codec_state_s handle failed\n");
|
||||
return -1;
|
||||
}
|
||||
memset(state, 0x00, sizeof(codec_state_s));
|
||||
|
||||
state->i2c_fd = fd;
|
||||
state->chip_number = init_cfg->chip_flag;
|
||||
|
||||
*h_codec = state;
|
||||
|
||||
/* reset adc and power down */
|
||||
es7210_i2c_write(*h_codec, RESET_CONTROL, 0xff);
|
||||
/* reset adc and digital */
|
||||
es7210_i2c_write(*h_codec, RESET_CONTROL, 0x32);
|
||||
/* chip init period control */
|
||||
es7210_i2c_write(*h_codec, CHIP_INIT_TIME_CONTROL0, 0x20);
|
||||
es7210_i2c_write(*h_codec, CHIP_INIT_TIME_CONTROL1, 0x10);
|
||||
/* adc12 hpf */
|
||||
es7210_i2c_write(*h_codec, ADC12_HPF2, 0x2A);
|
||||
es7210_i2c_write(*h_codec, ADC12_HPF1, 0x0A | (init_cfg->track_mode.adc12 << 6));
|
||||
/* adc34 hpf */
|
||||
es7210_i2c_write(*h_codec, ADC34_HPF1, 0x2A);
|
||||
es7210_i2c_write(*h_codec, ADC34_HPF2, 0x0A | (init_cfg->track_mode.adc34 << 6));
|
||||
|
||||
/* Mode Config */
|
||||
/** 超过48K采样率,必须使能DoubleSpeed才能工作 */
|
||||
if (init_cfg->samplerate > ES7210_SAMPLE_RATE_48000) {
|
||||
double_speed = 1;
|
||||
}
|
||||
/** TDM模式下,使用倍频LRCK,才需要配置,其他模式下默认为2即可 */
|
||||
if (init_cfg->i2s_cfg.format >= ES7210_TDM_NLRCK_I2S) {
|
||||
max_channel = init_cfg->channels;
|
||||
}
|
||||
temp_value = (max_channel << 3) + (init_cfg->i2s_cfg.bclk_inv_mode << 3) + 0x04 + (double_speed << 1) + init_cfg->i2s_cfg.mode;
|
||||
es7210_i2c_write(*h_codec, MODE_CFG, temp_value);
|
||||
|
||||
/* SDP Interface Config */
|
||||
switch (init_cfg->i2s_cfg.format) {
|
||||
case ES7210_I2S_STD:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x00);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x00);
|
||||
break;
|
||||
case ES7210_I2S_LJ:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x01);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x00);
|
||||
break;
|
||||
case ES7210_DSPA:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x03);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x00);
|
||||
break;
|
||||
case ES7210_DSPB:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x23);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x00);
|
||||
break;
|
||||
case ES7210_TDM_NLRCK_I2S:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x00);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x03);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, (init_cfg->chip_flag << 2) + 0x03);
|
||||
break;
|
||||
case ES7210_TDM_NLRCK_LJ:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x01);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x03);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, (init_cfg->chip_flag << 2) + 0x03);
|
||||
break;
|
||||
case ES7210_TDM_NLRCK_DSPA:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x03);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x03);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, (init_cfg->chip_flag << 2) + 0x03);
|
||||
break;
|
||||
case ES7210_TDM_NLRCK_DSPB:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x23);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x03);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, (init_cfg->chip_flag << 2) + 0x03);
|
||||
break;
|
||||
case ES7210_TDM_I2S:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x00);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x02);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, (init_cfg->chip_flag << 2) + 0x02);
|
||||
break;
|
||||
case ES7210_TDM_LJ:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x01);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x02);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, (init_cfg->chip_flag << 2) + 0x02);
|
||||
break;
|
||||
case ES7210_TDM_DSPA:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x03);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x01);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, (init_cfg->chip_flag << 2) + 0x01);
|
||||
break;
|
||||
case ES7210_TDM_DSPB:
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG1, (init_cfg->bitwidth << 5) + 0x23);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, 0x01);
|
||||
es7210_i2c_write(*h_codec, SDP_INTERFACE_CFG2, (init_cfg->chip_flag << 2) + 0x01);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* analog sysytem */
|
||||
es7210_i2c_write(*h_codec, CHIP_ANALOG_SYSTEM, 0xC3 - (init_cfg->vdda << 5) + (0x0C * init_cfg->vdda));
|
||||
|
||||
/* adc control */
|
||||
es7210_i2c_write(*h_codec, ADC34_CONTROL, 0x3C);
|
||||
es7210_i2c_write(*h_codec, ADC12_CONTROL, 0x3C);
|
||||
|
||||
/* alc common config 1 */
|
||||
es7210_i2c_write(*h_codec, ALC_COMMON_CFG1, 0x00); // 0.25dB/2LRCK
|
||||
|
||||
/* mic bias config */
|
||||
es7210_i2c_write(*h_codec, MIC12_BIAS, (init_cfg->micbias << 4));
|
||||
es7210_i2c_write(*h_codec, MIC34_BIAS, (init_cfg->micbias << 4));
|
||||
|
||||
/* mic low power, set PGA low power */
|
||||
es7210_i2c_write(*h_codec, MIC1_LP, 0x08);
|
||||
es7210_i2c_write(*h_codec, MIC2_LP, 0x08);
|
||||
es7210_i2c_write(*h_codec, MIC3_LP, 0x08);
|
||||
es7210_i2c_write(*h_codec, MIC4_LP, 0x08);
|
||||
|
||||
/* default ADC PGA Gain = 10dB */
|
||||
es7210_i2c_write(*h_codec, MIC1_GAIN, 0x1A);
|
||||
es7210_i2c_write(*h_codec, MIC2_GAIN, 0x1A);
|
||||
es7210_i2c_write(*h_codec, MIC3_GAIN, 0x1A);
|
||||
es7210_i2c_write(*h_codec, MIC4_GAIN, 0x1A);
|
||||
|
||||
/* default ADC Gain = 0dB */
|
||||
es7210_i2c_write(*h_codec, ADC4_MAX_GAIN, 0xBF);
|
||||
es7210_i2c_write(*h_codec, ADC3_MAX_GAIN, 0xBF);
|
||||
es7210_i2c_write(*h_codec, ADC2_MAX_GAIN, 0xBF);
|
||||
es7210_i2c_write(*h_codec, ADC1_MAX_GAIN, 0xBF);
|
||||
|
||||
/* BLCK DIV */
|
||||
temp_value = BCLK_DIV(init_cfg->i2s_cfg.mclk, init_cfg->samplerate, (init_cfg->channels * 2), get_bit_width(init_cfg->bitwidth));
|
||||
if (temp_value > 127) {
|
||||
printf("BCLK DIV is too lager. div=%d\n", temp_value);
|
||||
goto EXIT;
|
||||
}
|
||||
printf("mclk: %d, sr: %d, ch: %d, bw: %d, div: %d(0x%x)\n",
|
||||
init_cfg->i2s_cfg.mclk, init_cfg->samplerate, init_cfg->channels, get_bit_width(init_cfg->bitwidth), temp_value, temp_value);
|
||||
es7210_i2c_write(*h_codec, MASTER_CLOCK_CONTROL, temp_value);
|
||||
|
||||
/* power on */
|
||||
es7210_i2c_write(*h_codec, POWER, 0x00);
|
||||
|
||||
if (init_cfg->i2s_cfg.mode == ES7210_MASTER) {
|
||||
/* master mode config clk div */
|
||||
es7210_master_clk_ctl(*h_codec, init_cfg->i2s_cfg.mclk, init_cfg->samplerate, double_speed);
|
||||
}
|
||||
|
||||
// /* mic power down */
|
||||
es7210_i2c_write(*h_codec, MIC12_PD, 0x0F);
|
||||
es7210_i2c_write(*h_codec, MIC34_PD, 0x0F);
|
||||
|
||||
if (init_cfg->i2s_cfg.mode == ES7210_MASTER) {
|
||||
es7210_i2c_write(*h_codec, CLOCK_CONTROL, 0x40);
|
||||
es7210_i2c_write(*h_codec, RESET_CONTROL, 0x71);
|
||||
es7210_i2c_write(*h_codec, RESET_CONTROL, 0x01);
|
||||
es7210_i2c_write(*h_codec, MODE_CFG,
|
||||
(init_cfg->channels << 3) + (init_cfg->i2s_cfg.bclk_inv_mode << 3) + 0x04 + (double_speed << 1) + init_cfg->i2s_cfg.mode);
|
||||
}
|
||||
|
||||
if (init_cfg->i2s_cfg.mode == ES7210_SLAVER) {
|
||||
es7210_i2c_write(*h_codec, RESET_CONTROL, 0x71);
|
||||
es7210_i2c_write(*h_codec, RESET_CONTROL, 0x41);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
EXIT:
|
||||
free(state);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int es7210_deinit(codec_handle *h_codec)
|
||||
{
|
||||
codec_state_s *state = (codec_state_s*)h_codec;
|
||||
|
||||
if (state == NULL) {
|
||||
printf("codec handle is NULL, don't deinit\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
close_i2c_fd(state->i2c_fd);
|
||||
|
||||
memset(state, 0x00, sizeof(codec_state_s));
|
||||
free(state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int es7210_set_volume(codec_handle *h_codec, unsigned int vol)
|
||||
{
|
||||
unsigned int pga_gain = 0;
|
||||
unsigned int adc_gain = 0;
|
||||
|
||||
if (!h_codec) {
|
||||
printf("handle is not init\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vol < 0 && vol > ES7210_MAX_GAIN) {
|
||||
printf("set volume value error\n");
|
||||
return -1;
|
||||
}
|
||||
#if 1
|
||||
if (vol > 36) {
|
||||
pga_gain = 36;
|
||||
adc_gain = vol - 36;
|
||||
} else {
|
||||
pga_gain = vol;
|
||||
}
|
||||
#else
|
||||
if (vol >= 18) {
|
||||
pga_gain = 18;
|
||||
adc_gain = vol - 18;
|
||||
} else {
|
||||
pga_gain = vol;
|
||||
}
|
||||
#endif
|
||||
es7210_i2c_write(h_codec, MIC1_GAIN, 0x10 + (pga_gain / 3));
|
||||
es7210_i2c_write(h_codec, MIC2_GAIN, 0x10 + (pga_gain / 3));
|
||||
es7210_i2c_write(h_codec, MIC3_GAIN, 0x10 + (pga_gain / 3));
|
||||
es7210_i2c_write(h_codec, MIC4_GAIN, 0x10 + (pga_gain / 3));
|
||||
|
||||
/** ADC Gain Step 0.5dB, range: [-95.5, 32]: [0x00, 0xFF], 0xBF=0dB*/
|
||||
es7210_i2c_write(h_codec, ADC4_MAX_GAIN, 0xBF + (adc_gain << 1));
|
||||
es7210_i2c_write(h_codec, ADC3_MAX_GAIN, 0xBF + (adc_gain << 1));
|
||||
es7210_i2c_write(h_codec, ADC2_MAX_GAIN, 0xBF + (adc_gain << 1));
|
||||
es7210_i2c_write(h_codec, ADC1_MAX_GAIN, 0xBF + (adc_gain << 1));
|
||||
|
||||
printf("set es7210 vol(%d) success\n", vol);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
#ifndef __DRV_CODEC_ES7210_H__
|
||||
#define __DRV_CODEC_ES7210_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
typedef void *codec_handle;
|
||||
typedef void (*fn_i2c_gpio_map_cb)(void);
|
||||
typedef void (*fn_i2s_gpio_map_cb)(void);
|
||||
|
||||
typedef enum ES7210_CHANNEL_E {
|
||||
ES7210_CHANNELS_2 = 2,
|
||||
ES7210_CHANNELS_4 = 4,
|
||||
ES7210_CHANNELS_6 = 6,
|
||||
ES7210_CHANNELS_8 = 8,
|
||||
ES7210_CHANNELS_10 = 10,
|
||||
ES7210_CHANNELS_12 = 12,
|
||||
ES7210_CHANNELS_14 = 14,
|
||||
ES7210_CHANNELS_16 = 16,
|
||||
} ES7210_CHANNEL_E;
|
||||
|
||||
typedef enum ES7210_TRACK_MODE_E {
|
||||
ES7210_TRACK_NORMAL = 0,
|
||||
ES7210_TRACK_BOTH_LEFT,
|
||||
ES7210_TRACK_BOTH_RIGHT,
|
||||
ES7210_TRACK_EXCHANGE,
|
||||
} ES7210_TRACK_MODE_E;
|
||||
|
||||
typedef enum ES7210_SAMPLE_RATE_E {
|
||||
ES7210_SAMPLE_RATE_8000 = 8000,
|
||||
ES7210_SAMPLE_RATE_12000 = 12000,
|
||||
ES7210_SAMPLE_RATE_11025 = 11025,
|
||||
ES7210_SAMPLE_RATE_16000 = 16000,
|
||||
ES7210_SAMPLE_RATE_22050 = 22050,
|
||||
ES7210_SAMPLE_RATE_24000 = 24000,
|
||||
ES7210_SAMPLE_RATE_32000 = 32000,
|
||||
ES7210_SAMPLE_RATE_44100 = 44100,
|
||||
ES7210_SAMPLE_RATE_48000 = 48000,
|
||||
ES7210_SAMPLE_RATE_64000 = 64000,
|
||||
ES7210_SAMPLE_RATE_96000 = 96000,
|
||||
} ES7210_SAMPLE_RATE_E;
|
||||
|
||||
typedef enum ES7210_BIT_WIDTH_E {
|
||||
ES7210_BIT_WIDTH_24 = 0,
|
||||
ES7210_BIT_WIDTH_20 = 1,
|
||||
ES7210_BIT_WIDTH_18 = 2,
|
||||
ES7210_BIT_WIDTH_16 = 3,
|
||||
ES7210_BIT_WIDTH_32 = 4,
|
||||
} ES7210_BIT_WIDTH_E;
|
||||
|
||||
typedef enum ES7210_I2S_MODE_E {
|
||||
ES7210_SLAVER = 0,
|
||||
ES7210_MASTER = 1
|
||||
} ES7210_I2S_MODE_E;
|
||||
|
||||
typedef enum ES7210_I2S_FORMAT_E {
|
||||
ES7210_I2S_STD = 0, /** i2s standard mode, only transfer two channels data */
|
||||
ES7210_I2S_LJ, /** left justified mode, only transfer two channels data */
|
||||
ES7210_DSPA, /** pcm mode A */
|
||||
ES7210_DSPB, /** pcm mode B */
|
||||
ES7210_TDM_I2S, /** tdm i2s mode */
|
||||
ES7210_TDM_LJ, /** tdm left justified mode */
|
||||
ES7210_TDM_DSPA, /** tdm pcm mode A */
|
||||
ES7210_TDM_DSPB, /** tdm pcm mode B */
|
||||
ES7210_TDM_NLRCK_I2S,
|
||||
ES7210_TDM_NLRCK_LJ,
|
||||
ES7210_TDM_NLRCK_DSPA,
|
||||
ES7210_TDM_NLRCK_DSPB,
|
||||
} ES7210_I2S_FORMAT_E;
|
||||
|
||||
typedef enum ES7210_CHIPFLAG_E {
|
||||
ES7210_LAST = 0, /* TMD级联模式,最后一片codec */
|
||||
ES7210_NO_LAST, /* TMD级联模式,不是最后一片codec */
|
||||
} ES7210_CHIPFLAG_E;
|
||||
|
||||
typedef enum ES7210_CHIP_NUMBER_E {
|
||||
ES7210_CHIP_NUMBER_0 = 0,
|
||||
ES7210_CHIP_NUMBER_1,
|
||||
ES7210_CHIP_NUMBER_2,
|
||||
ES7210_CHIP_NUMBER_3,
|
||||
} ES7210_CHIP_NUMBER_E;
|
||||
|
||||
typedef enum ES7210_VDDA_E {
|
||||
ES7210_VDDA_3V3 = 0x00,
|
||||
ES7210_VDDA_1V8 = 0x01,
|
||||
} ES7210_VDDA_E;
|
||||
|
||||
typedef enum ES7210_VOL_TYPE_E {
|
||||
ES7210_PGA_VOL = 0,
|
||||
ES7210_ADC_VOL,
|
||||
} ES7210_VOL_TYPE_E;
|
||||
|
||||
typedef enum ES7210_MCLK_SOURCE_E {
|
||||
ES7210_MCLK_SOURCE_DEFAULT = 0,
|
||||
ES7210_MCLK_SOURCE_BCLK = 1,
|
||||
} ES7210_MCLK_SOURCE_E;
|
||||
|
||||
typedef enum ES7210_BCLK_INV_MODE_E {
|
||||
ES7210_BCLK_NORMAL = 0,
|
||||
ES7210_BCLK_INV = 1,
|
||||
} ES7210_BCLK_INV_MODE_E;
|
||||
|
||||
typedef enum ES7210_MICBIAS_E {
|
||||
ES7210_MICBIAS_2V18 = 0,
|
||||
ES7210_MICBIAS_2V26,
|
||||
ES7210_MICBIAS_2V36,
|
||||
ES7210_MICBIAS_2V45,
|
||||
ES7210_MICBIAS_2V55,
|
||||
ES7210_MICBIAS_2V66,
|
||||
ES7210_MICBIAS_2V78,
|
||||
ES7210_MICBIAS_2V87,
|
||||
} ES7210_MICBIAS_E;
|
||||
|
||||
typedef struct {
|
||||
ES7210_TRACK_MODE_E adc12;
|
||||
ES7210_TRACK_MODE_E adc34;
|
||||
} ES7210_TRACK_MODE_S;
|
||||
|
||||
|
||||
typedef struct {
|
||||
char dev_node[128]; /** i2c驱动节点描述符 */
|
||||
unsigned int addr; /** i2c地址 */
|
||||
fn_i2c_gpio_map_cb i2c_gpio_map_cb; /** i2c管脚映射回调函数 */
|
||||
} ES7210_I2C_CFG_S;
|
||||
|
||||
typedef struct {
|
||||
unsigned int mclk;
|
||||
ES7210_I2S_MODE_E mode; /** 主从模式配置 */
|
||||
ES7210_I2S_FORMAT_E format; /** 数据传输格式配置 */
|
||||
ES7210_MCLK_SOURCE_E mclk_source; /** MCLK时钟源 */
|
||||
ES7210_BCLK_INV_MODE_E bclk_inv_mode; /** BCLK极性是否反转 */
|
||||
fn_i2s_gpio_map_cb i2s_gpio_map_cb; /** i2s管脚映射回调函数 */
|
||||
} ES7210_I2S_CFG_S;
|
||||
|
||||
typedef struct {
|
||||
ES7210_VDDA_E vdda; /** vdda必须配置和io电压相等,否则会出现i2s读数据出错 */
|
||||
ES7210_MICBIAS_E micbias; /** 硅麦保持默认即可,驻极体麦克风根据硬件配置 */
|
||||
ES7210_CHIP_NUMBER_E chip_number; /** 芯片级联时配置芯片编号 */
|
||||
ES7210_CHIPFLAG_E chip_flag; /** 芯片级联时是否为最后一片 */
|
||||
|
||||
ES7210_I2C_CFG_S i2c_cfg; /** i2c 配置 */
|
||||
ES7210_I2S_CFG_S i2s_cfg; /** i2s 配置 */
|
||||
|
||||
ES7210_CHANNEL_E channels; /** 声道 */
|
||||
ES7210_SAMPLE_RATE_E samplerate; /** 采样率 */
|
||||
ES7210_BIT_WIDTH_E bitwidth; /** 位宽 */
|
||||
ES7210_TRACK_MODE_S track_mode; /** 声道模式 */
|
||||
} ES7210_CODEC_CFG_S;
|
||||
|
||||
int es7210_init(codec_handle *h_codec, ES7210_CODEC_CFG_S *cfg);
|
||||
int es7210_deinit(codec_handle *h_codec);
|
||||
int es7210_set_volume(codec_handle *h_codec, unsigned int vol);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
|
||||
#include "drv_i2c.h"
|
||||
|
||||
int i2c_write(int fd, unsigned int dev_addr, unsigned int reg_addr, unsigned char *data, int len)
|
||||
{
|
||||
int ret;
|
||||
unsigned char *wr_data = NULL;
|
||||
|
||||
ret = ioctl(fd, I2C_SLAVE, dev_addr);
|
||||
if (ret < 0) {
|
||||
printf("set i2c slave addr failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
wr_data = malloc(len + 1);
|
||||
if (!wr_data) {
|
||||
printf("malloc failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
wr_data[0] = reg_addr;
|
||||
memcpy(&wr_data[1], data, len);
|
||||
|
||||
ret = write(fd, wr_data, len+1);
|
||||
if (ret < 0) {
|
||||
printf("i2c write addr 0x%x failed\n", reg_addr);
|
||||
}
|
||||
|
||||
free(wr_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int i2c_read(int fd, unsigned int dev_addr, unsigned int reg_addr, unsigned char *val, int len)
|
||||
{
|
||||
int ret;
|
||||
unsigned char buf[1];
|
||||
|
||||
ret = ioctl(fd, I2C_SLAVE, dev_addr);
|
||||
if (ret < 0) {
|
||||
printf("set i2c slave addr failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf[0] = reg_addr;
|
||||
|
||||
ret = write(fd, buf, 1);
|
||||
if (ret < 0) {
|
||||
printf("write addr failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = read(fd, val, len);
|
||||
if (ret < 0) {
|
||||
printf("read value failed\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef __DRV_I2C_H__
|
||||
#define __DRV_I2C_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int i2c_write(int fd, unsigned int dev_addr, unsigned int reg_addr, unsigned char *data, int len);
|
||||
int i2c_read(int fd, unsigned int dev_addr, unsigned int reg_addr, unsigned char *val, int len);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
|
||||
#include "drv_led_ctl.h"
|
||||
#include "drv_i2c.h"
|
||||
|
||||
#define LP5864_DEV_I2C_NODE "/dev/i2c-0"
|
||||
|
||||
static int lp5864_i2c_write(unsigned int dev_addr, unsigned int reg_addr, unsigned int data)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
unsigned char buf[1] = { 0 };
|
||||
|
||||
fd = open(LP5864_DEV_I2C_NODE, O_RDWR);
|
||||
if (fd < 0) {
|
||||
printf("open %s failed\n", LP5864_DEV_I2C_NODE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf[0] = data;
|
||||
|
||||
ret = i2c_write(fd, dev_addr, reg_addr, buf, 1);
|
||||
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int lp5864_i2c_read(unsigned int dev_addr, unsigned int reg_addr, unsigned char *value)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
fd = open(LP5864_DEV_I2C_NODE, O_RDWR);
|
||||
if (fd < 0) {
|
||||
printf("open %s failed\n", LP5864_DEV_I2C_NODE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = i2c_read(fd, dev_addr, reg_addr, value, 1);
|
||||
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int lp5864_power(LP5864_POWER_E power)
|
||||
{
|
||||
return lp5864_i2c_write(LP5864_SLAVE_ADDR, LP5864_REG_CHIP_EN, power);
|
||||
}
|
||||
|
||||
int lp5864_set_mode(LP5864_MODE_E mode)
|
||||
{
|
||||
unsigned char value;
|
||||
lp5864_i2c_read(LP5864_SLAVE_ADDR, LP5864_REG_DEV_INIT, &value);
|
||||
|
||||
value = value & (mode << 1);
|
||||
|
||||
return lp5864_i2c_write(LP5864_SLAVE_ADDR, LP5864_REG_DEV_INIT, value);
|
||||
}
|
||||
|
||||
int lp5864_mode1_update_led(unsigned int led_number)
|
||||
{
|
||||
int i;
|
||||
unsigned int onoff_reg;
|
||||
|
||||
for (i = 0; i < LP5864_MAX_LEDS; i++) {
|
||||
lp5864_i2c_write(LP5864_SLAVE_ADDR_PWM, i, 0x00);
|
||||
}
|
||||
|
||||
onoff_reg = 71 - (0x12 * (led_number % 4) + (led_number / 4));
|
||||
|
||||
printf("lp5864 open led number: %d\n", onoff_reg);
|
||||
|
||||
return lp5864_i2c_write(LP5864_SLAVE_ADDR_PWM, onoff_reg, 0xff);
|
||||
}
|
||||
|
||||
void lp5864_model1_led_test(void)
|
||||
{
|
||||
int i;
|
||||
// one by one open led.
|
||||
for (i = 0; i < LP5864_MAX_LEDS; i++) {
|
||||
lp5864_i2c_write(LP5864_SLAVE_ADDR_PWM, i, 0xff);
|
||||
usleep(10000);
|
||||
}
|
||||
// close all leds.
|
||||
for (i = 0; i < LP5864_MAX_LEDS; i++) {
|
||||
lp5864_i2c_write(LP5864_SLAVE_ADDR_PWM, i, 0x00);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef __DRV_LED_CTL_H__
|
||||
#define __DRV_LED_CTL_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
typedef enum LP5864_POWER {
|
||||
POWER_UP = 0x01,
|
||||
POWER_DOWN = 0x00
|
||||
} LP5864_POWER_E;
|
||||
|
||||
|
||||
typedef enum LP5864_MODE {
|
||||
LP5864_MODE_1 = 0,
|
||||
LP5864_MODE_2 = 1,
|
||||
LP5864_MODE_3 = 2,
|
||||
} LP5864_MODE_E;
|
||||
|
||||
#define LP5864_MAX_LEDS 72
|
||||
/** lp5864 I2C addr */
|
||||
#define LP5864_SLAVE_ADDR 0x48
|
||||
#define LP5864_SLAVE_ADDR_PWM 0x4a
|
||||
/** lp5864 reg */
|
||||
#define LP5864_REG_CHIP_EN 0x00
|
||||
#define LP5864_REG_DEV_INIT 0x01
|
||||
#define LP5864_REG_DEV_CONFIG1 0x02
|
||||
#define LP5864_REG_DEV_CONFIG2 0x03
|
||||
#define LP5864_REG_DEV_CONFIG3 0x04
|
||||
#define LP5864_REG_GLOBAL_BRI 0x05
|
||||
#define LP5864_REG_GROUP0_BRI 0x06
|
||||
#define LP5864_REG_GPOUP1_BRI 0x07
|
||||
#define LP5864_REG_GROUP2_BRI 0x08
|
||||
#define LP5864_REG_RESET 0x9A
|
||||
|
||||
int lp5864_power(LP5864_POWER_E power);
|
||||
int lp5864_set_mode(LP5864_MODE_E mode);
|
||||
int lp5864_mode1_update_led(unsigned int led_number);
|
||||
void lp5864_model1_led_test(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,477 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_detect.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
|
||||
#include "drv_codec_es7210.h"
|
||||
#include "drv_i2c.h"
|
||||
|
||||
#define ES7210_CODEC_I2C_NODE "/dev/i2c-2"
|
||||
#define ES7210_CODEC_I2C_ADDR 0x40
|
||||
#define ES7210B_CODEC_I2C_ADDR 0x41
|
||||
static codec_handle g_h_codec;
|
||||
static xmedia_u32 mic_distance = 50;
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
#define CRY_ALARMLIMIT 80 // probability greater than which to count as one cry frame
|
||||
#define CRY_TIMELIMITCNT 3 // number of cry frame count as one cry event
|
||||
#define CRY_TIMELIMIT 5 // time interval to report cry event
|
||||
#define CRY_ALARMINTERVAL 3 // alarm interval time to unfreeze
|
||||
|
||||
#define GBD_TIMELIMIT 100 // time interval to report gbd event
|
||||
#define GBD_TIMELIMITCNT 1 // number of gbd frame count as one gbd event
|
||||
#define GBD_ALARMLIMIT 70 // probability greater than which to count as one gbd frame
|
||||
#define GBD_ALARMINTERVAL 3 // alarm interval time to unfreeze
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_s32 codec_input_vol;
|
||||
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static ai_vqe_attr_detect ai_detect_attr;
|
||||
static xmedia_u32 g_vqe_type;
|
||||
|
||||
static xmedia_void gpio_map_to_i2s(xmedia_void)
|
||||
{
|
||||
char cmds[128];
|
||||
|
||||
sprintf(cmds, "xmmm 0x100c0010 0x100b"); // I2S_MCLK
|
||||
system(cmds);
|
||||
sprintf(cmds, "xmmm 0x100c0000 0x100b"); // I2S_BCLK_TX
|
||||
system(cmds);
|
||||
sprintf(cmds, "xmmm 0x100c0004 0x100b"); // I2S_WS_TX
|
||||
system(cmds);
|
||||
sprintf(cmds, "xmmm 0x100c000c 0x100b"); // I2S_DATA_RX
|
||||
system(cmds);
|
||||
}
|
||||
|
||||
void gpio_map_to_i2c(void)
|
||||
{
|
||||
char cmds[128];
|
||||
|
||||
sprintf(cmds, "xmmm 0x11980014 0x1002");//I2C2_SCL
|
||||
system(cmds);
|
||||
sprintf(cmds, "xmmm 0x11980018 0x1002");//I2C2_SDA
|
||||
system(cmds);
|
||||
}
|
||||
|
||||
static xmedia_void es7210_config(xmedia_void)
|
||||
{
|
||||
ES7210_CODEC_CFG_S codec_cfg = {0};
|
||||
|
||||
strcpy(codec_cfg.i2c_cfg.dev_node, ES7210_CODEC_I2C_NODE);
|
||||
codec_cfg.i2c_cfg.addr = ES7210_CODEC_I2C_ADDR;
|
||||
codec_cfg.i2c_cfg.i2c_gpio_map_cb = (fn_i2c_gpio_map_cb)gpio_map_to_i2c;
|
||||
|
||||
codec_cfg.micbias = ES7210_MICBIAS_2V87;
|
||||
codec_cfg.vdda = ES7210_VDDA_3V3;
|
||||
codec_cfg.chip_flag = ES7210_LAST;
|
||||
codec_cfg.chip_flag = ES7210_CHIP_NUMBER_0;
|
||||
|
||||
codec_cfg.channels = ES7210_CHANNELS_2;
|
||||
codec_cfg.samplerate = g_user_input_args.sample_rate;
|
||||
codec_cfg.bitwidth = ES7210_BIT_WIDTH_16;
|
||||
|
||||
codec_cfg.track_mode.adc12 = ES7210_TRACK_NORMAL;
|
||||
codec_cfg.track_mode.adc34 = ES7210_TRACK_NORMAL;
|
||||
|
||||
codec_cfg.i2s_cfg.mode = ES7210_SLAVER;
|
||||
codec_cfg.i2s_cfg.format = ES7210_I2S_STD;
|
||||
codec_cfg.i2s_cfg.bclk_inv_mode = ES7210_BCLK_NORMAL;
|
||||
codec_cfg.i2s_cfg.mclk_source = ES7210_MCLK_SOURCE_DEFAULT;
|
||||
codec_cfg.i2s_cfg.i2s_gpio_map_cb = (fn_i2s_gpio_map_cb)gpio_map_to_i2s;
|
||||
switch (g_user_input_args.sample_rate) {
|
||||
case 8000:
|
||||
codec_cfg.i2s_cfg.mclk = 2048000;
|
||||
break;
|
||||
case 16000:
|
||||
codec_cfg.i2s_cfg.mclk = 4096000;
|
||||
break;
|
||||
case 32000:
|
||||
codec_cfg.i2s_cfg.mclk = 8192000;
|
||||
break;
|
||||
case 64000:
|
||||
codec_cfg.i2s_cfg.mclk = 8192000;
|
||||
break;
|
||||
case 48000:
|
||||
codec_cfg.i2s_cfg.mclk = 12288000;
|
||||
break;
|
||||
case 44100:
|
||||
codec_cfg.i2s_cfg.mclk = 11289600;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
es7210_init(&g_h_codec, &codec_cfg);
|
||||
es7210_set_volume(g_h_codec, 50);
|
||||
}
|
||||
|
||||
xmedia_void es7210_destroy(xmedia_void)
|
||||
{
|
||||
es7210_deinit(g_h_codec);
|
||||
}
|
||||
|
||||
static xmedia_s32 cry_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("cry callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 gbd_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("gbd callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ssl_callback(xmedia_void* attr, xmedia_s32 out)
|
||||
{
|
||||
static xmedia_s32 ssl_out = 0;
|
||||
static xmedia_s32 call_times = 0;
|
||||
call_times++;
|
||||
|
||||
if (ssl_out != out) {
|
||||
printf("attr(0x%x), call_times(%d), out_angle(%d)\n", (xmedia_u32)attr, call_times, out);
|
||||
}
|
||||
ssl_out = out;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ved_callback(xmedia_void* private, xmedia_bool is_event, xmedia_bool is_mutation, xmedia_s32 out_db)
|
||||
{
|
||||
if (is_event) {
|
||||
printf("volume event detect out_db = %d\n",out_db);
|
||||
}
|
||||
if (is_mutation) {
|
||||
printf("volume mutation detect out_db = %d\n", out_db);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_detect_attr(ai_vqe_attr* attr, xmedia_u32 sample_rate)
|
||||
{
|
||||
ai_vqe_attr_detect* detect_attr = &ai_detect_attr;
|
||||
|
||||
attr->version = AI_VQE_DETECT_ATTR_VERSION_1;
|
||||
attr->work_sample_rate = sample_rate;
|
||||
attr->in_channels = g_ai_config.dev_attr.channels;
|
||||
|
||||
if (g_vqe_type == 1) {
|
||||
detect_attr->mask =VQE_DETECT_MASK_BCD;
|
||||
} else if (g_vqe_type == 2) {
|
||||
if (attr->work_sample_rate == AUDIO_SAMPLE_RATE_16000) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
detect_attr->mask = VQE_DETECT_MASK_GBD;
|
||||
} else if (g_vqe_type == 3) {
|
||||
detect_attr->mask = VQE_DETECT_MASK_SSL;
|
||||
} else if (g_vqe_type == 4) {
|
||||
detect_attr->mask = VQE_DETECT_MASK_VED;
|
||||
} else if (g_vqe_type == 5) {
|
||||
detect_attr->mask = VQE_DETECT_MASK_BCD | VQE_DETECT_MASK_HPF | VQE_DETECT_MASK_VED | VQE_DETECT_MASK_SSL;
|
||||
}
|
||||
detect_attr->hpf_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->hpf_attr.freq = VQE_DETECT_HPF_FREQ_80;
|
||||
|
||||
detect_attr->bcd_attr.usr_mode = XMEDIA_TRUE;
|
||||
detect_attr->bcd_attr.bypass = XMEDIA_FALSE;
|
||||
detect_attr->bcd_attr.alarm_threshold = CRY_ALARMLIMIT;
|
||||
detect_attr->bcd_attr.time_limit = CRY_TIMELIMIT;
|
||||
detect_attr->bcd_attr.time_limit_threshold_count = CRY_TIMELIMITCNT;
|
||||
detect_attr->bcd_attr.interval_time = CRY_ALARMINTERVAL;
|
||||
/*just for npu bcd lib*/
|
||||
detect_attr->bcd_attr.bcd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr->bcd_attr.bcd_model.model_info.file.pathname = "../audio_xmm/bcd_neuron_network.xmm";
|
||||
detect_attr->bcd_attr.callback = (fn_bcd_callback)cry_callback;
|
||||
|
||||
detect_attr->ssl_attr.mic_distance = mic_distance;
|
||||
detect_attr->ssl_attr.shape = 0;
|
||||
detect_attr->ssl_attr.sensitivity_level = 5;
|
||||
detect_attr->ssl_attr.callback = (fn_detect_ssl_callback)ssl_callback;
|
||||
detect_attr->ssl_attr.private_data = (xmedia_void*)0x12345678;
|
||||
|
||||
detect_attr->ved_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->ved_attr.volume_threshold = -15;
|
||||
detect_attr->ved_attr.mutation_flag = 1;
|
||||
detect_attr->ved_attr.fast_change_threshold = 15;
|
||||
detect_attr->ved_attr.slow_change_threshold = 8;
|
||||
detect_attr->ved_attr.callback = (fn_detect_ved_callback)ved_callback;
|
||||
|
||||
detect_attr->gbd_attr.usr_mode = XMEDIA_TRUE;
|
||||
detect_attr->gbd_attr.bypass = XMEDIA_FALSE;
|
||||
detect_attr->gbd_attr.alarm_threshold = GBD_ALARMLIMIT;
|
||||
detect_attr->gbd_attr.time_limit = GBD_TIMELIMIT;
|
||||
detect_attr->gbd_attr.time_limit_threshold_count = GBD_TIMELIMITCNT;
|
||||
detect_attr->gbd_attr.interval_time = GBD_ALARMINTERVAL;
|
||||
/*just for npu gbd lib*/
|
||||
detect_attr->gbd_attr.gbd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr->gbd_attr.gbd_model.model_info.file.pathname = "../audio_xmm/gbd_neuron_network.xmm";
|
||||
detect_attr->gbd_attr.callback = (fn_detect_gbd_callback)gbd_callback;
|
||||
attr->attr = (xmedia_void*)&ai_detect_attr;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_I2S0;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_user_input_args.sample_rate / 1000;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.chn_attr.interleaved = XMEDIA_TRUE;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_FALSE;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.master = XMEDIA_TRUE;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.i2s_mode = AUDIO_I2S_STD_MODE;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.mclk_sel = AUDIO_I2S_MCLK_256_FS;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.bclk_sel = AUDIO_I2S_BCLK_4_DIV;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.pcm_sample_rise_edge = XMEDIA_TRUE;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.pcm_delay_cycle = AUDIO_I2S_PCM_1_DELAY;
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
ai_vqe_attr vqe_detect_attr;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
//开启检测算法
|
||||
if (g_vqe_type != 0) {
|
||||
load_ai_detect_attr(&vqe_detect_attr, g_user_input_args.sample_rate);
|
||||
ret = sample_comm_ai_register(ai_detect_attr.mask, vqe_detect_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
ret = sample_comm_detect_open(g_ai_config.dev, &vqe_detect_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_bcd_open");
|
||||
}
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_create_output_thread_to_file(&g_ai_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_output_thread_to_file");
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
CHECK_RET(ret, "sample_comm_ai_set_dev_param");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
ret = sample_comm_ai_destroy_output_thread_to_file(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_output_thread_to_file");
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_audio_record_detect(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ai vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ai vol\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'saXX' to set adc gain to xx dB\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v' ) {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'v') {
|
||||
ret = sample_comm_ai_get_volume(&g_ai_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'a') {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'a') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [samplerate] [usr_samplerate] [channels] [codec_input_vol] [outfile] [vqe_type] [mic_distance]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("dev_rate: dev samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("usr_rate: out file samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("dev_chn: dev chn cnt(1/2/8)\n");
|
||||
SAMPLE_AUDIO_DBG("out_file: pcm out file(.pcm)\n");
|
||||
SAMPLE_AUDIO_DBG("vqe_type: 0:not open detect, 1:open bcd, 2:open gbd, 3:open ssl, 4:open ved, 5:open bcd + ssl + ved\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 1 20 out.pcm 0\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 1 20 out.pcm 1\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 1 20 out.pcm 2\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 2 20 out.pcm 3 50\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 2 20 out.pcm 4\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 2 20 out.pcm 5\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc < 7) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->sample_rate = atoi(argv[1]);
|
||||
user_in_args->usr_sample_rate = atoi(argv[2]);
|
||||
user_in_args->channels = atoi(argv[3]);
|
||||
user_in_args->codec_input_vol = atoi(argv[4]);
|
||||
memcpy(user_in_args->output_file_name, argv[5], strlen(argv[5]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
g_vqe_type = atoi(argv[6]);
|
||||
if (g_vqe_type < 0 || g_vqe_type > 5) {
|
||||
printf("Invalid det_type:%d\n", g_vqe_type);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
mic_distance = atoi(argv[7]);
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" samplerate: %d\n", user_in_args->sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" user samplerate: %d\n", user_in_args->usr_sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" chnnels: %d\n", user_in_args->channels);
|
||||
SAMPLE_AUDIO_DBG(" codec_input_vol: %d\n", user_in_args->codec_input_vol);
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
es7210_config();
|
||||
|
||||
ret = sample_audio_record_detect();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_audio_record_vqev1 failed(0x%x)\n", ret);
|
||||
}
|
||||
es7210_destroy();
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,408 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
|
||||
#include "drv_codec_es7210.h"
|
||||
#include "drv_i2c.h"
|
||||
#include "drv_led_ctl.h"
|
||||
|
||||
#define ES7210_CODEC_I2C_NODE "/dev/i2c-2"
|
||||
#define ES7210_CODEC_I2C_ADDR 0x40
|
||||
#define ES7210B_CODEC_I2C_ADDR 0x41
|
||||
|
||||
static codec_handle g_h_codec;
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
ai_dev dev;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_bit_depth bit_depth;
|
||||
audio_channel channels;
|
||||
xmedia_s32 workmode;
|
||||
xmedia_u32 samples_per_frm;
|
||||
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
|
||||
static xmedia_s32 g_volume;
|
||||
|
||||
|
||||
static xmedia_void gpio_map_to_i2s(xmedia_void)
|
||||
{
|
||||
char cmds[128];
|
||||
|
||||
sprintf(cmds, "xmmm 0x100c0010 0x100b"); // I2S_MCLK
|
||||
system(cmds);
|
||||
sprintf(cmds, "xmmm 0x100c0000 0x100b"); // I2S_BCLK_TX
|
||||
system(cmds);
|
||||
sprintf(cmds, "xmmm 0x100c0004 0x100b"); // I2S_WS_TX
|
||||
system(cmds);
|
||||
sprintf(cmds, "xmmm 0x100c000c 0x100b"); // I2S_DATA_RX
|
||||
system(cmds);
|
||||
}
|
||||
|
||||
void gpio_map_to_i2c(void)
|
||||
{
|
||||
char cmds[128];
|
||||
|
||||
sprintf(cmds, "xmmm 0x11980014 0x1002");//I2C2_SCL
|
||||
system(cmds);
|
||||
sprintf(cmds, "xmmm 0x11980018 0x1002");//I2C2_SDA
|
||||
system(cmds);
|
||||
}
|
||||
|
||||
xmedia_void es7210b_config(xmedia_void)
|
||||
{
|
||||
ES7210_CODEC_CFG_S codec_cfg = {0};
|
||||
|
||||
strcpy(codec_cfg.i2c_cfg.dev_node, ES7210_CODEC_I2C_NODE);
|
||||
codec_cfg.i2c_cfg.addr = ES7210B_CODEC_I2C_ADDR;
|
||||
codec_cfg.i2c_cfg.i2c_gpio_map_cb = (fn_i2c_gpio_map_cb)gpio_map_to_i2c;
|
||||
|
||||
codec_cfg.micbias = ES7210_MICBIAS_2V87;
|
||||
codec_cfg.vdda = ES7210_VDDA_3V3;
|
||||
codec_cfg.chip_flag = ES7210_LAST;
|
||||
codec_cfg.chip_number = ES7210_CHIP_NUMBER_1;
|
||||
|
||||
codec_cfg.channels = ES7210_CHANNELS_4;
|
||||
codec_cfg.samplerate = g_user_input_args.sample_rate;
|
||||
codec_cfg.bitwidth = ES7210_BIT_WIDTH_16;
|
||||
|
||||
codec_cfg.track_mode.adc12 = ES7210_TRACK_NORMAL;
|
||||
codec_cfg.track_mode.adc34 = ES7210_TRACK_NORMAL;
|
||||
|
||||
codec_cfg.i2s_cfg.mode = ES7210_SLAVER;
|
||||
codec_cfg.i2s_cfg.format = ES7210_TDM_DSPA;
|
||||
codec_cfg.i2s_cfg.bclk_inv_mode = ES7210_BCLK_NORMAL;
|
||||
codec_cfg.i2s_cfg.mclk_source = ES7210_MCLK_SOURCE_DEFAULT;
|
||||
codec_cfg.i2s_cfg.i2s_gpio_map_cb = (fn_i2s_gpio_map_cb)gpio_map_to_i2s;
|
||||
switch (g_user_input_args.sample_rate) {
|
||||
case 8000:
|
||||
codec_cfg.i2s_cfg.mclk = 2048000;
|
||||
break;
|
||||
case 16000:
|
||||
codec_cfg.i2s_cfg.mclk = 4096000;
|
||||
break;
|
||||
case 32000:
|
||||
codec_cfg.i2s_cfg.mclk = 8192000;
|
||||
break;
|
||||
case 64000:
|
||||
codec_cfg.i2s_cfg.mclk = 8192000;
|
||||
break;
|
||||
case 48000:
|
||||
codec_cfg.i2s_cfg.mclk = 12288000;
|
||||
break;
|
||||
case 44100:
|
||||
codec_cfg.i2s_cfg.mclk = 11289600;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
es7210_init(&g_h_codec, &codec_cfg);
|
||||
es7210_set_volume(g_h_codec, g_volume);
|
||||
}
|
||||
|
||||
xmedia_void es7210_config(xmedia_void)
|
||||
{
|
||||
ES7210_CODEC_CFG_S codec_cfg = {0};
|
||||
|
||||
strcpy(codec_cfg.i2c_cfg.dev_node, ES7210_CODEC_I2C_NODE);
|
||||
codec_cfg.i2c_cfg.addr = ES7210_CODEC_I2C_ADDR;
|
||||
codec_cfg.i2c_cfg.i2c_gpio_map_cb = (fn_i2c_gpio_map_cb)gpio_map_to_i2c;
|
||||
|
||||
codec_cfg.micbias = ES7210_MICBIAS_2V87;
|
||||
codec_cfg.vdda = ES7210_VDDA_3V3;
|
||||
codec_cfg.chip_flag = ES7210_LAST;
|
||||
codec_cfg.chip_number = ES7210_CHIP_NUMBER_0;
|
||||
|
||||
codec_cfg.channels = ES7210_CHANNELS_2;
|
||||
codec_cfg.samplerate = g_user_input_args.sample_rate;
|
||||
codec_cfg.bitwidth = ES7210_BIT_WIDTH_16;
|
||||
|
||||
codec_cfg.track_mode.adc12 = ES7210_TRACK_NORMAL;
|
||||
codec_cfg.track_mode.adc34 = ES7210_TRACK_NORMAL;
|
||||
|
||||
codec_cfg.i2s_cfg.mode = ES7210_SLAVER;
|
||||
codec_cfg.i2s_cfg.format = ES7210_I2S_STD;
|
||||
codec_cfg.i2s_cfg.bclk_inv_mode = ES7210_BCLK_NORMAL;
|
||||
codec_cfg.i2s_cfg.mclk_source = ES7210_MCLK_SOURCE_DEFAULT;
|
||||
codec_cfg.i2s_cfg.i2s_gpio_map_cb = (fn_i2s_gpio_map_cb)gpio_map_to_i2s;
|
||||
switch (g_user_input_args.sample_rate) {
|
||||
case 8000:
|
||||
codec_cfg.i2s_cfg.mclk = 2048000;
|
||||
break;
|
||||
case 16000:
|
||||
codec_cfg.i2s_cfg.mclk = 4096000;
|
||||
break;
|
||||
case 32000:
|
||||
codec_cfg.i2s_cfg.mclk = 8192000;
|
||||
break;
|
||||
case 64000:
|
||||
codec_cfg.i2s_cfg.mclk = 8192000;
|
||||
break;
|
||||
case 48000:
|
||||
codec_cfg.i2s_cfg.mclk = 12288000;
|
||||
break;
|
||||
case 44100:
|
||||
codec_cfg.i2s_cfg.mclk = 11289600;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
es7210_init(&g_h_codec, &codec_cfg);
|
||||
es7210_set_volume(g_h_codec, g_volume);
|
||||
}
|
||||
|
||||
xmedia_void es7210_destroy(xmedia_void)
|
||||
{
|
||||
es7210_deinit(g_h_codec);
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = g_user_input_args.dev;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.bit_depth = g_user_input_args.bit_depth;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = g_user_input_args.samples_per_frm;
|
||||
g_ai_config.dev_attr.pcm_frame_num = 200;
|
||||
g_ai_config.dev_attr.mode = g_user_input_args.workmode;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.chn_attr.interleaved = XMEDIA_TRUE;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_FALSE;
|
||||
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.master = XMEDIA_TRUE;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.i2s_mode = AUDIO_I2S_STD_MODE;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.mclk_sel = AUDIO_I2S_MCLK_256_FS;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.bclk_sel = AUDIO_I2S_BCLK_4_DIV;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.pcm_sample_rise_edge = XMEDIA_TRUE;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.pcm_delay_cycle = AUDIO_I2S_PCM_1_DELAY;
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
ret = sample_comm_ai_create_output_thread_to_file(&g_ai_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_output_thread_to_file");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_ai_destroy_output_thread_to_file(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_output_thread_to_file");
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_audio_ai(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = xmedia_ai_init();
|
||||
CHECK_RET(ret, "xmedia_ai_init");
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ai vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ai vol\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'dso' to dump stream open\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'dsc' to dump stream close\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v') {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'v') {
|
||||
ret = sample_comm_ai_get_volume(&g_ai_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'd' && input_cmd[1] == 's' && input_cmd[2] == 'o') {
|
||||
system("echo setnode 1 > /proc/umap/ai");
|
||||
system("echo dump start > /proc/umap/ai");
|
||||
SAMPLE_AUDIO_DBG("\nSet dump orgin and ai post stream start\n");
|
||||
} else if (input_cmd[0] == 'd' && input_cmd[1] == 's' && input_cmd[2] == 'c') {
|
||||
system("echo dump stop > /proc/umap/ai");
|
||||
SAMPLE_AUDIO_DBG("\nSet dump stream stop \n");
|
||||
} else if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ERR_START_AI:
|
||||
sample_stop_ai();
|
||||
xmedia_ai_exit();
|
||||
CHECK_RET(ret, "xmedia_ai_exit");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [dev] [samplerate] [bit_depth] [channels] [outfile] [volume]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("dev: dev id\n");
|
||||
SAMPLE_AUDIO_DBG("samplerate: dev samplerate\n");
|
||||
SAMPLE_AUDIO_DBG("channels: dev chn cnt\n");
|
||||
SAMPLE_AUDIO_DBG("outfile: save file path\n");
|
||||
SAMPLE_AUDIO_DBG("volume: [0,68]\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG(" %s 0 8000 16 2 out.pcm 40\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 1 8000 16 4 out.pcm 40\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 1 16000 16 4 out.pcm 40\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
char file_name[128] = {0};
|
||||
xmedia_s32 i = 0;
|
||||
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 7) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->dev = atoi(argv[1]);
|
||||
user_in_args->sample_rate = atoi(argv[2]);
|
||||
user_in_args->usr_sample_rate = user_in_args->sample_rate;
|
||||
user_in_args->bit_depth = atoi(argv[3]);
|
||||
user_in_args->channels = atoi(argv[4]);
|
||||
user_in_args->workmode = 1;
|
||||
user_in_args->samples_per_frm = user_in_args->sample_rate / 100;
|
||||
g_volume = atoi(argv[6]);
|
||||
|
||||
memcpy(user_in_args->output_file_name, argv[5], strlen(argv[5]));
|
||||
if (strcmp(user_in_args->output_file_name, "null") == 0) {
|
||||
while (1) {
|
||||
memset(file_name, 0 , sizeof(file_name));
|
||||
if (user_in_args->sample_rate == 16000) {
|
||||
sprintf((void *)file_name,"audio_8ch_16k_file%d.pcm", i++);
|
||||
} else {
|
||||
sprintf((void *)file_name,"audio_8ch_8k_file%d.pcm", i++);
|
||||
}
|
||||
if (access(file_name, F_OK) == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
user_in_args->output_fd[0] = fopen(file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
} else {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" samplerate: %d\n", user_in_args->sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" bit_depth: %d\n", user_in_args->bit_depth);
|
||||
SAMPLE_AUDIO_DBG(" chnnels: %d\n", user_in_args->channels);
|
||||
SAMPLE_AUDIO_DBG(" workmode: %d\n", user_in_args->workmode);
|
||||
SAMPLE_AUDIO_DBG(" samples_per_frm: %d\n", user_in_args->samples_per_frm);
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
es7210_config();
|
||||
es7210_destroy();
|
||||
es7210b_config();
|
||||
es7210_destroy();
|
||||
|
||||
ret = sample_audio_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_auido_ai failed(0x%x)\n", ret);
|
||||
}
|
||||
user_args_deinit(&g_user_input_args);
|
||||
printf("exit sample ai\n");
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,739 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
#include "xmedia_audio_vqe_enhance_v3.h"
|
||||
#include "xmedia_audio_vqe_detect.h"
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define CRY_ALARMLIMIT 80 // probability greater than which to count as one cry frame
|
||||
#define CRY_TIMELIMITCNT 3 // number of cry frame count as one cry event
|
||||
#define CRY_TIMELIMIT 5 // time interval to report cry event
|
||||
#define CRY_ALARMINTERVAL 3 //alarm interval time to unfreeze
|
||||
|
||||
#define AI_DEFAULT_MIC_VOL 20
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
ai_dev dev;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_bit_depth bit_depth;
|
||||
audio_channel channels;
|
||||
xmedia_s32 workmode;
|
||||
xmedia_u32 samples_per_frm;
|
||||
xmedia_s32 codec_input_vol;
|
||||
xmedia_bool binder_mode;
|
||||
xmedia_bool share_mode_enable;
|
||||
|
||||
xmedia_u32 send_object;
|
||||
ao_dev send_object_dev;
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static sample_ao_config g_ao_config;
|
||||
static sample_aenc_config g_aenc_config;
|
||||
static ai_vqe_attr_v1 ai_vqev1_attr;
|
||||
static ai_vqe_attr_v2 ai_vqev2_attr;
|
||||
static ai_vqe_attr_v3 ai_vqev3_attr;
|
||||
static ai_vqe_attr_detect ai_detect_attr;
|
||||
static xmedia_u32 g_vqe_type;
|
||||
|
||||
static xmedia_s32 cry_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("cry callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ssl_callback(xmedia_void* attr, xmedia_s32 out)
|
||||
{
|
||||
static xmedia_s32 ssl_out = 0;
|
||||
static xmedia_s32 call_times = 0;
|
||||
call_times++;
|
||||
|
||||
if (ssl_out != out) {
|
||||
printf("attr(0x%x), call_times(%d), out_angle(%d)\n", (xmedia_u32)attr, call_times, out);
|
||||
}
|
||||
ssl_out = out;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ved_callback(xmedia_void* private, xmedia_bool is_event, xmedia_bool is_mutation, xmedia_s32 out_db)
|
||||
{
|
||||
if (is_event) {
|
||||
printf("volume event detect out_db = %d\n",out_db);
|
||||
}
|
||||
if (is_mutation) {
|
||||
printf("volume mutation detect out_db = %d\n", out_db);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_vqev1_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_v1 *vqev1_attr = &ai_vqev1_attr;
|
||||
|
||||
attr->version = AI_VQE_ENHANCE_ATTR_VERSION_1;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = 1;
|
||||
attr->attr = (xmedia_void*)&ai_vqev1_attr;
|
||||
vqev1_attr->mask = VQE_V1_MASK_AGC | VQE_V1_MASK_ANR | VQE_V1_MASK_HPF;
|
||||
|
||||
|
||||
vqev1_attr->agc_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->agc_attr.target_level = -6;
|
||||
vqev1_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev1_attr->agc_attr.noise_floor = -100;
|
||||
vqev1_attr->agc_attr.ratio = 12;
|
||||
vqev1_attr->agc_attr.attack_time = 8;
|
||||
vqev1_attr->agc_attr.release_time =20;
|
||||
|
||||
vqev1_attr->anr_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->anr_attr.usr_scene = VQE_V1_ANR_SCENE_NORMAL;
|
||||
vqev1_attr->anr_attr.nr_mode = VQE_V1_NR_MODE_SPEECH;
|
||||
vqev1_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev1_attr->anr_attr.suppress_level = 0x2;
|
||||
vqev1_attr->anr_attr.nonstationary_suppress_level = 0x0;
|
||||
|
||||
vqev1_attr->vad_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->vad_attr.sensitivity_level = 4;
|
||||
|
||||
vqev1_attr->hpf_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->hpf_attr.freq = VQE_V1_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev1_attr->eq_attr, 0, sizeof(vqe_eq_attr_v1));
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_vqev2_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_v2 *vqev2_attr = &ai_vqev2_attr;
|
||||
|
||||
attr->version = AI_VQE_ENHANCE_ATTR_VERSION_2;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = 2;
|
||||
attr->attr = (xmedia_void*)&ai_vqev2_attr;
|
||||
vqev2_attr->mask = VQE_V2_MASK_AGC | VQE_V2_MASK_ANR | VQE_V2_MASK_HPF | VQE_V2_MASK_BF;
|
||||
vqev2_attr->aec_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->aec_attr.cng_enable = XMEDIA_TRUE;
|
||||
vqev2_attr->aec_attr.freq_boundary = 1400;
|
||||
vqev2_attr->aec_attr.low_suppress_level = 0x1;
|
||||
vqev2_attr->aec_attr.high_suppress_level = 0x1;
|
||||
|
||||
vqev2_attr->agc_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->agc_attr.target_level = -6;
|
||||
vqev2_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev2_attr->agc_attr.noise_floor = -65;
|
||||
vqev2_attr->agc_attr.ratio = 10;
|
||||
vqev2_attr->agc_attr.attack_time = 20;
|
||||
vqev2_attr->agc_attr.release_time = 20;
|
||||
|
||||
vqev2_attr->anr_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->anr_attr.usr_scene = VQE_V2_ANR_SCENE_NORMAL;
|
||||
vqev2_attr->anr_attr.nr_mode = VQE_V2_NR_MODE_SPEECH;
|
||||
vqev2_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev2_attr->anr_attr.suppress_level = 0x2;
|
||||
vqev2_attr->anr_attr.nonstationary_suppress_level = 0x2;
|
||||
|
||||
vqev2_attr->bf_attr.reserved = 0;
|
||||
|
||||
vqev2_attr->hpf_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->hpf_attr.freq = VQE_V2_HPF_FREQ_80;
|
||||
|
||||
vqev2_attr->vad_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->vad_attr.sensitivity_level = 5;
|
||||
|
||||
memset(&vqev2_attr->eq_attr, 0, sizeof(vqe_eq_attr_v2));
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_vqev3_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_v3 *vqev3_attr = &ai_vqev3_attr;
|
||||
|
||||
attr->version = AI_VQE_ENHANCE_ATTR_VERSION_3;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = 2;
|
||||
attr->attr = (xmedia_void*)&ai_vqev3_attr;
|
||||
vqev3_attr->mask = VQE_V3_MASK_AGC | VQE_V3_MASK_ANR | VQE_V3_MASK_HPF | VQE_V3_MASK_EQ;
|
||||
|
||||
vqev3_attr->agc_attr.mode = VQE_V3_USR_MODE_AUTO;
|
||||
vqev3_attr->agc_attr.target_level = -6;
|
||||
vqev3_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev3_attr->agc_attr.noise_floor = -65;
|
||||
vqev3_attr->agc_attr.ratio = 10;
|
||||
vqev3_attr->agc_attr.attack_time = 20;
|
||||
vqev3_attr->agc_attr.release_time = 20;
|
||||
|
||||
vqev3_attr->anr_attr.mode = VQE_V3_USR_MODE_AUTO;
|
||||
vqev3_attr->anr_attr.level = 0;
|
||||
|
||||
vqev3_attr->hpf_attr.mode = VQE_V3_USR_MODE_AUTO;
|
||||
vqev3_attr->hpf_attr.freq = VQE_V3_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev3_attr->eq_attr, 0, sizeof(vqe_eq_attr_v3));
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_detect_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_detect* detect_attr = &ai_detect_attr;
|
||||
|
||||
attr->version = AI_VQE_DETECT_ATTR_VERSION_1;
|
||||
attr->work_sample_rate = AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = g_ai_config.dev_attr.channels;
|
||||
|
||||
detect_attr->mask = VQE_DETECT_MASK_HPF | VQE_DETECT_MASK_BCD | VQE_DETECT_MASK_VED;
|
||||
detect_attr->hpf_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->hpf_attr.freq = VQE_DETECT_HPF_FREQ_80;
|
||||
|
||||
detect_attr->bcd_attr.usr_mode = XMEDIA_TRUE;
|
||||
detect_attr->bcd_attr.bypass = XMEDIA_FALSE;
|
||||
detect_attr->bcd_attr.alarm_threshold = CRY_ALARMLIMIT;
|
||||
detect_attr->bcd_attr.time_limit = CRY_TIMELIMIT;
|
||||
detect_attr->bcd_attr.time_limit_threshold_count = CRY_TIMELIMITCNT;
|
||||
detect_attr->bcd_attr.interval_time = CRY_ALARMINTERVAL;
|
||||
detect_attr->bcd_attr.callback = (fn_bcd_callback)cry_callback;
|
||||
detect_attr->bcd_attr.bcd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr->bcd_attr.bcd_model.model_info.file.pathname = "./audio_xmm/bcd_neuron_network.xmm";
|
||||
|
||||
detect_attr->ssl_attr.mic_distance = 50;
|
||||
detect_attr->ssl_attr.sensitivity_level = 5;
|
||||
detect_attr->ssl_attr.shape = 0;
|
||||
detect_attr->ssl_attr.callback = (fn_detect_ssl_callback)ssl_callback;
|
||||
detect_attr->ssl_attr.private_data = (xmedia_void*)0x12345678;
|
||||
|
||||
detect_attr->ved_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->ved_attr.volume_threshold = -15;
|
||||
detect_attr->ved_attr.mutation_flag = 1;
|
||||
detect_attr->ved_attr.fast_change_threshold = 15;
|
||||
detect_attr->ved_attr.slow_change_threshold = 8;
|
||||
detect_attr->ved_attr.callback = (fn_detect_ved_callback)ved_callback;
|
||||
attr->attr = (xmedia_void*)&ai_detect_attr;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = g_user_input_args.dev;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.bit_depth = AUDIO_BIT_DEPTH_16;
|
||||
if (g_ai_config.dev_attr.sample_rate % AUDIO_SAMPLE_RATE_11025 == 0) {
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = 128 * (g_ai_config.dev_attr.sample_rate / AUDIO_SAMPLE_RATE_11025);
|
||||
} else {
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = g_ai_config.dev_attr.sample_rate / 100; // 10ms
|
||||
}
|
||||
g_ai_config.dev_attr.mode = g_user_input_args.workmode;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.chn_attr.interleaved = XMEDIA_TRUE;
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_PDM_I2S0) {
|
||||
g_ai_config.source = AI_EC_SOURCE_PDM_REF;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
} else {
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
}
|
||||
if (g_vqe_type == 1 || g_vqe_type == 3) {
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
load_ai_vqev1_attr(&g_ai_config.vqe_attr);
|
||||
} else if (g_vqe_type == 2) {
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
load_ai_vqev2_attr(&g_ai_config.vqe_attr);
|
||||
g_ai_config.vqe_attr.in_channels = g_ai_config.dev_attr.channels;
|
||||
} else if (g_vqe_type == 6) {
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
load_ai_vqev3_attr(&g_ai_config.vqe_attr);
|
||||
g_ai_config.vqe_attr.in_channels = g_ai_config.dev_attr.channels;
|
||||
} else {
|
||||
g_ai_config.vqe_enable = XMEDIA_FALSE;
|
||||
}
|
||||
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ai_config.vqe_enable && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_I2S0 && g_ai_config.dev_attr.channels == 16) {
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.i2s_mode = AUDIO_I2S_TDM_MODE;
|
||||
g_ai_config.dev_attr.un_attr.i2s_attr.bclk_sel = AUDIO_I2S_BCLK_1_DIV;
|
||||
}
|
||||
if (g_user_input_args.share_mode_enable) {
|
||||
g_ai_config.dev_attr.pcm_frame_num = 500;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ao_config_init(xmedia_void)
|
||||
{
|
||||
g_ao_config.dev = g_user_input_args.send_object_dev;
|
||||
|
||||
sample_comm_ao_get_default_attr(g_ao_config.dev, &g_ao_config.dev_attr);
|
||||
g_ao_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ao_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ao_config.dev_attr.bit_depth = AUDIO_BIT_DEPTH_16;
|
||||
g_ao_config.dev_attr.pcm_samples_per_frame = g_ai_config.dev_attr.pcm_samples_per_frame;
|
||||
g_ao_config.dev_attr.mode = g_user_input_args.workmode;
|
||||
|
||||
g_ao_config.vqe_enable = XMEDIA_FALSE;
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_ao_config.binder_src = MOD_ID_AI;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_aenc_config_init(xmedia_void)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.output_file_name, &type, &format);
|
||||
|
||||
g_aenc_config.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_aenc_config.channels = (g_vqe_type == 2 || g_vqe_type == 5 || g_ai_config.dev_attr.mode == AUDIO_DEV_WORK_MODE_MONO) ? 1 : g_user_input_args.channels; // ai open vqev2 or ai 1 channel
|
||||
g_aenc_config.bit_depth = AUDIO_BIT_DEPTH_16;
|
||||
g_aenc_config.chn = 0;
|
||||
g_aenc_config.type = type;
|
||||
g_aenc_config.format = format;
|
||||
g_aenc_config.binder_dev = g_user_input_args.dev;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_aenc_config.binder_src = MOD_ID_AI;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_s32 vol = AI_DEFAULT_MIC_VOL;
|
||||
ai_vqe_attr vqe_detect_attr;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
if (g_user_input_args.share_mode_enable) {
|
||||
ret = sample_comm_ai_set_share_mode(g_user_input_args.share_mode_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_set_share_mode");
|
||||
}
|
||||
|
||||
if (g_vqe_type == 1 || g_vqe_type == 3) {
|
||||
ret = sample_comm_ai_register(ai_vqev1_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
} else if (g_vqe_type == 2) {
|
||||
ret = sample_comm_ai_register(ai_vqev2_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
} else if (g_vqe_type == 6) {
|
||||
ret = sample_comm_ai_register(ai_vqev3_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
}else { //可能存在只有重采样场景
|
||||
if (g_ai_config.res_enable) {
|
||||
ret = sample_comm_ao_register(0, AI_VQE_ENHANCE_ATTR_VERSION_1, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
}
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_set_dev_param");
|
||||
}
|
||||
}
|
||||
|
||||
if (g_user_input_args.share_mode_enable) {
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
if (g_vqe_type == 3 || g_vqe_type == 4) {
|
||||
load_ai_detect_attr(&vqe_detect_attr);
|
||||
ret = sample_comm_ai_register(ai_detect_attr.mask, vqe_detect_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
ret = sample_comm_detect_open(g_ai_config.dev, &vqe_detect_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_bcd_open");
|
||||
}
|
||||
}
|
||||
|
||||
if (g_user_input_args.send_object == 0) {
|
||||
ret = sample_comm_ai_create_output_thread_to_file(&g_ai_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_output_thread_to_file");
|
||||
}
|
||||
|
||||
if ((g_user_input_args.send_object == 1) && (g_user_input_args.binder_mode == XMEDIA_FALSE)) {
|
||||
ret = sample_comm_ai_create_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_output_thread_to_aenc");
|
||||
}
|
||||
|
||||
if ((g_user_input_args.send_object == 2) && (g_user_input_args.binder_mode == XMEDIA_FALSE)) {
|
||||
ret = sample_comm_ai_create_output_thread_to_ao(&g_ai_config, g_user_input_args.send_object_dev, 0);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_output_thread_to_ao");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ao_config_init();
|
||||
CHECK_RET(ret, "sample_ao_config_init");
|
||||
|
||||
ret = sample_comm_ao_start(&g_ao_config);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_aenc_config_init();
|
||||
CHECK_RET(ret, "sample_aenc_config_init");
|
||||
|
||||
ret = sample_comm_aenc_register(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_aenc_start(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_start");
|
||||
|
||||
ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_data_thread");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
if (g_user_input_args.send_object == 0) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_file(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_output_thread_to_file");
|
||||
}
|
||||
|
||||
if ((g_user_input_args.send_object == 1) && (g_user_input_args.binder_mode == XMEDIA_FALSE)) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_output_thread_to_aenc");
|
||||
}
|
||||
|
||||
if ((g_user_input_args.send_object == 2) && (g_user_input_args.binder_mode == XMEDIA_FALSE)) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_ao(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_output_thread_to_ao");
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
if (g_user_input_args.share_mode_enable) {
|
||||
sample_comm_ai_set_share_mode(XMEDIA_FALSE);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_ao_stop(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_out_to_file_thread");
|
||||
|
||||
ret = sample_comm_aenc_stop(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_stop");
|
||||
|
||||
ret = sample_comm_aenc_unregister(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_aenc_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
xmedia_s32 sample_audio_ai(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
if (g_user_input_args.send_object == 2) {
|
||||
ret = sample_start_ao();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AO;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_user_input_args.send_object == 1) {
|
||||
ret = sample_start_aenc();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AENC;
|
||||
}
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ai vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ai vol\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'saXX' to set adc gain to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'ga' to get adc gain\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("Input 'se' to set ec source\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'eo' to enable org frame\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'do' to disable org frame\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'ee' to enable ec frame\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'de' to disable ec frame\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'dso' to dump stream open\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'dsc' to dump stream close\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'pow' to test suspend and resume\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v') {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'v') {
|
||||
ret = sample_comm_ai_get_volume(&g_ai_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'a') {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'a') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet adc gain %d return 0x%x\n", val, ret);
|
||||
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'e') {
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
ret = sample_comm_ai_set_ec_source(&g_ai_config);
|
||||
SAMPLE_AUDIO_DBG("\nSet ec source return 0x%x\n", ret);
|
||||
} else if (input_cmd[0] == 'e' && input_cmd[1] == 'o') {
|
||||
ret = sample_comm_ai_enable_org_frame(&g_ai_config, XMEDIA_TRUE);
|
||||
SAMPLE_AUDIO_DBG("\nSet enable org frame return 0x%x\n", ret);
|
||||
} else if (input_cmd[0] == 'd' && input_cmd[1] == 'o') {
|
||||
ret = sample_comm_ai_enable_org_frame(&g_ai_config, XMEDIA_FALSE);
|
||||
SAMPLE_AUDIO_DBG("\nSet disable org frame return 0x%x\n", ret);
|
||||
} else if (input_cmd[0] == 'e' && input_cmd[1] == 'e') {
|
||||
ret = sample_comm_ai_enable_ec_frame(&g_ai_config, XMEDIA_TRUE);
|
||||
SAMPLE_AUDIO_DBG("\nSet enable ec frame return 0x%x\n", ret);
|
||||
} else if (input_cmd[0] == 'd' && input_cmd[1] == 'e') {
|
||||
ret = sample_comm_ai_enable_ec_frame(&g_ai_config, XMEDIA_FALSE);
|
||||
SAMPLE_AUDIO_DBG("\nSet disable ec frame return 0x%x\n", ret);
|
||||
} else if (input_cmd[0] == 'd' && input_cmd[1] == 's' && input_cmd[2] == 'o') {
|
||||
system("echo setnode 1 > /proc/umap/ai");
|
||||
system("echo dump start > /proc/umap/ai");
|
||||
SAMPLE_AUDIO_DBG("\nSet dump orgin and ai post stream start\n");
|
||||
} else if (input_cmd[0] == 'd' && input_cmd[1] == 's' && input_cmd[2] == 'c') {
|
||||
system("echo dump stop > /proc/umap/ai");
|
||||
SAMPLE_AUDIO_DBG("\nSet dump stream stop \n");
|
||||
} else if (input_cmd[0] == 'p' && input_cmd[1] == 'o' && input_cmd[2] == 'w') {
|
||||
system("echo mem > /sys/power/state"); // 进入休眠状态 之后自动唤醒
|
||||
SAMPLE_AUDIO_DBG("\nSuspend and resume test ok\n");
|
||||
} else if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_user_input_args.send_object == 1) {
|
||||
sample_stop_aenc();
|
||||
}
|
||||
ERR_START_AENC:
|
||||
if (g_user_input_args.send_object == 2) {
|
||||
sample_stop_ao();
|
||||
}
|
||||
ERR_START_AO:
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [dev] [send_object] [binder_mode] [samplerate] [usr_samplerate] [channels] [workmode] [outfile/send_object_dev] [vqe_type/share_mode]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("dev: dev id\n");
|
||||
SAMPLE_AUDIO_DBG("send_object: 0:not send data and save ai file, 1:ai send data to aenc, 2:ai send data to ao\n");
|
||||
SAMPLE_AUDIO_DBG("binder_mode: use binder mode\n");
|
||||
SAMPLE_AUDIO_DBG("samplerate: dev samplerate\n");
|
||||
SAMPLE_AUDIO_DBG("usr_samplerate: ai user data samplerate\n");
|
||||
SAMPLE_AUDIO_DBG("channels: dev chn cnt\n");
|
||||
SAMPLE_AUDIO_DBG("workmode: mono:0, queue:1\n");
|
||||
SAMPLE_AUDIO_DBG("outfile/send_object_dev: ai out file or aenc encoder out file(.pcm/.g711a/.g711u/.g726/.aac/.mp3/.adpcm) or ao dev\n");
|
||||
SAMPLE_AUDIO_DBG("vqe_type/share_mode: 0: not open vqe, 1: open vqe v1, 2: open vqe v2, 3: open vqe v1 and detect, 4: open vqe detect, 5: open share mode, 6: open vqe v3\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG(" %s 0 1 1 8000 8000 1 1 out.g711a 1\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 0 2 1 8000 8000 1 1 0 1\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 0 0 0 8000 8000 2 1 out.pcm 2\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 0 0 0 16000 16000 1 1 out.pcm 3\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 0 0 0 16000 16000 1 1 out.pcm 4\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 0 0 0 8000 8000 2 1 out.pcm 5\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 0 0 0 16000 16000 1 1 out.pcm 6\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 10) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->dev = atoi(argv[1]);
|
||||
user_in_args->send_object = atoi(argv[2]);
|
||||
if (user_in_args->send_object == 0) {
|
||||
printf("ai not send data and save ai file\n");
|
||||
} else if (user_in_args->send_object == 1) {
|
||||
printf("ai send data to aenc\n");
|
||||
} else if (user_in_args->send_object == 2) {
|
||||
printf("ai send data to ao\n");
|
||||
} else {
|
||||
printf("Invalid send_object:%d\n", user_in_args->send_object);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
user_in_args->binder_mode = (atoi(argv[3]) == 0) ? XMEDIA_FALSE : XMEDIA_TRUE;
|
||||
user_in_args->sample_rate = atoi(argv[4]);
|
||||
user_in_args->usr_sample_rate = atoi(argv[5]);
|
||||
user_in_args->channels = atoi(argv[6]);
|
||||
user_in_args->workmode = atoi(argv[7]);
|
||||
|
||||
g_vqe_type = atoi(argv[9]);
|
||||
if (g_vqe_type < 0 || g_vqe_type > 6) {
|
||||
printf("Invalid vqe_type/share_mode:%d\n", g_vqe_type);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (user_in_args->send_object != 2) {
|
||||
memcpy(user_in_args->output_file_name, argv[8], strlen(argv[8]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
} else {
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
user_in_args->share_mode_enable = (g_vqe_type == 5) ? XMEDIA_TRUE : XMEDIA_FALSE;
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" dev: %d\n", user_in_args->dev);
|
||||
SAMPLE_AUDIO_DBG(" send_object: %d\n", user_in_args->send_object);
|
||||
SAMPLE_AUDIO_DBG(" binder_mode: %d\n", user_in_args->binder_mode);
|
||||
SAMPLE_AUDIO_DBG(" samplerate: %d\n", user_in_args->sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" user samplerate: %d\n", user_in_args->usr_sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" chnnels: %d\n", user_in_args->channels);
|
||||
SAMPLE_AUDIO_DBG(" workmode: %d\n", user_in_args->workmode);
|
||||
|
||||
SAMPLE_AUDIO_DBG(" vqe_type/share_mode: %d\n", g_vqe_type);
|
||||
SAMPLE_AUDIO_DBG(" share_mode: %d\n", user_in_args->share_mode_enable);
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_auido_ai failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
printf("exit sample ai\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ao.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define SLEEP_TIME 10000 /* 5ms */
|
||||
#define INPUT_CMD_LENGTH 32
|
||||
|
||||
#define SEED_FRAME_TIME 10 /*10ms*/
|
||||
#define ACQUIRE_FRAME_STATUS 1
|
||||
#define SEND_FRAME_STATUS 0
|
||||
|
||||
#define SAMPLE_GET_INPUTCMD(input_cmd) fgets((char *)(input_cmd), (sizeof(input_cmd) - 1), stdin)
|
||||
static sample_ao_config g_ao_config = {0};
|
||||
static ao_vqe_attr_v2 ao_vqev2_attr = {0};
|
||||
static ao_vqe_attr_v1 ao_vqev1_attr = {0};
|
||||
|
||||
typedef struct {
|
||||
xmedia_char *sample;
|
||||
xmedia_char *in_stream;
|
||||
xmedia_char *dev;
|
||||
xmedia_char *dev_rate;
|
||||
xmedia_char *dev_chn;
|
||||
xmedia_char *frm_rate;
|
||||
xmedia_char *frm_chn;
|
||||
xmedia_char *mode;
|
||||
xmedia_char *frame_pcm_sample;
|
||||
xmedia_char *vqe;
|
||||
} input_arg;
|
||||
|
||||
typedef struct {
|
||||
FILE *in_stream[2];
|
||||
ao_dev dev;
|
||||
ao_chn chn;
|
||||
|
||||
xmedia_u32 vqe;
|
||||
|
||||
xmedia_u32 frm_rate;
|
||||
xmedia_u32 frm_chn;
|
||||
xmedia_u32 dev_rate;
|
||||
xmedia_u32 dev_chn;
|
||||
xmedia_u32 frame_pcm_sample;
|
||||
audio_dev_work_mode mode;
|
||||
xmedia_u32 pcm_samples;
|
||||
} sample_ctx;
|
||||
|
||||
static xmedia_s32 sample_ctx_init(const input_arg *arg, sample_ctx *ctx)
|
||||
{
|
||||
xmedia_u32 i;
|
||||
|
||||
ctx->dev = atoi(arg->dev);
|
||||
ctx->dev_rate = atoi(arg->dev_rate);
|
||||
ctx->dev_chn = atoi(arg->dev_chn);
|
||||
ctx->frm_rate = atoi(arg->frm_rate);
|
||||
ctx->frm_chn = atoi(arg->frm_chn);
|
||||
ctx->mode = atoi(arg->mode);
|
||||
ctx->frame_pcm_sample = atoi(arg->frame_pcm_sample);
|
||||
ctx->vqe = atoi(arg->vqe);
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
ctx->in_stream[i] = fopen(arg->in_stream, "rb");
|
||||
if (ctx->in_stream[i] == XMEDIA_NULL) {
|
||||
SAMPLE_AUDIO_DBG("open file %s error!\n", arg->in_stream);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
//SAMPLE_AUDIO_DBG("dev_rate=%d,frm_rate=%d,ctx->vqe=%d,mode=%d\n", ctx->dev_rate, ctx->frm_rate, ctx->vqe, ctx->mode);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ctx_deinit(sample_ctx *ctx)
|
||||
{
|
||||
xmedia_u32 i;
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
if (ctx->in_stream[i] != XMEDIA_NULL) {
|
||||
fclose(ctx->in_stream[i]);
|
||||
ctx->in_stream[i] = XMEDIA_NULL;
|
||||
}
|
||||
}
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void sample_ao_load_vqe_v1_attr(ao_vqe_attr *vqe_attr)
|
||||
{
|
||||
ao_vqe_attr_v1 *vqev1_attr = &ao_vqev1_attr;
|
||||
|
||||
vqe_attr->version = AO_VQE_ENHANCE_ATTR_VERSION_1;
|
||||
vqe_attr->attr = (xmedia_void*)&ao_vqev1_attr;
|
||||
|
||||
vqev1_attr->mask = VQE_V1_MASK_AGC | VQE_V1_MASK_ANR | VQE_V1_MASK_HPF | VQE_V1_MASK_EQ;
|
||||
vqev1_attr->agc_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->agc_attr.target_level = -8;
|
||||
vqev1_attr->agc_attr.max_boost_gain = 25;
|
||||
vqev1_attr->agc_attr.noise_floor = -120;
|
||||
vqev1_attr->agc_attr.ratio = 12;
|
||||
vqev1_attr->agc_attr.attack_time = 2;
|
||||
vqev1_attr->agc_attr.release_time = 20;
|
||||
|
||||
vqev1_attr->anr_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->anr_attr.usr_scene = VQE_V1_ANR_SCENE_NORMAL;
|
||||
vqev1_attr->anr_attr.nr_mode = VQE_V1_NR_MODE_SPEECH;
|
||||
vqev1_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev1_attr->anr_attr.suppress_level = 0x0;
|
||||
vqev1_attr->anr_attr.nonstationary_suppress_level = 0x2;
|
||||
|
||||
vqev1_attr->hpf_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->hpf_attr.freq = VQE_V1_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev1_attr->eq_attr, 0, sizeof(vqe_eq_attr_v1));
|
||||
}
|
||||
|
||||
static xmedia_void sample_ao_load_vqe_v2_attr(ao_vqe_attr *vqe_attr)
|
||||
{
|
||||
ao_vqe_attr_v2 *vqev2_attr = &ao_vqev2_attr;
|
||||
|
||||
vqe_attr->version = AO_VQE_ENHANCE_ATTR_VERSION_2;
|
||||
vqe_attr->attr = (xmedia_void*)&ao_vqev2_attr;
|
||||
vqev2_attr->mask = VQE_V2_MASK_AGC | VQE_V2_MASK_ANR | VQE_V2_MASK_HPF | VQE_V2_MASK_EQ;
|
||||
|
||||
|
||||
vqev2_attr->agc_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->agc_attr.target_level = -6;
|
||||
vqev2_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev2_attr->agc_attr.noise_floor = -65;
|
||||
vqev2_attr->agc_attr.ratio = 10;
|
||||
vqev2_attr->agc_attr.attack_time = 20;
|
||||
vqev2_attr->agc_attr.release_time = 20;
|
||||
|
||||
vqev2_attr->anr_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->anr_attr.usr_scene = VQE_V2_ANR_SCENE_NORMAL;
|
||||
vqev2_attr->anr_attr.nr_mode = VQE_V2_NR_MODE_SPEECH;
|
||||
vqev2_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev2_attr->anr_attr.suppress_level = 0x2;
|
||||
vqev2_attr->anr_attr.nonstationary_suppress_level = 0x2;
|
||||
|
||||
vqev2_attr->hpf_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->hpf_attr.freq = VQE_V2_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev2_attr->eq_attr, 0, sizeof(vqe_eq_attr_v2));
|
||||
}
|
||||
|
||||
static xmedia_void sample_ao_load_vqe_attr(ao_vqe_attr *vqe_attr, xmedia_u32 vqe_enable)
|
||||
{
|
||||
if(vqe_enable == 1) {
|
||||
sample_ao_load_vqe_v1_attr(vqe_attr);
|
||||
} else if(vqe_enable == 2) {
|
||||
sample_ao_load_vqe_v2_attr(vqe_attr);
|
||||
}
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ao_config_init(sample_ctx* ctx)
|
||||
{
|
||||
g_ao_config.dev = ctx->dev;
|
||||
|
||||
sample_comm_ao_get_default_attr(g_ao_config.dev, &g_ao_config.dev_attr);
|
||||
g_ao_config.dev_attr.pcm_frame_max_num = 10;
|
||||
g_ao_config.dev_attr.channels = ctx->dev_chn;
|
||||
g_ao_config.dev_attr.sample_rate = ctx->dev_rate;
|
||||
g_ao_config.dev_attr.pcm_samples_per_frame = ctx->frame_pcm_sample;
|
||||
g_ao_config.dev_attr.mode = ctx->mode;
|
||||
|
||||
g_ao_config.frame_info.frm_rate = ctx->frm_rate;
|
||||
g_ao_config.frame_info.frm_chn = ctx->frm_chn;
|
||||
g_ao_config.frame_info.frm_bit = AUDIO_BIT_DEPTH_16;
|
||||
|
||||
g_ao_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ao_config.frame_info.frm_rate != g_ao_config.dev_attr.sample_rate)) {
|
||||
g_ao_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
g_ao_config.vqe_enable = ctx->vqe;
|
||||
sample_ao_load_vqe_attr(&g_ao_config.vqe_attr, ctx->vqe);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ao(sample_ctx* ctx)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ao_config_init(ctx);
|
||||
CHECK_RET(ret, "sample_ao_config_init");
|
||||
|
||||
if(ctx->vqe == 1) {
|
||||
ret = sample_comm_ao_register(ao_vqev1_attr.mask, g_ao_config.vqe_attr.version, g_ao_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ao_register");
|
||||
} else if(ctx->vqe == 2) {
|
||||
ret = sample_comm_ao_register(ao_vqev2_attr.mask, g_ao_config.vqe_attr.version, g_ao_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ao_register");
|
||||
} else { //可能存在只有重采样场景
|
||||
if (g_ao_config.res_enable) {
|
||||
ret = sample_comm_ao_register(0, AO_VQE_ENHANCE_ATTR_VERSION_1, g_ao_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ao_register");
|
||||
}
|
||||
}
|
||||
|
||||
ret = sample_comm_ao_start(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_start");
|
||||
|
||||
sample_comm_ao_create_input_thread_from_file(&g_ao_config, ctx->in_stream);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
sample_comm_ao_destroy_input_thread_from_file(&g_ao_config);
|
||||
|
||||
ret = sample_comm_ao_stop(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void usage(input_arg *arg)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG(" usage: %s infile dev dev_rate dev_chn frm_rate frm_chn mode pcm_sample vqe\n", arg->sample);
|
||||
SAMPLE_AUDIO_DBG(" infile: input file name,only support pcm file\n");
|
||||
SAMPLE_AUDIO_DBG(" dev: (0/1)->(DAC0/I2S0)\n");
|
||||
SAMPLE_AUDIO_DBG(" dev_rate: (8000/16000/32000/48000) -> dev attr chn\n");
|
||||
SAMPLE_AUDIO_DBG(" dev_chn: (1/2)-> dev chn\n");
|
||||
SAMPLE_AUDIO_DBG(" frm_rate: (8000/16000/32000/48000) -> user frame chn\n");
|
||||
SAMPLE_AUDIO_DBG(" frm_chn: (1/2)-> user data chn\n");
|
||||
SAMPLE_AUDIO_DBG(" mode: (0/1)->(mono/queue)\n");
|
||||
SAMPLE_AUDIO_DBG(" pcm_sample: frame_pcm_samples\n");
|
||||
SAMPLE_AUDIO_DBG(" vqe: (0/1/2)-> vqe disable/enable v1/enable v2\n");
|
||||
SAMPLE_AUDIO_DBG(" examples: \n");
|
||||
SAMPLE_AUDIO_DBG(" %s infile 0 8000 1 16000 1 0 80 0\n", arg->sample);
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
sample_ctx ctx;
|
||||
|
||||
input_arg *arg = (input_arg *)argv;
|
||||
xmedia_char input_cmd[INPUT_CMD_LENGTH];
|
||||
|
||||
if (argc != sizeof(input_arg) / sizeof(xmedia_char *)) {
|
||||
usage(arg);
|
||||
return -1;
|
||||
}
|
||||
memset(&ctx, 0, sizeof(sample_ctx));
|
||||
|
||||
ret = sample_ctx_init(arg, &ctx);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("call sample_ctx_init failed(0x%x)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
sample_comm_audio_init();
|
||||
|
||||
ret = sample_start_ao(&ctx);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("call sample_start_ao failed(0x%x)\n", ret);
|
||||
goto out;
|
||||
}
|
||||
while (1) {
|
||||
SAMPLE_AUDIO_DBG("\ninput q to quit!\n");
|
||||
SAMPLE_AUDIO_DBG("input 'sm 0/1' to set codec unmute/mute!\n");
|
||||
SAMPLE_AUDIO_DBG("input 'sg xx' to set codec gain to xx db!\n");
|
||||
SAMPLE_AUDIO_DBG("input 'gg' to get codec gain xxdb!\n");
|
||||
SAMPLE_AUDIO_DBG("input 'sv xx' to set ao chn volume to xx db!\n");
|
||||
SAMPLE_GET_INPUTCMD(input_cmd);
|
||||
|
||||
if (input_cmd[0] == 'q') {
|
||||
SAMPLE_AUDIO_DBG("prepare to quit!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'm') {
|
||||
xmedia_bool mute = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ao_set_dev_param(&g_ao_config, AO_PARAM_CODEC_SET_MUTE, &mute);
|
||||
SAMPLE_AUDIO_DBG("\nset ao codec mute(%d) return 0x%x\n", mute, ret);
|
||||
}
|
||||
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'g') {
|
||||
xmedia_s32 gain = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ao_set_dev_param(&g_ao_config, AO_PARAM_CODEC_SET_DAC_GAIN, &gain);
|
||||
SAMPLE_AUDIO_DBG("\nset ao codec gain(%d) return 0x%x\n", gain, ret);
|
||||
}
|
||||
|
||||
if (input_cmd[0] == 'g' && input_cmd[1] == 'g') {
|
||||
xmedia_s32 gain;
|
||||
ret = sample_comm_ao_set_dev_param(&g_ao_config, AO_PARAM_CODEC_GET_DAC_GAIN, &gain);
|
||||
SAMPLE_AUDIO_DBG("\nget ao codec gain(%d) return 0x%x\n", gain, ret);
|
||||
}
|
||||
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v') {
|
||||
xmedia_s32 vol = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ao_set_volume(&g_ao_config, vol);
|
||||
SAMPLE_AUDIO_DBG("\nset ao chn volume(%d) return 0x%x\n", vol, ret);
|
||||
}
|
||||
}
|
||||
|
||||
sample_stop_ao();
|
||||
out:
|
||||
sample_comm_audio_exit();
|
||||
sample_ctx_deinit(&ctx);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", arg->sample);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
typedef enum {
|
||||
MODE_SAVE_FILE,
|
||||
MODE_SEND_AO,
|
||||
MODE_BINDER_AO,
|
||||
MODE_DROP
|
||||
} sample_decoder_mode;
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
sample_decoder_mode mode;
|
||||
audio_sample_rate file_samplerate;
|
||||
xmedia_u32 chn_cnt;
|
||||
xmedia_char input_file_name[ADEC_MAX_CHN_NUM][MAX_FILE_NAME_LEN];
|
||||
FILE *input_fd[ADEC_MAX_CHN_NUM];
|
||||
FILE *output_fd[ADEC_MAX_CHN_NUM];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ao_config g_ao_config;
|
||||
static sample_adec_config g_adec_config[ADEC_MAX_CHN_NUM];
|
||||
|
||||
static xmedia_s32 sample_ao_config_init(xmedia_void)
|
||||
{
|
||||
g_ao_config.dev = XMEDIA_AO_DEV_DAC0;
|
||||
|
||||
sample_comm_ao_get_default_attr(g_ao_config.dev, &g_ao_config.dev_attr);
|
||||
g_ao_config.dev_attr.channels = 1;
|
||||
g_ao_config.dev_attr.sample_rate = 16000;
|
||||
g_ao_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_ao_config.dev_attr.sample_rate / 1000;
|
||||
g_ao_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_MONO;
|
||||
g_ao_config.dev_attr.pcm_frame_max_num = 12;
|
||||
g_ao_config.vqe_enable = XMEDIA_FALSE;
|
||||
if ((g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ao_config.frame_info.frm_rate != g_ao_config.dev_attr.sample_rate)) {
|
||||
g_ao_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
if (g_user_input_args.mode == MODE_BINDER_AO) {
|
||||
g_ao_config.binder_src = MOD_ID_ADEC;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_adec_config_init(adec_chn chn)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.input_file_name[chn], &type, &format);
|
||||
|
||||
g_adec_config[chn].sample_rate = g_user_input_args.file_samplerate;
|
||||
g_adec_config[chn].chn = chn;
|
||||
g_adec_config[chn].type = type;
|
||||
g_adec_config[chn].format = format;
|
||||
|
||||
//AAC/MP3不知道输入采样率,默认注册重采样
|
||||
g_ao_config.res_enable = XMEDIA_FALSE;
|
||||
if (g_adec_config[chn].type == CODEC_TYPE_AAC || g_adec_config[chn].type == CODEC_TYPE_MP3) {
|
||||
g_ao_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
if (g_user_input_args.mode == MODE_SAVE_FILE || g_user_input_args.mode == MODE_DROP) {
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
ret = sample_ao_config_init();
|
||||
CHECK_RET(ret, "sample_ao_config_init");
|
||||
|
||||
if (g_ao_config.res_enable) {
|
||||
ret = sample_comm_ao_register(0, AO_VQE_ENHANCE_ATTR_VERSION_1, g_ao_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ao_register");
|
||||
}
|
||||
|
||||
ret = sample_comm_ao_start(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_start");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_adec()
|
||||
{
|
||||
xmedia_s32 i;
|
||||
xmedia_s32 ret;
|
||||
|
||||
for (i = 0; i < g_user_input_args.chn_cnt; i++) {
|
||||
ret = sample_adec_config_init(i);
|
||||
CHECK_RET(ret, "sample_adec_config_init");
|
||||
|
||||
ret = sample_comm_adec_register(g_adec_config[i].type);
|
||||
//CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_adec_start(&g_adec_config[i]);
|
||||
CHECK_RET(ret, "sample_comm_adec_start");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
if (g_user_input_args.mode == MODE_SAVE_FILE || g_user_input_args.mode == MODE_DROP) {
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
ret = sample_comm_ao_stop(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_adec()
|
||||
{
|
||||
xmedia_s32 i;
|
||||
xmedia_s32 ret;
|
||||
|
||||
for (i = 0; i < g_user_input_args.chn_cnt; i++) {
|
||||
ret = sample_comm_adec_stop(&g_adec_config[i]);
|
||||
CHECK_RET(ret, "sample_comm_adec_stop");
|
||||
}
|
||||
|
||||
for (i = 0; i < g_user_input_args.chn_cnt; i++) {
|
||||
ret = sample_comm_adec_unregister(g_adec_config[i].type);
|
||||
CHECK_RET(ret, "sample_comm_adec_unregister");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_data_thread()
|
||||
{
|
||||
xmedia_s32 i;
|
||||
xmedia_s32 ret = XMEDIA_SUCCESS;
|
||||
for (i = 0; i < g_user_input_args.chn_cnt; i++) {
|
||||
ret = sample_comm_adec_create_input_thread_from_file(&g_adec_config[i], g_user_input_args.input_fd);
|
||||
CHECK_RET(ret, "sample_comm_adec_create_out_to_ao_thread");
|
||||
|
||||
if (g_user_input_args.mode == MODE_SEND_AO) {
|
||||
ret = sample_comm_adec_create_output_thread_to_ao(&g_adec_config[i], g_ao_config.dev, g_adec_config[i].chn);
|
||||
CHECK_RET(ret, "sample_comm_adec_create_out_to_ao_thread");
|
||||
} else if (g_user_input_args.mode == MODE_SAVE_FILE || g_user_input_args.mode == MODE_DROP) {
|
||||
ret = sample_comm_adec_create_output_thread_to_file(&g_adec_config[i], g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_adec_create_output_thread_to_file");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_data_thread()
|
||||
{
|
||||
xmedia_s32 i;
|
||||
xmedia_s32 ret = XMEDIA_SUCCESS;
|
||||
|
||||
for (i = 0; i < g_user_input_args.chn_cnt; i++) {
|
||||
ret = sample_comm_adec_destroy_input_thread_from_file(&g_adec_config[i]);
|
||||
CHECK_RET(ret, "sample_comm_adec_destroy_input_thread_from_file");
|
||||
if (g_user_input_args.mode == MODE_SEND_AO) {
|
||||
ret = sample_comm_adec_destroy_output_thread_to_ao(&g_adec_config[i]);
|
||||
CHECK_RET(ret, "sample_comm_adec_destroy_output_thread_to_ao");
|
||||
} else if (g_user_input_args.mode == MODE_SAVE_FILE || g_user_input_args.mode == MODE_DROP) {
|
||||
ret = sample_comm_adec_destroy_output_thread_to_file(&g_adec_config[i]);
|
||||
CHECK_RET(ret, "sample_comm_adec_destroy_output_thread_to_file");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
xmedia_s32 sample_audio_doubletalk(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_adec();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_ADEC;
|
||||
}
|
||||
|
||||
ret = sample_start_ao();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AO;
|
||||
}
|
||||
|
||||
ret = sample_start_data_thread();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_DATA_TRHEAD;;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_data_thread();
|
||||
|
||||
ERR_START_DATA_TRHEAD:
|
||||
sample_stop_ao();
|
||||
ERR_START_AO:
|
||||
sample_stop_adec();
|
||||
ERR_START_ADEC:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [mode] [infile samplerate] [infile]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("mode : 0:save file 1:send ao 2:bind ao 3: drop\n");
|
||||
SAMPLE_AUDIO_DBG("in_rate: input file samplerate\n");
|
||||
SAMPLE_AUDIO_DBG("in_file: input file for adec(.g711a/.g711u/.g726/.aac/.mp3/.adpcm)\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG("one chn: %s 0 16000 in.aac \n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("multi chn: %s 0 16000 in1.aac in2.aac in3.g711a in4.mp3\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
xmedia_s32 i;
|
||||
xmedia_char* pos;
|
||||
xmedia_char* in_file_path;
|
||||
xmedia_char out_file_path[MAX_FILE_NAME_LEN];
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc < 4) {
|
||||
SAMPLE_AUDIO_DBG("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->mode = atoi(argv[1]);
|
||||
user_in_args->file_samplerate = atoi(argv[2]);
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" mode: %d\n", user_in_args->mode);
|
||||
SAMPLE_AUDIO_DBG(" file samplerate: %d\n", user_in_args->file_samplerate);
|
||||
|
||||
for (i = 0; i < argc - 3; i++) {
|
||||
if (i >= ADEC_MAX_CHN_NUM) {
|
||||
break;
|
||||
}
|
||||
|
||||
in_file_path = argv[3 + i];
|
||||
SAMPLE_AUDIO_DBG(" in file: %s\n", in_file_path);
|
||||
memcpy(user_in_args->input_file_name[i], in_file_path, strlen(in_file_path));
|
||||
user_in_args->input_fd[i] = fopen(in_file_path, "rb");
|
||||
if (user_in_args->input_fd[i] == NULL) {
|
||||
SAMPLE_AUDIO_DBG("Open %s failed\n", in_file_path);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
user_in_args->chn_cnt++;
|
||||
|
||||
if (user_in_args->mode != MODE_SAVE_FILE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pos = strstr(in_file_path, ".");
|
||||
if (pos == XMEDIA_NULL) {
|
||||
SAMPLE_AUDIO_DBG("Open %s failed\n", in_file_path);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
memset(out_file_path, 0, MAX_FILE_NAME_LEN);
|
||||
memcpy(out_file_path, in_file_path, pos - in_file_path);
|
||||
snprintf(out_file_path + (pos - in_file_path), 64, "_chn%d.pcm", i);
|
||||
|
||||
SAMPLE_AUDIO_DBG(" out file: %s\n", out_file_path);
|
||||
user_in_args->output_fd[i] = fopen(out_file_path, "wb");
|
||||
if (user_in_args->output_fd[i] == NULL) {
|
||||
SAMPLE_AUDIO_DBG("Open %s failed\n", out_file_path);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
xmedia_s32 i;
|
||||
for (i = 0; i < ADEC_MAX_CHN_NUM; i++) {
|
||||
if (user_in_args->input_fd[i] != NULL) {
|
||||
fclose(user_in_args->input_fd[i]);
|
||||
user_in_args->input_fd[i] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[i] != NULL) {
|
||||
fclose(user_in_args->output_fd[i]);
|
||||
user_in_args->output_fd[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("user_args_init failed(0x%x)\n\n", ret);
|
||||
user_args_deinit(&g_user_input_args);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_doubletalk();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("sample_auido_ai failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,543 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
#define CRY_ALARMLIMIT 80 // probability greater than which to count as one cry frame
|
||||
#define CRY_TIMELIMITCNT 3 // number of cry frame count as one cry event
|
||||
#define CRY_TIMELIMIT 5 // time interval to report cry event
|
||||
#define CRY_ALARMINTERVAL 3 //alarm interval time to unfreeze
|
||||
|
||||
#define AI_DEFAULT_MIC_VOL 20
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_bool binder_mode;
|
||||
audio_sample_rate file_samplerate;
|
||||
|
||||
char input_file_name[MAX_FILE_NAME_LEN];
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *input_fd[2];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static sample_ao_config g_ao_config;
|
||||
static sample_adec_config g_adec_config;
|
||||
static sample_aenc_config g_aenc_config;
|
||||
static ai_vqe_attr_v1 ai_vqev1_attr;
|
||||
static ao_vqe_attr_v1 ao_vqev1_attr;
|
||||
|
||||
static xmedia_void load_ai_vqev1_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_v1 *vqev1_attr = &ai_vqev1_attr;
|
||||
|
||||
attr->version = AI_VQE_ENHANCE_ATTR_VERSION_1;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = 1;
|
||||
attr->attr = (xmedia_void*)&ai_vqev1_attr;
|
||||
vqev1_attr->mask = VQE_V1_MASK_AGC | VQE_V1_MASK_ANR | VQE_V1_MASK_AEC | VQE_V1_MASK_HPF;
|
||||
|
||||
vqev1_attr->aec_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->aec_attr.cng_enable = XMEDIA_TRUE;
|
||||
vqev1_attr->aec_attr.freq_boundary = 1800;
|
||||
vqev1_attr->aec_attr.low_suppress_level = 0x7;
|
||||
vqev1_attr->aec_attr.high_suppress_level = 0x5;
|
||||
vqev1_attr->aec_attr.low_enhance_voice_protect_level = 0;
|
||||
vqev1_attr->aec_attr.high_enhance_voice_protect_level = 0;
|
||||
|
||||
vqev1_attr->agc_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->agc_attr.target_level = -6;
|
||||
vqev1_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev1_attr->agc_attr.noise_floor = -100;
|
||||
vqev1_attr->agc_attr.ratio = 12;
|
||||
vqev1_attr->agc_attr.attack_time = 8;
|
||||
vqev1_attr->agc_attr.release_time =20;
|
||||
|
||||
vqev1_attr->anr_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->anr_attr.usr_scene = VQE_V1_ANR_SCENE_NORMAL;
|
||||
vqev1_attr->anr_attr.nr_mode = VQE_V1_NR_MODE_SPEECH;
|
||||
vqev1_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev1_attr->anr_attr.suppress_level = 0x2;
|
||||
vqev1_attr->anr_attr.nonstationary_suppress_level = 0x0;
|
||||
|
||||
vqev1_attr->vad_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->vad_attr.sensitivity_level = 4;
|
||||
|
||||
vqev1_attr->hpf_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->hpf_attr.freq = VQE_V1_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev1_attr->eq_attr, 0, sizeof(vqe_eq_attr_v1));
|
||||
}
|
||||
|
||||
static xmedia_void load_ao_vqev1_attr(ao_vqe_attr* attr)
|
||||
{
|
||||
ao_vqe_attr_v1 *vqev1_attr = &ao_vqev1_attr;
|
||||
|
||||
attr->version = AO_VQE_ENHANCE_ATTR_VERSION_1;
|
||||
attr->attr = (xmedia_void*)&ao_vqev1_attr;
|
||||
vqev1_attr->mask = VQE_V1_MASK_AGC | VQE_V1_MASK_ANR | VQE_V1_MASK_HPF;
|
||||
|
||||
vqev1_attr->agc_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->agc_attr.target_level = -6;
|
||||
vqev1_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev1_attr->agc_attr.noise_floor = -65;
|
||||
vqev1_attr->agc_attr.ratio = 10;
|
||||
vqev1_attr->agc_attr.attack_time = 20;
|
||||
vqev1_attr->agc_attr.release_time =20;
|
||||
|
||||
vqev1_attr->anr_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->anr_attr.usr_scene = VQE_V1_ANR_SCENE_NORMAL;
|
||||
vqev1_attr->anr_attr.nr_mode = VQE_V1_NR_MODE_SPEECH;
|
||||
vqev1_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev1_attr->anr_attr.suppress_level = 0x2;
|
||||
vqev1_attr->anr_attr.nonstationary_suppress_level = 0x2;
|
||||
|
||||
vqev1_attr->hpf_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->hpf_attr.freq = VQE_V1_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev1_attr->eq_attr, 0, sizeof(vqe_eq_attr_v1));
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_user_input_args.sample_rate / 1000;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
load_ai_vqev1_attr(&g_ai_config.vqe_attr);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ao_config_init(xmedia_void)
|
||||
{
|
||||
g_ao_config.dev = XMEDIA_AO_DEV_DAC0;
|
||||
|
||||
sample_comm_ao_get_default_attr(g_ao_config.dev, &g_ao_config.dev_attr);
|
||||
g_ao_config.dev_attr.channels = 1;
|
||||
g_ao_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ao_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_user_input_args.sample_rate / 1000;
|
||||
g_ao_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_MONO;
|
||||
|
||||
//AAC/MP3不知道输入采样率,默认注册重采样,其他格式根据输入采样率决定是否注册
|
||||
g_ao_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_adec_config.type == CODEC_TYPE_AAC || g_adec_config.type == CODEC_TYPE_MP3) ||
|
||||
(g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ao_config.frame_info.frm_rate != g_ao_config.dev_attr.sample_rate)) {
|
||||
g_ao_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
g_ao_config.vqe_enable = XMEDIA_TRUE;
|
||||
load_ao_vqev1_attr(&g_ao_config.vqe_attr);
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_ao_config.binder_src = MOD_ID_ADEC;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_adec_config_init(xmedia_void)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.input_file_name, &type, &format);
|
||||
|
||||
g_adec_config.sample_rate = g_user_input_args.file_samplerate;
|
||||
g_adec_config.chn = 0;
|
||||
g_adec_config.type = type;
|
||||
g_adec_config.format = format;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_aenc_config_init(xmedia_void)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.output_file_name, &type, &format);
|
||||
|
||||
g_aenc_config.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_aenc_config.channels = g_user_input_args.channels;
|
||||
g_aenc_config.bit_depth = 16;
|
||||
g_aenc_config.chn = 0;
|
||||
g_aenc_config.type = type;
|
||||
g_aenc_config.format = format;
|
||||
g_aenc_config.binder_dev = g_ai_config.dev;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_aenc_config.binder_src = MOD_ID_AI;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_s32 vol = AI_DEFAULT_MIC_VOL;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_register(ai_vqev1_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&vol);
|
||||
CHECK_RET(ret, "sample_comm_ai_set_dev_param");
|
||||
}
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_create_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_data_thread");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ao_config_init();
|
||||
CHECK_RET(ret, "sample_ao_config_init");
|
||||
|
||||
ret = sample_comm_ao_register(ao_vqev1_attr.mask, g_ao_config.vqe_attr.version, g_ao_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ao_start(&g_ao_config);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_adec()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_adec_config_init();
|
||||
CHECK_RET(ret, "sample_adec_config_init");
|
||||
|
||||
ret = sample_comm_adec_register(g_adec_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_adec_start(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_start");
|
||||
|
||||
ret = sample_comm_adec_create_input_thread_from_file(&g_adec_config, g_user_input_args.input_fd);
|
||||
CHECK_RET(ret, "sample_comm_adec_create_out_to_ao_thread");
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_adec_create_output_thread_to_ao(&g_adec_config, g_ao_config.dev, g_adec_config.chn);
|
||||
CHECK_RET(ret, "sample_comm_adec_create_out_to_ao_thread");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_aenc_config_init();
|
||||
CHECK_RET(ret, "sample_aenc_config_init");
|
||||
|
||||
ret = sample_comm_aenc_register(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_aenc_start(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_start");
|
||||
|
||||
ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_data_thread");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_data_thread");
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_ao_stop(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_adec()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_adec_destroy_input_thread_from_file(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_destroy_input_thread_from_file");
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_adec_destroy_output_thread_to_ao(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_destroy_output_thread_to_ao");
|
||||
}
|
||||
|
||||
ret = sample_comm_adec_stop(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_stop");
|
||||
|
||||
ret = sample_comm_adec_unregister(g_adec_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_out_to_file_thread");
|
||||
|
||||
ret = sample_comm_aenc_stop(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_stop");
|
||||
|
||||
ret = sample_comm_aenc_unregister(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_aenc_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
xmedia_s32 sample_audio_doubletalk(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_adec();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_ADEC;
|
||||
}
|
||||
|
||||
ret = sample_start_ao();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
ret = sample_start_aenc();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AENC;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ai vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'soXX' to set ao vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ai vol\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v' ) {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'o') {
|
||||
xmedia_s32 vol = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ao_set_volume(&g_ao_config, vol);
|
||||
SAMPLE_AUDIO_DBG("\nset ao chn volume(%d) return 0x%x\n", vol, ret);
|
||||
} else if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_aenc();
|
||||
ERR_START_AENC:
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
sample_stop_ao();
|
||||
ERR_START_AO:
|
||||
sample_stop_adec();
|
||||
ERR_START_ADEC:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [samplerate] [usr_samplerate] [channels] [binder_mode] [outfile] [infile] [infile samplerate]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("dev_rate: dev samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("usr_rate: out file samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("dev_chn: dev chn cnt(1/2/8)\n");
|
||||
SAMPLE_AUDIO_DBG("mode: binder mode(0/1)\n");
|
||||
SAMPLE_AUDIO_DBG("out_file: aenc encoder out file(.g711a/.g711u/.g726/.aac/.mp3/.pcm/.adpcm)\n");
|
||||
SAMPLE_AUDIO_DBG("in_file: input file for adec(.g711a/.g711u/.g726/.aac/.mp3/.pcm/.adpcm)\n");
|
||||
SAMPLE_AUDIO_DBG("file_rate: input file samplerate for voice\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 1 1 out.g711a in.aac 8000\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 1 1 out.g711a in.aac 16000\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 8) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->sample_rate = atoi(argv[1]);
|
||||
user_in_args->usr_sample_rate = atoi(argv[2]);
|
||||
user_in_args->channels = atoi(argv[3]);
|
||||
user_in_args->binder_mode = (atoi(argv[4]) == 0 ? XMEDIA_FALSE : XMEDIA_TRUE);
|
||||
memcpy(user_in_args->output_file_name, argv[5], strlen(argv[5]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(user_in_args->input_file_name, argv[6], strlen(argv[6]));
|
||||
if (strcmp(user_in_args->input_file_name, "null")) {
|
||||
user_in_args->input_fd[0] = fopen(user_in_args->input_file_name, "rb");
|
||||
if (user_in_args->input_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->input_file_name);
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
user_in_args->file_samplerate = atoi(argv[7]);
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" samplerate: %d\n", user_in_args->sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" user samplerate: %d\n", user_in_args->usr_sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" chnnels: %d\n", user_in_args->channels);
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->input_fd[1] != NULL) {
|
||||
fclose(user_in_args->input_fd[1]);
|
||||
user_in_args->input_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->input_fd[0] != NULL) {
|
||||
fclose(user_in_args->input_fd[0]);
|
||||
user_in_args->input_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_doubletalk();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_auido_ai failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,533 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
#define AI_DEFAULT_MIC_VOL 20
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_bool binder_mode;
|
||||
audio_sample_rate file_samplerate;
|
||||
|
||||
char input_file_name[MAX_FILE_NAME_LEN];
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *input_fd[2];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static sample_ao_config g_ao_config;
|
||||
static sample_adec_config g_adec_config;
|
||||
static sample_aenc_config g_aenc_config;
|
||||
static ai_vqe_attr_v2 ai_vqev2_attr;
|
||||
static ao_vqe_attr_v2 ao_vqev2_attr;
|
||||
|
||||
static xmedia_void load_ai_vqev2_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_v2 *vqev2_attr = &ai_vqev2_attr;
|
||||
|
||||
attr->version = AI_VQE_ENHANCE_ATTR_VERSION_2;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = 2;
|
||||
attr->attr = (xmedia_void*)&ai_vqev2_attr;
|
||||
vqev2_attr->mask = VQE_V2_MASK_AGC | VQE_V2_MASK_ANR | VQE_V2_MASK_AEC | VQE_V2_MASK_HPF | VQE_V2_MASK_BF;
|
||||
|
||||
vqev2_attr->aec_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->aec_attr.cng_enable = XMEDIA_TRUE;
|
||||
vqev2_attr->aec_attr.freq_boundary = 1800;
|
||||
vqev2_attr->aec_attr.low_suppress_level = 0x7;
|
||||
vqev2_attr->aec_attr.high_suppress_level = 0x5;
|
||||
|
||||
vqev2_attr->agc_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->agc_attr.target_level = -6;
|
||||
vqev2_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev2_attr->agc_attr.noise_floor = -100;
|
||||
vqev2_attr->agc_attr.ratio = 12;
|
||||
vqev2_attr->agc_attr.attack_time = 8;
|
||||
vqev2_attr->agc_attr.release_time =20;
|
||||
|
||||
vqev2_attr->anr_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->anr_attr.usr_scene = VQE_V2_ANR_SCENE_NORMAL;
|
||||
vqev2_attr->anr_attr.nr_mode = VQE_V2_NR_MODE_SPEECH;
|
||||
vqev2_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev2_attr->anr_attr.suppress_level = 0x2;
|
||||
vqev2_attr->anr_attr.nonstationary_suppress_level = 0x0;
|
||||
|
||||
vqev2_attr->bf_attr.reserved = 0;
|
||||
|
||||
vqev2_attr->vad_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->vad_attr.sensitivity_level = 5;
|
||||
|
||||
vqev2_attr->hpf_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->hpf_attr.freq = VQE_V2_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev2_attr->eq_attr, 0, sizeof(vqe_eq_attr_v2));
|
||||
}
|
||||
|
||||
static xmedia_void load_ao_vqev2_attr(ao_vqe_attr* attr)
|
||||
{
|
||||
ao_vqe_attr_v2 *vqev2_attr = &ao_vqev2_attr;
|
||||
|
||||
attr->version = AO_VQE_ENHANCE_ATTR_VERSION_2;
|
||||
attr->attr = (xmedia_void*)&ao_vqev2_attr;
|
||||
vqev2_attr->mask = VQE_V2_MASK_AGC | VQE_V2_MASK_ANR | VQE_V2_MASK_HPF;
|
||||
|
||||
vqev2_attr->agc_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->agc_attr.target_level = -6;
|
||||
vqev2_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev2_attr->agc_attr.noise_floor = -65;
|
||||
vqev2_attr->agc_attr.ratio = 10;
|
||||
vqev2_attr->agc_attr.attack_time = 20;
|
||||
vqev2_attr->agc_attr.release_time =20;
|
||||
|
||||
vqev2_attr->anr_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->anr_attr.usr_scene = VQE_V2_ANR_SCENE_NORMAL;
|
||||
vqev2_attr->anr_attr.nr_mode = VQE_V2_NR_MODE_SPEECH;
|
||||
vqev2_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev2_attr->anr_attr.suppress_level = 0x2;
|
||||
vqev2_attr->anr_attr.nonstationary_suppress_level = 0x2;
|
||||
|
||||
vqev2_attr->hpf_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->hpf_attr.freq = VQE_V2_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev2_attr->eq_attr, 0, sizeof(vqe_eq_attr_v2));
|
||||
}
|
||||
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_user_input_args.sample_rate / 1000;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
load_ai_vqev2_attr(&g_ai_config.vqe_attr);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ao_config_init(xmedia_void)
|
||||
{
|
||||
g_ao_config.dev = XMEDIA_AO_DEV_DAC0;
|
||||
|
||||
sample_comm_ao_get_default_attr(g_ao_config.dev, &g_ao_config.dev_attr);
|
||||
g_ao_config.dev_attr.channels = 1;
|
||||
g_ao_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ao_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_user_input_args.sample_rate / 1000;
|
||||
g_ao_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_MONO;
|
||||
|
||||
//AAC/MP3不知道输入采样率,默认注册重采样,其他格式根据输入采样率决定是否注册
|
||||
g_ao_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_adec_config.type == CODEC_TYPE_AAC || g_adec_config.type == CODEC_TYPE_MP3) ||
|
||||
(g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ao_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ao_config.frame_info.frm_rate != g_ao_config.dev_attr.sample_rate)) {
|
||||
g_ao_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
g_ao_config.vqe_enable = XMEDIA_TRUE;
|
||||
load_ao_vqev2_attr(&g_ao_config.vqe_attr);
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_ao_config.binder_src = MOD_ID_ADEC;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_adec_config_init(xmedia_void)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.input_file_name, &type, &format);
|
||||
|
||||
g_adec_config.sample_rate = g_user_input_args.file_samplerate;
|
||||
g_adec_config.chn = 0;
|
||||
g_adec_config.type = type;
|
||||
g_adec_config.format = format;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_aenc_config_init(xmedia_void)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.output_file_name, &type, &format);
|
||||
|
||||
g_aenc_config.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_aenc_config.channels = 1; // ai open vqev2
|
||||
g_aenc_config.bit_depth = 16;
|
||||
g_aenc_config.chn = 0;
|
||||
g_aenc_config.type = type;
|
||||
g_aenc_config.format = format;
|
||||
g_aenc_config.binder_dev = g_ai_config.dev;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_aenc_config.binder_src = MOD_ID_AI;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
xmedia_s32 vol = AI_DEFAULT_MIC_VOL;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_register(ai_vqev2_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&vol);
|
||||
CHECK_RET(ret, "sample_comm_ai_set_dev_param");
|
||||
}
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_create_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_data_thread");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ao_config_init();
|
||||
CHECK_RET(ret, "sample_ao_config_init");
|
||||
|
||||
ret = sample_comm_ao_register(ao_vqev2_attr.mask, g_ao_config.vqe_attr.version, g_ao_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ao_start(&g_ao_config);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_adec()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_adec_config_init();
|
||||
CHECK_RET(ret, "sample_adec_config_init");
|
||||
|
||||
ret = sample_comm_adec_register(g_adec_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_adec_start(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_start");
|
||||
|
||||
ret = sample_comm_adec_create_input_thread_from_file(&g_adec_config, g_user_input_args.input_fd);
|
||||
CHECK_RET(ret, "sample_comm_adec_create_out_to_ao_thread");
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_adec_create_output_thread_to_ao(&g_adec_config, g_ao_config.dev, g_adec_config.chn);
|
||||
CHECK_RET(ret, "sample_comm_adec_create_out_to_ao_thread");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_aenc_config_init();
|
||||
CHECK_RET(ret, "sample_aenc_config_init");
|
||||
|
||||
ret = sample_comm_aenc_register(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_aenc_start(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_start");
|
||||
|
||||
ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_data_thread");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_data_thread");
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ao()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_ao_stop(&g_ao_config);
|
||||
CHECK_RET(ret, "sample_comm_ao_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_adec()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_adec_destroy_input_thread_from_file(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_destroy_input_thread_from_file");
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_adec_destroy_output_thread_to_ao(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_destroy_output_thread_to_ao");
|
||||
}
|
||||
|
||||
ret = sample_comm_adec_stop(&g_adec_config);
|
||||
CHECK_RET(ret, "sample_comm_adec_stop");
|
||||
|
||||
ret = sample_comm_adec_unregister(g_adec_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_out_to_file_thread");
|
||||
|
||||
ret = sample_comm_aenc_stop(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_stop");
|
||||
|
||||
ret = sample_comm_aenc_unregister(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_aenc_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
xmedia_s32 sample_audio_doubletalk(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_adec();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_ADEC;
|
||||
}
|
||||
|
||||
ret = sample_start_ao();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
ret = sample_start_aenc();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AENC;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ai vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ai vol\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v' ) {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_aenc();
|
||||
ERR_START_AENC:
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
sample_stop_ao();
|
||||
ERR_START_AO:
|
||||
sample_stop_adec();
|
||||
ERR_START_ADEC:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [samplerate] [usr_samplerate] [channels] [binder_mode] [outfile] [infile] [infile samplerate]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("dev_rate: dev samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("usr_rate: out file samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("dev_chn: dev chn cnt(1/2/8)\n");
|
||||
SAMPLE_AUDIO_DBG("mode: binder mode(0/1)\n");
|
||||
SAMPLE_AUDIO_DBG("out_file: aenc encoder out file(.g711a/.g711u/.g726/.aac/.mp3/.pcm/.adpcm)\n");
|
||||
SAMPLE_AUDIO_DBG("in_file: input file for adec(.g711a/.g711u/.g726/.aac/.mp3/.pcm/.adpcm)\n");
|
||||
SAMPLE_AUDIO_DBG("file_rate: input file samplerate for voice\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 2 1 out.g711a in.aac 8000\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 2 1 out.g711a in.aac 16000\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 8) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->sample_rate = atoi(argv[1]);
|
||||
user_in_args->usr_sample_rate = atoi(argv[2]);
|
||||
user_in_args->channels = atoi(argv[3]);
|
||||
user_in_args->binder_mode = (atoi(argv[4]) == 0 ? XMEDIA_FALSE : XMEDIA_TRUE);
|
||||
memcpy(user_in_args->output_file_name, argv[5], strlen(argv[5]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(user_in_args->input_file_name, argv[6], strlen(argv[6]));
|
||||
if (strcmp(user_in_args->input_file_name, "null")) {
|
||||
user_in_args->input_fd[0] = fopen(user_in_args->input_file_name, "rb");
|
||||
if (user_in_args->input_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->input_file_name);
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
user_in_args->file_samplerate = atoi(argv[7]);
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" samplerate: %d\n", user_in_args->sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" user samplerate: %d\n", user_in_args->usr_sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" chnnels: %d\n", user_in_args->channels);
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->input_fd[1] != NULL) {
|
||||
fclose(user_in_args->input_fd[1]);
|
||||
user_in_args->input_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->input_fd[0] != NULL) {
|
||||
fclose(user_in_args->input_fd[0]);
|
||||
user_in_args->input_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_doubletalk();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_auido_ai failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Executable
+251
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
typedef enum {
|
||||
MODE_SAVE_FILE,
|
||||
MODE_BINDER_AI,
|
||||
MODE_DROP
|
||||
} sample_encoder_mode;
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate file_samplerate;
|
||||
audio_channel file_channel;
|
||||
xmedia_u32 chn_cnt;
|
||||
xmedia_char output_file_name[AENC_MAX_CHN_NUM][MAX_FILE_NAME_LEN];
|
||||
FILE *input_fd[AENC_MAX_CHN_NUM];
|
||||
FILE *output_fd[AENC_MAX_CHN_NUM];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_aenc_config g_aenc_config[AENC_MAX_CHN_NUM];
|
||||
|
||||
static xmedia_s32 sample_aenc_config_init(aenc_chn chn)
|
||||
{
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
sample_comm_get_codec_info(g_user_input_args.output_file_name[chn], &type, &format);
|
||||
|
||||
g_aenc_config[chn].sample_rate = g_user_input_args.file_samplerate;
|
||||
g_aenc_config[chn].chn = chn;
|
||||
g_aenc_config[chn].type = type;
|
||||
g_aenc_config[chn].format = format;
|
||||
g_aenc_config[chn].bit_depth = 16;
|
||||
g_aenc_config[chn].channels = g_user_input_args.file_channel;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_aenc()
|
||||
{
|
||||
xmedia_s32 i;
|
||||
xmedia_s32 ret;
|
||||
|
||||
for (i = 0; i < g_user_input_args.chn_cnt; i++) {
|
||||
ret = sample_aenc_config_init(i);
|
||||
CHECK_RET(ret, "sample_aenc_config_init");
|
||||
|
||||
ret = sample_comm_aenc_register(g_aenc_config[i].type);
|
||||
//CHECK_RET(ret, "sample_comm_aenc_register");
|
||||
|
||||
ret = sample_comm_aenc_start(&g_aenc_config[i]);
|
||||
CHECK_RET(ret, "sample_comm_aenc_start");
|
||||
|
||||
ret = sample_comm_aenc_create_input_thread_from_file(&g_aenc_config[i], g_user_input_args.input_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_input_thread_from_file");
|
||||
|
||||
ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config[i], g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_input_thread_from_file");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_aenc()
|
||||
{
|
||||
xmedia_s32 i;
|
||||
xmedia_s32 ret;
|
||||
|
||||
for (i = 0; i < g_user_input_args.chn_cnt; i++) {
|
||||
ret = sample_comm_aenc_stop(&g_aenc_config[i]);
|
||||
CHECK_RET(ret, "sample_comm_aenc_stop");
|
||||
|
||||
ret = sample_comm_aenc_destroy_input_thread_from_file(&g_aenc_config[i]);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_input_thread_from_file");
|
||||
|
||||
ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config[i]);
|
||||
CHECK_RET(ret, "sample_comm_aenc_destroy_output_thread_to_file");
|
||||
}
|
||||
|
||||
for (i = 0; i < g_user_input_args.chn_cnt; i++) {
|
||||
ret = sample_comm_aenc_unregister(g_aenc_config[i].type);
|
||||
CHECK_RET(ret, "sample_comm_aenc_unregister");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_audio_doubletalk(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_aenc();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AENC;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_aenc();
|
||||
ERR_START_AENC:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [infile samplerate] [infile channels] [infile] [outfile]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("infile samplerate: input file samplerate\n");
|
||||
SAMPLE_AUDIO_DBG("infile channels: input file channels\n");
|
||||
SAMPLE_AUDIO_DBG("infile: input file path for aenc\n");
|
||||
SAMPLE_AUDIO_DBG("outfile: .g711a/.g711u/.g726/.aac/.mp3/.adpcm\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG("one aenc chn: %s 16000 1 in.pcm out.g711a \n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("multi aenc chn: %s 16000 1 in1.pcm out1.g711a in2.pcm out2.aac\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
xmedia_s32 i;
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc < 5 || ((argc - 1) % 2 != 0)) {
|
||||
SAMPLE_AUDIO_DBG("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->file_samplerate = atoi(argv[1]);
|
||||
user_in_args->file_channel = atoi(argv[2]);
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" file samplerate: %d\n", user_in_args->file_samplerate);
|
||||
SAMPLE_AUDIO_DBG(" file channels: %d\n", user_in_args->file_channel);
|
||||
|
||||
for (i = 0; i < argc - 3; i += 2) {
|
||||
if (i >= AENC_MAX_CHN_NUM * 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
SAMPLE_AUDIO_DBG(" in file: %s\n", argv[3 + i]);
|
||||
user_in_args->input_fd[user_in_args->chn_cnt] = fopen(argv[3 + i], "rb");
|
||||
if (user_in_args->input_fd[user_in_args->chn_cnt] == NULL) {
|
||||
SAMPLE_AUDIO_DBG("Open %s failed\n", argv[3 + i]);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
memcpy(user_in_args->output_file_name[user_in_args->chn_cnt], argv[3 + i + 1], strlen(argv[3 + i + 1]));
|
||||
SAMPLE_AUDIO_DBG(" out file: %s\n", user_in_args->output_file_name[user_in_args->chn_cnt]);
|
||||
user_in_args->output_fd[user_in_args->chn_cnt] = fopen(user_in_args->output_file_name[user_in_args->chn_cnt], "wb");
|
||||
if (user_in_args->output_fd[user_in_args->chn_cnt] == NULL) {
|
||||
SAMPLE_AUDIO_DBG("Open %s failed\n", user_in_args->output_file_name[user_in_args->chn_cnt]);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->chn_cnt++;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
xmedia_s32 i;
|
||||
|
||||
for (i = 0; i < AENC_MAX_CHN_NUM; i++) {
|
||||
if (user_in_args->input_fd[i] != NULL) {
|
||||
fclose(user_in_args->input_fd[i]);
|
||||
user_in_args->input_fd[i] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[i] != NULL) {
|
||||
fclose(user_in_args->output_fd[i]);
|
||||
user_in_args->output_fd[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("user_args_init failed(0x%x)\n\n", ret);
|
||||
user_args_deinit(&g_user_input_args);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_doubletalk();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
SAMPLE_AUDIO_DBG("sample_auido_ai failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_detect.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
#define CRY_ALARMLIMIT 80 // probability greater than which to count as one cry frame
|
||||
#define CRY_TIMELIMITCNT 3 // number of cry frame count as one cry event
|
||||
#define CRY_TIMELIMIT 5 // time interval to report cry event
|
||||
#define CRY_ALARMINTERVAL 3 // alarm interval time to unfreeze
|
||||
|
||||
#define GBD_TIMELIMIT 5 // time interval to report gbd event
|
||||
#define GBD_TIMELIMITCNT 2 // number of gbd frame count as one gbd event
|
||||
#define GBD_ALARMLIMIT 80 // probability greater than which to count as one gbd frame
|
||||
#define GBD_ALARMINTERVAL 3 // alarm interval time to unfreeze
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_s32 codec_input_vol;
|
||||
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static ai_vqe_attr_detect ai_detect_attr;
|
||||
static xmedia_u32 g_vqe_type;
|
||||
|
||||
static xmedia_s32 cry_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("cry callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 gbd_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("gbd callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ssl_callback(xmedia_void* attr, xmedia_s32 out)
|
||||
{
|
||||
static xmedia_s32 ssl_out = 0;
|
||||
static xmedia_s32 call_times = 0;
|
||||
call_times++;
|
||||
|
||||
if (ssl_out != out) {
|
||||
printf("attr(0x%x), call_times(%d), out_angle(%d)\n", (xmedia_u32)attr, call_times, out);
|
||||
}
|
||||
ssl_out = out;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ved_callback(xmedia_void* private, xmedia_bool is_event, xmedia_bool is_mutation, xmedia_s32 out_db)
|
||||
{
|
||||
if (is_event) {
|
||||
printf("volume event detect out_db = %d\n",out_db);
|
||||
}
|
||||
if (is_mutation) {
|
||||
printf("volume mutation detect out_db = %d\n", out_db);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_detect_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_detect* detect_attr = &ai_detect_attr;
|
||||
|
||||
attr->version = AI_VQE_DETECT_ATTR_VERSION_1;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = g_ai_config.dev_attr.channels;
|
||||
|
||||
if (g_vqe_type == 1) {
|
||||
attr->work_sample_rate = AUDIO_SAMPLE_RATE_16000; //bcd只支持16K
|
||||
detect_attr->mask =VQE_DETECT_MASK_BCD;
|
||||
} else if (g_vqe_type == 2) {
|
||||
if (attr->work_sample_rate == AUDIO_SAMPLE_RATE_16000) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
detect_attr->mask = VQE_DETECT_MASK_GBD;
|
||||
} else if (g_vqe_type == 3) {
|
||||
detect_attr->mask = VQE_DETECT_MASK_SSL;
|
||||
} else if (g_vqe_type == 4) {
|
||||
detect_attr->mask = VQE_DETECT_MASK_VED;
|
||||
} else if (g_vqe_type == 5) {
|
||||
detect_attr->mask = VQE_DETECT_MASK_BCD | VQE_DETECT_MASK_HPF | VQE_DETECT_MASK_VED | VQE_DETECT_MASK_SSL;
|
||||
}
|
||||
detect_attr->hpf_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->hpf_attr.freq = VQE_DETECT_HPF_FREQ_80;
|
||||
|
||||
detect_attr->bcd_attr.usr_mode = XMEDIA_TRUE;
|
||||
detect_attr->bcd_attr.bypass = XMEDIA_FALSE;
|
||||
detect_attr->bcd_attr.alarm_threshold = CRY_ALARMLIMIT;
|
||||
detect_attr->bcd_attr.time_limit = CRY_TIMELIMIT;
|
||||
detect_attr->bcd_attr.time_limit_threshold_count = CRY_TIMELIMITCNT;
|
||||
detect_attr->bcd_attr.interval_time = CRY_ALARMINTERVAL;
|
||||
/*just for npu bcd lib*/
|
||||
detect_attr->bcd_attr.bcd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr->bcd_attr.bcd_model.model_info.file.pathname = "./audio_xmm/bcd_neuron_network.xmm";
|
||||
detect_attr->bcd_attr.callback = (fn_bcd_callback)cry_callback;
|
||||
detect_attr->bcd_attr.private_data = (xmedia_void*)0x12345678;
|
||||
|
||||
detect_attr->ssl_attr.mic_distance = 50;
|
||||
detect_attr->ssl_attr.shape = 0;
|
||||
detect_attr->ssl_attr.sensitivity_level = 5;
|
||||
detect_attr->ssl_attr.callback = (fn_detect_ssl_callback)ssl_callback;
|
||||
detect_attr->ssl_attr.private_data = (xmedia_void*)0x12345678;
|
||||
|
||||
detect_attr->ved_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->ved_attr.volume_threshold = -15;
|
||||
detect_attr->ved_attr.mutation_flag = 1;
|
||||
detect_attr->ved_attr.fast_change_threshold = 15;
|
||||
detect_attr->ved_attr.slow_change_threshold = 8;
|
||||
detect_attr->ved_attr.callback = (fn_detect_ved_callback)ved_callback;
|
||||
|
||||
detect_attr->gbd_attr.usr_mode = XMEDIA_TRUE;
|
||||
detect_attr->gbd_attr.bypass = XMEDIA_FALSE;
|
||||
detect_attr->gbd_attr.alarm_threshold = GBD_ALARMLIMIT;
|
||||
detect_attr->gbd_attr.time_limit = GBD_TIMELIMIT;
|
||||
detect_attr->gbd_attr.time_limit_threshold_count = GBD_TIMELIMITCNT;
|
||||
detect_attr->gbd_attr.interval_time = GBD_ALARMINTERVAL;
|
||||
/*just for npu gbd lib*/
|
||||
detect_attr->gbd_attr.gbd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr->gbd_attr.gbd_model.model_info.file.pathname = "./audio_xmm/gbd_neuron_network.xmm";
|
||||
detect_attr->gbd_attr.callback = (fn_detect_gbd_callback)gbd_callback;
|
||||
detect_attr->gbd_attr.private_data = (xmedia_void*)0x12345678;
|
||||
attr->attr = (xmedia_void*)&ai_detect_attr;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
if (g_user_input_args.channels > 2) {
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_PDM0;
|
||||
} else {
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
}
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_user_input_args.sample_rate / 1000;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_FALSE;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
ai_vqe_attr vqe_detect_attr;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
//开启检测算法
|
||||
if (g_vqe_type != 0) {
|
||||
load_ai_detect_attr(&vqe_detect_attr);
|
||||
ret = sample_comm_ai_register(ai_detect_attr.mask, vqe_detect_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
ret = sample_comm_detect_open(g_ai_config.dev, &vqe_detect_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_bcd_open");
|
||||
}
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_create_output_thread_to_file(&g_ai_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_output_thread_to_file");
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_set_dev_param");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
ret = sample_comm_ai_destroy_output_thread_to_file(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_output_thread_to_file");
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_audio_record_detect(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ai vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ai vol\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'saXX' to set adc gain to xx dB\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v' ) {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'v') {
|
||||
ret = sample_comm_ai_get_volume(&g_ai_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'a') {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'a') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [samplerate] [usr_samplerate] [channels] [codec_input_vol] [outfile] [vqe_type]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("dev_rate: dev samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("usr_rate: out file samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("dev_chn: dev chn cnt(1/2/8)\n");
|
||||
SAMPLE_AUDIO_DBG("codec_input_vol: adc input volume, range:[-95~48]\n");
|
||||
SAMPLE_AUDIO_DBG("out_file: pcm out file(.pcm)\n");
|
||||
SAMPLE_AUDIO_DBG("vqe_type: 0:not open detect, 1:open bcd, 2:open gbd, 3:open ssl, 4:open ved, 5:open bcd + ssl + ved\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 1 20 out.pcm 0\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 1 20 out.pcm 1\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 1 20 out.pcm 2\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 2 20 out.pcm 3\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 2 20 out.pcm 4\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 2 20 out.pcm 5\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 7) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->sample_rate = atoi(argv[1]);
|
||||
user_in_args->usr_sample_rate = atoi(argv[2]);
|
||||
user_in_args->channels = atoi(argv[3]);
|
||||
user_in_args->codec_input_vol = atoi(argv[4]);
|
||||
memcpy(user_in_args->output_file_name, argv[5], strlen(argv[5]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
g_vqe_type = atoi(argv[6]);
|
||||
if (g_vqe_type < 0 || g_vqe_type > 5) {
|
||||
printf("Invalid det_type:%d\n", g_vqe_type);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" samplerate: %d\n", user_in_args->sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" user samplerate: %d\n", user_in_args->usr_sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" chnnels: %d\n", user_in_args->channels);
|
||||
SAMPLE_AUDIO_DBG(" codec_input_vol: %d\n", user_in_args->codec_input_vol);
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_record_detect();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_audio_record_vqev1 failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Executable
+473
@@ -0,0 +1,473 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v1.h"
|
||||
#include "xmedia_audio_vqe_detect.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
#define CRY_ALARMLIMIT 80 // probability greater than which to count as one cry frame
|
||||
#define CRY_TIMELIMITCNT 3 // number of cry frame count as one cry event
|
||||
#define CRY_TIMELIMIT 5 // time interval to report cry event
|
||||
#define CRY_ALARMINTERVAL 3 // alarm interval time to unfreeze
|
||||
|
||||
#define GBD_TIMELIMIT 100 // time interval to report gbd event
|
||||
#define GBD_TIMELIMITCNT 1 // number of gbd frame count as one gbd event
|
||||
#define GBD_ALARMLIMIT 70 // probability greater than which to count as one gbd frame
|
||||
#define GBD_ALARMINTERVAL 3 // alarm interval time to unfreeze
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_bool binder_mode;
|
||||
xmedia_s32 codec_input_vol;
|
||||
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static sample_aenc_config g_aenc_config;
|
||||
static ai_vqe_attr_v1 ai_vqev1_attr;
|
||||
static ai_vqe_attr_detect ai_detect_attr;
|
||||
static xmedia_u32 g_vqe_type;
|
||||
|
||||
static xmedia_s32 cry_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("cry callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 gbd_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("gbd callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ved_callback(xmedia_void* private, xmedia_bool is_event, xmedia_bool is_mutation, xmedia_s32 out_db)
|
||||
{
|
||||
if (is_event) {
|
||||
printf("volume event detect out_db = %d\n",out_db);
|
||||
}
|
||||
if (is_mutation) {
|
||||
printf("volume mutation detect out_db = %d\n", out_db);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_vqev1_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_v1 *vqev1_attr = &ai_vqev1_attr;
|
||||
|
||||
attr->version = AI_VQE_ENHANCE_ATTR_VERSION_1;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = 1;
|
||||
attr->attr = (xmedia_void*)&ai_vqev1_attr;
|
||||
vqev1_attr->mask = VQE_V1_MASK_AEC|VQE_V1_MASK_AGC|VQE_V1_MASK_ANR|VQE_V1_MASK_VAD|VQE_V1_MASK_HPF|VQE_V1_MASK_WNS;
|
||||
|
||||
|
||||
vqev1_attr->agc_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->agc_attr.target_level = -6;
|
||||
vqev1_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev1_attr->agc_attr.noise_floor = -100;
|
||||
vqev1_attr->agc_attr.ratio = 12;
|
||||
vqev1_attr->agc_attr.attack_time = 8;
|
||||
vqev1_attr->agc_attr.release_time =20;
|
||||
|
||||
vqev1_attr->anr_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->anr_attr.usr_scene = VQE_V1_ANR_SCENE_NORMAL;
|
||||
vqev1_attr->anr_attr.nr_mode = VQE_V1_NR_MODE_SPEECH;
|
||||
vqev1_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev1_attr->anr_attr.suppress_level = 0x2;
|
||||
vqev1_attr->anr_attr.nonstationary_suppress_level = 0x0;
|
||||
|
||||
vqev1_attr->vad_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->vad_attr.sensitivity_level = 4;
|
||||
|
||||
vqev1_attr->hpf_attr.mode = VQE_V1_USR_MODE_AUTO;
|
||||
vqev1_attr->hpf_attr.freq = VQE_V1_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev1_attr->eq_attr, 0, sizeof(vqe_eq_attr_v1));
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_detect_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_detect* detect_attr = &ai_detect_attr;
|
||||
|
||||
attr->version = AI_VQE_DETECT_ATTR_VERSION_1;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = g_ai_config.dev_attr.channels;
|
||||
|
||||
if (g_vqe_type == 1) {
|
||||
attr->work_sample_rate = AUDIO_SAMPLE_RATE_16000; //bcd只支持16K
|
||||
detect_attr->mask =VQE_DETECT_MASK_BCD;
|
||||
} else if (g_vqe_type == 2) {
|
||||
if (attr->work_sample_rate == AUDIO_SAMPLE_RATE_16000) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
detect_attr->mask = VQE_DETECT_MASK_GBD;
|
||||
} else if (g_vqe_type == 3) {
|
||||
detect_attr->mask = VQE_DETECT_MASK_BCD | VQE_DETECT_MASK_HPF | VQE_DETECT_MASK_VED;
|
||||
}
|
||||
detect_attr->hpf_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->hpf_attr.freq = VQE_DETECT_HPF_FREQ_80;
|
||||
|
||||
detect_attr->bcd_attr.usr_mode = XMEDIA_TRUE;
|
||||
detect_attr->bcd_attr.bypass = XMEDIA_FALSE;
|
||||
detect_attr->bcd_attr.alarm_threshold = CRY_ALARMLIMIT;
|
||||
detect_attr->bcd_attr.time_limit = CRY_TIMELIMIT;
|
||||
detect_attr->bcd_attr.time_limit_threshold_count = CRY_TIMELIMITCNT;
|
||||
detect_attr->bcd_attr.interval_time = CRY_ALARMINTERVAL;
|
||||
/*just for npu bcd lib*/
|
||||
detect_attr->bcd_attr.bcd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr->bcd_attr.bcd_model.model_info.file.pathname = "./audio_xmm/bcd_neuron_network.xmm";
|
||||
detect_attr->bcd_attr.callback = (fn_bcd_callback)cry_callback;
|
||||
|
||||
detect_attr->ved_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->ved_attr.volume_threshold = -15;
|
||||
detect_attr->ved_attr.mutation_flag = 1;
|
||||
detect_attr->ved_attr.fast_change_threshold = 15;
|
||||
detect_attr->ved_attr.slow_change_threshold = 8;
|
||||
detect_attr->ved_attr.callback = (fn_detect_ved_callback)ved_callback;
|
||||
|
||||
detect_attr->gbd_attr.usr_mode = XMEDIA_TRUE;
|
||||
detect_attr->gbd_attr.bypass = XMEDIA_FALSE;
|
||||
detect_attr->gbd_attr.alarm_threshold = GBD_ALARMLIMIT;
|
||||
detect_attr->gbd_attr.time_limit = GBD_TIMELIMIT;
|
||||
detect_attr->gbd_attr.time_limit_threshold_count = GBD_TIMELIMITCNT;
|
||||
detect_attr->gbd_attr.interval_time = GBD_ALARMINTERVAL;
|
||||
/*just for npu gbd lib*/
|
||||
detect_attr->gbd_attr.gbd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr->gbd_attr.gbd_model.model_info.file.pathname = "./audio_xmm/gbd_neuron_network.xmm";
|
||||
detect_attr->gbd_attr.callback = (fn_detect_gbd_callback)gbd_callback;
|
||||
attr->attr = (xmedia_void*)&ai_detect_attr;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_user_input_args.sample_rate / 1000;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
load_ai_vqev1_attr(&g_ai_config.vqe_attr);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_aenc_config_init(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
ret = sample_comm_get_codec_info(g_user_input_args.output_file_name, &type, &format);
|
||||
CHECK_RET(ret, "sample_comm_get_codec_info");
|
||||
|
||||
g_aenc_config.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_aenc_config.channels = g_user_input_args.channels;
|
||||
g_aenc_config.bit_depth = 16;
|
||||
g_aenc_config.chn = 0;
|
||||
g_aenc_config.type = type;
|
||||
g_aenc_config.format = format;
|
||||
g_aenc_config.binder_dev = g_ai_config.dev;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_aenc_config.binder_src = MOD_ID_AI;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
ai_vqe_attr vqe_detect_attr;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_register(ai_vqev1_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
//开启检测算法
|
||||
if (g_vqe_type != 0) {
|
||||
load_ai_detect_attr(&vqe_detect_attr);
|
||||
ret = sample_comm_ai_register(ai_detect_attr.mask, vqe_detect_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
ret = sample_comm_detect_open(g_ai_config.dev, &vqe_detect_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_bcd_open");
|
||||
}
|
||||
}
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_create_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_data_thread");
|
||||
}
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_set_dev_param");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_aenc_config_init();
|
||||
CHECK_RET(ret, "sample_aenc_config_init");
|
||||
|
||||
ret = sample_comm_aenc_register(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_aenc_start(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_start");
|
||||
|
||||
ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_data_thread");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_data_thread");
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_out_to_file_thread");
|
||||
|
||||
ret = sample_comm_aenc_stop(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_stop");
|
||||
|
||||
ret = sample_comm_aenc_unregister(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_aenc_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
xmedia_s32 sample_audio_record_vqev1(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
ret = sample_start_aenc();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AENC;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ai vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ai vol\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'saXX' to set adc gain to xx dB\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v' ) {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'v') {
|
||||
ret = sample_comm_ai_get_volume(&g_ai_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'a') {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'a') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_aenc();
|
||||
ERR_START_AENC:
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [samplerate] [usr_samplerate] [binder_mode] [codec_input_vol] [outfile] [vqe_type]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("dev_rate: dev samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("usr_rate: out file samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("mode: binder mode(0/1)\n");
|
||||
SAMPLE_AUDIO_DBG("codec_input_vol: adc input volume, range:[-95~48]\n");
|
||||
SAMPLE_AUDIO_DBG("out_file: aenc encoder out file(.g711a/.g711u/.g726/.aac/.mp3/.pcm/.adpcm)\n");
|
||||
SAMPLE_AUDIO_DBG("vqe_type: 0:only open vqe v1, 1:open v1 + bcd, 2:open v1 + gbd, 3:open v1 + bcd + ved\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 1 20 out.g711a 0\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 1 20 out.g711a 1\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 1 20 out.g711a 2\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 1 20 out.g711a 3\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 7) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->sample_rate = atoi(argv[1]);
|
||||
user_in_args->usr_sample_rate = atoi(argv[2]);
|
||||
user_in_args->channels = AUDIO_CHANNEL_1;
|
||||
user_in_args->binder_mode = (atoi(argv[3]) == 0 ? XMEDIA_FALSE : XMEDIA_TRUE);
|
||||
user_in_args->codec_input_vol = atoi(argv[4]);
|
||||
memcpy(user_in_args->output_file_name, argv[5], strlen(argv[5]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
g_vqe_type = atoi(argv[6]);
|
||||
if (g_vqe_type < 0 || g_vqe_type > 3) {
|
||||
printf("Invalid det_type:%d\n", g_vqe_type);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" samplerate: %d\n", user_in_args->sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" user samplerate: %d\n", user_in_args->usr_sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" codec_input_vol: %d\n", user_in_args->codec_input_vol);
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_record_vqev1();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_audio_record_vqev1 failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Executable
+498
@@ -0,0 +1,498 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v2.h"
|
||||
#include "xmedia_audio_vqe_detect.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
#define CRY_ALARMLIMIT 80 // probability greater than which to count as one cry frame
|
||||
#define CRY_TIMELIMITCNT 3 // number of cry frame count as one cry event
|
||||
#define CRY_TIMELIMIT 5 // time interval to report cry event
|
||||
#define CRY_ALARMINTERVAL 3 // alarm interval time to unfreeze
|
||||
|
||||
#define GBD_TIMELIMIT 100 // time interval to report gbd event
|
||||
#define GBD_TIMELIMITCNT 1 // number of gbd frame count as one gbd event
|
||||
#define GBD_ALARMLIMIT 70 // probability greater than which to count as one gbd frame
|
||||
#define GBD_ALARMINTERVAL 3 // alarm interval time to unfreeze
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_bool binder_mode;
|
||||
xmedia_s32 codec_input_vol;
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static sample_aenc_config g_aenc_config;
|
||||
static ai_vqe_attr_v2 ai_vqev2_attr;
|
||||
static ai_vqe_attr_detect ai_detect_attr;
|
||||
static xmedia_u32 g_vqe_type;
|
||||
|
||||
static xmedia_s32 cry_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("cry callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 gbd_callback(xmedia_void *attr)
|
||||
{
|
||||
static xmedia_s32 count = 0;
|
||||
printf("gbd callback count(%d)\n" ,count++);
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ssl_callback(xmedia_void* attr, xmedia_s32 out)
|
||||
{
|
||||
static xmedia_s32 ssl_out = 0;
|
||||
static xmedia_s32 call_times = 0;
|
||||
call_times++;
|
||||
|
||||
if (ssl_out != out) {
|
||||
printf("attr(0x%x), call_times(%d), out_angle(%d)\n", (xmedia_u32)attr, call_times, out);
|
||||
}
|
||||
ssl_out = out;
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 ved_callback(xmedia_void* private, xmedia_bool is_event, xmedia_bool is_mutation, xmedia_s32 out_db)
|
||||
{
|
||||
if (is_event) {
|
||||
printf("volume event detect out_db = %d\n",out_db);
|
||||
}
|
||||
if (is_mutation) {
|
||||
printf("volume mutation detect out_db = %d\n", out_db);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_vqev2_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_v2 *vqev2_attr = &ai_vqev2_attr;
|
||||
|
||||
attr->version = AI_VQE_ENHANCE_ATTR_VERSION_2;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = 2;
|
||||
attr->attr = (xmedia_void*)&ai_vqev2_attr;
|
||||
vqev2_attr->mask = VQE_V2_MASK_AGC | VQE_V2_MASK_ANR | VQE_V2_MASK_HPF | VQE_V2_MASK_BF;
|
||||
|
||||
vqev2_attr->aec_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->aec_attr.cng_enable = XMEDIA_TRUE;
|
||||
vqev2_attr->aec_attr.freq_boundary = 1800;
|
||||
vqev2_attr->aec_attr.low_suppress_level = 0x7;
|
||||
vqev2_attr->aec_attr.high_suppress_level = 0x5;
|
||||
|
||||
vqev2_attr->agc_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->agc_attr.target_level = -6;
|
||||
vqev2_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev2_attr->agc_attr.noise_floor = -100;
|
||||
vqev2_attr->agc_attr.ratio = 12;
|
||||
vqev2_attr->agc_attr.attack_time = 8;
|
||||
vqev2_attr->agc_attr.release_time = 20;
|
||||
|
||||
vqev2_attr->anr_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->anr_attr.usr_scene = VQE_V2_ANR_SCENE_NORMAL;
|
||||
vqev2_attr->anr_attr.nr_mode = VQE_V2_NR_MODE_SPEECH;
|
||||
vqev2_attr->anr_attr.max_suppress_gain = 6;
|
||||
vqev2_attr->anr_attr.suppress_level = 0x2;
|
||||
vqev2_attr->anr_attr.nonstationary_suppress_level = 0x0;
|
||||
|
||||
vqev2_attr->bf_attr.reserved = 0;
|
||||
|
||||
vqev2_attr->vad_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->vad_attr.sensitivity_level = 5;
|
||||
|
||||
vqev2_attr->hpf_attr.mode = VQE_V2_USR_MODE_AUTO;
|
||||
vqev2_attr->hpf_attr.freq = VQE_V2_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev2_attr->eq_attr, 0, sizeof(vqe_eq_attr_v2));
|
||||
}
|
||||
|
||||
static xmedia_void load_ai_detect_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_detect* detect_attr = &ai_detect_attr;
|
||||
|
||||
attr->version = AI_VQE_DETECT_ATTR_VERSION_1;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = g_ai_config.dev_attr.channels;
|
||||
|
||||
if (g_vqe_type == 1) {
|
||||
attr->work_sample_rate = AUDIO_SAMPLE_RATE_16000; //bcd只支持16K
|
||||
detect_attr->mask = VQE_DETECT_MASK_BCD;
|
||||
} else if (g_vqe_type == 2) {
|
||||
if (attr->work_sample_rate == AUDIO_SAMPLE_RATE_16000) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
detect_attr->mask =VQE_DETECT_MASK_GBD;
|
||||
} else if (g_vqe_type == 3) {
|
||||
detect_attr->mask = VQE_DETECT_MASK_HPF | VQE_DETECT_MASK_BCD | VQE_DETECT_MASK_VED | VQE_DETECT_MASK_SSL;
|
||||
}
|
||||
detect_attr->hpf_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->hpf_attr.freq = VQE_DETECT_HPF_FREQ_80;
|
||||
|
||||
detect_attr->bcd_attr.usr_mode = XMEDIA_TRUE;
|
||||
detect_attr->bcd_attr.bypass = XMEDIA_FALSE;
|
||||
detect_attr->bcd_attr.alarm_threshold = CRY_ALARMLIMIT;
|
||||
detect_attr->bcd_attr.time_limit = CRY_TIMELIMIT;
|
||||
detect_attr->bcd_attr.time_limit_threshold_count = CRY_TIMELIMITCNT;
|
||||
detect_attr->bcd_attr.interval_time = CRY_ALARMINTERVAL;
|
||||
/*just for npu bcd lib*/
|
||||
detect_attr->bcd_attr.bcd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr->bcd_attr.bcd_model.model_info.file.pathname = "./audio_xmm/bcd_neuron_network.xmm";
|
||||
detect_attr->bcd_attr.callback = (fn_bcd_callback)cry_callback;
|
||||
|
||||
detect_attr->ssl_attr.mic_distance = 50;
|
||||
detect_attr->ssl_attr.sensitivity_level = 5;
|
||||
detect_attr->ssl_attr.shape = 0;
|
||||
detect_attr->ssl_attr.callback = (fn_detect_ssl_callback)ssl_callback;
|
||||
detect_attr->ssl_attr.private_data = (xmedia_void*)0x12345678;
|
||||
|
||||
detect_attr->ved_attr.mode = VQE_DET_USR_MODE_AUTO;
|
||||
detect_attr->ved_attr.volume_threshold = -15;
|
||||
detect_attr->ved_attr.mutation_flag = 1;
|
||||
detect_attr->ved_attr.fast_change_threshold = 15;
|
||||
detect_attr->ved_attr.slow_change_threshold = 8;
|
||||
detect_attr->ved_attr.callback = (fn_detect_ved_callback)ved_callback;
|
||||
|
||||
detect_attr->gbd_attr.usr_mode = XMEDIA_TRUE;
|
||||
detect_attr->gbd_attr.bypass = XMEDIA_FALSE;
|
||||
detect_attr->gbd_attr.alarm_threshold = GBD_ALARMLIMIT;
|
||||
detect_attr->gbd_attr.time_limit = GBD_TIMELIMIT;
|
||||
detect_attr->gbd_attr.time_limit_threshold_count = GBD_TIMELIMITCNT;
|
||||
detect_attr->gbd_attr.interval_time = GBD_ALARMINTERVAL;
|
||||
/*just for npu gbd lib*/
|
||||
detect_attr->gbd_attr.gbd_model.load_type = XMEDIA_CL_LOAD_FILE;
|
||||
detect_attr->gbd_attr.gbd_model.model_info.file.pathname = "./audio_xmm/gbd_neuron_network.xmm";
|
||||
detect_attr->gbd_attr.callback = (fn_detect_gbd_callback)gbd_callback;
|
||||
attr->attr = (xmedia_void*)&ai_detect_attr;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_user_input_args.sample_rate / 1000;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
load_ai_vqev2_attr(&g_ai_config.vqe_attr);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_aenc_config_init(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
ret = sample_comm_get_codec_info(g_user_input_args.output_file_name, &type, &format);
|
||||
CHECK_RET(ret, "sample_comm_get_codec_info");
|
||||
|
||||
g_aenc_config.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_aenc_config.channels = 1; // ai open vqev2
|
||||
g_aenc_config.bit_depth = 16;
|
||||
g_aenc_config.chn = 0;
|
||||
g_aenc_config.type = type;
|
||||
g_aenc_config.format = format;
|
||||
g_aenc_config.binder_dev = g_ai_config.dev;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_aenc_config.binder_src = MOD_ID_AI;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
ai_vqe_attr vqe_detect_attr;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_register(ai_vqev2_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
//开启检测算法
|
||||
if (g_vqe_type != 0) {
|
||||
load_ai_detect_attr(&vqe_detect_attr);
|
||||
ret = sample_comm_ai_register(ai_detect_attr.mask, vqe_detect_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
ret = sample_comm_detect_open(g_ai_config.dev, &vqe_detect_attr);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_bcd_open");
|
||||
}
|
||||
}
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_create_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_data_thread");
|
||||
}
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_set_dev_param");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_aenc_config_init();
|
||||
CHECK_RET(ret, "sample_aenc_config_init");
|
||||
|
||||
ret = sample_comm_aenc_register(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_aenc_start(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_start");
|
||||
|
||||
ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_data_thread");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_data_thread");
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_out_to_file_thread");
|
||||
|
||||
ret = sample_comm_aenc_stop(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_stop");
|
||||
|
||||
ret = sample_comm_aenc_unregister(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_aenc_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmedia_s32 sample_audio_record_vqev2(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
ret = sample_start_aenc();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AENC;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ai vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ai vol\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'saXX' to set adc gain to xx dB\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v' ) {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'v') {
|
||||
ret = sample_comm_ai_get_volume(&g_ai_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'a') {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'a') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_aenc();
|
||||
ERR_START_AENC:
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [samplerate] [usr_samplerate] [binder_mode] [codec_input_vol] [outfile] [vqe_type]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("dev_rate: dev samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("usr_rate: out file samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("mode: binder mode(0/1)\n");
|
||||
SAMPLE_AUDIO_DBG("codec_input_vol: adc input volume, range:[-95~48]\n");
|
||||
SAMPLE_AUDIO_DBG("out_file: aenc encoder out file(.g711a/.g711u/.g726/.aac/.mp3/.pcm/.adpcm)\n");
|
||||
SAMPLE_AUDIO_DBG("vqe_type: 0:only open vqe v2, 1:open v2 + bcd, 2:open v2 + gbd, 3:open v2 + bcd + ved + ssl\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 1 20 out.g711a 0\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 1 20 out.g711a 1\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 8000 8000 1 20 out.g711a 2\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 1 20 out.g711a 3\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 7) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->sample_rate = atoi(argv[1]);
|
||||
user_in_args->usr_sample_rate = atoi(argv[2]);
|
||||
user_in_args->channels = AUDIO_CHANNEL_2;
|
||||
user_in_args->binder_mode = (atoi(argv[3]) == 0 ? XMEDIA_FALSE : XMEDIA_TRUE);
|
||||
user_in_args->codec_input_vol = atoi(argv[4]);
|
||||
memcpy(user_in_args->output_file_name, argv[5], strlen(argv[5]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
g_vqe_type = atoi(argv[6]);
|
||||
if (g_vqe_type < 0 || g_vqe_type > 3) {
|
||||
printf("Invalid det_type:%d\n", g_vqe_type);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" samplerate: %d\n", user_in_args->sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" user samplerate: %d\n", user_in_args->usr_sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" codec_input_vol: %d\n", user_in_args->codec_input_vol);
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[1] != NULL) {
|
||||
fclose(user_in_args->output_fd[1]);
|
||||
user_in_args->output_fd[1] = NULL;
|
||||
}
|
||||
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_record_vqev2();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_audio_record_vqev2 failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Executable
+347
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
//#include "sample_comm.h"
|
||||
#include "xmedia_audio_common.h"
|
||||
#include "xmedia_audio_ai.h"
|
||||
#include "xmedia_audio_vqe.h"
|
||||
#include "xmedia_audio_vqe_enhance_v3.h"
|
||||
|
||||
#include "sample_comm_audio.h"
|
||||
|
||||
#define SAMPLE_AUDIO_DBG printf
|
||||
#define MAX_FILE_NAME_LEN 128
|
||||
#define FRAME_TIME 10 //ms
|
||||
|
||||
typedef struct user_input_args {
|
||||
xmedia_char* sample;
|
||||
audio_sample_rate sample_rate;
|
||||
audio_sample_rate usr_sample_rate;
|
||||
audio_channel channels;
|
||||
xmedia_bool binder_mode;
|
||||
xmedia_s32 codec_input_vol;
|
||||
char output_file_name[MAX_FILE_NAME_LEN];
|
||||
FILE *output_fd[2];
|
||||
} user_input_args;
|
||||
|
||||
static user_input_args g_user_input_args;
|
||||
static sample_ai_config g_ai_config;
|
||||
static sample_aenc_config g_aenc_config;
|
||||
static ai_vqe_attr_v3 ai_vqev3_attr;
|
||||
|
||||
static xmedia_void load_ai_vqev3_attr(ai_vqe_attr* attr)
|
||||
{
|
||||
ai_vqe_attr_v3 *vqev3_attr = &ai_vqev3_attr;
|
||||
|
||||
attr->version = AI_VQE_ENHANCE_ATTR_VERSION_3;
|
||||
attr->work_sample_rate = (g_user_input_args.sample_rate == AUDIO_SAMPLE_RATE_8000) ? AUDIO_SAMPLE_RATE_8000 : AUDIO_SAMPLE_RATE_16000;
|
||||
attr->in_channels = 1;
|
||||
attr->attr = (xmedia_void*)&ai_vqev3_attr;
|
||||
vqev3_attr->mask = VQE_V3_MASK_AGC | VQE_V3_MASK_ANR | VQE_V3_MASK_HPF;
|
||||
|
||||
vqev3_attr->agc_attr.mode = VQE_V3_USR_MODE_AUTO;
|
||||
vqev3_attr->agc_attr.target_level = -6;
|
||||
vqev3_attr->agc_attr.max_boost_gain = 20;
|
||||
vqev3_attr->agc_attr.noise_floor = -100;
|
||||
vqev3_attr->agc_attr.ratio = 12;
|
||||
vqev3_attr->agc_attr.attack_time = 8;
|
||||
vqev3_attr->agc_attr.release_time = 20;
|
||||
|
||||
vqev3_attr->anr_attr.mode = VQE_V3_USR_MODE_AUTO;
|
||||
|
||||
vqev3_attr->hpf_attr.mode = VQE_V3_USR_MODE_AUTO;
|
||||
vqev3_attr->hpf_attr.freq = VQE_V3_HPF_FREQ_80;
|
||||
|
||||
memset(&vqev3_attr->eq_attr, 0, sizeof(vqe_eq_attr_v3));
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_ai_config_init(xmedia_void)
|
||||
{
|
||||
g_ai_config.dev = XMEDIA_AI_DEV_ADC0;
|
||||
|
||||
sample_comm_ai_get_default_attr(g_ai_config.dev, &g_ai_config.dev_attr);
|
||||
g_ai_config.dev_attr.channels = g_user_input_args.channels;
|
||||
g_ai_config.dev_attr.sample_rate = g_user_input_args.sample_rate;
|
||||
g_ai_config.dev_attr.pcm_samples_per_frame = FRAME_TIME * g_user_input_args.sample_rate / 1000;
|
||||
g_ai_config.dev_attr.mode = AUDIO_DEV_WORK_MODE_QUEUE;
|
||||
g_ai_config.chn_attr.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_ai_config.source = AI_EC_SOURCE_AO_DAC0;
|
||||
g_ai_config.ec_chn_id = 0;
|
||||
g_ai_config.vqe_enable = XMEDIA_TRUE;
|
||||
g_ai_config.res_enable = XMEDIA_FALSE;
|
||||
if ((g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_8000 && g_ai_config.dev_attr.sample_rate != AUDIO_SAMPLE_RATE_16000)
|
||||
|| (g_ai_config.chn_attr.sample_rate != g_ai_config.dev_attr.sample_rate)) {
|
||||
g_ai_config.res_enable = XMEDIA_TRUE;
|
||||
}
|
||||
load_ai_vqev3_attr(&g_ai_config.vqe_attr);
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_aenc_config_init(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
voice_format format = VOICE_FORMAT_G711_A;
|
||||
audio_codec_type type = CODEC_TYPE_G711;
|
||||
|
||||
ret = sample_comm_get_codec_info(g_user_input_args.output_file_name, &type, &format);
|
||||
CHECK_RET(ret, "sample_comm_get_codec_info");
|
||||
|
||||
g_aenc_config.sample_rate = g_user_input_args.usr_sample_rate;
|
||||
g_aenc_config.channels = 1; // ai open vqev3
|
||||
g_aenc_config.bit_depth = 16;
|
||||
g_aenc_config.chn = 0;
|
||||
g_aenc_config.type = type;
|
||||
g_aenc_config.format = format;
|
||||
g_aenc_config.binder_dev = g_ai_config.dev;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_TRUE) {
|
||||
g_aenc_config.binder_src = MOD_ID_AI;
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_init_audio()
|
||||
{
|
||||
return sample_comm_audio_init();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_ai_config_init();
|
||||
CHECK_RET(ret, "sample_ai_config_init");
|
||||
|
||||
ret = sample_comm_ai_register(ai_vqev3_attr.mask, g_ai_config.vqe_attr.version, g_ai_config.res_enable);
|
||||
CHECK_RET(ret, "sample_comm_ai_register");
|
||||
|
||||
ret = sample_comm_ai_start(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_start");
|
||||
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_create_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_create_data_thread");
|
||||
}
|
||||
|
||||
if (g_ai_config.dev == XMEDIA_AI_DEV_ADC0) {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&g_user_input_args.codec_input_vol);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_set_dev_param");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_start_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_aenc_config_init();
|
||||
CHECK_RET(ret, "sample_aenc_config_init");
|
||||
|
||||
ret = sample_comm_aenc_register(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_adec_register");
|
||||
|
||||
ret = sample_comm_aenc_start(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_start");
|
||||
|
||||
ret = sample_comm_aenc_create_output_thread_to_file(&g_aenc_config, g_user_input_args.output_fd);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_data_thread");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_deinit_audio()
|
||||
{
|
||||
return sample_comm_audio_exit();
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_ai()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
if (g_user_input_args.binder_mode == XMEDIA_FALSE) {
|
||||
ret = sample_comm_ai_destroy_output_thread_to_aenc(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_destroy_data_thread");
|
||||
}
|
||||
|
||||
ret = sample_comm_ai_stop(&g_ai_config);
|
||||
CHECK_RET(ret, "sample_comm_ai_stop");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_s32 sample_stop_aenc()
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_comm_aenc_destroy_output_thread_to_file(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_create_out_to_file_thread");
|
||||
|
||||
ret = sample_comm_aenc_stop(&g_aenc_config);
|
||||
CHECK_RET(ret, "sample_comm_aenc_stop");
|
||||
|
||||
ret = sample_comm_aenc_unregister(g_aenc_config.type);
|
||||
CHECK_RET(ret, "sample_comm_aenc_unregister");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
xmedia_s32 sample_audio_record_vqev3(xmedia_void)
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = sample_init_audio();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_INIT_AUDIO;
|
||||
}
|
||||
|
||||
ret = sample_start_ai();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AI;
|
||||
}
|
||||
|
||||
ret = sample_start_aenc();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
goto ERR_START_AENC;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
xmedia_s32 val;
|
||||
xmedia_char input_cmd[32];
|
||||
SAMPLE_AUDIO_DBG("\nInput 'q' ENTER to exit\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'svXX' to set ai vol to xx dB\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'gv' to get ai vol\n");
|
||||
SAMPLE_AUDIO_DBG("Input 'saXX' to set adc gain to xx dB\n");
|
||||
|
||||
fgets(input_cmd, (sizeof(input_cmd) - 1), stdin);
|
||||
if (input_cmd[0] == 's' && input_cmd[1] == 'v' ) {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_volume(&g_ai_config, val);
|
||||
SAMPLE_AUDIO_DBG("\nSet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'v') {
|
||||
ret = sample_comm_ai_get_volume(&g_ai_config, &val);
|
||||
SAMPLE_AUDIO_DBG("\nGet ai volume %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 's' && input_cmd[1] == 'a') {
|
||||
val = atoi(input_cmd + 2);
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_SET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nSet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if (input_cmd[0] == 'g' && input_cmd[1] == 'a') {
|
||||
ret = sample_comm_ai_set_dev_param(&g_ai_config, AI_PARAM_GET_CODEC_ADC_GAIN, (xmedia_void*)&val);
|
||||
SAMPLE_AUDIO_DBG("\nGet adc gain %d return 0x%x\n", val, ret);
|
||||
} else if ((input_cmd[0] == 'q') || (input_cmd[0] == 'Q')) {
|
||||
SAMPLE_AUDIO_DBG("Ready to exit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sample_stop_aenc();
|
||||
ERR_START_AENC:
|
||||
sample_stop_ai();
|
||||
ERR_START_AI:
|
||||
ERR_INIT_AUDIO:
|
||||
sample_deinit_audio();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_usage(user_input_args* args)
|
||||
{
|
||||
SAMPLE_AUDIO_DBG("usage: %s [samplerate] [usr_samplerate] [binder_mode] [codec_input_vol] [outfile]\n", args->sample);
|
||||
SAMPLE_AUDIO_DBG("dev_rate: dev samplerate(16000)\n");
|
||||
SAMPLE_AUDIO_DBG("usr_rate: out file samplerate(8000/16000/32000/48000)\n");
|
||||
SAMPLE_AUDIO_DBG("mode: binder mode(0/1)\n");
|
||||
SAMPLE_AUDIO_DBG("codec_input_vol: adc input volume, range:[-95~48]\n");
|
||||
SAMPLE_AUDIO_DBG("out_file: aenc encoder out file(.g711a/.g711u/.g726/.aac/.mp3/.pcm/.adpcm)\n");
|
||||
|
||||
SAMPLE_AUDIO_DBG("examples:\n");
|
||||
SAMPLE_AUDIO_DBG(" %s 16000 16000 1 20 out.g711a\n", args->sample);
|
||||
}
|
||||
|
||||
static xmedia_s32 user_args_init(int argc, char* argv[], user_input_args* user_in_args)
|
||||
{
|
||||
user_in_args->sample = argv[0];
|
||||
|
||||
if ((argc >= 2) && (strcmp(argv[1], "-h")) == 0) {
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 6) {
|
||||
printf("Invalid argc:%d\n", argc);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
|
||||
user_in_args->sample_rate = atoi(argv[1]);
|
||||
if (user_in_args->sample_rate != AUDIO_SAMPLE_RATE_16000) {
|
||||
printf("Invalid dev sample_rate:%d\n", user_in_args->sample_rate);
|
||||
user_args_usage(user_in_args);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
user_in_args->usr_sample_rate = atoi(argv[2]);
|
||||
user_in_args->channels = AUDIO_CHANNEL_1;
|
||||
user_in_args->binder_mode = (atoi(argv[3]) == 0 ? XMEDIA_FALSE : XMEDIA_TRUE);
|
||||
user_in_args->codec_input_vol = atoi(argv[4]);
|
||||
memcpy(user_in_args->output_file_name, argv[5], strlen(argv[5]));
|
||||
if (strcmp(user_in_args->output_file_name, "null")) {
|
||||
user_in_args->output_fd[0] = fopen(user_in_args->output_file_name, "w+");
|
||||
if (user_in_args->output_fd[0] == NULL) {
|
||||
printf("Open %s failed\n", user_in_args->output_file_name);
|
||||
return XMEDIA_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
SAMPLE_AUDIO_DBG("get user args: \n");
|
||||
SAMPLE_AUDIO_DBG(" samplerate: %d\n", user_in_args->sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" user samplerate: %d\n", user_in_args->usr_sample_rate);
|
||||
SAMPLE_AUDIO_DBG(" codec_input_vol: %d\n", user_in_args->codec_input_vol);
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
SAMPLE_AUDIO_DBG(" mic0_file_name:%s\n", user_in_args->output_file_name);
|
||||
}
|
||||
|
||||
return XMEDIA_SUCCESS;
|
||||
}
|
||||
|
||||
static xmedia_void user_args_deinit(user_input_args* user_in_args)
|
||||
{
|
||||
if (user_in_args->output_fd[0] != NULL) {
|
||||
fclose(user_in_args->output_fd[0]);
|
||||
user_in_args->output_fd[0] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xmedia_s32 main(int argc, char* argv[])
|
||||
{
|
||||
xmedia_s32 ret;
|
||||
|
||||
ret = user_args_init(argc, argv, &g_user_input_args);
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("user_args_init failed(0x%x)\n\n", ret);
|
||||
return ret;
|
||||
}
|
||||
SAMPLE_AUDIO_DBG("user_args_init ok\n");
|
||||
|
||||
ret = sample_audio_record_vqev3();
|
||||
if (ret != XMEDIA_SUCCESS) {
|
||||
printf("sample_audio_record_vqev3 failed(0x%x)\n", ret);
|
||||
}
|
||||
|
||||
user_args_deinit(&g_user_input_args);
|
||||
SAMPLE_AUDIO_DBG("exit %s\n", g_user_input_args.sample);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user