/** Also calculates the number of bits necessary to code the scalefactors. */ public boolean scale_bitcount(final GrInfo cod_info) { int k, sfb, max_slen1 = 0, max_slen2 = 0; /* maximum values */ int[] tab; final int[] scalefac = cod_info.scalefac; assert (all_scalefactors_not_negative(scalefac, cod_info.sfbmax)); if (cod_info.block_type == Encoder.SHORT_TYPE) { tab = scale_short; if (cod_info.mixed_block_flag != 0) tab = scale_mixed; } else { /* block_type == 1,2,or 3 */ tab = scale_long; if (0 == cod_info.preflag) { for (sfb = 11; sfb < Encoder.SBPSY_l; sfb++) if (scalefac[sfb] < qupvt.pretab[sfb]) break; if (sfb == Encoder.SBPSY_l) { cod_info.preflag = 1; for (sfb = 11; sfb < Encoder.SBPSY_l; sfb++) scalefac[sfb] -= qupvt.pretab[sfb]; } } } for (sfb = 0; sfb < cod_info.sfbdivide; sfb++) if (max_slen1 < scalefac[sfb]) max_slen1 = scalefac[sfb]; for (; sfb < cod_info.sfbmax; sfb++) if (max_slen2 < scalefac[sfb]) max_slen2 = scalefac[sfb]; /* * from Takehiro TOMINAGA <*****@*****.**> 10/99 loop over *all* * posible values of scalefac_compress to find the one which uses the * smallest number of bits. ISO would stop at first valid index */ cod_info.part2_length = QuantizePVT.LARGE_BITS; for (k = 0; k < 16; k++) { if (max_slen1 < slen1_n[k] && max_slen2 < slen2_n[k] && cod_info.part2_length > tab[k]) { cod_info.part2_length = tab[k]; cod_info.scalefac_compress = k; } } return cod_info.part2_length == QuantizePVT.LARGE_BITS; }
private void scfsi_calc(int ch, final IIISideInfo l3_side) { int sfb; final GrInfo gi = l3_side.tt[1][ch]; final GrInfo g0 = l3_side.tt[0][ch]; for (int i = 0; i < Tables.scfsi_band.length - 1; i++) { for (sfb = Tables.scfsi_band[i]; sfb < Tables.scfsi_band[i + 1]; sfb++) { if (g0.scalefac[sfb] != gi.scalefac[sfb] && gi.scalefac[sfb] >= 0) break; } if (sfb == Tables.scfsi_band[i + 1]) { for (sfb = Tables.scfsi_band[i]; sfb < Tables.scfsi_band[i + 1]; sfb++) { gi.scalefac[sfb] = -1; } l3_side.scfsi[ch][i] = 1; } } int s1 = 0; int c1 = 0; for (sfb = 0; sfb < 11; sfb++) { if (gi.scalefac[sfb] == -1) continue; c1++; if (s1 < gi.scalefac[sfb]) s1 = gi.scalefac[sfb]; } int s2 = 0; int c2 = 0; for (; sfb < Encoder.SBPSY_l; sfb++) { if (gi.scalefac[sfb] == -1) continue; c2++; if (s2 < gi.scalefac[sfb]) s2 = gi.scalefac[sfb]; } for (int i = 0; i < 16; i++) { if (s1 < slen1_n[i] && s2 < slen2_n[i]) { final int c = slen1_tab[i] * c1 + slen2_tab[i] * c2; if (gi.part2_length > c) { gi.part2_length = c; gi.scalefac_compress = i; } } } }
/** * Also counts the number of bits to encode the scalefacs but for MPEG 2 Lower sampling * frequencies (24, 22.05 and 16 kHz.) * * <p>This is reverse-engineered from section 2.4.3.2 of the MPEG2 IS, "Audio Decoding Layer III" */ public boolean scale_bitcount_lsf(final LameInternalFlags gfc, final GrInfo cod_info) { int table_number, row_in_table, partition, nr_sfb, window; boolean over; int i, sfb, max_sfac[] = new int[4]; final int[] partition_table; final int[] scalefac = cod_info.scalefac; /* * Set partition table. Note that should try to use table one, but do * not yet... */ if (cod_info.preflag != 0) table_number = 2; else table_number = 0; for (i = 0; i < 4; i++) max_sfac[i] = 0; if (cod_info.block_type == Encoder.SHORT_TYPE) { row_in_table = 1; partition_table = qupvt.nr_of_sfb_block[table_number][row_in_table]; for (sfb = 0, partition = 0; partition < 4; partition++) { nr_sfb = partition_table[partition] / 3; for (i = 0; i < nr_sfb; i++, sfb++) for (window = 0; window < 3; window++) if (scalefac[sfb * 3 + window] > max_sfac[partition]) max_sfac[partition] = scalefac[sfb * 3 + window]; } } else { row_in_table = 0; partition_table = qupvt.nr_of_sfb_block[table_number][row_in_table]; for (sfb = 0, partition = 0; partition < 4; partition++) { nr_sfb = partition_table[partition]; for (i = 0; i < nr_sfb; i++, sfb++) if (scalefac[sfb] > max_sfac[partition]) max_sfac[partition] = scalefac[sfb]; } } for (over = false, partition = 0; partition < 4; partition++) { if (max_sfac[partition] > max_range_sfac_tab[table_number][partition]) over = true; } if (!over) { int slen1, slen2, slen3, slen4; cod_info.sfb_partition_table = qupvt.nr_of_sfb_block[table_number][row_in_table]; for (partition = 0; partition < 4; partition++) cod_info.slen[partition] = log2tab[max_sfac[partition]]; /* set scalefac_compress */ slen1 = cod_info.slen[0]; slen2 = cod_info.slen[1]; slen3 = cod_info.slen[2]; slen4 = cod_info.slen[3]; switch (table_number) { case 0: cod_info.scalefac_compress = (((slen1 * 5) + slen2) << 4) + (slen3 << 2) + slen4; break; case 1: cod_info.scalefac_compress = 400 + (((slen1 * 5) + slen2) << 2) + slen3; break; case 2: cod_info.scalefac_compress = 500 + (slen1 * 3) + slen2; break; default: System.err.printf("intensity stereo not implemented yet\n"); break; } } if (!over) { assert (cod_info.sfb_partition_table != null); cod_info.part2_length = 0; for (partition = 0; partition < 4; partition++) cod_info.part2_length += cod_info.slen[partition] * cod_info.sfb_partition_table[partition]; } return over; }