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 {
385 vbr_drift: i32,385 vbr_drift: i32,
386 vbr_offset: i32,386 vbr_offset: i32,
387 vbr_count: i32,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 // Per-frame scratch, allocated once.393 // Per-frame scratch, allocated once.
389 in_buf: Vec<f32>,394 in_buf: Vec<f32>,
390 freq: Vec<f32>,395 freq: Vec<f32>,
@@ -438,6 +443,8 @@ impl CeltEncoder {
438 vbr_drift: 0,443 vbr_drift: 0,
439 vbr_offset: 0,444 vbr_offset: 0,
440 vbr_count: 0,445 vbr_count: 0,
446+ stereo_saving: 0.0,
447+ spec_avg: 0.0,
441 in_buf: vec![0.0; channels * (max_n + OVERLAP)],448 in_buf: vec![0.0; channels * (max_n + OVERLAP)],
442 freq: vec![0.0; channels * max_n],449 freq: vec![0.0; channels * max_n],
443 x: vec![0.0; channels * max_n],450 x: vec![0.0; channels * max_n],
@@ -491,6 +498,8 @@ impl CeltEncoder {
491 self.vbr_drift = 0;498 self.vbr_drift = 0;
492 self.vbr_offset = 0;499 self.vbr_offset = 0;
493 self.vbr_count = 0;500 self.vbr_count = 0;
501+ self.stereo_saving = 0.0;
502+ self.spec_avg = 0.0;
494 }503 }
495 504
496 /// Encodes one frame of interleaved `f32` (`frame_size` samples per505 /// Encodes one frame of interleaved `f32` (`frame_size` samples per
@@ -728,7 +737,7 @@ impl CeltEncoder {
728 // --- Dynalloc analysis (offsets + spread_weight) --------------------737 // --- Dynalloc analysis (offsets + spread_weight) --------------------
729 self.offsets = [0; NB_BANDS];738 self.offsets = [0; NB_BANDS];
730 let mut spread_weight = [0i32; NB_BANDS];739 let mut spread_weight = [0i32; NB_BANDS];
731- self.dynalloc_analysis(740+ let max_depth = self.dynalloc_analysis(
732 start, end, c, lm, is_transient, effective_bytes, &mut spread_weight,741 start, end, c, lm, is_transient, effective_bytes, &mut spread_weight,
733 );742 );
734 743
@@ -1144,7 +1153,7 @@ impl CeltEncoder {
1144 is_transient: bool,1153 is_transient: bool,
1145 effective_bytes: i32,1154 effective_bytes: i32,
1146 spread_weight: &mut [i32; NB_BANDS],1155 spread_weight: &mut [i32; NB_BANDS],
1147- ) {1156+ ) -> f32 {
1148 const LSB_DEPTH: f32 = 24.0;1157 const LSB_DEPTH: f32 = 24.0;
1149 let mut noise_floor = [0.0f32; NB_BANDS];1158 let mut noise_floor = [0.0f32; NB_BANDS];
1150 for i in 0..end {1159 for i in 0..end {
@@ -1278,6 +1287,7 @@ impl CeltEncoder {
1278 self.offsets[i] = boost;1287 self.offsets[i] = boost;
1279 tot_boost += boost_bits;1288 tot_boost += boost_bits;
1280 }1289 }
1290+ max_depth
1281 }1291 }
1282 1292
1283 /// libopus `spreading_decision` (bands.c:479-570): classifies the current1293 /// libopus `spreading_decision` (bands.c:479-570): classifies the current