📄 psych.c
字号:
}, { /* width */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 12 }, { /* bval */ 0.00, 1.73, 3.41, 4.99, 6.45, 7.75, 8.92, 9.96, 10.87, 11.68, 12.39, 13.03, 13.61, 14.12, 14.59, 15.01, 15.40, 15.76, 16.39, 16.95, 17.45, 17.89, 18.30, 18.67, 19.02, 19.41, 19.85, 20.25, 20.62, 21.01, 21.43, 21.81, 22.15, 22.51, 22.87, 23.23, 23.59, 23.93, 24.00, 24.00, 24.00, 24.00 }, { /* qsthr */ 27.28, 22.28, 14.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 15.29, 15.29, 15.29, 15.29, 15.29, 15.29, 15.29, 17.05, 17.05, 20.05, 20.05, 23.30, 23.30, 23.30, 28.30, 29.27, 29.27, 40.06, 40.06, 40.73, 51.31, 51.82, 52.28, 53.07 } }, { 48000, 42, { /* w_low */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 21, 23, 25, 27, 29, 31, 34, 37, 40, 43, 46, 50, 54, 58, 63, 68, 74, 80, 87, 95, 104, 114, 126 }, { /* w_high */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30, 33, 36, 39, 42, 45, 49, 53, 57, 62, 67, 73, 79, 86, 94, 103, 113, 125, 127 }, { /* width */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 12, 1 }, { /* bval */ 0.00, 1.88, 3.70, 5.39, 6.93, 8.29, 9.49, 10.53, 11.45, 12.26, 12.96, 13.59, 14.15, 14.65, 15.11, 15.52, 15.90, 16.56, 17.15, 17.66, 18.13, 18.54, 18.93, 19.28, 19.69, 20.14, 20.54, 20.92, 21.27, 21.64, 22.03, 22.39, 22.76, 23.13, 23.49, 23.85, 24.00, 24.00, 24.00, 24.00, 24.00, 24.00 }, { /* qsthr */ 27.28, 22.28, 14.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 12.28, 15.29, 15.29, 15.29, 15.29, 15.29, 15.29, 15.29, 17.05, 20.05, 20.05, 20.05, 22.05, 23.30, 28.30, 28.30, 29.27, 39.27, 40.06, 40.06, 50.37, 51.31, 51.82, 52.28, 53.07, 53.07 } }, { 96000 }, { -1 }};/* added by T. Araki (1997.07.10) end *//* added by T. Araki (1997.10.16) */static double sample[MAX_TIME_CHANNELS][BLOCK_LEN_LONG*2]; /* sample value */static FFT_TABLE_LONG fft_tbl_long; /* table for long fft */static FFT_TABLE_SHORT fft_tbl_short; /* table for short fft */static PARTITION_TABLE_LONG *part_tbl_long; /* partition table for long block */static PARTITION_TABLE_SHORT *part_tbl_short; /* partition table for short block *//*static PSY_STATVARIABLE_LONG psy_stvar_long;*/static PSY_STATVARIABLE_LONG psy_stvar_long[MAX_TIME_CHANNELS]; /* static variables for long block *//*static PSY_STATVARIABLE_SHORT psy_stvar_short;*/static PSY_STATVARIABLE_SHORT psy_stvar_short[MAX_TIME_CHANNELS]; /* static variables for short block *//* added by T. Araki (1997.10.16) end */void EncTf_psycho_acoustic_init( void ){ int chanNum;/* added by T. Araki (1997.10.16) */ psy_fft_table_init(&fft_tbl_long, &fft_tbl_short); /* initializing fft table */ for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) { psy_calc_init(&sample[chanNum], &psy_stvar_long[chanNum], &psy_stvar_short[chanNum]); /* initializing static variables */ }/* added by T. Araki (1997.10.16) end */}/* added by T. Okada (1997.07.10) */void psy_fft_table_init(FFT_TABLE_LONG *fft_tbl_long, FFT_TABLE_SHORT *fft_tbl_short ){ int i,j,k,n,n2,n4,n8; double c,s,dc,ds,t; /* generating Hann window */ for(i = 0; i < BLOCK_LEN_LONG*2; ++i) fft_tbl_long->hw[i] = (0.5 - 0.5 * cos( M_PI * (double)(i + 0.5)/(double)(BLOCK_LEN_LONG) ) ); for(i = 0; i < BLOCK_LEN_SHORT*2; ++i) fft_tbl_short->hw[i] = (0.5 - 0.5 * cos( M_PI * (double)(i + 0.5)/(double)(BLOCK_LEN_SHORT) ) ); /* generating sin table (long) */ n = BLOCK_LEN_LONG * 2; n2 = n/2; n4 = n2/2; n8 = n4/2; t = sin(M_PI / (double)n); dc = 2.0*t*t; ds = sqrt(dc * (2.0 - dc)); t = 2*dc; c = fft_tbl_long->st[n4] = 1.0; s = fft_tbl_long->st[0] = 0; for(i = 1; i < n8; ++i){ c -= dc; dc += t * c; s += ds; ds -= t * s; fft_tbl_long->st[i] = s; fft_tbl_long->st[n4 - i] = c; } if (n8 != 0) fft_tbl_long->st[n8] = sqrt(0.5); for (i = 0; i < n4; i++) fft_tbl_long->st[n2 - i] = fft_tbl_long->st[i]; for (i = 0; i < n2 + n4; i++) fft_tbl_long->st[i + n2] = -fft_tbl_long->st[i]; /* generating sin table (short) */ n = BLOCK_LEN_SHORT * 2; n2 = n/2; n4 = n2/2; n8 = n4/2; t = sin(M_PI / (double)n); dc = 2*t*t; ds = sqrt(dc * (2.0 - dc)); t = 2*dc; c = fft_tbl_short->st[n4] = 1.0; s = fft_tbl_short->st[0] = 0; for(i = 1; i < n8; ++i){ c -= dc; dc += t * c; s += ds; ds -= t * s; fft_tbl_short->st[i] = s; fft_tbl_short->st[n4 - i] = c; } if (n8 != 0) fft_tbl_short->st[n8] = sqrt(0.5); for (i = 0; i < n4; i++) fft_tbl_short->st[n2 - i] = fft_tbl_short->st[i]; for (i = 0; i < n2 + n4; i++) fft_tbl_short->st[i + n2] = - fft_tbl_short->st[i]; /* generating bit inverse table (long) */ n = BLOCK_LEN_LONG * 2; n2 = n/2; i = j = 0; for(;;){ fft_tbl_long->brt[i] = j; if( ++i >= n ) break; k = n2; while(k <= j){ j -= k; k /= 2; } j += k; } /* generating bit inverse table (short) */ n = BLOCK_LEN_SHORT * 2; n2 = n/2; i = j = 0; for(;;){ fft_tbl_short->brt[i] = j; if( ++i >= n ) break; k = n2; while(k <= j){ j -= k; k /= 2; } j += k; }}/* added by T. Okada (1997.07.10) end *//* added by T. Araki (1997.07.10) */void psy_part_table_init( double sampling_rate, PARTITION_TABLE_LONG **part_tbl_long, PARTITION_TABLE_SHORT **part_tbl_short ){ int b,bb; /* Jul 10 */ double tmp; *part_tbl_long = &part_tbl_long_all[0]; /* find correct sampling rate depending parameters */ while( (*part_tbl_long)->sampling_rate != (int)sampling_rate ) { (*part_tbl_long)++; } *part_tbl_short = &part_tbl_short_all[0]; /* find correct sampling rate depending parameters */ while( (*part_tbl_short)->sampling_rate != (int)sampling_rate ) { (*part_tbl_short)++; }}void psy_calc_init( double sample[][BLOCK_LEN_LONG*2], PSY_STATVARIABLE_LONG *psy_stvar_long, PSY_STATVARIABLE_SHORT *psy_stvar_short ){ int ch; int chanNum; int w; int i; ch=0; /* for(ch = 0; ch < Chans; ++ch){ */ for(i = 0; i < BLOCK_LEN_LONG*2; ++i){ sample[ch][i] = 0.0; } /* } */ /* for(ch = 0; ch < Chans; ++ch){ */ for(i = 0; i < BLOCK_LEN_LONG*3; ++i){ psy_stvar_long->fft_r[ch][i] = 0.0; psy_stvar_long->fft_f[ch][i] = 0.0; } /* }*/ psy_stvar_long->p_fft = 0; /* for(ch = 0; ch < Chans; ++ch){*/ for(i = 0; i < NPART_LONG*2; ++i){ psy_stvar_long->nb[ch][i] = 90.0; } /*}*/ psy_stvar_long->p_nb = 0;/* added by T. Araki (1997.07.10) end *//* added by T. Araki (1997.10.16) */ /* for(ch = 0; ch < Chans; ++ch){*/ for(i = 0; i < BLOCK_LEN_SHORT; ++i){ psy_stvar_short->last6_fft_r[ch][i] = 0.0; psy_stvar_short->last6_fft_f[ch][i] = 0.0; psy_stvar_short->last7_fft_r[ch][i] = 0.0; psy_stvar_short->last7_fft_f[ch][i] = 0.0; } /* }*/ /* for(ch = 0; ch < Chans; ++ch){*/ for(i = 0; i < NPART_SHORT; ++i){ psy_stvar_short->last7_nb[ch][i] = 90.0; } /* }*//* added by T. Araki (1997.10.16) end */}/* main */void EncTf_psycho_acoustic( /* input */ double sampling_rate, int no_of_chan, /* no of audio channels */ double *p_time_signal[], enum WINDOW_TYPE block_type[], int qcSelect, int frameLength, /* output */ CH_PSYCH_OUTPUT p_chpo_long[], CH_PSYCH_OUTPUT p_chpo_short[][MAX_SHORT_WINDOWS] ){
int ch;
SR_INFO *p_sri;
/* added by T. Araki (1997.07.10) */
static int flag = 0;
PSY_VARIABLE_LONG psy_var_long; /* variables for long block */
PSY_VARIABLE_SHORT psy_var_short; /* variables for short block */
/* added by T. Araki (1997.07.10) end */
if ((qcSelect==AAC_QC)||(qcSelect==AAC_PRED)) { /* AAC */
switch (frameLength) {
case 960:
p_sri = &sr_info_960[0];
break;
case 1024:
p_sri = &sr_info_aac[0];
break;
}
} else {
p_sri = &sr_info_NOT_aac[0];
}
/* find correct sampling rate depending parameters */
while( p_sri->sampling_rate != (long)sampling_rate ) {
p_sri++;
}
/* added by T. Araki (1997.07.10) */
if( flag==0 ) {
psy_part_table_init(sampling_rate, &part_tbl_long, &part_tbl_short);
/* initializing Table B 2.1.*.a, B 2.1.*.b in N1650 */
flag = 1;
}
ch =0;
/* Add step1 to step14 here, if you want to use ismr values. */
{
int i;
/* This line below should be changed when using ismr values. */
p_chpo_long[ch].p_ratio = p_sri->fixed_ratio_long;
p_chpo_long[ch].cb_width = p_sri->cb_width_long;
p_chpo_long[ch].no_of_cb = p_sri->num_cb_long;
for( i=0; i<MAX_SHORT_WINDOWS; i++ ) {
/* This line below should be changed when using ismr values. */
p_chpo_short[ch][i].p_ratio = p_sri->fixed_ratio_short;
p_chpo_short[ch][i].cb_width = p_sri->cb_width_short;
p_chpo_short[ch][i].no_of_cb = p_sri->num_cb_short;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -