diff --git a/crates/ec-opus/src/celt.rs b/crates/ec-opus/src/celt.rs index 219051bb..158c3a72 100644 --- a/crates/ec-opus/src/celt.rs +++ b/crates/ec-opus/src/celt.rs @@ -1078,52 +1078,11 @@ fn compute_allocation_shared( } } -/// Facts about the last decoded frame, for diagnostics. -#[derive(Clone, Debug)] -pub struct CeltDecDiag { - /// The frame was coded as CELT digital silence. - pub silence: bool, - /// Coarse energies used the intra-frame reset. - pub intra: bool, - /// Short-block (transient) frame as coded. - pub transient: bool, - /// Packet bits the range decoder saw for this frame. - pub total_bits: i32, - /// Decoded log2 band energies after fine bits, per channel (`2*NB_BANDS`). - pub old_band_e: Vec, - /// Time-frequency resolution change per band after `tf_select`. - pub tf_res: Vec, - /// Spreading decision as coded (0..3). - pub spread: usize, - /// Anti-collapse flag as coded. - pub anti_collapse: bool, - /// Allocation trim index as coded (0..10). - pub alloc_trim: i32, - /// Per-band allocated pulses after `compute_allocation`. - pub pulses: Vec, - /// Per-band fine-energy precision bits. - pub fine_quant: Vec, - /// Stereo intensity band (bands >= this collapse to mono). - pub intensity: usize, - /// Dual-stereo flag as coded. - pub dual_stereo: bool, - /// Highest band actually allocated pulses (`codedBands`). - pub coded_bands: usize, - /// Bit balance left after allocation, in 1/8-bit units. - pub balance: i32, - /// Decoded dynalloc band boosts (1/8-bit units). - pub offsets: Vec, -} - /// A CELT layer decoder, one per Opus stream. #[derive(Clone, Debug)] pub struct CeltDecoder { /// Channels this decoder outputs. channels: usize, - /// Decode with the RFC 6716 reconstruction (no RFC 8251 Section 8 energy cap - /// and no Section 9 hybrid folding). Off by default: RFC 8251 Section 11 - /// makes the new behaviour the reference. - legacy_rfc6716: bool, /// Output decimation: 1 at 48 kHz, 2 at 24 kHz, and so on. downsample: usize, window: Vec, @@ -1161,7 +1120,6 @@ pub struct CeltDecoder { collapse_masks: [u8; 2 * NB_BANDS], iy: Vec, mdct_buf: Vec, - diag: CeltDecDiag, plc: Plc, } @@ -1183,7 +1141,6 @@ impl CeltDecoder { let max_n = SHORT_MDCT * 8; CeltDecoder { channels, - legacy_rfc6716: false, downsample, window: overlap_window(), plans: (0..4).map(|lm| ImdctPlan::new(SHORT_MDCT << lm)).collect(), @@ -1225,34 +1182,9 @@ impl CeltDecoder { start: 0, end: NB_BANDS, }, - diag: CeltDecDiag { - silence: false, - intra: false, - transient: false, - total_bits: 0, - old_band_e: vec![0.0; 2 * NB_BANDS], - tf_res: Vec::new(), - spread: 0, - anti_collapse: false, - alloc_trim: 0, - pulses: vec![0; NB_BANDS], - fine_quant: vec![0; NB_BANDS], - intensity: 0, - dual_stereo: false, - coded_bands: 0, - balance: 0, - offsets: vec![0; NB_BANDS], - }, } } - /// Selects the RFC 6716 reconstruction (`true`) or the RFC 8251 one (`false`, - /// the default). The two differ on some hybrid and high-energy frames, so each - /// vector set is decoded with the behaviour its reference was made with. - pub fn set_legacy_rfc6716(&mut self, on: bool) { - self.legacy_rfc6716 = on; - } - /// Drops all inter-frame state (after a seek, or on a mode switch). pub fn reset(&mut self) { self.decode_mem.fill(0.0); @@ -1277,11 +1209,6 @@ impl CeltDecoder { self.rng } - /// Facts from the last decoded frame (diagnostic). - pub fn last_diag(&self) -> &CeltDecDiag { - &self.diag - } - /// Decodes one CELT frame. /// /// `frame_size` is in 48 kHz samples; `start`/`end` bound the coded bands @@ -1485,11 +1412,7 @@ impl CeltDecoder { // RFC 8251 Section 8: cap the log2 energy at 32 so the amplitude // stays finite (libopus `log2Amp`, `MIN32(QCONST32(32.f, 16), lg)`). let lg = (self.old_band_e[ch * NB_BANDS + i] + mean) as f64; - let lg = if self.legacy_rfc6716 { - lg - } else { - lg.min(32.0) - }; + let lg = lg.min(32.0); lg.exp2() as f32 }; } @@ -1590,24 +1513,6 @@ impl CeltDecoder { self.old_log_e2[ch * NB_BANDS + i] = -28.0; } } - self.diag = CeltDecDiag { - silence, - intra, - transient, - total_bits, - old_band_e: self.old_band_e.clone(), - tf_res: self.tf_res.to_vec(), - spread, - anti_collapse: anti_collapse_on, - alloc_trim, - pulses: self.pulses.to_vec(), - fine_quant: self.fine_quant.to_vec(), - intensity, - dual_stereo, - coded_bands, - balance, - offsets: self.offsets.to_vec(), - }; self.rng = dec.range(); self.deemphasis(out, n, cc); @@ -1772,13 +1677,12 @@ impl CeltDecoder { // RFC 8251 Section 9: the second band may take the first band as its // lowband even when the first band is narrower than it. - let rfc8251 = !self.legacy_rfc6716; - if (m * E_BANDS[i] >= m * E_BANDS[start] + n_band || (rfc8251 && i == start + 1)) + if (m * E_BANDS[i] >= m * E_BANDS[start] + n_band || i == start + 1) && (update_lowband || lowband_offset == 0) { lowband_offset = i; } - if rfc8251 && i == start + 1 && start + 2 <= NB_BANDS { + if i == start + 1 && start + 2 <= NB_BANDS { // RFC 8251 Section 9: repeat part of band `start` so band `i` can // fold onto it. Copies nothing when band `i` is not wider than it. let n1 = m * (E_BANDS[start + 1] - E_BANDS[start]); @@ -1814,7 +1718,7 @@ impl CeltDecoder { let mut fold_end = lowband_offset - 1; loop { fold_end += 1; - if (rfc8251 && fold_end >= i) || m * E_BANDS[fold_end] >= low + n_band { + if fold_end >= i || m * E_BANDS[fold_end] >= low + n_band { break; } } diff --git a/crates/ec-opus/src/lib.rs b/crates/ec-opus/src/lib.rs index 4398d82a..0f9ae96e 100644 --- a/crates/ec-opus/src/lib.rs +++ b/crates/ec-opus/src/lib.rs @@ -118,30 +118,9 @@ pub struct Decoder { range_final: u32, /// Samples per channel of the last packet, the default concealment length. last_packet_size: usize, - /// Test hook: drop the (CELT, SILK) layer's output before the sum. - debug_mute: (bool, bool), } impl Decoder { - /// Test hook, not for production use: silences the CELT and/or SILK - /// layer's contribution to the output (the decoder state still advances) - /// so a hybrid packet's two layers can be measured one at a time. - #[doc(hidden)] - pub fn debug_mute_layers(&mut self, celt: bool, silk: bool) { - self.debug_mute = (celt, silk); - } - - /// Decodes with the RFC 6716 reconstruction instead of the RFC 8251 one - /// (the default). Needed only to reproduce the RFC 6716 reference vectors. - pub fn set_legacy_rfc6716(&mut self, on: bool) { - self.celt.set_legacy_rfc6716(on); - } - - /// Facts from the last decoded frame's CELT layer (diagnostic). - pub fn last_celt_diag(&self) -> &crate::celt::CeltDecDiag { - self.celt.last_diag() - } - /// A decoder for `channels` channels at `sample_rate`, which must be one of /// 8000, 12000, 16000, 24000 or 48000 Hz. pub fn new(sample_rate: u32, channels: usize) -> Result { @@ -179,7 +158,6 @@ impl Decoder { prev_redundancy: false, range_final: 0, last_packet_size: 960 / downsample, - debug_mute: (false, false), }) } @@ -513,10 +491,7 @@ impl Decoder { } // Sum the two layers. - if self.debug_mute.0 { - out.fill(0.0); - } - if mode != Mode::Celt && !self.debug_mute.1 { + if mode != Mode::Celt { for (o, s) in out.iter_mut().zip(silk_pcm.iter()) { *o += *s as f32 * (1.0 / 32768.0); }