private void recalc_divide_sub( final LameInternalFlags gfc, final GrInfo cod_info2, GrInfo gi, final int[] ix, final int r01_bits[], final int r01_div[], final int r0_tbl[], final int r1_tbl[]) { int bigv = cod_info2.big_values; for (int r2 = 2; r2 < Encoder.SBMAX_l + 1; r2++) { int a2 = gfc.scalefac_band.l[r2]; if (a2 >= bigv) break; int bits = r01_bits[r2 - 2] + cod_info2.count1bits; if (gi.part2_3_length <= bits) break; Bits bi = new Bits(bits); int r2t = choose_table(ix, a2, bigv, bi); bits = bi.bits; if (gi.part2_3_length <= bits) continue; gi.assign(cod_info2); gi.part2_3_length = bits; gi.region0_count = r01_div[r2 - 2]; gi.region1_count = r2 - 2 - r01_div[r2 - 2]; gi.table_select[0] = r0_tbl[r2 - 2]; gi.table_select[1] = r1_tbl[r2 - 2]; gi.table_select[2] = r2t; } }
/** count_bit */ public int noquant_count_bits( final LameInternalFlags gfc, final GrInfo gi, CalcNoiseData prev_noise) { final int[] ix = gi.l3_enc; int i = Math.min(576, ((gi.max_nonzero_coeff + 2) >> 1) << 1); if (prev_noise != null) prev_noise.sfb_count1 = 0; /* Determine count1 region */ for (; i > 1; i -= 2) if ((ix[i - 1] | ix[i - 2]) != 0) break; gi.count1 = i; /* Determines the number of bits to encode the quadruples. */ int a1 = 0; int a2 = 0; for (; i > 3; i -= 4) { int p; /* hack to check if all values <= 1 */ if ((((long) ix[i - 1] | (long) ix[i - 2] | (long) ix[i - 3] | (long) ix[i - 4]) & 0xffffffffL) > 1L) break; p = ((ix[i - 4] * 2 + ix[i - 3]) * 2 + ix[i - 2]) * 2 + ix[i - 1]; a1 += Tables.t32l[p]; a2 += Tables.t33l[p]; } int bits = a1; gi.count1table_select = 0; if (a1 > a2) { bits = a2; gi.count1table_select = 1; } gi.count1bits = bits; gi.big_values = i; if (i == 0) return bits; if (gi.block_type == Encoder.SHORT_TYPE) { a1 = 3 * gfc.scalefac_band.s[3]; if (a1 > gi.big_values) a1 = gi.big_values; a2 = gi.big_values; } else if (gi.block_type == Encoder.NORM_TYPE) { assert (i <= 576); /* bv_scf has 576 entries (0..575) */ a1 = gi.region0_count = gfc.bv_scf[i - 2]; a2 = gi.region1_count = gfc.bv_scf[i - 1]; assert (a1 + a2 + 2 < Encoder.SBPSY_l); a2 = gfc.scalefac_band.l[a1 + a2 + 2]; a1 = gfc.scalefac_band.l[a1 + 1]; if (a2 < i) { Bits bi = new Bits(bits); gi.table_select[2] = choose_table(ix, a2, i, bi); bits = bi.bits; } } else { gi.region0_count = 7; /* gi.region1_count = SBPSY_l - 7 - 1; */ gi.region1_count = Encoder.SBMAX_l - 1 - 7 - 1; a1 = gfc.scalefac_band.l[7 + 1]; a2 = i; if (a1 > a2) { a1 = a2; } } /* have to allow for the case when bigvalues < region0 < region1 */ /* (and region0, region1 are ignored) */ a1 = Math.min(a1, i); a2 = Math.min(a2, i); assert (a1 >= 0); assert (a2 >= 0); /* Count the number of bits necessary to code the bigvalues region. */ if (0 < a1) { Bits bi = new Bits(bits); gi.table_select[0] = choose_table(ix, 0, a1, bi); bits = bi.bits; } if (a1 < a2) { Bits bi = new Bits(bits); gi.table_select[1] = choose_table(ix, a1, a2, bi); bits = bi.bits; } if (gfc.use_best_huffman == 2) { gi.part2_3_length = bits; best_huffman_divide(gfc, gi); bits = gi.part2_3_length; } if (prev_noise != null) { if (gi.block_type == Encoder.NORM_TYPE) { int sfb = 0; while (gfc.scalefac_band.l[sfb] < gi.big_values) { sfb++; } prev_noise.sfb_count1 = sfb; } } return bits; }