From 237a87ff01dcc3ecb5ac92fe344f1d01ff89af62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 24 Nov 2026 17:37:57 +0300 Subject: [PATCH] ec-opus: SILK comfort noise (silk/CNG.c, bit-exact vs libopus 1.6 SILK PLC), Encoder::set_dtx (libopus DTX: TOC-only packets after 200 ms inactivity, 400 ms refresh), LBRR for stereo 10/20 ms and mono 40/60 ms, loss-driven LTP scaling (silk_LTP_scale_ctrl), MultistreamDecoder::conceal/decode_fec, MultistreamEncoder::set_inband_fec/set_packet_loss_perc; CELT noise PLC synthesizes long blocks like libopus; FEC-off output unchanged --- crates/ec-opus/src/celt.rs | 6 +- crates/ec-opus/src/encoder.rs | 129 ++++++++++++- crates/ec-opus/src/lib.rs | 2 +- crates/ec-opus/src/multistream.rs | 132 ++++++++++--- crates/ec-opus/src/multistream_enc.rs | 14 ++ crates/ec-opus/src/silk.rs | 142 +++++++++++++- crates/ec-opus/src/silk_enc_write.rs | 261 +++++++++++++++++++------- crates/ec-opus/src/stack_budget.rs | 20 +- 8 files changed, 582 insertions(+), 124 deletions(-) diff --git a/crates/ec-opus/src/celt.rs b/crates/ec-opus/src/celt.rs index d59b5669..f2588989 100644 --- a/crates/ec-opus/src/celt.rs +++ b/crates/ec-opus/src/celt.rs @@ -1334,7 +1334,6 @@ struct Plc { ext: Vec, start: usize, end: usize, - transient: bool, } impl CeltDecoder { @@ -1385,7 +1384,6 @@ impl CeltDecoder { ext: vec![0.0; max_n + OVERLAP], start: 0, end: NB_BANDS, - transient: false, }, diag: CeltDecDiag { silence: false, @@ -1522,7 +1520,6 @@ impl CeltDecoder { false }; let short_blocks = if transient { m } else { 0 }; - self.plc.transient = transient; let intra = if tell + 3 <= total_bits { dec.dec_bit_logp(3) @@ -2889,8 +2886,7 @@ impl CeltDecoder { self.decode_mem .copy_within(base + n..base + DECODE_BUFFER, base); } - let short_blocks = if self.plc.transient { m } else { 0 }; - self.inverse_mdcts(short_blocks, lm, n, cc); + self.inverse_mdcts(0, lm, n, cc); } fn plc_pitch_search(&self) -> usize { diff --git a/crates/ec-opus/src/encoder.rs b/crates/ec-opus/src/encoder.rs index c2ca7dc6..a50a1b68 100644 --- a/crates/ec-opus/src/encoder.rs +++ b/crates/ec-opus/src/encoder.rs @@ -87,6 +87,28 @@ pub enum Application { LowDelay, } +const DTX_START_Q1: i32 = 10 * 2 * 20; +const DTX_END_Q1: i32 = (10 + 20) * 2 * 20; +const DTX_ACTIVITY_THRESHOLD: f32 = 0.1; +const DTX_PSEUDO_SNR_THRESHOLD: f32 = 316.23; +const DTX_SILENCE: f32 = 1.0 / 16_777_216.0; + +/// The TOC-only packet libopus sends in DTX: code 0 is the TOC alone; code 3 +/// keeps its frame-count byte with no frames. Self-delimited framing adds a +/// zero frame length after it. +fn dtx_packet(toc: u8, count: u8, self_delimited: bool) -> ([u8; 3], usize) { + let mut bytes = [0u8; 3]; + let len = if toc & 3 == 3 { + bytes[0] = toc; + bytes[1] = count & 0x3F; + if self_delimited { 3 } else { 2 } + } else { + bytes[0] = toc & !3; + if self_delimited { 2 } else { 1 } + }; + (bytes, len) +} + /// One elementary Opus encoder: mono or stereo. #[derive(Clone, Debug)] pub struct Encoder { @@ -157,8 +179,13 @@ pub struct Encoder { lbrr_coded: bool, fec_bandwidth: Option, last_silk: Option, + use_dtx: bool, + nb_no_activity_ms_q1: i32, + peak_signal_energy: f32, } +const STEREO_TAG: u8 = 100; + fn toc_bandwidth(toc: u8) -> Bandwidth { const BW: [Bandwidth; 5] = [ Bandwidth::Narrow, @@ -245,6 +272,9 @@ impl Encoder { lbrr_coded: false, fec_bandwidth: None, last_silk: None, + use_dtx: false, + nb_no_activity_ms_q1: 0, + peak_signal_energy: 0.0, }; // `EC_OPUS_ALIGN=1` turns the alignment on for a whole process — how // the gate rows at `set_libopus_input_alignment` were produced. @@ -397,6 +427,46 @@ impl Encoder { self.packet_loss_perc = perc.min(100); } + /// OPUS_SET_DTX: send TOC-only packets during silence/inactivity (after 200 ms), refreshing every 400 ms. + pub fn set_dtx(&mut self, on: bool) { + self.use_dtx = on; + } + + /// libopus `decide_dtx_mode` plus the activity test of `opus_encode_native` + /// for one frame: true when this frame's packet is a DTX one. + fn dtx_frame(&mut self, pcm: &[f32], frame_size: usize) -> bool { + if !self.use_dtx { + return false; + } + let n = frame_size * self.channels; + let energy = pcm.iter().take(n).map(|x| x * x).sum::() / n as f32; + let is_silence = pcm.iter().all(|x| x.abs() <= DTX_SILENCE); + let (valid, prob) = (self.info.valid, self.info.activity_probability); + if !is_silence && valid && prob > DTX_ACTIVITY_THRESHOLD { + self.peak_signal_energy = (0.999 * self.peak_signal_energy).max(energy); + } + let active = if is_silence { + false + } else if valid { + prob >= DTX_ACTIVITY_THRESHOLD + || self.peak_signal_energy < DTX_PSEUDO_SNR_THRESHOLD * energy + } else { + true + }; + if active { + self.nb_no_activity_ms_q1 = 0; + return false; + } + self.nb_no_activity_ms_q1 += 2 * 1000 * frame_size as i32 / self.sample_rate as i32; + if self.nb_no_activity_ms_q1 > DTX_START_Q1 { + if self.nb_no_activity_ms_q1 <= DTX_END_Q1 { + return true; + } + self.nb_no_activity_ms_q1 = DTX_START_Q1; + } + false + } + /// Current target bitrate. pub fn bitrate(&self) -> u32 { self.bitrate @@ -453,6 +523,8 @@ impl Encoder { self.lbrr_coded = false; self.fec_bandwidth = None; self.last_silk = None; + self.nb_no_activity_ms_q1 = 0; + self.peak_signal_energy = 0.0; } /// Whether the application/bitrate (or an explicit [`Encoder::set_mode`]) @@ -721,7 +793,12 @@ impl Encoder { if let Some(fs_khz) = self.silk_choice(frame_48k) { let budget = self.packet_budget(frame_48k, cap); if self.channels == 2 { - self.last_silk = None; + let (lbrr, loss, same) = ( + self.lbrr_coded, + self.packet_loss_perc, + self.last_silk == Some(fs_khz as u8 + STEREO_TAG), + ); + self.last_silk = Some(fs_khz as u8 + STEREO_TAG); Self::zero_stuff_stereo(pcm, frame_size, self.upsample, &mut self.silk_stuff); if frame_48k > 960 { return self.encode_stereo_silk_multiframe(fs_khz, frame_48k); @@ -737,6 +814,11 @@ impl Encoder { .silk_stereo_wb .get_or_insert_with(|| Box::new(SilkStereoEncoder::new(true))), }; + if !same { + enc.drop_lbrr(); + } + enc.set_lbrr(lbrr, loss); + enc.set_packet_loss(loss); enc.set_bitrate(self.bitrate); enc.set_max_bytes(budget); let n = @@ -765,6 +847,7 @@ impl Encoder { enc.drop_lbrr(); } enc.set_lbrr(lbrr, loss); + enc.set_packet_loss(loss); // Keep SILK's own reservoir-based rate control tracking the // Encoder's current target on every frame — cheap (an Option // store) and catches set_bitrate calls made between frames. @@ -928,8 +1011,7 @@ impl Encoder { fn fec_for(&self, frame_48k: usize) -> (bool, Option) { if !self.inband_fec - || self.channels != 1 - || !matches!(frame_48k, 480 | 960) + || !(matches!(frame_48k, 480 | 960) || (self.channels == 1 && frame_48k <= 2880)) || self.mode == Some(Mode::Celt) { return (false, None); @@ -1140,6 +1222,7 @@ impl Encoder { Err(e) => Err(e), Ok((toc, payload)) => { let n = payload.len(); + let count = payload.first().copied().unwrap_or(0); if out.len() < 1 + n { Err(Error::corrupt(format!( "opus encode: packet needs {} bytes, buffer holds {}", @@ -1149,7 +1232,18 @@ impl Encoder { } else { out[0] = toc; out[1..1 + n].copy_from_slice(payload); - Ok(1 + n) + if self.dtx_frame(pcm, frame_size) { + self.final_range = 0; + let (bytes, len) = dtx_packet(toc, count, false); + if out.len() < len { + Err(Error::corrupt("opus encode: DTX packet buffer too small")) + } else { + out[..len].copy_from_slice(&bytes[..len]); + Ok(len) + } + } else { + Ok(1 + n) + } } } }; @@ -1177,6 +1271,7 @@ impl Encoder { let r = match self.encode_toc_and_payload(input, frame_size, out.len().saturating_sub(3)) { Err(e) => Err(e), Ok((toc, payload)) => { + let count = payload.first().copied().unwrap_or(0); let (head, last) = if toc & 3 == 3 { let count = usize::from(payload[0] & 0x3F); let mut pos = 1; @@ -1210,7 +1305,18 @@ impl Encoder { out[1..1 + head].copy_from_slice(&payload[..head]); out[1 + head..1 + head + len_bytes].copy_from_slice(&len[..len_bytes]); out[1 + head + len_bytes..total].copy_from_slice(&payload[head..]); - Ok(total) + if self.dtx_frame(pcm, frame_size) { + self.final_range = 0; + let (bytes, len) = dtx_packet(toc, count, true); + if out.len() < len { + Err(Error::corrupt("opus encode: DTX packet buffer too small")) + } else { + out[..len].copy_from_slice(&bytes[..len]); + Ok(len) + } + } else { + Ok(total) + } } } } @@ -1270,10 +1376,20 @@ impl Encoder { if self.lbrr_coded { Bandwidth::Full } else { bandwidth }, ); if self.channels == 2 { - self.last_silk = None; + let (lbrr, loss, same) = ( + self.lbrr_coded, + self.packet_loss_perc, + self.last_silk == Some(16 + STEREO_TAG), + ); + self.last_silk = Some(16 + STEREO_TAG); let silk = self .silk_stereo_wb .get_or_insert_with(|| Box::new(SilkStereoEncoder::new(true))); + if !same { + silk.drop_lbrr(); + } + silk.set_lbrr(lbrr, loss); + silk.set_packet_loss(loss); silk.set_bitrate(silk_rate); silk.set_max_bytes(silk_max); silk.encode_hybrid_ms(&delayed, &mut self.range, frame_ms)?; @@ -1290,6 +1406,7 @@ impl Encoder { silk.drop_lbrr(); } silk.set_lbrr(lbrr, loss); + silk.set_packet_loss(loss); silk.set_bitrate(silk_rate); silk.set_max_bytes(silk_max); silk.encode_hybrid_ms(&delayed, &mut self.range, frame_ms)?; diff --git a/crates/ec-opus/src/lib.rs b/crates/ec-opus/src/lib.rs index b0df48a7..eb73ab36 100644 --- a/crates/ec-opus/src/lib.rs +++ b/crates/ec-opus/src/lib.rs @@ -103,7 +103,7 @@ pub struct Decoder { channels: usize, downsample: usize, celt: CeltDecoder, - /// Boxed because a `SilkDecoder` is 6496 bytes, 83% of what a `Decoder` + /// Boxed because a `SilkDecoder` is 6512 bytes, 83% of what a `Decoder` /// costs a caller taking one BY VALUE from `Decoder::new`. It is the /// decoder's largest field and its only large one; `celt` is 1448. /// `Stack`: crate::stack_budget. diff --git a/crates/ec-opus/src/multistream.rs b/crates/ec-opus/src/multistream.rs index 16aff2cc..bb8191ba 100644 --- a/crates/ec-opus/src/multistream.rs +++ b/crates/ec-opus/src/multistream.rs @@ -20,6 +20,7 @@ use ec_core::{Error, Result}; +use crate::packet::Packet; use crate::Decoder; /// A decoder for a multichannel Opus stream, mono through 255 channels. @@ -32,6 +33,8 @@ pub struct MultistreamDecoder { sample_rate: u32, /// Scratch for one stream's output. buf: Vec, + /// Scratch for one stream's first frame as a plain packet. + fec: Vec, } impl MultistreamDecoder { @@ -94,6 +97,7 @@ impl MultistreamDecoder { channels: mapping.len(), sample_rate, buf: vec![0.0; 2 * 5760], + fec: Vec::with_capacity(1276), }) } @@ -166,45 +170,105 @@ impl MultistreamDecoder { rest = &rest[consumed.min(rest.len())..]; if s == 0 { frame_size = n; - if out.len() < n * self.channels { - return Err(Error::corrupt(format!( - "opus multistream: output buffer holds {} samples, packet needs {}", - out.len(), - n * self.channels - ))); - } + self.check_out(frame_size, out)?; } else if n != frame_size { return Err(Error::corrupt(format!( "opus multistream: stream {s} decoded {n} samples, stream 0 gave {frame_size}" ))); } - // Route this stream's channels to the outputs that name them. - for (c, &m) in self.mapping.iter().enumerate() { - if m == 255 { - continue; + self.route(s, frame_size, out); + } + self.silence(frame_size, out); + Ok(frame_size) + } + + /// Conceals `frame_size` lost samples per channel on every stream + /// (libopus `opus_multistream_decode(NULL)`), returning samples per + /// channel. + pub fn conceal(&mut self, frame_size: usize, out: &mut [f32]) -> Result { + self.check_out(frame_size, out)?; + for s in 0..self.streams.len() { + self.streams[s].conceal(frame_size, &mut self.buf)?; + self.route(s, frame_size, out); + } + self.silence(frame_size, out); + Ok(frame_size) + } + + /// Recovers a lost multistream packet from the in-band FEC of the packet + /// after it (libopus `decode_fec=1`). Each stream's first frame is handed + /// to that stream's FEC path; a stream whose bytes cannot be read, and + /// every stream after it, is concealed. Returns samples per channel. + pub fn decode_fec( + &mut self, + next_packet: &[u8], + frame_size: usize, + out: &mut [f32], + ) -> Result { + self.check_out(frame_size, out)?; + let nb_streams = self.streams.len(); + let mut rest = next_packet; + for s in 0..nb_streams { + let last = s == nb_streams - 1; + match first_frame(rest, !last, &mut self.fec) { + Ok(consumed) => { + rest = &rest[consumed.min(rest.len())..]; + self.streams[s].decode_fec(&self.fec, frame_size, &mut self.buf)?; + } + Err(_) => { + rest = &[]; + self.streams[s].conceal(frame_size, &mut self.buf)?; } - let m = m as usize; - let src = if s < self.coupled { - if m == 2 * s { - Some(0) - } else if m == 2 * s + 1 { - Some(1) - } else { - None - } - } else if m == s + self.coupled { + } + self.route(s, frame_size, out); + } + self.silence(frame_size, out); + Ok(frame_size) + } + + fn check_out(&self, frame_size: usize, out: &[f32]) -> Result<()> { + if out.len() < frame_size * self.channels { + return Err(Error::corrupt(format!( + "opus multistream: output buffer holds {} samples, packet needs {}", + out.len(), + frame_size * self.channels + ))); + } + Ok(()) + } + + /// Copies stream `s`'s channels from `self.buf` to the output channels + /// the mapping names. + fn route(&self, s: usize, frame_size: usize, out: &mut [f32]) { + let stream_channels = if s < self.coupled { 2 } else { 1 }; + for (c, &m) in self.mapping.iter().enumerate() { + if m == 255 { + continue; + } + let m = m as usize; + let src = if s < self.coupled { + if m == 2 * s { Some(0) + } else if m == 2 * s + 1 { + Some(1) } else { None - }; - if let Some(off) = src { - for i in 0..frame_size { - out[self.channels * i + c] = self.buf[stream_channels * i + off]; - } + } + } else if m == s + self.coupled { + Some(0) + } else { + None + }; + if let Some(off) = src { + for i in 0..frame_size { + out[self.channels * i + c] = self.buf[stream_channels * i + off]; } } } - // Channels the mapping leaves unassigned are silent. + } + + /// Channels the mapping leaves unassigned are silent. + fn silence(&self, frame_size: usize, out: &mut [f32]) { for (c, &m) in self.mapping.iter().enumerate() { if m == 255 { for i in 0..frame_size { @@ -212,10 +276,22 @@ impl MultistreamDecoder { } } } - Ok(frame_size) } } +/// Reads the first frame of the stream packet at the head of `data` and +/// rebuilds it as a plain code-0 packet in `scratch`, returning the bytes the +/// stream packet occupied. +fn first_frame(data: &[u8], self_delimited: bool, scratch: &mut Vec) -> Result { + let packet = Packet::parse(data, self_delimited)?; + let first: &[u8] = packet.frames.first().copied().unwrap_or(&[]); + let toc = packet.toc; + scratch.clear(); + scratch.push((toc.config << 3) | (u8::from(toc.stereo) << 2)); + scratch.extend_from_slice(first); + Ok(packet.consumed) +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/ec-opus/src/multistream_enc.rs b/crates/ec-opus/src/multistream_enc.rs index c477d6ee..7bef84de 100644 --- a/crates/ec-opus/src/multistream_enc.rs +++ b/crates/ec-opus/src/multistream_enc.rs @@ -136,6 +136,20 @@ impl MultistreamEncoder { } } + /// OPUS_SET_INBAND_FEC on every stream. + pub fn set_inband_fec(&mut self, on: bool) { + for enc in self.streams.iter_mut() { + enc.set_inband_fec(on); + } + } + + /// OPUS_SET_PACKET_LOSS_PERC on every stream. + pub fn set_packet_loss_perc(&mut self, perc: u8) { + for enc in self.streams.iter_mut() { + enc.set_packet_loss_perc(perc); + } + } + /// Drops all inter-frame state in every stream. pub fn reset(&mut self) { for enc in self.streams.iter_mut() { diff --git a/crates/ec-opus/src/silk.rs b/crates/ec-opus/src/silk.rs index 00a21ea8..b6a65bc5 100644 --- a/crates/ec-opus/src/silk.rs +++ b/crates/ec-opus/src/silk.rs @@ -14,7 +14,8 @@ //! //! LBRR (in-band FEC) frames are decoded through [`SilkFrameMode::Lbrr`], and //! lost frames are concealed by the packet loss concealment of the reference -//! (`silk/PLC.c`), selected with [`SilkFrameMode::Lost`]. +//! (`silk/PLC.c`), selected with [`SilkFrameMode::Lost`], and comfort noise +//! (`silk/CNG.c`) is mixed into frames while the signal is noise-like. // SILK is transliterated fixed-point arithmetic: the loops below index parallel // arrays by position because the reference's index arithmetic is the @@ -51,7 +52,12 @@ const N_RATE_LEVELS: usize = 10; pub(crate) const PE_MIN_LAG_MS: i32 = 2; pub(crate) const PE_MAX_LAG_MS: i32 = 18; const STEREO_INTERP_LEN_MS: usize = 8; +const TYPE_NO_VOICE_ACTIVITY: i32 = 0; const TYPE_VOICED: i32 = 2; +const CNG_BUF_MASK_MAX: i32 = 255; +const CNG_GAIN_SMTH_Q16: i32 = 4634; +const CNG_NLSF_SMTH_Q16: i32 = 16348; +const CNG_GAIN_SMTH_THRESHOLD_Q16: i32 = 46396; const MAX_LPC_STABILIZE_ITERATIONS: usize = 16; const BWE_COEF_Q16: i32 = 64881; const BWE_AFTER_LOSS_Q16: i32 = 63570; @@ -124,6 +130,11 @@ pub(crate) fn smulbb(a: i32, b: i32) -> i32 { (a as i16 as i32).wrapping_mul(b as i16 as i32) } +#[inline] +fn smultt(a: i32, b: i32) -> i32 { + (a >> 16) * (b >> 16) +} + #[inline] fn smlabb(a: i32, b: i32, c: i32) -> i32 { a.wrapping_add(smulbb(b, c)) @@ -358,6 +369,30 @@ struct PlcState { subfr_length: usize, } +/// Comfort noise state (`silk_CNG_struct`). +#[derive(Clone, Debug)] +struct CngState { + exc_buf_q14: [i32; MAX_FRAME_LENGTH], + smth_nlsf_q15: [i16; MAX_LPC_ORDER], + synth_state: [i32; MAX_LPC_ORDER], + smth_gain_q16: i32, + rand_seed: i32, + fs_khz: usize, +} + +impl Default for CngState { + fn default() -> Self { + CngState { + exc_buf_q14: [0; MAX_FRAME_LENGTH], + smth_nlsf_q15: [0; MAX_LPC_ORDER], + synth_state: [0; MAX_LPC_ORDER], + smth_gain_q16: 0, + rand_seed: 0, + fs_khz: 0, + } + } +} + /// One SILK channel's inter-frame state. #[derive(Clone, Debug)] struct ChannelState { @@ -389,6 +424,7 @@ struct ChannelState { lbrr_flags: [bool; 3], resampler: Resampler, plc: PlcState, + cng: Box, loss_cnt: i32, } @@ -421,6 +457,7 @@ impl ChannelState { lbrr_flags: [false; 3], resampler: Resampler::default(), plc: PlcState::default(), + cng: Box::default(), loss_cnt: 0, } } @@ -1686,6 +1723,108 @@ impl ChannelState { } } +/// `silk_CNG_exc`: draws the comfort noise excitation from the saved history. +fn cng_exc(exc: &mut [i32], exc_buf: &[i32], rand_seed: &mut i32) { + let mut exc_mask = CNG_BUF_MASK_MAX; + while exc_mask > exc.len() as i32 { + exc_mask >>= 1; + } + let mut seed = *rand_seed; + for v in exc.iter_mut() { + seed = silk_rand(seed); + let idx = ((seed >> 24) & exc_mask) as usize; + *v = exc_buf[idx]; + } + *rand_seed = seed; +} + +impl ChannelState { + /// `silk_CNG_Reset`. + fn cng_reset(&mut self) { + let order = self.lpc_order; + let step = 32767 / (order as i32 + 1); + let mut acc = 0i32; + for i in 0..order { + acc += step; + self.cng.smth_nlsf_q15[i] = acc as i16; + } + self.cng.smth_gain_q16 = 0; + self.cng.rand_seed = 3176576; + } + + /// `silk_CNG`: mixes comfort noise into `frame`. + fn cng(&mut self, ctrl: &FrameCtrl, frame: &mut [i16]) { + if self.fs_khz != self.cng.fs_khz { + self.cng_reset(); + self.cng.fs_khz = self.fs_khz; + } + let order = self.lpc_order; + let sl = self.subfr_length; + let nb = self.nb_subfr; + if self.loss_cnt == 0 && self.prev_signal_type == TYPE_NO_VOICE_ACTIVITY { + for i in 0..order { + let d = self.prev_nlsf_q15[i] as i32 - self.cng.smth_nlsf_q15[i] as i32; + self.cng.smth_nlsf_q15[i] = + (self.cng.smth_nlsf_q15[i] as i32 + smulwb(d, CNG_NLSF_SMTH_Q16)) as i16; + } + let mut max_gain = 0; + let mut subfr = 0; + for i in 0..nb { + if ctrl.gains_q16[i] > max_gain { + max_gain = ctrl.gains_q16[i]; + subfr = i; + } + } + self.cng.exc_buf_q14.copy_within(0..(nb - 1) * sl, sl); + self.cng.exc_buf_q14[..sl].copy_from_slice(&self.exc_q14[subfr * sl..(subfr + 1) * sl]); + for i in 0..nb { + let g = ctrl.gains_q16[i]; + self.cng.smth_gain_q16 += smulwb(g - self.cng.smth_gain_q16, CNG_GAIN_SMTH_Q16); + if smulww(self.cng.smth_gain_q16, CNG_GAIN_SMTH_THRESHOLD_Q16) > g { + self.cng.smth_gain_q16 = g; + } + } + } + if self.loss_cnt != 0 { + let length = frame.len(); + let smth = self.cng.smth_gain_q16; + let mut gain_q16 = smulww(self.plc.rand_scale_q14 as i32, self.plc.prev_gain_q16[1]); + if gain_q16 >= 1 << 21 || smth > 1 << 23 { + gain_q16 = smultt(gain_q16, gain_q16); + gain_q16 = smultt(smth, smth).wrapping_sub(gain_q16 << 5); + gain_q16 = sqrt_approx(gain_q16) << 16; + } else { + gain_q16 = smulww(gain_q16, gain_q16); + gain_q16 = smulww(smth, smth).wrapping_sub(gain_q16 << 5); + gain_q16 = sqrt_approx(gain_q16) << 8; + } + let gain_q10 = gain_q16 >> 6; + + let mut sig = [0i32; MAX_FRAME_LENGTH + MAX_LPC_ORDER]; + cng_exc( + &mut sig[MAX_LPC_ORDER..MAX_LPC_ORDER + length], + &self.cng.exc_buf_q14, + &mut self.cng.rand_seed, + ); + let a_q12 = nlsf2a(&self.cng.smth_nlsf_q15, order); + sig[..MAX_LPC_ORDER].copy_from_slice(&self.cng.synth_state); + for i in 0..length { + let mut pred = (order >> 1) as i32; + for j in 0..order { + pred = smlawb(pred, sig[MAX_LPC_ORDER + i - j - 1], a_q12[j] as i32); + } + let s = MAX_LPC_ORDER + i; + sig[s] = sig[s].saturating_add(lshift_sat32(pred, 4)); + let noise = sat16(rshift_round(smulww(sig[s], gain_q10), 8)); + frame[i] = sat16(frame[i] as i32 + noise as i32); + } + self.cng.synth_state.copy_from_slice(&sig[length..length + MAX_LPC_ORDER]); + } else { + self.cng.synth_state[..order].fill(0); + } + } +} + /// `silk_LPC_analysis_filter`: the whitening filter used to rebuild the LTP /// state from previously decoded output. fn lpc_analysis_filter(out: &mut [i16], input: &[i16], b_q12: &[i16], len: usize, d: usize) { @@ -1869,6 +2008,7 @@ fn decode_frame( let mv_len = ch.ltp_mem_length - fl; ch.out_buf.copy_within(fl..fl + mv_len, 0); ch.out_buf[mv_len..mv_len + fl].copy_from_slice(&out[..fl]); + ch.cng(&ctrl, &mut out[..fl]); ch.plc_glue_frames(&mut out[..fl]); ch.lag_prev = ctrl.pitch_l[ch.nb_subfr - 1]; fl diff --git a/crates/ec-opus/src/silk_enc_write.rs b/crates/ec-opus/src/silk_enc_write.rs index a62ba347..31b2ba13 100644 --- a/crates/ec-opus/src/silk_enc_write.rs +++ b/crates/ec-opus/src/silk_enc_write.rs @@ -97,10 +97,15 @@ pub struct SilkEncoder { last_diag: SilkFrameDiag, lbrr_enabled: bool, lbrr_gain_increases: i32, - pending_lbrr: Option>, - lbrr_in_packet: Option>, + pending_lbrr: [Option>; MAX_PACKET_FRAMES], + lbrr_in_packet: [Option>; MAX_PACKET_FRAMES], + lbrr_chain: Option, + loss_perc: u8, + last_snr_db: f32, } +const MAX_PACKET_FRAMES: usize = 3; + /// Noise-shaping constants: AR (denominator) and MA (numerator) bandwidth /// expansions of the LPC, harmonic comb depth, voiced spectral tilt, and the /// linear ratio of one gain-quantiser step (2^(1.365 dB / 6.02)). @@ -182,8 +187,11 @@ impl SilkEncoder { last_diag: SilkFrameDiag::default(), lbrr_enabled: false, lbrr_gain_increases: 7, - pending_lbrr: None, - lbrr_in_packet: None, + pending_lbrr: Default::default(), + lbrr_in_packet: Default::default(), + lbrr_chain: None, + loss_perc: 0, + last_snr_db: 0.0, } } @@ -225,18 +233,28 @@ impl SilkEncoder { 7 }; } else { - self.pending_lbrr = None; + self.pending_lbrr = Default::default(); } self.lbrr_enabled = enabled; } - /// Drops the LBRR frame waiting for the next packet (that packet will not follow the frame it protects). + /// Drops the LBRR frames waiting for the next packet (that packet will not follow the frames they protect). pub fn drop_lbrr(&mut self) { - self.pending_lbrr = None; + self.pending_lbrr = Default::default(); + } + + /// Expected packet loss in percent; raises LTP scaling (libopus silk_LTP_scale_ctrl). + pub fn set_packet_loss(&mut self, perc: u8) { + self.loss_perc = perc; } fn reset_state(&mut self) { + let (lbrr, gain_increases, loss_perc) = + (self.lbrr_enabled, self.lbrr_gain_increases, self.loss_perc); *self = Self::with_fs_khz(self.fs_khz); + self.lbrr_enabled = lbrr; + self.lbrr_gain_increases = gain_increases; + self.loss_perc = loss_perc; } /// Algorithmic delay in 48 kHz samples: the analysis resampler only @@ -278,17 +296,17 @@ impl SilkEncoder { let mut frames = Vec::with_capacity(frames_per_packet); let sub_ms = if frame_ms == 10 { 10 } else { 20 }; let mut prev_signal_type = 0; + self.lbrr_in_packet = Default::default(); for i in 0..frames_per_packet { let from = i * sub_ms * 48; let to = from + sub_ms * 48; - let conditional = i > 0; let trial = self.encode_inner( &pcm48[from..to], sub_ms, None, - conditional, + i, + frames_per_packet, prev_signal_type, - frames_per_packet == 1, )?; prev_signal_type = trial.signal_type; frames.push(trial); @@ -298,8 +316,9 @@ impl SilkEncoder { } self.range.reset(1275); let refs: Vec<&Trial> = frames.iter().collect(); - let lbrr = self.lbrr_in_packet.take(); - write_packet_header(&mut self.range, &refs, lbrr.as_deref()); + let lbrr = std::mem::take(&mut self.lbrr_in_packet); + let lbrr_refs: [Option<&Trial>; MAX_PACKET_FRAMES] = lbrr.each_ref().map(|t| t.as_deref()); + write_packet_header(&mut self.range, &refs, &lbrr_refs[..frames_per_packet]); prev_signal_type = 0; for (i, frame) in frames.iter().enumerate() { write_frame_data(&mut self.range, frame, i > 0, prev_signal_type); @@ -347,7 +366,7 @@ impl SilkEncoder { enc: &mut RangeEncoder, frame_ms: usize, ) -> Result<()> { - let trial = self.encode_inner(pcm48, frame_ms, Some(enc), false, 0, true)?; + let trial = self.encode_inner(pcm48, frame_ms, Some(enc), 0, 1, 0)?; self.voiced_frames += usize::from(trial.voiced); Ok(()) } @@ -396,9 +415,9 @@ impl SilkEncoder { pcm48: &[f32], frame_ms: usize, shared: Option<&mut RangeEncoder>, - conditional: bool, + frame: usize, + frames: usize, prev_signal_type: i32, - single_frame_packet: bool, ) -> Result { assert!( matches!(frame_ms, 10 | 20), @@ -409,12 +428,9 @@ impl SilkEncoder { 48 * frame_ms, "SilkEncoder input is 48 kHz mono" ); - let pending = if single_frame_packet { - self.pending_lbrr.take() - } else { - self.pending_lbrr = None; - None - }; + let conditional = frame > 0; + let single_frame_packet = frames == 1; + let pending = self.pending_lbrr[frame].take(); let fs = self.fs_khz; let order = if fs == 16 { MAX_LPC_ORDER } else { 10 }; let nb_subfr = frame_ms / 5; @@ -516,6 +532,7 @@ impl SilkEncoder { // of the best vector is the LTP gain that picks the scale index. let mut targets = [0i32; MAX_NB_SUBFR]; let mut ltp_gain = 0f32; + let mut ltp_res_energy = 0f32; { let mut r_ol: Vec = (-(n as isize)..0).map(whiten).collect(); r_ol.extend_from_slice(&res); @@ -534,6 +551,7 @@ impl SilkEncoder { ((0..sub).map(|i| res[k * sub + i].powi(2)).sum(), 0.0) }; ltp_gain = ltp_gain.max(gsum); + ltp_res_energy += e; let rms = (e / sub as f32).sqrt(); targets[k] = ((rms * 65536.0).round() as i64).clamp(1, i32::MAX as i64) as i32; } @@ -548,7 +566,7 @@ impl SilkEncoder { }; // Over-unity LTP gain: scale the previous frame's history down so // quantisation error does not build up through the pitch loop. - let ltp_scale_index = if !voiced { + let mut ltp_scale_index = if !voiced { 0 } else if ltp_gain > 1.25 { 2 @@ -557,6 +575,20 @@ impl SilkEncoder { } else { 0 }; + if !conditional && voiced && self.loss_perc > 0 { + let mut round_loss = self.loss_perc as f32 * frames as f32; + if self.lbrr_enabled { + round_loss = 2.0 + round_loss * round_loss / 100.0; + } + let res_energy: f32 = res.iter().map(|v| v * v).sum(); + let pred_gain_db = + (10.0 * (res_energy / ltp_res_energy.max(1e-9)).log10()).max(0.0); + let x_gain = pred_gain_db * round_loss; + let snr = self.last_snr_db; + let loss_index = usize::from(x_gain > 2f32.powf(22.66 - snr)) + + usize::from(x_gain > 2f32.powf(30.47 - snr)); + ltp_scale_index = ltp_scale_index.max(loss_index); + } let ltp_scale = LTPSCALES_TABLE_Q14[ltp_scale_index] as f32 / 16384.0; // Inactive or low-energy frames (and sparse voiced excitation) take the // small quantisation offset; dense unvoiced excitation the large one. @@ -717,15 +749,15 @@ impl SilkEncoder { // One full trial at a common gain offset (in quantiser steps): returns // the coded packet body so the rate loop can read its exact size. let candidates: Vec = if voiced { vec![0, 1, 2] } else { vec![0] }; - let mut trial = |step: i32| -> Trial { + let mut trial = |step: i32, cond: bool, start_prev: i32| -> Trial { let scale = GAIN_STEP.powi(step); let mut t = targets; for v in t.iter_mut() { *v = ((*v as f64 * scale as f64).round() as i64).clamp(1, i32::MAX as i64) as i32; } - let mut prev_gain_index = self.prev_gain_index; + let mut prev_gain_index = start_prev; let (gain_idx, gains_q16) = - quantize_gains(&t, &mut prev_gain_index, conditional, nb_subfr); + quantize_gains(&t, &mut prev_gain_index, cond, nb_subfr); let (per_index, run) = candidates .iter() .map(|&per| (per, run(per, &gains_q16))) @@ -756,8 +788,9 @@ impl SilkEncoder { }; let enc = &mut self.range; enc.reset(1275); - write_packet_header(enc, &[&trial], pending.as_deref()); - write_frame_data(enc, &trial, conditional, prev_signal_type); + let measured_lbrr = [if single_frame_packet { pending.as_deref() } else { None }]; + write_packet_header(enc, &[&trial], &measured_lbrr); + write_frame_data(enc, &trial, cond, prev_signal_type); enc.done(); debug_assert!(!enc.error()); let len = enc.range_bytes(); @@ -769,7 +802,7 @@ impl SilkEncoder { // Rate control: a common gain offset moves every subframe's pulse // magnitudes together; the reservoir carries each packet's miss. let mut chosen_step = if CARRY_RATE_STEP { self.rate_step } else { 0 }; - let mut best = trial(chosen_step); + let mut best = trial(chosen_step, conditional, self.prev_gain_index); if let Some(bps) = self.target_bps { let mut frame_bits = bps as f32 * frame_ms as f32 / 1000.0; // A packet cap is a promise to fill it: the CBR packet is padded to @@ -809,7 +842,7 @@ impl SilkEncoder { if step == s0 { break; } - let t = trial(step); + let t = trial(step, conditional, self.prev_gain_index); let b1 = bits_of(&t); if (b1 - target).abs() < (b0 - target).abs() { if b1 != b0 { @@ -845,7 +878,7 @@ impl SilkEncoder { } floor_step = best_step; let before = best.bytes.len(); - best = trial(step); + best = trial(step, conditional, self.prev_gain_index); best_step = step; trials += 1; if best.bytes.len() == before { @@ -858,7 +891,7 @@ impl SilkEncoder { while best.bytes.len() > max && mul < 64.0 { mul *= if mul < 4.0 { 1.15 } else { 2.0 }; lam_mul.set(mul); - best = trial(best_step); + best = trial(best_step, conditional, self.prev_gain_index); } lam_mul.set(1.0); // The ceil step can overshoot a whole step's worth of bytes; @@ -868,7 +901,7 @@ impl SilkEncoder { && best_step - 1 > floor_step && trials < MAX_BUDGET_TRIALS { - let finer = trial(best_step - 1); + let finer = trial(best_step - 1, conditional, self.prev_gain_index); trials += 1; if finer.bytes.len() > max { break; @@ -891,18 +924,34 @@ impl SilkEncoder { ) }; } - let new_lbrr = if self.lbrr_enabled && single_frame_packet && best.vad_flag { - Some(Box::new(trial(chosen_step + self.lbrr_gain_increases))) + let (lbrr_cond, lbrr_prev) = match self.lbrr_chain { + Some(prev) if conditional => (true, prev), + _ => (false, self.prev_gain_index), + }; + let new_lbrr = if self.lbrr_enabled && best.vad_flag { + Some(Box::new(trial( + chosen_step + self.lbrr_gain_increases, + lbrr_cond, + lbrr_prev, + ))) } else { None }; if let Some(enc) = shared { let trial_ref = &best; - write_packet_header(enc, &[trial_ref], pending.as_deref()); + write_packet_header(enc, &[trial_ref], &[pending.as_deref()]); write_frame_data(enc, trial_ref, conditional, prev_signal_type); } - self.pending_lbrr = new_lbrr; - self.lbrr_in_packet = pending; + self.lbrr_chain = new_lbrr.as_ref().map(|t| t.prev_gain_index); + self.pending_lbrr[frame] = new_lbrr; + if frame + 1 == frames { + for slot in self.pending_lbrr.iter_mut().skip(frames) { + *slot = None; + } + } + self.lbrr_in_packet[frame] = pending; + let x_energy: f32 = x.iter().map(|v| v * v).sum(); + self.last_snr_db = 10.0 * (x_energy / best.run.err.max(1e-9)).max(1e-9).log10(); self.prev_gain_index = best.prev_gain_index; self.shape_d.copy_from_slice(&best.run.d[n..]); self.shape_u.copy_from_slice(&best.run.u[n..]); @@ -1006,6 +1055,24 @@ impl SilkStereoEncoder { self.max_bytes = max; } + /// Enables LBRR on the mid and side channels (see SilkEncoder::set_lbrr). + pub fn set_lbrr(&mut self, enabled: bool, loss_perc: u8) { + self.mid.set_lbrr(enabled, loss_perc); + self.side.set_lbrr(enabled, loss_perc); + } + + /// Drops the LBRR frames waiting for the next packet on both channels. + pub fn drop_lbrr(&mut self) { + self.mid.drop_lbrr(); + self.side.drop_lbrr(); + } + + /// Expected packet loss in percent; raises LTP scaling on both channels. + pub fn set_packet_loss(&mut self, perc: u8) { + self.mid.set_packet_loss(perc); + self.side.set_packet_loss(perc); + } + /// Hands each channel its share of the packet budget, split as the bits /// are (`mid_bps : side_bps`), less a two-byte margin for the shared header. /// A side channel that is not coded takes no share. @@ -1150,26 +1217,27 @@ impl SilkStereoEncoder { }; let mid_trial = self .mid - .encode_inner(&mid, frame_ms, None, false, 0, true)?; + .encode_inner(&mid, frame_ms, None, 0, 1, 0)?; let side_trial = if mid_only { None } else { self.side_budget_after_mid(mid_trial.bytes.len()); Some( self.side - .encode_inner(&side, frame_ms, None, false, 0, true)?, + .encode_inner(&side, frame_ms, None, 0, 1, 0)?, ) }; - let side_vad = side_trial.as_ref().map(|t| t.vad_flag).unwrap_or(false); - write_stereo_packet_header(enc, mid_trial.vad_flag, side_vad); - write_stereo_zero_pred(enc); - if !side_vad { - enc.enc_icdf(usize::from(mid_only), &STEREO_ONLY_CODE_MID_ICDF, 8); - } - write_frame_data(enc, &mid_trial, false, 0); - if let Some(trial) = &side_trial { - write_frame_data(enc, trial, false, 0); - } + let mid_lbrr = self.mid.lbrr_in_packet[0].take(); + let side_lbrr = self.side.lbrr_in_packet[0].take(); + write_stereo_packet( + enc, + &mid_trial, + side_trial.as_ref(), + mid_only, + self.prev_mid_only, + mid_lbrr.as_deref(), + side_lbrr.as_deref(), + ); self.mid.replay_ms(&mid_trial.bytes, frame_ms)?; match &side_trial { Some(trial) => self.side.replay_ms(&trial.bytes, frame_ms)?, @@ -1231,32 +1299,29 @@ impl SilkStereoEncoder { }; let mid_trial = self .mid - .encode_inner(&mid, frame_ms, None, false, 0, true)?; + .encode_inner(&mid, frame_ms, None, 0, 1, 0)?; let side_trial = if mid_only { None } else { self.side_budget_after_mid(mid_trial.bytes.len()); Some( self.side - .encode_inner(&side, frame_ms, None, false, 0, true)?, + .encode_inner(&side, frame_ms, None, 0, 1, 0)?, ) }; self.range.reset(1275); - write_stereo_packet_header( + let mid_lbrr = self.mid.lbrr_in_packet[0].take(); + let side_lbrr = self.side.lbrr_in_packet[0].take(); + write_stereo_packet( &mut self.range, - mid_trial.vad_flag, - side_trial.as_ref().map(|t| t.vad_flag).unwrap_or(false), + &mid_trial, + side_trial.as_ref(), + mid_only, + self.prev_mid_only, + mid_lbrr.as_deref(), + side_lbrr.as_deref(), ); - write_stereo_zero_pred(&mut self.range); - if !side_trial.as_ref().map(|t| t.vad_flag).unwrap_or(false) { - self.range - .enc_icdf(usize::from(mid_only), &STEREO_ONLY_CODE_MID_ICDF, 8); - } - write_frame_data(&mut self.range, &mid_trial, false, 0); - if let Some(trial) = &side_trial { - write_frame_data(&mut self.range, trial, false, 0); - } self.range.done(); debug_assert!(!self.range.error()); let len = self.range.range_bytes(); @@ -1317,11 +1382,39 @@ impl SilkStereoEncoder { } } -fn write_stereo_packet_header(enc: &mut RangeEncoder, mid_vad: bool, side_vad: bool) { - enc.enc_bit_logp(mid_vad, 1); - enc.enc_bit_logp(false, 1); +fn write_stereo_packet( + enc: &mut RangeEncoder, + mid: &Trial, + side: Option<&Trial>, + mid_only: bool, + prev_mid_only: bool, + mid_lbrr: Option<&Trial>, + side_lbrr: Option<&Trial>, +) { + let side_lbrr = side_lbrr.filter(|_| mid_lbrr.is_some()); + let side_vad = side.is_some_and(|t| t.vad_flag); + enc.enc_bit_logp(mid.vad_flag, 1); + enc.enc_bit_logp(mid_lbrr.is_some(), 1); enc.enc_bit_logp(side_vad, 1); - enc.enc_bit_logp(false, 1); + enc.enc_bit_logp(side_lbrr.is_some(), 1); + if let Some(m) = mid_lbrr { + write_stereo_zero_pred(enc); + if side_lbrr.is_none() { + enc.enc_icdf(usize::from(prev_mid_only), &STEREO_ONLY_CODE_MID_ICDF, 8); + } + write_frame_data(enc, m, false, 0); + if let Some(s) = side_lbrr { + write_frame_data(enc, s, false, 0); + } + } + write_stereo_zero_pred(enc); + if !side_vad { + enc.enc_icdf(usize::from(mid_only), &STEREO_ONLY_CODE_MID_ICDF, 8); + } + write_frame_data(enc, mid, false, 0); + if let Some(s) = side { + write_frame_data(enc, s, false, 0); + } } fn write_stereo_zero_pred(enc: &mut RangeEncoder) { @@ -1366,15 +1459,37 @@ struct Trial { seed_index: i32, } -fn write_packet_header(enc: &mut RangeEncoder, frames: &[&Trial], lbrr: Option<&Trial>) { +fn write_packet_header(enc: &mut RangeEncoder, frames: &[&Trial], lbrr: &[Option<&Trial>]) { for frame in frames { enc.enc_bit_logp(frame.vad_flag, 1); } - enc.enc_bit_logp(lbrr.is_some(), 1); - if let Some(t) = lbrr - && frames.len() == 1 - { - write_frame_data(enc, t, false, 0); + let lbrr = &lbrr[..frames.len()]; + let any = lbrr.iter().any(Option::is_some); + enc.enc_bit_logp(any, 1); + if !any { + return; + } + if frames.len() > 1 { + let mask = lbrr + .iter() + .enumerate() + .fold(0usize, |m, (i, t)| m | (usize::from(t.is_some()) << i)); + let icdf: &[u8] = if frames.len() == 2 { + &LBRR_FLAGS_2_ICDF + } else { + &LBRR_FLAGS_3_ICDF + }; + enc.enc_icdf(mask - 1, icdf, 8); + } + for (i, slot) in lbrr.iter().enumerate() { + let Some(t) = slot else { continue }; + let conditional = i > 0 && lbrr[i - 1].is_some(); + let prev_signal_type = if conditional { + lbrr[i - 1].map_or(0, |p| p.signal_type) + } else { + 0 + }; + write_frame_data(enc, t, conditional, prev_signal_type); } } diff --git a/crates/ec-opus/src/stack_budget.rs b/crates/ec-opus/src/stack_budget.rs index 8a069b89..10cd7d1c 100755 --- a/crates/ec-opus/src/stack_budget.rs +++ b/crates/ec-opus/src/stack_budget.rs @@ -69,8 +69,8 @@ //! that holds one is a `Box`, which //! [`the_crate_private_silk_encoders_stay_behind_a_box`] pins by source. //! -//! **Where the number sits.** At 8 KiB with the worst budgeted return at 4,080 -//! bytes ([`Encoder`]), the worst a caller owes is `2 x 4080 = 8,160` bytes -- +//! **Where the number sits.** At 8 KiB with the worst budgeted return at 4,088 +//! bytes ([`Encoder`]), the worst a caller owes is `2 x 4088 = 8,176` bytes -- //! **0.39%** of a 2 MiB thread -- and the budget sits 2.01x above the //! incumbent. The pre-fix `Encoder` (87,024 B) is **10.62x over** and the //! pre-fix `Decoder` (7,576 B) sat at 92.5% of it, so the historical defect @@ -114,7 +114,7 @@ pub(crate) const BY_VALUE_TYPES: &[(&str, Option, bool, &str)] = &[ // -- lib.rs ----------------------------------------------------------- ( "Decoder", - Some(1576), + Some(1568), true, "Decoder::new -> Result. Was 7576, 92.5% of the budget, \ because a 6304-byte SilkDecoder sat inline; that field is now a Box", @@ -122,7 +122,7 @@ pub(crate) const BY_VALUE_TYPES: &[(&str, Option, bool, &str)] = &[ // -- encoder.rs ------------------------------------------------------- ( "Encoder", - Some(4080), + Some(4088), true, "Encoder::new -> Result. Was 87024, 10.62x the budget: six \ inline Option/Option slots (79176 \ @@ -138,7 +138,7 @@ pub(crate) const BY_VALUE_TYPES: &[(&str, Option, bool, &str)] = &[ // -- celt.rs ---------------------------------------------------------- ( "CeltDecoder", - Some(1448), + Some(1440), true, "celt::CeltDecoder::new(channels, downsample) -> Self; also moved by \ value into Decoder::celt", @@ -164,7 +164,7 @@ pub(crate) const BY_VALUE_TYPES: &[(&str, Option, bool, &str)] = &[ // -- multistream.rs / multistream_enc.rs ------------------------------ ( "MultistreamDecoder", - Some(96), + Some(120), true, "MultistreamDecoder::with_rate / try_with_rate, the crate's deepest \ public by-value chain: with_rate -> try_with_rate -> Result<..>", @@ -218,10 +218,10 @@ pub(crate) const BY_VALUE_TYPES: &[(&str, Option, bool, &str)] = &[ // -- silk.rs ---------------------------------------------------------- ( "SilkDecoder", - Some(6496), + Some(6512), true, "silk::SilkDecoder::new -> Self, and it is `pub use`d at the crate \ - root, so 6496 bytes is a caller's by-value cost TODAY even though \ + root, so 6512 bytes is a caller's by-value cost TODAY even though \ Decoder::new moves it straight into a Box. At 77% of the budget it \ is the LARGEST budgeted row in the table, and the one that says how \ little headroom the budget would have left if it had stayed inline", @@ -235,7 +235,7 @@ pub(crate) const BY_VALUE_TYPES: &[(&str, Option, bool, &str)] = &[ // -- silk_enc_write.rs ------------------------------------------------ ( "SilkEncoder", - Some(6880), + Some(6944), false, "silk_enc_write::SilkEncoder::new -> Self. `pub`, `pub use`d at the \ crate root, and returned by value -- but every field that holds one \ @@ -243,7 +243,7 @@ pub(crate) const BY_VALUE_TYPES: &[(&str, Option, bool, &str)] = &[ ), ( "SilkStereoEncoder", - Some(20432), + Some(20576), false, "silk_enc_write::SilkStereoEncoder::new -> Self. The largest single \ type in the crate at 2.42x the budget, and the reason three of the \