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(
1078 }1078 }
1079 }1079 }
1080 1080
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-
1118 /// A CELT layer decoder, one per Opus stream.1081 /// A CELT layer decoder, one per Opus stream.
1119 #[derive(Clone, Debug)]1082 #[derive(Clone, Debug)]
1120 pub struct CeltDecoder {1083 pub struct CeltDecoder {
1121 /// Channels this decoder outputs.1084 /// Channels this decoder outputs.
1122 channels: usize,1085 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,
1127 /// Output decimation: 1 at 48 kHz, 2 at 24 kHz, and so on.1086 /// Output decimation: 1 at 48 kHz, 2 at 24 kHz, and so on.
1128 downsample: usize,1087 downsample: usize,
1129 window: Vec<f32>,1088 window: Vec<f32>,
@@ -1161,7 +1120,6 @@ pub struct CeltDecoder {
1161 collapse_masks: [u8; 2 * NB_BANDS],1120 collapse_masks: [u8; 2 * NB_BANDS],
1162 iy: Vec<i32>,1121 iy: Vec<i32>,
1163 mdct_buf: Vec<f32>,1122 mdct_buf: Vec<f32>,
1164- diag: CeltDecDiag,
1165 plc: Plc,1123 plc: Plc,
1166 }1124 }
1167 1125
@@ -1183,7 +1141,6 @@ impl CeltDecoder {
1183 let max_n = SHORT_MDCT * 8;1141 let max_n = SHORT_MDCT * 8;
1184 CeltDecoder {1142 CeltDecoder {
1185 channels,1143 channels,
1186- legacy_rfc6716: false,
1187 downsample,1144 downsample,
1188 window: overlap_window(),1145 window: overlap_window(),
1189 plans: (0..4).map(|lm| ImdctPlan::new(SHORT_MDCT << lm)).collect(),1146 plans: (0..4).map(|lm| ImdctPlan::new(SHORT_MDCT << lm)).collect(),
@@ -1225,34 +1182,9 @@ impl CeltDecoder {
1225 start: 0,1182 start: 0,
1226 end: NB_BANDS,1183 end: NB_BANDS,
1227 },1184 },
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- },
1246 }1185 }
1247 }1186 }
1248 1187
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-
1256 /// Drops all inter-frame state (after a seek, or on a mode switch).1188 /// Drops all inter-frame state (after a seek, or on a mode switch).
1257 pub fn reset(&mut self) {1189 pub fn reset(&mut self) {
1258 self.decode_mem.fill(0.0);1190 self.decode_mem.fill(0.0);
@@ -1277,11 +1209,6 @@ impl CeltDecoder {
1277 self.rng1209 self.rng
1278 }1210 }
1279 1211
1280- /// Facts from the last decoded frame (diagnostic).
1281- pub fn last_diag(&self) -> &CeltDecDiag {
1282- &self.diag
1283- }
1284-
1285 /// Decodes one CELT frame.1212 /// Decodes one CELT frame.
1286 ///1213 ///
1287 /// `frame_size` is in 48 kHz samples; `start`/`end` bound the coded bands1214 /// `frame_size` is in 48 kHz samples; `start`/`end` bound the coded bands
@@ -1485,11 +1412,7 @@ impl CeltDecoder {
1485 // RFC 8251 Section 8: cap the log2 energy at 32 so the amplitude1412 // RFC 8251 Section 8: cap the log2 energy at 32 so the amplitude
1486 // stays finite (libopus `log2Amp`, `MIN32(QCONST32(32.f, 16), lg)`).1413 // stays finite (libopus `log2Amp`, `MIN32(QCONST32(32.f, 16), lg)`).
1487 let lg = (self.old_band_e[ch * NB_BANDS + i] + mean) as f64;1414 let lg = (self.old_band_e[ch * NB_BANDS + i] + mean) as f64;
1488- let lg = if self.legacy_rfc6716 {1415+ let lg = lg.min(32.0);
1489- lg
1490- } else {
1491- lg.min(32.0)
1492- };
1493 lg.exp2() as f321416 lg.exp2() as f32
1494 };1417 };
1495 }1418 }
@@ -1590,24 +1513,6 @@ impl CeltDecoder {
1590 self.old_log_e2[ch * NB_BANDS + i] = -28.0;1513 self.old_log_e2[ch * NB_BANDS + i] = -28.0;
1591 }1514 }
1592 }1515 }
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- };
1611 self.rng = dec.range();1516 self.rng = dec.range();
1612 1517
1613 self.deemphasis(out, n, cc);1518 self.deemphasis(out, n, cc);
@@ -1772,13 +1677,12 @@ impl CeltDecoder {
1772 1677
1773 // RFC 8251 Section 9: the second band may take the first band as its1678 // RFC 8251 Section 9: the second band may take the first band as its
1774 // lowband even when the first band is narrower than it.1679 // lowband even when the first band is narrower than it.
1775- let rfc8251 = !self.legacy_rfc6716;1680+ if (m * E_BANDS[i] >= m * E_BANDS[start] + n_band || i == start + 1)
1776- if (m * E_BANDS[i] >= m * E_BANDS[start] + n_band || (rfc8251 && i == start + 1))
1777 && (update_lowband || lowband_offset == 0)1681 && (update_lowband || lowband_offset == 0)
1778 {1682 {
1779 lowband_offset = i;1683 lowband_offset = i;
1780 }1684 }
1781- if rfc8251 && i == start + 1 && start + 2 <= NB_BANDS {1685+ if i == start + 1 && start + 2 <= NB_BANDS {
1782 // RFC 8251 Section 9: repeat part of band `start` so band `i` can1686 // RFC 8251 Section 9: repeat part of band `start` so band `i` can
1783 // fold onto it. Copies nothing when band `i` is not wider than it.1687 // fold onto it. Copies nothing when band `i` is not wider than it.
1784 let n1 = m * (E_BANDS[start + 1] - E_BANDS[start]);1688 let n1 = m * (E_BANDS[start + 1] - E_BANDS[start]);
@@ -1814,7 +1718,7 @@ impl CeltDecoder {
1814 let mut fold_end = lowband_offset - 1;1718 let mut fold_end = lowband_offset - 1;
1815 loop {1719 loop {
1816 fold_end += 1;1720 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 {
1818 break;1722 break;
1819 }1723 }
1820 }1724 }
crates/ec-opus/src/lib.rsmodified+1 -26
@@ -118,30 +118,9 @@ pub struct Decoder {
118 range_final: u32,118 range_final: u32,
119 /// Samples per channel of the last packet, the default concealment length.119 /// Samples per channel of the last packet, the default concealment length.
120 last_packet_size: usize,120 last_packet_size: usize,
121- /// Test hook: drop the (CELT, SILK) layer's output before the sum.
122- debug_mute: (bool, bool),
123 }121 }
124 122
125 impl Decoder {123 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-
145 /// A decoder for `channels` channels at `sample_rate`, which must be one of124 /// A decoder for `channels` channels at `sample_rate`, which must be one of
146 /// 8000, 12000, 16000, 24000 or 48000 Hz.125 /// 8000, 12000, 16000, 24000 or 48000 Hz.
147 pub fn new(sample_rate: u32, channels: usize) -> Result<Decoder> {126 pub fn new(sample_rate: u32, channels: usize) -> Result<Decoder> {
@@ -179,7 +158,6 @@ impl Decoder {
179 prev_redundancy: false,158 prev_redundancy: false,
180 range_final: 0,159 range_final: 0,
181 last_packet_size: 960 / downsample,160 last_packet_size: 960 / downsample,
182- debug_mute: (false, false),
183 })161 })
184 }162 }
185 163
@@ -513,10 +491,7 @@ impl Decoder {
513 }491 }
514 492
515 // Sum the two layers.493 // Sum the two layers.
516- if self.debug_mute.0 {494+ if mode != Mode::Celt {
517- out.fill(0.0);
518- }
519- if mode != Mode::Celt && !self.debug_mute.1 {
520 for (o, s) in out.iter_mut().zip(silk_pcm.iter()) {495 for (o, s) in out.iter_mut().zip(silk_pcm.iter()) {
521 *o += *s as f32 * (1.0 / 32768.0);496 *o += *s as f32 * (1.0 / 32768.0);
522 }497 }