forge
Explore
Log in

Don't you dare go Hollow

The MP3 and Vorbis encode seats are the native ec-mp3 / ec-vorbis

Browse files at this commit

f68f46d0fd79caf02c53049fceedbc90c6a52ad3Ahmet Kaan GümüşParent: 8a736e4
  • feat
    • the MP3 and Vorbis encode seats are the native ec-mp3 / ec-vorbis
Show full message
🔁 feat(audio): the MP3 and Vorbis encode seats are the native ec-mp3 / ec-vorbis

The two registry-crate encoder seats (rusty_mp3 0.6, rusty_vorbis 0.1.1)
leave the tree; both formats encode through the codec family's own crates
(path deps, same boundary ec-opus/ec-ac3 already cross).

MP3 (CBR per the card's rate rows): same seat contract, same
Mp3EncoderConfig field names, call sites unchanged. A/B on identical
16-bit PCM (suite fixtures + a 30 s 44.1 kHz stereo music decode),
outputs decoded through symphonia: correlation 0.9994-0.9998 against the
incumbent's 0.9980-0.9991 at the same 192 kbps, PSNR +5..+7 dB, and the
decoded length lands exactly on the mix (the old seat ran 180 samples
long with a 1057-sample shift the gapless tag only partly hid).

Vorbis: the seat's quality knob alone saturates below the incumbent's
operating band, so write_ogg drives the encoder the way its own rate
gates are measured -- rate loop started at quality 0.85 and held to a
128 kbps target. At the incumbent's own 0.85 operating point (123.8 kbps
actual on the music clip, correlation 0.9947) the new seat reads
129.0 kbps actual at correlation 0.9968, +3.1 dB PSNR; against ffmpeg's
libvorbis -q 5 it is par at the same rate (0.9968 vs 0.9973). Every
export decodes to exactly the timeline's frame count, correlation peak
at lag zero.

That measurement retires write_ogg's workaround: the old seat advanced
its granule a hop early and overran the tail, so the function carried a
1024-sample pre-roll and two granule corrections around it. ec-vorbis
reports spec granules and clamps its final one to the sample count fed,
so the pre-roll, the per-packet shift and the manual tail declaration are
deleted. Mono stays dual mono (bit-identical L/R, worst |L-R| = 0
measured) because the format row promises stereo, not because the encoder
refuses mono as the old seat's did.

Perf, named: MP3 encode wall is 0.05x the old seat on the 30 s clip
(4.3 s vs 0.20 s CBR; the old shim encoded blocks across all cores, the
new seat is single-threaded sequential) -- the price of the quality and
gapless-exactness above; Vorbis at the seat's operating point is 1.4x
faster than the old seat (49 ms vs 69 ms per 30 s). audio_export and
backends suites green (14 + 8), export lib tests green, cargo check -p
engine --all-targets zero warnings; lock carries no rusty_mp3/rusty_vorbis
stanza.
Cargo.lockmodified+18 -14
@@ -1647,6 +1647,14 @@ dependencies = [
1647 "ec-core",1647 "ec-core",
1648 ]1648 ]
1649 1649
1650+[[package]]
1651+name = "ec-mp3"
1652+version = "0.1.0"
1653+dependencies = [
1654+ "ec-core",
1655+ "ec-dsp",
1656+]
1657+
1650 [[package]]1658 [[package]]
1651 name = "ec-opus"1659 name = "ec-opus"
1652 version = "0.1.0"1660 version = "0.1.0"
@@ -1657,6 +1665,14 @@ dependencies = [
1657 "wide",1665 "wide",
1658 ]1666 ]
1659 1667
1668+[[package]]
1669+name = "ec-vorbis"
1670+version = "0.1.0"
1671+dependencies = [
1672+ "ec-core",
1673+ "ec-dsp",
1674+]
1675+
1660 [[package]]1676 [[package]]
1661 name = "ec-vp8"1677 name = "ec-vp8"
1662 version = "0.1.0"1678 version = "0.1.0"
@@ -1717,7 +1733,9 @@ dependencies = [
1717 "ec-av1",1733 "ec-av1",
1718 "ec-core",1734 "ec-core",
1719 "ec-h264",1735 "ec-h264",
1736+ "ec-mp3",
1720 "ec-opus",1737 "ec-opus",
1738+ "ec-vorbis",
1721 "flacenc",1739 "flacenc",
1722 "hound",1740 "hound",
1723 "image",1741 "image",
@@ -1733,8 +1751,6 @@ dependencies = [
1733 "oxideav-subtitle",1751 "oxideav-subtitle",
1734 "rav1e",1752 "rav1e",
1735 "rusty_aac",1753 "rusty_aac",
1736- "rusty_mp3",
1737- "rusty_vorbis",
1738 "symphonia",1754 "symphonia",
1739 "symphonia-codec-aac",1755 "symphonia-codec-aac",
1740 "symphonia-core",1756 "symphonia-core",
@@ -5097,18 +5113,6 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
5097 name = "rusty_aac"5113 name = "rusty_aac"
5098 version = "0.5.0"5114 version = "0.5.0"
5099 5115
5100-[[package]]
5101-name = "rusty_mp3"
5102-version = "0.6.1"
5103-source = "registry+https://github.com/rust-lang/crates.io-index"
5104-checksum = "a99f339ec9a2d84eec8fc2a42baa92426966b25238c498e79d57b4e49b14fbad"
5105-
5106-[[package]]
5107-name = "rusty_vorbis"
5108-version = "0.1.1"
5109-source = "registry+https://github.com/rust-lang/crates.io-index"
5110-checksum = "6eddf79e697ce9279ef0e012432cd2889a7b6305a45efb5bb16e8a1d6338646f"
5111-
5112 [[package]]5116 [[package]]
5113 name = "rustybuzz"5117 name = "rustybuzz"
5114 version = "0.14.1"5118 version = "0.14.1"
crates/app/src/export_ui.rsmodified+1 -1
@@ -119,7 +119,7 @@ pub(crate) const FORMATS: [(&[Format], &str, &str, &str); 9] = [
119 &[Format::Ogg],119 &[Format::Ogg],
120 "o",120 "o",
121 "OGG",121 "OGG",
122- "Vorbis (rusty_vorbis) — quality-coded, stereo",122+ "Vorbis (ec-vorbis) — quality-coded, stereo",
123 ),123 ),
124 (&[], "", "VP9", "AV1 above replaces it"),124 (&[], "", "VP9", "AV1 above replaces it"),
125 (&[], "", "VP8", "AV1 above replaces it"),125 (&[], "", "VP8", "AV1 above replaces it"),
crates/app/src/player/export.rsmodified+1 -1
@@ -358,7 +358,7 @@ impl Player {
358 // A format with no picture has no seat to probe -- and the *last*358 // A format with no picture has no seat to probe -- and the *last*
359 // format's is not its answer: cleared rather than left standing, or359 // format's is not its answer: cleared rather than left standing, or
360 // picking MP3 after AV1 would read "SW encode (rav1e) · MP3 · SW360 // picking MP3 after AV1 would read "SW encode (rav1e) · MP3 · SW
361- // (rusty_mp3)", which names an encoder that will not run.361+ // (ec-mp3)", which names an encoder that will not run.
362 if !settings.format.has_video() {362 if !settings.format.has_video() {
363 self.export_seat = None;363 self.export_seat = None;
364 return;364 return;
crates/app/src/tests/media.rsmodified+1 -1
@@ -650,7 +650,7 @@ fn every_codec_row_is_offered_or_says_why_not() {
650 .expect("OGG has a row");650 .expect("OGG has a row");
651 assert_eq!(row, [Format::Ogg], "OGG is a row that picks now");651 assert_eq!(row, [Format::Ogg], "OGG is a row that picks now");
652 assert!(652 assert!(
653- detail.contains("rusty_vorbis"),653+ detail.contains("ec-vorbis"),
654 "the row names the encoder like every other live one: {detail}"654 "the row names the encoder like every other live one: {detail}"
655 );655 );
656 assert!(656 assert!(
crates/engine/Cargo.tomlmodified+22 -15
@@ -81,21 +81,28 @@ ec-av1 = { path = "../../../edith_codecs/crates/ec-av1" }
81 # `vendor/rusty_aac` -- see the patch table in the workspace manifest. Its81 # `vendor/rusty_aac` -- see the patch table in the workspace manifest. Its
82 # *decoder* left the tree when `ec-aac` above took the multichannel seat.82 # *decoder* left the tree when `ec-aac` above took the multichannel seat.
83 rusty_aac = "0.5"83 rusty_aac = "0.5"
84-# The MP3 encoder, so that format is a row a user can pick rather than a licence84+# The MP3 encode seat, the family's own: MPEG-1/2/2.5 Layer III, CBR and true
85-# note: pure Rust, Apache-2.0, CBR and VBR. The decoder side of mp3 is85+# VBR (a quality in [0, 1] whose mean tracks its own bitrate ladder), with a
86-# symphonia's below -- an mp3 has always been importable here, and until this it86+# Xing/Info gapless header whose delay/padding fields are *measured* correct.
87-# was the one format the editor could read and never write.87+# It took the seat the registry crate `rusty_mp3` held -- same public shape
88-rusty_mp3 = "0.6"88+# (`Mp3EncoderConfig { bitrate_kbps, vbr_quality }`, push/finish/next_packet),
89-# The Vorbis encoder, same family and the same reason as the three above: pure89+# which is why the swap stops at this line and the use sites. The decoder side
90-# Rust, Apache-2.0, no C and no FFI. It is the *first* permissively-licensed90+# of mp3 is symphonia's below -- an mp3 has always been importable here, and
91-# pure-Rust Vorbis encoder -- `vorbis_rs` and `vorbis-encoder` are both bindings91+# until 2026-08 this was the one format the editor could read and never write.
92-# to Xiph's C library, which this project's no-install rule forbids, and92+ec-mp3 = { path = "../../../edith_codecs/crates/ec-mp3" }
93-# `oxideav-vorbis` (whose own manifest calls itself an "orphan-rebuild scaffold")93+# The Vorbis encode seat, the family's own: a full Vorbis I encoder -- its own
94-# ships encoder-side *bitstream writers* with no analysis stage at all: no psy94+# floor fit, residue quantiser and per-stream codebooks, block switching
95-# model, no floor fit, no residue quantiser, nothing that turns PCM into a95+# included -- where the registry crates with encoders are either C bindings
96-# packet. This one does the whole pipeline. Its quirks are measured and worked96+# (`vorbis_rs`, `vorbis-encoder`: the project's no-install rule forbids both)
97-# around in [`crate::export::write_ogg`] -- read that before touching this line.97+# or bitstream writers with no analysis stage at all (`oxideav-vorbis`, whose
98-rusty_vorbis = "0.1.1"98+# own manifest calls itself an "orphan-rebuild scaffold"). It took the seat the
99+# first permissively-licensed pure-Rust encoder, `rusty_vorbis`, held. The old
100+# seat emitted long blocks only and numbered its first packet a hop early, so
101+# [`crate::export::write_ogg`] carried a pre-roll and two granule corrections
102+# around it; this one reports spec granules and clamps its final one to the
103+# sample count fed, which let the workaround go. See [`crate::export::write_ogg`]
104+# for the measurement that decided it.
105+ec-vorbis = { path = "../../../edith_codecs/crates/ec-vorbis" }
99 # Symphonia has no Opus at any version -- its feature list stops at vorbis and106 # Symphonia has no Opus at any version -- its feature list stops at vorbis and
100 # there is no `symphonia-codec-opus` crate -- while both of its containers *read*107 # there is no `symphonia-codec-opus` crate -- while both of its containers *read*
101 # the format already: `A_OPUS` and `OpusHead` have always mapped to108 # the format already: `A_OPUS` and `OpusHead` have always mapped to
crates/engine/src/caps.rsmodified+2 -2
@@ -39,11 +39,11 @@ const SW_CODECS: [(&str, &str, bool, bool); 10] = [
39 // Decode is split by width: symphonia carries stereo and narrower, `ec-aac`39 // Decode is split by width: symphonia carries stereo and narrower, `ec-aac`
40 // everything wider; the encoder is `rusty_aac`.40 // everything wider; the encoder is `rusty_aac`.
41 ("AAC", "symphonia / ec-aac / rusty_aac", true, true),41 ("AAC", "symphonia / ec-aac / rusty_aac", true, true),
42- ("MP3", "symphonia / rusty_mp3", true, true),42+ ("MP3", "symphonia / ec-mp3", true, true),
43 ("FLAC", "symphonia / flacenc", true, true),43 ("FLAC", "symphonia / flacenc", true, true),
44 ("PCM", "symphonia / hound", true, true),44 ("PCM", "symphonia / hound", true, true),
45 ("AC-3", "ec-ac3", true, false),45 ("AC-3", "ec-ac3", true, false),
46- ("Vorbis", "symphonia / rusty_vorbis", true, true),46+ ("Vorbis", "symphonia / ec-vorbis", true, true),
47 ("ALAC", "symphonia", true, false),47 ("ALAC", "symphonia", true, false),
48 ];48 ];
49 49
crates/engine/src/export.rsmodified+100 -115
@@ -23,7 +23,7 @@
23 //! equalized one, a source that is not AAC inside an mp4's own sample table —23 //! equalized one, a source that is not AAC inside an mp4's own sample table —
24 //! the sound is decoded, mixed and encoded again with `rusty_aac`24 //! the sound is decoded, mixed and encoded again with `rusty_aac`
25 //! ([`encode_audio`]). The audio-only formats have no such split: `hound` writes25 //! ([`encode_audio`]). The audio-only formats have no such split: `hound` writes
26-//! PCM, `flacenc` encodes FLAC, `rusty_mp3` encodes MP3 and `rusty_vorbis`26+//! PCM, `flacenc` encodes FLAC, `ec-mp3` encodes MP3 and `ec-vorbis`
27 //! encodes Vorbis, so those are always *decoded* out of the timeline. The worker owns everything: the caller gets an27 //! encodes Vorbis, so those are always *decoded* out of the timeline. The worker owns everything: the caller gets an
28 //! [`ExportHandle`] and polls it from its render loop.28 //! [`ExportHandle`] and polls it from its render loop.
29 //!29 //!
@@ -123,7 +123,7 @@ const MAX_EXPLICIT_BITRATE: u64 = 50_000_000;
123 /// The rates the sound may be coded at, smallest first -- what a front-end123 /// The rates the sound may be coded at, smallest first -- what a front-end
124 /// offers and what [`ExportSettings::audio_kbps`] is clamped into. Every one of124 /// offers and what [`ExportSettings::audio_kbps`] is clamped into. Every one of
125 /// them is a legal MPEG-1 Layer III value, so the MP3 path writes the figure it125 /// them is a legal MPEG-1 Layer III value, so the MP3 path writes the figure it
126-/// was given rather than the nearest one `rusty_mp3` snaps to.126+/// was given rather than the nearest one `ec-mp3` snaps to.
127 pub const AUDIO_KBPS: [u32; 4] = [128, 192, 256, 320];127 pub const AUDIO_KBPS: [u32; 4] = [128, 192, 256, 320];
128 128
129 /// What the sound is coded at when nobody picked: the rate this project wrote129 /// What the sound is coded at when nobody picked: the rate this project wrote
@@ -156,9 +156,9 @@ const HEVC_QP_MAX: i32 = 40;
156 /// What an export writes. H.264-in-mp4, AV1 and HEVC -- each of the last two in156 /// What an export writes. H.264-in-mp4, AV1 and HEVC -- each of the last two in
157 /// Matroska or in mp4, the user's pick of container -- are the *video* pairs157 /// Matroska or in mp4, the user's pick of container -- are the *video* pairs
158 /// with both an encoder and a decoder under this project's no-install rule, and158 /// with both an encoder and a decoder under this project's no-install rule, and
159-/// WAV, FLAC, MP3 and Ogg Vorbis are the standalone audio formats with a159+/// pure-Rust encoder: `hound`, `flacenc`, `ec-mp3` and `ec-vorbis`. Opus
160-/// pure-Rust encoder: `hound`, `flacenc`, `rusty_mp3` and `rusty_vorbis`. Opus160+/// still has none as a *file* -- the Matroska seat is `ec-opus`, but a standalone
161-/// still has none -- `oxideav-opus` encodes CELT alone, which is half a codec.161+/// `.opus` row this project does not offer.
162 /// (AAC has one too -- `rusty_aac`, which is what a re-encoded video track's162 /// (AAC has one too -- `rusty_aac`, which is what a re-encoded video track's
163 /// sound leaves through -- but AAC is a container's own audio, never a file of163 /// sound leaves through -- but AAC is a container's own audio, never a file of
164 /// its own here.) VP9 and VP8 are the164 /// its own here.) VP9 and VP8 are the
@@ -198,10 +198,10 @@ pub enum Format {
198 Wav,198 Wav,
199 /// The audio lanes alone, losslessly compressed.199 /// The audio lanes alone, losslessly compressed.
200 Flac,200 Flac,
201- /// The audio lanes alone, MPEG-1 Layer III CBR (`rusty_mp3`) at the rate201+ /// The audio lanes alone, MPEG-1 Layer III CBR (`ec-mp3`) at the rate
202 /// [`ExportSettings::audio_kbps`] asks for.202 /// [`ExportSettings::audio_kbps`] asks for.
203 Mp3,203 Mp3,
204- /// The audio lanes alone, Vorbis I in an Ogg container -- `rusty_vorbis`204+ /// The audio lanes alone, Vorbis I in an Ogg container -- `ec-vorbis`
205 /// encoding, `oxideav-ogg` paging. Quality-coded and not rate-coded, which205 /// encoding, `oxideav-ogg` paging. Quality-coded and not rate-coded, which
206 /// is why [`audio_rate_refusal`] takes the Sound row away here: see206 /// is why [`audio_rate_refusal`] takes the Sound row away here: see
207 /// [`VORBIS_QUALITY`] for the operating point and how it was measured.207 /// [`VORBIS_QUALITY`] for the operating point and how it was measured.
@@ -846,8 +846,8 @@ fn audio_label(
846 match format {846 match format {
847 Format::Wav => "PCM · SW (hound)",847 Format::Wav => "PCM · SW (hound)",
848 Format::Flac => "FLAC · SW (flacenc)",848 Format::Flac => "FLAC · SW (flacenc)",
849- Format::Mp3 => "MP3 · SW (rusty_mp3)",849+ Format::Mp3 => "MP3 · SW (ec-mp3)",
850- Format::Ogg => "Vorbis · SW (rusty_vorbis)",850+ Format::Ogg => "Vorbis · SW (ec-vorbis)",
851 _ => match copied.unwrap_or(!forces_encode(project, ranged)) {851 _ => match copied.unwrap_or(!forces_encode(project, ranged)) {
852 true => "AAC copy",852 true => "AAC copy",
853 // A Matroska file gets Opus where the mix allows it -- 48 kHz and853 // A Matroska file gets Opus where the mix allows it -- 48 kHz and
@@ -918,12 +918,12 @@ pub fn audio_rate_refusal(project: &Project, format: Format, ranged: bool) -> Op
918 match format {918 match format {
919 _ if !has_sound(project) => Some("no sound to write"),919 _ if !has_sound(project) => Some("no sound to write"),
920 Format::Wav | Format::Flac => Some("lossless — the samples themselves, at no rate"),920 Format::Wav | Format::Flac => Some("lossless — the samples themselves, at no rate"),
921- // Vorbis has a quality knob and no rate knob, and the two are not the921+ // Vorbis is written at one measured operating point ([`VORBIS_QUALITY`]
922- // same control wearing different words: measured across this suite's922+ // + [`VORBIS_TARGET_BPS`]), not at a rate a user may pick: its actual
923- // fixtures, the whole usable quality band lands between 55 and 175 kbps923+ // landing moves with the content around that target (124-134 kbps
924- // ([`VORBIS_QUALITY`]), so two of the four rates on offer here are not924+ // across this suite's bench inputs), so a live rate row would print a
925- // rates it can reach at all. A live row would print a figure the file925+ // figure the file does not hold -- the one thing this card is built
926- // does not hold, which is the one thing this card is built not to do.926+ // not to do.
927 Format::Ogg => Some("quality-coded — Vorbis holds no rate to pick"),927 Format::Ogg => Some("quality-coded — Vorbis holds no rate to pick"),
928 Format::Mp3 => None,928 Format::Mp3 => None,
929 _ if forces_encode(project, ranged) => None,929 _ if forces_encode(project, ranged) => None,
@@ -3318,20 +3318,21 @@ fn write_wav(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<()
3318 Ok(())3318 Ok(())
3319 }3319 }
3320 3320
3321-/// The same samples as MPEG-1 Layer III, `rusty_mp3` doing the encoding -- pure3321+/// The same samples as MPEG-1 Layer III, `ec-mp3` doing the encoding -- the
3322-/// Rust like every other encoder here, and the reason this format is a row at3322+/// family's own, taking the seat at the same contract (CBR in, frames out,
3323-/// all: the LGPL `shine-rs` was the only one when it was not.3323+/// `Mp3EncoderConfig`'s fields are the old seat's names), so the swap cost the
3324+/// call sites nothing.
3324 ///3325 ///
3325 /// CBR at the caller's rate, [`DEFAULT_AUDIO_KBPS`] where there was none. Every3326 /// CBR at the caller's rate, [`DEFAULT_AUDIO_KBPS`] where there was none. Every
3326 /// offered rate is already a legal Layer III value, so the encoder's snap is a3327 /// offered rate is already a legal Layer III value, so the encoder's snap is a
3327 /// backstop and not a silent substitution; a sample rate MPEG has no frame for3328 /// backstop and not a silent substitution; a sample rate MPEG has no frame for
3328-/// (anything but 8-48 kHz) is refused there by name rather than written as3329+/// (anything but the nine MPEG rates 8-48 kHz) is refused there by name rather
3329-/// something else.3330+/// than written as something else.
3330 ///3331 ///
3331 /// corner-cut: CBR only -- the card offers rates and not a quality index. Upgrade3332 /// corner-cut: CBR only -- the card offers rates and not a quality index. Upgrade
3332 /// path is `Mp3EncoderConfig::vbr_quality` behind a setting of its own.3333 /// path is `Mp3EncoderConfig::vbr_quality` behind a setting of its own.
3333 fn write_mp3(out: &Path, samples: &[i32], audio: &AudioMeta, kbps: u32) -> crate::Result<()> {3334 fn write_mp3(out: &Path, samples: &[i32], audio: &AudioMeta, kbps: u32) -> crate::Result<()> {
3334- let mut encoder = rusty_mp3::Mp3Encoder::new(rusty_mp3::Mp3EncoderConfig {3335+ let mut encoder = ec_mp3::encode::Mp3Encoder::new(ec_mp3::encode::Mp3EncoderConfig {
3335 bitrate_kbps: kbps,3336 bitrate_kbps: kbps,
3336 vbr_quality: None,3337 vbr_quality: None,
3337 });3338 });
@@ -3353,72 +3354,58 @@ fn write_mp3(out: &Path, samples: &[i32], audio: &AudioMeta, kbps: u32) -> crate
3353 Ok(())3354 Ok(())
3354 }3355 }
3355 3356
3356-/// The Vorbis quality every `.ogg` this program writes is coded at, on3357+/// Where the Vorbis rate loop starts, on `ec-vorbis`'s normalised `[0, 1]`
3357-/// `rusty_vorbis`'s normalised `[0, 1]` scale -- about `-q 8.35` on the scale3358+/// scale, beside [`VORBIS_TARGET_BPS`] -- the two numbers every `.ogg` this
3358-/// Vorbis itself is spoken in (`quality01_from_vorbis_q`).3359+/// program writes is coded at.
3359 ///3360 ///
3360-/// A measured number, not a taste. The 2026-08-11 bench encoded three of this3361+/// A measured operating point, not a taste (2026-09-13 bench, every output
3361-/// suite's fixtures (`test_tone_48k.wav`, `test_av.mp4`, `test_tone.mp3`) at3362+/// decoded back with **symphonia** -- an independent decoder, and the very one
3362-/// every quality from 0.40 to 0.95 and decoded each back with **symphonia** --3363+/// [`crate::audio`] reopens an export with). The incumbent seat's own 0.85 --
3363-/// an independent decoder, and the very one [`crate::audio`] reopens an export3364+/// its top quality that still decoded every fixture to exactly its own length
3364-/// with. Two things came out of it:3365+/// -- measured 124-176 kbps across this suite's fixtures with correlation
3365-///3366+/// 0.9947-0.9957 against the source. The quality knob alone on the new seat
3366-/// * **Below 0.50 the encoder is quiet, not just coarse.** The decoded RMS3367+/// saturates well under that band (0.98 lands ~87 kbps on a 30-second music
3367-/// against the source's runs 0.83-0.94 at quality 0.40 (a 1 to 1.6 dB level3368+/// clip), so the seat is driven the way its own rate gates are measured: the
3368-/// error), and at 0.10 and below the file decodes to near-silence -- the same3369+/// loop starts at 0.85 and is held to a 128 kbps target, which landed
3369-/// class of failure the AC-3 mono downmix has in `crate::audio`. From 0.55 up3370+/// 124-134 kbps actual on the same inputs and beat the incumbent at its own
3370-/// the level sits at 1.000-1.009, which is what a lossy codec should do.3371+/// operating point on every one of them -- correlation 0.9968 against 0.9947
3371-/// * **The band tops out well under the rates the Sound row offers.** Quality3372+/// on the music clip, +3.1 dB PSNR -- at the same size of file. Against
3372-/// 0.85 measured 176, 144 and 148 kbps on the three fixtures; 0.95 only3373+/// ffmpeg's own libvorbis at `-q 5` (125.8 kbps actual on the same clip) it
3373-/// reaches ~200. That is why [`audio_rate_refusal`] takes the row away rather3374+/// reads 0.9968 against 0.9973: par at the same rate.
3374-/// than mapping 128/192/256/320 onto quality steps: the top two are numbers
3375-/// this encoder cannot produce, and a card that printed them would be lying.
3376-///
3377-/// 0.85 is the top of the band where every fixture still decoded to *exactly*
3378-/// its own length (0.95 overshot one by 820 samples), which is the property
3379-/// [`write_ogg`] is built around.
3380 const VORBIS_QUALITY: f32 = 0.85;3375 const VORBIS_QUALITY: f32 = 0.85;
3381 3376
3382-/// The Vorbis block hop, and the size of the pre-roll [`write_ogg`] feeds the3377+/// The rate [`VORBIS_QUALITY`]'s loop is held to, in bits per second. Measured
3383-/// encoder. `rusty_vorbis` emits long blocks only (`N = 2048`, hop `N/2`).3378+/// landing within +1..+5% of target across the bench's inputs; the Sound row
3384-const VORBIS_HOP: usize = 1024;3379+/// stays refused for this format because this target is the encoder's measured
3380+/// operating point, not a number a card may offer.
3381+const VORBIS_TARGET_BPS: i32 = 128_000;
3385 3382
3386-/// The same samples as Vorbis I in an Ogg container: `rusty_vorbis` encodes,3383+/// The same samples as Vorbis I in an Ogg container: `ec-vorbis` encodes,
3387 /// `oxideav-ogg` pages. Pure Rust on both halves, like every other encoder here.3384 /// `oxideav-ogg` pages. Pure Rust on both halves, like every other encoder here.
3388 ///3385 ///
3389-/// Two corrections stand between that library pair and a file this project would3386+/// The old seat's two corrections are gone with it, and the going is measured
3390-/// ship, and both are measured rather than guessed (2026-08-11, decoded back3387+/// rather than assumed (2026-09-13, every output decoded back with symphonia).
3391-/// with symphonia every time):3388+/// This encoder numbers its packets the spec's way -- the first audio packet
3392-///3389+/// at granule 0, every packet after at the absolute sample position its block
3393-/// 1. **One hop of pre-roll.** `rusty_vorbis` advances the granule by a full hop3390+/// ends on -- and clamps its final granule to the sample count it was fed, so
3394-/// on its *first* audio packet, which its own doc comment says decodes to3391+/// a decoder trims the block grid's tail on its own. Written straight through,
3395-/// zero samples. Written straight through, every sample lands ~1024 early:3392+/// every file decodes to exactly the timeline's frame count with the
3396-/// a marker signal whose only energy was its first and last 1024 samples came3393+/// correlation peak at lag zero, which is what the one-hop pre-roll and the
3397-/// back with the head at 36% of its amplitude and a full-scale burst 15003394+/// two granule corrections this function used to carry around the old encoder
3398-/// samples *before* the real one, in what should have been silence. Feeding3395+/// were for.
3399-/// [`VORBIS_HOP`] samples of silence ahead of the mix and subtracting the same
3400-/// from every granule puts it back: head 0.86 against an input peak of 0.80,
3401-/// the phantom burst down to 0.04, the real burst at its own place. The
3402-/// decoder drops the pre-roll itself -- a first page whose granule is under
3403-/// what its packets decode to is exactly how Ogg says "skip this much".
3404-/// 2. **The tail is declared, not encoded.** The block grid overshoots the last
3405-/// sample, so the stream is padded out and the *last* page's granule is set
3406-/// to the timeline's own frame count. A decoder trims to it, which is what
3407-/// makes an `.ogg` here exactly as long as the WAV of the same timeline --
3408-/// the promise [`run_audio`] makes for every other audio format.
3409 ///3396 ///
3410-/// **Stereo, always.** The embedded setup header `rusty_vorbis` ships is a3397+/// **Stereo, always.** The format row promises stereo, so a mono mix is
3411-/// stereo profile: a mono push is refused outright ("bad coupling channels"),3398+/// written as dual mono, both channels bit-identical (measured: `max|L-R|` is
3412-/// and so is anything wider. A mono mix is therefore written as dual mono, both3399+/// exactly 0; the encoder's own channel coupling codes the empty side channel
3413-/// channels bit-identical (measured: `max|L-R|` is exactly 0, and Vorbis's own3400+/// for almost nothing). The encoder would serve a mono stream, but the row
3414-/// channel coupling codes the empty side channel for almost nothing). Wider than3401+/// says stereo and folding the file back down must give exactly what was
3415-/// stereo cannot reach here -- [`crate::audio`] folds 5.1 to stereo when the3402+/// mixed. Wider than stereo cannot reach here -- [`crate::audio`] folds 5.1
3416-/// source is opened -- but it is refused by name rather than left to the3403+/// to stereo when the source is opened -- but it is refused by name rather
3417-/// library's own message.3404+/// than left to the library's own message.
3418 ///3405 ///
3419-/// corner-cut: one quality, [`VORBIS_QUALITY`], with no user control -- the Sound3406+/// corner-cut: one operating point, [`VORBIS_QUALITY`] +
3420-/// row is refused for this format because the rates it offers are not rates3407+/// [`VORBIS_TARGET_BPS`], with no user control -- the Sound row is refused for
3421-/// Vorbis reaches. Upgrade path is a quality picker of its own, worth building3408+/// this format. Upgrade path is a quality picker of its own, worth building
3422 /// the day the card has a control that speaks in quality rather than kbps.3409 /// the day the card has a control that speaks in quality rather than kbps.
3423 fn write_ogg(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<()> {3410 fn write_ogg(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<()> {
3424 if audio.channels > 2 {3411 if audio.channels > 2 {
@@ -3428,47 +3415,49 @@ fn write_ogg(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<()
3428 )3415 )
3429 .into());3416 .into());
3430 }3417 }
3431- // The mp3 path's conversion, so the two files are one mix, plus the pre-roll3418+ // The mp3 path's conversion, so the two files are one mix -- the same
3432- // and (for a mono mix) the dual-mono widening: the same sample in both3419+ // /32768 scaling this engine's own decoders do -- plus (for a mono mix)
3433- // channels is the same signal, not a widening of it, so what a player folds3420+ // the dual-mono widening: the same sample in both channels is the same
3434- // back down is what was mixed.3421+ // signal, not a widening of it, so what a player folds back down is what
3435- let mut pcm: Vec<i16> = vec![0; VORBIS_HOP * 2];3422+ // was mixed.
3436- match audio.channels < 2 {3423+ let pcm: Vec<f32> = match audio.channels < 2 {
3437- true => pcm.extend(samples.iter().flat_map(|&s| [s as i16, s as i16])),3424+ true => samples
3438- false => pcm.extend(samples.iter().map(|&s| s as i16)),3425+ .iter()
3439- }3426+ .flat_map(|&s| [f32::from(s as i16) / 32768.0; 2])
3440- // The block grid has to run past the last real sample or the tail is never3427+ .collect(),
3441- // coded at all; the granule below is what trims the padding back off.3428+ false => samples
3429+ .iter()
3430+ .map(|&s| f32::from(s as i16) / 32768.0)
3431+ .collect(),
3432+ };
3442 let frames = samples.len() / usize::from(audio.channels).max(1);3433 let frames = samples.len() / usize::from(audio.channels).max(1);
3443- pcm.resize(pcm.len() + VORBIS_HOP * 4 * 2, 0);
3444 3434
3445- let mut encoder = rusty_vorbis::VorbisEncoder::new(rusty_vorbis::VorbisEncoderConfig {3435+ let mut encoder = ec_vorbis::VorbisEncoder::new(ec_vorbis::EncoderConfig {
3446- bitrate_bps: rusty_vorbis::BITRATE_NOMINAL,3436+ sample_rate: audio.sample_rate,
3437+ channels: 2,
3438+ bitrate_bps: VORBIS_TARGET_BPS,
3447 quality: VORBIS_QUALITY,3439 quality: VORBIS_QUALITY,
3448- });3440+ })
3441+ .map_err(|e| format!("vorbis encode: {e}"))?;
3449 encoder3442 encoder
3450- .push_pcm_s16(&pcm, 2, audio.sample_rate)3443+ .push_interleaved(&pcm)
3451 .map_err(|e| format!("vorbis encode: {e}"))?;3444 .map_err(|e| format!("vorbis encode: {e}"))?;
3452 encoder.finish();3445 encoder.finish();
3453 let mut packets = Vec::new();3446 let mut packets = Vec::new();
3454 loop {3447 loop {
3455 match encoder.next_packet() {3448 match encoder.next_packet() {
3456 Ok(packet) => packets.push(packet),3449 Ok(packet) => packets.push(packet),
3457- Err(rusty_vorbis::Error::Eof) => break,3450+ Err(ec_core::Error::Eof) => break,
3451+ Err(ec_core::Error::NeedMore) => continue,
3458 Err(e) => return Err(format!("vorbis encode: {e}").into()),3452 Err(e) => return Err(format!("vorbis encode: {e}").into()),
3459 }3453 }
3460 }3454 }
3461- // Identification, comment and setup, then at least one audio packet: fewer3455+ // The three setup headers travel with the encoder, not in the packet
3462- // than four and there is no stream to page.3456+ // stream; with no audio packets there is no stream to page.
3463- if packets.len() < 4 {3457+ if packets.is_empty() {
3464- return Err(format!("vorbis encode: {} packets is not a stream", packets.len()).into());3458+ return Err("vorbis encode: no audio packets is not a stream".into());
3465 }3459 }
3466- let headers = [3460+ let extradata = oxideav_ogg::mux::xiph_lace(&encoder.headers())
3467- &packets[0].data[..],
3468- &packets[1].data[..],
3469- &packets[2].data[..],
3470- ];
3471- let extradata = oxideav_ogg::mux::xiph_lace(&headers)
3472 .ok_or("vorbis encode: the three headers would not lace")?;3461 .ok_or("vorbis encode: the three headers would not lace")?;
3473 3462
3474 let time_base = oxideav_core::TimeBase::new(1, i64::from(audio.sample_rate));3463 let time_base = oxideav_core::TimeBase::new(1, i64::from(audio.sample_rate));
@@ -3492,18 +3481,14 @@ fn write_ogg(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<()
3492 muxer3481 muxer
3493 .write_header()3482 .write_header()
3494 .map_err(|e| format!("ogg mux: {e:?}"))?;3483 .map_err(|e| format!("ogg mux: {e:?}"))?;
3495- let last = packets.len() - 1;3484+ for packet in &packets {
3496- for (i, packet) in packets.iter().enumerate().skip(3) {3485+ // The granule is the encoder's own: the absolute sample position this
3497- // Correction 1 on every packet, correction 2 on the last one.3486+ // packet ends at, clamped to the mix's length on the last one.
3498- let granule = match i == last {
3499- true => frames as i64,
3500- false => (packet.pts - VORBIS_HOP as i64).max(0),
3501- };
3502 muxer3487 muxer
3503 .write_packet(3488 .write_packet(
3504 &oxideav_core::Packet::new(0, time_base, packet.data.clone())3489 &oxideav_core::Packet::new(0, time_base, packet.data.clone())
3505- .with_pts(granule)3490+ .with_pts(packet.granule)
3506- .with_duration(packet.duration),3491+ .with_duration(packet.samples),
3507 )3492 )
3508 .map_err(|e| format!("ogg mux: {e:?}"))?;3493 .map_err(|e| format!("ogg mux: {e:?}"))?;
3509 }3494 }
crates/engine/tests/audio_export.rsmodified+14 -15
@@ -273,7 +273,7 @@ fn exports_the_timeline_as_a_flac() {
273 std::fs::remove_file(&out).unwrap();273 std::fs::remove_file(&out).unwrap();
274 }274 }
275 275
276-/// The third audio row, and the one that used to be a licence note: `rusty_mp3`276+/// The third audio row, and the one that used to be a licence note: `ec-mp3`
277 /// encodes it, and the file is read straight back through symphonia's mp3277 /// encodes it, and the file is read straight back through symphonia's mp3
278 /// decoder -- the very door an mp3 *import* comes in through, so an export can278 /// decoder -- the very door an mp3 *import* comes in through, so an export can
279 /// be dropped back onto the timeline it came from.279 /// be dropped back onto the timeline it came from.
@@ -872,17 +872,17 @@ fn a_51_ac3_source_round_trips_through_a_wav() {
872 }872 }
873 873
874 /// The fourth audio row, and the one that used to be a refusal: Vorbis in an Ogg874 /// The fourth audio row, and the one that used to be a refusal: Vorbis in an Ogg
875-/// container, `rusty_vorbis` encoding and `oxideav-ogg` paging, read straight875+/// container, `ec-vorbis` encoding and `oxideav-ogg` paging, read straight
876 /// back through the engine's own reader like every other export here.876 /// back through the engine's own reader like every other export here.
877 ///877 ///
878 /// The shape is asserted *exactly* -- `assert_timeline_shape`, the same the WAV878 /// The shape is asserted *exactly* -- `assert_timeline_shape`, the same the WAV
879-/// and the FLAC are held to, and not the MP3's within-a-frame slack. That is the879+/// and the FLAC are held to, and not the MP3's within-a-frame slack. The old
880-/// whole point of the two corrections in `export::write_ogg`: the encoder's own880+/// seat needed two corrections in `export::write_ogg` to earn that (its granule
881-/// granule numbering puts every sample a block early and its block grid overruns881+/// numbering ran a hop early and its block grid overran the tail); `ec-vorbis`
882-/// the tail, so written straight through, this file would be a hop out of step882+/// reports spec granules and clamps its last one to the mix's own length, so
883-/// and short of the timeline. The 1 Hz pulse is what proves the *timing* rather883+/// the file is written straight through and still lands here. The 1 Hz pulse
884-/// than merely the length -- a stream shifted by a block lands its peak nearer884+/// is what proves the *timing* rather than merely the length -- a stream
885-/// where the dip belongs.885+/// shifted by a block lands its peak nearer where the dip belongs.
886 #[test]886 #[test]
887 fn exports_the_timeline_as_an_ogg_vorbis() {887 fn exports_the_timeline_as_an_ogg_vorbis() {
888 let out = out_path("ogg", "ogg");888 let out = out_path("ogg", "ogg");
@@ -1108,12 +1108,11 @@ fn a_split_and_crossfaded_clip_has_no_muted_interior() {
1108 std::fs::remove_file(&src).unwrap();1108 std::fs::remove_file(&src).unwrap();
1109 }1109 }
1110 1110
1111-/// A **mono** timeline through the same door. `rusty_vorbis` ships one embedded1111+/// A **mono** timeline through the same door. The format row promises stereo,
1112-/// setup header and it is a stereo profile -- a mono push is refused outright1112+/// so `export::write_ogg` writes a mono mix as dual mono (the encoder itself
1113-/// ("bad coupling channels") -- so `export::write_ogg` writes the mix as dual1113+/// would serve a mono stream; the row is the contract). This is the test that
1114-/// mono. This is the test that it is *dual mono* and not a widening: both1114+/// it is *dual mono* and not a widening: both channels come back
1115-/// channels come back bit-identical, so folding the file back down gives exactly1115+/// bit-identical, so folding the file back down gives exactly what was mixed.
1116-/// what was mixed.
1117 #[test]1116 #[test]
1118 fn a_mono_timeline_exports_as_dual_mono_ogg() {1117 fn a_mono_timeline_exports_as_dual_mono_ogg() {
1119 // A mono fixture, written here because the suite has none: one second of1118 // A mono fixture, written here because the suite has none: one second of