forge
Explore
Log in

Don't you dare go Hollow

U8: ec-opus delete decoder test hooks: debug_mute_layers, set_legacy_rfc6716 (RFC 8251 path always), last_celt_diag and CeltDecDiag (output unchanged, default is RFC 8251)

Browse files at this commit

28e42579319cfc441ba0f2d9ac16e4aeb5194264Ahmet Kaan GümüşParent: 8066205
crates/ec-opus/src/celt.rsmodified+4 -100
@@ -1078,52 +1078,11 @@ fn compute_allocation_shared(
10781078 }
10791079 }
10801080
1081-/// Facts about the last decoded frame, for diagnostics.
1082-#[derive(Clone, Debug)]
1083-pub struct CeltDecDiag {
1084- /// The frame was coded as CELT digital silence.
1085- pub silence: bool,
1086- /// Coarse energies used the intra-frame reset.
1087- pub intra: bool,
1088- /// Short-block (transient) frame as coded.
1089- pub transient: bool,
1090- /// Packet bits the range decoder saw for this frame.
1091- pub total_bits: i32,
1092- /// Decoded log2 band energies after fine bits, per channel (`2*NB_BANDS`).
1093- pub old_band_e: Vec<f32>,
1094- /// Time-frequency resolution change per band after `tf_select`.
1095- pub tf_res: Vec<i32>,
1096- /// Spreading decision as coded (0..3).
1097- pub spread: usize,
1098- /// Anti-collapse flag as coded.
1099- pub anti_collapse: bool,
1100- /// Allocation trim index as coded (0..10).
1101- pub alloc_trim: i32,
1102- /// Per-band allocated pulses after `compute_allocation`.
1103- pub pulses: Vec<i32>,
1104- /// Per-band fine-energy precision bits.
1105- pub fine_quant: Vec<i32>,
1106- /// Stereo intensity band (bands >= this collapse to mono).
1107- pub intensity: usize,
1108- /// Dual-stereo flag as coded.
1109- pub dual_stereo: bool,
1110- /// Highest band actually allocated pulses (`codedBands`).
1111- pub coded_bands: usize,
1112- /// Bit balance left after allocation, in 1/8-bit units.
1113- pub balance: i32,
1114- /// Decoded dynalloc band boosts (1/8-bit units).
1115- pub offsets: Vec<i32>,
1116-}
1117-
11181081 /// A CELT layer decoder, one per Opus stream.
11191082 #[derive(Clone, Debug)]
11201083 pub struct CeltDecoder {
11211084 /// Channels this decoder outputs.
11221085 channels: usize,
1123- /// Decode with the RFC 6716 reconstruction (no RFC 8251 Section 8 energy cap
1124- /// and no Section 9 hybrid folding). Off by default: RFC 8251 Section 11
1125- /// makes the new behaviour the reference.
1126- legacy_rfc6716: bool,
11271086 /// Output decimation: 1 at 48 kHz, 2 at 24 kHz, and so on.
11281087 downsample: usize,
11291088 window: Vec<f32>,
@@ -1161,7 +1120,6 @@ pub struct CeltDecoder {
11611120 collapse_masks: [u8; 2 * NB_BANDS],
11621121 iy: Vec<i32>,
11631122 mdct_buf: Vec<f32>,
1164- diag: CeltDecDiag,
11651123 plc: Plc,
11661124 }
11671125
@@ -1183,7 +1141,6 @@ impl CeltDecoder {
11831141 let max_n = SHORT_MDCT * 8;
11841142 CeltDecoder {
11851143 channels,
1186- legacy_rfc6716: false,
11871144 downsample,
11881145 window: overlap_window(),
11891146 plans: (0..4).map(|lm| ImdctPlan::new(SHORT_MDCT << lm)).collect(),
@@ -1225,34 +1182,9 @@ impl CeltDecoder {
12251182 start: 0,
12261183 end: NB_BANDS,
12271184 },
1228- diag: CeltDecDiag {
1229- silence: false,
1230- intra: false,
1231- transient: false,
1232- total_bits: 0,
1233- old_band_e: vec![0.0; 2 * NB_BANDS],
1234- tf_res: Vec::new(),
1235- spread: 0,
1236- anti_collapse: false,
1237- alloc_trim: 0,
1238- pulses: vec![0; NB_BANDS],
1239- fine_quant: vec![0; NB_BANDS],
1240- intensity: 0,
1241- dual_stereo: false,
1242- coded_bands: 0,
1243- balance: 0,
1244- offsets: vec![0; NB_BANDS],
1245- },
12461185 }
12471186 }
12481187
1249- /// Selects the RFC 6716 reconstruction (`true`) or the RFC 8251 one (`false`,
1250- /// the default). The two differ on some hybrid and high-energy frames, so each
1251- /// vector set is decoded with the behaviour its reference was made with.
1252- pub fn set_legacy_rfc6716(&mut self, on: bool) {
1253- self.legacy_rfc6716 = on;
1254- }
1255-
12561188 /// Drops all inter-frame state (after a seek, or on a mode switch).
12571189 pub fn reset(&mut self) {
12581190 self.decode_mem.fill(0.0);
@@ -1277,11 +1209,6 @@ impl CeltDecoder {
12771209 self.rng
12781210 }
12791211
1280- /// Facts from the last decoded frame (diagnostic).
1281- pub fn last_diag(&self) -> &CeltDecDiag {
1282- &self.diag
1283- }
1284-
12851212 /// Decodes one CELT frame.
12861213 ///
12871214 /// `frame_size` is in 48 kHz samples; `start`/`end` bound the coded bands
@@ -1485,11 +1412,7 @@ impl CeltDecoder {
14851412 // RFC 8251 Section 8: cap the log2 energy at 32 so the amplitude
14861413 // stays finite (libopus `log2Amp`, `MIN32(QCONST32(32.f, 16), lg)`).
14871414 let lg = (self.old_band_e[ch * NB_BANDS + i] + mean) as f64;
1488- let lg = if self.legacy_rfc6716 {
1489- lg
1490- } else {
1491- lg.min(32.0)
1492- };
1415+ let lg = lg.min(32.0);
14931416 lg.exp2() as f32
14941417 };
14951418 }
@@ -1590,24 +1513,6 @@ impl CeltDecoder {
15901513 self.old_log_e2[ch * NB_BANDS + i] = -28.0;
15911514 }
15921515 }
1593- self.diag = CeltDecDiag {
1594- silence,
1595- intra,
1596- transient,
1597- total_bits,
1598- old_band_e: self.old_band_e.clone(),
1599- tf_res: self.tf_res.to_vec(),
1600- spread,
1601- anti_collapse: anti_collapse_on,
1602- alloc_trim,
1603- pulses: self.pulses.to_vec(),
1604- fine_quant: self.fine_quant.to_vec(),
1605- intensity,
1606- dual_stereo,
1607- coded_bands,
1608- balance,
1609- offsets: self.offsets.to_vec(),
1610- };
16111516 self.rng = dec.range();
16121517
16131518 self.deemphasis(out, n, cc);
@@ -1772,13 +1677,12 @@ impl CeltDecoder {
17721677
17731678 // RFC 8251 Section 9: the second band may take the first band as its
17741679 // lowband even when the first band is narrower than it.
1775- let rfc8251 = !self.legacy_rfc6716;
1776- if (m * E_BANDS[i] >= m * E_BANDS[start] + n_band || (rfc8251 && i == start + 1))
1680+ if (m * E_BANDS[i] >= m * E_BANDS[start] + n_band || i == start + 1)
17771681 && (update_lowband || lowband_offset == 0)
17781682 {
17791683 lowband_offset = i;
17801684 }
1781- if rfc8251 && i == start + 1 && start + 2 <= NB_BANDS {
1685+ if i == start + 1 && start + 2 <= NB_BANDS {
17821686 // RFC 8251 Section 9: repeat part of band `start` so band `i` can
17831687 // fold onto it. Copies nothing when band `i` is not wider than it.
17841688 let n1 = m * (E_BANDS[start + 1] - E_BANDS[start]);
@@ -1814,7 +1718,7 @@ impl CeltDecoder {
18141718 let mut fold_end = lowband_offset - 1;
18151719 loop {
18161720 fold_end += 1;
1817- if (rfc8251 && fold_end >= i) || m * E_BANDS[fold_end] >= low + n_band {
1721+ if fold_end >= i || m * E_BANDS[fold_end] >= low + n_band {
18181722 break;
18191723 }
18201724 }
crates/ec-opus/src/lib.rsmodified+1 -26
@@ -118,30 +118,9 @@ pub struct Decoder {
118118 range_final: u32,
119119 /// Samples per channel of the last packet, the default concealment length.
120120 last_packet_size: usize,
121- /// Test hook: drop the (CELT, SILK) layer's output before the sum.
122- debug_mute: (bool, bool),
123121 }
124122
125123 impl Decoder {
126- /// Test hook, not for production use: silences the CELT and/or SILK
127- /// layer's contribution to the output (the decoder state still advances)
128- /// so a hybrid packet's two layers can be measured one at a time.
129- #[doc(hidden)]
130- pub fn debug_mute_layers(&mut self, celt: bool, silk: bool) {
131- self.debug_mute = (celt, silk);
132- }
133-
134- /// Decodes with the RFC 6716 reconstruction instead of the RFC 8251 one
135- /// (the default). Needed only to reproduce the RFC 6716 reference vectors.
136- pub fn set_legacy_rfc6716(&mut self, on: bool) {
137- self.celt.set_legacy_rfc6716(on);
138- }
139-
140- /// Facts from the last decoded frame's CELT layer (diagnostic).
141- pub fn last_celt_diag(&self) -> &crate::celt::CeltDecDiag {
142- self.celt.last_diag()
143- }
144-
145124 /// A decoder for `channels` channels at `sample_rate`, which must be one of
146125 /// 8000, 12000, 16000, 24000 or 48000 Hz.
147126 pub fn new(sample_rate: u32, channels: usize) -> Result<Decoder> {
@@ -179,7 +158,6 @@ impl Decoder {
179158 prev_redundancy: false,
180159 range_final: 0,
181160 last_packet_size: 960 / downsample,
182- debug_mute: (false, false),
183161 })
184162 }
185163
@@ -513,10 +491,7 @@ impl Decoder {
513491 }
514492
515493 // Sum the two layers.
516- if self.debug_mute.0 {
517- out.fill(0.0);
518- }
519- if mode != Mode::Celt && !self.debug_mute.1 {
494+ if mode != Mode::Celt {
520495 for (o, s) in out.iter_mut().zip(silk_pcm.iter()) {
521496 *o += *s as f32 * (1.0 / 32768.0);
522497 }