コード例 #1
0
ファイル: vorbisenc.java プロジェクト: GaryShearer/RSChan
  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;
  }
コード例 #2
0
ファイル: vorbisenc.java プロジェクト: GaryShearer/RSChan
  public Object vorbis_encode_ctl(vorbis_info _vi, int number, Object arg) {

    if (_vi == null) return false;

    codec_setup_info ci = vi.codec_setup;
    highlevel_encode_setup hi = ci.hi;
    int setp = (number & 0xf); // a read request has a low nibble of 0

    if ((setp > 0) && (hi.set_in_stone > 0)) return false;

    switch (number) {

        // now deprecated *****************
        /*
        case OV_ECTL_RATEMANAGE_GET: {

        	ovectl_ratemanage_arg ai= ( ovectl_ratemanage_arg )arg;

        	ai.management_active=hi.managed;
        	ai.bitrate_hard_window=ai.bitrate_av_window=(double)hi.bitrate_reservoir/vi.rate;
        	ai.bitrate_av_window_center=1.;
        	ai.bitrate_hard_min=hi.bitrate_min;
        	ai.bitrate_hard_max=hi.bitrate_max;
        	ai.bitrate_av_lo=hi.bitrate_av;
        	ai.bitrate_av_hi=hi.bitrate_av;
        }
        return true;

        // now deprecated *****************
        case OV_ECTL_RATEMANAGE_SET: {

        	ovectl_ratemanage_arg ai= ( ovectl_ratemanage_arg )arg;

        	if ( ai == null ) {
        		hi.managed=0;
        	} else {
        		hi.managed=ai.management_active;
        		vorbis_encode_ctl( vi, OV_ECTL_RATEMANAGE_AVG, arg );
        		vorbis_encode_ctl( vi, OV_ECTL_RATEMANAGE_HARD, arg );
        	}
        }
        return true;

        // now deprecated *****************
        case OV_ECTL_RATEMANAGE_AVG: {

        	ovectl_ratemanage_arg ai= ( ovectl_ratemanage_arg )arg;

        	if (ai == null) {
        		hi.bitrate_av=0;
        	} else {
        		hi.bitrate_av=(ai.bitrate_av_lo+ai.bitrate_av_hi)*.5;
        	}
        }
        return true;

        // now deprecated *****************
        case OV_ECTL_RATEMANAGE_HARD: {

        	ovectl_ratemanage_arg ai= ( ovectl_ratemanage_arg )arg;

        	if (ai == null ) {
        		hi.bitrate_min=0;
        		hi.bitrate_max=0;
        	} else {
        		hi.bitrate_min=ai.bitrate_hard_min;
        		hi.bitrate_max=ai.bitrate_hard_max;
        		hi.bitrate_reservoir=ai.bitrate_hard_window*(hi.bitrate_max+hi.bitrate_min)*.5;
        	}
        	if ( hi.bitrate_reservoir < 128.f )
        		hi.bitrate_reservoir=128;
        }
        return true;
        */

        // replacement ratemanage interface
      case OV_ECTL_RATEMANAGE2_GET:
        {
          ovectl_ratemanage2_arg ai = (ovectl_ratemanage2_arg) arg;

          if (ai == null) return false;

          ai.management_active = hi.managed;
          ai.bitrate_limit_min_kbps = hi.bitrate_min / 1000;
          ai.bitrate_limit_max_kbps = hi.bitrate_max / 1000;
          ai.bitrate_average_kbps = hi.bitrate_av / 1000;
          ai.bitrate_average_damping = hi.bitrate_av_damp;
          ai.bitrate_limit_reservoir_bits = hi.bitrate_reservoir;
          ai.bitrate_limit_reservoir_bias = hi.bitrate_reservoir_bias;

          return ai;
        }

      case OV_ECTL_RATEMANAGE2_SET:
        {
          ovectl_ratemanage2_arg ai = (ovectl_ratemanage2_arg) arg;

          if (ai == null) {
            hi.managed = 0;
          } else {
            // sanity check; only catch invariant violations
            if (ai.bitrate_limit_min_kbps > 0
                && ai.bitrate_average_kbps > 0
                && ai.bitrate_limit_min_kbps > ai.bitrate_average_kbps) return false;

            if (ai.bitrate_limit_max_kbps > 0
                && ai.bitrate_average_kbps > 0
                && ai.bitrate_limit_max_kbps < ai.bitrate_average_kbps) return false;

            if (ai.bitrate_limit_min_kbps > 0
                && ai.bitrate_limit_max_kbps > 0
                && ai.bitrate_limit_min_kbps > ai.bitrate_limit_max_kbps) return false;

            if (ai.bitrate_average_damping <= 0.) return false;

            if (ai.bitrate_limit_reservoir_bits < 0) return false;

            if (ai.bitrate_limit_reservoir_bias < 0.) return false;

            if (ai.bitrate_limit_reservoir_bias > 1.) return false;

            hi.managed = ai.management_active;
            hi.bitrate_min = ai.bitrate_limit_min_kbps * 1000;
            hi.bitrate_max = ai.bitrate_limit_max_kbps * 1000;
            hi.bitrate_av = ai.bitrate_average_kbps * 1000;
            hi.bitrate_av_damp = ai.bitrate_average_damping;
            hi.bitrate_reservoir = ai.bitrate_limit_reservoir_bits;
            hi.bitrate_reservoir_bias = ai.bitrate_limit_reservoir_bias;
          }
        }
        return true;

      case OV_ECTL_LOWPASS_GET:
        {
          return hi.lowpass_kHz;
        }

      case OV_ECTL_LOWPASS_SET:
        {
          hi.lowpass_kHz = (Float) arg;

          if (hi.lowpass_kHz < 2.f) hi.lowpass_kHz = 2.f;
          if (hi.lowpass_kHz > 99.f) hi.lowpass_kHz = 99.f;
        }
        return true;

      case OV_ECTL_IBLOCK_GET:
        {
          return hi.impulse_noisetune;
        }

      case OV_ECTL_IBLOCK_SET:
        {
          hi.impulse_noisetune = (Float) arg;

          if (hi.impulse_noisetune > 0.f) hi.impulse_noisetune = 0.f;
          if (hi.impulse_noisetune < -15.f) hi.impulse_noisetune = -15.f;
        }
        return true;
    }
    return true;
  }