Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
872
sdk/lib/audio/audio_code/audio_code.c
Normal file
872
sdk/lib/audio/audio_code/audio_code.c
Normal file
@@ -0,0 +1,872 @@
|
||||
#include "basic_include.h"
|
||||
#include "lib/audio/audio_code/audio_code.h"
|
||||
|
||||
AUCODE_MANAGE *g_aucode_manage = NULL;
|
||||
struct os_mutex g_aucode_mutex;
|
||||
|
||||
AUCODE_MALLOC aucode_malloc = NULL;
|
||||
AUCODE_ZALLOC aucode_zalloc = NULL;
|
||||
AUCODE_CALLOC aucode_calloc = NULL;
|
||||
AUCODE_REALLOC aucode_realloc = NULL;
|
||||
AUCODE_FREE aucode_free = NULL;
|
||||
|
||||
void reg_aucoder_alloc(AUCODE_MALLOC m, AUCODE_ZALLOC z, AUCODE_CALLOC c, AUCODE_REALLOC r, AUCODE_FREE f)
|
||||
{
|
||||
aucode_malloc = m;
|
||||
aucode_zalloc = z;
|
||||
aucode_calloc = c;
|
||||
aucode_realloc = r;
|
||||
aucode_free = f;
|
||||
}
|
||||
|
||||
void aucode_mutex_init(void)
|
||||
{
|
||||
os_mutex_init(&g_aucode_mutex);
|
||||
}
|
||||
|
||||
void *aucode_stack_alloc(uint32_t size)
|
||||
{
|
||||
void *return_addr = NULL;
|
||||
if((size%32)!=0) {
|
||||
size = (size+32)/32*32;
|
||||
}
|
||||
// os_printf("%s %d %d %x\n",__FUNCTION__,g_aucode_manage->used_size,size,RETURN_ADDR());
|
||||
if((g_aucode_manage->used_size+sizeof(uint32_t)+size)>g_aucode_manage->total_size) {
|
||||
while(1) {
|
||||
_os_printf("aucode_stack_alloc fail\n");
|
||||
os_sleep_ms(1000);
|
||||
}
|
||||
}
|
||||
*((uint32_t*)(g_aucode_manage->stack_priv+g_aucode_manage->used_size+size)) = size;
|
||||
return_addr = g_aucode_manage->stack_priv+g_aucode_manage->used_size;
|
||||
// os_printf("%s %p %p\n",__FUNCTION__,return_addr,(g_aucode_manage->stack_priv+g_aucode_manage->used_size+size));
|
||||
g_aucode_manage->used_size += (sizeof(uint32_t)+size);
|
||||
return return_addr;
|
||||
}
|
||||
|
||||
void aucode_stack_free(void *ptr)
|
||||
{
|
||||
uint32_t last_size = *((uint32_t*)(g_aucode_manage->stack_priv+g_aucode_manage->used_size-4));
|
||||
// os_printf("%s %p %p %d\n",__FUNCTION__,ptr,(g_aucode_manage->stack_priv+g_aucode_manage->used_size-4),last_size);
|
||||
if(ptr != (g_aucode_manage->stack_priv+g_aucode_manage->used_size-last_size-4)) {
|
||||
while(1) {
|
||||
_os_printf("aucode_stack_free fail\n");
|
||||
os_sleep_ms(1000);
|
||||
}
|
||||
}
|
||||
g_aucode_manage->used_size -= (sizeof(uint32_t)+last_size);
|
||||
// os_printf("%s %d\n",__FUNCTION__,g_aucode_manage->used_size);
|
||||
}
|
||||
|
||||
AUCODE_HDL *audio_coder_open(uint32_t coder, uint32_t samplerate, uint32_t channel)
|
||||
{
|
||||
AUCODE_HDL *aucode_hdl = NULL;
|
||||
if(g_aucode_mutex.hdl) {
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
}
|
||||
else {
|
||||
AUCODE_INFO("g_aucode_mutex.hdl is null\n");
|
||||
return NULL;
|
||||
}
|
||||
if(g_aucode_manage == NULL) {
|
||||
g_aucode_manage = (AUCODE_MANAGE*)aucode_zalloc(sizeof(AUCODE_MANAGE));
|
||||
}
|
||||
if(g_aucode_manage == NULL) {
|
||||
AUCODE_INFO("alloc aucode_manage fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
aucode_hdl = (AUCODE_HDL*)aucode_zalloc(sizeof(AUCODE_HDL));
|
||||
if(!aucode_hdl) {
|
||||
AUCODE_INFO("alloc aucode_hdl fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
switch(coder) {
|
||||
#if AAC_ENC_CTRL
|
||||
case AAC_ENC:
|
||||
{
|
||||
void *aac_enc = NULL;
|
||||
#if AAC_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
aac_enc = aac_encoder_open(samplerate, channel);
|
||||
#else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
aac_enc = aac_encoder_open_rpc(samplerate, channel);
|
||||
if(aac_enc) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = aac_enc;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if (!aac_enc) {
|
||||
AUCODE_INFO("aac encoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = aac_enc;
|
||||
aucode_hdl->coder_type = AAC_ENC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if AAC_DEC_CTRL
|
||||
case AAC_DEC:
|
||||
{
|
||||
void *aac_dec = NULL;
|
||||
#if AAC_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
aac_dec = aac_decoder_open();
|
||||
#else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
aac_dec = aac_decoder_open_rpc();
|
||||
if(aac_dec) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = aac_dec;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if(!aac_dec) {
|
||||
AUCODE_INFO("aac decoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = aac_dec;
|
||||
aucode_hdl->coder_type = AAC_DEC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if AMRNB_DEC_CTRL
|
||||
case AMRNB_DEC:
|
||||
{
|
||||
void *amrnb_dec = NULL;
|
||||
#if AMRNB_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
amrnb_dec = amrnb_decoder_open();
|
||||
#else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
amrnb_dec = amrnb_decoder_open_rpc();
|
||||
if(amrnb_dec) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = amrnb_dec;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if(!amrnb_dec) {
|
||||
AUCODE_INFO("amrnb decoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = amrnb_dec;
|
||||
aucode_hdl->coder_type = AMRNB_DEC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if AMRWB_DEC_CTRL
|
||||
case AMRWB_DEC:
|
||||
{
|
||||
void *amrwb_dec = NULL;
|
||||
#if AMRWB_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
amrwb_dec = amrwb_decoder_open();
|
||||
#else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
amrwb_dec = amrwb_decoder_open_rpc();
|
||||
if(amrwb_dec) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = amrwb_dec;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if(!amrwb_dec) {
|
||||
AUCODE_INFO("amrwb decoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = amrwb_dec;
|
||||
aucode_hdl->coder_type = AMRWB_DEC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if MP3_DEC_CTRL
|
||||
case MP3_DEC:
|
||||
{
|
||||
void *mp3_dec = NULL;
|
||||
mp3_dec = mp3_decoder_open();
|
||||
if(!mp3_dec) {
|
||||
AUCODE_INFO("mp3 decoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = mp3_dec;
|
||||
aucode_hdl->coder_type = MP3_DEC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ALAW_ENC_CTRL
|
||||
case ALAW_ENC:
|
||||
{
|
||||
void *alaw_enc = NULL;
|
||||
#if ALAW_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
alaw_enc = alaw_encoder_open();
|
||||
else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
alaw_enc = alaw_encoder_open_rpc();
|
||||
if(alaw_enc) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = alaw_enc;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if(!alaw_enc) {
|
||||
AUCODE_INFO("alaw encoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = alaw_enc;
|
||||
aucode_hdl->coder_type = ALAW_ENC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ALAW_DEC_CTRL
|
||||
case ALAW_DEC:
|
||||
{
|
||||
void *alaw_dec = NULL;
|
||||
#if ALAW_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
alaw_dec = alaw_decoder_open();
|
||||
else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
alaw_dec = alaw_decoder_open_rpc();
|
||||
if(alaw_dec) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = alaw_dec;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if(!alaw_dec) {
|
||||
AUCODE_INFO("alaw decoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = alaw_dec;
|
||||
aucode_hdl->coder_type = ALAW_DEC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ULAW_ENC_CTRL
|
||||
case ULAW_ENC:
|
||||
{
|
||||
void *ulaw_enc = NULL;
|
||||
#if ALAW_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
ulaw_enc = ulaw_encoder_open();
|
||||
else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
ulaw_enc = ulaw_encoder_open_rpc();
|
||||
if(ulaw_enc) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = ulaw_enc;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if(!ulaw_enc) {
|
||||
AUCODE_INFO("ulaw encoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = ulaw_enc;
|
||||
aucode_hdl->coder_type = ULAW_ENC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ULAW_DEC_CTRL
|
||||
case ULAW_DEC:
|
||||
{
|
||||
void *ulaw_dec = NULL;
|
||||
#if ULAW_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
ulaw_dec = ulaw_decoder_open();
|
||||
else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
ulaw_dec = ulaw_decoder_open_rpc();
|
||||
if(ulaw_dec) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = ulaw_dec;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if(!ulaw_dec) {
|
||||
AUCODE_INFO("ulaw decoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = ulaw_dec;
|
||||
aucode_hdl->coder_type = ULAW_DEC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if OPUS_ENC_CTRL
|
||||
case OPUS_ENC:
|
||||
{
|
||||
void *opus_enc = NULL;
|
||||
#if OPUS_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
opus_enc = opus_encoder_open(samplerate, channel);
|
||||
#else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
opus_enc = opus_encoder_open_rpc(samplerate, channel);
|
||||
if(opus_enc) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = opus_enc;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if(!opus_enc) {
|
||||
AUCODE_INFO("opus encoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
if(g_aucode_manage->stack_priv == NULL) {
|
||||
g_aucode_manage->total_size = AUCODE_STACK_SIZE;
|
||||
g_aucode_manage->used_size = 0;
|
||||
g_aucode_manage->stack_priv = (int8_t*)aucode_malloc(sizeof(int8_t) * g_aucode_manage->total_size);
|
||||
if(g_aucode_manage->stack_priv == NULL) {
|
||||
#if OPUS_ENC_CTRL == AUCODER_RUN_IN_CPU1
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = NULL;
|
||||
#endif
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
}
|
||||
g_aucode_manage->stack_used_num++;
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = opus_enc;
|
||||
aucode_hdl->coder_type = OPUS_ENC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if OPUS_DEC_CTRL
|
||||
case OPUS_DEC:
|
||||
{
|
||||
void *opus_dec = NULL;
|
||||
#if OPUS_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
opus_dec = opus_decoder_open(samplerate, channel);
|
||||
#else
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
audio_coder_run_rpc(g_aucode_manage);
|
||||
}
|
||||
if(g_aucode_manage->task_hdl == NULL) {
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
opus_dec = opus_decoder_open_rpc(samplerate, channel);
|
||||
if(opus_dec) {
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = opus_dec;
|
||||
g_aucode_manage->rpc_coder_num++;
|
||||
}
|
||||
#endif
|
||||
if (!opus_dec) {
|
||||
AUCODE_INFO("opus decoder open fail!\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
if(g_aucode_manage->stack_priv == NULL) {
|
||||
g_aucode_manage->total_size = AUCODE_STACK_SIZE;
|
||||
g_aucode_manage->used_size = 0;
|
||||
g_aucode_manage->stack_priv = (int8_t*)aucode_malloc(sizeof(int8_t) * g_aucode_manage->total_size);
|
||||
if(g_aucode_manage->stack_priv == NULL) {
|
||||
#if OPUS_DEC_CTRL == AUCODER_RUN_IN_CPU1
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
g_aucode_manage->rpc_aucode_s[g_aucode_manage->rpc_coder_num] = NULL;
|
||||
#endif
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
}
|
||||
g_aucode_manage->stack_used_num++;
|
||||
g_aucode_manage->coder_num++;
|
||||
aucode_hdl->coder = opus_dec;
|
||||
aucode_hdl->coder_type = OPUS_DEC;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
AUCODE_INFO("audio coder open fail,unsupport coder type!\r\n");
|
||||
goto audio_coder_open_err;
|
||||
}
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
return aucode_hdl;
|
||||
audio_coder_open_err:
|
||||
if(g_aucode_manage) {
|
||||
if(g_aucode_manage->stack_priv && (g_aucode_manage->stack_used_num == 0)) {
|
||||
aucode_free(g_aucode_manage->stack_priv);
|
||||
g_aucode_manage->stack_priv = NULL;
|
||||
}
|
||||
if(g_aucode_manage->rpc_coder_num == 0) {
|
||||
if(g_aucode_manage->task_hdl) {
|
||||
g_aucode_manage->state = coder_close;
|
||||
while(g_aucode_manage->state != coder_exit) {
|
||||
os_sleep_ms(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(g_aucode_manage->coder_num == 0) {
|
||||
aucode_free(g_aucode_manage);
|
||||
g_aucode_manage = NULL;
|
||||
}
|
||||
}
|
||||
if(aucode_hdl) {
|
||||
aucode_free(aucode_hdl);
|
||||
}
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t audio_encoder_set_bitrate(AUCODE_HDL *aucode_hdl, uint32_t bitrate)
|
||||
{
|
||||
int32_t ret = AUCODE_ERR;
|
||||
switch(aucode_hdl->coder_type) {
|
||||
#if OPUS_ENC_CTRL
|
||||
case OPUS_ENC:
|
||||
{
|
||||
#if OPUS_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
ret = opus_encoder_set_bitrate(aucode_hdl->coder, bitrate);
|
||||
#else
|
||||
ret = opus_encoder_set_bitrate_rpc(aucode_hdl->coder, bitrate);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
AUCODE_INFO("audio encoder unsupport set bitrate!\r\n");
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t audio_encode_data(AUCODE_HDL *aucode_hdl, int16_t *in_data, uint32_t samples, uint8_t *out_data)
|
||||
{
|
||||
int32_t encode_bytes = 0;
|
||||
|
||||
switch(aucode_hdl->coder_type) {
|
||||
#if AAC_ENC_CTRL
|
||||
case AAC_ENC:
|
||||
{
|
||||
#if AAC_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
encode_bytes = aac_encode_data(aucode_hdl->coder, in_data, samples, out_data);
|
||||
#else
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
audio_encode_data_rpc(aucode_hdl->coder, in_data, samples, out_data, &encode_bytes);
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ALAW_ENC_CTRL
|
||||
case ALAW_ENC:
|
||||
{
|
||||
#if ALAW_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
encode_bytes = alaw_encode_data(aucode_hdl->coder, in_data, samples, out_data);
|
||||
#else
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
audio_encode_data_rpc(aucode_hdl->coder, in_data, samples, out_data, &encode_bytes);
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ULAW_ENC_CTRL
|
||||
case ULAW_ENC:
|
||||
{
|
||||
#if ALAW_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
encode_bytes = ulaw_encode_data(aucode_hdl->coder, in_data, samples, out_data);
|
||||
#else
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
audio_encode_data_rpc(aucode_hdl->coder, in_data, samples, out_data, &encode_bytes);
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if OPUS_ENC_CTRL
|
||||
case OPUS_ENC:
|
||||
{
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
#if OPUS_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
encode_bytes = opus_encode_data(aucode_hdl->coder, in_data, samples, out_data);
|
||||
#else
|
||||
audio_encode_data_rpc(aucode_hdl->coder, in_data, samples, out_data, &encode_bytes);
|
||||
#endif
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
AUCODE_INFO("audio encode data fail,unknow coder type!\r\n");
|
||||
break;
|
||||
}
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
return encode_bytes;
|
||||
}
|
||||
|
||||
int32_t audio_decode_fade_in(AUCODE_HDL *aucode_hdl)
|
||||
{
|
||||
aucode_hdl->fade_type = 1;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t audio_decode_fade_out(AUCODE_HDL *aucode_hdl)
|
||||
{
|
||||
aucode_hdl->fade_type = 2;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t audio_decode_data(AUCODE_HDL *aucode_hdl, uint8_t *in_data, uint32_t bytes, int16_t *out_data, AUCODE_FRAME_INFO *frame_info)
|
||||
{
|
||||
int32_t decode_samples = 0;
|
||||
float fade_init = 0.0001f;
|
||||
float fade_speed = 0.0001f;
|
||||
|
||||
switch(aucode_hdl->coder_type) {
|
||||
#if AAC_DEC_CTRL
|
||||
case AAC_DEC:
|
||||
{
|
||||
#if AAC_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
decode_samples = aac_decode_data(aucode_hdl->coder, in_data, bytes, out_data, frame_info);
|
||||
#else
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
audio_decode_data_rpc(aucode_hdl->coder, in_data, bytes, out_data, frame_info, &decode_samples);
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if AMRNB_DEC_CTRL
|
||||
case AMRNB_DEC:
|
||||
{
|
||||
#if AMRNB_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
decode_samples = amrnb_decode_data(aucode_hdl->coder, in_data, bytes, out_data, frame_info);
|
||||
#else
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
audio_decode_data_rpc(aucode_hdl->coder, in_data, bytes, out_data, frame_info, &decode_samples);
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if AMRWB_DEC_CTRL
|
||||
case AMRWB_DEC:
|
||||
{
|
||||
#if AMRWB_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
decode_samples = amrwb_decode_data(aucode_hdl->coder, in_data, bytes, out_data, frame_info);
|
||||
#else
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
audio_decode_data_rpc(aucode_hdl->coder, in_data, bytes, out_data, frame_info, &decode_samples);
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if MP3_DEC_CTRL
|
||||
case MP3_DEC:
|
||||
{
|
||||
decode_samples = mp3_decode_data(aucode_hdl->coder, in_data, bytes, out_data, frame_info);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ALAW_DEC_CTRL
|
||||
case ALAW_DEC:
|
||||
{
|
||||
#if ALAW_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
decode_samples = alaw_decode_data(aucode_hdl->coder, in_data, bytes, out_data, frame_info);
|
||||
#else
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
audio_decode_data_rpc(aucode_hdl->coder, in_data, bytes, out_data, frame_info, &decode_samples);
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ULAW_DEC_CTRL
|
||||
case ULAW_DEC:
|
||||
{
|
||||
#if ULAW_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
decode_samples = ulaw_decode_data(aucode_hdl->coder, in_data, bytes, out_data, frame_info);
|
||||
#else
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
audio_decode_data_rpc(aucode_hdl->coder, in_data, bytes, out_data, frame_info, &decode_samples);
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if OPUS_DEC_CTRL
|
||||
case OPUS_DEC:
|
||||
{
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
#if OPUS_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
decode_samples = opus_decode_data(aucode_hdl->coder, in_data, bytes, out_data, frame_info);
|
||||
#else
|
||||
audio_decode_data_rpc(aucode_hdl->coder, in_data, bytes, out_data, frame_info, &decode_samples);
|
||||
#endif
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
AUCODE_INFO("audio decode data fail,unknow coder type!\r\n");
|
||||
break;
|
||||
}
|
||||
if(aucode_hdl->fade_type == 1) {
|
||||
fade_init = 0.0001f;
|
||||
fade_speed = 1.0f / decode_samples;
|
||||
for(uint32_t i=0; i<decode_samples; i++) {
|
||||
out_data[i] = (int16_t)((float)out_data[i] * fade_init);
|
||||
fade_init += fade_speed;
|
||||
}
|
||||
}
|
||||
else if(aucode_hdl->fade_type == 2) {
|
||||
fade_init = 1.0f;
|
||||
fade_speed = 1.0f / decode_samples;
|
||||
for(uint32_t i=0; i<decode_samples; i++) {
|
||||
out_data[i] = (int16_t)((float)out_data[i] * fade_init);
|
||||
fade_init -= fade_speed;
|
||||
}
|
||||
}
|
||||
aucode_hdl->fade_type = 0;
|
||||
aucode_hdl->frame_nsamples = decode_samples;
|
||||
return decode_samples;
|
||||
}
|
||||
|
||||
int32_t audio_decode_output_mute(AUCODE_HDL *aucode_hdl, int16_t *out_data)
|
||||
{
|
||||
int32_t decode_samples = 0;
|
||||
decode_samples = aucode_hdl->frame_nsamples;
|
||||
os_memset(out_data, 0, decode_samples * sizeof(int16_t));
|
||||
return decode_samples;
|
||||
}
|
||||
|
||||
int32_t audio_decode_do_plc(AUCODE_HDL *aucode_hdl, int16_t *out_data)
|
||||
{
|
||||
int32_t decode_samples = 0;
|
||||
switch(aucode_hdl->coder_type) {
|
||||
#if OPUS_DEC_CTRL
|
||||
case OPUS_DEC:
|
||||
{
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
#if OPUS_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
decode_samples = opus_decode_plc(aucode_hdl->coder, out_data, aucode_hdl->frame_nsamples);
|
||||
#else
|
||||
audio_decode_plc_rpc(aucode_hdl->coder, out_data, aucode_hdl->frame_nsamples, &decode_samples);
|
||||
#endif
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
AUCODE_INFO("audio decoder unsupport do plc!\r\n");
|
||||
break;
|
||||
}
|
||||
return decode_samples;
|
||||
}
|
||||
|
||||
void audio_coder_close(AUCODE_HDL *aucode_hdl)
|
||||
{
|
||||
if(aucode_hdl == NULL) {
|
||||
return;
|
||||
}
|
||||
os_mutex_lock(&g_aucode_mutex, osWaitForever);
|
||||
for(uint32_t i=0; i<g_aucode_manage->rpc_coder_num; i++) {
|
||||
if(g_aucode_manage->rpc_aucode_s[i] == aucode_hdl->coder) {
|
||||
g_aucode_manage->rpc_aucode_s[i] = NULL;
|
||||
os_memmove(&(g_aucode_manage->rpc_aucode_s[i]), &(g_aucode_manage->rpc_aucode_s[i+1]),
|
||||
(g_aucode_manage->rpc_coder_num-1-i)*sizeof(RPC_AUCODE_STRUCT*));
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch(aucode_hdl->coder_type) {
|
||||
#if AAC_ENC_CTRL
|
||||
case AAC_ENC:
|
||||
{
|
||||
#if AAC_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
aac_encoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if AAC_DEC_CTRL
|
||||
case AAC_DEC:
|
||||
{
|
||||
#if AAC_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
aac_decoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if AMRNB_DEC_CTRL
|
||||
case AMRNB_DEC:
|
||||
{
|
||||
#if AMRNB_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
amrnb_decoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if AMRWB_DEC_CTRL
|
||||
case AMRWB_DEC:
|
||||
{
|
||||
#if AMRWB_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
amrwb_decoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if MP3_DEC_CTRL
|
||||
case MP3_DEC:
|
||||
{
|
||||
mp3_decoder_close(aucode_hdl->coder);
|
||||
g_aucode_manage->coder_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ALAW_ENC_CTRL
|
||||
case ALAW_ENC:
|
||||
{
|
||||
#if ALAW_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
alaw_encoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ALAW_DEC_CTRL
|
||||
case ALAW_DEC:
|
||||
{
|
||||
#if ALAW_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
alaw_decoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ULAW_ENC_CTRL
|
||||
case ULAW_ENC:
|
||||
{
|
||||
#if ULAW_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
ulaw_encoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if ULAW_DEC_CTRL
|
||||
case ULAW_DEC:
|
||||
{
|
||||
#if ULAW_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
ulaw_decoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if OPUS_ENC_CTRL
|
||||
case OPUS_ENC:
|
||||
{
|
||||
#if OPUS_ENC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
opus_encoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
g_aucode_manage->stack_used_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if OPUS_DEC_CTRL
|
||||
case OPUS_DEC:
|
||||
{
|
||||
#if OPUS_DEC_CTRL == AUCODER_RUN_IN_CPU0
|
||||
opus_decoder_close(aucode_hdl->coder);
|
||||
#else
|
||||
audio_coder_close_rpc(aucode_hdl->coder);
|
||||
g_aucode_manage->rpc_coder_num--;
|
||||
#endif
|
||||
g_aucode_manage->coder_num--;
|
||||
g_aucode_manage->stack_used_num--;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
AUCODE_INFO("audio coder close fail,unknow coder type!\r\n");
|
||||
break;
|
||||
}
|
||||
aucode_free(aucode_hdl);
|
||||
if(g_aucode_manage->stack_priv && (g_aucode_manage->stack_used_num == 0)) {
|
||||
aucode_free(g_aucode_manage->stack_priv);
|
||||
g_aucode_manage->stack_priv = NULL;
|
||||
}
|
||||
if(g_aucode_manage->rpc_coder_num == 0) {
|
||||
if(g_aucode_manage->task_hdl) {
|
||||
g_aucode_manage->state = coder_close;
|
||||
while(g_aucode_manage->state != coder_exit) {
|
||||
os_sleep_ms(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(g_aucode_manage->coder_num == 0) {
|
||||
aucode_free(g_aucode_manage);
|
||||
g_aucode_manage = NULL;
|
||||
}
|
||||
os_mutex_unlock(&g_aucode_mutex);
|
||||
}
|
||||
9
sdk/lib/audio/audio_code/audio_code_run_rpc.c
Normal file
9
sdk/lib/audio/audio_code/audio_code_run_rpc.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "basic_include.h"
|
||||
#include "lib/audio/audio_code/audio_code.h"
|
||||
#include "lib/rpc/cpurpc.h"
|
||||
|
||||
int32 audio_coder_run_rpc(AUCODE_MANAGE *aucode_manage)
|
||||
{
|
||||
uint32 args[] = {(uint32)aucode_manage};
|
||||
return CPU_RPC_CALL(audio_coder_run);
|
||||
}
|
||||
159
sdk/lib/audio/audio_proc/audio_proc.c
Normal file
159
sdk/lib/audio/audio_proc/audio_proc.c
Normal file
@@ -0,0 +1,159 @@
|
||||
#include "basic_include.h"
|
||||
#include "lib/audio/audio_proc/audio_proc.h"
|
||||
|
||||
AUPROC_STACK *g_auproc_stack = NULL;
|
||||
|
||||
volatile AUPROC_MALLOC auproc_malloc = NULL;
|
||||
volatile AUPROC_ZALLOC auproc_zalloc = NULL;
|
||||
volatile AUPROC_CALLOC auproc_calloc = NULL;
|
||||
volatile AUPROC_REALLOC auproc_realloc = NULL;
|
||||
volatile AUPROC_FREE auproc_free = NULL;
|
||||
|
||||
void reg_auproc_alloc(AUPROC_MALLOC m, AUPROC_ZALLOC z, AUPROC_CALLOC c, AUPROC_REALLOC r, AUPROC_FREE f)
|
||||
{
|
||||
auproc_malloc = m;
|
||||
auproc_zalloc = z;
|
||||
auproc_calloc = c;
|
||||
auproc_realloc = r;
|
||||
auproc_free = f;
|
||||
}
|
||||
|
||||
void *auproc_stack_alloc(uint32_t size)
|
||||
{
|
||||
void *return_addr = NULL;
|
||||
if((size%32)!=0) {
|
||||
size = (size+32)/32*32;
|
||||
}
|
||||
// _os_printf("%s %d %d %p\n",__FUNCTION__,g_auproc_stack->used_size,size,RETURN_ADDR());
|
||||
if((g_auproc_stack->used_size+sizeof(uint32_t)+size)>g_auproc_stack->total_size) {
|
||||
while(1) {
|
||||
_os_printf("auproc_stack_alloc fail\n");
|
||||
os_sleep_ms(1000);
|
||||
}
|
||||
}
|
||||
*((uint32_t*)(g_auproc_stack->stack_priv+g_auproc_stack->used_size+size)) = size;
|
||||
return_addr = g_auproc_stack->stack_priv+g_auproc_stack->used_size;
|
||||
// _os_printf("%s %p %p %p\n",__FUNCTION__,return_addr,(g_auproc_stack->stack_priv+g_auproc_stack->used_size+size),RETURN_ADDR());
|
||||
g_auproc_stack->used_size += (sizeof(uint32_t)+size);
|
||||
return return_addr;
|
||||
}
|
||||
|
||||
void auproc_stack_free(void *ptr)
|
||||
{
|
||||
uint32_t last_size = *((uint32_t*)(g_auproc_stack->stack_priv+g_auproc_stack->used_size-4));
|
||||
// _os_printf("%s %p %p %d %p\n",__FUNCTION__,ptr,(g_auproc_stack->stack_priv+g_auproc_stack->used_size-4),last_size,RETURN_ADDR());
|
||||
if(ptr != (g_auproc_stack->stack_priv+g_auproc_stack->used_size-last_size-4)) {
|
||||
while(1) {
|
||||
_os_printf("auproc_stack_free fail\n");
|
||||
os_sleep_ms(1000);
|
||||
}
|
||||
}
|
||||
g_auproc_stack->used_size -= (sizeof(uint32_t)+last_size);
|
||||
}
|
||||
|
||||
AUPROC_HDL *audio_process_init(uint32_t samplerate, uint32_t channels, uint32_t frame_size)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
AUPROC_HDL *auproc_hdl = NULL;
|
||||
g_auproc_stack = (AUPROC_STACK*)auproc_zalloc(sizeof(AUPROC_STACK));
|
||||
if(g_auproc_stack == NULL) {
|
||||
os_printf("alloc auproc stack fail\n");
|
||||
return NULL;
|
||||
}
|
||||
g_auproc_stack->stack_priv = (int8_t*)auproc_malloc(sizeof(int8_t)*AUPROC_STACK_SIZE);
|
||||
if(g_auproc_stack->stack_priv == NULL) {
|
||||
os_printf("alloc g_auproc_stack->stack_priv fail\n");
|
||||
goto audio_process_init_err;
|
||||
}
|
||||
g_auproc_stack->total_size = AUPROC_STACK_SIZE;
|
||||
auproc_hdl = audio_process_open(samplerate, channels, frame_size);
|
||||
if(!auproc_hdl) {
|
||||
os_printf("audio_process_open fail!\n");
|
||||
goto audio_process_init_err;
|
||||
}
|
||||
#if ANF_PROCESSING
|
||||
ret = auproc_attach_anf(auproc_hdl);
|
||||
if(ret != 0) {
|
||||
os_printf("auproc_attach_anf fail!\n");
|
||||
goto audio_process_init_err;
|
||||
}
|
||||
#endif
|
||||
#if AEC_PROCESSING
|
||||
ret = auproc_attach_aec(auproc_hdl);
|
||||
if(ret != 0) {
|
||||
os_printf("auproc_attach_aec fail!\n");
|
||||
goto audio_process_init_err;
|
||||
}
|
||||
#endif
|
||||
#if AHS_PROCESSING
|
||||
ret = auproc_attach_ahs(auproc_hdl, 3);
|
||||
if(ret != 0) {
|
||||
os_printf("auproc_attach_ahs fail!\n");
|
||||
goto audio_process_init_err;
|
||||
}
|
||||
#endif
|
||||
#if ANS_PROCESSING
|
||||
ret = auproc_attach_ans(auproc_hdl, 3);
|
||||
if(ret != 0) {
|
||||
os_printf("auproc_attach_ans fail!\n");
|
||||
goto audio_process_init_err;
|
||||
}
|
||||
#endif
|
||||
#if RES_PROCESSING
|
||||
ret = auproc_attach_res(auproc_hdl);
|
||||
if(ret != 0) {
|
||||
os_printf("auproc_attach_res fail!\n");
|
||||
goto audio_process_init_err;
|
||||
}
|
||||
#endif
|
||||
ret = audio_process_prepare(auproc_hdl);
|
||||
if(ret != RET_OK) {
|
||||
os_printf("audio_process_prepare fail!\n");
|
||||
goto audio_process_init_err;
|
||||
}
|
||||
return auproc_hdl;
|
||||
audio_process_init_err:
|
||||
if(auproc_hdl) {
|
||||
audio_process_close(auproc_hdl);
|
||||
}
|
||||
if(g_auproc_stack->stack_priv) {
|
||||
auproc_free(g_auproc_stack->stack_priv);
|
||||
}
|
||||
if(g_auproc_stack) {
|
||||
auproc_free(g_auproc_stack);
|
||||
g_auproc_stack = NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t audio_process_data(AUPROC_HDL *auproc_hdl, int16_t *data, uint32_t nsamples)
|
||||
{
|
||||
return audio_process(auproc_hdl, data, nsamples);
|
||||
}
|
||||
|
||||
int32_t audio_process_fardata(AUPROC_HDL *auproc_hdl, int16_t *data, uint32_t nsamples)
|
||||
{
|
||||
return audio_process_put_fardata(auproc_hdl, data, nsamples);
|
||||
}
|
||||
|
||||
int32_t audio_resample_config(AUPROC_HDL *auproc_hdl, uint32_t src_samplerate, uint32_t dest_samplerate)
|
||||
{
|
||||
return audio_resample_reconfig(auproc_hdl, src_samplerate, dest_samplerate);
|
||||
}
|
||||
|
||||
int32_t audio_resample_data(AUPROC_HDL *auproc_hdl, int16_t *in_data, uint32_t in_size, int16_t *out_data, uint32_t *out_size)
|
||||
{
|
||||
return audio_resample(auproc_hdl, in_data, in_size, out_data, out_size);
|
||||
}
|
||||
|
||||
int32_t audio_process_deinit(AUPROC_HDL *auproc_hdl)
|
||||
{
|
||||
if(g_auproc_stack->stack_priv) {
|
||||
auproc_free(g_auproc_stack->stack_priv);
|
||||
}
|
||||
if(g_auproc_stack) {
|
||||
auproc_free(g_auproc_stack);
|
||||
g_auproc_stack = NULL;
|
||||
}
|
||||
return audio_process_close(auproc_hdl);
|
||||
}
|
||||
148
sdk/lib/audio/ring_buffer/ring_buffer.c
Normal file
148
sdk/lib/audio/ring_buffer/ring_buffer.c
Normal file
@@ -0,0 +1,148 @@
|
||||
#include "basic_include.h"
|
||||
#include "lib/audio/ring_buffer/ring_buffer.h"
|
||||
#include "lib/heap/av_psram_heap.h"
|
||||
|
||||
RINGBUF *ringbuf_Init(uint8_t elementsize, uint32_t elementcount)
|
||||
{
|
||||
RINGBUF *ringbuf = (RINGBUF*)av_psram_zalloc(sizeof(RINGBUF));
|
||||
if(ringbuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ringbuf->front = 0;
|
||||
ringbuf->rear = 0;
|
||||
ringbuf->elementsize = elementsize;
|
||||
ringbuf->elementcount = elementcount + 1;
|
||||
ringbuf->data = av_psram_malloc(elementsize * (elementcount + 1) * sizeof(uint8_t));
|
||||
if(ringbuf->data == NULL) {
|
||||
av_psram_free(ringbuf);
|
||||
ringbuf = NULL;
|
||||
}
|
||||
return ringbuf;
|
||||
}
|
||||
|
||||
int32_t ringbuf_read_available(RINGBUF *ringbuf)
|
||||
{
|
||||
if(ringbuf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return ((ringbuf->rear + ringbuf->elementcount - ringbuf->front) % ringbuf->elementcount);
|
||||
}
|
||||
|
||||
int32_t ringbuf_write_available(RINGBUF *ringbuf)
|
||||
{
|
||||
if(ringbuf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return ((ringbuf->front + ringbuf->elementcount - ringbuf->rear - 1) % ringbuf->elementcount);
|
||||
}
|
||||
|
||||
int32_t ringbuf_read(RINGBUF *ringbuf, void *data, uint32_t elementcount)
|
||||
{
|
||||
uint32_t readcount = 0;
|
||||
if(ringbuf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if(ringbuf->front == ringbuf->rear) {
|
||||
return 0;
|
||||
}
|
||||
if(elementcount > (uint32_t)ringbuf_read_available(ringbuf)) {
|
||||
readcount = (uint32_t)ringbuf_read_available(ringbuf);
|
||||
}
|
||||
else {
|
||||
readcount = elementcount;
|
||||
}
|
||||
if((ringbuf->front + readcount) > (ringbuf->elementcount))
|
||||
{
|
||||
os_memcpy((uint8_t*)data, ringbuf->data + ringbuf->front * ringbuf->elementsize,
|
||||
(ringbuf->elementcount - ringbuf->front) * ringbuf->elementsize);
|
||||
os_memcpy(((uint8_t*)data) + (ringbuf->elementcount - ringbuf->front) * ringbuf->elementsize,
|
||||
ringbuf->data, (readcount - ringbuf->elementcount + ringbuf->front) * ringbuf->elementsize);
|
||||
}
|
||||
else {
|
||||
os_memcpy((uint8_t*)data, ringbuf->data + ringbuf->front * ringbuf->elementsize, readcount * ringbuf->elementsize);
|
||||
}
|
||||
ringbuf->front = (ringbuf->front + readcount) % (ringbuf->elementcount);
|
||||
return readcount;
|
||||
}
|
||||
|
||||
int32_t ringbuf_write(RINGBUF *ringbuf, void *data, uint32_t elementcount)
|
||||
{
|
||||
uint32_t writecount = 0;
|
||||
if(ringbuf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if(elementcount > (uint32_t)ringbuf_write_available(ringbuf)) {
|
||||
writecount = (uint32_t)ringbuf_write_available(ringbuf);
|
||||
}
|
||||
else {
|
||||
writecount = elementcount;
|
||||
}
|
||||
if((ringbuf->rear + writecount) > (ringbuf->elementcount))
|
||||
{
|
||||
os_memcpy(ringbuf->data + ringbuf->rear * ringbuf->elementsize, (uint8_t*)data,
|
||||
(ringbuf->elementcount - ringbuf->rear) * ringbuf->elementsize);
|
||||
os_memcpy(ringbuf->data, ((uint8_t*)data) + (ringbuf->elementcount - ringbuf->rear) * ringbuf->elementsize,
|
||||
(writecount - ringbuf->elementcount + ringbuf->rear) * ringbuf->elementsize);
|
||||
}
|
||||
else {
|
||||
os_memcpy(ringbuf->data + ringbuf->rear * ringbuf->elementsize, (uint8_t*)data, writecount * ringbuf->elementsize);
|
||||
}
|
||||
ringbuf->rear = (ringbuf->rear + writecount) % (ringbuf->elementcount);
|
||||
return writecount;
|
||||
}
|
||||
|
||||
int32_t ringbuf_move_readptr(RINGBUF *ringbuf, int32_t elementcount)
|
||||
{
|
||||
uint32_t read_avable = ringbuf_read_available(ringbuf);
|
||||
if(read_avable < elementcount) {
|
||||
ringbuf->front = (ringbuf->front + read_avable) % (ringbuf->elementcount);
|
||||
return read_avable;
|
||||
}
|
||||
else {
|
||||
ringbuf->front = (ringbuf->front + elementcount) % (ringbuf->elementcount);
|
||||
return elementcount;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ringbuf_read_nomove(RINGBUF *ringbuf, void *data, uint32_t elementcount)
|
||||
{
|
||||
uint32_t readcount = 0;
|
||||
if(ringbuf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if(ringbuf->front == ringbuf->rear) {
|
||||
return 0;
|
||||
}
|
||||
if(elementcount > (uint32_t)ringbuf_read_available(ringbuf)) {
|
||||
readcount = (uint32_t)ringbuf_read_available(ringbuf);
|
||||
}
|
||||
else {
|
||||
readcount = elementcount;
|
||||
}
|
||||
if((ringbuf->front + readcount) > (ringbuf->elementcount))
|
||||
{
|
||||
os_memcpy((uint8_t*)data, ringbuf->data + ringbuf->front * ringbuf->elementsize,
|
||||
(ringbuf->elementcount - ringbuf->front) * ringbuf->elementsize);
|
||||
os_memcpy(((uint8_t*)data) + (ringbuf->elementcount - ringbuf->front) * ringbuf->elementsize,
|
||||
ringbuf->data, (readcount - ringbuf->elementcount + ringbuf->front) * ringbuf->elementsize);
|
||||
}
|
||||
else {
|
||||
os_memcpy((uint8_t*)data, ringbuf->data + ringbuf->front * ringbuf->elementsize, readcount * ringbuf->elementsize);
|
||||
}
|
||||
return readcount;
|
||||
}
|
||||
|
||||
void ringbuf_clean(RINGBUF *ringbuf)
|
||||
{
|
||||
ringbuf->front = 0;
|
||||
ringbuf->rear = 0;
|
||||
}
|
||||
|
||||
void ringbuf_del(RINGBUF *ringbuf)
|
||||
{
|
||||
if(ringbuf == NULL) {
|
||||
return;
|
||||
}
|
||||
av_psram_free(ringbuf->data);
|
||||
av_psram_free(ringbuf);
|
||||
}
|
||||
358
sdk/lib/audio/uac/uac_host.c
Normal file
358
sdk/lib/audio/uac/uac_host.c
Normal file
@@ -0,0 +1,358 @@
|
||||
#include "lib/audio/uac/uac_host.h"
|
||||
|
||||
static uint8_t *empty_buf = NULL;
|
||||
uint32 usbmic_packet_len = 16;
|
||||
uint8 *usbmic_buf = NULL;
|
||||
uint8 *usbspk_buf = NULL;
|
||||
|
||||
#define UAC_FRAME_NUM 4
|
||||
#define UAC_FRAME_LEN 1024
|
||||
|
||||
volatile UAC_MANAGE usbmic_manage[UAC_FRAME_NUM];
|
||||
volatile UAC_MANAGE usbspk_manage[UAC_FRAME_NUM];
|
||||
|
||||
struct list_head usbmic_free_list;
|
||||
struct list_head usbmic_use_list;
|
||||
|
||||
struct list_head usbspk_free_list;
|
||||
struct list_head usbspk_use_list;
|
||||
|
||||
static uint8 check_usbmic_room = 0;
|
||||
static uint8 check_usbspk_room = 0;
|
||||
|
||||
uint8_t uac_run = 0;
|
||||
uint8_t uac_open = 0;
|
||||
uint8 *get_uac_frame_data(UAC_MANAGE *uac_manage)
|
||||
{
|
||||
return uac_manage->data_addr;
|
||||
}
|
||||
uint8 get_uac_frame_sta(UAC_MANAGE *uac_manage)
|
||||
{
|
||||
return uac_manage->sta;
|
||||
}
|
||||
void set_uac_frame_sta(UAC_MANAGE *uac_manage, uint8 sta)
|
||||
{
|
||||
uac_manage->sta = sta;
|
||||
}
|
||||
uint32 get_uac_frame_datalen(UAC_MANAGE *uac_manage)
|
||||
{
|
||||
return uac_manage->data_len;
|
||||
}
|
||||
void set_uac_frame_datalen(UAC_MANAGE *uac_manage, uint32 len)
|
||||
{
|
||||
uac_manage->data_len = len;
|
||||
}
|
||||
uint32 get_uac_frame_respace_len(UAC_MANAGE *uac_manage)
|
||||
{
|
||||
return uac_manage->respace_len;
|
||||
}
|
||||
|
||||
uint32 get_uac_frame_num(struct list_head *head)
|
||||
{
|
||||
int count = 0;
|
||||
struct list_head *first = (struct list_head *)head;
|
||||
while(head->next != first)
|
||||
{
|
||||
head = head->next;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
void usbmic_frame_init(void)
|
||||
{
|
||||
for(uint8 i=0; i<UAC_FRAME_NUM; i++)
|
||||
{
|
||||
usbmic_manage[i].data_addr = NULL;
|
||||
usbmic_manage[i].data_len = 0;
|
||||
usbmic_manage[i].respace_len = UAC_FRAME_LEN;
|
||||
usbmic_manage[i].offset = 0;
|
||||
usbmic_manage[i].sta = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void usbspk_frame_init(void)
|
||||
{
|
||||
for(uint8 i=0; i<UAC_FRAME_NUM; i++)
|
||||
{
|
||||
usbspk_manage[i].data_addr = NULL;
|
||||
usbspk_manage[i].data_len = 0;
|
||||
usbspk_manage[i].respace_len = UAC_FRAME_LEN;
|
||||
usbspk_manage[i].offset = 0;
|
||||
usbspk_manage[i].sta = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void usbmic_room_init(void)
|
||||
{
|
||||
usbmic_frame_init();
|
||||
|
||||
INIT_LIST_HEAD((struct list_head *)&usbmic_free_list);
|
||||
INIT_LIST_HEAD((struct list_head *)&usbmic_use_list);
|
||||
|
||||
if(check_usbmic_room == 0) {
|
||||
usbmic_buf = (uint8*)os_zalloc(UAC_FRAME_LEN*UAC_FRAME_NUM);
|
||||
if(usbmic_buf)
|
||||
check_usbmic_room = 1;
|
||||
}
|
||||
|
||||
if(!usbmic_buf)
|
||||
{
|
||||
os_printf("malloc usbmic room err\n");
|
||||
return;
|
||||
}
|
||||
for(uint8 i=0; i<UAC_FRAME_NUM; i++)
|
||||
{
|
||||
usbmic_manage[i].data_addr = usbmic_buf+i*UAC_FRAME_LEN;
|
||||
list_add_tail((struct list_head *)&usbmic_manage[i].list,(struct list_head *)&usbmic_free_list);
|
||||
}
|
||||
os_printf("usbmic_room_init\n");
|
||||
}
|
||||
|
||||
void usbmic_room_del(void)
|
||||
{
|
||||
if(usbmic_buf) {
|
||||
os_free(usbmic_buf);
|
||||
os_printf("usbmic_room_del\n");
|
||||
usbmic_buf = NULL;
|
||||
check_usbmic_room = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void usbspk_room_init(uint32_t empty_buf_len)
|
||||
{
|
||||
usbspk_frame_init();
|
||||
|
||||
INIT_LIST_HEAD((struct list_head *)&usbspk_free_list);
|
||||
INIT_LIST_HEAD((struct list_head *)&usbspk_use_list);
|
||||
|
||||
if(empty_buf_len == 0)
|
||||
{
|
||||
empty_buf_len = 96; //48K采样率
|
||||
}
|
||||
|
||||
empty_buf = (uint8_t*)os_zalloc(empty_buf_len);
|
||||
if(!empty_buf)
|
||||
{
|
||||
os_printf("malloc empty buf err\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(check_usbspk_room == 0) {
|
||||
usbspk_buf = (uint8*)os_zalloc(UAC_FRAME_LEN*UAC_FRAME_NUM);
|
||||
if(usbspk_buf)
|
||||
check_usbspk_room = 1;
|
||||
}
|
||||
|
||||
if(!usbspk_buf)
|
||||
{
|
||||
os_printf("malloc usbspk room err\n");
|
||||
return;
|
||||
}
|
||||
for(uint8 i=0; i<UAC_FRAME_NUM; i++)
|
||||
{
|
||||
usbspk_manage[i].data_addr = usbspk_buf+i*UAC_FRAME_LEN;
|
||||
list_add_tail((struct list_head *)&usbspk_manage[i].list,(struct list_head *)&usbspk_free_list);
|
||||
}
|
||||
os_printf("usbspk_room_init\n");
|
||||
}
|
||||
|
||||
void usbspk_room_del(void)
|
||||
{
|
||||
if(usbspk_buf) {
|
||||
os_free(usbspk_buf);
|
||||
os_printf("usbspk_room_del\n");
|
||||
usbspk_buf = NULL;
|
||||
check_usbspk_room = 0;
|
||||
}
|
||||
if(empty_buf) {
|
||||
os_free(empty_buf);
|
||||
os_printf("empty buf free\n");
|
||||
empty_buf = NULL;
|
||||
}
|
||||
}
|
||||
UAC_MANAGE *get_usbmic_new_frame(uint8 grab)
|
||||
{
|
||||
UAC_MANAGE *uac_manage = NULL;
|
||||
if(grab == 0)
|
||||
{
|
||||
if(list_empty((const struct list_head *)&usbmic_free_list)){
|
||||
// os_printf("Not usbmic free frame\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if(grab == 1)
|
||||
{
|
||||
if(list_empty((const struct list_head *)&usbmic_free_list)){
|
||||
list_move_tail((struct list_head *)usbmic_use_list.prev, (struct list_head *)&usbmic_free_list);
|
||||
}
|
||||
}
|
||||
uac_manage = list_entry((struct list_head *)usbmic_free_list.next, UAC_MANAGE, list);
|
||||
uac_manage->data_len = 0;
|
||||
uac_manage->respace_len = UAC_FRAME_LEN;
|
||||
uac_manage->offset = 0;
|
||||
set_uac_frame_sta(uac_manage, 1);
|
||||
return uac_manage;
|
||||
}
|
||||
UAC_MANAGE *get_usbmic_frame(void)
|
||||
{
|
||||
UAC_MANAGE *uac_manage = NULL;
|
||||
if(list_empty((const struct list_head *)&usbmic_use_list)){
|
||||
// os_printf("Not usbmic use frame\n");
|
||||
return 0;
|
||||
}
|
||||
uac_manage = list_entry((struct list_head *)usbmic_use_list.next, UAC_MANAGE, list);
|
||||
set_uac_frame_sta(uac_manage, 3);
|
||||
return uac_manage;
|
||||
}
|
||||
void put_usbmic_frame_to_use(UAC_MANAGE *uac_manage)
|
||||
{
|
||||
set_uac_frame_sta(uac_manage, 2);
|
||||
list_move_tail((struct list_head *)&uac_manage->list, (struct list_head *)&usbmic_use_list);
|
||||
}
|
||||
void del_usbmic_frame(UAC_MANAGE *uac_manage)
|
||||
{
|
||||
set_uac_frame_sta(uac_manage, 0);
|
||||
list_move_tail((struct list_head *)&uac_manage->list, (struct list_head *)&usbmic_free_list);
|
||||
}
|
||||
|
||||
UAC_MANAGE *get_usbspk_new_frame(uint8 grab)
|
||||
{
|
||||
UAC_MANAGE *uac_manage = NULL;
|
||||
if(grab == 0)
|
||||
{
|
||||
if(list_empty((const struct list_head *)&usbspk_free_list)){
|
||||
// os_printf("Not usbspk free frame\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if(grab == 1)
|
||||
{
|
||||
if(list_empty((const struct list_head *)&usbspk_free_list)){
|
||||
list_move_tail((struct list_head *)usbspk_use_list.prev, (struct list_head *)&usbspk_free_list);
|
||||
}
|
||||
}
|
||||
uac_manage = list_entry((struct list_head *)usbspk_free_list.next, UAC_MANAGE, list);
|
||||
uac_manage->data_len = 0;
|
||||
uac_manage->respace_len = UAC_FRAME_LEN;
|
||||
uac_manage->offset = 0;
|
||||
set_uac_frame_sta(uac_manage, 1);
|
||||
return uac_manage;
|
||||
}
|
||||
UAC_MANAGE *get_usbspk_frame(void)
|
||||
{
|
||||
UAC_MANAGE *uac_manage = NULL;
|
||||
if(list_empty((const struct list_head *)&usbspk_use_list)){
|
||||
// os_printf("Not usbspk use frame\n");
|
||||
return 0;
|
||||
}
|
||||
uac_manage = list_entry((struct list_head *)usbspk_use_list.next, UAC_MANAGE, list);
|
||||
set_uac_frame_sta(uac_manage, 3);
|
||||
return uac_manage;
|
||||
}
|
||||
void put_usbspk_frame_to_use(UAC_MANAGE *uac_manage)
|
||||
{
|
||||
set_uac_frame_sta(uac_manage, 2);
|
||||
list_move_tail((struct list_head *)&uac_manage->list, (struct list_head *)&usbspk_use_list);
|
||||
}
|
||||
void del_usbspk_frame(UAC_MANAGE *uac_manage)
|
||||
{
|
||||
set_uac_frame_sta(uac_manage, 0);
|
||||
list_move_tail((struct list_head *)&uac_manage->list, (struct list_head *)&usbspk_free_list);
|
||||
}
|
||||
|
||||
void force_reset_usbmic_frame()
|
||||
{
|
||||
uint8 frame_num = 0;
|
||||
if(check_usbmic_room) {
|
||||
for(frame_num=0; frame_num<UAC_FRAME_NUM; frame_num++)
|
||||
{
|
||||
del_usbmic_frame((UAC_MANAGE *)&usbmic_manage[frame_num]);
|
||||
}
|
||||
}
|
||||
}
|
||||
void force_reset_usbspk_frame()
|
||||
{
|
||||
uint8 frame_num = 0;
|
||||
if(check_usbspk_room) {
|
||||
for(frame_num=0; frame_num<UAC_FRAME_NUM; frame_num++)
|
||||
{
|
||||
del_usbspk_frame((UAC_MANAGE *)&usbspk_manage[frame_num]);
|
||||
}
|
||||
}
|
||||
}
|
||||
static UAC_MANAGE *mic_frame = NULL;
|
||||
static UAC_MANAGE *spk_frame = NULL;
|
||||
|
||||
int usbmic_deal(struct usb_device *p_dev, uint8_t* rx_buff)
|
||||
{
|
||||
if(!mic_frame){
|
||||
mic_frame = get_usbmic_new_frame(1);
|
||||
}
|
||||
if(!mic_frame) {
|
||||
return 0;
|
||||
}
|
||||
uint8 *addr = get_uac_frame_data(mic_frame);
|
||||
os_memcpy(addr+(mic_frame->offset), rx_buff, usbmic_packet_len);
|
||||
mic_frame->offset += usbmic_packet_len;
|
||||
mic_frame->respace_len -= usbmic_packet_len;
|
||||
mic_frame->data_len += usbmic_packet_len;
|
||||
if(mic_frame->respace_len < usbmic_packet_len)
|
||||
{
|
||||
put_usbmic_frame_to_use(mic_frame);
|
||||
mic_frame = NULL;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void usbspk_tx(struct usb_device *p_dev, uint8_t ep, uint32_t len, usbh_audio_spk_tx func)
|
||||
{
|
||||
uint32 packetlen = len;
|
||||
static uint32_t send_empty_cnt = 0;
|
||||
uint8 *audio_addr = NULL;
|
||||
|
||||
if(send_empty_cnt > 0) {
|
||||
func(p_dev, ep, (uint8_t *)empty_buf, packetlen);
|
||||
send_empty_cnt--;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!spk_frame) {
|
||||
spk_frame = get_usbspk_frame();
|
||||
}
|
||||
if(!spk_frame)
|
||||
{
|
||||
func(p_dev, ep, (uint8_t *)empty_buf, packetlen);
|
||||
send_empty_cnt = UAC_FRAME_LEN/packetlen - 1;
|
||||
}
|
||||
else {
|
||||
audio_addr = get_uac_frame_data(spk_frame);
|
||||
func(p_dev, ep, (uint8_t *)(audio_addr+(spk_frame->offset)), packetlen);
|
||||
spk_frame->offset += packetlen;
|
||||
if(spk_frame->offset >= get_uac_frame_datalen(spk_frame))
|
||||
{
|
||||
del_usbspk_frame(spk_frame);
|
||||
spk_frame = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void uac_stop(void)
|
||||
{
|
||||
if(uac_open) {
|
||||
uac_run = 0;
|
||||
os_sleep_ms(10);
|
||||
if(check_usbmic_room) {
|
||||
os_memset(usbmic_buf, 0, UAC_FRAME_LEN*UAC_FRAME_NUM);
|
||||
}
|
||||
if(check_usbspk_room) {
|
||||
os_memset(usbspk_buf, 0, UAC_FRAME_LEN*UAC_FRAME_NUM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
88
sdk/lib/audio/wsola/wsola_process.c
Normal file
88
sdk/lib/audio/wsola/wsola_process.c
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "lib/audio/wsola/wsola_process.h"
|
||||
|
||||
WSOLA_MALLOC wsola_malloc = NULL;
|
||||
WSOLA_ZALLOC wsola_zalloc = NULL;
|
||||
WSOLA_CALLOC wsola_calloc = NULL;
|
||||
WSOLA_REALLOC wsola_realloc = NULL;
|
||||
WSOLA_FREE wsola_free = NULL;
|
||||
|
||||
void reg_wsola_alloc(WSOLA_MALLOC m, WSOLA_ZALLOC z, WSOLA_CALLOC c, WSOLA_REALLOC r, WSOLA_FREE f)
|
||||
{
|
||||
wsola_malloc = m;
|
||||
wsola_zalloc = z;
|
||||
wsola_calloc = c;
|
||||
wsola_realloc = r;
|
||||
wsola_free = f;
|
||||
}
|
||||
|
||||
WsolaStream *wsolaStream_init(uint32_t samplerate, uint32_t channels, float speed, float pitch,
|
||||
uint32_t max_input_nsamples, uint32_t max_output_nsamples)
|
||||
{
|
||||
WsolaStream *stream = wsola_stream_init(samplerate, channels, max_input_nsamples, max_output_nsamples);
|
||||
if(stream==NULL) {
|
||||
return NULL;
|
||||
}
|
||||
wsola_stream_set_speed(stream, speed);
|
||||
wsola_stream_set_pitch(stream, pitch);
|
||||
return stream;
|
||||
}
|
||||
|
||||
int32_t wsolaStream_input_data(WsolaStream* stream, int16_t *data, uint32_t nsamples)
|
||||
{
|
||||
return wsola_stream_write_data(stream, data, nsamples);
|
||||
}
|
||||
|
||||
int32_t wsolaStream_output_data(WsolaStream* stream, int16_t *data, uint32_t max_nsamples)
|
||||
{
|
||||
return wsola_stream_read_data(stream, data, max_nsamples);
|
||||
}
|
||||
|
||||
int32_t wsolaStream_input_available(WsolaStream* stream)
|
||||
{
|
||||
return wsola_stream_write_available(stream);
|
||||
}
|
||||
|
||||
int32_t wsolaStream_output_available(WsolaStream* stream)
|
||||
{
|
||||
return wsola_stream_read_available(stream);
|
||||
}
|
||||
|
||||
void wsolaStream_set_pitch(WsolaStream* stream, float pitch)
|
||||
{
|
||||
wsola_stream_set_pitch(stream, pitch);
|
||||
}
|
||||
|
||||
void wsolaStream_set_speed(WsolaStream* stream, float speed)
|
||||
{
|
||||
wsola_stream_set_speed(stream, speed);
|
||||
}
|
||||
|
||||
float wsolaStream_get_pitch(WsolaStream* stream)
|
||||
{
|
||||
return wsola_stream_get_pitch(stream);
|
||||
}
|
||||
|
||||
float wsolaStream_get_speed(WsolaStream* stream)
|
||||
{
|
||||
return wsola_stream_get_speed(stream);
|
||||
}
|
||||
|
||||
uint32_t wsolaStream_get_sampleRate(WsolaStream *stream)
|
||||
{
|
||||
return wsola_stream_get_samplerate(stream);
|
||||
}
|
||||
|
||||
void wsolaStream_clean(WsolaStream* stream)
|
||||
{
|
||||
wsola_stream_clean(stream);
|
||||
}
|
||||
|
||||
int32_t wsolaStream_flush(WsolaStream* stream)
|
||||
{
|
||||
return wsola_stream_flush(stream);
|
||||
}
|
||||
|
||||
void wsolaStream_deinit(WsolaStream *stream)
|
||||
{
|
||||
wsola_stream_deinit(stream);
|
||||
}
|
||||
Reference in New Issue
Block a user