%Copyright (C) 2007-2015  Brian Langenberger
%This work is licensed under the
%Creative Commons Attribution-Share Alike 3.0 United States License.
%To view a copy of this license, visit
%http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
%Creative Commons,
%171 Second Street, Suite 300,
%San Francisco, California, 94105, USA.

\chapter{MP3}
MP3 is the de-facto standard for lossy audio.
It is little more than a series of MPEG frames with an
optional ID3v2 metadata header and optional ID3v1 metadata
footer.

MP3 decoders are assumed to be very tolerant of anything in
the stream that doesn't look like an MPEG frame, ignoring such
junk until the next frame is found.
Since MP3 files have no standard container format in which
non-MPEG data can be placed, metadata such as ID3 tags are often
made `sync-safe' by formatting them in a way that decoders won't
confuse tags for MPEG frames.
\section{the MP3 File Stream}
\begin{figure}[h]
\includegraphics{figures/mp3/stream.pdf}
\end{figure}
\begin{table}[h]
\begin{tabular}{|c||l||l||r|r|r||l|}
\hline
& & & \multicolumn{3}{c||}{Sample Rate} & \\
bits & MPEG ID & Description & MPEG-1 & MPEG-2 & MPEG-2.5 & Channels \\
\hline
\texttt{00} & MPEG-2.5 & reserved & 44100 & 22050 & 11025 & Stereo \\
\texttt{01} & reserved & Layer III & 48000 & 24000 & 12000 & Joint stereo \\
\texttt{10} & MPEG-2 & Layer II & 32000 & 16000 & 8000 & Dual channel stereo\\
\texttt{11} & MPEG-1 & Layer I & reserved & reserved & reserved & Mono \\
\hline
\end{tabular}
\end{table}
\par
\noindent
Layer I frames always contain 384 samples.
Layer II and Layer III frames always contain 1152 samples.
If the \VAR{Protection} bit is 0, the frame header is followed by a
16 bit CRC.

\pagebreak

\begin{table}[h]
{\relsize{-2}
\begin{tabular}{|c||r|r|r|r|r|}
\hline
& MPEG-1 & MPEG-1 & MPEG-1 & MPEG-2 & MPEG-2 \\
bits & Layer-1 & Layer-2 & Layer-3 & Layer-1 & Layer-2/3 \\
\hline
\texttt{0000} & free & free & free & free & free \\
\texttt{0001} & 32 & 32 & 32 & 32 & 8 \\
\texttt{0010} & 64 & 48 & 40 & 48 & 16 \\
\texttt{0011} & 96 & 56 & 48 & 56 & 24 \\
\texttt{0100} & 128 & 64 & 56 & 64 & 32 \\
\texttt{0101} & 160 & 80 & 64 & 80 & 40 \\
\texttt{0110} & 192 & 96 & 80 & 96 & 48 \\
\texttt{0111} & 224 & 112 & 96 & 112 & 56 \\
\texttt{1000} & 256 & 128 & 112 & 128 & 64 \\
\texttt{1001} & 288 & 160 & 128 & 144 & 80 \\
\texttt{1010} & 320 & 192 & 160 & 160 & 96 \\
\texttt{1011} & 352 & 224 & 192 & 176 & 112 \\
\texttt{1100} & 384 & 256 & 224 & 192 & 128 \\
\texttt{1101} & 416 & 320 & 256 & 224 & 144 \\
\texttt{1110} & 448 & 384 & 320 & 256 & 160 \\
\texttt{1111} & bad & bad & bad & bad & bad \\
\hline
\end{tabular}
}
\caption{Bitrate in 1000 bits per second}
\end{table}
To find the total size of an MPEG frame, use one of the following
formulas:
\begin{align}
\intertext{Layer I:}
\text{Byte Length} &= \left ( \frac{12 \times \text{Bitrate}}{\text{Sample Rate}} + \text{Pad} \right ) \times 4 \\
\intertext{Layer II/III:}
\text{Byte Length} &= \frac{144 \times \text{Bitrate}}{\text{Sample Rate}} + \text{Pad}
\end{align}
For example, an MPEG-1 Layer III frame with a sampling rate of 44100,
a bitrate of 128kbps and a set pad bit is 418 bytes long, including the header.
\begin{equation}
\frac{144 \times 128000}{44100} + 1 = 418
\end{equation}

\clearpage

\subsection{the Xing Header}

An MP3 frame header contains the track's sampling rate,
bits-per-sample and number of channels.
However, because MP3 files are little more than
concatenated MPEG frames, there is no obvious place to
store the track's total length.
Since the length of each frame is a constant number of samples,
one can calculate the track length by counting the number of frames.
This method is the most accurate but is also quite slow.

For MP3 files in which all frames have the same bitrate
- also known as constant bitrate, or CBR files -
one can divide the total size of file (minus any ID3 headers/footers),
by the bitrate to determine its length.
If an MP3 file has no Xing header in its first frame,
one can assume it is CBR.

An MP3 file that does contain a Xing header in its first frame
can be assumed to be variable bitrate, or VBR.
In that case, the rate of the first frame cannot be used as a
basis to calculate the length of the entire file.
Instead, one must use the information from the Xing header
which contains that length.

All of the fields within a Xing header are big-endian.
\begin{figure}[h]
\includegraphics{figures/mp3/xing.pdf}
\end{figure}

\clearpage

\section{ID3v1 Tags}
ID3v1 tags are very simple metadata tags appended to an MP3 file.
All of the fields are fixed length, padded with NULLs if necessary,
and the text encoding is undefined.
There are two versions of ID3v1 tags.
ID3v1.1 has a track number field as a 1 byte value
at the end of the comment field.
If the byte just before the end is not null (0x00),
assume we're dealing with a classic ID3v1 tag without a
track number.

\subsection{ID3v1}

\begin{figure}[h]
\includegraphics{figures/mp3/id3v1.pdf}
\end{figure}

\subsection{ID3v1.1}

\begin{figure}[h]
\includegraphics{figures/mp3/id3v11.pdf}
\end{figure}

\clearpage

\subsection{ID3v1.1 Tag Example}
\begin{figure}[h]
  \includegraphics{figures/mp3/id3v11-example.pdf}
\end{figure}
\begin{table}[h]
  \begin{tabular}{rl}
    track title : & \texttt{some track name} \\
    artist name : & \texttt{artist's name} \\
    album name : & \texttt{album title} \\
    year : & \texttt{2012} \\
    comment : & \texttt{a lengthy comment field} \\
    track number : & \texttt{1} \\
    genre : & \texttt{0} \\
  \end{tabular}
\end{table}

\clearpage

\section{ID3v2 Tags}

The ID3v2 tag was invented to address the deficiencies in the original
ID3v1 tag.
ID3v2 comes in three similar but not entirely compatible variants:
ID3v2.2, ID3v2.3 and ID3v2.4.
All of its fields are big-endian.

\begin{figure}[h]
\includegraphics{figures/mp3/id3v2_stream.pdf}
\end{figure}
\par
\noindent
\VAR{major version} is 2 for ID3v2.2, 3 for ID3v2.3 and 4 for ID3v2.4.
\VAR{minor version} is always 0.
The four \VAR{size} fields are recombined as follows:
\begin{equation*}
  \text{ID3 Frames size} = (\text{size}_3 \times 2 ^ {21}) + (\text{size}_2 \times 2 ^ {14}) + (\text{size}_1 \times 2 ^ 7) + \text{size}_0
\end{equation*}
Splitting the field with 0 bits ensures that no size value
will appear to be an MP3 frame sync.

\clearpage

\subsection{ID3v2 Header Example}
\begin{figure}[h]
  \includegraphics{figures/mp3/id3v2_stream-example.pdf}
\end{figure}
\begin{table}[h]
  \begin{tabular}{rl}
    ID : & \texttt{"ID3"} \\
    major version : & \texttt{3} \\
    minor version : & \texttt{0} \\
    flags : & \texttt{0} \\
    $\text{size}_3$ : & \texttt{0} \\
    $\text{size}_2$ : & \texttt{0} \\
    $\text{size}_1$ : & \texttt{1} \\
    $\text{size}_0$ : & \texttt{21} \\
    ID3 Frames size : & $(0 \times 2 ^ {21}) + (0 \times 2 ^ {14}) + (1 \times 2 ^ 7) + 21 = 149$ bytes \\
  \end{tabular}
\end{table}
\par
\noindent
Which indicates this is an ID3v2.3 tag with 149 bytes of ID3v2.3 frames.
Since there is no `total number of frames' field,
we must use the size field to determine when to stop reading
additional ID3 frames.

\clearpage

\subsection{ID3v2.2 Header}

\begin{figure}[h]
\includegraphics{figures/id3v22/header.pdf}
\end{figure}
\par
\noindent
The \VAR{unsync} and \VAR{compression} flags are normally unused.

\subsection{ID3v2.2 Frames}
\begin{figure}[h]
\includegraphics{figures/id3v22/frames.pdf}
\end{figure}
\par
\noindent
\VAR{frame ID} is a 3 byte ASCII string.
\VAR{frame size} is the length of the frame data,
not including its 6 byte header.

\clearpage

\subsubsection{COM Frame}
\begin{figure}[h]
\includegraphics{figures/id3v22/com.pdf}
\end{figure}
\par
\noindent
This frame supports a lengthy string of comment text.
\VAR{encoding} is 0 for Latin-1, 1 for UCS-2,
indicating the text encoding of the \VAR{short description}
and \VAR{comment text} fields.
\VAR{language} is a 3 byte ASCII string.
\VAR{short description} is a NULL-terminated string
containing a short description of the comment.
Note that for UCS-2 comments, the NULL terminator is 2 bytes.
The remainder of the frame is the comment text itself.

\subsubsection{COM Frame Example}
\begin{figure}[h]
  \includegraphics{figures/id3v22/com-example.pdf}
\end{figure}
\begin{table}[h]
  \begin{tabular}{rl}
    encoding : & \texttt{0} (Latin-1) \\
    language : & \texttt{"eng"} \\
    short description : & \texttt{""} (empty string) \\
    comment text : & \texttt{"comment text"} \\
  \end{tabular}
\end{table}

\clearpage

\subsubsection{PIC Frame}
\begin{figure}[h]
\includegraphics{figures/id3v22/pic.pdf}
\end{figure}
\par
\noindent
This frame contains an embedded image file.
\VAR{image format} is a 3 byte string indicating the format of the image,
typically `JPG' for JPEG images or 'PNG' for PNG images.
\VAR{description} is a Latin-1 or UCS-2 encoded NULL-terminated string,
depending on if \VAR{encoding} is 0 or 1, respectively.
\VAR{picture type} is one of the following:
\begin{table}[h]
{\relsize{-1}
\begin{tabular}{|r|l||r|l|}
\hline
value & type & value & type \\
\hline
0 & other & 1 & 32x32 pixels `file icon' (PNG only) \\
2 & other file icon & 3 & cover (front) \\
4 & cover (back) & 5 & leaflet page \\
6 & media (e.g. label side of CD) & 7 & lead artist / lead performer / soloist \\
8 & artist / performer & 9 & conductor \\
10 & band / orchestra & 11 & composer \\
12 & lyricist / text writer & 13 & recording location \\
14 & during recording & 15 & during performance \\
16 & movie / video screen capture & 17 & a bright colored fish \\
18 & illustration & 19 & band / artist logotype \\
20 & publisher / studio logotype & &  \\
\hline
\end{tabular}
\caption{PIC image types}
}
\end{table}

\clearpage

\subsubsection{PIC Frame Example}
\begin{figure}[h]
  \includegraphics{figures/id3v22/pic-example.pdf}
\end{figure}
\begin{table}[h]
  \begin{tabular}{rl}
    encoding : & \texttt{0} (Latin-1) \\
    image format : & \texttt{"PNG"} \\
    image type : & \texttt{3} (front cover) \\
    description : & \texttt{"Description"} \\
\end{tabular}
\end{table}

\clearpage

\subsubsection{Text Frames}
\begin{figure}[h]
\includegraphics{figures/id3v22/t__.pdf}
\end{figure}
\par
\noindent
Frames whose ID starts with `T' are for textual information.
\VAR{encoding} is 0 for Latin-1 encoding, 1 for UCS-2 encoding.
\par
\noindent
{\relsize{-1}
\begin{tabular}{r|l}
frame ID & meaning \\
\hline
\texttt{TAL} & album / movie / show title \\
\texttt{TBP} & BPM (beats per minute) \\
\texttt{TCM} & composer \\
\texttt{TCO} & content type \\
\texttt{TCR} & copyright message \\
\texttt{TDA} & date \\
\texttt{TDY} & playlist delay \\
\texttt{TEN} & encoded by \\
\texttt{TFT} & file type \\
\texttt{TIM} & time \\
\texttt{TKE} & initial key \\
\texttt{TLA} & language(s) \\
\texttt{TLE} & length \\
\texttt{TMT} & media type \\
\texttt{TOA} & original artist(s) / performer(s) \\
\texttt{TOF} & original filename \\
\texttt{TOL} & original Lyricist(s) / text writer(s) \\
\texttt{TOR} & original release year \\
\texttt{TOT} & original album / movie / show title \\
\texttt{TP1} & lead artist(s) / performer(s) / soloist(s) / performing group \\
\texttt{TP2} & band / orchestra / accompaniment \\
\texttt{TP3} & conductor / performer refinement \\
\texttt{TP4} & interpreted, remixed, or otherwise modified by \\
\texttt{TPA} & album number / part of a set \\
\texttt{TPB} & publisher \\
\texttt{TRC} & ISRC (International Standard Recording Code) \\
\texttt{TRD} & recording dates \\
\texttt{TRK} & track number / position in set \\
\texttt{TSI} & size \\
\texttt{TSS} & software / hardware and settings used for encoding \\
\texttt{TT1} & content group description \\
\texttt{TT2} & title / songname / content description \\
\texttt{TT3} & subtitle / description refinement \\
\texttt{TXT} & lyricist / text writer \\
\texttt{TYE} & year \\
\end{tabular}
}

\clearpage

The \texttt{TRK} and \texttt{TPA} numeric fields may be extended
with the ``/'' character, indicating the field's total number.
For example, a \texttt{TRK} of ``3/5'' means the track is number
3 out of a total of 5.

\subsubsection{Text Frame Example}
\begin{figure}[h]
  \includegraphics{figures/id3v22/t__-example.pdf}
\end{figure}
\begin{table}[h]
\begin{tabular}{rl}
frame ID : & \texttt{"TT2"} (title / song name / content description) \\
encoding : & \texttt{0} (Latin-1) \\
text : & \texttt{"some track name"}
\end{tabular}
\end{table}

\subsubsection{User-Defined Text Frame}
\begin{figure}[h]
\includegraphics{figures/id3v22/txx.pdf}
\end{figure}
\par
\noindent
This frame is for user-defined text information.
\VAR{description} is a NULL-terminated string indicating
what the frame is for.
\VAR{encoding} is 0 for Latin-1 encoding, 1 for UCS-2 encoding.

\clearpage

\subsubsection{URL Frames}
\begin{figure}[h]
  \includegraphics{figures/id3v22/w__.pdf}
\end{figure}
\par
\noindent
Frames whose ID begins with `W' contain URL links to external resources.
\par
\begin{table}[h]
  \begin{tabular}{|r|l|}
    \hline
    Frame ID & Meaning \\
    \hline
    \texttt{WAF} & official audio file webpage \\
    \texttt{WAR} & official artist / performer webpage \\
    \texttt{WAS} & official audio source webpage \\
    \texttt{WCM} & commercial information \\
    \texttt{WCP} & copyright / legal information \\
    \texttt{WPB} & publishers official webpage \\
    \hline
  \end{tabular}
\end{table}
\begin{figure}[h]
  \includegraphics{figures/id3v22/wxx.pdf}
\end{figure}
\par
\noindent
This is a frame for user-defined links to external resources.
\VAR{description} is a NULL-terminated string indicating
what the frame is for.
\VAR{encoding} is 0 for Latin-1 encoding, 1 for UCS-2 encoding.

\clearpage

\subsubsection{ULT Frame}
\begin{figure}[h]
\includegraphics{figures/id3v22/ult.pdf}
\end{figure}
\par
\noindent
This frame is for unsynchronized (non-karaoke) lyrics text,
similar to a comment frame.
\VAR{encoding} is 0 for Latin-1, 1 for UCS-2.
\VAR{language} is a 3 byte ASCII string.
\VAR{short description} is a NULL-terminated string
containing a short description of the lyrics.
Note that for UCS-2 lyrics, the NULL terminator is 2 bytes.
The remainder of the frame is the lyrics text itself.

\clearpage

\subsubsection{GEO Frame}
\begin{figure}[h]
  \includegraphics{figures/id3v22/geo.pdf}
\end{figure}
\par
\noindent
This frame contains an embedded file (i.e. a ``general encapsulated object'').
\VAR{MIME Type} and \VAR{filename} are encoded as NULL-terminated
Latin-1 strings.
\VAR{description} is encoded as a Latin-1 or UCS-2 NULL-terminated
string, depending on if \VAR{encoding} is 0 or 1, respectively.
The remainder of the frame is the file's binary data.

\clearpage

\subsection{ID3v2.3 Header}
\begin{figure}[h]
\includegraphics{figures/id3v23/header.pdf}
\end{figure}
\par
\noindent
The \VAR{unsync}, \VAR{extended}, \VAR{experimental} and \VAR{footer}
flags are normally unused.

\subsection{ID3v2.3 Frames}
\begin{figure}[h]
  \includegraphics{figures/id3v23/frames.pdf}
\end{figure}
\par
\noindent
\VAR{frame ID} is a 4 byte ASCII string.
\VAR{frame size} is the length of the frame data,
not including its 10 byte header.
The \VAR{tag alter}, \VAR{file alter}, \VAR{read only},
\VAR{compression}, \VAR{encryption} and \VAR{grouping} flags
are normally unused.

\clearpage

\subsubsection{APIC Frame}
\begin{figure}[h]
\includegraphics{figures/id3v23/apic.pdf}
\end{figure}
\par
\noindent
This frame contains an embedded image file.
\VAR{MIME type} is a NULL-terminated MIME type such as ``image/jpeg''
or ``image/png''.
\VAR{description} is a Latin-1 or UCS-2 encoded NULL-terminated string,
depending on if \VAR{encoding} is 0 or 1, respectively.
\VAR{picture Type} is one of the following:
\begin{table}[h]
{\relsize{-1}
\begin{tabular}{|r|l||r|l|}
\hline
value & type & value & type \\
\hline
0 & other & 1 & 32x32 pixels `file icon' (PNG only) \\
2 & other file icon & 3 & cover (front) \\
4 & cover (back) & 5 & leaflet page \\
6 & media (e.g. label side of CD) & 7 & lead artist / lead performer / soloist \\
8 & artist / performer & 9 & conductor \\
10 & band / orchestra & 11 & composer \\
12 & lyricist / text writer & 13 & recording location \\
14 & during recording & 15 & during performance \\
16 & movie / video screen capture & 17 & a bright colored fish \\
18 & illustration & 19 & band / artist logotype \\
20 & publisher / studio logotype & &  \\
\hline
\end{tabular}
\caption{APIC image types}
}
\end{table}

\clearpage

\subsubsection{APIC Frame Example}
\begin{figure}[h]
  \includegraphics{figures/id3v23/apic-example.pdf}
\end{figure}
\begin{table}[h]
\begin{tabular}{rl}
text encoding : & \texttt{0} (Latin-1) \\
MIME type : & \texttt{"image/png"} \\
picture type : & \texttt{3} (front cover) \\
description : & \texttt{"Description"} \\
\end{tabular}
\end{table}

\clearpage

\subsubsection{Text Frames}
\begin{figure}[h]
  \includegraphics{figures/id3v23/t___.pdf}
\end{figure}
\par
\noindent
Frames beginning with `T' are text frames.
\VAR{encoding} is 0 for Latin-1 encoding, 1 for UCS-2 encoding.
\begin{table}[h]
  {\relsize{-2}
    \begin{tabular}{|c|l||c|l|}
      \hline
      ID & Meaning & ID & Meaning \\
      \hline
      \texttt{TALB} & album name &
      \texttt{TBPM} & beats-per-minute \\
      \texttt{TCOM} & composer &
      \texttt{TCON} & content type \\
      \texttt{TCOP} & copyright message &
      \texttt{TDAT} & date \\
      \texttt{TDLY} & playlist delay &
      \texttt{TENC} & encoded by \\
      \texttt{TEXT} & lyricist / text writer &
      \texttt{TFLT} & file type \\
      \texttt{TIME} & time &
      \texttt{TIT1} & content group description \\
      \texttt{TIT2} & title / songname / content description &
      \texttt{TIT3} & subtitle / description refinement \\
      \texttt{TKEY} & initial key &
      \texttt{TLAN} & language(s) \\
      \texttt{TLEN} & length &
      \texttt{TMED} & media type \\
      \texttt{TOAL} & original album / movie / show title &
      \texttt{TOFN} & original filename \\
      \texttt{TOLY} & original lyricist(s) / text writer(s) &
      \texttt{TOPE} & original artist(s) / performer(s) \\
      \texttt{TORY} & original release year &
      \texttt{TOWN} & file owner / licensee \\
      \texttt{TPE1} & lead performer(s) / soloist(s) &
      \texttt{TPE2} & band / orchestra / accompaniment \\
      \texttt{TPE3} & conductor / performer refinement &
      \texttt{TPE4} & interpreted, remixed, or otherwise modified by \\
      \texttt{TPOS} & part of a set &
      \texttt{TPUB} & publisher \\
      \texttt{TRCK} & track number / position in set &
      \texttt{TRDA} & recording dates \\
      \texttt{TRSN} & internet radio station name &
      \texttt{TRSO} & internet radio station owner \\
      \texttt{TSIZ} & size &
      \texttt{TSRC} & ISRC (International Standard Recording Code) \\
      \texttt{TSSE} & software / hardware and encoding settings &
      \texttt{TYER} & year \\
      \hline
    \end{tabular}
  }
\end{table}

\subsubsection{Text Frame Example}
\begin{figure}[h]
  \includegraphics{figures/id3v23/t___-example.pdf}
\end{figure}
\par
\noindent
\begin{tabular}{rl}
frame type : & \texttt{"TIT2"} (title / song name / content description) \\
encoding : & \texttt{0} (Latin-1) \\
text : & \texttt{"Track Name"} \\
\end{tabular}

\clearpage

\subsubsection{User-Defined Text Frame}

\begin{figure}[h]
  \includegraphics{figures/id3v23/txxx.pdf}
\end{figure}
\par
\noindent
This frame is for user-defined text information.
\VAR{description} is a NULL-terminated string indicating
what the frame is for.
\VAR{encoding} is 0 for Latin-1 encoding, 1 for UCS-2 encoding.

\subsubsection{GEOB Frame}
\begin{figure}[h]
\includegraphics{figures/id3v23/geob.pdf}
\end{figure}
This frame contains an embedded file (i.e. a ``general encapsulated object'').
\VAR{MIME type} is a NULL-terminated Latin-1 string.
\VAR{filename} and \VAR{content description} are NULL-terminated
Latin-1 or UCS-2 encoded strings, if \VAR{encoding} is 0 or 1,
respectively.
\VAR{encapsulated object} is binary file data.

\clearpage

\subsubsection{COMM Frame}
\begin{figure}[h]
\includegraphics{figures/id3v23/comm.pdf}
\end{figure}
\par
\noindent
This frame supports a lengthy string of comment text.
\VAR{encoding} is 0 for Latin-1, 1 for UCS-2.
\VAR{language} is a 3 byte ASCII string.
\VAR{description} is a NULL-terminated string
containing a short description of the comment.
Note that for UCS-2 comments, the NULL terminator is 2 bytes.
The remainder of the frame is the comment text itself.

\subsubsection{COMM Frame Example}
\begin{figure}[h]
  \includegraphics{figures/id3v23/comm-example.pdf}
\end{figure}
\begin{table}[h]
\begin{tabular}{rl}
encoding : & \texttt{0} (Latin-1) \\
language : & \texttt{"eng"} \\
description : & \texttt{""} (empty string) \\
comment text : & \texttt{"Comment Text"} \\
\end{tabular}
\end{table}

\clearpage

\subsubsection{URL Frames}
\begin{figure}[h]
\includegraphics{figures/id3v23/w___.pdf}
\end{figure}
\par
\noindent
Frames beginning with `W' are URL links to external resources.
\par
\begin{table}[h]
\begin{tabular}{|c|l|}
\hline
ID & Meaning \\
\hline
\texttt{WCOM} & commercial information \\
\texttt{WCOP} & copyright / legal information \\
\texttt{WOAF} & official audio file webpage \\
\texttt{WOAR} & official artist/performer webpage \\
\texttt{WOAS} & official audio source webpage \\
\texttt{WORS} & official internet radio station homepage \\
\texttt{WPAY} & payment \\
\texttt{WPUB} & publisher's official webpage \\
\hline
\end{tabular}
\end{table}

\subsubsection{User-Defined URL Frame}

\begin{figure}[h]
\includegraphics{figures/id3v23/wxxx.pdf}
\end{figure}
\par
\noindent
This is a frame for user-defined links to external resources.
\VAR{description} is a NULL-terminated string indicating
what the frame is for.
\VAR{encoding} is 0 for Latin-1 encoding, 1 for UCS-2 encoding.

\clearpage

\subsubsection{USLT Frame}
\begin{figure}[h]
  \includegraphics{figures/id3v23/uslt.pdf}
\end{figure}
\par
\noindent
This frame is for unsynchronized (non-karaoke) lyrics text,
similar to a comment frame.
\VAR{encoding} is 0 for Latin-1, 1 for UCS-2.
\VAR{language} is a 3 byte ASCII string.
\VAR{description} is a NULL-terminated string
containing a short description of the lyrics.
Note that for UCS-2 comments, the NULL terminator is 2 bytes.
The remainder of the frame is the lyrics text itself.

\clearpage

\subsection{ID3v2.4 Header}
\begin{figure}[h]
\includegraphics{figures/id3v24/header.pdf}
\end{figure}

\subsection{ID3v2.4 Frames}
\begin{figure}[h]
  \includegraphics{figures/id3v24/frames.pdf}
\end{figure}
\par
\noindent
The ID3v2.4 frame size field also also ``sync safe'', like the ID3v2 headers.
It also contains \VAR{tag alter}, \VAR{file alter}, \VAR{read only},
\VAR{grouping}, \VAR{compression}, \VAR{encryption}, \VAR{unsync}
and \VAR{data length} flags which are typically usused.

\clearpage

\subsubsection{APIC Frame}
\begin{figure}[h]
\includegraphics{figures/id3v24/apic.pdf}
\end{figure}
\par
\noindent
This frame contains an embedded image file.
\VAR{MIME type} is a NULL-terminated MIME type such as ``image/jpeg''
or ``image/png''.
\VAR{encoding} determines the encoding of the NULL-terminated
\VAR{description} field.
Valid encodings are \texttt{0} for Latin-1,
\texttt{1} for UTF-16,
\texttt{2} for UTF-16BE
and \texttt{3} for UTF-8.
\VAR{picture type} is one of the following:
\begin{table}[h]
{\relsize{-1}
\begin{tabular}{|r|l||r|l|}
\hline
value & type & value & type \\
\hline
0 & other & 1 & 32x32 pixels `file icon' (PNG only) \\
2 & other file icon & 3 & cover (front) \\
4 & cover (back) & 5 & leaflet page \\
6 & media (e.g. label side of CD) & 7 & lead artist / lead performer / soloist \\
8 & artist / performer & 9 & conductor \\
10 & band / orchestra & 11 & composer \\
12 & lyricist / text writer & 13 & recording location \\
14 & during recording & 15 & during performance \\
16 & movie / video screen capture & 17 & a bright colored fish \\
18 & illustration & 19 & band / artist logotype \\
20 & publisher / studio logotype & &  \\
\hline
\end{tabular}
\caption{APIC image types}
}
\end{table}

\clearpage

\subsubsection{APIC Frame Example}
\begin{figure}[h]
\includegraphics{figures/id3v24/apic-example.pdf}
\end{figure}
\begin{table}[h]
\begin{tabular}{rl}
encoding : & \texttt{0} (Latin-1) \\
MIME type : & \texttt{"image/png"} \\
picture type : & \texttt{3} (front cover) \\
description : & \texttt{"Description"} \\
\end{tabular}
\end{table}
\par
\noindent
As with all ID3v2.4 frames, the \VAR{frame size} field contains
embedded 0 bits as follows:
\begin{figure}[h]
\includegraphics{figures/id3v24/size.pdf}
\end{figure}
\par
\noindent
which indicates the frame's data size is:
\begin{equation*}
(0 \times 2 ^ {21}) + (0 \times 2 ^ {14}) + (1 \times 2 ^ {7}) + 55 = 183 \text{ bytes}
\end{equation*}

\clearpage

\subsubsection{Text Frames}
\begin{figure}[h]
  \includegraphics{figures/id3v24/t___.pdf}
\end{figure}
\par
\noindent
Frames beginning with `T' are text frames.
\VAR{encoding} is 0 for Latin-1 encoding, 1 for UTF-16 encoding,
2 for UTF-16BE encoding and 3 for UTF-8 encoding.
\begin{table}[h]
  {\relsize{-2}
    \begin{tabular}{|c|l||c|l|}
      \hline
      ID & Meaning & ID & Meaning \\
      \hline
      \texttt{TALB} & album name &
      \texttt{TBPM} & beats-per-minute \\
      \texttt{TCOM} & composer &
      \texttt{TCON} & content type \\
      \texttt{TCOP} & copyright message &
      \texttt{TDAT} & date \\
      \texttt{TDEN} & encoding time &
      \texttt{TDLY} & playlist delay \\
      \texttt{TDOR} & original release time &
      \texttt{TDRC} & recording time \\
      \texttt{TDRL} & release time &
      \texttt{TDTG} & tagging time \\
      \texttt{TENC} & encoded by &
      \texttt{TEXT} & lyricist / text writer \\
      \texttt{TFLT} & file type &
      \texttt{TIPL} & involved people list \\
      \texttt{TIT1} & content group description &
      \texttt{TIT2} & title / songname / content description \\
      \texttt{TIT3} & subtitle / description refinement &
      \texttt{TKEY} & initial key \\
      \texttt{TLAN} & language(s) &
      \texttt{TLEN} & length \\
      \texttt{TMCL} & musician credits list &
      \texttt{TMED} & media type \\
      \texttt{TMOO} & mood &
      \texttt{TOAL} & original album / movie / show title \\
      \texttt{TOFN} & original filename &
      \texttt{TOLY} & original lyricist(s) / text writer(s) \\
      \texttt{TOPE} & original artist(s) / performer(s) &
      \texttt{TOWN} & file owner / licensee \\
      \texttt{TPE1} & lead performer(s) / soloist(s) &
      \texttt{TPE2} & band / orchestra / accompaniment \\
      \texttt{TPE3} & conductor / performer refinement &
      \texttt{TPE4} & interpreted, remixed, or otherwise modified by \\
      \texttt{TPOS} & part of a set &
      \texttt{TPRO} & produced notice \\
      \texttt{TPUB} & publisher &
      \texttt{TRCK} & track number / position in set \\
      \texttt{TRSN} & internet radio station name &
      \texttt{TRSO} & internet radio station owner \\
      \texttt{TSOA} & album sort order &
      \texttt{TSOP} & performer sort order \\
      \texttt{TSOT} & title sort order &
      \texttt{TSRC} & ISRC (International Standard Recording Code) \\
      \texttt{TSSE} & software / hardware and encoding settings &
      \texttt{TSST} & set subtitle \\
      \hline
    \end{tabular}
  }
\end{table}

\clearpage

\subsubsection{Text Frame Example}
\begin{figure}[h]
  \includegraphics{figures/id3v24/t___-example.pdf}
\end{figure}
\begin{table}[h]
\begin{tabular}{rl}
frame ID : & \texttt{"TIT2"} (title / song name / content description) \\
encoding : & \texttt{0} (Latin-1) \\
text: & \texttt{"Track Name"} \\
\end{tabular}
\end{table}

\subsubsection{User-Defined Text Frame}
\begin{figure}[h]
  \includegraphics{figures/id3v24/txxx.pdf}
\end{figure}
\par
\noindent
This frame is for user-defined text information.
\VAR{encoding} is 0 for Latin-1 encoding, 1 for UTF-16 encoding,
2 for UTF-16BE encoding and 3 for UTF-8 encoding.
\VAR{description} is a NULL-terminated string indicating
what the frame is for.

\clearpage

\subsubsection{COMM Frame}
\begin{figure}[h]
\includegraphics{figures/id3v24/comm.pdf}
\end{figure}
\par
\noindent
This frame supports a lengthy string of comment text.
\VAR{encoding} determines the encoding of the NULL-terminated
\VAR{description} field and \VAR{comment text} field.
Valid encodings are \texttt{0} for Latin-1,
\texttt{1} for UTF-16,
\texttt{2} for UTF-16BE
and \texttt{3} for UTF-8.
\VAR{language} is a 3 byte ASCII string.

\subsubsection{COMM Frame Example}
\begin{figure}[h]
\includegraphics{figures/id3v24/comm-example.pdf}
\end{figure}
\begin{table}[h]
\begin{tabular}{rl}
encoding : & \texttt{0} (Latin-1) \\
language : & \texttt{"eng"} \\
description : & \texttt{""} (empty string) \\
comment text : & \texttt{"Comment Text"} \\
\end{tabular}
\end{table}

\clearpage

\subsubsection{URL Frames}
\begin{figure}[h]
\includegraphics{figures/id3v24/w___.pdf}
\end{figure}
\par
\noindent
Frames with IDs beginning with `W' are URL links to external resources.
\par
\begin{table}[h]
\begin{tabular}{|c|l|}
\hline
ID & Meaning \\
\hline
\texttt{WCOM} & commercial information \\
\texttt{WCOP} & copyright / legal information \\
\texttt{WOAF} & official audio file webpage \\
\texttt{WOAR} & official artist/performer webpage \\
\texttt{WOAS} & official audio source webpage \\
\texttt{WORS} & official internet radio station homepage \\
\texttt{WPAY} & payment \\
\texttt{WPUB} & publisher's official webpage \\
\hline
\end{tabular}
\end{table}

\clearpage

\subsubsection{User-Defined URL Frame}

\begin{figure}[h]
\includegraphics{figures/id3v24/wxxx.pdf}
\end{figure}
\par
\noindent
This is a frame for user-defined links to external resources.
\VAR{encoding} is 0 for Latin-1 encoding, 1 for UTF-16 encoding,
2 for UTF-16BE encoding and 3 for UTF-8 encoding.
\VAR{description} is a NULL-terminated string indicating
what the frame is for.

\clearpage

\subsubsection{GEOB Frame}
\begin{figure}[h]
  \includegraphics{figures/id3v24/geob.pdf}
\end{figure}
\par
\noindent
This frame contains an embedded file (i.e. a ``general encapsulated object'').
\VAR{MIME type} is a NULL-terminated Latin-1 string.
\VAR{filename} and \VAR{content description} are NULL-terminated
strings encoded as Latin-1, UTF-16, UTF-16BE or UTF-8,
depending on the \VAR{encoding field}.
\VAR{encapsulated object} is binary file data.

\clearpage

\subsubsection{USLT Frame}
\begin{figure}[h]
  \includegraphics{figures/id3v24/uslt.pdf}
\end{figure}
\par
\noindent
This frame is for unsynchronized (non-karaoke) lyrics text,
similar to a comment frame.
\VAR{language} is a 3 byte ASCII string.
\VAR{description} and \VAR{lyrics text} are a NULL-terminated strings
encoded as Latin-1, UTF-16, UTF-16BE or UTF-8,
depending on the \VAR{encoding field}.
