Parses an AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1 - Android Media

Android examples for Media:Audio

Description

Parses an AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1

Demo Code

/*//from   ww w. j av a 2 s  .c om
 * 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 android.annotation.SuppressLint;
import android.media.MediaCodecInfo.CodecProfileLevel;
import android.util.Pair;
import java.util.ArrayList;
import java.util.List;

public class Main{
    private static final int[] AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE = new int[] {
            96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000,
            12000, 11025, 8000, 7350 };
    /**
     * Parses an AudioSpecificConfig, as defined in ISO 14496-3 1.6.2.1
     *
     * @param audioSpecificConfig The AudioSpecificConfig to parse.
     * @return A pair consisting of the sample rate in Hz and the channel count.
     */
    public static Pair<Integer, Integer> parseAudioSpecificConfig(
            byte[] audioSpecificConfig) {
        int audioObjectType = (audioSpecificConfig[0] >> 3) & 0x1F;
        int byteOffset = audioObjectType == 5 || audioObjectType == 29 ? 1
                : 0;
        int frequencyIndex = (audioSpecificConfig[byteOffset] & 0x7) << 1
                | ((audioSpecificConfig[byteOffset + 1] >> 7) & 0x1);
        Assertions.checkState(frequencyIndex < 13);
        int sampleRate = AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE[frequencyIndex];
        int channelCount = (audioSpecificConfig[byteOffset + 1] >> 3) & 0xF;
        return Pair.create(sampleRate, channelCount);
    }
}

Related Tutorials