You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
4.3 KiB
165 lines
4.3 KiB
#include <iostream>
|
|
#include <string>
|
|
|
|
#include "zlinuxcomponents/zmainhelper.hpp"
|
|
//
|
|
#include "configs/gconfig.hpp"
|
|
#include "iflytopcpp/core/spdlogfactory/logger.hpp"
|
|
#include "iflytopcpp/core/thread/thread.hpp"
|
|
#include "spdlog/spdlog.h"
|
|
#include "version.hpp"
|
|
#include "zlinuxcomponents/rootfs_auto_update/rootfs_auto_update.hpp"
|
|
#include "zservice_container/zservice_container.hpp"
|
|
//
|
|
#include "service/device_io_service.hpp"
|
|
#include "service/device_io_service_mock.hpp"
|
|
#include "service/light_control_service.hpp"
|
|
#include "service/report_service.hpp"
|
|
#include "zlinuxcomponents/aiui_ws/aiui_service.hpp"
|
|
|
|
//
|
|
|
|
#include "zlinuxcomponents/aiui_ws/aiui.h"
|
|
//
|
|
#include "audio_process_api.h"
|
|
ZMAIN();
|
|
|
|
#define LEN 128 // Process Length Should Be 128 ,Do not Modify
|
|
#define MIC_CH 4
|
|
void Main::onSIGINT() { exit(0); }
|
|
|
|
int Main::main(int argc, char *argv[]) {
|
|
FILE *mic_fd = NULL;
|
|
FILE *ref_fd = NULL;
|
|
FILE *out_fd1 = NULL;
|
|
FILE *out_fd2 = NULL;
|
|
|
|
short aecout_buff[LEN * MIC_CH];
|
|
short mic_buff[LEN * MIC_CH];
|
|
short ref_buff[LEN];
|
|
short asr_buf[LEN];
|
|
|
|
// 6mic
|
|
// float coord_data[18] = {0.04,0,0, 0.02,-0.0346,0, -0.02,-0.0346,0, -0.04,0,0, -0.02,0.0346,0, 0.02,0.0346,0};
|
|
|
|
// 4mic
|
|
float coord_data[18] = {0.038, 0, 0, 0, -0.038, 0, -0.038, 0, 0, 0, 0.038, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
// 2mic
|
|
// float coord_data[18] = {0.038,0,0, -0.038,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0};
|
|
|
|
int aec_state = 1;
|
|
int aec_farend = 1;
|
|
int vad_state = 1;
|
|
float doa1, doa2, doa3;
|
|
|
|
if (argc != 5) {
|
|
printf("usage:audio_test mic_file ref_file asr_file1 wkp_file2\n");
|
|
return -1;
|
|
}
|
|
|
|
mic_fd = fopen(argv[1], "rb");
|
|
// mic_fd = fopen("zero.pcm","rb");
|
|
if (mic_fd == NULL) {
|
|
printf("open mic file failed!\n");
|
|
return -1;
|
|
}
|
|
|
|
ref_fd = fopen(argv[2], "rb");
|
|
// ref_fd = fopen("zero.pcm","rb");
|
|
if (ref_fd == NULL) {
|
|
printf("open ref file failed!\n");
|
|
fclose(mic_fd);
|
|
mic_fd = 0;
|
|
return -1;
|
|
}
|
|
|
|
out_fd1 = fopen(argv[3], "wb");
|
|
// out_fd1 = fopen("asr.pcm","wb");
|
|
if (out_fd1 == NULL) {
|
|
printf("open output file1 failed!\n");
|
|
fclose(mic_fd);
|
|
fclose(ref_fd);
|
|
mic_fd = 0;
|
|
ref_fd = 0;
|
|
return -1;
|
|
}
|
|
|
|
out_fd2 = fopen(argv[4], "wb");
|
|
// out_fd2 = fopen("wkp.pcm","wb");
|
|
if (out_fd2 == NULL) {
|
|
printf("open output file2 failed!\n");
|
|
fclose(mic_fd);
|
|
fclose(ref_fd);
|
|
fclose(out_fd1);
|
|
mic_fd = 0;
|
|
ref_fd = 0;
|
|
out_fd1 = 0;
|
|
return -1;
|
|
}
|
|
|
|
float *audio_aec_obj = audio_aec_init(MIC_CH);
|
|
if (audio_aec_obj == NULL) {
|
|
printf("Audio Aec Init Error\n");
|
|
fclose(mic_fd);
|
|
fclose(ref_fd);
|
|
fclose(out_fd1);
|
|
fclose(out_fd2);
|
|
return -1;
|
|
}
|
|
|
|
float *audio_doa_obj = audio_doa_init(MIC_CH, coord_data, 0, 360);
|
|
if (audio_doa_obj == NULL) {
|
|
printf("Audio doa Init Error\n");
|
|
fclose(mic_fd);
|
|
fclose(ref_fd);
|
|
fclose(out_fd1);
|
|
fclose(out_fd2);
|
|
return -1;
|
|
}
|
|
|
|
float *audio_gsc_obj = audio_gsc_init(MIC_CH, coord_data);
|
|
if (audio_gsc_obj == NULL) {
|
|
printf("Audio gsc Init Error\n");
|
|
fclose(mic_fd);
|
|
fclose(ref_fd);
|
|
fclose(out_fd1);
|
|
fclose(out_fd2);
|
|
return -1;
|
|
}
|
|
|
|
float *audio_agc_obj = audio_agc_init(128, 1, 24000.0);
|
|
int frame = 0;
|
|
int doavad;
|
|
|
|
while (1) {
|
|
if (fread(mic_buff, sizeof(short), LEN * MIC_CH, mic_fd) <= 0) break;
|
|
if (fread(ref_buff, sizeof(short), LEN, ref_fd) <= 0) break;
|
|
|
|
if (audio_aec_process(audio_aec_obj, mic_buff, ref_buff, aecout_buff, &aec_state, &aec_farend)) break;
|
|
|
|
if (audio_doa_process(audio_doa_obj, aecout_buff, aec_state, aec_farend, &doa1, &doa2, &doa3, &vad_state)) break;
|
|
doavad = vad_state;
|
|
// printf("doa:%d,%d,%d\n",(short)doa1, (short)doa2, (short)doa3);
|
|
|
|
if (audio_gsc_fixed(audio_gsc_obj, aecout_buff, aec_state, aec_farend, 0.0, 180.0, asr_buf, &vad_state)) break;
|
|
printf("doa:%5d,%5d,%5d vad:%d,%d\n", (short)doa1, (short)doa2, (short)doa3, doavad, vad_state);
|
|
|
|
if (audio_agc_process(audio_agc_obj, asr_buf, asr_buf, vad_state, aec_state)) break;
|
|
// printf("frame:%d\n",frame++);
|
|
fwrite(asr_buf, sizeof(short), LEN, out_fd1);
|
|
fwrite(aecout_buff, sizeof(short), LEN * MIC_CH, out_fd2);
|
|
}
|
|
|
|
audio_aec_uninit(audio_aec_obj);
|
|
audio_doa_uninit(audio_doa_obj);
|
|
audio_gsc_uninit(audio_gsc_obj);
|
|
audio_agc_uninit(audio_agc_obj);
|
|
|
|
fclose(mic_fd);
|
|
fclose(ref_fd);
|
|
fclose(out_fd1);
|
|
fclose(out_fd2);
|
|
|
|
return 0;
|
|
}
|