chore: migrate project into clean repository

This commit is contained in:
yuuux
2026-08-13 16:50:52 +08:00
commit d1d25a09e7
27405 changed files with 9422808 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
if (CONFIG_ACOMP)
listenai_library_sources(
acomp_wsp.c
)
listenai_include_directories(
./
)
endif()

View File

@@ -0,0 +1,345 @@
#include <string.h>
#include "ipc/acomp_ipc.h"
#include "acomp_wsp.h"
#include "acomp_err.h"
#include "gcl_cb_list/gcl_cb_list.h"
#include "private/wsp_ipc.h"
#include "acomp_stream_ipc.h"
#define TAG "acomp_wsp"
#include "lisa_log.h"
#define ACOMP_WSP_DEV_NAME "acomp.wsp"
typedef struct {
uint32_t dev_index;
gcl_cb_list_t event_callbacks;
acomp_stream_t *stream;
} acomp_wsp_handle_t;
static acomp_wsp_handle_t *wsp_handle = NULL;
void event_callback(acomp_ipc_message_t *message, void *priv)
{
acomp_wsp_handle_t *handle = (acomp_wsp_handle_t *)priv;
if (handle == NULL) {
return;
}
if (message->hdr.hdr.cmd == ACOMP_CONTEXT_IPC_GLB_NOTIFY) {
if (message->acomp_cmd == ACOMP_IPC_CMD_NOTIFY_RESULT) {
if (((void *)message->address != NULL) && (message->len > 0)) {
acomp_ipc_notify_result_t *result = (acomp_ipc_notify_result_t *)message->address;
gcl_cb_event_dispatch(handle->event_callbacks, WSP_CB_EVENT_ENGINE_RLT, result->data, result->len);
}
} else if (message->acomp_cmd == ACOMP_IPC_CMD_NOTIFY_SUBCMD) {
if (((void *)message->address != NULL) && (message->len > 0)) {
acomp_ipc_notify_subcmd_t *subcmd = (acomp_ipc_notify_subcmd_t *)message->address;
wsp_ipc_notify_subcmd_hdr_t *hdr = (wsp_ipc_notify_subcmd_hdr_t *)subcmd->data;
if ((hdr->cmd == WSP_IPC_NOTIFY_SUBCMD_VAD_BEGIN) || (hdr->cmd == WSP_IPC_NOTIFY_SUBCMD_VAD_END)) {
wsp_ipc_notify_subcmd_vad_t *vad = (wsp_ipc_notify_subcmd_vad_t *)subcmd->data;
if (vad->hdr.cmd == WSP_IPC_NOTIFY_SUBCMD_VAD_BEGIN) {
gcl_cb_event_dispatch(handle->event_callbacks, WSP_CB_EVENT_ENGINE_VAD_BEGIN, &vad->frame_idx,
sizeof(vad->frame_idx));
} else if (vad->hdr.cmd == WSP_IPC_NOTIFY_SUBCMD_VAD_END) {
gcl_cb_event_dispatch(handle->event_callbacks, WSP_CB_EVENT_ENGINE_VAD_END, &vad->frame_idx,
sizeof(vad->frame_idx));
}
}
else{
LISA_LOGW(TAG,"unknow notify hdr cmd:%d",hdr->cmd);
}
}
}
else if(message->acomp_cmd == ACOMP_IPC_CMD_NOTIFY_STREAM_UPDATE){
if (((void *)message->address != NULL) && (message->len > 0)) {
acomp_ipc_stream_update_t *ipc_msg;
uint32_t chn;
ipc_msg = (acomp_ipc_stream_update_t *)message->address;
chn = ipc_msg->index;
if(chn < sizeof(handle->stream->ch)/sizeof(handle->stream->ch[0])){
gcl_cb_event_dispatch(handle->event_callbacks,
WSP_CB_EVENT_STREAM_UPDATE,
handle->stream->ch[chn],
sizeof(acomp_stream_channel_t));
}
}
}
}
}
int acomp_wsp_init(void)
{
int ret = 0;
if (wsp_handle != NULL) {
return ACOMP_ERR_INVALID_STATE;
}
wsp_handle = (acomp_wsp_handle_t *)psram_malloc(sizeof(acomp_wsp_handle_t));
if (wsp_handle == NULL) {
return ACOMP_ERR_NO_MEM;
}
memset(wsp_handle, 0, sizeof(acomp_wsp_handle_t));
wsp_handle->event_callbacks = gcl_cb_list_create();
wsp_handle->dev_index = acomp_ipc_get_dev_index(ACOMP_WSP_DEV_NAME);
if (wsp_handle->dev_index < 0) {
psram_free(wsp_handle);
wsp_handle = NULL;
LISA_LOGE(TAG, "acomp wsp dev index not found!");
return ACOMP_ERR_NOT_FOUND;
}
LISA_LOGI(TAG, "acomp wsp dev index %d,name:%s", wsp_handle->dev_index, ACOMP_WSP_DEV_NAME);
ret = acomp_ipc_add_callback(wsp_handle->dev_index, (ipc_event_cb_t)event_callback, wsp_handle);
if (ret != ACOMP_ERR_OK) {
return ret;
}
ret = acomp_ipc_build_frame_send_sync(wsp_handle->dev_index, ACOMP_CONTEXT_IPC_GLB_NEW | IPC_HEADER_REQ_REPALY, 0,
0, NULL, 0);
if (ret != ACOMP_ERR_OK) {
return ret;
}
wsp_handle->stream = acomp_stream_create(wsp_handle->dev_index );
if(wsp_handle->stream == NULL){
return ACOMP_ERR_CREATE_STREAM_FAILED;
}
return 0;
}
int acomp_wsp_deinit(void)
{
/*TODO*/
return ACOMP_ERR_NOT_SUPPORTED;
}
int acomp_wsp_prepare(void)
{
#define ACOMP_WSP_RES_NUMBER (2)
#define WSP_INDEX_MLP_ENCODER (1)
#define WSP_INDEX_MLP_DECODER (2)
acomp_ipc_prepare_t *prepare;
uint32_t size;
int ret;
size = sizeof(acomp_ipc_prepare_t) + sizeof(acomp_res_item_t) * ACOMP_WSP_RES_NUMBER;
prepare = psram_malloc_align(IPC_ALIGN_SIZE, size);
if (prepare == NULL) {
return ACOMP_ERR_NO_MEM;
}
memset(prepare, 0, sizeof(acomp_ipc_prepare_t));
prepare->number = ACOMP_WSP_RES_NUMBER;
prepare->item[0].index = WSP_INDEX_MLP_ENCODER;
prepare->item[0].addr = CONFIG_ACOMP_WSP_RES_ENCODER_ADDRESS;
prepare->item[0].offset = 0;
prepare->item[0].size = CONFIG_ACOMP_WSP_RES_ENCODER_LENGTH;
prepare->item[1].index = WSP_INDEX_MLP_DECODER;
prepare->item[1].addr = CONFIG_ACOMP_WSP_RES_DECODER_ADDRESS;
prepare->item[1].offset = 0;
prepare->item[1].size = CONFIG_ACOMP_WSP_RES_DECODER_LENGTH;
ret = acomp_ipc_build_frame_send_sync(wsp_handle->dev_index, ACOMP_CONTEXT_IPC_GLB_CONTROL | IPC_HEADER_REQ_REPALY,
ACOMP_IPC_CMD_PREPARE, 0, prepare, size);
psram_free(prepare);
return ret;
}
int acomp_wsp_cleanup(void)
{
int ret;
ret = acomp_ipc_build_frame_send_sync(wsp_handle->dev_index, ACOMP_CONTEXT_IPC_GLB_CONTROL | IPC_HEADER_REQ_REPALY,
ACOMP_IPC_CMD_CLEANUP, 0, NULL, 0);
return ret;
}
int acomp_wsp_start(void)
{
int ret;
ret = acomp_ipc_build_frame_send_sync(wsp_handle->dev_index, ACOMP_CONTEXT_IPC_GLB_CONTROL | IPC_HEADER_REQ_REPALY,
ACOMP_IPC_CMD_START, 0, NULL, 0);
return ret;
}
int acomp_wsp_stop(void)
{
int ret;
ret = acomp_ipc_build_frame_send_sync(wsp_handle->dev_index, ACOMP_CONTEXT_IPC_GLB_CONTROL | IPC_HEADER_REQ_REPALY,
ACOMP_IPC_CMD_STOP, 0, NULL, 0);
return ret;
}
int acomp_wsp_params_set(acomp_wsp_params_t *params)
{
int ret;
ret = acomp_ipc_build_frame_send_sync(wsp_handle->dev_index, ACOMP_CONTEXT_IPC_GLB_CONTROL | IPC_HEADER_REQ_REPALY,
ACOMP_IPC_CMD_CONTROL, 0, params, sizeof(acomp_wsp_params_t));
return ret;
}
int acomp_wsp_add_callback(uint32_t events, wsp_event_cb_t cb, void *priv)
{
int ret;
if (wsp_handle == NULL) {
return ACOMP_ERR_INVALID_STATE;
}
ret = gcl_cb_list_add_callback(wsp_handle->event_callbacks, events, cb, priv);
return ret;
}
int acomp_wsp_remove_callback(wsp_event_cb_t cb)
{
int ret;
if (wsp_handle == NULL) {
return ACOMP_ERR_INVALID_STATE;
}
ret = gcl_cb_list_remove(wsp_handle->event_callbacks, cb);
return ret;
}
int acomp_wsp_stream_ch_enable(int chn,acomp_stream_chn_create_desc_t *desc){
int ret = 0;
if ((wsp_handle == NULL) || (wsp_handle->stream == NULL)) {
return ACOMP_ERR_INVALID_STATE;
}
if(chn >= ACOMP_STREAM_MAX_CHANNEL){
return ACOMP_ERR_INVALID_ARG;
}
wsp_handle->stream->ch[chn] = acomp_stream_ipc_channel_create(wsp_handle->stream,chn,wsp_handle->dev_index,desc);
if(wsp_handle->stream->ch[chn] == NULL){
return ACOMP_ERR_CREATE_STREAM_FAILED;
}
LISA_LOGI(TAG,"acomp_wsp_stream_ch_enable chn(%s) index(%d),desc(%p)",desc->cname,chn,desc);
return ret;
}
int acomp_wsp_stream_ch_disable(int chn){
int ret;
if (wsp_handle == NULL) {
return ACOMP_ERR_INVALID_STATE;
}
if(chn >= ACOMP_STREAM_MAX_CHANNEL){
return ACOMP_ERR_INVALID_ARG;
}
ret = acomp_stream_ipc_channel_destroy(chn);
LISA_LOGI(TAG,"acomp_wsp_stream_ch_disable chn index(%d),ret(%d)",chn,ret);
wsp_handle->stream->ch[chn] = NULL;
return ret;
}
void* acomp_wsp_stream_rx_buffer_get(int chn, uint32_t* len, uint16_t* desc_idx){
uint8_t *ptr;
if (wsp_handle == NULL) {
return NULL;
}
if(chn >= ACOMP_STREAM_MAX_CHANNEL){
return NULL;
}
if(wsp_handle->stream->ch[chn] == NULL){
return NULL;
}
ptr = wsp_handle->stream->ops.rx_buffer_get(wsp_handle->stream->ch[chn], len, desc_idx);
return ptr;
}
int acomp_wsp_stream_rx_buffer_release(int chn, uint16_t desc_idx, uint32_t len,void* buffer){
int ret;
if (wsp_handle == NULL) {
return ACOMP_ERR_INVALID_STATE;
}
if(chn >= ACOMP_STREAM_MAX_CHANNEL){
return ACOMP_ERR_INVALID_ARG;
}
ret = wsp_handle->stream->ops.rx_buffer_release(wsp_handle->stream->ch[chn],buffer, len, desc_idx);
return ret;
}
void* acomp_wsp_stream_tx_buffer_alloc(int chn, uint32_t* len, uint16_t* desc_idx){
uint8_t* buffer;
if (wsp_handle == NULL) {
return NULL;
}
if(chn >= ACOMP_STREAM_MAX_CHANNEL){
return NULL;
}
if(wsp_handle->stream->ch[chn] == NULL){
return NULL;
}
buffer = wsp_handle->stream->ops.tx_buffer_alloc(wsp_handle->stream->ch[chn], len, desc_idx);
return buffer;
}
int acomp_wsp_stream_tx_buffer_submit(int chn, void* buffer, uint32_t len, uint16_t desc_idx){
int ret;
if (wsp_handle == NULL) {
return ACOMP_ERR_INVALID_STATE;
}
if(chn >= ACOMP_STREAM_MAX_CHANNEL){
return ACOMP_ERR_INVALID_ARG;
}
if(wsp_handle->stream->ch[chn] == NULL){
return ACOMP_ERR_INVALID_STATE;
}
ret = wsp_handle->stream->ops.tx_buffer_submit(wsp_handle->stream->ch[chn], buffer, len, desc_idx);
return ret;
}
int acomp_virtqueue_dump(int chn)
{
virtqueue_dump(wsp_handle->stream->ch[chn]->vq);
return 0;
}

View File

@@ -0,0 +1,189 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "comm/stream/acomp_stream_ipc.h"
#include "utils/acomp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef BIT
#define BIT(x) (1 << (x))
#endif
/*WSP组件音频帧大小 BYTES*/
#define WSP_FRAME_BYTES (320)
typedef struct {
int32_t alg_wsp_en; /* 0-CSP OFF; 1-CSP ON */
int32_t alg_vad_en; /* 0-VAD OFF; 1-VAD ON */
int32_t alg_vad_threshold; /* Vad门限 */
int32_t alg_vad_gap; /* Vad的末端点GAP */
int32_t adc_a_gain; /* ADC 模块的模拟增益*/
int32_t adc_d_gain; /* ADC 模块的数字增益*/
int32_t stream_cut_front_ms; /* 裁剪启动后音频数据的长度,单位为ms*/
int32_t stream_cut_last_ms; /* 裁剪停止前音频数据的长度,单位为ms*/
int32_t stream_direction; /* 音频流方向,0:Capture使用MIC采集音频,1:playback外部输入音频*/
int32_t stream_channel_index; /* 录音通道号,0:左声道有效,1:右声道有效*/
} __attribute__((packed)) acomp_wsp_params_t;
typedef enum{
COMP_WSP_RESULT_TYPE_UNKNOWN = 0,
COMP_WSP_RESULT_TYPE_STREAM,
COMP_WSP_RESULT_TYPE_FINISH,
}comp_wsp_result_type_e;
typedef struct{
comp_wsp_result_type_e type;
uint32_t len;
uint8_t data[];
}__attribute__((packed)) comp_wsp_result_t;
typedef struct {
int32_t mlp_res_type; /* 引擎声学模型类型*/
char version[64]; /* 引擎版本信息*/
} __attribute__((packed)) wsp_gcl_info_t;
/*发音拼读组件回调事件定义*/
#define WSP_CB_EVENT_STREAM_UPDATE BIT(0) /*音频数据流更新*/
#define WSP_CB_EVENT_ENGINE_RLT BIT(4) /*发音拼读引擎结果返回*/
#define WSP_CB_EVENT_ENGINE_VAD_BEGIN BIT(5) /*VAD检测起始*/
#define WSP_CB_EVENT_ENGINE_VAD_END BIT(6) /*VAD检测结束*/
#define WSP_CB_EVENT_ENGINE_WR_ERR BIT(7) /*算法引擎数据写入出错*/
typedef void (*wsp_event_cb_t)(uint32_t event, void *event_data, uint32_t event_data_len, void *priv);
/**
* @brief 初始化发音拼读组件(WSP)
*
* @return ACOMP_ERR_OK : 成功
* @retval ACOMP_ERR_NO_MEM : 没有足够内存
* @retval ACOMP_ERR_INVALID_STATE : 无效状态
* @retval ACOMP_ERR_NOT_FOUND : 设备未找到
*
*/
extern int acomp_wsp_init(void);
// /**
// * @brief 逆初始化发音拼读组件(WSP)
// *
// * @return GCL_OK : 成功
// * @retval -GCL_ERR_COMM_FAIL(209) : 通讯失败
// *
// */
// extern int acomp_wsp_deinit(void);
/**
* @brief 就绪发音拼读组件(WSP)
*
* @note 该函数会初始化内存块及算法资源,在调用wsp_gcl_start之前,必须调用该函数让组件进入就绪状态。
*
* @return ACOMP_ERR_OK : 成功
* @retval ACOMP_ERR_NO_MEM : 没有足够内存
* @retval ACOMP_ERR_INVALID_STATE : 无效状态
*
*/
extern int acomp_wsp_prepare(void);
/**
* @brief 复位发音拼读组件(WSP)
*
* @note 该函数会释放内存块及算法资源。
*
* @return ACOMP_ERR_OK : 成功
* @retval ACOMP_ERR_INVALID_STATE : 无效状态
*
*/
extern int acomp_wsp_cleanup(void);
/**
* @brief 启动发音拼读组件(WSP)
*
* @note 该函数会启动发音拼读组件,同步会启动音频流传输
*
* @return ACOMP_ERR_OK : 成功
* @retval ACOMP_ERR_NO_MEM : 没有足够内存
* @retval ACOMP_ERR_INVALID_STATE : 无效状态
*
*/
extern int acomp_wsp_start(void);
/**
* @brief 停止发音拼读组件(WSP)
*
* @note 该函数会停止发音拼读组件,同步会停止音频流传输
*
* @return ACOMP_ERR_OK : 成功
* @retval ACOMP_ERR_NO_MEM : 没有足够内存
* @retval ACOMP_ERR_INVALID_STATE : 无效状态
*
*/
extern int acomp_wsp_stop(void);
/**
* @brief 设置组件参数
*
* @note 设置组件参数信息,该参数项将在组件进入就绪态时生效(调用wsp_gcl_prepare())。
*
* @param params[in] 存储参数的结构指针
*
* @return ACOMP_ERR_OK : 成功
* @retval ACOMP_ERR_INVALID_ARG : 错误参数
* @retval ACOMP_ERR_INVALID_STATE : 无效状态
*
*/
extern int acomp_wsp_params_set(acomp_wsp_params_t *params);
/**
* @brief 写入音频数据
*
* @note 只有当参数(stream_direction)设置为1(playback)时,可以使用该接口向engine输入音频数据
*
* @param data[in] 音频数据指针
* @param len[in] 数据长度,固定为WSP_FRAME_BYTES(320 bytes)
*
* @return ACOMP_ERR_OK : 成功
* @retval ACOMP_ERR_NO_MEM : 没有足够内存
* @retval ACOMP_ERR_INVALID_ARG : 错误参数
* @retval ACOMP_ERR_INVALID_STATE : 无效状态
*
*/
// extern int acomp_wsp_stream_write(uint8_t* data,uint32_t len);
/**
* @brief 给组件增加事件回调函数
*
* @param events[in] 待增加的事件位,可以同步注册多个事件位;
* @param cb[in] 回调的函数指针;
* @param priv[in] 回调函数的私有数据指针;
*
* @return ACOMP_ERR_OK : 成功
* @retval ACOMP_ERR_NO_MEM : 没有足够内存
* @retval ACOMP_ERR_INVALID_ARG : 错误参数
* @retval ACOMP_ERR_INVALID_STATE : 无效状态
*
*/
extern int acomp_wsp_add_callback(uint32_t events, wsp_event_cb_t cb, void *priv);
/**
* @brief 移除组件的毁掉函数
*
* @param cb[in] 待移除的回调函数
*
* @return ACOMP_ERR_OK : 成功
* @retval ACOMP_ERR_INVALID_ARG : 错误参数
* @retval ACOMP_ERR_INVALID_STATE : 无效状态
* @retval ACOMP_ERR_NOT_SUPPORTED : 无效操作
*
*
*/
extern int acomp_wsp_remove_callback(wsp_event_cb_t cb);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum{
WSP_IPC_NOTIFY_SUBCMD_VAD_BEGIN = 1,
WSP_IPC_NOTIFY_SUBCMD_VAD_END = 2,
}wsp_ipc_notify_subcmd_e;
typedef struct{
wsp_ipc_notify_subcmd_e cmd;
}__attribute__((packed)) wsp_ipc_notify_subcmd_hdr_t;
typedef struct{
wsp_ipc_notify_subcmd_hdr_t hdr;
uint32_t frame_idx;
}__attribute__((packed,aligned(32))) wsp_ipc_notify_subcmd_vad_t;
#ifdef __cplusplus
}
#endif