|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.farng.mp3.MP3File
How is MP3 built? |
Most people with a little knowledge in MP3 files know that the sound is divided into smaller parts and compressed with a psycoacoustic model. This smaller pieces of the audio is then put into something called 'frames', which is a little datablock with a header. I'll focus on that header in this text. The header is 4 bytes, 32 bits, big and begins with something called sync. This sync is, at least according to the MPEG standard, 12 set bits in a row. Some add-on standards made later uses 11 set bits and one cleared bit. The sync is directly followed by a ID bit, indicating if the file is a MPEG-1 och MPEG-2 file. 0=MPEG-2 and 1=MPEG-1 The layer is defined with the two layers bits. They are oddly defined as
With this information and the information in the bitrate field we can determine the bitrate of the audio (in kbit/s) according to this table.
The sample rate is described in the frequency field. These values is dependent of which MPEG standard is used according to the following table.
Three bits is not needed in the decoding process at all. These are the copyright bit, original home bit and the private bit. The copyright has the same meaning as the copyright bit on CDs and DAT tapes, i.e. telling that it is illegal to copy the contents if the bit is set. The original home bit indicates, if set, that the frame is located on its original media. No one seems to know what the privat bit is good for. If the protection bit is NOT set then the frame header is followed by a 16 bit checksum, inserted before the audio data. If the padding bit is set then the frame is padded with an extra byte. Knowing this the size of the complete frame can be calculated with the following formula FrameSize = 144 * BitRate / SampleRate FrameSize = (144 * BitRate / SampleRate) + 1 The frameSize is of course an integer. If for an example BitRate=128000, SampleRate=44100 and the padding bit is cleared, then the FrameSize = 144 * 128000 / 44100 = 417 The mode field is used to tell which sort of stereo/mono encoding that has been used. The purpose of the mode extension field is different for different layers, but I really don't know exactly what it's for.
The last field is the emphasis field. It is used to sort of 're-equalize' the sound after a Dolby-like noise supression. This is not very used and will probably never be. The following noise supression model is used
|
Constructor Summary | |
MP3File()
Creates a new empty MP3File object that is not associated with a specific file. |
|
MP3File(java.io.File file)
Creates a new MP3File object and parse the tag from the given file Object. |
|
MP3File(java.io.File file,
boolean writeable)
Creates a new MP3File object and parse the tag from the given file Object. |
|
MP3File(MP3File copyObject)
Creates a new MP3File object. |
|
MP3File(java.lang.String filename)
Creates a new MP3File object and parse the tag from the given filename. |
Method Summary | |
boolean |
adjustID3v2Padding()
Adjust the lenght of the ID3v2 padding at the beginning of the MP3 file referred to in this object. |
boolean |
adjustID3v2Padding(int paddingSize,
boolean willShorten,
boolean copyID3v2Tag)
Adjust the length of the ID3v2 padding at the beginning of the MP3 file this object refers to. |
boolean |
adjustID3v2Padding(int paddingSize,
boolean willShorten,
boolean copyID3v2Tag,
java.io.File file)
Adjust the length of the ID3v2 padding at the beginning of the MP3 file this object refers to. |
void |
delete(AbstractMP3Tag mp3tag)
|
int |
getBitRate()
|
byte |
getEmphasis()
|
FilenameTag |
getFilenameTag()
Sets the filename tag for this MP3 File. |
java.util.List |
getFrameAcrossTags(java.lang.String identifier)
Gets the frames from all four (id3v1, lyrics3, filename, id3v2) mp3 tags in this instance for each tag that exists. |
double |
getFrequency()
|
ID3v1 |
getID3v1Tag()
Returns the ID3v1 tag for this object. |
AbstractID3v2 |
getID3v2Tag()
Returns the ID3v2 tag for this object. |
byte |
getLayer()
|
AbstractLyrics3 |
getLyrics3Tag()
Returns the ID3v1 tag for this object. |
byte |
getMode()
|
byte |
getModeExtension()
|
java.io.File |
getMp3file()
|
long |
getMp3StartByte()
Returns the byte position of the first MP3 Frame that this object refers to. |
long |
getMp3StartByte(java.io.File file)
Returns the byte position of the first MP3 Frame that the file arguement refers to. |
byte |
getMpegVersion()
|
java.util.Set |
getUnsynchronizedFragments()
Returns a HashSet of unsynchronized fragments across all tags in this object. |
boolean |
hasFilenameTag()
Returns true if this object contains an filename pseudo-tag |
boolean |
hasID3v1Tag()
Returns true if this object contains an Id3v1 tag |
boolean |
hasID3v2Tag()
Returns true if this object contains an Id3v2 tag |
boolean |
hasLyrics3Tag()
Returns true if this object contains an Lyrics3 tag |
boolean |
isCopyProtected()
|
boolean |
isHome()
|
boolean |
isPadding()
|
boolean |
isPrivacy()
|
boolean |
isProtection()
|
boolean |
isUnsynchronized()
Returns true if there are any unsynchronized tags in this object. |
boolean |
isVariableBitRate()
|
void |
save()
Saves the tags in this object to the file referred to by this object. |
void |
save(java.io.File file)
Saves the tags in this object to the file argument. |
void |
save(java.io.File file,
int saveMode)
Saves the tags in this object to the file argument. |
void |
save(int saveMode)
Saves the tags in this object to the file referred to by this object. |
void |
save(java.lang.String filename)
Saves the tags in this object to the file argument. |
void |
save(java.lang.String filename,
int saveMode)
Saves the tags in this object to the file argument. |
boolean |
seekMP3Frame()
Returns true if the first MP3 frame can be found for the MP3 file that this object refers to. |
boolean |
seekMP3Frame(java.io.RandomAccessFile seekFile)
Returns true if the first MP3 frame can be found for the MP3 file argument. |
void |
setFilenameTag(FilenameTag filenameTag)
Sets the filename tag for this MP3 File. |
void |
setFrameAcrossTags(AbstractID3v2Frame frame)
Sets all four (id3v1, lyrics3, filename, id3v2) tags in this instance to the frame argument if the
tag exists. |
void |
setID3v1Tag(AbstractMP3Tag mp3tag)
Sets the ID3v1 tag for this object. |
void |
setID3v1Tag(ID3v1 id3v1tag)
|
void |
setID3v2Tag(AbstractID3v2 id3v2tag)
|
void |
setID3v2Tag(AbstractMP3Tag mp3tag)
Sets the ID3v2 tag for this object. |
void |
setLyrics3Tag(AbstractLyrics3 lyrics3tag)
|
void |
setLyrics3Tag(AbstractMP3Tag mp3tag)
Sets the Lyrics3 tag for this object. |
void |
setMp3file(java.io.File mp3file)
|
void |
setVariableBitRate(boolean variableBitRate)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MP3File()
public MP3File(MP3File copyObject)
public MP3File(java.lang.String filename) throws java.io.IOException, TagException
filename
- MP3 file
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public MP3File(java.io.File file) throws java.io.IOException, TagException
file
- MP3 file
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public MP3File(java.io.File file, boolean writeable) throws java.io.IOException, TagException
file
- MP3 filewriteable
- open in read (false) or read-write (true) mode
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.Method Detail |
public int getBitRate()
public boolean isCopyProtected()
public byte getEmphasis()
public void setFilenameTag(FilenameTag filenameTag)
TagUtilities.parseFileName
and
TagUtilities.createID3v2Tag
for more information about parsing file names into ID3v2_4
objects.
filenameTag
- parsed ID3v2_4
filename tagpublic FilenameTag getFilenameTag()
TagUtilities.parseFileName
and
TagUtilities.createID3v2Tag
for more information about parsing file names into ID3v2_4
objects.
ID3v2_4
filename tagpublic void setFrameAcrossTags(AbstractID3v2Frame frame)
frame
argument if the
tag exists. This method does not use the options inside the tagOptions
object.
frame
- frame to set / replace in all four tags.public java.util.List getFrameAcrossTags(java.lang.String identifier)
tagOptions
object.
identifier
- ID3v2.4 Tag Frame Identifier.
ID3v2_4Frame
. The nature of the code returns the array in a specific order, but this order
is not guaranteed for future versions of this library.public double getFrequency()
public boolean isHome()
public void setID3v1Tag(AbstractMP3Tag mp3tag)
ID3v1
tag for this object. A new ID3v1_1
object is created from the argument
and then used here.
mp3tag
- Any MP3Tag object can be used and will be converted into a new ID3v1_1 object.public void setID3v1Tag(ID3v1 id3v1tag)
public ID3v1 getID3v1Tag()
ID3v1
tag for this object.
ID3v1
tag for this objectpublic void setID3v2Tag(AbstractMP3Tag mp3tag)
ID3v2
tag for this object. A new ID3v2_4
object is created from the argument
and then used here.
mp3tag
- Any MP3Tag object can be used and will be converted into a new ID3v2_4 object.public void setID3v2Tag(AbstractID3v2 id3v2tag)
public AbstractID3v2 getID3v2Tag()
ID3v2
tag for this object.
ID3v2
tag for this objectpublic byte getLayer()
public void setLyrics3Tag(AbstractMP3Tag mp3tag)
Lyrics3
tag for this object. A new Lyrics3v2
object is created from the
argument and then used here.
mp3tag
- Any MP3Tag object can be used and will be converted into a new Lyrics3v2 object.public void setLyrics3Tag(AbstractLyrics3 lyrics3tag)
public AbstractLyrics3 getLyrics3Tag()
ID3v1
tag for this object.
ID3v1
tag for this objectpublic byte getMode()
public byte getModeExtension()
public long getMp3StartByte() throws java.io.IOException, java.io.FileNotFoundException
java.io.IOException
- on any I/O error
java.io.FileNotFoundException
- if the file exists but is a directory rather than a regular file or cannot be
opened for any other reasonpublic long getMp3StartByte(java.io.File file) throws java.io.IOException, java.io.FileNotFoundException
file
arguement refers to. This is the
first byte of music data and not the ID3 Tag Frame.
file
- MP3 file to search
java.io.IOException
- on any I/O error
java.io.FileNotFoundException
- if the file exists but is a directory rather than a regular file or cannot be
opened for any other reasonpublic void setMp3file(java.io.File mp3file)
public java.io.File getMp3file()
public byte getMpegVersion()
public boolean isPadding()
public boolean isPrivacy()
public boolean isProtection()
public boolean isUnsynchronized()
public java.util.Set getUnsynchronizedFragments()
public void setVariableBitRate(boolean variableBitRate)
public boolean isVariableBitRate()
public boolean adjustID3v2Padding() throws java.io.FileNotFoundException, java.io.IOException, TagException
ID3v2
tag in
this object. The old file will be deleted, and the new file renamed. All parameters will be taken from the
tagOptions
object.
java.io.FileNotFoundException
- if the file exists but is a directory rather than a regular file or cannot be
opened for any other reason
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public boolean adjustID3v2Padding(int paddingSize, boolean willShorten, boolean copyID3v2Tag) throws java.io.FileNotFoundException, java.io.IOException, TagException
ID3v2
tag. The old
file will be deleted, and the new file renamed.
paddingSize
- Initial padding size. This size is doubled until the ID3v2 tag will fit.willShorten
- if the newly calculated padding size is less than the padding length of the file, then news
the new shorter padding size if this is true.copyID3v2Tag
- if true, write the ID3v2
tag of this object into the file
java.io.FileNotFoundException
- if the file exists but is a directory rather than a regular file or cannot be
opened for any other reason
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public boolean adjustID3v2Padding(int paddingSize, boolean willShorten, boolean copyID3v2Tag, java.io.File file) throws java.io.FileNotFoundException, java.io.IOException, TagException
ID3v2
tag. The old
file will be deleted, and the new file renamed.
paddingSize
- Initial padding size. This size is doubled until the ID3v2 tag will fit. A paddingSize of
zero will create a padding length exactly equal to the tag size.willShorten
- Shorten the padding size by halves if the ID3v2 tag will fitcopyID3v2Tag
- if true, write the ID3v2
tag of this object into the filefile
- The file to adjust the padding length of
java.io.FileNotFoundException
- if the file exists but is a directory rather than a regular file or cannot be
opened for any other reason
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public void delete(AbstractMP3Tag mp3tag) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
public boolean hasFilenameTag()
public boolean hasID3v1Tag()
Id3v1
tag
Id3v1
tagpublic boolean hasID3v2Tag()
Id3v2
tag
Id3v2
tagpublic boolean hasLyrics3Tag()
Lyrics3
tag
Lyrics3
tagpublic void save() throws java.io.IOException, TagException
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public void save(int saveMode) throws java.io.IOException, TagException
saveMode
- write, overwrite, or append. Defined as TagConstants.MP3_FILE_SAVE_WRITE
TagConstants.MP3_FILE_SAVE_OVERWRITE TagConstants.MP3_FILE_SAVE_APPEND
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public void save(java.lang.String filename) throws java.io.IOException, TagException
filename
- file to save the this object's tags to
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public void save(java.io.File file) throws java.io.IOException, TagException
file
- file to save the this object's tags to
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public void save(java.lang.String filename, int saveMode) throws java.io.IOException, TagException
filename
- file to save the this object's tags tosaveMode
- write, overwrite, or append. Defined as TagConstants.MP3_FILE_SAVE_WRITE
TagConstants.MP3_FILE_SAVE_OVERWRITE TagConstants.MP3_FILE_SAVE_APPEND
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public void save(java.io.File file, int saveMode) throws java.io.IOException, TagException
file
- file to save the this object's tags tosaveMode
- write, overwrite, or append. Defined as TagConstants.MP3_FILE_SAVE_WRITE
TagConstants.MP3_FILE_SAVE_OVERWRITE TagConstants.MP3_FILE_SAVE_APPEND
java.io.IOException
- on any I/O error
TagException
- on any exception generated by this library.public boolean seekMP3Frame() throws java.io.IOException
java.io.IOException
- on any I/O errorpublic boolean seekMP3Frame(java.io.RandomAccessFile seekFile) throws java.io.IOException
TagOptions.getNumberMP3SyncFrame
This is the first byte of music data and not the ID3 Tag
Frame.
seekFile
- MP3 file to seek
java.io.IOException
- on any I/O error
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |