]> git.nihav.org Git - nihav.git/blobdiff - nihav-mpeg/src/codecs/aac/sbr/mod.rs
aacsbr: fix high<->low resolution envelope mapping
[nihav.git] / nihav-mpeg / src / codecs / aac / sbr / mod.rs
index fb455cbce997e60d9fb0f36ee23b8edab42e5e4d..d2477b98a45a5735d5c83a2b1c58a487158a2e23 100644 (file)
@@ -189,9 +189,10 @@ impl SBRState {
             }
         }
         for (dst, high) in self.low_to_high_res.iter_mut().zip(high_src.iter()) {
-            match low_src.binary_search(high) {
-                Ok(idx) | Err(idx) => *dst = idx,
-            };
+            *dst = match low_src.binary_search(high) {
+                    Ok(idx) => idx,
+                    Err(idx) => idx - 1,
+                };
         }
 
         let num_q = (((hdr.noise_bands as f32) * ((k2 as f32) / (k_x as f32)).log2()).round() as usize).max(1);
@@ -400,7 +401,7 @@ fn calculate_master_frequencies(f: &mut [usize; SBR_BANDS], k0: usize, k2: usize
             if v_dk1[0] < max_vdk0 {
                 let change = (max_vdk0 - v_dk1[0]).min((v_dk1[num_bands1 - 1] - v_dk1[0]) / 2);
                 v_dk1[0] += change;
-                v_dk1[num_bands1 - 1] -= change; 
+                v_dk1[num_bands1 - 1] -= change;
             }
             let mut v_k1 = [0; SBR_BANDS];
             v_k1[0] = k1;