Example #1
0
  private boolean vorbis_encode_setup_setting(int channels, int rate) {

    int i, is;

    codec_setup_info ci = vi.codec_setup;
    highlevel_encode_setup hi = ci.hi;
    ve_setup_data_template setup = hi.setup;
    float ds; // double

    // vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate)
    vi.version = 0;
    vi.channels = channels;
    vi.rate = rate;

    is = new Float(hi.base_setting).intValue();
    ds = hi.base_setting - is;

    hi.short_setting = hi.base_setting;
    hi.long_setting = hi.base_setting;

    hi.managed = 0;

    hi.impulse_block_p = 1;
    hi.noise_normalize_p = 1;

    hi.stereo_point_setting = hi.base_setting;
    hi.lowpass_kHz = setup.psy_lowpass[is] * (1.0f - ds) + setup.psy_lowpass[is + 1] * ds;

    hi.ath_floating_dB = setup.psy_ath_float[is] * (1.0f - ds) + setup.psy_ath_float[is + 1] * ds;
    hi.ath_absolute_dB = setup.psy_ath_abs[is] * (1.0f - ds) + setup.psy_ath_abs[is + 1] * ds;

    hi.amplitude_track_dBpersec = -6.0f;
    hi.trigger_setting = hi.base_setting;

    for (i = 0; i < 4; i++)
      hi.block[i] =
          new highlevel_byblocktype(
              hi.base_setting, hi.base_setting, hi.base_setting, hi.base_setting);

    return true;
  }
Example #2
0
  public boolean vorbis_encode_setup_init() { // the final setup call

    int i0 = 0;
    int singleblock = 0;

    codec_setup_info ci = vi.codec_setup;
    ve_setup_data_template setup = null;
    highlevel_encode_setup hi = ci.hi;

    if (ci == null) {
      System.out.println("vorbis_info.codec_setup_info doesnt exist");
      return false;
    }

    if (hi.impulse_block_p == 0) i0 = 1;

    // too low/high an ATH floater is nonsensical, but doesn't break anything
    if (hi.ath_floating_dB > -80) hi.ath_floating_dB = -80;
    if (hi.ath_floating_dB < -200) hi.ath_floating_dB = -200;

    // again, bound this to avoid the app shooting itself in the foot
    if (hi.amplitude_track_dBpersec > 0.) hi.amplitude_track_dBpersec = 0.0f;
    if (hi.amplitude_track_dBpersec < -99999.) hi.amplitude_track_dBpersec = -99999.0f;

    // get the appropriate setup template; matches the fetch in previous stages
    setup = hi.setup;
    if (setup == null) {
      System.out.println(
          "vorbis_info.codec_setup.highlevel_encode_setup.ve_setup_data_template doesnt exist");
      return false;
    }

    hi.set_in_stone = 1;

    // choose block sizes from configured sizes as well as paying attention
    // to long_block_p and short_block_p.  If the configured short and long
    // blocks are the same length, we set long_block_p and unset short_block_p

    vorbis_encode_blocksize_setup(hi.base_setting, setup.blocksize_short, setup.blocksize_long);
    if (ci.blocksizes[0] == ci.blocksizes[1]) singleblock = 1;

    // floor setup; choose proper floor params.  Allocated on the floor stack in order; if we alloc
    // only long floor, it's 0
    vorbis_encode_floor_setup(
        hi.short_setting, 0, setup.floor_books, setup.floor_params, setup.floor_short_mapping);
    if (singleblock == 0)
      vorbis_encode_floor_setup(
          hi.long_setting, 1, setup.floor_books, setup.floor_params, setup.floor_long_mapping);

    // setup of [mostly] short block detection and stereo
    vorbis_encode_global_psych_setup(hi.trigger_setting, setup.global_params, setup.global_mapping);
    vorbis_encode_global_stereo(hi, setup.stereo_modes);

    // basic psych setup and noise normalization
    vorbis_encode_psyset_setup(
        hi.short_setting,
        setup.psy_noise_normal_start[0],
        setup.psy_noise_normal_partition[0],
        setup.psy_noise_normal_thresh,
        0);
    vorbis_encode_psyset_setup(
        hi.short_setting,
        setup.psy_noise_normal_start[0],
        setup.psy_noise_normal_partition[0],
        setup.psy_noise_normal_thresh,
        1);
    if (singleblock == 0) {
      vorbis_encode_psyset_setup(
          hi.long_setting,
          setup.psy_noise_normal_start[1],
          setup.psy_noise_normal_partition[1],
          setup.psy_noise_normal_thresh,
          2);
      vorbis_encode_psyset_setup(
          hi.long_setting,
          setup.psy_noise_normal_start[1],
          setup.psy_noise_normal_partition[1],
          setup.psy_noise_normal_thresh,
          3);
    }

    // tone masking setup
    vorbis_encode_tonemask_setup(
        hi.block[i0].tone_mask_setting,
        0,
        setup.psy_tone_masteratt,
        setup.psy_tone_0dB,
        setup.psy_tone_adj_impulse);
    vorbis_encode_tonemask_setup(
        hi.block[1].tone_mask_setting,
        1,
        setup.psy_tone_masteratt,
        setup.psy_tone_0dB,
        setup.psy_tone_adj_other);
    if (singleblock == 0) {
      vorbis_encode_tonemask_setup(
          hi.block[2].tone_mask_setting,
          2,
          setup.psy_tone_masteratt,
          setup.psy_tone_0dB,
          setup.psy_tone_adj_other);
      vorbis_encode_tonemask_setup(
          hi.block[3].tone_mask_setting,
          3,
          setup.psy_tone_masteratt,
          setup.psy_tone_0dB,
          setup.psy_tone_adj_long);
    }

    // noise companding setup
    vorbis_encode_compand_setup(
        hi.block[i0].noise_compand_setting,
        0,
        setup.psy_noise_compand,
        setup.psy_noise_compand_short_mapping);
    vorbis_encode_compand_setup(
        hi.block[1].noise_compand_setting,
        1,
        setup.psy_noise_compand,
        setup.psy_noise_compand_short_mapping);
    if (singleblock == 0) {
      vorbis_encode_compand_setup(
          hi.block[2].noise_compand_setting,
          2,
          setup.psy_noise_compand,
          setup.psy_noise_compand_long_mapping);
      vorbis_encode_compand_setup(
          hi.block[3].noise_compand_setting,
          3,
          setup.psy_noise_compand,
          setup.psy_noise_compand_long_mapping);
    }

    // peak guarding setup
    vorbis_encode_peak_setup(hi.block[i0].tone_peaklimit_setting, 0, setup.psy_tone_dBsuppress);
    vorbis_encode_peak_setup(hi.block[1].tone_peaklimit_setting, 1, setup.psy_tone_dBsuppress);
    if (singleblock == 0) {
      vorbis_encode_peak_setup(hi.block[2].tone_peaklimit_setting, 2, setup.psy_tone_dBsuppress);
      vorbis_encode_peak_setup(hi.block[3].tone_peaklimit_setting, 3, setup.psy_tone_dBsuppress);
    }

    // noise bias setup
    float userbias = 0;
    if (i0 == 0) userbias = hi.impulse_noisetune;
    vorbis_encode_noisebias_setup(
        hi.block[i0].noise_bias_setting,
        0,
        setup.psy_noise_dBsuppress,
        setup.psy_noise_bias_impulse,
        setup.psy_noiseguards,
        userbias);
    vorbis_encode_noisebias_setup(
        hi.block[1].noise_bias_setting,
        1,
        setup.psy_noise_dBsuppress,
        setup.psy_noise_bias_padding,
        setup.psy_noiseguards,
        0.0f);
    if (singleblock == 0) {
      vorbis_encode_noisebias_setup(
          hi.block[2].noise_bias_setting,
          2,
          setup.psy_noise_dBsuppress,
          setup.psy_noise_bias_trans,
          setup.psy_noiseguards,
          0.0f);
      vorbis_encode_noisebias_setup(
          hi.block[3].noise_bias_setting,
          3,
          setup.psy_noise_dBsuppress,
          setup.psy_noise_bias_long,
          setup.psy_noiseguards,
          0.0f);
    }

    vorbis_encode_ath_setup(0);
    vorbis_encode_ath_setup(1);
    if (singleblock == 0) {
      vorbis_encode_ath_setup(2);
      vorbis_encode_ath_setup(3);
    }

    vorbis_encode_map_n_res_setup(hi.base_setting, setup.maps);

    // set bitrate readonlies and management
    if (hi.bitrate_av > 0) vi.bitrate_nominal = hi.bitrate_av;
    else vi.bitrate_nominal = new Float(setting_to_approx_bitrate()).intValue();

    vi.bitrate_lower = hi.bitrate_min;
    vi.bitrate_upper = hi.bitrate_max;
    if (hi.bitrate_av > 0) vi.bitrate_window = hi.bitrate_reservoir / hi.bitrate_av;
    else vi.bitrate_window = 0;

    if (hi.managed > 0) {

      ci.bi =
          new bitrate_manager_info(
              hi.bitrate_av,
              hi.bitrate_min,
              hi.bitrate_max,
              hi.bitrate_reservoir,
              hi.bitrate_reservoir_bias,
              hi.bitrate_av_damp);
    }

    return true;
  }