helliker.id3
Class MPEGAudioFrameHeader

java.lang.Object
  extended byhelliker.id3.MPEGAudioFrameHeader

public class MPEGAudioFrameHeader
extends java.lang.Object


Field Summary
private  int bitRate
           
private  int[][] bitrateTable
           
private  java.lang.String[] channelLabels
           
private  int channelMode
           
private  boolean copyrighted
           
private  boolean crced
           
private  int emphasis
           
private  java.lang.String[] emphasisLabels
           
private  int frameLength
           
private  int HEADER_SIZE
           
private  int layer
           
private  java.lang.String[] layerLabels
           
private  long location
           
static int MONO_MODE
           
private  java.io.File mp3
           
static int MPEG_L_1
           
static int MPEG_L_2
           
static int MPEG_L_3
           
static int MPEG_V_1
           
static int MPEG_V_2
           
static int MPEG_V_25
           
private  boolean original
           
private  boolean padding
           
private  boolean privateBit
           
private  int sampleRate
           
private  int[][] sampleTable
           
private  int[] slotLength
           
private  int version
           
private  java.lang.String[] versionLabels
           
private  XingVBRHeader xingHead
           
 
Constructor Summary
MPEGAudioFrameHeader(java.io.File mp3)
          Create an MPEGAudioFrameHeader from the file specified.
MPEGAudioFrameHeader(java.io.File mp3, int offset)
          Create an MPEGAudioFrameHeader from the file specified.
 
Method Summary
private  void findBitRate(int bitrateIndex)
          Based on the bitrate index found in the header, try to find and set the bitrate from the table.
private  long findFrame(java.io.RandomAccessFile raf, int offset)
          Searches through the file and finds the first occurrence of an mpeg frame.
private  void findSampleRate(int sampleIndex)
          Based on the sample rate index found in the header, attempt to lookup and set the sample rate from the table.
 int getBitRate()
          Returns the bitrate of this mpeg.
 java.lang.String getChannelMode()
          Return the channel mode of the mpeg in string form.
 java.lang.String getEmphasis()
          Returns the emphasis.
 int getFrameLength()
          Computes the length of the frame found.
 java.lang.String getLayer()
          Return the layer description of the mpeg in string form.
 long getLocation()
          Returns the offset at which the first mpeg frame was found in the file.
 int getSampleRate()
          Returns the sample rate of the mpeg in Hz
 int getVBRPlayingTime()
          If this is a VBR file, return an accurate playing time of this mpeg.
 java.lang.String getVersion()
          Return the version of the mpeg in string form.
 boolean hasPadding()
          Returns true if the mpeg frames are padded in this file.
 boolean isCopyrighted()
          Returns true if the audio is copyrighted
 boolean isMP3()
          Returns true if the file passed to the constructor is an mp3 (MPEG layer III).
 boolean isOriginal()
          Returns true if this is the original media
 boolean isProtected()
          Returns true if this mpeg is protected by CRC
 boolean isVBR()
           
 boolean privateBitSet()
          Returns true if the private bit is set.
private  void readHeader(java.io.RandomAccessFile raf, long location)
          Read in all the information found in the mpeg header.
 java.lang.String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MPEG_V_25

public static final int MPEG_V_25
See Also:
Constant Field Values

MPEG_V_2

public static final int MPEG_V_2
See Also:
Constant Field Values

MPEG_V_1

public static final int MPEG_V_1
See Also:
Constant Field Values

MPEG_L_3

public static final int MPEG_L_3
See Also:
Constant Field Values

MPEG_L_2

public static final int MPEG_L_2
See Also:
Constant Field Values

MPEG_L_1

public static final int MPEG_L_1
See Also:
Constant Field Values

MONO_MODE

public static final int MONO_MODE
See Also:
Constant Field Values

HEADER_SIZE

private final int HEADER_SIZE
See Also:
Constant Field Values

bitrateTable

private final int[][] bitrateTable

sampleTable

private final int[][] sampleTable

versionLabels

private final java.lang.String[] versionLabels

layerLabels

private final java.lang.String[] layerLabels

channelLabels

private final java.lang.String[] channelLabels

emphasisLabels

private final java.lang.String[] emphasisLabels

slotLength

private final int[] slotLength

xingHead

private XingVBRHeader xingHead

mp3

private java.io.File mp3

version

private int version

layer

private int layer

bitRate

private int bitRate

sampleRate

private int sampleRate

channelMode

private int channelMode

copyrighted

private boolean copyrighted

crced

private boolean crced

original

private boolean original

privateBit

private boolean privateBit

emphasis

private int emphasis

location

private long location

frameLength

private int frameLength

padding

private boolean padding
Constructor Detail

MPEGAudioFrameHeader

public MPEGAudioFrameHeader(java.io.File mp3)
                     throws NoMPEGFramesException,
                            java.io.FileNotFoundException,
                            java.io.IOException,
                            CorruptHeaderException
Create an MPEGAudioFrameHeader from the file specified. Upon creation information will be read in from the first frame header the object encounters in the file.

Parameters:
mp3 - the file to read from
Throws:
NoMPEGFramesException - if the file is not a valid mpeg
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs
CorruptHeaderException - if an error occurs

MPEGAudioFrameHeader

public MPEGAudioFrameHeader(java.io.File mp3,
                            int offset)
                     throws NoMPEGFramesException,
                            java.io.FileNotFoundException,
                            java.io.IOException,
                            CorruptHeaderException
Create an MPEGAudioFrameHeader from the file specified. Upon creation information will be read in from the first frame header the object encounters in the file. The offset tells the object where to start searching for an MPEG frame. If you know the size of an id3v2 tag attached to the file and pass it to this ctor, it will take less time to find the frame.

Parameters:
mp3 - the file to read from
offset - the offset to start searching from
Throws:
NoMPEGFramesException - if the file is not a valid mpeg
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs
CorruptHeaderException - if an error occurs
Method Detail

findFrame

private long findFrame(java.io.RandomAccessFile raf,
                       int offset)
                throws java.io.IOException
Searches through the file and finds the first occurrence of an mpeg frame. Returns the location of the header of the frame.

Parameters:
raf - the open file to find the frame in
offset - the offset to start searching from
Returns:
the location of the header of the frame
Throws:
java.io.IOException - if an error occurs

readHeader

private void readHeader(java.io.RandomAccessFile raf,
                        long location)
                 throws java.io.IOException,
                        CorruptHeaderException
Read in all the information found in the mpeg header.

Parameters:
raf - the open file to find the frame in
location - the location of the header (found by findFrame)
Throws:
CorruptHeaderException - if an error occurs
java.io.IOException - if an error occurs

findBitRate

private void findBitRate(int bitrateIndex)
Based on the bitrate index found in the header, try to find and set the bitrate from the table.

Parameters:
bitrateIndex - the bitrate index read from the header

findSampleRate

private void findSampleRate(int sampleIndex)
Based on the sample rate index found in the header, attempt to lookup and set the sample rate from the table.

Parameters:
sampleIndex - the sample rate index read from the header

getFrameLength

public int getFrameLength()
Computes the length of the frame found. This is not necessarily constant for all frames.

Returns:
the length of the frame found

toString

public java.lang.String toString()
Return a string representation of this object. Includes all information read in.

Returns:
a string representation of this object

getVersion

public java.lang.String getVersion()
Return the version of the mpeg in string form. Ex: MPEG Version 1.0

Returns:
the version of the mpeg

getLayer

public java.lang.String getLayer()
Return the layer description of the mpeg in string form. Ex: Layer III

Returns:
the layer description of the mpeg

getChannelMode

public java.lang.String getChannelMode()
Return the channel mode of the mpeg in string form. Ex: Joint Stereo (STEREO)

Returns:
the channel mode of the mpeg

getSampleRate

public int getSampleRate()
Returns the sample rate of the mpeg in Hz

Returns:
the sample rate of the mpeg in Hz

isCopyrighted

public boolean isCopyrighted()
Returns true if the audio is copyrighted

Returns:
true if the audio is copyrighted

isProtected

public boolean isProtected()
Returns true if this mpeg is protected by CRC

Returns:
true if this mpeg is protected by CRC

isOriginal

public boolean isOriginal()
Returns true if this is the original media

Returns:
true if this is the original media

isVBR

public boolean isVBR()

getEmphasis

public java.lang.String getEmphasis()
Returns the emphasis. I don't know what this means, it just does it...

Returns:
the emphasis

getLocation

public long getLocation()
Returns the offset at which the first mpeg frame was found in the file.

Returns:
the offset of the mpeg data

isMP3

public boolean isMP3()
Returns true if the file passed to the constructor is an mp3 (MPEG layer III).

Returns:
true if the file is an mp3

hasPadding

public boolean hasPadding()
Returns true if the mpeg frames are padded in this file.

Returns:
true if the mpeg frames are padded in this file

privateBitSet

public boolean privateBitSet()
Returns true if the private bit is set.

Returns:
true if the private bit is set

getVBRPlayingTime

public int getVBRPlayingTime()
If this is a VBR file, return an accurate playing time of this mpeg. If this is not a VBR file -1 is returned.

Returns:
an accurate playing time of this mpeg

getBitRate

public int getBitRate()
Returns the bitrate of this mpeg. If it is a VBR file the average bitrate is returned.

Returns:
the bitrate of this mpeg (in kbps)


Copyright © 2004 NeurosDBM Dev Team All Rights Reserved.