Fields Summary |
---|
private static final int | BYTE_1Constants for MP3 Frame header, each frame has a basic header of
4 bytes |
private static final int | BYTE_2 |
private static final int | BYTE_3 |
private static final int | BYTE_4 |
public static final int | HEADER_SIZE |
public static final int | SYNC_SIZESync Value to identify the start of an MPEGFrame |
public static final int | SYNC_BYTE1 |
public static final int | SYNC_BYTE2 |
public static final int | SYNC_BIT_ANDSAMPING_BYTE3 |
private static final byte[] | header |
public static final Map | mpegVersionMapConstants for MPEG Version |
public static final int | VERSION_2_5 |
public static final int | VERSION_2 |
public static final int | VERSION_1 |
public static final Map | mpegLayerMapConstants for MPEG Layer |
public static final int | LAYER_I |
public static final int | LAYER_II |
public static final int | LAYER_III |
public static final int | LAYER_I_SLOT_SIZESlot Size is dependent on Layer |
public static final int | LAYER_II_SLOT_SIZE |
public static final int | LAYER_III_SLOT_SIZE |
private static final Map | bitrateMapBit Rates, the setBitrate varies for different Version and Layer |
public static final Map | modeMapConstants for Channel mode |
public static final int | MODE_STEREO |
public static final int | MODE_JOINT_STEREO |
public static final int | MODE_DUAL_CHANNEL |
public static final int | MODE_MONO |
private static final Map | emphasisMapConstants for Emphasis |
public static final int | EMPHASIS_NONE |
public static final int | EMPHASIS_5015MS |
public static final int | EMPHASIS_RESERVED |
public static final int | EMPHASIS_CCITT |
private static final Map | modeExtensionMap |
private static final int | MODE_EXTENSION_NONE |
private static final int | MODE_EXTENSION_ONE |
private static final int | MODE_EXTENSION_TWO |
private static final int | MODE_EXTENSION_THREE |
private static final Map | modeExtensionLayerIIIMap |
private static final int | MODE_EXTENSION_OFF_OFF |
private static final int | MODE_EXTENSION_ON_OFF |
private static final int | MODE_EXTENSION_OFF_ON |
private static final int | MODE_EXTENSION_ON_ON |
private static final Map | samplingRateMapSampling Rate in Hz |
private static final Map | samplingV1Map |
private static final Map | samplingV2Map |
private static final Map | samplingV25Map |
private static final Map | samplesPerFrameMap |
private static final Map | samplesPerFrameV1Map |
private static final Map | samplesPerFrameV2Map |
private static final Map | samplesPerFrameV25Map |
private static final int | SCALE_BY_THOUSAND |
private static final int | LAYER_I_FRAME_SIZE_COEFFICIENT |
private static final int | LAYER_II_FRAME_SIZE_COEFFICIENT |
private static final int | LAYER_III_FRAME_SIZE_COEFFICIENT |
private static final int | MASK_MP3_IDMP3 Frame Header bit mask |
private static final int | MASK_MP3_VERSIONMP3 version, confusingly for MP3s the version is 1. |
private static final int | MASK_MP3_LAYERMP3 Layer, for MP3s the Layer is 3 |
private static final int | MASK_MP3_PROTECTIONDoes it include a CRC Checksum at end of header, this can be used to check the header. |
private static final int | MASK_MP3_BITRATEThe setBitrate of this MP3 |
private static final int | MASK_MP3_FREQUENCYThe sampling/frequency rate |
private static final int | MASK_MP3_PADDINGAn extra padding bit is sometimes used to make sure frames are exactly the right length |
private static final int | MASK_MP3_PRIVACYPrivate bit set, for application specific |
private static final int | MASK_MP3_MODEChannel Mode, Stero/Mono/Dual Channel |
private static final int | MASK_MP3_MODE_EXTENSIONMP3 Frame Header bit mask |
private static final int | MASK_MP3_COPYMP3 Frame Header bit mask |
private static final int | MASK_MP3_HOMEMP3 Frame Header bit mask |
private static final int | MASK_MP3_EMPHASISMP3 Frame Header bit mask |
private byte[] | mpegBytes |
private int | versionThe version of this MPEG frame (see the constants) |
private String | versionAsString |
private int | layerContains the mpeg layer of this frame (see constants) |
private String | layerAsString |
private Integer | bitRateBitrate of this frame |
private int | channelModeChannel Mode of this Frame (see constants) |
private String | channelModeAsStringChannel Mode of this Frame As English String |
private int | emphasisEmphasis of this frame |
private String | emphasisAsStringEmphasis mode string |
private String | modeExtensionMode Extension |
private boolean | isPaddingFlag indicating if this frame has padding byte |
private boolean | isCopyrightedFlag indicating if this frame contains copyrighted material |
private boolean | isOriginalFlag indicating if this frame contains original material |
private boolean | isProtectedFlag indicating if this frame is protected |
private boolean | isPrivateFlag indicating if this frame is private |
private Integer | samplingRate |
Methods Summary |
---|
public java.lang.Integer | getBitRate()
return bitRate;
|
public int | getChannelMode()
return channelMode;
|
public java.lang.String | getChannelModeAsString()
return channelModeAsString;
|
public int | getEmphasis()
return emphasis;
|
public java.lang.String | getEmphasisAsString()
return emphasisAsString;
|
public int | getFrameLength()
switch (version)
{
case VERSION_2:
case VERSION_2_5:
switch (layer)
{
case LAYER_I:
return (LAYER_I_FRAME_SIZE_COEFFICIENT * (getBitRate() * SCALE_BY_THOUSAND) / getSamplingRate() + getPaddingLength()) * LAYER_I_SLOT_SIZE;
case LAYER_II:
return (LAYER_II_FRAME_SIZE_COEFFICIENT ) * (getBitRate() * SCALE_BY_THOUSAND) / getSamplingRate() + getPaddingLength() * LAYER_II_SLOT_SIZE;
case LAYER_III:
if (this.getChannelMode() == MODE_MONO)
{
return (LAYER_III_FRAME_SIZE_COEFFICIENT / 2 ) * (getBitRate() * SCALE_BY_THOUSAND) / getSamplingRate() + getPaddingLength() * LAYER_III_SLOT_SIZE;
}
else
{
return (LAYER_III_FRAME_SIZE_COEFFICIENT) * (getBitRate() * SCALE_BY_THOUSAND) / getSamplingRate() + getPaddingLength() * LAYER_III_SLOT_SIZE;
}
default:
throw new RuntimeException("Mp3 Unknown Layer:" + layer);
}
case VERSION_1:
switch (layer)
{
case LAYER_I:
return (LAYER_I_FRAME_SIZE_COEFFICIENT * (getBitRate() * SCALE_BY_THOUSAND) / getSamplingRate() + getPaddingLength()) * LAYER_I_SLOT_SIZE;
case LAYER_II:
return LAYER_II_FRAME_SIZE_COEFFICIENT * (getBitRate() * SCALE_BY_THOUSAND) / getSamplingRate() + getPaddingLength() * LAYER_II_SLOT_SIZE;
case LAYER_III:
return LAYER_III_FRAME_SIZE_COEFFICIENT * (getBitRate() * SCALE_BY_THOUSAND) / getSamplingRate() + getPaddingLength() * LAYER_III_SLOT_SIZE;
default:
throw new RuntimeException("Mp3 Unknown Layer:" + layer);
}
default:
throw new RuntimeException("Mp3 Unknown Version:" + version);
}
|
public int | getLayer()Gets the layerVersion attribute of the MPEGFrame object
return layer;
|
public java.lang.String | getLayerAsString()
return layerAsString;
|
public java.lang.String | getModeExtension()
return modeExtension;
|
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
Integer noOfSamples = samplesPerFrameMap.get(version).get(layer);
return noOfSamples;
|
public int | getNumberOfChannels()Gets the number of channels
switch (channelMode)
{
case MODE_DUAL_CHANNEL:
return 2;
case MODE_JOINT_STEREO:
return 2;
case MODE_MONO:
return 1;
case MODE_STEREO:
return 2;
default:
return 0;
}
|
public int | getPaddingLength()Gets the paddingLength attribute of the MPEGFrame object
if (isPadding())
{
return 1;
}
else
{
return 0;
}
|
public java.lang.Integer | getSamplingRate()
return samplingRate;
|
public int | getVersion()Gets the mPEGVersion attribute of the MPEGFrame object
return version;
|
public java.lang.String | getVersionAsString()
return versionAsString;
|
public boolean | isCopyrighted()
return isCopyrighted;
|
public static boolean | isMPEGFrame(java.nio.ByteBuffer bb)Gets the MPEGFrame attribute of the MPEGFrame object
int position = bb.position();
return (((bb.get(position) & SYNC_BYTE1) == SYNC_BYTE1)
&& ((bb.get(position + 1) & SYNC_BYTE2) == SYNC_BYTE2)
&& ((bb.get(position + 2) & SYNC_BIT_ANDSAMPING_BYTE3) != SYNC_BIT_ANDSAMPING_BYTE3));
|
public boolean | isOriginal()
return isOriginal;
|
public boolean | isPadding()
return isPadding;
|
public boolean | isPrivate()
return isPrivate;
|
public boolean | isProtected()
return isProtected;
|
public boolean | isVariableBitRate()
return false;
|
public static org.jaudiotagger.audio.mp3.MPEGFrameHeader | parseMPEGHeader(java.nio.ByteBuffer bb)Parse the MPEGFrameHeader of an MP3File, file pointer returns at end of the frame header
int position = bb.position();
bb.get(header, 0, HEADER_SIZE);
bb.position(position);
MPEGFrameHeader frameHeader = new MPEGFrameHeader(header);
return frameHeader;
|
private void | setBitrate()Get the setBitrate of this frame
/* BitRate, get by checking header setBitrate bits and MPEG Version and Layer */
int bitRateIndex = mpegBytes[BYTE_3] & MASK_MP3_BITRATE | mpegBytes[BYTE_2] & MASK_MP3_ID | mpegBytes[BYTE_2] & MASK_MP3_LAYER;
bitRate = bitrateMap.get(bitRateIndex);
if (bitRate == null)
{
throw new InvalidAudioFrameException("Invalid bitrate");
}
|
private void | setChannelMode()Set the Mpeg channel mode of this frame as a constant (see constants)
channelMode = (mpegBytes[BYTE_4] & MASK_MP3_MODE) >>> 6;
channelModeAsString = modeMap.get(channelMode);
if (channelModeAsString == null)
{
throw new InvalidAudioFrameException("Invalid channel mode");
}
|
private void | setCopyrighted()Gets the copyrighted attribute of the MPEGFrame object
isCopyrighted = (mpegBytes[BYTE_4] & MASK_MP3_COPY) != 0;
|
private void | setEmphasis()Get the setEmphasis mode of this frame in a string representation
emphasis = mpegBytes[BYTE_4] & MASK_MP3_EMPHASIS;
emphasisAsString = emphasisMap.get(emphasis);
if (getEmphasisAsString() == null)
{
throw new InvalidAudioFrameException("Invalid emphasis");
}
|
private void | setLayer()Get the layer version of this frame as a constant int value (see constants)
layer = (mpegBytes[BYTE_2] & MASK_MP3_LAYER) >>> 1;
layerAsString = mpegLayerMap.get(layer);
if (layerAsString == null)
{
throw new InvalidAudioFrameException("Invalid Layer");
}
|
private void | setModeExtension()Sets the string representation of the mode extension of this frame
int index = (mpegBytes[BYTE_4] & MASK_MP3_MODE_EXTENSION) >> 4;
if (layer == LAYER_III)
{
modeExtension = modeExtensionLayerIIIMap.get(index);
if (getModeExtension() == null)
{
throw new InvalidAudioFrameException("Invalid Mode Extension");
}
}
else
{
modeExtension = modeExtensionMap.get(index);
if (getModeExtension() == null)
{
throw new InvalidAudioFrameException("Invalid Mode Extension");
}
}
|
private void | setOriginal()Sets the original attribute of the MPEGFrame object
isOriginal = (mpegBytes[BYTE_4] & MASK_MP3_HOME) != 0;
|
private void | setPadding()Set whether this frame uses padding bytes
isPadding = (mpegBytes[BYTE_3] & MASK_MP3_PADDING) != 0;
|
private void | setPrivate()Sets the private attribute of the MPEGFrame object
isPrivate = (mpegBytes[BYTE_3] & MASK_MP3_PRIVACY) != 0;
|
private void | setProtected()Sets the protected attribute of the MPEGFrame object
isProtected = (mpegBytes[BYTE_2] & MASK_MP3_PROTECTION) == 0x00;
|
private void | setSamplingRate()set the sampling rate in Hz of this frame
//Frequency
int index = (mpegBytes[BYTE_3] & MASK_MP3_FREQUENCY) >>> 2;
Map<Integer, Integer> samplingRateMapForVersion = samplingRateMap.get(version);
if (samplingRateMapForVersion == null)
{
throw new InvalidAudioFrameException("Invalid version");
}
samplingRate = samplingRateMapForVersion.get(index);
if (samplingRate == null)
{
throw new InvalidAudioFrameException("Invalid sampling rate");
}
|
private void | setVersion()Set the version of this frame as an int value (see constants)
//MPEG Version
version = (byte) ((mpegBytes[BYTE_2] & MASK_MP3_VERSION) >> 3);
versionAsString = mpegVersionMap.get(version);
if (versionAsString == null)
{
throw new InvalidAudioFrameException("Invalid mpeg version");
}
|
public java.lang.String | toString()
return " mpeg frameheader:" + " frame length:" + getFrameLength() + " version:" + versionAsString + " layer:" + layerAsString + " channelMode:" + channelModeAsString + " noOfSamples:" + getNoOfSamples() + " samplingRate:" + samplingRate + " isPadding:" + isPadding + " isProtected:" + isProtected + " isPrivate:" + isPrivate + " isCopyrighted:" + isCopyrighted + " isOriginal:" + isCopyrighted + " isVariableBitRate" + this.isVariableBitRate() + " header as binary:" + AbstractTagDisplayFormatter.displayAsBinary(mpegBytes[BYTE_1]) + " " + AbstractTagDisplayFormatter.displayAsBinary(mpegBytes[BYTE_2]) + " " + AbstractTagDisplayFormatter.displayAsBinary(mpegBytes[BYTE_3]) + " " + AbstractTagDisplayFormatter.displayAsBinary(mpegBytes[BYTE_4]);
|