#include #include #include #include #include #include #include #include #include "drv/global.h" #include "f2f.h" #include "execute.h" #include "scene.h" #include //#include "drv/fft.h" volatile int sp_flag =0; volatile int inputcnt=0, inputcnt3=0; volatile int dma_count[2]; 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)) 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++; usb_sp_flag = 1; } #if 0 void sport_isr(int sig_int) { float secs; // inputcnt++; // inputcnt &= 0x1; int dmaid = (sig_int == SIG_SP1) ? 0 : 1; if(scene_loading == 1){ output_empty(); output_fflush(sig_int, dma_count[dmaid]&0x1); } else if(sig_int == SIG_SP1){ clock_start = clock(); input_fflush(sig_int, dma_count[dmaid]&0x1); scene_running(); output_fflush(sig_int, dma_count[dmaid]&0x1); 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{ input_fflush(sig_int, dma_count[dmaid]&0x1); output_fflush(sig_int, dma_count[dmaid]&0x1); } dsp_status = dsp_running_ok; dma_count[dmaid]++; } #else int fflush_lock = 0; void sport_isr(int sig_int) { float secs; sysreg_bit_clr(sysreg_MODE1, IRPTEN); inputcnt++; inputcnt &= 0x1; if( scene_loading == 0){ clock_start = clock(); input_fflush(SIG_SP1, inputcnt); scene_running(); output_fflush(SIG_SP1, 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(SIG_SP1, inputcnt); } dsp_status = dsp_running_ok; dma_count[0]++; sysreg_bit_set(sysreg_MODE1, IRPTEN); } void sport3_isr(int sig_int) { float secs; sysreg_bit_clr(sysreg_MODE1, IRPTEN); //fflush_lock = 1; inputcnt3++; inputcnt3 &= 0x1; if(scene_loading == 0){ //input_fflush(SIG_SP3, inputcnt3); //output_fflush(SIG_SP3, inputcnt3); dante_input_fflush(inputcnt3); dante_output_fflush(inputcnt3); } else{ //output_empty(); dante_output_empty(); //output_fflush(SIG_SP3, inputcnt3); dante_output_fflush(inputcnt3); } //sp_dante_flag =1; dma_count[1]++; //fflush_lock = 0; sysreg_bit_set(sysreg_MODE1, IRPTEN); } #endif static void audio_mix_process(short* mask , float* output) { int i; memset(output ,0 , NUM_SAMPLES); for(i =0 ;i>(i&15))&0x1){ alg_mixer_process(output , get_rx_channel(i), output ,0, NUM_SAMPLES); } } } int empty_execute(void* handle) { return 0; } int input_execute(pinput_handle handle) { int i; int vad= 0; for(i=0;ioutput_num;i++){ float* in_ptr = get_rx_channel(handle->il_id[i]); float* out_ptr = get_tx_channel(handle->ol_id[i]); //vad = 1; 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){ 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; } 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;iinput_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_process6((const float*)xin, (float*)xout, handle->gain // , handle->delay_ptr,(int*)handle->delay, handle->weight // ,handle->output_num,handle->input_num,NUM_SAMPLES); for(i=0;ioutput_num;i++){ memcpy(get_rx_channel(handle->ol_id[i]),xout[i],NUM_SAMPLES); } */ 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;ioutput_num;i++){ exchange_ptr(handle->ol_id[i],handle->ol_id[i]); } return 0; } 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;ioutput_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) { 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;insection;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]); } else{ alg_nhs_process(handle->halg,in_ptr,out_ptr); handle->period++; if (handle->period >= LEVEL_DETECT_PERIOD){ for(i=0;insection;i++){ handle->level[2*i] =20; handle->level[2*i+1]= 0; } handle->period=0; } } return 0; } int gainsharing_automixer_execute(pgainsharing_mixer_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;iinput_num;i++){ handle->level[2*i] = -12000; handle->level[2*i+1]=-12000; } handle->period=0; } } else{ for(i=0;iinput_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;iinput_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;ioutput_num;i++){ exchange_ptr(handle->ol_id[i], handle->ol_id[i]); } } return 0; } 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(!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]); } return 0; } int ans_execute(pans_handle handle) { 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 afc_execute(pafc_handle handle) { if(!handle->bypass){ float* in_ptr = get_rx_channel(handle->il_id[0]); float* out_ptr = get_tx_channel(handle->ol_id[0]); //alg_afc_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; extern void msg_netvoice_upload(int netchannel ); for(i=0;iinput_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]); } // handle->sample_count += NUM_SAMPLES; // if(handle->sample_count >= (RATE_SAMPLES/10)){ // msg_netvoice_upload(1); // msg_netvoice_upload(3); // handle->sample_count =0; // } return 0; } int selector_execute(pselector_handle handle) { int i,j; for(i=0;ioutput_num;i++){ float* out_ptr = get_tx_channel(handle->ol_id[i]); memset(out_ptr,0,NUM_SAMPLES); for(j=0;jinput_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;joutput_num;j++){ exchange_ptr(handle->ol_id[j],handle->ol_id[j]); } return 0; } int gating_automixer_execute(pgating_mixer_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;iinput_num;i++){ handle->level[2*i] = -12000; handle->level[2*i+1]=-12000; } handle->period=0; } } else{ for(i=0;iinput_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_gating_automixer_process(handle->halg,pin,pout); handle->period++; if (handle->period >= LEVEL_DETECT_PERIOD){ for(i=0; iinput_num; i++){ handle->level[2*i] = alg_gating_automixer_get_level(handle->halg,i)*100; handle->level[2*i+1]= alg_gating_automixer_get_autogain(handle->halg,i)*100; } handle->period = 0; } for(i=0;ioutput_num;i++){ exchange_ptr(handle->ol_id[i], handle->ol_id[i]); } } return 0; } int spl_execute(pspl_handle handle) { float side_in[NUM_SAMPLES]; float* in_ptr = get_rx_channel(handle->il_id[0]); float* out_ptr = get_tx_channel(handle->ol_id[0]); if(!handle->bypass){ audio_mix_process(handle->mask ,side_in); alg_spl_continuous_process(handle->halg,in_ptr, side_in ,out_ptr); handle->period++; if (handle->period >= LEVEL_DETECT_PERIOD){ handle->level[0]= alg_spl_get_sense_level(handle->halg)*100.0f; handle->level[1]= alg_spl_get_correlation_coffes(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]= -12000; handle->level[1]= 0; //handle->level[2]= 0; handle->period=0; } } return 0; } int gate_execute(pgate_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_gate_process(handle->halg,in_ptr,out_ptr); handle->period++; if (handle->period >= LEVEL_DETECT_PERIOD){ handle->level[0]= alg_gate_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 ducker_execute(pducker_handle handle) { float side_in[NUM_SAMPLES]; float* in_ptr = get_rx_channel(handle->il_id[0]); float* out_ptr = get_tx_channel(handle->ol_id[0]); if(!handle->bypass){ audio_mix_process(handle->mask ,side_in); alg_ducker_process(handle->halg,in_ptr, side_in ,out_ptr); handle->period++; if (handle->period >= LEVEL_DETECT_PERIOD){ handle->level[0]= alg_ducker_get_atten(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 reverb_execute(preverb_handle handle) { return 0; } int echo_execute(pecho_handle handle) { return 0; } int geq_execute(pgeq_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; }