bugfix(esp-sr): support C++

This commit is contained in:
xysun 2024-11-05 11:19:47 +08:00
parent 6bf81a4681
commit c84f4afb35
6 changed files with 62 additions and 42 deletions

View File

@ -115,10 +115,12 @@ typedef struct {
.memory_alloc_mode = AFE_MEMORY_ALLOC_INTERNAL_PSRAM_BALANCE, \
.afe_linear_gain = 1.0, \
.agc_mode = AFE_MN_PEAK_AGC_MODE_2, \
.pcm_config.total_ch_num = 2, \
.pcm_config.mic_num = 1, \
.pcm_config.ref_num = 1, \
.pcm_config.sample_rate = 16000, \
.pcm_config = { \
.total_ch_num = 2, \
.mic_num = 1, \
.ref_num = 1, \
.sample_rate = 16000, \
}, \
.debug_init = false, \
.debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL}, {AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}}, \
.afe_ns_mode = NS_MODE_SSP, \
@ -145,10 +147,12 @@ typedef struct {
.memory_alloc_mode = AFE_MEMORY_ALLOC_MORE_PSRAM, \
.afe_linear_gain = 1.0, \
.agc_mode = AFE_MN_PEAK_AGC_MODE_2, \
.pcm_config.total_ch_num = 2, \
.pcm_config.mic_num = 1, \
.pcm_config.ref_num = 1, \
.pcm_config.sample_rate = 16000, \
.pcm_config = { \
.total_ch_num = 2, \
.mic_num = 1, \
.ref_num = 1, \
.sample_rate = 16000, \
}, \
.debug_init = false, \
.debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL}, {AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}}, \
.afe_ns_mode = NS_MODE_SSP, \
@ -175,10 +179,12 @@ typedef struct {
.memory_alloc_mode = AFE_MEMORY_ALLOC_MORE_PSRAM, \
.afe_linear_gain = 1.0, \
.agc_mode = AFE_MN_PEAK_AGC_MODE_2, \
.pcm_config.total_ch_num = 3, \
.pcm_config.mic_num = 2, \
.pcm_config.ref_num = 1, \
.pcm_config.sample_rate = 16000, \
.pcm_config = { \
.total_ch_num = 3, \
.mic_num = 2, \
.ref_num = 1, \
.sample_rate = 16000, \
}, \
.debug_init = false, \
.debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL}, {AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}}, \
.afe_ns_mode = NS_MODE_SSP, \

View File

@ -1,9 +1,9 @@
set(srcs
"test_app_main.c"
"test_wakenet.c"
"test_multinet.c"
"test_afe.c"
"app_main.cpp"
"test_wakenet.cpp"
"test_multinet.cpp"
"test_afe.cpp"
)
idf_component_register(SRCS ${srcs}

View File

@ -7,12 +7,11 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "unity.h"
#include <stdio.h>
#include <string.h>
#include "unity.h"
void app_main(void)
extern "C" void app_main(void)
{
/* These are the different ways of running registered tests.
* In practice, only one of them is usually needed.
@ -45,4 +44,4 @@ void app_main(void)
* Make sure that task watchdog is disabled if you use this function.
*/
unity_run_menu();
}
}

View File

@ -112,7 +112,7 @@ TEST_CASE(">>>>>>>> audio_front_end SR create/destroy API & memory leak <<<<<<<<
afe_data = afe_handle->create_from_config(&afe_config);
audio_chunksize = afe_handle->get_feed_chunksize(afe_data);
feed_buff = malloc(audio_chunksize * sizeof(int16_t) * afe_config.pcm_config.total_ch_num);
feed_buff = (int16_t *) malloc(audio_chunksize * sizeof(int16_t) * afe_config.pcm_config.total_ch_num);
assert(feed_buff);
afe_handle->feed(afe_data, feed_buff);
@ -145,7 +145,7 @@ void test_feed_Task(void *arg)
esp_afe_sr_iface_t *afe_handle = (esp_afe_sr_iface_t *)arg;
int feed_chunksize = afe_handle->get_feed_chunksize(afe_data);
int total_nch = afe_handle->get_total_channel_num(afe_data);
int16_t *i2s_buff = malloc(feed_chunksize * sizeof(int16_t) * total_nch);
int16_t *i2s_buff = (int16_t *) malloc(feed_chunksize * sizeof(int16_t) * total_nch);
assert(i2s_buff);
ESP_LOGI(TAG, "feed task start\n");
// FILE *fp = fopen("/sdcard/out", "w");
@ -169,7 +169,7 @@ void test_detect_Task(void *arg)
// esp_afe_sr_iface_t *afe_handle = &ESP_AFE_SR_HANDLE;
esp_afe_sr_iface_t *afe_handle = (esp_afe_sr_iface_t *)arg;
int fetch_chunksize = afe_handle->get_fetch_chunksize(afe_data);
int16_t *buff = malloc(fetch_chunksize * sizeof(int16_t));
int16_t *buff = (int16_t *) malloc(fetch_chunksize * sizeof(int16_t));
assert(buff);
ESP_LOGI(TAG, "------------detect start------------\n");
@ -208,21 +208,29 @@ esp_err_t audio_sys_get_real_time_stats(void)
// Allocate array to store current task states
start_array_size = uxTaskGetNumberOfTasks() + ARRAY_SIZE_OFFSET;
start_array = malloc(sizeof(TaskStatus_t) * start_array_size);
start_array = (TaskStatus_t*) malloc(sizeof(TaskStatus_t) * start_array_size);
assert(start_array);
// Get current task states
start_array_size = uxTaskGetSystemState(start_array, start_array_size, &start_run_time);
if (start_array_size == 0) {
ESP_LOGE(TAG, "Insufficient array size for uxTaskGetSystemState. Trying increasing ARRAY_SIZE_OFFSET");
ret = ESP_FAIL;
goto exit;
if (start_array) {
free(start_array);
start_array = NULL;
}
if (end_array) {
free(end_array);
end_array = NULL;
}
return ret;
}
vTaskDelay(pdMS_TO_TICKS(AUDIO_SYS_TASKS_ELAPSED_TIME_MS));
// Allocate array to store tasks states post delay
end_array_size = uxTaskGetNumberOfTasks() + ARRAY_SIZE_OFFSET;
end_array = malloc(sizeof(TaskStatus_t) * end_array_size);
end_array = (TaskStatus_t*) malloc(sizeof(TaskStatus_t) * end_array_size);
assert(end_array);
// Get post delay task states
@ -230,7 +238,15 @@ esp_err_t audio_sys_get_real_time_stats(void)
if (end_array_size == 0) {
ESP_LOGE(TAG, "Insufficient array size for uxTaskGetSystemState. Trying increasing ARRAY_SIZE_OFFSET");
ret = ESP_FAIL;
goto exit;
if (start_array) {
free(start_array);
start_array = NULL;
}
if (end_array) {
free(end_array);
end_array = NULL;
}
return ret;
}
// Calculate total_elapsed_time in units of run time stats clock period.
@ -238,7 +254,15 @@ esp_err_t audio_sys_get_real_time_stats(void)
if (total_elapsed_time == 0) {
ESP_LOGE(TAG, "Delay duration too short. Trying increasing AUDIO_SYS_TASKS_ELAPSED_TIME_MS");
ret = ESP_FAIL;
goto exit;
if (start_array) {
free(start_array);
start_array = NULL;
}
if (end_array) {
free(end_array);
end_array = NULL;
}
return ret;
}
ESP_LOGI(TAG, "| Task | Run Time | Per | Prio | HWM | State | CoreId | Stack ");
@ -277,15 +301,6 @@ esp_err_t audio_sys_get_real_time_stats(void)
printf("\n");
ret = ESP_OK;
exit: // Common return path
if (start_array) {
free(start_array);
start_array = NULL;
}
if (end_array) {
free(end_array);
end_array = NULL;
}
return ret;
#else
ESP_LOGW(TAG, "Please enbale `CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID` and `CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS` in menuconfig");
@ -386,7 +401,7 @@ TEST_CASE("audio_front_end VC create/destroy API & memory leak", "[afe_vc]")
afe_config.se_init = se_init;
afe_config.vad_init = vad_init;
afe_config.voice_communication_agc_init = voice_communication_agc_init;
afe_config.afe_ns_mode = afe_ns_mode;
afe_config.afe_ns_mode = (afe_ns_mode_t)afe_ns_mode;
//start_total_mem_size = heap_caps_get_free_size(MALLOC_CAP_8BIT);
//start_internal_mem_size = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
@ -412,7 +427,7 @@ TEST_CASE("audio_front_end VC create/destroy API & memory leak", "[afe_vc]")
}
audio_chunksize = afe_handle->get_feed_chunksize(afe_data);
feed_buff = malloc(audio_chunksize * sizeof(int16_t) * afe_config.pcm_config.total_ch_num);
feed_buff = (int16_t *) malloc(audio_chunksize * sizeof(int16_t) * afe_config.pcm_config.total_ch_num);
assert(feed_buff);
afe_handle->feed(afe_data, feed_buff);

View File

@ -88,7 +88,7 @@ TEST_CASE("multinet cpu loading", "[mn]")
printf("commands: da kai kong tiao, size:%d\n", data_size);
}
int16_t *buffer = malloc(audio_chunksize);
int16_t *buffer = (int16_t *) malloc(audio_chunksize);
int chunks = 0;
struct timeval tv_start, tv_end;
gettimeofday(&tv_start, NULL);

View File

@ -65,7 +65,7 @@ TEST_CASE("wakenet create/destroy API & memory leak", "[wn]")
// DET_MODE_3CH_90 = 4,
// DET_MODE_3CH_95 = 5,
// } det_mode_t;
model_data = wakenet->create(model_name, i);
model_data = wakenet->create(model_name, (det_mode_t)i);
printf("destroy ...\n");
wakenet->destroy(model_data);
@ -89,7 +89,7 @@ TEST_CASE("wakenet detect API & cpu loading", "[wn]")
model_iface_data_t *model_data = wakenet->create(model_name, DET_MODE_95);
int frequency = wakenet->get_samp_rate(model_data);
int audio_chunksize = wakenet->get_samp_chunksize(model_data) * sizeof(int16_t);
int16_t *buffer = malloc(audio_chunksize);
int16_t *buffer = (int16_t *) malloc(audio_chunksize);
int chunks = 0;
int detected = 0;
struct timeval tv_start, tv_end;