///|
/// Decode residue for the given channels.
fn decode_residue(
br : BitReader,
residue : VorbisResidueConfig,
codebooks : Array[VorbisCodebook],
n : Int,
ch : Int,
do_not_decode : Array[Bool],
) -> Array[Array[Float]] raise AudioError {
let output : Array[Array[Float]] = []
for _ in 0.. Unit raise AudioError {
let mut partition_count = 0
while partition_count < n_to_decode {
// Decode classification
if residue.classbook >= codebooks.length() {
break
}
let temp = codebook_decode(codebooks[residue.classbook], br)
let mut t = temp
let classifications : Array[Int] = Array::make(classwords, 0)
for j in (classwords - 1)..<=0 {
if j < 0 {
break
}
if residue.classifications > 0 {
classifications[j] = t % residue.classifications
t = t / residue.classifications
}
}
for j in 0..= n_to_decode {
break
}
let vq_class = classifications[j]
// Read pass 0 (simplified - only pass 0 for basic decoding)
if vq_class < residue.cascade.length() &&
(residue.cascade[vq_class] & 1) != 0 {
if vq_class < residue.books.length() {
let book_idx = residue.books[vq_class][0]
if book_idx >= 0 && book_idx < codebooks.length() {
let book = codebooks[book_idx]
let offset = residue.begin +
partition_count * residue.partition_size
let vectors_in_partition = residue.partition_size / book.dimensions
for _ in 0..