📄 l3psy.c
字号:
tbb = -0.299 - 0.43*cbb; /* conv1=-0.299, conv2=-0.43 */ tbb = minimum( 1.0, maximum( 0.0, tbb) ) ; /* 0<tbb<1 */ SNR_l[b] = maximum( minval[b], 29.0*tbb+6.0*(1.0-tbb) ); } /* TMN=29.0,NMT=6.0 for all calculation partitions */ for ( b = 0; b < CBANDS; b++ ) /* calculate the threshold for each partition */ nb[b] = ecb[b] * norm_l[b] * exp( -SNR_l[b] * LN_TO_LOG10 ); for ( b = 0; b < CBANDS; b++ ) { /* pre-echo control */ double temp_1; /* BUG of IS */ temp_1 = minimum( nb[b], minimum(2.0*nb_1[channel][b],16.0*nb_2[channel][b]) ); thr[b] = maximum( qthr_l[b], temp_1 ); nb_2[channel][b] = nb_1[channel][b]; nb_1[channel][b] = nb[b]; } *pe = 0.0; /* calculate perceptual entropy */ for ( b = 0; b < CBANDS; b++ ) { double tp ; tp = minimum( 0.0, log((thr[b]+1.0) / (eb[b]+1.0) ) ) ; /*not log*/ *pe -= numlines[b] * tp ; } #define switch_pe 1800 blocktype = NORM_TYPE; if ( *pe < switch_pe ) { /* no attack : use long blocks */ switch( blocktype_old[channel] ) { case NORM_TYPE: case STOP_TYPE: blocktype = NORM_TYPE; break; case SHORT_TYPE: blocktype = STOP_TYPE; break; case START_TYPE: fprintf( stderr, "Error in block selecting\n" ); abort(); break; /* problem */ } /* threshold calculation (part 2) */ for ( sb = 0; sb < SBMAX_l; sb++ ) { en[sb] = w1_l[sb] * eb[bu_l[sb]] + w2_l[sb] * eb[bo_l[sb]]; thm[sb] = w1_l[sb] *thr[bu_l[sb]] + w2_l[sb] * thr[bo_l[sb]]; for ( b = bu_l[sb]+1; b < bo_l[sb]; b++ ) { en[sb] += eb[b]; thm[sb] += thr[b]; } if ( en[sb] != 0.0 ) ratio[channel][sb] = thm[sb]/en[sb]; else ratio[channel][sb] = 0.0; } } else { /* attack : use short blocks */ blocktype = SHORT_TYPE; if(blocktype_old[channel]==NORM_TYPE) blocktype_old[channel] = START_TYPE; if(blocktype_old[channel]==STOP_TYPE) blocktype_old[channel] = SHORT_TYPE ; /* threshold calculation for short blocks */ for ( sblock = 0; sblock < 3; sblock++ ) { for ( b = 0; b < CBANDS_s; b++ ) { eb[b] = 0.0; ecb[b] = 0.0; } for ( j = 0; j < HBLKSIZE_s; j++ ) eb[partition_s[j]] += energy_s[sblock][j]; for ( b = 0; b < CBANDS_s; b++ ) for ( k = 0; k < CBANDS_s; k++ ) ecb[b] += s3_l[b][k] * eb[k]; for ( b = 0; b < CBANDS_s; b++ ) { nb[b] = ecb[b] * norm_l[b] * exp((double)SNR_s[b]*LN_TO_LOG10); thr[b] = maximum(qthr_s[b],nb[b]); } for ( sb = 0; sb < SBMAX_s; sb++ ) { en[sb] = w1_s[sb] * eb[bu_s[sb]] + w2_s[sb] * eb[bo_s[sb]]; thm[sb] = w1_s[sb] *thr[bu_s[sb]] + w2_s[sb] * thr[bo_s[sb]]; for ( b = bu_s[sb]+1; b < bo_s[sb]; b++ ) { en[sb] += eb[b]; thm[sb] += thr[b]; } if(en[sb]!=0.0) ratio_s[channel][sb][sblock] = thm[sb]/en[sb]; else ratio_s[channel][sb][sblock] = 0.0; } } } cod_info->block_type = blocktype_old[channel]; blocktype_old[channel] = blocktype; if ( cod_info->block_type == NORM_TYPE ) cod_info->window_switching_flag = 0; else cod_info->window_switching_flag = 1; cod_info->mixed_block_flag = 0;}#include "psy_data.h"void L3para_read(){int curr_line = 0;char *temp; double freq_tp; static double bval_l[CBANDS], bval_s[CBANDS]; int cbmax=0, cbmax_tp; static double s3_s[CBANDS][CBANDS]; char tp[256]; int sbmax ; int i,j,k,k2,loop, part_max ;/* Read long block data */ for(loop=0;loop<6;loop++) {temp = psy_data[curr_line++]; sscanf(temp,"freq = %lf partition = %d\n",&freq_tp,&cbmax_tp); cbmax_tp++; if (config.wave.samplerate == freq_tp) { cbmax = cbmax_tp; for(i=0,k2=0;i<cbmax_tp;i++) {temp = psy_data[curr_line++]; sscanf(temp, "No=%d #lines=%d minval=%lf qthr=%lf norm=%lf bval=%lf\n", &j,&numlines[i],&minval[i],&qthr_l[i],&norm_l[i],&bval_l[i]); if (j!=i) { printf("please check \"psy_data\""); exit(-1); } for(k=0;k<numlines[i];k++) partition_l[k2++] = i ; } } else { for(j=0;j<cbmax_tp;j++) {char *temp;temp = psy_data[curr_line++]; sscanf(temp,"No=%d %s\n",&i,tp); if (j!=i) { printf("please check \"psy_data.\"\n"); exit(-1); } } } }/************************************************************************ * Now compute the spreading function, s[j][i], the value of the spread-* * ing function, centered at band j, for band i, store for later use * ************************************************************************/ part_max = cbmax ; for(i=0;i<part_max;i++) { double tempx,x,tempy,temp; for(j=0;j<part_max;j++) { tempx = (bval_l[i] - bval_l[j])*1.05; if (j>=i) tempx = (bval_l[i] - bval_l[j])*3.0; else tempx = (bval_l[i] - bval_l[j])*1.5; if(tempx>=0.5 && tempx<=2.5) { temp = tempx - 0.5; x = 8.0 * (temp*temp - 2.0 * temp); } else x = 0.0; tempx += 0.474; tempy = 15.811389 + 7.5*tempx - 17.5*sqrt(1.0+tempx*tempx); if (tempy <= -60.0) s3_l[i][j] = 0.0; else s3_l[i][j] = exp( (x + tempy)*LN_TO_LOG10 ); } }/* Read short block data */ for(loop=0;loop<6;loop++) {temp = psy_data[curr_line++]; sscanf(temp,"freq = %lf partition = %d\n",&freq_tp,&cbmax_tp); cbmax_tp++; if (config.wave.samplerate==freq_tp) { cbmax = cbmax_tp; for(i=0,k2=0;i<cbmax_tp;i++) {temp = psy_data[curr_line++]; sscanf(temp, "No=%d #lines=%d qthr=%lf norm=%lf SNR=%lf bval=%lf\n", &j,&numlines[i],&qthr_s[i],&norm_s[i],&SNR_s[i],&bval_s[i]); if (j!=i) { printf("please check \"psy_data\""); exit(-1); } for(k=0;k<numlines[i];k++) partition_s[k2++] = i ; } } else { for(j=0;j<cbmax_tp;j++) {temp = psy_data[curr_line++]; sscanf(temp,"No=%d %s\n",&i,tp); if (j!=i) { printf("please check \"psy_data.\"\n"); exit(-1); } } } }/************************************************************************ * Now compute the spreading function, s[j][i], the value of the spread-* * ing function, centered at band j, for band i, store for later use * ************************************************************************/ part_max = cbmax ; for(i=0;i<part_max;i++) { double tempx,x,tempy,temp; for(j=0;j<part_max;j++) { tempx = (bval_s[i] - bval_s[j])*1.05; if (j>=i) tempx = (bval_s[i] - bval_s[j])*3.0; else tempx = (bval_s[i] - bval_s[j])*1.5; if(tempx>=0.5 && tempx<=2.5) { temp = tempx - 0.5; x = 8.0 * (temp*temp - 2.0 * temp); } else x = 0.0; tempx += 0.474; tempy = 15.811389 + 7.5*tempx - 17.5*sqrt(1.0+tempx*tempx); if (tempy <= -60.0) s3_s[i][j] = 0.0; else s3_s[i][j] = exp( (x + tempy)*LN_TO_LOG10 ); } }/* Read long block data for converting threshold calculation partitions to scale factor bands */ for(loop=0;loop<6;loop++) {temp = psy_data[curr_line++]; sscanf(temp,"freq=%lf sb=%d\n",&freq_tp,&sbmax); sbmax++; if (config.wave.samplerate== freq_tp) { for(i=0;i<sbmax;i++) {temp = psy_data[curr_line++]; sscanf(temp, "sb=%d cbw=%d bu=%d bo=%d w1=%lf w2=%lf\n", &j,&cbw_l[i],&bu_l[i],&bo_l[i],&w1_l[i],&w2_l[i]); if (j!=i) { printf("30:please check \"psy_data\"\n"); exit(-1); } if (i!=0) if ( (bo_l[i] != (bu_l[i]+cbw_l[i])) || (fabs(1.0-w1_l[i]-w2_l[i-1]) > 0.01 ) ) { printf("31:please check \"psy_data.\"\n"); exit(-1); } } } else { for(j=0;j<sbmax;j++) {temp = psy_data[curr_line++]; sscanf(temp,"sb=%d %s\n",&i,tp); if (j!=i) { printf("please check \"psy_data.\"\n"); exit(-1); } } } }/* Read short block data for converting threshold calculation partitions to scale factor bands */ for(loop=0;loop<6;loop++) {temp = psy_data[curr_line++]; sscanf(temp,"freq=%lf sb=%d\n",&freq_tp,&sbmax); sbmax++; if (config.wave.samplerate == freq_tp) { for(i=0;i<sbmax;i++) {temp = psy_data[curr_line++]; sscanf(temp, "sb=%d cbw=%d bu=%d bo=%d w1=%lf w2=%lf\n", &j,&cbw_s[i],&bu_s[i],&bo_s[i],&w1_s[i],&w2_s[i]); if (j!=i) { printf("30:please check \"psy_data\"\n"); exit(-1); } if (i!=0) if ( (bo_s[i] != (bu_s[i]+cbw_s[i])) || (fabs(1.0-w1_s[i]-w2_s[i-1]) > 0.01 ) ) { printf("31:please check \"psy_data.\"\n"); exit(-1); } } } else { for(j=0;j<sbmax;j++) {temp = psy_data[curr_line++]; sscanf(temp,"sb=%d %s\n",&i,tp); if (j!=i) { printf("please check \"psy_data.\"\n"); exit(-1); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -