一.tinyalsa介绍
ALSA(Advanced Linux Sound Architecture)是一个开源项目,涵盖了用户空间和内核空间对音频设备的操作接口,通过应用层使用alsalib可以实现对音频设备的控制
TinyAlsa是android推出的一个精简的ALSA库,当然alsa-driver这块没有改动
alsa包含:1、内核 alsa-driver 2.用户空间 alsa-lib(android使用的TinyAlsa)
二.使用tinyplay测试音频
tinycap /data/test.wav -D pdm声卡号 -d 0 -c 10 -r 48000 -b 16 -p 1024 -n 4 //D 后面接pdm声卡的声卡号
三.在TinyAlsa集成第三方音频降
tinyalsa目录:
hardware\rockchip\audio\tinyalsa_hal\
第三方算法供应商提供的音频降噪算法so库:
修改Android:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libElevocMeetingVoice
+LOCAL_SRC_FILES_32 := lib_out_honghe/armeabi-v7a/libElevocMeetingVoice.so
+LOCAL_SRC_FILES_64 := lib_out_honghe/arm64-v8a/libElevocMeetingVoice.so
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MULTILIB := both
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := audio.primary.$(TARGET_BOARD_HARDWARE)
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
bitstream/audio_iec958.c \
bitstream/audio_bitstream.c \
bitstream/audio_bitstream_manager.c \
audio_hw.c \
alsa_route.c \
alsa_mixer.c \
voice_preprocess.c \
audio_hw_hdmi.c \
out_honghe.c \
denoise/rkdenoise.c
LOCAL_C_INCLUDES += \
$(call include-path-for, audio-utils) \
$(call include-path-for, audio-route) \
$(call include-path-for, speex)
LOCAL_CFLAGS += -Wno-error
+LOCAL_SHARED_LIBRARIES := liblog libcutils libaudioutils libaudioroute +libhardware_legacy libspeexresampler libElevocMeetingVoice
#API 31 -> Android 12.0, Android 12.0 link libtinyalsa_iec958
ifneq (1, $(strip $(shell expr $(PLATFORM_SDK_VERSION) \< 31)))
LOCAL_SHARED_LIBRARIES += libtinyalsa_iec958
else
LOCAL_SHARED_LIBRARIES += libtinyalsa
endif
ifeq ($(strip $(BOARD_SUPPORT_MULTIAUDIO)), true)
LOCAL_CFLAGS += -DSUPPORT_MULTIAUDIO
endif
LOCAL_STATIC_LIBRARIES := libspeex
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -Wno-error
LOCAL_SRC_FILES:= amix.c alsa_mixer.c
LOCAL_MODULE:= amix
LOCAL_PROPRIETARY_MODULE := true
LOCAL_SHARED_LIBRARIES := liblog libc libcutils
include $(BUILD_EXECUTABLE)
这样降噪音频算法so就集成在Android里面了。
一般算法供应商会提供调用的算法的demo供我们集成在tinyalsa里面。
四.使用算法供应商提供的demo测试音频
main.cpp:
//#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <memory>
#include <iostream>
#include <time.h>
//#include "wav_io.h"
#include "ElevocAIOTProcess.h"
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <sys/time.h>
#endif
#include <chrono>
using namespace std;
#define ELEV_FRMAE_SIZE 256
#define ELEV_MIC_NUM 8
#define ELEV_REF_NUM 2
#define ELEV_ALL_NUM (ELEV_MIC_NUM+ELEV_REF_NUM)
static const char* fname_mdl = "./model-1477000--11.475842399597168_export_convert_mdl_q16.EM2";
void test_short(){
ELEVOC_AIOT_PROCESS* p = elevoc_aiot_init(fname_mdl);
string record_filePath = "./";
string input_path = record_filePath + "in.pcm";// "testg12_6ch_230815.raw";// "testg12_230815.raw";// "testg12.raw"; //"testg12.raw";
FILE* ifp = fopen(input_path.c_str(), "rb");
size_t input_size = 0;
if (ifp != NULL) {
if (!fseek(ifp, 0, SEEK_END)) {
input_size = ftell(ifp);
fseek(ifp, 0, SEEK_SET);
}
}
else {
fprintf(stderr, "file open error\n");
}
printf("samplers : %zd\n", input_size / sizeof(float));
string outPath = record_filePath + "out.pcm";
FILE* pFout = fopen(outPath.c_str(), "wb");
size_t once_read = ELEV_FRMAE_SIZE * ELEV_ALL_NUM;
size_t left_size = input_size / sizeof(int16_t);
size_t readSize = 0;
int16_t readBuffer[ELEV_FRMAE_SIZE * ELEV_ALL_NUM];
int16_t outputBuffer[ELEV_FRMAE_SIZE];
int16_t output[ELEV_FRMAE_SIZE];
printf("start ...\n");
clock_t start, finish;
double total_time;
int frm = 0;
#ifdef COUNT_ELAPSE
double elapseSum = 0;
double maxElapse = 0;
double minElapse = 100;
#endif
while (true) {
frm++;
/*if (frm>=63*114)
{
printf("debug\n");
}*/
readSize = left_size < once_read ? left_size : once_read;
if (readSize < once_read) {
break;
}
fread(readBuffer, sizeof(int16_t), once_read, ifp);
//start = clock();
#ifdef COUNT_ELAPSE
auto startTime = std::chrono::system_clock::now();
#endif
printf("guyilian elevoc_aiot_process_short start ...\n");
elevoc_aiot_process_short(p, readBuffer, once_read* sizeof(short), outputBuffer);
printf("guyilian elevoc_aiot_process_short end ...\n");
#ifdef COUNT_ELAPSE
auto endTime = std::chrono::system_clock::now();
std::chrono::duration<double, std::milli> elapse = endTime - startTime;
double elapseDouble = elapse.count();
if (elapseDouble > maxElapse) {
maxElapse = elapseDouble;
}
if (minElapse > elapseDouble) {
minElapse = elapseDouble;
}
elapseSum += elapseDouble;
#endif
//finish = clock();
//long total_time = (finish - start);
//printf("time %ld msec \n", total_time);
for (int i = 0; i < ELEV_FRMAE_SIZE; i++)
{
output[i] = (int16_t)(outputBuffer[i] * 1);
}
fwrite(output, sizeof(int16_t), ELEV_FRMAE_SIZE, pFout);
left_size -= readSize;
}
#ifdef COUNT_ELAPSE
std::printf("each frame process avg = cost %f ms ,[min = %f][max = %f] \n",
elapseSum / (double)frm, minElapse, maxElapse);
#endif
printf("end ...\n");
fclose(pFout);
}
int main() {
//test();
test_short();
system("PAUSE");
return 0;
}
Android: 文章来源:https://www.toymoban.com/news/detail-818732.html
LOCAL_PATH := $(call my-dir)
LOCAL_C_INCLUDES += \
elemain/ElevocAIOTProcess.h
include $(CLEAR_VARS)
LOCAL_CFLAGS += -Wno-error
LOCAL_SRC_FILES := \
main.cpp
LOCAL_MODULE:= elemain
LOCAL_PROPRIETARY_MODULE := true
LOCAL_SHARED_LIBRARIES := liblog libc libcutils libElevocMeetingVoice
include $(BUILD_EXECUTABLE)
这样测试demo会被编译成可执行文件elemain。文章来源地址https://www.toymoban.com/news/detail-818732.html
到了这里,关于RK3568平台 TinyAlsa集成第三方音频算法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!