feat: Support C++

This commit is contained in:
xysun 2023-09-13 18:01:59 +08:00
parent 2b52031029
commit 35ff685da4
28 changed files with 171 additions and 11 deletions

View File

@ -32,6 +32,10 @@
#include "esp32s3/rom/cache.h" #include "esp32s3/rom/cache.h"
#endif #endif
#ifdef __cplusplus
extern "C" {
#endif
typedef int padding_state; typedef int padding_state;
// /** // /**
@ -407,5 +411,8 @@ dl_matrix2d_t *dl_basic_conv_layer(const dl_matrix2d_t *in, const dl_matrix2d_t
dl_matrix2d_t *dl_basic_conv_layer_quantised_weight(const dl_matrix2d_t *in, const dl_matrix2dq_t *weight, const dl_matrix2d_t *bias, int filter_width, int filter_height, dl_matrix2d_t *dl_basic_conv_layer_quantised_weight(const dl_matrix2d_t *in, const dl_matrix2dq_t *weight, const dl_matrix2d_t *bias, int filter_width, int filter_height,
const int out_channels, const int stride_x, const int stride_y, padding_state pad, const dl_matrix2d_t* out); const int out_channels, const int stride_x, const int stride_y, padding_state pad, const dl_matrix2d_t* out);
#ifdef __cplusplus
}
#endif #endif
#endif

View File

@ -19,6 +19,10 @@
#include "dl_lib_matrixq8.h" #include "dl_lib_matrixq8.h"
#include "cJSON.h" #include "cJSON.h"
#ifdef __cplusplus
extern "C" {
#endif
//Set this if the coefficient requested is a batch-normalization popvar matrix which needs to be preprocessed by //Set this if the coefficient requested is a batch-normalization popvar matrix which needs to be preprocessed by
//dl_batch_normalize_get_sqrtvar first. //dl_batch_normalize_get_sqrtvar first.
#define COEF_GETTER_HINT_BNVAR (1<<0) #define COEF_GETTER_HINT_BNVAR (1<<0)
@ -69,4 +73,8 @@ typedef struct {
const cJSON* (*getter_config)(void *arg); const cJSON* (*getter_config)(void *arg);
} model_coeff_getter_t; } model_coeff_getter_t;
#endif #ifdef __cplusplus
}
#endif
#endif

View File

@ -16,8 +16,11 @@
#include "dl_lib_matrix.h" #include "dl_lib_matrix.h"
typedef float fptp_t; #ifdef __cplusplus
extern "C" {
#endif
typedef float fptp_t;
//Flags for matrices //Flags for matrices
// #define DL_MF_FOREIGNDATA (0) /*< Matrix *item data actually points to another matrix and should not be freed */ // #define DL_MF_FOREIGNDATA (0) /*< Matrix *item data actually points to another matrix and should not be freed */
@ -170,4 +173,8 @@ fptp_t *dl_dilation_layer(dl_conv_queue_t *in, dl_conv_queue_t *out, int rate, i
void test_atrous_conv(int size, int rate, int in_channel, int out_channel); void test_atrous_conv(int size, int rate, int in_channel, int out_channel);
#endif #ifdef __cplusplus
}
#endif
#endif

View File

@ -20,6 +20,10 @@
#include "dl_lib_conv_queue.h" #include "dl_lib_conv_queue.h"
#include "dl_lib_convq_queue.h" #include "dl_lib_convq_queue.h"
#ifdef __cplusplus
extern "C" {
#endif
//[nch, n, c] //[nch, n, c]
typedef struct { typedef struct {
int n; /*< the length of queue */ int n; /*< the length of queue */
@ -290,4 +294,9 @@ void print_convq8(dl_convq8_queue_t *cq, int offset);
void print_convq(dl_convq_queue_t *cq, int offset); void print_convq(dl_convq_queue_t *cq, int offset);
void lstmq8_free(void); void lstmq8_free(void);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -18,6 +18,9 @@
#include "dl_lib_conv_queue.h" #include "dl_lib_conv_queue.h"
#include "dl_lib.h" #include "dl_lib.h"
#ifdef __cplusplus
extern "C" {
#endif
//fixed-point convolution FIFO queue. //fixed-point convolution FIFO queue.
//[nch, n, c] //[nch, n, c]
@ -372,4 +375,8 @@ void test_lstm_convq(int size, int in_dim, int lstm_cell);
void dl_nn_tanh_i162(dl_convq_queue_t **cqm, int offset, int nch); void dl_nn_tanh_i162(dl_convq_queue_t **cqm, int offset, int nch);
void dl_copy_queue_item_by_qmf(dl_convq_queue_t *cq, fptp_t* item, int m_bit, int f_bit, int offset, int ch); void dl_copy_queue_item_by_qmf(dl_convq_queue_t *cq, fptp_t* item, int m_bit, int f_bit, int offset, int ch);
void dl_convq_queue_mc_bzero(dl_convq_queue_t **cqm, int nch); void dl_convq_queue_mc_bzero(dl_convq_queue_t **cqm, int nch);
#endif #ifdef __cplusplus
}
#endif
#endif

View File

@ -21,6 +21,10 @@
#include "esp_system.h" #include "esp_system.h"
#endif #endif
#ifdef __cplusplus
extern "C" {
#endif
// #ifdef CONFIG_IDF_TARGET_ESP32S3 // #ifdef CONFIG_IDF_TARGET_ESP32S3
// #include "dl_tie728_bzero.h" // #include "dl_tie728_bzero.h"
// #endif // #endif
@ -249,5 +253,9 @@ inline static void dl_matrix_set(dl_matrix2d_t *m, const int x, const int y, fpt
void matrix_get_range(const dl_matrix2d_t *m, fptp_t *rmin, fptp_t *rmax); void matrix_get_range(const dl_matrix2d_t *m, fptp_t *rmin, fptp_t *rmax);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -17,6 +17,10 @@
#include <stdint.h> #include <stdint.h>
#include "dl_lib_matrix.h" #include "dl_lib_matrix.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef int16_t qtp_t; typedef int16_t qtp_t;
//Quantized matrix. Uses fixed numbers and has the storage for the rows/columns inverted //Quantized matrix. Uses fixed numbers and has the storage for the rows/columns inverted
@ -375,4 +379,9 @@ fptp_t dl_matrixq_get(const dl_matrix2dq_t *m, const int x, const int y);
*/ */
void dl_matrixq_set(dl_matrix2dq_t *m, const int x, const int y, fptp_t val); void dl_matrixq_set(dl_matrix2dq_t *m, const int x, const int y, fptp_t val);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -19,6 +19,10 @@
#include "dl_lib.h" #include "dl_lib.h"
#include "dl_lib_matrixq.h" #include "dl_lib_matrixq.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef int8_t q8tp_t; typedef int8_t q8tp_t;
typedef struct { typedef struct {
@ -68,4 +72,9 @@ dl_matrix2dq8_t *dl_matrixq8_copy_to_psram(const dl_matrix2dq8_t *m);
*/ */
dl_matrix2dq8_t *dl_matrixq8_from_matrix2d(const dl_matrix2d_t *m, dl_matrix2dq8_t *out); dl_matrix2dq8_t *dl_matrixq8_from_matrix2d(const dl_matrix2d_t *m, dl_matrix2dq8_t *out);
#endif #ifdef __cplusplus
}
#endif
#endif

View File

@ -4,6 +4,10 @@
#include "esp_wn_models.h" #include "esp_wn_models.h"
#include "esp_vad.h" #include "esp_vad.h"
#ifdef __cplusplus
extern "C" {
#endif
//AFE: Audio Front-End //AFE: Audio Front-End
//SR: Speech Recognition //SR: Speech Recognition
//afe_sr/AFE_SR: the audio front-end for speech recognition //afe_sr/AFE_SR: the audio front-end for speech recognition
@ -135,4 +139,8 @@ typedef struct {
.debug_init = false, \ .debug_init = false, \
.debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL}, {AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}}, \ .debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL}, {AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}}, \
} }
#endif
#ifdef __cplusplus
}
#endif #endif

View File

@ -2,6 +2,10 @@
#include "stdint.h" #include "stdint.h"
#include "esp_afe_config.h" #include "esp_afe_config.h"
#ifdef __cplusplus
extern "C" {
#endif
//AFE: Audio Front-End //AFE: Audio Front-End
//SR: Speech Recognition //SR: Speech Recognition
//afe_sr/AFE_SR: the audio front-end for speech recognition //afe_sr/AFE_SR: the audio front-end for speech recognition
@ -200,3 +204,7 @@ typedef struct {
esp_afe_sr_iface_op_enable_se_t enable_se; esp_afe_sr_iface_op_enable_se_t enable_se;
esp_afe_sr_iface_op_destroy_t destroy; esp_afe_sr_iface_op_destroy_t destroy;
} esp_afe_sr_iface_t; } esp_afe_sr_iface_t;
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,9 @@
#pragma once #pragma once
#ifdef __cplusplus
extern "C" {
#endif
#if defined CONFIG_USE_AFE #if defined CONFIG_USE_AFE
#include "esp_afe_sr_iface.h" #include "esp_afe_sr_iface.h"
@ -24,4 +28,8 @@ extern const esp_afe_sr_iface_t esp_afe_vc_v1;
#define ESP_AFE_SR_HANDLE esp_afe_sr_v1 #define ESP_AFE_SR_HANDLE esp_afe_sr_v1
#define ESP_AFE_VC_HANDLE esp_afe_vc_v1 #define ESP_AFE_VC_HANDLE esp_afe_vc_v1
#endif
#ifdef __cplusplus
}
#endif #endif

View File

@ -14,6 +14,10 @@
#ifndef _ESP_AGC_H_ #ifndef _ESP_AGC_H_
#define _ESP_AGC_H_ #define _ESP_AGC_H_
#ifdef __cplusplus
extern "C" {
#endif
////all positive value is valid, negective is error ////all positive value is valid, negective is error
typedef enum { typedef enum {
ESP_AGC_SUCCESS = 0, ////success ESP_AGC_SUCCESS = 0, ////success
@ -28,4 +32,9 @@ void set_agc_config(void *agc_handle, int gain_dB, int limiter_enable, int targe
int esp_agc_process(void *agc_handle, short *in_pcm, short *out_pcm, int frame_size, int sample_rate); int esp_agc_process(void *agc_handle, short *in_pcm, short *out_pcm, int frame_size, int sample_rate);
void esp_agc_close(void *agc_handle); void esp_agc_close(void *agc_handle);
#ifdef __cplusplus
}
#endif
#endif // _ESP_AGC_H_ #endif // _ESP_AGC_H_

View File

@ -11,6 +11,12 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License // limitations under the License
#ifndef _ESP_MASE_H_
#define _ESP_MASE_H_
#ifdef __cplusplus
extern "C" {
#endif
#define MASE_SAMPLE_RATE 16000 // Supports 16kHz only #define MASE_SAMPLE_RATE 16000 // Supports 16kHz only
#define MASE_FRAME_SIZE 16 // Supports 16ms only #define MASE_FRAME_SIZE 16 // Supports 16ms only
@ -78,4 +84,10 @@ void mase_process(mase_handle_t st, int16_t *in, int16_t *dsp_out);
* @return None * @return None
* *
*/ */
void mase_destory(mase_handle_t st); void mase_destory(mase_handle_t st);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,9 @@
#pragma once #pragma once
#include "stdint.h" #include "stdint.h"
#include "esp_wn_iface.h" #include "esp_wn_iface.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ESP_MN_RESULT_MAX_NUM 5 #define ESP_MN_RESULT_MAX_NUM 5
#define ESP_MN_MAX_PHRASE_NUM 400 #define ESP_MN_MAX_PHRASE_NUM 400
@ -213,3 +216,7 @@ typedef struct {
esp_mn_iface_op_print_active_speech_commands print_active_speech_commands; esp_mn_iface_op_print_active_speech_commands print_active_speech_commands;
esp_mn_iface_op_check_speech_command check_speech_command; esp_mn_iface_op_check_speech_command check_speech_command;
} esp_mn_iface_t; } esp_mn_iface_t;
#ifdef __cplusplus
}
#endif

View File

@ -4,7 +4,9 @@
//Contains declarations of all available speech recognion models. Pair this up with the right coefficients and you have a model that can recognize //Contains declarations of all available speech recognion models. Pair this up with the right coefficients and you have a model that can recognize
//a specific phrase or word. //a specific phrase or word.
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* @brief Get the multinet handle from model name * @brief Get the multinet handle from model name
* *
@ -59,3 +61,6 @@ if (r>0) {
model->destroy(model_data) model->destroy(model_data)
*/ */
#ifdef __cplusplus
}
#endif

View File

@ -1,6 +1,10 @@
#pragma once #pragma once
#include "stdint.h" #include "stdint.h"
#ifdef __cplusplus
extern "C" {
#endif
//Opaque model data container //Opaque model data container
typedef struct model_iface_data_t model_iface_data_t; typedef struct model_iface_data_t model_iface_data_t;
@ -183,3 +187,7 @@ typedef struct {
esp_wn_iface_op_clean_t clean; esp_wn_iface_op_clean_t clean;
esp_wn_iface_op_destroy_t destroy; esp_wn_iface_op_destroy_t destroy;
} esp_wn_iface_t; } esp_wn_iface_t;
#ifdef __cplusplus
}
#endif

View File

@ -1,6 +1,9 @@
#pragma once #pragma once
#include "esp_wn_iface.h" #include "esp_wn_iface.h"
#ifdef __cplusplus
extern "C" {
#endif
// The prefix of wakenet model name is used to filter all wakenet from availabel models. // The prefix of wakenet model name is used to filter all wakenet from availabel models.
#define ESP_WN_PREFIX "wn" #define ESP_WN_PREFIX "wn"
@ -98,6 +101,10 @@ char* esp_wn_wakeword_from_name(const char *model_name);
#define WAKENET_COEFF "COEFF_NULL" #define WAKENET_COEFF "COEFF_NULL"
#endif #endif
#ifdef __cplusplus
}
#endif
/* /*
static const sr_model_iface_t *model = esp_wn_handle_from_name(model_name); static const sr_model_iface_t *model = esp_wn_handle_from_name(model_name);

View File

@ -139,7 +139,8 @@ typedef struct {
.debug_init = false, \ .debug_init = false, \
.debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL}, {AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}}, \ .debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL}, {AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}}, \
} }
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

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.

View File

@ -15,6 +15,10 @@
#include "esp_err.h" #include "esp_err.h"
#include "esp_mn_iface.h" #include "esp_mn_iface.h"
#ifdef __cplusplus
extern "C" {
#endif
/* /*
esp_mn_node_t is a singly linked list which is used to manage speech commands. esp_mn_node_t is a singly linked list which is used to manage speech commands.
It is easy to add one speech command into linked list and remove one speech command from linked list. It is easy to add one speech command into linked list and remove one speech command from linked list.
@ -170,4 +174,8 @@ void esp_mn_commands_print(void);
/** /**
* @brief Print all active commands. * @brief Print all active commands.
*/ */
void esp_mn_active_commands_print(void); void esp_mn_active_commands_print(void);
#ifdef __cplusplus
}
#endif

View File

@ -2,6 +2,10 @@
#include "esp_err.h" #include "esp_err.h"
#include "esp_mn_iface.h" #include "esp_mn_iface.h"
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* @brief Check chip config to ensure optimum performance * @brief Check chip config to ensure optimum performance
*/ */
@ -21,3 +25,7 @@ void check_chip_config(void);
* - ESP_ERR_INVALID_STATE Fail * - ESP_ERR_INVALID_STATE Fail
*/ */
esp_mn_error_t* esp_mn_commands_update_from_sdkconfig(const esp_mn_iface_t *multinet, model_iface_data_t *model_data); esp_mn_error_t* esp_mn_commands_update_from_sdkconfig(const esp_mn_iface_t *multinet, model_iface_data_t *model_data);
#ifdef __cplusplus
}
#endif

View File

@ -5,7 +5,9 @@
#include "esp_partition.h" #include "esp_partition.h"
#endif #endif
#define ESP_SR_IDF_V5 #ifdef __cplusplus
extern "C" {
#endif
typedef struct { typedef struct {
int num; // the number of files int num; // the number of files
@ -119,4 +121,9 @@ srmodel_list_t *get_static_srmodels(void);
* @return model_coeff_getter_t pointer or NULL * @return model_coeff_getter_t pointer or NULL
*/ */
model_coeff_getter_t *srmodel_get_model_coeff(char *model_name); model_coeff_getter_t *srmodel_get_model_coeff(char *model_name);
#endif
#ifdef __cplusplus
}
#endif #endif