Example #1
0
  private boolean get_setup_template(int ch, int srate, float req, int q_or_bitrate) {

    int i = 0, j;
    highlevel_encode_setup hi = vi.codec_setup.hi;

    if (q_or_bitrate > 0) req /= ch;

    while (setup_list[i] != null) {

      if (setup_list[i].coupling_restriction == -1 || setup_list[i].coupling_restriction == ch) {

        if (srate >= setup_list[i].samplerate_min_restriction
            && srate <= setup_list[i].samplerate_max_restriction) {

          int mappings = setup_list[i].mappings;
          float[] map;
          if (q_or_bitrate > 0) map = setup_list[i].rate_mapping;
          else map = setup_list[i].quality_mapping;

          // the template matches.  Does the requested quality mode fall within this templates
          // modes?
          if (req < map[0]) {
            ++i;
            continue;
          }

          if (req > map[setup_list[i].mappings]) {
            ++i;
            continue;
          }

          for (j = 0; j < mappings; j++) if (req >= map[j] && req < map[j + 1]) break;

          // an all points match
          hi.setup = setup_list[i];

          if (j == mappings) hi.base_setting = j - .001f;
          else {
            float low = map[j];
            float high = map[j + 1];
            float del = (req - low) / (high - low);
            hi.base_setting = j + del;
          }

          return true;
        }
      }
      i++;
    }
    hi.setup = null;
    return false;
  }