#include <stdio.h>
|
#include <stdlib.h>
|
#include <string.h>
|
#include <math.h>
|
#include <time.h>
|
#include <vector.h>
|
#include <alg.h>
|
|
#include "drv/global.h"
|
#include "f2f.h"
|
#include "execute.h"
|
#include "scene.h"
|
#include "drv/fft.h"
|
|
|
volatile int sp_flag =0;
|
volatile int inputcnt=0;
|
volatile int dma_count=0;
|
int dsp_status =0 ;
|
|
extern int scene_loading;
|
extern void* haec,*hans;
|
|
int usb_input_cnt =0 ;
|
int usb_dma_count =0;
|
int usb_sp_flag =0;
|
|
double proc_secs;/////////////////////////////////////////////////
|
static double clock_start,clock_stop;
|
|
|
#define LEVEL_DETECT_PERIOD (70*RATE_SAMPLES/1000/NUM_SAMPLES) //µçƽ¼ÆËã100msÒ»´Î
|
|
#define MAX(x,y) ((x)>(y)?(x):(y))
|
|
|
|
double cpu_get_process_ulitity(void)
|
{
|
return proc_secs;
|
}
|
volatile int test_count = 0;
|
void sport_usb_isr(int sig_int)
|
{
|
usb_input_cnt++;
|
usb_input_cnt &= 0x1;
|
|
if(scene_loading == 0){
|
usb_input_fflush(usb_input_cnt);
|
usb_output_fflush(usb_input_cnt);
|
}
|
usb_dma_count++;// = dma_count;
|
|
usb_sp_flag = 1;
|
|
|
}
|
|
void sport_isr(int sig_int)
|
{
|
float secs;
|
|
inputcnt++;
|
inputcnt &= 0x1;
|
|
if( scene_loading == 0){
|
|
clock_start = clock();
|
|
input_fflush(inputcnt);
|
scene_running();
|
output_fflush(inputcnt);
|
|
clock_stop = clock();
|
secs = ((double) (clock_stop - clock_start))/ CLOCKS_PER_SEC_NLP;
|
|
alg_aec_timer_handler(haec, secs);
|
alg_ans_timer_handler(hans, secs);
|
if(secs > proc_secs) {
|
proc_secs = secs;
|
}
|
}
|
else{
|
output_empty();
|
output_fflush(inputcnt);
|
}
|
|
dsp_status = dsp_running_ok;
|
dma_count++;
|
}
|
|
|
int BuiltIn_Expander(void *Expander, int channel_id)
|
{
|
float* in_ptr = get_rx_channel(channel_id);
|
float* out_ptr = get_tx_channel(channel_id);
|
|
alg_expander_process(Expander,in_ptr,out_ptr);
|
exchange_ptr(channel_id,channel_id);
|
|
return 0;
|
}
|
|
|
int input_execute(pinput_handle handle)
|
{
|
int i;
|
|
for(i=0;i<handle->output_num;i++){
|
float* in_ptr = get_rx_channel(handle->il_id[i]);
|
float* out_ptr = get_tx_channel(handle->ol_id[i]);
|
|
if(handle->input[i].type){
|
alg_sg_process(handle->input[i].hgen,in_ptr);
|
}
|
|
if(handle->input[i].mute){
|
if(handle->input[i].time>0){
|
fgain_step(in_ptr,out_ptr,&handle->input[i].old_gain,FADE_OUT_GAIN,handle->input[i].step_gain,NUM_SAMPLES);
|
handle->input[i].time --;
|
}
|
else{
|
memset(out_ptr, 0 ,NUM_SAMPLES);
|
}
|
}
|
else{
|
if(handle->input[i].gain <= -72.0){
|
memset(out_ptr, 0 ,NUM_SAMPLES);
|
}
|
else if(handle->input[i].time>0){
|
fgain_step(in_ptr,out_ptr,&handle->input[i].old_gain, handle->input[i].gain,handle->input[i].step_gain,NUM_SAMPLES);
|
handle->input[i].time --;
|
|
}
|
else{
|
// alg_expander_process(handle->input[i].hExpander,in_ptr,out_ptr);
|
fgain_proc(in_ptr,out_ptr,&handle->input[i].old_gain,&handle->input[i].gain,NUM_SAMPLES);
|
}
|
}
|
|
|
if(handle->input[i].delay>0){
|
memset(out_ptr,0,NUM_SAMPLES);
|
handle->input[i].delay-=NUM_SAMPLES;
|
}
|
else if(handle->input[i].phase){
|
vecsmltf(out_ptr, -1, out_ptr ,NUM_SAMPLES);
|
}
|
|
exchange_ptr(handle->ol_id[i],handle->ol_id[i]);
|
}
|
|
return 0;
|
}
|
|
|
int meter_execute(pmeter_handle handle)
|
{
|
int i;
|
|
|
for(i=0;i< handle->input_num;i++){
|
float* ptr = get_rx_channel(handle->il_id[i]);
|
float curMaxData = fpeak_data(ptr,NUM_SAMPLES);
|
|
|
handle->maxLevel[i] = MAX(handle->maxLevel[i], curMaxData );
|
|
|
if(handle->period[i] < RATE_SAMPLES*0.05){
|
handle->period[i] += NUM_SAMPLES;
|
continue;
|
}
|
|
handle->period[i] =0;
|
|
if(handle->maxLevel[i] == 0){
|
handle->level[i] = -12000;
|
}
|
else{
|
handle->level[i] = 2000 * log10f(handle->maxLevel[i]);
|
if(handle->level[i]<-32767){
|
handle->level[i] = -32767;
|
}
|
}
|
|
handle->maxLevel[i] = 0;
|
|
}
|
|
|
return 0;
|
}
|
|
int delay_execute(pdelay_handle handle)
|
{
|
|
float* in_ptr = get_rx_channel(handle->il_id[0]);
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
if(!handle->bypass){
|
|
alg_delay_process(handle->halg,in_ptr,out_ptr);
|
|
exchange_ptr(handle->ol_id[0],handle->ol_id[0]);
|
}
|
|
return 0;
|
}
|
|
int eq_execute(peq_handle handle)
|
{
|
|
float* in_ptr = get_rx_channel(handle->il_id[0]);
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
if(!handle->bypass){
|
alg_eq_filter(handle->halg,in_ptr,out_ptr);
|
|
exchange_ptr(handle->ol_id[0],handle->ol_id[0]);
|
}
|
|
return 0;
|
}
|
|
|
int expander_execute(pexpander_handle handle)
|
{
|
|
float* in_ptr = get_rx_channel(handle->il_id[0]);
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
if(!handle->bypass){
|
alg_expander_process(handle->halg,in_ptr,out_ptr);
|
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
handle->level[0]=alg_expander_get_reducedb(handle->halg)*100.0f;
|
handle->period=0;
|
}
|
|
exchange_ptr(handle->ol_id[0],handle->ol_id[0]);
|
}else{
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
handle->level[0]= 0;
|
handle->period=0;
|
}
|
}
|
|
return 0;
|
}
|
|
int compressor_execute(pcompressor_handle handle)
|
{
|
|
float* in_ptr = get_rx_channel(handle->il_id[0]);
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
if(!handle->bypass){
|
|
alg_compress_process(handle->halg,in_ptr,out_ptr);
|
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
//float pg = fpeak_data(out_ptr,NUM_SAMPLES);
|
//handle->level[0]=alg_compress_get_db(handle->halg)*100.0f;
|
//handle->level[1]=pg==0?-12000:2000*log10f(pg);
|
handle->level[0]=alg_compress_get_db(handle->halg)*100.0f;
|
handle->level[1]=alg_compress_get_output_db(handle->halg)*100.0f;
|
handle->period=0;
|
}
|
|
exchange_ptr(handle->ol_id[0],handle->ol_id[0]);
|
}
|
else{
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
handle->level[0]= 0;
|
handle->level[1]= -12000;
|
handle->period=0;
|
}
|
}
|
|
return 0;
|
}
|
|
#if 0
|
int mixer_execute(pmixer_handle handle)
|
{
|
static float xin[MAX_MIXER_INPUT][NUM_SAMPLES];
|
static float xout[MAX_MIXER_OUTPUT][NUM_SAMPLES];
|
|
int i,j;
|
|
for(i=0;i<handle->input_num;i++){
|
memcpy(xin[i],get_rx_channel(handle->il_id[i]),NUM_SAMPLES);
|
}
|
|
alg_mixer_process2((float*)&xin, (float*)&xout, handle->gain, handle->output_num,handle->input_num,NUM_SAMPLES);
|
//alg_mixer_process5((const float**)xin, (float**)xout, handle->gain, handle->weight ,handle->output_num,handle->input_num,NUM_SAMPLES);
|
|
for(i=0;i<handle->output_num;i++){
|
memcpy(get_rx_channel(handle->ol_id[i]),xout[i],NUM_SAMPLES);
|
}
|
|
return 0;
|
|
}
|
#else
|
int mixer_execute(pmixer_handle handle)
|
{
|
int i, j;
|
|
for(i =0 ;i < handle->output_num ;i ++) {
|
float *xout = get_tx_channel(handle->ol_id[i]);
|
|
memset(xout, 0 , NUM_SAMPLES);
|
|
for(j =0 ;j < handle->input_num;j++) {
|
if(handle->mask[i][j/16]&(1<<(j&15))) {
|
alg_mixer_process(xout, get_rx_channel(handle->il_id[j]) ,xout, handle->gain[i][j], NUM_SAMPLES );
|
}
|
}
|
}
|
|
for(i=0;i<handle->output_num;i++){
|
exchange_ptr(handle->ol_id[i],handle->ol_id[i]);
|
}
|
|
return 0;
|
|
}
|
#endif
|
|
int crossover_execute(pcrossover_handle handle)
|
{
|
float* in_ptr ;
|
float* out_ptr ;
|
|
|
if(!handle->lowbypass){
|
in_ptr = get_rx_channel(handle->il_id[0]);
|
out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
alg_filter_process(handle->hLowalg,in_ptr,out_ptr);
|
|
exchange_ptr(handle->ol_id[0],handle->ol_id[0]);
|
}
|
|
if(!handle->highbypass){
|
in_ptr = get_rx_channel(handle->il_id[0]);
|
out_ptr = get_tx_channel(handle->ol_id[0]);
|
alg_filter_process(handle->hHighalg,in_ptr,out_ptr);
|
exchange_ptr(handle->ol_id[0],handle->ol_id[0]);
|
}
|
|
|
return 0;
|
}
|
|
int gain_execute(pgain_handle handle)
|
{
|
float* in_ptr = get_rx_channel(handle->il_id[0]);
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
fgain_proc(in_ptr,out_ptr,&handle->old_gain,&handle->gain,NUM_SAMPLES);
|
|
exchange_ptr(handle->ol_id[0],handle->ol_id[0]);
|
|
return 0;
|
}
|
|
|
int output_execute(poutput_handle handle)
|
{
|
int i;
|
|
for(i=0;i<handle->output_num;i++){
|
float* in_ptr = get_rx_channel(handle->il_id[i]);
|
float* out_ptr = get_tx_channel(handle->ol_id[i]);
|
|
if(handle->output[i].mute){
|
if(handle->output[i].time>0){
|
fgain_step(in_ptr,out_ptr,&handle->output[i].old_gain,FADE_OUT_GAIN,handle->output[i].step_gain,NUM_SAMPLES);
|
handle->output[i].time --;
|
}
|
else{
|
memset(out_ptr, 0 ,NUM_SAMPLES);
|
}
|
//
|
}
|
else{
|
if(handle->output[i].gain <= -72.0){
|
memset(out_ptr, 0 ,NUM_SAMPLES);
|
}
|
else if(handle->output[i].time>0){
|
fgain_step(in_ptr,out_ptr,&handle->output[i].old_gain, handle->output[i].gain,handle->output[i].step_gain,NUM_SAMPLES);
|
handle->output[i].time --;
|
|
}
|
else{
|
fgain_proc(in_ptr,out_ptr,&handle->output[i].old_gain,&handle->output[i].gain,NUM_SAMPLES);
|
}
|
|
}
|
|
if(handle->output[i].phase){
|
vecsmltf(out_ptr, -1, out_ptr ,NUM_SAMPLES);
|
}
|
|
exchange_ptr(handle->il_id[i],handle->ol_id[i]);
|
}
|
|
return 0;
|
}
|
|
|
int feedback_execute(pfeedback_handle handle)
|
{
|
#if 1
|
int i,ret;
|
float* in_ptr = get_rx_channel(handle->il_id[0]);
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
ptag_feedback pfeedback = handle->param_ptr;
|
|
alg_nhs_set_bypass(handle->halg, handle->bypass);
|
|
if(!handle->bypass){
|
alg_nhs_process(handle->halg,in_ptr,out_ptr);
|
//alg_nhs_process(handle->halg,in_ptr,out_ptr,handle->bypass);/////////////////////////////////
|
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
for(i=0;i<FEEDBACK_FILTERS_NUM;i++){
|
handle->level[2*i] = alg_nhs_get_unit_frequency(handle->halg,i);
|
handle->level[2*i+1] = alg_nhs_get_unit_gain(handle->halg,i)*100;
|
pfeedback->flt_group[i].fc = handle->level[2*i];
|
pfeedback->flt_group[i].gain = handle->level[2*i+1];
|
}
|
handle->period=0;
|
}
|
|
exchange_ptr(handle->ol_id[0], handle->ol_id[0]);
|
// feedback_num++;
|
}
|
else{
|
alg_nhs_process(handle->halg,in_ptr,out_ptr);
|
//alg_nhs_process(handle->halg,in_ptr,out_ptr,handle->bypass);/////////////////////////////////////////////
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
for(i=0;i<FEEDBACK_FILTERS_NUM;i++){
|
//handle->level[2*i] =20;
|
//handle->level[2*i+1]= 0;
|
handle->level[2*i] = alg_nhs_get_unit_frequency(handle->halg,i);
|
handle->level[2*i+1] = alg_nhs_get_unit_gain(handle->halg,i)*100;
|
}
|
handle->period=0;
|
}
|
}
|
#endif
|
return 0;
|
}
|
|
#if 1
|
int automixer_execute(pautomixer_handle handle)
|
{
|
int i;
|
float* pin[AUTOMIXER_CHANNEL_NUM];
|
float* pout[AUTOMIXER_CHANNEL_NUM+1];
|
|
if(handle->bypass){
|
memset(get_rx_channel(handle->input_num) ,0 , NUM_SAMPLES);
|
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
for(i=0;i<handle->input_num;i++){
|
handle->level[2*i] = -12000;
|
handle->level[2*i+1]=-12000;
|
}
|
handle->period=0;
|
}
|
}
|
else{
|
for(i=0;i<handle->input_num;i++){
|
pin[i] = get_rx_channel(handle->il_id[i]);
|
pout[i] = get_tx_channel(handle->ol_id[i]);
|
}
|
pout[i] = get_tx_channel(handle->ol_id[i]);
|
|
alg_automixer_process(handle->halg,pin,pout);
|
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
for(i=0;i<handle->input_num;i++){
|
handle->level[2*i] = alg_automixer_get_level(handle->halg,i)*100;
|
handle->level[2*i+1]=alg_automixer_get_autogain(handle->halg,i)*100;
|
}
|
handle->period=0;
|
}
|
for(i=0;i<handle->output_num;i++){
|
exchange_ptr(handle->ol_id[i], handle->ol_id[i]);
|
}
|
}
|
|
|
return 0;
|
}
|
#else
|
int automixer_execute(pautomixer_handle handle)
|
{
|
int i;
|
float* pin[AUTOMIXER_CHANNEL_NUM];
|
float* pout[AUTOMIXER_CHANNEL_NUM+1];
|
|
if(handle->bypass){
|
memset(get_rx_channel(handle->input_num) ,0 , NUM_SAMPLES);
|
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
for(i=0;i<handle->input_num;i++){
|
handle->level[2*i] = -12000;
|
handle->level[2*i+1]=-12000;
|
}
|
handle->period=0;
|
}
|
}
|
else{
|
for(i=0;i<handle->input_num;i++){
|
pin[i] = get_rx_channel(handle->il_id[i]);
|
pout[i] = get_tx_channel(handle->ol_id[i]);
|
}
|
pout[i] = get_tx_channel(handle->ol_id[i]);
|
|
alg_pri_automixer_process(handle->halg,pin,pout);
|
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
for(i=0;i<handle->input_num;i++){
|
handle->level[2*i] = alg_pri_automixer_get_level(handle->halg,i)*100;
|
handle->level[2*i+1]=alg_pri_automixer_get_autogain(handle->halg,i)*100;
|
}
|
handle->period=0;
|
}
|
for(i=0;i<handle->output_num;i++){
|
exchange_ptr(handle->ol_id[i], handle->ol_id[i]);
|
}
|
}
|
|
|
return 0;
|
}
|
#endif
|
|
int fir_execute(pcommon_handle handle)
|
{
|
|
float* in_ptr = get_rx_channel(handle->il_id[0]);
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
if(!handle->bypass){
|
//alg_fir_process(handle->halg,in_ptr,out_ptr);
|
exchange_ptr(handle->ol_id[0],handle->ol_id[0]);
|
}
|
|
return 0;
|
}
|
|
|
int agc_execute(pagc_handle handle)
|
{
|
float* in_ptr = get_rx_channel(handle->il_id[0]);
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
if(!handle->bypass){
|
|
alg_agc_process(handle->halg,in_ptr,out_ptr);
|
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
handle->level[0] = alg_agc_input_level(handle->halg)*100;
|
handle->level[1] = alg_agc_output_level(handle->halg)*100;
|
|
handle->period=0;
|
}
|
exchange_ptr(handle->ol_id[0], handle->ol_id[0]);
|
}
|
else{
|
handle->period++;
|
if (handle->period >= LEVEL_DETECT_PERIOD){
|
handle->level[0] = -12000;
|
handle->level[1]= -12000;
|
|
handle->period=0;
|
}
|
}
|
|
return 0;
|
}
|
|
int aec_execute(paec_handle handle)
|
{
|
#if 1
|
if(handle == NULL) {
|
return -1;
|
}
|
|
if(!handle->bypass){
|
float* ne_ptr = get_rx_channel(handle->il_id[0]);
|
float* far_ptr = get_rx_channel(handle->il_id[1]);
|
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
alg_aec_process(handle->halg,ne_ptr ,far_ptr, out_ptr);
|
|
exchange_ptr(handle->il_id[0],handle->ol_id[0]);
|
}
|
#endif
|
return 0;
|
}
|
|
int ans_execute(pans_handle handle)
|
{
|
if(handle == NULL) {
|
return -1;
|
}
|
|
if(!handle->bypass){
|
float* in_ptr = get_rx_channel(handle->il_id[0]);
|
float* out_ptr = get_tx_channel(handle->ol_id[0]);
|
|
alg_ans_process(handle->halg,in_ptr , out_ptr);
|
|
exchange_ptr(handle->il_id[0],handle->ol_id[0]);
|
}
|
|
return 0;
|
}
|
|
int sysctl_execute(psysctl_handle handle)
|
{
|
int i;
|
|
for(i=0;i<handle->input_num;i++){
|
float* in_ptr = get_rx_channel(handle->il_id[i]);
|
float* out_ptr = get_tx_channel(handle->ol_id[i]);
|
|
|
if(handle->mute){
|
if(handle->time>0){
|
fgain_step(in_ptr,out_ptr,&handle->old_gain[i],FADE_OUT_GAIN,handle->step_gain[i],NUM_SAMPLES);
|
handle->time --;
|
}
|
else{
|
memset(out_ptr, 0 ,NUM_SAMPLES);
|
}
|
}
|
else{
|
if(handle->time>0){
|
fgain_step(in_ptr,out_ptr,&handle->old_gain[i],handle->gain,handle->step_gain[i],NUM_SAMPLES);
|
handle->time --;
|
}
|
else{
|
fgain_proc(in_ptr,out_ptr,&handle->old_gain[i],&handle->gain,NUM_SAMPLES);
|
}
|
}
|
|
exchange_ptr(handle->il_id[i],handle->ol_id[i]);
|
}
|
return 0;
|
}
|
|
int selector_execute(pselector_handle handle)
|
{
|
int i,j;
|
|
for(i=0;i<handle->output_num;i++){
|
float* out_ptr = get_tx_channel(handle->ol_id[i]);
|
memset(out_ptr,0,NUM_SAMPLES);
|
|
for(j=0;j<handle->input_num;j++){
|
if((handle->mask[i][j/16]>>(j&15))&0x1){
|
float* in_ptr = get_rx_channel(handle->il_id[j]);
|
|
alg_mixer_process(out_ptr,in_ptr,out_ptr,0 ,NUM_SAMPLES);
|
}
|
}
|
}
|
|
for(j=0;j<handle->output_num;j++){
|
exchange_ptr(handle->ol_id[j],handle->ol_id[j]);
|
}
|
|
return 0;
|
}
|
|
|