📄 encode.c
字号:
#endif */ return (samples_read);}/*************************************************************************/*/* matricing()/*/* The five-channel signal must be matricied to guarantee/* the compatibility to the stereo-decoder./* There must be something of the surround information in the/* two front channels. In a five-channel decoder there will/* be a dematricing./* There must be 7 channels for channel switching 8/10/93, SR/* /* Channel 5 and 6 are the not matriced signals L and R/*/* If phantom coding is used the high-frequency part of the/* center signal is matrixed to left and right./* 27/07/95 WtK/* *//***************************************************************************/void normalizing (double (*sb_sample)[3][12][32], frame_params *fr_ps){ double matrNorm; /* factor for normalizing JMZ */ double matrC; /* weighting factor for C, Phantom C */ double matrLsRs; /* weighting factor for Ls, Rs */ int stereo = fr_ps->stereo; int i, j, k, l; layer *info = fr_ps->header; switch (info->matrix) { /* Changed the factors according to International Standard */ case 0: case 2: matrNorm = 1 / (1 + sqrt(2.0)); matrC = 1 / sqrt(2.0); matrLsRs = 1 / sqrt(2.0); break; case 1: matrNorm = 1 / (1.5 + 0.5*sqrt(2.0)); matrC = 1 / sqrt(2.0); matrLsRs = 0.5; break; case 3: matrNorm = 1; matrC = 1; matrLsRs = 1; break; } for (i = 0; i < stereo; i++) for (j = 0; j < 3; j++) for (l = 0; l < 12; l++) for (k = 0; k < SBLIMIT; k ++) sb_sample[i][j][l][k] *= matrNorm; for (j = 0; j < 3; ++j) for (l = 0; l < 12; l ++) for (k = 0; k < SBLIMIT; k ++) if (fr_ps->config == 320) { sb_sample[2][j][l][k] = sb_sample[2][j][l][k] * matrNorm * matrC; sb_sample[3][j][l][k] = sb_sample[3][j][l][k] * matrNorm * matrLsRs; sb_sample[4][j][l][k] = sb_sample[4][j][l][k] * matrNorm * matrLsRs; } else if (fr_ps->config == 310) { sb_sample[2][j][l][k] = sb_sample[2][j][l][k] * matrNorm * matrC; sb_sample[3][j][l][k] = sb_sample[3][j][l][k] * matrNorm * matrLsRs; } else if (fr_ps->config == 220) { sb_sample[2][j][l][k] = sb_sample[2][j][l][k] * matrNorm * matrLsRs; sb_sample[3][j][l][k] = sb_sample[3][j][l][k] * matrNorm * matrLsRs; } else if (fr_ps->config == 300 || fr_ps->config == 302) sb_sample[2][j][l][k] = sb_sample[2][j][l][k] * matrNorm * matrC; else if (fr_ps->config == 210) sb_sample[2][j][l][k] = sb_sample[2][j][l][k] * matrNorm * matrLsRs;}void matricing (double (*sb_sample)[3][12][32], frame_params *fr_ps){ double matrPC; /* weighting factor for Phantom C */ double mono_surround; register double val; int i, j, k, l; layer *info = fr_ps->header; switch (info->matrix) { /* Changed the factors according to International Standard */ case 0: case 1: case 2: matrPC = 1; break; case 3: matrPC = 1 / sqrt(2.0); break; } for (j = 0; j < 3; ++j) { for (l = 0; l < 12; l ++) { for (k = 0; k < SBLIMIT; k ++) { sb_sample[5][j][l][k] = sb_sample[0][j][l][k]; sb_sample[6][j][l][k] = sb_sample[1][j][l][k]; if (fr_ps->config == 320) { /* 960819 FdB changed matricing */ if (info->matrix == 0 || info->matrix == 1) { sb_sample[0][j][l][k] = sb_sample[5][j][l][k] + sb_sample[2][j][l][k] + sb_sample[3][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k] + sb_sample[2][j][l][k] + sb_sample[4][j][l][k]; } else if (info->matrix == 2) { mono_surround = (sb_sample[3][j][l][k] + sb_sample[4][j][l][k]) / 2.0; sb_sample[0][j][l][k] = sb_sample[5][j][l][k] + sb_sample[2][j][l][k] - mono_surround; sb_sample[1][j][l][k] = sb_sample[6][j][l][k] + sb_sample[2][j][l][k] + mono_surround; } else { sb_sample[0][j][l][k] = sb_sample[5][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k]; } } else if (fr_ps->config == 310) { /* 960819 FdB changed matricing */ if (info->matrix == 0 || info->matrix == 1) { sb_sample[0][j][l][k] = sb_sample[5][j][l][k] + sb_sample[2][j][l][k] + sb_sample[3][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k] + sb_sample[2][j][l][k] + sb_sample[3][j][l][k]; } else if (info->matrix == 2) { sb_sample[0][j][l][k] = sb_sample[5][j][l][k] + sb_sample[2][j][l][k] - sb_sample[3][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k] + sb_sample[2][j][l][k] + sb_sample[3][j][l][k]; } else { sb_sample[0][j][l][k] = sb_sample[5][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k]; } } else if (fr_ps->config == 220) { /* 960819 FdB changed matricing */ if (info->matrix == 0 || info->matrix == 1) { sb_sample[0][j][l][k] = sb_sample[5][j][l][k] + sb_sample[2][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k] + sb_sample[3][j][l][k]; } else if (info->matrix == 3) { sb_sample[0][j][l][k] = sb_sample[5][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k]; } } else if (fr_ps->config == 300 || fr_ps->config == 302) { /* 960819 FdB changed matricing */ if (info->matrix == 0 || info->matrix == 1) { sb_sample[0][j][l][k] = sb_sample[5][j][l][k] + sb_sample[2][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k] + sb_sample[2][j][l][k]; } else if (info->matrix == 3) { sb_sample[0][j][l][k] = sb_sample[5][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k]; } } else if (fr_ps->config == 210) { /* 960819 FdB changed matricing */ if (info->matrix == 0 || info->matrix == 1) { sb_sample[0][j][l][k] = sb_sample[5][j][l][k] + sb_sample[2][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k] + sb_sample[2][j][l][k]; } else if (info->matrix == 3) { sb_sample[0][j][l][k] = sb_sample[5][j][l][k]; sb_sample[1][j][l][k] = sb_sample[6][j][l][k]; } } } if (info->center == 3) /* 27/07/95 WtK */ { if (info->matrix==3) for (k = 12; k < SBLIMIT; k ++) { val = matrPC * sb_sample[2][j][l][k]; sb_sample[0][j][l][k] += val; sb_sample[1][j][l][k] += val; sb_sample[2][j][l][k] = 0; } else for (k = 12; k < SBLIMIT; k ++) { val = matrPC * sb_sample[2][j][l][k]; sb_sample[5][j][l][k] += val; sb_sample[6][j][l][k] += val; sb_sample[2][j][l][k] = 0; } } } }}#ifdef Augmentation_7chvoid normalizing_aug (double (*sb_sample)[3][12][32], frame_params *fr_ps){ double norm; /* factor for normalizing JMZ */ double c[7]; int i, j, k, l; layer *info = fr_ps->header; for (i = 0; i < 7; i++) c[i] = 1.0; switch (info->matrix) { /* factors according to International Standard */ case 0: case 2: c[2] = c[3] = c[4] = 1.0 / sqrt (2.0); /* weigh factor for C, Ls and Rs */ break; case 1: c[2] = 1.0 / sqrt (2.0); /* weigh factor for C */ c[3] = c[4] = 0.5; /* weigh factor for Ls, Rs */ break; } if (info->aug_mtx_proc == 0) /* factors according to 7-ch augmentation */ /* unweigh factor for LC, RC */ c[5] = c[6] = 0.75; /* normalization factor */ switch (info->matrix * 10 + info->aug_mtx_proc) { case 00: case 20: norm = 1.0 / (1.75 + 1.25 * sqrt (2.0)); break; case 10: norm = 1.0 / (2.25 + 0.75 * sqrt (2.0)); break; case 30: norm = 1.0 / 1.75; break; case 01: case 21: norm = 1.0 / (2.0 + sqrt (2.0)); break; case 11: norm = 1.0 / (2.5 + 0.5 * sqrt (2.0)); break; case 31: norm = 0.5; break; case 03: case 23: norm = 1.0 / (1.0 + sqrt (2.0)); break; case 13: norm = 1.0 / (1.5 + 0.5 * sqrt (2.0)); break; case 33: norm = 1.0; break; } for (i = 0; i < 7; i++) c[i] *= norm; /* normalizing */ for (i = 0; i < 7; i++) for (j = 0; j < 3; j++) for (k = 0; k < 12; k++) for (l = 0; l < SBLIMIT; l++) sb_sample[i][j][k][l] *= c[i];}void matricing_aug (double (*sb_sample)[3][12][32], frame_params *fr_ps){ int i, j, k, l; layer *info = fr_ps->header; for (j = 0; j < 3; ++j) for (l = 0; l < 12; l ++) for (k = 0; k < SBLIMIT; k ++) { /* copy L7, R7, C7, Lc and Rc to sb_sample[7 .. 11] */ sb_sample[11][j][l][k] = sb_sample[6][j][l][k]; sb_sample[10][j][l][k] = sb_sample[5][j][l][k]; sb_sample[ 9][j][l][k] = sb_sample[2][j][l][k]; sb_sample[ 8][j][l][k] = sb_sample[1][j][l][k]; sb_sample[ 7][j][l][k] = sb_sample[0][j][l][k]; /* 960819 FdB changed matricing */ if (info->aug_mtx_proc == 0 || info->aug_mtx_proc == 1) { sb_sample[0][j][l][k] += sb_sample[5][j][l][k]; sb_sample[1][j][l][k] += sb_sample[6][j][l][k]; } if (info->aug_mtx_proc == 0) sb_sample[2][j][l][k] += (sb_sample[5][j][l][k] + sb_sample[6][j][l][k]) / 3; }}#endif/*************************************************************************/*/* matricing_fft()/*/* To get the best results in psychoacoustics there must be both,/* the matriced and the not matriced signal. This matricing/* may be in full bandwith. * * If LFE is not enabled, "buffer" contains: * buffer[0] L * buffer[1] R * buffer[2] C * buffer[3] Ls * buffer[4] Rs * * If LFE is enabled, "buffer" contains: * buffer[0] L * buffer[1] R * buffer[2] C * buffer[3] LFE * buffer[4] Ls * buffer[5] Rs * * This function matrixes the original audio samples to pass to the * psychoacoustic model. The model considers the matrixed and non- * matrixed versions of the signal, so both are retained here. * * On exit, buffer_matr[0] to buffer_matr[6] contain the channels * Lo, Ro, C, Ls, Rs, L, R, respectively. * **************************************************************************/void matricing_fft (double (*buffer)[1152], double (*buffer_matr)[1152], frame_params *fr_ps){ double matrNorm; /* factor for normalizing JMZ */ double matrC; /* weighting factor for C */ double matrLsRs; /* weighting factor for Ls, Rs */ double mono_surround; int i, j, k, l; int lfe, lfe_pos; double dummy; layer *info = fr_ps->header; lfe = info->lfe; lfe_pos = fr_ps->lfe_pos; switch(info->matrix) { case 0: case 2: matrNorm = 1 / (1 + sqrt(2.0)); matrC = 1 / sqrt(2.0); matrLsRs = 1 / sqrt(2.0); break; case 1: matrNorm = 1 / (1.5 + 0.5*sqrt(2.0)); matrC = 1 / sqrt(2.0); matrLsRs = 0.5; break; case 3: matrNorm = 1; matrC = 1; matrLsRs = 1; break; } for (i = 0; i < 1152; i++) { if (lfe && lfe_pos < 3) buffer_matr[2][i] = buffer[3][i]; else buffer_matr[2][i] = buffer[2][i]; buffer_matr[3][i] = buffer[3+lfe][i]; buffer_matr[4][i] = buffer[4+lfe][i]; buffer_matr[5][i] = buffer[0][i]; buffer_matr[6][i] = buffer[1][i]; switch (info->matrix) { case 0: case 1: buffer_matr[0][i] = matrNorm*(buffer[0][i] + matrC*buffer_matr[2][i] + matrLsRs*buffer_matr[3][i]); buffer_matr[1][i] = matrNorm*(buffer[1][i] + matrC*buffer_matr[2][i] + matrLsRs*buffer_matr[4][i]); break; case 2: mono_surround = (buffer_matr[3][i] + buffer_matr[4][i]) / 2.0; buffer_matr[0][i] = matrNorm*(buffer[0][i] + matrC*buffer_matr[2][i] - matrLsRs * mono_surround); buffer_matr[1][i] = matrNorm*(buffer[1][i] + matrC*buffer_matr[2][i] + matrLsRs * mono_surround); break; case 3: buffer_matr[0][i] = buffer[0][i]; buffer_matr[1][i] = buffer[1][i]; break; } }}#ifdef Augmentation_7ch/*************************************************************************/*/* matricing_aug_fft()/*/* To get the best results in psychoacoustics there must be both,/* the matriced and the not matriced signal. This matricing/* may be in full bandwith. * * If LFE is not enabled, "buffer" contains: * buffer[0] L * buffer[1] R * buffer[2] C * buffer[3] Ls * buffer[4] Rs * buffer[5] Lc * buffer[6] Rc * * If LFE is enabled, "buffer" contains: * buffer[0] L * buffer[1] R * buffer[2] C * buffer[3] LFE * buffer[4] Ls * buffer[5] Rs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -