diff --git a/crates/ec-opus/src/celt_enc.rs b/crates/ec-opus/src/celt_enc.rs index 3216bb7c..dff7405c 100644 --- a/crates/ec-opus/src/celt_enc.rs +++ b/crates/ec-opus/src/celt_enc.rs @@ -384,7 +384,7 @@ struct EncBand { } /// Per-frame encoder diagnostics for the dropout investigation. Captured at -/// the end of [`CeltEncoder::encode`]; read via [`CeltEncoder::last_diag`]. +/// the end of `CeltEncoder::encode`; read via [`CeltEncoder::last_diag`]. #[derive(Clone, Debug)] pub struct CeltFrameDiag { /// Transient flag as coded into the bitstream. @@ -603,9 +603,7 @@ impl CeltEncoder { self.channels } - /// Diagnostics captured at the end of the most recent [`encode`] call. - /// - /// [`encode`]: CeltEncoder::encode + /// Diagnostics captured at the end of the most recent `encode` call. pub fn last_diag(&self) -> &CeltFrameDiag { &self.last_diag } diff --git a/crates/ec-opus/src/encoder.rs b/crates/ec-opus/src/encoder.rs index e6a9193b..0385857e 100644 --- a/crates/ec-opus/src/encoder.rs +++ b/crates/ec-opus/src/encoder.rs @@ -108,7 +108,7 @@ pub struct Encoder { /// Scratch space for the SILK packet payload, sized once so the steady-state /// loop (`steady_state_encode_loop_zero_alloc`) doesn't allocate. silk_buf: [u8; MAX_SILK_PACKET_BYTES], - /// Hybrid: the last [`Encoder::hybrid_silk_delay_48k`] samples of SILK-layer input. + /// Hybrid: the last `Encoder::hybrid_silk_delay_48k` samples of SILK-layer input. silk_delay: Vec, /// Scratch space for the zero-stuffed SILK/hybrid input, sized once so /// the steady-state loop doesn't allocate a `Vec` per frame. @@ -241,11 +241,11 @@ impl Encoder { /// delay compensation, 312 samples at 48 kHz. /// SILK (10, 20, 40 or 60 ms frames, when the application/bitrate or an /// explicit [`Encoder::set_mode`] select it — the same - /// [`Encoder::silk_choice`] predicate `encode_toc_and_payload` dispatches + /// `Encoder::silk_choice` predicate `encode_toc_and_payload` dispatches /// on, so this always matches which layer actually codes the frame): - /// [`SILK_LOOK_AHEAD_48K_NB`], [`SILK_LOOK_AHEAD_48K_MB`] or - /// [`SILK_LOOK_AHEAD_48K_WB`]. Hybrid: CELT's 120, the SILK layer being - /// delayed to meet it ([`Encoder::hybrid_silk_delay_48k`]). Any other frame size + /// `SILK_LOOK_AHEAD_48K_NB`, `SILK_LOOK_AHEAD_48K_MB` or + /// `SILK_LOOK_AHEAD_48K_WB`. Hybrid: CELT's 120, the SILK layer being + /// delayed to meet it (`Encoder::hybrid_silk_delay_48k`). Any other frame size /// falls back to CELT here exactly as `encode_toc_and_payload` does. pub fn look_ahead(&self, frame_size: usize) -> usize { let frame_48k = frame_size * self.upsample; @@ -499,7 +499,7 @@ impl Encoder { /// Zero-stuffs a mono, `frame_size`-sample native-rate frame up to /// `frame_size * upsample` samples at 48 kHz, the rate [`SilkEncoder`] - /// takes — the same technique [`CeltEncoder::encode`] uses, scaled by + /// takes — the same technique `CeltEncoder::encode` uses, scaled by /// `upsample` so the passband gain survives the stuffing. Writes into /// `out` (an `Encoder` scratch field, not a fresh `Vec` per call) rather /// than returning one, so the caller doesn't allocate every frame; the @@ -958,7 +958,7 @@ impl Encoder { /// One hybrid frame (10 or 20 ms, mono or stereo, `bandwidth` SWB or FB) /// into the internal range coder, returning its byte length: the SILK /// layer's symbols (WB, 16 kHz internal, fed the input delayed by - /// [`Encoder::hybrid_silk_delay_48k`]), the no-redundancy flag under the decoder's + /// `Encoder::hybrid_silk_delay_48k`), the no-redundancy flag under the decoder's /// exact presence rule, then the CELT layer from band 17 in the same /// coder. CBR: the packet is the bitrate's size unless SILK alone needs /// more, in which case CELT keeps [`HYBRID_CELT_MIN_BYTES`] on top. diff --git a/crates/ec-opus/src/silk.rs b/crates/ec-opus/src/silk.rs index c7ac689c..4186aea7 100644 --- a/crates/ec-opus/src/silk.rs +++ b/crates/ec-opus/src/silk.rs @@ -250,17 +250,35 @@ struct Indices { /// packets against ffmpeg-libopus's. #[derive(Clone, Debug, Default)] pub struct SilkDecIndices { + /// 0 = inactive/unvoiced, 1 = unvoiced, 2 = voiced (SILK `SignalType`). pub signal_type: i32, + /// Quantization offset flavor: 0 = low-bitrate offset, 1 = default offset. pub quant_offset_type: i32, + /// Per-subframe coded excitation gains; each is an index into the gain + /// dequantization table, not a linear gain. pub gains: [i8; 4], + /// Quantized normalized LSF coefficients; 17 entries (`MAX_LPC_ORDER + 1`), + /// the last being the interpolated residual-energy weight. pub nlsf: [i8; 17], + /// Interpolation weight between the previous and current frame's NLSFs, + /// Q2 in [0, 4] (4 = no interpolation). pub nlsf_interp_coef_q2: i32, + /// Raw pitch lag index; the lag in samples is derived from this plus the + /// frame's lag range and minimum lag. pub lag_index: i32, + /// Index into the pitch-contour codebook for the current bandwidth and + /// subframe count. pub contour_index: i32, + /// Periodicity index selecting the LTP filter scaling per subframe. pub per_index: usize, + /// Per-subframe LTP codebook indices; `usize::MAX` means LTP is off for + /// that subframe. pub ltp_index: [usize; 4], + /// Index of the LTP gain scaling factor applied to all subframes. pub ltp_scale_index: usize, + /// Pseudorandom seed for excitation sign/pulse decoding. pub seed: i32, + /// Diagnostic-only counter of SILK frames this state has decoded. pub frames_decoded: usize, } diff --git a/crates/ec-opus/src/silk_enc_write.rs b/crates/ec-opus/src/silk_enc_write.rs index 387c16f0..010758b8 100644 --- a/crates/ec-opus/src/silk_enc_write.rs +++ b/crates/ec-opus/src/silk_enc_write.rs @@ -1,4 +1,4 @@ -//! SILK payload writer (subtask D2a): turns the analysis in [`crate::silk_enc`] +//! SILK payload writer (subtask D2a): turns the analysis in `crate::silk_enc` //! into decodable SILK packets, NB (8 kHz), MB (12 kHz) or WB (16 kHz). //! //! Symbol order is exactly `silk::decode()`'s, and every decision is made @@ -42,14 +42,25 @@ const MAX_PULSE: i32 = 1023; /// call, for the speech-quality diagnostic lane. #[derive(Clone, Debug, Default)] pub struct SilkFrameDiag { + /// Whether the VAD classified the input frame as voiced. pub voiced: bool, + /// SILK signal type chosen by the encoder (0 inactive, 1 unvoiced, + /// 2 voiced). pub signal_type: i32, + /// Per-subframe gain codebook indices as written to the bitstream. pub gain_idx: [i8; MAX_NB_SUBFR], + /// Number of subframes in the frame (2 for 10 ms, 4 for 20 ms). pub nb_subfr: usize, + /// Raw pitch lag index written to the bitstream (first subframe's). pub lag_index: i32, + /// Pitch lag in samples per subframe as used by the LTP analysis. pub pitch_l: [i32; MAX_NB_SUBFR], + /// NLSF interpolation coefficient (Q2, 0..4) encoded for this frame. pub nlsf_interp: i32, + /// Number of payload bytes the frame's encode produced. pub bytes: usize, + /// Total LTP excitation gain across subframes (linear scale, 0 if the + /// frame had no LTP). pub ltp_gain: f32, }