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.

75 lines
2.1 KiB

3 years ago
  1. #include "encoder_acquistion.h"
  2. #include "config.h"
  3. #include "stdlib.h"
  4. #include "zassert.h"
  5. #include "zboard.h"
  6. #include "zthread.h"
  7. #define REPORT_BUF_SIZE 1000
  8. #define TAG "aencoder_acquistion_driver"
  9. static zthread_t s_workingthread;
  10. uint8_t *s_reportbuf;
  11. uint32_t s_reportbufsize;
  12. encoder_acquisition_cb_t s_cb;
  13. /**
  14. * @brief
  15. *
  16. * @param arg
  17. *
  18. * PS:
  19. * 240MHZ的情况下1s的语音数据(32bit,16k)2ms的处理时间
  20. */
  21. static void prv_workingthread(void *arg) {
  22. while (!zthread_is_expect_stop(&s_workingthread)) {
  23. size_t bytes_read;
  24. // ESP_LOGI(TAG, "read %d ", bytes_read);
  25. if (s_cb) {
  26. #if 0
  27. //测试放大方法效率
  28. uint32_t sticket = xTaskGetTickCount();
  29. for(unsigned i = 0; i < 16*4; ++i) {
  30. amf_voice(s_reportbuf, bytes_read);
  31. }
  32. uint32_t endticket = xTaskGetTickCount();
  33. ESP_LOGI(TAG, " %d use %d", bytes_read,endticket - sticket);
  34. #else
  35. // amf_voice(s_reportbuf, bytes_read);
  36. #endif
  37. // 因为MIC最大响度能够达到的幅值为0.316v,和3.3v差了3.3/0.316倍,
  38. // 又因为PCM1808位宽为24bit,32位中低八位为零,已经默认放大
  39. // 则可以保证数据放大3.3/0.316后数据是无损的.
  40. for (size_t i = 0; i < bytes_read; i += 4) {
  41. int32_t *rxdata = (int32_t *)&s_reportbuf[i];
  42. (*rxdata) = (*rxdata) * 3.3 / 0.316;
  43. }
  44. // 对音频按照配置进行放大
  45. for (size_t i = 0; i < bytes_read; i += 4) {
  46. int32_t *rxdata = (int32_t *)&s_reportbuf[i];
  47. }
  48. s_cb(s_reportbuf, bytes_read);
  49. }
  50. }
  51. }
  52. void encoder_acquisition_init(encoder_acquisition_cb_t cb) {
  53. // s_workingthread
  54. // s_workingthread
  55. s_reportbuf = malloc(REPORT_BUF_SIZE);
  56. s_reportbufsize = REPORT_BUF_SIZE;
  57. s_cb = cb;
  58. Z_ASSERT(s_reportbuf);
  59. Z_ASSERT(s_reportbufsize);
  60. Z_ASSERT(s_cb);
  61. zthread_init(&s_workingthread, "encoder_acquistion_driver", prv_workingthread);
  62. }
  63. void encoder_acquisition_start_cauture() { zthread_start(&s_workingthread); }
  64. void encoder_acquisition_stop_cauture() { zthread_stop(&s_workingthread); }