%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.

\section{ALAC Decoding}
\begin{wrapfigure}[6]{r}{1.5in}
\includegraphics{alac/figures/atoms.pdf}
\end{wrapfigure}
The basic process for decoding an ALAC file is as follows:
\par
\begin{wrapfigure}[6]{l}{4.5in}
{\relsize{-1}
  \input{alac/algorithms/alac_decode}
}
\par
Seeking to a particular atom within the ALAC file is a recursive
process.
Each ALAC atom is laid out as follows:
\vskip .1in
\includegraphics{alac/figures/atom.pdf}
\vskip .1in
where \VAR{atom length} is the full size of the atom in bytes,
including the 8 byte atom header.
\VAR{atom type} is an ASCII string
\VAR{atom data} is a binary blob of data
which may contain one or more sub-atoms.
\end{wrapfigure}

\clearpage

\subsection{Parsing the alac Atom}
\label{alac:read_alac_atom}
The \texttt{stsd} atom contains a single \texttt{alac} atom
which contains an \texttt{alac} sub-atom of its own.
\begin{figure}[h]
\includegraphics{alac/figures/alac_atom.pdf}
\end{figure}
\par
\noindent
Many of these fields appear redundant between the outer \texttt{alac} atom
and the inner sub-atom.
However, for proper decoding, one must ignore the outer atom entirely
and use only the parameters from the innermost \texttt{alac} atom.

Of these, we'll be interested in \VAR{samples per frame},
\VAR{bits per sample}, \VAR{history multiplier}, \VAR{initial history},
\VAR{maximum K}, \VAR{channels} and \VAR{sample rate}.
The others can safely be ignored.

\clearpage

For example, given the bytes:
\par
\begin{figure}[h]
\includegraphics{alac/figures/alac-atom-parse.pdf}
\end{figure}
\begin{tabular}{rcrcl}
$alac~length$ & $\leftarrow$ & \texttt{00000024} & = & 36 \\
$alac$ & $\leftarrow$ & \texttt{616C6163} & = & \texttt{"alac"} \\
$padding$ & $\leftarrow$ & \texttt{00000000} & = & 0 \\
samples per frame & $\leftarrow$ & \texttt{00001000} & = & 4096 \\
compatible version & $\leftarrow$ & \texttt{00} & = & 0 \\
bits per sample & $\leftarrow$ & \texttt{10} & = & 16 \\
history multiplier & $\leftarrow$ & \texttt{28} & = & 40 \\
initial history & $\leftarrow$ & \texttt{0A} & = & 10 \\
maximum K & $\leftarrow$ & \texttt{0E} & = & 14 \\
channels & $\leftarrow$ & \texttt{02} & = & 2 \\
max run & $\leftarrow$ & \texttt{FF} & = & 255 \\
max coded frame size & $\leftarrow$ & \texttt{24} & = & 36 bytes \\
bitrate & $\leftarrow$ & \texttt{0AC4} & = & 2756 \\
sample rate & $\leftarrow$ & \texttt{0000AC44} & = & 44100 Hz\\
\end{tabular}

\clearpage

\subsection{Parsing the mdhd atom}
\label{alac:read_mdhd_atom}
\begin{figure}[h]
\includegraphics{alac/figures/mdhd.pdf}
\end{figure}
\par
\noindent
\VAR{version} indicates whether the Mac UTC date fields are 32 or 64 bit.
These date fields 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 the Macintosh Epoch to a Unix Epoch timestamp
(seconds since January 1st, 1970), one needs to subtract 24,107 days -
or \texttt{2082844800} seconds.
\par
\noindent
\VAR{track length} is the total length of the ALAC file, in PCM frames.
\par
\noindent
\VAR{language} is 3, 5 bit fields encoded as ISO 639-2.
Add 96 to each field to convert the value to ASCII.

\clearpage

For example, given the bytes:
\begin{figure}[h]
\includegraphics{alac/figures/mdhd-parse.pdf}
\end{figure}
\par
\noindent
\begin{tabular}{rcrcll}
created MAC UTC date & $\leftarrow$ & \texttt{CA6BF4A9} & = & 3396072617 \\
modified MAC UTC date & $\leftarrow$ & \texttt{CA6BFF5E} & = & 3396075358 \\
sample rate & $\leftarrow$ & \texttt{0000AC44} & = & 44100 Hz \\
PCM frame count & $\leftarrow$ & \texttt{8EACE80} & = & 149606016 & \texttt{56m 32s} \\
$\text{language}_0$ & $\leftarrow$ & \texttt{15} & = & 21 & + 96 = `\texttt{u}'\\
$\text{language}_1$ & $\leftarrow$ & \texttt{0E} & = & 14 & + 96 = `\texttt{n}'\\
$\text{language}_2$ & $\leftarrow$ & \texttt{04} & = & 4 & + 96 = `\texttt{d}'\\
\end{tabular}
\vskip .15in
\par
\noindent
Note that the language field is typically \texttt{und},
meaning ``undetermined''.

\clearpage

\subsection{Decoding ALAC Frameset}
\label{alac:decode_frameset}
ALAC framesets contain multiple frames,
each of which contains 1 or 2 subframes.
\par
\noindent
\input{alac/algorithms/decode_frameset}
\begin{figure}[h]
\includegraphics{alac/figures/frameset.pdf}
\end{figure}

\clearpage

\subsection{Decoding ALAC Frame}
\label{alac:decode_frame}
{\relsize{-1}
  \input{alac/algorithms/decode_frame}
}
\begin{figure}[h]
\includegraphics{alac/figures/frame.pdf}
\end{figure}

\clearpage

\subsection{Decoding Compressed Frame}
\label{alac:decode_compressed_frame}
{\relsize{-1}
  \input{alac/algorithms/decode_compressed_frame}
}

\clearpage

\subsection{Reading Subframe Header}
\label{alac:read_subframe_header}
{\relsize{-1}
  \input{alac/algorithms/read_subframe_header}
}
\begin{figure}[h]
\includegraphics{alac/figures/subframe_header.pdf}
\end{figure}

\clearpage

For example, given the bytes on the opposite page,
our frame and subframe headers are:
\begin{table}[h]
{\relsize{-1}
\begin{tabular}{rclcl}
\multicolumn{5}{l}{frame header:} \\
\textsf{channels} & $\leftarrow$ & \texttt{0} (+1) &=& 2 \\
\textsf{has sample count} & $\leftarrow$ & \texttt{1} \\
\textsf{uncompressed LSBs} & $\leftarrow$ & \texttt{0} \\
\textsf{not compressed} & $\leftarrow$ & \texttt{0} \\
\textsf{sample count} & $\leftarrow$ & \texttt{0x19} &=& 25 \\
\textsf{interlacing shift} & $\leftarrow$ & \texttt{2} \\
\textsf{interlacing leftweight} & $\leftarrow$ & \texttt{2} \\
\hline
\multicolumn{5}{l}{subframe header 0:} \\
$\textsf{prediction type}_0$ & $\leftarrow$ & \texttt{0} \\
$\textsf{QLP shift needed}_0$ & $\leftarrow$ & \texttt{9} \\
$\textsf{Rice modifier}_0$ & $\leftarrow$ & \texttt{4} \\
$\textsf{coefficient count}_0$ & $\leftarrow$ & \texttt{4} \\
$\textsf{coefficient}_{0~0}$ & $\leftarrow$ & \texttt{0x05A6} &=& 1446 \\
$\textsf{coefficient}_{0~1}$ & $\leftarrow$ & \texttt{0xF943} &=& -1725 \\
$\textsf{coefficient}_{0~2}$ & $\leftarrow$ & \texttt{0x0430} &=& 1072 \\
$\textsf{coefficient}_{0~3}$ & $\leftarrow$ & \texttt{0xFECF} &=& -305 \\
\hline
\multicolumn{5}{l}{subframe header 1:} \\
$\textsf{prediction type}_1$ & $\leftarrow$ & \texttt{0} \\
$\textsf{QLP shift needed}_1$ & $\leftarrow$ & \texttt{9} \\
$\textsf{Rice modifier}_1$ & $\leftarrow$ & \texttt{4} \\
$\textsf{coefficient count}_1$ & $\leftarrow$ & \texttt{4} \\
$\textsf{coefficient}_{1~0}$ & $\leftarrow$ & \texttt{0x0587} &=& 1415 \\
$\textsf{coefficient}_{1~1}$ & $\leftarrow$ & \texttt{0xF987} &=& -1657 \\
$\textsf{coefficient}_{1~2}$ & $\leftarrow$ & \texttt{0x03F3} &=& 1011 \\
$\textsf{coefficient}_{1~3}$ & $\leftarrow$ & \texttt{0xFEE5} &=& -283 \\
\end{tabular}
}
\end{table}

\clearpage

\begin{figure}[h]
\includegraphics{alac/figures/subframe-parse.pdf}
\caption{mdat atom bytes}
\end{figure}

\clearpage

\subsection{Reading Residual Block}
\label{alac:read_residual_block}
{\relsize{-1}
  \input{alac/algorithms/read_residuals}
}

\clearpage

\subsubsection{Reading Residual}
\label{alac:read_residual}
\input{alac/algorithms/read_residual}

\begin{landscape}
\subsubsection{Residual Decoding Example}
For this example, \VAR{initial history} (from the \texttt{alac} atom) is 10.
\par
\begin{figure}[h]
\includegraphics{alac/figures/residual-parse.pdf}
\end{figure}
\par
\noindent
Note how unreading a bit when $i = 1$ means that $\text{LSB}_1$'s 3rd bit
(a \texttt{1} in this case) is also $\text{MSB}_2$'s 1st bit.
This is signified by $\text{}_1 \leftrightarrow \text{}_2$
since the same bit is in both fields.

\clearpage

\begin{table}[h]
{\relsize{-1}
\renewcommand{\arraystretch}{1.25}
\begin{tabular}{r||>{$}r<{$}|>{$}r<{$}|>{$}r<{$}|>{$}r<{$}|>{$}r<{$}|>{$}r<{$}}
$i$ & \kappa & \textsf{MSB}_i & \textsf{LSB}_i & \textsf{unsigned}_i &
\textsf{residual}_i & \textsf{history}_{i + 1} \\
\hline
0 &
\lfloor\log_2(10 \div 2 ^ 9 + 3)\rfloor = 1 &
9 & & 64 &
64 \div 2 = 32 &
10 + (64 \times 40) - \left\lfloor\frac{10 \times 40}{2 ^ 9}\right\rfloor = 2570
\\
1 &
\lfloor\log_2(2570 \div 2 ^ 9 + 3)\rfloor = 3 &
2 & *1 & 2 \times (2 ^ 3 - 1) = 14 &
14 \div 2 = 7 &
2570 + (14 \times 40) - \left\lfloor\frac{2570 \times 40}{2 ^ 9}\right\rfloor = 2930
\\
2 &
\lfloor\log_2(2930 \div 2 ^ 9 + 3)\rfloor = 3 &
1 & 2 & 1 \times (2 ^ 3 - 1) + (2 - 1) = 8 &
8 \div 2 = 4 &
2930 + (8 \times 40) - \left\lfloor\frac{2930 \times 40}{2 ^ 9}\right\rfloor = 3022
\\
3 &
\lfloor\log_2(3022 \div 2 ^ 9 + 3)\rfloor = 3 &
0 & 5 & 0 \times (2 ^ 3 - 1) + (5 - 1) = 4 &
4 \div 2 = 2 &
3022 + (4 \times 40) - \left\lfloor\frac{3022 \times 40}{2 ^ 9}\right\rfloor = 2946
\\
4 &
\lfloor\log_2(2946 \div 2 ^ 9 + 3)\rfloor = 3 &
0 & 2 & 0 \times (2 ^ 3 - 1) + (2 - 1) = 1 &
-((1 + 1) \div 2) = -1 &
2946 + (1 \times 40) - \left\lfloor\frac{2946 \times 40}{2 ^ 9}\right\rfloor = 2756
\\
5 &
\lfloor\log_2(2756 \div 2 ^ 9 + 3)\rfloor = 3 &
0 & 2 & 0 \times (2 ^ 3 - 1) + (2 - 1) = 1 &
-((1 + 1) \div 2) = -1 &
2756 + (1 \times 40) - \left\lfloor\frac{2756 \times 40}{2 ^ 9}\right\rfloor = 2581
\\
6 &
\lfloor\log_2(2581 \div 2 ^ 9 + 3)\rfloor = 3 &
0 & 2 & 0 \times (2 ^ 3 - 1) + (2 - 1) = 1 &
-((1 + 1) \div 2) = -1 &
2581 + (1 \times 40) - \left\lfloor\frac{2581 \times 40}{2 ^ 9}\right\rfloor = 2420
\\
7 &
\lfloor\log_2(2420 \div 2 ^ 9 + 3)\rfloor = 2 &
2 & 2 & 2 \times (2 ^ 2 - 1) + (2 - 1) = 7 &
-((7 + 1) \div 2) = -4 &
2420 + (7 \times 40) - \left\lfloor\frac{2420 \times 40}{2 ^ 9}\right\rfloor = 2511
\\
8 &
\lfloor\log_2(2511 \div 2 ^ 9 + 3)\rfloor = 2 &
0 & 2 & 0 \times (2 ^ 2 - 1) + (2 - 1) = 1 &
-((1 + 1) \div 2) = -1 &
2511 + (1 \times 40) - \left\lfloor\frac{2511 \times 40}{2 ^ 9}\right\rfloor = 2355
\\
9 &
\lfloor\log_2(2355 \div 2 ^ 9 + 3)\rfloor = 2 &
2 & 2 & 2 \times (2 ^ 2 - 1) + (2 - 1) = 7 &
-((7 + 1) \div 2) = -4 &
2355 + (7 \times 40) - \left\lfloor\frac{2355 \times 40}{2 ^ 9}\right\rfloor = 2452
\\
10 &
\lfloor\log_2(2452 \div 2 ^ 9 + 3)\rfloor = 2 &
1 & *1 & 1 \times (2 ^ 2 - 1) = 3 &
-((3 + 1) \div 2) = -2 &
2452 + (3 \times 40) - \left\lfloor\frac{2452 \times 40}{2 ^ 9}\right\rfloor = 2381
\\
11 &
\lfloor\log_2(2381 \div 2 ^ 9 + 3)\rfloor = 2 &
1 & 3 & 1 \times (2 ^ 2 - 1) + (3 - 1) = 5 &
-((5 + 1) \div 2) = -3 &
2381 + (5 \times 40) - \left\lfloor\frac{2381 \times 40}{2 ^ 9}\right\rfloor = 2395
\\
12 &
\lfloor\log_2(2395 \div 2 ^ 9 + 3)\rfloor = 2 &
0 & 2 & 0 \times (2 ^ 2 - 1) + (2 - 1) = 1 &
-((1 + 1) \div 2) = -1 &
2395 + (1 \times 40) - \left\lfloor\frac{2395 \times 40}{2 ^ 9}\right\rfloor = 2248
\\
13 &
\lfloor\log_2(2248 \div 2 ^ 9 + 3)\rfloor = 2 &
0 & 2 & 0 \times (2 ^ 2 - 1) + (2 - 1) = 1 &
-((1 + 1) \div 2) = -1 &
2248 + (1 \times 40) - \left\lfloor\frac{2248 \times 40}{2 ^ 9}\right\rfloor = 2113
\\
14 &
\lfloor\log_2(2113 \div 2 ^ 9 + 3)\rfloor = 2 &
0 & 2 & 0 \times (2 ^ 2 - 1) + (2 - 1) = 1 &
-((1 + 1) \div 2) = -1 &
2113 + (1 \times 40) - \left\lfloor\frac{2113 \times 40}{2 ^ 9}\right\rfloor = 1988
\\
15 &
\lfloor\log_2(1988 \div 2 ^ 9 + 3)\rfloor = 2 &
0 & 3 & 0 \times (2 ^ 2 - 1) + (3 - 1) = 2 &
2 \div 2 = 1 &
1988 + (2 \times 40) - \left\lfloor\frac{1988 \times 40}{2 ^ 9}\right\rfloor = 1913
\\
16 &
\lfloor\log_2(1913 \div 2 ^ 9 + 3)\rfloor = 2 &
0 & *0 & 0 \times (2 ^ 2 - 1) = 0 &
0 \div 2 = 0 &
1913 + (0 \times 40) - \left\lfloor\frac{1913 \times 40}{2 ^ 9}\right\rfloor = 1764
\\
17 &
\lfloor\log_2(1764 \div 2 ^ 9 + 3)\rfloor = 2 &
0 & *1 & 0 \times (2 ^ 2 - 1) = 0 &
0 \div 2 = 0 &
1764 + (0 \times 40) - \left\lfloor\frac{1764 \times 40}{2 ^ 9}\right\rfloor = 1627
\\
18 &
\lfloor\log_2(1627 \div 2 ^ 9 + 3)\rfloor = 2 &
2 & *1 & 2 \times (2 ^ 2 - 1) = 6 &
6 \div 2 = 3 &
1627 + (6 \times 40) - \left\lfloor\frac{1627 \times 40}{2 ^ 9}\right\rfloor = 1740
\\
19 &
\lfloor\log_2(1740 \div 2 ^ 9 + 3)\rfloor = 2 &
1 & 2 & 1 \times (2 ^ 2 - 1) + (2 - 1) = 4 &
4 \div 2 = 2 &
1740 + (4 \times 40) - \left\lfloor\frac{1740 \times 40}{2 ^ 9}\right\rfloor = 1765
\\
20 &
\lfloor\log_2(1765 \div 2 ^ 9 + 3)\rfloor = 2 &
0 & 3 & 0 \times (2 ^ 2 - 1) + (3 - 1) = 2 &
2 \div 2 = 1 &
1765 + (2 \times 40) - \left\lfloor\frac{1765 \times 40}{2 ^ 9}\right\rfloor = 1708
\\
21 &
\lfloor\log_2(1708 \div 2 ^ 9 + 3)\rfloor = 2 &
2 & 3 & 2 \times (2 ^ 2 - 1) + (3 - 1) = 8 &
8 \div 2 = 4 &
1708 + (8 \times 40) - \left\lfloor\frac{1708 \times 40}{2 ^ 9}\right\rfloor = 1895
\\
22 &
\lfloor\log_2(1895 \div 2 ^ 9 + 3)\rfloor = 2 &
0 & 3 & 0 \times (2 ^ 2 - 1) + (3 - 1) = 2 &
2 \div 2 = 1 &
1895 + (2 \times 40) - \left\lfloor\frac{1895 \times 40}{2 ^ 9}\right\rfloor = 1827
\\
23 &
\lfloor\log_2(1827 \div 2 ^ 9 + 3)\rfloor = 2 &
2 & *1 & 2 \times (2 ^ 2 - 1) = 6 &
6 \div 2 = 3 &
1827 + (6 \times 40) - \left\lfloor\frac{1827 \times 40}{2 ^ 9}\right\rfloor = 1925
\\
24 &
\lfloor\log_2(1925 \div 2 ^ 9 + 3)\rfloor = 2 &
1 & 2 & 1 \times (2 ^ 2 - 1) + (2 - 1) = 4 &
4 \div 2 = 2 &
1925 + (4 \times 40) - \left\lfloor\frac{1925 \times 40}{2 ^ 9}\right\rfloor = 1935
\\
\end{tabular}
\renewcommand{\arraystretch}{1.0}
}
\end{table}
\end{landscape}

\clearpage

\subsection{Decoding Subframe}
\label{alac:decode_subframe}
{\relsize{-1}
  \input{alac/algorithms/decode_subframe}
}

\subsubsection{The \texttt{truncate} Function}
{\relsize{-1}
  \input{alac/algorithms/truncate}
}

\clearpage

\subsubsection{The \texttt{sign} Function}
{\relsize{-1}
\begin{equation*}
\texttt{sign}(x) =
\begin{cases}
\texttt{ 1} & \text{if } x > 0 \\
\texttt{ 0} & \text{if } x = 0 \\
\texttt{-1} & \text{if } x < 0
\end{cases}
\end{equation*}
}

\subsubsection{Decoding Subframe Example}
Given the residuals
\texttt{32, 7, 4, 2, -1, -1, -1, -4, -1, -4, -2},
the QLP coefficients
\texttt{1446, -1725, 1072, -305}
and a QLP shift needed value of \texttt{9},
the subframe samples are calculated as follows:
\begin{table}[h]
{\relsize{-1}
\begin{tabular}{r||r|r|>{$}r<{$}|>{$}r<{$}|>{$}r<{$}}
$i$ & $\textsf{residual}_i$ & $\textsf{base}_i$ & \textsf{QLP sum}_i & \textsf{sample}_i & \textsf{QLP coefficient}_{(i + 1)~j} \\
\hline
0 & 32 & & & 32 \\
1 & 7 & & & 7 + 32 = 39 \\
2 & 4 & & & 4 + 39 = 43 \\
3 & 2 & & & 2 + 43 = 45 \\
4 & -1 & & & -1 + 45 = 44 \\
\hline
5 & -1 & 32 & 1446 \times (44 - 32) \texttt{ +} & \lfloor(4584 + 2 ^ 8) \div 2 ^ 9\rfloor - 1 + 32 = 40 & 1446 \\
& & & -1725 \times (45 - 32) \texttt{ +}& & -1725 \\
& & & 1072 \times (43 - 32) \texttt{ +} & & 1072 \\
& & & -305 \times (39 - 32) \texttt{~~} & & -305 - 1 = -306 \\
\hline
6 & -1 & 39 & 1446 \times (40 - 39) \texttt{ +} & \lfloor(-1971 + 2 ^ 8) \div 2 ^ 9\rfloor - 1 + 39 = 34 & 1446 \\
& & & -1725 \times (44 - 39) \texttt{ +} & & -1725 \\
& & & 1072 \times (45 - 39) \texttt{ +} & & 1072 \\
& & & -306 \times (43 - 39) \texttt{~~} & & -306 - 1 = -307 \\
\hline
7 & -4 & 43 & 1446 \times (34 - 43) \texttt{ +} & \lfloor(-7381 + 2 ^ 8) \div 2 ^ 9\rfloor - 4 + 43 = 25 & 1446 \\
& & & -1725 \times (40 - 43) \texttt{ +} & & -1725 + 1 = -1724 \\
& & & 1072 \times (44 - 43) \texttt{ +} & & 1072 - 1 = 1071 \\
& & & -307 \times (45 - 43) \texttt{~~} & & -307 - 1 = -308 \\
\hline
8 & -1 & 45 & 1446 \times (25 - 45) \texttt{ +} & \lfloor(-15003 + 2 ^ 8) \div 2 ^ 9\rfloor - 1 + 45 = 15 & 1446 \\
& & & -1724 \times (34 - 45) \texttt{ +} & & -1724 \\
& & & 1071 \times (40 - 45) \texttt{ +} & & 1071 \\
& & & -308 \times (44 - 45) \texttt{~~} & & -308 + 1 = -307 \\
\hline
9 & -4 & 44 & 1446 \times (15 - 44) \texttt{ +} & \lfloor(-18660 + 2 ^ 8) \div 2 ^ 9\rfloor - 4 + 44 = 4 & 1446 \\
& & & -1724 \times (25 - 44) \texttt{ +} & & -1724 + 1 = -1723 \\
& & & 1071 \times (34 - 44) \texttt{ +} & & 1071 + 1 = 1072 \\
& & & -307 \times (40 - 44) \texttt{~~} & & -307 + 1 = -306 \\
\hline
10 & -2 & 40 & 1446 \times (4 - 40) \texttt{ +} & \lfloor(-23225 + 2 ^ 8) \div 2 ^ 9\rfloor - 2 + 40 = -7 & 1446 \\
& & & -1723 \times (15 - 40) \texttt{ +} & & -1723 \\
& & & 1072 \times (25 - 40) \texttt{ +} & & 1072 + 1 = 1073 \\
& & & -306 \times (34 - 40) \texttt{~~} & & -306 + 1 = -305 \\
\hline
\end{tabular}
}
\end{table}

Although some steps have been omitted for brevity,
what's important to note is how the base sample
is removed prior to $\textsf{QLP sum}_i$ calculation,
how it is re-added during $\textsf{sample}_i$ calculation
and how the next sample's \textsf{QLP coefficient} values are shifted.

\clearpage

\subsection{Channel Decorrelation}
\label{alac:decorrelate_channels}
\input{alac/algorithms/channel_decorrelation}
For example, given the $\textsf{subframe}_0$ samples of 14, 15, 19, 17, 18;
the $\textsf{subframe}_1$ samples of 16, 17, 26, 25, 24,
an \VAR{interlacing shift} value of 2 and an \VAR{interlacing leftweight}
values of 3, we calculate output samples as follows:
\begin{table}[h]
\begin{tabular}{|c||>{$}r<{$}|>{$}r<{$}||>{$}r<{$}|>{$}r<{$}|}
\hline
$i$ & \textsf{subframe}_{0~i} & \textsf{subframe}_{1~i} & \textsf{right}_i & \textsf{left}_i \\
\hline
0 & 14 & 16 & 14 - \lfloor(16 \times 3) \div 2^2\rfloor = \textbf{2} & 16 + \textbf{2} = \textbf{18} \\
1 & 15 & 17 & 15 - \lfloor(17 \times 3) \div 2^2\rfloor = \textbf{3} & 17 + \textbf{3} = \textbf{20} \\
2 & 19 & 26 & 19 - \lfloor(26 \times 3) \div 2^2\rfloor = \textbf{0} & 26 + \textbf{0} = \textbf{26} \\
3 & 17 & 25 & 17 - \lfloor(25 \times 3) \div 2^2\rfloor = \textbf{-1} & 25 + \textbf{-1} = \textbf{24} \\
4 & 18 & 24 & 18 - \lfloor(24 \times 3) \div 2^2\rfloor = \textbf{0} & 24 + \textbf{0} = \textbf{24} \\
\hline
\end{tabular}
\end{table}

\subsection{Channel Assignment}
\begin{table}[h]
\begin{tabular}{r|l}
channels & assignment \\
\hline
1 & mono \\
2 & left, right \\
3 & center, left, right \\
4 & center, left, right, center surround \\
5 & center, left, right, left surround, right surround \\
6 & center, left, right, left surround, right surround, LFE \\
7 & center, left, right, left surround, right surround, center surround, LFE \\
8 & center, left center, right center, left, right, left surround, right surround, LFE \\
\end{tabular}
\end{table}
