예제 #1
0
  /**
   * Returns the AC-3 frame size in bytes given {@code data} containing the frame header starting
   * from the sync word.
   *
   * @param data Data to parse, positioned at the start of the syncword.
   * @return The frame size parsed from data in the header.
   */
  public static int parseFrameSize(ParsableBitArray data) {
    // Skip syncword and crc1.
    data.skipBits(4 * 8);

    int fscod = data.readBits(2);
    int frmsizecod = data.readBits(6);
    int sampleRate = SAMPLE_RATES[fscod];
    int bitrate = BITRATES[frmsizecod / 2];
    if (sampleRate == 32000) {
      return 6 * bitrate;
    } else if (sampleRate == 44100) {
      return 2 * (FRMSIZECOD_TO_FRAME_SIZE_44_1[frmsizecod / 2] + (frmsizecod % 2));
    } else { // sampleRate == 48000
      return 4 * bitrate;
    }
  }
예제 #2
0
  /**
   * Returns the AC-3 format given {@code data} containing the frame header starting from the sync
   * word.
   *
   * @param data Data to parse, positioned at the start of the syncword.
   * @return AC-3 format parsed from data in the header.
   */
  public static MediaFormat parseFrameAc3Format(ParsableBitArray data) {
    // Skip syncword and crc1.
    data.skipBits(4 * 8);

    int fscod = data.readBits(2);
    data.skipBits(14); // frmsizecod(6) + bsid (5 bits) + bsmod (3 bits)
    int acmod = data.readBits(3);
    if ((acmod & 0x01) != 0 && acmod != 1) {
      data.skipBits(2); // cmixlev
    }
    if ((acmod & 0x04) != 0) {
      data.skipBits(2); // surmixlev
    }
    if (acmod == 0x02) {
      data.skipBits(2); // dsurmod
    }
    boolean lfeon = data.readBit();
    return MediaFormat.createAudioFormat(
        MimeTypes.AUDIO_AC3,
        MediaFormat.NO_VALUE,
        CHANNEL_COUNTS[acmod] + (lfeon ? 1 : 0),
        SAMPLE_RATES[fscod],
        null);
  }