📄 mp3enc_quantization_12_fp.c
字号:
case 0x444 : si[k][i] = 2;
if (sf[k][0][i] > sf[k][2][i])
sf[k][0][i] = sf[k][2][i];
sf[k][1][i] = sf[k][2][i] = sf[k][0][i];
}
}
}
static Ipp32s mp3enc_bits_js_l2(MP3Enc *state)
{
Ipp32s i, sb, ch, ba;
Ipp16u (*scfsi)[32] = state->com.scfsi;
Ipp32f (*smr)[32] = state->pa_snr;
Ipp32s stereo = state->com.stereo;
Ipp32s sblimit = state->com.sblimit;
Ipp32s sblimit_real = state->com.sblimit_real;
Ipp32s jsbound = state->com.jsbound;
Ipp32s req_bits = 0, bbal = 0, berr = 16, banc = 32;
Ipp32s maxAlloc, sel_bits, sc_bits, smp_bits;
Ipp32s *nbal_alloc_table = state->com.nbal_alloc_table;
Ipp8u *alloc_table = state->com.alloc_table;
for(i = 0; i < jsbound; i++)
bbal += nbal_alloc_table[i] << (stereo - 1);
for(i = jsbound; i < sblimit; i++)
bbal += nbal_alloc_table[i];
req_bits = banc + bbal + berr;
for(sb = 0; sb < sblimit_real; sb++)
for(ch = 0; ch < ((sb < jsbound) ? stereo : 1); ch++) {
maxAlloc = (1 << nbal_alloc_table[sb]) - 1;
sel_bits = sc_bits = smp_bits = 0;
for(ba = 0; ba < maxAlloc - 1; ba++)
if(mpa_tab_snr_l2[alloc_table[sb * 16 + ba] + ((ba > 0) ? 1 : 0)] >= smr[ch][sb])
break;
if(stereo == 2 && sb >= jsbound)
for(; ba < maxAlloc - 1; ba++)
if(mpa_tab_snr_l2[alloc_table[sb * 16 + ba] + ((ba > 0) ? 1 : 0)] >= smr[1 - ch][sb])
break;
if(ba > 0) {
Ipp32s nb = mp3_cls_quant[alloc_table[sb * 16 + ba]];
smp_bits = (nb < 0) ? -12 * nb : 36 * nb;
sel_bits = 2;
sc_bits = 6 * mp3enc_sfs_per_scfsi[scfsi[ch][sb]];
if(stereo == 2 && sb >= jsbound) {
sel_bits += 2;
sc_bits += 6 * mp3enc_sfs_per_scfsi[scfsi[1-ch][sb]];
}
req_bits += smp_bits + sel_bits + sc_bits;
}
}
return req_bits;
}
static void mp3enc_bit_allocation_l2(MP3Enc *state)
{
VM_ALIGN16_DECL(Ipp32f) mnr[NUM_CHANNELS][32];
VM_ALIGN16_DECL(Ipp8u) used[NUM_CHANNELS][32];
Ipp16u (*scfsi)[32] = state->com.scfsi;
Ipp32f (*smr)[32] = state->pa_snr;
Ipp16s (*allocation)[32] = state->com.allocation;
Ipp32f smal;
Ipp32s adb = (state->com.slot_size << 3);
Ipp32s i, min_ch, min_sb, oth_ch, k, kk, increment, scale, seli, ba, tb;
Ipp32s bspl, bscf, bsel, bbal;
Ipp32s stereo = state->com.stereo;
Ipp32s mc_channel = state->com.mc_channel;
Ipp32s mc_sblimit = state->com.mc_sblimit;
Ipp32s mc_channel_conf = state->com.mc_channel_conf;
Ipp32s sblimit = state->com.sblimit;
Ipp32s sblimit_real = state->com.sblimit_real;
Ipp32s jsbound = state->com.jsbound;
Ipp32s len = stereo << 5;
Ipp32s mc_len = mc_channel << 5;
Ipp32s mode, mode_ext;
Ipp32s rq_db;
Ipp32s banc = 32+16;
Ipp32s berr = 16;
Ipp32s *nbal_alloc_table = state->com.nbal_alloc_table;
Ipp8u *alloc_table = state->com.alloc_table;
if (mc_channel) {
berr += 16;
banc += 16+3;
}
if (state->com.mc_header.lfe) {
banc += 70;
}
mode = MPA_LR_STEREO;
if(state->com.stereo_mode_param == MPA_JOINT_STEREO) {
mode_ext = 0;
jsbound = sblimit;
if((rq_db = mp3enc_bits_js_l2(state)) > adb) {
mode = MPA_JOINT_STEREO;
mode_ext = 4;
do {
mode_ext--;
jsbound = 4 + mode_ext * 4;
state->com.jsbound = jsbound;
rq_db = mp3enc_bits_js_l2(state);
} while( (rq_db > adb) && (mode_ext > 0));
state->com.jsbound = jsbound;
state->com.stereo_mode_ext = mode_ext;
}
}
state->com.stereo_mode = mode;
bbal = 0;
for(i = 0; i < jsbound; i++)
bbal += nbal_alloc_table[i] << (stereo - 1);
for(i = jsbound; i < sblimit; i++)
bbal += nbal_alloc_table[i];
if (mc_channel) {
for(i = 0; i < mc_sblimit; i++)
bbal += nbal_alloc_table[i] * mc_channel;
if (mc_channel_conf == 320)
tb = 3;
else if (mc_channel_conf == 310)
tb = 3;
else if (mc_channel_conf== 220)
tb = 2;
else if (mc_channel_conf == 300 || mc_channel_conf == 302 || mc_channel_conf == 210)
tb = 2;
else
tb = 0;
if (state->com.mc_tc_sbgr_select == 0)
bbal += 12 * tb;
else
bbal += tb;
}
adb -= bbal + berr + banc;
ippsSubCRev_32f(&smr[0][0], mpa_tab_snr_l2[0], &mnr[0][0], len + mc_len);
ippsZero_16s(&allocation[0][0], len + mc_len);
ippsZero_8u(&used[0][0], len + mc_len);
bspl = bscf = bsel = 0;
do {
smal = mnr[0][0] + 1;
min_sb = -1;
min_ch = -1;
for(k = 0; k < stereo + mc_channel; k++) {
for(i = 0; i < sblimit_real; i++) {
kk = mp3enc_mc_trans_channel (&state->com, mp3_mc_sb_group[i], k);
if ((i >= 12) && (state->com.mc_header.center == 3) && (kk == 2))
used[kk][i] = 2;
if (used[kk][i] != 2 && smal > mnr[kk][i]) {
smal = mnr[kk][i];
min_sb = i;
min_ch = kk;
}
}
}
if(min_sb > -1) {
Ipp32s nba = allocation[min_ch][min_sb];
Ipp32s nb1 = mp3_cls_quant[alloc_table[(min_sb << 4) + nba + 1]];
Ipp32s nb0 = mp3_cls_quant[alloc_table[(min_sb << 4) + nba]];
increment = (nb1 < 0) ? (-12 * nb1) : (36 * nb1);
if (used[min_ch][min_sb])
increment -= (nb0 < 0) ? (-12 * nb0): (36 * nb0);
oth_ch = 1 - min_ch;
if (used[min_ch][min_sb]) scale = seli = 0;
else {
seli = 2;
scale = 6 * mp3enc_sfs_per_scfsi[scfsi[min_ch][min_sb]];
if(stereo == 2 && min_sb >= jsbound) {
seli += 2;
scale += 6 * mp3enc_sfs_per_scfsi[scfsi[oth_ch][min_sb]];
}
}
if (adb >= bspl + bscf + bsel + seli + scale + increment) {
ba = ++allocation[min_ch][min_sb];
bspl += increment;
bscf += scale;
bsel += seli;
used[min_ch][min_sb] = 1;
mnr[min_ch][min_sb] = mpa_tab_snr_l2[alloc_table[min_sb * 16 + ba] + 1] -
smr[min_ch][min_sb];
if (ba >= (1 << nbal_alloc_table[min_sb]) - 1)
used[min_ch][min_sb] = 2;
}
else
used[min_ch][min_sb] = 2;
if(min_sb >= jsbound && stereo == 2) {
ba = allocation[oth_ch][min_sb] = allocation[min_ch][min_sb];
used[oth_ch][min_sb] = used[min_ch][min_sb];
mnr[oth_ch][min_sb] = mpa_tab_snr_l2[alloc_table[min_sb * 16 + ba] + 1] -
smr[oth_ch][min_sb];
}
}
} while(min_sb > -1);
}
static void mp3enc_subband_quantization_l2(MP3Enc *state)
{
VM_ALIGN16_DECL(Ipp32f) fbout[36];
Ipp32s i, j, k, kk, s, n, qnt, bal, xor_coef, ind;
Ipp32s stereo = state->com.stereo;
Ipp32s sblimit = state->com.sblimit;
Ipp32s jsbound = state->com.jsbound;
Ipp32f d, fxor_coef, rscale;
Ipp16s (*sf)[3][32] = state->com.scalefactor;
Ipp16s (*allocation)[32] = state->com.allocation;
for (k = 0; k < stereo + state->com.mc_channel; k++) {
Ipp32s limit;
if (k == 1)
limit = IPP_MIN(jsbound, sblimit);
else
limit = sblimit;
for (i = 0; i < limit; i++)
if ((bal = allocation[k][i]) != 0) {
qnt = state->com.alloc_table[i * 16 + bal];
n = mp3_numbits[qnt] - 1;
xor_coef = 1 << n;
fxor_coef = (Ipp32f)xor_coef;
kk = k;
if (k == 0 && i >= jsbound)
kk = 2;
ind = 0;
for (s = 0; s < 3; s++) {
for (j = 0; j < 12; j++) {
fbout[ind++] = state->fbout_data[kk][0][s * 12 + j][i];
}
}
ind = 0;
for (s = 0; s < 3; s++) {
rscale = mp3_rscale_values[sf[kk][s][i]] * mpa_tab_a_l2[qnt];
ippsMulC_32f_I(rscale, fbout + ind, 12);
ippsAddC_32f_I(mpa_tab_b_l2[qnt], fbout + ind, 12);
ind += 12;
}
for (j = 0; j < 36; j++) {
d = fbout[j];
if (d >= 0) {
state->com.sample[k][i][j] = (Ipp32s)(d * fxor_coef) | xor_coef;
} else {
state->com.sample[k][i][j] = (Ipp32s)((d + 1.0f) * fxor_coef);
}
}
}
}
}
static void mp3enc_lfe_quantization_l2(MP3Enc *state)
{
Ipp32s j, n, qnt, xor_coef;
Ipp32f d, fxor_coef, rscale;
if (state->com.mc_header.lfe && state->com.mc_lfe_alloc)
{
qnt = 5;
n = mp3_numbits[qnt] - 1;
xor_coef = 1 << n;
fxor_coef = (Ipp32f)xor_coef;
rscale = mp3_rscale_values[state->com.mc_lfe_scf] * mpa_tab_a_l2[qnt];
ippsMulC_32f_I(rscale, state->mc_lfe_buf, 12);
ippsAddC_32f_I(mpa_tab_b_l2[qnt], state->mc_lfe_buf, 12);
for (j = 0; j < 12; j++) {
d = state->mc_lfe_buf[j];
if (d >= 0) {
state->com.mc_lfe_spl[j] = (Ipp32s)(d * fxor_coef) | xor_coef;
} else {
state->com.mc_lfe_spl[j] = (Ipp32s)((d + 1.0f) * fxor_coef);
}
}
}
}
static void mp3enc_join_LR_l2(MP3Enc *state)
{
Ipp32s sb, j;
Ipp32s sblimit_real = state->com.sblimit_real;
for (sb = 0; sb < sblimit_real; sb++)
for (j = 0; j < 36; j++)
state->fbout_data[2][0][j][sb] = 0.5f * (state->fbout_data[0][0][j][sb] +
state->fbout_data[1][0][j][sb]);
}
Ipp32s mp3enc_quantization_l2(MP3Enc *state)
{
if(state->com.stereo_mode_param == MPA_JOINT_STEREO) {
mp3enc_join_LR_l2(state);
}
if (state->com.mc_header.lfe) {
state->com.mc_lfe_alloc = 4;
}
mp3enc_scale_factor_calc_l2(state);
mp3enc_transmission_pattern_l2(state);
mp3enc_bit_allocation_l2(state);
mp3enc_lfe_quantization_l2(state);
mp3enc_subband_quantization_l2(state);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -