Merge branch 'lane-opusdocs' (01744b26): ec-opus's 21 missing-docs warnings (SilkDecIndices + SilkFrameDiag fields) documented with real semantics -- edith's build is warning-free again through the path dep
Browse files at this commit4 changed files +39 -12
- crates/ec-opus/src/celt_enc.rs +2 -4
- crates/ec-opus/src/encoder.rs +7 -7
- crates/ec-opus/src/silk.rs +18 -0
- crates/ec-opus/src/silk_enc_write.rs +12 -1
crates/ec-opus/src/celt_enc.rsmodified+2 -4
| @@ -384,7 +384,7 @@ struct EncBand { | |||
| 384 | } | 384 | } |
| 385 | 385 | ||
| 386 | /// Per-frame encoder diagnostics for the dropout investigation. Captured at | 386 | /// Per-frame encoder diagnostics for the dropout investigation. Captured at |
| 387 | -/// the end of [`CeltEncoder::encode`]; read via [`CeltEncoder::last_diag`]. | 387 | +/// the end of `CeltEncoder::encode`; read via [`CeltEncoder::last_diag`]. |
| 388 | #[derive(Clone, Debug)] | 388 | #[derive(Clone, Debug)] |
| 389 | pub struct CeltFrameDiag { | 389 | pub struct CeltFrameDiag { |
| 390 | /// Transient flag as coded into the bitstream. | 390 | /// Transient flag as coded into the bitstream. |
| @@ -603,9 +603,7 @@ impl CeltEncoder { | |||
| 603 | self.channels | 603 | self.channels |
| 604 | } | 604 | } |
| 605 | 605 | ||
| 606 | - /// Diagnostics captured at the end of the most recent [`encode`] call. | 606 | + /// Diagnostics captured at the end of the most recent `encode` call. |
| 607 | - /// | ||
| 608 | - /// [`encode`]: CeltEncoder::encode | ||
| 609 | pub fn last_diag(&self) -> &CeltFrameDiag { | 607 | pub fn last_diag(&self) -> &CeltFrameDiag { |
| 610 | &self.last_diag | 608 | &self.last_diag |
| 611 | } | 609 | } |
crates/ec-opus/src/encoder.rsmodified+7 -7
| @@ -108,7 +108,7 @@ pub struct Encoder { | |||
| 108 | /// Scratch space for the SILK packet payload, sized once so the steady-state | 108 | /// Scratch space for the SILK packet payload, sized once so the steady-state |
| 109 | /// loop (`steady_state_encode_loop_zero_alloc`) doesn't allocate. | 109 | /// loop (`steady_state_encode_loop_zero_alloc`) doesn't allocate. |
| 110 | silk_buf: [u8; MAX_SILK_PACKET_BYTES], | 110 | silk_buf: [u8; MAX_SILK_PACKET_BYTES], |
| 111 | - /// Hybrid: the last [`Encoder::hybrid_silk_delay_48k`] samples of SILK-layer input. | 111 | + /// Hybrid: the last `Encoder::hybrid_silk_delay_48k` samples of SILK-layer input. |
| 112 | silk_delay: Vec<f32>, | 112 | silk_delay: Vec<f32>, |
| 113 | /// Scratch space for the zero-stuffed SILK/hybrid input, sized once so | 113 | /// Scratch space for the zero-stuffed SILK/hybrid input, sized once so |
| 114 | /// the steady-state loop doesn't allocate a `Vec` per frame. | 114 | /// the steady-state loop doesn't allocate a `Vec` per frame. |
| @@ -241,11 +241,11 @@ impl Encoder { | |||
| 241 | /// delay compensation, 312 samples at 48 kHz. | 241 | /// delay compensation, 312 samples at 48 kHz. |
| 242 | /// SILK (10, 20, 40 or 60 ms frames, when the application/bitrate or an | 242 | /// SILK (10, 20, 40 or 60 ms frames, when the application/bitrate or an |
| 243 | /// explicit [`Encoder::set_mode`] select it — the same | 243 | /// explicit [`Encoder::set_mode`] select it — the same |
| 244 | - /// [`Encoder::silk_choice`] predicate `encode_toc_and_payload` dispatches | 244 | + /// `Encoder::silk_choice` predicate `encode_toc_and_payload` dispatches |
| 245 | /// on, so this always matches which layer actually codes the frame): | 245 | /// on, so this always matches which layer actually codes the frame): |
| 246 | - /// [`SILK_LOOK_AHEAD_48K_NB`], [`SILK_LOOK_AHEAD_48K_MB`] or | 246 | + /// `SILK_LOOK_AHEAD_48K_NB`, `SILK_LOOK_AHEAD_48K_MB` or |
| 247 | - /// [`SILK_LOOK_AHEAD_48K_WB`]. Hybrid: CELT's 120, the SILK layer being | 247 | + /// `SILK_LOOK_AHEAD_48K_WB`. Hybrid: CELT's 120, the SILK layer being |
| 248 | - /// delayed to meet it ([`Encoder::hybrid_silk_delay_48k`]). Any other frame size | 248 | + /// delayed to meet it (`Encoder::hybrid_silk_delay_48k`). Any other frame size |
| 249 | /// falls back to CELT here exactly as `encode_toc_and_payload` does. | 249 | /// falls back to CELT here exactly as `encode_toc_and_payload` does. |
| 250 | pub fn look_ahead(&self, frame_size: usize) -> usize { | 250 | pub fn look_ahead(&self, frame_size: usize) -> usize { |
| 251 | let frame_48k = frame_size * self.upsample; | 251 | let frame_48k = frame_size * self.upsample; |
| @@ -499,7 +499,7 @@ impl Encoder { | |||
| 499 | 499 | ||
| 500 | /// Zero-stuffs a mono, `frame_size`-sample native-rate frame up to | 500 | /// Zero-stuffs a mono, `frame_size`-sample native-rate frame up to |
| 501 | /// `frame_size * upsample` samples at 48 kHz, the rate [`SilkEncoder`] | 501 | /// `frame_size * upsample` samples at 48 kHz, the rate [`SilkEncoder`] |
| 502 | - /// takes — the same technique [`CeltEncoder::encode`] uses, scaled by | 502 | + /// takes — the same technique `CeltEncoder::encode` uses, scaled by |
| 503 | /// `upsample` so the passband gain survives the stuffing. Writes into | 503 | /// `upsample` so the passband gain survives the stuffing. Writes into |
| 504 | /// `out` (an `Encoder` scratch field, not a fresh `Vec` per call) rather | 504 | /// `out` (an `Encoder` scratch field, not a fresh `Vec` per call) rather |
| 505 | /// than returning one, so the caller doesn't allocate every frame; the | 505 | /// than returning one, so the caller doesn't allocate every frame; the |
| @@ -958,7 +958,7 @@ impl Encoder { | |||
| 958 | /// One hybrid frame (10 or 20 ms, mono or stereo, `bandwidth` SWB or FB) | 958 | /// One hybrid frame (10 or 20 ms, mono or stereo, `bandwidth` SWB or FB) |
| 959 | /// into the internal range coder, returning its byte length: the SILK | 959 | /// into the internal range coder, returning its byte length: the SILK |
| 960 | /// layer's symbols (WB, 16 kHz internal, fed the input delayed by | 960 | /// layer's symbols (WB, 16 kHz internal, fed the input delayed by |
| 961 | - /// [`Encoder::hybrid_silk_delay_48k`]), the no-redundancy flag under the decoder's | 961 | + /// `Encoder::hybrid_silk_delay_48k`), the no-redundancy flag under the decoder's |
| 962 | /// exact presence rule, then the CELT layer from band 17 in the same | 962 | /// exact presence rule, then the CELT layer from band 17 in the same |
| 963 | /// coder. CBR: the packet is the bitrate's size unless SILK alone needs | 963 | /// coder. CBR: the packet is the bitrate's size unless SILK alone needs |
| 964 | /// more, in which case CELT keeps [`HYBRID_CELT_MIN_BYTES`] on top. | 964 | /// more, in which case CELT keeps [`HYBRID_CELT_MIN_BYTES`] on top. |
crates/ec-opus/src/silk.rsmodified+18 -0
| @@ -250,17 +250,35 @@ struct Indices { | |||
| 250 | /// packets against ffmpeg-libopus's. | 250 | /// packets against ffmpeg-libopus's. |
| 251 | #[derive(Clone, Debug, Default)] | 251 | #[derive(Clone, Debug, Default)] |
| 252 | pub struct SilkDecIndices { | 252 | pub struct SilkDecIndices { |
| 253 | + /// 0 = inactive/unvoiced, 1 = unvoiced, 2 = voiced (SILK `SignalType`). | ||
| 253 | pub signal_type: i32, | 254 | pub signal_type: i32, |
| 255 | + /// Quantization offset flavor: 0 = low-bitrate offset, 1 = default offset. | ||
| 254 | pub quant_offset_type: i32, | 256 | pub quant_offset_type: i32, |
| 257 | + /// Per-subframe coded excitation gains; each is an index into the gain | ||
| 258 | + /// dequantization table, not a linear gain. | ||
| 255 | pub gains: [i8; 4], | 259 | pub gains: [i8; 4], |
| 260 | + /// Quantized normalized LSF coefficients; 17 entries (`MAX_LPC_ORDER + 1`), | ||
| 261 | + /// the last being the interpolated residual-energy weight. | ||
| 256 | pub nlsf: [i8; 17], | 262 | pub nlsf: [i8; 17], |
| 263 | + /// Interpolation weight between the previous and current frame's NLSFs, | ||
| 264 | + /// Q2 in [0, 4] (4 = no interpolation). | ||
| 257 | pub nlsf_interp_coef_q2: i32, | 265 | pub nlsf_interp_coef_q2: i32, |
| 266 | + /// Raw pitch lag index; the lag in samples is derived from this plus the | ||
| 267 | + /// frame's lag range and minimum lag. | ||
| 258 | pub lag_index: i32, | 268 | pub lag_index: i32, |
| 269 | + /// Index into the pitch-contour codebook for the current bandwidth and | ||
| 270 | + /// subframe count. | ||
| 259 | pub contour_index: i32, | 271 | pub contour_index: i32, |
| 272 | + /// Periodicity index selecting the LTP filter scaling per subframe. | ||
| 260 | pub per_index: usize, | 273 | pub per_index: usize, |
| 274 | + /// Per-subframe LTP codebook indices; `usize::MAX` means LTP is off for | ||
| 275 | + /// that subframe. | ||
| 261 | pub ltp_index: [usize; 4], | 276 | pub ltp_index: [usize; 4], |
| 277 | + /// Index of the LTP gain scaling factor applied to all subframes. | ||
| 262 | pub ltp_scale_index: usize, | 278 | pub ltp_scale_index: usize, |
| 279 | + /// Pseudorandom seed for excitation sign/pulse decoding. | ||
| 263 | pub seed: i32, | 280 | pub seed: i32, |
| 281 | + /// Diagnostic-only counter of SILK frames this state has decoded. | ||
| 264 | pub frames_decoded: usize, | 282 | pub frames_decoded: usize, |
| 265 | } | 283 | } |
| 266 | 284 | ||
crates/ec-opus/src/silk_enc_write.rsmodified+12 -1
| @@ -1,4 +1,4 @@ | |||
| 1 | -//! SILK payload writer (subtask D2a): turns the analysis in [`crate::silk_enc`] | 1 | +//! SILK payload writer (subtask D2a): turns the analysis in `crate::silk_enc` |
| 2 | //! into decodable SILK packets, NB (8 kHz), MB (12 kHz) or WB (16 kHz). | 2 | //! into decodable SILK packets, NB (8 kHz), MB (12 kHz) or WB (16 kHz). |
| 3 | //! | 3 | //! |
| 4 | //! Symbol order is exactly `silk::decode()`'s, and every decision is made | 4 | //! Symbol order is exactly `silk::decode()`'s, and every decision is made |
| @@ -42,14 +42,25 @@ const MAX_PULSE: i32 = 1023; | |||
| 42 | /// call, for the speech-quality diagnostic lane. | 42 | /// call, for the speech-quality diagnostic lane. |
| 43 | #[derive(Clone, Debug, Default)] | 43 | #[derive(Clone, Debug, Default)] |
| 44 | pub struct SilkFrameDiag { | 44 | pub struct SilkFrameDiag { |
| 45 | + /// Whether the VAD classified the input frame as voiced. | ||
| 45 | pub voiced: bool, | 46 | pub voiced: bool, |
| 47 | + /// SILK signal type chosen by the encoder (0 inactive, 1 unvoiced, | ||
| 48 | + /// 2 voiced). | ||
| 46 | pub signal_type: i32, | 49 | pub signal_type: i32, |
| 50 | + /// Per-subframe gain codebook indices as written to the bitstream. | ||
| 47 | pub gain_idx: [i8; MAX_NB_SUBFR], | 51 | pub gain_idx: [i8; MAX_NB_SUBFR], |
| 52 | + /// Number of subframes in the frame (2 for 10 ms, 4 for 20 ms). | ||
| 48 | pub nb_subfr: usize, | 53 | pub nb_subfr: usize, |
| 54 | + /// Raw pitch lag index written to the bitstream (first subframe's). | ||
| 49 | pub lag_index: i32, | 55 | pub lag_index: i32, |
| 56 | + /// Pitch lag in samples per subframe as used by the LTP analysis. | ||
| 50 | pub pitch_l: [i32; MAX_NB_SUBFR], | 57 | pub pitch_l: [i32; MAX_NB_SUBFR], |
| 58 | + /// NLSF interpolation coefficient (Q2, 0..4) encoded for this frame. | ||
| 51 | pub nlsf_interp: i32, | 59 | pub nlsf_interp: i32, |
| 60 | + /// Number of payload bytes the frame's encode produced. | ||
| 52 | pub bytes: usize, | 61 | pub bytes: usize, |
| 62 | + /// Total LTP excitation gain across subframes (linear scale, 0 if the | ||
| 63 | + /// frame had no LTP). | ||
| 53 | pub ltp_gain: f32, | 64 | pub ltp_gain: f32, |
| 54 | } | 65 | } |
| 55 | 66 | ||