Exemple #1
0
  /**
   *
   *
   * <PRE>
   * -oo dB  =>  -1.00
   * - 6 dB  =>  -0.97
   * - 3 dB  =>  -0.80
   * - 2 dB  =>  -0.64
   * - 1 dB  =>  -0.38
   * 0 dB  =>   0.00
   * + 1 dB  =>  +0.49
   * + 2 dB  =>  +1.06
   * + 3 dB  =>  +1.68
   * + 6 dB  =>  +3.69
   * +10 dB  =>  +6.45
   * </PRE>
   */
  public final int calc_noise(
      final GrInfo cod_info,
      final float[] l3_xmin,
      final float[] distort,
      final CalcNoiseResult res,
      final CalcNoiseData prev_noise) {
    int distortPos = 0;
    int l3_xminPos = 0;
    int sfb, l, over = 0;
    float over_noise_db = 0;
    /* 0 dB relative to masking */
    float tot_noise_db = 0;
    /* -200 dB relative to masking */
    float max_noise = -20.0f;
    int j = 0;
    final int[] scalefac = cod_info.scalefac;
    int scalefacPos = 0;

    res.over_SSD = 0;

    for (sfb = 0; sfb < cod_info.psymax; sfb++) {
      final int s =
          cod_info.global_gain
              - (((scalefac[scalefacPos++]) + (cod_info.preflag != 0 ? pretab[sfb] : 0))
                  << (cod_info.scalefac_scale + 1))
              - cod_info.subblock_gain[cod_info.window[sfb]] * 8;
      float noise = 0.0f;

      if (prev_noise != null && (prev_noise.step[sfb] == s)) {

        /* use previously computed values */
        noise = prev_noise.noise[sfb];
        j += cod_info.width[sfb];
        distort[distortPos++] = noise / l3_xmin[l3_xminPos++];

        noise = prev_noise.noise_log[sfb];

      } else {
        final float step = POW20(s);
        l = cod_info.width[sfb] >> 1;

        if ((j + cod_info.width[sfb]) > cod_info.max_nonzero_coeff) {
          int usefullsize;
          usefullsize = cod_info.max_nonzero_coeff - j + 1;

          if (usefullsize > 0) l = usefullsize >> 1;
          else l = 0;
        }

        StartLine sl = new StartLine(j);
        noise = calc_noise_core(cod_info, sl, l, step);
        j = sl.s;

        if (prev_noise != null) {
          /* save noise values */
          prev_noise.step[sfb] = s;
          prev_noise.noise[sfb] = noise;
        }

        noise = distort[distortPos++] = noise / l3_xmin[l3_xminPos++];

        /* multiplying here is adding in dB, but can overflow */
        noise = Util.FAST_LOG10((float) Math.max(noise, 1E-20));

        if (prev_noise != null) {
          /* save noise values */
          prev_noise.noise_log[sfb] = noise;
        }
      }

      if (prev_noise != null) {
        /* save noise values */
        prev_noise.global_gain = cod_info.global_gain;
      }

      tot_noise_db += noise;

      if (noise > 0.0) {
        int tmp;

        tmp = Math.max((int) (noise * 10 + .5), 1);
        res.over_SSD += tmp * tmp;

        over++;
        /* multiplying here is adding in dB -but can overflow */
        /* over_noise *= noise; */
        over_noise_db += noise;
      }
      max_noise = Math.max(max_noise, noise);
    }

    res.over_count = over;
    res.tot_noise = tot_noise_db;
    res.over_noise = over_noise_db;
    res.max_noise = max_noise;

    return over;
  }
Exemple #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;
  }