code
stringlengths 1
1.05M
| repo_name
stringlengths 6
83
| path
stringlengths 3
242
| language
stringclasses 222
values | license
stringclasses 20
values | size
int64 1
1.05M
|
|---|---|---|---|---|---|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
// All rights reserved.
#ifndef _OPUS_DECODER_H_
#define _OPUS_DECODER_H_
#include "esp_err.h"
#include "audio_element.h"
#include "audio_common.h"
#ifdef __cplusplus
extern "C" {
#endif
#define OPUS_DECODER_TASK_STACK_SIZE (30 * 1024)
#define OPUS_DECODER_TASK_CORE (0)
#define OPUS_DECODER_TASK_PRIO (5)
#define OPUS_DECODER_RINGBUFFER_SIZE (2 * 1024)
#define DEFAULT_OPUS_DECODER_CONFIG() { \
.out_rb_size = OPUS_DECODER_RINGBUFFER_SIZE, \
.task_stack = OPUS_DECODER_TASK_STACK_SIZE, \
.task_core = OPUS_DECODER_TASK_CORE, \
.task_prio = OPUS_DECODER_TASK_PRIO, \
.stack_in_ext = true, \
}
/**
* @brief OPUS Decoder configuration
*/
typedef struct {
int out_rb_size; /*!< Size of output ringbuffer */
int task_stack; /*!< Task stack size */
int task_core; /*!< CPU core number (0 or 1) where decoder task in running */
int task_prio; /*!< Task priority (based on freeRTOS priority) */
bool stack_in_ext; /*!< Try to allocate stack in external memory */
} opus_decoder_cfg_t;
/**
* @brief Create an Audio Element handle to decode incoming OPUS data
*
* @param config The configuration
*
* @return The audio element handle
*/
audio_element_handle_t decoder_opus_init(opus_decoder_cfg_t *config);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/codec/opus_decoder.h
|
C
|
apache-2.0
| 1,601
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
// All rights reserved.
#ifndef _OPUS_ENCODER_H_
#define _OPUS_ENCODER_H_
#include "esp_err.h"
#include "audio_element.h"
#include "audio_common.h"
#ifdef __cplusplus
extern "C" {
#endif
#define OPUS_ENCODER_TASK_STACK (40 * 1024)
#define OPUS_ENCODER_TASK_CORE (0)
#define OPUS_ENCODER_TASK_PRIO (3)
#define OPUS_ENCODER_RINGBUFFER_SIZE (2 * 1024)
#define OPUS_ENCODER_SAMPLE_RATE (16000)
#define OPUS_ENCODER_CHANNELS (1)
#define OPUS_ENCODER_BITRATE (64000)
#define OPUS_ENCODER_COMPLEXITY (10)
#define DEFAULT_OPUS_ENCODER_CONFIG() { \
.sample_rate = OPUS_ENCODER_SAMPLE_RATE, \
.channel = OPUS_ENCODER_CHANNELS, \
.bitrate = OPUS_ENCODER_BITRATE, \
.complexity = OPUS_ENCODER_COMPLEXITY, \
.out_rb_size = OPUS_ENCODER_RINGBUFFER_SIZE, \
.task_stack = OPUS_ENCODER_TASK_STACK, \
.task_core = OPUS_ENCODER_TASK_CORE, \
.task_prio = OPUS_ENCODER_TASK_PRIO, \
.stack_in_ext = true, \
}
/**
* @brief OPUS Encoder configurations
*/
typedef struct {
int sample_rate; /*!< the sample rate of OPUS audio*/
int channel; /*!< the numble of channels of OPUS audio*/
int bitrate; /*!< the rate of bit of OPUS audio. unit:bps*/
int complexity; /*!< Indicates the complexity of OPUS encoding. 0 is lowest. 10 is higest.*/
int out_rb_size; /*!< Size of output ringbuffer */
int task_stack; /*!< Task stack size */
int task_core; /*!< Task running in core (0 or 1) */
int task_prio; /*!< Task priority (based on freeRTOS priority) */
bool stack_in_ext; /*!< Try to allocate stack in external memory */
} opus_encoder_cfg_t;
/**
* @brief Set OPUS encoder music info
*
* @param self Audio element handle
*
* @param sample_rate The sample rate of OPUS audio
*
* @param channel The numble of channels of OPUS audio
*
* @param bit The bit of OPUS audio
*
* @return
* ESP_OK
* ESP_FAIL
*/
esp_err_t opus_encoder_set_music_info(audio_element_handle_t self, int sample_rate, int channel, int bit);
/**
* @brief Set OPUS encoder bitrate
*
* @param self Audio element handle
*
* @param bitrate The bitrate of OPUS audio
*
* @return
* ESP_OK
* ESP_FAIL
*/
esp_err_t opus_encoder_set_bitrate(audio_element_handle_t self, int bitrate);
/**
* @brief Set OPUS encoder complexity
*
* @param self Audio element handle
*
* @param complexity Encode complexity choose, 0 is lowest. 10 is higest
*
* @return
* ESP_OK
* ESP_FAIL
*/
esp_err_t opus_encoder_set_complexity(audio_element_handle_t self, int complexity);
/**
* @brief Create an Audio Element handle to encode incoming opus data
*
* @param config The configuration
*
* @return The audio element handle
*/
audio_element_handle_t encoder_opus_init(opus_encoder_cfg_t *config);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/codec/opus_encoder.h
|
C
|
apache-2.0
| 3,480
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD.>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _PCM_DECODER_H_
#define _PCM_DECODER_H_
#include "esp_err.h"
#include "audio_element.h"
#ifdef __cplusplus
extern "C" {
#endif
#define PCM_DECODER_TASK_STACK (3 * 1024)
#define PCM_DECODER_TASK_CORE (0)
#define PCM_DECODER_TASK_PRIO (5)
#define PCM_DECODER_RINGBUFFER_SIZE (8 * 1024)
#define DEFAULT_PCM_DECODER_CONFIG() { \
.out_rb_size = PCM_DECODER_RINGBUFFER_SIZE, \
.task_stack = PCM_DECODER_TASK_STACK, \
.task_core = PCM_DECODER_TASK_CORE, \
.task_prio = PCM_DECODER_TASK_PRIO, \
.stack_in_ext = true, \
.rate = 44100, \
.bits = 16, \
.channels = 2, \
}
/**
* @note The sample rate and channle of PCM should be specific by user with `audio_element_setinfo`.
*/
/**
* @brief PCM Decoder configurations
*/
typedef struct {
int out_rb_size; /*!< Size of output ringbuffer */
int task_stack; /*!< Task stack size */
int task_core; /*!< Task running in core (0 or 1) */
int task_prio; /*!< Task priority (based on freeRTOS priority) */
bool stack_in_ext; /*!< Try to allocate stack in external memory */
int rate; /*!< Sample rates in Hz */
int bits; /*!< Bit wide */
int channels; /*!< Number of audio channel, mono is 1, stereo is 2 */
} pcm_decoder_cfg_t;
/**
* @brief Create an Audio Element handle to decode incoming PCM data
*
* @param config The configuration
*
* @return The audio element handle
*/
audio_element_handle_t pcm_decoder_init(pcm_decoder_cfg_t *config);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/codec/pcm_decoder.h
|
C
|
apache-2.0
| 3,213
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD.>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _WAV_DECODER_H_
#define _WAV_DECODER_H_
#include "esp_err.h"
#include "audio_element.h"
#ifdef __cplusplus
extern "C" {
#endif
#define WAV_DECODER_TASK_STACK (3 * 1024)
#define WAV_DECODER_TASK_CORE (0)
#define WAV_DECODER_TASK_PRIO (5)
#define WAV_DECODER_RINGBUFFER_SIZE (8 * 1024)
#define DEFAULT_WAV_DECODER_CONFIG() { \
.out_rb_size = WAV_DECODER_RINGBUFFER_SIZE, \
.task_stack = WAV_DECODER_TASK_STACK, \
.task_core = WAV_DECODER_TASK_CORE, \
.task_prio = WAV_DECODER_TASK_PRIO, \
.stack_in_ext = true, \
}
/**
* brief WAV Decoder configurations
*/
typedef struct {
int out_rb_size; /*!< Size of output ringbuffer */
int task_stack; /*!< Task stack size */
int task_core; /*!< Task running in core (0 or 1) */
int task_prio; /*!< Task priority (based on freeRTOS priority) */
bool stack_in_ext; /*!< Try to allocate stack in external memory */
} wav_decoder_cfg_t;
/**
* @brief Create an Audio Element handle to decode incoming WAV data
*
* @param config The configuration
*
* @return The audio element handle
*/
audio_element_handle_t wav_decoder_init(wav_decoder_cfg_t *config);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/codec/wav_decoder.h
|
C
|
apache-2.0
| 2,697
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
// All rights reserved.
#ifndef _WAV_ENCODER_H_
#define _WAV_ENCODER_H_
#include "esp_err.h"
#include "audio_element.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief WAV Encoder configurations
*/
typedef struct {
int out_rb_size; /*!< Size of output ringbuffer */
int task_stack; /*!< Task stack size */
int task_core; /*!< Task running in core (0 or 1) */
int task_prio; /*!< Task priority (based on freeRTOS priority) */
bool stack_in_ext; /*!< Try to allocate stack in external memory */
} wav_encoder_cfg_t;
#define WAV_ENCODER_TASK_STACK (3 * 1024)
#define WAV_ENCODER_TASK_CORE (0)
#define WAV_ENCODER_TASK_PRIO (5)
#define WAV_ENCODER_RINGBUFFER_SIZE (8 * 1024)
#define DEFAULT_WAV_ENCODER_CONFIG() {\
.out_rb_size = WAV_ENCODER_RINGBUFFER_SIZE,\
.task_stack = WAV_ENCODER_TASK_STACK,\
.task_core = WAV_ENCODER_TASK_CORE,\
.task_prio = WAV_ENCODER_TASK_PRIO,\
.stack_in_ext = true,\
}
/**
* @brief Create a handle to an Audio Element to encode incoming data using WAV format
*
* @param config The configuration
*
* @return The audio element handle
*/
audio_element_handle_t wav_encoder_init(wav_encoder_cfg_t *config);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/codec/wav_encoder.h
|
C
|
apache-2.0
| 1,490
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD.>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _ESP_AUDIO_ALC_H_
#define _ESP_AUDIO_ALC_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief ALC Configuration
*/
typedef struct {
unsigned char *in_buf; /*!< Input buffer */
int volume; /*!< Volume of input stream. The volume can be set.*/
int channel; /*!< Number of channels for input stream */
void *handle; /*!< The handle for setting volume */
} volume_set_t;
/**
* @brief Initialise volume setup with ALC
*
* @return Handle for setting volume
*/
void *alc_volume_setup_open();
/**
* @brief Stop and cleanup the handle for setting volume with ALC
*
* @param handle the handle for setting volume
*/
void alc_volume_setup_close(void *handle);
/**
* @brief Process data buffer by setting volume with ALC
*
* @param buffer input and output buffer
* @param bytes size of `buffer`. unit: bytes
* @param channels the number of channels for input stream
* @param handle the handle for setting volume
* @param volume the volume to be set to
*
* @return -1 the number of channels for input stream is not 1 or 2
* 0 success
*/
int alc_volume_setup_process(void *buffer, unsigned int bytes, int channels, void *handle, int volume);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/processing/esp_alc.h
|
C
|
apache-2.0
| 2,687
|
// Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD.>
// All rights reserved.
#ifndef _ESP_DOWNMIX_H_
#define _ESP_DOWNMIX_H_
#ifdef __cplusplus
extern "C"
{
#endif
#define GAIN_MAX 100 /*!< the maximum gain of input stream */
#define GAIN_MIN -100 /*!< the minimum gain of input stream */
#define SAMPLERATE_MAX 100000 /*!< the maximum samplerate of input stream */
#define SAMPLERATE_MIN 4000 /*!< the minimum samplerate of input stream */
#define SOURCE_NUM_MAX 8 /*!< the maximum number of input streams */
/**
Function Description
Mixing less or equal than`SOURCE_NUM_MAX` of input streams into output stream with the correspondingly gains. And the number of channels of output stream can be set. refer to `esp_downmix_output_type_t`.
The downmix process has 3 work status:
* Bypass Downmixing -- Only the first streams will be played;
* Switch on Downmixing -- All input streams will enter the transition period, during which the gains of these streams will be changed from the original level to the target level; then enter the stable period, sharing a same target gain;
* Switch off Downmixing -- All input streams and the others stream will enter the transition period, during which the gains of these streams will be changed back to their original levels; then enter the stable period, with their original gains, respectively. After that, the audio device enters the bypass status.
Note that, the sample rates of all input streams must be the same. Otherwise, an error occurs.
*/
/**
* @brief The type of output stream
*/
typedef enum {
ESP_DOWNMIX_OUTPUT_TYPE_ONE_CHANNEL = 1, /*!< Output stream is mono */
ESP_DOWNMIX_OUTPUT_TYPE_TWO_CHANNEL = 2, /*!< Output stream is stereo */
ESP_DOWNMIX_OUTPUT_TYPE_MAX, /*!< The maximum value */
} esp_downmix_output_type_t;
/**
* @brief The work status of mixer
*/
typedef enum {
ESP_DOWNMIX_WORK_MODE_INVALID = -1, /*!< Invalid status */
ESP_DOWNMIX_WORK_MODE_BYPASS = 0, /*!< Only the first stream will be played */
ESP_DOWNMIX_WORK_MODE_SWITCH_ON = 1, /*!< The all input stream will enter the transition period, during which the gains of these will be changed from the original level to the target level; then enter the stable period, sharing a same target gain */
ESP_DOWNMIX_WORK_MODE_SWITCH_OFF = 2, /*!< The all input stream will enter the transition period, during which the gains of these will be changed back to their original levels; then enter the stable period, with their original gains, respectively. After that, the audio device enters the bypass status */
ESP_DOWNMIX_WORK_MODE_MAX, /*!< The maximum value */
} esp_downmix_work_mode_t;
/**
* @brief Content of per channel of output stream
*
* @note If output stream is stereo, the function of `ESP_DOWNMIX_OUT_CTX_ONLY_LEFT` and `ESP_DOWNMIX_OUT_CTX_ONLY_RIGHT` is the same as `ESP_DOWNMIX_OUT_CTX_NORMAL`.
*/
typedef enum {
ESP_DOWNMIX_OUT_CTX_LEFT_RIGHT = 0, /*!< Include left and right channel content of all input streams in per channel of output stream */
ESP_DOWNMIX_OUT_CTX_ONLY_LEFT = 1, /*!< Include only left channel content of all input streams in per channel of output stream. */
ESP_DOWNMIX_OUT_CTX_ONLY_RIGHT = 2, /*!< Include only right channel content of all input streams in per channel of output stream. */
ESP_DOWNMIX_OUT_CTX_NORMAL = 3, /*!< Include left or right channel content of all input streams in left or right channel of output stream respectively. If all input streams are mono, per channel of output stream contain all content of all input streams.*/
ESP_DOWNMIX_OUT_CTX_MAX, /*!< The maximum value. */
} esp_downmix_out_ctx_type_t;
/**
* @brief Input stream infomation
*/
typedef struct {
int samplerate; /*!< Sample rate */
int channel; /*!< the number of channel(s) of the input stream;*/
int bits_num; /*!< Only 16-bit PCM audio is supported */
float gain[2]; /*!< The gain is expressed using the logarithmic decibel (dB) units (dB gain).
When the downmixing is switched on, the gains of the input streams will be gradually changed from gain[0] to gain[1] in the transition period, and stay at gain[1] in the stable period;
When the downmixing is switched off, the gains of the input streams will be gradually changed back from gain[1] to gain[0] in the transition period, and stay at gain[0] in the stable period;
For the input streams:
- gain[0]: the original gain of the input streams before the downmixing process. Usually, if the downmixing is not used, gain[0] is usually set to 0 dB.
- gain[1]: the target gain of the input streams after the downmixing process.*/
int transit_time; /*!< The length of the transition period in milliseconds, which is the same for "switch on down-mixing" and "switch off down-mixing". */
} esp_downmix_input_info_t;
/**
* @brief Downmix information
*/
typedef struct {
esp_downmix_input_info_t *source_info; /*!< Input streams infomation*/
int source_num; /*!< The number of input streams*/
esp_downmix_out_ctx_type_t out_ctx; /*!< Select content of per channel of output stream. refer to `esp_downmix_out_ctx_type_t`*/
esp_downmix_work_mode_t mode; /*!< The work status with downmixing. refer to `esp_downmix_work_mode_t`*/
esp_downmix_output_type_t output_type; /*!< The type of output stream by processed downmix*/
} esp_downmix_info_t;
/**
* @brief Creates the Downmix handle
*
* @param downmix the downmix information
*
* @return The Downmix handle for esp_downmix_process and esp_downmix_close. NULL: creating Downmix handle failed
*/
void *esp_downmix_open(esp_downmix_info_t *downmix);
/**
* @brief Processes the stream through downmixing.
*
* @param downmix_handle the Downmix handle created and returned by esp_downmix_open()
* @param inbuf the buffer that stores the input stream, which is in PCM format
* @param outbuf the buffer that stores the output stream, which is in PCM format
* @param sample The number of sample per downmix processing
* @param work_mode the work mode. For details, please check the description in esp_downmix_work_mode_t.
*
* @return The length of the output stream (in bytes), which is also in PCM format. A negative return value indicates an error has occurred.
*/
int esp_downmix_process(void *downmix_handle, unsigned char *inbuf[], unsigned char *outbuf, int sample, esp_downmix_work_mode_t work_mode);
/**
* @brief Releases the Downmix handle.
*
* @param downmix_handle the Downmix handle.
*/
void esp_downmix_close(void *downmix_handle);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/processing/esp_downmix.h
|
C
|
apache-2.0
| 7,179
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
// All rights reserved.
#ifndef _ESP_EQUALIZER_H
#define _ESP_EQUALIZER_H
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief Initialize the equalizer handle
*
* @param nch The audio channel number
* @param g_rate The audio sample rate. Four sample rates are supported: 11025Hz, 22050Hz, 44100Hz and 48000Hz.
* @param n_band The number of audio sub-bands. Fixed number of 10 sub-bands is supported and this value should be set to 10.
* @param use_xmms_original_freqs Currently should be set 0
*
* @return The equalizer handle.
*/
void *esp_equalizer_init(int nch, int g_rate, int n_band, int use_xmms_original_freqs);
/**
* @brief Uninitialize the equalizer handle.
*
* @param handle The the equalizer handle
*/
void esp_equalizer_uninit(void *handle);
/**
* @brief Process the data through the equalizer
*
* @param handle The the equalizer handle
* @param pcm_buf The audio pcm input & output buffer
* @param length The length of current bytes in pcm_buf
* @param g_rate The audio sample rate. Four sample rates are supported: 11025Hz, 22050Hz, 44100Hz and 48000Hz.
* @param nch The audio channel number
*
* @return Length of pcm_buf after processing
*/
int esp_equalizer_process(void *handle, unsigned char *pcm_buf, int length, int g_rate, int nch);
/**
* @brief Set the number of sub-bands for the equalizer
*
* @param handle The the equalizer handle
* @param value The audio sub-bands gain. unit:db. 0 means no gain.
* @param index The index of audio sub-bands. e.g. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
* @param nch The audio channel number
*/
void esp_equalizer_set_band_value(void *handle, float value, int index, int nch);
/**
* @brief Get the number of the equalizer sub-bands
*
* @param handle The the equalizer handle
*
* @return The number of the equalizer sub-bands
*/
int esp_equalizer_get_band_count(void *handle);
/**
* @brief Get the value of the equalizer sub-bands
*
* @param handle The the equalizer handle
* @param index The index of audio sub-bands. Currently only support 10 sub-bands, so it should be 0-9.
* @param nch The audio channel number
*
* @return The number of the equalizer sub-bands
*/
float esp_equalizer_get_band_value(void *handle, int index, int nch);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/processing/esp_equalizer.h
|
C
|
apache-2.0
| 2,539
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
// All rights reserved.
#ifndef _ESPRESSIF_RESAMPLE_H_
#define _ESPRESSIF_RESAMPLE_H_
#ifdef __cplusplus
extern "C" {
#endif
#define PCM_INOUT_NUM_RESTRICT (2)
#define COMPLEXITY_MAX_NUM (5)
#if (PCM_INOUT_NUM_RESTRICT < 0) || (PCM_INOUT_NUM_RESTRICT > 64)
#error input/output PCM number restrict setup error
#endif
typedef enum {
ESP_RSP_PREFER_TYPE_MEMORY = 0, /*!< INRAM usage lesser and CPU usage higher than `ESP_RSP_PREFER_TYPE_SPEED`*/
ESP_RSP_PREFER_TYPE_SPEED = 1, /*!< INRAM usage higher and CPU usage lower than `ESP_RSP_PREFER_TYPE_MEMORY`*/
} esp_rsp_prefer_type_t;
typedef enum {
RESAMPLE_SUCCESS = 1, /*!< Any positive value indicates success resampling. Here, the vaule 1 is just an example. The function will return the actual length of the PCM data (in bytes). */
RESAMPLE_FAIL = 0, /*!< Error occurs during the resampling. */
RESAMPLE_SRC_RATE_CHANGE = -1, /*!< The sampling rate of the source file has changed. */
RESAMPLE_SRC_CH_CHANGE = -2, /*!< The number of channel(s) of the source file has changed. */
RESAMPLE_DEST_RATE_CHANGE = -3, /*!< The sampling rate of the destination file has changed.*/
RESAMPLE_DEST_CH_CHANGE = -4, /*!< The number of channel(s) of the destination file has changed. */
RESAMPLE_MODE_CHANGE = -5, /*!< The resampling mode has changed. */
RESAMPLE_TYPE_CHANGE = -6, /*!< The resampling type has changed. */
RESAMPLE_COMPLEXITY_CHANGE = -7, /*!< The complexity parameter has changed. */
RESAMPLE_IN_DATA_OVER_LENGTH = -8, /*!< The size of the input data exceeds the set buffer size. */
RESAMPLE_SAMPLE_BITS_NOT_SUPPORT = -9, /*!< The only supported bit width is 16 bits. The function will return -9 if other bit widths are used. */
RESAMPLE_IN_DATA_BUF_TOO_SMALL = -10, /*!< The size of the input buffer is not enough. This error may occur when the buffer of the output PCM data is set too big. Only valid in encoing mode. */
RESAMPLE_IN_DATA_NUM_ERROR = -11, /*!< The actual size of the input data, which equals the size of the input buffer multiplied by the number of channel(s) of the input data, exceeds the maximum value set in the configuration. */
RESAMPLE_OUT_DATA_NUM_ERROR = -12, /*!< The actual size of the output buffer is not equal to the output buffer size set in the configuration.*/
RESAMPLE_IN_BUF_ALIGNED_ERROR = -13, /*!< The buffer of the input PCM data is not byte aligned. */
RESAMPLE_DOWN_CH_IDX_CHANGE = -14, /*!< The currently selected channel (right or left) is not equal to the channel selected in configuration. This error is only triggered when the complexity parameter is set to 0 and the number of channel(s) of the input file has changed from dual to mono. */
} esp_resp_err_t;
typedef enum {
ESP_RESAMPLE_TYPE_AUTO = -1, /*!<automatically select the following type */
ESP_RESAMPLE_TYPE_DECIMATE = 0, /*!<only down-sampling, for integer time down-sampling case, like 48000 to 24000 or 12000 or 8000 */
ESP_RESAMPLE_TYPE_INTERP = 1, /*!<only up-sampling, for interger time up-sampling case, like 8000 to 16000 or 24000 or 48000 */
ESP_RESAMPLE_TYPE_RESAMPLE = 2, /*!<first up-sampling, then down-sampling, for non-integer case, like 44100 to 48000 */
ESP_RESAMPLE_TYPE_BYPASS = 3, /*!<source sample rate and target sample rate equal case, just by pass */
}esp_resample_type_t;
/**
* @brief Resampling supports two modes
* - Mode 0: decoding mode
* - Mode 1: encoding mode
*/
typedef enum {
RESAMPLE_DECODE_MODE = 0, /*!<In decoding mode, the buffer size of the input stream data is a constant, while the size of the output stream data changes from the size of the input stream data */
RESAMPLE_ENCODE_MODE = 1, /*!<In encoding mode, the buffer size of the output file is a constant, while the size of the input file changes from the output file. Note that, you have to store enough data in the input buffer, the minumum requirement of which is relevant to the parameter RESAMPLING_POINT_NUM. The resampling returns the size of the input file that is actually used. */
} esp_resample_mode_t;
/**
* @brief Resampling Filter Configuration
*/
typedef struct {
int src_rate; /*!< The sampling rate of the source PCM data */
int src_ch; /*!< The number of channel(s) of the source PCM data */
int dest_rate; /*!< The sampling rate of the destination PCM data */
int dest_ch; /*!< The number of channel(s) of the destination PCM data */
int sample_bits; /*!< The bit width of the PCM data. Currently, the only supported bit width is 16 bits. */
esp_resample_mode_t mode; /*!< The resampling mode (the encoding mode and the decoding mode) */
int max_indata_bytes; /*!< The maximum buffer size of the input PCM (in bytes) */
int out_len_bytes; /*!< The buffer length of the output stream data. This parameter must be configured in encoding mode. */
esp_resample_type_t type; /*!< The resampling type (Automatic, Upsampling and Downsampling), which can be selected manually at the integer multiples of the resampling cycle. */
int complexity; /*!< Indicates the complexity of the resampling. This parameter is only valid when a FIR filter is used. Range: 0~4; O indicates the lowest complexity, which means the accuracy is the lowest and the speed is the fastest; Meanwhile, 4 indicates the highest complexity, which means the accuracy is the highest and the speed is the slowest.*/
int down_ch_idx; /*!< Indicates the channel that is selected (the right channel or the left channel). This parameter is only valid when the complexity parameter is set to 0 and the number of channel(s) of the input file has changed from dual to mono. */
esp_rsp_prefer_type_t prefer_flag; /*!< The select flag about lesser CPU usage or lower INRAM usage */
} resample_info_t;
/**
* @brief Initializes the resampling parameters
*
* @param[in] info the information of resampling parameters
* @param[out] p_in the buffer of the input PCM data
* @param[out] p_out the buffer of the output PCM data
*
* @return the resampling handle succeed
* NULL failed
*/
void *esp_resample_create(void *info, unsigned char **p_in, unsigned char **p_out);
/**
* @brief Changes the sampling rate of the source file to that of the destination file
*
* @param[in] handle the resampling handle
* @param[in] info the information of resampling parameters
* @param[in] p_in the buffer of the input PCM data. And it must be `p_in` of `esp_resample_create`.
* @param[in] p_out the buffer of the output PCM data. And it must be `p_out` of `esp_resample_create`.
* @param[in] in_data_size the length of the PCM data in `p_in` (in bytes).
* In `RESAMPLE_DECODE_MODE`, it must equal `max_indata_bytes` in `resample_info_t`.
* In `RESAMPLE_ENCODE_MODE`, it could be lesser than or equal `max_indata_bytes` in `resample_info_t`. And the function will return consume byte.
* @param out_data_size the length of the PCM stream data in `p_out` (in bytes).
* In `RESAMPLE_ENCODE_MODE`, it must be set to user wanted output size. And the value must be the integral multiple of ``sizeof(short) * `src_ch``
*
* @return esp_resp_err_t Positive value: the consume size of the input PCM stream data; Others: error occurs (Please refer to esp_resp_err_t)
*/
esp_resp_err_t esp_resample_run(void *handle, void *info, unsigned char *p_in, unsigned char *p_out, int in_data_size, int *out_data_size);
/**
* @brief Destroys the resampling handle
*
* @param[in] handle the resampling handle
*/
void esp_resample_destroy(void *handle);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/processing/esp_resample.h
|
C
|
apache-2.0
| 8,369
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
// All rights reserved.
#ifndef __ESP_SONIC_H__
#define __ESP_SONIC_H__
#ifdef __cplusplus
extern "C"
{
#endif
/* This specifies the range of voice pitches we try to match.
Note that if we go lower than 65, we could overflow in findPitchInRange */
#define SONIC_MIN_PITCH 65
#define SONIC_MAX_PITCH 400
/* For all of the following functions, numChannels is multiplied by numSamples
to determine the actual number of values read or returned. */
/**
* @brief Create a sonic stream
*
* @param sample_rate The sample rate of the stream
* @param channels The number channel(s) of the stream (1 : mono, 2 : dual)
*
* @return allocate the stream. NULL only if we are out of memory and cannot
*/
void* esp_sonic_create_stream(int sample_rate, int channels);
/**
* @brief Set the resample method
*
* @param handle The handle of the sonic stream
* @param resample_linear_interpolate 1 for linear interpolation, faster but lower accuracy
*/
void esp_sonic_set_resample_mode(void* handle, int resample_linear_interpolate);
/**
* @brief Set the speed of the stream
*
* @param handle The handle of the sonic stream
* @param speed The scaling factor of speed of the stream
*/
void esp_sonic_set_speed(void* handle, float speed);
/**
* @brief Set the pitch of the stream
*
* @param handle The handle of the sonic stream
* @param pitch The scaling factor of pitch of the stream
*/
void esp_sonic_set_pitch(void* handle, float pitch);
/**
* @brief Set the rate of the stream
*
* @param handle The handle of the sonic stream
* @param rate The rate of the stream
*/
void esp_sonic_set_rate(void* handle, float rate);
/**
* @brief Set the scaling factor of the stream
*
* @param handle The handle of the sonic stream
* @param volume The scaling factor of volume of the stream
*/
void esp_sonic_set_volume(void* handle, float volume);
/**
* @brief Set chord pitch mode on or off.
*
* @param handle The handle of the sonic stream
* @param use_chord_pitch Default is off.
*/
void esp_sonic_set_chord_pitch(void* handle, int use_chord_pitch);
/**
* @brief Set the "quality"
*
* @param handle The handle of the sonic stream
* @param quality Default 0 is virtually as good as 1, but very much faster
*/
void esp_sonic_set_quality(void* handle, int quality);
/**
* @brief Force the sonic stream to generate output using whatever data it currently
* has. No extra delay will be added to the output, but flushing in the middle
* of words could introduce distortion.
*
* @param handle The handle of the sonic stream
*/
int esp_sonic_flush_stream(void* handle);
/**
* @brief Use this to write 16-bit data to be speed up or down into the stream
*
* @param handle The handle of the sonic stream
* @param samples The buffer of output stream
* @param num_samples The length of output stream
*
* @return 0 if memory realloc failed, otherwise 1
*/
int esp_sonic_write_to_stream(void* handle, short* samples, int num_samples);
/**
* @brief Use this to read 16-bit data out of the stream. Sometimes no data will
* be available, and zero is returned, which is not an error condition.
*
* @param handle The handle of the sonic stream
* @param samples The buffer of input stream
* @param max_samples The maximum of the length of "samples"
*
* @return allocate the stream. NULL will be returned ,only if we are out of memory and cannot
*/
int esp_sonic_read_from_stream(void* handle, short* samples, int max_samples);
/**
* @brief Destroy the sonic stream
*
* @param handle The handle of the sonic stream
*/
void esp_sonic_destroy_stream(void* handle);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/processing/esp_sonic.h
|
C
|
apache-2.0
| 4,109
|
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
// All rights reserved.
#ifndef _WAV_HEADER_H_
#define _WAV_HEADER_H_
#include "esp_err.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define CHUNKID_RIFF (0X46464952)
#define CHUNKID_WAVE (0X45564157)
#define CHUNKID_FMT (0X20746D66)
#define CHUNKID_DATA (0X61746164)
/**
* brief RIFF block
*/
typedef struct {
uint32_t chunk_id; /*!<chunk id;"RIFF",0X46464952 */
uint32_t chunk_size; /*!<file length - 8 */
uint32_t format; /*!<WAVE,0X45564157 */
} chunk_riff_t;
/**
* brief FMT block
*/
typedef struct {
uint32_t chunk_id; /*!<chunk id;"fmt ",0X20746D66 */
uint32_t chunk_size; /*!<Size of this fmt block (Not include ID and Size);16 or 18 or 40 bytes. */
uint16_t audio_format; /*!<format;0X01:linear PCM;0X11:IMA ADPCM */
uint16_t num_of_channels; /*!<Number of channel;1: 1 channel;2: 2 channels; */
uint32_t samplerate; /*!<sample rate;0X1F40 = 8Khz */
uint32_t byterate; /*!<Byte rate; */
uint16_t block_align; /*!<align with byte; */
uint16_t bits_per_sample; /*!<Bit lenght per sample point,4 ADPCM */
// uint16_t ByteExtraData; /*!<Exclude in linear PCM format(0~22) */
} __attribute__((packed)) chunk_fmt_t;
/**
* brief FACT block
*/
typedef struct {
uint32_t chunk_id; /*!<chunk id;"fact",0X74636166; */
uint32_t chunk_size; /*!<Size(Not include ID and Size);4 byte */
uint32_t num_of_samples; /*!<number of sample */
} __attribute__((packed)) chunk_fact_t;
/**
* brief LIST block
*/
typedef struct {
uint32_t chunk_id; /*!<chunk id 0X5453494C; */
uint32_t chunk_size; /*!<Size */
} __attribute__((packed)) chunk_list_t;
/**
* brief PEAK block
*/
typedef struct {
uint32_t chunk_id; /*!<chunk id; 0X4B414550 */
uint32_t chunk_size; /*!<Size */
} __attribute__((packed)) chunk_peak_t;
/**
* brief Data block
*/
typedef struct {
uint32_t chunk_id; /*!<chunk id;"data",0X5453494C */
uint32_t chunk_size; /*!<Size of data block(Not include ID and Size) */
} __attribute__((packed)) chunk_data_t;
/**
* brief subchunk block
*/
typedef struct {
uint32_t chunk_id; /*!<sub chunk id */
uint32_t chunk_size; /*!<Size of data block(Not include ID and Size) */
} __attribute__((packed)) sub_chunk_t;
/**
* brief WAV block
*/
typedef struct {
chunk_riff_t riff; /*!<riff */
chunk_fmt_t fmt; /*!<fmt */
// chunk_fact_t fact; /*!<fact,Exclude in linear PCM format */
chunk_data_t data; /*!<data */
} __attribute__((packed)) wav_header_t;
/**
* brief WAV control struct
*/
typedef struct {
uint16_t audio_format; /*!<format;0X01,linear PCM;0X11 IMA ADPCM */
uint16_t channels; /*!<Number of channel;1: 1 channel;2: 2 channels; */
uint16_t block_align; /*!<align */
uint32_t data_size; /*!<size of data */
uint32_t totsec; /*!<total time,second */
uint32_t cursec; /*!<current time, second */
uint32_t bitrate; /*!<bit sample rate */
uint32_t samplerate; /*!<sample rate */
uint16_t bits; /*!<bit length 16bit,24bit,32bit */
uint32_t data_shift; /*!<Data shift. */
uint32_t data_remain; /*!<Data remain. */
uint32_t head_size; /*!<Wav header size. */
} __attribute__((packed)) wav_info_t;
/**
* @brief Check whether this stream is WAV or not
*
* @param in_data The input stream data of WAV stream
* @param len The length of input stream data
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t wav_check_type(uint8_t *in_data, int len);
/**
* @brief Initialize the header information of WAV stream
*
* @param wavhead The header information of WAV stream
* @param sample_rate The sample rate of WAV stream
* @param bits The bit width of WAV stream
* @param channels The number channel(s) of WAV stream
*/
void wav_head_init(wav_header_t *wavhead, int sample_rate, int bits, int channels);
/**
* @brief Parse the header of WAV stream
*
* @param codec_data The handle of codec_data
* @param inData The input stream data of WAV stream
* @param len The length of input stream data
* @param info The header information of stream data
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t wav_parse_header(void *codec_data, uint8_t *inData, int len, wav_info_t *info);
/**
* @brief Get audio data size of WAV stream
*
* @param wavhead The header information of WAV stream
* @param dataSize The size of WAV stream
*/
void wav_head_size(wav_header_t *wavhead, uint32_t dataSize);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/include/processing/wav_head.h
|
C
|
apache-2.0
| 5,251
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
// All rights reserved.
#include "esp_log.h"
#include "audio_mem.h"
#include "audio_element.h"
#include "wav_encoder.h"
#include "wav_head.h"
#include "audio_error.h"
static const char *TAG = "WAV_ENCODER";
typedef struct wav_encoder {
bool parsed_header;
} wav_encoder_t;
static esp_err_t _wav_encoder_destroy(audio_element_handle_t self)
{
wav_encoder_t *wav = (wav_encoder_t *)audio_element_getdata(self);
audio_free(wav);
return ESP_OK;
}
static esp_err_t _wav_encoder_open(audio_element_handle_t self)
{
ESP_LOGD(TAG, "_wav_encoder_open");
return ESP_OK;
}
static esp_err_t _wav_encoder_close(audio_element_handle_t self)
{
ESP_LOGD(TAG, "_wav_encoder_close");
if (AEL_STATE_PAUSED != audio_element_get_state(self)) {
audio_element_set_byte_pos(self, 0);
audio_element_set_total_bytes(self, 0);
}
return ESP_OK;
}
static int _wav_encoder_process(audio_element_handle_t self, char *in_buffer, int in_len)
{
int r_size = audio_element_input(self, in_buffer, in_len);
int out_len = r_size;
if (r_size > 0) {
out_len = audio_element_output(self, in_buffer, r_size);
if (out_len > 0) {
audio_element_update_byte_pos(self, out_len);
}
}
return out_len;
}
audio_element_handle_t wav_encoder_init(wav_encoder_cfg_t *config)
{
wav_encoder_t *wav = audio_calloc(1, sizeof(wav_encoder_t));
AUDIO_MEM_CHECK(TAG, wav, {return NULL;});
audio_element_cfg_t cfg = DEFAULT_AUDIO_ELEMENT_CONFIG();
cfg.destroy = _wav_encoder_destroy;
cfg.process = _wav_encoder_process;
cfg.open = _wav_encoder_open;
cfg.close = _wav_encoder_close;
cfg.task_stack = WAV_ENCODER_TASK_STACK;
if (config) {
if (config->task_stack) {
cfg.task_stack = config->task_stack;
}
cfg.stack_in_ext = config->stack_in_ext;
cfg.task_prio = config->task_prio;
cfg.task_core = config->task_core;
cfg.out_rb_size = config->out_rb_size;
}
cfg.tag = "wav";
audio_element_handle_t el = audio_element_init(&cfg);
AUDIO_MEM_CHECK(TAG, el, {audio_free(wav); return NULL;});
audio_element_setdata(el, wav);
ESP_LOGD(TAG, "wav_encoder_init");
return el;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_codec/wav_encoder.c
|
C
|
apache-2.0
| 2,303
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _ESP_SIP_H
#define _ESP_SIP_H
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct sip_* sip_handle_t;
/**
* @brief SIP audio codec type
*/
typedef enum {
SIP_ACODEC_G711A,
SIP_ACODEC_G711U,
SIP_ACODEC_OPUS,
SIP_ACODEC_SPEEX,
} sip_audio_codec_t;
/**
* @brief SIP session state
*/
typedef enum {
SIP_STATE_NONE = 0x00,
SIP_STATE_CONNECTED = 0x01,
SIP_STATE_REGISTERED = 0x02,
SIP_STATE_CALLING = 0x04,
SIP_STATE_SESS_PROGRESS = 0x08,
SIP_STATE_RINGING = 0x10,
SIP_STATE_ON_CALL = 0x20,
SIP_STATE_CALL_OWNER = 0x40,
} sip_state_t;
/**
* @brief SIP session event
*/
typedef enum {
SIP_EVENT_NONE = 0,
SIP_EVENT_REGISTERED,
SIP_EVENT_RINGING,
SIP_EVENT_INVITING,
SIP_EVENT_HANGUP,
SIP_EVENT_BUSY,
SIP_EVENT_UNREGISTERED,
SIP_EVENT_AUDIO_SESSION_BEGIN,
SIP_EVENT_READ_AUDIO_DATA,
SIP_EVENT_WRITE_AUDIO_DATA,
SIP_EVENT_AUDIO_SESSION_END,
SIP_EVENT_REQUEST_NETWORK_STATUS,
SIP_EVENT_REQUEST_NETWORK_IP,
SIP_EVENT_READ_DTMF,
} sip_event_t;
/**
* @brief SIP Messages header info
*/
typedef struct {
char *via; /*!< SIP Messages via fields */
char *from; /*!< SIP Messages from fields */
char *to; /*!< SIP Messages to fields */
char *contact; /*!< SIP Messages contact fields */
} sip_messages_info_t;
/**
* @brief SIP session event message
*/
typedef struct {
sip_event_t type; /*!< SIP session event type */
void *data; /*!< RTP TX/RX data */
int data_len; /*!< Length of rtp data */
} sip_event_msg_t;
typedef int (*sip_event_handle)(sip_event_msg_t *event);
/**
* @brief SIP session configurations
*/
typedef struct {
sip_event_handle event_handler; /*!< SIP session event handler */
const char *uri; /*!< Transport://user:pass@server:port/path */
const char *cert_pem; /*!< SSL server certification, PEM format as string, if the client requires to verify server */
const char *client_cert_pem; /*!< SSL client certification, PEM format as string, if the server requires to verify client */
const char *client_key_pem; /*!< SSL client key, PEM format as string, if the server requires to verify client */
bool send_options; /*!< Send 'OPTIONS' messages to Server for keep NAT hole opened*/
sip_audio_codec_t acodec_type; /*!< Audio codec type */
} sip_config_t;
/**
* @brief Intialize SIP Service
*
* @param[in] config The SIP configuration
*
* @return The sip handle
*/
sip_handle_t esp_sip_init(sip_config_t *config);
/**
* @brief Start sip task and register the device
*
* @param[in] sip The sip handle
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_start(sip_handle_t sip);
/**
* @brief Stop sip task
*
* @param[in] sip The sip handle
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_stop(sip_handle_t sip);
/**
* @brief Destroy SIP Service
*
* @param[in] sip The sip handle
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_destroy(sip_handle_t sip);
/**
* @brief Answer the sip Session
*
* @param[in] sip The sip handle
* @param[in] accept accept the session or not
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_uas_answer(sip_handle_t sip, bool accept);
/**
* @brief Initialize a sip session
*
* @param[in] sip The sip handle
* @param[in] extension Remote extension ID
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_uac_invite(sip_handle_t sip, const char *extension);
/**
* @brief Hang up
*
* @param[in] sip The sip handle
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_uac_bye(sip_handle_t sip);
/**
* @brief Cancel the sip session
*
* @param[in] sip The sip handle
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_uac_cancel(sip_handle_t sip);
/**
* @brief Get the current session state
*
* @param[in] sip The sip handle
*
* @return SIP session state
*/
sip_state_t esp_sip_get_state(sip_handle_t sip);
/**
* @brief Send DTMF event ( Only support out band method (RFC2833) )
*
* @param[in] sip The sip handle
* @param[in] dtmf_event DTMF event ID (0-15)
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_send_dtmf(sip_handle_t sip, const uint8_t dtmf_event);
/**
* @brief Set custom invite info
*
* @param[in] sip The sip handle
* @param[in] sip_set_info Set Via, From, To, Contact fields
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_set_invite_info(sip_handle_t sip, const sip_messages_info_t *sip_set_info);
/**
* @brief Read incomming sip message
*
* @param[in] sip The sip handle
* @param[in] sip_messages_info_t Read Via, From, To, Contact fields, we will copy to user buffer.
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_sip_read_incomming_messages(sip_handle_t sip, sip_messages_info_t *sip_read_info);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_sip/include/esp_sip.h
|
C
|
apache-2.0
| 6,912
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _ESP_SSDP_H_
#define _ESP_SSDP_H_
#include "freertos/FreeRTOS.h"
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief SSDP Configuration struct
*/
typedef struct {
char *udn; /*!< Unique Device Name */
char *location; /*!< The ssdp location for this udn, format as example: http://192.168.8.196/path
or http://${ip}/path which ${ip} will be replaced by device ip address */
int port; /*!< SSDP listening on this port, default port will be used if not set */
int notify_interval_ms; /*!< SSDP notify interval */
int task_stack; /*!< Task stack size */
int task_core; /*!< Task running in core (0 or 1) */
int task_prio; /*!< Task priority (based on freeRTOS priority) */
bool stack_in_ext; /*!< Try to allocate stack in external memory */
} ssdp_config_t;
#define DEFAULT_SSDP_UDN "ESP32_DMR"
#define DEFAULT_SSDP_LOCATION "http://${ip}/rootDesc.xml"
#define DEFAULT_SSDP_PORT (1900)
#define DEFAULT_SSDP_TASK_STACK (4*1024)
#define DEFAULT_SSDP_TASK_CORE (0)
#define DEFAULT_SSDP_TASK_PRIORITY (6)
#define DEFAULT_SSDP_NOTIFY_INTERVAL_MS (30000)
#define SSDP_DEFAULT_CONFIG() {\
.udn = DEFAULT_SSDP_UDN, \
.location = DEFAULT_SSDP_LOCATION, \
.port = DEFAULT_SSDP_PORT, \
.notify_interval_ms = DEFAULT_SSDP_NOTIFY_INTERVAL_MS, \
.task_stack = DEFAULT_SSDP_TASK_STACK, \
.task_core = DEFAULT_SSDP_TASK_CORE, \
.task_prio = DEFAULT_SSDP_TASK_PRIORITY, \
.stack_in_ext = true, \
}
/**
* @brief SSDP service description
*/
typedef struct {
char *uuid;
char *usn; //Unique Service Name
char *location;
} ssdp_service_t;
/**
* @brief Start SSDP responder service
*
* @param config SSDP configuration
* @param services SSDP Search Target that will be responding
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t ssdp_start(ssdp_config_t *config, const ssdp_service_t services[]);
/**
* @brief Stop and free all SSDP resources
*/
void ssdp_stop();
/**
* @brief Send SSDP byebye multicast
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t ssdp_send_byebye();
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_ssdp/include/esp_ssdp.h
|
C
|
apache-2.0
| 3,524
|
// Copyright 2015-2018 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 _UPNP_H
#define _UPNP_H
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_http_server.h"
#include "upnp_service.h"
typedef struct upnp_* upnp_handle_t;
/**
* UPnP Device Description – general info
* Official: http://www.upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf
* Ref: https://embeddedinn.wordpress.com/tutorials/upnp-device-architecture/
*/
typedef struct {
const char *friendly_name; /*!< Short user-friendly title */
const char *serial; /*!< Device manufacturer's serial number */
const char *uuid; /*!< Device UUID */
const char *root_path; /*!< The custom XML root path */
const char *device_type; /*!< Will replace for deviceType in UPnP schema urn:schemas-upnp-org:device:deviceType:version */
const char *version; /*!< Will replace for version in UPnP schema urn:schemas-upnp-org:device:deviceType:version */
const char *upc; /*!< Universal Product Code */
const char *manufacturer; /*!< Manufacturer name */
const char *manufacturer_url; /*!< URL to manufacturer site */
const char *model_description; /*!< long user-friendly title */
const char *model_name; /*!< model name */
const char *model_number; /*!< model number */
const char *model_url; /*!< URL to model site */
const upnp_file_info_t logo; /*!< Logo for the device*/
httpd_handle_t httpd; /*!< UPnP needs a HTTP server to work */
int port; /*!< Server port (for advertise)*/
void *user_ctx; /*!< User context, it be will passed to attribute/notify and action callback */
bool device_list; /*<! Support Device List */
} upnp_config_t;
/**
* @brief Intialize UPnP object
*
* @param[in] config The configuration
*
* @return UPnP handle
*/
upnp_handle_t upnp_init(const upnp_config_t *config);
/**
* @brief Send the notification to the client
*
* @param[in] upnp The upnp handle
* @param[in] service_name The service name
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_send_notify(upnp_handle_t upnp, const char *service_name);
/**
* @brief Send the AVTransport notification to the client
*
* @param[in] upnp The upnp handle
* @param[in] action_name The action name
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_send_avt_notify(upnp_handle_t upnp, const char *action_name);
/**
* @brief Send custom notification to the client
*
* @param[in] upnp The upnp handle
* @param[in] service_name The service name
* @param[in] event_xml custom event xml (ref: EventLastChange.xml)
* @param[in] xml_length The xml length
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_send_custom_notify(upnp_handle_t upnp, const char *service_name, const char *event_xml, int32_t xml_length);
/**
* @brief Clean up and destroy the UPnP handle
*
* @param[in] upnp The UPnP handle
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_destroy(upnp_handle_t upnp);
/**
* @brief Serve http static files (using upnp_file_info_t format)
*
* @param req The request
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_serve_static_files(httpd_req_t *req);
/**
* @brief Register actions/notifies for the service
*
* @param[in] upnp The UPnP handle
* @param[in] service_item The service item
* @param[in] service_actions The service actions
* @param[in] service_notify The service notify
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_register_service(upnp_handle_t upnp,
const upnp_service_item_t *service_item,
const service_action_t service_actions[],
const service_notify_t service_notify[]);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_upnp/include/upnp.h
|
C
|
apache-2.0
| 4,953
|
// Copyright 2015-2018 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 _UPNP_NOTIF_H_
#define _UPNP_NOTIF_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct upnp_notify_* upnp_notify_handle_t;
/**
* @brief Initialize UPnP notify, the value returned by this function can be used to
* subscribe/unsubscribe and to send an event to a client
*
* @return The upnp notify handle
*/
upnp_notify_handle_t upnp_notify_init();
/**
* @brief Subscribe/Re-new the subscriptions for UPnP events
*
* @param[in] notify The notify handle
* @param[in] service_name The service name
* @param[in] uri_or_sid The uri or sid
* @param[in] timeout_sec The timeout in seconds (If after this time passes without any renew
* this subscription will be unsubscribed automatically )
*
* @return The sid
*/
char *upnp_notify_subscribe(upnp_notify_handle_t notify,
const char *service_name,
const char *uri_or_sid,
int timeout_sec);
/**
* @brief Unsubscribe the notify by sid
*
* @param[in] notify The notify handle
* @param[in] sid The sid
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_notify_unsubscribe(upnp_notify_handle_t notify, char *sid);
/**
* @brief Unsubscribe the notify by service name
*
* @param[in] notify The notify handle
* @param[in] service_name The service name
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_notify_unsubscribe_by_name(upnp_notify_handle_t notify, const char *service_name);
/**
* @brief Send the notification to the client
*
* @param[in] notify The notify handle
* @param data The data
* @param[in] data_len The data length
* @param[in] service_name The service name
* @param[in] delay_send_ms The delay timeout, after a period of milliseconds the message will be sent
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_notify_send(upnp_notify_handle_t notify,
char *data,
int data_len,
const char *service_name);
/**
* @brief Clean up & destroy the notify
*
* @param[in] notify The notify
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_notify_destroy(upnp_notify_handle_t notify);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_upnp/include/upnp_notify.h
|
C
|
apache-2.0
| 3,174
|
// Copyright 2015-2018 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 _UPNP_SERVICE_H
#define _UPNP_SERVICE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "upnp_utils.h"
#include "esp_http_server.h"
typedef struct upnp_service_* upnp_service_handle_t;
typedef enum {
ATTR_POINTER = 0x10000000, /*!< The execution type is POINTER, the value can be resolved by reference */
ATTR_CONST = 0x20000000, /*!< The execution type is CONSTANT, the value can be resolved directly */
ATTR_RESPONSE = 0x40000000, /*!< The execution type is RESPONSE, it can produce the response tag */
ATTR_CALLBACK = 0x80000000, /*!< The execution type is upnp_attr_cb, the value can be resolved by calling this callback */
ATTR_TYPE_INT = 0x01000000, /*!< The execution type is integer, the value can be resolved as integer */
ATTR_TYPE_STR = 0x02000000, /*!< The execution type is string, the value can be resolved as string */
/* User attribute space (lower 2bytes) */
/* ... */
} upnp_attr_type_t;
/**
* UPnP attribute
*/
typedef struct {
const char *name; /*!< The XML tag attribute (for notificaiton) or tag name (for SOAP action) */
void *val; /*!< Attribute execution type, depends on the type, it can be a callback, a pointer or a constant */
upnp_attr_type_t type; /*!< Attribute type */
const char *service_name; /*!< UPnP service name */
const char *action_name; /*!< UPnP SOAP action name */
} upnp_attr_t;
typedef int (*upnp_attr_cb)(void *user_ctx, const upnp_attr_t *attr, int attr_num, char *buffer, int max_buffer_len);
/**
* UPnP Service notify definition, currently only LastChange events are supported
*/
typedef struct {
const char *name; /*!< Notify Tag name */
const int num_attrs; /*!< Notify attributes number */
const upnp_attr_t *attrs; /*!< Notifies pointer */
} service_notify_t;
/**
* UPnP Service action definition
*/
typedef struct service_action {
const char *name; /*!< The action name */
const int num_attrs; /*!< Action attributes number */
const upnp_attr_t *attrs; /*!< Action attributes pointer */
upnp_attr_cb callback; /*!< The callback to execute when this action name meets the request */
} service_action_t;
/**
* UPnP Service definition
*/
typedef struct {
const char *name; /*!< Service name */
const char *version; /*!< Service version */
const upnp_file_info_t service_desc; /*!< Service XML description */
const upnp_file_info_t notify_template; /*!< Service XML notification template */
} upnp_service_item_t;
/**
* UPnP Service configurations
*/
typedef struct {
void *user_ctx; /*!< User context, it will be passed to the action & attribute callback */
httpd_handle_t httpd; /*!< HTTPD handle need to be register the service */
} upnp_service_config_t;
/**
* @brief Initialize UPnP service
*
* @param config The configuration
*
* @return The UPnP service handle
*/
upnp_service_handle_t upnp_service_init(upnp_service_config_t *config);
/**
* @brief Clean up and destroy the UPnP service, including unregistering of all services
*
* @param[in] services The services
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_service_destroy(upnp_service_handle_t services);
/**
* @brief Register SOAP action for UPnP service
*
* @param[in] services The UPnP service handle
* @param[in] httpd The httpd handle
* @param[in] service The service item definition
* @param[in] actions The actions
* @param[in] notifies The notifies
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_service_register_actions(upnp_service_handle_t services,
httpd_handle_t httpd,
const upnp_service_item_t *service,
const service_action_t actions[],
const service_notify_t notifies[]);
/**
* @brief Get XML descriptions for all registered services
* Notes: The returned string must be freed after use
*
* @param[in] services The UPnP service handle
*
* @return The xml string
*/
char *upnp_service_get_xml_description(upnp_service_handle_t services);
/**
* @brief Send all service actions notification to the client
*
* @param[in] services The services
* @param[in] service_name The service name
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_service_send_notify(upnp_service_handle_t services,
const char *service_name);
/**
* @brief Send single AVTransport actions notification to the client
*
* @param[in] services The services
* @param[in] service_name The service name
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_service_send_avt_notify(upnp_service_handle_t services,
const char *action_name);
/**
* @brief Send custom notification to the client
*
* @param[in] services The services
* @param[in] service_name The service name
* @param[in] event_xml custom event xml (ref: EventLastChange.xml)
* @param[in] xml_length The xml length
*
* @return
* - ESP_OK
* - ESP_xx if any errors
*/
esp_err_t upnp_service_send_custom_notify(upnp_service_handle_t services, const char *service_name, const char *event_xml, int32_t xml_length);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_upnp/include/upnp_service.h
|
C
|
apache-2.0
| 6,386
|
// Copyright 2015-2018 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 _UPNP_UTILS_H
#define _UPNP_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "audio_mem.h"
#define UPNP_MEM_FREE(a) if(a) { audio_free(a); a = NULL; }
#define UPNP_MEM_CHECK(addr, action) if (addr == NULL) { ESP_LOGE(TAG, "Memory exhausted at %d", __LINE__); action; }
/**
* File format for UPnP
*/
typedef struct {
const char *data; /*!< Data pointer */
const int size; /*!< File size */
const char *mime_type; /*!< MIME Types */
const char *path; /*!< File path */
} upnp_file_info_t;
/**
* @brief Check the string ``str`` if it ends with ``suffix``
*
* @param[in] str The string to check
* @param[in] suffix The suffix to look for
*
* @return true or false
*/
bool utils_ends_with(const char *str, const char *suffix);
/**
* @brief Remove white space at begin and end of string
*
* @param str The string
*
* @return the str pointer returned is difference pointer with the input string
*/
char *utils_trim(char *str);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_upnp/include/upnp_utils.h
|
C
|
apache-2.0
| 1,653
|
/* Copyright (c) 2013-2014 Yoran Heling
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef YXML_H
#define YXML_H
#include <stdint.h>
#include <stddef.h>
#if defined(_MSC_VER) && !defined(__cplusplus) && !defined(inline)
#define inline __inline
#endif
/* Full API documentation for this library can be found in the "yxml.pod" file
* in the yxml git repository, or online at http://dev.yorhel.nl/yxml/man */
typedef enum {
YXML_EEOF = -5, /* Unexpected EOF */
YXML_EREF = -4, /* Invalid character or entity reference (&whatever;) */
YXML_ECLOSE = -3, /* Close tag does not match open tag (<Tag> .. </OtherTag>) */
YXML_ESTACK = -2, /* Stack overflow (too deeply nested tags or too long element/attribute name) */
YXML_ESYN = -1, /* Syntax error (unexpected byte) */
YXML_OK = 0, /* Character consumed, no new token present */
YXML_ELEMSTART = 1, /* Start of an element: '<Tag ..' */
YXML_CONTENT = 2, /* Element content */
YXML_ELEMEND = 3, /* End of an element: '.. />' or '</Tag>' */
YXML_ATTRSTART = 4, /* Attribute: 'Name=..' */
YXML_ATTRVAL = 5, /* Attribute value */
YXML_ATTREND = 6, /* End of attribute '.."' */
YXML_PISTART = 7, /* Start of a processing instruction */
YXML_PICONTENT = 8, /* Content of a PI */
YXML_PIEND = 9 /* End of a processing instruction */
} yxml_ret_t;
/* When, exactly, are tokens returned?
*
* <TagName
* '>' ELEMSTART
* '/' ELEMSTART, '>' ELEMEND
* ' ' ELEMSTART
* '>'
* '/', '>' ELEMEND
* Attr
* '=' ATTRSTART
* "X ATTRVAL
* 'Y' ATTRVAL
* 'Z' ATTRVAL
* '"' ATTREND
* '>'
* '/', '>' ELEMEND
*
* </TagName
* '>' ELEMEND
*/
typedef struct {
/* PUBLIC (read-only) */
/* Name of the current element, zero-length if not in any element. Changed
* after YXML_ELEMSTART. The pointer will remain valid up to and including
* the next non-YXML_ATTR* token, the pointed-to buffer will remain valid
* up to and including the YXML_ELEMEND for the corresponding element. */
char *elem;
/* The last read character(s) of an attribute value (YXML_ATTRVAL), element
* data (YXML_CONTENT), or processing instruction (YXML_PICONTENT). Changed
* after one of the respective YXML_ values is returned, and only valid
* until the next yxml_parse() call. Usually, this string only consists of
* a single byte, but multiple bytes are returned in the following cases:
* - "<?SomePI ?x ?>": The two characters "?x"
* - "<![CDATA[ ]x ]]>": The two characters "]x"
* - "<![CDATA[ ]]x ]]>": The three characters "]]x"
* - "&#N;" and "&#xN;", where dec(n) > 127. The referenced Unicode
* character is then encoded in multiple UTF-8 bytes.
*/
char data[8];
/* Name of the current attribute. Changed after YXML_ATTRSTART, valid up to
* and including the next YXML_ATTREND. */
char *attr;
/* Name/target of the current processing instruction, zero-length if not in
* a PI. Changed after YXML_PISTART, valid up to (but excluding)
* the next YXML_PIEND. */
char *pi;
/* Line number, byte offset within that line, and total bytes read. These
* values refer to the position _after_ the last byte given to
* yxml_parse(). These are useful for debugging and error reporting. */
uint64_t byte;
uint64_t total;
uint32_t line;
/* PRIVATE */
int state;
unsigned char *stack; /* Stack of element names + attribute/PI name, separated by \0. Also starts with a \0. */
size_t stacksize, stacklen;
unsigned reflen;
unsigned quote;
int nextstate; /* Used for '@' state remembering and for the "string" consuming state */
unsigned ignore;
unsigned char *string;
} yxml_t;
#ifdef __cplusplus
extern "C" {
#endif
void yxml_init(yxml_t *, void *, size_t);
yxml_ret_t yxml_parse(yxml_t *, int);
/* May be called after the last character has been given to yxml_parse().
* Returns YXML_OK if the XML document is valid, YXML_EEOF otherwise. Using
* this function isn't really necessary, but can be used to detect documents
* that don't end correctly. In particular, an error is returned when the XML
* document did not contain a (complete) root element, or when the document
* ended while in a comment or processing instruction. */
yxml_ret_t yxml_eof(yxml_t *);
#ifdef __cplusplus
}
#endif
/* Returns the length of the element name (x->elem), attribute name (x->attr),
* or PI name (x->pi). This function should ONLY be used directly after the
* YXML_ELEMSTART, YXML_ATTRSTART or YXML_PISTART (respectively) tokens have
* been returned by yxml_parse(), calling this at any other time may not give
* the correct results. This function should also NOT be used on strings other
* than x->elem, x->attr or x->pi. */
static inline size_t yxml_symlen(yxml_t *x, const char *s) {
return (x->stack + x->stacklen) - (const unsigned char*)s;
}
#endif
/* vim: set noet sw=4 ts=4: */
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/esp_upnp/include/yxml.h
|
C
|
apache-2.0
| 6,186
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _MRM_CLIENT_H_
#define _MRM_CLIENT_H_
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DEFAULT_MRM_CLIENT_VERSION "ESP32 MRM/1.0"
#define DEFAULT_MRM_GROUP_ADDR "239.255.255.252"
#define DEFAULT_MRM_SYNC_SOCK_PORT (1900)
#define DEFAULT_MRM_BUFFER_SIZE (2*1024)
#define DEFAULT_MRM_TASK_STACK (4*1024)
#define DEFAULT_MRM_TASK_PRIO (5)
typedef struct esp_mrm_client *esp_mrm_client_handle_t;
/**
* @brief MRM client event
*/
typedef enum {
MRM_EVENT_NONE = 0,
MRM_EVENT_SET_URL,
MRM_EVENT_SET_SYNC,
MRM_EVENT_GET_PTS,
MRM_EVENT_GET_TSF,
MRM_EVENT_SYNC_FAST,
MRM_EVENT_SYNC_SLOW,
MRM_EVENT_PLAY_STOP
} mrm_event_t;
/**
* @brief MRM client event message
*/
typedef struct {
mrm_event_t type; /*!< MRM client event type */
int data_len; /*!< Data length */
void *data; /*!< TX/RX data */
} mrm_event_msg_t;
typedef int (*mrm_event_handle)(mrm_event_msg_t *event, void *ctx);
/**
* @brief MRM client configurations
*/
typedef struct
{
mrm_event_handle event_handler; /*!< MRM client event handler */
char *group_addr; /*!< MRM client multicast group addr */
int sync_sock_port; /*!< MRM client sync socket port */
int data_sock_port; /*!< MRM client data socket port */
void *ctx; /*!< MRM client User context */
} esp_mrm_client_config_t;
/**
* @brief Creates mrm client handle based on the configuration
*
* @param config mrm configuration structure
*
* @return mrm_client_handle if successfully created, NULL on error
*/
esp_mrm_client_handle_t esp_mrm_client_create(esp_mrm_client_config_t *config);
/**
* @brief Destroys the client handle
*
* @param client mrm client handle
*
* @return ESP_OK
*/
esp_err_t esp_mrm_client_destroy(esp_mrm_client_handle_t client);
/**
* @brief mrm master client start
*
* @param client mrm client handle
* @param URL mrm client play url
*
* @return ESP_OK
*/
esp_err_t esp_mrm_client_master_start(esp_mrm_client_handle_t client, const char *URL);
/**
* @brief mrm master client stop
*
* @param client mrm client handle
*
* @return ESP_OK
*/
esp_err_t esp_mrm_client_master_stop(esp_mrm_client_handle_t client);
/**
* @brief mrm slave client start
*
* @param client mrm client handle
*
* @return ESP_OK
*/
esp_err_t esp_mrm_client_slave_start(esp_mrm_client_handle_t client);
/**
* @brief mrm slave client stop
*
* @param client mrm client handle
*
* @return ESP_OK
*/
esp_err_t esp_mrm_client_slave_stop(esp_mrm_client_handle_t client);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/mrm_client/include/mrm_client.h
|
C
|
apache-2.0
| 3,999
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __RECORDER_ENGINE_H__
#define __RECORDER_ENGINE_H__
#define REC_ONE_BLOCK_SIZE 2880 // 90ms[16k,16bit,1channel]
#ifdef __cplusplus
extern "C" {
#endif
#define DEFAULT_REC_ENGINE_CONFIG() {\
.one_frame_duration_ms = 10,\
.sensitivity = 0,\
.vad_off_delay_ms = 600,\
.wakeup_time_ms = 10000,\
.task_core = 1,\
.enable_wwe = true,\
.open = NULL,\
.fetch = NULL,\
.close = NULL,\
.evt_cb = NULL,\
}
/*
// Ther are some decription of recorder events with 4 use case.
///////////////////////////// Use case 1: Single dialog by rec_engine_trigger_start ///////////////////////
+ + wakeup time +
| +--------------+
| | |
| | |
Wakeup Time +--------+ | +-----------------+
| | |
| +---------------+ | |
| | voice | | |
| | | | |
Voice level +------------------+ +-----------------------+-----------------+
| | |
| +------------------------+ |
| | | | |
| | | | |
EVENT +------------------+ | +--------------------------------+
|\ |\ | vad |\ |\
| \ | \ | off | \ | \
| WAKEUP | VAD START | time | VAD STOP | WAKEUP END
+ START + + + +
///////////////////////////// Use case 2: Single dialog by voice wakeup /////////////////////////////////
+ + wakeup time +
| +--------------+
| | |
| | |
Wakeup Time +------------+ | +------------+
| | |
+--------+ +---------------+ | |
| wakeup | | voice | | |
| word | | | | |
Voice level +------------+---------+ +-----------------------+------------+
| | |
| +------------------------+ |
| | | | |
| | | | |
EVENT +----------------------+ | +---------------------------+
|\ |\ | vad |\ |\
| \ | \ | off | \ | \
| WAKEUP | VAD START | time | VAD STOP | WAKEUP END
+ START + + + +
/////////////////////////////// Use case 3: Multi dialog after rec_engine_trigger_start ////////////////////
+ + wakeup time +
| +-------------+
| | |
| | |
Wakeup Time +-----------+ | +----------+
+ +----------+ +-------+ +---------+ | |
| | voice | | music | | voice | | |
| | | | | | | | |
Voice level +-----------+---------+ +------+ +---+ +-------------------------------+
| | | | | |
| +----------------+ | | | |
| SUSPEND ON \ | SUSPEND OFF\ | | | | |
| \| \| | | | |
SUSPEND ON +--------------------------------+ +-------------------------------------------+
| | | | | |
| +----------+ | +------+ |
| | | | | | |
| | | | | | |
EVENT +---------------------+ +------------------------------------------------------------+
|\ |\ |\ /| | |\ |\
| \ | \ | \ / | | vad | \ | \
| WAKEUP | VAD | VAD VAD | | off | VAD | WAKEUP
+ START + START + STOP START + + time + STOP + END
////////////////////////////////////// Use case 4: Multi dialog after voice wakeup ////////////////////////
+ + wakeup time +
| +-------------+
| | |
| | |
Wakeup Time +-----------+ | +---------+
+--------+ +----------+ +-------+ +---------+ | |
| wakeup | | voice | | music | | voice | | |
| word | | | | | | | | |
Voice level +--+--------+---------+ +------+ +---+ +------------------------------+
| | | | | |
| +----------------+ | | | |
| SUSPEND ON \ | SUSPEND OFF\ | | | | |
| \| \| | | | |
SUSPEND ON +--------------------------------+ +------------------------------------------+
| | | | | |
| +----------+ | +------+ |
| | | | | | |
| | | | | | |
EVENT +---------------------+ +-----------------------------------------------------------+
|\ |\ |\ /| | |\ |\
| \ | \ | \ / | | vad | \ | \
| WAKEUP | VAD | VAD VAD | | off | VAD | WAKEUP
+ START + START + STOP START + + time + STOP + END
///////////////////////////////////////////////////////////////////////////////////////////////////////////
*/
typedef enum {
REC_EVENT_WAKEUP_START,
REC_EVENT_WAKEUP_END,
REC_EVENT_VAD_START,
REC_EVENT_VAD_STOP,
} rec_event_type_t;
typedef void (*rec_callback)(rec_event_type_t type, void *user_data);
typedef esp_err_t (*rec_open)(void **handle);
typedef esp_err_t (*rec_fetch)(void *handle, char *data, int data_size);
typedef esp_err_t (*rec_close)(void *handle);
typedef enum {
REC_VOICE_SUSPEND_OFF,
REC_VOICE_SUSPEND_ON,
} rec_voice_suspend_t;
/**
* @brief recorder configuration parameters
*/
typedef struct {
int one_frame_duration_ms; /*!< Duration of one frame (optional) */
int sensitivity; /*!< For response accuracy rate sensitivity. Default 0: 90%, 1: 95% */
int vad_off_delay_ms; /*!< Vad off delay to stop if no voice is detected */
int wakeup_time_ms; /*!< Time of wakeup */
bool support_encoding; /*!< Support encoding data */
const char *extension; /*!< Encoding format."amr" or "amrwb" support */
int task_core; /*!< Recorder task running in core (0 or 1) */
bool enable_wwe; /*!< Enable Wake Word Engine or not */
rec_open open; /*!< Recorder open callback function */
rec_fetch fetch; /*!< Recorder fetch data callback function */
rec_close close; /*!< Recorder close callback function */
rec_callback evt_cb; /*!< Recorder event callback function */
void *user_data; /*!< Pointer to user data (optional) */
} rec_config_t;
/**
* @brief Create recorder engine according to parameters.
*
* @note Sample rate is 16k, 1 channel, 16bits, by default.
* Upon completion of this function rec_open callback will be triggered.
*
* @param cfg See rec_config_t structure for additional details
*
* @return
* - 0: Success
* - -1: Error
*/
esp_err_t rec_engine_create(rec_config_t *cfg);
/**
* @brief Read voice data after REC_EVENT_VAD_START.
*
* @param buffer data pointer
* @param buffer_size Size of buffer, must be equal to REC_ONE_BLOCK_SIZE.
* @param waiting_time Timeout for reading data. Default time of REC_ONE_BLOCK_SIZE is 100ms, larger than 100ms is recommended.
*
* @return
* - -2 : timeout of read
* - -1 : parameters invalid or task not running.
* - 0 : last voice block.
* - others: voice block index.
*/
int rec_engine_data_read(uint8_t *buffer, int buffer_size, int waiting_time);
/**
* @brief Suspend or enable voice detection by vad.
*
* @param flag REC_VOICE_SUSPEND_ON: Voice detection is suspended
* REC_VOICE_SUSPEND_OFF: Voice detection is not suspended
*
* @return
* - 0: Success
* - -1: Error
*/
esp_err_t rec_engine_detect_suspend(rec_voice_suspend_t flag);
/**
* @brief Start recording by force.
*
* @return
* - 0: Success
* - -1: Error
*/
esp_err_t rec_engine_trigger_start(void);
/**
* @brief Stop recording by force.
*
* @return
* - 0: Success
* - -1: Error
*/
esp_err_t rec_engine_trigger_stop(void);
/**
* @brief Destroy the recorder engine.
*
* @note Upon completion of this function rec_close callback will be triggered.
*
* @return
* - 0: Success
* - -1: Error
*/
esp_err_t rec_engine_destroy(void);
/**
* @brief Disable or enable the VAD(voice activity detection).
*
* @note Enable vad by default.
* Usage: Call this function before `rec_engine_trigger_start` to disable voice activity detection,
* Call this funciton after `rec_engine_trigger_stop` to enable voice activity detection.
* Even if disable voice activity detection, the `REC_EVENT_VAD_START` and `REC_EVENT_VAD_STOP` events
* still notified when `rec_engine_trigger_start` and `rec_engine_trigger_stop` called.
*
* @param vad_enable true is enable vad, false disable vad
*
* @return
* - 0: Success
* - -1: Error
*/
esp_err_t rec_engine_vad_enable(bool vad_enable);
/**
* @brief Enable the recoder encoding, or not.
*
* @note `support_encoding` must be set, `rec_engine_enc_enable` can be used.
* Disable encoding by default.
*
* @param enc_enable true is enable encoding, false is disable.
*
* @return
* - 0: Success
* - -1: Error
*/
esp_err_t rec_engine_enc_enable(bool enc_enable);
/**
* @brief Read voice data after REC_EVENT_VAD_START.
*
* @note `support_encoding` and `rec_engine_enc_enable` must be set.
*
* @param buffer data pointer
* @param buffer_size Size of buffer, must be equal to REC_ONE_BLOCK_SIZE.
* @param waiting_time Timeout for reading data.
* @param out_size Valid size of buffer.
*
* @return
* - -2 : timeout of read
* - -1 : parameters invalid or not encoding mode.
* - 0 : success.
* - others: voice block index.
*/
esp_err_t rec_engine_enc_data_read(uint8_t *buffer, int buffer_size, int waiting_time, int *out_size);
/**
* @brief Enable the recoder mute, or not.
*
* @note if enable mute, no data fill the buffer, so the `rec_engine_enc_data_read` and `rec_engine_data_read` will be blocked.
*
* @param mute_enable true is mute, false is not.
*
* @return
* - 0: Success
* - -1: Error
*/
esp_err_t rec_engine_mute_enable(bool mute_enable);
/**
* @brief Get recorder engine wakeup state.
*
* @param wakeup_start_t true is WAKEUP_START, false is not.
*
* @return
* - 0: Success
* - -1: Error
*/
esp_err_t rec_engine_get_wakeup_stat(bool *wakeup_start_t);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-adf-libs/recorder_engine/include/recorder_engine.h
|
C
|
apache-2.0
| 15,820
|
set(COMPONENT_SRCS
speech_command_recognition/mn_process_commands.c
)
set(COMPONENT_ADD_INCLUDEDIRS
lib/include
wake_word_engine/include
speech_command_recognition/include
acoustic_algorithm/include
esp-tts/esp_tts_chinese/include
)
register_component()
target_link_libraries(${COMPONENT_TARGET} "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib")
target_link_libraries(${COMPONENT_TARGET} "-L ${CMAKE_CURRENT_SOURCE_DIR}/wake_word_engine")
target_link_libraries(${COMPONENT_TARGET} "-L ${CMAKE_CURRENT_SOURCE_DIR}/speech_command_recognition")
target_link_libraries(${COMPONENT_TARGET} "-L ${CMAKE_CURRENT_SOURCE_DIR}/acoustic_algorithm")
target_link_libraries(${COMPONENT_TARGET} "-L ${CMAKE_CURRENT_SOURCE_DIR}/esp-tts/esp_tts_chinese")
IF (IDF_VER MATCHES "v4.")
add_prebuilt_library(multinet "${CMAKE_CURRENT_SOURCE_DIR}/lib/libmultinet.a" PRIV_REQUIRES esp-sr)
add_prebuilt_library(esp_audio_processor "${CMAKE_CURRENT_SOURCE_DIR}/acoustic_algorithm/libesp_audio_processor.a" PRIV_REQUIRES esp-sr)
add_prebuilt_library(wakenet "${CMAKE_CURRENT_SOURCE_DIR}/lib/libwakenet.a" PRIV_REQUIRES esp-sr)
ENDIF (IDF_VER MATCHES "v4.")
if(IDF_TARGET STREQUAL "esp32")
target_link_libraries(${COMPONENT_TARGET} "-Wl,--start-group"
wakenet
dl_lib
c_speech_features
hilexin_wn3
hilexin_wn4
hilexin_wn5
hilexin_wn5X2
hilexin_wn5X3
hijeson_wn5X3
nihaoxiaozhi_wn5
nihaoxiaozhi_wn5X2
nihaoxiaozhi_wn5X3
nihaoxiaoxin_wn6
nihaoxiaoxin_wn5X3
customized_word_wn5
customized_word_wn6
multinet
multinet1_ch
multinet1_en
esp_tts_chinese
voice_set_xiaole
voice_set_template
esp_audio_processor "-Wl,--end-group")
endif()
if(IDF_TARGET STREQUAL "esp32s2")
target_link_libraries(${COMPONENT_TARGET} "-Wl,--start-group"
esp_tts_chinese_esp32s2
voice_set_xiaole_esp32s2
voice_set_template_esp32s2
"-Wl,--end-group")
endif()
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/CMakeLists.txt
|
CMake
|
apache-2.0
| 1,941
|
PROJECT_NAME := esp_sr_public
MODULE_PATH := $(abspath $(shell pwd))
EXTRA_COMPONENT_DIRS += $(MODULE_PATH)/lib
EXTRA_COMPONENT_DIRS += $(MODULE_PATH)/wake_word_engine
EXTRA_COMPONENT_DIRS += $(MODULE_PATH)/speech_command_recognition
EXTRA_COMPONENT_DIRS += $(MODULE_PATH)/acoustic_algorithm
include $(IDF_PATH)/make/project.mk
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/Makefile
|
Makefile
|
apache-2.0
| 332
|
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := .
LIB_FILES := $(shell ls $(COMPONENT_PATH)/lib*.a)
LIBS := $(patsubst lib%.a,-l%,$(notdir $(LIB_FILES)))
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/ $(LIBS)
ALL_LIB_FILES += $(LIB_FILES)
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/acoustic_algorithm/component.mk
|
Makefile
|
apache-2.0
| 254
|
// 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_AEC_H_
#define _ESP_AEC_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define USE_AEC_FFT // Not kiss_fft
#define AEC_USE_SPIRAM 0
#define AEC_SAMPLE_RATE 16000 // Only Support 16000Hz
#define AEC_FRAME_LENGTH_MS 16
#define AEC_FILTER_LENGTH 1200 // Number of samples of echo to cancel
typedef void* aec_handle_t;
/**
* @brief Creates an instance to the AEC structure.
*
* @param sample_rate The Sampling frequency (Hz) must be 16000.
*
* @param frame_length The length of the audio processing must be 16ms.
*
* @param filter_length Number of samples of echo to cancel.
*
* @return
* - NULL: Create failed
* - Others: The instance of AEC
*/
aec_handle_t aec_create(int sample_rate, int frame_length, int filter_length);
/**
* @brief Creates an instance to the AEC structure.
*
* @param sample_rate The Sampling frequency (Hz) must be 16000.
*
* @param frame_length The length of the audio processing must be 16ms.
*
* @param filter_length Number of samples of echo to cancel.
*
* @param nch Number of input signal channel.
*
* @return
* - NULL: Create failed
* - Others: The instance of AEC
*/
aec_handle_t aec_create_multimic(int sample_rate, int frame_length, int filter_length, int nch);
/**
* @brief Creates an instance of more powerful AEC.
*
* @param frame_length Length of input signal. Must be 16ms if mode is 0; otherwise could be 16ms or 32ms. Length of input signal to aec_process must be modified accordingly.
*
* @param nch Number of microphones.
*
* @param mode Mode of AEC (0 to 4), indicating aggressiveness and RAM allocation. 0: mild; 1 or 2: medium (1: internal RAM, 2: SPIRAM); 3 and 4: aggressive (3: internal RAM, 4: SPIRAM).
*
* @return
* - NULL: Create failed
* - Others: An Instance of AEC
*/
aec_handle_t aec_pro_create(int frame_length, int nch, int 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 An array of 16-bit signed audio samples from mic.
*
* @param refdata An array of 16-bit signed audio samples sent to the speaker.
*
* @param outdata Returns near-end signal with echo removed.
*
* @return None
*
*/
void aec_process(const aec_handle_t inst, int16_t *indata, int16_t *refdata, int16_t *outdata);
/**
* @brief Free the AEC instance
*
* @param inst The instance of AEC.
*
* @return None
*
*/
void aec_destroy(aec_handle_t inst);
#ifdef __cplusplus
}
#endif
#endif //_ESP_AEC_H_
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/acoustic_algorithm/include/esp_aec.h
|
C
|
apache-2.0
| 3,342
|
// 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_AGC_H_
#define _ESP_AGC_H_
////all positive value is valid, negective is error
typedef enum {
ESP_AGC_SUCCESS = 0, ////success
ESP_AGC_FAIL = -1, ////agc fail
ESP_AGC_SAMPLE_RATE_ERROR = -2, ///sample rate can be only 8khz, 16khz, 32khz
ESP_AGC_FRAME_SIZE_ERROR = -3, ////the input frame size should be only 10ms, so should together with sample-rate to get the frame size
} ESP_AGE_ERR;
void *esp_agc_open(int agc_mode, int sample_rate);
void set_agc_config(void *agc_handle, int gain_dB, int limiter_enable, int target_level_dbfs);
int esp_agc_process(void *agc_handle, short *in_pcm, short *out_pcm, int frame_size, int sample_rate);
void esp_agc_clse(void *agc_handle);
#endif // _ESP_AGC_H_
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/acoustic_algorithm/include/esp_agc.h
|
C
|
apache-2.0
| 1,348
|
// 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
#define MAP_SAMPLE_RATE 16000 // Supports 16kHz only
#define MAP_FRAME_SIZE 16 // Supports 16ms only
#define MAP_MIC_DISTANCE 50 // According to physical design of mic-array
#define MAP_AEC_ON true
#define MAP_AEC_OFF false
#define MAP_AEC_FILTER_LENGTH 1200 // Number of samples of echo to cancel
/**
* @brief Sets mic-array type, currently 2-mic line array and 3-mic circular array
* are supported.
*/
typedef enum {
TWO_MIC_LINE = 0,
THREE_MIC_CIRCLE = 1
} map_mic_array_type_t;
typedef void* mic_array_processor_t;
/**
* @brief Creates an instance to the MAP structure.
*
* @param sample_rate The sampling frequency (Hz) must be 16000.
*
* @param frame_size The length of the audio processing must be 16ms.
*
* @param array_type '0' for 2-mic line array and '1' for 3-mic circular array.
*
* @param mic_distance The distance between neiboring microphones in mm.
*
* @param aec_on Decides whether to turn on AEC.
*
* @param filter_length Number of samples of echo to cancel, effective when AEC is on.
*
* @return
* - NULL: Create failed
* - Others: An instance of MAP
*/
mic_array_processor_t map_create(int fs, int frame_size, int array_type, float mic_distance, bool aec_on, int filter_length);
/**
* @brief Performs mic array processing for one frame.
*
* @param inst The instance of MAP.
*
* @param in An array of 16-bit signed audio samples from mic.
*
* @param far_end An array of 16-bit signed audio samples sent to the speaker, can be none when AEC is turned off.
*
* @param dsp_out Returns enhanced signal.
*
* @return None
*
*/
void map_process(mic_array_processor_t st, int16_t *in, int16_t *far_end, int16_t *dsp_out);
/**
* @brief Free the MAP instance
*
* @param inst The instance of MAP.
*
* @return None
*
*/
void map_destory(mic_array_processor_t st);
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/acoustic_algorithm/include/esp_map.h
|
C
|
apache-2.0
| 2,578
|
// 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
#define MASE_SAMPLE_RATE 16000 // Supports 16kHz only
#define MASE_FRAME_SIZE 16 // Supports 16ms only
#define MASE_MIC_DISTANCE 65 // According to physical design of mic-array
/**
* @brief Sets mic-array type, currently 2-mic line array and 3-mic circular array
* are supported.
*/
typedef enum {
TWO_MIC_LINE = 0,
THREE_MIC_CIRCLE = 1
} mase_mic_array_type_t;
/**
* @brief Sets operating mode, supporting normal mode and wake-up enhancement mode
*/
typedef enum {
NORMAL_ENHANCEMENT_MODE = 0,
WAKE_UP_ENHANCEMENT_MODE = 1
} mase_op_mode_t;
typedef void* mase_handle_t;
/**
* @brief Creates an instance to the MASE structure.
*
* @param sample_rate The sampling frequency (Hz) must be 16000.
*
* @param frame_size The length of the audio processing must be 16ms.
*
* @param array_type '0' for 2-mic line array and '1' for 3-mic circular array.
*
* @param mic_distance The distance between neiboring microphones in mm.
*
* @param operating_mode '0' for normal mode and '1' for wake-up enhanced mode.
*
* @param filter_strength Strengh of the mic-array speech enhancement, must be 0 to 6.
*
* @return
* - NULL: Create failed
* - Others: An instance of MASE
*/
mase_handle_t mase_create(int fs, int frame_size, int array_type, float mic_distance, int operating_mode, int filter_strength);
/**
* @brief Performs mic array processing for one frame.
*
* @param inst The instance of MASE.
*
* @param in An array of 16-bit signed audio samples from mic.
*
* @param dsp_out Returns enhanced signal.
*
* @return None
*
*/
void mase_process(mase_handle_t st, int16_t *in, int16_t *dsp_out);
/**
* @brief Free the MASE instance
*
* @param inst The instance of MASE.
*
* @return None
*
*/
void mase_destory(mase_handle_t st);
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/acoustic_algorithm/include/esp_mase.h
|
C
|
apache-2.0
| 2,482
|
// 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_NS_H_
#define _ESP_NS_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define NS_USE_SPIARM 0
#define NS_FRAME_LENGTH_MS 10
/**
* The Sampling frequency (Hz) must be 16000Hz
*/
typedef void* ns_handle_t;
/**
* @brief Creates an instance to the NS structure.
*
* @param frame_length_ms The length of the audio processing can be 10ms, 20ms, 30ms.
*
* @return
* - NULL: Create failed
* - Others: The instance of NS
*/
ns_handle_t ns_create(int frame_length_ms);
/**
* @brief Creates an instance of the more powerful noise suppression algorithm.
*
* @warning frame_length_ms only supports be 10 ms.
*
* @param frame_length_ms The length of the audio processing can only be 10ms.
* @param mode 0: Mild, 1: Medium, 2: Aggressive
*
* @return
* - NULL: Create failed
* - Others: The instance of NS
*/
ns_handle_t ns_pro_create(int frame_length_ms, int mode);
/**
* @brief Feed samples of an audio stream to the NS and get the audio stream after Noise suppression.
*
* @param inst The instance of NS.
*
* @param indata An array of 16-bit signed audio samples.
*
* @param outdata An array of 16-bit signed audio samples after noise suppression.
*
* @return None
*
*/
void ns_process(ns_handle_t inst, int16_t *indata, int16_t *outdata);
/**
* @brief Free the NS instance
*
* @param inst The instance of NS.
*
* @return None
*
*/
void ns_destroy(ns_handle_t inst);
#ifdef __cplusplus
extern "C" {
#endif
#endif //_ESP_NS_H_
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/acoustic_algorithm/include/esp_ns.h
|
C
|
apache-2.0
| 2,180
|
// 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_VAD_H_
#define _ESP_VAD_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SAMPLE_RATE_HZ 16000 //Supports 32000, 16000, 8000
#define VAD_FRAME_LENGTH_MS 30 //Supports 10ms, 20ms, 30ms
/**
* @brief Sets the VAD operating mode. A more aggressive (higher mode) VAD is more
* restrictive in reporting speech.
*/
typedef enum {
VAD_MODE_0 = 0,
VAD_MODE_1,
VAD_MODE_2,
VAD_MODE_3,
VAD_MODE_4
} vad_mode_t;
typedef enum {
VAD_SILENCE = 0,
VAD_SPEECH
} vad_state_t;
typedef void* vad_handle_t;
/**
* @brief Creates an instance to the VAD structure.
*
* @param vad_mode Sets the VAD operating mode.
*
* @param sample_rate_hz The Sampling frequency (Hz) can be 32000, 16000, 8000, default: 16000.
*
* @param one_frame_ms The length of the audio processing can be 10ms, 20ms, 30ms, default: 30.
*
* @return
* - NULL: Create failed
* - Others: The instance of VAD
*/
vad_handle_t vad_create(vad_mode_t vad_mode, int sample_rate_hz, int one_frame_ms);
/**
* @brief Feed samples of an audio stream to the VAD and check if there is someone speaking.
*
* @param inst The instance of VAD.
*
* @param data An array of 16-bit signed audio samples.
*
* @return
* - VAD_SILENCE if no voice
* - VAD_SPEECH if voice is detected
*
*/
vad_state_t vad_process(vad_handle_t inst, int16_t *data);
/**
* @brief Free the VAD instance
*
* @param inst The instance of VAD.
*
* @return None
*
*/
void vad_destroy(vad_handle_t inst);
/*
* Programming Guide:
*
* @code{c}
* vad_handle_t vad_inst = vad_create(VAD_MODE_3, SAMPLE_RATE_HZ, VAD_FRAME_LENGTH_MS); // Creates an instance to the VAD structure.
*
* while (1) {
* //Use buffer to receive the audio data from MIC.
* vad_state_t vad_state = vad_process(vad_inst, buffer); // Feed samples to the VAD process and get the result.
* }
*
* vad_destroy(vad_inst); // Free the VAD instance at the end of whole VAD process
*
* @endcode
*/
#ifdef __cplusplus
}
#endif
#endif //_ESP_VAD_H_
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/acoustic_algorithm/include/esp_vad.h
|
C
|
apache-2.0
| 2,707
|
COMPONENT_ADD_INCLUDEDIRS := lib/include \
wake_word_engine/include \
speech_command_recognition/include \
acoustic_algorithm/include \
esp-tts/esp_tts_chinese/include \
COMPONENT_SRCDIRS := speech_command_recognition
LIB_FILES := $(shell ls $(COMPONENT_PATH)/wake_word_engine/lib*.a) \
$(shell ls $(COMPONENT_PATH)/lib/lib*.a) \
$(shell ls $(COMPONENT_PATH)/acoustic_algorithm/lib*.a) \
$(shell ls $(COMPONENT_PATH)/speech_command_recognition/lib*.a) \
$(shell ls $(COMPONENT_PATH)/esp-tts/esp_tts_chinese/lib*.a) \
LIBS := $(patsubst lib%.a,-l%,$(LIB_FILES))
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/lib \
-L$(COMPONENT_PATH)/wake_word_engine \
-L$(COMPONENT_PATH)/speech_command_recognition \
-L$(COMPONENT_PATH)/acoustic_algorithm \
-L$(COMPONENT_PATH)/esp-tts \
$(LIBS)
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/component.mk
|
Makefile
|
apache-2.0
| 1,084
|
set(COMPONENT_ADD_INCLUDEDIRS
./esp_tts_chinese/include
)
register_component()
target_link_libraries(${COMPONENT_TARGET} INTERFACE "-L ${CMAKE_CURRENT_SOURCE_DIR}/esp_tts_chinese")
if(IDF_TARGET STREQUAL "esp32")
target_link_libraries(${COMPONENT_TARGET} INTERFACE
esp_tts_chinese
voice_set_xiaole
voice_set_template
)
endif()
if(IDF_TARGET STREQUAL "esp32s2")
target_link_libraries(${COMPONENT_TARGET} INTERFACE
esp_tts_chinese_esp32s2
voice_set_xiaole_esp32s2
voice_set_template_esp32s2
)
endif()
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/esp-tts/CMakeLists.txt
|
CMake
|
apache-2.0
| 546
|
COMPONENT_ADD_INCLUDEDIRS := esp_tts_chinese/include
LIB_FILES := $(shell ls $(COMPONENT_PATH)/esp_tts_chinese/lib*.a)
LIBS := $(patsubst lib%.a,-l%,$(LIB_FILES))
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/esp_tts_chinese \
$(LIBS)
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/esp-tts/component.mk
|
Makefile
|
apache-2.0
| 250
|
// 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_TTS_H_
#define _ESP_TTS_H_
#include "stdlib.h"
#include "stdio.h"
#include "esp_tts_voice.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
NONE_MODE = 0, //do not play any word before playing a specific number
ALI_PAY_MODE, //play zhi fu bao shou kuan before playing a specific number
WEIXIN_PAY_MODE //play wei xin shou kuan before playing a specific number
} pay_mode_t;
typedef void * esp_tts_handle_t;
/**
* @brief Init an instance of the TTS voice set structure.
*
* @param template The const esp_tts_voice_template.
* @param data The customize voice data
* @return
* - NULL: Init failed
* - Others: The instance of voice set
*/
esp_tts_voice_t *esp_tts_voice_set_init(const esp_tts_voice_t *template, void *data);
/**
* @brief Init an instance of the TTS voice set structure.
*
* @param template The const esp_tts_voice_template.
* @param data The customize voice data
* @return
* - NULL: Init failed
* - Others: The instance of voice set
*/
void esp_tts_voice_set_free(esp_tts_voice_t *voice);
/**
* @brief Creates an instance of the TTS structure.
*
* @param voice Voice set containing all basic phonemes.
* @return
* - NULL: Create failed
* - Others: The instance of TTS structure
*/
esp_tts_handle_t esp_tts_create(esp_tts_voice_t *voice);
/**
* @brief parse money pronuciation.
*
* @param tts_handle Instance of TTS
* @param yuan The number of yuan
* @param jiao The number of jiao
* @param fen The number of fen
* @param mode The pay mode: please refer to pay_mode_t
* @return
* - 0: failed
* - 1: succeeded
*/
int esp_tts_parse_money(esp_tts_handle_t tts_handle, int yuan, int jiao, int fen, pay_mode_t mode);
/**
* @brief parse Chinese PinYin pronuciation.
*
* @param tts_handle Instance of TTS
* @param pinyin PinYin string, like this "da4 jia1 hao3"
* @return
* - 0: failed
* - 1: succeeded
*/
int esp_tts_parse_pinyin(esp_tts_handle_t tts_handle, const char *pinyin);
/**
* @brief parse Chinese string.
*
* @param tts_handle Instance of TTS
* @param str Chinese string, like this "大家好"
* @return
* - 0: failed
* - 1: succeeded
*/
int esp_tts_parse_chinese(esp_tts_handle_t tts_handle, const char *str);
/**
* @brief output TTS voice data by stream.
*
* @Warning The output data should not be freed.
Once the output length is 0, the all voice data has been output.
*
* @param tts_handle Instance of TTS
* @param len The length of output data
* @param speed The speech speed speed of synthesized speech,
range:0~5, 0: the slowest speed, 5: the fastest speech
* @return
* - voice raw data
*/
short* esp_tts_stream_play(esp_tts_handle_t tts_handle, int *len, unsigned int speed);
/**
* @brief reset tts stream and clean all cache of TTS instance.
*
* @param tts_handle Instance of TTS
*/
void esp_tts_stream_reset(esp_tts_handle_t tts_handle);
/**
* @brief Free the TTS instance
*
* @param tts_handle The instance of TTS.
*/
void esp_tts_destroy(esp_tts_handle_t tts_handle);
#ifdef __cplusplus
extern "C" {
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts.h
|
C
|
apache-2.0
| 3,952
|
#ifndef _ESP_TTS_PARSER_H_
#define _ESP_TTS_PARSER_H_
#include "stdlib.h"
#include "esp_tts_voice.h"
typedef struct {
int *syll_idx;
int syll_num;
int total_num;
esp_tts_voice_t *voice;
}esp_tts_utt_t;
esp_tts_utt_t* esp_tts_parser_chinese (const char* str, esp_tts_voice_t *voice);
esp_tts_utt_t* esp_tts_parser_money(char *play_tag, int yuan, int jiao, int fen, esp_tts_voice_t *voice);
esp_tts_utt_t* esp_tts_parser_pinyin(char* pinyin, esp_tts_voice_t *voice);
esp_tts_utt_t* esp_tts_utt_alloc(int syll_num, esp_tts_voice_t *voice);
void esp_tts_utt_free(esp_tts_utt_t *utt);
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_parser.h
|
C
|
apache-2.0
| 601
|
// 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_TTS_PLAYER_H_
#define _ESP_TTS_PLAYER_H_
#include "stdlib.h"
#include "stdio.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void * esp_tts_player_handle_t;
/**
* @brief Creates an instance of the TTS Player structure.
*
* @param mode mode of player, default:0
* @return
* - NULL: Create failed
* - Others: The instance of TTS Player
*/
esp_tts_player_handle_t esp_tts_player_create(int mode);
/**
* @brief Concatenate audio files.
*
* @Warning Just support mono audio data.
*
* @param player The handle of TTS player
* @param file_list The dir of files
* @param file_num The number of file
* @param len The length of return audio buffer
* @param sample_rate The sample rate of input audio file
* @param sample_width The sample width of input audio file, sample_width=1:8-bit, sample_width=2:16-bit,...
* @return
* - audio data buffer
*/
unsigned char* esp_tts_stream_play_by_concat(esp_tts_player_handle_t player, const char **file_list, int file_num, int *len, int *sample_rate, int *sample_width);
/**
* @brief Free the TTS Player instance
*
* @param player The instance of TTS Player.
*/
void esp_tts_player_destroy(esp_tts_player_handle_t player);
#ifdef __cplusplus
extern "C" {
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_player.h
|
C
|
apache-2.0
| 1,924
|
////////////////////////////////////////////////////////////////////////////
// **** AUDIO-STRETCH **** //
// Time Domain Harmonic Scaler //
// Copyright (c) 2019 David Bryant //
// All Rights Reserved. //
// Distributed under the BSD Software License (see license.txt) //
////////////////////////////////////////////////////////////////////////////
// stretch.h
// Time Domain Harmonic Compression and Expansion
//
// This library performs time domain harmonic scaling with pitch detection
// to stretch the timing of a 16-bit PCM signal (either mono or stereo) from
// 1/2 to 2 times its original length. This is done without altering any of
// its tonal characteristics.
#ifndef STRETCH_H
#define STRETCH_H
#ifdef __cplusplus
extern "C" {
#endif
typedef void *StretchHandle;
/* extern function */
StretchHandle stretch_init (int shortest_period, int longest_period, int num_chans, int fast_mode);
int stretch_samples (StretchHandle handle, short *samples, int num_samples, short *output, float ratio);
int stretch_flush (StretchHandle handle, short *output);
void stretch_deinit (StretchHandle handle);
/* internel function */
StretchHandle stretcher_init_internal(int shortest_period, int longest_period, int buff_len);
void stretcher_deinit (StretchHandle handle);
int stretcher_is_empty(StretchHandle handle);
int stretcher_is_full(StretchHandle handle, int num_samples);
int stretcher_push_data(StretchHandle handle, short *samples, int num_samples);
int stretcher_stretch_samples(StretchHandle handle, short *output, float ratio);
int stretcher_stretch_samples_flash(StretchHandle handle, short *output, float ratio, const short *period_data,
int *start_idx, int end_idx);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_stretcher.h
|
C
|
apache-2.0
| 1,952
|
#ifndef _ESP_TTS_VOICE_H_
#define _ESP_TTS_VOICE_H_
typedef struct {
char *voice_name; // voice set name
char *format; // the format of voice data, currently support pcm and amrwb
int sample_rate; // the sample rate of voice data, just for pcm format
int bit_width; // the bit width of voice data, just for pcm format
int syll_num; // the syllable mumber
char **sylls; // the syllable names
int *syll_pos; // the position of syllable in syllable audio data array
short *pinyin_idx; // the index of pinyin
short *phrase_dict; // the pinyin dictionary of common phrase
short *extern_idx; // the idx of extern phrases
short *extern_dict; // the extern phrase dictionary
unsigned char *data; // the audio data of all syllables
} esp_tts_voice_t;
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice.h
|
C
|
apache-2.0
| 848
|
#pragma once
#include "esp_tts.h"
extern const esp_tts_voice_t esp_tts_voice_template;
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice_template.h
|
C
|
apache-2.0
| 90
|
#pragma once
#include "esp_tts.h"
extern const esp_tts_voice_t esp_tts_voice_xiaole;
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/esp-tts/esp_tts_chinese/include/esp_tts_voice_xiaole.h
|
C
|
apache-2.0
| 88
|
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := .
LIB_FILES := $(shell ls $(COMPONENT_PATH)/lib*.a)
LIBS := $(patsubst lib%.a,-l%,$(notdir $(LIB_FILES)))
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/ $(LIBS)
ALL_LIB_FILES += $(LIB_FILES)
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/lib/component.mk
|
Makefile
|
apache-2.0
| 254
|
// 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 DL_LIB_H
#define DL_LIB_H
#include "dl_lib_matrix.h"
#include "dl_lib_matrixq.h"
typedef int padding_state;
/**
* @brief Does a fast version of the exp() operation on a floating point number.
*
* As described in https://codingforspeed.com/using-faster-exponential-approximation/
* Should be good til an input of 5 or so with a steps factor of 8.
*
* @param in Floating point input
* @param steps Approximation steps. More is more precise. 8 or 10 should be good enough for most purposes.
* @return Exp()'ed output
*/
fptp_t fast_exp(double x, int steps);
/**
* @brief Does a softmax operation on a matrix.
*
* @param in Input matrix
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_softmax(const dl_matrix2d_t *in, dl_matrix2d_t *out);
/**
* @brief Does a softmax operation on a quantized matrix.
*
* @param in Input matrix
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_softmax_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out);
/**
* @brief Does a sigmoid operation on a floating point number
*
* @param in Floating point input
* @return Sigmoid output
*/
fptp_t dl_sigmoid_op(fptp_t in);
/**
* @brief Does a sigmoid operation on a matrix.
*
* @param in Input matrix
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_sigmoid(const dl_matrix2d_t *in, dl_matrix2d_t *out);
/**
* @brief Does a tanh operation on a floating point number
*
* @param in Floating point input number
* @return Tanh value
*/
fptp_t dl_tanh_op(fptp_t v);
/**
* @brief Does a tanh operation on a matrix.
*
* @param in Input matrix
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_tanh(const dl_matrix2d_t *in, dl_matrix2d_t *out);
/**
* @brief Does a relu (Rectifier Linear Unit) operation on a floating point number
*
* @param in Floating point input
* @param clip If value is higher than this, it will be clipped to this value
* @return Relu output
*/
fptp_t dl_relu_op(fptp_t in, fptp_t clip);
/**
* @brief Does a ReLu operation on a matrix.
*
* @param in Input matrix
* @param clip If values are higher than this, they will be clipped to this value
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_relu(const dl_matrix2d_t *in, fptp_t clip, dl_matrix2d_t *out);
/**
* @brief Fully connected layer operation
*
* @param in Input vector
* @param weight Weights of the neurons
* @param bias Biases for the neurons. Can be NULL if a bias of 0 is required.
* @param out Output array. Outputs are placed here. Needs to be an initialized, weight->w by in->h in size, matrix.
*/
void dl_fully_connect_layer(const dl_matrix2d_t *in, const dl_matrix2d_t *weight, const dl_matrix2d_t *bias, dl_matrix2d_t *out);
/**
* @brief Pre-calculate the sqrtvari variable for the batch_normalize function.
* The sqrtvari matrix depends on the variance and epsilon values, which normally are constant. Hence,
* this matrix only needs to be calculated once. This function does that.
*
* @param
* @return
*/
void dl_batch_normalize_get_sqrtvar(const dl_matrix2d_t *variance, fptp_t epsilon, dl_matrix2d_t *out);
/**
* @brief Batch-normalize a matrix
*
* @param m The matrix to normalize
* @param offset Offset matrix
* @param scale Scale matrix
* @param mean Mean matrix
* @param sqrtvari Matrix precalculated using dl_batch_normalize_get_sqrtvar
* @return
*/
void dl_batch_normalize(dl_matrix2d_t *m, const dl_matrix2d_t *offset, const dl_matrix2d_t *scale,
const dl_matrix2d_t *mean, const dl_matrix2d_t *sqrtvari);
/**
* @brief Do a basic LSTM layer pass.
*
* @warning Returns state_h pointer, so do not free result.
* @param in Input vector
* @param state_c Internal state of the LSTM network
* @param state_h Internal state (previous output values) of the LSTM network
* @param weights Weights for the neurons
* @param bias Bias for the neurons. Can be NULL if no bias is required
* @return Output values of the neurons
*/
dl_matrix2d_t *dl_basic_lstm_layer(const dl_matrix2d_t *in, dl_matrix2d_t *state_c, dl_matrix2d_t *state_h,
const dl_matrix2d_t *weight, const dl_matrix2d_t *bias);
/**
* @brief Do a basic LSTM layer pass, partial quantized version.
* This LSTM function accepts 16-bit fixed-point weights and 32-bit float-point bias.
*
* @warning Returns state_h pointer, so do not free result.
* @param in Input vector
* @param state_c Internal state of the LSTM network
* @param state_h Internal state (previous output values) of the LSTM network
* @param weights Weights for the neurons, need to be quantised
* @param bias Bias for the neurons. Can be NULL if no bias is required
* @return Output values of the neurons
*/
dl_matrix2dq_t *dl_basic_lstm_layer_quantised_weights(const dl_matrix2d_t *in, dl_matrix2d_t *state_c, dl_matrix2d_t *state_h,
const dl_matrix2dq_t *weight, const dl_matrix2d_t *bias);
/**
* @brief Do a fully-connected layer pass, fully-quantized version.
*
* @param in Input vector
* @param weight Weights of the neurons
* @param bias Bias values of the neurons. Can be NULL if no bias is needed.
* @param shift Number of bits to shift the result back by. See dl_lib_matrixq.h for more info
* @return Output values of the neurons
*/
void dl_fully_connect_layer_q(const dl_matrix2dq_t *in, const dl_matrix2dq_t *weight, const dl_matrix2dq_t *bias, dl_matrix2dq_t *out, int shift);
/**
* @brief Do a basic LSTM layer pass, fully-quantized version
*
* @warning Returns state_h pointer, so do not free result.
* @param in Input vector
* @param state_c Internal state of the LSTM network
* @param state_h Internal state (previous output values) of the LSTM network
* @param weights Weights for the neurons
* @param bias Bias for the neurons. Can be NULL if no bias is required
* @param shift Number of bits to shift the result back by. See dl_lib_matrixq.h for more info
* @return Output values of the neurons
*/
dl_matrix2dq_t *dl_basic_lstm_layer_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *state_c, dl_matrix2dq_t *state_h,
const dl_matrix2dq_t *weight, const dl_matrix2dq_t *bias, int shift);
/**
* @brief Batch-normalize a matrix, fully-quantized version
*
* @param m The matrix to normalize
* @param offset Offset matrix
* @param scale Scale matrix
* @param mean Mean matrix
* @param sqrtvari Matrix precalculated using dl_batch_normalize_get_sqrtvar
* @param shift Number of bits to shift the result back by. See dl_lib_matrixq.h for more info
* @return
*/
void dl_batch_normalize_q(dl_matrix2dq_t *m, const dl_matrix2dq_t *offset, const dl_matrix2dq_t *scale,
const dl_matrix2dq_t *mean, const dl_matrix2dq_t *sqrtvari, int shift);
/**
* @brief Does a relu (Rectifier Linear Unit) operation on a fixed-point number
* This accepts and returns fixed-point 32-bit number with the last 15 bits being the bits after the decimal
* point. (Equivalent to a mantissa in a quantized matrix with exponent -15.)
*
* @param in Fixed-point input
* @param clip If value is higher than this, it will be clipped to this value
* @return Relu output
*/
qtp_t dl_relu_q_op(qtp_t in, qtp_t clip);
/**
* @brief Does a ReLu operation on a matrix, quantized version
*
* @param in Input matrix
* @param clip If values are higher than this, they will be clipped to this value
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_relu_q(const dl_matrix2dq_t *in, fptp_t clip, dl_matrix2dq_t *out);
/**
* @brief Does a sigmoid operation on a fixed-point number.
* This accepts and returns a fixed-point 32-bit number with the last 15 bits being the bits after the decimal
* point. (Equivalent to a mantissa in a quantized matrix with exponent -15.)
*
* @param in Fixed-point input
* @return Sigmoid output
*/
int dl_sigmoid_op_q(const int in);
/**
* @brief Does a sigmoid operation on a matrix, quantized version
*
* @param in Input matrix
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_sigmoid_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out);
/**
* @brief Does a tanh operation on a matrix, quantized version
*
* @param in Input matrix
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_tanh_q(const dl_matrix2dq_t *in, dl_matrix2dq_t *out);
/**
* @brief Does a tanh operation on a fixed-point number.
* This accepts and returns a fixed-point 32-bit number with the last 15 bits being the bits after the decimal
* point. (Equivalent to a mantissa in a quantized matrix with exponent -15.)
*
* @param in Fixed-point input
* @return tanh output
*/
int dl_tanh_op_q(int v);
/**
* @brief Filter out the number greater than clip in the matrix, quantized version
*
* @param in Input matrix
* @param clip If values are higher than this, they will be clipped to this value
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_minimum(const dl_matrix2d_t *in, fptp_t clip, dl_matrix2d_t *out);
/**
* @brief Filter out the number greater than clip in the matrix, float version
*
* @param in Input matrix
* @param clip If values are higher than this, they will be clipped to this value
* @param out Output matrix. Can be the same as the input matrix; if so, output results overwrite the input.
*/
void dl_minimum_q(const dl_matrix2dq_t *in, fptp_t clip, dl_matrix2dq_t *out);
/**
* @brief Do a basic CNN layer pass.
*
* @Warning This just supports the single channel input image, and the output is single row matrix.
That is to say, the height of output is 1, and the weight of output is out_channels*out_image_width*out_image_height
*
* @param in Input single channel image
* @param weight Weights of the neurons, weight->w = out_channels, weight->h = filter_width*filter_height
* @param bias Bias for the CNN layer.
* @param filter_height The height of convolution kernel
* @param filter_width The width of convolution kernel
* @param out_channels The number of output channels of convolution kernel
* @param stride_x The step length of the convolution window in x(width) direction
* @param stride_y The step length of the convolution window in y(height) direction
* @param pad One of `"VALID"` or `"SAME"`, 0 is "VALID" and the other is "SAME"
* @param out The result of CNN layer, out->h=1.
* @return The result of CNN layer.
*/
dl_matrix2d_t *dl_basic_conv_layer(const dl_matrix2d_t *in, const dl_matrix2d_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);
/**
* @brief Do a basic CNN layer pass, quantised wersion.
*
* @Warning This just supports the single channel input image, and the output is single row matrix.
That is to say, the height of output is 1, and the weight of output is out_channels*out_image_width*out_image_height
*
* @param in Input single channel image
* @param weight Weights of the neurons, weight->w = out_channels, weight->h = filter_width*filter_height,
* @param bias Bias of the neurons.
* @param filter_height The height of convolution kernel
* @param filter_width The width of convolution kernel
* @param out_channels The number of output channels of convolution kernel
* @param stride_x The step length of the convolution window in x(width) direction
* @param stride_y The step length of the convolution window in y(height) direction
* @param pad One of `"VALID"` or `"SAME"`, 0 is "VALID" and the other is "SAME"
* @param out The result of CNN layer, out->h=1
* @return The result of CNN layer
*/
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);
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/lib/include/dl_lib.h
|
C
|
apache-2.0
| 13,616
|
// 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 DL_LIB_COEFGETTER_IF_H
#define DL_LIB_COEFGETTER_IF_H
#include "dl_lib_matrix.h"
#include "dl_lib_matrixq.h"
//Set this if the coefficient requested is a batch-normalization popvar matrix which needs to be preprocessed by
//dl_batch_normalize_get_sqrtvar first.
#define COEF_GETTER_HINT_BNVAR (1<<0)
/*
This struct describes the basic information of model data:
word_num: the number of wake words or speech commands
word_list: the name list of wake words or speech commands
thres_list: the threshold list of wake words or speech commands
info_str: the string used to reflect the version and information of model data
which consist of the architecture of network, the version of model data, wake words and their threshold
*/
typedef struct {
int word_num;
char **word_list;
int *win_list;
float *thresh_list;
char *info_str;
} model_info_t;
/*
Alphabet struct describes the basic grapheme or phoneme.
item_num: the number of baisc item(grapheme or phonemr)
items: the list of basic item
*/
typedef struct {
int item_num;
char **items;
}alphabet_t;
/*
This struct describes a generic coefficient getter: a way to get the constant coefficients needed for a neural network.
For the two getters, the name describes the name of the coefficient matrix, usually the same as the Numpy filename the
coefficient was originally stored in. The arg argument can be used to optionally pass an additional user-defined argument
to the getter (e.g. the directory to look for files in the case of the Numpy file loader getter). The hint argument
is a bitwise OR of the COEF_GETTER_HINT_* flags or 0 when none is needed. Use the free_f/free_q functions to release the
memory for the returned matrices, when applicable.
*/
typedef struct {
const dl_matrix2d_t* (*getter_f)(const char *name, void *arg, int hint);
const dl_matrix2dq_t* (*getter_q)(const char *name, void *arg, int hint);
void (*free_f)(const dl_matrix2d_t *m);
void (*free_q)(const dl_matrix2dq_t *m);
const model_info_t* (*getter_info)(void *arg);
const alphabet_t* (*getter_alphabet)(void *arg);
} model_coeff_getter_t;
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/lib/include/dl_lib_coefgetter_if.h
|
C
|
apache-2.0
| 2,766
|
// 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 DL_LIB_CONV_QUEUE_H
#define DL_LIB_CONV_QUEUE_H
#include "dl_lib_matrix.h"
typedef float fptp_t;
//Flags for matrices
#define DL_MF_FOREIGNDATA (1<<0) /*< Matrix *item data actually points to another matrix and should not be freed */
//Float convolution FIFO queue.
typedef struct {
int n; /*< the length of queue */
int c; /*< the channel number of queue element*/
int front; /*< the front(top) position of queue */
int flag; /*< not used*/
fptp_t *item; /*< Pointer to item array */
} dl_conv_queue_t;
/**
* @brief Allocate a convolution queue
*
* @param n The length of queue
* @param c The channel number of elements in the queue
* @return The convolution queue, or NULL if out of memory
*/
dl_conv_queue_t *dl_conv_queue_alloc(int n, int c);
/**
* @brief Free a convolution queue
*
* @param cq The convolution queue to free
*/
void dl_conv_queue_free(dl_conv_queue_t *cq);
void dl_conv_to_matrix2d(dl_conv_queue_t *cq, dl_matrix2d_t* out);
/**
* @brief Move the front pointer of queue forward,
the First(oldest) element become the last(newest) element,
*
* @param cq Input convolution queue
* @return Pointer of oldest element
*/
fptp_t *dl_conv_queue_pop(dl_conv_queue_t *cq);
/**
* @brief Remove the oldest element, then insert the input element at the end of queue
*
* @param cq Input convolution queue
* @param item The new element
*/
void dl_conv_queue_push(dl_conv_queue_t *cq, fptp_t* item);
/**
* @brief Get the pointer of element in the queue by offset
*
* @param cq Input convolution queue
* @param offset Offset from the front of the queue
* @return Pointer of the element
*/
fptp_t *dl_get_queue_item(dl_conv_queue_t *cq, int offset);
/**
* @brief Does a sigmoid operation on the one of element in the convolution queue.
* Gets the pointer of element in the convolution queue by offset, and does a sigmoid operation
* by this pointer, then return the pointer
*
* @param cq Input convolution queue
* @param offset Offset from the front of the queue
* @return Pointer of the element
*/
fptp_t *dl_sigmoid_step(dl_conv_queue_t *cq, int offset);
/**
* @brief Does a tanh operation on the one of element in the convolution queue.
* Gets the pointer of element in the convolution queue by offset, and does a tanh operation
* by this pointer, then return the pointer
*
* @param cq Input convolution queue
* @param offset Offset from the front of the queue
* @return Pointer of the element
*/
fptp_t *dl_tanh_step(dl_conv_queue_t *cq, int offset);
/**
* @brief Does a softmax operation on the one of element in the convolution queue.
* Gets the pointer of element in the convolution queue by offset, and does a softmax operation
* by this pointer, then return the pointer
*
* @param cq Input convolution queue
* @param offset Offset from the front of the queue
* @return Pointer of the element
*/
fptp_t *dl_softmax_step(dl_conv_queue_t *cq, int offset);
fptp_t *dl_relu_step(dl_conv_queue_t *cq, int offset);
fptp_t *dl_relu_look(dl_matrix2d_t *cq, int offset);
dl_matrix2d_t *dl_matrix_concat1(const dl_conv_queue_t *a, const dl_matrix2d_t *b);
dl_matrix2d_t *dl_basic_lstm_layer1(const dl_conv_queue_t *in, dl_matrix2d_t *state_c, dl_matrix2d_t *state_h,
const dl_matrix2d_t *weight, const dl_matrix2d_t *bias);
/**
* @brief Fast implement for 1D atrous convolution (a.k.a. convolution with holes or dilated convolution)
* based on convolution queue.
*
* @Warning All input and output convolution queue and matrix should be allocated. The return pointer
* is first element of output queue and should not be freed separately.
*
* @param in Input convolution queue
* @param out Output convolution queue
* @param rate A positive int, the stride with which we sample input value
* @param size A positive int, the size of 1D-filter
* @param kernel The kernel matrix of filter
* @param bias The bias matrix of filter. Can be NULL if a bias of 0 is required.
* @return The result of atrous convolution
*/
fptp_t *dl_atrous_conv1d_step(dl_conv_queue_t *in, dl_conv_queue_t *out, int rate, int size,
dl_matrix2d_t* kernel, dl_matrix2d_t* bias);
fptp_t *dl_look_conv_step(dl_conv_queue_t *in, dl_matrix2d_t *out, int rate, int size,
dl_matrix2d_t* kernel, dl_matrix2d_t* bias);
/**
* @brief Fast implement of dilation layer as follows
*
* |-> [gate(sigmoid)] -|
* input - | |-> (*) - output
* |-> [filter(tanh)] -|
*
* @Warning All input and output convolution queue and matrix should be allocated. The return pointer
* is first element of output queue and should not be freed separately.
*
* @param in Input convolution queue
* @param out Output convolution queue
* @param rate A positive int, the stride with which we sample input value
* @param size A positive int, the size of 1D-filter
* @param filter_kernel The kernel matrix of filter
* @param filter_bias The bias matrix of filter. Can be NULL if a bias of 0 is required.
* @param gate_kernel The kernel matrix of gate
* @param gate_bias The bias matrix of gate. Can be NULL if a bias of 0 is required.
* @return The result of dilation layer
*/
fptp_t *dl_dilation_layer(dl_conv_queue_t *in, dl_conv_queue_t *out, int rate, int size,
dl_matrix2d_t* filter_kernel, dl_matrix2d_t* filter_bias,
dl_matrix2d_t* gate_kernel, dl_matrix2d_t* gate_bias);
void test_atrous_conv(int size, int rate, int in_channel, int out_channel);
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/lib/include/dl_lib_conv_queue.h
|
C
|
apache-2.0
| 6,529
|
// 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 DL_LIB_CONVQ_QUEUE_H
#define DL_LIB_CONVQ_QUEUE_H
#include "dl_lib_matrixq.h"
#include "dl_lib_conv_queue.h"
//fixed-point convolution FIFO queue.
typedef struct {
int n; /*< the length of queue */
int c; /*< the channel number of queue element*/
int front; /*< the front(top) position of queue */
int flag; /*< not used */
int exponent; /*< The values in items should be multiplied by pow(2,exponent)
to get the real values */
qtp_t *itemq; /*< Pointer to item array */
} dl_convq_queue_t;
/**
* @brief Allocate a fixed-point convolution queue
*
* @param n The length of queue
* @param c The channel number of elements in the queue
* @return The convolution queue, or NULL if out of memory
*/
dl_convq_queue_t *dl_convq_queue_alloc(int n, int c);
void dl_convq_to_matrix2dq(dl_convq_queue_t *cq, dl_matrix2dq_t* out, int row);
/**
* @brief Free a fixed-point convolution queue
*
* @param cq The fixed-point convolution queue to free
*/
void dl_convq_queue_free(dl_convq_queue_t *cq);
/**
* @brief Move the front pointer of queue forward,
the First(oldest) element become the last(newest) element,
*
* @param cq Input fixed-point convolution queue
* @return Pointer of oldest element
*/
qtp_t *dl_convq_queue_pop(dl_convq_queue_t *cq);
/**
* @brief Remove the oldest element, then insert the input element at the end of queue
*
* @param cq Input fixed-point convolution queue
* @param item The new element
*/
void dl_convq_queue_push(dl_convq_queue_t *cq, dl_matrix2dq_t *a, int shift);
/**
* @brief Insert the float-point element at the end of queue.
* The precision of fixed-point numbers is described by the Qm.f notation,
*
* @param cq Input fixed-point convolution queue
* @param item The float-point element
* @param m_bit The number of integer bits including the sign bits
* @param f_bit The number of fractional bits
*/
void dl_convq_queue_push_by_qmf(dl_convq_queue_t *cq, fptp_t* item, int m_bit, int f_bit);
/**
* @brief Get the pointer of element in the queue by offset
*
* @param cq Input fixed-point convolution queue
* @param offset Offset from the front of the queue
* @return Pointer of the element
*/
qtp_t *dl_get_queue_itemq(dl_convq_queue_t *cq, int offset);
/**
* @brief Does a tanh operation on the one of element in the convolution queue.
* Gets the pointer of element in the convolution queue by offset, and does a
* tanh operation by this pointer, then return the pointer
*
* @param cq Input fixed-point convolution queue
* @param offset Offset from the front of the queue
* @return Pointer of the element
*/
void dl_tanh_convq(dl_convq_queue_t *cq, int last_num);
/**
* @brief Does a relu operation on the one of element in the convolution queue.
* Gets the pointer of element in the convolution queue by offset, and does a
* relu operation by this pointer, then return the pointer
*
* @param cq Input fixed-point convolution queue
* @param offset Offset from the front of the queue
* @return Pointer of the element
*/
void dl_relu_convq(dl_convq_queue_t *cq, fptp_t clip, int last_num);
/**
* @brief Does a softmax operation on the one of element in the convolution queue.
* Gets the pointer of element in the convolution queue by offset, input data
stay as it is. Results are saved into the *out* array.
*
* @param cq Input fixed-point convolution queue
* @param offset Offset from the front of the queue
* @param out Old array to re-use. Passing NULL will allocate a new matrix.
* @return softmax results
*/
fptp_t * dl_softmax_step_q(dl_convq_queue_t *cq, int offset, fptp_t *out);
/**
* @brief Fast and quantised implement for 1D atrous convolution (a.k.a. convolution with holes or dilated convolution)
* based on convolution queue.
*
* @Warning All input and output convolution queue and matrix should be allocated. The return pointer
* is last element of output queue and should not be freed separately.
*
* @param in Input fixed-point convolution queue
* @param out Output fixed-point convolution queue
* @param rate A positive int, the stride with which we sample input value
* @param size A positive int, the size of 1D-filter
* @param kernel The kernel matrix of filter
* @param bias The bias matrix of filter. Can be NULL if a bias of 0 is required.
* @param shift Shift ratio used in dot operation between two 16-bit fixed point vector
* @return The result of atrous convolution
*/
qtp_t *dl_atrous_conv1dq(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size,
dl_matrix2dq_t* kernel, dl_matrix2dq_t* bias, int shift);
qtp_t *dl_atrous_conv1dq_steps(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size,
dl_matrix2dq_t* kernel, dl_matrix2dq_t* bias, int shift, int offset);
/**
* @brief Fast implement of dilation layer as follows
*
* |-> [gate(sigmoid)] -|
* input - | |-> (*) - output
* |-> [filter(tanh)] -|
*
* @Warning All input and output convolution queue and matrix should be allocated. The return pointer
* is last element of output queue and should not be freed separately.
*
* @param in Input fixed-point convolution queue
* @param out Output fixed-point convolution queue
* @param rate A positive int, the stride with which we sample input value
* @param size A positive int, the size of 1D-filter
* @param filter_kernel The kernel matrix of filter
* @param filter_bias The bias matrix of filter. Can be NULL if a bias of 0 is required.
* @param gate_kernel The kernel matrix of gate
* @param gate_bias The bias matrix of gate. Can be NULL if a bias of 0 is required.
* @filter_shift Shift ratio used in filter operation between two 16-bit fixed point vector
* @gate_shift Shift ratio used in gate operation between two 16-bit fixed point vector
* @return The result of dilation layer
*/
qtp_t *dl_dilation_layerq(dl_convq_queue_t *in, dl_convq_queue_t *out, int rate, int size,
dl_matrix2dq_t* filter_kernel, dl_matrix2dq_t* filter_bias,
dl_matrix2dq_t* gate_kernel, dl_matrix2dq_t* gate_bias,
int filter_shift, int gate_shift);
dl_matrix2dq_t *dl_basic_lstm_layer1_q(const dl_convq_queue_t *in, dl_matrix2dq_t *state_c, dl_matrix2dq_t *state_h,
const dl_matrix2dq_t *weight, const dl_matrix2dq_t *bias, int step, int shift);
void test_atrous_convq(int size, int rate, int in_channel, int out_channel);
dl_conv_queue_t *dl_convq_queue_add(dl_convq_queue_t *cq1, dl_convq_queue_t *cq2);
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/lib/include/dl_lib_convq_queue.h
|
C
|
apache-2.0
| 7,651
|
// 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 DL_LIB_MATRIX_H
#define DL_LIB_MATRIX_H
#if CONFIG_BT_SHARE_MEM_REUSE
#include "freertos/FreeRTOS.h"
#endif
typedef float fptp_t;
#if CONFIG_BT_SHARE_MEM_REUSE
extern multi_heap_handle_t gst_heap;
#endif
//Flags for matrices
#define DL_MF_FOREIGNDATA (1<<0) /*< Matrix *item data actually points to another matrix and should not be freed */
//'Normal' float matrix
typedef struct {
int w; /*< Width */
int h; /*< Height */
int stride; /*< Row stride, essentially how many items to skip to get to the same position in the next row */
int flags; /*< Flags. OR of DL_MF_* values */
fptp_t *item; /*< Pointer to item array */
} dl_matrix2d_t;
//Macro to quickly access the raw items in a matrix
#define DL_ITM(m, x, y) m->item[(x)+(y)*m->stride]
/**
* @brief Allocate a matrix
*
* @param w Width of the matrix
* @param h Height of the matrix
* @return The matrix, or NULL if out of memory
*/
dl_matrix2d_t *dl_matrix_alloc(int w, int h);
/**
* @brief Free a matrix
* Frees the matrix structure and (if it doesn't have the DL_MF_FOREIGNDATA flag set) the m->items space as well.
*
* @param m Matrix to free
*/
void dl_matrix_free(dl_matrix2d_t *m);
/**
* @brief Zero out the matrix
* Sets all entries in the matrix to 0.
*
* @param m Matrix to zero
*/
void dl_matrix_zero(dl_matrix2d_t *m);
/**
* @brief Generate a new matrix using a range of items from an existing matrix.
* When using this, the data of the new matrix is not allocated/copied but it re-uses a pointer
* to the existing data. Changing the data in the resulting matrix, as a result, will also change
* the data in the existing matrix that has been sliced.
*
* @param x X-offset of the origin of the returned matrix within the sliced matrix
* @param y Y-offset of the origin of the returned matrix within the sliced matrix
* @param w Width of the resulting matrix
* @param h Height of the resulting matrix
* @param in Old matrix (with foreign data) to re-use. Passing NULL will allocate a new matrix.
* @return The resulting slice matrix, or NULL if out of memory
*/
dl_matrix2d_t *dl_matrix_slice(const dl_matrix2d_t *src, int x, int y, int w, int h, dl_matrix2d_t *in);
/**
* @brief select a range of items from an existing matrix and flatten them into one dimension.
*
* @Warning The results are flattened in row-major order.
*
* @param x X-offset of the origin of the returned matrix within the sliced matrix
* @param y Y-offset of the origin of the returned matrix within the sliced matrix
* @param w Width of the resulting matrix
* @param h Height of the resulting matrix
* @param in Old matrix to re-use. Passing NULL will allocate a new matrix.
* @return The resulting flatten matrix, or NULL if out of memory
*/
dl_matrix2d_t *dl_matrix_flatten(const dl_matrix2d_t *src, int x, int y, int w, int h, dl_matrix2d_t *in);
/**
* @brief Generate a matrix from existing floating-point data
*
* @param w Width of resulting matrix
* @param h Height of resulting matrix
* @param data Data to populate matrix with
* @return A newaly allocated matrix populated with the given input data, or NULL if out of memory.
*/
dl_matrix2d_t *dl_matrix_from_data(int w, int h, int stride, const void *data);
/**
* @brief Multiply a pair of matrices item-by-item: res=a*b
*
* @param a First multiplicand
* @param b Second multiplicand
* @param res Multiplicated data. Can be equal to a or b to overwrite that.
*/
void dl_matrix_mul(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *res);
/**
* @brief Do a dotproduct of two matrices : res=a.b
*
* @param a First multiplicand
* @param b Second multiplicand
* @param res Dotproduct data. *Must* be a *different* matrix from a or b!
*/
void dl_matrix_dot(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *res);
/**
* @brief Add a pair of matrices item-by-item: res=a-b
*
* @param a First matrix
* @param b Second matrix
* @param res Added data. Can be equal to a or b to overwrite that.
*/
void dl_matrix_add(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *out);
/**
* @brief Divide a pair of matrices item-by-item: res=a/b
*
* @param a First matrix
* @param b Second matrix
* @param res Divided data. Can be equal to a or b to overwrite that.
*/
void dl_matrix_div(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *out);
/**
* @brief Subtract a matrix from another, item-by-item: res=a-b
*
* @param a First matrix
* @param b Second matrix
* @param res Subtracted data. Can be equal to a or b to overwrite that.
*/
void dl_matrix_sub(const dl_matrix2d_t *a, const dl_matrix2d_t *b, dl_matrix2d_t *out);
/**
* @brief Add a constant to every item of the matrix
*
* @param subj Matrix to add the constant to
* @param add The constant
*/
void dl_matrix_add_const(dl_matrix2d_t *subj, const fptp_t add);
/**
* @brief Concatenate the rows of two matrices into a new matrix
*
* @param a First matrix
* @param b Second matrix
* @return A newly allocated array with as avlues a|b
*/
dl_matrix2d_t *dl_matrix_concat(const dl_matrix2d_t *a, const dl_matrix2d_t *b);
/**
* @brief Print the contents of a matrix to stdout. Used for debugging.
*
* @param a The matrix to print.
*/
void dl_printmatrix(const dl_matrix2d_t *a);
/**
* @brief Return the average square error given a correct and a test matrix.
*
* ...Well, more or less. If anything, it gives an indication of the error between
* the two. Check the code for the exact implementation.
*
* @param a First of the two matrices to compare
* @param b Second of the two matrices to compare
* @return value indicating the relative difference between matrices
*/
float dl_matrix_get_avg_sq_err(const dl_matrix2d_t *a, const dl_matrix2d_t *b);
/**
* @brief Check if two matrices have the same shape, that is, the same amount of rows and columns
*
* @param a First of the two matrices to compare
* @param b Second of the two matrices to compare
* @return true if the two matrices are shaped the same, false otherwise.
*/
int dl_matrix_same_shape(const dl_matrix2d_t *a, const dl_matrix2d_t *b);
/**
* @brief Get a specific item from the matrix
*
* Please use these for external matrix access instead of DL_ITM
*
* @param m Matrix to access
* @param x Column address
* @param y Row address
* @return Value in that position
*/
inline static fptp_t dl_matrix_get(const dl_matrix2d_t *m, const int x, const int y) {
return DL_ITM(m, x, y);
}
/**
* @brief Set a specific item in the matrix to the given value
*
* Please use these for external matrix access instead of DL_ITM
*
* @param m Matrix to access
* @param x Column address
* @param y Row address
* @param val Value to write to that position
*/
inline static void dl_matrix_set(dl_matrix2d_t *m, const int x, const int y, fptp_t val) {
DL_ITM(m, x, y)=val;
}
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/lib/include/dl_lib_matrix.h
|
C
|
apache-2.0
| 7,721
|
// 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 DL_LIB_MATRIXQ_H
#define DL_LIB_MATRIXQ_H
#include <stdint.h>
#include "dl_lib_matrix.h"
typedef int16_t qtp_t;
//Quantized matrix. Uses fixed numbers and has the storage for the rows/columns inverted
//for easy use as a multiplicand without stressing out the flash cache too much.
typedef struct {
int w;
int h;
int stride; //Normally equals h, not w!
int flags;
int exponent; //The values in items should be multiplied by pow(2,exponent) to get the real values.
qtp_t *itemq;
} dl_matrix2dq_t;
#define DL_QTP_SHIFT 15
#define DL_QTP_RANGE ((1<<DL_QTP_SHIFT)-1)
#define DL_ITMQ(m, x, y) m->itemq[(y)+(x)*m->stride]
#define DL_QTP_EXP_NA 255 //non-applicable exponent because matrix is null
#define DL_SHIFT_AUTO 32
/**
* @info About quantized matrices and shift values
*
* Grab a coffee (or tea, or hot water) and sit down when you read this for the first
* time. Quantized matrices can speed up your operations, but come with some quirks, and
* it's good to understand how they work before using them.
*
* The data in the quantized matrix type is stored similarily to floating-point types:
* when storing a real value, the value is stored as a mantissa (base number) and an
* exponent. The 'real' value that can be re-derived from those two numbers is something
* similar to mantissa*2^exponent. Up to this point, there's not that much difference from
* the standard floating point implementations like e.g. IEEE-754.
*
* The difference with respect to quantized matrices is that for a quantized matrix, it is
* assumed all values stored have more-or-less the same order of magnitude. This allows the
* matrix to only store all the mantissas, while the exponents are shared; there is only one
* exponent for the entire matrix. This makes it quicker to handle matrix operations - the
* logic to fix the exponents only needs to happen once, while the rest can be done in simple
* integer arithmetic. It also nets us some memory savings - while normally a floating point
* number is 32-bit, storing only 16-bit mantissas as the matrix items almost halves the
* memory requirements.
*
* While most of the details of handling the intricacies of the quantized matrixes are done
* transparently by the code in dl_lib_matrixq.c, some implementation details leak out,
* specifically in places where addition/subtraction/division happens.
*
* The problem is that the routines do not know what the size of the resulting operation is. For
* instance, when adding two matrices of numbers, the resulting numbers *could* be large enough
* to overflow the mantissa of the result if the exponent is the same. However, if by default we
* assume the mantissas needs to be scaled back, we may lose precision.
*
* In order to counter this, all operations that have this issue have a ``shift`` argument. If
* the argument is zero, the routine will be conservative, that is, increase the exponent of
* the result to such an extent it's mathematically impossible a value in the result will exceed
* the maximum value that can be stored. However, when this argument is larger than zero, the
* algorithm will hold back on this scaling by the indicated amount of bits, preserving precision
* but increasing the chance of some of the calculated values not fitting in the mantissa anymore.
* If this happens, the value will be clipped to the largest (or, for negative values, smallest)
* value possible. (Neural networks usually are okay with this happening for a limited amount
* of matrix indices).
*
* For deciding on these shift values, it is recommended to start with a shift value of one, then
* use dl_matrixq_check_sanity on the result. If this indicates clipping, lower the shift value.
* If it indicates bits are under-used, increase it. Note that for adding and subtraction, only
* shift values of 0 or 1 make sense; these routines will error out if you try to do something
* else.
*
* For neural networks and other noise-tolerant applications, note that even when
* dl_matrixq_check_sanity does not indicate any problems, twiddling with the shift value may lead
* to slightly improved precision. Feel free to experiment.
**/
/**
* @brief Allocate a matrix
*
* @param w Width of the matrix
* @param h Height of the matrix
* @return The matrix, or NULL if out of memory
*/
dl_matrix2dq_t *dl_matrixq_alloc(int w, int h);
/**
* @brief Convert a floating-point matrix to a quantized matrix
*
* @param m Floating-point matrix to convert
* @param out Quantized matrix to re-use. If NULL, allocate a new one.
* @Return The quantized version of the floating-point matrix
*/
dl_matrix2dq_t *dl_matrixq_from_matrix2d(const dl_matrix2d_t *m, dl_matrix2dq_t *out);
/**
* TODO: DESCRIBE THIS FUNCTION
*/
dl_matrix2dq_t *dl_matrixq_from_matrix2d_by_qmf(const dl_matrix2d_t *m, dl_matrix2dq_t *out, int m_bit, int f_bit);
/**
* @brief Convert a quantized matrix to a floating-point one.
*
* @param m Floating-point matrix to convert
* @param out Quantized matrix to re-use. If NULL, allocate a new one.
* @Return The quantized version of the floating-point matrix
**/
dl_matrix2d_t *dl_matrix2d_from_matrixq(const dl_matrix2dq_t *m, dl_matrix2d_t *out);
/**
* @brief Free a quantized matrix
* Frees the matrix structure and (if it doesn't have the DL_MF_FOREIGNDATA flag set) the m->items space as well.
*
* @param m Matrix to free
*/
void dl_matrixq_free(dl_matrix2dq_t *m);
/**
* @brief Zero out the matrix
* Sets all entries in the matrix to 0.
*
* @param m Matrix to zero
*/
void dl_matrixq_zero(dl_matrix2dq_t *m);
/**
* @brief Do a dotproduct of two quantized matrices : res=a.b, Result is a fixed-point matrix.
*
* @param a First multiplicand
* @param b Second multiplicand
* @param res Dotproduct data. *Must* be a *different* matrix from a or b!
* @param shift Shift ratio
*/
void dl_matrixq_dot(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *res, int shift);
/**
* @brief Do a dotproduct of two quantized matrices: res=a.b, Result is a floating-point matrix.
*
* @param a First multiplicand
* @param b Second multiplicand
* @param res Dotproduct data. *Must* be a *different* matrix from a or b!
*/
void dl_matrixq_dot_matrix_out(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2d_t *res);
/**
* @brief Do a dotproduct of two quantized matrices : res=a.b. This always uses the simple & stupid C algo for the dot product.
*
* Result is a fixed-point matrix.
*
* Use this only if you expect something is wrong with the accelerated routines that dl_matrixq_dot calls; this function can be
* much slower than dl_matrixq_dot .
*
* @param a First multiplicand
* @param b Second multiplicand
* @param res Dotproduct data. *Must* be a *different* matrix from a or b!
* @param shift Shift ratio
*/
void dl_matrixq_dot_c_impl(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *res, int shift);
/**
* @brief Do a dotproduct of two quantized matrices : res=a.b. This always uses the simple & stupid C algo for the dot product.
*
* Result is a floating-point matrix.
*
* Use this only if you expect something is wrong with the accelerated routines that dl_matrixq_dot_matrix_out calls; this function can be
* much slower than dl_matrixq_dot_matrix_out.
*
* @param a First multiplicand
* @param b Second multiplicand
* @param res Dotproduct data. *Must* be a *different* matrix from a or b!
*/
void dl_matrixq_dot_matrix_out_c_impl(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2d_t *res);
/**
* @brief Do a dotproduct of a floating point and a quantized matrix. Result is a floating-point matrix.
*
* @param a First multiplicand; float matrix
* @param b Second multiplicand; quantized matrix
* @param res Dotproduct data; float matrix. *Must* be a *different* matrix from a or b!
*/
void dl_matrix_matrixq_dot(const dl_matrix2d_t *a, const dl_matrix2dq_t *b, dl_matrix2d_t *res);
/**
* @brief Print the contents of a quantized matrix to stdout. Used for debugging.
*
* @param a The matrix to print.
*/
void dl_printmatrixq(const dl_matrix2dq_t *a);
/**
* @brief Add a pair of quantizedmatrices item-by-item: res=a-b
*
* @param a First matrix
* @param b Second matrix
* @param res Added data. Can be equal to a or b to overwrite that.
* @param shift Shift value. Only 0 or 1 makes sense here. <ToDo: check>
*/
void dl_matrixq_add(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *res, int shift);
/**
* @brief Generate a new matrix using a range of items from an existing matrix.
* When using this, the data of the new matrix is not allocated/copied but it re-uses a pointer
* to the existing data. Changing the data in the resulting matrix, as a result, will also change
* the data in the existing matrix that has been sliced.
*
* @Warning In contrast to the floating point equivalent of this function, the fixed-point version
* of this has the issue that as soon as the output exponent of one of the slices changes, the data
* in the sliced matrix gets corrupted (because the exponent of that matrix is still the same.) If you
* use this function, either treat the slices as read-only, or assume the sliced matrix contains
* garbage after modifying the data in one of the slices.
*
* @param x X-offset of the origin of the returned matrix within the sliced matrix
* @param y Y-offset of the origin of the returned matrix within the sliced matrix
* @param w Width of the resulting matrix
* @param h Height of the resulting matrix
* @param in Old matrix (with foreign data) to re-use. Passing NULL will allocate a new matrix.
* @return The resulting slice matrix, or NULL if out of memory
*/
dl_matrix2dq_t *dl_matrixq_slice(const dl_matrix2dq_t *src, int x, int y, int w, int h, dl_matrix2dq_t *in);
/**
* @brief select a range of items from an existing matrix and flatten them into one dimension.
*
* @Warning The results are flattened in row-major order.
*
* @param x X-offset of the origin of the returned matrix within the sliced matrix
* @param y Y-offset of the origin of the returned matrix within the sliced matrix
* @param w Width of the resulting matrix
* @param h Height of the resulting matrix
* @param in Old matrix to re-use. Passing NULL will allocate a new matrix.
* @return The resulting flatten matrix, or NULL if out of memory
*/
dl_matrix2dq_t *dl_matrixq_flatten(const dl_matrix2dq_t *src, int x, int y, int w, int h, dl_matrix2dq_t *in);
/**
* @brief Subtract a quantized matrix from another, item-by-item: res=a-b
*
* @param a First matrix
* @param b Second matrix
* @param res Subtracted data. Can be equal to a or b to overwrite that.
* @param shift Shift value. Only 0 or 1 makes sense here. <ToDo: check>
*/
void dl_matrixq_sub(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *res, int shift);
/**
* @brief Multiply a pair of quantized matrices item-by-item: res=a*b
*
* @param a First multiplicand
* @param b Second multiplicand
* @param res Multiplicated data. Can be equal to a or b to overwrite that matrix.
*/
void dl_matrixq_mul(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *res);
/**
* @brief Divide a pair of quantized matrices item-by-item: res=a/b
*
* @param a First matrix
* @param b Second matrix
* @param res Divided data. Can be equal to a or b to overwrite that.
*/
void dl_matrixq_div(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b, dl_matrix2dq_t *out, int shift);
/**
* @brief Check if two quantized matrices have the same shape, that is, the same amount of
* rows and columns
*
* @param a First of the two matrices to compare
* @param b Second of the two matrices to compare
* @return true if the two matrices are shaped the same, false otherwise.
*/
int dl_matrixq_same_shape(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b);
/**
* @brief Concatenate the rows of two quantized matrices into a new matrix
*
* @param a First matrix
* @param b Second matrix
* @return A newly allocated quantized matrix with as values a|b
*/
dl_matrix2dq_t *dl_matrixq_concat(const dl_matrix2dq_t *a, const dl_matrix2dq_t *b);
/**
* @brief Add a constant to every item of the quantized matrix
*
* @param subj Matrix to add the constant to
* @param add The constant
*/
void dl_matrixq_add_const(dl_matrix2dq_t *subj, const fptp_t add, int shift);
/**
* @brief Check the sanity of a quantized matrix
*
* Due to the nature of quantized matrices, depending on the calculations a quantized
* matrix is the result of and the shift values chosen in those calculations, a quantized
* matrix may have an exponent and mantissas that lead to a loss of precision, either because
* most significant mantissa bits are unused, or because a fair amount of mantissas are
* clipped. This function checks if this is the case and will report a message to stdout
* if significant loss of precision is detected.
*
* @param m The quantized matrix to check
* @param name A string to be displayed in the message if the sanity check fails
* @return True if matrix is sane, false otherwise
**/
int dl_matrixq_check_sanity(dl_matrix2dq_t *m, const char *name);
/**
* @brief re-adjust the exponent of the matrix to fit the mantissa better
*
* This function will shift up all the data in the mantissas so there are no
* most-significant bits that are unused in all mantissas. It will also adjust
* the exponent to keep the actua values in the matrix the same.
*
* Some operations done on a matrix, especially operations that re-use the
* result of earlier operations done in the same way, can lead to the loss of
* data because the exponent of the quantized matrix is never re-adjusted. You
* can do that implicitely by calling this function.
*
* @param m The matrix to re-adjust
**/
void dl_matrixq_readjust_exp(dl_matrix2dq_t *m);
/**
* @brief Get the floating-point value of a specific item from the quantized matrix
*
* @param m Matrix to access
* @param x Column address
* @param y Row address
* @return Value in that position
*/
fptp_t dl_matrixq_get(const dl_matrix2dq_t *m, const int x, const int y);
/**
* @brief Set a specific item in the quantized matrix to the given
* floating-point value
*
* @warning If the given value is more than the exponent in the quantized matrix
* allows for, all mantissas in the matrix will be shifted down to make the value
* 'fit'. If, however, the exponent is such that the value would result in a
* quantized mantissa of 0, nothing is done.
*
* @param m Matrix to access
* @param x Column address
* @param y Row address
* @param val Value to write to that position
*/
void dl_matrixq_set(dl_matrix2dq_t *m, const int x, const int y, fptp_t val);
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/lib/include/dl_lib_matrixq.h
|
C
|
apache-2.0
| 15,644
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "audio_process.h"
#include "esp_ns.h"
#include "esp_aec.h"
#include "esp_agc.h"
#include "esp_vad.h"
#include "esp_mase.h"
#include "audio_test_file.h"
void NSTask(void *arg)
{
ns_handle_t ns_inst = ns_create(NS_FRAME_LENGTH_MS);
int chunks = 0;
int audio_chunksize = NS_FRAME_LENGTH_MS * 16;
int16_t *ns_in = malloc(audio_chunksize * sizeof(int16_t));
int16_t *ns_out = malloc(audio_chunksize * sizeof(int16_t));
while (1) {
if ((chunks + 1) * audio_chunksize * sizeof(int16_t) <= sizeof(audio_test_file)) {
memcpy(ns_in, audio_test_file + chunks * audio_chunksize * sizeof(int16_t), audio_chunksize * sizeof(int16_t));
} else {
break;
}
ns_process(ns_inst, ns_in, ns_out);
chunks++;
}
ns_destroy(ns_inst);
free(ns_in);
free(ns_out);
printf("NS test successfully\n\n");
vTaskDelete(NULL);
}
#define AGC_FRAME_BYTES 320
void AGCTask(void *arg)
{
void *agc_handle = esp_agc_open(3, 16000);
set_agc_config(agc_handle, 15, 1, -3);
int chunks = 0;
int16_t *agc_in = malloc(AGC_FRAME_BYTES);
int16_t *agc_out = malloc(AGC_FRAME_BYTES);
while (1) {
if ((chunks + 1) * AGC_FRAME_BYTES <= sizeof(audio_test_file)) {
memcpy(agc_in, audio_test_file + chunks * AGC_FRAME_BYTES, AGC_FRAME_BYTES);
} else {
break;
}
esp_agc_process(agc_handle, agc_in, agc_out, AGC_FRAME_BYTES / 2, 16000);
chunks++;
}
esp_agc_clse(agc_handle);
free(agc_in);
free(agc_out);
printf("AGC test successfully\n\n");
vTaskDelete(NULL);
}
void AECTask(void *arg)
{
aec_handle_t aec_inst = aec_create(AEC_SAMPLE_RATE, AEC_FRAME_LENGTH_MS, AEC_FILTER_LENGTH);
int chunks = 0;
int audio_chunksize = AEC_FRAME_LENGTH_MS * 16;
int16_t *aec_in = malloc(audio_chunksize * sizeof(int16_t));
int16_t *aec_ref = malloc(audio_chunksize * sizeof(int16_t));
int16_t *aec_out = malloc(audio_chunksize * sizeof(int16_t));
while (1) {
if ((chunks + 1) * audio_chunksize * sizeof(int16_t) <= sizeof(audio_test_file)) {
memcpy(aec_in, audio_test_file + chunks * audio_chunksize * sizeof(int16_t), audio_chunksize * sizeof(int16_t));
memset(aec_ref, 0, audio_chunksize * sizeof(int16_t));
} else {
break;
}
aec_process(aec_inst, aec_in, aec_ref, aec_out);
chunks++;
}
aec_destroy(aec_inst);
free(aec_in);
free(aec_ref);
free(aec_out);
printf("AEC test successfully\n\n");
vTaskDelete(NULL);
}
void VADTask(void *arg)
{
vad_handle_t vad_inst = vad_create(VAD_MODE_4, SAMPLE_RATE_HZ, VAD_FRAME_LENGTH_MS);
int chunks = 0;
int audio_chunksize = VAD_FRAME_LENGTH_MS * 16;
int16_t *vad_in = malloc(audio_chunksize * sizeof(int16_t));
while (1) {
if ((chunks + 1) * audio_chunksize * sizeof(int16_t) <= sizeof(audio_test_file)) {
memcpy(vad_in, audio_test_file + chunks * audio_chunksize * sizeof(int16_t), audio_chunksize * sizeof(int16_t));
} else {
break;
}
vad_state_t vad_state = vad_process(vad_inst, vad_in);
chunks++;
}
vad_destroy(vad_inst);
free(vad_in);
printf("VAD test successfully\n\n");
vTaskDelete(NULL);
}
void MASETask(void *arg)
{
mase_handle_t mase_st = mase_create(MASE_SAMPLE_RATE, MASE_FRAME_SIZE, THREE_MIC_CIRCLE, MASE_MIC_DISTANCE, WAKE_UP_ENHANCEMENT_MODE, 6);
int chunks = 0;
int nch = 3;
int audio_chunksize = MASE_FRAME_SIZE * MASE_SAMPLE_RATE * nch / 1000;
int16_t *mase_in = malloc(audio_chunksize * sizeof(int16_t));
int16_t *mase_out = malloc(audio_chunksize / nch * sizeof(int16_t));
while (1) {
if ((chunks + 1) * audio_chunksize * sizeof(int16_t) <= sizeof(audio_test_file)) {
memcpy(mase_in, audio_test_file + chunks * audio_chunksize * sizeof(int16_t), audio_chunksize * sizeof(int16_t));
memset(mase_out, 0, audio_chunksize / nch * sizeof(int16_t));
} else {
break;
}
mase_process(mase_st, mase_in, mase_out);
chunks++;
}
mase_destory(mase_st);
free(mase_in);
free(mase_out);
printf("MASE test successfully\n\n");
printf("TEST3 FINISHED\n\n");
vTaskDelete(NULL);
}
void audio_process_test()
{
xTaskCreatePinnedToCore(&NSTask, "noise_suppression", 3 * 1024, NULL, 5, NULL, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
xTaskCreatePinnedToCore(&AGCTask, "automatic_gain_control", 3 * 1024, NULL, 5, NULL, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
xTaskCreatePinnedToCore(&AECTask, "acoustic_echo_cancellation", 3 * 1024, NULL, 5, NULL, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
xTaskCreatePinnedToCore(&VADTask, "voice_activity_detection", 3 * 1024, NULL, 5, NULL, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
xTaskCreatePinnedToCore(&MASETask, "mic_array_speech_enhancement", 3 * 1024, NULL, 5, NULL, 1);
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/main/audio_process.c
|
C
|
apache-2.0
| 5,163
|
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
COMPONENT_DEPENDS := wake_word_engine
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/main/component.mk
|
Makefile
|
apache-2.0
| 184
|
#pragma once
void audio_process_test();
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/main/include/audio_process.h
|
C
|
apache-2.0
| 40
|
#pragma once
void multinet_test();
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/main/include/multinet_test.h
|
C
|
apache-2.0
| 36
|
#pragma once
void wakenet_test();
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/main/include/wakenet_test.h
|
C
|
apache-2.0
| 34
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "xtensa/core-macros.h"
#include "wakenet_test.h"
#include "multinet_test.h"
#include "audio_process.h"
void app_main()
{
// test wakenet
wakenet_test();
vTaskDelay(3000 / portTICK_PERIOD_MS);
// test multinet
multinet_test();
vTaskDelay(3000 / portTICK_PERIOD_MS);
// test acoustic algorithm
audio_process_test();
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/main/main.c
|
C
|
apache-2.0
| 502
|
#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_mn_iface.h"
#include "esp_mn_models.h"
#include "dl_lib_coefgetter_if.h"
#include "multinet_test.h"
#include "dakaidiandeng.h"
static const esp_mn_iface_t *multinet = &MULTINET_MODEL;
void multinetTask(void *arg)
{
model_iface_data_t *model_data = arg;
int audio_chunksize = multinet->get_samp_chunksize(model_data);
int chunk_num = multinet->get_samp_chunknum(model_data);
int16_t *buffer = malloc(audio_chunksize * sizeof(int16_t));
assert(buffer);
int chunks = 0;
while (1) {
if ((chunks+1)*audio_chunksize*sizeof(int16_t) <= sizeof(dakaidiandeng)) {
memcpy(buffer, dakaidiandeng+chunks*audio_chunksize*sizeof(int16_t), audio_chunksize * sizeof(int16_t));
} else {
memset(buffer, 0, audio_chunksize*sizeof(int16_t));
}
int command_id = multinet->detect(model_data, buffer);
chunks++;
if (chunks == chunk_num || command_id > -1) {
if (command_id > -1) {
printf("MN test successfully, Commands ID: %d.\n", command_id);
break;
} else {
printf("can not recognize any speech commands\n");
}
break;
}
}
printf("TEST2 FINISHED\n\n");
multinet->destroy(model_data);
vTaskDelete(NULL);
}
void multinet_test()
{
int start_size = heap_caps_get_free_size(MALLOC_CAP_8BIT);
printf("Start free RAM size: %d\n", start_size);
//Initialize multinet model
model_iface_data_t *model_data = multinet->create(&MULTINET_COEFF, 6000);
//define_speech_commands(multinet, model_data);
printf("multinet RAM size: %d\nRAM size after multinet init: %d\n",
start_size - heap_caps_get_free_size(MALLOC_CAP_8BIT), heap_caps_get_free_size(MALLOC_CAP_8BIT));
xTaskCreatePinnedToCore(&multinetTask, "multinet", 2 * 1024, (void*)model_data, 5, NULL, 1);
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/main/multinet_test.c
|
C
|
apache-2.0
| 2,004
|
#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_wn_iface.h"
#include "esp_wn_models.h"
#include "dl_lib_coefgetter_if.h"
#include "wakenet_test.h"
#include "hilexin.h"
#include <sys/time.h>
static const esp_wn_iface_t *wakenet = &WAKENET_MODEL;
static const model_coeff_getter_t *model_coeff_getter = &WAKENET_COEFF;
void wakenetTask(void *arg)
{
model_iface_data_t *model_data = arg;
int frequency = wakenet->get_samp_rate(model_data);
int audio_chunksize = wakenet->get_samp_chunksize(model_data);
int16_t *buffer = malloc(audio_chunksize * sizeof(int16_t));
assert(buffer);
int chunks = 0;
struct timeval tv_start, tv_end;
gettimeofday(&tv_start, NULL);
while (1) {
if ((chunks + 1)*audio_chunksize * sizeof(int16_t) <= sizeof(hilexin)) {
memcpy(buffer, hilexin + chunks * audio_chunksize * sizeof(int16_t), audio_chunksize * sizeof(int16_t));
} else {
break;
}
int r = wakenet->detect(model_data, buffer);
if (r) {
int ms = (chunks * audio_chunksize * 1000) / frequency;
printf("WN test successfully, %.2f: Neural network detection triggered output %d.\n", (float)ms / 1000.0, r);
}
chunks++;
}
gettimeofday(&tv_end, NULL);
int tv_ms=(tv_end.tv_sec-tv_start.tv_sec)*1000+(tv_end.tv_usec-tv_start.tv_usec)/1000;
printf("Done! Took %d ms to parse %d ms worth of samples in %d iterations. CPU loading(single core):%.1f%%\n",
tv_ms, chunks*30, chunks, tv_ms*1.0/chunks/3*10);
printf("TEST1 FINISHED\n\n");
vTaskDelete(NULL);
}
void wakenet_test()
{
int start_size = heap_caps_get_free_size(MALLOC_CAP_8BIT);
printf("Start free RAM size: %d\n", start_size);
//Initialize wakenet model
model_iface_data_t *model_data = wakenet->create(model_coeff_getter, DET_MODE_90);
printf("WakeNet RAM size: %d\nRAM size after WakeNet init: %d\n",
start_size - heap_caps_get_free_size(MALLOC_CAP_8BIT), heap_caps_get_free_size(MALLOC_CAP_8BIT));
xTaskCreatePinnedToCore(&wakenetTask, "wakenet", 2 * 1024, (void*)model_data, 5, NULL, 1);
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/main/wakenet_test.c
|
C
|
apache-2.0
| 2,206
|
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := .
LIB_FILES := $(shell ls $(COMPONENT_PATH)/lib*.a)
LIBS := $(patsubst lib%.a,-l%,$(notdir $(LIB_FILES)))
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/ $(LIBS)
ALL_LIB_FILES += $(LIB_FILES)
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/speech_command_recognition/component.mk
|
Makefile
|
apache-2.0
| 254
|
#pragma once
#include "stdint.h"
#include "esp_err.h"
#include "dl_lib_coefgetter_if.h"
#include "esp_wn_iface.h"
// //Opaque model data container
// typedef struct model_iface_data_t model_iface_data_t;
/**
* @brief Initialze a model instance with specified model coefficient.
*
* @param coeff The wakenet model coefficient.
* @param coeff The wakenet model coefficient.
* @parm sample_length Audio length for speech recognition, in ms.
* @returns Handle to the model data.
*/
typedef model_iface_data_t* (*esp_mn_iface_op_create_t)(const model_coeff_getter_t *coeff, int sample_length);
/**
* @brief Callback function type to fetch the amount of samples that need to be passed to the detect function
*
* Every speech recognition model processes a certain number of samples at the same time. This function
* can be used to query that amount. Note that the returned amount is in 16-bit samples, not in bytes.
*
* @param model The model object to query
* @return The amount of samples to feed the detect function
*/
typedef int (*esp_mn_iface_op_get_samp_chunksize_t)(model_iface_data_t *model);
/**
* @brief Callback function type to fetch the number of frames recognized by the command word
*
* @param model The model object to query
* @return The number of the frames recognized by the command word
*/
typedef int (*esp_mn_iface_op_get_samp_chunknum_t)(model_iface_data_t *model);
/**
* @brief Set the detection threshold to manually abjust the probability
*
* @param model The model object to query
* @param det_treshold The threshold to trigger speech commands, the range of det_threshold is 0.5~0.9999
*/
typedef int (*esp_mn_iface_op_set_det_threshold_t)(model_iface_data_t *model, float det_threshold);
/**
* @brief Get the sample rate of the samples to feed to the detect function
*
* @param model The model object to query
* @return The sample rate, in hz
*/
typedef int (*esp_mn_iface_op_get_samp_rate_t)(model_iface_data_t *model);
/**
* @brief Feed samples of an audio stream to the speech recognition model and detect if there is a speech command found.
*
* @param model The model object to query.
* @param samples An array of 16-bit signed audio samples. The array size used can be queried by the
* get_samp_chunksize function.
* @return The command id, return 0 if no command word is detected,
*/
typedef int (*esp_mn_iface_op_detect_t)(model_iface_data_t *model, int16_t *samples);
/**
* @brief Destroy a speech commands recognition model
*
* @param model The Model object to destroy
*/
typedef void (*esp_mn_iface_op_destroy_t)(model_iface_data_t *model);
/**
* @brief Reset the speech commands recognition model
*
*/
typedef void (*esp_mn_iface_op_reset_t)(void);
typedef struct {
esp_mn_iface_op_create_t create;
esp_mn_iface_op_get_samp_rate_t get_samp_rate;
esp_mn_iface_op_get_samp_chunksize_t get_samp_chunksize;
esp_mn_iface_op_get_samp_chunknum_t get_samp_chunknum;
esp_mn_iface_op_set_det_threshold_t set_det_threshold;
esp_mn_iface_op_detect_t detect;
esp_mn_iface_op_destroy_t destroy;
esp_mn_iface_op_reset_t reset;
} esp_mn_iface_t;
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/speech_command_recognition/include/esp_mn_iface.h
|
C
|
apache-2.0
| 3,219
|
#pragma once
#include "esp_mn_iface.h"
//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.
extern const esp_mn_iface_t esp_sr_multinet1_quantized_cn;
extern const esp_mn_iface_t esp_sr_multinet1_quantized_en;
extern const esp_mn_iface_t esp_sr_multinet2_quantized_cn;
/*
Configure network to use based on what's selected in menuconfig.
*/
// #if CONFIG_SINGLE_RECOGNITION
// #define MULTINET_MODEL esp_sr_multinet1_quantized
// #else
// #error No valid neural network model selected.
// #endif
/*
Configure wake word to use based on what's selected in menuconfig.
*/
#if CONFIG_SR_CHINESE && CONFIG_SINGLE_RECOGNITION
#include "multinet1_ch.h"
#define MULTINET_MODEL esp_sr_multinet1_quantized_cn
#define MULTINET_COEFF get_coeff_multinet1_ch
#elif CONFIG_SR_ENGLISH && CONFIG_SINGLE_RECOGNITION
#include "multinet1_en.h"
#define MULTINET_MODEL esp_sr_multinet1_quantized_en
#define MULTINET_COEFF get_coeff_multinet1_en
#elif CONFIG_SR_CHINESE && CONFIG_CONTINUOUS_RECOGNITION
#include "multinet1_ch.h"
#define MULTINET_MODEL esp_sr_multinet2_quantized_cn
#define MULTINET_COEFF get_coeff_multinet1_ch
#else
#error No valid wake word selected.
#endif
/* example
static const esp_mn_iface_t *multinet = &MULTINET_MODEL;
//Initialize MultiNet model data
model_iface_data_t *model_data = multinet->create(&MULTINET_COEFF);
add_speech_commands(multinet, model_data);
//Set parameters of buffer
int audio_chunksize=model->get_samp_chunksize(model_data);
int frequency = model->get_samp_rate(model_data);
int16_t *buffer=malloc(audio_chunksize*sizeof(int16_t));
//Detect
int r=model->detect(model_data, buffer);
if (r>0) {
printf("Detection triggered output %d.\n", r);
}
//Destroy model
model->destroy(model_data)
*/
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/speech_command_recognition/include/esp_mn_models.h
|
C
|
apache-2.0
| 1,854
|
#pragma once
#include "esp_mn_iface.h"
#define SPEECH_COMMANDS_NUM CONFIG_SPEECH_COMMANDS_NUM
#if CONFIG_SR_CHINESE
#define MN_SPEECH_COMMAND_ID0 CONFIG_CN_SPEECH_COMMAND_ID0
#define MN_SPEECH_COMMAND_ID1 CONFIG_CN_SPEECH_COMMAND_ID1
#define MN_SPEECH_COMMAND_ID2 CONFIG_CN_SPEECH_COMMAND_ID2
#define MN_SPEECH_COMMAND_ID3 CONFIG_CN_SPEECH_COMMAND_ID3
#define MN_SPEECH_COMMAND_ID4 CONFIG_CN_SPEECH_COMMAND_ID4
#define MN_SPEECH_COMMAND_ID5 CONFIG_CN_SPEECH_COMMAND_ID5
#define MN_SPEECH_COMMAND_ID6 CONFIG_CN_SPEECH_COMMAND_ID6
#define MN_SPEECH_COMMAND_ID7 CONFIG_CN_SPEECH_COMMAND_ID7
#define MN_SPEECH_COMMAND_ID8 CONFIG_CN_SPEECH_COMMAND_ID8
#define MN_SPEECH_COMMAND_ID9 CONFIG_CN_SPEECH_COMMAND_ID9
#define MN_SPEECH_COMMAND_ID10 CONFIG_CN_SPEECH_COMMAND_ID10
#define MN_SPEECH_COMMAND_ID11 CONFIG_CN_SPEECH_COMMAND_ID11
#define MN_SPEECH_COMMAND_ID12 CONFIG_CN_SPEECH_COMMAND_ID12
#define MN_SPEECH_COMMAND_ID13 CONFIG_CN_SPEECH_COMMAND_ID13
#define MN_SPEECH_COMMAND_ID14 CONFIG_CN_SPEECH_COMMAND_ID14
#define MN_SPEECH_COMMAND_ID15 CONFIG_CN_SPEECH_COMMAND_ID15
#define MN_SPEECH_COMMAND_ID16 CONFIG_CN_SPEECH_COMMAND_ID16
#define MN_SPEECH_COMMAND_ID17 CONFIG_CN_SPEECH_COMMAND_ID17
#define MN_SPEECH_COMMAND_ID18 CONFIG_CN_SPEECH_COMMAND_ID18
#define MN_SPEECH_COMMAND_ID19 CONFIG_CN_SPEECH_COMMAND_ID19
#define MN_SPEECH_COMMAND_ID20 CONFIG_CN_SPEECH_COMMAND_ID20
#define MN_SPEECH_COMMAND_ID21 CONFIG_CN_SPEECH_COMMAND_ID21
#define MN_SPEECH_COMMAND_ID22 CONFIG_CN_SPEECH_COMMAND_ID22
#define MN_SPEECH_COMMAND_ID23 CONFIG_CN_SPEECH_COMMAND_ID23
#define MN_SPEECH_COMMAND_ID24 CONFIG_CN_SPEECH_COMMAND_ID24
#define MN_SPEECH_COMMAND_ID25 CONFIG_CN_SPEECH_COMMAND_ID25
#define MN_SPEECH_COMMAND_ID26 CONFIG_CN_SPEECH_COMMAND_ID26
#define MN_SPEECH_COMMAND_ID27 CONFIG_CN_SPEECH_COMMAND_ID27
#define MN_SPEECH_COMMAND_ID28 CONFIG_CN_SPEECH_COMMAND_ID28
#define MN_SPEECH_COMMAND_ID29 CONFIG_CN_SPEECH_COMMAND_ID29
#define MN_SPEECH_COMMAND_ID30 CONFIG_CN_SPEECH_COMMAND_ID30
#define MN_SPEECH_COMMAND_ID31 CONFIG_CN_SPEECH_COMMAND_ID31
#define MN_SPEECH_COMMAND_ID32 CONFIG_CN_SPEECH_COMMAND_ID32
#define MN_SPEECH_COMMAND_ID33 CONFIG_CN_SPEECH_COMMAND_ID33
#define MN_SPEECH_COMMAND_ID34 CONFIG_CN_SPEECH_COMMAND_ID34
#define MN_SPEECH_COMMAND_ID35 CONFIG_CN_SPEECH_COMMAND_ID35
#define MN_SPEECH_COMMAND_ID36 CONFIG_CN_SPEECH_COMMAND_ID36
#define MN_SPEECH_COMMAND_ID37 CONFIG_CN_SPEECH_COMMAND_ID37
#define MN_SPEECH_COMMAND_ID38 CONFIG_CN_SPEECH_COMMAND_ID38
#define MN_SPEECH_COMMAND_ID39 CONFIG_CN_SPEECH_COMMAND_ID39
#define MN_SPEECH_COMMAND_ID40 CONFIG_CN_SPEECH_COMMAND_ID40
#define MN_SPEECH_COMMAND_ID41 CONFIG_CN_SPEECH_COMMAND_ID41
#define MN_SPEECH_COMMAND_ID42 CONFIG_CN_SPEECH_COMMAND_ID42
#define MN_SPEECH_COMMAND_ID43 CONFIG_CN_SPEECH_COMMAND_ID43
#define MN_SPEECH_COMMAND_ID44 CONFIG_CN_SPEECH_COMMAND_ID44
#define MN_SPEECH_COMMAND_ID45 CONFIG_CN_SPEECH_COMMAND_ID45
#define MN_SPEECH_COMMAND_ID46 CONFIG_CN_SPEECH_COMMAND_ID46
#define MN_SPEECH_COMMAND_ID47 CONFIG_CN_SPEECH_COMMAND_ID47
#define MN_SPEECH_COMMAND_ID48 CONFIG_CN_SPEECH_COMMAND_ID48
#define MN_SPEECH_COMMAND_ID49 CONFIG_CN_SPEECH_COMMAND_ID49
#define MN_SPEECH_COMMAND_ID50 CONFIG_CN_SPEECH_COMMAND_ID50
#define MN_SPEECH_COMMAND_ID51 CONFIG_CN_SPEECH_COMMAND_ID51
#define MN_SPEECH_COMMAND_ID52 CONFIG_CN_SPEECH_COMMAND_ID52
#define MN_SPEECH_COMMAND_ID53 CONFIG_CN_SPEECH_COMMAND_ID53
#define MN_SPEECH_COMMAND_ID54 CONFIG_CN_SPEECH_COMMAND_ID54
#define MN_SPEECH_COMMAND_ID55 CONFIG_CN_SPEECH_COMMAND_ID55
#define MN_SPEECH_COMMAND_ID56 CONFIG_CN_SPEECH_COMMAND_ID56
#define MN_SPEECH_COMMAND_ID57 CONFIG_CN_SPEECH_COMMAND_ID57
#define MN_SPEECH_COMMAND_ID58 CONFIG_CN_SPEECH_COMMAND_ID58
#define MN_SPEECH_COMMAND_ID59 CONFIG_CN_SPEECH_COMMAND_ID59
#define MN_SPEECH_COMMAND_ID60 CONFIG_CN_SPEECH_COMMAND_ID60
#define MN_SPEECH_COMMAND_ID61 CONFIG_CN_SPEECH_COMMAND_ID61
#define MN_SPEECH_COMMAND_ID62 CONFIG_CN_SPEECH_COMMAND_ID62
#define MN_SPEECH_COMMAND_ID63 CONFIG_CN_SPEECH_COMMAND_ID63
#define MN_SPEECH_COMMAND_ID64 CONFIG_CN_SPEECH_COMMAND_ID64
#define MN_SPEECH_COMMAND_ID65 CONFIG_CN_SPEECH_COMMAND_ID65
#define MN_SPEECH_COMMAND_ID66 CONFIG_CN_SPEECH_COMMAND_ID66
#define MN_SPEECH_COMMAND_ID67 CONFIG_CN_SPEECH_COMMAND_ID67
#define MN_SPEECH_COMMAND_ID68 CONFIG_CN_SPEECH_COMMAND_ID68
#define MN_SPEECH_COMMAND_ID69 CONFIG_CN_SPEECH_COMMAND_ID69
#define MN_SPEECH_COMMAND_ID70 CONFIG_CN_SPEECH_COMMAND_ID70
#define MN_SPEECH_COMMAND_ID71 CONFIG_CN_SPEECH_COMMAND_ID71
#define MN_SPEECH_COMMAND_ID72 CONFIG_CN_SPEECH_COMMAND_ID72
#define MN_SPEECH_COMMAND_ID73 CONFIG_CN_SPEECH_COMMAND_ID73
#define MN_SPEECH_COMMAND_ID74 CONFIG_CN_SPEECH_COMMAND_ID74
#define MN_SPEECH_COMMAND_ID75 CONFIG_CN_SPEECH_COMMAND_ID75
#define MN_SPEECH_COMMAND_ID76 CONFIG_CN_SPEECH_COMMAND_ID76
#define MN_SPEECH_COMMAND_ID77 CONFIG_CN_SPEECH_COMMAND_ID77
#define MN_SPEECH_COMMAND_ID78 CONFIG_CN_SPEECH_COMMAND_ID78
#define MN_SPEECH_COMMAND_ID79 CONFIG_CN_SPEECH_COMMAND_ID79
#define MN_SPEECH_COMMAND_ID80 CONFIG_CN_SPEECH_COMMAND_ID80
#define MN_SPEECH_COMMAND_ID81 CONFIG_CN_SPEECH_COMMAND_ID81
#define MN_SPEECH_COMMAND_ID82 CONFIG_CN_SPEECH_COMMAND_ID82
#define MN_SPEECH_COMMAND_ID83 CONFIG_CN_SPEECH_COMMAND_ID83
#define MN_SPEECH_COMMAND_ID84 CONFIG_CN_SPEECH_COMMAND_ID84
#define MN_SPEECH_COMMAND_ID85 CONFIG_CN_SPEECH_COMMAND_ID85
#define MN_SPEECH_COMMAND_ID86 CONFIG_CN_SPEECH_COMMAND_ID86
#define MN_SPEECH_COMMAND_ID87 CONFIG_CN_SPEECH_COMMAND_ID87
#define MN_SPEECH_COMMAND_ID88 CONFIG_CN_SPEECH_COMMAND_ID88
#define MN_SPEECH_COMMAND_ID89 CONFIG_CN_SPEECH_COMMAND_ID89
#define MN_SPEECH_COMMAND_ID90 CONFIG_CN_SPEECH_COMMAND_ID90
#define MN_SPEECH_COMMAND_ID91 CONFIG_CN_SPEECH_COMMAND_ID91
#define MN_SPEECH_COMMAND_ID92 CONFIG_CN_SPEECH_COMMAND_ID92
#define MN_SPEECH_COMMAND_ID93 CONFIG_CN_SPEECH_COMMAND_ID93
#define MN_SPEECH_COMMAND_ID94 CONFIG_CN_SPEECH_COMMAND_ID94
#define MN_SPEECH_COMMAND_ID95 CONFIG_CN_SPEECH_COMMAND_ID95
#define MN_SPEECH_COMMAND_ID96 CONFIG_CN_SPEECH_COMMAND_ID96
#define MN_SPEECH_COMMAND_ID97 CONFIG_CN_SPEECH_COMMAND_ID97
#define MN_SPEECH_COMMAND_ID98 CONFIG_CN_SPEECH_COMMAND_ID98
#define MN_SPEECH_COMMAND_ID99 CONFIG_CN_SPEECH_COMMAND_ID99
#elif CONFIG_SR_ENGLISH
#define MN_SPEECH_COMMAND_ID0 CONFIG_EN_SPEECH_COMMAND_ID0
#define MN_SPEECH_COMMAND_ID1 CONFIG_EN_SPEECH_COMMAND_ID1
#define MN_SPEECH_COMMAND_ID2 CONFIG_EN_SPEECH_COMMAND_ID2
#define MN_SPEECH_COMMAND_ID3 CONFIG_EN_SPEECH_COMMAND_ID3
#define MN_SPEECH_COMMAND_ID4 CONFIG_EN_SPEECH_COMMAND_ID4
#define MN_SPEECH_COMMAND_ID5 CONFIG_EN_SPEECH_COMMAND_ID5
#define MN_SPEECH_COMMAND_ID6 CONFIG_EN_SPEECH_COMMAND_ID6
#define MN_SPEECH_COMMAND_ID7 CONFIG_EN_SPEECH_COMMAND_ID7
#define MN_SPEECH_COMMAND_ID8 CONFIG_EN_SPEECH_COMMAND_ID8
#define MN_SPEECH_COMMAND_ID9 CONFIG_EN_SPEECH_COMMAND_ID9
#define MN_SPEECH_COMMAND_ID10 CONFIG_EN_SPEECH_COMMAND_ID10
#define MN_SPEECH_COMMAND_ID11 CONFIG_EN_SPEECH_COMMAND_ID11
#define MN_SPEECH_COMMAND_ID12 CONFIG_EN_SPEECH_COMMAND_ID12
#define MN_SPEECH_COMMAND_ID13 CONFIG_EN_SPEECH_COMMAND_ID13
#define MN_SPEECH_COMMAND_ID14 CONFIG_EN_SPEECH_COMMAND_ID14
#define MN_SPEECH_COMMAND_ID15 CONFIG_EN_SPEECH_COMMAND_ID15
#define MN_SPEECH_COMMAND_ID16 CONFIG_EN_SPEECH_COMMAND_ID16
#define MN_SPEECH_COMMAND_ID17 CONFIG_EN_SPEECH_COMMAND_ID17
#define MN_SPEECH_COMMAND_ID18 CONFIG_EN_SPEECH_COMMAND_ID18
#define MN_SPEECH_COMMAND_ID19 CONFIG_EN_SPEECH_COMMAND_ID19
#define MN_SPEECH_COMMAND_ID20 CONFIG_EN_SPEECH_COMMAND_ID20
#define MN_SPEECH_COMMAND_ID21 CONFIG_EN_SPEECH_COMMAND_ID21
#define MN_SPEECH_COMMAND_ID22 CONFIG_EN_SPEECH_COMMAND_ID22
#define MN_SPEECH_COMMAND_ID23 CONFIG_EN_SPEECH_COMMAND_ID23
#define MN_SPEECH_COMMAND_ID24 CONFIG_EN_SPEECH_COMMAND_ID24
#define MN_SPEECH_COMMAND_ID25 CONFIG_EN_SPEECH_COMMAND_ID25
#define MN_SPEECH_COMMAND_ID26 CONFIG_EN_SPEECH_COMMAND_ID26
#define MN_SPEECH_COMMAND_ID27 CONFIG_EN_SPEECH_COMMAND_ID27
#define MN_SPEECH_COMMAND_ID28 CONFIG_EN_SPEECH_COMMAND_ID28
#define MN_SPEECH_COMMAND_ID29 CONFIG_EN_SPEECH_COMMAND_ID29
#define MN_SPEECH_COMMAND_ID30 CONFIG_EN_SPEECH_COMMAND_ID30
#define MN_SPEECH_COMMAND_ID31 CONFIG_EN_SPEECH_COMMAND_ID31
#define MN_SPEECH_COMMAND_ID32 CONFIG_EN_SPEECH_COMMAND_ID32
#define MN_SPEECH_COMMAND_ID33 CONFIG_EN_SPEECH_COMMAND_ID33
#define MN_SPEECH_COMMAND_ID34 CONFIG_EN_SPEECH_COMMAND_ID34
#define MN_SPEECH_COMMAND_ID35 CONFIG_EN_SPEECH_COMMAND_ID35
#define MN_SPEECH_COMMAND_ID36 CONFIG_EN_SPEECH_COMMAND_ID36
#define MN_SPEECH_COMMAND_ID37 CONFIG_EN_SPEECH_COMMAND_ID37
#define MN_SPEECH_COMMAND_ID38 CONFIG_EN_SPEECH_COMMAND_ID38
#define MN_SPEECH_COMMAND_ID39 CONFIG_EN_SPEECH_COMMAND_ID39
#define MN_SPEECH_COMMAND_ID40 CONFIG_EN_SPEECH_COMMAND_ID40
#define MN_SPEECH_COMMAND_ID41 CONFIG_EN_SPEECH_COMMAND_ID41
#define MN_SPEECH_COMMAND_ID42 CONFIG_EN_SPEECH_COMMAND_ID42
#define MN_SPEECH_COMMAND_ID43 CONFIG_EN_SPEECH_COMMAND_ID43
#define MN_SPEECH_COMMAND_ID44 CONFIG_EN_SPEECH_COMMAND_ID44
#define MN_SPEECH_COMMAND_ID45 CONFIG_EN_SPEECH_COMMAND_ID45
#define MN_SPEECH_COMMAND_ID46 CONFIG_EN_SPEECH_COMMAND_ID46
#define MN_SPEECH_COMMAND_ID47 CONFIG_EN_SPEECH_COMMAND_ID47
#define MN_SPEECH_COMMAND_ID48 CONFIG_EN_SPEECH_COMMAND_ID48
#define MN_SPEECH_COMMAND_ID49 CONFIG_EN_SPEECH_COMMAND_ID49
#define MN_SPEECH_COMMAND_ID50 CONFIG_EN_SPEECH_COMMAND_ID50
#define MN_SPEECH_COMMAND_ID51 CONFIG_EN_SPEECH_COMMAND_ID51
#define MN_SPEECH_COMMAND_ID52 CONFIG_EN_SPEECH_COMMAND_ID52
#define MN_SPEECH_COMMAND_ID53 CONFIG_EN_SPEECH_COMMAND_ID53
#define MN_SPEECH_COMMAND_ID54 CONFIG_EN_SPEECH_COMMAND_ID54
#define MN_SPEECH_COMMAND_ID55 CONFIG_EN_SPEECH_COMMAND_ID55
#define MN_SPEECH_COMMAND_ID56 CONFIG_EN_SPEECH_COMMAND_ID56
#define MN_SPEECH_COMMAND_ID57 CONFIG_EN_SPEECH_COMMAND_ID57
#define MN_SPEECH_COMMAND_ID58 CONFIG_EN_SPEECH_COMMAND_ID58
#define MN_SPEECH_COMMAND_ID59 CONFIG_EN_SPEECH_COMMAND_ID59
#define MN_SPEECH_COMMAND_ID60 CONFIG_EN_SPEECH_COMMAND_ID60
#define MN_SPEECH_COMMAND_ID61 CONFIG_EN_SPEECH_COMMAND_ID61
#define MN_SPEECH_COMMAND_ID62 CONFIG_EN_SPEECH_COMMAND_ID62
#define MN_SPEECH_COMMAND_ID63 CONFIG_EN_SPEECH_COMMAND_ID63
#define MN_SPEECH_COMMAND_ID64 CONFIG_EN_SPEECH_COMMAND_ID64
#define MN_SPEECH_COMMAND_ID65 CONFIG_EN_SPEECH_COMMAND_ID65
#define MN_SPEECH_COMMAND_ID66 CONFIG_EN_SPEECH_COMMAND_ID66
#define MN_SPEECH_COMMAND_ID67 CONFIG_EN_SPEECH_COMMAND_ID67
#define MN_SPEECH_COMMAND_ID68 CONFIG_EN_SPEECH_COMMAND_ID68
#define MN_SPEECH_COMMAND_ID69 CONFIG_EN_SPEECH_COMMAND_ID69
#define MN_SPEECH_COMMAND_ID70 CONFIG_EN_SPEECH_COMMAND_ID70
#define MN_SPEECH_COMMAND_ID71 CONFIG_EN_SPEECH_COMMAND_ID71
#define MN_SPEECH_COMMAND_ID72 CONFIG_EN_SPEECH_COMMAND_ID72
#define MN_SPEECH_COMMAND_ID73 CONFIG_EN_SPEECH_COMMAND_ID73
#define MN_SPEECH_COMMAND_ID74 CONFIG_EN_SPEECH_COMMAND_ID74
#define MN_SPEECH_COMMAND_ID75 CONFIG_EN_SPEECH_COMMAND_ID75
#define MN_SPEECH_COMMAND_ID76 CONFIG_EN_SPEECH_COMMAND_ID76
#define MN_SPEECH_COMMAND_ID77 CONFIG_EN_SPEECH_COMMAND_ID77
#define MN_SPEECH_COMMAND_ID78 CONFIG_EN_SPEECH_COMMAND_ID78
#define MN_SPEECH_COMMAND_ID79 CONFIG_EN_SPEECH_COMMAND_ID79
#define MN_SPEECH_COMMAND_ID80 CONFIG_EN_SPEECH_COMMAND_ID80
#define MN_SPEECH_COMMAND_ID81 CONFIG_EN_SPEECH_COMMAND_ID81
#define MN_SPEECH_COMMAND_ID82 CONFIG_EN_SPEECH_COMMAND_ID82
#define MN_SPEECH_COMMAND_ID83 CONFIG_EN_SPEECH_COMMAND_ID83
#define MN_SPEECH_COMMAND_ID84 CONFIG_EN_SPEECH_COMMAND_ID84
#define MN_SPEECH_COMMAND_ID85 CONFIG_EN_SPEECH_COMMAND_ID85
#define MN_SPEECH_COMMAND_ID86 CONFIG_EN_SPEECH_COMMAND_ID86
#define MN_SPEECH_COMMAND_ID87 CONFIG_EN_SPEECH_COMMAND_ID87
#define MN_SPEECH_COMMAND_ID88 CONFIG_EN_SPEECH_COMMAND_ID88
#define MN_SPEECH_COMMAND_ID89 CONFIG_EN_SPEECH_COMMAND_ID89
#define MN_SPEECH_COMMAND_ID90 CONFIG_EN_SPEECH_COMMAND_ID90
#define MN_SPEECH_COMMAND_ID91 CONFIG_EN_SPEECH_COMMAND_ID91
#define MN_SPEECH_COMMAND_ID92 CONFIG_EN_SPEECH_COMMAND_ID92
#define MN_SPEECH_COMMAND_ID93 CONFIG_EN_SPEECH_COMMAND_ID93
#define MN_SPEECH_COMMAND_ID94 CONFIG_EN_SPEECH_COMMAND_ID94
#define MN_SPEECH_COMMAND_ID95 CONFIG_EN_SPEECH_COMMAND_ID95
#define MN_SPEECH_COMMAND_ID96 CONFIG_EN_SPEECH_COMMAND_ID96
#define MN_SPEECH_COMMAND_ID97 CONFIG_EN_SPEECH_COMMAND_ID97
#define MN_SPEECH_COMMAND_ID98 CONFIG_EN_SPEECH_COMMAND_ID98
#define MN_SPEECH_COMMAND_ID99 CONFIG_EN_SPEECH_COMMAND_ID99
#endif
char *get_id_name(int i);
void reset_speech_commands(model_iface_data_t *model_data, char* command_str, char *err_phrase_id);
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/speech_command_recognition/include/mn_process_commands.h
|
C
|
apache-2.0
| 12,832
|
#pragma once
#define SR_FLASH_TYPE 32
#define SR_FLASH_SUBTYPE 32
#define SR_FLASH_PARTITION_NAME "fr"
#define SR_FLASH_INFO_FLAG 12138
int8_t speech_command_flash_init(void);
int8_t enroll_speech_command_to_flash_with_id(char *phrase, int mn_command_id);
int get_use_flag_from_flash();
int get_enroll_num_from_flash();
char *read_speech_command_from_flash(int i);
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/speech_command_recognition/include/sr_flash.h
|
C
|
apache-2.0
| 370
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
#include "mn_process_commands.h"
char *get_id_name(int i)
{
if (i == 0)
return MN_SPEECH_COMMAND_ID0;
else if (i == 1)
return MN_SPEECH_COMMAND_ID1;
else if (i == 2)
return MN_SPEECH_COMMAND_ID2;
else if (i == 3)
return MN_SPEECH_COMMAND_ID3;
else if (i == 4)
return MN_SPEECH_COMMAND_ID4;
else if (i == 5)
return MN_SPEECH_COMMAND_ID5;
else if (i == 6)
return MN_SPEECH_COMMAND_ID6;
else if (i == 7)
return MN_SPEECH_COMMAND_ID7;
else if (i == 8)
return MN_SPEECH_COMMAND_ID8;
else if (i == 9)
return MN_SPEECH_COMMAND_ID9;
else if (i == 10)
return MN_SPEECH_COMMAND_ID10;
else if (i == 11)
return MN_SPEECH_COMMAND_ID11;
else if (i == 12)
return MN_SPEECH_COMMAND_ID12;
else if (i == 13)
return MN_SPEECH_COMMAND_ID13;
else if (i == 14)
return MN_SPEECH_COMMAND_ID14;
else if (i == 15)
return MN_SPEECH_COMMAND_ID15;
else if (i == 16)
return MN_SPEECH_COMMAND_ID16;
else if (i == 17)
return MN_SPEECH_COMMAND_ID17;
else if (i == 18)
return MN_SPEECH_COMMAND_ID18;
else if (i == 19)
return MN_SPEECH_COMMAND_ID19;
else if (i == 20)
return MN_SPEECH_COMMAND_ID20;
else if (i == 21)
return MN_SPEECH_COMMAND_ID21;
else if (i == 22)
return MN_SPEECH_COMMAND_ID22;
else if (i == 23)
return MN_SPEECH_COMMAND_ID23;
else if (i == 24)
return MN_SPEECH_COMMAND_ID24;
else if (i == 25)
return MN_SPEECH_COMMAND_ID25;
else if (i == 26)
return MN_SPEECH_COMMAND_ID26;
else if (i == 27)
return MN_SPEECH_COMMAND_ID27;
else if (i == 28)
return MN_SPEECH_COMMAND_ID28;
else if (i == 29)
return MN_SPEECH_COMMAND_ID29;
else if (i == 30)
return MN_SPEECH_COMMAND_ID30;
else if (i == 31)
return MN_SPEECH_COMMAND_ID31;
else if (i == 32)
return MN_SPEECH_COMMAND_ID32;
else if (i == 33)
return MN_SPEECH_COMMAND_ID33;
else if (i == 34)
return MN_SPEECH_COMMAND_ID34;
else if (i == 35)
return MN_SPEECH_COMMAND_ID35;
else if (i == 36)
return MN_SPEECH_COMMAND_ID36;
else if (i == 37)
return MN_SPEECH_COMMAND_ID37;
else if (i == 38)
return MN_SPEECH_COMMAND_ID38;
else if (i == 39)
return MN_SPEECH_COMMAND_ID39;
else if (i == 40)
return MN_SPEECH_COMMAND_ID40;
else if (i == 41)
return MN_SPEECH_COMMAND_ID41;
else if (i == 42)
return MN_SPEECH_COMMAND_ID42;
else if (i == 43)
return MN_SPEECH_COMMAND_ID43;
else if (i == 44)
return MN_SPEECH_COMMAND_ID44;
else if (i == 45)
return MN_SPEECH_COMMAND_ID45;
else if (i == 46)
return MN_SPEECH_COMMAND_ID46;
else if (i == 47)
return MN_SPEECH_COMMAND_ID47;
else if (i == 48)
return MN_SPEECH_COMMAND_ID48;
else if (i == 49)
return MN_SPEECH_COMMAND_ID49;
else if (i == 50)
return MN_SPEECH_COMMAND_ID50;
else if (i == 51)
return MN_SPEECH_COMMAND_ID51;
else if (i == 52)
return MN_SPEECH_COMMAND_ID52;
else if (i == 53)
return MN_SPEECH_COMMAND_ID53;
else if (i == 54)
return MN_SPEECH_COMMAND_ID54;
else if (i == 55)
return MN_SPEECH_COMMAND_ID55;
else if (i == 56)
return MN_SPEECH_COMMAND_ID56;
else if (i == 57)
return MN_SPEECH_COMMAND_ID57;
else if (i == 58)
return MN_SPEECH_COMMAND_ID58;
else if (i == 59)
return MN_SPEECH_COMMAND_ID59;
else if (i == 60)
return MN_SPEECH_COMMAND_ID60;
else if (i == 61)
return MN_SPEECH_COMMAND_ID61;
else if (i == 62)
return MN_SPEECH_COMMAND_ID62;
else if (i == 63)
return MN_SPEECH_COMMAND_ID63;
else if (i == 64)
return MN_SPEECH_COMMAND_ID64;
else if (i == 65)
return MN_SPEECH_COMMAND_ID65;
else if (i == 66)
return MN_SPEECH_COMMAND_ID66;
else if (i == 67)
return MN_SPEECH_COMMAND_ID67;
else if (i == 68)
return MN_SPEECH_COMMAND_ID68;
else if (i == 69)
return MN_SPEECH_COMMAND_ID69;
else if (i == 70)
return MN_SPEECH_COMMAND_ID70;
else if (i == 71)
return MN_SPEECH_COMMAND_ID71;
else if (i == 72)
return MN_SPEECH_COMMAND_ID72;
else if (i == 73)
return MN_SPEECH_COMMAND_ID73;
else if (i == 74)
return MN_SPEECH_COMMAND_ID74;
else if (i == 75)
return MN_SPEECH_COMMAND_ID75;
else if (i == 76)
return MN_SPEECH_COMMAND_ID76;
else if (i == 77)
return MN_SPEECH_COMMAND_ID77;
else if (i == 78)
return MN_SPEECH_COMMAND_ID78;
else if (i == 79)
return MN_SPEECH_COMMAND_ID79;
else if (i == 80)
return MN_SPEECH_COMMAND_ID80;
else if (i == 81)
return MN_SPEECH_COMMAND_ID81;
else if (i == 82)
return MN_SPEECH_COMMAND_ID82;
else if (i == 83)
return MN_SPEECH_COMMAND_ID83;
else if (i == 84)
return MN_SPEECH_COMMAND_ID84;
else if (i == 85)
return MN_SPEECH_COMMAND_ID85;
else if (i == 86)
return MN_SPEECH_COMMAND_ID86;
else if (i == 87)
return MN_SPEECH_COMMAND_ID87;
else if (i == 88)
return MN_SPEECH_COMMAND_ID88;
else if (i == 89)
return MN_SPEECH_COMMAND_ID89;
else if (i == 90)
return MN_SPEECH_COMMAND_ID90;
else if (i == 91)
return MN_SPEECH_COMMAND_ID91;
else if (i == 92)
return MN_SPEECH_COMMAND_ID92;
else if (i == 93)
return MN_SPEECH_COMMAND_ID93;
else if (i == 94)
return MN_SPEECH_COMMAND_ID94;
else if (i == 95)
return MN_SPEECH_COMMAND_ID95;
else if (i == 96)
return MN_SPEECH_COMMAND_ID96;
else if (i == 97)
return MN_SPEECH_COMMAND_ID97;
else if (i == 98)
return MN_SPEECH_COMMAND_ID98;
else if (i == 99)
return MN_SPEECH_COMMAND_ID99;
else
return NULL;
}
void reset_speech_commands_v1(model_iface_data_t *model_data, char* command_str, char *err_phrase_id);
void reset_speech_commands_v2(model_iface_data_t *model_data, char* command_str, char *err_phrase_id);
void reset_speech_commands(model_iface_data_t *model_data, char* command_str, char *err_phrase_id)
{
#if CONFIG_SINGLE_RECOGNITION
reset_speech_commands_v1(model_data, command_str, err_phrase_id);
#elif CONFIG_SR_CHINESE && CONFIG_CONTINUOUS_RECOGNITION
reset_speech_commands_v2(model_data, command_str, err_phrase_id);
#endif
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/speech_command_recognition/mn_process_commands.c
|
C
|
apache-2.0
| 6,794
|
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := .
LIB_FILES := $(shell ls $(COMPONENT_PATH)/lib*.a)
LIBS := $(patsubst lib%.a,-l%,$(notdir $(LIB_FILES)))
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/ $(LIBS)
ALL_LIB_FILES += $(LIB_FILES)
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/wake_word_engine/component.mk
|
Makefile
|
apache-2.0
| 254
|
#pragma once
#include "stdint.h"
#include "dl_lib_coefgetter_if.h"
//Opaque model data container
typedef struct model_iface_data_t model_iface_data_t;
//Set wake words recognition operating mode
//The probability of being wake words is increased with increasing mode,
//As a consequence also the false alarm rate goes up
typedef enum {
DET_MODE_90 = 0, //Normal, response accuracy rate about 90%
DET_MODE_95 //Aggressive, response accuracy rate about 95%
} det_mode_t;
typedef struct {
int wake_word_num; //The number of all wake words
char **wake_word_list; //The name list of wake words
} wake_word_info_t;
/**
* @brief Easy function type to initialze a model instance with a detection mode and specified wake word coefficient
*
* @param det_mode The wake words detection mode to trigger wake words, DET_MODE_90 or DET_MODE_95
* @param model_coeff The specified wake word model coefficient
* @returns Handle to the model data
*/
typedef model_iface_data_t* (*esp_wn_iface_op_create_t)(const model_coeff_getter_t *model_coeff, det_mode_t det_mode);
/**
* @brief Function type to initialze a model instance with a detection mode and specified wake word coefficient
*
* Warning: Just wakeNet6 support this function to select which core to run neural network.
*
* @param det_mode The wake words detection mode to trigger wake words, DET_MODE_90 or DET_MODE_95
* @param model_coeff The specified wake word model coefficient
* @param core Core to run neural network
* @returns Handle to the model data
*/
typedef model_iface_data_t* (*esp_wn_iface_op_create_pinned_to_core_t)(const model_coeff_getter_t *model_coeff, det_mode_t det_mode, int core);
/**
* @brief Callback function type to fetch the amount of samples that need to be passed to the detect function
*
* Every speech recognition model processes a certain number of samples at the same time. This function
* can be used to query that amount. Note that the returned amount is in 16-bit samples, not in bytes.
*
* @param model The model object to query
* @return The amount of samples to feed the detect function
*/
typedef int (*esp_wn_iface_op_get_samp_chunksize_t)(model_iface_data_t *model);
/**
* @brief Get the sample rate of the samples to feed to the detect function
*
* @param model The model object to query
* @return The sample rate, in hz
*/
typedef int (*esp_wn_iface_op_get_samp_rate_t)(model_iface_data_t *model);
/**
* @brief Get the number of wake words
*
* @param model The model object to query
* @returns the number of wake words
*/
typedef int (*esp_wn_iface_op_get_word_num_t)(model_iface_data_t *model);
/**
* @brief Get the name of wake word by index
*
* @Warning The index of wake word start with 1
* @param model The model object to query
* @param word_index The index of wake word
* @returns the detection threshold
*/
typedef char* (*esp_wn_iface_op_get_word_name_t)(model_iface_data_t *model, int word_index);
/**
* @brief Set the detection threshold to manually abjust the probability
*
* @param model The model object to query
* @param det_treshold The threshold to trigger wake words, the range of det_threshold is 0.5~0.9999
* @param word_index The index of wake word
* @return 0: setting failed, 1: setting success
*/
typedef int (*esp_wn_iface_op_set_det_threshold_t)(model_iface_data_t *model, float det_threshold, int word_index);
/**
* @brief Get the wake word detection threshold of different modes
*
* @param model The model object to query
* @param word_index The index of wake word
* @returns the detection threshold
*/
typedef float (*esp_wn_iface_op_get_det_threshold_t)(model_iface_data_t *model, int word_index);
/**
* @brief Feed samples of an audio stream to the keyword detection model and detect if there is a keyword found.
*
* @Warning The index of wake word start with 1, 0 means no wake words is detected.
*
* @param model The model object to query
* @param samples An array of 16-bit signed audio samples. The array size used can be queried by the
* get_samp_chunksize function.
* @return The index of wake words, return 0 if no wake word is detected, else the index of the wake words.
*/
typedef int (*esp_wn_iface_op_detect_t)(model_iface_data_t *model, int16_t *samples);
/**
* @brief Destroy a speech recognition model
*
* @param model Model object to destroy
*/
typedef void (*esp_wn_iface_op_destroy_t)(model_iface_data_t *model);
/**
* This structure contains the functions used to do operations on a wake word detection model.
*/
typedef struct {
esp_wn_iface_op_create_t create;
esp_wn_iface_op_create_pinned_to_core_t create_pinned_to_core;
esp_wn_iface_op_get_samp_chunksize_t get_samp_chunksize;
esp_wn_iface_op_get_samp_rate_t get_samp_rate;
esp_wn_iface_op_get_word_num_t get_word_num;
esp_wn_iface_op_get_word_name_t get_word_name;
esp_wn_iface_op_set_det_threshold_t set_det_threshold;
esp_wn_iface_op_get_det_threshold_t get_det_threshold;
esp_wn_iface_op_detect_t detect;
esp_wn_iface_op_destroy_t destroy;
} esp_wn_iface_t;
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/wake_word_engine/include/esp_wn_iface.h
|
C
|
apache-2.0
| 5,126
|
#pragma once
#include "esp_wn_iface.h"
//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.
extern const esp_wn_iface_t esp_sr_wakenet3_quantized;
extern const esp_wn_iface_t esp_sr_wakenet4_quantized;
extern const esp_wn_iface_t esp_sr_wakenet5_quantized;
extern const esp_wn_iface_t esp_sr_wakenet5_float;
extern const esp_wn_iface_t esp_sr_wakenet6_quantized;
/*
Configure network to use based on what's selected in menuconfig.
*/
#if CONFIG_SR_MODEL_WN3_QUANT
#define WAKENET_MODEL esp_sr_wakenet3_quantized
#elif CONFIG_SR_MODEL_WN4_QUANT
#define WAKENET_MODEL esp_sr_wakenet4_quantized
#elif CONFIG_SR_MODEL_WN5_FLOAT
#define WAKENET_MODEL esp_sr_wakenet5_float
#elif CONFIG_SR_MODEL_WN5_QUANT
#define WAKENET_MODEL esp_sr_wakenet5_quantized
#elif CONFIG_SR_MODEL_WN6_QUANT
#define WAKENET_MODEL esp_sr_wakenet6_quantized
#else
#error No valid neural network model selected.
#endif
/*
Configure wake word to use based on what's selected in menuconfig.
*/
#if CONFIG_SR_WN3_HILEXIN
#include "hilexin_wn3.h"
#define WAKENET_COEFF get_coeff_hilexin_wn3
#elif CONFIG_SR_WN4_HILEXIN
#include "hilexin_wn4.h"
#define WAKENET_COEFF get_coeff_hilexin_wn4
#elif CONFIG_SR_WN5_HILEXIN & CONFIG_SR_MODEL_WN5_FLOAT
#include "hilexin_wn5_float.h"
#define WAKENET_COEFF get_coeff_hilexin_wn5_float
#elif CONFIG_SR_WN5_HILEXIN & CONFIG_SR_MODEL_WN5_QUANT
#include "hilexin_wn5.h"
#define WAKENET_COEFF get_coeff_hilexin_wn5
#elif CONFIG_SR_WN5X2_HILEXIN & CONFIG_SR_MODEL_WN5_QUANT
#include "hilexin_wn5X2.h"
#define WAKENET_COEFF get_coeff_hilexin_wn5X2
#elif CONFIG_SR_WN5X3_HILEXIN & CONFIG_SR_MODEL_WN5_QUANT
#include "hilexin_wn5X3.h"
#define WAKENET_COEFF get_coeff_hilexin_wn5X3
#elif CONFIG_SR_WN5_NIHAOXIAOZHI & CONFIG_SR_MODEL_WN5_QUANT
#include "nihaoxiaozhi_wn5.h"
#define WAKENET_COEFF get_coeff_nihaoxiaozhi_wn5
#elif CONFIG_SR_WN5X2_NIHAOXIAOZHI & CONFIG_SR_MODEL_WN5_QUANT
#include "nihaoxiaozhi_wn5X2.h"
#define WAKENET_COEFF get_coeff_nihaoxiaozhi_wn5X2
#elif CONFIG_SR_WN5X3_NIHAOXIAOZHI & CONFIG_SR_MODEL_WN5_QUANT
#include "nihaoxiaozhi_wn5X3.h"
#define WAKENET_COEFF get_coeff_nihaoxiaozhi_wn5X3
#elif CONFIG_SR_WN5X3_NIHAOXIAOXIN & CONFIG_SR_MODEL_WN5_QUANT
#include "nihaoxiaoxin_wn5X3.h"
#define WAKENET_COEFF get_coeff_nihaoxiaoxin_wn5X3
#elif CONFIG_SR_WN5X3_HIJESON & CONFIG_SR_MODEL_WN5_QUANT
#include "hijeson_wn5X3.h"
#define WAKENET_COEFF get_coeff_hijeson_wn5X3
#elif CONFIG_SR_WN6_NIHAOXIAOXIN
#include "nihaoxiaoxin_wn6.h"
#define WAKENET_COEFF get_coeff_nihaoxiaoxin_wn6
#elif CONFIG_SR_WN5_CUSTOMIZED_WORD
#include "customized_word_wn5.h"
#define WAKENET_COEFF get_coeff_customized_word_wn5
#elif CONFIG_SR_WN6_CUSTOMIZED_WORD
#include "customized_word_wn6.h"
#define WAKENET_COEFF get_coeff_customized_word_wn6
#else
#error No valid wake word selected.
#endif
/* example
static const sr_model_iface_t *model = &WAKENET_MODEL;
//Initialize wakeNet model data
static model_iface_data_t *model_data=model->create(DET_MODE_90);
//Set parameters of buffer
int audio_chunksize=model->get_samp_chunksize(model_data);
int frequency = model->get_samp_rate(model_data);
int16_t *buffer=malloc(audio_chunksize*sizeof(int16_t));
//Detect
int r=model->detect(model_data, buffer);
if (r>0) {
printf("Detection triggered output %d.\n", r);
}
//Destroy model
model->destroy(model_data)
*/
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp-sr/wake_word_engine/include/esp_wn_models.h
|
C
|
apache-2.0
| 3,459
|
set(COMPONENT_ADD_INCLUDEDIRS include)
# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES audio_sal nvs_flash spi_flash)
set(COMPONENT_PRIV_REQUIRES esp_dispatcher wifi_service display_service esp-adf-libs audio_pipeline audio_sal dueros_service)
set(COMPONENT_SRCS ./display_action.c
./dueros_action.c
./player_action.c
./recorder_action.c
./wifi_action.c
./nvs_action.c
./partition_action.c)
register_component()
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/CMakeLists.txt
|
CMake
|
apache-2.0
| 578
|
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := .
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/component.mk
|
Makefile
|
apache-2.0
| 206
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "audio_error.h"
#include "display_action.h"
#include "esp_log.h"
#include "display_service.h"
static const char *TAG = "DIS_ACTION";
esp_err_t display_action_wifi_disconnected(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
display_service_handle_t dis = (display_service_handle_t)instance;
int ret = display_service_set_pattern(dis, DISPLAY_PATTERN_WIFI_DISCONNECTED, 0);
return ret;
}
esp_err_t display_action_wifi_connected(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
display_service_handle_t dis = (display_service_handle_t)instance;
int ret = display_service_set_pattern(dis, DISPLAY_PATTERN_WIFI_CONNECTED, 0);
return ret;
}
esp_err_t display_action_wifi_setting(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
display_service_handle_t dis = (display_service_handle_t)instance;
int ret = display_service_set_pattern(dis, DISPLAY_PATTERN_WIFI_SETTING, 0);
return ret;
}
esp_err_t display_action_turn_off(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
display_service_handle_t dis = (display_service_handle_t)instance;
int ret = display_service_set_pattern(dis, DISPLAY_PATTERN_TURN_OFF, 0);
return ret;
}
esp_err_t display_action_turn_on(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
display_service_handle_t dis = (display_service_handle_t)instance;
int ret = display_service_set_pattern(dis, DISPLAY_PATTERN_TURN_ON, 0);
return ret;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/display_action.c
|
C
|
apache-2.0
| 2,905
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "audio_error.h"
#include "esp_log.h"
#include "dueros_action.h"
#include "dueros_service.h"
static const char *TAG = "DUER_ACTION";
esp_err_t dueros_action_disconnect(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
esp_err_t dueros_action_connect(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
audio_service_handle_t handle = (audio_service_handle_t)instance;
int ret = audio_service_connect(handle);
return ret;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/dueros_action.c
|
C
|
apache-2.0
| 1,795
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __DISPLAY_ACTION_H__
#define __DISPLAY_ACTION_H__
#include "esp_action_def.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* brief Display provides pattern of Wi-Fi disconnection
*
* @param instance The display service instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, errors
*/
esp_err_t display_action_wifi_disconnected(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Display provides pattern of Wi-Fi connection
*
* @param instance The display service instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, errors
*/
esp_err_t display_action_wifi_connected(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Display provides pattern of wifi setting
*
* @param instance The display service instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, errors
*/
esp_err_t display_action_wifi_setting(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Display provides pattern of turn off
*
* @param instance The display service instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, errors
*/
esp_err_t display_action_turn_off(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Display provides pattern of turn on
*
* @param instance The display service instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, errors
*/
esp_err_t display_action_turn_on(void *instance, action_arg_t *arg, action_result_t *result);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/include/display_action.h
|
C
|
apache-2.0
| 3,455
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __DUEROS_SERVICE_ACTION_H__
#define __DUEROS_SERVICE_ACTION_H__
#include "esp_action_def.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* brief Dueros provides service of disconnection
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t dueros_action_disconnect(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief DuerOS provides service of connection
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t dueros_action_connect(void *instance, action_arg_t *arg, action_result_t *result);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/include/dueros_action.h
|
C
|
apache-2.0
| 2,204
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __NVS_ACTION_H__
#define __NVS_ACTION_H__
#include "nvs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief The arguments structure of nvs open action
*/
typedef struct {
const char *name;
nvs_open_mode open_mode;
} nvs_action_open_args_t;
/**
* @brief The arguments structure of nvs open partition action
*/
typedef struct {
const char *partition;
char *name;
nvs_open_mode open_mode;
} nvs_action_open_partition_args_t;
/**
* @brief The arguments structure of nvs write action
*/
typedef struct {
const char *key;
nvs_type_t type;
union {
int8_t i8;
int16_t i16;
int32_t i32;
int64_t i64;
uint8_t u8;
uint16_t u16;
uint32_t u32;
uint64_t u64;
char* string;
void* blob;
} value;
int len;
} nvs_action_set_args_t;
/**
* @brief The arguments structure of nvs read action
*/
typedef struct {
const char *key;
nvs_type_t type;
size_t wanted_size;
} nvs_action_get_args_t;
/**
* @brief NVS Open
*
* @param instance The execution instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_open(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief NVS Open form partition
*
* @param instance The execution instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_open_from_partion(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Write data to NVS
*
* @param instance The NVS instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_set(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Read data from NVS
*
* @param instance The NVS instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_get(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Erase key in NVS
*
* @param instance The NVS instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_erase_key(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Erase all keys in NVS
*
* @param instance The NVS instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_erase_all(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Commit the modification.
*
* @param instance The NVS instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_commit(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Close the NVS handle.
*
* @param instance The NVS instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_close(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Get NVS status
*
* @param instance The NVS instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_get_stats(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Get NVS used entry count
*
* @param instance The NVS instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t nvs_action_get_used_entry_count(void *instance, action_arg_t *arg, action_result_t *result);
#ifdef __cplusplus
}
#endif
#endif /* __NVS_ACTION_H__ */
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/include/nvs_action.h
|
C
|
apache-2.0
| 6,034
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __PARTITION_ACTION__
#define __PARTITION_ACTION__
#include "esp_partition.h"
#include "esp_action_def.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief The arguments structure of partition find first action
*/
typedef struct partition_find_args_s {
esp_partition_type_t type;
esp_partition_subtype_t subtype;
const char *label;
} partition_find_args_t;
/**
* @brief The arguments structure of partition read action
*/
typedef struct partition_read_args_s {
const esp_partition_t *partition;
size_t src_offset;
void *dst;
size_t size;
} partition_read_args_t;
/**
* @brief The arguments structure of partition write action
*/
typedef struct partition_write_args_s {
const esp_partition_t *partition;
size_t dst_offset;
void *src;
size_t size;
} partition_write_args_t;
/**
* @brief Partition find first
*
* @param instance The execution instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t partition_find_action(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Partition read
*
* @param instance The execution instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t partition_read_action(void *instance, action_arg_t *arg, action_result_t *result);
/**
* @brief Partition write
*
* @param instance The execution instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t partition_write_action(void *instance, action_arg_t *arg, action_result_t *result);
#ifdef __cplusplus
}
#endif
#endif /*__PARTITION_ACTION__*/
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/include/partition_action.h
|
C
|
apache-2.0
| 3,267
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _PLAYER_ACTION_H__
#define _PLAYER_ACTION_H__
#include "esp_action_def.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* brief Player provides service of playing music
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t player_action_play(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Player provides service of pausing music playing
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t player_action_pause(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Player provides service of playing the next audio file
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t player_action_next(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Player provides service of playing the previous audio file
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t player_action_prev(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Player provides service of increasing volume
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t player_action_vol_up(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Player provides service of decreasing volume
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t player_action_vol_down(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Player provides service of mute on
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t player_action_mute_on(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Player provides service of mute off
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t player_action_mute_off(void *instance, action_arg_t *arg, action_result_t *result);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/include/player_action.h
|
C
|
apache-2.0
| 4,583
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __RECORDER_ACTION_H__
#define __RECORDER_ACTION_H__
#include "esp_action_def.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* brief Recorder provides service of turn on WAV recoding
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t recorder_action_rec_wav_turn_on(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Recorder provides service of turn off WAV recoding
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t recorder_action_rec_wav_turn_off(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Recorder provides service of turn on AMR recoding
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t recorder_action_rec_amr_turn_on(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Recorder provides service of turn off AMR recoding
*
* @param instance The player instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t recorder_action_rec_amr_turn_off(void *instance, action_arg_t *arg, action_result_t *result);
#ifdef __cplusplus
}
#endif
#endif //
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/include/recorder_action.h
|
C
|
apache-2.0
| 3,066
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __WIFI_ACTION_H__
#define __WIFI_ACTION_H__
#include "esp_action_def.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* brief Wi-Fi provides service of connection
*
* @param instance The Wi-Fi service instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t wifi_action_connect(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Wi-Fi provides service of disconnection
*
*
* @param instance The Wi-Fi service instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t wifi_action_disconnect(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Wi-Fi provides service of start Wi-Fi setting
*
* @param instance The Wi-Fi service instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t wifi_action_setting_start(void *instance, action_arg_t *arg, action_result_t *result);
/**
* brief Wi-Fi provides service of stop Wi-Fi setting
*
* @param instance The Wi-Fi service instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK, success
* - Others, error
*/
esp_err_t wifi_action_setting_stop(void *instance, action_arg_t *arg, action_result_t *result);
#ifdef __cplusplus
}
#endif
#endif
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/include/wifi_action.h
|
C
|
apache-2.0
| 3,016
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "audio_error.h"
#include "audio_mem.h"
#include "esp_action_def.h"
#include "esp_audio.h"
#include "esp_log.h"
#include "nvs_action.h"
static const char *TAG = "NVS_ACTION";
esp_err_t nvs_action_open(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, arg, return ESP_FAIL);
AUDIO_MEM_CHECK(TAG, result, return ESP_FAIL);
nvs_action_open_args_t *open_arg = (nvs_action_open_args_t *)arg->data;
result->data = audio_calloc(1, sizeof(nvs_handle));
result->len = sizeof(nvs_handle);
return nvs_open(open_arg->name, open_arg->open_mode, result->data);
}
esp_err_t nvs_action_open_from_partion(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, arg, return ESP_FAIL);
AUDIO_MEM_CHECK(TAG, result, return ESP_FAIL);
nvs_action_open_partition_args_t *open_arg = (nvs_action_open_partition_args_t *)arg->data;
result->data = audio_calloc(1, sizeof(nvs_handle));
result->len = sizeof(nvs_handle);
return nvs_open_from_partition(open_arg->partition, open_arg->name, open_arg->open_mode, result->data);
}
esp_err_t nvs_action_set(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, instance, return ESP_FAIL);
AUDIO_MEM_CHECK(TAG, arg, return ESP_FAIL);
AUDIO_MEM_CHECK(TAG, result, return ESP_FAIL);
nvs_action_set_args_t *set_arg = (nvs_action_set_args_t *)arg->data;
esp_err_t err = ESP_FAIL;
switch (set_arg->type) {
case NVS_TYPE_U8:
err = nvs_set_u8((nvs_handle)instance, set_arg->key, set_arg->value.u8);
break;
case NVS_TYPE_I8:
err = nvs_set_i8((nvs_handle)instance, set_arg->key, set_arg->value.i8);
break;
case NVS_TYPE_U16:
err = nvs_set_u16((nvs_handle)instance, set_arg->key, set_arg->value.u16);
break;
case NVS_TYPE_I16:
err = nvs_set_i16((nvs_handle)instance, set_arg->key, set_arg->value.i16);
break;
case NVS_TYPE_U32:
err = nvs_set_u32((nvs_handle)instance, set_arg->key, set_arg->value.u32);
break;
case NVS_TYPE_I32:
err = nvs_set_i32((nvs_handle)instance, set_arg->key, set_arg->value.i32);
break;
case NVS_TYPE_U64:
err = nvs_set_u64((nvs_handle)instance, set_arg->key, set_arg->value.u64);
break;
case NVS_TYPE_I64:
err = nvs_set_i64((nvs_handle)instance, set_arg->key, set_arg->value.i64);
break;
case NVS_TYPE_STR:
err = nvs_set_str((nvs_handle)instance, set_arg->key, set_arg->value.string);
break;
case NVS_TYPE_BLOB:
err = nvs_set_blob((nvs_handle)instance, set_arg->key, set_arg->value.blob, set_arg->len);
break;
default:
break;
}
return err;
}
esp_err_t nvs_action_get(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, instance, return ESP_FAIL);
AUDIO_MEM_CHECK(TAG, arg, return ESP_FAIL);
AUDIO_MEM_CHECK(TAG, result, return ESP_FAIL);
nvs_action_get_args_t *get_arg = (nvs_action_get_args_t *)arg->data;
esp_err_t err = ESP_FAIL;
switch (get_arg->type) {
case NVS_TYPE_U8: {
result->data = audio_calloc(1, sizeof(uint8_t));
result->len = sizeof(uint8_t);
err = nvs_get_u8((nvs_handle)instance, get_arg->key, result->data);
break;
}
case NVS_TYPE_I8: {
result->data = audio_calloc(1, sizeof(int8_t));
result->len = sizeof(int8_t);
err = nvs_get_i8((nvs_handle)instance, get_arg->key, result->data);
break;
}
case NVS_TYPE_U16: {
result->data = audio_calloc(1, sizeof(uint16_t));
result->len = sizeof(uint16_t);
err = nvs_get_u16((nvs_handle)instance, get_arg->key, result->data);
break;
}
case NVS_TYPE_I16: {
result->data = audio_calloc(1, sizeof(int16_t));
result->len = sizeof(int16_t);
err = nvs_get_i16((nvs_handle)instance, get_arg->key, result->data);
break;
}
case NVS_TYPE_U32: {
result->data = audio_calloc(1, sizeof(uint32_t));
result->len = sizeof(uint32_t);
err = nvs_get_u32((nvs_handle)instance, get_arg->key, result->data);
break;
}
case NVS_TYPE_I32: {
result->data = audio_calloc(1, sizeof(int32_t));
result->len = sizeof(int32_t);
err = nvs_get_i32((nvs_handle)instance, get_arg->key, result->data);
break;
}
case NVS_TYPE_U64: {
result->data = audio_calloc(1, sizeof(uint64_t));
result->len = sizeof(uint64_t);
err = nvs_get_u64((nvs_handle)instance, get_arg->key, result->data);
break;
}
case NVS_TYPE_I64: {
result->data = audio_calloc(1, sizeof(int64_t));
result->len = sizeof(int64_t);
err = nvs_get_i64((nvs_handle)instance, get_arg->key, result->data);
break;
}
case NVS_TYPE_STR: {
result->data = audio_calloc(1, get_arg->wanted_size + 1);
result->len = get_arg->wanted_size + 1;
err = nvs_get_str((nvs_handle)instance, get_arg->key, result->data, (size_t *)&result->len);
break;
}
case NVS_TYPE_BLOB: {
result->data = audio_calloc(1, get_arg->wanted_size + 1);
result->len = get_arg->wanted_size + 1;
err = nvs_get_blob((nvs_handle)instance, get_arg->key, result->data, (size_t *)&result->len);
break;
}
default:
break;
}
return err;
}
esp_err_t nvs_action_erase_key(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, instance, return ESP_FAIL);
AUDIO_MEM_CHECK(TAG, arg, return ESP_FAIL);
return nvs_erase_key((nvs_handle)instance, arg->data);
}
esp_err_t nvs_action_erase_all(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, instance, return ESP_FAIL);
return nvs_erase_all((nvs_handle)instance);
}
esp_err_t nvs_action_commit(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, instance, return ESP_FAIL);
return nvs_commit((nvs_handle)instance);
}
esp_err_t nvs_action_close(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, instance, return ESP_FAIL);
nvs_close((nvs_handle)instance);
return ESP_OK;
}
esp_err_t nvs_action_get_stats(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, arg, return ESP_FAIL);
AUDIO_MEM_CHECK(TAG, result, return ESP_FAIL);
result->data = audio_calloc(1, sizeof(action_result_t));
result->len = sizeof(action_result_t);
return nvs_get_stats(arg->data, result->data);
}
esp_err_t nvs_action_get_used_entry_count(void *instance, action_arg_t *arg, action_result_t *result)
{
AUDIO_MEM_CHECK(TAG, instance, return ESP_FAIL);
AUDIO_MEM_CHECK(TAG, result, return ESP_FAIL);
result->data = audio_calloc(1, sizeof(size_t));
result->len = sizeof(size_t);
return nvs_get_used_entry_count((nvs_handle)instance, (size_t *)&result->data);
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/nvs_action.c
|
C
|
apache-2.0
| 8,668
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "audio_error.h"
#include "esp_action_def.h"
#include "partition_action.h"
esp_err_t partition_find_action(void *instance, action_arg_t *arg, action_result_t *result)
{
partition_find_args_t *find_arg = (partition_find_args_t *)arg->data;
result->data = (void *)esp_partition_find_first(find_arg->type, find_arg->subtype, find_arg->label);
result->err = result->data != NULL ? ESP_OK : ESP_FAIL;
return result->err;
}
esp_err_t partition_read_action(void *instance, action_arg_t *arg, action_result_t *result)
{
partition_read_args_t *read_arg = (partition_read_args_t *)arg->data;
result->err = esp_partition_read(read_arg->partition, read_arg->src_offset, read_arg->dst, read_arg->size);
return result->err;
}
esp_err_t partition_write_action(void *instance, action_arg_t *arg, action_result_t *result)
{
partition_write_args_t *write_arg = (partition_write_args_t *)arg->data;
result->err = esp_partition_write(write_arg->partition, write_arg->dst_offset, write_arg->src, write_arg->size);
return result->err;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/partition_action.c
|
C
|
apache-2.0
| 2,304
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "audio_error.h"
#include "esp_action_def.h"
#include "esp_audio.h"
#include "esp_log.h"
static const char *TAG = "PLAYER_ACTION";
esp_err_t player_action_play(void *instance, action_arg_t *arg, action_result_t *result)
{
esp_audio_handle_t handle = (esp_audio_handle_t)instance;
ESP_LOGI(TAG, "%s", __func__);
int ret = esp_audio_play(handle, AUDIO_CODEC_TYPE_DECODER, NULL, 0);
return ret;
}
esp_err_t player_action_pause(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
esp_audio_handle_t handle = (esp_audio_handle_t)instance;
int ret = esp_audio_pause(handle);
return ret;
}
esp_err_t player_action_next(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
esp_err_t player_action_prev(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
esp_err_t player_action_vol_up(void *instance, action_arg_t *arg, action_result_t *result)
{
int player_volume = 0;
esp_audio_handle_t handle = (esp_audio_handle_t)instance;
esp_audio_vol_get(handle, &player_volume);
player_volume += 10;
if (player_volume > 100) {
player_volume = 100;
}
esp_audio_vol_set(handle, player_volume);
ESP_LOGI(TAG, "%s, vol:[%d]", __func__, player_volume);
return ESP_OK;
}
esp_err_t player_action_vol_down(void *instance, action_arg_t *arg, action_result_t *result)
{
int player_volume = 0;
esp_audio_handle_t handle = (esp_audio_handle_t)instance;
esp_audio_vol_get(handle, &player_volume);
player_volume -= 10;
if (player_volume < 0) {
player_volume = 0;
}
esp_audio_vol_set(handle, player_volume);
ESP_LOGI(TAG, "%s, vol:[%d]", __func__, player_volume);
return ESP_OK;
}
esp_err_t player_action_mute_on(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
esp_err_t player_action_mute_off(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/player_action.c
|
C
|
apache-2.0
| 3,500
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "audio_error.h"
#include "esp_log.h"
#include "recorder_action.h"
#include "recorder_engine.h"
static const char *TAG = "REC_ACTION";
esp_err_t recorder_action_rec_wav_turn_on(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
int ret = rec_engine_trigger_start();
return ret;
}
esp_err_t recorder_action_rec_wav_turn_off(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
int ret = rec_engine_trigger_stop();
return ret;
}
esp_err_t recorder_action_rec_amr_turn_on(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
esp_err_t recorder_action_rec_amr_turn_off(void *instance, action_arg_t *arg, action_result_t *result)
{
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/recorder_action.c
|
C
|
apache-2.0
| 2,101
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "audio_error.h"
#include "esp_log.h"
#include "wifi_action.h"
#include "wifi_service.h"
static const char *TAG = "WIFI_ACTION";
esp_err_t wifi_action_connect(void *ctx, action_arg_t *arg, action_result_t *result)
{
periph_service_handle_t wifi_serv = (periph_service_handle_t)ctx;
wifi_service_connect(wifi_serv);
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
esp_err_t wifi_action_disconnect(void *ctx, action_arg_t *arg, action_result_t *result)
{
periph_service_handle_t wifi_serv = (periph_service_handle_t)ctx;
wifi_service_disconnect(wifi_serv);
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
esp_err_t wifi_action_setting_start(void *ctx, action_arg_t *arg, action_result_t *result)
{
periph_service_handle_t wifi_serv = (periph_service_handle_t)ctx;
wifi_service_setting_start(wifi_serv, 0);
ESP_LOGI(TAG, "%s", __func__);
return ESP_OK;
}
esp_err_t wifi_action_setting_stop(void *ctx, action_arg_t *arg, action_result_t *result)
{
periph_service_handle_t wifi_serv = (periph_service_handle_t)ctx;
ESP_LOGI(TAG, "%s", __func__);
wifi_service_setting_stop(wifi_serv, 0);
return ESP_OK;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_actions/wifi_action.c
|
C
|
apache-2.0
| 2,413
|
set(COMPONENT_ADD_INCLUDEDIRS include)
# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES )
set(COMPONENT_PRIV_REQUIRES audio_sal)
set(COMPONENT_SRCS ./audio_service.c ./esp_dispatcher.c ./periph_service.c ./esp_delegate.c)
register_component()
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/CMakeLists.txt
|
CMake
|
apache-2.0
| 288
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "sys/queue.h"
#include "esp_log.h"
#include "audio_service.h"
#include "audio_mutex.h"
#include "audio_mem.h"
static const char *TAG = "AUDIO_SERVICE";
/**
* @brief Audio service configurations
*/
typedef struct audio_service_impl {
service_ctrl service_start;
service_ctrl service_stop;
service_ctrl service_connect;
service_ctrl service_disconnect;
service_ctrl service_destroy;
service_callback callback_func;
void *user_cb_ctx;
char *service_name;
TaskHandle_t task_handle;
void *user_data;
} audio_service_impl_t;
audio_service_handle_t audio_service_create(audio_service_config_t *config)
{
AUDIO_NULL_CHECK(TAG, config, return NULL);
audio_service_handle_t impl = audio_calloc(1, sizeof(audio_service_impl_t));
AUDIO_MEM_CHECK(TAG, impl, return NULL);
impl->service_start = config->service_start;
impl->service_stop = config->service_stop;
impl->service_connect = config->service_connect;
impl->service_disconnect = config->service_disconnect;
impl->service_destroy = config->service_destroy;
impl->user_data = config->user_data;
if (config->service_name) {
impl->service_name = audio_strdup(config->service_name);
AUDIO_MEM_CHECK(TAG, impl, goto serv_failed);
}
if (config->task_stack > 0) {
if (pdPASS != xTaskCreatePinnedToCore(config->task_func,
config->service_name,
config->task_stack,
impl,
config->task_prio,
&impl->task_handle,
config->task_core)) {
ESP_LOGE(TAG, "Create task failed on %s", __func__);
goto serv_failed;
}
}
return impl;
serv_failed:
audio_free(impl->service_name);
impl->service_name = NULL;
audio_free(impl);
impl = NULL;
return impl;
}
esp_err_t audio_service_destroy(audio_service_handle_t handle)
{
AUDIO_NULL_CHECK(TAG, handle, return ESP_ERR_INVALID_ARG);
audio_service_impl_t *impl = (audio_service_impl_t *) handle;
if (impl->service_destroy) {
impl->service_destroy(handle);
}
audio_free(impl->service_name);
impl->service_name = NULL;
impl->task_handle = NULL;
audio_free(impl);
impl = NULL;
return ESP_OK;
}
esp_err_t audio_service_start(audio_service_handle_t handle)
{
audio_service_impl_t *impl = (audio_service_impl_t *) handle;
AUDIO_NULL_CHECK(TAG, (handle && impl->service_start), return ESP_ERR_INVALID_ARG);
return impl->service_start(handle);
}
esp_err_t audio_service_stop(audio_service_handle_t handle)
{
audio_service_impl_t *impl = (audio_service_impl_t *) handle;
AUDIO_NULL_CHECK(TAG, (handle && impl->service_stop), return ESP_ERR_INVALID_ARG);
return impl->service_stop(handle);
}
esp_err_t audio_service_set_callback(audio_service_handle_t handle, service_callback cb, void *ctx)
{
audio_service_impl_t *impl = (audio_service_impl_t *) handle;
impl->callback_func = cb;
impl->user_cb_ctx = ctx;
return ESP_OK;
}
esp_err_t audio_service_callback(audio_service_handle_t handle, service_event_t *evt)
{
audio_service_impl_t *impl = (audio_service_impl_t *) handle;
AUDIO_NULL_CHECK(TAG, (handle && impl->callback_func), return ESP_ERR_INVALID_ARG);
return impl->callback_func(handle, evt, impl->user_cb_ctx);
}
esp_err_t audio_service_connect(audio_service_handle_t handle)
{
audio_service_impl_t *impl = (audio_service_impl_t *) handle;
AUDIO_NULL_CHECK(TAG, (handle && impl->service_connect), return ESP_ERR_INVALID_ARG);
return impl->service_connect(handle);
}
esp_err_t audio_service_disconnect(audio_service_handle_t handle)
{
audio_service_impl_t *impl = (audio_service_impl_t *) handle;
AUDIO_NULL_CHECK(TAG, (handle && impl->service_disconnect), return ESP_ERR_INVALID_ARG);
return impl->service_disconnect(handle);
}
esp_err_t audio_service_set_data(audio_service_handle_t handle, void *data)
{
AUDIO_NULL_CHECK(TAG, handle, return ESP_ERR_INVALID_ARG);
audio_service_impl_t *impl = (audio_service_impl_t *) handle;
impl->user_data = data;
return ESP_OK;
}
void *audio_service_get_data(audio_service_handle_t handle)
{
AUDIO_NULL_CHECK(TAG, handle, return NULL);
audio_service_impl_t *impl = (audio_service_impl_t *) handle;
return impl->user_data;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/audio_service.c
|
C
|
apache-2.0
| 6,161
|
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := .
COMPONENT_PRIV_INCLUDEDIRS :=
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/component.mk
|
Makefile
|
apache-2.0
| 237
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <stddef.h>
#include "esp_err.h"
#include "esp_delegate.h"
static void *shared_handle = NULL;
esp_dispatcher_handle_t esp_dispatcher_get_delegate_handle(void)
{
if (shared_handle == NULL) {
esp_dispatcher_config_t d_cfg = ESP_DISPATCHER_CONFIG_DEFAULT();
d_cfg.task_core = CONFIG_ESP_DISPATCHER_DELEGATE_TASK_CORE;
d_cfg.task_prio = CONFIG_ESP_DISPATCHER_DELEGATE_TASK_PRIO;
d_cfg.task_stack = CONFIG_ESP_DISPATCHER_DELEGATE_STACK_SIZE;
d_cfg.stack_in_ext = false;
shared_handle = esp_dispatcher_create(&d_cfg);
}
return shared_handle;
}
esp_err_t esp_dispatcher_release_delegate_handle(void)
{
esp_err_t ret = ESP_OK;
if (shared_handle) {
ret = esp_dispatcher_destroy(shared_handle);
if (ret == ESP_OK) {
shared_handle = NULL;
}
}
return ret;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/esp_delegate.c
|
C
|
apache-2.0
| 2,106
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "sys/queue.h"
#include "esp_log.h"
#include "esp_dispatcher.h"
#include "audio_mutex.h"
#include "audio_mem.h"
#include "audio_error.h"
#include "audio_thread.h"
static const char *TAG = "DISPATCHER";
#define ESP_DISPATCHER_EVENT_SIZE (3)
typedef enum {
ESP_DISPCH_EVENT_TYPE_UNKNOWN,
ESP_DISPCH_EVENT_TYPE_CMD,
ESP_DISPCH_EVENT_TYPE_EXE,
} esp_dispatcher_event_type_t;
typedef struct {
esp_dispatcher_event_type_t type;
int sub_index;
esp_action_exe pfunc;
void *instance;
action_arg_t arg;
func_ret_cb_t ret_cb;
void *user_data;
} esp_dispatcher_info_t;
typedef struct evt_exe_item {
STAILQ_ENTRY(evt_exe_item) entries;
int sub_index;
esp_action_exe exe_func;
void* exe_instance;
} esp_action_exe_item_t;
typedef struct esp_dispatcher {
audio_thread_t thread;
QueueHandle_t exe_que;
QueueHandle_t result_que;
SemaphoreHandle_t mutex;
TaskHandle_t task_handle;
STAILQ_HEAD(action_exe_list, evt_exe_item) exe_list;
} esp_dispatcher_t;
static esp_err_t execute_index_exist(esp_dispatcher_handle_t h, int idx)
{
esp_dispatcher_t *impl = (esp_dispatcher_t *)h;
esp_action_exe_item_t *item;
STAILQ_FOREACH(item, &impl->exe_list, entries) {
if (idx == item->sub_index) {
return ESP_OK;
}
}
return ESP_FAIL;
}
static esp_action_exe_item_t *found_exe_func(esp_dispatcher_handle_t h, int idx)
{
esp_dispatcher_t *impl = (esp_dispatcher_t *)h;
esp_action_exe_item_t *item;
STAILQ_FOREACH(item, &impl->exe_list, entries) {
if (idx == item->sub_index) {
return item;
}
}
return NULL;
}
static void dispatcher_event_task(void *parameters)
{
esp_dispatcher_t *dispch = (esp_dispatcher_t *)parameters;
esp_dispatcher_info_t msg = {0};
action_result_t result = {0};
esp_action_exe_item_t *exe_item = NULL;
bool task_run = true;
ESP_LOGI(TAG, "%s is running...", __func__);
while (task_run) {
if (xQueueReceive(dispch->exe_que, &msg, portMAX_DELAY) == pdTRUE) {
if (msg.type == ESP_DISPCH_EVENT_TYPE_EXE) {
esp_action_exe exe_func = NULL;
void *exe_handle = NULL;
result.err = ESP_OK;
result.data = 0;
result.len = 0;
ESP_LOGD(TAG, "EXE type:%d, index:%x, pfunc:%p, %p, %d",
msg.type, msg.sub_index, msg.pfunc, msg.arg.data, msg.arg.len);
if (msg.sub_index != -1) {
exe_item = found_exe_func(dispch, msg.sub_index);
if (exe_item) {
exe_func = exe_item->exe_func;
exe_handle = exe_item->exe_instance;
} else {
result.err = ESP_ERR_ADF_NOT_SUPPORT;
ESP_LOGW(TAG, "Not found index:%x", msg.sub_index);
}
} else if (msg.sub_index == -1 && msg.pfunc != NULL) {
exe_func = msg.pfunc;
exe_handle = msg.instance;
} else {
result.err = ESP_ERR_ADF_NOT_SUPPORT;
ESP_LOGW(TAG, "Unsupported type index:%x, pfunc:%p", msg.sub_index, msg.pfunc);
}
if (exe_func) {
result.err = exe_func(exe_handle, &msg.arg, &result);
}
if (msg.ret_cb) {
msg.ret_cb(result, msg.user_data);
} else {
if (xQueueSend(dispch->result_que, &result, pdMS_TO_TICKS(0)) == pdFALSE) {
ESP_LOGW(TAG, "Send result failed, pfunc: %p, index:%x", msg.pfunc, msg.sub_index);
}
}
} else if (msg.type == ESP_DISPCH_EVENT_TYPE_CMD) {
task_run = false;
}
} else {
ESP_LOGE(TAG, "Unknown queue or receive error");
}
}
result.err = ESP_OK;
result.data = 0;
result.len = 0;
xQueueSend(dispch->result_que, &result, 0 / portTICK_PERIOD_MS);
vTaskDelete(NULL);
}
esp_err_t esp_dispatcher_reg_exe_func(esp_dispatcher_handle_t dh, void *exe_inst, int sub_event_index, esp_action_exe func)
{
esp_dispatcher_t *impl = (esp_dispatcher_t *)dh;
AUDIO_NULL_CHECK(TAG, impl, return ESP_ERR_INVALID_ARG);
if (execute_index_exist(dh, sub_event_index) == ESP_OK) {
ESP_LOGW(TAG, "The %x index of function already exists", sub_event_index);
return ESP_ERR_ADF_ALREADY_EXISTS;
}
esp_action_exe_item_t *item = audio_calloc(1, sizeof(esp_action_exe_item_t));
item->sub_index = sub_event_index;
item->exe_func = func;
item->exe_instance = exe_inst;
STAILQ_INSERT_TAIL(&impl->exe_list, item, entries);
return ESP_OK;
}
esp_err_t esp_dispatcher_execute(esp_dispatcher_handle_t dh, int sub_event_index,
action_arg_t *in_para, action_result_t *out_result)
{
esp_dispatcher_t *impl = (esp_dispatcher_t *)dh;
AUDIO_NULL_CHECK(TAG, impl, return ESP_ERR_INVALID_ARG);
esp_dispatcher_info_t info = {0};
info.type = ESP_DISPCH_EVENT_TYPE_EXE;
info.sub_index = sub_event_index;
if (in_para) {
memcpy(&info.arg, in_para, sizeof(action_arg_t));
}
ESP_LOGI(TAG, "EXE IN, cmd type:%d, index:%x, data:%p, len:%d",
info.type, info.sub_index, info.arg.data, info.arg.len);
mutex_lock(impl->mutex);
if (xQueueSend(impl->exe_que, &info, 5000 / portTICK_PERIOD_MS) == pdFALSE) {
ESP_LOGE(TAG, "Send timeout type:%d, index:%x", info.type, info.sub_index);
mutex_unlock(impl->mutex);
return ESP_ERR_ADF_TIMEOUT;
}
action_result_t ret = {0};
xQueueReceive(impl->result_que, &ret, portMAX_DELAY);
mutex_unlock(impl->mutex);
if (out_result) {
memcpy(out_result, &ret, sizeof(action_result_t));
}
ESP_LOGI(TAG, "EXE OUT,result type:%d, index:%x, ret:%x, data:%p, len:%d", info.type, info.sub_index, ret.err, ret.data, ret.len);
return ret.err;
}
esp_err_t esp_dispatcher_execute_async(esp_dispatcher_handle_t dh, int sub_event_index,
action_arg_t *in_para, func_ret_cb_t ret_cb, void* user_data)
{
esp_dispatcher_t *impl = (esp_dispatcher_t *)dh;
AUDIO_NULL_CHECK(TAG, impl, return ESP_ERR_INVALID_ARG);
esp_dispatcher_info_t info = {0};
info.type = ESP_DISPCH_EVENT_TYPE_EXE;
info.sub_index = sub_event_index;
info.ret_cb = ret_cb;
info.user_data = user_data;
if (in_para) {
memcpy(&info.arg, in_para, sizeof(action_arg_t));
}
ESP_LOGI(TAG, "EXE IN, cmd type:%d, index:%x, data:%p, len:%d",
info.type, info.sub_index, info.arg.data, info.arg.len);
mutex_lock(impl->mutex);
if (xQueueSend(impl->exe_que, &info, pdMS_TO_TICKS(5000)) != pdPASS) {
ESP_LOGE(TAG, "Message send timeout");
action_result_t result = {0};
result.err = ESP_FAIL;
ret_cb(result, user_data);
mutex_unlock(impl->mutex);
return ESP_ERR_ADF_TIMEOUT;
}
mutex_unlock(impl->mutex);
return ESP_OK;
}
esp_err_t esp_dispatcher_execute_with_func(esp_dispatcher_handle_t dh,
esp_action_exe func,
void *instance,
action_arg_t *arg,
action_result_t *ret)
{
esp_dispatcher_t *impl = (esp_dispatcher_t *)dh;
AUDIO_NULL_CHECK(TAG, impl, return ESP_ERR_INVALID_ARG);
AUDIO_NULL_CHECK(TAG, ret, return ESP_ERR_INVALID_ARG);
esp_dispatcher_info_t delegate = { 0 };
delegate.type = ESP_DISPCH_EVENT_TYPE_EXE;
delegate.sub_index = -1;
delegate.pfunc = func;
delegate.instance = instance;
delegate.ret_cb = NULL;
delegate.user_data = NULL;
if (arg) {
memcpy(&delegate.arg, arg, sizeof(action_arg_t));
}
mutex_lock(impl->mutex);
if (xQueueSend(impl->exe_que, &delegate, pdMS_TO_TICKS(5000)) != pdPASS) {
ret->err = ESP_FAIL;
ESP_LOGE(TAG, "Message send timeout");
mutex_unlock(impl->mutex);
return ESP_ERR_ADF_TIMEOUT;
}
xQueueReceive(impl->result_que, ret, portMAX_DELAY);
mutex_unlock(impl->mutex);
return ret->err;
}
esp_err_t esp_dispatcher_execute_with_func_async(esp_dispatcher_handle_t dh,
esp_action_exe func,
void *instance,
action_arg_t *arg,
func_ret_cb_t ret_cb,
void* user_data)
{
esp_dispatcher_t *impl = (esp_dispatcher_t *)dh;
AUDIO_NULL_CHECK(TAG, impl, return ESP_ERR_INVALID_ARG);
esp_dispatcher_info_t delegate = { 0 };
delegate.type = ESP_DISPCH_EVENT_TYPE_EXE;
delegate.sub_index = -1;
delegate.pfunc = func;
delegate.instance = instance;
delegate.ret_cb = ret_cb;
delegate.user_data = user_data;
if (arg) {
memcpy(&delegate.arg, arg, sizeof(action_arg_t));
}
mutex_lock(impl->mutex);
if (xQueueSend(impl->exe_que, &delegate, pdMS_TO_TICKS(5000)) != pdPASS) {
ESP_LOGE(TAG, "Message send timeout");
action_result_t result = {0};
result.err = ESP_FAIL;
ret_cb(result, user_data);
mutex_unlock(impl->mutex);
return ESP_ERR_ADF_TIMEOUT;
}
mutex_unlock(impl->mutex);
return ESP_OK;
}
esp_dispatcher_handle_t esp_dispatcher_create(esp_dispatcher_config_t *cfg)
{
AUDIO_NULL_CHECK(TAG, cfg, return NULL);
esp_dispatcher_handle_t impl = audio_calloc(1, sizeof(esp_dispatcher_t));
AUDIO_MEM_CHECK(TAG, impl, return NULL);
impl->result_que = xQueueCreate(1, sizeof(action_result_t));
AUDIO_MEM_CHECK(TAG, impl->result_que, goto _failed;);
impl->exe_que = xQueueCreate(ESP_DISPATCHER_EVENT_SIZE, sizeof(esp_dispatcher_info_t));
AUDIO_MEM_CHECK(TAG, impl->exe_que, goto _failed;);
impl->mutex = mutex_create();
AUDIO_MEM_CHECK(TAG, impl->mutex, goto _failed;);
STAILQ_INIT(&impl->exe_list);
ESP_LOGE(TAG, "exe first list: %p", STAILQ_FIRST(&impl->exe_list));
if (ESP_OK != audio_thread_create(&impl->thread,
"esp_dispatcher",
dispatcher_event_task,
impl,
cfg->task_stack,
cfg->task_prio,
cfg->stack_in_ext,
cfg->task_core)) {
ESP_LOGE(TAG, "Create task failed on %s", __func__);
goto _failed;
}
return impl;
_failed:
if (impl->result_que) {
vQueueDelete(impl->result_que);
impl->result_que = NULL;
}
if (impl->exe_que) {
vQueueDelete(impl->exe_que);
impl->exe_que = NULL;
}
if (impl->mutex) {
mutex_destroy(impl->mutex);
impl->mutex = NULL;
}
audio_free(impl);
impl = NULL;
return impl;
}
esp_err_t esp_dispatcher_destroy(esp_dispatcher_handle_t dh)
{
esp_dispatcher_t *impl = (esp_dispatcher_t *)dh;
AUDIO_NULL_CHECK(TAG, impl, return ESP_ERR_INVALID_ARG);
esp_dispatcher_info_t info = {0};
action_result_t ret = {0};
info.type = ESP_DISPCH_EVENT_TYPE_CMD;
xQueueSend(impl->exe_que, &info, portMAX_DELAY);
xQueueReceive(impl->result_que, &ret, portMAX_DELAY);
esp_action_exe_item_t *item;
STAILQ_FOREACH(item, &impl->exe_list, entries) {
STAILQ_REMOVE(&impl->exe_list, item, evt_exe_item, entries);
audio_free(item);
}
if (impl->result_que) {
vQueueDelete(impl->result_que);
impl->result_que = NULL;
}
if (impl->exe_que) {
vQueueDelete(impl->exe_que);
impl->exe_que = NULL;
}
if (impl->mutex) {
mutex_destroy(impl->mutex);
impl->mutex = NULL;
}
audio_free(impl);
impl = NULL;
return ESP_OK;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/esp_dispatcher.c
|
C
|
apache-2.0
| 13,971
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __AUDIO_SERVICE_H__
#define __AUDIO_SERVICE_H__
#include "audio_error.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Audio service state
*/
typedef enum {
SERVICE_STATE_UNKNOWN,
SERVICE_STATE_IDLE,
SERVICE_STATE_CONNECTING,
SERVICE_STATE_CONNECTED,
SERVICE_STATE_RUNNING,
SERVICE_STATE_STOPPED,
} service_state_t;
/**
* @brief Audio service event informations
*/
typedef struct {
int type; /*!< Type of event */
void *source; /*!< Event source */
void *data; /*!< Event data */
int len; /*!< Length of data */
} service_event_t;
typedef struct audio_service_impl *audio_service_handle_t;
typedef esp_err_t (*service_ctrl)(audio_service_handle_t handle);
typedef esp_err_t (*service_callback)(audio_service_handle_t handle, service_event_t *evt, void *ctx);
/**
* @brief Audio service configurations
*/
typedef struct {
int task_stack; /*!< >0 Service task stack; =0 with out task created */
int task_prio; /*!< Service task priority (based on freeRTOS priority) */
int task_core; /*!< Service task running in core (0 or 1) */
TaskFunction_t task_func; /*!< A pointer to TaskFunction_t for service task function */
service_ctrl service_start; /*!< Start function */
service_ctrl service_stop; /*!< Stop function */
service_ctrl service_connect; /*!< Connect function */
service_ctrl service_disconnect; /*!< Disconnect function */
service_ctrl service_destroy; /*!< Destroy function */
const char *service_name; /*!< Name of audio service */
void *user_data; /*!< User context */
} audio_service_config_t;
/**
* brief Create audio service instance
*
* @param[in] config Configuration of the audio service instance
*
* @return
* - NULL, Fail
* - Others, Success
*/
audio_service_handle_t audio_service_create(audio_service_config_t *config);
/**
* brief Destroy audio service instance
*
* @param[in] handle The audio service instance
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t audio_service_destroy(audio_service_handle_t handle);
/**
* brief Start the specific audio service
*
* @param[in] handle The audio service instance
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t audio_service_start(audio_service_handle_t handle);
/**
* brief Stop the specific audio service
*
* @param[in] handle The audio service instance
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t audio_service_stop(audio_service_handle_t handle);
/**
* brief Set the specific audio service callback function.
*
* @param[in] handle The audio service instance
* @param[in] cb A pointer to service_callback
* @param[in] ctx A pointer to user context
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t audio_service_set_callback(audio_service_handle_t handle, service_callback cb, void *ctx);
/**
* brief Called audio service by configurations
*
* @param[in] handle The audio service instance
* @param[in] evt A pointer to service_event_t
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t audio_service_callback(audio_service_handle_t handle, service_event_t *evt);
/**
* brief Connect the specific audio service
*
* @param[in] handle The audio service instance
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t audio_service_connect(audio_service_handle_t handle);
/**
* brief Disconnect the specific audio service
*
* @param[in] handle The audio service instance
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t audio_service_disconnect(audio_service_handle_t handle);
/**
* brief Set user data to specific audio service instance
*
* @param[in] handle The audio service instance
* @param[in] data A pointer to user data
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t audio_service_set_data(audio_service_handle_t handle, void *data);
/**
* brief Get user data by specific audio service instance
*
* @param[in] handle The audio service instance
*
* @return A pointer to user data
*/
void *audio_service_get_data(audio_service_handle_t handle);
#ifdef __cplusplus
}
#endif
#endif // End of __AUDIO_SERVICE_H__
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/include/audio_service.h
|
C
|
apache-2.0
| 6,075
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __ESP_ACTION_DEF_H__
#define __ESP_ACTION_DEF_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief The result of action
*/
typedef struct {
esp_err_t err; /*!< Error code */
void *data; /*!< Pointer to result data */
int len; /*!< Length of the data */
} action_result_t;
/**
* @brief The action arguments
*/
typedef struct {
void *data; /*!< Pointer to arguments data */
int len; /*!< Length of the data */
} action_arg_t;
typedef esp_err_t (*esp_action_exe) (void *instance, action_arg_t *arg, action_result_t *result);
#ifdef __cplusplus
}
#endif
#endif // __ESP_ACTION_DEF_H__
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/include/esp_action_def.h
|
C
|
apache-2.0
| 2,041
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __ESP_ACTION_COMMON_TYPE_H__
#define __ESP_ACTION_COMMON_TYPE_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
ACTION_EXE_TYPE_UNKNOWN = - 1,
ACTION_EXE_TYPE_CONNECTIVITY_BASE = 0x0,
ACTION_EXE_TYPE_WIFI_DISCONNECT = 0x1,
ACTION_EXE_TYPE_WIFI_CONNECT = 0x2,
ACTION_EXE_TYPE_WIFI_SETTING_START = 0x3,
ACTION_EXE_TYPE_WIFI_SETTING_STOP = 0x4,
ACTION_EXE_TYPE_CONNECTIVITY_MAX = 0xFFF,
ACTION_EXE_TYPE_AUDIO_BASE = 0x1000,
ACTION_EXE_TYPE_AUDIO_PLAY = 0x1001,
ACTION_EXE_TYPE_AUDIO_PAUSE = 0x1002,
ACTION_EXE_TYPE_AUDIO_RESUME = 0x1003,
ACTION_EXE_TYPE_AUDIO_STOP = 0x1004,
ACTION_EXE_TYPE_AUDIO_GET_PROGRESS_BYTE = 0x1005,
ACTION_EXE_TYPE_AUDIO_GET_PROGRESS_TIME = 0x1006,
ACTION_EXE_TYPE_AUDIO_VOLUME_SET = 0x1007,
ACTION_EXE_TYPE_AUDIO_VOLUME_GET = 0x1008,
ACTION_EXE_TYPE_AUDIO_VOLUME_UP = 0x1009,
ACTION_EXE_TYPE_AUDIO_VOLUME_DOWN = 0x100A,
ACTION_EXE_TYPE_AUDIO_MUTE_ON = 0x100B,
ACTION_EXE_TYPE_AUDIO_MUTE_OFF = 0x100C,
ACTION_EXE_TYPE_AUDIO_MAX = 0x1FFF,
ACTION_EXE_TYPE_RECORDER_BASE = 0x2000,
ACTION_EXE_TYPE_REC_WAV_TURN_ON = 0x2001,
ACTION_EXE_TYPE_REC_WAV_TURN_OFF = 0x2002,
ACTION_EXE_TYPE_REC_AMR_TURN_ON = 0x2003,
ACTION_EXE_TYPE_REC_AMR_TURN_OFF = 0x2004,
ACTION_EXE_TYPE_RECORDER_MAX = 0x2FFF,
ACTION_EXE_TYPE_DISPLAY_BASE = 0x3000,
ACTION_EXE_TYPE_DISPLAY_TURN_ON = 0x3001,
ACTION_EXE_TYPE_DISPLAY_TURN_OFF = 0x3002,
ACTION_EXE_TYPE_DISPLAY_WIFI_SETTING = 0x3003,
ACTION_EXE_TYPE_DISPLAY_WIFI_DISCONNECTED = 0x3004,
ACTION_EXE_TYPE_DISPLAY_WIFI_CONNECTED = 0x3005,
ACTION_EXE_TYPE_DISPLAY_SETTING_TIMEOUT = 0x3006,
ACTION_EXE_TYPE_DISPLAY_BATTERY_CHARGING = 0x3007,
ACTION_EXE_TYPE_DISPLAY_BATTERY_FULL = 0x3008,
ACTION_EXE_TYPE_DISPLAY_BATTERY_DISCHARGING = 0x3009,
ACTION_EXE_TYPE_DISPLAY_MAX = 0x3FFF,
ACTION_EXE_TYPE_DUER_BASE = 0x4000,
ACTION_EXE_TYPE_DUER_AUDIO = 0x4001,
ACTION_EXE_TYPE_DUER_SPEAK = 0x4002,
ACTION_EXE_TYPE_DUER_VOLUME_ADJ = 0x4003,
ACTION_EXE_TYPE_DUER_PAUSE = 0x4004,
ACTION_EXE_TYPE_DUER_RESUME = 0x4005,
ACTION_EXE_TYPE_DUER_STOP = 0x4006,
ACTION_EXE_TYPE_DUER_DISCONNECT = 0x4007,
ACTION_EXE_TYPE_DUER_CONNECT = 0x4008,
ACTION_EXE_TYPE_DUER_MAX = 0x4FFF,
ACTION_EXE_TYPE_CUSTOMER_BASE = 0x80000,
} action_exe_type_t;
#ifdef __cplusplus
}
#endif
#endif // End of __ESP_ACTION_COMMON_TYPE_H__
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/include/esp_action_exe_type.h
|
C
|
apache-2.0
| 4,832
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __ESP_DELEGATE_H__
#define __ESP_DELEGATE_H__
#include "esp_dispatcher.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Return the shared dispatcher handle, this will hold a dispatcher with its stack in DRAM.
*
* @note This function is not thread safe.
* Tasks should not call this function at the same time when device boot up.
*
* @param
*
* @return
* - NULL, Fail
* - Others, Success
*/
esp_dispatcher_handle_t esp_dispatcher_get_delegate_handle(void);
/**
* @brief Release the shared dispatcher handle, this will destroy the handle.
*
* @param
*
* @return
* - ESP_OK
* - Others, Fail
*/
esp_err_t esp_dispatcher_release_delegate_handle(void);
#ifdef __cplusplus
}
#endif
#endif // End of __ESP_DELEGATE_H__
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/include/esp_delegate.h
|
C
|
apache-2.0
| 2,031
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __ESP_DISPATCHER_H__
#define __ESP_DISPATCHER_H__
#include <stdbool.h>
#include "esp_err.h"
#include "esp_action_def.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DEFAULT_ESP_DISPATCHER_STACK_SIZE (4*1024)
#define DEFAULT_ESP_DISPATCHER_TASK_PRIO (10)
#define DEFAULT_ESP_DISPATCHER_TASK_CORE (0)
/**
* @brief The dispatcher configuration
*/
typedef struct {
int task_stack; /*!< >0 Task stack; =0 with out task created */
int task_prio; /*!< Task priority (based on freeRTOS priority) */
int task_core; /*!< Task running in core (0 or 1) */
bool stack_in_ext; /*!< Try to allocate stack in external memory */
} esp_dispatcher_config_t;
typedef struct esp_dispatcher *esp_dispatcher_handle_t;
/**
* @brief the delegate result callback type
*/
typedef void (*func_ret_cb_t)(action_result_t ret, void *user_data);
#define ESP_DISPATCHER_CONFIG_DEFAULT() { \
.task_stack = DEFAULT_ESP_DISPATCHER_STACK_SIZE, \
.task_prio = DEFAULT_ESP_DISPATCHER_TASK_PRIO, \
.task_core = DEFAULT_ESP_DISPATCHER_TASK_CORE, \
.stack_in_ext = false, \
}
/**
* brief Create ESP dispatcher instance
*
* @param cfg Configuration of the ESP dispatcher instance
*
* @return
* - NULL, Fail
* - Others, Success
*/
esp_dispatcher_handle_t esp_dispatcher_create(esp_dispatcher_config_t *cfg);
/**
* brief Destroy ESP dispatcher instance
*
* @param handle The ESP dispatcher instance
*
* @return
* - ESP_OK
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_dispatcher_destroy(esp_dispatcher_handle_t handle);
/**
* brief Register index of event and execution function to ESP dispatcher instance
*
* @param handle The ESP dispatcher instance
* @param exe_inst The execution instance
* @param sub_event_index The index of event
* @param func The execution function
*
* @return
* - ESP_OK
* - ESP_ERR_ADF_ALREADY_EXISTS
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_dispatcher_reg_exe_func(esp_dispatcher_handle_t handle, void *exe_inst, int sub_event_index, esp_action_exe func);
/**
* brief Execution function with specific index of event.
* This is a synchronization interface.
*
* @param handle The ESP dispatcher instance
* @param sub_event_index The index of event
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK
* - ESP_ERR_INVALID_ARG
* - ESP_ERR_ADF_TIMEOUT, send request command timeout.
* - Others, execute function result.
*/
esp_err_t esp_dispatcher_execute(esp_dispatcher_handle_t handle, int sub_event_index,
action_arg_t *arg, action_result_t *result);
/**
* brief Execution function with specific index of event.
* This is a asynchronous interface.
*
* @param handle The ESP dispatcher instance
* @param sub_event_index The index of event
* @param arg The arguments of execution function
* @param ret_cb The call back used to receive the function execute result
* @param user_data The data used in callback
*
* @return
* - ESP_OK
* - ESP_ERR_INVALID_ARG
* - ESP_ERR_ADF_TIMEOUT, send request command timeout.
* - Others, execute function result.
*/
esp_err_t esp_dispatcher_execute_async(esp_dispatcher_handle_t dh, int sub_event_index,
action_arg_t *in_para, func_ret_cb_t ret_cb, void* user_data);
/**
* @brief Synchronize invoke functions in ESP dispatcher
*
* @param handle The ESP dispatcher instance
* @param func The function to invoke
* @param exe_inst The execution instance
* @param arg The arguments of execution function
* @param result The result of execution function
*
* @return
* - ESP_OK
* - ESP_ERR_INVALID_ARG
* - ESP_ERR_ADF_TIMEOUT, send request command timeout.
* - Others, execute function result.
*/
esp_err_t esp_dispatcher_execute_with_func(esp_dispatcher_handle_t handle,
esp_action_exe func,
void *exe_inst,
action_arg_t *arg,
action_result_t *ret);
/**
* @brief Asynchronous invoke functions in ESP dispatcher
*
* @param handle The ESP dispatcher instance
* @param func The function to invoke
* @param exe_inst The execution instance
* @param arg The arguments of execution function
* @param ret_cb The call back used to receive the function execute result
* @param user_data The data used in callback
*
* @return
* - ESP_OK
* - ESP_ERR_INVALID_ARG
* - ESP_ERR_ADF_TIMEOUT, send request command timeout.
* - Others, execute function result.
*/
esp_err_t esp_dispatcher_execute_with_func_async(esp_dispatcher_handle_t handle,
esp_action_exe func,
void *exe_inst,
action_arg_t *arg,
func_ret_cb_t ret_cb,
void* user_data);
#ifdef __cplusplus
}
#endif
#endif // End of __ESP_DISPATCHER_H__
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/include/esp_dispatcher.h
|
C
|
apache-2.0
| 6,831
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __PERIPH_SERVICE_H__
#define __PERIPH_SERVICE_H__
#include "audio_error.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Peripheral service state
*/
typedef enum {
PERIPH_SERVICE_STATE_UNKNOWN,
PERIPH_SERVICE_STATE_IDLE,
PERIPH_SERVICE_STATE_RUNNING,
PERIPH_SERVICE_STATE_STOPPED,
} periph_service_state_t;
/**
* @brief Peripheral service event informations
*/
typedef struct {
int type; /*!< Type of event */
void *source; /*!< Event source */
void *data; /*!< Event data */
int len; /*!< Length of data */
} periph_service_event_t;
typedef struct periph_service_impl *periph_service_handle_t;
typedef esp_err_t (*periph_service_ctrl)(periph_service_handle_t handle);
typedef esp_err_t (*periph_service_io)(void *ioctl_handle, int cmd, int value);
typedef esp_err_t (*periph_service_cb)(periph_service_handle_t handle, periph_service_event_t *evt, void *ctx);
/**
* @brief Peripheral service configurations
*/
typedef struct {
int task_stack; /*!< >0 Service task stack; =0 with out task created */
int task_prio; /*!< Service task priority (based on freeRTOS priority) */
int task_core; /*!< Service task running in core (0 or 1) */
TaskFunction_t task_func; /*!< Service task function */
bool extern_stack; /*!< Task stack allocate on the extern ram */
periph_service_ctrl service_start; /*!< Start function */
periph_service_ctrl service_stop; /*!< Stop function */
periph_service_ctrl service_destroy; /*!< Destroy function */
periph_service_io service_ioctl; /*!< In out control function */
char *service_name; /*!< Name of peripheral service */
void *user_data; /*!< User data */
} periph_service_config_t;
/**
* brief Create peripheral service instance
*
* @param[in] config Configuration of the peripheral service instance
*
* @return
* - NULL, Fail
* - Others, Success
*/
periph_service_handle_t periph_service_create(periph_service_config_t *config);
/**
* brief Destroy peripheral service instance
*
* @param[in] handle The peripheral service instance
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t periph_service_destroy(periph_service_handle_t handle);
/**
* brief Start the specific peripheral service
*
* @param[in] handle The peripheral service instance
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t periph_service_start(periph_service_handle_t handle);
/**
* brief Stop the specific peripheral service
*
* @param[in] handle The peripheral service instance
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t periph_service_stop(periph_service_handle_t handle);
/**
* brief Set the specific peripheral service callback function
*
* @param[in] handle The peripheral service instance
* @param[in] cb A pointer to service_callback
* @param[in] ctx A pointer to user context
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t periph_service_set_callback(periph_service_handle_t handle, periph_service_cb cb, void *ctx);
/**
* brief Called peripheral service by configurations
*
* @param[in] handle The peripheral service instance
* @param[in] evt A pointer to periph_service_event_t
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t periph_service_callback(periph_service_handle_t handle, periph_service_event_t *evt);
/**
* brief Set user data to specific peripheral service instance
*
* @param[in] handle The peripheral service instance
* @param[in] data A pointer to user data
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t periph_service_set_data(periph_service_handle_t handle, void *data);
/**
* brief Get user data by specific peripheral service instance
*
* @param[in] handle The peripheral service instance
*
* @return A pointer to user data
*/
void *periph_service_get_data(periph_service_handle_t handle);
/**
* brief In/out control by peripheral service instance
*
* @param[in] handle The peripheral service instance
* @param[in] ioctl_handle Sub-instance handle
* @param[in] cmd Command of value
* @param[in] value Data of the command
*
* @return
* - ESP_OK
* - ESP_FAIL
* - ESP_ERR_INVALID_ARG
*/
esp_err_t periph_service_ioctl(periph_service_handle_t handle, void *ioctl_handle, int cmd, int value);
#ifdef __cplusplus
}
#endif
#endif // End of __PERIPH_SERVICE_H__
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/include/periph_service.h
|
C
|
apache-2.0
| 6,301
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "sys/queue.h"
#include "esp_log.h"
#include "periph_service.h"
#include "audio_mutex.h"
#include "audio_mem.h"
#include "audio_error.h"
#include "audio_thread.h"
static const char *TAG = "PERIPH_SERVICE";
/**
* @brief Peripheral service configurations
*/
typedef struct periph_service_impl {
periph_service_ctrl service_start;
periph_service_ctrl service_stop;
periph_service_ctrl service_destroy;
periph_service_io service_ioctl;
periph_service_cb callback_func;
void *user_cb_ctx;
char *service_name;
TaskHandle_t task_handle;
audio_thread_t audio_thread;
void *user_data;
} periph_service_impl_t;
periph_service_handle_t periph_service_create(periph_service_config_t *config)
{
AUDIO_NULL_CHECK(TAG, config, return NULL);
periph_service_handle_t impl = audio_calloc(1, sizeof(periph_service_impl_t));
AUDIO_MEM_CHECK(TAG, impl, return NULL);
impl->service_start = config->service_start;
impl->service_stop = config->service_stop;
impl->service_destroy = config->service_destroy;
impl->service_ioctl = config->service_ioctl;
impl->user_data = config->user_data;
if (config->service_name) {
impl->service_name = audio_strdup(config->service_name);
AUDIO_MEM_CHECK(TAG, impl, goto serv_failed);
}
if (config->task_stack > 0) {
if ( audio_thread_create(&impl->audio_thread,
config->service_name,
config->task_func,
impl,
config->task_stack,
config->task_prio,
config->extern_stack,
config->task_core) != ESP_OK) {
ESP_LOGE(TAG, "Create task failed on %s", __func__);
goto serv_failed;
}
}
return impl;
serv_failed:
audio_free(impl->service_name);
impl->service_name = NULL;
audio_free(impl);
impl = NULL;
return impl;
}
esp_err_t periph_service_destroy(periph_service_handle_t handle)
{
AUDIO_NULL_CHECK(TAG, handle, return ESP_ERR_INVALID_ARG);
periph_service_impl_t *impl = (periph_service_impl_t *) handle;
if (impl->service_destroy) {
impl->service_destroy(handle);
}
audio_free(impl->service_name);
impl->service_name = NULL;
impl->task_handle = NULL;
audio_free(impl);
impl = NULL;
return ESP_OK;
}
esp_err_t periph_service_start(periph_service_handle_t handle)
{
periph_service_impl_t *impl = (periph_service_impl_t *) handle;
AUDIO_NULL_CHECK(TAG, (handle && impl->service_start), return ESP_ERR_INVALID_ARG);
return impl->service_start(handle);
}
esp_err_t periph_service_stop(periph_service_handle_t handle)
{
periph_service_impl_t *impl = (periph_service_impl_t *) handle;
AUDIO_NULL_CHECK(TAG, (handle && impl->service_stop), return ESP_ERR_INVALID_ARG);
return impl->service_stop(handle);
}
esp_err_t periph_service_set_callback(periph_service_handle_t handle, periph_service_cb cb, void *ctx)
{
periph_service_impl_t *impl = (periph_service_impl_t *) handle;
impl->callback_func = cb;
impl->user_cb_ctx = ctx;
return ESP_OK;
}
esp_err_t periph_service_callback(periph_service_handle_t handle, periph_service_event_t *evt)
{
periph_service_impl_t *impl = (periph_service_impl_t *) handle;
AUDIO_NULL_CHECK(TAG, (handle && impl->callback_func), return ESP_ERR_INVALID_ARG);
return impl->callback_func(handle, evt, impl->user_cb_ctx);
}
esp_err_t periph_service_set_data(periph_service_handle_t handle, void *data)
{
AUDIO_NULL_CHECK(TAG, handle, return ESP_ERR_INVALID_ARG);
periph_service_impl_t *impl = (periph_service_impl_t *) handle;
impl->user_data = data;
return ESP_OK;
}
void *periph_service_get_data(periph_service_handle_t handle)
{
AUDIO_NULL_CHECK(TAG, handle, return NULL);
periph_service_impl_t *impl = (periph_service_impl_t *) handle;
return impl->user_data;
}
esp_err_t periph_service_ioctl(periph_service_handle_t handle, void *ioctl_handle, int cmd, int value)
{
periph_service_impl_t *impl = (periph_service_impl_t *) handle;
AUDIO_NULL_CHECK(TAG, (handle && impl->service_ioctl), return ESP_ERR_INVALID_ARG);
return impl->service_ioctl(ioctl_handle, cmd, value);
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/periph_service.c
|
C
|
apache-2.0
| 6,002
|
#
#Component Makefile
#
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/test/component.mk
|
Makefile
|
apache-2.0
| 112
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>
#include "unity.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_action_def.h"
#include "esp_delegate.h"
#include "esp_log.h"
#include "audio_thread.h"
static xQueueHandle que = NULL;
static esp_err_t delay(void *instance, action_arg_t *arg, action_result_t *result)
{
vTaskDelay(pdMS_TO_TICKS(100));
result->err = ESP_OK;
return result->err;
}
static void delegate_sync_task(void *args)
{
esp_dispatcher_handle_t dispatcher = (esp_dispatcher_handle_t)args;
action_result_t result = { 0 };
esp_dispatcher_execute_with_func(dispatcher, delay, NULL, NULL, &result);
TEST_ASSERT_EQUAL(ESP_OK, result.err);
int cmd = 0;
xQueueSend(que, &cmd, portMAX_DELAY);
vTaskDelete(NULL);
}
TEST_CASE("esp_dispatcher stress test sync", "esp-adf")
{
#define TASK_NUM (200)
int core_id = 0;
audio_thread_t thread = NULL;
esp_dispatcher_config_t d_cfg = ESP_DISPATCHER_CONFIG_DEFAULT();
d_cfg.stack_in_ext = false;
void *dispatcher = esp_dispatcher_create(&d_cfg);
que = xQueueCreate(10, sizeof(uint8_t));
for (int i = 0; i < TASK_NUM; i++) {
audio_thread_create(&thread, "sync", delegate_sync_task, dispatcher, 5 * 1024, 5, true, (core_id++) % 2);
}
for (int i = 0; i < TASK_NUM; i++) {
int cmd;
xQueueReceive(que, &cmd, portMAX_DELAY);
}
vQueueDelete(que);
esp_dispatcher_destroy(dispatcher);
}
static void invoke_cb(action_result_t ret, void *user_data)
{
int cmd = 0;
xQueueSend(que, &cmd, portMAX_DELAY);
}
static void delegate_async_task(void *args)
{
esp_dispatcher_handle_t dispatcher = (esp_dispatcher_handle_t)args;
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func_async(dispatcher, delay, NULL, NULL, invoke_cb, NULL));
vTaskDelete(NULL);
}
TEST_CASE("esp_dispatcher stress test async", "esp-adf")
{
#define TASK_NUM (200)
int core_id = 0;
audio_thread_t thread = NULL;
esp_dispatcher_config_t d_cfg = ESP_DISPATCHER_CONFIG_DEFAULT();
d_cfg.stack_in_ext = false;
void *dispatcher = esp_dispatcher_create(&d_cfg);
que = xQueueCreate(10, sizeof(uint8_t));
for (int i = 0; i < TASK_NUM; i++) {
audio_thread_create(&thread, "async", delegate_async_task, dispatcher, 5 * 1024, 5, true, (core_id++) % 2);
}
for (int i = 0; i < TASK_NUM; i++) {
int cmd;
xQueueReceive(que, &cmd, portMAX_DELAY);
}
vQueueDelete(que);
esp_dispatcher_destroy(dispatcher);
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/test/esp_dispatcher_stress_test.c
|
C
|
apache-2.0
| 3,776
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>
#include "unity.h"
#include "esp_dispatcher.h"
#include "esp_action_def.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "nvs_action.h"
TEST_CASE("esp_dispatcher sync set and read nvs", "esp-adf")
{
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
TEST_ASSERT_EQUAL(ESP_OK, err);
esp_dispatcher_config_t d_cfg = ESP_DISPATCHER_CONFIG_DEFAULT();
d_cfg.stack_in_ext = false;
esp_dispatcher_handle_t dispatcher = esp_dispatcher_create(&d_cfg);
TEST_ASSERT_NOT_NULL(dispatcher);
action_result_t result = { 0 };
nvs_handle nvs_sync_handle = NULL;
// Open
printf("Open NVS\n");
nvs_action_open_args_t open = {
.name = "action_sync",
.open_mode = NVS_READWRITE,
};
action_arg_t open_arg = {
.data = &open,
.len = sizeof(nvs_action_open_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_open, NULL, &open_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_NOT_NULL(result.data);
nvs_sync_handle = *(nvs_handle *)result.data;
free(result.data);
// Test u8
printf("Set U8\n");
nvs_action_set_args_t set_u8 = {
.key = "u8",
.type = NVS_TYPE_U8,
.value.u8 = 0xAB,
.len = sizeof(uint8_t),
};
action_arg_t set_u8_arg = {
.data = &set_u8,
.len = sizeof(nvs_action_set_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_set, (void *)nvs_sync_handle, &set_u8_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_commit, (void *)nvs_sync_handle, NULL, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
printf("Read U8\n");
nvs_action_get_args_t get_u8 = {
.key = "u8",
.type = NVS_TYPE_U8,
.wanted_size = sizeof(uint8_t),
};
action_arg_t get_u8_arg = {
.data = &get_u8,
.len = sizeof(nvs_action_get_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_get, (void *)nvs_sync_handle, &get_u8_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_NOT_NULL(result.data);
uint8_t *ret_u8 = (uint8_t *)result.data;
printf("Read [ 0x%X ] from nvs\n", *ret_u8);
free(result.data);
// Test i8
printf("Set I8\n");
nvs_action_set_args_t set_i8 = {
.key = "i8",
.type = NVS_TYPE_I8,
.value.i8 = -1,
.len = sizeof(int8_t),
};
action_arg_t set_i8_arg = {
.data = &set_i8,
.len = sizeof(nvs_action_set_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_set, (void *)nvs_sync_handle, &set_i8_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_commit, (void *)nvs_sync_handle, NULL, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
printf("Read I8\n");
nvs_action_get_args_t get_i8 = {
.key = "i8",
.type = NVS_TYPE_I8,
.wanted_size = sizeof(int8_t),
};
action_arg_t get_i8_arg = {
.data = &get_i8,
.len = sizeof(nvs_action_get_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_get, (void *)nvs_sync_handle, &get_i8_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_NOT_NULL(result.data);
int8_t *ret_i8 = (int8_t *)result.data;
printf("Read [ %d ] from nvs\n", *ret_i8);
free(result.data);
// Test u16
printf("Set U16\n");
nvs_action_set_args_t set_u16 = {
.key = "u16",
.type = NVS_TYPE_U16,
.value.u16 = 0xABCD,
.len = sizeof(uint16_t),
};
action_arg_t set_u16_arg = {
.data = &set_u16,
.len = sizeof(nvs_action_set_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_set, (void *)nvs_sync_handle, &set_u16_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_commit, (void *)nvs_sync_handle, NULL, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
printf("Read U16\n");
nvs_action_get_args_t get_u16 = {
.key = "u16",
.type = NVS_TYPE_U16,
.wanted_size = sizeof(uint16_t),
};
action_arg_t get_u16_arg = {
.data = &get_u16,
.len = sizeof(nvs_action_get_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_get, (void *)nvs_sync_handle, &get_u16_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_NOT_NULL(result.data);
uint16_t *ret_u16 = (uint16_t *)result.data;
printf("Read [ 0x%X ] from nvs\n", *ret_u16);
free(result.data);
// Test i16
printf("Set I16\n");
nvs_action_set_args_t set_i16 = {
.key = "i16",
.type = NVS_TYPE_I16,
.value.i16 = -2,
.len = sizeof(int16_t),
};
action_arg_t set_i16_arg = {
.data = &set_i16,
.len = sizeof(nvs_action_set_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_set, (void *)nvs_sync_handle, &set_i16_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_commit, (void *)nvs_sync_handle, NULL, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
printf("Read I16\n");
nvs_action_get_args_t get_i16 = {
.key = "i16",
.type = NVS_TYPE_I16,
.wanted_size = sizeof(int16_t),
};
action_arg_t get_i16_arg = {
.data = &get_i16,
.len = sizeof(nvs_action_get_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_get, (void *)nvs_sync_handle, &get_i16_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_NOT_NULL(result.data);
int16_t *ret_i16 = (int16_t *)result.data;
printf("Read [ %d ] from nvs\n", *ret_i16);
free(result.data);
// Test u32
printf("Set U32\n");
nvs_action_set_args_t set_u32 = {
.key = "u32",
.type = NVS_TYPE_U32,
.value.u32 = 0xABCDABCD,
.len = sizeof(uint32_t),
};
action_arg_t set_u32_arg = {
.data = &set_u32,
.len = sizeof(nvs_action_set_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_set, (void *)nvs_sync_handle, &set_u32_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_commit, (void *)nvs_sync_handle, NULL, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
printf("Read U32\n");
nvs_action_get_args_t get_u32 = {
.key = "u32",
.type = NVS_TYPE_U32,
.wanted_size = sizeof(uint32_t),
};
action_arg_t get_u32_arg = {
.data = &get_u32,
.len = sizeof(nvs_action_get_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_get, (void *)nvs_sync_handle, &get_u32_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_NOT_NULL(result.data);
uint32_t *ret_u32 = (uint32_t *)result.data;
printf("Read [ 0x%X ] from nvs\n", *ret_u32);
free(result.data);
// Test i16
printf("Set I32\n");
nvs_action_set_args_t set_i32 = {
.key = "i32",
.type = NVS_TYPE_I32,
.value.i32 = -3,
.len = sizeof(int32_t),
};
action_arg_t set_i32_arg = {
.data = &set_i32,
.len = sizeof(nvs_action_set_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_set, (void *)nvs_sync_handle, &set_i32_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_commit, (void *)nvs_sync_handle, NULL, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
printf("Read I32\n");
nvs_action_get_args_t get_i32 = {
.key = "i32",
.type = NVS_TYPE_I32,
.wanted_size = sizeof(int32_t),
};
action_arg_t get_i32_arg = {
.data = &get_i32,
.len = sizeof(nvs_action_get_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_get, (void *)nvs_sync_handle, &get_i32_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_NOT_NULL(result.data);
int32_t *ret_i32 = (int32_t *)result.data;
printf("Read [ %d ] from nvs\n", *ret_i32);
free(result.data);
// Test String
printf("Set string\n");
nvs_action_set_args_t set_str = {
.key = "string",
.type = NVS_TYPE_STR,
.value.string = "Hello ESP dispatcher",
.len = strlen("Hello ESP dispatcher"),
};
action_arg_t set_str_arg = {
.data = &set_str,
.len = sizeof(nvs_action_set_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_set, (void *)nvs_sync_handle, &set_str_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_commit, (void *)nvs_sync_handle, NULL, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
printf("Read string\n");
nvs_action_get_args_t get_str = {
.key = "string",
.type = NVS_TYPE_STR,
.wanted_size = 128,
};
action_arg_t get_str_arg = {
.data = &get_str,
.len = sizeof(nvs_action_get_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_get, (void *)nvs_sync_handle, &get_str_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_NOT_NULL(result.data);
char *ret_str = (char *)result.data;
printf("Read [ %s ] from nvs\n", ret_str);
free(result.data);
// Test Blob
typedef struct {
int8_t i8;
int16_t i16;
int32_t i32;
} data_t;
data_t dat = {
.i8 = 0x11,
.i16 = 0x2222,
.i32 = 0x33333333,
};
printf("Set blob\n");
nvs_action_set_args_t set_blob = {
.key = "blob",
.type = NVS_TYPE_BLOB,
.value.blob = &dat,
.len = sizeof(data_t),
};
action_arg_t set_blob_arg = {
.data = &set_blob,
.len = sizeof(nvs_action_set_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_set, (void *)nvs_sync_handle, &set_blob_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_commit, (void *)nvs_sync_handle, NULL, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
printf("Read blob\n");
nvs_action_get_args_t get_blob = {
.key = "blob",
.type = NVS_TYPE_BLOB,
.wanted_size = sizeof(data_t),
};
action_arg_t get_blob_arg = {
.data = &get_blob,
.len = sizeof(nvs_action_get_args_t),
};
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_get, (void *)nvs_sync_handle, &get_blob_arg, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_NOT_NULL(result.data);
data_t *ret_blob = (data_t *)result.data;
printf("Read [ 0x%X, 0x%X, 0x%X ] from nvs\n", ret_blob->i8, ret_blob->i16, ret_blob->i32);
free(result.data);
// Close
printf("Close NVS\n");
memset(&result, 0x00, sizeof(action_result_t));
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_execute_with_func(dispatcher, nvs_action_close, (void *)nvs_sync_handle, NULL, &result));
TEST_ASSERT_EQUAL(ESP_OK, result.err);
TEST_ASSERT_EQUAL(ESP_OK, esp_dispatcher_destroy(dispatcher));
TEST_ASSERT_EQUAL(ESP_OK, nvs_flash_deinit());
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_dispatcher/test/esp_dispatcher_with_nvs_actions_test.c
|
C
|
apache-2.0
| 14,745
|
set(COMPONENT_SRCS "esp_event_cast.c")
set(COMPONENT_ADD_INCLUDEDIRS include)
set(COMPONENT_REQUIRES audio_sal)
register_component()
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_event_cast/CMakeLists.txt
|
CMake
|
apache-2.0
| 136
|
#
# Main Makefile. This is basically the same as a component makefile.
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_SRCDIRS := .
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_event_cast/component.mk
|
Makefile
|
apache-2.0
| 131
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "audio_mutex.h"
#include "esp_event_cast.h"
#include "sys/queue.h"
#include "audio_mem.h"
#include "audio_error.h"
#include "esp_log.h"
static const char *TAG = "EVT_CAST";
typedef struct esp_evt_cast_item {
STAILQ_ENTRY(esp_evt_cast_item) next;
xQueueHandle que;
} esp_evt_cast_item_t;
typedef STAILQ_HEAD(esp_event_cast_list, esp_evt_cast_item) esp_event_cast_list_t;
typedef struct esp_event_cast {
xSemaphoreHandle _mux;
esp_event_cast_list_t evt_list;
} esp_event_cast_t;
esp_event_cast_handle_t esp_event_cast_create(void)
{
esp_event_cast_handle_t obj = audio_calloc(1, sizeof(esp_event_cast_t));
AUDIO_NULL_CHECK(TAG, obj, return NULL);
obj->_mux = mutex_create();
AUDIO_NULL_CHECK(TAG, obj->_mux, {audio_free(obj);
return NULL;
});
STAILQ_INIT(&obj->evt_list);
return obj;
}
esp_err_t esp_event_cast_destroy(esp_event_cast_handle_t handle)
{
if (handle) {
esp_evt_cast_item_t *item, *tmp;
STAILQ_FOREACH_SAFE(item, &handle->evt_list, next, tmp) {
STAILQ_REMOVE(&handle->evt_list, item, esp_evt_cast_item, next);
audio_free(item);
}
mutex_destroy(handle->_mux);
free(handle);
return ESP_OK;
}
return ESP_FAIL;
}
esp_err_t esp_event_cast_register(esp_event_cast_handle_t handle, xQueueHandle que)
{
if ((handle == NULL) || (que == NULL)) {
ESP_LOGE(TAG, "func:%s, invalid parameters, handle=%p, que=%p", __func__, handle, que);
return ESP_FAIL;
}
esp_evt_cast_item_t *local_list = audio_calloc(1, sizeof(esp_evt_cast_item_t));
AUDIO_MEM_CHECK(TAG, local_list, {return ESP_FAIL;});
mutex_lock(handle->_mux);
local_list->que = que;
STAILQ_INSERT_TAIL(&handle->evt_list, local_list, next);
mutex_unlock(handle->_mux);
ESP_LOGD(TAG, "INERT, list[%p], que:%p", handle, que);
return ESP_OK;
}
esp_err_t esp_event_cast_unregister(esp_event_cast_handle_t handle, xQueueHandle que)
{
if ((handle == NULL) || (que == NULL)) {
ESP_LOGE(TAG, "func:%s, invalid parameters, handle=%p, que=%p", __func__, handle, que);
return ESP_FAIL;
}
mutex_lock(handle->_mux);
esp_evt_cast_item_t *item, *tmp;
STAILQ_FOREACH_SAFE(item, &handle->evt_list, next, tmp) {
ESP_LOGD(TAG, "func:%s, list=%p, que=%p, target que:%p", __func__, item, item->que, que);
if (item->que == que) {
STAILQ_REMOVE(&handle->evt_list, item, esp_evt_cast_item, next);
audio_free(item);
break;
}
}
mutex_unlock(handle->_mux);
ESP_LOGD(TAG, "func:%s, que size=%d", __func__, esp_event_cast_get_count(handle));
return 0;
}
esp_err_t esp_event_cast_broadcasting(esp_event_cast_handle_t handle, void *data)
{
if ((handle == NULL) || (data == NULL)) {
ESP_LOGE(TAG, "func:%s, invalid parameters, handle=%p, data=%p", __func__, handle, data);
return ESP_FAIL;
}
mutex_lock(handle->_mux);
esp_evt_cast_item_t *item, *tmp;
STAILQ_FOREACH_SAFE(item, &handle->evt_list, next, tmp) {
ESP_LOGD(TAG, "func:%s, list=%p, que=%p, data:%p", __func__, item, item->que, data);
if (item->que) {
if (pdFALSE == xQueueSend(item->que, data, 0)) {
ESP_LOGW(TAG, "Queue[%p] send failed, free size:%d", item->que, uxQueueSpacesAvailable(item->que));
}
}
}
mutex_unlock(handle->_mux);
return 0;
}
esp_err_t esp_event_cast_broadcasting_isr(esp_event_cast_handle_t handle, void *data)
{
if ((handle == NULL) || (data == NULL)) {
ESP_EARLY_LOGE(TAG, "func:%s, invalid parameters, handle=%p, data=%p", __func__, handle, data);
return ESP_FAIL;
}
mutex_lock(handle->_mux);
esp_evt_cast_item_t *item, *tmp;
STAILQ_FOREACH_SAFE(item, &handle->evt_list, next, tmp) {
if (item->que) {
if (pdFALSE == xQueueSendFromISR(item->que, data, 0)) {
ESP_EARLY_LOGW(TAG, "Queue[%p] send failed, free size:%d", item->que, uxQueueSpacesAvailable(item->que));
}
}
}
mutex_unlock(handle->_mux);
return 0;
}
esp_err_t esp_event_cast_get_count(esp_event_cast_handle_t handle)
{
if (handle == NULL) {
ESP_LOGE(TAG, "func:%s, invalid parameters, handle=%p", __func__, handle);
return ESP_FAIL;
}
mutex_lock(handle->_mux);
int cnt = 0;
esp_evt_cast_item_t *item, *tmp;
STAILQ_FOREACH_SAFE(item, &handle->evt_list, next, tmp) {
cnt ++;
}
mutex_unlock(handle->_mux);
return cnt;
}
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_event_cast/esp_event_cast.c
|
C
|
apache-2.0
| 6,193
|
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __ESP_EVENT_CAST_H__
#define __ESP_EVENT_CAST_H__
typedef struct esp_event_cast *esp_event_cast_handle_t;
/**
* @brief Create esp_event_cast instance
*
* @return
* - Valid pointer on success
* - NULL when any errors
*/
esp_event_cast_handle_t esp_event_cast_create(void);
/**
* @brief Destroy the specific esp_event_cast instance
*
* @praram handle: A poniter to esp_event_cast_handle_t
*
* @return
* - ESP_OK: success
* - ESP_FAIL: Parameter is NULL
*/
esp_err_t esp_event_cast_destroy(esp_event_cast_handle_t handle);
/**
* @brief Add queue to esp_event_cast_handle_t object
*
* @param handle: A poniter to esp_event_cast_handle_t
* @praram que: The specific queue as receiver added to esp_event_cast_handle_t instance
*
* @return
* - ESP_OK: success
* - ESP_FAIL: others
*/
esp_err_t esp_event_cast_register(esp_event_cast_handle_t handle, xQueueHandle que);
/**
* @brief Remove queue item from esp_event_cast_handle_t object, but does't delete the queue
*
* @param handle : A poniter to esp_event_cast_handle_t
* @praram que: A queue will be removed from `handle` instance
*
* @return
* - ESP_OK: success
* - ESP_FAIL: others
*/
esp_err_t esp_event_cast_unregister(esp_event_cast_handle_t handle, xQueueHandle que);
/**
* @brief Broadcasting the data to receiver
*
* @param handle: A poniter to esp_event_cast_handle_t
* @param data: Data packet will be broadcasting
*
* @return
* - ESP_OK: success
* - ESP_FAIL: others
*/
esp_err_t esp_event_cast_broadcasting(esp_event_cast_handle_t handle, void *data);
/**
* @brief Broadcasting the data to receiver from ISR
*
* @note This API is untested
*
* @param handle: A poniter to esp_event_cast_handle_t
* @param data: Data packet will be broadcasting
*
* @return
* - ESP_OK: success
* - ESP_FAIL: others
*/
esp_err_t esp_event_cast_broadcasting_isr(esp_event_cast_handle_t handle, void *data);
/**
* @brief Get the count of registered receiver
*
* @param handle: A poniter to esp_event_cast_handle_t
*
* @return
* - ESP_FAIL: Fail
* - Others: Number of registered receiver
*/
esp_err_t esp_event_cast_get_count(esp_event_cast_handle_t handle);
#endif //__ESP_EVENT_CAST_H__
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_event_cast/include/esp_event_cast.h
|
C
|
apache-2.0
| 3,518
|
#
#Component Makefile
#
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
YifuLiu/AliOS-Things
|
hardware/chip/espressif_adf/esp-adf/components/esp_event_cast/test/component.mk
|
Makefile
|
apache-2.0
| 112
|