/*
|
* scene.c
|
* Description:
|
*
|
* Created on: 2014-10-28
|
* Author: Graydon
|
* Modify:
|
*/
|
#include <stdio.h>
|
#include <assert.h>
|
#include <stdlib.h>
|
#include <string.h>
|
#include <alg.h>
|
#include "drv/global.h"
|
#include "drv/hmem.h"
|
#include "scene.h"
|
#include "drv/fft.h"
|
|
static short level_buf[1024];
|
static int nlevels=0;
|
#define LEVEL_MALLOC(n) level_buf+nlevels;nlevels+=n
|
|
#define AEC_MEM1 (void*)0x000c3000
|
#define AEC_MEM2 (void*)0x000c5000
|
#define AEC_SMALES 32000
|
#define AEC_TAIL 256
|
|
void* hafc=0;
|
void* haec=0;
|
void* hans=0;
|
|
//alg_asy_handle alg= {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;i<n;i++){
|
// level_buf[i] = -12000;
|
//}
|
|
// for(i=0;i<sizeof(m->feedback_meter);i+=2){
|
// m->feedback_meter[i] = 20;
|
// m->feedback_meter[i+1] = 0;
|
// }
|
}
|
|
int str_delim(const char* str, unsigned int number[])
|
{
|
char pstr[32];
|
char * ptr;
|
|
int i = 0;
|
|
strcpy(pstr, str);
|
ptr = strtok(pstr, "|");
|
|
if (strcmp(ptr, str) == 0) {
|
int start, end;
|
ptr = strtok(pstr, "-");
|
start = atoi(ptr);
|
|
ptr = strtok(NULL, "-");
|
end = atoi(ptr);
|
while (start<=end)
|
{
|
number[i++] = start++;
|
}
|
return i;
|
}
|
else
|
{
|
while (ptr)
|
{
|
number[i++] = atoi(ptr);
|
ptr = strtok(NULL, "|");
|
}
|
return i;
|
}
|
}
|
|
void normalize(short* ptr,int size)
|
{
|
int i;
|
for(i=0;i<size;i++){
|
ptr[i]=NORMALIZE(ptr[i]);
|
}
|
}
|
|
void* input_create(ptag_input pInput,char* inport_str,char* outport_str)
|
{
|
int i;
|
pinput_handle handle = mymalloc(SRAM_AUTO , sizeof(input_handle));
|
assert(handle!=0);
|
|
normalize((short*)pInput,sizeof(tag_input));
|
memset(handle,0,sizeof(input_handle));
|
|
handle->input_num=str_delim(inport_str,handle->il_id);
|
handle->output_num=str_delim(outport_str,handle->ol_id);
|
|
for(i=0;i<handle->input_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&0x3;
|
handle->input[i].phase = pInput->input[i].phase&0x1;
|
|
if(pInput->input[i].phant){
|
handle->input[i].delay = RATE_SAMPLES*5;
|
}
|
|
// handle->input[i].hExpander = alg_expander_create(RATE_SAMPLES,NUM_SAMPLES);
|
// alg_expander_set_param(handle->input[i].hExpander, -72.0, 1.2, 1,1);
|
|
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;
|
}
|
|
void* output_create(ptag_output pOutput, char* inport_str, char* outport_str)
|
{
|
|
int i;
|
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;i<handle->output_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;
|
}
|
|
void* delay_create( ptag_delay pDelay, char* inport_str, char* outport_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;
|
}
|
if(pDelay->us > 999) {
|
pDelay->us= 0;
|
}
|
|
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+pDelay->us*0.001);
|
|
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;
|
}
|
|
void* shelf_create(ptag_shelf pshelf,char* inport_str, char* outport_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;
|
}
|
|
void* eq_create(ptag_eq pEQ, char* inport_str, char* outport_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;i<pEQ->nsection;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;i<pEQ->nsection;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;
|
}
|
|
void* expander_create(ptag_expander pExpander, char* inport_str, char* outport_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;
|
}
|
|
void* compressor_create(ptag_compress pcompress, char* inport_str, char* outport_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;
|
}
|
|
#if 0
|
void* mixer_create(ptag_mixer pMixer, char* inport_str, char* outport_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);
|
|
for (i=0;i<handle->output_num ;i ++){
|
for(j=0;j<handle->input_num;j++){
|
if((pMixer->input_mask[i][j/16]>>(j&15))&0x1){
|
handle->gain[i*handle->input_num+j] = fgain_get_factor(pMixer->input_gain[i][j]/100.0f);
|
handle->step[i*handle->input_num+j] = handle->gain[i*handle->input_num+j] ;
|
}
|
else{
|
handle->gain[i*handle->input_num+j] = 0;
|
handle->step[i*handle->input_num+j] = 0;
|
}
|
|
}
|
handle->weight[i] = 1.0f;
|
}
|
//memcpy(handle->mask,pMixer->input_mask,sizeof(pMixer->input_mask));
|
|
handle->param_ptr = pMixer;
|
|
|
return handle;
|
}
|
#else
|
void* mixer_create(ptag_mixer pMixer, char* inport_str, char* outport_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);
|
|
for (i=0;i<handle->output_num ;i ++){
|
for(j=0;j<handle->input_num;j++){
|
handle->gain[i][j] = pMixer->input_gain[i][j]*0.01f;
|
}
|
}
|
memcpy(handle->mask,pMixer->input_mask,sizeof(pMixer->input_mask));
|
|
handle->param_ptr = pMixer;
|
|
|
return handle;
|
}
|
#endif
|
|
void* crossover_create(ptag_crossover pCross, char* inport_str, char* outport_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;
|
}
|
|
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)
|
{
|
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;
|
}
|
|
|
void* feedback_create(ptag_feedback pfeedback, char* inport_str,char* outport_str)
|
{
|
int i;
|
|
pfeedback_handle handle = mymalloc(SRAM_AUTO ,sizeof(feedback_handle));
|
assert(handle!=0);
|
#if 1
|
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;
|
}
|
|
|
handle->bypass = pfeedback->bypass;
|
|
#if 1
|
handle->halg=alg_nhs_create(RATE_SAMPLES,NUM_SAMPLES, 8, pfeedback->fb_threshold*0.01, pfeedback->panic_threshold*0.01);
|
|
alg_nhs_set_parameters(handle->halg, 2.5 ,pfeedback->flt_depth*0.01, pfeedback->bw*0.01);
|
|
for(i=0;i<FEEDBACK_FILTERS_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);
|
|
}
|
#else
|
{
|
static int init=0;
|
if(inport_str[0]=='1' && init ==0){
|
handle->halg = alg_afc_create(RATE_SAMPLES,NUM_SAMPLES);
|
alg.hafc = handle->halg;
|
init =1;
|
}
|
else{
|
handle->halg = 0;
|
}
|
}
|
#endif
|
|
handle->level = LEVEL_MALLOC(FEEDBACK_FILTERS_NUM*2);
|
#endif
|
return handle;
|
}
|
|
#if 1
|
void* automixer_create(ptag_automixer pautomixer, char* inport_str,char* outport_str)
|
{
|
int i;
|
pautomixer_handle handle = mymalloc(SRAM_AUTO ,sizeof(automixer_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;i<handle->input_num;i++){
|
if(pautomixer->channels[i].gain<-7200 || pautomixer->channels[i].gain>1200){
|
pautomixer->channels[i].gain = 0;
|
}
|
if(pautomixer->channels[i].threshold< 0 || pautomixer->channels[i].threshold>10){
|
pautomixer->channels[i].threshold =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;i<handle->input_num;i++){
|
alg_automixer_set_param(handle->halg, i, pautomixer->channels[i].automatic&0x1,pautomixer->channels[i].master&0x1
|
, pautomixer->channels[i].threshold, pautomixer->channels[i].gain/100.0f);
|
}
|
|
|
handle->level = LEVEL_MALLOC(handle->input_num*2);
|
return handle;
|
}
|
#else
|
void* automixer_create(ptag_automixer pautomixer, char* inport_str,char* outport_str)
|
{
|
int i;
|
pautomixer_handle handle = mymalloc(SRAM_AUTO ,sizeof(automixer_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;
|
|
//2?¨ºy?¨¬2¨¦
|
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;i<handle->input_num;i++){
|
if(pautomixer->channels[i].gain<-7200 || pautomixer->channels[i].gain>1200){
|
pautomixer->channels[i].gain = 0;
|
}
|
if(pautomixer->channels[i].threshold<-6000 || pautomixer->channels[i].threshold>0){
|
pautomixer->channels[i].threshold =-4800;
|
}
|
}
|
|
handle->halg = alg_pri_automixer_create(handle->input_num,NUM_SAMPLES, RATE_SAMPLES
|
,pautomixer->master_gain/100.0f, pautomixer->response,pautomixer->slope/100.f);
|
|
for(i=0;i<handle->input_num;i++){
|
alg_pri_automixer_set_param(handle->halg, i, pautomixer->channels[i].automatic&0x1,pautomixer->channels[i].master&0x1
|
, pautomixer->channels[i].threshold*0.01 , pautomixer->channels[i].gain/100.0f);
|
}
|
|
|
handle->level = LEVEL_MALLOC(handle->input_num*2);
|
return handle;
|
}
|
#endif
|
|
|
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)
|
{
|
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;
|
}
|
//pagc->threshold = -7200;
|
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->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->input_num=str_delim(inport_str,handle->il_id);
|
handle->output_num=str_delim(outport_str,handle->ol_id);
|
|
handle->level = LEVEL_MALLOC(2);
|
|
handle->param_ptr = pagc;
|
|
return handle;
|
}
|
|
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));
|
|
//void *aec_mem1 = mymalloc(SRAM_AUTO ,6*1024);
|
//void *aec_mem2 = mymalloc(SRAM_AUTO ,6*1024);
|
|
handle->bypass = paec->bypass&0x1;
|
handle->halg = alg_aec_create(RATE_SAMPLES,AEC_SMALES ,NUM_SAMPLES,AEC_MEM1 ,AEC_MEM2, AEC_TAIL);
|
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;
|
|
if(pans->mode >= ns_off) pans->mode = ns_18dB;
|
|
handle->halg = alg_ans_create(RATE_SAMPLES, RATE_SAMPLES , NUM_SAMPLES);
|
alg_ans_set_policy(handle->halg, (ans_mode)pans->mode);
|
|
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* 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->input_num=str_delim(inport_str,handle->il_id);
|
handle->output_num=str_delim(outport_str,handle->ol_id);
|
|
for(i=0 ;i<handle->input_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;
|
|
|
return handle;
|
|
}
|