megre voice sdk
This commit is contained in:
parent
9ec2876c1c
commit
49af68ba9e
|
@ -0,0 +1,35 @@
|
|||
DESCRIPTION = "mic-asp"
|
||||
LICENSE = "MediaTekProprietary"
|
||||
APPS_SRC = "${TOPDIR}/../src/apps/aud-base/mic_asp"
|
||||
|
||||
inherit workonsrc systemd
|
||||
|
||||
WORKONSRC = "${APPS_SRC}"
|
||||
|
||||
SYSTEMD_PACKAGES = "${PN}"
|
||||
SYSTEMD_SERVICE_${PN} = "mic_asp.service"
|
||||
|
||||
do_compile() {
|
||||
echo "Print Env"
|
||||
|
||||
cd ${S} && make
|
||||
}
|
||||
|
||||
do_install() {
|
||||
install -d ${D}/usr/lib64
|
||||
install -d ${D}${bindir}
|
||||
install -d ${D}${systemd_unitdir}/system
|
||||
install -d ${D}/data
|
||||
#install -d ${D}/data/res
|
||||
cp -a ${S}/res ${D}/data/
|
||||
install -m 0644 ${S}libs/libaiwrap_6mic_c500.so ${D}/usr/lib64/
|
||||
install -m 0644 ${S}libs/lib6mic_circle.so ${D}/usr/lib64/
|
||||
install -m 755 ${S}/mic_asp ${D}${bindir}
|
||||
install -m 755 ${S}/mic_asp.service ${D}${systemd_unitdir}/system
|
||||
}
|
||||
|
||||
FILES_${PN} += "/usr/lib64 /data/res"
|
||||
FILES_${PN} += "${systemd_unitdir}/system/mic_asp.service"
|
||||
INSANE_SKIP_${PN} += "already-stripped ldflags"
|
||||
FILES_${PN}-dev = ""
|
||||
|
|
@ -32,6 +32,7 @@ IMAGE_INSTALL_append = " \
|
|||
prog \
|
||||
ntpdate \
|
||||
appmainprog \
|
||||
mic-asp \
|
||||
ppc \
|
||||
ppccli \
|
||||
mtk-audio-service \
|
||||
|
|
|
@ -26,8 +26,9 @@ mk_userdata_image() {
|
|||
rm -rf ${IMAGE_ROOTFS}/usr/lib/public/bluetooth_hfp/Sleep_Away.mp3
|
||||
fi
|
||||
|
||||
|
||||
cp -a ${IMAGE_ROOTFS}/data/res ${STATE_DIR_CONTENT}
|
||||
cp -a ${IMAGE_ROOTFS}/etc/wpa_supplicant.conf ${STATE_DIR_CONTENT}/etc/wpa_supplicant.conf
|
||||
rm -rf ${IMAGE_ROOTFS}/data/res
|
||||
#rm -rf ${IMAGE_ROOTFS}/usr/bin/*.coreutils
|
||||
rm -rf ${IMAGE_ROOTFS}/usr/lib/opkg
|
||||
#rm -rf ${IMAGE_ROOTFS}/lib64/security
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
## FILE
|
||||
lib -- cae and aiwrap lib
|
||||
res -- asp config file
|
||||
sdk -- aiwrap header files
|
||||
mis_asp.c -- main process
|
||||
tdmi_interface* -- alsa interface
|
||||
|
||||
## USE
|
||||
|
||||
1. read 6mic origin data
|
||||
Read(data);
|
||||
2. write to asp
|
||||
_apr_aiwrap_write(handle, data, len);
|
||||
3. 1 channel data for wakeup and regcognize
|
||||
test_presswk_fn()//callbak func
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,38 @@
|
|||
#source file
|
||||
SOURCE := $(wildcard *.c) $(wildcard *.cpp)
|
||||
OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
|
||||
|
||||
#target you can change test to what you want
|
||||
TARGET := mic_asp
|
||||
|
||||
#compile and lib parameter
|
||||
#CC := gcc
|
||||
LIBS := -ldl -lstdc++ -lpthread -lrt -lasound
|
||||
LDFLAGS := -Wl,--hash-style=gnu
|
||||
DEFINES :=
|
||||
INCLUDE :=
|
||||
|
||||
CFLAGS := -g -Wall -O0 -DCLI_SUPPORT=1 -funwind-tables -fPIC $(DEFINES) $(INCLUDE)
|
||||
CXXFLAGS:= $(CFLAGS) -std=c++11
|
||||
|
||||
#i think you should do anything here
|
||||
.PHONY : everything objs clean veryclean rebuild
|
||||
|
||||
everything : $(TARGET)
|
||||
|
||||
all : $(TARGET)
|
||||
|
||||
objs : $(OBJS)
|
||||
|
||||
rebuild: veryclean everything
|
||||
|
||||
clean :
|
||||
rm -fr *.so
|
||||
rm -fr *.o
|
||||
|
||||
veryclean : clean
|
||||
rm -fr $(TARGET)
|
||||
|
||||
$(TARGET) : $(OBJS)
|
||||
$(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
|
||||
|
|
@ -0,0 +1,277 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stdint.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <errno.h>
|
||||
#include <sys/sem.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/shm.h>
|
||||
#include "tdmin_interface.h"
|
||||
#include "sdk/apr_sdk.h"
|
||||
#include "sdk/apr_sdk_def.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#define lib_handle void*
|
||||
#define lib_load(path) dlopen(path, RTLD_LAZY)
|
||||
#define lib_free dlclose
|
||||
#define lib_func dlsym
|
||||
|
||||
#define DECL_API_PROC(name) static Proc_##name _##name = NULL;
|
||||
#define LOAD_API_PROC(name) _##name = (Proc_##name)lib_func(handle, #name);
|
||||
#define DEF_API_PROC(name) static Proc_##name _##name = name;
|
||||
|
||||
#define LOG printf
|
||||
|
||||
#define ASSERT_M(x, ...) \
|
||||
if (!(x)) { \
|
||||
LOG(__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define ASSERT_R(x, ...) \
|
||||
if (!(x)) { \
|
||||
LOG(__VA_ARGS__); \
|
||||
return (-1); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define USE_SDK_DSO 1
|
||||
#if USE_SDK_DSO
|
||||
static lib_handle g_lib_sdk;
|
||||
API_LIST_SDK(DECL_API_PROC);
|
||||
#else
|
||||
API_LIST_SDK(DEF_API_PROC);
|
||||
#endif
|
||||
|
||||
#define DUMP_AUD 0
|
||||
#define BUFFER_SIZE (8 * 4 * 16000)
|
||||
|
||||
static PCMContainer_t sPcmParam;
|
||||
int dirty_count=50;
|
||||
typedef long long _off64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
|
||||
static apr_aiwrap_t* handle = NULL;
|
||||
|
||||
static FILE *frecog = NULL;
|
||||
static FILE *fpresswk = NULL;
|
||||
static FILE *fivw = NULL;
|
||||
static FILE *flog = NULL;
|
||||
static FILE *fdump = NULL;
|
||||
|
||||
const char* DOS_PATH = "/usr/lib64/libaiwrap_6mic_c500.so";
|
||||
const char* CONFIG_PATH = "/data/res/conf_6mic_c500_nr_release.ini";
|
||||
const char* AUTH_PATH = "/data/res/auth.param";
|
||||
const char* CAE_PATH = "/usr/lib64/lib6mic_circle.so";
|
||||
|
||||
const char* presswk_path = "/tmp/presswk.pcm";
|
||||
const char* ivw_path = "/tmp/ivw.pcm";
|
||||
const char* dump_path = "/tmp/dump.pcm";
|
||||
|
||||
static const char* TAG="MAIN";
|
||||
static int hold_count = -1;
|
||||
|
||||
int Read(void* data) {
|
||||
int len=0;
|
||||
len = alsa_read_tdmin_pcm(&sPcmParam);
|
||||
memcpy(data, sPcmParam.data_buf, sPcmParam.chunk_bytes);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
static void signal_handler(int sig)
|
||||
{
|
||||
printf("Aborted by signal [%d]%s...\n", sig, strsignal(sig));
|
||||
exit(sig);
|
||||
//signal(sig, signal_handler);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void test_ivw_fn(void *userdata, void *data, int len)
|
||||
{
|
||||
#if DUMP_AUD
|
||||
if (fivw != NULL) {
|
||||
fwrite(data, 1, len, fivw);
|
||||
fflush(fivw);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//output 1 channel data for wakeup and recognize
|
||||
static void test_presswk_fn(void *userdata, void *data, int len)
|
||||
{
|
||||
#if DUMP_AUD
|
||||
if (fpresswk != NULL) {
|
||||
fwrite(data, 1, len, fpresswk);
|
||||
fflush(fpresswk);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int ret =-1;
|
||||
int len= 0;
|
||||
int client_len = 0;
|
||||
|
||||
char version[1024];
|
||||
char data[BUFFER_SIZE]={0};
|
||||
signal(SIGINT, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGABRT, signal_handler);
|
||||
signal(SIGKILL, signal_handler);
|
||||
signal(SIGQUIT, signal_handler);
|
||||
signal(SIGKILL, signal_handler);
|
||||
//signal(SIGPIPE, signal_handler);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
printf("##### Record Test Start...!\n");
|
||||
dirty_count = 50;
|
||||
alsa_mixer_set_gain(9, 6); //MIC GAIN, DSP GAIN for adc
|
||||
|
||||
ret = alsa_tdmin_init(&sPcmParam, 16000, 8, 128000);
|
||||
if(ret != 0)
|
||||
{
|
||||
printf("Alsa TDMIN init failed!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if USE_SDK_DSO
|
||||
if (!g_lib_sdk)
|
||||
{
|
||||
g_lib_sdk = lib_load(DOS_PATH);
|
||||
if(g_lib_sdk == NULL)
|
||||
{
|
||||
printf("Load library Failed! %s \n",DOS_PATH);
|
||||
return -1;
|
||||
}
|
||||
lib_handle handle = g_lib_sdk;
|
||||
API_LIST_SDK(LOAD_API_PROC);
|
||||
ASSERT_R(_apr_aiwrap_create, "lib_sym error\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
lib_sdk = dlopen("libaiwrap_6mic_c500.so",RTLD_LAZY);
|
||||
if(lib_sdk == NULL)
|
||||
{
|
||||
printf("Load library Failed!\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
printf("Load Success!\n");
|
||||
|
||||
ret = _apr_aiwrap_create(&handle, CONFIG_PATH, AUTH_PATH);
|
||||
if(ret !=0){
|
||||
printf("apr_aiwrap_create failed!\n");
|
||||
return ret;
|
||||
}
|
||||
ret = _apr_aiwrap_param_get(handle, "version", version, 1024);
|
||||
if(ret !=0){
|
||||
printf("apr_aiwrap_param_get ver failed!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ret = _apr_aiwrap_cb_set(handle, "ivw", test_ivw_fn, 0);
|
||||
if(ret !=0){
|
||||
printf("apr_aiwrap_cb_set ivw failed!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ret = _apr_aiwrap_cb_set(handle, "presswk", test_presswk_fn, 0);
|
||||
if(ret !=0){
|
||||
printf("apr_aiwrap_cb_set presswk failed!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = _apr_aiwrap_param_set(handle, "cae_dso", CAE_PATH);
|
||||
if(ret !=0){
|
||||
printf("apr_aiwrap_cb_set cae_dso failed!\n");
|
||||
return ret;
|
||||
}
|
||||
#if 0
|
||||
if (sn)
|
||||
{
|
||||
rv = _apr_aiwrap_param_set(handle, "auth_sn", sn);
|
||||
ASSERT_R(rv == 0, "apr_aiwrap_param_set auth_sn error, rv = %d\n", rv);
|
||||
}
|
||||
#endif
|
||||
ret = _apr_aiwrap_start(handle);
|
||||
if(ret !=0){
|
||||
printf("apr_aiwrap_start failed!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (presswk_path != NULL) {
|
||||
fpresswk = fopen(presswk_path, "wb");
|
||||
if (fpresswk == NULL) {
|
||||
fprintf(stderr, "open presswk pcm error");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (ivw_path != NULL) {
|
||||
fivw = fopen(ivw_path, "wb");
|
||||
if (fivw == NULL) {
|
||||
fprintf(stderr, "open ivw pcm error");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
//if (log_path != NULL) {
|
||||
/// flog = fopen(log_path, "w");
|
||||
// if (flog == NULL) {
|
||||
// fprintf(stderr, "open ivw log error");
|
||||
// return -1;
|
||||
// }
|
||||
//}
|
||||
if (dump_path != NULL) {
|
||||
fdump = fopen(dump_path, "wb");
|
||||
if (fdump == NULL) {
|
||||
fprintf(stderr, "open dump pcm error");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
//static int frame_size = 8*4*512; //6mic 32ms
|
||||
while(1){
|
||||
usleep(1000);
|
||||
if(dirty_count == 0){
|
||||
len=Read(data);
|
||||
//write 6mic origin data
|
||||
_apr_aiwrap_write(handle, data, len);
|
||||
}else{
|
||||
printf("cae_audio_write ignore!\n");
|
||||
dirty_count--;
|
||||
}
|
||||
}
|
||||
printf("CAE finished!\n");
|
||||
|
||||
_apr_aiwrap_stop(handle);
|
||||
_apr_aiwrap_destory(handle);
|
||||
|
||||
if (frecog != NULL) fclose(frecog);
|
||||
if (fpresswk != NULL) fclose(fpresswk);
|
||||
if (fivw != NULL) fclose(fivw);
|
||||
if (flog != NULL) fclose(flog);
|
||||
if (fdump != NULL) fclose(fdump);
|
||||
|
||||
|
||||
dlclose(handle);
|
||||
alsa_tdmin_uninit(&sPcmParam);
|
||||
return 0;
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
[Unit]
|
||||
Description=cae_process
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/cae_process
|
||||
Type=simple
|
||||
StandardOutput=syslog
|
||||
StandardError=syslog
|
||||
|
||||
[Install]
|
||||
Alias=cae_process
|
||||
WantedBy=multi-user.target
|
Binary file not shown.
|
@ -0,0 +1,87 @@
|
|||
[cae]
|
||||
#麦克数,可选值:1 2,4,6
|
||||
nMicNum = 6
|
||||
|
||||
#参考数,可选值:1 2
|
||||
nRefNum = 2
|
||||
|
||||
#主波束索引,可选值:0 1 2
|
||||
nChiefBeam = 1
|
||||
|
||||
#麦克风间距,单位米
|
||||
nMicDist = 0.035
|
||||
|
||||
nDerType = 1
|
||||
|
||||
#输出采样率,默认16000
|
||||
nOutSampleRate = 16000
|
||||
|
||||
#oneshot功能开关,默认关闭
|
||||
nOneshotEnable = false
|
||||
|
||||
nOutNum = 3
|
||||
|
||||
[delay]
|
||||
#delay开关
|
||||
delay_on = false
|
||||
|
||||
[aec]
|
||||
#aec开关
|
||||
aec_on = true
|
||||
|
||||
#aec调试选项
|
||||
aec_debug = false
|
||||
|
||||
#aec消除等级,可选值:1-5
|
||||
aec_level = 5
|
||||
|
||||
#aec fft长度,可选值:512 1024
|
||||
aec_fft_size = 512
|
||||
|
||||
#参数文件路径
|
||||
aec_coef =
|
||||
|
||||
[der]
|
||||
#der开关
|
||||
der_on = true
|
||||
|
||||
#der调试选项
|
||||
der_debug = false
|
||||
|
||||
#der 阶数,可选值10-24(偶数)
|
||||
nOrder = 20
|
||||
|
||||
[mab]
|
||||
#mab调试选项
|
||||
mab_debug = false
|
||||
|
||||
[post]
|
||||
#der开关
|
||||
post_on = true
|
||||
|
||||
#mab调试选项
|
||||
post_debug = false
|
||||
|
||||
[agc]
|
||||
#agc开关
|
||||
agc_on = true
|
||||
|
||||
#agc调试选项
|
||||
#agc_debug = false
|
||||
|
||||
[mlp]
|
||||
#NN AES开关
|
||||
aes_on = true
|
||||
|
||||
#NN AES调试选项
|
||||
aes_debug = true
|
||||
|
||||
|
||||
#aes_model = ../models/mlp_aes_1024.bin
|
||||
|
||||
td_on = false
|
||||
|
||||
td_model_type = cldnn
|
||||
td_dynamic = true
|
||||
td_delay = 5
|
||||
#td_model = ../models/mlp_td_cldnn_xyxy_20211208_d5d0.bin
|
|
@ -0,0 +1,13 @@
|
|||
[cae]
|
||||
#前端动态库路径
|
||||
cae_dso = /usr/lib64/lib6mic_circle.so
|
||||
cae_res_mode = 1
|
||||
#配置文件路径
|
||||
cae_res_param = /data/res/cae_6mic_circle_nr.ini
|
||||
#AES模型文件路径
|
||||
cae_res_aes = /data/res/mlp_aes_1024_tv_xyxy_20200728.bin
|
||||
#音频缓存队列大小
|
||||
cae_queue_size = 10
|
||||
cae_out_num = 3
|
||||
#后端动态库路径
|
||||
ivw_enable = 0
|
Binary file not shown.
|
@ -0,0 +1,35 @@
|
|||
#ifndef APR_SDK_H
|
||||
#define APR_SDK_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#define API_EXPORT
|
||||
#define API_CALL
|
||||
#else
|
||||
#define API_PUBLIC __attribute__ ((visibility("default")))
|
||||
#define API_EXPORT API_PUBLIC
|
||||
#define API_CALL __attribute__ ((visibility("default")))
|
||||
#endif
|
||||
|
||||
typedef struct apr_aiwrap_t apr_aiwrap_t;
|
||||
typedef void(*apr_aiwrap_cb_t)(void *userdata, void *data, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
API_EXPORT int apr_aiwrap_create(apr_aiwrap_t** inst, const char* ini_path, const char* param_path);
|
||||
API_EXPORT int apr_aiwrap_destory(apr_aiwrap_t* inst);
|
||||
API_EXPORT int apr_aiwrap_start(apr_aiwrap_t* inst);
|
||||
API_EXPORT int apr_aiwrap_stop(apr_aiwrap_t* inst);
|
||||
API_EXPORT int apr_aiwrap_write(apr_aiwrap_t* inst, void* data, int size);
|
||||
API_EXPORT int apr_aiwrap_param_set(apr_aiwrap_t* inst, const char* param, const char* value);
|
||||
API_EXPORT int apr_aiwrap_param_get(apr_aiwrap_t* inst, const char* param, char* value, int ilen);
|
||||
API_EXPORT int apr_aiwrap_cb_set(apr_aiwrap_t* inst, const char* name, void* cb, void* userdata);
|
||||
API_EXPORT int apr_aiwrap_cb_unset(apr_aiwrap_t* inst, const char* name);
|
||||
API_EXPORT int apr_aiwrap_res_set(apr_aiwrap_t* inst, const char* param, char* value, int ilen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //APR_SDK_H
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef APR_SDK_DEF_H
|
||||
#define APR_SDK_DEF_H
|
||||
|
||||
#include "apr_sdk.h"
|
||||
|
||||
#define API_LIST_SDK(func) \
|
||||
func(apr_aiwrap_create)\
|
||||
func(apr_aiwrap_destory)\
|
||||
func(apr_aiwrap_start)\
|
||||
func(apr_aiwrap_stop)\
|
||||
func(apr_aiwrap_write)\
|
||||
func(apr_aiwrap_param_set)\
|
||||
func(apr_aiwrap_param_get)\
|
||||
func(apr_aiwrap_cb_set)\
|
||||
func(apr_aiwrap_cb_unset)\
|
||||
func(apr_aiwrap_res_set)
|
||||
|
||||
typedef int (*Proc_apr_aiwrap_create)(apr_aiwrap_t** inst, const char* ini_path, const char* param_path);
|
||||
typedef int (*Proc_apr_aiwrap_destory)(apr_aiwrap_t* inst);
|
||||
typedef int (*Proc_apr_aiwrap_start)(apr_aiwrap_t* inst);
|
||||
typedef int (*Proc_apr_aiwrap_stop)(apr_aiwrap_t* inst);
|
||||
typedef int (*Proc_apr_aiwrap_write)(apr_aiwrap_t* inst, void* data, int size);
|
||||
typedef int (*Proc_apr_aiwrap_param_set)(apr_aiwrap_t* inst, const char* param, const char* value);
|
||||
typedef int (*Proc_apr_aiwrap_param_get)(apr_aiwrap_t* inst, const char* param, char* value, int ilen);
|
||||
typedef int (*Proc_apr_aiwrap_cb_set)(apr_aiwrap_t* inst, const char* name, void* cb, void* userdata);
|
||||
typedef int (*Proc_apr_aiwrap_cb_unset)(apr_aiwrap_t* inst, const char* name);
|
||||
typedef int (*Proc_apr_aiwrap_res_set)(apr_aiwrap_t* inst, const char* param, char* value, int ilen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //APR_SDK_DEF_H
|
|
@ -0,0 +1,113 @@
|
|||
#ifndef APR_WRAP_ERRNO_H
|
||||
#define APR_WRAP_ERRNO_H
|
||||
|
||||
//#include <apr/apr_errno.h>
|
||||
|
||||
#ifndef APR_OS_ERRFUNC
|
||||
#define APR_OS_ERRFUNC(e) (-(e))
|
||||
#endif
|
||||
|
||||
/* WRAP´íÎóÂ루70000-80000£©*/
|
||||
#ifndef APR_OS_START_SYSERR
|
||||
#define APR_OS_START_WRAP 70000
|
||||
#else
|
||||
#define APR_OS_START_WRAP (APR_OS_START_SYSERR + APR_OS_ERRSPACE_SIZE)
|
||||
#endif
|
||||
|
||||
/* CAE´íÎóÂë 70100+ */
|
||||
#define APR_CAE_ERR APR_OS_ERRFUNC(APR_OS_START_WRAP + 100)
|
||||
#define APR_CAE_ECAECREATE APR_OS_ERRFUNC(APR_OS_START_WRAP + 101)
|
||||
#define APR_CAE_ECAESETPARAM APR_OS_ERRFUNC(APR_OS_START_WRAP + 102)
|
||||
#define APR_CAE_ECAEDEL APR_OS_ERRFUNC(APR_OS_START_WRAP + 103)
|
||||
#define APR_CAE_ECAEAPPENDMIC APR_OS_ERRFUNC(APR_OS_START_WRAP + 104)
|
||||
#define APR_CAE_ECAEAPPENDREF APR_OS_ERRFUNC(APR_OS_START_WRAP + 105)
|
||||
#define APR_CAE_ECAEDOAEC APR_OS_ERRFUNC(APR_OS_START_WRAP + 106)
|
||||
#define APR_CAE_ECAEGETDATA APR_OS_ERRFUNC(APR_OS_START_WRAP + 107)
|
||||
#define APR_CAE_ECAEDATAERR APR_OS_ERRFUNC(APR_OS_START_WRAP + 108)
|
||||
#define APR_CAE_ECAEGETSTATUS APR_OS_ERRFUNC(APR_OS_START_WRAP + 109)
|
||||
#define APR_CAE_ECAEGETANGLE APR_OS_ERRFUNC(APR_OS_START_WRAP + 110)
|
||||
#define APR_CAE_ECAEGETPARAM APR_OS_ERRFUNC(APR_OS_START_WRAP + 111)
|
||||
#define APR_CAE_ECAEAPPENDAUDIO APR_OS_ERRFUNC(APR_OS_START_WRAP + 112)
|
||||
#define APR_CAE_ELOADRES APR_OS_ERRFUNC(APR_OS_START_WRAP + 113)
|
||||
#define APR_CAE_ELOADDSO APR_OS_ERRFUNC(APR_OS_START_WRAP + 114)
|
||||
#define APR_CAE_EGETSYM APR_OS_ERRFUNC(APR_OS_START_WRAP + 115)
|
||||
|
||||
/* IVW´íÎóÂë 70200+ */
|
||||
#define APR_IVW_ERR APR_OS_ERRFUNC(APR_OS_START_WRAP + 200)
|
||||
#define APR_IVW_EINIT APR_OS_ERRFUNC(APR_OS_START_WRAP + 201)
|
||||
#define APR_IVW_EUNINIT APR_OS_ERRFUNC(APR_OS_START_WRAP + 202)
|
||||
#define APR_IVW_ERESADD APR_OS_ERRFUNC(APR_OS_START_WRAP + 203)
|
||||
#define APR_IVW_ERESDEL APR_OS_ERRFUNC(APR_OS_START_WRAP + 204)
|
||||
#define APR_IVW_EWRITE APR_OS_ERRFUNC(APR_OS_START_WRAP + 205)
|
||||
#define APR_IVW_EGETRESULT APR_OS_ERRFUNC(APR_OS_START_WRAP + 206)
|
||||
#define APR_IVW_ECREATEINST APR_OS_ERRFUNC(APR_OS_START_WRAP + 207)
|
||||
#define APR_IVW_EDESTROYINST APR_OS_ERRFUNC(APR_OS_START_WRAP + 208)
|
||||
#define APR_IVW_ESTART APR_OS_ERRFUNC(APR_OS_START_WRAP + 209)
|
||||
#define APR_IVW_ESTOP APR_OS_ERRFUNC(APR_OS_START_WRAP + 210)
|
||||
#define APR_IVW_EREGCB APR_OS_ERRFUNC(APR_OS_START_WRAP + 211)
|
||||
#define APR_IVW_EUNREGCB APR_OS_ERRFUNC(APR_OS_START_WRAP + 212)
|
||||
#define APR_IVW_EGETMLPRES APR_OS_ERRFUNC(APR_OS_START_WRAP + 213)
|
||||
#define APR_IVW_EGETFILLERRES APR_OS_ERRFUNC(APR_OS_START_WRAP + 214)
|
||||
#define APR_IVW_EGETKEYWORDRES APR_OS_ERRFUNC(APR_OS_START_WRAP + 215)
|
||||
#define APR_IVW_EADDMLPRES APR_OS_ERRFUNC(APR_OS_START_WRAP + 216)
|
||||
#define APR_IVW_EADDFILLERRES APR_OS_ERRFUNC(APR_OS_START_WRAP + 217)
|
||||
#define APR_IVW_EADDKEYWORDRES APR_OS_ERRFUNC(APR_OS_START_WRAP + 218)
|
||||
#define APR_IVW_EPARSEISTART APR_OS_ERRFUNC(APR_OS_START_WRAP + 219)
|
||||
#define APR_IVW_EPARSEIDURATION APR_OS_ERRFUNC(APR_OS_START_WRAP + 220)
|
||||
#define APR_IVW_EPARSENCM APR_OS_ERRFUNC(APR_OS_START_WRAP + 221)
|
||||
#define APR_IVW_EPARSEKEYWORD APR_OS_ERRFUNC(APR_OS_START_WRAP + 222)
|
||||
#define APR_IVW_ESETPARAM APR_OS_ERRFUNC(APR_OS_START_WRAP + 223)
|
||||
#define APR_IVW_EGETPARAM APR_OS_ERRFUNC(APR_OS_START_WRAP + 224)
|
||||
#define APR_IVW_ELOADRES APR_OS_ERRFUNC(APR_OS_START_WRAP + 225)
|
||||
#define APR_IVW_ELOADDSO APR_OS_ERRFUNC(APR_OS_START_WRAP + 226)
|
||||
#define APR_IVW_EGETSYM APR_OS_ERRFUNC(APR_OS_START_WRAP + 227)
|
||||
|
||||
/* ENGINE´íÎóÂë 70300+ */
|
||||
#define APR_EGINE_ERR APR_OS_ERRFUNC(APR_OS_START_WRAP + 300)
|
||||
#define APR_EGINE_ERUNNING APR_OS_ERRFUNC(APR_OS_START_WRAP + 301)
|
||||
#define APR_EGINE_ERELOADING APR_OS_ERRFUNC(APR_OS_START_WRAP + 302)
|
||||
#define APR_EGINE_ENOTRUN APR_OS_ERRFUNC(APR_OS_START_WRAP + 303)
|
||||
|
||||
/* PARAM´íÎóÂë 70400+ */
|
||||
#define APR_PARAM_EOPENPARAM APR_OS_ERRFUNC(APR_OS_START_WRAP + 401)
|
||||
#define APR_PARAM_EPARSEPARAM APR_OS_ERRFUNC(APR_OS_START_WRAP + 402)
|
||||
#define APR_PARAM_EOPENRES APR_OS_ERRFUNC(APR_OS_START_WRAP + 403)
|
||||
#define APR_PARAM_EPARSERES APR_OS_ERRFUNC(APR_OS_START_WRAP + 404)
|
||||
#define APR_PARAM_EUNKNOW APR_OS_ERRFUNC(APR_OS_START_WRAP + 405)
|
||||
#define APR_PARAM_EPARSEINI APR_OS_ERRFUNC(APR_OS_START_WRAP + 406)
|
||||
|
||||
/* AUTH´íÎóÂë 70500+ */
|
||||
#define APR_AUTH_EHTTP_ERR APR_OS_ERRFUNC(APR_OS_START_WRAP + 500)
|
||||
#define APR_AUTH_EHTTP_PRIKEY APR_OS_ERRFUNC(APR_OS_START_WRAP + 501)
|
||||
#define APR_AUTH_EHTTP_PUBKEY APR_OS_ERRFUNC(APR_OS_START_WRAP + 502)
|
||||
#define APR_AUTH_EHTTP_AES_ENC APR_OS_ERRFUNC(APR_OS_START_WRAP + 503)
|
||||
#define APR_AUTH_EHTTP_AES_DEC APR_OS_ERRFUNC(APR_OS_START_WRAP + 504)
|
||||
#define APR_AUTH_EHTTP_B64_ENC APR_OS_ERRFUNC(APR_OS_START_WRAP + 505)
|
||||
#define APR_AUTH_EHTTP_B64_DEC APR_OS_ERRFUNC(APR_OS_START_WRAP + 506)
|
||||
#define APR_AUTH_EHTTP_INIT APR_OS_ERRFUNC(APR_OS_START_WRAP + 507)
|
||||
#define APR_AUTH_EHTTP_EXEC APR_OS_ERRFUNC(APR_OS_START_WRAP + 508)
|
||||
#define APR_AUTH_EHTTP_C200 APR_OS_ERRFUNC(APR_OS_START_WRAP + 509)
|
||||
#define APR_AUTH_EHTTP_INVALAPPID APR_OS_ERRFUNC(APR_OS_START_WRAP + 510)
|
||||
#define APR_AUTH_EHTTP_INVALFLAG APR_OS_ERRFUNC(APR_OS_START_WRAP + 511)
|
||||
#define APR_AUTH_EHTTP_INVALTIME APR_OS_ERRFUNC(APR_OS_START_WRAP + 512)
|
||||
#define APR_AUTH_EHTTP_EXPIRE APR_OS_ERRFUNC(APR_OS_START_WRAP + 513)
|
||||
#define APR_AUTH_EHTTP_ACCESS APR_OS_ERRFUNC(APR_OS_START_WRAP + 614)
|
||||
#define APR_AUTH_EHTTP_CHECKSN APR_OS_ERRFUNC(APR_OS_START_WRAP + 615)
|
||||
#define APR_AUTH_EHTTP_NOLIMIT_INVAL APR_OS_ERRFUNC(APR_OS_START_WRAP + 616)
|
||||
#define APR_AUTH_EHTTP_STRONG APR_OS_ERRFUNC(APR_OS_START_WRAP + 617)
|
||||
#define APR_AUTH_EHTTP_WEEK_INVAL APR_OS_ERRFUNC(APR_OS_START_WRAP + 618)
|
||||
#define APR_AUTH_EHTTP_WEEK_TIMEOUT APR_OS_ERRFUNC(APR_OS_START_WRAP + 619)
|
||||
|
||||
/* AUTH´íÎóÂë 70600+ */
|
||||
#define APR_AUTH_ECHIP_ERR APR_OS_ERRFUNC(APR_OS_START_WRAP + 600)
|
||||
#define APR_AUTH_ECHIP_LOADKEY APR_OS_ERRFUNC(APR_OS_START_WRAP + 601)
|
||||
#define APR_AUTH_ECHIP_INIT APR_OS_ERRFUNC(APR_OS_START_WRAP + 602)
|
||||
#define APR_AUTH_ECHIP_LOADINFO APR_OS_ERRFUNC(APR_OS_START_WRAP + 603)
|
||||
#define APR_AUTH_ECHIP_CHECK APR_OS_ERRFUNC(APR_OS_START_WRAP + 604)
|
||||
#define APR_AUTH_ECHIP_ACCESS APR_OS_ERRFUNC(APR_OS_START_WRAP + 605)
|
||||
|
||||
/* WRAP´íÎóÂë 71000+ */
|
||||
#define APR_WRAP_ERR APR_OS_ERRFUNC(APR_OS_START_WRAP + 1000)
|
||||
#define APR_WRAP_INVIADOBJ APR_OS_ERRFUNC(APR_OS_START_WRAP + 1001)
|
||||
|
||||
#endif /* APR_WRAP_ERRNO_H */
|
|
@ -0,0 +1,485 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <alsa/asoundlib.h>
|
||||
#include "tdmin_interface.h"
|
||||
|
||||
#define ALSA_OK 0
|
||||
#define ALSA_FAIL -1
|
||||
|
||||
#if 0
|
||||
#define PB_ALSA_ERR(x) printf x
|
||||
#define PB_ALSA_INFO(x) printf x
|
||||
#else
|
||||
#define PB_ALSA_ERR(x)
|
||||
#define PB_ALSA_INFO(x)
|
||||
#endif
|
||||
|
||||
#define PCM_HANDLE_CHECK(handle) do{ \
|
||||
if(NULL == handle) \
|
||||
{ PB_ALSA_ERR((PB_ALSA_DEBUG_TAG"%s -- Invail pcm handle fail\n",__FUNCTION__)); \
|
||||
return ALSA_FAIL;} \
|
||||
}while(0)
|
||||
static int cset(int argc, char argv1[], char argv2[], int roflag,
|
||||
int keep_handle);
|
||||
static long long gdatalen = 0;
|
||||
/*---------------------------------------------------------------------------
|
||||
* Name
|
||||
* Playback_Alsa_ReadPCM
|
||||
* Description -
|
||||
* Input arguments -
|
||||
* Output arguments -
|
||||
* Returns -ok:write pcm size fail or pause:-1
|
||||
*---------------------------------------------------------------------------*/
|
||||
int gLineOutDetected=0;
|
||||
static int _alsa_read_pcm(PCMContainer_t *sndpcm, size_t rcount) {
|
||||
ssize_t r;
|
||||
size_t result = 0;
|
||||
size_t count = rcount;
|
||||
uint8_t *data = sndpcm->data_buf_16;
|
||||
uint32_t index;
|
||||
uint8_t cid = 1;
|
||||
if (count != sndpcm->chunk_size) {
|
||||
count = sndpcm->chunk_size;
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
r = snd_pcm_readi(sndpcm->handle, data, count);
|
||||
if (r == -EAGAIN || (r >= 0 && (size_t) r < count)) {
|
||||
snd_pcm_wait(sndpcm->handle, 1000);
|
||||
} else if (r == -EPIPE) {
|
||||
snd_pcm_prepare(sndpcm->handle);
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"<<<<<<<<<<<<<<< Buffer Underrun >>>>>>>>>>>>>>>\n"));
|
||||
} else if (r == -ESTRPIPE) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"<<<<<<<<<<<<<<< Need suspend >>>>>>>>>>>>>>>\n"));
|
||||
} else if (r < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_readi: [%s]\n", snd_strerror(r)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (r > 0) {
|
||||
result += r;
|
||||
count -= r;
|
||||
data += r * sndpcm->bits_per_frame / 8;
|
||||
}
|
||||
}
|
||||
#if 1
|
||||
unsigned char* data_raw = sndpcm->data_buf_16;
|
||||
unsigned char* data_32 = sndpcm->data_buf;
|
||||
|
||||
//rcount = chunk_bytes_16
|
||||
memset(sndpcm->data_buf, 0, sndpcm->chunk_bytes);
|
||||
for(int i=0; i<rcount; i+=32)
|
||||
{
|
||||
memcpy((data_32+24), (data_raw), 4);
|
||||
memcpy((data_32+28), (data_raw+4), 4);
|
||||
memcpy((data_32), (data_raw+8), 4);
|
||||
memcpy((data_32+12), (data_raw+12), 4);
|
||||
memcpy((data_32+8), (data_raw+16), 4);
|
||||
memcpy((data_32+4), (data_raw+20), 4);
|
||||
memcpy((data_32+16), (data_raw+24), 4);
|
||||
memcpy((data_32+20), (data_raw+28), 4);
|
||||
|
||||
data_raw+=32;
|
||||
data_32+=32;
|
||||
}
|
||||
#endif
|
||||
|
||||
return rcount;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Name
|
||||
* Playback_Alsa_SetHWParams
|
||||
* Description -
|
||||
* Input arguments -
|
||||
* Output arguments -
|
||||
* Returns - OK(0) PARAMS ERR(-1)
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
static int _alsa_set_hw_params(PCMContainer_t *pcm_params,
|
||||
uint32_t ui4_max_buffer_time) {
|
||||
snd_pcm_hw_params_t *hwparams;
|
||||
uint32_t exact_rate;
|
||||
uint32_t buffer_time, period_time;
|
||||
int err;
|
||||
|
||||
PCM_HANDLE_CHECK(pcm_params->handle);
|
||||
|
||||
/* Allocate the snd_pcm_hw_params_t structure on the stack. */
|
||||
snd_pcm_hw_params_alloca(&hwparams);
|
||||
|
||||
/* Fill it with default values */
|
||||
err = snd_pcm_hw_params_any(pcm_params->handle, hwparams);
|
||||
if (err < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_hw_params_any : %s\n",snd_strerror(err)));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
|
||||
/* Interleaved mode */
|
||||
err = snd_pcm_hw_params_set_access(pcm_params->handle, hwparams,
|
||||
SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||
if (err < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_hw_params_set_access : %s\n",snd_strerror(err)));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
|
||||
/* Set sample format */
|
||||
err = snd_pcm_hw_params_set_format(pcm_params->handle, hwparams,
|
||||
pcm_params->format);
|
||||
if (err < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_hw_params_set_format : %s\n",snd_strerror(err)));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
|
||||
/* Set number of channels */
|
||||
err = snd_pcm_hw_params_set_channels(pcm_params->handle, hwparams,
|
||||
LE_SHORT(pcm_params->channels));
|
||||
if (err < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_hw_params_set_channels : %s\n",snd_strerror(err)));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
|
||||
/* Set sample rate. If the exact rate is not supported */
|
||||
/* by the hardware, use nearest possible rate. */
|
||||
exact_rate = LE_INT(pcm_params->sample_rate);
|
||||
err = snd_pcm_hw_params_set_rate_near(pcm_params->handle, hwparams,
|
||||
&exact_rate, 0);
|
||||
if (err < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_hw_params_set_rate_near : %s\n",snd_strerror(err)));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
if (LE_INT(pcm_params->sample_rate) != exact_rate) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"The rate %d Hz is not supported by your hardware.\n ==> Using %d Hz instead.\n", LE_INT(pcm_params->sample_rate), exact_rate));
|
||||
}
|
||||
|
||||
err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time, 0);
|
||||
if (err < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_hw_params_get_buffer_time_max : %s\n",snd_strerror(err)));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"snd_pcm_hw_params_get_buffer_time_max : %ul (us)\n",buffer_time));
|
||||
|
||||
if (buffer_time > ui4_max_buffer_time)
|
||||
buffer_time = ui4_max_buffer_time;/*200000us = 200ms*/
|
||||
|
||||
if (buffer_time > 0)
|
||||
period_time = buffer_time / 4;
|
||||
|
||||
err = snd_pcm_hw_params_set_buffer_time_near(pcm_params->handle, hwparams,
|
||||
&buffer_time, 0);
|
||||
if (err < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_hw_params_set_buffer_time_near : %s\n",snd_strerror(err)));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
|
||||
err = snd_pcm_hw_params_set_period_time_near(pcm_params->handle, hwparams,
|
||||
&period_time, 0);
|
||||
if (err < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_hw_params_set_period_time_near : %s\n",snd_strerror(err)));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
|
||||
/* Set hw params */
|
||||
err = snd_pcm_hw_params(pcm_params->handle, hwparams);
|
||||
if (err < 0) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error snd_pcm_hw_params: %s at line->%d\n",snd_strerror(err),__LINE__));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
|
||||
snd_pcm_hw_params_get_period_size(hwparams, &pcm_params->chunk_size, 0);
|
||||
snd_pcm_hw_params_get_buffer_size(hwparams, &pcm_params->buffer_size);
|
||||
if (pcm_params->chunk_size == pcm_params->buffer_size) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Can't use period equal to buffer size (%lu == %lu)\n", pcm_params->chunk_size, pcm_params->buffer_size));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
printf(">> chunk_size = %d, buffer_size = %d\n", (unsigned int)pcm_params->chunk_size, (unsigned int)pcm_params->buffer_size);
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"chunk_size is %lu, buffer size is %lu\n", pcm_params->chunk_size, pcm_params->buffer_size));
|
||||
|
||||
/*bits per sample = bits depth*/
|
||||
pcm_params->bits_per_sample = snd_pcm_format_physical_width(
|
||||
pcm_params->format);
|
||||
|
||||
/*bits per frame = bits depth * channels*/
|
||||
pcm_params->bits_per_frame = pcm_params->bits_per_sample
|
||||
* LE_SHORT(pcm_params->channels);
|
||||
|
||||
/*chunk byte is a better size for each write or read for alsa*/
|
||||
pcm_params->chunk_bytes_16 = pcm_params->chunk_size * pcm_params->bits_per_frame / 8;
|
||||
pcm_params->chunk_bytes = pcm_params->chunk_bytes_16 * 2;
|
||||
|
||||
printf(">>> bps = %d, chunk_bytes = %d\n", (unsigned int)pcm_params->bits_per_frame, (unsigned int)pcm_params->chunk_bytes_16);
|
||||
/* Allocate audio data buffer */
|
||||
pcm_params->data_buf = (uint8_t *) malloc(pcm_params->chunk_bytes);
|
||||
if (!pcm_params->data_buf) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error malloc: [data_buf] at line-> %d\n",__LINE__));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
pcm_params->data_buf_16 = (uint8_t *) malloc(pcm_params->chunk_bytes_16);
|
||||
if (!pcm_params->data_buf_16) {
|
||||
PB_ALSA_ERR(
|
||||
(PB_ALSA_DEBUG_TAG"Error malloc: [data_buf] at line-> %d\n",__LINE__));
|
||||
goto ERR_SET_PARAMS;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
ERR_SET_PARAMS:
|
||||
if (NULL != pcm_params->data_buf) {
|
||||
free(pcm_params->data_buf);
|
||||
pcm_params->data_buf = NULL;
|
||||
}
|
||||
if (NULL != pcm_params->data_buf_16) {
|
||||
free(pcm_params->data_buf_16);
|
||||
pcm_params->data_buf_16 = NULL;
|
||||
}
|
||||
snd_pcm_close(pcm_params->handle);
|
||||
pcm_params->handle = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _pcm_32_to_16(char *dst_buf, char *ori_buf, int ori_len, int fseek_bit) {
|
||||
char *p = ori_buf;
|
||||
char *q = dst_buf;
|
||||
unsigned int *temp;
|
||||
|
||||
if (dst_buf == NULL || ori_buf == NULL) {
|
||||
printf("Err: u_aispeech_pcm_32_to_16() buf is null!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (ori_len >= 4) {
|
||||
temp = (unsigned int *) p;
|
||||
*temp = (*temp << fseek_bit);
|
||||
*q = *(p + 2);
|
||||
*(q + 1) = *(p + 3);
|
||||
q += 2;
|
||||
p += 4;
|
||||
ori_len -= 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int alsa_tdmin_init(PCMContainer_t *pcm_params, int samplerate,int channels,int max_buffer_time) {
|
||||
|
||||
int i4_ret = 0;
|
||||
|
||||
if (pcm_params == NULL) {
|
||||
printf("PCMContainer handle == NULL!\n");
|
||||
return TDMIN_INV_ARG;
|
||||
}
|
||||
|
||||
pcm_params->format = SND_PCM_FORMAT_S32_LE;
|
||||
pcm_params->sample_rate = samplerate;
|
||||
pcm_params->channels = channels;
|
||||
//i4_ret = snd_pcm_open(&pcm_params->handle, AISPEECH_TDMIC_PCM_RECORD_DEVICE_NAME, SND_PCM_STREAM_CAPTURE, 0);
|
||||
i4_ret = snd_pcm_open(&pcm_params->handle, TDM_IN_DEVICE_NAME,
|
||||
SND_PCM_STREAM_CAPTURE, 0);
|
||||
if (0 != i4_ret) {
|
||||
printf("snd_pcm_open failed %d!\n",i4_ret);
|
||||
return TDMIN_FAIL;
|
||||
}
|
||||
i4_ret = _alsa_set_hw_params(pcm_params, max_buffer_time);
|
||||
if (i4_ret != 0) {
|
||||
printf("u_alsa_set_hw_params failed!\n");
|
||||
return TDMIN_FAIL;
|
||||
}
|
||||
printf("Set alsa param OK, start read pcm!!!\n");
|
||||
gdatalen = 0;
|
||||
return TDMIN_OK;
|
||||
}
|
||||
|
||||
void alsa_tdmin_uninit(PCMContainer_t *pcm_params) {
|
||||
if (pcm_params == NULL) {
|
||||
printf("PCMContainer handle == NULL!\n");
|
||||
return;
|
||||
}
|
||||
if (NULL != pcm_params->data_buf) {
|
||||
free(pcm_params->data_buf);
|
||||
pcm_params->data_buf = NULL;
|
||||
}
|
||||
if (NULL != pcm_params->data_buf_16) {
|
||||
free(pcm_params->data_buf_16);
|
||||
pcm_params->data_buf_16 = NULL;
|
||||
}
|
||||
snd_pcm_close(pcm_params->handle);
|
||||
pcm_params->handle = NULL;
|
||||
}
|
||||
int asla_tdmin_init_bias() {
|
||||
cset(2, "name='ADC Gain Switch'", "0", 0, 0);
|
||||
cset(2, "name='ADC Bais'", "19", 0, 0);
|
||||
|
||||
cset(2, "name='ADC Gain Switch'", "1", 0, 0);
|
||||
cset(2, "name='ADC Bais'", "19", 0, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
int asla_tdmin_set_bias(int on) {
|
||||
cset(2, "name='ADC Gain Switch'", "0", 0, 0);
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
char cmd[128];
|
||||
sprintf(cmd, "name='Channel%d enable'", i);
|
||||
cset(2, cmd, on ? "1" : "0", 0, 0);
|
||||
}
|
||||
|
||||
cset(2, "name='ADC Gain Switch'", "1", 0, 0);
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
char cmd[128];
|
||||
sprintf(cmd, "name='Channel%d enable'", i);
|
||||
cset(2, cmd, on ? "1" : "0", 0, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int alsa_read_tdmin_pcm(PCMContainer_t *pcm_params) {
|
||||
int i4_ret = 0;
|
||||
|
||||
if (pcm_params == NULL) {
|
||||
printf("PCMContainer handle == NULL!\n");
|
||||
return TDMIN_INV_ARG;
|
||||
}
|
||||
|
||||
i4_ret = _alsa_read_pcm(pcm_params, pcm_params->chunk_bytes_16);
|
||||
return i4_ret;
|
||||
|
||||
}
|
||||
|
||||
static int cset(int argc, char argv1[], char argv2[], int roflag,
|
||||
int keep_handle) {
|
||||
#define LEVEL_BASIC (1<<0)
|
||||
#define LEVEL_INACTIVE (1<<1)
|
||||
#define LEVEL_ID (1<<2)
|
||||
|
||||
int err;
|
||||
static snd_ctl_t *handle = NULL;
|
||||
snd_ctl_elem_info_t *info;
|
||||
snd_ctl_elem_id_t *id;
|
||||
snd_ctl_elem_value_t *control;
|
||||
snd_ctl_elem_info_alloca(&info);
|
||||
snd_ctl_elem_id_alloca(&id);
|
||||
snd_ctl_elem_value_alloca(&control);
|
||||
char card[64] = "default";
|
||||
if (argc < 1) {
|
||||
fprintf(stderr,
|
||||
"Specify a full control identifier: [[iface=<iface>,][name='name',][index=<index>,][device=<device>,][subdevice=<subdevice>]]|[numid=<numid>]\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (snd_ctl_ascii_elem_id_parse(id, argv1)) {
|
||||
fprintf(stderr, "Wrong control identifier: %s\n", argv1);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (handle == NULL && (err = snd_ctl_open(&handle, card, 0)) < 0) {
|
||||
printf("Control %s open error: %s\n", card, snd_strerror(err));
|
||||
return err;
|
||||
}
|
||||
snd_ctl_elem_info_set_id(info, id);
|
||||
if ((err = snd_ctl_elem_info(handle, info)) < 0) {
|
||||
printf("Cannot find the given element from control %s\n", card);
|
||||
if (!keep_handle) {
|
||||
snd_ctl_close(handle);
|
||||
handle = NULL;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
snd_ctl_elem_info_get_id(info, id); /* FIXME: Remove it when hctl find works ok !!! */
|
||||
if (!roflag) {
|
||||
snd_ctl_elem_value_set_id(control, id);
|
||||
if ((err = snd_ctl_elem_read(handle, control)) < 0) {
|
||||
printf("Cannot read the given element from control %s\n", card);
|
||||
if (!keep_handle) {
|
||||
snd_ctl_close(handle);
|
||||
handle = NULL;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
err = snd_ctl_ascii_value_parse(handle, control, info, argv2);
|
||||
if (err < 0) {
|
||||
printf("Control %s parse error: %s\n", card, snd_strerror(err));
|
||||
if (!keep_handle) {
|
||||
snd_ctl_close(handle);
|
||||
handle = NULL;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
if ((err = snd_ctl_elem_write(handle, control)) < 0) {
|
||||
printf("Control %s element write error: %s\n", card,
|
||||
snd_strerror(err));
|
||||
if (!keep_handle) {
|
||||
snd_ctl_close(handle);
|
||||
handle = NULL;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if (!keep_handle) {
|
||||
snd_ctl_close(handle);
|
||||
handle = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//amixer cset name='ADC1 PGA gain' 1
|
||||
int alsa_mixer_set_gain(int mic_gain, int dsp_gain) {
|
||||
char mic_gain_buf[4];
|
||||
char dsp_gain_buf[4];
|
||||
int ret = 0;
|
||||
|
||||
sprintf(mic_gain_buf, "%d", mic_gain);
|
||||
sprintf(dsp_gain_buf, "%d", dsp_gain);
|
||||
|
||||
#if 0
|
||||
ret = cset(2, "name='ADC Gain Switch'", "0", 0, 0);
|
||||
ret = cset(2, "name='ADC1 PGA gain'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='ADC2 PGA gain'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='ADC3 PGA gain'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='ADC4 PGA gain'", mic_gain_buf, 0, 0);
|
||||
|
||||
//ADC2
|
||||
ret = cset(2, "name='ADC Gain Switch'", "1", 0, 0);
|
||||
ret = cset(2, "name='ADC1 PGA gain'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='ADC2 PGA gain'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='ADC3 PGA gain'", dsp_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='ADC4 PGA gain'", dsp_gain_buf, 0, 0);
|
||||
#endif
|
||||
ret = cset(2, "name='PGA1_setting'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='PGA2_setting'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='PGA3_setting'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='PGA4_setting'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='PGA5_setting'", dsp_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='PGA6_setting'", dsp_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='PGA7_setting'", mic_gain_buf, 0, 0);
|
||||
ret = cset(2, "name='PGA8_setting'", mic_gain_buf, 0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int alsa_mixer_switch_mode(int mode) {
|
||||
int ret = 0;
|
||||
if(mode==0){ //default
|
||||
ret = cset(2, "name='Channel Switch'", "0", 0, 0);
|
||||
}
|
||||
else{
|
||||
ret = cset(2, "name='Channel Switch'", "1", 0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
#ifndef _TDMIN_INTERFACE_H_
|
||||
#define _TDMIN_INTERFACE_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#define PB_ALSA_DEBUG_TAG "<playback_alsa>"
|
||||
|
||||
#define TDM_IN_DEVICE_NAME "hw:0,1"
|
||||
#define INTER_ADC_DEVICE_NAME "hw:0,2"
|
||||
|
||||
#define AISPEECH_TDMIC_PCM_RECORD_DEVICE_NAME "hw:0,1"
|
||||
#define AISPEECH_TDMIC_SAMPLERATE 16000
|
||||
#define AISPEECH_TDMIC_CHANNLE 8
|
||||
#define AISPEECH_TDMIC_BITWIDTH 16
|
||||
#define PCM_SEEK_BIT 2
|
||||
|
||||
#define AISPEECH_FEED_DATA_LENGTH_32 AISPEECH_TDMIC_SAMPLERATE*AISPEECH_TDMIC_CHANNLE*AISPEECH_TDMIC_BITWIDTH/8/10
|
||||
#define AISPEECH_FEED_DATA_LENGTH_24 AISPEECH_FEED_DATA_LENGTH_32*3/4
|
||||
#define AISPEECH_FEED_DATA_LENGTH_16 AISPEECH_FEED_DATA_LENGTH_32/2
|
||||
|
||||
#define TDMIN_OK (0)
|
||||
#define TDMIN_FAIL (-1) /* abnormal return must < 0 */
|
||||
#define TDMIN_INV_ARG (-2)
|
||||
|
||||
/* Definitions for Microsoft WAVE format */
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define COMPOSE_ID(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24))
|
||||
#define LE_SHORT(v) (v)
|
||||
#define LE_INT(v) (v)
|
||||
#define BE_SHORT(v) bswap_16(v)
|
||||
#define BE_INT(v) bswap_32(v)
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define COMPOSE_ID(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24))
|
||||
#define LE_SHORT(v) bswap_16(v)
|
||||
#define LE_INT(v) bswap_32(v)
|
||||
#define BE_SHORT(v) (v)
|
||||
#define BE_INT(v) (v)
|
||||
#else
|
||||
#error "Wrong endian"
|
||||
#endif
|
||||
|
||||
typedef long long _off64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
|
||||
typedef struct PCMContainer {
|
||||
snd_pcm_t *handle; /*need to set*/
|
||||
snd_output_t *log;
|
||||
snd_pcm_uframes_t chunk_size; /*auto calc*/
|
||||
snd_pcm_uframes_t buffer_size; /*auto calc*/
|
||||
snd_pcm_format_t format; /*need to set*/
|
||||
uint16_t channels; /*need to set*/
|
||||
size_t chunk_bytes;
|
||||
size_t chunk_bytes_16;
|
||||
size_t bits_per_sample;
|
||||
size_t bits_per_frame;
|
||||
size_t sample_rate; /*need to set*/
|
||||
_off64_t chunk_count; /*usb wav need to set */
|
||||
|
||||
uint8_t *data_buf;
|
||||
uint8_t *data_buf_16;
|
||||
} PCMContainer_t;
|
||||
|
||||
|
||||
int _pcm_32_to_16(char *dst_buf, char *ori_buf, int ori_len, int fseek_bit);
|
||||
int alsa_tdmin_init(PCMContainer_t *pcm_params, int samplerate,int channels,int max_buffer_time);
|
||||
void alsa_tdmin_uninit(PCMContainer_t *pcm_params);
|
||||
int alsa_read_tdmin_pcm(PCMContainer_t *pcm_params);
|
||||
int alsa_mixer_set_gain(int mic_gain, int dsp_gain);
|
||||
int alsa_mixer_switch_mode(int mode);
|
||||
int asla_tdmin_set_bias(int on);
|
||||
int asla_tdmin_init_bias();
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue