forge
Explore
Log in

Don't you dare go Hollow

wip(opus-vbr/r1): stereo_saving/spec_avg state, dynalloc returns max_depth

Browse files at this commit

27e52666158172ce44e34a6cf8e690117795536dAhmet Kaan GümüşParent: 730a563
crates/ec-opus/src/celt_enc.rsmodified+12 -2
@@ -385,6 +385,11 @@ pub struct CeltEncoder {
385385 vbr_drift: i32,
386386 vbr_offset: i32,
387387 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,
388393 // Per-frame scratch, allocated once.
389394 in_buf: Vec<f32>,
390395 freq: Vec<f32>,
@@ -438,6 +443,8 @@ impl CeltEncoder {
438443 vbr_drift: 0,
439444 vbr_offset: 0,
440445 vbr_count: 0,
446+ stereo_saving: 0.0,
447+ spec_avg: 0.0,
441448 in_buf: vec![0.0; channels * (max_n + OVERLAP)],
442449 freq: vec![0.0; channels * max_n],
443450 x: vec![0.0; channels * max_n],
@@ -491,6 +498,8 @@ impl CeltEncoder {
491498 self.vbr_drift = 0;
492499 self.vbr_offset = 0;
493500 self.vbr_count = 0;
501+ self.stereo_saving = 0.0;
502+ self.spec_avg = 0.0;
494503 }
495504
496505 /// Encodes one frame of interleaved `f32` (`frame_size` samples per
@@ -728,7 +737,7 @@ impl CeltEncoder {
728737 // --- Dynalloc analysis (offsets + spread_weight) --------------------
729738 self.offsets = [0; NB_BANDS];
730739 let mut spread_weight = [0i32; NB_BANDS];
731- self.dynalloc_analysis(
740+ let max_depth = self.dynalloc_analysis(
732741 start, end, c, lm, is_transient, effective_bytes, &mut spread_weight,
733742 );
734743
@@ -1144,7 +1153,7 @@ impl CeltEncoder {
11441153 is_transient: bool,
11451154 effective_bytes: i32,
11461155 spread_weight: &mut [i32; NB_BANDS],
1147- ) {
1156+ ) -> f32 {
11481157 const LSB_DEPTH: f32 = 24.0;
11491158 let mut noise_floor = [0.0f32; NB_BANDS];
11501159 for i in 0..end {
@@ -1278,6 +1287,7 @@ impl CeltEncoder {
12781287 self.offsets[i] = boost;
12791288 tot_boost += boost_bits;
12801289 }
1290+ max_depth
12811291 }
12821292
12831293 /// libopus `spreading_decision` (bands.c:479-570): classifies the current