Example #1
0
 /**
  * Returns the AC-3 format given {@code data} containing the AC3SpecificBox according to ETSI TS
  * 102 366 Annex F.
  */
 public static MediaFormat parseAnnexFAc3Format(ParsableByteArray data) {
   // fscod (sample rate code)
   int fscod = (data.readUnsignedByte() & 0xC0) >> 6;
   int sampleRate = SAMPLE_RATES[fscod];
   int nextByte = data.readUnsignedByte();
   // Map acmod (audio coding mode) onto a channel count.
   int channelCount = CHANNEL_COUNTS[(nextByte & 0x38) >> 3];
   // lfeon (low frequency effects on)
   if ((nextByte & 0x04) != 0) {
     channelCount++;
   }
   return MediaFormat.createAudioFormat(
       MimeTypes.AUDIO_AC3, MediaFormat.NO_VALUE, channelCount, sampleRate, null);
 }
Example #2
0
  /**
   * Returns the AC-3 format given {@code data} containing the EC3SpecificBox according to ETSI TS
   * 102 366 Annex F.
   */
  public static MediaFormat parseAnnexFEAc3Format(ParsableByteArray data) {
    data.skipBytes(2); // Skip data_rate and num_ind_sub.

    // Read only the first substream.
    // TODO: Read later substreams?
    // fscod (sample rate code)
    int fscod = (data.readUnsignedByte() & 0xC0) >> 6;
    int sampleRate = SAMPLE_RATES[fscod];
    int nextByte = data.readUnsignedByte();
    // Map acmod (audio coding mode) onto a channel count.
    int channelCount = CHANNEL_COUNTS[(nextByte & 0x0E) >> 1];
    // lfeon (low frequency effects on)
    if ((nextByte & 0x01) != 0) {
      channelCount++;
    }
    return MediaFormat.createAudioFormat(
        MimeTypes.AUDIO_EC3, MediaFormat.NO_VALUE, channelCount, sampleRate, null);
  }
Example #3
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);
  }