/* * scene.c * Description: * * Created on: 2014-10-28 * Author: Graydon * Modify: */ #include #include #include #include #include #include "drv/global.h" #include "drv/hmem.h" #include "scene.h" #include "drv/fft.h" static short level_buf[1536]; static int nlevels=0; #define LEVEL_MALLOC(n) level_buf+nlevels;nlevels+=n void* hafc=0; void* haec=0; void* hans=0; int GetLevelPtr(short** ptr) { *ptr = level_buf; return nlevels; } void LevelEmpty() { int i; int n = sizeof(level_buf)/sizeof(short); //Meter* m = (Meter*)level_buf; hafc =0; hans =0; haec =0; nlevels = 0; for(i=0;iinput_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); for(i=0;iinput_num;i++){ if(pInput->input[i].gain>1200 || pInput->input[i].gain<-7200){ pInput->input[i].gain = 0; } handle->input[i].gain= pInput->input[i].gain/100.0f; handle->input[i].old_gain = -48 ; handle->input[i].time = FADE_OUT_TIME; handle->input[i].step_gain = (handle->input[i].gain - handle->input[i].old_gain)/FADE_OUT_TIME; handle->input[i].mute = pInput->input[i].mute&0x1; handle->input[i].type = pInput->input[i].type&0x7; handle->input[i].phase = pInput->input[i].phase&0x1; if(pInput->input[i].phant){ handle->input[i].delay = RATE_SAMPLES*5; } handle->input[i].hgen = alg_sg_create(RATE_SAMPLES,NUM_SAMPLES); alg_sg_set_param(handle->input[i].hgen,pInput->input[i].freq,handle->input[i].type,pInput->input[i].level/100.0f); } handle->param_ptr = pInput; return handle; END_DECLINE(0) } void* output_create(ptag_output pOutput, char* inport_str, char* outport_str) { BEIGN_DECLINE(inport_str) int i, pitch_alloc =0; poutput_handle handle = mymalloc(SRAM_AUTO ,sizeof(output_handle)); ASSERT(handle!=0); normalize((short*)pOutput,sizeof(tag_output)); memset(handle,0,sizeof(output_handle)); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); for (i=0;ioutput_num;i++){ if(pOutput->output[i].gain>1200 || pOutput->output[i].gain<-7200){ pOutput->output[i].gain = 0; } handle->output[i].mute = pOutput->output[i].mute; handle->output[i].gain = pOutput->output[i].gain/100.0f; handle->output[i].old_gain = -48 ; handle->output[i].time = FADE_OUT_TIME; handle->output[i].step_gain = (handle->output[i].gain - handle->output[i].old_gain)/FADE_OUT_TIME; handle->output[i].phase = pOutput->output[i].phase&0x1; } handle->param_ptr = pOutput; return handle; END_DECLINE(0) } void* delay_create( ptag_delay pDelay, char* inport_str, char* outport_str) { BEIGN_DECLINE(inport_str) pdelay_handle handle = mymalloc(SRAM_AUTO ,sizeof(delay_handle)); ASSERT(handle!=0); normalize((short*)pDelay,sizeof(tag_delay)); pDelay->bypass&=0x1; if(pDelay->ms> MAX_DELAY_MSEC){ pDelay->ms=1; } handle->bypass = pDelay->bypass&0x1; handle->halg = alg_delay_create(MAX_DELAY_MSEC , RATE_SAMPLES,NUM_SAMPLES); alg_delay_set_msec(handle->halg,pDelay->ms*1.0f); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pDelay; return handle; END_DECLINE(0) } void* shelf_create(ptag_shelf pshelf,char* inport_str, char* outport_str) { BEIGN_DECLINE(inport_str) pshelf_handle handle = mymalloc(SRAM_AUTO ,sizeof(eq_handle)); ASSERT(handle!=NULL); normalize((short*)pshelf,sizeof(tag_shelf)); if(pshelf->lowshelf.freq>20000 || pshelf->lowshelf.freq<20){ pshelf->lowshelf.freq = 20; } if(pshelf->lowshelf.gain>1500 || pshelf->lowshelf.gain<-4500){ pshelf->lowshelf.gain = 0; } if(pshelf->lowshelf.q>5000 || pshelf->lowshelf.q<2){ pshelf->lowshelf.q = 71; } if(pshelf->highshelf.freq>20000 || pshelf->highshelf.freq<20){ pshelf->highshelf.freq = 20; } if(pshelf->highshelf.gain>1500 || pshelf->highshelf.gain<-4500){ pshelf->highshelf.gain = 0; } if(pshelf->highshelf.q>5000 || pshelf->highshelf.q<2){ pshelf->highshelf.q = 71; } pshelf->lowshelf.bypass &= 0x1; pshelf->highshelf.bypass &= 0x1; if(pshelf->lowshelf.bypass && pshelf->highshelf.bypass){ handle->bypass =1 ; } else{ handle->bypass =0 ; } handle->halg = alg_eq_create(RATE_SAMPLES,NUM_SAMPLES,2); alg_eq_set_param(handle->halg,0,eq_highshelf, pshelf->highshelf.bypass,pshelf->highshelf.freq,pshelf->highshelf.gain/100.0f ,pshelf->highshelf.q/100.0f); alg_eq_set_param(handle->halg,1,eq_lowshelf, pshelf->lowshelf.bypass,pshelf->lowshelf.freq,pshelf->lowshelf.gain/100.0f ,pshelf->lowshelf.q/100.0f); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pshelf; return handle; END_DECLINE(0) } void* eq_create(ptag_eq pEQ, char* inport_str, char* outport_str) { BEIGN_DECLINE(inport_str) int i; peq_handle handle = mymalloc(SRAM_AUTO ,sizeof(eq_handle)); ASSERT(handle!=NULL); normalize((short*)pEQ,sizeof(tag_eq)); if(pEQ->nsection>MAX_EQ_SECTION){ pEQ->nsection = MAX_EQ_SECTION; } for(i=0;insection;i++){ pEQ->eq_attr[i].bypass&=0x1; if(pEQ->eq_attr[i].freq>20000 || pEQ->eq_attr[i].freq<20){ pEQ->eq_attr[i].freq = 200; } if(pEQ->eq_attr[i].gain<-4800 || pEQ->eq_attr[i].gain>2400){ pEQ->eq_attr[i].gain = 0; } if(pEQ->eq_attr[i].q<=0 || pEQ->eq_attr[i].q>5000){ pEQ->eq_attr[i].q = 100; } if(pEQ->eq_attr[i].type> (int)eq_highshelf ){ pEQ->eq_attr[i].type = (int)eq_peaking_eq; } } handle->bypass = pEQ->bypass&0x1; handle->halg = alg_eq_create(RATE_SAMPLES,NUM_SAMPLES,pEQ->nsection); for(i=0;insection;i++){ alg_eq_set_param(handle->halg,i,(eq_type_t)pEQ->eq_attr[i].type, pEQ->eq_attr[i].bypass,pEQ->eq_attr[i].freq,pEQ->eq_attr[i].gain/100.0f ,pEQ->eq_attr[i].q/100.0f); } handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pEQ; return handle; END_DECLINE(0) } void* expander_create(ptag_expander pExpander, char* inport_str, char* outport_str) { BEIGN_DECLINE(inport_str) pexpander_handle handle = mymalloc(SRAM_AUTO ,sizeof(expander_handle)); ASSERT(handle!=0); normalize((short*)pExpander,sizeof(tag_expander)); if(pExpander->threshold>0 || pExpander->threshold<-7200){ pExpander->threshold = -4800; } if(pExpander->ratio>10000|| pExpander->ratio<100){ pExpander->ratio = 100; } if(pExpander->attack>10000){ pExpander->attack = 1; } if(pExpander->release>10000){ pExpander->release = 1; } handle->bypass = pExpander->bypass; handle->halg = alg_expander_create(RATE_SAMPLES,NUM_SAMPLES); alg_expander_set_param(handle->halg, pExpander->threshold/100.0f, pExpander->ratio/100.0f, pExpander->attack,pExpander->release); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pExpander; handle->level = LEVEL_MALLOC(1); return handle; END_DECLINE(1) } void* compressor_create(ptag_compress pcompress, char* inport_str, char* outport_str) { BEIGN_DECLINE(inport_str) pcompressor_handle handle = mymalloc(SRAM_AUTO ,sizeof(compressor_handle)); ASSERT(handle!=0); normalize((short*)pcompress,sizeof(tag_compress)); if(pcompress->threshold>0 || pcompress->threshold<-4800){ pcompress->threshold = -4800; } if(pcompress->ratio>10000 || pcompress->ratio<100){ pcompress->ratio = 100; } if(pcompress->attack>10000){ pcompress->attack = 1; } if(pcompress->release>10000){ pcompress->release = 1; } if(pcompress->gain>1200 || pcompress->gain<-7200){ pcompress->gain = 0; } handle->bypass = pcompress->bypass; handle->halg = alg_compress_create(RATE_SAMPLES,NUM_SAMPLES,compresser_peak); alg_compress_set_param(handle->halg, pcompress->threshold/100.0f, pcompress->ratio/100.0f,pcompress->attack,pcompress->release,pcompress->gain/100.0f,0 ); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pcompress; handle->level = LEVEL_MALLOC(2); return handle; END_DECLINE(2) } void* mixer_create(ptag_mixer pMixer, char* inport_str, char* outport_str) { BEIGN_DECLINE(inport_str) int i,j; pmixer_handle handle = mymalloc(SRAM_AUTO ,sizeof(mixer_handle)); ASSERT(handle!=0); normalize((short*)pMixer,sizeof(tag_mixer)); memset(handle,0,sizeof(mixer_handle)); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); // handle->gain= mymalloc(SRAM_AUTO ,handle->output_num*handle->input_num); // handle->step = mymalloc(SRAM_AUTO ,handle->output_num*handle->input_num); // handle->delay_ptr = mymalloc(SRAM_AUTO ,handle->output_num*handle->input_num); // handle->delay = mymalloc(SRAM_AUTO ,handle->output_num*handle->input_num); for (i=0;ioutput_num ;i ++){ for(j=0;jinput_num;j++){ handle->gain[i][j] = pMixer->input_gain[i][j]*0.01f; //handle->delay_ptr[i*handle->input_num+j] = alg_delay_create(100 , RATE_SAMPLES,NUM_SAMPLES); //if(pMixer->delay[i][j]>100 ){ // pMixer->delay[i][j] =0; //} //handle->delay[i*handle->input_num+j] = pMixer->delay[i][j]; //alg_delay_set_msec(handle->delay_ptr[i*handle->input_num+j] , handle->delay[i*handle->input_num+j]); } // handle->weight[i] = 1.0f; } memcpy(handle->mask,pMixer->input_mask,sizeof(pMixer->input_mask)); handle->param_ptr = pMixer; return handle; END_DECLINE(0) } void* crossover_create(ptag_crossover pCross, char* inport_str, char* outport_str) { BEIGN_DECLINE(inport_str) pcrossover_handle handle = mymalloc(SRAM_AUTO ,sizeof(crossover_handle)); ASSERT(handle!=0); normalize((short*)pCross,sizeof(tag_crossover)); if(pCross->highpass.freq>20000 || pCross->highpass.freq<20){ pCross->highpass.freq = 20; } if(pCross->highpass.taps>48 || pCross->highpass.taps<6){ pCross->highpass.taps = 6; } if(pCross->lowpass.freq>20000 || pCross->lowpass.freq<20){ pCross->highpass.freq = 20; } if(pCross->lowpass.taps>48 || pCross->lowpass.taps<6){ pCross->highpass.taps = 6; } if(pCross->lowpass.gain>1500 || pCross->lowpass.gain<-1500){ pCross->lowpass.gain = 0; } if(pCross->highpass.gain>1500 || pCross->highpass.gain<-1500){ pCross->highpass.gain = 0; } handle->lowbypass = pCross->lowpass.bypass&0x1; handle->highbypass = pCross->highpass.bypass&0x1; handle->hLowalg = alg_filter_create(RATE_SAMPLES,NUM_SAMPLES,bqLowPass); handle->hHighalg = alg_filter_create(RATE_SAMPLES,NUM_SAMPLES,bqHighPass); alg_filter_set_param(handle->hLowalg,pCross->lowpass.freq,pCross->lowpass.taps,(eFilterType)pCross->lowpass.type, pCross->lowpass.gain/100.0f); alg_filter_set_param(handle->hHighalg,pCross->highpass.freq,pCross->highpass.taps,(eFilterType)pCross->highpass.type,pCross->highpass.gain/100.0f); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pCross; return handle; END_DECLINE(0) } void* meter_create(ptag_Meter pMeter, char* inport_str, char* outport_str) { pmeter_handle handle = mymalloc(SRAM_AUTO ,sizeof(meter_handle)); ASSERT(handle!=0); //normalize((short*)pMeter,sizeof(tag_Meter)); handle->input_num= str_delim(inport_str,handle->il_id); handle->meter_num = handle->input_num; handle->param_ptr = pMeter; handle->level = LEVEL_MALLOC(handle->meter_num); memset(handle->maxLevel,0 , handle->meter_num); memset(handle->period,0 , handle->meter_num); //memset(handle->old_level,0,handle->meter_num); return handle; } void* gain_create(ptag_gain pgain,char* inport_str, char* outport_str) { BEIGN_DECLINE(inport_str) pgain_handle handle = mymalloc(SRAM_AUTO ,sizeof(gain_handle)); ASSERT(handle!=0); normalize((short*)pgain,sizeof(tag_gain)); if(pgain->gain>1200 || pgain->gain<-7200){ pgain->gain = 0; } handle->gain = pgain->gain/100.0f; handle->old_gain=-100.0f; handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pgain; return handle; END_DECLINE(0) } void* feedback_create(ptag_feedback pfeedback, char* inport_str,char* outport_str) { BEIGN_DECLINE(inport_str) int i; pfeedback_handle handle = mymalloc(SRAM_AUTO ,sizeof(feedback_handle)); ASSERT(handle!=0); normalize((short*)pfeedback,sizeof(tag_feedback)); handle->bypass = pfeedback->bypass&0x1; handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pfeedback; if(pfeedback->panic_threshold<-3600 || pfeedback->panic_threshold>0){ pfeedback->panic_threshold = -1800; } if(pfeedback->flt_depth<100 || pfeedback->flt_depth>2400){ pfeedback->flt_depth = 1800; } if(pfeedback->step<50 || pfeedback->step>300){ pfeedback->step = 250; } if(pfeedback->fbc_num<8 || pfeedback->fbc_num>16){ pfeedback->fbc_num = 8; } handle->bypass = pfeedback->bypass; handle->halg = alg_nhs_create(RATE_SAMPLES,NUM_SAMPLES, pfeedback->fbc_num, pfeedback->fb_threshold*0.01, pfeedback->panic_threshold*0.01); alg_nhs_set_parameters(handle->halg, pfeedback->step*0.01 ,pfeedback->flt_depth*0.01, pfeedback->bw*0.01); for(i=0;ifbc_num;i++){ if(pfeedback->flt_group[i].fc<20 || pfeedback->flt_group[i].fc>20000){ pfeedback->flt_group[i].fc =20; } if( pfeedback->flt_group[i].type>2){ pfeedback->flt_group[i].type = 0; } if(pfeedback->flt_group[i].gain<-2400 || pfeedback->flt_group[i].gain>0){ pfeedback->flt_group[i].gain = 0; } alg_nhs_filters_set_unit(handle->halg , i ,pfeedback->flt_group[i].type , pfeedback->flt_group[i].fc,pfeedback->flt_group[i].gain/100.0); } handle->level = LEVEL_MALLOC(pfeedback->fbc_num*2); handle->nsection = pfeedback->fbc_num; return handle; END_DECLINE(pfeedback->fbc_num*2) } void* gainsharing_automixer_create(ptag_gainsharing_mixer pautomixer, char* inport_str,char* outport_str) { int i; pgainsharing_mixer_handle handle = mymalloc(SRAM_AUTO ,sizeof(gainsharing_mixer_handle)); ASSERT(handle!=0); normalize((short*)pautomixer,sizeof(tag_automixer)); handle->bypass = pautomixer->bypass ; handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pautomixer; //²ÎÊý¼ì²é if(pautomixer->master_gain<-7200 || pautomixer->master_gain>1200){ pautomixer->master_gain =0; } if(pautomixer->response<5 || pautomixer->response>5000){ pautomixer->response =100; } if(pautomixer->slope<100 || pautomixer->slope>600){ pautomixer->slope =200; } for(i=0;iinput_num;i++){ if(pautomixer->channels[i].gain<-7200 || pautomixer->channels[i].gain>1200){ pautomixer->channels[i].gain = 0; } if(pautomixer->channels[i].priority<0 || pautomixer->channels[i].priority>10){ pautomixer->channels[i].priority =5; } } handle->halg = alg_automixer_create(handle->input_num,NUM_SAMPLES, RATE_SAMPLES ,pautomixer->master_gain/100.0f, pautomixer->response,pautomixer->slope/100.f); for(i=0;iinput_num;i++){ alg_automixer_set_param(handle->halg, i, pautomixer->channels[i].automatic&0x1,pautomixer->channels[i].mute&0x1 , pautomixer->channels[i].priority , pautomixer->channels[i].gain/100.0f); } handle->level = LEVEL_MALLOC(handle->input_num*2); return handle; } void* fir_create(ptag_fir pfir, char* inport_str,char* outport_str) { pcommon_handle handle = mymalloc(SRAM_AUTO ,sizeof(common_handle)); ASSERT(handle!=0); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->bypass =1 ; //handle->halg = alg_fir_create(NUM_SAMPLES, RATE_SAMPLES); return handle; } void* agc_create(ptag_agc pagc, char* inport_str,char* outport_str) { BEIGN_DECLINE(inport_str) pagc_handle handle = mymalloc(SRAM_AUTO ,sizeof(agc_handle)); ASSERT(handle != 0); normalize((short*)pagc,sizeof(tag_agc)); pagc->bypass &= 0x1; if(pagc->threshold<-9600 || pagc->threshold>-2000){ pagc->threshold = -9600; } if(pagc->tar_threshold<-4000 || pagc->tar_threshold>0){ pagc->tar_threshold = 0; } if(pagc->ratio<100 || pagc->ratio>2000){ pagc->ratio = 100; } if(pagc->attacktime >10000){ pagc->attacktime = 1; } if(pagc->releasetime >10000){ pagc->releasetime = 1; } handle->bypass = pagc->bypass; handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->halg = alg_agc_create(RATE_SAMPLES,NUM_SAMPLES); alg_agc_set_param(handle->halg ,pagc->threshold/100.0f , pagc->tar_threshold/100.0f, pagc->ratio/100.0f ,pagc->attacktime , pagc->releasetime); handle->level = LEVEL_MALLOC(2); handle->param_ptr = pagc; return handle; END_DECLINE(2) } #define AEC_SAMPLE_RATE 32000 #define mem1_ptr (void*)0x000C3000 #define mem2_ptr (void*)0x000C5000 #define TAIL_MS 256 void *aec_create(ptag_aec paec, char* inport_str,char* outport_str) { paec_handle handle = mymalloc(SRAM_AUTO ,sizeof(aec_handle)); ASSERT(handle!=0); normalize((short*)paec,sizeof(tag_aec)); handle->bypass = paec->bypass&0x1; handle->halg = alg_aec_create(RATE_SAMPLES , AEC_SAMPLE_RATE, NUM_SAMPLES, mem1_ptr , mem2_ptr, TAIL_MS); alg_aec_set_param(handle->halg, (aec_mode_t)paec->mode); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = paec; haec = handle->halg; return handle; } void *ans_create(ptag_ans pans, char* inport_str,char* outport_str) { pans_handle handle = mymalloc(SRAM_AUTO ,sizeof(ans_handle)); ASSERT(handle!=0); handle->bypass = pans->bypass&0x1; handle->halg = alg_ans_create(RATE_SAMPLES,RATE_SAMPLES,NUM_SAMPLES); alg_ans_set_policy(handle->halg, (ans_mode)pans->mode); if(pans->mode >= ns_off) pans->mode = ns_18dB; handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pans; hans = handle->halg; return handle; } void *afc_create(ptag_afc pafc, char* inport_str,char* outport_str) { pafc_handle handle = mymalloc(SRAM_AUTO ,sizeof(afc_handle)); ASSERT(handle!=0); if(pafc->gain >1200 || pafc->gain <-7200){ pafc->gain =0; } handle->bypass = pafc->bypass&0x1; handle->gain = pafc->gain; handle->halg = 0;//alg_afc_create(RATE_SAMPLES,NUM_SAMPLES); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pafc; hafc = handle->halg; return handle; } void* sysctl_create(ptag_sysctl psysctl , char* inport_str,char* outport_str) { int i; psysctl_handle handle = mymalloc(SRAM_AUTO ,sizeof(sysctl_handle)); ASSERT(handle!=0); if(psysctl->gain>1200 || psysctl->gain<-8000){ psysctl->gain = 0; } handle->gain = psysctl->gain *0.01; handle->mute = psysctl->mute&0x1; handle->time = 0 ; handle->sample_count =0; handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); for(i=0 ;iinput_num; i++){ handle->old_gain[i] = -120; } handle->param_ptr = psysctl; return handle; } void* selector_create(ptag_selector pselector , char* inport_str,char* outport_str) { int i,j; pselector_handle handle = mymalloc(SRAM_AUTO ,sizeof(selector_handle)); ASSERT(handle!=0); normalize((short*)pselector,sizeof(tag_selector)); memset(handle,0,sizeof(selector_handle)); memcpy(handle->mask,pselector->input_mask,sizeof(pselector->input_mask)); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pselector; //handle->mask[0][34/16]|= 1<<(34&15); return handle; } void* spl_create(ptag_spl pspl ,char* inport_str,char* outport_str) { BEIGN_DECLINE(inport_str) pspl_handle handle = mymalloc(SRAM_AUTO ,sizeof(spl_handle)); ASSERT(handle!=0); normalize((short*)pspl,sizeof(tag_spl)); memset(handle,0,sizeof(spl_handle)); pspl->bypass &= 0x1; if(pspl->maxgain<0 || pspl->maxgain>2000){ pspl->maxgain = 2000; } if(pspl->mingain<-3000 || pspl->mingain>0){ pspl->mingain = -3000; } if(pspl->sense_ratio <50 || pspl->sense_ratio>150){ pspl->sense_ratio = 75; } if(pspl->speed < 500 || pspl->speed>60000){ pspl->speed = 500; } if(pspl->trim < -1000 || pspl->trim > 1000){ pspl->trim = 0; } memcpy (handle->mask ,pspl->mask , sizeof(handle->mask)); handle->halg = alg_spl_continuous_create(RATE_SAMPLES,NUM_SAMPLES); alg_spl_continuous_set_distance(handle->halg ,pspl->distance*0.01); alg_spl_continuous_set_parameters(handle->halg,pspl->noise_thr*0.01, pspl->maxgain*0.01 ,pspl->mingain*0.01 ,pspl->sense_ratio*0.01, pspl->speed,pspl->trim*0.01); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pspl; handle->level = LEVEL_MALLOC(2); handle->bypass = pspl->bypass; return handle; END_DECLINE(2) } void* gate_create(ptag_gate pgate ,char* inport_str,char* outport_str) { BEIGN_DECLINE(inport_str) pgate_handle handle = mymalloc(SRAM_AUTO ,sizeof(gate_handle)); ASSERT(handle!=0); normalize((short*)pgate, sizeof(tag_gate)); memset(handle, 0, sizeof(gate_handle)); if(pgate->attacktime<1 || pgate->attacktime>1000){ pgate->attacktime = 2; } if(pgate->releasetime<5 || pgate->releasetime >10000){ pgate->releasetime = 1000; } if(pgate->holdtime<5 || pgate->holdtime >10000){ pgate->holdtime = 5; } if(pgate->threshold < -4800 || pgate->threshold>0){ pgate->threshold = -3000; } pgate->bypass &= 0x1; if(pgate->depth <-7200 || pgate->depth>0){ pgate->depth = -6000; } handle->halg = alg_gate_create(RATE_SAMPLES,NUM_SAMPLES); alg_gate_set_param(handle->halg, pgate->threshold*0.01, pgate->holdtime, pgate->depth*0.01, pgate->releasetime ,pgate->attacktime); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pgate; handle->level = LEVEL_MALLOC(1); handle->bypass = pgate->bypass; return handle; END_DECLINE(1) } void* ducker_create(ptag_ducker pducker ,char* inport_str,char* outport_str) { BEIGN_DECLINE(inport_str) pducker_handle handle = mymalloc(SRAM_AUTO ,sizeof(ducker_handle)); ASSERT(handle!=0); normalize((short*)pducker, sizeof(tag_ducker)); memset(handle, 0, sizeof(ducker_handle)); if(pducker->attacktime<10 || pducker->attacktime>500){ pducker->attacktime = 20; } if(pducker->holdtime <10 || pducker->holdtime >10000){ pducker->holdtime = 1000; } if(pducker->releasetime <10 || pducker->releasetime >60000){ pducker->releasetime = 1000; } if(pducker->depth <-7200 || pducker->depth>0){ pducker->depth = -6000; } if(pducker->side_gain<-7200 || pducker->side_gain>1200){ pducker->side_gain =0 ; } if(pducker->threshold < -6000 || pducker->threshold>0){ pducker->threshold = -4500; } pducker->bypass &= 0x1; pducker->mute &= 0x1; memcpy (handle->mask ,pducker->mask , sizeof(handle->mask)); handle->bypass = pducker->bypass; handle->halg = alg_ducker_create(RATE_SAMPLES,NUM_SAMPLES); alg_ducker_set_parameters(handle->halg ,pducker->threshold*0.01 ,pducker->depth*0.01, pducker->attacktime , pducker->releasetime ,pducker->holdtime ,pducker->mute , pducker->side_gain*0.01); handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pducker; handle->level = LEVEL_MALLOC(1); return handle; END_DECLINE(1) } void* reverb_create(ptag_reverb preverb ,char* inport_str,char* outport_str) { return 0; } void* echo_create(ptag_echo pecho ,char* inport_str,char* outport_str) { return 0; } void* geq_create(ptag_geq pgeq ,char* inport_str,char* outport_str) { BEIGN_DECLINE(inport_str) int i; float q; pgeq_handle handle = mymalloc(SRAM_AUTO ,sizeof(geq_handle)); ASSERT(handle!=0); normalize((short*)pgeq, sizeof(tag_geq)); memset(handle, 0, sizeof(geq_handle)); pgeq->bypass&=0x1; if(pgeq->nsections > 31) pgeq->nsections =31; if(pgeq->q <1 || pgeq->q>3){ pgeq->q = 2; } for(i=0;insections;i++){ if(pgeq->eq_attr[i].gain<-7200 || pgeq->eq_attr[i].gain > 1200){ pgeq->eq_attr[i].gain =0; } } handle->bypass = pgeq->bypass; handle->halg = alg_eq_create(RATE_SAMPLES,NUM_SAMPLES, pgeq->nsections); q = alg_geq_get_q(handle->halg, pgeq->nsections, pgeq->q); for(i=0;insections;i++){ alg_eq_set_param(handle->halg , i ,eq_geq, 0 ,0, pgeq->eq_attr[i].gain*0.01 , q); } handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pgeq; return handle; END_DECLINE(0) } void* gating_automixer_create(ptag_gating_mixer pautomixer,char* inport_str,char* outport_str) { int i; pgating_mixer_handle handle = mymalloc(SRAM_AUTO ,sizeof(gating_mixer_handle)); ASSERT(handle!=0); normalize((short*)pautomixer,sizeof(tag_gating_mixer)); handle->bypass = pautomixer->bypass ; handle->input_num=str_delim(inport_str,handle->il_id); handle->output_num=str_delim(outport_str,handle->ol_id); handle->param_ptr = pautomixer; //²ÎÊý¼ì²é if(pautomixer->master_gain<-7200 || pautomixer->master_gain>1200){ pautomixer->master_gain =0; } if(pautomixer->holdtime < 100 || pautomixer->holdtime>5000){ pautomixer->holdtime = 500; } if(pautomixer->last_on > AUTOMIXER_CHANNEL_NUM){ pautomixer->last_on = 0; } if(pautomixer->offgain<-9000 || pautomixer->offgain>-1000){ pautomixer->offgain = -4000; } if(pautomixer->noise_thr <-9600 || pautomixer->noise_thr >-2400){ pautomixer->noise_thr = -4800; } if(pautomixer->nom_atten > 600){ pautomixer->nom_atten = 300; } if(pautomixer->nom_num > handle->input_num){ pautomixer->nom_num = 4; } if(pautomixer->sensitivity < 300 || pautomixer->sensitivity>3000){ pautomixer->sensitivity = 600; } pautomixer->master_mute &= 0x1; for(i=0;iinput_num;i++){ if(pautomixer->channels[i].gain<-7200 || pautomixer->channels[i].gain>1200){ pautomixer->channels[i].gain = 0; } if(pautomixer->channels[i].priority>10){ pautomixer->channels[i].priority =5; } pautomixer->channels[i].automatic &= 0x1; pautomixer->channels[i].mute &= 0x1; } handle->halg = alg_gating_automixer_create(handle->input_num,NUM_SAMPLES, RATE_SAMPLES ,pautomixer->master_gain/100.0f, pautomixer->master_mute, pautomixer->last_on); alg_gating_automixer_set_master_param(handle->halg , pautomixer->holdtime, pautomixer->offgain*0.01 ,pautomixer->noise_thr*0.01, pautomixer->sensitivity*0.01, pautomixer->nom_atten*0.01, pautomixer->nom_num); for(i=0;iinput_num;i++){ alg_gating_automixer_set_param(handle->halg, i, pautomixer->channels[i].automatic,pautomixer->channels[i].mute , pautomixer->channels[i].priority , pautomixer->channels[i].gain/100.0f, pautomixer->channels[i].def); } handle->level = LEVEL_MALLOC(handle->input_num*2); return handle; }