📄 tonal.c
字号:
ltg[k].x = non_lin_add(ltg[k].x, tmps, MASK_ADD); } t = power[t].next; } if (bit_rate < H_THR_OS_BR) ltg[k].x = non_lin_add(ltg[k].hear, ltg[k].x, QUIET_ADD); else ltg[k].x = non_lin_add(ltg[k].hear + H_THR_OFFSET, ltg[k].x, QUIET_ADD); } /* for */ fflush(stderr);}/* --------------------------------------------------------------non_lin_addA flexible addition function for levels.Input: a,b: the levels to be added. c: the number of dB increase when a and b are equal.Common values for c are 3.01 (power addition) and 6.02 (voltage addition).10.0/(10*log10(2)) = 3.3219Function added 1993-04-14 Soren H. Nielsen-------------------------------------------------------------- */double non_lin_add(double a, double b, double c){ c *= 3.3219; a = pow(10.0, a/c); b = pow(10.0, b/c); return(c*log10(a+b));}/****************************************************************//*/* This function finds the minimum masking threshold and/* return the value to the encoder./*/****************************************************************/void II_minimum_mask(int sub_size, g_thres *ltg, double *ltmin, int sblimit){ double min; int i,j; j=1; for(i=0;i<sblimit;i++) if(j>=sub_size-1) /* check subband limit, and */ ltmin[i] = ltg[sub_size-1].hear; /* calculate the minimum masking */ else { /* level of LTMIN for each subband*/ min = ltg[j].x; while(ltg[j].line>>4 == i && j < sub_size){ if(min>ltg[j].x) min = ltg[j].x; j++; } ltmin[i] = min; }}/*****************************************************************//*/* This procedure is called in musicin to pick out the/* smaller of the scalefactor or threshold./*/*****************************************************************/void II_smr (double *ltmin, double *smr, double *spike, double *scale, int sblimit, int l, int m){ int i,j; double max; for (i = l; i < m; i++) { /* determine the signal */ max = 20 * log10 (scale[i] * 32768) - 10; /* level for each subband */ if (spike[i] > max) max = spike[i]; /* for the maximum scale */ max -= ltmin[i]; /* factors */ smr[i] = max; }} /****************************************************************//*/* This procedure calls all the necessary functions to/* complete the psychoacoustic analysis./*/****************************************************************/void II_Psycho_One (double (*buffer)[1152], double (*scale)[32], double (*ltmin)[32], frame_params *fr_ps, double (*smr)[32], double (*spiki)[32], int aiff){ layer *info = fr_ps->header; int stereo = fr_ps->stereo; int stereomc = fr_ps->stereomc; int stereoaug = fr_ps->stereoaug; int sblimit = fr_ps->sblimit; int k,i, tone=0, noise=0; static char init = 0; static int off[12] = {256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256}; /* max 7 MC channels + 5 compatible channels */ double *sample; DSBL *spike; static D1408 *fft_buf; static mask_ptr power; static g_ptr ltg; int j, l, z, q; static int crit_band; static int *cbound; static int sub_size; sample = (double *) mem_alloc (sizeof (DFFT), "sample"); spike = (DSBL *) mem_alloc (sizeof (D12SBL), "spike"); if (!init) { /* bands, bark values, and mapping */ /* changed 5 to 7 for matricing 8/10/93,SR */ /* changed 7 to 12 for aug matricing 8/11/96,FdB */ fft_buf = (D1408 *) mem_alloc ((long) sizeof (D1408) * 12, "fft_buf"); power = (mask_ptr) mem_alloc (sizeof (mask) * HAN_SIZE, "power"); /* call functions for critical boundaries, freq. */ crit_band = read_crit_band (info->lay, info->sampling_frequency); cbound = (int *) mem_alloc (sizeof (int) * crit_band, "cbound"); read_cbound (info->lay, info->sampling_frequency, crit_band, cbound); read_freq_band (&sub_size, <g, info->lay, info->sampling_frequency); make_map (sub_size, power, ltg); for (i = 0; i < 1408; i++) fft_buf[0][i] = fft_buf[1][i] = fft_buf[2][i] = fft_buf[3][i] = fft_buf[4][i] = fft_buf[5][i] = fft_buf[6][i] = fft_buf[7][i] = fft_buf[8][i] = fft_buf[9][i] = fft_buf[10][i] = fft_buf[11][i] = 0; init = 1; } if (aiff != 1) { j = 0; l = 2; } else { j = 0; if (stereoaug == 2) l = 12; /*fr_ps->stereo + fr_ps->stereomc + fr_ps->stereoaug + 5 compatible */ else l = 7; /*fr_ps->stereo + fr_ps->stereomc + 2 compatible */ } for (k = j; k < l; k++) { for (i = 0; i < 1152; i++) fft_buf[k][(i + off[k]) % 1408] = (double) buffer[k][i] / SCALE; for (i = 0; i < FFT_SIZE; i++) sample[i] = fft_buf[k][(i + 1216 + off[k]) % 1408]; off[k] += 1152; off[k] %= 1408; /* call functions for windowing PCM samples,*/ II_hann_win (sample); /* location of spectral components in each */ for (i = 0; i < HAN_SIZE; i++) power[i].x = DBMIN; /* subband with labeling */ II_f_f_t (sample, power); /* locate remaining non- */ if (fr_ps->header->center == 3 && k == 2) { /* set center to 0, 9/2/93,SR*/ /* add to Left and Right ? WtK */ for (z = 184; z < HAN_SIZE; z++) power[z].x = -103.670; /* DBMIN + 96.330; */ } II_pick_max (power, spike[k]); /* tonal sinusoidals, */#ifdef PRINTOUT if (verbosity >= 3) { printf ("\nChannel %d", k); printf ("\nSignal value per subband, from the FFT:\n"); for (i = 0; i < sblimit; i++) printf ("%5.1f dB ", spike[k][i]); printf ("\nMax. signal peak per subband, SCF SPL:\n"); for (i = 0; i < sblimit; i++) /* from [II_smr] determine the SCF SPL */ printf ("%5.1f dB ", 20 * log10(scale[k][i] * 32768)); fflush (stdout); }#endif II_tonal_label (power, &tone); /* reduce noise & tonal components , find */ noise_label (crit_band, cbound, power, &noise, ltg); #ifdef PRINTOUT if (verbosity >= 3) { printf ("\nMaskers before sorting, FFT based levels:\n"); for (i = 0; i < 511; i++) { if ((power[i].type == NOISE) && (power[i].x > -200)) printf ("N:%3u %5.1f dB ", i, power[i].x); if ((power[i].type == TONE) && (power[i].x > -200)) printf ("T:%3u %5.1f dB ", i, power[i].x); } printf ("tone = %d noise = %d \n", tone, noise); fflush (stdout); }#endif subsampling (power, ltg, &tone, &noise); /* global & minimal */ #ifdef PRINTOUT if (verbosity >= 3) { printf ("\nMaskers after sorting:\n"); for (i = 0; i < 511; i++) { if ((power[i].type == NOISE) && (power[i].x > -200)) printf ("N:%3u %5.1f dB ", i, power[i].x); if ((power[i].type == TONE) && (power[i].x > -200)) printf ("T:%3u %5.1f dB ", i, power[i].x); } fflush (stdout); }#endif threshold (sub_size, power, ltg, &tone, &noise, bitrate[info->lay-1][info->bitrate_index] / (stereo+stereomc+stereoaug)); /*to-mask ratio*//* 21/03/1995 JMZ BUG ???!!!???*/ II_minimum_mask (sub_size, ltg, <min[k][0], sblimit); #ifdef PRINTOUT if (verbosity >= 3) { printf ("\nMinimum masking threshold:\n"); for (i = 0; i < sblimit; i++) printf ("%5.1f dB ", ltmin[k][i]); fflush (stdout); }#endif for (i = 0; i < SBLIMIT; i++) spiki[k][i] = spike[k][i]; i = 0; q = sblimit; II_smr (ltmin[k], smr[k], spike[k], scale[k], sblimit, i, q); } mem_free ((void **) &sample); mem_free ((void **) &spike); } /*II_Psycho_One*/void II_Psycho_One_ml ( double (*buffer)[1152], double (*scale)[32], double (*ltmin)[32], frame_params *fr_ps, double (*smr)[32], double (*spiki)[32]){ layer *info = fr_ps->header; int n_ml_ch = info->multiling_ch; int sblimit_ml = fr_ps->sblimit_ml; int k,i, tone=0, noise=0; static char init = 0; static int off[7] = {256, 256, 256, 256, 256, 256, 256}; /* max 7 ML channels */ double *sample; DSBL *spike; static D1408 *fft_buf; static mask_ptr power; static g_ptr ltg_ml; static int crit_band_ml; static int *cbound_ml; static int sub_size_ml; int j, l, z, q; sample = (double *) mem_alloc (sizeof (DFFT), "sample"); spike = (DSBL *) mem_alloc (sizeof (D7SBL), "spike"); if (!init) { /* bands, bark values, and mapping */ fft_buf = (D1408 *) mem_alloc ((long) sizeof (D1408) * 7, "fft_buf"); power = (mask_ptr) mem_alloc (sizeof (mask) * HAN_SIZE, "power"); /* call functions for critical boundaries, freq. */ if (info->multiling_fs == 0) { crit_band_ml = read_crit_band (info->lay, info->sampling_frequency); cbound_ml = (int *) mem_alloc (sizeof (int) * crit_band_ml, "cbound_ml"); read_cbound (info->lay, info->sampling_frequency, crit_band_ml, cbound_ml); read_freq_band (&sub_size_ml, <g_ml, info->lay, info->sampling_frequency); /* values are equal to those for the mc audio data */ } else { crit_band_ml = read_crit_band (info->lay, info->sampling_frequency + 4); cbound_ml = (int *) mem_alloc (sizeof (int) * crit_band_ml, "cbound_ml"); read_cbound (info->lay, info->sampling_frequency + 4, crit_band_ml, cbound_ml); read_freq_band (&sub_size_ml, <g_ml, info->lay, info->sampling_frequency + 4); } make_map (sub_size_ml, power, ltg_ml); for (i = 0; i < 1408; i++) fft_buf[0][i] = fft_buf[1][i] = fft_buf[2][i] = fft_buf[3][i] = fft_buf[4][i] = fft_buf[5][i] = fft_buf[6][i] = 0; init = 1; } if (n_ml_ch > 0) { for (k = 0; k < n_ml_ch; k++) { for (i = 0; i < 1152; i++) fft_buf[k][(i+off[k]) % 1408]= (double) buffer[7+k][i] / SCALE; for (i = 0; i < FFT_SIZE; i++) sample[i] = fft_buf[k][(i+1216+off[k]) % 1408]; off[k] += 1152; off[k] %= 1408; /* call functions for windowing PCM samples,*/ II_hann_win (sample); /* location of spectral components in each */ for (i = 0; i < HAN_SIZE; i++) power[i].x = DBMIN; /* subband with labeling */ II_f_f_t (sample, power); /* locate remaining non- */ II_pick_max (power, spike[k]); /* tonal sinusoidals, */ II_tonal_label (power, &tone); /* reduce noise & tonal components , find */ noise_label (crit_band_ml, cbound_ml, power, &noise, ltg_ml); subsampling (power, ltg_ml, &tone, &noise); /* global & minimal */ threshold (sub_size_ml, power, ltg_ml, &tone, &noise, bitrate[info->lay-1][info->bitrate_index] / 2); /* to-mask ratio */ /* threshold, and sgnl- */ /* fprintf(stderr, "sblimit_ml : %d\n", sblimit_ml); fflush(stderr); */ II_minimum_mask (sub_size_ml, ltg_ml, <min[7+k][0], sblimit_ml); for (i = 0; i < SBLIMIT; i++) spiki[7+k][i] = spike[k][i]; i = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -