The Opus decoder gets the transform it was written around
Browse files at this commitedbb3e368288de76116a9001c5ab9a9938bedf8eParent: 267d45b- perf
- the Opus decoder gets the transform it was written around
2 changed files +169 -3
- Cargo.lock +151 -0
- crates/engine/Cargo.toml +18 -3
Cargo.lockmodified+151 -0
| @@ -3372,6 +3372,16 @@ dependencies = [ | ||
| 3372 | 3372 | "libc", |
| 3373 | 3373 | ] |
| 3374 | 3374 | |
| 3375 | +[[package]] | |
| 3376 | +name = "matrixmultiply" | |
| 3377 | +version = "0.3.11" | |
| 3378 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3379 | +checksum = "3f607c237553f086e7043417a51df26b2eb899d3caff94e6a67592ff992fedc7" | |
| 3380 | +dependencies = [ | |
| 3381 | + "autocfg", | |
| 3382 | + "rawpointer", | |
| 3383 | +] | |
| 3384 | + | |
| 3375 | 3385 | [[package]] |
| 3376 | 3386 | name = "maybe-rayon" |
| 3377 | 3387 | version = "0.1.1" |
| @@ -3538,6 +3548,22 @@ dependencies = [ | ||
| 3538 | 3548 | "getrandom 0.2.17", |
| 3539 | 3549 | ] |
| 3540 | 3550 | |
| 3551 | +[[package]] | |
| 3552 | +name = "ndarray" | |
| 3553 | +version = "0.17.2" | |
| 3554 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3555 | +checksum = "520080814a7a6b4a6e9070823bb24b4531daac8c4627e08ba5de8c5ef2f2752d" | |
| 3556 | +dependencies = [ | |
| 3557 | + "matrixmultiply", | |
| 3558 | + "num-complex", | |
| 3559 | + "num-integer", | |
| 3560 | + "num-traits", | |
| 3561 | + "portable-atomic", | |
| 3562 | + "portable-atomic-util", | |
| 3563 | + "rawpointer", | |
| 3564 | + "serde", | |
| 3565 | +] | |
| 3566 | + | |
| 3541 | 3567 | [[package]] |
| 3542 | 3568 | name = "new_debug_unreachable" |
| 3543 | 3569 | version = "1.0.6" |
| @@ -3608,6 +3634,34 @@ dependencies = [ | ||
| 3608 | 3634 | "memchr", |
| 3609 | 3635 | ] |
| 3610 | 3636 | |
| 3637 | +[[package]] | |
| 3638 | +name = "non-empty-iter" | |
| 3639 | +version = "0.3.1" | |
| 3640 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3641 | +checksum = "ac123b8e4bd1fef3e8e972ba7a07f046ac6b608633ad761c61876b7197313f63" | |
| 3642 | +dependencies = [ | |
| 3643 | + "non-zero-size", | |
| 3644 | +] | |
| 3645 | + | |
| 3646 | +[[package]] | |
| 3647 | +name = "non-empty-slice" | |
| 3648 | +version = "0.6.0" | |
| 3649 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3650 | +checksum = "9935c822e11be79ef40f986558b00da0ff176b7c87ddf6d9fb8b9138a6112c20" | |
| 3651 | +dependencies = [ | |
| 3652 | + "non-empty-iter", | |
| 3653 | + "non-zero-size", | |
| 3654 | + "ownership", | |
| 3655 | + "serde", | |
| 3656 | + "thiserror 2.0.20", | |
| 3657 | +] | |
| 3658 | + | |
| 3659 | +[[package]] | |
| 3660 | +name = "non-zero-size" | |
| 3661 | +version = "0.2.0" | |
| 3662 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3663 | +checksum = "401b3a4027292c1c318fd2305783f791d5579d18e7143ef72d653bf0c29e6b36" | |
| 3664 | + | |
| 3611 | 3665 | [[package]] |
| 3612 | 3666 | name = "noop_proc_macro" |
| 3613 | 3667 | version = "0.3.0" |
| @@ -3672,6 +3726,7 @@ checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" | ||
| 3672 | 3726 | dependencies = [ |
| 3673 | 3727 | "bytemuck", |
| 3674 | 3728 | "num-traits", |
| 3729 | + "serde", | |
| 3675 | 3730 | ] |
| 3676 | 3731 | |
| 3677 | 3732 | [[package]] |
| @@ -3951,6 +4006,12 @@ dependencies = [ | ||
| 3951 | 4006 | "pin-project-lite", |
| 3952 | 4007 | ] |
| 3953 | 4008 | |
| 4009 | +[[package]] | |
| 4010 | +name = "ownership" | |
| 4011 | +version = "0.3.0" | |
| 4012 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 4013 | +checksum = "cfb1aeb68b9f2683ee3f83960c10668b37a8a640224ba1169697ee8fd1e906c1" | |
| 4014 | + | |
| 3954 | 4015 | [[package]] |
| 3955 | 4016 | name = "oxideav-ac3" |
| 3956 | 4017 | version = "0.0.10" |
| @@ -4279,6 +4340,21 @@ version = "0.2.5" | ||
| 4279 | 4340 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4280 | 4341 | checksum = "5da3b0203fd7ee5720aa0b5e790b591aa5d3f41c3ed2c34a3a393382198af2f7" |
| 4281 | 4342 | |
| 4343 | +[[package]] | |
| 4344 | +name = "portable-atomic" | |
| 4345 | +version = "1.15.0" | |
| 4346 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 4347 | +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" | |
| 4348 | + | |
| 4349 | +[[package]] | |
| 4350 | +name = "portable-atomic-util" | |
| 4351 | +version = "0.2.7" | |
| 4352 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 4353 | +checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" | |
| 4354 | +dependencies = [ | |
| 4355 | + "portable-atomic", | |
| 4356 | +] | |
| 4357 | + | |
| 4282 | 4358 | [[package]] |
| 4283 | 4359 | name = "postage" |
| 4284 | 4360 | version = "0.5.0" |
| @@ -4324,6 +4400,15 @@ dependencies = [ | ||
| 4324 | 4400 | "syn 2.0.119", |
| 4325 | 4401 | ] |
| 4326 | 4402 | |
| 4403 | +[[package]] | |
| 4404 | +name = "primal-check" | |
| 4405 | +version = "0.3.4" | |
| 4406 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 4407 | +checksum = "dc0d895b311e3af9902528fbb8f928688abbd95872819320517cc24ca6b2bd08" | |
| 4408 | +dependencies = [ | |
| 4409 | + "num-integer", | |
| 4410 | +] | |
| 4411 | + | |
| 4327 | 4412 | [[package]] |
| 4328 | 4413 | name = "proc-macro-crate" |
| 4329 | 4414 | version = "3.5.0" |
| @@ -4700,6 +4785,12 @@ dependencies = [ | ||
| 4700 | 4785 | "raw-window-handle", |
| 4701 | 4786 | ] |
| 4702 | 4787 | |
| 4788 | +[[package]] | |
| 4789 | +name = "rawpointer" | |
| 4790 | +version = "0.2.1" | |
| 4791 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 4792 | +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" | |
| 4793 | + | |
| 4703 | 4794 | [[package]] |
| 4704 | 4795 | name = "rayon" |
| 4705 | 4796 | version = "1.12.0" |
| @@ -4731,6 +4822,15 @@ dependencies = [ | ||
| 4731 | 4822 | "once_cell", |
| 4732 | 4823 | ] |
| 4733 | 4824 | |
| 4825 | +[[package]] | |
| 4826 | +name = "realfft" | |
| 4827 | +version = "3.5.0" | |
| 4828 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 4829 | +checksum = "f821338fddb99d089116342c46e9f1fbf3828dba077674613e734e01d6ea8677" | |
| 4830 | +dependencies = [ | |
| 4831 | + "rustfft", | |
| 4832 | +] | |
| 4833 | + | |
| 4734 | 4834 | [[package]] |
| 4735 | 4835 | name = "reborrow" |
| 4736 | 4836 | version = "0.5.5" |
| @@ -4869,6 +4969,9 @@ name = "ruopus" | ||
| 4869 | 4969 | version = "0.1.2" |
| 4870 | 4970 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4871 | 4971 | checksum = "fcfcd963c83fc1ada2180ccdac7f1568d87fb0f2ad7236b266fdc9fb9122fbfd" |
| 4972 | +dependencies = [ | |
| 4973 | + "spectrograms", | |
| 4974 | +] | |
| 4872 | 4975 | |
| 4873 | 4976 | [[package]] |
| 4874 | 4977 | name = "rust-embed" |
| @@ -4927,6 +5030,20 @@ dependencies = [ | ||
| 4927 | 5030 | "semver", |
| 4928 | 5031 | ] |
| 4929 | 5032 | |
| 5033 | +[[package]] | |
| 5034 | +name = "rustfft" | |
| 5035 | +version = "6.4.1" | |
| 5036 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 5037 | +checksum = "21db5f9893e91f41798c88680037dba611ca6674703c1a18601b01a72c8adb89" | |
| 5038 | +dependencies = [ | |
| 5039 | + "num-complex", | |
| 5040 | + "num-integer", | |
| 5041 | + "num-traits", | |
| 5042 | + "primal-check", | |
| 5043 | + "strength_reduce", | |
| 5044 | + "transpose", | |
| 5045 | +] | |
| 5046 | + | |
| 4930 | 5047 | [[package]] |
| 4931 | 5048 | name = "rustix" |
| 4932 | 5049 | version = "0.38.44" |
| @@ -5506,6 +5623,24 @@ dependencies = [ | ||
| 5506 | 5623 | "windows-sys 0.61.2", |
| 5507 | 5624 | ] |
| 5508 | 5625 | |
| 5626 | +[[package]] | |
| 5627 | +name = "spectrograms" | |
| 5628 | +version = "2.1.3" | |
| 5629 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 5630 | +checksum = "3ff1e83612f5a16e413dbfaf0381753b5eee714932fc95db19fe0974d5e6462b" | |
| 5631 | +dependencies = [ | |
| 5632 | + "ndarray", | |
| 5633 | + "non-empty-slice", | |
| 5634 | + "num-complex", | |
| 5635 | + "num-traits", | |
| 5636 | + "once_cell", | |
| 5637 | + "pkg-config", | |
| 5638 | + "realfft", | |
| 5639 | + "regex", | |
| 5640 | + "rustfft", | |
| 5641 | + "thiserror 2.0.20", | |
| 5642 | +] | |
| 5643 | + | |
| 5509 | 5644 | [[package]] |
| 5510 | 5645 | name = "spin" |
| 5511 | 5646 | version = "0.9.9" |
| @@ -5570,6 +5705,12 @@ version = "1.1.0" | ||
| 5570 | 5705 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 5571 | 5706 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" |
| 5572 | 5707 | |
| 5708 | +[[package]] | |
| 5709 | +name = "strength_reduce" | |
| 5710 | +version = "0.2.4" | |
| 5711 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 5712 | +checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82" | |
| 5713 | + | |
| 5573 | 5714 | [[package]] |
| 5574 | 5715 | name = "strict-num" |
| 5575 | 5716 | version = "0.1.1" |
| @@ -6401,6 +6542,16 @@ dependencies = [ | ||
| 6401 | 6542 | "once_cell", |
| 6402 | 6543 | ] |
| 6403 | 6544 | |
| 6545 | +[[package]] | |
| 6546 | +name = "transpose" | |
| 6547 | +version = "0.2.3" | |
| 6548 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 6549 | +checksum = "1ad61aed86bc3faea4300c7aee358b4c6d0c8d6ccc36524c96e4c92ccf26e77e" | |
| 6550 | +dependencies = [ | |
| 6551 | + "num-integer", | |
| 6552 | + "strength_reduce", | |
| 6553 | +] | |
| 6554 | + | |
| 6404 | 6555 | [[package]] |
| 6405 | 6556 | name = "try-lock" |
| 6406 | 6557 | version = "0.2.5" |
crates/engine/Cargo.tomlmodified+18 -3
| @@ -81,8 +81,23 @@ rusty_mp3 = "0.6" | ||
| 81 | 81 | # packet. This one does the whole pipeline. Its quirks are measured and worked |
| 82 | 82 | # around in [`crate::export::write_ogg`] -- read that before touching this line. |
| 83 | 83 | rusty_vorbis = "0.1.1" |
| 84 | -# The Opus decoder: pure Rust, MIT, no C and no FFI, and no dependencies at all | |
| 85 | -# without its default features (`spectrograms` is for its own analysis tools). | |
| 84 | +# The Opus decoder: pure Rust, MIT, no C and no FFI. | |
| 85 | +# | |
| 86 | +# `spectrograms` is not, as this line long claimed, "for its own analysis tools": | |
| 87 | +# it is the crate's *FFT backend*, and it is default-on because CELT synthesis is | |
| 88 | +# an N/4 complex FFT per block. Turned off -- which is what asking for `std` | |
| 89 | +# alone did -- `celt/mdct.rs` falls back to an O(n²) DFT evaluated in f64, and a | |
| 90 | +# 5.1 film soundtrack decodes at **0.95x realtime**: slower than playing it. | |
| 91 | +# With the backend on, the same file decodes at **104x** (7.1: 0.93x -> 112x, | |
| 92 | +# stereo: 10.4x -> 135x). The cost is fifteen pure-Rust crates (`spectrograms` -> | |
| 93 | +# `realfft`/`rustfft`, `ndarray`, `regex`), still no C and no `build.rs`. | |
| 94 | +# The output is *not* bit-identical to the DFT build -- FFT summation order | |
| 95 | +# differs -- but the two agree to 144 dB SNR (max |Δ| 3.7e-8, half an LSB at | |
| 96 | +# 24-bit) while *both* sit 93 dB from ffmpeg's own libopus decode of the same | |
| 97 | +# file. The change is 40 dB below the decoder's existing distance to the | |
| 98 | +# reference, i.e. inside float noise, and upstream says as much: Opus conformance | |
| 99 | +# is a quality threshold (`opus_compare`), not bit-exactness, and every | |
| 100 | +# bitstream-affecting computation stays exact either way. | |
| 86 | 101 | # Symphonia has no Opus at any version -- its feature list stops at vorbis and |
| 87 | 102 | # there is no `symphonia-codec-opus` crate -- while both of its containers *read* |
| 88 | 103 | # the format already: `A_OPUS` and `OpusHead` have always mapped to |
| @@ -99,7 +114,7 @@ rusty_vorbis = "0.1.1" | ||
| 99 | 114 | # where the film is silent. This one matches ffmpeg's own decode of the same file to a |
| 100 | 115 | # correlation of 1.0000 on all six channels. Pinned exactly, like `oxideav-ac3` |
| 101 | 116 | # below, because a decoder is a bit-exactness dependency. |
| 102 | -ruopus = { version = "=0.1.2", default-features = false, features = ["std"] } | |
| 117 | +ruopus = { version = "=0.1.2", default-features = false, features = ["std", "spectrograms"] } | |
| 103 | 118 | # The Opus *encoder*, the other half of that pair: a pure-Rust port of libopus |
| 104 | 119 | # 1.6, BSD-3, `build.rs`-less and with **no dependencies at all** -- checked, not |
| 105 | 120 | # taken from the README (`cargo tree` is two lines; there is not one `.c`, `.h` |