Java tutorial
//package com.java2s; /* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.nio.ByteBuffer; public class Main { /** * The number of new samples per (E-)AC-3 audio block. */ private static final int AUDIO_SAMPLES_PER_AUDIO_BLOCK = 256; /** * Number of audio blocks per E-AC-3 syncframe, indexed by numblkscod. */ private static final int[] BLOCKS_PER_SYNCFRAME_BY_NUMBLKSCOD = new int[] { 1, 2, 3, 6 }; /** * Returns the number of audio samples represented by the given E-AC-3 syncframe. * * @param data The syncframe to parse. * @return The number of audio samples represented by the syncframe. */ public static int parseEAc3SyncframeAudioSampleCount(byte[] data) { // See ETSI TS 102 366 subsection E.1.2.2. return AUDIO_SAMPLES_PER_AUDIO_BLOCK * (((data[4] & 0xC0) >> 6) == 0x03 ? 6 // fscod : BLOCKS_PER_SYNCFRAME_BY_NUMBLKSCOD[(data[4] & 0x30) >> 4]); } /** * Like {@link #parseEAc3SyncframeAudioSampleCount(byte[])} but reads from a byte buffer. The * buffer position is not modified. * * @see #parseEAc3SyncframeAudioSampleCount(byte[]) */ public static int parseEAc3SyncframeAudioSampleCount(ByteBuffer buffer) { // See ETSI TS 102 366 subsection E.1.2.2. int fscod = (buffer.get(buffer.position() + 4) & 0xC0) >> 6; return AUDIO_SAMPLES_PER_AUDIO_BLOCK * (fscod == 0x03 ? 6 : BLOCKS_PER_SYNCFRAME_BY_NUMBLKSCOD[(buffer.get(buffer.position() + 4) & 0x30) >> 4]); } }