📄 common.c
字号:
return (1);
}
int dyn_bbal (int config, int center, int dynx, int sbgr)
{
/* 960627 FdB Dyn_ch table dependent on configuration */
if (config == 320)
{
if (center == 3)
return (dyn_bbal4PhC[dynx][sbgr]);
else
return (dyn_bbal4[dynx][sbgr]);
}
else if (config == 310 || config == 220)
{
if (center == 3)
return (dyn_bbal3PhC[dynx][sbgr]);
else
return (dyn_bbal3[dynx][sbgr]);
}
else if (config == 300 || config == 302 || config == 210)
{
if (center == 3)
return (dyn_bbal1PhC[dynx][sbgr]);
else
return (dyn_bbal1[dynx][sbgr]);
}
else
return (0);
}
int dyn_bbal_2ndst (int dynx, int sbgr)
{
return (dyn_bbal4[dynx][sbgr]);
}
#ifdef Augmentation_7ch
int dyn_bbal_aug (int aug_dynx, int sbgr)
{
/* 960627 FdB Dyn_ch table dependent on configuration */
return (dyn_bbal5[aug_dynx][sbgr]);
}
#endif
void init_mc_pred (frame_params *fr_ps)
{
layer *info = fr_ps->header;
int i, j, k;
switch (fr_ps->config)
{
case 320: for (i = 0; i < 16; i++) n_pred_coef[i] = n_pred_coef4[i]; break;
case 310:
case 220: for (i = 0; i < 16; i++) n_pred_coef[i] = n_pred_coef3[i]; break;
case 300:
case 302:
case 210: for (i = 0; i < 16; i++) n_pred_coef[i] = n_pred_coef1[i]; break;
default: for (i = 0; i < 16; i++) n_pred_coef[i] = 0; break;
}
for (i = 0; i < 8; i++)
{
info->mc_pred[i] = 0;
for (j = 0; j < 6; j++)
{
info->delay_comp[i][j] = 0;
info->predsi[i][j] = 0;
for (k = 0; k < 3; k++)
info->pred_coef[i][j][k] = 127;
}
}
}
void set_mc_pred (frame_params *fr_ps)
{
layer *info = fr_ps->header;
int config = fr_ps->config;
int dynx;
int i, j, k, npred;
for (i = 0; i < 8; i++)
{
info->mc_pred[i] = rand () % 2;
if (info->mc_pred[i])
{
dynx = fr_ps->header->dyn_cross[i];
npred = n_pred_coef[dynx];
for (j = 0; j < npred; j++)
{
info->predsi[i][j] = rand () % 4;
if (info->predsi[i][j])
{
info->delay_comp[i][j] = rand () % 8;
for (k = 0; k < info->predsi[i][j]; k++)
info->pred_coef[i][j][k] = rand () % 256;
}
}
}
}
}
/*****************************************************************************
*
* CRC error protection package
*
*****************************************************************************/
void I_CRC_calc (frame_params *fr_ps, unsigned int (*bit_alloc)[32], unsigned int *crc)
{
int i, k;
layer *info = fr_ps->header;
int stereo = fr_ps->stereo;
int jsbound = fr_ps->jsbound;
*crc = 0xffff; /* changed from '0' 92-08-11 shn */
update_CRC(info->bitrate_index, 4, crc);
update_CRC(info->sampling_frequency, 2, crc);
update_CRC(info->padding, 1, crc);
update_CRC(info->extension, 1, crc);
update_CRC(info->mode, 2, crc);
update_CRC(info->mode_ext, 2, crc);
update_CRC(info->copyright, 1, crc);
update_CRC(info->original, 1, crc);
update_CRC(info->emphasis, 2, crc);
for (i=0;i<SBLIMIT;i++)
for (k=0;k<((i<jsbound)?stereo:1);k++)
update_CRC(bit_alloc[k][i], 4, crc);
}
void II_CRC_calc (frame_params *fr_ps, unsigned int (*bit_alloc)[32], unsigned int (*scfsi)[32], unsigned int *crc)
{
int i, k;
layer *info = fr_ps->header;
int stereo = fr_ps->stereo;
int sblimit = fr_ps->sblimit;
int jsbound = fr_ps->jsbound;
al_table *alloc = fr_ps->alloc;
*crc = 0xffff; /* changed from '0' 92-08-11 shn */
update_CRC(info->bitrate_index, 4, crc);
update_CRC(info->sampling_frequency, 2, crc);
update_CRC(info->padding, 1, crc);
update_CRC(info->extension, 1, crc);
update_CRC(info->mode, 2, crc);
update_CRC(info->mode_ext, 2, crc);
update_CRC(info->copyright, 1, crc);
update_CRC(info->original, 1, crc);
update_CRC(info->emphasis, 2, crc);
for (i=0;i<sblimit;i++)
for (k=0;k<((i<jsbound)?stereo:1);k++)
update_CRC(bit_alloc[k][i], (*alloc)[i][0].bits, crc);
for (i=0;i<sblimit;i++)
for (k=0;k<stereo;k++)
if (bit_alloc[k][i])
update_CRC(scfsi[k][i], 2, crc);
}
void II_CRC_calc_mc (frame_params *fr_ps, unsigned int (*bit_alloc)[32], unsigned int lfe_alloc, unsigned int (*scfsi)[32], unsigned int *crc)
{
int i, k, m, l;
layer *info = fr_ps->header;
int nr_tc = fr_ps->stereo + fr_ps->stereomc;
int center = info->center;
int surround = info->surround;
int sblimit = fr_ps->sblimit_mc;
al_table *alloc = fr_ps->alloc_mc;
*crc = 0xffff; /* changed from '0' 92-08-11 shn */
update_CRC(info->ext_bit_stream_present, 1, crc);
if(info->ext_bit_stream_present == 1)
update_CRC(info->n_ad_bytes, 8, crc);
update_CRC(center, 2, crc);
update_CRC(surround, 2, crc);
update_CRC(info->lfe, 1, crc);
update_CRC(info->audio_mix, 1, crc);
update_CRC(info->matrix, 2, crc);
update_CRC(info->multiling_ch, 3, crc);
update_CRC(info->multiling_fs, 1, crc);
update_CRC(info->multiling_lay, 1, crc);
update_CRC(info->copy_ident_bit, 1, crc);
update_CRC(info->copy_ident_start, 1, crc);
update_CRC(info->tc_sbgr_select, 1, crc);
update_CRC(info->dyn_cross_on, 1, crc);
update_CRC(info->mc_prediction_on, 1, crc);
/* 960627 FdB tca bits dependent on configuration */
if ((center == 1 || center == 3) &&
(surround == 1 || surround == 2))
{
/* 3 bits for tca's */
if(info->tc_sbgr_select == 1)
update_CRC(info->tc_allocation, 3, crc);
else
for(i = 0; i < 12; i++)
update_CRC(info->tc_alloc[i], 3, crc);
}
else if (center == 1 || center == 3 || surround == 1 || surround == 2)
{
/* 2 bits for tca's */
if(info->tc_sbgr_select == 1)
update_CRC(info->tc_allocation, 2, crc);
else
for(i = 0; i < 12; i++)
update_CRC(info->tc_alloc[i], 2, crc);
}
if(info->dyn_cross_on == 1)
{
update_CRC(info->dyn_cross_LR, 1, crc);
for(i = 0; i < 12; i++)
{
/* 960627 FdB DynX bits dependent on configuration */
if((center == 1 || center == 3) && surround == 2)
/* 3/2 */
update_CRC(info->dyn_cross[i], 4, crc);
else if(((center == 1 || center == 3) && surround == 1) ||
(center == 0 && surround == 2))
/* 3/1 and 2/2 */
update_CRC(info->dyn_cross[i], 3, crc);
else if(center == 1 || center == 3 || surround == 1)
/* 3/0 (+2/0) and 2/1 */
update_CRC(info->dyn_cross[i], 1, crc);
if(surround == 3)
update_CRC(info->dyn_second_stereo[i], 1, crc);
}
}
if (info->mc_prediction_on == 1)
{
for(i = 0; i < 8; i++)
{
update_CRC (info->mc_pred[i], 1, crc);
if (info->mc_pred[i] == 1)
for (k = 0; k < n_pred_coef[info->dyn_cross[i]]; k ++)
update_CRC (info->predsi[i][k], 2, crc);
}
}
if (fr_ps->header->lfe == 1)
update_CRC (lfe_alloc, (*alloc)[0][0].bits, crc);
for (i = 0; i < sblimit; i++)
{
l = sbgrp[i];
for (m = fr_ps->stereo; m < fr_ps->stereo + fr_ps->stereomc; m++)
{
k = transmission_channel (fr_ps, l, m);
if ((i < 12) || (k != 2) || (fr_ps->header->center != 3))
{
/* 960627 FdB DynX dependent on configuration */
if (dyn_ch (fr_ps, l, m) == 1)
update_CRC (bit_alloc[k][i], (*alloc)[i][0].bits, crc);
}
}
}
for (i = 0; i < sblimit; i++)
{
l = sbgrp[i];
for (m = fr_ps->stereo; m < fr_ps->stereo + fr_ps->stereomc; m++)
{
k = transmission_channel (fr_ps, l, m);
if (bit_alloc[k][i] && (i < 12 || m != 2 || center != 3))
update_CRC (scfsi[k][i], 2, crc);
}
}
}
#ifdef Augmentation_7ch
void II_CRC_calc_aug (frame_params *fr_ps, unsigned int (*bit_alloc)[32], unsigned int (*scfsi)[32], unsigned int *crc)
{
int i, k, m, l;
int aug_future_ext = 0;
layer *info = fr_ps->header;
int sblimit = fr_ps->sblimit_mc;
al_table *alloc = fr_ps->alloc_mc;
*crc = 0xffff; /* changed from '0' 92-08-11 shn */
update_CRC (info->aug_mtx_proc, 2, crc);
update_CRC (info->aug_dyn_cross_on, 1, crc);
update_CRC (aug_future_ext, 1, crc);
/* 960627 FdB aug tca bits dependent on configuration */
if (info->aug_mtx_proc == 0)
for (i = 0; i < 12; i++)
update_CRC (info->aug_tc_alloc[i], 3, crc);
else if (info->aug_mtx_proc == 1)
for (i = 0; i < 12; i++)
update_CRC (info->aug_tc_alloc[i], 2, crc);
if (info->aug_dyn_cross_on == 1)
for (i = 0; i < 12; i++)
update_CRC (info->aug_dyn_cross[i], 5, crc);
for (i = 0; i < sblimit; i++)
{
l = sbgrp[i];
for (m = 5; m < 7; ++m)
{
k = transmission_channel (fr_ps, l, m);
if (dyn_ch (fr_ps, l, m) == 1)
update_CRC (bit_alloc[k][i], (*alloc)[i][0].bits, crc);
}
}
for (i = 0; i < sblimit; i++)
{
l = sbgrp[i];
for (m = 5; m < 7; ++m)
{
k = transmission_channel (fr_ps, l, m);
if (bit_alloc[k][i])
update_CRC (scfsi[k][i], 2, crc);
}
}
}
#endif
void II_CRC_calc_ext (frame_params *fr_ps, unsigned int *z, unsigned int *crc)
{
int i;
layer *info = fr_ps->header;
*crc = 0xffff;
update_CRC (info->ext_length, 11, crc);
update_CRC (info->ext_bit, 1, crc);
for (i = 0; i < 14; i++)
{
update_CRC (z[i], 8, crc);
}
update_CRC (z[14], 4, crc);
}
void update_CRC (unsigned int data, unsigned int length, unsigned int *crc)
{
unsigned int masking, carry;
masking = 1 << length;
while (masking >>= 1)
{
carry = *crc & 0x8000;
*crc <<= 1;
if (!carry ^ !(data & masking))
*crc ^= CRC16_POLYNOMIAL;
}
*crc &= 0xffff;
#ifdef PrintCRCDebug
printf ("crc_len: %2d code: %4x crc: %4x\n", length, data, *crc);
fflush (stdout);
#endif
}
/*****************************************************************************
*
* End of CRC error protection package
*
*****************************************************************************/
#ifdef MACINTOSH
/*****************************************************************************
*
* Set Macintosh file attributes.
*
*****************************************************************************/
void set_mac_file_attr(fileName, vRefNum, creator, fileType)
char fileName[MAX_NAME_SIZE];
short vRefNum;
OsType creator;
OsType fileType;
{
short theFile;
char pascal_fileName[MAX_NAME_SIZE];
FInfo fndrInfo;
CtoPstr(strcpy(pascal_fileName, fileName));
FSOpen(pascal_fileName, vRefNum, &theFile);
GetFInfo(pascal_fileName, vRefNum, &fndrInfo);
fndrInfo.fdCreator = creator;
fndrInfo.fdType = fileType;
SetFInfo(pascal_fileName, vRefNum, &fndrInfo);
FSClose(theFile);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -