FileDocCategorySizeDatePackage
VorbisIdentificationHeader.javaAPI DocJaudiotagger 2.0.45877Wed Mar 30 16:11:54 BST 2011org.jaudiotagger.audio.ogg.util

VorbisIdentificationHeader

public class VorbisIdentificationHeader extends Object implements VorbisHeader
Vorbis Identification header

From http://xiph.org/vorbis/doc/Vorbis_I_spec.html#id326710

The identification header is a short header of only a few fields used to declare the stream definitively as Vorbis, and provide a few externally relevant pieces of information about the audio stream. The identification header is coded as follows:

1) [vorbis_version] = read 32 bits as unsigned integer 2) [audio_channels] = read 8 bit integer as unsigned 3) [audio_sample_rate] = read 32 bits as unsigned integer 4) [bitrate_maximum] = read 32 bits as signed integer 5) [bitrate_nominal] = read 32 bits as signed integer 6) [bitrate_minimum] = read 32 bits as signed integer 7) [blocksize_0] = 2 exponent (read 4 bits as unsigned integer) 8) [blocksize_1] = 2 exponent (read 4 bits as unsigned integer) 9) [framing_flag] = read one bit

$Id: VorbisIdentificationHeader.java 813 2009-09-03 09:23:25Z paultaylor $

author
Raphael Slinckx (KiKiDonK)
version
16 d�cembre 2003

Fields Summary
public static Logger
logger
private int
audioChannels
private boolean
isValid
private int
vorbisVersion
private int
audioSampleRate
private int
bitrateMinimal
private int
bitrateNominal
private int
bitrateMaximal
public static final int
FIELD_VORBIS_VERSION_POS
public static final int
FIELD_AUDIO_CHANNELS_POS
public static final int
FIELD_AUDIO_SAMPLE_RATE_POS
public static final int
FIELD_BITRATE_MAX_POS
public static final int
FIELD_BITRATE_NOMAIML_POS
public static final int
FIELD_BITRATE_MIN_POS
public static final int
FIELD_BLOCKSIZE_POS
public static final int
FIELD_FRAMING_FLAG_POS
public static final int
FIELD_VORBIS_VERSION_LENGTH
public static final int
FIELD_AUDIO_CHANNELS_LENGTH
public static final int
FIELD_AUDIO_SAMPLE_RATE_LENGTH
public static final int
FIELD_BITRATE_MAX_LENGTH
public static final int
FIELD_BITRATE_NOMAIML_LENGTH
public static final int
FIELD_BITRATE_MIN_LENGTH
public static final int
FIELD_BLOCKSIZE_LENGTH
public static final int
FIELD_FRAMING_FLAG_LENGTH
Constructors Summary
public VorbisIdentificationHeader(byte[] vorbisData)



      
    
        decodeHeader(vorbisData);
    
Methods Summary
public voiddecodeHeader(byte[] b)

        int packetType = b[FIELD_PACKET_TYPE_POS];
        logger.fine("packetType" + packetType);
        String vorbis = Utils.getString(b, VorbisHeader.FIELD_CAPTURE_PATTERN_POS, VorbisHeader.FIELD_CAPTURE_PATTERN_LENGTH, "ISO-8859-1");

        if (packetType == VorbisPacketType.IDENTIFICATION_HEADER.getType() && vorbis.equals(CAPTURE_PATTERN))
        {
            this.vorbisVersion = b[7] + (b[8] << 8) + (b[9] << 16) + (b[10] << 24);
            logger.fine("vorbisVersion" + vorbisVersion);
            this.audioChannels = u(b[FIELD_AUDIO_CHANNELS_POS]);
            logger.fine("audioChannels" + audioChannels);
            this.audioSampleRate = u(b[12]) + (u(b[13]) << 8) + (u(b[14]) << 16) + (u(b[15]) << 24);
            logger.fine("audioSampleRate" + audioSampleRate);
            logger.fine("audioSampleRate" + b[12] + " " + b[13] + " " + b[14]);

            //TODO is this right spec says signed
            this.bitrateMinimal = u(b[16]) + (u(b[17]) << 8) + (u(b[18]) << 16) + (u(b[19]) << 24);
            this.bitrateNominal = u(b[20]) + (u(b[21]) << 8) + (u(b[22]) << 16) + (u(b[23]) << 24);
            this.bitrateMaximal = u(b[24]) + (u(b[25]) << 8) + (u(b[26]) << 16) + (u(b[27]) << 24);
            //byte blockSize0 = (byte) ( b[28] & 240 );
            //byte blockSize1 = (byte) ( b[28] & 15 );

            int framingFlag = b[FIELD_FRAMING_FLAG_POS];
            logger.fine("framingFlag" + framingFlag);
            if (framingFlag != 0)
            {
                isValid = true;
            }

        }
    
public intgetChannelNumber()

        return audioChannels;
    
public java.lang.StringgetEncodingType()

        return VorbisVersion.values()[vorbisVersion].toString();
    
public intgetMaxBitrate()

        return bitrateMaximal;
    
public intgetMinBitrate()

        return bitrateMinimal;
    
public intgetNominalBitrate()

        return bitrateNominal;
    
public intgetSamplingRate()

        return audioSampleRate;
    
public booleanisValid()

        return isValid;
    
private intu(int i)

        return i & 0xFF;