main.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // 秒寻科技
  2. // 系统入口
  3. // 系统内存遵从谁申请谁负责释放的原则
  4. // zt
  5. // 2023-02-27
  6. #include "src/includes/includes.h"
  7. #include "src/sysdefine/sysmacro.h"
  8. // 导出所需的全局变量
  9. extern PUB_LOCATION_DATA_T gg_astLocationDataList[PUB_SYS_CARRIER_NUM]; // 定位数据队列
  10. // 系统入口函数
  11. int main()
  12. {
  13. // 初始化业务模块
  14. main_module_init();
  15. // 初始化IMU模块
  16. imu_init();
  17. // 测试业务逻辑
  18. if (PUB_DEBUG_ENABLE)
  19. {
  20. main_read_wav();
  21. // main_read_bin();
  22. }
  23. printf("wasm init ok\n");
  24. return 0;
  25. }
  26. // 初始化各模块
  27. void main_module_init()
  28. {
  29. // 业务模块初始化
  30. sysmain_init();
  31. return;
  32. }
  33. // 从wav文件中读取数据,驱动信号处理模块
  34. void main_read_wav()
  35. {
  36. // const char *pFileName = "E:\\work\\ips8000\\aplm8000sdk\\wave\\zcq(20251203-09).wav";
  37. // const char *pFileName = "E:\\work\\ips8000\\aplm8000sdk\\wave\\rec5-0-5(0245)-btsx.wav";
  38. const char *pFileName = "E:\\work\\ips8000\\aplm8000sdk\\wave\\zcq(20241217-03).wav";
  39. int16 *pwData = NULL; // 音频数据存储地址
  40. uint8 byIsOver = 0;
  41. uint16 wCounter = 0;
  42. // char *pFilePaht = "E:\\work\\ips8000\\aplm8000sdk\\output\\lctdata\\audioSourceFile.bin";
  43. pwData = (int16 *)dmdl_main_get_audio_sample_data();
  44. // 读取wave文件
  45. #pragma pack(push, 1) // 确保结构体按照字节对齐
  46. typedef struct
  47. {
  48. char chunkID[4];
  49. int chunkSize;
  50. char format[4];
  51. char subchunk1ID[4];
  52. int subchunk1Size;
  53. short audioFormat;
  54. short numChannels;
  55. int sampleRate;
  56. int byteRate;
  57. short blockAlign;
  58. short bitsPerSample;
  59. char subchunk2ID[4];
  60. int subchunk2Size;
  61. } WaveHeader;
  62. #pragma pack(pop) // 恢复默认的对齐方式
  63. FILE *file = fopen(pFileName, "rb");
  64. if (file == NULL)
  65. {
  66. perror("Error opening file");
  67. return;
  68. }
  69. WaveHeader header;
  70. if (fread(&header, sizeof(WaveHeader), 1, file) != 1)
  71. {
  72. perror("Error reading header");
  73. fclose(file);
  74. return;
  75. }
  76. int bytesPerSample = header.bitsPerSample / 8;
  77. int totalSamples = header.subchunk2Size / bytesPerSample;
  78. int samplesToRead = 12000;
  79. int bytesRead = 0;
  80. while (bytesRead < totalSamples)
  81. {
  82. int remainingSamples = totalSamples - bytesRead;
  83. int samplesToReadNow = (remainingSamples >= samplesToRead) ? samplesToRead : remainingSamples;
  84. memset(pwData, 0, sizeof(int16) * PUB_SLOT_FRAME_LEN);
  85. int actualRead = (int)fread(pwData, bytesPerSample, samplesToReadNow, file);
  86. if (actualRead != samplesToReadNow)
  87. {
  88. if (feof(file))
  89. {
  90. printf("total %d frame\n", wCounter);
  91. byIsOver = 1;
  92. break;
  93. }
  94. else
  95. {
  96. byIsOver = 1;
  97. perror("Error reading samples");
  98. fclose(file);
  99. return;
  100. }
  101. }
  102. // wCounter++;
  103. // if (wCounter >= 136 && wCounter <= 180)
  104. // {
  105. // util_write_flt32_to_bin_file(pFilePaht, PUB_SLOT_FRAME_LEN, pfData);
  106. // dmdl_main(gg_astLocationDataList);
  107. // }
  108. // 读文件结束或者数据长度不够一帧
  109. if (!byIsOver || actualRead != PUB_SLOT_FRAME_LEN)
  110. {
  111. // 信号处理
  112. sysmain_audio_signal_process();
  113. }
  114. bytesRead += actualRead;
  115. }
  116. return;
  117. }
  118. void main_read_bin()
  119. {
  120. uint8 byFlag = 1;
  121. char *pFilePaht = "E:\\work\\ips8000\\aplm8000sdk\\wave\\IPS8000.bin";
  122. int16 *pwData = NULL; // 音频数据存储地址
  123. uint16 wReadTimes = 0;
  124. pwData = (int16 *)dmdl_main_get_audio_sample_data();
  125. while (byFlag)
  126. {
  127. memset(pwData, 0, sizeof(int16) * PUB_SLOT_FRAME_LEN);
  128. byFlag = util_file_read_int16_from_bin_file(pFilePaht, wReadTimes, PUB_SLOT_FRAME_LEN, pwData);
  129. if (!byFlag)
  130. {
  131. printf("is over\n");
  132. break;
  133. }
  134. sysmain_audio_signal_process();
  135. wReadTimes++;
  136. }
  137. }
  138. // 测试矩阵求逆
  139. void main_test_matrix()
  140. {
  141. flt32 afM1[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
  142. flt32 afM2[16] = {0};
  143. uint8 bySize = 4;
  144. matrix_inversion(afM1, afM2, bySize);
  145. matrix_print(afM1, 4, 4);
  146. matrix_print(afM2, 4, 4);
  147. }
  148. // 测试fft变换
  149. void main_test_fft()
  150. {
  151. flt32 afRealDataList[8] = {-0.0000001, -0.0000002, -0.0000003, -0.0000004, 0.0000001, 0.0000002, 0.0000003, 0.0000004};
  152. flt32 afImagDataList[8] = {0};
  153. uint16 awButterFlyList[8] = {0};
  154. // 生成蝴蝶因子
  155. util_fft_init_butterfly_table(8, (short *)awButterFlyList);
  156. util_fft_fft(8, afRealDataList, afImagDataList, (short *)awButterFlyList);
  157. util_fft_ifft(8, afRealDataList, afImagDataList, (short *)awButterFlyList);
  158. }