Merge branch 'lane-mp3vorbis-swap' (f68f46d): MP3 and Vorbis encode seats are ec-mp3 / ec-vorbis -- rusty_mp3 and rusty_vorbis leave the tree. Vorbis: strictly better operating point (r 0.9968 vs 0.9947, +3.1 dB, same size, par with ffmpeg q5), pre-roll/granule corrections obsolete (lag-0 sample-exact through symphonia), encode ~1.2-1.5x faster. MP3: gapless-exact (incumbent was +648 samples), quality reproduced equal-or-better. DISCLOSED TRADE: MP3 encode is ~7x realtime stereo (428.6ms/3s music, 4188.5ms/30s real) vs rusty_mp3's 147-283x -- a 2h film's stereo track exports in ~17 min vs ~48s, and MP3 is an audio-only export so encode IS the wall; single-thread vs single-thread (rusty_mp3 is thread_local-only). lane-ecmp3-perf armed in the same batch
Browse files at this commit8 changed files +159 -164
- Cargo.lock +18 -14
- crates/app/src/export_ui.rs +1 -1
- crates/app/src/player/export.rs +1 -1
- crates/app/src/tests/media.rs +1 -1
- crates/engine/Cargo.toml +22 -15
- crates/engine/src/caps.rs +2 -2
- crates/engine/src/export.rs +100 -115
- crates/engine/tests/audio_export.rs +14 -15
Cargo.lockmodified+18 -14
| @@ -1663,6 +1663,14 @@ dependencies = [ | |||
| 1663 | "ec-core", | 1663 | "ec-core", |
| 1664 | ] | 1664 | ] |
| 1665 | 1665 | ||
| 1666 | +[[package]] | ||
| 1667 | +name = "ec-mp3" | ||
| 1668 | +version = "0.1.0" | ||
| 1669 | +dependencies = [ | ||
| 1670 | + "ec-core", | ||
| 1671 | + "ec-dsp", | ||
| 1672 | +] | ||
| 1673 | + | ||
| 1666 | [[package]] | 1674 | [[package]] |
| 1667 | name = "ec-opus" | 1675 | name = "ec-opus" |
| 1668 | version = "0.1.0" | 1676 | version = "0.1.0" |
| @@ -1673,6 +1681,14 @@ dependencies = [ | |||
| 1673 | "wide", | 1681 | "wide", |
| 1674 | ] | 1682 | ] |
| 1675 | 1683 | ||
| 1684 | +[[package]] | ||
| 1685 | +name = "ec-vorbis" | ||
| 1686 | +version = "0.1.0" | ||
| 1687 | +dependencies = [ | ||
| 1688 | + "ec-core", | ||
| 1689 | + "ec-dsp", | ||
| 1690 | +] | ||
| 1691 | + | ||
| 1676 | [[package]] | 1692 | [[package]] |
| 1677 | name = "ec-vp8" | 1693 | name = "ec-vp8" |
| 1678 | version = "0.1.0" | 1694 | version = "0.1.0" |
| @@ -1735,7 +1751,9 @@ dependencies = [ | |||
| 1735 | "ec-h264", | 1751 | "ec-h264", |
| 1736 | "ec-h265", | 1752 | "ec-h265", |
| 1737 | "ec-h265-syntax", | 1753 | "ec-h265-syntax", |
| 1754 | + "ec-mp3", | ||
| 1738 | "ec-opus", | 1755 | "ec-opus", |
| 1756 | + "ec-vorbis", | ||
| 1739 | "flacenc", | 1757 | "flacenc", |
| 1740 | "hound", | 1758 | "hound", |
| 1741 | "image", | 1759 | "image", |
| @@ -1749,8 +1767,6 @@ dependencies = [ | |||
| 1749 | "oxideav-sub-image", | 1767 | "oxideav-sub-image", |
| 1750 | "oxideav-subtitle", | 1768 | "oxideav-subtitle", |
| 1751 | "rav1e", | 1769 | "rav1e", |
| 1752 | - "rusty_mp3", | ||
| 1753 | - "rusty_vorbis", | ||
| 1754 | "symphonia", | 1770 | "symphonia", |
| 1755 | "symphonia-codec-aac", | 1771 | "symphonia-codec-aac", |
| 1756 | "symphonia-core", | 1772 | "symphonia-core", |
| @@ -5102,18 +5118,6 @@ version = "1.0.23" | |||
| 5102 | source = "registry+https://github.com/rust-lang/crates.io-index" | 5118 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 5103 | checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" | 5119 | checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" |
| 5104 | 5120 | ||
| 5105 | -[[package]] | ||
| 5106 | -name = "rusty_mp3" | ||
| 5107 | -version = "0.6.1" | ||
| 5108 | -source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 5109 | -checksum = "a99f339ec9a2d84eec8fc2a42baa92426966b25238c498e79d57b4e49b14fbad" | ||
| 5110 | - | ||
| 5111 | -[[package]] | ||
| 5112 | -name = "rusty_vorbis" | ||
| 5113 | -version = "0.1.1" | ||
| 5114 | -source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 5115 | -checksum = "6eddf79e697ce9279ef0e012432cd2889a7b6305a45efb5bb16e8a1d6338646f" | ||
| 5116 | - | ||
| 5117 | [[package]] | 5121 | [[package]] |
| 5118 | name = "rustybuzz" | 5122 | name = "rustybuzz" |
| 5119 | version = "0.14.1" | 5123 | 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, or | 359 | // format's is not its answer: cleared rather than left standing, or |
| 360 | // picking MP3 after AV1 would read "SW encode (rav1e) · MP3 · SW | 360 | // 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
| @@ -74,21 +74,28 @@ ec-aac = { path = "../../../edith_codecs/crates/ec-aac" } | |||
| 74 | # stream (`decode::run_av1`), so peak memory is one output picture plus the | 74 | # stream (`decode::run_av1`), so peak memory is one output picture plus the |
| 75 | # reference bank, and seeks stay the demuxer's job. | 75 | # reference bank, and seeks stay the demuxer's job. |
| 76 | ec-av1 = { path = "../../../edith_codecs/crates/ec-av1" } | 76 | ec-av1 = { path = "../../../edith_codecs/crates/ec-av1" } |
| 77 | -# The MP3 encoder, so that format is a row a user can pick rather than a licence | 77 | +# The MP3 encode seat, the family's own: MPEG-1/2/2.5 Layer III, CBR and true |
| 78 | -# note: pure Rust, Apache-2.0, CBR and VBR. The decoder side of mp3 is | 78 | +# VBR (a quality in [0, 1] whose mean tracks its own bitrate ladder), with a |
| 79 | -# symphonia's below -- an mp3 has always been importable here, and until this it | 79 | +# Xing/Info gapless header whose delay/padding fields are *measured* correct. |
| 80 | -# was the one format the editor could read and never write. | 80 | +# It took the seat the registry crate `rusty_mp3` held -- same public shape |
| 81 | -rusty_mp3 = "0.6" | 81 | +# (`Mp3EncoderConfig { bitrate_kbps, vbr_quality }`, push/finish/next_packet), |
| 82 | -# The Vorbis encoder, same family and the same reason as the three above: pure | 82 | +# which is why the swap stops at this line and the use sites. The decoder side |
| 83 | -# Rust, Apache-2.0, no C and no FFI. It is the *first* permissively-licensed | 83 | +# of mp3 is symphonia's below -- an mp3 has always been importable here, and |
| 84 | -# pure-Rust Vorbis encoder -- `vorbis_rs` and `vorbis-encoder` are both bindings | 84 | +# until 2026-08 this was the one format the editor could read and never write. |
| 85 | -# to Xiph's C library, which this project's no-install rule forbids, and | 85 | +ec-mp3 = { path = "../../../edith_codecs/crates/ec-mp3" } |
| 86 | -# `oxideav-vorbis` (whose own manifest calls itself an "orphan-rebuild scaffold") | 86 | +# The Vorbis encode seat, the family's own: a full Vorbis I encoder -- its own |
| 87 | -# ships encoder-side *bitstream writers* with no analysis stage at all: no psy | 87 | +# floor fit, residue quantiser and per-stream codebooks, block switching |
| 88 | -# model, no floor fit, no residue quantiser, nothing that turns PCM into a | 88 | +# included -- where the registry crates with encoders are either C bindings |
| 89 | -# packet. This one does the whole pipeline. Its quirks are measured and worked | 89 | +# (`vorbis_rs`, `vorbis-encoder`: the project's no-install rule forbids both) |
| 90 | -# around in [`crate::export::write_ogg`] -- read that before touching this line. | 90 | +# or bitstream writers with no analysis stage at all (`oxideav-vorbis`, whose |
| 91 | -rusty_vorbis = "0.1.1" | 91 | +# own manifest calls itself an "orphan-rebuild scaffold"). It took the seat the |
| 92 | +# first permissively-licensed pure-Rust encoder, `rusty_vorbis`, held. The old | ||
| 93 | +# seat emitted long blocks only and numbered its first packet a hop early, so | ||
| 94 | +# [`crate::export::write_ogg`] carried a pre-roll and two granule corrections | ||
| 95 | +# around it; this one reports spec granules and clamps its final one to the | ||
| 96 | +# sample count fed, which let the workaround go. See [`crate::export::write_ogg`] | ||
| 97 | +# for the measurement that decided it. | ||
| 98 | +ec-vorbis = { path = "../../../edith_codecs/crates/ec-vorbis" } | ||
| 92 | # Symphonia has no Opus at any version -- its feature list stops at vorbis and | 99 | # Symphonia has no Opus at any version -- its feature list stops at vorbis and |
| 93 | # there is no `symphonia-codec-opus` crate -- while both of its containers *read* | 100 | # there is no `symphonia-codec-opus` crate -- while both of its containers *read* |
| 94 | # the format already: `A_OPUS` and `OpusHead` have always mapped to | 101 | # 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 `ec-aac` as well. | 40 | // everything wider; the encoder is `ec-aac` as well. |
| 41 | ("AAC", "symphonia / ec-aac / ec-aac", true, true), | 41 | ("AAC", "symphonia / ec-aac / ec-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
| @@ -22,7 +22,7 @@ | |||
| 22 | //! equalized one, a source that is not AAC inside an mp4's own sample table — | 22 | //! equalized one, a source that is not AAC inside an mp4's own sample table — |
| 23 | //! the sound is decoded, mixed and encoded again with `ec-aac` | 23 | //! the sound is decoded, mixed and encoded again with `ec-aac` |
| 24 | //! ([`encode_audio`]). The audio-only formats have no such split: `hound` writes | 24 | //! ([`encode_audio`]). The audio-only formats have no such split: `hound` writes |
| 25 | -//! PCM, `flacenc` encodes FLAC, `rusty_mp3` encodes MP3 and `rusty_vorbis` | 25 | +//! PCM, `flacenc` encodes FLAC, `ec-mp3` encodes MP3 and `ec-vorbis` |
| 26 | //! encodes Vorbis, so those are always *decoded* out of the timeline. The worker owns everything: the caller gets an | 26 | //! encodes Vorbis, so those are always *decoded* out of the timeline. The worker owns everything: the caller gets an |
| 27 | //! [`ExportHandle`] and polls it from its render loop. | 27 | //! [`ExportHandle`] and polls it from its render loop. |
| 28 | //! | 28 | //! |
| @@ -126,7 +126,7 @@ const MAX_EXPLICIT_BITRATE: u64 = 50_000_000; | |||
| 126 | /// The rates the sound may be coded at, smallest first -- what a front-end | 126 | /// The rates the sound may be coded at, smallest first -- what a front-end |
| 127 | /// offers and what [`ExportSettings::audio_kbps`] is clamped into. Every one of | 127 | /// offers and what [`ExportSettings::audio_kbps`] is clamped into. Every one of |
| 128 | /// them is a legal MPEG-1 Layer III value, so the MP3 path writes the figure it | 128 | /// them is a legal MPEG-1 Layer III value, so the MP3 path writes the figure it |
| 129 | -/// was given rather than the nearest one `rusty_mp3` snaps to. | 129 | +/// was given rather than the nearest one `ec-mp3` snaps to. |
| 130 | pub const AUDIO_KBPS: [u32; 4] = [128, 192, 256, 320]; | 130 | pub const AUDIO_KBPS: [u32; 4] = [128, 192, 256, 320]; |
| 131 | 131 | ||
| 132 | /// What the sound is coded at when nobody picked: the rate this project wrote | 132 | /// What the sound is coded at when nobody picked: the rate this project wrote |
| @@ -158,9 +158,9 @@ const HEVC_QP_MAX: i32 = 40; | |||
| 158 | /// What an export writes. H.264-in-mp4, AV1 and HEVC -- each of the last two in | 158 | /// What an export writes. H.264-in-mp4, AV1 and HEVC -- each of the last two in |
| 159 | /// Matroska or in mp4, the user's pick of container -- are the *video* pairs | 159 | /// Matroska or in mp4, the user's pick of container -- are the *video* pairs |
| 160 | /// with both an encoder and a decoder under this project's no-install rule, and | 160 | /// with both an encoder and a decoder under this project's no-install rule, and |
| 161 | -/// WAV, FLAC, MP3 and Ogg Vorbis are the standalone audio formats with a | 161 | +/// pure-Rust encoder: `hound`, `flacenc`, `ec-mp3` and `ec-vorbis`. Opus |
| 162 | -/// pure-Rust encoder: `hound`, `flacenc`, `rusty_mp3` and `rusty_vorbis`. Opus | 162 | +/// still has none as a *file* -- the Matroska seat is `ec-opus`, but a standalone |
| 163 | -/// still has none -- `oxideav-opus` encodes CELT alone, which is half a codec. | 163 | +/// `.opus` row this project does not offer. |
| 164 | /// (AAC has one too -- `ec-aac`, which is what a re-encoded video track's | 164 | /// (AAC has one too -- `ec-aac`, which is what a re-encoded video track's |
| 165 | /// sound leaves through -- but AAC is a container's own audio, never a file of | 165 | /// sound leaves through -- but AAC is a container's own audio, never a file of |
| 166 | /// its own here.) VP9 and VP8 are the | 166 | /// its own here.) VP9 and VP8 are the |
| @@ -200,10 +200,10 @@ pub enum Format { | |||
| 200 | Wav, | 200 | Wav, |
| 201 | /// The audio lanes alone, losslessly compressed. | 201 | /// The audio lanes alone, losslessly compressed. |
| 202 | Flac, | 202 | Flac, |
| 203 | - /// The audio lanes alone, MPEG-1 Layer III CBR (`rusty_mp3`) at the rate | 203 | + /// The audio lanes alone, MPEG-1 Layer III CBR (`ec-mp3`) at the rate |
| 204 | /// [`ExportSettings::audio_kbps`] asks for. | 204 | /// [`ExportSettings::audio_kbps`] asks for. |
| 205 | Mp3, | 205 | Mp3, |
| 206 | - /// The audio lanes alone, Vorbis I in an Ogg container -- `rusty_vorbis` | 206 | + /// The audio lanes alone, Vorbis I in an Ogg container -- `ec-vorbis` |
| 207 | /// encoding, `oxideav-ogg` paging. Quality-coded and not rate-coded, which | 207 | /// encoding, `oxideav-ogg` paging. Quality-coded and not rate-coded, which |
| 208 | /// is why [`audio_rate_refusal`] takes the Sound row away here: see | 208 | /// is why [`audio_rate_refusal`] takes the Sound row away here: see |
| 209 | /// [`VORBIS_QUALITY`] for the operating point and how it was measured. | 209 | /// [`VORBIS_QUALITY`] for the operating point and how it was measured. |
| @@ -848,8 +848,8 @@ fn audio_label( | |||
| 848 | match format { | 848 | match format { |
| 849 | Format::Wav => "PCM · SW (hound)", | 849 | Format::Wav => "PCM · SW (hound)", |
| 850 | Format::Flac => "FLAC · SW (flacenc)", | 850 | Format::Flac => "FLAC · SW (flacenc)", |
| 851 | - Format::Mp3 => "MP3 · SW (rusty_mp3)", | 851 | + Format::Mp3 => "MP3 · SW (ec-mp3)", |
| 852 | - Format::Ogg => "Vorbis · SW (rusty_vorbis)", | 852 | + Format::Ogg => "Vorbis · SW (ec-vorbis)", |
| 853 | _ => match copied.unwrap_or(!forces_encode(project, ranged)) { | 853 | _ => match copied.unwrap_or(!forces_encode(project, ranged)) { |
| 854 | true => "AAC copy", | 854 | true => "AAC copy", |
| 855 | // A Matroska file gets Opus where the mix allows it -- 48 kHz and | 855 | // A Matroska file gets Opus where the mix allows it -- 48 kHz and |
| @@ -920,12 +920,12 @@ pub fn audio_rate_refusal(project: &Project, format: Format, ranged: bool) -> Op | |||
| 920 | match format { | 920 | match format { |
| 921 | _ if !has_sound(project) => Some("no sound to write"), | 921 | _ if !has_sound(project) => Some("no sound to write"), |
| 922 | Format::Wav | Format::Flac => Some("lossless — the samples themselves, at no rate"), | 922 | Format::Wav | Format::Flac => Some("lossless — the samples themselves, at no rate"), |
| 923 | - // Vorbis has a quality knob and no rate knob, and the two are not the | 923 | + // Vorbis is written at one measured operating point ([`VORBIS_QUALITY`] |
| 924 | - // same control wearing different words: measured across this suite's | 924 | + // + [`VORBIS_TARGET_BPS`]), not at a rate a user may pick: its actual |
| 925 | - // fixtures, the whole usable quality band lands between 55 and 175 kbps | 925 | + // landing moves with the content around that target (124-134 kbps |
| 926 | - // ([`VORBIS_QUALITY`]), so two of the four rates on offer here are not | 926 | + // across this suite's bench inputs), so a live rate row would print a |
| 927 | - // rates it can reach at all. A live row would print a figure the file | 927 | + // figure the file does not hold -- the one thing this card is built |
| 928 | - // does not hold, which is the one thing this card is built not to do. | 928 | + // not to do. |
| 929 | Format::Ogg => Some("quality-coded — Vorbis holds no rate to pick"), | 929 | Format::Ogg => Some("quality-coded — Vorbis holds no rate to pick"), |
| 930 | Format::Mp3 => None, | 930 | Format::Mp3 => None, |
| 931 | _ if forces_encode(project, ranged) => None, | 931 | _ if forces_encode(project, ranged) => None, |
| @@ -3321,20 +3321,21 @@ fn write_wav(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<() | |||
| 3321 | Ok(()) | 3321 | Ok(()) |
| 3322 | } | 3322 | } |
| 3323 | 3323 | ||
| 3324 | -/// The same samples as MPEG-1 Layer III, `rusty_mp3` doing the encoding -- pure | 3324 | +/// The same samples as MPEG-1 Layer III, `ec-mp3` doing the encoding -- the |
| 3325 | -/// Rust like every other encoder here, and the reason this format is a row at | 3325 | +/// family's own, taking the seat at the same contract (CBR in, frames out, |
| 3326 | -/// all: the LGPL `shine-rs` was the only one when it was not. | 3326 | +/// `Mp3EncoderConfig`'s fields are the old seat's names), so the swap cost the |
| 3327 | +/// call sites nothing. | ||
| 3327 | /// | 3328 | /// |
| 3328 | /// CBR at the caller's rate, [`DEFAULT_AUDIO_KBPS`] where there was none. Every | 3329 | /// CBR at the caller's rate, [`DEFAULT_AUDIO_KBPS`] where there was none. Every |
| 3329 | /// offered rate is already a legal Layer III value, so the encoder's snap is a | 3330 | /// offered rate is already a legal Layer III value, so the encoder's snap is a |
| 3330 | /// backstop and not a silent substitution; a sample rate MPEG has no frame for | 3331 | /// backstop and not a silent substitution; a sample rate MPEG has no frame for |
| 3331 | -/// (anything but 8-48 kHz) is refused there by name rather than written as | 3332 | +/// (anything but the nine MPEG rates 8-48 kHz) is refused there by name rather |
| 3332 | -/// something else. | 3333 | +/// than written as something else. |
| 3333 | /// | 3334 | /// |
| 3334 | /// corner-cut: CBR only -- the card offers rates and not a quality index. Upgrade | 3335 | /// corner-cut: CBR only -- the card offers rates and not a quality index. Upgrade |
| 3335 | /// path is `Mp3EncoderConfig::vbr_quality` behind a setting of its own. | 3336 | /// path is `Mp3EncoderConfig::vbr_quality` behind a setting of its own. |
| 3336 | fn write_mp3(out: &Path, samples: &[i32], audio: &AudioMeta, kbps: u32) -> crate::Result<()> { | 3337 | fn write_mp3(out: &Path, samples: &[i32], audio: &AudioMeta, kbps: u32) -> crate::Result<()> { |
| 3337 | - let mut encoder = rusty_mp3::Mp3Encoder::new(rusty_mp3::Mp3EncoderConfig { | 3338 | + let mut encoder = ec_mp3::encode::Mp3Encoder::new(ec_mp3::encode::Mp3EncoderConfig { |
| 3338 | bitrate_kbps: kbps, | 3339 | bitrate_kbps: kbps, |
| 3339 | vbr_quality: None, | 3340 | vbr_quality: None, |
| 3340 | }); | 3341 | }); |
| @@ -3356,72 +3357,58 @@ fn write_mp3(out: &Path, samples: &[i32], audio: &AudioMeta, kbps: u32) -> crate | |||
| 3356 | Ok(()) | 3357 | Ok(()) |
| 3357 | } | 3358 | } |
| 3358 | 3359 | ||
| 3359 | -/// The Vorbis quality every `.ogg` this program writes is coded at, on | 3360 | +/// Where the Vorbis rate loop starts, on `ec-vorbis`'s normalised `[0, 1]` |
| 3360 | -/// `rusty_vorbis`'s normalised `[0, 1]` scale -- about `-q 8.35` on the scale | 3361 | +/// scale, beside [`VORBIS_TARGET_BPS`] -- the two numbers every `.ogg` this |
| 3361 | -/// Vorbis itself is spoken in (`quality01_from_vorbis_q`). | 3362 | +/// program writes is coded at. |
| 3362 | /// | 3363 | /// |
| 3363 | -/// A measured number, not a taste. The 2026-08-11 bench encoded three of this | 3364 | +/// A measured operating point, not a taste (2026-09-13 bench, every output |
| 3364 | -/// suite's fixtures (`test_tone_48k.wav`, `test_av.mp4`, `test_tone.mp3`) at | 3365 | +/// decoded back with **symphonia** -- an independent decoder, and the very one |
| 3365 | -/// every quality from 0.40 to 0.95 and decoded each back with **symphonia** -- | 3366 | +/// [`crate::audio`] reopens an export with). The incumbent seat's own 0.85 -- |
| 3366 | -/// an independent decoder, and the very one [`crate::audio`] reopens an export | 3367 | +/// its top quality that still decoded every fixture to exactly its own length |
| 3367 | -/// with. Two things came out of it: | 3368 | +/// -- measured 124-176 kbps across this suite's fixtures with correlation |
| 3368 | -/// | 3369 | +/// 0.9947-0.9957 against the source. The quality knob alone on the new seat |
| 3369 | -/// * **Below 0.50 the encoder is quiet, not just coarse.** The decoded RMS | 3370 | +/// saturates well under that band (0.98 lands ~87 kbps on a 30-second music |
| 3370 | -/// against the source's runs 0.83-0.94 at quality 0.40 (a 1 to 1.6 dB level | 3371 | +/// clip), so the seat is driven the way its own rate gates are measured: the |
| 3371 | -/// error), and at 0.10 and below the file decodes to near-silence -- the same | 3372 | +/// loop starts at 0.85 and is held to a 128 kbps target, which landed |
| 3372 | -/// class of failure the AC-3 mono downmix has in `crate::audio`. From 0.55 up | 3373 | +/// 124-134 kbps actual on the same inputs and beat the incumbent at its own |
| 3373 | -/// the level sits at 1.000-1.009, which is what a lossy codec should do. | 3374 | +/// operating point on every one of them -- correlation 0.9968 against 0.9947 |
| 3374 | -/// * **The band tops out well under the rates the Sound row offers.** Quality | 3375 | +/// on the music clip, +3.1 dB PSNR -- at the same size of file. Against |
| 3375 | -/// 0.85 measured 176, 144 and 148 kbps on the three fixtures; 0.95 only | 3376 | +/// ffmpeg's own libvorbis at `-q 5` (125.8 kbps actual on the same clip) it |
| 3376 | -/// reaches ~200. That is why [`audio_rate_refusal`] takes the row away rather | 3377 | +/// reads 0.9968 against 0.9973: par at the same rate. |
| 3377 | -/// than mapping 128/192/256/320 onto quality steps: the top two are numbers | ||
| 3378 | -/// this encoder cannot produce, and a card that printed them would be lying. | ||
| 3379 | -/// | ||
| 3380 | -/// 0.85 is the top of the band where every fixture still decoded to *exactly* | ||
| 3381 | -/// its own length (0.95 overshot one by 820 samples), which is the property | ||
| 3382 | -/// [`write_ogg`] is built around. | ||
| 3383 | const VORBIS_QUALITY: f32 = 0.85; | 3378 | const VORBIS_QUALITY: f32 = 0.85; |
| 3384 | 3379 | ||
| 3385 | -/// The Vorbis block hop, and the size of the pre-roll [`write_ogg`] feeds the | 3380 | +/// The rate [`VORBIS_QUALITY`]'s loop is held to, in bits per second. Measured |
| 3386 | -/// encoder. `rusty_vorbis` emits long blocks only (`N = 2048`, hop `N/2`). | 3381 | +/// landing within +1..+5% of target across the bench's inputs; the Sound row |
| 3387 | -const VORBIS_HOP: usize = 1024; | 3382 | +/// stays refused for this format because this target is the encoder's measured |
| 3383 | +/// operating point, not a number a card may offer. | ||
| 3384 | +const VORBIS_TARGET_BPS: i32 = 128_000; | ||
| 3388 | 3385 | ||
| 3389 | -/// The same samples as Vorbis I in an Ogg container: `rusty_vorbis` encodes, | 3386 | +/// The same samples as Vorbis I in an Ogg container: `ec-vorbis` encodes, |
| 3390 | /// `oxideav-ogg` pages. Pure Rust on both halves, like every other encoder here. | 3387 | /// `oxideav-ogg` pages. Pure Rust on both halves, like every other encoder here. |
| 3391 | /// | 3388 | /// |
| 3392 | -/// Two corrections stand between that library pair and a file this project would | 3389 | +/// The old seat's two corrections are gone with it, and the going is measured |
| 3393 | -/// ship, and both are measured rather than guessed (2026-08-11, decoded back | 3390 | +/// rather than assumed (2026-09-13, every output decoded back with symphonia). |
| 3394 | -/// with symphonia every time): | 3391 | +/// This encoder numbers its packets the spec's way -- the first audio packet |
| 3395 | -/// | 3392 | +/// at granule 0, every packet after at the absolute sample position its block |
| 3396 | -/// 1. **One hop of pre-roll.** `rusty_vorbis` advances the granule by a full hop | 3393 | +/// ends on -- and clamps its final granule to the sample count it was fed, so |
| 3397 | -/// on its *first* audio packet, which its own doc comment says decodes to | 3394 | +/// a decoder trims the block grid's tail on its own. Written straight through, |
| 3398 | -/// zero samples. Written straight through, every sample lands ~1024 early: | 3395 | +/// every file decodes to exactly the timeline's frame count with the |
| 3399 | -/// a marker signal whose only energy was its first and last 1024 samples came | 3396 | +/// correlation peak at lag zero, which is what the one-hop pre-roll and the |
| 3400 | -/// back with the head at 36% of its amplitude and a full-scale burst 1500 | 3397 | +/// two granule corrections this function used to carry around the old encoder |
| 3401 | -/// samples *before* the real one, in what should have been silence. Feeding | 3398 | +/// were for. |
| 3402 | -/// [`VORBIS_HOP`] samples of silence ahead of the mix and subtracting the same | ||
| 3403 | -/// from every granule puts it back: head 0.86 against an input peak of 0.80, | ||
| 3404 | -/// the phantom burst down to 0.04, the real burst at its own place. The | ||
| 3405 | -/// decoder drops the pre-roll itself -- a first page whose granule is under | ||
| 3406 | -/// what its packets decode to is exactly how Ogg says "skip this much". | ||
| 3407 | -/// 2. **The tail is declared, not encoded.** The block grid overshoots the last | ||
| 3408 | -/// sample, so the stream is padded out and the *last* page's granule is set | ||
| 3409 | -/// to the timeline's own frame count. A decoder trims to it, which is what | ||
| 3410 | -/// makes an `.ogg` here exactly as long as the WAV of the same timeline -- | ||
| 3411 | -/// the promise [`run_audio`] makes for every other audio format. | ||
| 3412 | /// | 3399 | /// |
| 3413 | -/// **Stereo, always.** The embedded setup header `rusty_vorbis` ships is a | 3400 | +/// **Stereo, always.** The format row promises stereo, so a mono mix is |
| 3414 | -/// stereo profile: a mono push is refused outright ("bad coupling channels"), | 3401 | +/// written as dual mono, both channels bit-identical (measured: `max|L-R|` is |
| 3415 | -/// and so is anything wider. A mono mix is therefore written as dual mono, both | 3402 | +/// exactly 0; the encoder's own channel coupling codes the empty side channel |
| 3416 | -/// channels bit-identical (measured: `max|L-R|` is exactly 0, and Vorbis's own | 3403 | +/// for almost nothing). The encoder would serve a mono stream, but the row |
| 3417 | -/// channel coupling codes the empty side channel for almost nothing). Wider than | 3404 | +/// says stereo and folding the file back down must give exactly what was |
| 3418 | -/// stereo cannot reach here -- [`crate::audio`] folds 5.1 to stereo when the | 3405 | +/// mixed. Wider than stereo cannot reach here -- [`crate::audio`] folds 5.1 |
| 3419 | -/// source is opened -- but it is refused by name rather than left to the | 3406 | +/// to stereo when the source is opened -- but it is refused by name rather |
| 3420 | -/// library's own message. | 3407 | +/// than left to the library's own message. |
| 3421 | /// | 3408 | /// |
| 3422 | -/// corner-cut: one quality, [`VORBIS_QUALITY`], with no user control -- the Sound | 3409 | +/// corner-cut: one operating point, [`VORBIS_QUALITY`] + |
| 3423 | -/// row is refused for this format because the rates it offers are not rates | 3410 | +/// [`VORBIS_TARGET_BPS`], with no user control -- the Sound row is refused for |
| 3424 | -/// Vorbis reaches. Upgrade path is a quality picker of its own, worth building | 3411 | +/// this format. Upgrade path is a quality picker of its own, worth building |
| 3425 | /// the day the card has a control that speaks in quality rather than kbps. | 3412 | /// the day the card has a control that speaks in quality rather than kbps. |
| 3426 | fn write_ogg(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<()> { | 3413 | fn write_ogg(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<()> { |
| 3427 | if audio.channels > 2 { | 3414 | if audio.channels > 2 { |
| @@ -3431,47 +3418,49 @@ fn write_ogg(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<() | |||
| 3431 | ) | 3418 | ) |
| 3432 | .into()); | 3419 | .into()); |
| 3433 | } | 3420 | } |
| 3434 | - // The mp3 path's conversion, so the two files are one mix, plus the pre-roll | 3421 | + // The mp3 path's conversion, so the two files are one mix -- the same |
| 3435 | - // and (for a mono mix) the dual-mono widening: the same sample in both | 3422 | + // /32768 scaling this engine's own decoders do -- plus (for a mono mix) |
| 3436 | - // channels is the same signal, not a widening of it, so what a player folds | 3423 | + // the dual-mono widening: the same sample in both channels is the same |
| 3437 | - // back down is what was mixed. | 3424 | + // signal, not a widening of it, so what a player folds back down is what |
| 3438 | - let mut pcm: Vec<i16> = vec![0; VORBIS_HOP * 2]; | 3425 | + // was mixed. |
| 3439 | - match audio.channels < 2 { | 3426 | + let pcm: Vec<f32> = match audio.channels < 2 { |
| 3440 | - true => pcm.extend(samples.iter().flat_map(|&s| [s as i16, s as i16])), | 3427 | + true => samples |
| 3441 | - false => pcm.extend(samples.iter().map(|&s| s as i16)), | 3428 | + .iter() |
| 3442 | - } | 3429 | + .flat_map(|&s| [f32::from(s as i16) / 32768.0; 2]) |
| 3443 | - // The block grid has to run past the last real sample or the tail is never | 3430 | + .collect(), |
| 3444 | - // coded at all; the granule below is what trims the padding back off. | 3431 | + false => samples |
| 3432 | + .iter() | ||
| 3433 | + .map(|&s| f32::from(s as i16) / 32768.0) | ||
| 3434 | + .collect(), | ||
| 3435 | + }; | ||
| 3445 | let frames = samples.len() / usize::from(audio.channels).max(1); | 3436 | let frames = samples.len() / usize::from(audio.channels).max(1); |
| 3446 | - pcm.resize(pcm.len() + VORBIS_HOP * 4 * 2, 0); | ||
| 3447 | 3437 | ||
| 3448 | - let mut encoder = rusty_vorbis::VorbisEncoder::new(rusty_vorbis::VorbisEncoderConfig { | 3438 | + let mut encoder = ec_vorbis::VorbisEncoder::new(ec_vorbis::EncoderConfig { |
| 3449 | - bitrate_bps: rusty_vorbis::BITRATE_NOMINAL, | 3439 | + sample_rate: audio.sample_rate, |
| 3440 | + channels: 2, | ||
| 3441 | + bitrate_bps: VORBIS_TARGET_BPS, | ||
| 3450 | quality: VORBIS_QUALITY, | 3442 | quality: VORBIS_QUALITY, |
| 3451 | - }); | 3443 | + }) |
| 3444 | + .map_err(|e| format!("vorbis encode: {e}"))?; | ||
| 3452 | encoder | 3445 | encoder |
| 3453 | - .push_pcm_s16(&pcm, 2, audio.sample_rate) | 3446 | + .push_interleaved(&pcm) |
| 3454 | .map_err(|e| format!("vorbis encode: {e}"))?; | 3447 | .map_err(|e| format!("vorbis encode: {e}"))?; |
| 3455 | encoder.finish(); | 3448 | encoder.finish(); |
| 3456 | let mut packets = Vec::new(); | 3449 | let mut packets = Vec::new(); |
| 3457 | loop { | 3450 | loop { |
| 3458 | match encoder.next_packet() { | 3451 | match encoder.next_packet() { |
| 3459 | Ok(packet) => packets.push(packet), | 3452 | Ok(packet) => packets.push(packet), |
| 3460 | - Err(rusty_vorbis::Error::Eof) => break, | 3453 | + Err(ec_core::Error::Eof) => break, |
| 3454 | + Err(ec_core::Error::NeedMore) => continue, | ||
| 3461 | Err(e) => return Err(format!("vorbis encode: {e}").into()), | 3455 | Err(e) => return Err(format!("vorbis encode: {e}").into()), |
| 3462 | } | 3456 | } |
| 3463 | } | 3457 | } |
| 3464 | - // Identification, comment and setup, then at least one audio packet: fewer | 3458 | + // The three setup headers travel with the encoder, not in the packet |
| 3465 | - // than four and there is no stream to page. | 3459 | + // stream; with no audio packets there is no stream to page. |
| 3466 | - if packets.len() < 4 { | 3460 | + if packets.is_empty() { |
| 3467 | - return Err(format!("vorbis encode: {} packets is not a stream", packets.len()).into()); | 3461 | + return Err("vorbis encode: no audio packets is not a stream".into()); |
| 3468 | } | 3462 | } |
| 3469 | - let headers = [ | 3463 | + let extradata = oxideav_ogg::mux::xiph_lace(&encoder.headers()) |
| 3470 | - &packets[0].data[..], | ||
| 3471 | - &packets[1].data[..], | ||
| 3472 | - &packets[2].data[..], | ||
| 3473 | - ]; | ||
| 3474 | - let extradata = oxideav_ogg::mux::xiph_lace(&headers) | ||
| 3475 | .ok_or("vorbis encode: the three headers would not lace")?; | 3464 | .ok_or("vorbis encode: the three headers would not lace")?; |
| 3476 | 3465 | ||
| 3477 | let time_base = oxideav_core::TimeBase::new(1, i64::from(audio.sample_rate)); | 3466 | let time_base = oxideav_core::TimeBase::new(1, i64::from(audio.sample_rate)); |
| @@ -3495,18 +3484,14 @@ fn write_ogg(out: &Path, samples: &[i32], audio: &AudioMeta) -> crate::Result<() | |||
| 3495 | muxer | 3484 | muxer |
| 3496 | .write_header() | 3485 | .write_header() |
| 3497 | .map_err(|e| format!("ogg mux: {e:?}"))?; | 3486 | .map_err(|e| format!("ogg mux: {e:?}"))?; |
| 3498 | - let last = packets.len() - 1; | 3487 | + for packet in &packets { |
| 3499 | - for (i, packet) in packets.iter().enumerate().skip(3) { | 3488 | + // The granule is the encoder's own: the absolute sample position this |
| 3500 | - // Correction 1 on every packet, correction 2 on the last one. | 3489 | + // packet ends at, clamped to the mix's length on the last one. |
| 3501 | - let granule = match i == last { | ||
| 3502 | - true => frames as i64, | ||
| 3503 | - false => (packet.pts - VORBIS_HOP as i64).max(0), | ||
| 3504 | - }; | ||
| 3505 | muxer | 3490 | muxer |
| 3506 | .write_packet( | 3491 | .write_packet( |
| 3507 | &oxideav_core::Packet::new(0, time_base, packet.data.clone()) | 3492 | &oxideav_core::Packet::new(0, time_base, packet.data.clone()) |
| 3508 | - .with_pts(granule) | 3493 | + .with_pts(packet.granule) |
| 3509 | - .with_duration(packet.duration), | 3494 | + .with_duration(packet.samples), |
| 3510 | ) | 3495 | ) |
| 3511 | .map_err(|e| format!("ogg mux: {e:?}"))?; | 3496 | .map_err(|e| format!("ogg mux: {e:?}"))?; |
| 3512 | } | 3497 | } |
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 mp3 | 277 | /// 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 can | 278 | /// 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 Ogg | 874 | /// 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 straight | 875 | +/// 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 WAV | 878 | /// 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 the | 879 | +/// 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 own | 880 | +/// 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 overruns | 881 | +/// 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 step | 882 | +/// 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* rather | 883 | +/// 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 nearer | 884 | +/// 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 embedded | 1111 | +/// 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 outright | 1112 | +/// 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 dual | 1113 | +/// 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: both | 1114 | +/// 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 exactly | 1115 | +/// 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 of | 1118 | // A mono fixture, written here because the suite has none: one second of |