Esempio n. 1
0
  public void best_huffman_divide(final LameInternalFlags gfc, GrInfo gi) {
    GrInfo cod_info2 = new GrInfo();
    final int[] ix = gi.l3_enc;

    int r01_bits[] = new int[7 + 15 + 1];
    int r01_div[] = new int[7 + 15 + 1];
    int r0_tbl[] = new int[7 + 15 + 1];
    int r1_tbl[] = new int[7 + 15 + 1];

    /* SHORT BLOCK stuff fails for MPEG2 */
    if (gi.block_type == Encoder.SHORT_TYPE && gfc.mode_gr == 1) return;

    cod_info2.assign(gi);
    if (gi.block_type == Encoder.NORM_TYPE) {
      recalc_divide_init(gfc, gi, ix, r01_bits, r01_div, r0_tbl, r1_tbl);
      recalc_divide_sub(gfc, cod_info2, gi, ix, r01_bits, r01_div, r0_tbl, r1_tbl);
    }

    int i = cod_info2.big_values;
    if (i == 0 || (ix[i - 2] | ix[i - 1]) > 1) return;

    i = gi.count1 + 2;
    if (i > 576) return;

    /* Determines the number of bits to encode the quadruples. */
    cod_info2.assign(gi);
    cod_info2.count1 = i;
    int a1 = 0;
    int a2 = 0;

    assert (i <= 576);

    for (; i > cod_info2.big_values; i -= 4) {
      final int p = ((ix[i - 4] * 2 + ix[i - 3]) * 2 + ix[i - 2]) * 2 + ix[i - 1];
      a1 += Tables.t32l[p];
      a2 += Tables.t33l[p];
    }
    cod_info2.big_values = i;

    cod_info2.count1table_select = 0;
    if (a1 > a2) {
      a1 = a2;
      cod_info2.count1table_select = 1;
    }

    cod_info2.count1bits = a1;

    if (cod_info2.block_type == Encoder.NORM_TYPE)
      recalc_divide_sub(gfc, cod_info2, gi, ix, r01_bits, r01_div, r0_tbl, r1_tbl);
    else {
      /* Count the number of bits necessary to code the bigvalues region. */
      cod_info2.part2_3_length = a1;
      a1 = gfc.scalefac_band.l[7 + 1];
      if (a1 > i) {
        a1 = i;
      }
      if (a1 > 0) {
        Bits bi = new Bits(cod_info2.part2_3_length);
        cod_info2.table_select[0] = choose_table(ix, 0, a1, bi);
        cod_info2.part2_3_length = bi.bits;
      }
      if (i > a1) {
        Bits bi = new Bits(cod_info2.part2_3_length);
        cod_info2.table_select[1] = choose_table(ix, a1, i, bi);
        cod_info2.part2_3_length = bi.bits;
      }
      if (gi.part2_3_length > cod_info2.part2_3_length) gi.assign(cod_info2);
    }
  }
Esempio n. 2
0
  /** 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;
  }