org.jaudiotagger.audio.mp3
Class MPEGFrameHeader

java.lang.Object
  extended by org.jaudiotagger.audio.mp3.MPEGFrameHeader

public class MPEGFrameHeader
extends java.lang.Object

Represents a MPEGFrameHeader, an MP3 is made up of a number of frames each frame starts with a four byte frame header.


Field Summary
private  java.lang.Integer bitRate
          Bitrate of this frame
private static java.util.Map<java.lang.Integer,java.lang.Integer> bitrateMap
          Bit Rates, the setBitrate varies for different Version and Layer
private static int BYTE_1
          Constants for MP3 Frame header, each frame has a basic header of 4 bytes
private static int BYTE_2
           
private static int BYTE_3
           
private static int BYTE_4
           
private  int channelMode
          Channel Mode of this Frame (see constants)
private  java.lang.String channelModeAsString
          Channel Mode of this Frame As English String
private  int emphasis
          Emphasis of this frame
static int EMPHASIS_5015MS
           
static int EMPHASIS_CCITT
           
static int EMPHASIS_NONE
           
static int EMPHASIS_RESERVED
           
private  java.lang.String emphasisAsString
          Emphasis mode string
private static java.util.Map<java.lang.Integer,java.lang.String> emphasisMap
          Constants for Emphasis
private static byte[] header
           
static int HEADER_SIZE
           
private  boolean isCopyrighted
          Flag indicating if this frame contains copyrighted material
private  boolean isOriginal
          Flag indicating if this frame contains original material
private  boolean isPadding
          Flag indicating if this frame has padding byte
private  boolean isPrivate
          Flag indicating if this frame is private
private  boolean isProtected
          Flag indicating if this frame is protected
private  int layer
          Contains the mpeg layer of this frame (see constants)
static int LAYER_I
           
private static int LAYER_I_FRAME_SIZE_COEFFICIENT
           
static int LAYER_I_SLOT_SIZE
          Slot Size is dependent on Layer
static int LAYER_II
           
private static int LAYER_II_FRAME_SIZE_COEFFICIENT
           
static int LAYER_II_SLOT_SIZE
           
static int LAYER_III
           
private static int LAYER_III_FRAME_SIZE_COEFFICIENT
           
static int LAYER_III_SLOT_SIZE
           
private  java.lang.String layerAsString
           
private static int MASK_MP3_BITRATE
          The setBitrate of this MP3
private static int MASK_MP3_COPY
          MP3 Frame Header bit mask
private static int MASK_MP3_EMPHASIS
          MP3 Frame Header bit mask
private static int MASK_MP3_FREQUENCY
          The sampling/frequency rate
private static int MASK_MP3_HOME
          MP3 Frame Header bit mask
private static int MASK_MP3_ID
          MP3 Frame Header bit mask
private static int MASK_MP3_LAYER
          MP3 Layer, for MP3s the Layer is 3
private static int MASK_MP3_MODE
          Channel Mode, Stero/Mono/Dual Channel
private static int MASK_MP3_MODE_EXTENSION
          MP3 Frame Header bit mask
private static int MASK_MP3_PADDING
          An extra padding bit is sometimes used to make sure frames are exactly the right length
private static int MASK_MP3_PRIVACY
          Private bit set, for application specific
private static int MASK_MP3_PROTECTION
          Does it include a CRC Checksum at end of header, this can be used to check the header.
private static int MASK_MP3_VERSION
          MP3 version, confusingly for MP3s the version is 1.
static int MODE_DUAL_CHANNEL
           
private static int MODE_EXTENSION_NONE
           
private static int MODE_EXTENSION_OFF_OFF
           
private static int MODE_EXTENSION_OFF_ON
           
private static int MODE_EXTENSION_ON_OFF
           
private static int MODE_EXTENSION_ON_ON
           
private static int MODE_EXTENSION_ONE
           
private static int MODE_EXTENSION_THREE
           
private static int MODE_EXTENSION_TWO
           
static int MODE_JOINT_STEREO
           
static int MODE_MONO
           
static int MODE_STEREO
           
private  java.lang.String modeExtension
          Mode Extension
private static java.util.Map<java.lang.Integer,java.lang.String> modeExtensionLayerIIIMap
           
private static java.util.Map<java.lang.Integer,java.lang.String> modeExtensionMap
           
protected static java.util.Map<java.lang.Integer,java.lang.String> modeMap
          Constants for Channel mode
private  byte[] mpegBytes
           
static java.util.Map<java.lang.Integer,java.lang.String> mpegLayerMap
          Constants for MPEG Layer
static java.util.Map<java.lang.Integer,java.lang.String> mpegVersionMap
          Constants for MPEG Version
private static java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.lang.Integer>> samplesPerFrameMap
           
private static java.util.Map<java.lang.Integer,java.lang.Integer> samplesPerFrameV1Map
           
private static java.util.Map<java.lang.Integer,java.lang.Integer> samplesPerFrameV25Map
           
private static java.util.Map<java.lang.Integer,java.lang.Integer> samplesPerFrameV2Map
           
private  java.lang.Integer samplingRate
           
private static java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.lang.Integer>> samplingRateMap
          Sampling Rate in Hz
private static java.util.Map<java.lang.Integer,java.lang.Integer> samplingV1Map
           
private static java.util.Map<java.lang.Integer,java.lang.Integer> samplingV25Map
           
private static java.util.Map<java.lang.Integer,java.lang.Integer> samplingV2Map
           
private static int SCALE_BY_THOUSAND
           
static int SYNC_BYTE1
           
static int SYNC_BYTE2
           
static int SYNC_SIZE
          Sync Value to identify the start of an MPEGFrame
private  int version
          The version of this MPEG frame (see the constants)
static int VERSION_1
           
static int VERSION_2
           
static int VERSION_2_5
           
private  java.lang.String versionAsString
           
 
Constructor Summary
private MPEGFrameHeader()
          Hide Constructor
private MPEGFrameHeader(byte[] b)
          Try and create a new MPEG frame with the given byte array and decodes its contents If decoding header causes a problem it is not a valid header
 
Method Summary
 java.lang.Integer getBitRate()
           
 int getChannelMode()
           
 java.lang.String getChannelModeAsString()
           
 int getEmphasis()
           
 java.lang.String getEmphasisAsString()
           
 int getFrameLength()
           
 int getLayer()
          Gets the layerVersion attribute of the MPEGFrame object
 java.lang.String getLayerAsString()
           
 java.lang.String getModeExtension()
           
 int getNoOfSamples()
          Get the number of samples in a frame, all frames in a file have a set number of samples as defined by their MPEG Versiona and Layer
 int getNumberOfChannels()
          Gets the number of channels
 int getPaddingLength()
          Gets the paddingLength attribute of the MPEGFrame object
 java.lang.Integer getSamplingRate()
           
 int getVersion()
          Gets the mPEGVersion attribute of the MPEGFrame object
 java.lang.String getVersionAsString()
           
 boolean isCopyrighted()
           
static boolean isMPEGFrame(java.nio.ByteBuffer bb)
          Gets the MPEGFrame attribute of the MPEGFrame object
 boolean isOriginal()
           
 boolean isPadding()
           
 boolean isPrivate()
           
 boolean isProtected()
           
 boolean isVariableBitRate()
           
static MPEGFrameHeader parseMPEGHeader(java.nio.ByteBuffer bb)
          Parse the MPEGFrameHeader of an MP3File, file pointer returns at end of the frame header
private  void setBitrate()
          Get the setBitrate of this frame
private  void setChannelMode()
          Set the Mpeg channel mode of this frame as a constant (see constants)
private  void setCopyrighted()
          Gets the copyrighted attribute of the MPEGFrame object
private  void setEmphasis()
          Get the setEmphasis mode of this frame in a string representation
private  void setLayer()
          Get the layer version of this frame as a constant int value (see constants)
private  void setModeExtension()
          Sets the string representation of the mode extension of this frame
private  void setOriginal()
          Sets the original attribute of the MPEGFrame object
private  void setPadding()
          Set whether this frame uses padding bytes
private  void setPrivate()
          Sets the private attribute of the MPEGFrame object
private  void setProtected()
          Sets the protected attribute of the MPEGFrame object
private  void setSamplingRate()
          set the sampling rate in Hz of this frame
private  void setVersion()
          Set the version of this frame as an int value (see constants)
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BYTE_1

private static final int BYTE_1
Constants for MP3 Frame header, each frame has a basic header of 4 bytes

See Also:
Constant Field Values

BYTE_2

private static final int BYTE_2
See Also:
Constant Field Values

BYTE_3

private static final int BYTE_3
See Also:
Constant Field Values

BYTE_4

private static final int BYTE_4
See Also:
Constant Field Values

HEADER_SIZE

public static final int HEADER_SIZE
See Also:
Constant Field Values

SYNC_SIZE

public static final int SYNC_SIZE
Sync Value to identify the start of an MPEGFrame

See Also:
Constant Field Values

SYNC_BYTE1

public static final int SYNC_BYTE1
See Also:
Constant Field Values

SYNC_BYTE2

public static final int SYNC_BYTE2
See Also:
Constant Field Values

header

private static final byte[] header

mpegVersionMap

public static final java.util.Map<java.lang.Integer,java.lang.String> mpegVersionMap
Constants for MPEG Version


VERSION_2_5

public static final int VERSION_2_5
See Also:
Constant Field Values

VERSION_2

public static final int VERSION_2
See Also:
Constant Field Values

VERSION_1

public static final int VERSION_1
See Also:
Constant Field Values

mpegLayerMap

public static final java.util.Map<java.lang.Integer,java.lang.String> mpegLayerMap
Constants for MPEG Layer


LAYER_I

public static final int LAYER_I
See Also:
Constant Field Values

LAYER_II

public static final int LAYER_II
See Also:
Constant Field Values

LAYER_III

public static final int LAYER_III
See Also:
Constant Field Values

LAYER_I_SLOT_SIZE

public static final int LAYER_I_SLOT_SIZE
Slot Size is dependent on Layer

See Also:
Constant Field Values

LAYER_II_SLOT_SIZE

public static final int LAYER_II_SLOT_SIZE
See Also:
Constant Field Values

LAYER_III_SLOT_SIZE

public static final int LAYER_III_SLOT_SIZE
See Also:
Constant Field Values

bitrateMap

private static final java.util.Map<java.lang.Integer,java.lang.Integer> bitrateMap
Bit Rates, the setBitrate varies for different Version and Layer


modeMap

protected static final java.util.Map<java.lang.Integer,java.lang.String> modeMap
Constants for Channel mode


MODE_STEREO

public static final int MODE_STEREO
See Also:
Constant Field Values

MODE_JOINT_STEREO

public static final int MODE_JOINT_STEREO
See Also:
Constant Field Values

MODE_DUAL_CHANNEL

public static final int MODE_DUAL_CHANNEL
See Also:
Constant Field Values

MODE_MONO

public static final int MODE_MONO
See Also:
Constant Field Values

emphasisMap

private static final java.util.Map<java.lang.Integer,java.lang.String> emphasisMap
Constants for Emphasis


EMPHASIS_NONE

public static final int EMPHASIS_NONE
See Also:
Constant Field Values

EMPHASIS_5015MS

public static final int EMPHASIS_5015MS
See Also:
Constant Field Values

EMPHASIS_RESERVED

public static final int EMPHASIS_RESERVED
See Also:
Constant Field Values

EMPHASIS_CCITT

public static final int EMPHASIS_CCITT
See Also:
Constant Field Values

modeExtensionMap

private static final java.util.Map<java.lang.Integer,java.lang.String> modeExtensionMap

MODE_EXTENSION_NONE

private static final int MODE_EXTENSION_NONE
See Also:
Constant Field Values

MODE_EXTENSION_ONE

private static final int MODE_EXTENSION_ONE
See Also:
Constant Field Values

MODE_EXTENSION_TWO

private static final int MODE_EXTENSION_TWO
See Also:
Constant Field Values

MODE_EXTENSION_THREE

private static final int MODE_EXTENSION_THREE
See Also:
Constant Field Values

modeExtensionLayerIIIMap

private static final java.util.Map<java.lang.Integer,java.lang.String> modeExtensionLayerIIIMap

MODE_EXTENSION_OFF_OFF

private static final int MODE_EXTENSION_OFF_OFF
See Also:
Constant Field Values

MODE_EXTENSION_ON_OFF

private static final int MODE_EXTENSION_ON_OFF
See Also:
Constant Field Values

MODE_EXTENSION_OFF_ON

private static final int MODE_EXTENSION_OFF_ON
See Also:
Constant Field Values

MODE_EXTENSION_ON_ON

private static final int MODE_EXTENSION_ON_ON
See Also:
Constant Field Values

samplingRateMap

private static final java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.lang.Integer>> samplingRateMap
Sampling Rate in Hz


samplingV1Map

private static final java.util.Map<java.lang.Integer,java.lang.Integer> samplingV1Map

samplingV2Map

private static final java.util.Map<java.lang.Integer,java.lang.Integer> samplingV2Map

samplingV25Map

private static final java.util.Map<java.lang.Integer,java.lang.Integer> samplingV25Map

samplesPerFrameMap

private static final java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.lang.Integer>> samplesPerFrameMap

samplesPerFrameV1Map

private static final java.util.Map<java.lang.Integer,java.lang.Integer> samplesPerFrameV1Map

samplesPerFrameV2Map

private static final java.util.Map<java.lang.Integer,java.lang.Integer> samplesPerFrameV2Map

samplesPerFrameV25Map

private static final java.util.Map<java.lang.Integer,java.lang.Integer> samplesPerFrameV25Map

SCALE_BY_THOUSAND

private static final int SCALE_BY_THOUSAND
See Also:
Constant Field Values

LAYER_I_FRAME_SIZE_COEFFICIENT

private static final int LAYER_I_FRAME_SIZE_COEFFICIENT
See Also:
Constant Field Values

LAYER_II_FRAME_SIZE_COEFFICIENT

private static final int LAYER_II_FRAME_SIZE_COEFFICIENT
See Also:
Constant Field Values

LAYER_III_FRAME_SIZE_COEFFICIENT

private static final int LAYER_III_FRAME_SIZE_COEFFICIENT
See Also:
Constant Field Values

MASK_MP3_ID

private static final int MASK_MP3_ID
MP3 Frame Header bit mask

See Also:
Constant Field Values

MASK_MP3_VERSION

private static final int MASK_MP3_VERSION
MP3 version, confusingly for MP3s the version is 1.

See Also:
Constant Field Values

MASK_MP3_LAYER

private static final int MASK_MP3_LAYER
MP3 Layer, for MP3s the Layer is 3

See Also:
Constant Field Values

MASK_MP3_PROTECTION

private static final int MASK_MP3_PROTECTION
Does it include a CRC Checksum at end of header, this can be used to check the header.

See Also:
Constant Field Values

MASK_MP3_BITRATE

private static final int MASK_MP3_BITRATE
The setBitrate of this MP3

See Also:
Constant Field Values

MASK_MP3_FREQUENCY

private static final int MASK_MP3_FREQUENCY
The sampling/frequency rate

See Also:
Constant Field Values

MASK_MP3_PADDING

private static final int MASK_MP3_PADDING
An extra padding bit is sometimes used to make sure frames are exactly the right length

See Also:
Constant Field Values

MASK_MP3_PRIVACY

private static final int MASK_MP3_PRIVACY
Private bit set, for application specific

See Also:
Constant Field Values

MASK_MP3_MODE

private static final int MASK_MP3_MODE
Channel Mode, Stero/Mono/Dual Channel

See Also:
Constant Field Values

MASK_MP3_MODE_EXTENSION

private static final int MASK_MP3_MODE_EXTENSION
MP3 Frame Header bit mask

See Also:
Constant Field Values

MASK_MP3_COPY

private static final int MASK_MP3_COPY
MP3 Frame Header bit mask

See Also:
Constant Field Values

MASK_MP3_HOME

private static final int MASK_MP3_HOME
MP3 Frame Header bit mask

See Also:
Constant Field Values

MASK_MP3_EMPHASIS

private static final int MASK_MP3_EMPHASIS
MP3 Frame Header bit mask

See Also:
Constant Field Values

mpegBytes

private byte[] mpegBytes

version

private int version
The version of this MPEG frame (see the constants)


versionAsString

private java.lang.String versionAsString

layer

private int layer
Contains the mpeg layer of this frame (see constants)


layerAsString

private java.lang.String layerAsString

bitRate

private java.lang.Integer bitRate
Bitrate of this frame


channelMode

private int channelMode
Channel Mode of this Frame (see constants)


channelModeAsString

private java.lang.String channelModeAsString
Channel Mode of this Frame As English String


emphasis

private int emphasis
Emphasis of this frame


emphasisAsString

private java.lang.String emphasisAsString
Emphasis mode string


modeExtension

private java.lang.String modeExtension
Mode Extension


isPadding

private boolean isPadding
Flag indicating if this frame has padding byte


isCopyrighted

private boolean isCopyrighted
Flag indicating if this frame contains copyrighted material


isOriginal

private boolean isOriginal
Flag indicating if this frame contains original material


isProtected

private boolean isProtected
Flag indicating if this frame is protected


isPrivate

private boolean isPrivate
Flag indicating if this frame is private


samplingRate

private java.lang.Integer samplingRate
Constructor Detail

MPEGFrameHeader

private MPEGFrameHeader()
                 throws InvalidAudioFrameException
Hide Constructor

Throws:
InvalidAudioFrameException

MPEGFrameHeader

private MPEGFrameHeader(byte[] b)
                 throws InvalidAudioFrameException
Try and create a new MPEG frame with the given byte array and decodes its contents If decoding header causes a problem it is not a valid header

Parameters:
b - the array of bytes representing this mpeg frame
Throws:
InvalidAudioFrameException - if does not match expected format
Method Detail

getLayer

public int getLayer()
Gets the layerVersion attribute of the MPEGFrame object

Returns:
The layerVersion value

getLayerAsString

public java.lang.String getLayerAsString()

setCopyrighted

private void setCopyrighted()
Gets the copyrighted attribute of the MPEGFrame object


setVersion

private void setVersion()
                 throws InvalidAudioFrameException
Set the version of this frame as an int value (see constants)

Throws:
InvalidAudioFrameException

setOriginal

private void setOriginal()
Sets the original attribute of the MPEGFrame object


setProtected

private void setProtected()
Sets the protected attribute of the MPEGFrame object


setPrivate

private void setPrivate()
Sets the private attribute of the MPEGFrame object


setBitrate

private void setBitrate()
                 throws InvalidAudioFrameException
Get the setBitrate of this frame

Throws:
InvalidAudioFrameException

setChannelMode

private void setChannelMode()
                     throws InvalidAudioFrameException
Set the Mpeg channel mode of this frame as a constant (see constants)

Throws:
InvalidAudioFrameException

setEmphasis

private void setEmphasis()
                  throws InvalidAudioFrameException
Get the setEmphasis mode of this frame in a string representation

Throws:
InvalidAudioFrameException

setPadding

private void setPadding()
Set whether this frame uses padding bytes


setLayer

private void setLayer()
               throws InvalidAudioFrameException
Get the layer version of this frame as a constant int value (see constants)

Throws:
InvalidAudioFrameException

setModeExtension

private void setModeExtension()
                       throws InvalidAudioFrameException
Sets the string representation of the mode extension of this frame

Throws:
InvalidAudioFrameException

setSamplingRate

private void setSamplingRate()
                      throws InvalidAudioFrameException
set the sampling rate in Hz of this frame

Throws:
InvalidAudioFrameException

getNumberOfChannels

public int getNumberOfChannels()
Gets the number of channels

Returns:
The setChannelMode value

getChannelMode

public int getChannelMode()

getChannelModeAsString

public java.lang.String getChannelModeAsString()

getVersion

public int getVersion()
Gets the mPEGVersion attribute of the MPEGFrame object

Returns:
The mPEGVersion value

getVersionAsString

public java.lang.String getVersionAsString()

getPaddingLength

public int getPaddingLength()
Gets the paddingLength attribute of the MPEGFrame object

Returns:
The paddingLength value

getBitRate

public java.lang.Integer getBitRate()

getSamplingRate

public java.lang.Integer getSamplingRate()

getFrameLength

public int getFrameLength()

getNoOfSamples

public int getNoOfSamples()
Get the number of samples in a frame, all frames in a file have a set number of samples as defined by their MPEG Versiona and Layer

Returns:

isPadding

public boolean isPadding()

isCopyrighted

public boolean isCopyrighted()

isOriginal

public boolean isOriginal()

isProtected

public boolean isProtected()

isPrivate

public boolean isPrivate()

isVariableBitRate

public boolean isVariableBitRate()

getEmphasis

public int getEmphasis()

getEmphasisAsString

public java.lang.String getEmphasisAsString()

getModeExtension

public java.lang.String getModeExtension()

parseMPEGHeader

public static MPEGFrameHeader parseMPEGHeader(java.nio.ByteBuffer bb)
                                       throws InvalidAudioFrameException
Parse the MPEGFrameHeader of an MP3File, file pointer returns at end of the frame header

Parameters:
bb - the byte buffer containing the header
Returns:
Throws:
InvalidAudioFrameException - if there is no header at this point

isMPEGFrame

public static boolean isMPEGFrame(java.nio.ByteBuffer bb)
Gets the MPEGFrame attribute of the MPEGFrame object

Parameters:
bb -
Returns:
The mPEGFrame value

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string represntation