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

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include <iostream>
  2. #include <string>
  3. #include "zlinuxcomponents/zmainhelper.hpp"
  4. //
  5. #include "configs/gconfig.hpp"
  6. #include "iflytopcpp/core/spdlogfactory/logger.hpp"
  7. #include "iflytopcpp/core/thread/thread.hpp"
  8. #include "spdlog/spdlog.h"
  9. #include "version.hpp"
  10. #include "zlinuxcomponents/rootfs_auto_update/rootfs_auto_update.hpp"
  11. #include "zservice_container/zservice_container.hpp"
  12. //
  13. #include "service/device_io_service.hpp"
  14. #include "service/device_io_service_mock.hpp"
  15. #include "service/light_control_service.hpp"
  16. #include "service/report_service.hpp"
  17. #include "zlinuxcomponents/aiui_ws/aiui_service.hpp"
  18. //
  19. #include "zlinuxcomponents/aiui_ws/aiui.h"
  20. //
  21. #include "audio_process_api.h"
  22. ZMAIN();
  23. #define LEN 128 // Process Length Should Be 128 ,Do not Modify
  24. #define MIC_CH 4
  25. void Main::onSIGINT() { exit(0); }
  26. int Main::main(int argc, char *argv[]) {
  27. FILE *mic_fd = NULL;
  28. FILE *ref_fd = NULL;
  29. FILE *out_fd1 = NULL;
  30. FILE *out_fd2 = NULL;
  31. short aecout_buff[LEN * MIC_CH];
  32. short mic_buff[LEN * MIC_CH];
  33. short ref_buff[LEN];
  34. short asr_buf[LEN];
  35. // 6mic
  36. // 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};
  37. // 4mic
  38. 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};
  39. // 2mic
  40. // float coord_data[18] = {0.038,0,0, -0.038,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0};
  41. int aec_state = 1;
  42. int aec_farend = 1;
  43. int vad_state = 1;
  44. float doa1, doa2, doa3;
  45. if (argc != 5) {
  46. printf("usage:audio_test mic_file ref_file asr_file1 wkp_file2\n");
  47. return -1;
  48. }
  49. mic_fd = fopen(argv[1], "rb");
  50. // mic_fd = fopen("zero.pcm","rb");
  51. if (mic_fd == NULL) {
  52. printf("open mic file failed!\n");
  53. return -1;
  54. }
  55. ref_fd = fopen(argv[2], "rb");
  56. // ref_fd = fopen("zero.pcm","rb");
  57. if (ref_fd == NULL) {
  58. printf("open ref file failed!\n");
  59. fclose(mic_fd);
  60. mic_fd = 0;
  61. return -1;
  62. }
  63. out_fd1 = fopen(argv[3], "wb");
  64. // out_fd1 = fopen("asr.pcm","wb");
  65. if (out_fd1 == NULL) {
  66. printf("open output file1 failed!\n");
  67. fclose(mic_fd);
  68. fclose(ref_fd);
  69. mic_fd = 0;
  70. ref_fd = 0;
  71. return -1;
  72. }
  73. out_fd2 = fopen(argv[4], "wb");
  74. // out_fd2 = fopen("wkp.pcm","wb");
  75. if (out_fd2 == NULL) {
  76. printf("open output file2 failed!\n");
  77. fclose(mic_fd);
  78. fclose(ref_fd);
  79. fclose(out_fd1);
  80. mic_fd = 0;
  81. ref_fd = 0;
  82. out_fd1 = 0;
  83. return -1;
  84. }
  85. float *audio_aec_obj = audio_aec_init(MIC_CH);
  86. if (audio_aec_obj == NULL) {
  87. printf("Audio Aec Init Error\n");
  88. fclose(mic_fd);
  89. fclose(ref_fd);
  90. fclose(out_fd1);
  91. fclose(out_fd2);
  92. return -1;
  93. }
  94. float *audio_doa_obj = audio_doa_init(MIC_CH, coord_data, 0, 360);
  95. if (audio_doa_obj == NULL) {
  96. printf("Audio doa Init Error\n");
  97. fclose(mic_fd);
  98. fclose(ref_fd);
  99. fclose(out_fd1);
  100. fclose(out_fd2);
  101. return -1;
  102. }
  103. float *audio_gsc_obj = audio_gsc_init(MIC_CH, coord_data);
  104. if (audio_gsc_obj == NULL) {
  105. printf("Audio gsc Init Error\n");
  106. fclose(mic_fd);
  107. fclose(ref_fd);
  108. fclose(out_fd1);
  109. fclose(out_fd2);
  110. return -1;
  111. }
  112. float *audio_agc_obj = audio_agc_init(128, 1, 24000.0);
  113. int frame = 0;
  114. int doavad;
  115. while (1) {
  116. if (fread(mic_buff, sizeof(short), LEN * MIC_CH, mic_fd) <= 0) break;
  117. if (fread(ref_buff, sizeof(short), LEN, ref_fd) <= 0) break;
  118. if (audio_aec_process(audio_aec_obj, mic_buff, ref_buff, aecout_buff, &aec_state, &aec_farend)) break;
  119. if (audio_doa_process(audio_doa_obj, aecout_buff, aec_state, aec_farend, &doa1, &doa2, &doa3, &vad_state)) break;
  120. doavad = vad_state;
  121. // printf("doa:%d,%d,%d\n",(short)doa1, (short)doa2, (short)doa3);
  122. if (audio_gsc_fixed(audio_gsc_obj, aecout_buff, aec_state, aec_farend, 0.0, 180.0, asr_buf, &vad_state)) break;
  123. printf("doa:%5d,%5d,%5d vad:%d,%d\n", (short)doa1, (short)doa2, (short)doa3, doavad, vad_state);
  124. if (audio_agc_process(audio_agc_obj, asr_buf, asr_buf, vad_state, aec_state)) break;
  125. // printf("frame:%d\n",frame++);
  126. fwrite(asr_buf, sizeof(short), LEN, out_fd1);
  127. fwrite(aecout_buff, sizeof(short), LEN * MIC_CH, out_fd2);
  128. }
  129. audio_aec_uninit(audio_aec_obj);
  130. audio_doa_uninit(audio_doa_obj);
  131. audio_gsc_uninit(audio_gsc_obj);
  132. audio_agc_uninit(audio_agc_obj);
  133. fclose(mic_fd);
  134. fclose(ref_fd);
  135. fclose(out_fd1);
  136. fclose(out_fd2);
  137. return 0;
  138. }