Java tutorial
//package com.java2s; /* * Copyright (C) 2016 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 { /** * Returns the number of audio samples represented by the given DTS frame. * * @param data The frame to parse. * @return The number of audio samples represented by the frame. */ public static int parseDtsAudioSampleCount(byte[] data) { // See ETSI TS 102 114 subsection 5.4.1. int nblks = ((data[4] & 0x01) << 6) | ((data[5] & 0xFC) >> 2); return (nblks + 1) * 32; } /** * Like {@link #parseDtsAudioSampleCount(byte[])} but reads from a {@link ByteBuffer}. The * buffer's position is not modified. * * @param buffer The {@link ByteBuffer} from which to read. * @return The number of audio samples represented by the syncframe. */ public static int parseDtsAudioSampleCount(ByteBuffer buffer) { // See ETSI TS 102 114 subsection 5.4.1. int position = buffer.position(); int nblks = ((buffer.get(position + 4) & 0x01) << 6) | ((buffer.get(position + 5) & 0xFC) >> 2); return (nblks + 1) * 32; } }