📄 misc2.c
字号:
if (is_pos==is_max[sfb+6]) is_pos=IS_ILLEGAL;
a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]);
}
for (i=0;i<window_len;i++) {
stereo_s(l,a,t_reorder[id][sfreq][l],ms_flag,is_pos,header);
l++;
}
}
sfb++;
window_len=t_s[sfb]-t_s[sfb-1];
}
while (l<576) {
int reorder = t_reorder[id][sfreq][l++];
xr[0][0][reorder]=xr[1][0][reorder]=0;
}
} else {
/*
* requantize_ms - short blocks w/stereo processing ********************
*/
int window,window_len;
ms_flag=find_isbound(isbound,gr,info,header);
sfb=0; l=0;
window_len=t_s[0]+1;
while (l<(MAX(non_zero[0],non_zero[1]))) {
for (window=0;window<3;window++) {
subblock_gain[0]=info->subblock_gain[gr][0][window];
subblock_gain[1]=info->subblock_gain[gr][1][window];
scalefac[0]=scalefac_s[gr][0][sfb][window];
scalefac[1]=scalefac_s[gr][1][sfb][window];
if (t_s[sfb] < isbound[window]) {
is_pos=IS_ILLEGAL;
a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]);
a[1]=fras_s(global_gain[1],subblock_gain[1],scalefac_scale[1],scalefac[1]);
} else {
is_pos=scalefac[1];
if (id==1) /* MPEG1 */
if (is_pos==7) is_pos=IS_ILLEGAL;
else /* MPEG2 */
if (is_pos==is_max[sfb+6]) is_pos=IS_ILLEGAL;
a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]);
}
for (i=0;i<window_len;i++) {
stereo_s(l,a,t_reorder[id][sfreq][l],ms_flag,is_pos,header);
l++;
}
}
/* this won't do anymore
* window_len=-t_s[sfb]+t_s[++sfb];
*/
window_len = -t_s[sfb++];
window_len += t_s[sfb];
}
while (l<576) {
int reorder = t_reorder[id][sfreq][l++];
xr[0][0][reorder]=xr[1][0][reorder]=0;
}
}
else {
/*
* long blocks w/stereo processing *************************************
*/
int *preflag=info->preflag[gr];
ms_flag=find_isbound(isbound,gr,info,header);
sfb=0; l=0;
scalefac[0]=scalefac_l[gr][0][sfb];
a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]);
scalefac[1]=scalefac_l[gr][1][sfb];
a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]);
/* no intensity stereo part
*/
if (ms_flag)
while (l< isbound[0]) {
#if defined(PENTIUM_RDTSC)
unsigned int cnt4, cnt3, cnt2, cnt1;
static int min_cycles = 99999999;
__asm__(".byte 0x0f,0x31" : "=a" (cnt1), "=d" (cnt4));
#endif
{
register float Mi = fras2(is[0][l],a[0]);
register float Si = fras2(is[1][l],a[1]);
register float tmp = i_sq2;
xr[0][0][l]=(Mi+Si)*tmp;
xr[1][0][l]=(Mi-Si)*tmp;
}
#if defined(PENTIUM_RDTSC)
__asm__(".byte 0x0f,0x31" : "=a" (cnt2), "=d" (cnt4));
if (cnt2-cnt1 < min_cycles) {
min_cycles = cnt2-cnt1;
printf("%d cycles\n", min_cycles);
}
#endif
if (l==t_l[sfb]) {
#if defined(PENTIUM_RDTSC2)
unsigned int cnt4, cnt2, cnt1;
static int min_cycles = 99999999;
__asm__(".byte 0x0f,0x31" : "=a" (cnt1), "=d" (cnt4));
#endif
sfb++;
scalefac[0]=scalefac_l[gr][0][sfb];
a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]);
scalefac[1]=scalefac_l[gr][1][sfb];
a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]);
#if defined(PENTIUM_RDTSC2)
__asm__(".byte 0x0f,0x31" : "=a" (cnt2), "=d" (cnt4));
if (cnt2-cnt1 < min_cycles) {
min_cycles = cnt2-cnt1;
printf("%d cycles, sfb %d\n", min_cycles, sfb);
}
#endif
}
l++;
}
else
while (l< isbound[0]) {
xr[0][0][l]=fras2(is[0][l],a[0]);
xr[1][0][l]=fras2(is[1][l],a[1]);
if (l==t_l[sfb]) {
sfb++;
scalefac[0]=scalefac_l[gr][0][sfb];
a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]);
scalefac[1]=scalefac_l[gr][1][sfb];
a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]);
}
l++;
}
/* intensity stereo part
*/
while (l<(MAX(non_zero[0],non_zero[1]))) {
int is_pos=scalefac[1];
if (id==1) /* MPEG1 */
if (is_pos==7) is_pos=IS_ILLEGAL;
else /* MPEG2 */
if (is_pos==is_max[sfb]) is_pos=IS_ILLEGAL;
stereo_l(l,a,ms_flag,is_pos,header);
if (l==t_l[sfb]) {
sfb++;
scalefac[0]=scalefac_l[gr][0][sfb];
scalefac[1]=scalefac_l[gr][1][sfb];
a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]);
}
l++;
}
while (l<576) {
xr[0][0][l]=0;
xr[1][0][l]=0;
l++;
}
}
}
/*
* requantize_downmix **********************************************************
*/
void requantize_downmix(int gr,struct SIDE_INFO *info,struct AUDIO_HEADER *header)
{
int l,sfb,ms_flag,is_pos,i,ch;
int *global_gain,subblock_gain[2],*scalefac_scale,scalefac[2],isbound[3];
int sfreq=header->sampling_frequency;
int id = header->ID;
float a[2];
/* first set some variables
*/
global_gain=info->global_gain[gr];
scalefac_scale=info->scalefac_scale[gr];
if (header->mode_extension==2 || header->mode_extension==3) ms_flag=1;
else ms_flag=0;
/* ... and then we're off for requantization
*/
if (info->window_switching_flag[gr][0] && info->block_type[gr][0]==2)
if (info->mixed_block_flag[gr][0]) {
die("mixed block? hmmmm...., downmix for mixed blocks is not yet implemented\n");
} else {
int window,window_len;
int isbound[3];
int is_pos;
int dummy=find_isbound(isbound,gr,info,header); /* ugly hack, part3 */
sfb=0; l=0; window_len=t_s[0]+1;
while (l<(MAX(non_zero[0],non_zero[1]))) {
for (window=0;window<3;window++) {
subblock_gain[0]=info->subblock_gain[gr][0][window];
subblock_gain[1]=info->subblock_gain[gr][1][window];
scalefac[0]=scalefac_s[gr][0][sfb][window];
is_pos=scalefac[1]=scalefac_s[gr][1][sfb][window];
if (t_s[sfb] < isbound[window]) {
a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]);
if (ms_flag) {
for (i=0;i<window_len;i++) {
register float Mi=fras2(is[0][l],a[0]);
register float tmp = i_sq2;
xr[0][0][t_reorder[id][sfreq][l]]=Mi*i_sq2;
l++;
}
} else {
a[1]=fras_s(global_gain[1],subblock_gain[1],scalefac_scale[1],scalefac[1]);
for (i=0;i<window_len;i++) {
register float tmp1=fras2(is[0][l],a[0]);
register float tmp2=fras2(is[1][l],a[1]);
xr[0][0][t_reorder[id][sfreq][l]]=(tmp1+tmp2)*0.5f;
l++;
}
}
} else {
a[0]=fras_s(global_gain[0],subblock_gain[0],scalefac_scale[0],scalefac[0]);
for (i=0;i<window_len;i++) {
register float ftmp = fras2(is[0][l], a[0]);
if (id==0 && is_pos<is_max[sfb])
ftmp*=t_downmix[intensity_scale][(is_pos+1)>>1];
xr[0][0][t_reorder[id][sfreq][l]] = ftmp;
l++;
}
}
}
window_len = -t_s[sfb++];
window_len += t_s[sfb];
}
while (l<576) {
xr[0][0][l]=0;
l++;
}
}
else {
int *preflag=info->preflag[gr];
int isbound;
if (header->mode_extension==1 || header->mode_extension==3) {
int tmp=non_zero[1];
while (is[1][tmp] == 0) tmp--;
sfb=0; while (t_l[sfb] < tmp && sfb < 21) sfb++;
isbound=t_l[sfb]+1;
no_of_imdcts[0]=no_of_imdcts[1]=(non_zero[0]-1)/18+1;
} else {
isbound=(MAX(non_zero[0],non_zero[1]));
no_of_imdcts[0]=no_of_imdcts[1]=(isbound-1)/18+1;
}
sfb=0; l=0;
scalefac[0]=scalefac_l[gr][0][sfb];
a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]);
scalefac[1]=scalefac_l[gr][1][sfb];
a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]);
/* no intensity stereo part
*/
if (ms_flag)
while (l < isbound) {
register float Mi = fras2(is[0][l],a[0]);
register float tmp = i_sq2;
xr[0][0][l]=Mi*tmp;
if (l==t_l[sfb]) {
sfb++;
scalefac[0]=scalefac_l[gr][0][sfb];
a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]);
scalefac[1]=scalefac_l[gr][1][sfb];
}
l++;
}
else
while (l < isbound) {
register float tmp1=fras2(is[0][l],a[0]);
register float tmp2=fras2(is[1][l],a[1]);
xr[0][0][l]=(tmp1+tmp2)*0.5f;
if (l==t_l[sfb]) {
sfb++;
scalefac[0]=scalefac_l[gr][0][sfb];
a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]);
scalefac[1]=scalefac_l[gr][1][sfb];
a[1]=fras_l(sfb,global_gain[1],scalefac_scale[1],scalefac[1],preflag[1]);
}
l++;
}
/* intensity stereo part
*/
while (l<(MAX(non_zero[0],non_zero[1]))) {
int is_pos=scalefac[1];
register float ftmp=fras2(is[0][l], a[0]);
if (id==0 && is_pos<is_max[sfb]) {
ftmp*=t_downmix[intensity_scale][(is_pos+1)>>1];
}
xr[0][0][l] = ftmp;
if (l==t_l[sfb]) {
sfb++;
scalefac[0]=scalefac_l[gr][0][sfb];
a[0]=fras_l(sfb,global_gain[0],scalefac_scale[0],scalefac[0],preflag[0]);
scalefac[1]=scalefac_l[gr][1][sfb];
}
l++;
}
/* _always_ zero out everything else
*/
while (l<576) {
xr[0][0][l]=0;
l++;
}
}
}
/*
* antialiasing butterflies ****************************************************
*
*/
void alias_reduction(int ch)
{
unsigned int sb;
for (sb=1;sb<32;sb++) {
float *x = xr[ch][sb];
register float a, b;
a = x[0];
b = x[-1];
x[-1] = b * Cs[0] - a * Ca[0];
x[0] = a * Cs[0] + b * Ca[0];
a = x[1];
b = x[-2];
x[-2] = b * Cs[1] - a * Ca[1];
x[1] = a * Cs[1] + b * Ca[1];
a = x[2];
b = x[-3];
x[-3] = b * Cs[2] - a * Ca[2];
x[2] = a * Cs[2] + b * Ca[2];
a = x[3];
b = x[-4];
x[-4] = b * Cs[3] - a * Ca[3];
x[3] = a * Cs[3] + b * Ca[3];
a = x[4];
b = x[-5];
x[-5] = b * Cs[4] - a * Ca[4];
x[4] = a * Cs[4] + b * Ca[4];
a = x[5];
b = x[-6];
x[-6] = b * Cs[5] - a * Ca[5];
x[5] = a * Cs[5] + b * Ca[5];
a = x[6];
b = x[-7];
x[-7] = b * Cs[6] - a * Ca[6];
x[6] = a * Cs[6] + b * Ca[6];
a = x[7];
b = x[-8];
x[-8] = b * Cs[7] - a * Ca[7];
x[7] = a * Cs[7] + b * Ca[7];
}
}
/* calculating t_43 instead of having that big table in misc2.h
*/
void calculate_t43(void)
{
int i;
for (i=0;i<8192;i++)
t_43[i]=(float)pow((float)i,1.33333333333f);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -