Packet decode proceeds as follows, matching the description offered earlier in the document.
\begin{programlisting}
1) allocate and zero all vectors that will be returned.
2) if ([n\_to\_read] is zero), stop; there is no residue to decode.
3) iterate [pass] over the range 0 ... 7 {
4) [partition\_count] = 0
5) while [partition\_count] is less than [partitions\_to\_read]
6) if ([pass] is zero) {
7) iterate [j] over the range 0 .. [ch]-1 {
8) if vector [j] is not marked 'do not decode' {
9) [temp] = read from packet using codebook [residue\_classbook] in scalar context
10) iterate [i] descending over the range [classwords\_per\_codeword]-1 ... 0 {
11) array [classifications] element [j],([i]+[partition\_count]) =
[temp] integer modulo [residue\_classifications]
12) [temp] = [temp] / [residue\_classifications] using integer division
}
}
}
}
13) iterate [i] over the range 0 .. ([classwords\_per\_codeword] - 1) while [partition\_count]
is also less than [partitions\_to\_read] {
14) iterate [j] over the range 0 .. [ch]-1 {
15) if vector [j] is not marked 'do not decode' {
16) [vqclass] = array [classifications] element [j],[partition\_count]
17) [vqbook] = array [residue\_books] element [vqclass],[pass]
18) if ([vqbook] is not 'unused') {
19) decode partition into output vector number [j], starting at scalar
offset [limit\_residue\_begin]+[partition\_count]*[residue\_partition\_size] using
codebook number [vqbook] in VQ context
}
}
20) increment [partition\_count] by one
}
}
}
21) done
\end{programlisting}
An end-of-packet condition during packet decode is to be considered a
nominal occurrence. Decode returns the result of vector decode up to
that point.
\subsubsection{format 0 specifics}
Format zero decodes partitions exactly as described earlier in the
'Residue Format: residue 0' section. The following pseudocode
presents the same algorithm. Assume:
\begin{itemize}
\item\varname{[n]} is the value in \varname{[residue\_partition\_size]}
\item\varname{[v]} is the residue vector
\item\varname{[offset]} is the beginning read offset in [v]
\end{itemize}
\begin{programlisting}
1) [step] = [n] / [codebook\_dimensions]
2) iterate [i] over the range 0 ... [step]-1 {
3) vector [entry\_temp] = read vector from packet using current codebook in VQ context
4) iterate [j] over the range 0 ... [codebook\_dimensions]-1 {
5) vector [v] element ([offset]+[i]+[j]*[step]) =
vector [v] element ([offset]+[i]+[j]*[step]) +
vector [entry\_temp] element [j]
}
}
6) done
\end{programlisting}
\subsubsection{format 1 specifics}
Format 1 decodes partitions exactly as described earlier in the
'Residue Format: residue 1' section. The following pseudocode
presents the same algorithm. Assume:
\begin{itemize}
\item\varname{[n]} is the value in
\varname{[residue\_partition\_size]}
\item\varname{[v]} is the residue vector
\item\varname{[offset]} is the beginning read offset in [v]
\end{itemize}
\begin{programlisting}
1) [i] = 0
2) vector [entry\_temp] = read vector from packet using current codebook in VQ context
3) iterate [j] over the range 0 ... [codebook\_dimensions]-1 {
4) vector [v] element ([offset]+[i]) =
vector [v] element ([offset]+[i]) +
vector [entry\_temp] element [j]
5) increment [i]
}
6) if ( [i] is less than [n] ) continue at step 2
7) done
\end{programlisting}
\subsubsection{format 2 specifics}
Format 2 is reducible to format 1. It may be implemented as an additional step prior to and an additional post-decode step after a normal format 1 decode.
Format 2 handles 'do not decode' vectors differently than residue 0 or
1; if all vectors are marked 'do not decode', no decode occurrs.
However, if at least one vector is to be decoded, all the vectors are
decoded. We then request normal format 1 to decode a single vector
representing all output channels, rather than a vector for each
channel. After decode, deinterleave the vector into independent vectors, one for each output channel. That is:
\begin{enumerate}
\item If all vectors 0 through \emph{ch}-1 are marked 'do not decode', allocate and clear a single vector \varname{[v]}of length \emph{ch*n} and skip step 2 below; proceed directly to the post-decode step.
\item Rather than performing format 1 decode to produce \emph{ch} vectors of length \emph{n} each, call format 1 decode to produce a single vector \varname{[v]} of length \emph{ch*n}.
\item Post decode: Deinterleave the single vector \varname{[v]} returned by format 1 decode as described above into \emph{ch} independent vectors, one for each outputchannel, according to:
\begin{programlisting}
1) iterate [i] over the range 0 ... [n]-1 {
2) iterate [j] over the range 0 ... [ch]-1 {
3) output vector number [j] element [i] = vector [v] element ([i] * [ch] + [j])