mirror of
https://github.com/espressif/esp-sr.git
synced 2025-09-15 15:28:44 +08:00
dump esp-sr v2.0.1
This commit is contained in:
parent
f2cc8a9394
commit
b4f1200553
@ -1,4 +1,4 @@
|
||||
version: "2.0.0"
|
||||
version: "2.0.1"
|
||||
description: esp_sr provides basic algorithms for Speech Recognition applications
|
||||
url: https://github.com/espressif/esp-sr
|
||||
dependencies:
|
||||
|
||||
@ -2,9 +2,8 @@
|
||||
#ifndef _ESP_AFE_AEC_H_
|
||||
#define _ESP_AFE_AEC_H_
|
||||
|
||||
|
||||
#include "esp_afe_config.h"
|
||||
#include "esp_aec.h"
|
||||
#include "esp_afe_config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -20,12 +19,12 @@ typedef struct {
|
||||
int16_t *data;
|
||||
} afe_aec_handle_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates an instance to the AEC structure.
|
||||
*
|
||||
* @warning Currently only support 1 microphone channel and 1 playback channe.
|
||||
* If input has multiple microphone channels and playback channels, just the first microphone channel and playback channel will be selected.
|
||||
* If input has multiple microphone channels and playback channels, just the first microphone channel and playback
|
||||
* channel will be selected.
|
||||
*
|
||||
* The input format, same as afe config:
|
||||
* M to represent the microphone channel
|
||||
@ -37,7 +36,8 @@ typedef struct {
|
||||
*
|
||||
* @param input_format The input format
|
||||
* @param filter_length The length of filter. The larger the filter, the higher the CPU loading.
|
||||
* Recommended filter_length = 4 for esp32s3 and esp32p4. Recommended filter_length = 2 for esp32c5.
|
||||
* Recommended filter_length = 4 for esp32s3 and esp32p4. Recommended filter_length = 2 for
|
||||
* esp32c5.
|
||||
* @param type The type of afe, AFE_TYPE_SR or AFE_TYPE_VC
|
||||
* @param mode The mode of afe, AFE_MODE_LOW_COST or AFE_MODE_HIGH_PERF
|
||||
*
|
||||
@ -45,17 +45,17 @@ typedef struct {
|
||||
*/
|
||||
afe_aec_handle_t *afe_aec_create(const char *input_format, int filter_length, afe_type_t type, afe_mode_t mode);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Performs echo cancellation a frame, based on the audio sent to the speaker and frame from mic.
|
||||
*
|
||||
* @param inst The instance of AEC.
|
||||
* @param indata Input audio data, format is define by input_format. Note indata will be modified in function call.
|
||||
* @param outdata Returns near-end signal with echo removed.
|
||||
* @param indata Input audio data, format is define by input_format.
|
||||
* @param outdata Near-end signal with echo removed. outdata must be 16-bit aligned.
|
||||
* please use heap_caps_aligned_calloc(16, n, size, caps) to allocate an aligned chunk of memory
|
||||
|
||||
* @return The bytes of outdata.
|
||||
*/
|
||||
size_t afe_aec_process(afe_aec_handle_t *handel, int16_t *indata, int16_t *outdata);
|
||||
size_t afe_aec_process(afe_aec_handle_t *handel, const int16_t *indata, int16_t *outdata);
|
||||
|
||||
/**
|
||||
* @brief Get frame size of AEC (the samples of one frame)
|
||||
@ -64,7 +64,6 @@ size_t afe_aec_process(afe_aec_handle_t *handel, int16_t *indata, int16_t *outda
|
||||
*/
|
||||
int afe_aec_get_chunksize(afe_aec_handle_t *handle);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Free the AEC instance
|
||||
*
|
||||
|
||||
@ -2,9 +2,8 @@
|
||||
#ifndef _ESP_AFE_AEC_H_
|
||||
#define _ESP_AFE_AEC_H_
|
||||
|
||||
|
||||
#include "esp_afe_config.h"
|
||||
#include "esp_aec.h"
|
||||
#include "esp_afe_config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -20,12 +19,12 @@ typedef struct {
|
||||
int16_t *data;
|
||||
} afe_aec_handle_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates an instance to the AEC structure.
|
||||
*
|
||||
* @warning Currently only support 1 microphone channel and 1 playback channe.
|
||||
* If input has multiple microphone channels and playback channels, just the first microphone channel and playback channel will be selected.
|
||||
* If input has multiple microphone channels and playback channels, just the first microphone channel and playback
|
||||
* channel will be selected.
|
||||
*
|
||||
* The input format, same as afe config:
|
||||
* M to represent the microphone channel
|
||||
@ -37,7 +36,8 @@ typedef struct {
|
||||
*
|
||||
* @param input_format The input format
|
||||
* @param filter_length The length of filter. The larger the filter, the higher the CPU loading.
|
||||
* Recommended filter_length = 4 for esp32s3 and esp32p4. Recommended filter_length = 2 for esp32c5.
|
||||
* Recommended filter_length = 4 for esp32s3 and esp32p4. Recommended filter_length = 2 for
|
||||
* esp32c5.
|
||||
* @param type The type of afe, AFE_TYPE_SR or AFE_TYPE_VC
|
||||
* @param mode The mode of afe, AFE_MODE_LOW_COST or AFE_MODE_HIGH_PERF
|
||||
*
|
||||
@ -45,17 +45,17 @@ typedef struct {
|
||||
*/
|
||||
afe_aec_handle_t *afe_aec_create(const char *input_format, int filter_length, afe_type_t type, afe_mode_t mode);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Performs echo cancellation a frame, based on the audio sent to the speaker and frame from mic.
|
||||
*
|
||||
* @param inst The instance of AEC.
|
||||
* @param indata Input audio data, format is define by input_format. Note indata will be modified in function call.
|
||||
* @param outdata Returns near-end signal with echo removed.
|
||||
* @param indata Input audio data, format is define by input_format.
|
||||
* @param outdata Near-end signal with echo removed. outdata must be 16-bit aligned.
|
||||
* please use heap_caps_aligned_calloc(16, n, size, caps) to allocate an aligned chunk of memory
|
||||
|
||||
* @return The bytes of outdata.
|
||||
*/
|
||||
size_t afe_aec_process(afe_aec_handle_t *handel, int16_t *indata, int16_t *outdata);
|
||||
size_t afe_aec_process(afe_aec_handle_t *handel, const int16_t *indata, int16_t *outdata);
|
||||
|
||||
/**
|
||||
* @brief Get frame size of AEC (the samples of one frame)
|
||||
@ -64,7 +64,6 @@ size_t afe_aec_process(afe_aec_handle_t *handel, int16_t *indata, int16_t *outda
|
||||
*/
|
||||
int afe_aec_get_chunksize(afe_aec_handle_t *handle);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Free the AEC instance
|
||||
*
|
||||
|
||||
@ -2,9 +2,8 @@
|
||||
#ifndef _ESP_AFE_AEC_H_
|
||||
#define _ESP_AFE_AEC_H_
|
||||
|
||||
|
||||
#include "esp_afe_config.h"
|
||||
#include "esp_aec.h"
|
||||
#include "esp_afe_config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -20,12 +19,12 @@ typedef struct {
|
||||
int16_t *data;
|
||||
} afe_aec_handle_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates an instance to the AEC structure.
|
||||
*
|
||||
* @warning Currently only support 1 microphone channel and 1 playback channe.
|
||||
* If input has multiple microphone channels and playback channels, just the first microphone channel and playback channel will be selected.
|
||||
* If input has multiple microphone channels and playback channels, just the first microphone channel and playback
|
||||
* channel will be selected.
|
||||
*
|
||||
* The input format, same as afe config:
|
||||
* M to represent the microphone channel
|
||||
@ -37,7 +36,8 @@ typedef struct {
|
||||
*
|
||||
* @param input_format The input format
|
||||
* @param filter_length The length of filter. The larger the filter, the higher the CPU loading.
|
||||
* Recommended filter_length = 4 for esp32s3 and esp32p4. Recommended filter_length = 2 for esp32c5.
|
||||
* Recommended filter_length = 4 for esp32s3 and esp32p4. Recommended filter_length = 2 for
|
||||
* esp32c5.
|
||||
* @param type The type of afe, AFE_TYPE_SR or AFE_TYPE_VC
|
||||
* @param mode The mode of afe, AFE_MODE_LOW_COST or AFE_MODE_HIGH_PERF
|
||||
*
|
||||
@ -45,17 +45,17 @@ typedef struct {
|
||||
*/
|
||||
afe_aec_handle_t *afe_aec_create(const char *input_format, int filter_length, afe_type_t type, afe_mode_t mode);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Performs echo cancellation a frame, based on the audio sent to the speaker and frame from mic.
|
||||
*
|
||||
* @param inst The instance of AEC.
|
||||
* @param indata Input audio data, format is define by input_format. Note indata will be modified in function call.
|
||||
* @param outdata Returns near-end signal with echo removed.
|
||||
* @param indata Input audio data, format is define by input_format.
|
||||
* @param outdata Near-end signal with echo removed. outdata must be 16-bit aligned.
|
||||
* please use heap_caps_aligned_calloc(16, n, size, caps) to allocate an aligned chunk of memory
|
||||
|
||||
* @return The bytes of outdata.
|
||||
*/
|
||||
size_t afe_aec_process(afe_aec_handle_t *handel, int16_t *indata, int16_t *outdata);
|
||||
size_t afe_aec_process(afe_aec_handle_t *handel, const int16_t *indata, int16_t *outdata);
|
||||
|
||||
/**
|
||||
* @brief Get frame size of AEC (the samples of one frame)
|
||||
@ -64,7 +64,6 @@ size_t afe_aec_process(afe_aec_handle_t *handel, int16_t *indata, int16_t *outda
|
||||
*/
|
||||
int afe_aec_get_chunksize(afe_aec_handle_t *handle);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Free the AEC instance
|
||||
*
|
||||
|
||||
84
include/esp32s3/esp_sr_webrtc.h
Normal file
84
include/esp32s3/esp_sr_webrtc.h
Normal file
@ -0,0 +1,84 @@
|
||||
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License
|
||||
#ifndef _ESP_WEBRTC_H_
|
||||
#define _ESP_WEBRTC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "esp_agc.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_ns.h"
|
||||
#include "sr_ringbuf.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
typedef struct {
|
||||
void *ns_handle;
|
||||
void *agc_handle;
|
||||
int frame_size;
|
||||
int sample_rate;
|
||||
int16_t *buff;
|
||||
int16_t *out_data;
|
||||
sr_ringbuf_handle_t rb;
|
||||
} webrtc_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Creates an instance of webrtc.
|
||||
*
|
||||
* @warning frame_length can supports be 10 ms, 20 ms, 30 ms, 32 ms.
|
||||
*
|
||||
* @param frame_length_ms The length of the audio processing
|
||||
* @param ns_mode The mode of NS. -1 means NS is disabled. 0: Mild, 1: Medium, 2: Aggressive
|
||||
* @param agc_mode The model of AGC
|
||||
* @param agc_gain The gain of AGC. default is 9
|
||||
* @param agc_target_level The target level of AGC. default is -3 dbfs
|
||||
* @param sample_rate The sample rate of the audio.
|
||||
*
|
||||
* @return
|
||||
* - NULL: Create failed
|
||||
* - Others: The instance of webrtc
|
||||
*/
|
||||
webrtc_handle_t *webrtc_create(
|
||||
int frame_length_ms, int ns_mode, agc_mode_t agc_mode, int agc_gain, int agc_target_level, int sample_rate);
|
||||
|
||||
/**
|
||||
* @brief Feed samples of an audio stream to the webrtc and get the audio stream after Noise suppression.
|
||||
*
|
||||
* @param handle The instance of NS.
|
||||
* @param in_data An array of 16-bit signed audio samples.
|
||||
* @param out_size The sample size of output data
|
||||
* @param enable_ns Enable noise suppression
|
||||
* @param enable_agc Enable automatic gain control
|
||||
*
|
||||
* @return data after noise suppression
|
||||
*/
|
||||
int16_t *webrtc_process(webrtc_handle_t *handle, int16_t *indata, int *size, bool enable_ns, bool enable_agc);
|
||||
|
||||
/**
|
||||
* @brief Free the webrtc instance
|
||||
*
|
||||
* @param handle The instance of webrtc.
|
||||
*
|
||||
* @return None
|
||||
*
|
||||
*/
|
||||
void webrtc_destroy(webrtc_handle_t *handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_ESP_NS_H_
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
24016
test_apps/esp-sr/main/samples/audio_test_file.h
Normal file
24016
test_apps/esp-sr/main/samples/audio_test_file.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,25 +6,24 @@
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "string.h"
|
||||
#include <limits.h>
|
||||
#include "unity.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "model_path.h"
|
||||
#include "esp_wn_iface.h"
|
||||
#include "esp_wn_models.h"
|
||||
#include "esp_afe_sr_models.h"
|
||||
#include "audio_test_file.h"
|
||||
#include "dl_lib_convq_queue.h"
|
||||
#include "esp_afe_aec.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
#if (CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4)
|
||||
#include "esp_nsn_models.h"
|
||||
#include "esp_afe_sr_models.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_nsn_iface.h"
|
||||
#endif
|
||||
#include "esp_nsn_models.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_wn_iface.h"
|
||||
#include "esp_wn_models.h"
|
||||
#include "model_path.h"
|
||||
#include "string.h"
|
||||
#include "unity.h"
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define ARRAY_SIZE_OFFSET 8 // Increase this if audio_sys_get_real_time_stats returns ESP_ERR_INVALID_SIZE
|
||||
#define AUDIO_SYS_TASKS_ELAPSED_TIME_MS 1000 // Period of stats measurement
|
||||
@ -33,7 +32,6 @@ static const char *TAG = "AFE_TEST";
|
||||
static int detect_cnt = 0;
|
||||
static int fetch_task_flag = 0;
|
||||
|
||||
|
||||
void test_afe_by_config(afe_config_t *afe_config, int frame_num, int *memory, float *cpu, int idx)
|
||||
{
|
||||
int start_size = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
@ -96,7 +94,10 @@ void test_afe_by_config(afe_config_t *afe_config, int frame_num, int* memory, fl
|
||||
cpu[idx * 2] = feed_cpu_time * 1.0 / feed_data_time;
|
||||
cpu[idx * 2 + 1] = fetch_cpu_time * 1.0 / feed_data_time;
|
||||
printf("Internal RAM: %d, PSRAM:%d, feed cpu loading:%f, fetch cpu loading:%f\n",
|
||||
memory[idx*2], memory[idx*2+1], cpu[idx*2], cpu[idx*2+1]);
|
||||
memory[idx * 2],
|
||||
memory[idx * 2 + 1],
|
||||
cpu[idx * 2],
|
||||
cpu[idx * 2 + 1]);
|
||||
TEST_ASSERT_EQUAL(true, mem_leak < 1000 && end_size == first_end_size);
|
||||
}
|
||||
|
||||
@ -120,8 +121,13 @@ TEST_CASE(">>>>>>>> AFE create/destroy API & memory leak <<<<<<<<", "[afe]")
|
||||
for (int vad_init = 0; vad_init < 2; vad_init++) {
|
||||
for (int wakenet_init = 0; wakenet_init < 2; wakenet_init++) {
|
||||
printf("format: %s, type: %d, mode: %d, memory size:%d %d\n",
|
||||
input_format[format_id], afe_type[type_id], afe_mode[mode_id], heap_caps_get_free_size(MALLOC_CAP_8BIT), count);
|
||||
afe_config_t *afe_config = afe_config_init(input_format[format_id], models, afe_type[type_id], afe_mode[mode_id]);
|
||||
input_format[format_id],
|
||||
afe_type[type_id],
|
||||
afe_mode[mode_id],
|
||||
heap_caps_get_free_size(MALLOC_CAP_8BIT),
|
||||
count);
|
||||
afe_config_t *afe_config = afe_config_init(
|
||||
input_format[format_id], models, afe_type[type_id], afe_mode[mode_id]);
|
||||
afe_config->aec_init = aec_init;
|
||||
afe_config->se_init = se_init;
|
||||
afe_config->ns_init = ns_init;
|
||||
@ -140,7 +146,10 @@ TEST_CASE(">>>>>>>> AFE create/destroy API & memory leak <<<<<<<<", "[afe]")
|
||||
}
|
||||
for (int idx = 0; idx < 256; idx++) {
|
||||
printf("Internal RAM: %d, PSRAM:%d, feed cpu loading:%f, fetch cpu loading:%f\n",
|
||||
memory[idx*2], memory[idx*2+1], cpu[idx*2], cpu[idx*2+1]);
|
||||
memory[idx * 2],
|
||||
memory[idx * 2 + 1],
|
||||
cpu[idx * 2],
|
||||
cpu[idx * 2 + 1]);
|
||||
}
|
||||
printf("AFE create/destroy API & memory leak test done\n");
|
||||
}
|
||||
@ -160,8 +169,13 @@ TEST_CASE(">>>>>>>> AFE default setting <<<<<<<<", "[afe_benchmark]")
|
||||
for (int type_id = 0; type_id < 2; type_id++) {
|
||||
for (int mode_id = 0; mode_id < 2; mode_id++) {
|
||||
printf("format: %s, type: %d, mode: %d, memory size:%d %d\n",
|
||||
input_format[format_id], afe_type[type_id], afe_mode[mode_id], heap_caps_get_free_size(MALLOC_CAP_8BIT), count);
|
||||
afe_config_t *afe_config = afe_config_init(input_format[format_id], models, afe_type[type_id], afe_mode[mode_id]);
|
||||
input_format[format_id],
|
||||
afe_type[type_id],
|
||||
afe_mode[mode_id],
|
||||
heap_caps_get_free_size(MALLOC_CAP_8BIT),
|
||||
count);
|
||||
afe_config_t *afe_config =
|
||||
afe_config_init(input_format[format_id], models, afe_type[type_id], afe_mode[mode_id]);
|
||||
test_afe_by_config(afe_config, 8, memory, cpu, count);
|
||||
afe_config_free(afe_config);
|
||||
count++;
|
||||
@ -172,10 +186,15 @@ TEST_CASE(">>>>>>>> AFE default setting <<<<<<<<", "[afe_benchmark]")
|
||||
for (int format_id = 0; format_id < 2; format_id++) {
|
||||
for (int type_id = 0; type_id < 2; type_id++) {
|
||||
for (int mode_id = 0; mode_id < 2; mode_id++) {
|
||||
|
||||
printf("--------format: %s, type: %s, mode: %s------------\n", input_format[format_id], type_id==0? "SR": "VC", mode_id==0? "LOW_COST": "HIGH_PERF");
|
||||
printf("--------format: %s, type: %s, mode: %s------------\n",
|
||||
input_format[format_id],
|
||||
type_id == 0 ? "SR" : "VC",
|
||||
mode_id == 0 ? "LOW_COST" : "HIGH_PERF");
|
||||
printf("Internal RAM: %d, PSRAM:%d, feed cpu loading:%f, fetch cpu loading:%f\n",
|
||||
memory[count*2], memory[count*2+1], cpu[count*2], cpu[count*2+1]);
|
||||
memory[count * 2],
|
||||
memory[count * 2 + 1],
|
||||
cpu[count * 2],
|
||||
cpu[count * 2 + 1]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@ -183,7 +202,6 @@ TEST_CASE(">>>>>>>> AFE default setting <<<<<<<<", "[afe_benchmark]")
|
||||
printf("test done\n");
|
||||
}
|
||||
|
||||
|
||||
void test_feed_Task(void *arg)
|
||||
{
|
||||
afe_task_into_t *afe_task_info = (afe_task_into_t *)arg;
|
||||
@ -258,8 +276,10 @@ TEST_CASE("afe performance test (1ch)", "[afe_perf]")
|
||||
task_info.feed_task = NULL;
|
||||
task_info.fetch_task = NULL;
|
||||
fetch_task_flag = 1;
|
||||
xTaskCreatePinnedToCore(test_feed_Task, "feed_task", 8 * 1024, (void *)(&task_info), 5, &task_info.feed_task, 0);
|
||||
xTaskCreatePinnedToCore(test_fetch_Task, "fetch_task", 8 * 1024, (void *)(&task_info), 5, &task_info.fetch_task, 0);
|
||||
xTaskCreatePinnedToCore(
|
||||
test_feed_Task, "feed_task", 8 * 1024, (void *)(&task_info), 5, &task_info.feed_task, 0);
|
||||
xTaskCreatePinnedToCore(
|
||||
test_fetch_Task, "fetch_task", 8 * 1024, (void *)(&task_info), 5, &task_info.fetch_task, 0);
|
||||
while (fetch_task_flag) {
|
||||
vTaskDelay(32 / portTICK_PERIOD_MS);
|
||||
}
|
||||
@ -289,8 +309,10 @@ TEST_CASE("afe performance test (2ch)", "[afe_perf]")
|
||||
task_info.feed_task = NULL;
|
||||
task_info.fetch_task = NULL;
|
||||
fetch_task_flag = 1;
|
||||
xTaskCreatePinnedToCore(&test_feed_Task, "feed_task", 8 * 1024, (void *)(&task_info), 5, &task_info.feed_task, 0);
|
||||
xTaskCreatePinnedToCore(&test_fetch_Task, "fetch_task", 8 * 1024, (void *)(&task_info), 5, &task_info.fetch_task, 0);
|
||||
xTaskCreatePinnedToCore(
|
||||
&test_feed_Task, "feed_task", 8 * 1024, (void *)(&task_info), 5, &task_info.feed_task, 0);
|
||||
xTaskCreatePinnedToCore(
|
||||
&test_fetch_Task, "fetch_task", 8 * 1024, (void *)(&task_info), 5, &task_info.fetch_task, 0);
|
||||
while (fetch_task_flag) {
|
||||
vTaskDelay(32 / portTICK_PERIOD_MS);
|
||||
}
|
||||
@ -300,23 +322,62 @@ TEST_CASE("afe performance test (2ch)", "[afe_perf]")
|
||||
esp_srmodel_deinit(models);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("test afe aec interface", "[afe]")
|
||||
{
|
||||
int start_size = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
|
||||
afe_aec_handle_t *handle = afe_aec_create("MNR", 4, AFE_TYPE_SR, AFE_MODE_HIGH_PERF);
|
||||
int frame_bytes = handle->frame_size * sizeof(int16_t);
|
||||
int16_t *indata = (int16_t *) malloc(frame_bytes*handle->pcm_config.total_ch_num);
|
||||
int16_t *outdata = (int16_t *) malloc(frame_bytes);
|
||||
afe_aec_handle_t *afe_aec_handle = afe_aec_create("MNR", 4, AFE_TYPE_SR, AFE_MODE_LOW_COST);
|
||||
aec_handle_t *aec_handle = aec_create(16000, 4, 1, AEC_MODE_SR_LOW_COST);
|
||||
int frame_size = afe_aec_handle->frame_size;
|
||||
int nch = afe_aec_handle->pcm_config.total_ch_num;
|
||||
int mic_idx = afe_aec_handle->pcm_config.mic_ids[0];
|
||||
int ref_idx = afe_aec_handle->pcm_config.ref_ids[0];
|
||||
int frame_bytes = frame_size * sizeof(int16_t);
|
||||
int16_t *afe_indata = (int16_t *)heap_caps_calloc(1, frame_bytes * nch, MALLOC_CAP_SPIRAM);
|
||||
int16_t *indata = (int16_t *)heap_caps_aligned_calloc(16, 1, frame_bytes, MALLOC_CAP_SPIRAM);
|
||||
int16_t *refdata = (int16_t *)heap_caps_aligned_calloc(16, 1, frame_bytes, MALLOC_CAP_SPIRAM);
|
||||
int16_t *outdata1 = (int16_t *)heap_caps_aligned_calloc(16, 1, frame_bytes, MALLOC_CAP_SPIRAM);
|
||||
int16_t *outdata2 = (int16_t *)heap_caps_aligned_calloc(16, 1, frame_bytes, MALLOC_CAP_SPIRAM);
|
||||
int chunks = 0;
|
||||
uint32_t c0, c1, t_aec = 0, t_afe_aec = 0;
|
||||
|
||||
afe_aec_process(handle, indata, outdata);
|
||||
afe_aec_process(handle, indata, outdata);
|
||||
afe_aec_process(handle, indata, outdata);
|
||||
while (1) {
|
||||
if ((chunks + 1) * frame_bytes <= sizeof(audio_mic_file)) {
|
||||
memcpy(indata, audio_mic_file + chunks * frame_size, frame_bytes);
|
||||
memcpy(refdata, audio_ref_file + chunks * frame_size, frame_bytes);
|
||||
|
||||
afe_aec_destroy(handle);
|
||||
for (int i = 0; i < frame_size; i++) {
|
||||
afe_indata[i * nch + mic_idx] = indata[i];
|
||||
afe_indata[i * nch + ref_idx] = refdata[i];
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
c0 = esp_timer_get_time();
|
||||
afe_aec_process(afe_aec_handle, afe_indata, outdata1);
|
||||
c1 = esp_timer_get_time();
|
||||
t_afe_aec += c1 - c0;
|
||||
|
||||
c0 = esp_timer_get_time();
|
||||
aec_process(aec_handle, indata, refdata, outdata2);
|
||||
c1 = esp_timer_get_time();
|
||||
|
||||
t_aec += c1 - c0;
|
||||
chunks++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < frame_size; i++) {
|
||||
assert(outdata1[i] == outdata2[i]);
|
||||
}
|
||||
printf("afe aec interface:%d\n, aec interface:%d\n", t_afe_aec, t_aec);
|
||||
afe_aec_destroy(afe_aec_handle);
|
||||
aec_destroy(aec_handle);
|
||||
free(afe_indata);
|
||||
free(indata);
|
||||
free(outdata);
|
||||
free(refdata);
|
||||
free(outdata1);
|
||||
free(outdata2);
|
||||
int end_size = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
TEST_ASSERT_EQUAL(true, end_size == start_size);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user