📄 encode.c
字号:
/* 3/0 (+2/0) and 2/1 */ putbits (bs, info->dyn_cross[i], 1); if (info->surround == 3) put1bit (bs, info->dyn_second_stereo[i]); } } if (info->mc_prediction_on == 1) { for(i = 0; i < 8; i++) { put1bit (bs, info->mc_pred[i]); if (info->mc_pred[i] == 1) { for (j = 0; j < n_pred_coef[info->dyn_cross[i]]; j++) putbits (bs, info->predsi[i][j], 2); } } }} #ifdef Augmentation_7chvoid encode_info_aug (frame_params *fr_ps, Bit_stream_struc *bs){ int sbgr; layer *info = fr_ps->header; putbits (bs, info->aug_mtx_proc, 2); put1bit (bs, info->aug_dyn_cross_on); put1bit (bs, info->aug_future_ext); if (info->aug_mtx_proc == 0) for (sbgr = 0; sbgr < 12; sbgr++) putbits (bs, info->aug_tc_alloc[sbgr], 3); else if (info->aug_mtx_proc == 1) for (sbgr = 0; sbgr < 12; sbgr++) putbits (bs, info->aug_tc_alloc[sbgr], 2); if (info->aug_dyn_cross_on == 1) for (sbgr = 0; sbgr < 12; sbgr++) putbits (bs, info->aug_dyn_cross[sbgr], 5); }#endifvoid encode_info_ext1 (frame_params *fr_ps, Bit_stream_struc *bs_ext){ layer *info = fr_ps->header; info->ext_sync = 0x7ff; putbits (bs_ext, info->ext_sync, 12); }void encode_info_ext2 (frame_params *fr_ps, Bit_stream_struc *bs_ext, unsigned int crc){ layer *info = fr_ps->header; putbits (bs_ext, crc, 16); putbits (bs_ext, info->ext_length, 11); put1bit (bs_ext, info->ext_bit);}/************************************************************************//*/* mod()/*/* PURPOSE: Returns the absolute value of its argument/*/************************************************************************/ double mod(double a){ return (a > 0) ? a : -a;} /************************************************************************//*/* I_combine_LR (Layer I)/* II_combine_LR (Layer II)/*/* PURPOSE:Combines left and right channels into a mono channel/*/* SEMANTICS: The average of left and right subband samples is put into/* #joint_sample#/*/* Layer I and II differ in frame length and # subbands used/*/************************************************************************/ void I_combine_LR(double (*sb_sample)[3][12][32], double (*joint_sample)[3][12][32]) /*far*/ /*far*/ { /* make a filtered mono for joint stereo */ int sb, smp; for(sb = 0; sb<SBLIMIT; ++sb) for(smp = 0; smp<SCALE_BLOCK; ++smp) joint_sample[0][0][smp][sb] = .5 * (sb_sample[0][0][smp][sb] + sb_sample[1][0][smp][sb]);} void II_combine_LR(double (*sb_sample)[3][12][32], double (*joint_sample)[3][12][32], int sblimit) /*far*/ /*far*/ { /* make a filtered mono for joint stereo */ int sb, smp, sufr; for(sb = 0; sb<sblimit; ++sb) for(smp = 0; smp<SCALE_BLOCK; ++smp) for(sufr = 0; sufr<3; ++sufr) joint_sample[0][sufr][smp][sb] = .5 * (sb_sample[0][sufr][smp][sb] + sb_sample[1][sufr][smp][sb]);}/************************************************************************/*/* I_scale_factor_calc (Layer I)/* II_scale_factor_calc (Layer II)/*/* PURPOSE:For each subband, calculate the scale factor for each set/* of the 12 (6 in case of lsf ML) subband samples/*/* SEMANTICS: Pick the scalefactor #multiple[]# just larger than the/* absolute value of the peak subband sample of 12 samples,/* and store the corresponding scalefactor index in #scalar#./*/* Layer II has three sets of 12 (6 in case of lsf ML) subband samples /* for a given subband./*/************************************************************************/ void I_scale_factor_calc(double (*sb_sample)[3][12][32], unsigned int (*scalar)[3][32], int stereo) /*far*/ { int i,j, k; double s[SBLIMIT]; for (k=0;k<stereo;k++) { for (i=0;i<SBLIMIT;i++) for (j=1, s[i] = mod(sb_sample[k][0][0][i]);j<SCALE_BLOCK;j++) if (mod(sb_sample[k][0][j][i]) > s[i]) s[i] = mod(sb_sample[k][0][j][i]); for (i=0;i<SBLIMIT;i++) for (j=SCALE_RANGE-1,scalar[k][0][i]=0;j>=0;j--) if (s[i] < multiple[j]) { /* <= changed to <, 1992-11-06 shn */ scalar[k][0][i] = j; break; } }}/******************************** Layer II ******************************/ void II_scale_factor_calc (frame_params *fr_ps, double (*sb_sample)[3][12][32], unsigned int (*scalar)[3][32], int sblimit, int l, int m)/* sblimit has the value of sblimit_ml in case II_scale_factor_calc *//* is called in a ML channel , 7/8/95 WtK */{ int i,j, k,t; double s[SBLIMIT]; int leng; leng = SCALE_BLOCK; /* == 12 */ if (l >= 7 && fr_ps->header->multiling_fs == 1) leng /= 2; for (k = l; k < m; k++) for (t = 0; t < 3; t++) { for (i = 0; i < sblimit; i++) for (j = 1, s[i] = mod (sb_sample[k][t][0][i]); j < leng; j++) if (mod (sb_sample[k][t][j][i]) > s[i]) s[i] = mod (sb_sample[k][t][j][i]); for (i = 0; i < sblimit; i++) for (j = SCALE_RANGE - 1, scalar[k][t][i] = 0; j >= 0; j--) if (s[i] < multiple[j]) { /* <= changed to <, 1992-11-06 shn */ scalar[k][t][i] = j; break; } for (i = sblimit; i < SBLIMIT; i++) scalar[k][t][i] = SCALE_RANGE - 1; }} /***************************************************************************/* void II_scale_factor_calc1(sb_sample, scalar, stereo, sblimit)/*/* in case of any joint stereo the scalefactor must be computed/* a second time for the combind samples/*/***************************************************************************/void II_scale_factor_calc1(double (*sb_sample)[3][12][32], unsigned int (*scalar)[3][32], int sblimit, int dim) /*far*/ { int i,j, k,t; double s[SBLIMIT]; for (t=0;t<3;t++) { for (i=0;i<sblimit;i++) for (j=1, s[i] = mod(sb_sample[dim][t][0][i]);j<SCALE_BLOCK;j++) if (mod(sb_sample[dim][t][j][i]) > s[i]) s[i] = mod(sb_sample[dim][t][j][i]); for (i=0;i<sblimit;i++) for (j=SCALE_RANGE-1,scalar[dim][t][i]=0;j>=0;j--) if (s[i] < multiple[j]) { /* <= changed to <, 1992-11-06 shn */ scalar[dim][t][i] = j; break; } for (i=sblimit;i<SBLIMIT;i++) scalar[dim][t][i] = SCALE_RANGE-1; }}/************************************************************************/*/* pick_scale (Layer II)/*/* PURPOSE:For each subband, puts the smallest scalefactor of the 3/* associated with a frame into #max_sc#. This is used/* used by Psychoacoustic Model I./* (I would recommend changin max_sc to min_sc)/*/************************************************************************/ void pick_scale (unsigned int (*scalar)[3][32], frame_params *fr_ps, double (*max_sc)[32], int cha_sw, int aug_cha_sw, int aiff) { int i,j,k,l,m; int max; int stereo = fr_ps->stereo; int stereomc = fr_ps->stereomc; int stereoaug = fr_ps->stereoaug; int sblimit = fr_ps->sblimit; int sblimit_mc = fr_ps->sblimit_mc; int sblimit_ml = fr_ps->sblimit_ml; int n_ml_ch = fr_ps->header->multiling_ch; /* 08/03/1995 JMZ Multilingual */ if (aiff != 1) { l = 0; m = stereo; } else { l = 0; if (stereoaug == 2) m = 12; else m = 7; } for (k = 0; k < stereo; k++) { for (i = 0; i < sblimit; max_sc[k][i] = multiple[max], i++) for (j=1, max = scalar[k][0][i];j<3;j++) if (max > scalar[k][j][i]) max = scalar[k][j][i]; for (i = sblimit; i < SBLIMIT;i++) max_sc[k][i] = 1E-20; } for (k = stereo; k < m; k++) { for (i = 0; i < sblimit_mc; max_sc[k][i] = multiple[max], i++) for (j=1, max = scalar[k][0][i];j<3;j++) if (max > scalar[k][j][i]) max = scalar[k][j][i]; for (i = sblimit_mc; i < SBLIMIT;i++) max_sc[k][i] = 1E-20; } if (aiff == 1) {/* OLD 961114 FdB if (fr_ps->header->matrix == 3 || cha_sw == 0) { fr_ps->header->tc_sbgr_select = 1; for (i = 0; i < 12; i++) fr_ps->header->tc_alloc[i] = 0; } else tc_alloc (fr_ps, max_sc);*/ for (i = 0; i < 12; i++) if (cha_sw == -1 && fr_ps->header->matrix != 3) switch (fr_ps->config) { case 320: if (fr_ps->header->center == 3 && i >= 10) /* tc_alloc = 0,3,4,5 */ { fr_ps->header->tc_alloc[i] = rand () % 4; if (fr_ps->header->tc_alloc[i] > 0) fr_ps->header->tc_alloc[i] += 2; } else fr_ps->header->tc_alloc[i] = rand () % 8; break; case 310: if (fr_ps->header->center == 3 && i >= 10) /* tc_alloc = 0,3,4 */ { fr_ps->header->tc_alloc[i] = rand () % 3; if (fr_ps->header->tc_alloc[i] > 0) fr_ps->header->tc_alloc[i] += 2; } else if (fr_ps->header->matrix == 2) fr_ps->header->tc_alloc[i] = rand () % 6; else fr_ps->header->tc_alloc[i] = rand () % 5; break; case 300: case 302: if (fr_ps->header->center == 3 && i >= 10) /* tc_alloc = 0 */ fr_ps->header->tc_alloc[i] = 0; else fr_ps->header->tc_alloc[i] = rand () % 3; break; case 220: fr_ps->header->tc_alloc[i] = rand () % 4; break; case 210: fr_ps->header->tc_alloc[i] = rand () % 3; break; default: break; } else if (cha_sw == -2 && fr_ps->header->matrix != 3) tc_alloc (fr_ps, max_sc); else if (fr_ps->header->matrix == 3) fr_ps->header->tc_alloc[i] = 0; else fr_ps->header->tc_alloc[i] = cha_sw; fr_ps->header->tc_sbgr_select = 1; fr_ps->header->tc_allocation = fr_ps->header->tc_alloc[0]; for (i = 1; i < 12; i++) if (fr_ps->header->tc_alloc[i] != fr_ps->header->tc_alloc[0]) fr_ps->header->tc_sbgr_select = 0;#ifdef Augmentation_7ch for (i = 0; i < 12; i++) if (aug_cha_sw == -1) switch (fr_ps->header->aug_mtx_proc) { case 0: fr_ps->header->aug_tc_alloc[i] = rand () % 8; break; case 1: fr_ps->header->aug_tc_alloc[i] = rand () % 4; break; case 3: fr_ps->header->aug_tc_alloc[i] = 0; break; } else fr_ps->header->aug_tc_alloc[i] = aug_cha_sw;#endif } /********************************************************//* JMZ 08/03/1995 Multilingual , WtK 07/08/95 */ if (n_ml_ch > 0) { for (k = 7; k < 7 + n_ml_ch; k++) { for (i = 0; i < sblimit_ml; max_sc[k][i] = multiple[max], i++) for (j = 1, max = scalar[k][0][i]; j < 3; j++) if (max > scalar[k][j][i]) max = scalar[k][j][i]; for (i= sblimit_ml; i < SBLIMIT;i++) max_sc[k][i] = 1E-20; } }/* JMZ 08/03/1995 Multilingual *//********************************************************/}/***************************************************************************/*/* tc_alloc (Layer II, multichannel)/*/* PURPOSE: For each subbandgroup the three transmissionchannels are/* determined by taking the channel with the lowest level/* according to the tabel tc_allocation in the draft/* 8/10/93, SR /* /* changed to a certain limit of TC_ALLOC which must be stepped/* beyond, before there is channel-switching/* 9/20/93 SR/* JMZ 08/03/1995 Ajout pour traiter les differentes configurations /* envisagees dans la norme/**************************************************************************/void tc_alloc (frame_params *fr_ps, double (*max_sc)[32]){ layer *info = fr_ps->header; int center = info->center; int surround = info->surround; int matrix = info->matrix; int i, l, k; int min; double min1; double min2[7][12]; /* 01/03/1995 JMZ Configuration 3/2 */ if (surround == 2 && center != 0) { /* if (matrix == 3) ->tc_alloc = 0 else if (center == 3) ->tc_alloc = 0,3,4,5 else ->tc_alloc = 0,1,2,3,4,5,6,7 */ if (matrix == 3) { for (i = 0; i < 12; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -