%Copyright (C) 2007-2014  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{M4A}
\label{m4a}
M4A is typically AAC audio in a QuickTime container stream, though
it may also contain other formats such as MPEG-1 audio.

\section{the QuickTime File Stream}
\begin{figure}[h]
\includegraphics{figures/m4a/quicktime.pdf}
\end{figure}
\par
\noindent
Unlike other chunked formats such as RIFF WAVE, QuickTime's atom chunks
may be containers for other atoms.  All of its fields are big-endian.
\subsection{a QuickTime Atom}
\begin{figure}[h]
\includegraphics{figures/m4a/atom.pdf}
\end{figure}
\VAR{Atom Type} is an ASCII string.
\VAR{Atom Length} is the length of the entire atom, including the header.
If \VAR{Atom Length} is 0, the atom continues until the end of the file.
If \VAR{Atom Length} is 1, the atom has an extended size.  This means
there is a 64-bit length field immediately after the header which is
the atom's actual size.
\begin{figure}[h]
\includegraphics{figures/m4a/atom2.pdf}
\end{figure}
\subsection{Container Atoms}
There is no flag or field to tell a QuickTime parser which
of its atoms are containers and which ones are not.
If an atom is known to be a container, one can treat its Atom Data
as a QuickTime stream and parse it in a recursive fashion.

\clearpage

\section{M4A Atoms}
\subsection{the ftyp Atom}
\begin{figure}[h]
  \includegraphics{figures/m4a/ftyp.pdf}
\end{figure}
\par
\noindent
The \VAR{major brand} and \VAR{compatible brand} fields are ASCII strings,
or NULL when compatible brand fields are exhausted.
\VAR{major brand version} is an integer.

\subsubsection{ftyp Atom Example}
\begin{figure}[h]
  \includegraphics{figures/m4a/ftyp-example.pdf}
\end{figure}
\par
\noindent
\begin{tabular}{rl}
  \textsf{length} & 32 bytes \\
  \textsf{name} & \texttt{ftyp} \\
  \textsf{major brand} & \texttt{"M4A "} \\
  \textsf{major brand version} & 0 \\
  $\textsf{compatible brand}_0$ & \texttt{"M4A "} \\
  $\textsf{compatible brand}_1$ & \texttt{"mp42"} \\
  $\textsf{compatible brand}_2$ & \texttt{"isom"} \\
  $\textsf{compatible brand}_3$ & NULL \\
\end{tabular}

\clearpage

\subsection{the moov Atom}
\begin{wrapfigure}[5]{r}{2in}
  \includegraphics{figures/m4a/moov-tree.pdf}
\end{wrapfigure}

\begin{figure}[h]
  \includegraphics{figures/m4a/moov.pdf}
\end{figure}
\par
\noindent
This is a container for \hyperref[atom:mvhd]{\ATOM{mvhd}},
\hyperref[atom:trak]{\ATOM{trak}} and
\hyperref[atom:udta]{\ATOM{udta}} atoms.

\clearpage

\subsection{the mvhd Atom}
\label{atom:mvhd}
\begin{figure}[h]
  \includegraphics{figures/m4a/mvhd.pdf}
\end{figure}
\par
\noindent
If \VAR{version} is 0, \VAR{created Mac UTC Date},
\VAR{modified Mac UTC Date} and
\VAR{duration} are 32-bit fields.  If it is 1, they are 64-bit fields.
The \VAR{created MAC UTC date} and \VAR{modified MAC UTC date} are seconds
since the Macintosh Epoch, which is 00:00:00, January 1st, 1904.\footnote{Why 1904?  It's the first leap year of the 20th century.}
To convert a Unix Epoch timestamp (seconds since January 1st, 1970) to
a Macintosh Epoch, one needs to add 24,107 days -
or \texttt{2082844800} seconds.
\VAR{Time scale} is the file's sample rate
and \VAR{duration} is the length of the file, in PCM frames.

\clearpage

\subsubsection{mvhd Atom Example}
\begin{figure}[h]
  \includegraphics{figures/m4a/mvhd-example.pdf}
\end{figure}
\par
\noindent
\begin{tabular}{rl}
  \textsf{length} & 108 bytes \\
  \textsf{name} & \texttt{mvhd} \\
  \textsf{version} & 0 \\
  \textsf{flags} & 0 \\
  \textsf{created Mac UTC date} & 3441086831 \\
  \textsf{modified Mac UTC date} & 3441086831 \\
  \textsf{time scale} & 44100 Hz \\
  \textsf{duration} & 304844 PCM frames \\
  \textsf{playback speed} & 65536 \\
  \textsf{user volume} & 256 \\
  \textsf{reserved} & 0 \\
  \textsf{WGM A} & 65536 \\
  \textsf{WGM B} & 0 \\
  \textsf{WGM U} & 0 \\
  \textsf{WGM C} & 0 \\
  \textsf{WGM D} & 65536 \\
  \textsf{WGM V} & 0 \\
  \textsf{WGM X} & 0 \\
  \textsf{WGM Y} & 0 \\
  \textsf{WGM W} & 1073741824 \\
  \textsf{QT preview} & 0 \\
  \textsf{QT still poster} & 0 \\
  \textsf{QT selection time} & 0 \\
  \textsf{QT current time} & 0 \\
  \textsf{next track ID} & 2 \\
\end{tabular}

\clearpage

\begin{wrapfigure}[5]{r}{1in}
  \includegraphics[width=1in,keepaspectratio]{figures/m4a/trak-tree.pdf}
\end{wrapfigure}
\subsection{the trak Atom}
\label{atom:trak}
\begin{minipage}[t]{4.75in}
\includegraphics[width=4.75in,keepaspectratio]{figures/m4a/trak.pdf}
\par
\noindent
This is a container for \hyperref[atom:tkhd]{\ATOM{tkhd}} and
\hyperref[atom:mdia]{\ATOM{mdia}} atoms.
\noindent
\subsection{the tkhd Atom}
\label{atom:tkhd}
\includegraphics[width=4.75in,keepaspectratio]{figures/m4a/tkhd.pdf}
\par
\noindent
As with `mvhd', if \VAR{version} is 0, \VAR{created Mac UTC Date},
\VAR{modified Mac UTC Date} and \VAR{duration} are 32-bit fields.
If it is 1, they are 64-bit fields.
\end{minipage}

\clearpage

\subsubsection{tkhd Atom Example}
\begin{figure}[h]
  \includegraphics{figures/m4a/tkhd-example.pdf}
\end{figure}
\par
\noindent
\begin{tabular}{rl}
  \textsf{length} & 92 bytes \\
  \textsf{name} & \texttt{tkhd} \\
  \textsf{version} & 0 \\
  \textsf{reserved} & 0 \\
  \textsf{track in poster} & 0 \\
  \textsf{track in preview} & 1 \\
  \textsf{track in movie} & 1 \\
  \textsf{track enabled} & 1 \\
  \textsf{created Mac UTC date} & 3441086831 \\
  \textsf{modified Mac UTC date} & 3441086831 \\
  \textsf{track ID} & 1 \\
  \textsf{reserved} & 0 \\
  \textsf{duration} & 304844 PCM frames \\
  \textsf{reserved} & 0 \\
  \textsf{video layer} & 0 \\
  \textsf{QT alternate} & 0 \\
  \textsf{volume} & 256 \\
  \textsf{reserved} & 0 \\
  \textsf{VGM Value A} & 65536 \\
  \textsf{VGM Value B} & 0 \\
  \textsf{VGM Value U} & 0 \\
  \textsf{VGM Value C} & 0 \\
  \textsf{VGM Value D} & 65536 \\
  \textsf{VGM Value V} & 0 \\
  \textsf{VGM Value X} & 0 \\
  \textsf{VGM Value Y} & 0 \\
  \textsf{VGM Value W} & 1073741824 \\
  \textsf{video width} & 0 \\
  \textsf{video height} & 0 \\
\end{tabular}

\clearpage

\begin{wrapfigure}[5]{r}{1in}
  \includegraphics[width=1in,keepaspectratio]{figures/m4a/mdia-tree.pdf}
\end{wrapfigure}
\begin{minipage}[t]{4.75in}
\subsection{the mdia Atom}
\label{atom:mdia}
\includegraphics[width=4.75in,keepaspectratio]{figures/m4a/mdia.pdf}
\par
\noindent
This is a container for \hyperref[atom:mdhd]{\ATOM{mdhd}},
\hyperref[atom:hdlr]{\ATOM{hdlr}} and
\hyperref[atom:minf]{\ATOM{minf}} atoms.

\subsection{the mdhd Atom}
\label{atom:mdhd}
\includegraphics[width=4.75in,keepaspectratio]{figures/m4a/mdhd.pdf}
\par
\noindent
The \ATOM{mdhd} atom contains track information such as samples-per-second,
track length and creation/modification times.
As with \ATOM{mvhd}, if \VAR{version} is 0, \VAR{created Mac UTC date},
\VAR{modified Mac UTC date} and \VAR{track length} are 32-bit fields.
If it is 1, they are 64-bit fields.
\VAR{language} is a set of 3, 5-bit fields which can be converted
back to ASCII by adding 96 to their values.
\end{minipage}

\clearpage

\subsubsection{mdhd Atom Example}
\begin{figure}[h]
  \includegraphics{figures/m4a/mdhd-example.pdf}
\end{figure}
\begin{figure}[h]
  \includegraphics{figures/m4a/mdhd-example2.pdf}
\end{figure}
\par
\noindent
\begin{tabular}{rl}
  \textsf{length} & 32 bytes \\
  \textsf{name} & \texttt{mdhd} \\
  \textsf{version} & 0 \\
  \textsf{flags} & 0 \\
  \textsf{create MAC UTC date} & 3441086831 \\
  \textsf{modify MAC UTC date} & 3441086831 \\
  \textsf{sample rate} & 44100 Hz \\
  \textsf{PCM frame count} & 304844 \\
  $\textsf{language}_0$ & \multicolumn{1}{r}{21 + 96 = \texttt{'u'}} \\
  $\textsf{language}_1$ & \multicolumn{1}{r}{14 + 96 = \texttt{'n'}} \\
  $\textsf{language}_2$ & \multicolumn{1}{r}{4 + 96 = \texttt{'d'}} \\
  \textsf{quality} & 0 \\
\end{tabular}
\par
\noindent
The three language fields combine to make \texttt{"und"} meaning
undefined, which is typical.

\clearpage

\subsection{the hdlr Atom}
\label{atom:hdlr}
\begin{figure}[h]
\includegraphics{figures/m4a/hdlr.pdf}
\end{figure}
\par
\noindent
\VAR{QuickTime flags}, \VAR{QuickTime flags mask} and
\VAR{component name length}
are integers.  The rest are ASCII strings.

\subsubsection{hdlr Atom Example}
\begin{figure}[h]
\includegraphics{figures/m4a/hdlr-example.pdf}
\end{figure}
\begin{tabular}{rl}
  \textsf{length} & 34 bytes \\
  \textsf{name} & \texttt{hdlr} \\
  \textsf{version} & 0 \\
  \textsf{flags} & 0 \\
  \textsf{QuickTime type} & NULL \\
  \textsf{subtype/media} & \textsf{"soun"} \\
  \textsf{QuickTime manufacturer} & NULL \\
  \textsf{QuickTime flags} & 0 \\
  \textsf{QuickTime flags mask} & 0 \\
  \textsf{component name length} & 0 \\
  \textsf{component name} & \textsf{""} \\
\end{tabular}

\clearpage

\begin{wrapfigure}[5]{r}{1in}
  \includegraphics[width=1in,keepaspectratio]{figures/m4a/minf-tree.pdf}
\end{wrapfigure}
\begin{minipage}[t]{4.75in}
\subsection{the minf Atom}
\label{atom:minf}
\includegraphics[width=4.75in,keepaspectratio]{figures/m4a/minf.pdf}
\par
\noindent
This atom is a container for \hyperref[atom:smhd]{\ATOM{smhd}},
\hyperref[atom:dinf]{\ATOM{dinf}} and
\hyperref[atom:stbl]{\ATOM{stbl}} atoms.

\subsection{the smhd Atom}
\label{atom:smhd}
\includegraphics[width=4.75in,keepaspectratio]{figures/m4a/smhd.pdf}

\subsubsection{smhd Atom Example}
\includegraphics[width=4.75in,keepaspectratio]{figures/m4a/smhd-example.pdf}
\begin{tabular}{rl}
  \textsf{length} & 16 bytes \\
  \textsf{name} & \textsf{smhd} \\
  \textsf{version} & 0 \\
  \textsf{flags} & 0 \\
  \textsf{audio balance} & 0 \\
  \textsf{reserved} & 0 \\
\end{tabular}
\end{minipage}

\clearpage

\subsection{the dinf Atom}
\label{atom:dinf}
\begin{figure}[h]
  \includegraphics{figures/m4a/dinf.pdf}
\end{figure}
\par
\noindent
This atom is a container for the \hyperref[atom:dref]{\ATOM{dref}} atom.

\subsection{the dref Atom}
\label{atom:dref}
\begin{figure}[h]
\includegraphics{figures/m4a/dref.pdf}
\end{figure}
\par
\noindent
This atom is a container for a number of reference atoms.

\subsubsection{dref Atom Example}
\begin{figure}[h]
  \includegraphics{figures/m4a/dref-example.pdf}
\end{figure}
\begin{tabular}{rl}
  \textsf{length} & 28 bytes \\
  \textsf{name} & \textsf{dref} \\
  \textsf{reference atoms} & 1 \\
\end{tabular}

\clearpage

\begin{wrapfigure}[5]{r}{1in}
  \includegraphics[width=1in,keepaspectratio]{figures/m4a/stbl-tree.pdf}
\end{wrapfigure}
\begin{minipage}[t]{4.75in}
\subsection{the stbl Atom}
\label{atom:stbl}
\includegraphics[width=4.75in,keepaspectratio]{figures/m4a/stbl.pdf}
\par
\noindent
This atom is a container for the
\hyperref[atom:stsd]{\ATOM{stsd}},
\hyperref[atom:stts]{\ATOM{stts}},
\hyperref[atom:stsc]{\ATOM{stsc}},
\hyperref[atom:stsz]{\ATOM{stsz}} and
\hyperref[atom:stco]{\ATOM{stco}} atoms.
\end{minipage}


\clearpage

\subsection{the stsd Atom}
\label{atom:stsd}
\begin{figure}[h]
\includegraphics{figures/m4a/stsd.pdf}
\end{figure}
\par
\noindent
This atom typically contains a decription atom,
which contents will vary depending on the file format.
AAC audio contains a \ATOM{mp4a} description,
Apple Lossless contains an \ATOM{alac} description
and so forth.

\subsubsection{stsd Atom Example}
\begin{figure}[h]
  \includegraphics{figures/m4a/stsd-example.pdf}
\end{figure}
\begin{tabular}{rl}
  \textsf{length} & 88 bytes \\
  \textsf{name} & \textsf{stsd} \\
  \textsf{version} & 0 \\
  \textsf{flags} & 0 \\
  \textsf{number of descriptions} & 1 \\
\end{tabular}

\clearpage

%% \subsection{the mp4a Atom}

%% The \ATOM{mp4a} atom contains information such as the number of channels
%% and bits-per-sample.  It can be found in the \ATOM{stsd} atom.

%% \begin{figure}[h]
%% \includegraphics{figures/m4a/mp4a.pdf}
%% \end{figure}

%% \clearpage

\subsection{the stts Atom}
\label{atom:stts}
\begin{figure}[h]
  \includegraphics{figures/m4a/stts.pdf}
\end{figure}
\par
\noindent
This atom is for storing stream block sizes.
\subsubsection{stts Atom Example}
\begin{figure}[h]
  \includegraphics{figures/m4a/stts-example.pdf}
\end{figure}
\par
\noindent
\begin{tabular}{rl}
  \textsf{length} & 32 bytes \\
  \textsf{name} & \texttt{stts} \\
  \textsf{version} & 0 \\
  \textsf{flags} & 0 \\
  \textsf{number of times} & 2 \\
  $\textsf{frame count}_0$ & 74 \\
  $\textsf{duration}_0$ & 4096 PCM frames \\
  $\textsf{frame count}_1$ & 1 \\
  $\textsf{duration}_1$ & 1740 PCM frames \\
\end{tabular}
\par
\noindent
Which indicates the stream has 74 frames with 4096 PCM frames each,
and 1 frame with 1740 PCM frames, for a total of 304844 PCM frames
(which matches values stored elsewhere in the stream).

\clearpage

\subsection{the stsc Atom}
\label{atom:stsc}
\begin{figure}[h]
  \includegraphics{figures/m4a/stsc.pdf}
\end{figure}
\par
\noindent
This atom indicates how the file is split into seekable chunks.
\VAR{first chunk} is the index of the first chunk
which contains \VAR{frames per chunk} M4A or ALAC frames per
chunk and continues at that interval until the next index.

\subsubsection{stsc Atom Example}
\begin{figure}[h]
  \includegraphics{figures/m4a/stsc-example.pdf}
\end{figure}
\par
\noindent
\begin{tabular}{rl}
  \textsf{length} & 28 bytes \\
  \textsf{name} & \texttt{stsc} \\
  \textsf{number of chunks} & 1 \\
  $\textsf{first chunk}_0$ & 1 \\
  $\textsf{frames per chunk}_0$ & 5 \\
  $\textsf{sample duration index}$ & 1 \\
\end{tabular}
\par
\noindent
Which indicates that all of the file's chunks, which start from index 1,
have 5 M4A or ALAC frames.

\clearpage

\subsection{the stsz Atom}
\label{atom:stsz}
\begin{figure}[h]
  \includegraphics{figures/m4a/stsz.pdf}
\end{figure}
\par
\noindent
This atom contains a list of M4A or ALAC frame sizes,
with one size value per frame.
%% \subsubsection{stsz Atom Example}
%% \begin{figure}[h]
%%   \includegraphics{figures/m4a/stsz-example.pdf}
%% \end{figure}
%% \par
%% \noindent
%% \begin{tabular}{rl}
%%   \textsf{length} & 320 bytes \\
%%   \textsf{name} & \texttt{stsz} \\
%%   \textsf{block byte size} & 0 \\
%%   \textsf{number of frame sizes} & 75 \\
%%   $\textsf{size}_{0}$ & 3890 bytes \\
%%   $\textsf{size}_{1}$ & 3541 bytes \\
%%   $\textsf{size}_{2}$ & 3607 bytes \\
%%   $\textsf{size}_{3}$ & 3636 bytes \\
%%   $\textsf{size}_{4}$ & 3756 bytes \\
%%   $\textsf{size}_{5}$ & 3787 bytes \\
%%   $\textsf{size}_{6}$ & 4538 bytes \\
%%   $\textsf{size}_{7}$ & 5154 bytes \\
%%   $\textsf{size}_{8}$ & 5459 bytes \\
%%   $\textsf{size}_{9}$ & 5853 bytes \\
%%   $\textsf{size}_{10}$ & 6310 bytes \\
%%   $\textsf{size}_{11}$ & 6269 bytes \\
%%   $\textsf{size}_{12}$ & 5976 bytes \\
%%   $\textsf{size}_{13}$ & 5774 bytes \\
%%   $\textsf{size}_{14}$ & 5665 bytes \\
%%   $\textsf{size}_{15}$ & 5483 bytes \\
%%   $\textsf{size}_{16}$ & 5204 bytes \\
%%   $\textsf{size}_{17}$ & 4940 bytes \\
%%   $\textsf{size}_{18}$ & 4876 bytes \\
%%   $\textsf{size}_{19}$ & 4775 bytes \\
%%   $\textsf{size}_{20}$ & 4730 bytes \\
%%   $\textsf{size}_{21}$ & 4731 bytes \\
%%   $\textsf{size}_{22}$ & 4750 bytes \\
%%   $\textsf{size}_{23}$ & 4922 bytes \\
%%   $\textsf{size}_{24}$ & 4738 bytes \\
%%   $\textsf{size}_{25}$ & 5647 bytes \\
%%   $\textsf{size}_{26}$ & 6984 bytes \\
%%   $\textsf{size}_{27}$ & 7450 bytes \\
%%   $\textsf{size}_{28}$ & 7855 bytes \\
%%   $\textsf{size}_{29}$ & 8919 bytes \\
%%   $\textsf{size}_{30}$ & 9049 bytes \\
%%   $\textsf{size}_{31}$ & 8484 bytes \\
%%   $\textsf{size}_{32}$ & 6517 bytes \\
%%   $\textsf{size}_{33}$ & 6271 bytes \\
%%   $\textsf{size}_{34}$ & 6066 bytes \\
%%   $\textsf{size}_{35}$ & 5833 bytes \\
%%   $\textsf{size}_{36}$ & 5545 bytes \\
%%   $\textsf{size}_{37}$ & 5312 bytes \\
%%   $\textsf{size}_{38}$ & 5139 bytes \\
%%   $\textsf{size}_{39}$ & 5004 bytes \\
%%   $\textsf{size}_{40}$ & 4887 bytes \\
%%   $\textsf{size}_{41}$ & 4808 bytes \\
%%   $\textsf{size}_{42}$ & 4822 bytes \\
%%   $\textsf{size}_{43}$ & 7520 bytes \\
%%   $\textsf{size}_{44}$ & 8109 bytes \\
%%   $\textsf{size}_{45}$ & 9061 bytes \\
%%   $\textsf{size}_{46}$ & 9113 bytes \\
%%   $\textsf{size}_{47}$ & 9785 bytes \\
%%   $\textsf{size}_{48}$ & 9244 bytes \\
%%   $\textsf{size}_{49}$ & 8864 bytes \\
%%   $\textsf{size}_{50}$ & 8428 bytes \\
%%   $\textsf{size}_{51}$ & 8175 bytes \\
%%   $\textsf{size}_{52}$ & 7531 bytes \\
%%   $\textsf{size}_{53}$ & 7216 bytes \\
%%   $\textsf{size}_{54}$ & 7039 bytes \\
%%   $\textsf{size}_{55}$ & 6611 bytes \\
%%   $\textsf{size}_{56}$ & 6210 bytes \\
%%   $\textsf{size}_{57}$ & 5914 bytes \\
%%   $\textsf{size}_{58}$ & 5757 bytes \\
%%   $\textsf{size}_{59}$ & 5587 bytes \\
%%   $\textsf{size}_{60}$ & 5509 bytes \\
%%   $\textsf{size}_{61}$ & 5225 bytes \\
%%   $\textsf{size}_{62}$ & 5107 bytes \\
%%   $\textsf{size}_{63}$ & 4850 bytes \\
%%   $\textsf{size}_{64}$ & 4607 bytes \\
%%   $\textsf{size}_{65}$ & 4600 bytes \\
%%   $\textsf{size}_{66}$ & 4566 bytes \\
%%   $\textsf{size}_{67}$ & 4367 bytes \\
%%   $\textsf{size}_{68}$ & 4376 bytes \\
%%   $\textsf{size}_{69}$ & 4313 bytes \\
%%   $\textsf{size}_{70}$ & 4116 bytes \\
%%   $\textsf{size}_{71}$ & 4143 bytes \\
%%   $\textsf{size}_{72}$ & 3873 bytes \\
%%   $\textsf{size}_{73}$ & 4029 bytes \\
%%   $\textsf{size}_{74}$ & 1636 bytes \\
%% \end{tabular}

\clearpage

\subsection{the stco Atom}
\label{atom:stco}
\begin{figure}[h]
  \includegraphics{figures/m4a/stco.pdf}
\end{figure}
\par
\noindent
Offsets point to an absolute position in the file,
which will be the start of frames in the \ATOM{mdat} atom.
\subsubsection{stco Atom Example}
\begin{figure}[h]
  \includegraphics{figures/m4a/stco-example.pdf}
\end{figure}
\par
\noindent
{\relsize{-2}
\begin{tabular}{rl}
  \textsf{length} & 76 bytes \\
  \textsf{name} & \texttt{stco} \\
  \textsf{version} & 0 \\
  \textsf{flags} & 0 \\
  \textsf{number of offsets} & 15 \\
  $\textsf{offset}_{0}$ & \texttt{0x2000} \\
  $\textsf{offset}_{1}$ & \texttt{0x67FE} \\
  $\textsf{offset}_{2}$ & \texttt{0xC8D5} \\
  $\textsf{offset}_{3}$ & \texttt{0x13DFF} \\
  $\textsf{offset}_{4}$ & \texttt{0x1A0BD} \\
  $\textsf{offset}_{5}$ & \texttt{0x1FDFC} \\
  $\textsf{offset}_{6}$ & \texttt{0x28DF3} \\
  $\textsf{offset}_{7}$ & \texttt{0x31C16} \\
  $\textsf{offset}_{8}$ & \texttt{0x384E7} \\
  $\textsf{offset}_{9}$ & \texttt{0x3FAA9} \\
  $\textsf{offset}_{10}$ & \texttt{0x4AE9C} \\
  $\textsf{offset}_{11}$ & \texttt{0x54491} \\
  $\textsf{offset}_{12}$ & \texttt{0x5BA10} \\
  $\textsf{offset}_{13}$ & \texttt{0x61CE2} \\
  $\textsf{offset}_{14}$ & \texttt{0x673B0} \\
\end{tabular}
}

\clearpage

\subsection{the utda Atom}
\label{atom:udta}
\begin{figure}[h]
  \includegraphics{figures/m4a/udta.pdf}
\end{figure}
\par
\noindent
This atom is a container for the \hyperref[atom:meta]{\ATOM{meta}} atom.

\subsection{the meta Atom}
\label{atom:meta}
\begin{figure}[h]
  \includegraphics{figures/m4a/meta.pdf}
\end{figure}
\begin{wrapfigure}[3]{r}{1.5in}
  \includegraphics{figures/m4a/meta_atoms.pdf}
\end{wrapfigure}
\par
\noindent
This atom is a container for
\hyperref[atom:hdlr]{\ATOM{hdlr}},
\hyperref[atom:ilst]{\ATOM{ilst}} and
\hyperref[atom:free]{\ATOM{free}} atoms.
Note that unlike other containers, \ATOM{meta} has \VAR{version}
and \VAR{flags} fields prior to its sub-atoms.

\clearpage

\subsection{the ilst Atom}
\label{atom:ilst}
\begin{figure}[h]
  \includegraphics{figures/m4a/ilst.pdf}
\end{figure}
\par
\noindent
Text \ATOM{data} atoms have a \VAR{type} of 1
and their names are often prefixed by the \texttt{0xA9} byte
which indicates that the value of \VAR{metadata} is UTF-8 encoded text.
Binary data atoms typically have a \VAR{type} of 0
which indicates \VAR{metadata} is something else.
\begin{table}[h]
  \begin{tabular}{rlrl}
    \textsf{atom name} & meaning & \textsf{atom name} & meaning \\
    \hline
    \texttt{alb} & album name & \texttt{ART} & track artist \\
    \texttt{cmt} & comments & \texttt{covr} & cover image \\
    \texttt{cpil} & compilation & \texttt{cprt} & copyright \\
    \texttt{day} & year & \texttt{disk} & disc number \\
    \texttt{gnre} & genre & \texttt{grp} & grouping \\
    \texttt{----} & iTunes-specific & \texttt{nam} & track name \\
    \texttt{rtng} & rating & \texttt{tmpo} & BMP \\
    \texttt{too} & encoder & \texttt{trkn} & track number \\
    \texttt{wrt} & composer \\
  \end{tabular}
\end{table}

\clearpage

\subsubsection{the trkn Sub-Atom}
\begin{figure}[h]
\includegraphics{figures/m4a/trkn.pdf}
\end{figure}
\par
\noindent
\ATOM{trkn} is a binary sub-atom of \ATOM{ilst} which contains
the file's track number and track total.

\subsubsection{the disk Sub-Atom}
\begin{figure}[h]
\includegraphics{figures/m4a/disk.pdf}
\end{figure}
\par
\noindent
\ATOM{disk} is a binary sub-atom of \ATOM{ilst} which contains
the file's disc number and disc total.

\clearpage

\subsubsection{meta Atom Example}
\begin{figure}[h]
\includegraphics[height=6in]{figures/m4a/meta-example.pdf}
\end{figure}

\clearpage

\subsubsection{nam Atom Example}
\includegraphics{figures/m4a/nam-example.pdf}
\par
\noindent
\begin{tabular}{rl}
  \textsf{atom name} & \texttt{ nam} \\
  \textsf{type} & 1 (text) \\
  \textsf{metadata} & \texttt{"Track Name"} (UTF-8 encoded text) \\
\end{tabular}

\subsubsection{alb Atom Example}
\includegraphics{figures/m4a/alb-example.pdf}
\par
\noindent
\begin{tabular}{rl}
  \textsf{atom name} & \texttt{ alb} \\
  \textsf{type} & 1 (text) \\
  \textsf{metadata} & \texttt{"Album Name"} (UTF-8 encoded text) \\
\end{tabular}

\subsubsection{trkn Atom Example}
\includegraphics{figures/m4a/trkn-example.pdf}
\par
\noindent
\begin{tabular}{rl}
  \textsf{atom name} & \texttt{trkn} \\
  \textsf{type} & 0 (binary) \\
  \textsf{track number} : & \texttt{1} \\
  \textsf{total tracks} : & \texttt{2} \\
\end{tabular}

\subsubsection{disk Atom Example}
\includegraphics{figures/m4a/disk-example.pdf}
\par
\noindent
\begin{tabular}{rl}
  \textsf{atom name} & \texttt{disk} \\
  \textsf{type} & 0 (binary) \\
  \textsf{track number} : & \texttt{3} \\
  \textsf{total tracks} : & \texttt{4} \\
\end{tabular}

\clearpage

\subsection{the free Atom}
\label{atom:free}
\begin{figure}[h]
  \includegraphics{figures/m4a/free.pdf}
\end{figure}
\par
\noindent
This atom is a collection of NULL bytes which are easy
to resize in order to accomodate more data
in the \ATOM{meta} atom without having to change
its size and rewrite the whole file.

\subsection{the mdat Atom}
\begin{figure}[h]
  \includegraphics{figures/m4a/mdat.pdf}
\end{figure}
\par
\noindent
This atom is contains the file's audio data frames.
