wip(opus-vbr/r1): stereo_saving/spec_avg state, dynalloc returns max_depth
Browse files at this commit27e52666158172ce44e34a6cf8e690117795536dParent: 730a5631 changed file +12 -2
crates/ec-opus/src/celt_enc.rsmodified+12 -2
| @@ -385,6 +385,11 @@ pub struct CeltEncoder { | ||
| 385 | 385 | vbr_drift: i32, |
| 386 | 386 | vbr_offset: i32, |
| 387 | 387 | vbr_count: i32, |
| 388 | + /// libopus `st->stereo_saving` — mid/side bit-saving estimate (Q8 in C, | |
| 389 | + /// plain f32 here), updated in `alloc_trim_analysis`. | |
| 390 | + stereo_saving: f32, | |
| 391 | + /// libopus `st->spec_avg` — temporal-VBR follower average, updated each frame. | |
| 392 | + spec_avg: f32, | |
| 388 | 393 | // Per-frame scratch, allocated once. |
| 389 | 394 | in_buf: Vec<f32>, |
| 390 | 395 | freq: Vec<f32>, |
| @@ -438,6 +443,8 @@ impl CeltEncoder { | ||
| 438 | 443 | vbr_drift: 0, |
| 439 | 444 | vbr_offset: 0, |
| 440 | 445 | vbr_count: 0, |
| 446 | + stereo_saving: 0.0, | |
| 447 | + spec_avg: 0.0, | |
| 441 | 448 | in_buf: vec![0.0; channels * (max_n + OVERLAP)], |
| 442 | 449 | freq: vec![0.0; channels * max_n], |
| 443 | 450 | x: vec![0.0; channels * max_n], |
| @@ -491,6 +498,8 @@ impl CeltEncoder { | ||
| 491 | 498 | self.vbr_drift = 0; |
| 492 | 499 | self.vbr_offset = 0; |
| 493 | 500 | self.vbr_count = 0; |
| 501 | + self.stereo_saving = 0.0; | |
| 502 | + self.spec_avg = 0.0; | |
| 494 | 503 | } |
| 495 | 504 | |
| 496 | 505 | /// Encodes one frame of interleaved `f32` (`frame_size` samples per |
| @@ -728,7 +737,7 @@ impl CeltEncoder { | ||
| 728 | 737 | // --- Dynalloc analysis (offsets + spread_weight) -------------------- |
| 729 | 738 | self.offsets = [0; NB_BANDS]; |
| 730 | 739 | let mut spread_weight = [0i32; NB_BANDS]; |
| 731 | - self.dynalloc_analysis( | |
| 740 | + let max_depth = self.dynalloc_analysis( | |
| 732 | 741 | start, end, c, lm, is_transient, effective_bytes, &mut spread_weight, |
| 733 | 742 | ); |
| 734 | 743 | |
| @@ -1144,7 +1153,7 @@ impl CeltEncoder { | ||
| 1144 | 1153 | is_transient: bool, |
| 1145 | 1154 | effective_bytes: i32, |
| 1146 | 1155 | spread_weight: &mut [i32; NB_BANDS], |
| 1147 | - ) { | |
| 1156 | + ) -> f32 { | |
| 1148 | 1157 | const LSB_DEPTH: f32 = 24.0; |
| 1149 | 1158 | let mut noise_floor = [0.0f32; NB_BANDS]; |
| 1150 | 1159 | for i in 0..end { |
| @@ -1278,6 +1287,7 @@ impl CeltEncoder { | ||
| 1278 | 1287 | self.offsets[i] = boost; |
| 1279 | 1288 | tot_boost += boost_bits; |
| 1280 | 1289 | } |
| 1290 | + max_depth | |
| 1281 | 1291 | } |
| 1282 | 1292 | |
| 1283 | 1293 | /// libopus `spreading_decision` (bands.c:479-570): classifies the current |