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
75 lines
2.1 KiB
#include "encoder_acquistion.h"
|
|
|
|
#include "config.h"
|
|
#include "stdlib.h"
|
|
#include "zassert.h"
|
|
#include "zboard.h"
|
|
#include "zthread.h"
|
|
|
|
#define REPORT_BUF_SIZE 1000
|
|
|
|
#define TAG "aencoder_acquistion_driver"
|
|
static zthread_t s_workingthread;
|
|
uint8_t *s_reportbuf;
|
|
uint32_t s_reportbufsize;
|
|
encoder_acquisition_cb_t s_cb;
|
|
|
|
/**
|
|
* @brief 在这里上报语音
|
|
*
|
|
* @param arg
|
|
*
|
|
* PS:
|
|
* 函数效率在240MHZ的情况下,1s的语音数据(32bit,16k)大概需要2ms的处理时间
|
|
*/
|
|
|
|
static void prv_workingthread(void *arg) {
|
|
while (!zthread_is_expect_stop(&s_workingthread)) {
|
|
size_t bytes_read;
|
|
// ESP_LOGI(TAG, "read %d ", bytes_read);
|
|
if (s_cb) {
|
|
#if 0
|
|
//测试放大方法效率
|
|
uint32_t sticket = xTaskGetTickCount();
|
|
for(unsigned i = 0; i < 16*4; ++i) {
|
|
amf_voice(s_reportbuf, bytes_read);
|
|
}
|
|
uint32_t endticket = xTaskGetTickCount();
|
|
ESP_LOGI(TAG, " %d use %d", bytes_read,endticket - sticket);
|
|
#else
|
|
// amf_voice(s_reportbuf, bytes_read);
|
|
#endif
|
|
|
|
// 因为MIC最大响度能够达到的幅值为0.316v,和3.3v差了3.3/0.316倍,
|
|
// 又因为PCM1808位宽为24bit,32位中低八位为零,已经默认放大
|
|
// 则可以保证数据放大3.3/0.316后数据是无损的.
|
|
for (size_t i = 0; i < bytes_read; i += 4) {
|
|
int32_t *rxdata = (int32_t *)&s_reportbuf[i];
|
|
(*rxdata) = (*rxdata) * 3.3 / 0.316;
|
|
}
|
|
|
|
// 对音频按照配置进行放大
|
|
for (size_t i = 0; i < bytes_read; i += 4) {
|
|
int32_t *rxdata = (int32_t *)&s_reportbuf[i];
|
|
}
|
|
|
|
s_cb(s_reportbuf, bytes_read);
|
|
}
|
|
}
|
|
}
|
|
void encoder_acquisition_init(encoder_acquisition_cb_t cb) {
|
|
// s_workingthread
|
|
|
|
// s_workingthread
|
|
|
|
s_reportbuf = malloc(REPORT_BUF_SIZE);
|
|
s_reportbufsize = REPORT_BUF_SIZE;
|
|
s_cb = cb;
|
|
Z_ASSERT(s_reportbuf);
|
|
Z_ASSERT(s_reportbufsize);
|
|
Z_ASSERT(s_cb);
|
|
|
|
zthread_init(&s_workingthread, "encoder_acquistion_driver", prv_workingthread);
|
|
}
|
|
void encoder_acquisition_start_cauture() { zthread_start(&s_workingthread); }
|
|
void encoder_acquisition_stop_cauture() { zthread_stop(&s_workingthread); }
|