Mp3dings 
20100427

helliker.id3
Class XingVBRHeader

java.lang.Object
  extended by helliker.id3.XingVBRHeader
All Implemented Interfaces:
VBRHeader

public class XingVBRHeader
extends Object

Reads information from a Xing info header. Thanks to the Scilla project (http://www.xs4all.nl/~rwvtveer/scilla/) for code ideas.


Constructor Summary
XingVBRHeader(ByteBuffer header, int layer, int mpegVersion, int sampleRate, int channelMode, long filesize)
          Looks for a Xing VBR header in the file.
 
Method Summary
protected  void calc(int layer, int mpegVersion, int sampleRate)
          Calculates the playing time and the average bitrate.
 boolean exists()
          Returns true if a Xing VBR header was found in the file passed to the constructor.
 int getAvgBitrate()
          Returns the average bit rate of the mpeg file if a Xing header exists and -1 otherwise.
 int getLength()
          Returns the length (in bytes) of this Xing VBR header.
 int getNumBytes()
          Returns the number of data bytes in the mpeg frames.
 int getNumFrames()
          Returns the number of MPEG frames in the file passed to the constructor.
 int getPlayingTime()
          Returns the approximate playing time in seconds.
 byte[] getTOC()
          Returns the toc used to seek to an area of this VBR file.
 int getVBRScale()
          Returns the VBR scale used to generate this VBR file.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XingVBRHeader

public XingVBRHeader(ByteBuffer header,
                     int layer,
                     int mpegVersion,
                     int sampleRate,
                     int channelMode,
                     long filesize)
              throws IOException
Looks for a Xing VBR header in the file. If it is found then that means this is a variable bit rate file and all the data in the header will be parsed. The position of the header buffer will be unchanged, and its mark will be set to its position when this method returns.

Parameters:
xingbytes - the bytes to read the xing header from
layer - the layer value read by the MPEGAudioFrameHeader
mpegVersion - the version value read by the MPEGAudioFrameHeader
sampleRate - the sample rate read by the MPEGAudioFrameHeader
channelMode - the channel mode read by the MPEGAudioFrameHeader
Throws:
IOException - if an error occurs
CorruptHeaderException - if an error occurs
Method Detail

exists

public boolean exists()
Returns true if a Xing VBR header was found in the file passed to the constructor.

Returns:
whether a Xing VBR header was found

getNumFrames

public int getNumFrames()
Returns the number of MPEG frames in the file passed to the constructor. If a header is not found, -1 is returned.

Returns:
the number of MPEG frames

getNumBytes

public int getNumBytes()
Returns the number of data bytes in the mpeg frames. If a header is not found, -1 is returned.

Returns:
the number of data bytes in the mpeg frames

getVBRScale

public int getVBRScale()
Returns the VBR scale used to generate this VBR file. If a header is not found, -1 is returned.

Returns:
the VBR scale used to generate this VBR file

getTOC

public byte[] getTOC()
Returns the toc used to seek to an area of this VBR file. If a header is not found an empty array is returned.

Returns:
the toc used to seek to an area of this VBR file

getLength

public int getLength()
Returns the length (in bytes) of this Xing VBR header.

Returns:
the length of this Xing VBR header

calc

protected void calc(int layer,
                    int mpegVersion,
                    int sampleRate)
Calculates the playing time and the average bitrate.

Parameters:
layer - the layer value read by the MPEGAudioFrameHeader
mpegVersion - the version value read by the MPEGAudioFrameHeader
sampleRate - the sample rate read by the MPEGAudioFrameHeader

getAvgBitrate

public int getAvgBitrate()
Returns the average bit rate of the mpeg file if a Xing header exists and -1 otherwise.

Specified by:
getAvgBitrate in interface VBRHeader
Returns:
the average bit rate (in kbps)

getPlayingTime

public int getPlayingTime()
Description copied from interface: VBRHeader
Returns the approximate playing time in seconds.

Specified by:
getPlayingTime in interface VBRHeader

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a string representation of this object

Mp3dings 
20100427