Integrate and verify the native Windows desktop client
- Update pinned Rust, Slint, DSP and WebRTC dependencies, preserving the local vendor patches and source receipts. - Fix desktop audio scheduling and disconnect handling; include isolated duplex, identity, bookmark and notification checks. - Record measured differences from TeamSpeak 6.0.0.5232; full visual and server-feature parity remain open.
This commit is contained in:
1 parent
05e8d34bcf
commit
57807c184e
530 files changed
+68818
-47940
No files matched your search
Vendored
+12
-12
@@ -1,29 +1,29 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"upstream_revision": "a024d6ef8351add55be5e8b1d6cc35f555787660",
|
||||
"upstream_revision": "1632d47c1e77d0857f9145bd175134b348541e11",
|
||||
"packages": [
|
||||
{
|
||||
"name": "sonora",
|
||||
"version": "0.2.0",
|
||||
"version": "0.3.0",
|
||||
"registry": "https://crates.io",
|
||||
"archive": "https://static.crates.io/crates/sonora/sonora-0.2.0.crate",
|
||||
"sha256": "2e1ce442ab5cb392c4067b8f2cced20be4cf12e479f6dfbf44acbe9b14ac9250",
|
||||
"archive": "https://static.crates.io/crates/sonora/sonora-0.3.0.crate",
|
||||
"sha256": "d461e6c9ad112f8728919387a4bc5639fd28631f2070171efad38676e907edd8",
|
||||
"path_in_vcs": "crates/sonora",
|
||||
"modified_sources": ["src/gain_controller2.rs"],
|
||||
"patch": "Mono AGC2 noise analysis uses a stack channel descriptor. Adaptive gain, fixed gain and limiter borrow AudioBuffer::channel_mut(0), eliminating caller-side per-frame channel/sample Vec allocation and copy-back. Multichannel processing remains the upstream path. Includes mono-vs-identical-stereo signal equivalence test."
|
||||
"patch": "Preserve the mono AGC2 stack channel descriptors and direct AudioBuffer::channel_mut(0) processing, avoiding the upstream reusable-buffer copy for mono. Multichannel uses the 0.3.0 reusable owned-buffer pipeline. Retains the mono-vs-identical-stereo signal equivalence test and standalone sonora-agc2 path patch."
|
||||
},
|
||||
{
|
||||
"name": "sonora-agc2",
|
||||
"version": "0.2.0",
|
||||
"version": "0.3.0",
|
||||
"registry": "https://crates.io",
|
||||
"archive": "https://static.crates.io/crates/sonora-agc2/sonora-agc2-0.2.0.crate",
|
||||
"sha256": "9a93a9fa8373a33e61a7fb441d8a9e725ac6024079d2c77a845cf6abe1790b9f",
|
||||
"archive": "https://static.crates.io/crates/sonora-agc2/sonora-agc2-0.3.0.crate",
|
||||
"sha256": "501b5dd3f8bdc8c983dc64a131cef22a429f3ff879d6f0007b8bfe46ec7b96aa",
|
||||
"path_in_vcs": "crates/sonora-agc2",
|
||||
"modified_sources": ["src/limiter.rs"],
|
||||
"patch": "Mono limiter level estimation uses a stack immutable channel descriptor rather than collecting Vec<&[f32]>. Multichannel processing and numerical operations remain unchanged."
|
||||
"modified_sources": [],
|
||||
"patch": "The former mono limiter descriptor-allocation patch is subsumed by upstream 0.3.0: generic channel views pass directly to compute_level_of_channels without collecting a Vec for either mono or multichannel. The public borrowed-slice entry point used by the local sonora mono path remains available."
|
||||
}
|
||||
],
|
||||
"scope": "This removes the inspected AGC2 mono channel-adapter allocations/copies; it is not an allocation-free guarantee for the complete Sonora APM or its other dependencies.",
|
||||
"source": "Copied installed pinned registry sources, retaining upstream Cargo manifests, lockfiles, license, README and VCS metadata; registry .cargo-ok extraction markers omitted.",
|
||||
"verification": "Tests added, not executed by delegated worker. Parent runs verification after integration."
|
||||
"source": "Official 0.3.0 registry archives, retaining upstream files and licenses; mono behavioral/performance patch rebased rather than dropped. Standalone sonora Cargo manifest and lock retain the local sonora-agc2 path patch.",
|
||||
"verification": "Source migration only. Retained local equivalence test and included upstream release tests; no builds, tests, formatters or cargo update executed by delegated worker. Parent runs verification after integration."
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "a024d6ef8351add55be5e8b1d6cc35f555787660"
|
||||
"sha1": "1632d47c1e77d0857f9145bd175134b348541e11"
|
||||
},
|
||||
"path_in_vcs": "crates/sonora-agc2"
|
||||
}
|
||||
+214
-110
@@ -10,24 +10,52 @@ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.8.0"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3"
|
||||
checksum = "56d87354e4229f54a44f7bf2435906a4656dba36026ab6eaca629a2c436a691c"
|
||||
dependencies = [
|
||||
"bit-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.8.0"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
|
||||
checksum = "5727b15fa97d4f4fee0a3b7c3d550ed0269f54329207b86388de918604e31269"
|
||||
dependencies = [
|
||||
"borsh",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.1"
|
||||
version = "2.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da"
|
||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||
|
||||
[[package]]
|
||||
name = "borsh"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "553c5d846a6ba5150c65e3b1b8ec073bcf1abc20f9b7220de384a4443ea4e20a"
|
||||
dependencies = [
|
||||
"borsh-derive",
|
||||
"bytes",
|
||||
"cfg_aliases",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "borsh-derive"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12cdfe656708a01f89b451a7d36466e6fe6c414de0aa18fc54f864f6f9ca9f56"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
@@ -40,26 +68,55 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck_derive"
|
||||
version = "1.11.0"
|
||||
version = "1.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f65693059b6b9c588b9f62fed1cedbf0a8b805631457ea162d68f0de186f3de5"
|
||||
checksum = "6a1f896587b6f2c069c73d2f0913e2d590c3990285cd2f0b6aa02b786b4c679c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
name = "bytes"
|
||||
version = "1.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||
|
||||
[[package]]
|
||||
name = "cfg_aliases"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
|
||||
|
||||
[[package]]
|
||||
name = "chacha20"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core_detect"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
|
||||
checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
@@ -73,7 +130,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"structmeta",
|
||||
"syn",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -94,10 +151,16 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustc_version",
|
||||
"syn",
|
||||
"syn 2.0.119",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.14"
|
||||
@@ -120,18 +183,6 @@ version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi 5.3.0",
|
||||
"wasip2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.3"
|
||||
@@ -140,14 +191,31 @@ checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi 6.0.0",
|
||||
"r-efi",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.189"
|
||||
version = "0.2.191"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
@@ -155,6 +223,12 @@ version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
@@ -177,12 +251,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
name = "proc-macro-crate"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||
checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -196,16 +270,17 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proptest"
|
||||
version = "1.11.0"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744"
|
||||
checksum = "b8530004ccb15eae51c7e40009fbe317f341f804db54dc033eec1c50be28cfa0"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"bit-vec",
|
||||
"bitflags",
|
||||
"chacha20",
|
||||
"core_detect",
|
||||
"num-traits",
|
||||
"rand",
|
||||
"rand_chacha",
|
||||
"rand_xorshift",
|
||||
"regex-syntax",
|
||||
"rusty-fork",
|
||||
@@ -228,12 +303,6 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "5.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "6.0.0"
|
||||
@@ -242,38 +311,25 @@ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.9.5"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41"
|
||||
checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af"
|
||||
dependencies = [
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"getrandom",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.9.5"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
|
||||
dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
]
|
||||
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
||||
|
||||
[[package]]
|
||||
name = "rand_xorshift"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
|
||||
checksum = "60aa6af80be32871323012e02e6e65f8a7cc7890931ae421d217ad8fe0df2ccf"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
@@ -295,9 +351,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.1.4"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"
|
||||
checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
@@ -324,9 +380,39 @@ version = "1.0.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sonora-agc2"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"derive_more",
|
||||
@@ -340,9 +426,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sonora-common-audio"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6635bc61b24807ceac93ad0807b1292b6b0620caa6cd360d3be89fc616b833cc"
|
||||
checksum = "2c05dfa300c14dc8498751ce2c5b87aad2acf1892d4f9d66b92ae2f372a83410"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"sonora-simd",
|
||||
@@ -350,15 +436,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sonora-fft"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27e272c70f34363afb5382dd1818c05f8f63ef6785635736a14e9ccbbb5ba012"
|
||||
checksum = "ec3529f2cf748f1acc85d9403ffa08a3fe69dec6bf22383910b3bd21aca2fd26"
|
||||
dependencies = [
|
||||
"sonora-simd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sonora-simd"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7cf0804e4752a5562262e143014f53043080ead4cd5a98f9278d3ceaf32d868"
|
||||
checksum = "f939d8e63a2a0baa7555294d7b09c5e3d382f28358755b920e13ad527658c8fa"
|
||||
dependencies = [
|
||||
"cpufeatures",
|
||||
]
|
||||
@@ -372,7 +461,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"structmeta-derive",
|
||||
"syn",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -383,7 +472,7 @@ checksum = "152a0b65a590ff6c3da95cabe2353ee04e6167c896b28e3b14478c2636c922fc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -397,6 +486,17 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.27.0"
|
||||
@@ -404,7 +504,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.4.3",
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
@@ -420,7 +520,37 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"structmeta",
|
||||
"syn",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "1.1.3+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.25.19+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime",
|
||||
"toml_parser",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.1.5+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c"
|
||||
dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -442,7 +572,7 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -462,9 +592,9 @@ checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
@@ -481,15 +611,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasip2"
|
||||
version = "1.0.4+wasi-0.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"
|
||||
dependencies = [
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
@@ -506,27 +627,10 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.57.1"
|
||||
name = "winnow"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5a105cd7b140f6eeec8acff2ea38135d3cab283ada58540f629fe51e46696eb"
|
||||
checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fe976fb70c78cd64cccfe3a6fc142244e8a77b70959b30faf9d0ac37ee228eb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"memchr",
|
||||
]
|
||||
Vendored
+8
-4
@@ -13,7 +13,7 @@
|
||||
edition = "2024"
|
||||
rust-version = "1.91"
|
||||
name = "sonora-agc2"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
build = false
|
||||
autolib = false
|
||||
autobins = false
|
||||
@@ -37,6 +37,10 @@ repository = "https://github.com/dignifiedquire/sonora"
|
||||
name = "sonora_agc2"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[test]]
|
||||
name = "published_signatures"
|
||||
path = "tests/published_signatures.rs"
|
||||
|
||||
[dependencies.bytemuck]
|
||||
version = "1"
|
||||
features = ["derive"]
|
||||
@@ -46,13 +50,13 @@ version = "2"
|
||||
features = ["debug"]
|
||||
|
||||
[dependencies.sonora-common-audio]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dependencies.sonora-fft]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dependencies.sonora-simd]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dependencies.tracing]
|
||||
version = "0.1"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "sonora-agc2"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
description = "Automatic Gain Control 2 (AGC2) with RNN VAD for WebRTC Audio Processing"
|
||||
keywords = ["webrtc", "audio", "agc", "gain-control", "vad"]
|
||||
categories = ["multimedia::audio"]
|
||||
|
||||
@@ -122,6 +122,19 @@ impl AdaptiveDigitalGainController {
|
||||
|
||||
/// Analyzes `info`, updates the digital gain and applies it to a 10 ms frame.
|
||||
pub fn process(&mut self, info: &FrameInfo, frame: &mut [&mut [f32]]) {
|
||||
self.process_channels(info, frame);
|
||||
}
|
||||
|
||||
/// Analyzes `info`, updates the digital gain and applies it to a frame in owned buffers.
|
||||
pub fn process_owned_frame(&mut self, info: &FrameInfo, frame: &mut [Vec<f32>]) {
|
||||
self.process_channels(info, frame);
|
||||
}
|
||||
|
||||
fn process_channels<C: AsRef<[f32]> + AsMut<[f32]>>(
|
||||
&mut self,
|
||||
info: &FrameInfo,
|
||||
frame: &mut [C],
|
||||
) {
|
||||
debug_assert!(info.speech_level_dbfs >= -150.0);
|
||||
debug_assert!(!frame.is_empty());
|
||||
|
||||
@@ -174,7 +187,7 @@ impl AdaptiveDigitalGainController {
|
||||
.set_gain_factor(db_to_ratio(self.last_gain_db + gain_change_this_frame_db));
|
||||
}
|
||||
|
||||
self.gain_applier.apply_gain(frame);
|
||||
self.gain_applier.apply_gain_to_channels(frame);
|
||||
|
||||
// Remember that the gain has changed for the next iteration.
|
||||
self.last_gain_db += gain_change_this_frame_db;
|
||||
|
||||
@@ -45,14 +45,22 @@ impl FixedDigitalLevelEstimator {
|
||||
/// The input is assumed to be in FloatS16 format. Returns `SUB_FRAMES_IN_FRAME`
|
||||
/// level estimates, one per sub-frame.
|
||||
pub fn compute_level(&mut self, frame: &[&[f32]]) -> [f32; SUB_FRAMES_IN_FRAME as usize] {
|
||||
self.compute_level_of_channels(frame)
|
||||
}
|
||||
|
||||
pub(crate) fn compute_level_of_channels<C: AsRef<[f32]>>(
|
||||
&mut self,
|
||||
frame: &[C],
|
||||
) -> [f32; SUB_FRAMES_IN_FRAME as usize] {
|
||||
let num_channels = frame.len();
|
||||
debug_assert!(num_channels > 0);
|
||||
debug_assert_eq!(frame[0].len(), self.samples_in_frame as usize);
|
||||
debug_assert_eq!(frame[0].as_ref().len(), self.samples_in_frame as usize);
|
||||
|
||||
// Compute max envelope without smoothing.
|
||||
let mut envelope = [0.0_f32; SUB_FRAMES_IN_FRAME as usize];
|
||||
let sub_frame_len = self.samples_in_sub_frame as usize;
|
||||
for channel in frame {
|
||||
let channel = channel.as_ref();
|
||||
for (sub_frame, env) in envelope.iter_mut().enumerate() {
|
||||
let sub_frame_samples =
|
||||
&channel[sub_frame * sub_frame_len..(sub_frame + 1) * sub_frame_len];
|
||||
|
||||
+19
-7
@@ -12,20 +12,20 @@ fn gain_close_to_one(gain_factor: f32) -> bool {
|
||||
}
|
||||
|
||||
/// Clamps all samples in multi-channel signal to FloatS16 range.
|
||||
fn clip_signal(signal: &mut [&mut [f32]]) {
|
||||
fn clip_signal<C: AsMut<[f32]>>(signal: &mut [C]) {
|
||||
for channel in signal.iter_mut() {
|
||||
for sample in channel.iter_mut() {
|
||||
for sample in channel.as_mut().iter_mut() {
|
||||
*sample = sample.clamp(MIN_FLOAT_S16_VALUE, MAX_FLOAT_S16_VALUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies gain with linear ramping across the frame.
|
||||
fn apply_gain_with_ramping(
|
||||
fn apply_gain_with_ramping<C: AsMut<[f32]>>(
|
||||
last_gain: f32,
|
||||
gain_at_end: f32,
|
||||
inverse_samples_per_channel: f32,
|
||||
signal: &mut [&mut [f32]],
|
||||
signal: &mut [C],
|
||||
) {
|
||||
// Do not modify the signal.
|
||||
if last_gain == gain_at_end && gain_close_to_one(gain_at_end) {
|
||||
@@ -35,7 +35,7 @@ fn apply_gain_with_ramping(
|
||||
// Gain is constant and different from 1.
|
||||
if last_gain == gain_at_end {
|
||||
for channel in signal.iter_mut() {
|
||||
for sample in channel.iter_mut() {
|
||||
for sample in channel.as_mut().iter_mut() {
|
||||
*sample *= gain_at_end;
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ fn apply_gain_with_ramping(
|
||||
let increment = (gain_at_end - last_gain) * inverse_samples_per_channel;
|
||||
for channel in signal.iter_mut() {
|
||||
let mut gain = last_gain;
|
||||
for sample in channel.iter_mut() {
|
||||
for sample in channel.as_mut().iter_mut() {
|
||||
*sample *= gain;
|
||||
gain += increment;
|
||||
}
|
||||
@@ -81,7 +81,19 @@ impl GainApplier {
|
||||
|
||||
/// Applies gain to the signal with linear ramping between frames.
|
||||
pub fn apply_gain(&mut self, signal: &mut [&mut [f32]]) {
|
||||
let spc = signal.first().map_or(0, |ch| ch.len()) as i32;
|
||||
self.apply_gain_to_channels(signal);
|
||||
}
|
||||
|
||||
/// Applies gain to a signal in owned buffers with linear ramping between frames.
|
||||
pub fn apply_gain_to_owned_signal(&mut self, signal: &mut [Vec<f32>]) {
|
||||
self.apply_gain_to_channels(signal);
|
||||
}
|
||||
|
||||
pub(crate) fn apply_gain_to_channels<C: AsRef<[f32]> + AsMut<[f32]>>(
|
||||
&mut self,
|
||||
signal: &mut [C],
|
||||
) {
|
||||
let spc = signal.first().map_or(0, |ch| ch.as_ref().len()) as i32;
|
||||
if spc != self.samples_per_channel {
|
||||
self.initialize(spc);
|
||||
}
|
||||
|
||||
+17
-11
@@ -53,11 +53,14 @@ fn compute_per_sample_subframe_factors(
|
||||
}
|
||||
}
|
||||
|
||||
fn scale_samples(per_sample_scaling_factors: &[f32], signal: &mut [&mut [f32]]) {
|
||||
let samples_per_channel = signal.first().map_or(0, |ch| ch.len());
|
||||
fn scale_samples<C: AsRef<[f32]> + AsMut<[f32]>>(
|
||||
per_sample_scaling_factors: &[f32],
|
||||
signal: &mut [C],
|
||||
) {
|
||||
let samples_per_channel = signal.first().map_or(0, |ch| ch.as_ref().len());
|
||||
debug_assert_eq!(samples_per_channel, per_sample_scaling_factors.len());
|
||||
for channel in signal.iter_mut() {
|
||||
for (sample, &factor) in channel.iter_mut().zip(per_sample_scaling_factors) {
|
||||
for (sample, &factor) in channel.as_mut().iter_mut().zip(per_sample_scaling_factors) {
|
||||
*sample = (*sample * factor).clamp(MIN_FLOAT_S16_VALUE, MAX_FLOAT_S16_VALUE);
|
||||
}
|
||||
}
|
||||
@@ -91,16 +94,19 @@ impl Limiter {
|
||||
|
||||
/// Applies limiter and hard-clipping to the signal.
|
||||
pub fn process(&mut self, signal: &mut [&mut [f32]]) {
|
||||
let samples_per_channel = signal.first().map_or(0, |ch| ch.len());
|
||||
self.process_channels(signal);
|
||||
}
|
||||
|
||||
/// Applies limiter and hard-clipping to a signal in owned buffers.
|
||||
pub fn process_owned_signal(&mut self, signal: &mut [Vec<f32>]) {
|
||||
self.process_channels(signal);
|
||||
}
|
||||
|
||||
fn process_channels<C: AsRef<[f32]> + AsMut<[f32]>>(&mut self, signal: &mut [C]) {
|
||||
let samples_per_channel = signal.first().map_or(0, |ch| ch.as_ref().len());
|
||||
debug_assert!(samples_per_channel <= MAXIMAL_NUMBER_OF_SAMPLES_PER_CHANNEL);
|
||||
|
||||
// Mono capture needs only a stack descriptor; keep the generic multichannel path.
|
||||
let level_estimate = if signal.len() == 1 {
|
||||
self.level_estimator.compute_level(&[&*signal[0]])
|
||||
} else {
|
||||
let signal_refs: Vec<&[f32]> = signal.iter().map(|ch| &**ch).collect();
|
||||
self.level_estimator.compute_level(&signal_refs)
|
||||
};
|
||||
let level_estimate = self.level_estimator.compute_level_of_channels(signal);
|
||||
|
||||
debug_assert_eq!(level_estimate.len() + 1, self.scaling_factors.len());
|
||||
self.scaling_factors[0] = self.last_scaling_factor;
|
||||
|
||||
+12
-3
@@ -7,10 +7,10 @@ const FRAMES_PER_SECOND: i32 = 100;
|
||||
/// Update the noise floor every 5 seconds.
|
||||
const UPDATE_PERIOD_NUM_FRAMES: i32 = 500;
|
||||
|
||||
fn frame_energy(audio: &[&[f32]]) -> f32 {
|
||||
fn frame_energy<C: AsRef<[f32]>>(audio: &[C]) -> f32 {
|
||||
let mut energy = 0.0_f32;
|
||||
for channel in audio {
|
||||
let channel_energy: f32 = channel.iter().map(|&s| s * s).sum();
|
||||
let channel_energy: f32 = channel.as_ref().iter().map(|&s| s * s).sum();
|
||||
energy = energy.max(channel_energy);
|
||||
}
|
||||
energy
|
||||
@@ -76,8 +76,17 @@ impl NoiseLevelEstimator {
|
||||
/// Analyzes a 10 ms frame, updates the noise level estimation and returns
|
||||
/// the value for the latter in dBFS.
|
||||
pub fn analyze(&mut self, frame: &[&[f32]]) -> f32 {
|
||||
self.analyze_channels(frame)
|
||||
}
|
||||
|
||||
/// Analyzes a 10 ms frame in owned buffers, like [`Self::analyze`].
|
||||
pub fn analyze_owned_frame(&mut self, frame: &[Vec<f32>]) -> f32 {
|
||||
self.analyze_channels(frame)
|
||||
}
|
||||
|
||||
fn analyze_channels<C: AsRef<[f32]>>(&mut self, frame: &[C]) -> f32 {
|
||||
debug_assert!(!frame.is_empty());
|
||||
let samples_per_channel = frame[0].len();
|
||||
let samples_per_channel = frame[0].as_ref().len();
|
||||
|
||||
// Detect sample rate changes.
|
||||
let sample_rate_hz = samples_per_channel as i32 * FRAMES_PER_SECOND;
|
||||
|
||||
+4
-2
@@ -101,8 +101,10 @@ mod tests {
|
||||
let mut bytes = Vec::new();
|
||||
file.read_to_end(&mut bytes).unwrap();
|
||||
bytes
|
||||
.chunks_exact(4)
|
||||
.map(|c| f32::from_le_bytes(c.try_into().unwrap()))
|
||||
.as_chunks::<4>()
|
||||
.0
|
||||
.iter()
|
||||
.map(|c| f32::from_le_bytes(*c))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
||||
@@ -540,8 +540,10 @@ mod tests {
|
||||
let mut bytes = Vec::new();
|
||||
file.read_to_end(&mut bytes).unwrap();
|
||||
let floats: Vec<f32> = bytes
|
||||
.chunks_exact(4)
|
||||
.map(|c| f32::from_le_bytes(c.try_into().unwrap()))
|
||||
.as_chunks::<4>()
|
||||
.0
|
||||
.iter()
|
||||
.map(|c| f32::from_le_bytes(*c))
|
||||
.collect();
|
||||
|
||||
let mut offset = 0;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
//! Checks that methods keep the signatures they had in sonora-agc2 0.2.0.
|
||||
|
||||
use sonora_agc2::adaptive_digital_gain_controller::{AdaptiveDigitalGainController, FrameInfo};
|
||||
use sonora_agc2::common::SUB_FRAMES_IN_FRAME;
|
||||
use sonora_agc2::fixed_digital_level_estimator::FixedDigitalLevelEstimator;
|
||||
use sonora_agc2::gain_applier::GainApplier;
|
||||
use sonora_agc2::limiter::Limiter;
|
||||
use sonora_agc2::noise_level_estimator::NoiseLevelEstimator;
|
||||
|
||||
// Generic signatures break 0.2.0 callers that take a function pointer, pass
|
||||
// an empty slice or mix buffer types in one slice literal.
|
||||
#[test]
|
||||
fn methods_keep_published_signatures() {
|
||||
let _: fn(&mut AdaptiveDigitalGainController, &FrameInfo, &mut [&mut [f32]]) =
|
||||
AdaptiveDigitalGainController::process;
|
||||
let _: fn(&mut FixedDigitalLevelEstimator, &[&[f32]]) -> [f32; SUB_FRAMES_IN_FRAME as usize] =
|
||||
FixedDigitalLevelEstimator::compute_level;
|
||||
let _: fn(&mut GainApplier, &mut [&mut [f32]]) = GainApplier::apply_gain;
|
||||
let _: fn(&mut Limiter, &mut [&mut [f32]]) = Limiter::process;
|
||||
let _: fn(&mut NoiseLevelEstimator, &[&[f32]]) -> f32 = NoiseLevelEstimator::analyze;
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "a024d6ef8351add55be5e8b1d6cc35f555787660"
|
||||
"sha1": "1632d47c1e77d0857f9145bd175134b348541e11"
|
||||
},
|
||||
"path_in_vcs": "crates/sonora"
|
||||
}
|
||||
+120
-118
@@ -4,9 +4,9 @@ version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.4"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||
checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
@@ -112,9 +112,9 @@ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.1"
|
||||
version = "2.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da"
|
||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||
|
||||
[[package]]
|
||||
name = "block2"
|
||||
@@ -142,13 +142,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck_derive"
|
||||
version = "1.11.0"
|
||||
version = "1.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f65693059b6b9c588b9f62fed1cedbf0a8b805631457ea162d68f0de186f3de5"
|
||||
checksum = "6a1f896587b6f2c069c73d2f0913e2d590c3990285cd2f0b6aa02b786b4c679c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -165,9 +165,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.4.0"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9"
|
||||
checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
@@ -175,9 +175,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||
|
||||
[[package]]
|
||||
name = "cfg_aliases"
|
||||
@@ -214,9 +214,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.6.4"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d91e0c145792ef73a6ad36d27c75ac09f1832222a3c209689d90f534685ee5b7"
|
||||
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@@ -224,9 +224,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.6.2"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f09628afdcc538b57f3c6341e9c8e9970f18e4a481690a64974d7023bd33548b"
|
||||
checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -236,21 +236,21 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.6.4"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061"
|
||||
checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.3",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "1.1.0"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
|
||||
checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
@@ -260,9 +260,9 @@ checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "4.6.7"
|
||||
version = "4.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd"
|
||||
checksum = "4356eba6976435498d05a311ee9fc486da3bc81c200d3f0d7dd9703b41913f92"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"memchr",
|
||||
@@ -284,9 +284,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cpal"
|
||||
version = "0.18.1"
|
||||
version = "0.18.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f77b11176c37874be37e8d691c946e31b2b8c357abce9526f6a99eb469e1028"
|
||||
checksum = "6f02e8d0327b42d3e2e4ab2119af397344eb9fc54a34bf0ddeaa1277af8681f1"
|
||||
dependencies = [
|
||||
"alsa",
|
||||
"block2",
|
||||
@@ -314,9 +314,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
|
||||
checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
@@ -358,9 +358,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.7"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5181e0de7b61eb03a81e347d6dd8797bae9da5146707b51077e2d71a54ec0ceb"
|
||||
checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
@@ -368,18 +368,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.20"
|
||||
version = "0.9.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d6914041f254d6e9176c01941b21115dcfb7089e55135a35411081bd106ef3f"
|
||||
checksum = "dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.22"
|
||||
version = "0.8.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17"
|
||||
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
@@ -440,39 +440,39 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.17.0"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e5e8f6c15a24b9a3ee5efec809ccd006d3b30e8b3bb63c39af737c7f87daa1d"
|
||||
checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.9"
|
||||
version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
||||
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.33"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cd50c473c80f6d7c3670a752354b8e569b1a7cbfdc0419ec88e5edad85e0dc7"
|
||||
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.33"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b231ed28831efb4a61a08580c4bc233ec56bc009f4cd8f52da2c3cb97df0c109"
|
||||
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.33"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a77a90a256fce34da66415271e30f94ee91c57b04b8a2c042d9cf3220179deaa"
|
||||
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
@@ -511,9 +511,9 @@ checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.14.0"
|
||||
version = "2.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
|
||||
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
@@ -552,7 +552,7 @@ dependencies = [
|
||||
"jni-sys 0.4.1",
|
||||
"log",
|
||||
"simd_cesu8",
|
||||
"thiserror 2.0.19",
|
||||
"thiserror 2.0.21",
|
||||
"walkdir",
|
||||
"windows-link",
|
||||
]
|
||||
@@ -600,9 +600,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.103"
|
||||
version = "0.3.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102"
|
||||
checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -611,21 +611,21 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.189"
|
||||
version = "0.2.191"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.33"
|
||||
version = "0.4.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
||||
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
|
||||
|
||||
[[package]]
|
||||
name = "mach2"
|
||||
@@ -742,9 +742,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "objc2"
|
||||
version = "0.6.4"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f"
|
||||
checksum = "08849bbd4767dfae9457696856ae1c84fe4e0281bbe4a7abff2d0e06fb7981f8"
|
||||
dependencies = [
|
||||
"objc2-encode",
|
||||
]
|
||||
@@ -866,9 +866,9 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.33"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
|
||||
checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
|
||||
|
||||
[[package]]
|
||||
name = "plotters"
|
||||
@@ -900,15 +900,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.14.0"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d20d5497ef88037a52ff98267d066e7f11fcc5e99bbfbd58a42336193aacec3"
|
||||
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic-util"
|
||||
version = "0.2.7"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618"
|
||||
checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
@@ -974,9 +974,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.16"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fcfdb36bda0c880c5931cdc7a2bcdc8ba4556847b9d912bca70bc94708711ad"
|
||||
checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -991,9 +991,9 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "ringbuf"
|
||||
version = "0.5.1"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a158e09ede21a14b172ca6cdd6208386c6ae2cb6acef58d774368ef8c450dfa7"
|
||||
checksum = "b58b631e416dd7d84549d7e6a50f767e111f9b03e30d04f40072f6618f386aaf"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
"portable-atomic",
|
||||
@@ -1057,14 +1057,14 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.3",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.151"
|
||||
version = "1.0.154"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14"
|
||||
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
@@ -1112,13 +1112,13 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.15.2"
|
||||
version = "1.16.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90"
|
||||
checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8"
|
||||
|
||||
[[package]]
|
||||
name = "sonora"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
@@ -1139,9 +1139,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sonora-aec3"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50280e31256d09f7838aff6715ed4b7640e514dc1092a1e14013c01e552380db"
|
||||
checksum = "f2809c3fda13f71deac22d0ddb6c02c493f254d3da2afe59a7e256a8f15bcffe"
|
||||
dependencies = [
|
||||
"sonora-common-audio",
|
||||
"sonora-fft",
|
||||
@@ -1150,7 +1150,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sonora-agc2"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"derive_more",
|
||||
@@ -1162,9 +1162,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sonora-common-audio"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6635bc61b24807ceac93ad0807b1292b6b0620caa6cd360d3be89fc616b833cc"
|
||||
checksum = "2c05dfa300c14dc8498751ce2c5b87aad2acf1892d4f9d66b92ae2f372a83410"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"sonora-simd",
|
||||
@@ -1172,24 +1172,27 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sonora-fft"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27e272c70f34363afb5382dd1818c05f8f63ef6785635736a14e9ccbbb5ba012"
|
||||
checksum = "ec3529f2cf748f1acc85d9403ffa08a3fe69dec6bf22383910b3bd21aca2fd26"
|
||||
dependencies = [
|
||||
"sonora-simd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sonora-ns"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d511feef19302c716d245c4555087d161ba91c178735ea11107dcce0d0b7a86f"
|
||||
checksum = "31c0a62e78419a174dbf9c9c01943c1ecd8c298a68d15c4fb4906cb19f0428b9"
|
||||
dependencies = [
|
||||
"sonora-fft",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sonora-simd"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7cf0804e4752a5562262e143014f53043080ead4cd5a98f9278d3ceaf32d868"
|
||||
checksum = "f939d8e63a2a0baa7555294d7b09c5e3d382f28358755b920e13ad527658c8fa"
|
||||
dependencies = [
|
||||
"cpufeatures",
|
||||
]
|
||||
@@ -1213,9 +1216,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.3"
|
||||
version = "3.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
|
||||
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -1233,11 +1236,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.19"
|
||||
version = "2.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09a43598840e33d5b0331f38c5e30d13bb11c11210a4b58f0d9b18a5a5eefcd9"
|
||||
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
|
||||
dependencies = [
|
||||
"thiserror-impl 2.0.19",
|
||||
"thiserror-impl 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1253,13 +1256,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.19"
|
||||
version = "2.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43cbfe0cf76104d42a574802844187e84a305e531ed54455f11fbde0f10541cd"
|
||||
checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.3",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1283,18 +1286,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "1.1.1+spec-1.1.0"
|
||||
version = "1.1.3+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7"
|
||||
checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.25.13+spec-1.1.0"
|
||||
version = "0.25.19+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6975367e4d2ef766d86af01ffad14b622fecc8d4357a998fbc4deb6e9bacaf9b"
|
||||
checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime",
|
||||
@@ -1304,9 +1307,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.1.3+spec-1.1.0"
|
||||
version = "1.1.5+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56"
|
||||
checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c"
|
||||
dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
@@ -1374,9 +1377,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
@@ -1408,12 +1411,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.126"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4"
|
||||
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
@@ -1421,9 +1423,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.126"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1"
|
||||
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -1431,31 +1433,31 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.126"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e"
|
||||
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
"syn 3.0.9",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.126"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24"
|
||||
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.103"
|
||||
version = "0.3.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8622dcb61c0bcc9fffa6938bed81210af2da9a7e4a1a834b2e37a59b6dfb6141"
|
||||
checksum = "d7d179596ff5ec0f6de4db64d54011bde6289cc49603d3a6e4ce3f329207ab88"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
@@ -1613,27 +1615,27 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "1.0.4"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81"
|
||||
checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.55"
|
||||
version = "0.8.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5a105cd7b140f6eeec8acff2ea38135d3cab283ada58540f629fe51e46696eb"
|
||||
checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.55"
|
||||
version = "0.8.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fe976fb70c78cd64cccfe3a6fc142244e8a77b70959b30faf9d0ac37ee228eb"
|
||||
checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
||||
Vendored
+15
-7
@@ -13,7 +13,7 @@
|
||||
edition = "2024"
|
||||
rust-version = "1.91"
|
||||
name = "sonora"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
build = false
|
||||
autolib = false
|
||||
autobins = false
|
||||
@@ -61,6 +61,14 @@ required-features = ["examples"]
|
||||
name = "simple"
|
||||
path = "examples/simple.rs"
|
||||
|
||||
[[test]]
|
||||
name = "echo_canceller3_config"
|
||||
path = "tests/echo_canceller3_config.rs"
|
||||
|
||||
[[test]]
|
||||
name = "no_allocation"
|
||||
path = "tests/no_allocation.rs"
|
||||
|
||||
[[bench]]
|
||||
name = "pipeline"
|
||||
path = "benches/pipeline.rs"
|
||||
@@ -93,19 +101,19 @@ version = "0.5"
|
||||
optional = true
|
||||
|
||||
[dependencies.sonora-aec3]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dependencies.sonora-agc2]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dependencies.sonora-common-audio]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dependencies.sonora-ns]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dependencies.sonora-simd]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dependencies.tracing]
|
||||
version = "0.1"
|
||||
@@ -115,7 +123,7 @@ version = "0.8"
|
||||
features = ["html_reports"]
|
||||
|
||||
[dev-dependencies.sonora-fft]
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
||||
[dev-dependencies.tracing-subscriber]
|
||||
version = "0.3"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "sonora"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
description = "WebRTC Audio Processing — pure Rust port with echo cancellation, noise suppression, and AGC"
|
||||
keywords = ["audio", "webrtc", "echo-cancellation", "noise-suppression", "agc"]
|
||||
categories = ["multimedia::audio"]
|
||||
|
||||
+64
@@ -111,6 +111,69 @@ fn bench_process_stream(c: &mut Criterion) {
|
||||
group.finish();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Issue #34: AEC3 with a silent render reference
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Render+capture pair cost with an active and with an exact-zero render
|
||||
/// reference. Without hardware flush-to-zero the recursive filters settle in
|
||||
/// the subnormal range once render goes silent and stay there, which costs a
|
||||
/// microcode assist per operation on x86 (10-50x per the report). The
|
||||
/// silent/active ratio is the figure to watch; it should stay near 1.
|
||||
fn bench_aec3_silent_render(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("aec3_render");
|
||||
let stream = StreamConfig::new(48000, 1);
|
||||
let n = stream.num_frames();
|
||||
let speech: Vec<f32> = (0..n).map(|i| (i as f32 * 0.01).sin() * 0.1).collect();
|
||||
let echo: Vec<f32> = speech.iter().map(|x| 0.5 * x).collect();
|
||||
let silence = vec![0.0f32; n];
|
||||
// About -60 dBFS deterministic noise on the capture side.
|
||||
let noise: Vec<f32> = (0..n)
|
||||
.map(|i| ((i * 7919 % 101) as f32 / 101.0 - 0.5) * 2e-3)
|
||||
.collect();
|
||||
let mut out = vec![0.0f32; n];
|
||||
let mut render_out = vec![0.0f32; n];
|
||||
|
||||
for (name, render, capture) in [
|
||||
("48k_mono_active", &speech, &echo),
|
||||
("48k_mono_silent", &silence, &noise),
|
||||
] {
|
||||
let config = Config {
|
||||
echo_canceller: Some(EchoCanceller::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let mut apm = AudioProcessing::builder()
|
||||
.config(config)
|
||||
.capture_config(stream)
|
||||
.render_config(stream)
|
||||
.build();
|
||||
// 1 s with active render and echo, then 6 s of the measured
|
||||
// condition so the filter states have settled before timing. Without
|
||||
// flush-to-zero, the slowest state (the low-render detector's average
|
||||
// power) turns subnormal about 4 s into the silent condition.
|
||||
for _ in 0..100 {
|
||||
apm.process_render_f32(&[&speech], &mut [&mut render_out])
|
||||
.unwrap();
|
||||
apm.process_capture_f32(&[&echo], &mut [&mut out]).unwrap();
|
||||
}
|
||||
for _ in 0..600 {
|
||||
apm.process_render_f32(&[render], &mut [&mut render_out])
|
||||
.unwrap();
|
||||
apm.process_capture_f32(&[capture], &mut [&mut out])
|
||||
.unwrap();
|
||||
}
|
||||
group.bench_function(name, |b| {
|
||||
b.iter(|| {
|
||||
apm.process_render_f32(&[black_box(render)], &mut [&mut render_out])
|
||||
.unwrap();
|
||||
apm.process_capture_f32(&[black_box(capture)], &mut [&mut out])
|
||||
.unwrap();
|
||||
});
|
||||
});
|
||||
}
|
||||
group.finish();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Component benchmarks
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -204,6 +267,7 @@ fn bench_sinc_resampler(c: &mut Criterion) {
|
||||
criterion_group!(
|
||||
benches,
|
||||
bench_process_stream,
|
||||
bench_aec3_silent_render,
|
||||
bench_noise_suppressor,
|
||||
bench_pffft,
|
||||
bench_sinc_resampler,
|
||||
|
||||
+27
-26
@@ -43,6 +43,10 @@ pub(crate) struct AudioBuffer {
|
||||
output_resamplers: Vec<PushSincResampler>,
|
||||
downmix_by_averaging: bool,
|
||||
channel_for_downmixing: usize,
|
||||
/// Working buffer for downmixing and sample format conversion in the
|
||||
/// `copy_*` methods. It is sized at construction for the longer of the
|
||||
/// input and output frames so that processing a frame does not allocate.
|
||||
scratch: Vec<f32>,
|
||||
}
|
||||
|
||||
impl AudioBuffer {
|
||||
@@ -120,6 +124,7 @@ impl AudioBuffer {
|
||||
output_resamplers,
|
||||
downmix_by_averaging: true,
|
||||
channel_for_downmixing: 0,
|
||||
scratch: vec![0.0; input_num_frames.max(output_num_frames)],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,9 +232,8 @@ impl AudioBuffer {
|
||||
let resampling_needed = self.input_num_frames != self.buffer_num_frames;
|
||||
|
||||
if downmix_needed {
|
||||
let mut downmix = vec![0.0f32; self.input_num_frames];
|
||||
|
||||
if self.downmix_by_averaging {
|
||||
let downmixed_data: &[f32] = if self.downmix_by_averaging {
|
||||
let downmix = &mut self.scratch[..self.input_num_frames];
|
||||
let scale = 1.0 / self.input_num_channels as f32;
|
||||
for (i, d) in downmix.iter_mut().enumerate() {
|
||||
let mut value = stacked_data[0][i];
|
||||
@@ -238,14 +242,7 @@ impl AudioBuffer {
|
||||
}
|
||||
*d = value * scale;
|
||||
}
|
||||
} else {
|
||||
downmix.copy_from_slice(
|
||||
&stacked_data[self.channel_for_downmixing][..self.input_num_frames],
|
||||
);
|
||||
}
|
||||
|
||||
let downmixed_data = if self.downmix_by_averaging {
|
||||
&downmix
|
||||
downmix
|
||||
} else {
|
||||
&stacked_data[self.channel_for_downmixing][..self.input_num_frames]
|
||||
};
|
||||
@@ -318,10 +315,14 @@ impl AudioBuffer {
|
||||
let buf_frames = buffer.num_frames();
|
||||
if resampling_needed {
|
||||
for i in 0..self.num_channels {
|
||||
// Resample straight into the destination channel instead of a
|
||||
// temporary vector, so this real-time path does not allocate.
|
||||
// This fills the whole destination only because the resampler
|
||||
// produces exactly `buf_frames` samples per call.
|
||||
let src = self.data.bands(i);
|
||||
let mut temp = vec![0.0f32; buf_frames];
|
||||
self.output_resamplers[i].resample(src, &mut temp);
|
||||
buffer.channel_mut(i)[..buf_frames].copy_from_slice(&temp);
|
||||
let written = self.output_resamplers[i]
|
||||
.resample(src, &mut buffer.channel_mut(i)[..buf_frames]);
|
||||
debug_assert_eq!(written, buf_frames);
|
||||
}
|
||||
} else {
|
||||
for i in 0..self.num_channels {
|
||||
@@ -362,13 +363,13 @@ impl AudioBuffer {
|
||||
if self.input_num_channels == 1 {
|
||||
// Mono to mono.
|
||||
if resampling_required {
|
||||
let mut float_buffer = vec![0.0f32; self.input_num_frames];
|
||||
let float_buffer = &mut self.scratch[..self.input_num_frames];
|
||||
audio_util::s16_to_float_s16_slice(
|
||||
&interleaved_data[..self.input_num_frames],
|
||||
&mut float_buffer,
|
||||
float_buffer,
|
||||
);
|
||||
let ch0 = self.data.bands_mut(0);
|
||||
self.input_resamplers[0].resample(&float_buffer, ch0);
|
||||
self.input_resamplers[0].resample(float_buffer, ch0);
|
||||
} else {
|
||||
let ch0 = self.data.bands_mut(0);
|
||||
audio_util::s16_to_float_s16_slice(
|
||||
@@ -378,7 +379,7 @@ impl AudioBuffer {
|
||||
}
|
||||
} else {
|
||||
// Multi-channel to mono (downmix).
|
||||
let mut downmixed = vec![0.0f32; self.input_num_frames];
|
||||
let downmixed = &mut self.scratch[..self.input_num_frames];
|
||||
|
||||
if self.downmix_by_averaging {
|
||||
for (j, sample) in downmixed.iter_mut().enumerate().take(self.input_num_frames)
|
||||
@@ -399,15 +400,15 @@ impl AudioBuffer {
|
||||
|
||||
if resampling_required {
|
||||
let ch0 = self.data.bands_mut(0);
|
||||
self.input_resamplers[0].resample(&downmixed, ch0);
|
||||
self.input_resamplers[0].resample(downmixed, ch0);
|
||||
} else {
|
||||
self.data.bands_mut(0)[..self.input_num_frames].copy_from_slice(&downmixed);
|
||||
self.data.bands_mut(0)[..self.input_num_frames].copy_from_slice(downmixed);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Multi-channel, deinterleave.
|
||||
if resampling_required {
|
||||
let mut float_buffer = vec![0.0f32; self.input_num_frames];
|
||||
let float_buffer = &mut self.scratch[..self.input_num_frames];
|
||||
for i in 0..self.num_channels {
|
||||
// Deinterleave channel i.
|
||||
for (j, sample) in float_buffer
|
||||
@@ -418,7 +419,7 @@ impl AudioBuffer {
|
||||
*sample = interleaved_data[j * self.input_num_channels + i] as f32;
|
||||
}
|
||||
let ch = self.data.bands_mut(i);
|
||||
self.input_resamplers[i].resample(&float_buffer, ch);
|
||||
self.input_resamplers[i].resample(float_buffer, ch);
|
||||
}
|
||||
} else {
|
||||
for i in 0..self.num_channels {
|
||||
@@ -444,11 +445,11 @@ impl AudioBuffer {
|
||||
let resampling_required = self.buffer_num_frames != self.output_num_frames;
|
||||
|
||||
if self.num_channels == 1 {
|
||||
let mut float_buffer = vec![0.0f32; self.output_num_frames];
|
||||
let float_buffer = &mut self.scratch[..self.output_num_frames];
|
||||
|
||||
if resampling_required {
|
||||
let ch0 = self.data.bands(0);
|
||||
self.output_resamplers[0].resample(ch0, &mut float_buffer);
|
||||
self.output_resamplers[0].resample(ch0, float_buffer);
|
||||
} else {
|
||||
float_buffer.copy_from_slice(&self.data.bands(0)[..self.output_num_frames]);
|
||||
}
|
||||
@@ -470,9 +471,9 @@ impl AudioBuffer {
|
||||
} else {
|
||||
if resampling_required {
|
||||
for i in 0..self.num_channels {
|
||||
let mut float_buffer = vec![0.0f32; self.output_num_frames];
|
||||
let float_buffer = &mut self.scratch[..self.output_num_frames];
|
||||
let ch = self.data.bands(i);
|
||||
self.output_resamplers[i].resample(ch, &mut float_buffer);
|
||||
self.output_resamplers[i].resample(ch, float_buffer);
|
||||
for (k, sample) in float_buffer.iter().enumerate().take(self.output_num_frames)
|
||||
{
|
||||
interleaved_data[k * config_num_channels + i] =
|
||||
|
||||
+42
-1
@@ -10,7 +10,7 @@ use std::error;
|
||||
use std::fmt;
|
||||
|
||||
use crate::audio_processing_impl::AudioProcessingImpl;
|
||||
use crate::config::{Config, PlayoutAudioDeviceInfo, RuntimeSetting};
|
||||
use crate::config::{Config, EchoCanceller3Config, PlayoutAudioDeviceInfo, RuntimeSetting};
|
||||
use crate::stats::AudioProcessingStats;
|
||||
use crate::stream_config::StreamConfig;
|
||||
/// Errors returned by audio processing operations.
|
||||
@@ -313,6 +313,7 @@ pub struct AudioProcessingBuilder {
|
||||
capture_config: StreamConfig,
|
||||
render_config: StreamConfig,
|
||||
echo_detector: bool,
|
||||
echo_canceller3_config: Option<EchoCanceller3Config>,
|
||||
}
|
||||
|
||||
impl Default for AudioProcessingBuilder {
|
||||
@@ -322,6 +323,7 @@ impl Default for AudioProcessingBuilder {
|
||||
capture_config: DEFAULT_STREAM_CONFIG,
|
||||
render_config: DEFAULT_STREAM_CONFIG,
|
||||
echo_detector: false,
|
||||
echo_canceller3_config: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,9 +363,24 @@ impl AudioProcessingBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Use this AEC3 configuration instead of the default one (matching C++
|
||||
/// `EchoCanceller3Factory(config)`). Only takes effect when
|
||||
/// [`Config::echo_canceller`] is enabled; its `transparent_mode` still
|
||||
/// overrides `echo_removal_control.transparent_mode`. The configuration
|
||||
/// is validated (clamped to valid ranges) when the echo canceller is
|
||||
/// created. It applies to mono and multichannel render alike, as with
|
||||
/// C++ `EchoCanceller3Factory(config)`.
|
||||
pub fn echo_canceller3_config(mut self, config: EchoCanceller3Config) -> Self {
|
||||
self.echo_canceller3_config = Some(config);
|
||||
self
|
||||
}
|
||||
|
||||
/// Build the [`AudioProcessing`] instance.
|
||||
pub fn build(self) -> AudioProcessing {
|
||||
let mut inner = AudioProcessingImpl::with_config(self.config);
|
||||
if let Some(config) = self.echo_canceller3_config {
|
||||
inner.set_echo_canceller3_config(config);
|
||||
}
|
||||
|
||||
if self.echo_detector {
|
||||
inner.set_echo_detector();
|
||||
@@ -413,6 +430,30 @@ impl AudioProcessingBuilder {
|
||||
/// - Call `apply_config` from any thread, but never concurrently with
|
||||
/// `config()`.
|
||||
///
|
||||
/// # Floating-point environment
|
||||
///
|
||||
/// Like upstream WebRTC, each `process_*` call sets hardware flush-to-zero
|
||||
/// for its duration on x86/x86_64 with SSE (MXCSR FTZ and DAZ) and on
|
||||
/// aarch64 with NEON (FPCR.FZ), and restores the calling thread's previous
|
||||
/// setting before it returns, also when it panics. While a call runs,
|
||||
/// subnormal input samples are read as zero, and any code the call reaches
|
||||
/// on this thread runs in that mode too: `tracing` subscribers, the global
|
||||
/// allocator and the panic hook. In that mode a comparison with a subnormal
|
||||
/// operand can change its result; for example, `x > 0.0` is false for the
|
||||
/// smallest positive subnormal `x`. On Linux and other platforms where a new
|
||||
/// thread inherits the floating-point environment, a thread started during
|
||||
/// the call (for example by a subscriber or the allocator) keeps
|
||||
/// flush-to-zero for its whole life; only the calling thread is restored.
|
||||
/// Changing the floating-point environment is formally undefined behavior in
|
||||
/// Rust, and upstream's `DenormalDisabler`, nih-plug and the `no_denormals`
|
||||
/// crate also change it; sonora sets flush-to-zero only on the calling thread
|
||||
/// and restores that thread's setting when each call returns (threads started
|
||||
/// during the call can inherit it; see above), and the audio pipeline has no
|
||||
/// subnormal-sensitive logic. All other targets do not flush, for example
|
||||
/// 32-bit ARM, `arm64ec`, wasm, x86 without SSE (i586) and aarch64 without
|
||||
/// NEON (soft-float). There, near-silent input can make processing slower on
|
||||
/// hardware with a subnormal penalty.
|
||||
///
|
||||
/// # Usage
|
||||
///
|
||||
/// 1. Create an instance via [`AudioProcessing::builder()`] or
|
||||
|
||||
+64
-6
@@ -11,6 +11,7 @@ use crate::audio_buffer::AudioBuffer;
|
||||
use crate::audio_converter::AudioConverter;
|
||||
use crate::capture_levels_adjuster::CaptureLevelsAdjuster;
|
||||
use crate::config::{Config, DownmixMethod, NoiseSuppressionLevel, RuntimeSetting};
|
||||
use crate::denormal_disabler::DenormalDisabler;
|
||||
use crate::echo_canceller3::EchoCanceller3;
|
||||
use crate::gain_controller2::{
|
||||
Agc2AdaptiveDigitalConfig, Agc2Config, Agc2InputVolumeControllerConfig, FixedDigitalConfig,
|
||||
@@ -165,6 +166,8 @@ pub(crate) struct AudioProcessingImpl {
|
||||
capture_input_rms: RmsLevel,
|
||||
capture_output_rms: RmsLevel,
|
||||
capture_rms_interval_counter: usize,
|
||||
// AEC3 tuning given to the builder; the default configuration if `None`.
|
||||
echo_canceller3_config: Option<EchoCanceller3Config>,
|
||||
}
|
||||
|
||||
impl AudioProcessingImpl {
|
||||
@@ -193,11 +196,20 @@ impl AudioProcessingImpl {
|
||||
capture_input_rms: RmsLevel::new(),
|
||||
capture_output_rms: RmsLevel::new(),
|
||||
capture_rms_interval_counter: 0,
|
||||
echo_canceller3_config: None,
|
||||
};
|
||||
if !DenormalDisabler::is_supported() {
|
||||
tracing::info!("Denormal disabler unsupported");
|
||||
}
|
||||
apm.initialize();
|
||||
apm
|
||||
}
|
||||
|
||||
/// Sets the AEC3 configuration used when the echo canceller is created.
|
||||
pub(crate) fn set_echo_canceller3_config(&mut self, config: EchoCanceller3Config) {
|
||||
self.echo_canceller3_config = Some(config);
|
||||
}
|
||||
|
||||
/// Installs the residual echo detector (opt-in).
|
||||
///
|
||||
/// Must be called before `initialize()`.
|
||||
@@ -322,6 +334,7 @@ impl AudioProcessingImpl {
|
||||
/// Processes a capture audio frame.
|
||||
///
|
||||
/// `src` and `dest` are deinterleaved float channel slices, one per channel.
|
||||
#[inline(never)]
|
||||
pub(crate) fn process_stream(
|
||||
&mut self,
|
||||
src: &[&[f32]],
|
||||
@@ -329,6 +342,12 @@ impl AudioProcessingImpl {
|
||||
output_config: &StreamConfig,
|
||||
dest: &mut [&mut [f32]],
|
||||
) {
|
||||
// SAFETY: the pipeline tolerates flushed subnormals; upstream runs it
|
||||
// under the same guard (audio_processing_impl.cc, DenormalDisabler).
|
||||
// Foreign code in the window (tracing subscribers, the allocator, the
|
||||
// panic hook) is documented on `AudioProcessing`. `#[inline(never)]`
|
||||
// keeps caller code from being inlined into the window.
|
||||
let _denormal_disabler = unsafe { DenormalDisabler::new() };
|
||||
self.maybe_initialize_capture(input_config, output_config);
|
||||
|
||||
let capture_audio = self.capture.capture_audio.as_mut().unwrap();
|
||||
@@ -353,6 +372,7 @@ impl AudioProcessingImpl {
|
||||
/// Processes a reverse (render / far-end) audio frame.
|
||||
///
|
||||
/// `src` and `dest` are deinterleaved float channel slices, one per channel.
|
||||
#[inline(never)]
|
||||
pub(crate) fn process_reverse_stream(
|
||||
&mut self,
|
||||
src: &[&[f32]],
|
||||
@@ -360,6 +380,12 @@ impl AudioProcessingImpl {
|
||||
output_config: &StreamConfig,
|
||||
dest: &mut [&mut [f32]],
|
||||
) {
|
||||
// SAFETY: the pipeline tolerates flushed subnormals; upstream runs it
|
||||
// under the same guard (audio_processing_impl.cc, DenormalDisabler).
|
||||
// Foreign code in the window (tracing subscribers, the allocator, the
|
||||
// panic hook) is documented on `AudioProcessing`. `#[inline(never)]`
|
||||
// keeps caller code from being inlined into the window.
|
||||
let _denormal_disabler = unsafe { DenormalDisabler::new() };
|
||||
self.maybe_initialize_render(input_config, output_config);
|
||||
self.analyze_reverse_stream_locked(src, input_config);
|
||||
|
||||
@@ -387,6 +413,7 @@ impl AudioProcessingImpl {
|
||||
}
|
||||
|
||||
/// Processes a capture audio frame (int16, interleaved).
|
||||
#[inline(never)]
|
||||
pub(crate) fn process_stream_i16(
|
||||
&mut self,
|
||||
src: &[i16],
|
||||
@@ -394,6 +421,12 @@ impl AudioProcessingImpl {
|
||||
output_config: &StreamConfig,
|
||||
dest: &mut [i16],
|
||||
) {
|
||||
// SAFETY: the pipeline tolerates flushed subnormals; upstream runs it
|
||||
// under the same guard (audio_processing_impl.cc, DenormalDisabler).
|
||||
// Foreign code in the window (tracing subscribers, the allocator, the
|
||||
// panic hook) is documented on `AudioProcessing`. `#[inline(never)]`
|
||||
// keeps caller code from being inlined into the window.
|
||||
let _denormal_disabler = unsafe { DenormalDisabler::new() };
|
||||
self.maybe_initialize_capture(input_config, output_config);
|
||||
|
||||
let capture_audio = self.capture.capture_audio.as_mut().unwrap();
|
||||
@@ -429,6 +462,7 @@ impl AudioProcessingImpl {
|
||||
}
|
||||
|
||||
/// Processes a reverse (render / far-end) audio frame (int16, interleaved).
|
||||
#[inline(never)]
|
||||
pub(crate) fn process_reverse_stream_i16(
|
||||
&mut self,
|
||||
src: &[i16],
|
||||
@@ -436,6 +470,12 @@ impl AudioProcessingImpl {
|
||||
output_config: &StreamConfig,
|
||||
dest: &mut [i16],
|
||||
) {
|
||||
// SAFETY: the pipeline tolerates flushed subnormals; upstream runs it
|
||||
// under the same guard (audio_processing_impl.cc, DenormalDisabler).
|
||||
// Foreign code in the window (tracing subscribers, the allocator, the
|
||||
// panic hook) is documented on `AudioProcessing`. `#[inline(never)]`
|
||||
// keeps caller code from being inlined into the window.
|
||||
let _denormal_disabler = unsafe { DenormalDisabler::new() };
|
||||
self.maybe_initialize_render(input_config, output_config);
|
||||
|
||||
let render_audio = self.render.render_audio.as_mut().unwrap();
|
||||
@@ -683,10 +723,11 @@ impl AudioProcessingImpl {
|
||||
.capture_multi_band_processing_active(ec_active)
|
||||
{
|
||||
// Copy the multi-band processed audio to the fullband buffer.
|
||||
// Temporarily take capture_audio to avoid double &mut borrow.
|
||||
let mut capture = self.capture.capture_audio.take().unwrap();
|
||||
capture.copy_to_buffer(fullband);
|
||||
self.capture.capture_audio = Some(capture);
|
||||
self.capture
|
||||
.capture_audio
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.copy_to_buffer(fullband);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1277,9 +1318,26 @@ impl AudioProcessingImpl {
|
||||
let num_render_channels = self.num_reverse_channels();
|
||||
let num_capture_channels = self.num_proc_channels();
|
||||
|
||||
let mut config = EchoCanceller3Config::default();
|
||||
// The default path stays exactly as before; only a caller's tuning
|
||||
// is validated (clamped to valid ranges).
|
||||
let mut config = match &self.echo_canceller3_config {
|
||||
Some(custom) => {
|
||||
let mut custom = custom.clone();
|
||||
if !custom.validate() {
|
||||
tracing::warn!("Invalid EchoCanceller3Config; clamped to valid ranges");
|
||||
}
|
||||
custom
|
||||
}
|
||||
None => EchoCanceller3Config::default(),
|
||||
};
|
||||
config.echo_removal_control.transparent_mode = ec.transparent_mode;
|
||||
let multichannel_config = Some(EchoCanceller3Config::create_default_multichannel_config());
|
||||
// Like C++ `AudioProcessingImpl::InitializeEchoController`: the default
|
||||
// multichannel config is used only when the caller set no config. A
|
||||
// caller's config applies to mono and multichannel render alike.
|
||||
let multichannel_config = match self.echo_canceller3_config {
|
||||
Some(_) => None,
|
||||
None => Some(EchoCanceller3Config::create_default_multichannel_config()),
|
||||
};
|
||||
|
||||
self.submodules.echo_controller = Some(EchoCanceller3::new(
|
||||
config,
|
||||
|
||||
Vendored
+4
-2
@@ -173,8 +173,7 @@ impl Default for HighPassFilter {
|
||||
/// Echo canceller (AEC3) settings.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EchoCanceller {
|
||||
/// Enforce the highpass filter to be on (default: true). Has no effect
|
||||
/// in mobile mode.
|
||||
/// Enforce the highpass filter to be on (default: true).
|
||||
pub enforce_high_pass_filtering: bool,
|
||||
/// Which transparent mode algorithm to use (default: `Legacy`).
|
||||
///
|
||||
@@ -195,6 +194,9 @@ impl Default for EchoCanceller {
|
||||
|
||||
pub use sonora_aec3::config::TransparentModeType;
|
||||
|
||||
/// Full AEC3 tuning, for [`AudioProcessingBuilder::echo_canceller3_config`](crate::AudioProcessingBuilder::echo_canceller3_config).
|
||||
pub use sonora_aec3::config::EchoCanceller3Config;
|
||||
|
||||
/// Background noise suppression settings.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct NoiseSuppression {
|
||||
|
||||
+640
@@ -0,0 +1,640 @@
|
||||
//! Scoped hardware flush-to-zero for the processing entry points.
|
||||
//!
|
||||
//! Mirrors WebRTC's `DenormalDisabler` (`rtc_base/denormal_disabler.{h,cc}`),
|
||||
//! which `AudioProcessingImpl` places at every stream entry point. Several
|
||||
//! recursive filters in the pipeline (the two-band QMF all-pass states, the
|
||||
//! AEC3 decimator biquads, the reverb models) never decay to zero on silent
|
||||
//! input under IEEE gradual underflow: they settle in a limit cycle a few
|
||||
//! ulps above zero, in the subnormal range. On x86 every arithmetic operation
|
||||
//! on a subnormal operand takes a microcode assist, which made AEC3 10-50x
|
||||
//! slower while the render reference was silent (issue #34). Upstream hides
|
||||
//! this with FTZ/DAZ; so does this guard.
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Sets hardware flush-to-zero for the current thread while alive.
|
||||
///
|
||||
/// - x86 / x86_64 with SSE: MXCSR.FTZ (bit 15) and MXCSR.DAZ (bit 6).
|
||||
/// - aarch64 with NEON: FPCR.FZ (bit 24), which flushes inputs and outputs.
|
||||
/// - Everything else is a no-op, including all 32-bit ARM targets
|
||||
/// (`armv7-linux-androideabi`), `arm64ec`, wasm32, i586 and Miri. Upstream
|
||||
/// also flushes on 32-bit ARM (FPSCR.FZ); this port does not yet.
|
||||
///
|
||||
/// Like upstream, the guard changes the register only if the bits are not
|
||||
/// already all set, and restores the saved word only if it changed it, so
|
||||
/// nested guards are harmless and a caller that already runs with FTZ keeps
|
||||
/// it.
|
||||
#[derive(Debug)]
|
||||
#[must_use = "denormals are only disabled while the guard is alive"]
|
||||
pub(crate) struct DenormalDisabler {
|
||||
/// Control word read by `new`; `Some` only if `new` changed the register.
|
||||
saved: Option<imp::Word>,
|
||||
/// FP control registers are per thread, so the guard is `!Send + !Sync`.
|
||||
_not_send: PhantomData<*const ()>,
|
||||
}
|
||||
|
||||
impl DenormalDisabler {
|
||||
/// Sets the flush-to-zero bits for the current thread.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// Rust assumes the default floating-point environment: RFC 3514 makes
|
||||
/// any change to it undefined behavior, and the `core::arch` MXCSR
|
||||
/// documentation calls a changed DAZ bit "immediate Undefined Behavior".
|
||||
/// Until the guard drops, everything that runs on this thread sees
|
||||
/// subnormal inputs and results as zero. That includes code sonora does
|
||||
/// not control: `tracing` subscribers, the global allocator and the panic
|
||||
/// hook (which runs before unwinding drops the guard). On Linux and other
|
||||
/// platforms where a new thread inherits the floating-point environment,
|
||||
/// a thread that such code starts before the guard drops keeps
|
||||
/// flush-to-zero for its whole life; `Drop` restores only this thread. A
|
||||
/// comparison with a subnormal operand can change its result (`x > 0.0`
|
||||
/// is false for `x = f32::from_bits(1)`). LLVM may also move float
|
||||
/// operations across the guard boundary: the `asm!` blocks order only
|
||||
/// memory the compiler cannot prove private, so arithmetic on values in
|
||||
/// registers, on the stack, or behind a `&` or `&mut` can run on either
|
||||
/// side. Compile-time float results can also differ from run-time ones
|
||||
/// in the subnormal range. The caller must run only code that tolerates
|
||||
/// all of this. The audio pipeline has no subnormal-sensitive logic, and
|
||||
/// upstream runs the same algorithms with the same bits set.
|
||||
#[inline]
|
||||
pub(crate) unsafe fn new() -> Self {
|
||||
#[cfg(test)]
|
||||
if tests::BYPASS.get() {
|
||||
return Self {
|
||||
saved: None,
|
||||
_not_send: PhantomData,
|
||||
};
|
||||
}
|
||||
let before = imp::read();
|
||||
let saved = if imp::denormals_enabled(before) {
|
||||
// SAFETY: the caller accepts the non-default FP environment (see
|
||||
// the function contract). The written word differs from `before`
|
||||
// only in the defined FTZ/DAZ bits.
|
||||
unsafe { imp::write(imp::with_ftz(before)) };
|
||||
Some(before)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Self {
|
||||
saved,
|
||||
_not_send: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if this target has a hardware flush-to-zero path.
|
||||
/// Mirrors upstream `DenormalDisabler::IsSupported()`.
|
||||
pub(crate) const fn is_supported() -> bool {
|
||||
imp::SUPPORTED
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for DenormalDisabler {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
if let Some(word) = self.saved {
|
||||
// SAFETY: restores the exact word read in `new`, on the same
|
||||
// thread (the guard is `!Send`), which returns the caller to its
|
||||
// own environment. Runs during unwinding too.
|
||||
unsafe { imp::write(word) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
not(miri),
|
||||
any(target_arch = "x86", target_arch = "x86_64"),
|
||||
target_feature = "sse"
|
||||
))]
|
||||
mod imp {
|
||||
use core::arch::asm;
|
||||
|
||||
pub(super) type Word = u32;
|
||||
pub(super) const SUPPORTED: bool = true;
|
||||
/// MXCSR.FTZ (bit 15) | MXCSR.DAZ (bit 6); upstream `kDenormalBitMask`.
|
||||
const MASK: Word = 0x8040;
|
||||
|
||||
pub(super) const fn denormals_enabled(word: Word) -> bool {
|
||||
word & MASK != MASK
|
||||
}
|
||||
|
||||
pub(super) const fn with_ftz(word: Word) -> Word {
|
||||
word | MASK
|
||||
}
|
||||
|
||||
/// Test-only: FTZ set and DAZ clear, a word the guard must still change
|
||||
/// and whose FTZ bit a sloppy restore would drop.
|
||||
#[cfg(test)]
|
||||
pub(super) const fn non_default_word(word: Word) -> Word {
|
||||
(word | 0x8000) & !0x0040
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(super) fn read() -> Word {
|
||||
let mut csr: Word = 0;
|
||||
// SAFETY: `stmxcsr` stores MXCSR into the 4 bytes at `p`, a live
|
||||
// local. It changes no register and no flag. Never `pure`: the value
|
||||
// depends on hidden state.
|
||||
unsafe {
|
||||
asm!(
|
||||
"stmxcsr [{p}]",
|
||||
p = in(reg) &raw mut csr,
|
||||
options(nostack, preserves_flags),
|
||||
);
|
||||
}
|
||||
csr
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// `csr` must be a word read by `read`, optionally with `MASK` set, and
|
||||
/// the caller must accept the resulting FP environment.
|
||||
#[inline(always)]
|
||||
pub(super) unsafe fn write(csr: Word) {
|
||||
// SAFETY: `ldmxcsr` reads the 4 bytes at `p`, a live local. It
|
||||
// rewrites the MXCSR exception flags, so `preserves_flags` is not
|
||||
// claimed. No `nomem`/`readonly`: the block also orders memory the
|
||||
// compiler cannot prove private (not data behind a `&mut`).
|
||||
unsafe {
|
||||
asm!("ldmxcsr [{p}]", p = in(reg) &raw const csr, options(nostack));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(not(miri), target_arch = "aarch64", target_feature = "neon"))]
|
||||
mod imp {
|
||||
use core::arch::asm;
|
||||
|
||||
pub(super) type Word = u64;
|
||||
pub(super) const SUPPORTED: bool = true;
|
||||
/// FPCR.FZ (bit 24).
|
||||
const MASK: Word = 1 << 24;
|
||||
|
||||
pub(super) const fn denormals_enabled(word: Word) -> bool {
|
||||
word & MASK != MASK
|
||||
}
|
||||
|
||||
pub(super) const fn with_ftz(word: Word) -> Word {
|
||||
word | MASK
|
||||
}
|
||||
|
||||
/// Test-only: FPCR.DN (bit 25) set, a bit the guard does not own and a
|
||||
/// restore to a fixed default word would drop. (Clearing FZ from the
|
||||
/// saved word cannot lose anything here: `new` saves only words with FZ
|
||||
/// clear.)
|
||||
#[cfg(test)]
|
||||
pub(super) const fn non_default_word(word: Word) -> Word {
|
||||
word | (1 << 25)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(super) fn read() -> Word {
|
||||
let fpcr: Word;
|
||||
// SAFETY: reads FPCR into a general register. FPCR holds no NZCV or
|
||||
// FPSR state, so no flag changes.
|
||||
unsafe {
|
||||
asm!("mrs {}, fpcr", out(reg) fpcr, options(nomem, nostack, preserves_flags));
|
||||
}
|
||||
fpcr
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// The caller must accept the resulting FP environment.
|
||||
#[inline(always)]
|
||||
pub(super) unsafe fn write(fpcr: Word) {
|
||||
// SAFETY: writes FPCR from a general register; NZCV and FPSR are
|
||||
// untouched. No `nomem`: the block also orders memory the compiler
|
||||
// cannot prove private (not data behind a `&mut`).
|
||||
unsafe {
|
||||
asm!("msr fpcr, {}", in(reg) fpcr, options(nostack, preserves_flags));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(
|
||||
all(
|
||||
not(miri),
|
||||
any(target_arch = "x86", target_arch = "x86_64"),
|
||||
target_feature = "sse"
|
||||
),
|
||||
all(not(miri), target_arch = "aarch64", target_feature = "neon"),
|
||||
)))]
|
||||
mod imp {
|
||||
// `u32`, not `()`: a unit word trips clippy `let_unit_value`/`unit_arg`.
|
||||
pub(super) type Word = u32;
|
||||
pub(super) const SUPPORTED: bool = false;
|
||||
|
||||
pub(super) const fn denormals_enabled(_word: Word) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub(super) const fn with_ftz(word: Word) -> Word {
|
||||
word
|
||||
}
|
||||
|
||||
/// Test-only: there is no register, so the word stays as it is.
|
||||
#[cfg(test)]
|
||||
pub(super) const fn non_default_word(word: Word) -> Word {
|
||||
word
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(super) fn read() -> Word {
|
||||
0
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// Always safe; `unsafe` only to match the supported variants.
|
||||
#[inline(always)]
|
||||
pub(super) unsafe fn write(_word: Word) {}
|
||||
}
|
||||
|
||||
// Every test whose result depends on the target asserts it against
|
||||
// `is_supported()` instead of skipping unsupported targets; the other tests
|
||||
// hold on every target. On a no-op target the tests therefore check that the
|
||||
// guard really is a no-op, nothing shows as passed without running, and the
|
||||
// target predicates exist only once (in `imp`).
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::cell::Cell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::f32::consts::PI;
|
||||
use std::hint::black_box;
|
||||
use std::panic;
|
||||
|
||||
use super::{DenormalDisabler, imp};
|
||||
use crate::config::EchoCanceller;
|
||||
use crate::{AudioProcessing, Config, StreamConfig};
|
||||
|
||||
thread_local! {
|
||||
/// Test-only: makes `DenormalDisabler::new` a no-op on this thread,
|
||||
/// so the regression test can run a control without the guard.
|
||||
pub(super) static BYPASS: Cell<bool> = const { Cell::new(false) };
|
||||
}
|
||||
|
||||
/// `MIN_POSITIVE / 123.125` is subnormal under IEEE and zero under FTZ.
|
||||
/// `black_box` keeps LLVM from folding it at compile time, where the FTZ
|
||||
/// bit is invisible.
|
||||
fn runtime_division_is_subnormal() -> bool {
|
||||
(black_box(f32::MIN_POSITIVE) / black_box(123.125f32)).is_subnormal()
|
||||
}
|
||||
|
||||
/// `2^-149 * 2^100` is `2^-49` (normal) under IEEE; DAZ reads the
|
||||
/// subnormal input as zero.
|
||||
fn subnormal_input_reads_as_zero() -> bool {
|
||||
black_box(f32::from_bits(1)) * black_box(2.0f32.powi(100)) == 0.0
|
||||
}
|
||||
|
||||
fn guard() -> DenormalDisabler {
|
||||
// SAFETY: test code; tolerates flushed subnormals.
|
||||
unsafe { DenormalDisabler::new() }
|
||||
}
|
||||
|
||||
/// Every test assumes it starts in Rust's default FP environment. If a
|
||||
/// platform starts threads with FTZ set, fail here, loudly, rather than
|
||||
/// in a confusing later assertion.
|
||||
fn assert_ieee_default() {
|
||||
assert!(
|
||||
runtime_division_is_subnormal() && !subnormal_input_reads_as_zero(),
|
||||
"precondition: the test thread must start in the IEEE default FP environment"
|
||||
);
|
||||
}
|
||||
|
||||
/// Upstream parity (`ZeroDenormals`): subnormal results become zero
|
||||
/// inside the guard. This is the FTZ half of the fix.
|
||||
#[test]
|
||||
fn guard_flushes_subnormal_results() {
|
||||
assert_ieee_default();
|
||||
let _g = guard();
|
||||
assert_eq!(
|
||||
!runtime_division_is_subnormal(),
|
||||
DenormalDisabler::is_supported()
|
||||
);
|
||||
}
|
||||
|
||||
/// Subnormal *inputs* must read as zero too (x86 DAZ; FPCR.FZ covers
|
||||
/// inputs on aarch64). Without DAZ, x86 still takes a microcode assist for
|
||||
/// every subnormal operand the caller feeds in; the FTZ test above cannot
|
||||
/// tell 0x8000 from 0x8040.
|
||||
#[test]
|
||||
fn guard_treats_subnormal_inputs_as_zero() {
|
||||
assert_ieee_default();
|
||||
let _g = guard();
|
||||
assert_eq!(
|
||||
subnormal_input_reads_as_zero(),
|
||||
DenormalDisabler::is_supported()
|
||||
);
|
||||
}
|
||||
|
||||
/// Upstream parity (`RestoreDenormalsEnabled`): a leaked FTZ bit would
|
||||
/// silently change the numerics of unrelated code on the caller's thread.
|
||||
#[test]
|
||||
fn guard_restores_caller_environment() {
|
||||
assert_ieee_default();
|
||||
{
|
||||
let _g = guard();
|
||||
}
|
||||
assert_ieee_default();
|
||||
}
|
||||
|
||||
/// The guard promises to restore the exact word it read: not the default
|
||||
/// word, and not that word with the flush bits cleared. From the default
|
||||
/// word all three are equal, so start from a word the guard must change
|
||||
/// and that a sloppy restore would lose: FTZ without DAZ on x86 (a caller
|
||||
/// that chose FTZ only), FPCR.DN on aarch64.
|
||||
#[test]
|
||||
fn guard_restores_non_default_word_exactly() {
|
||||
assert_ieee_default();
|
||||
let default = imp::read();
|
||||
let start = imp::non_default_word(default);
|
||||
// SAFETY: test code; tolerates flushed subnormals and default NaNs.
|
||||
// The default word is written back before any assertion can panic.
|
||||
unsafe { imp::write(start) };
|
||||
let inside = {
|
||||
let _g = guard();
|
||||
imp::read()
|
||||
};
|
||||
let after = imp::read();
|
||||
// SAFETY: as above; this is the word the thread started with.
|
||||
unsafe { imp::write(default) };
|
||||
assert_eq!(
|
||||
inside != start,
|
||||
DenormalDisabler::is_supported(),
|
||||
"guard did not change {start:#x}"
|
||||
);
|
||||
assert_eq!(after, start, "restored {after:#x}, expected {start:#x}");
|
||||
assert_ieee_default();
|
||||
}
|
||||
|
||||
/// Upstream's nesting rule: a nested guard, or a caller that already set
|
||||
/// FTZ, must keep the outer state after the inner guard drops.
|
||||
#[test]
|
||||
fn nested_guard_keeps_outer_state() {
|
||||
assert_ieee_default();
|
||||
let _outer = guard();
|
||||
{
|
||||
let _inner = guard();
|
||||
}
|
||||
assert_eq!(
|
||||
!runtime_division_is_subnormal(),
|
||||
DenormalDisabler::is_supported()
|
||||
);
|
||||
}
|
||||
|
||||
/// Upstream parity (`DoNotZeroInfNan`): FTZ must not touch Inf or NaN.
|
||||
#[test]
|
||||
fn guard_keeps_inf_and_nan() {
|
||||
assert_ieee_default();
|
||||
let _g = guard();
|
||||
assert!((black_box(f32::MAX) * black_box(2.0f32)).is_infinite());
|
||||
assert!(black_box(-1.0f32).sqrt().is_nan());
|
||||
}
|
||||
|
||||
/// The C API catches panics and the caller's thread carries on, so the
|
||||
/// environment must be restored during unwinding as well.
|
||||
#[test]
|
||||
fn guard_restores_on_unwind() {
|
||||
assert_ieee_default();
|
||||
let r = panic::catch_unwind(|| {
|
||||
let _g = guard();
|
||||
panic!("unwind through the guard");
|
||||
});
|
||||
assert!(r.is_err());
|
||||
assert_ieee_default();
|
||||
}
|
||||
|
||||
fn ec_48k_mono() -> AudioProcessing {
|
||||
let config = Config {
|
||||
echo_canceller: Some(EchoCanceller::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let stream = StreamConfig::new(48_000, 1);
|
||||
AudioProcessing::builder()
|
||||
.config(config)
|
||||
.capture_config(stream)
|
||||
.render_config(stream)
|
||||
.build()
|
||||
}
|
||||
|
||||
/// Calls each public processing entry point once and returns after each
|
||||
/// call so the caller can inspect the thread's FP environment.
|
||||
fn for_each_process_call(apm: &mut AudioProcessing, mut check: impl FnMut(&str)) {
|
||||
let n = 480;
|
||||
let src = vec![0.01f32; n];
|
||||
let mut dst = vec![0.0f32; n];
|
||||
let src_i16 = vec![100i16; n];
|
||||
let mut dst_i16 = vec![0i16; n];
|
||||
apm.process_render_f32(&[&src], &mut [&mut dst]).unwrap();
|
||||
check("process_render_f32");
|
||||
apm.process_capture_f32(&[&src], &mut [&mut dst]).unwrap();
|
||||
check("process_capture_f32");
|
||||
apm.process_render_i16(&src_i16, &mut dst_i16).unwrap();
|
||||
check("process_render_i16");
|
||||
apm.process_capture_i16(&src_i16, &mut dst_i16).unwrap();
|
||||
check("process_capture_i16");
|
||||
}
|
||||
|
||||
/// sonora must hand the caller's thread back in the environment it
|
||||
/// found, through the real API: IEEE for a default caller, and FTZ kept
|
||||
/// for a caller (such as a DAW audio thread) that already set it.
|
||||
#[test]
|
||||
fn process_calls_leave_caller_environment_unchanged() {
|
||||
assert_ieee_default();
|
||||
let mut apm = ec_48k_mono();
|
||||
for_each_process_call(&mut apm, |call| {
|
||||
assert!(runtime_division_is_subnormal(), "{call} leaked FTZ");
|
||||
assert!(!subnormal_input_reads_as_zero(), "{call} leaked DAZ");
|
||||
});
|
||||
let _caller_ftz = guard();
|
||||
for_each_process_call(&mut apm, |call| {
|
||||
assert_eq!(
|
||||
!runtime_division_is_subnormal(),
|
||||
DenormalDisabler::is_supported(),
|
||||
"{call} cleared the caller's FTZ"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Counts nonzero values below `f32::MIN_POSITIVE` per state field in the
|
||||
/// pretty `Debug` dump of the whole processor (every state struct derives
|
||||
/// `Debug`). Keys are the field path, e.g.
|
||||
/// `inner.render.render_audio.splitting_filter.state.analysis_state1`.
|
||||
///
|
||||
/// The scan cannot tell `f32` from `f64` fields, so it also counts `f64`
|
||||
/// values below that bound (normal `f64`s, untouched by FTZ), and some
|
||||
/// state is `f64`, such as `echo_return_loss` in the stored statistics.
|
||||
/// That can only add counts: it can fail the guarded run, with the field
|
||||
/// named in the message, but cannot hide an `f32` subnormal.
|
||||
fn subnormals_by_field(apm: &AudioProcessing) -> BTreeMap<String, usize> {
|
||||
let dump = format!("{apm:#?}");
|
||||
let mut stack: Vec<Option<&str>> = Vec::new();
|
||||
let mut counts = BTreeMap::new();
|
||||
for line in dump.lines() {
|
||||
let body = line.trim_start();
|
||||
stack.truncate((line.len() - body.len()) / 4);
|
||||
let field = body.split_once(": ").map(|(name, _)| name).filter(|name| {
|
||||
name.starts_with(|c: char| c.is_ascii_alphabetic() || c == '_')
|
||||
&& name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')
|
||||
});
|
||||
stack.push(field);
|
||||
let n = body
|
||||
.split(|c: char| !(c.is_ascii_digit() || matches!(c, '.' | 'e' | 'E' | '-' | '+')))
|
||||
.filter_map(|t| t.parse::<f64>().ok())
|
||||
.filter(|v| *v != 0.0 && v.abs() < f64::from(f32::MIN_POSITIVE))
|
||||
.count();
|
||||
if n > 0 {
|
||||
let key: Vec<&str> = stack.iter().flatten().copied().collect();
|
||||
*counts.entry(key.join(".")).or_insert(0) += n;
|
||||
}
|
||||
}
|
||||
counts
|
||||
}
|
||||
|
||||
/// Deterministic speech-like source: LCG noise with a 4 Hz envelope.
|
||||
fn speech_like(frame: usize, n: usize, out: &mut [f32]) {
|
||||
let mut seed = (frame as u32).wrapping_mul(2_654_435_761).wrapping_add(1);
|
||||
for (i, s) in out.iter_mut().enumerate().take(n) {
|
||||
seed = seed.wrapping_mul(1_664_525).wrapping_add(1_013_904_223);
|
||||
let noise = (seed >> 8) as f32 / (1u32 << 24) as f32 - 0.5;
|
||||
let t = (frame * n + i) as f32 / 48_000.0;
|
||||
let env = 0.5 + 0.5 * (2.0 * PI * 4.0 * t).sin();
|
||||
*s = 0.2 * env * noise;
|
||||
}
|
||||
}
|
||||
|
||||
/// Frames (10 ms) of 1 s speech-like render and echo.
|
||||
const SPEECH_END: usize = 100;
|
||||
/// Then exact-zero render (the reported case) with capture noise at about
|
||||
/// -75 dBFS RMS and -66 dBFS peak, until checkpoint A.
|
||||
const CHECKPOINT_A: usize = 300;
|
||||
/// Then exact-zero render and capture, until checkpoint B. The latest
|
||||
/// onset in the control (`y2_smoothed`, about frame 650) leaves a margin
|
||||
/// of 150 frames; keep one if either moves.
|
||||
const CHECKPOINT_B: usize = 800;
|
||||
|
||||
/// Runs the issue #34 scenario through the f32 or i16 API and returns the
|
||||
/// subnormal state per field at checkpoints A and B.
|
||||
fn silent_render_scenario(use_i16: bool) -> [BTreeMap<String, usize>; 2] {
|
||||
let mut apm = ec_48k_mono();
|
||||
let n = 480;
|
||||
let mut render = vec![0.0f32; n];
|
||||
let mut capture = vec![0.0f32; n];
|
||||
let mut out = vec![0.0f32; n];
|
||||
let mut render_out = vec![0.0f32; n];
|
||||
let mut out_i16 = vec![0i16; n];
|
||||
let to_i16 = |x: &[f32]| -> Vec<i16> { x.iter().map(|v| (v * 32767.0) as i16).collect() };
|
||||
let mut checkpoint_a = BTreeMap::new();
|
||||
for frame in 0..CHECKPOINT_B {
|
||||
if frame < SPEECH_END {
|
||||
speech_like(frame, n, &mut render);
|
||||
for (c, r) in capture.iter_mut().zip(&render) {
|
||||
*c = 0.5 * r;
|
||||
}
|
||||
} else if frame < CHECKPOINT_A {
|
||||
render.fill(0.0);
|
||||
speech_like(frame, n, &mut capture);
|
||||
for c in &mut capture {
|
||||
*c *= 0.005;
|
||||
}
|
||||
} else {
|
||||
render.fill(0.0);
|
||||
capture.fill(0.0);
|
||||
}
|
||||
if use_i16 {
|
||||
apm.process_render_i16(&to_i16(&render), &mut out_i16)
|
||||
.unwrap();
|
||||
apm.process_capture_i16(&to_i16(&capture), &mut out_i16)
|
||||
.unwrap();
|
||||
} else {
|
||||
apm.process_render_f32(&[&render], &mut [&mut render_out])
|
||||
.unwrap();
|
||||
apm.process_capture_f32(&[&capture], &mut [&mut out])
|
||||
.unwrap();
|
||||
}
|
||||
if frame + 1 == CHECKPOINT_A {
|
||||
checkpoint_a = subnormals_by_field(&apm);
|
||||
}
|
||||
}
|
||||
[checkpoint_a, subnormals_by_field(&apm)]
|
||||
}
|
||||
|
||||
/// Recursive states that settle in the subnormal range without the guard,
|
||||
/// with the checkpoint by which each must hold a subnormal in the control
|
||||
/// run. The control proves the scenario still reaches every known source;
|
||||
/// without it, a scenario that stopped producing subnormals would pass.
|
||||
const SOURCES: &[(usize, &str)] = &[
|
||||
// Render side, reached in the reported case (onset about frame 110-140).
|
||||
(
|
||||
CHECKPOINT_A,
|
||||
"render_audio.splitting_filter.state.analysis_state1",
|
||||
),
|
||||
(
|
||||
CHECKPOINT_A,
|
||||
"render_audio.splitting_filter.state.synthesis_state1",
|
||||
),
|
||||
(
|
||||
CHECKPOINT_A,
|
||||
"render_decimator.anti_aliasing_filter.biquads.y",
|
||||
),
|
||||
(
|
||||
CHECKPOINT_A,
|
||||
"render_decimator.noise_reduction_filter.biquads.y",
|
||||
),
|
||||
// Slower render-driven smoothers (onset about frame 330 and 500).
|
||||
(CHECKPOINT_B, "aec_state.avg_render_reverb.reverb"),
|
||||
(CHECKPOINT_B, "residual_echo_estimator.echo_reverb.reverb"),
|
||||
(CHECKPOINT_B, "low_render_detector.average_power"),
|
||||
// Capture side, once capture is exact zero too (onset about 310-650).
|
||||
(
|
||||
CHECKPOINT_B,
|
||||
"capture_audio.splitting_filter.state.analysis_state1",
|
||||
),
|
||||
(
|
||||
CHECKPOINT_B,
|
||||
"capture_audio.splitting_filter.state.synthesis_state1",
|
||||
),
|
||||
(CHECKPOINT_B, "high_pass_filter.filters.biquads.y"),
|
||||
(
|
||||
CHECKPOINT_B,
|
||||
"capture_decimator.anti_aliasing_filter.biquads.y",
|
||||
),
|
||||
(CHECKPOINT_B, "echo_remover.cng.y2_smoothed"),
|
||||
];
|
||||
|
||||
/// Issue #34. After the render reference goes silent, the pipeline's
|
||||
/// recursive filters (QMF all-pass, decimator and high-pass biquads,
|
||||
/// reverb models, smoothers) settle a few ulps above zero under IEEE
|
||||
/// gradual underflow and never reach zero, so every later frame computes
|
||||
/// on subnormals: a microcode assist per operation on x86. With the guard
|
||||
/// in every `process_*` entry point, no subnormal may survive in any
|
||||
/// state. Deterministic, no timing, so it runs on real x86_64 in CI.
|
||||
#[test]
|
||||
fn silent_render_leaves_no_subnormal_state() {
|
||||
assert_ieee_default();
|
||||
BYPASS.set(true);
|
||||
let control = silent_render_scenario(false);
|
||||
BYPASS.set(false);
|
||||
for &(checkpoint, source) in SOURCES {
|
||||
let at = &control[usize::from(checkpoint == CHECKPOINT_B)];
|
||||
assert!(
|
||||
at.iter().any(|(k, &v)| k.ends_with(source) && v > 0),
|
||||
"control: scenario no longer drives {source} subnormal by frame {checkpoint}"
|
||||
);
|
||||
}
|
||||
for use_i16 in [false, true] {
|
||||
for (at, checkpoint) in silent_render_scenario(use_i16)
|
||||
.iter()
|
||||
.zip([CHECKPOINT_A, CHECKPOINT_B])
|
||||
{
|
||||
let total: usize = at.values().sum();
|
||||
assert_eq!(
|
||||
total == 0,
|
||||
DenormalDisabler::is_supported(),
|
||||
"{total} subnormal state values at frame {checkpoint} (i16 API: {use_i16}): {at:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-15
@@ -560,15 +560,11 @@ impl EchoCanceller3 {
|
||||
&mut self.capture_sub_frame_view,
|
||||
);
|
||||
|
||||
// Convert sub-frame slices to the format FrameBlocker expects.
|
||||
let sub_frame_refs: Vec<Vec<&[f32]>> = self
|
||||
.capture_sub_frame_view
|
||||
.iter()
|
||||
.map(|band| band.iter().map(|ch| ch.as_slice()).collect())
|
||||
.collect();
|
||||
|
||||
self.capture_blocker
|
||||
.insert_sub_frame_and_extract_block(&sub_frame_refs, &mut self.capture_block);
|
||||
.insert_owned_sub_frame_and_extract_block(
|
||||
&self.capture_sub_frame_view,
|
||||
&mut self.capture_block,
|
||||
);
|
||||
|
||||
// Process through block processor.
|
||||
let echo_path_gain_change = level_change || aec_reference_is_downmixed_stereo;
|
||||
@@ -679,14 +675,11 @@ impl EchoCanceller3 {
|
||||
&mut self.render_sub_frame_view,
|
||||
);
|
||||
|
||||
let sub_frame_refs: Vec<Vec<&[f32]>> = self
|
||||
.render_sub_frame_view
|
||||
.iter()
|
||||
.map(|band| band.iter().map(|ch| ch.as_slice()).collect())
|
||||
.collect();
|
||||
|
||||
self.render_blocker
|
||||
.insert_sub_frame_and_extract_block(&sub_frame_refs, &mut self.render_block);
|
||||
.insert_owned_sub_frame_and_extract_block(
|
||||
&self.render_sub_frame_view,
|
||||
&mut self.render_block,
|
||||
);
|
||||
self.block_processor.buffer_render(&self.render_block);
|
||||
}
|
||||
|
||||
|
||||
+29
-24
@@ -104,11 +104,14 @@ fn compute_audio_levels(audio: &AudioBuffer) -> AudioLevels {
|
||||
}
|
||||
}
|
||||
|
||||
/// Copies channel data out of an AudioBuffer for use with `&mut [&mut [f32]]` APIs.
|
||||
fn extract_channels(audio: &AudioBuffer) -> Vec<Vec<f32>> {
|
||||
(0..audio.num_channels())
|
||||
.map(|ch| audio.channel(ch).to_vec())
|
||||
.collect()
|
||||
/// Copies the channels of `audio` into `channel_data`, reusing its buffers:
|
||||
/// once they have grown to the frame size, this does not allocate.
|
||||
fn copy_channels(audio: &AudioBuffer, channel_data: &mut Vec<Vec<f32>>) {
|
||||
channel_data.resize_with(audio.num_channels(), Vec::new);
|
||||
for (ch, data) in channel_data.iter_mut().enumerate() {
|
||||
data.clear();
|
||||
data.extend_from_slice(audio.channel(ch));
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes channel data back into an AudioBuffer.
|
||||
@@ -132,6 +135,9 @@ pub(crate) struct GainController2 {
|
||||
adaptive_digital_controller: Option<AdaptiveDigitalGainController>,
|
||||
limiter: Limiter,
|
||||
recommended_input_volume: Option<i32>,
|
||||
/// Reusable frame buffers for the upstream multichannel path. Mono borrows
|
||||
/// the existing audio channel without allocating or copying these buffers.
|
||||
channel_data: Vec<Vec<f32>>,
|
||||
}
|
||||
|
||||
impl GainController2 {
|
||||
@@ -201,6 +207,13 @@ impl GainController2 {
|
||||
adaptive_digital_controller,
|
||||
limiter: Limiter::new(samples_per_channel),
|
||||
recommended_input_volume: None,
|
||||
channel_data: if num_channels == 1 {
|
||||
Vec::new()
|
||||
} else {
|
||||
(0..num_channels)
|
||||
.map(|_| Vec::with_capacity(samples_per_channel))
|
||||
.collect()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,14 +271,17 @@ impl GainController2 {
|
||||
// Compute audio levels from the first channel.
|
||||
let audio_levels = compute_audio_levels(audio);
|
||||
|
||||
// Mono capture borrows its channel directly; multichannel reuses upstream buffers.
|
||||
if audio.num_channels() != 1 {
|
||||
copy_channels(audio, &mut self.channel_data);
|
||||
}
|
||||
|
||||
// Noise level estimation.
|
||||
let noise_rms_dbfs = if let Some(ref mut nle) = self.noise_level_estimator {
|
||||
if audio.num_channels() == 1 {
|
||||
Some(nle.analyze(&[audio.channel(0)]))
|
||||
} else {
|
||||
let num_ch = audio.num_channels();
|
||||
let channels: Vec<&[f32]> = (0..num_ch).map(|ch| audio.channel(ch)).collect();
|
||||
Some(nle.analyze(&channels))
|
||||
Some(nle.analyze_owned_frame(&self.channel_data))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
@@ -311,15 +327,10 @@ impl GainController2 {
|
||||
limiter_envelope_dbfs,
|
||||
};
|
||||
|
||||
// Mono capture borrows the existing channel; no sample/descriptor Vec is needed.
|
||||
if audio.num_channels() == 1 {
|
||||
adc.process(&info, &mut [audio.channel_mut(0)]);
|
||||
} else {
|
||||
let mut channel_data = extract_channels(audio);
|
||||
let mut channel_slices: Vec<&mut [f32]> =
|
||||
channel_data.iter_mut().map(|v| v.as_mut_slice()).collect();
|
||||
adc.process(&info, &mut channel_slices);
|
||||
write_back_channels(audio, &channel_data);
|
||||
adc.process_owned_frame(&info, &mut self.channel_data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,22 +338,16 @@ impl GainController2 {
|
||||
if audio.num_channels() == 1 {
|
||||
self.fixed_gain_applier.apply_gain(&mut [audio.channel_mut(0)]);
|
||||
} else {
|
||||
let mut channel_data = extract_channels(audio);
|
||||
let mut channel_slices: Vec<&mut [f32]> =
|
||||
channel_data.iter_mut().map(|v| v.as_mut_slice()).collect();
|
||||
self.fixed_gain_applier.apply_gain(&mut channel_slices);
|
||||
write_back_channels(audio, &channel_data);
|
||||
self.fixed_gain_applier
|
||||
.apply_gain_to_owned_signal(&mut self.channel_data);
|
||||
}
|
||||
|
||||
// Limiter.
|
||||
if audio.num_channels() == 1 {
|
||||
self.limiter.process(&mut [audio.channel_mut(0)]);
|
||||
} else {
|
||||
let mut channel_data = extract_channels(audio);
|
||||
let mut channel_slices: Vec<&mut [f32]> =
|
||||
channel_data.iter_mut().map(|v| v.as_mut_slice()).collect();
|
||||
self.limiter.process(&mut channel_slices);
|
||||
write_back_channels(audio, &channel_data);
|
||||
self.limiter.process_owned_signal(&mut self.channel_data);
|
||||
write_back_channels(audio, &self.channel_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+140
-25
@@ -116,6 +116,9 @@ pub(crate) struct InputVolumeControllerConfig {
|
||||
pub speech_ratio_threshold: f32,
|
||||
}
|
||||
|
||||
/// Upstream's production `InputVolumeController::Config{}` (upstream commit
|
||||
/// d9b92fe1bc), which C++ `AudioProcessingImpl::InitializeGainController2()`
|
||||
/// passes to the controller.
|
||||
impl Default for InputVolumeControllerConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -124,12 +127,12 @@ impl Default for InputVolumeControllerConfig {
|
||||
clipped_level_step: 15,
|
||||
clipped_ratio_threshold: 0.1,
|
||||
clipped_wait_frames: 300,
|
||||
enable_clipping_predictor: false,
|
||||
target_range_max_dbfs: -18,
|
||||
target_range_min_dbfs: -30,
|
||||
update_input_volume_wait_frames: 0,
|
||||
speech_probability_threshold: 0.5,
|
||||
speech_ratio_threshold: 0.8,
|
||||
enable_clipping_predictor: true,
|
||||
target_range_max_dbfs: -12,
|
||||
target_range_min_dbfs: -50,
|
||||
update_input_volume_wait_frames: 100,
|
||||
speech_probability_threshold: 0.7,
|
||||
speech_ratio_threshold: 0.6,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1413,12 +1416,124 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The APM pipeline builds the controller from
|
||||
/// `InputVolumeControllerConfig::default()`, just as C++ APM builds it from
|
||||
/// `InputVolumeController::Config{}`. Any difference between the two
|
||||
/// changes `recommended_stream_analog_level()` relative to C++. The Rust
|
||||
/// default once drifted to test-like values (target range [-30, -18]
|
||||
/// dBFS, no clipping predictor, no update wait), so this test pins every
|
||||
/// field to upstream's production values in
|
||||
/// `modules/audio_processing/agc2/input_volume_controller.h` at upstream
|
||||
/// commit d9b92fe1bc ("Make max target input level for input controller
|
||||
/// -12dB").
|
||||
#[test]
|
||||
fn default_config_matches_upstream_production_config() {
|
||||
let config = InputVolumeControllerConfig::default();
|
||||
assert_eq!(config.min_input_volume, 20);
|
||||
assert_eq!(config.clipped_level_min, 70);
|
||||
assert_eq!(config.clipped_level_step, 15);
|
||||
assert_eq!(config.clipped_ratio_threshold, 0.1);
|
||||
assert_eq!(config.clipped_wait_frames, 300);
|
||||
assert!(config.enable_clipping_predictor);
|
||||
// d9b92fe1bc raised this from -30 (M145) to the former experimental
|
||||
// value of -12 and removed `target_range_experimental_max_dbfs`.
|
||||
assert_eq!(config.target_range_max_dbfs, -12);
|
||||
assert_eq!(config.target_range_min_dbfs, -50);
|
||||
assert_eq!(config.update_input_volume_wait_frames, 100);
|
||||
assert_eq!(config.speech_probability_threshold, 0.7);
|
||||
assert_eq!(config.speech_ratio_threshold, 0.6);
|
||||
}
|
||||
|
||||
/// Port of upstream `InputVolumeControllerChannelSampleRateTest.CheckIsAlive`.
|
||||
/// Upstream's `Config{.enable_clipping_predictor = true}` equals the
|
||||
/// production default, so this checks that the default config lowers the
|
||||
/// volume on clipping, raises it below the target range, and lowers it
|
||||
/// above the target range.
|
||||
#[test]
|
||||
fn check_is_alive() {
|
||||
for num_channels in [1, 2, 3, 6] {
|
||||
for sample_rate_hz in [8000, 16000, 32000, 48000] {
|
||||
let case = format!("num_channels={num_channels}, sample_rate_hz={sample_rate_hz}");
|
||||
let config = InputVolumeControllerConfig {
|
||||
enable_clipping_predictor: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut controller = InputVolumeController::new(num_channels, &config);
|
||||
controller.initialize();
|
||||
let mut buffer = AudioBuffer::new(
|
||||
sample_rate_hz,
|
||||
num_channels,
|
||||
sample_rate_hz,
|
||||
num_channels,
|
||||
sample_rate_hz,
|
||||
);
|
||||
|
||||
const STARTUP_VOLUME: i32 = 100;
|
||||
let mut applied_input_volume = STARTUP_VOLUME;
|
||||
|
||||
// Trigger a downward adaptation with clipping.
|
||||
let level_within_target_dbfs =
|
||||
(config.target_range_min_dbfs + config.target_range_max_dbfs) / 2;
|
||||
write_alternating_audio_buffer_samples(MAX_SAMPLE, &mut buffer);
|
||||
let initial_volume_1 = applied_input_volume;
|
||||
for _ in 0..400 {
|
||||
controller.analyze_input_audio(applied_input_volume, &buffer);
|
||||
applied_input_volume = controller
|
||||
.recommend_input_volume(
|
||||
LOW_SPEECH_PROBABILITY,
|
||||
Some(level_within_target_dbfs as f32),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
assert!(
|
||||
controller.recommended_input_volume() < initial_volume_1,
|
||||
"{case}"
|
||||
);
|
||||
|
||||
// Fill in audio that does not clip.
|
||||
write_alternating_audio_buffer_samples(1234.5, &mut buffer);
|
||||
|
||||
// Trigger an upward adaptation.
|
||||
let initial_volume_2 = controller.recommended_input_volume();
|
||||
for _ in 0..config.clipped_wait_frames {
|
||||
controller.analyze_input_audio(applied_input_volume, &buffer);
|
||||
applied_input_volume = controller
|
||||
.recommend_input_volume(
|
||||
HIGH_SPEECH_PROBABILITY,
|
||||
Some((config.target_range_min_dbfs - 5) as f32),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
assert!(
|
||||
controller.recommended_input_volume() > initial_volume_2,
|
||||
"{case}"
|
||||
);
|
||||
|
||||
// Trigger a downward adaptation.
|
||||
let initial_volume = controller.recommended_input_volume();
|
||||
for _ in 0..config.update_input_volume_wait_frames {
|
||||
controller.analyze_input_audio(applied_input_volume, &buffer);
|
||||
applied_input_volume = controller
|
||||
.recommend_input_volume(
|
||||
HIGH_SPEECH_PROBABILITY,
|
||||
Some((config.target_range_max_dbfs + 5) as f32),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
assert!(
|
||||
controller.recommended_input_volume() < initial_volume,
|
||||
"{case}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn startup_min_volume_configuration_respected_when_applied_input_volume_above_min() {
|
||||
for min_input_volume in [12, 20] {
|
||||
let mut helper = TestHelper::new(InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
});
|
||||
|
||||
assert_eq!(helper.call_agc_sequence(128, 0.9, -80.0, 1).unwrap(), 128);
|
||||
@@ -1430,7 +1545,7 @@ mod tests {
|
||||
for min_input_volume in [12, 20] {
|
||||
let mut helper = TestHelper::new(InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
});
|
||||
|
||||
assert!(helper.call_agc_sequence(10, 0.9, -80.0, 1).unwrap() >= 10);
|
||||
@@ -1446,7 +1561,7 @@ mod tests {
|
||||
update_input_volume_wait_frames: 1,
|
||||
speech_probability_threshold: 0.5,
|
||||
speech_ratio_threshold: 0.5,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
});
|
||||
|
||||
let volume = helper.call_agc_sequence(1, 0.9, -80.0, 1).unwrap();
|
||||
@@ -1463,7 +1578,7 @@ mod tests {
|
||||
update_input_volume_wait_frames: 1,
|
||||
speech_probability_threshold: 0.5,
|
||||
speech_ratio_threshold: 0.5,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
});
|
||||
|
||||
for _ in 0..100 {
|
||||
@@ -1482,7 +1597,7 @@ mod tests {
|
||||
update_input_volume_wait_frames: 1,
|
||||
speech_probability_threshold: 0.5,
|
||||
speech_ratio_threshold: 0.5,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
});
|
||||
|
||||
let volume = helper.call_agc_sequence(0, 0.9, -80.0, 1).unwrap();
|
||||
@@ -1595,7 +1710,7 @@ mod tests {
|
||||
for min_input_volume in [12, 20] {
|
||||
let config = InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
};
|
||||
let mut helper_1 = TestHelper::new(config.clone());
|
||||
let mut helper_2 = TestHelper::new(config);
|
||||
@@ -1632,7 +1747,7 @@ mod tests {
|
||||
for min_input_volume in [12, 20] {
|
||||
let config = InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
};
|
||||
let mut helper = TestHelper::new(config);
|
||||
helper.call_agc_sequence(
|
||||
@@ -1663,7 +1778,7 @@ mod tests {
|
||||
for min_input_volume in [12, 20] {
|
||||
let config = InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
};
|
||||
let mut helper = TestHelper::new(config);
|
||||
helper.call_agc_sequence(
|
||||
@@ -1694,7 +1809,7 @@ mod tests {
|
||||
for min_input_volume in [12, 20] {
|
||||
let config = InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
};
|
||||
let mut helper = TestHelper::new(config);
|
||||
helper.call_agc_sequence(
|
||||
@@ -1714,7 +1829,7 @@ mod tests {
|
||||
for min_input_volume in [12, 20] {
|
||||
let config = InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
};
|
||||
let mut helper = TestHelper::new(config);
|
||||
helper.call_agc_sequence(
|
||||
@@ -1734,7 +1849,7 @@ mod tests {
|
||||
for min_input_volume in [12, 20] {
|
||||
let config = InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
};
|
||||
let mut helper = TestHelper::new(config);
|
||||
helper.call_agc_sequence(255, HIGH_SPEECH_PROBABILITY, SPEECH_LEVEL, 1);
|
||||
@@ -1749,7 +1864,7 @@ mod tests {
|
||||
for min_input_volume in [12, 20] {
|
||||
let config = InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
};
|
||||
let mut helper = TestHelper::new(config);
|
||||
helper.call_agc_sequence(255, HIGH_SPEECH_PROBABILITY, SPEECH_LEVEL, 1);
|
||||
@@ -1788,7 +1903,7 @@ mod tests {
|
||||
clipped_level_step: CLIPPED_LEVEL_STEP,
|
||||
clipped_ratio_threshold: CLIPPED_RATIO_THRESHOLD,
|
||||
clipped_wait_frames: CLIPPED_WAIT_FRAMES,
|
||||
..Default::default()
|
||||
..get_test_config()
|
||||
};
|
||||
let mut controller = InputVolumeController::new(1, &config);
|
||||
controller.initialize();
|
||||
@@ -1800,7 +1915,7 @@ mod tests {
|
||||
clipped_level_step: 10,
|
||||
clipped_ratio_threshold: 0.2,
|
||||
clipped_wait_frames: 50,
|
||||
..Default::default()
|
||||
..get_test_config()
|
||||
};
|
||||
let mut controller_custom = InputVolumeController::new(1, &config_custom);
|
||||
controller_custom.initialize();
|
||||
@@ -1818,7 +1933,7 @@ mod tests {
|
||||
clipped_ratio_threshold: CLIPPED_RATIO_THRESHOLD,
|
||||
clipped_wait_frames: CLIPPED_WAIT_FRAMES,
|
||||
enable_clipping_predictor: false,
|
||||
..Default::default()
|
||||
..get_test_config()
|
||||
};
|
||||
let mut controller = InputVolumeController::new(1, &config);
|
||||
controller.initialize();
|
||||
@@ -1836,7 +1951,7 @@ mod tests {
|
||||
clipped_ratio_threshold: CLIPPED_RATIO_THRESHOLD,
|
||||
clipped_wait_frames: CLIPPED_WAIT_FRAMES,
|
||||
enable_clipping_predictor: true,
|
||||
..Default::default()
|
||||
..get_test_config()
|
||||
};
|
||||
let mut controller = InputVolumeController::new(1, &config);
|
||||
controller.initialize();
|
||||
@@ -1851,7 +1966,7 @@ mod tests {
|
||||
for min_input_volume in [12, 20] {
|
||||
let config = InputVolumeControllerConfig {
|
||||
min_input_volume,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
};
|
||||
let mut helper = TestHelper::new(config);
|
||||
helper.call_agc_sequence(
|
||||
@@ -1887,7 +2002,7 @@ mod tests {
|
||||
let mut helper = TestHelper::new(InputVolumeControllerConfig {
|
||||
min_input_volume: 80,
|
||||
clipped_level_min: 70,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
});
|
||||
|
||||
write_audio_buffer_samples(4000.0, 0.8, &mut helper.audio_buffer);
|
||||
@@ -1902,7 +2017,7 @@ mod tests {
|
||||
let mut helper = TestHelper::new(InputVolumeControllerConfig {
|
||||
min_input_volume: 70,
|
||||
clipped_level_min: 80,
|
||||
..get_test_config()
|
||||
..InputVolumeControllerConfig::default()
|
||||
});
|
||||
|
||||
write_audio_buffer_samples(4000.0, 0.8, &mut helper.audio_buffer);
|
||||
|
||||
Vendored
+1
@@ -7,6 +7,7 @@ pub(crate) mod audio_processing_impl;
|
||||
pub(crate) mod audio_samples_scaler;
|
||||
pub(crate) mod capture_levels_adjuster;
|
||||
pub(crate) mod config_selector;
|
||||
pub(crate) mod denormal_disabler;
|
||||
pub(crate) mod echo_canceller3;
|
||||
pub(crate) mod echo_detector;
|
||||
pub(crate) mod gain_controller2;
|
||||
|
||||
+175
-17
@@ -5,6 +5,8 @@
|
||||
//!
|
||||
//! Ported from `modules/audio_processing/three_band_filter_bank.h/cc`.
|
||||
|
||||
use sonora_simd::NATIVE_FMA;
|
||||
|
||||
const SQRT_3: f32 = 1.732_050_8;
|
||||
|
||||
const SPARSITY: usize = 4;
|
||||
@@ -57,8 +59,20 @@ const DCT_MODULATION: [[f32; NUM_BANDS]; NUM_NON_ZERO_FILTERS] = [
|
||||
/// Polyphase filter core: filters `input` through `filter` with shift `in_shift`,
|
||||
/// using and updating `state`.
|
||||
///
|
||||
/// If `FMA`, the unrolled 4-tap sums of Parts 1 and 3 use [`f32::mul_add`];
|
||||
/// otherwise they use plain arithmetic, in the C++ operation order. C++ starts
|
||||
/// that sum from `0.0`; leaving it out changes only the sign of an all-zero
|
||||
/// sum, which `analysis` and `synthesis` lose when they add the result into
|
||||
/// zeroed buffers. The public methods pass [`NATIVE_FMA`]; the tests run both
|
||||
/// forms.
|
||||
///
|
||||
/// Direct port of C++ `FilterCore` in `three_band_filter_bank.cc`.
|
||||
fn filter_core(
|
||||
// LLVM's inline cost for this body sits at its threshold, so without
|
||||
// `inline(always)` whether `analysis` and `synthesis` inline it depends on
|
||||
// the codegen-unit partition (with Cargo's default 16 units it did on
|
||||
// aarch64 and did not on x86_64).
|
||||
#[inline(always)]
|
||||
fn filter_core<const FMA: bool>(
|
||||
filter: &[f32; FILTER_SIZE],
|
||||
input: &[f32; SPLIT_BAND_SIZE],
|
||||
in_shift: usize,
|
||||
@@ -79,13 +93,20 @@ fn filter_core(
|
||||
#[allow(clippy::needless_range_loop, reason = "index used in arithmetic")]
|
||||
for k in 0..in_shift {
|
||||
let j = MEMORY_SIZE + k - in_shift;
|
||||
output[k] = f0.mul_add(
|
||||
state[j],
|
||||
f1.mul_add(
|
||||
state[j - STRIDE],
|
||||
f2.mul_add(state[j - 2 * STRIDE], f3 * state[j - 3 * STRIDE]),
|
||||
),
|
||||
);
|
||||
output[k] = if FMA {
|
||||
f0.mul_add(
|
||||
state[j],
|
||||
f1.mul_add(
|
||||
state[j - STRIDE],
|
||||
f2.mul_add(state[j - 2 * STRIDE], f3 * state[j - 3 * STRIDE]),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
f0 * state[j]
|
||||
+ f1 * state[j - STRIDE]
|
||||
+ f2 * state[j - 2 * STRIDE]
|
||||
+ f3 * state[j - 3 * STRIDE]
|
||||
};
|
||||
}
|
||||
|
||||
// Part 2: transition samples (partially from input, partially from state).
|
||||
@@ -112,13 +133,20 @@ fn filter_core(
|
||||
#[allow(clippy::needless_range_loop, reason = "index used in arithmetic")]
|
||||
for k in (FILTER_SIZE * STRIDE)..SPLIT_BAND_SIZE {
|
||||
let base = k - in_shift;
|
||||
output[k] = f0.mul_add(
|
||||
input[base],
|
||||
f1.mul_add(
|
||||
input[base - STRIDE],
|
||||
f2.mul_add(input[base - 2 * STRIDE], f3 * input[base - 3 * STRIDE]),
|
||||
),
|
||||
);
|
||||
output[k] = if FMA {
|
||||
f0.mul_add(
|
||||
input[base],
|
||||
f1.mul_add(
|
||||
input[base - STRIDE],
|
||||
f2.mul_add(input[base - 2 * STRIDE], f3 * input[base - 3 * STRIDE]),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
f0 * input[base]
|
||||
+ f1 * input[base - STRIDE]
|
||||
+ f2 * input[base - 2 * STRIDE]
|
||||
+ f3 * input[base - 3 * STRIDE]
|
||||
};
|
||||
}
|
||||
|
||||
// Update state from end of input.
|
||||
@@ -151,6 +179,18 @@ impl ThreeBandFilterBank {
|
||||
&mut self,
|
||||
input: &[f32; FULL_BAND_SIZE],
|
||||
output: &mut [[f32; SPLIT_BAND_SIZE]; NUM_BANDS],
|
||||
) {
|
||||
self.analysis_with::<NATIVE_FMA>(input, output);
|
||||
}
|
||||
|
||||
/// [`Self::analysis`], with [`filter_core`] in the form `FMA` selects.
|
||||
/// Always inlined, so that LLVM optimizes this body as part of
|
||||
/// `analysis`.
|
||||
#[inline(always)]
|
||||
fn analysis_with<const FMA: bool>(
|
||||
&mut self,
|
||||
input: &[f32; FULL_BAND_SIZE],
|
||||
output: &mut [[f32; SPLIT_BAND_SIZE]; NUM_BANDS],
|
||||
) {
|
||||
// Initialize output to zero.
|
||||
for band in output.iter_mut() {
|
||||
@@ -184,7 +224,7 @@ impl ThreeBandFilterBank {
|
||||
|
||||
// Filter.
|
||||
let mut out_subsampled = [0.0f32; SPLIT_BAND_SIZE];
|
||||
filter_core(
|
||||
filter_core::<FMA>(
|
||||
filter,
|
||||
&in_subsampled,
|
||||
in_shift,
|
||||
@@ -208,6 +248,18 @@ impl ThreeBandFilterBank {
|
||||
&mut self,
|
||||
input: &[[f32; SPLIT_BAND_SIZE]; NUM_BANDS],
|
||||
output: &mut [f32; FULL_BAND_SIZE],
|
||||
) {
|
||||
self.synthesis_with::<NATIVE_FMA>(input, output);
|
||||
}
|
||||
|
||||
/// [`Self::synthesis`], with [`filter_core`] in the form `FMA` selects.
|
||||
/// Always inlined, so that LLVM optimizes this body as part of
|
||||
/// `synthesis`.
|
||||
#[inline(always)]
|
||||
fn synthesis_with<const FMA: bool>(
|
||||
&mut self,
|
||||
input: &[[f32; SPLIT_BAND_SIZE]; NUM_BANDS],
|
||||
output: &mut [f32; FULL_BAND_SIZE],
|
||||
) {
|
||||
output.fill(0.0);
|
||||
|
||||
@@ -240,7 +292,7 @@ impl ThreeBandFilterBank {
|
||||
|
||||
// Filter.
|
||||
let mut out_subsampled = [0.0f32; SPLIT_BAND_SIZE];
|
||||
filter_core(
|
||||
filter_core::<FMA>(
|
||||
filter,
|
||||
&in_subsampled,
|
||||
in_shift,
|
||||
@@ -334,6 +386,112 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Both forms of the unrolled Parts 1 and 3 of `filter_core`, on every
|
||||
/// target: the fused form must match the `mul_add` chain, and the plain
|
||||
/// form the C++ tap order, bit for bit.
|
||||
#[test]
|
||||
fn filter_core_matches_fused_and_plain_references() {
|
||||
use std::array::from_fn;
|
||||
|
||||
let filter = &FILTER_COEFFS[1];
|
||||
let state: [f32; MEMORY_SIZE] = from_fn(|i| (i as f32 * 0.618_034).fract() - 0.5);
|
||||
let input: [f32; SPLIT_BAND_SIZE] = from_fn(|i| (i as f32 * 0.414_214).fract() - 0.5);
|
||||
// Sample n of the stream is history[MEMORY_SIZE + n]; n < 0 is state.
|
||||
let history: Vec<f32> = state.iter().chain(&input).copied().collect();
|
||||
|
||||
let (mut part1_differs, mut part3_differs) = (false, false);
|
||||
// in_shift >= 1 so that Part 1 (state only) runs.
|
||||
for in_shift in 1..STRIDE {
|
||||
let mut fused_output = [0.0_f32; SPLIT_BAND_SIZE];
|
||||
filter_core::<true>(
|
||||
filter,
|
||||
&input,
|
||||
in_shift,
|
||||
&mut fused_output,
|
||||
&mut state.clone(),
|
||||
);
|
||||
let mut plain_output = [0.0_f32; SPLIT_BAND_SIZE];
|
||||
filter_core::<false>(
|
||||
filter,
|
||||
&input,
|
||||
in_shift,
|
||||
&mut plain_output,
|
||||
&mut state.clone(),
|
||||
);
|
||||
|
||||
// Part 2 (taps split between state and input) is unchanged.
|
||||
let parts_1_and_3 = (0..in_shift).chain(FILTER_SIZE * STRIDE..SPLIT_BAND_SIZE);
|
||||
for k in parts_1_and_3 {
|
||||
let t: [f32; FILTER_SIZE] =
|
||||
from_fn(|i| history[MEMORY_SIZE + k - in_shift - i * STRIDE]);
|
||||
let f = filter;
|
||||
let fused = f[0].mul_add(t[0], f[1].mul_add(t[1], f[2].mul_add(t[2], f[3] * t[3])));
|
||||
// C++ accumulates `out[k] += in[j] * filter[i]` for i = 0..3.
|
||||
let plain = f[0] * t[0] + f[1] * t[1] + f[2] * t[2] + f[3] * t[3];
|
||||
if fused.to_bits() != plain.to_bits() {
|
||||
if k < in_shift {
|
||||
part1_differs = true;
|
||||
} else {
|
||||
part3_differs = true;
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
fused_output[k].to_bits(),
|
||||
fused.to_bits(),
|
||||
"fused, in_shift {in_shift}, k {k}"
|
||||
);
|
||||
assert_eq!(
|
||||
plain_output[k].to_bits(),
|
||||
plain.to_bits(),
|
||||
"plain, in_shift {in_shift}, k {k}"
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(part1_differs && part3_differs);
|
||||
}
|
||||
|
||||
fn bits(v: &[f32]) -> Vec<u32> {
|
||||
v.iter().map(|x| x.to_bits()).collect()
|
||||
}
|
||||
|
||||
/// Output bits of `analysis_with::<FMA>` on `input` and of
|
||||
/// `synthesis_with::<FMA>` on `bands`, each on a new filter bank.
|
||||
fn run_forms<const FMA: bool>(
|
||||
input: &[f32; FULL_BAND_SIZE],
|
||||
bands: &[[f32; SPLIT_BAND_SIZE]; NUM_BANDS],
|
||||
) -> [Vec<u32>; 2] {
|
||||
let mut analysis = [[0.0_f32; SPLIT_BAND_SIZE]; NUM_BANDS];
|
||||
ThreeBandFilterBank::new().analysis_with::<FMA>(input, &mut analysis);
|
||||
let mut synthesis = [0.0_f32; FULL_BAND_SIZE];
|
||||
ThreeBandFilterBank::new().synthesis_with::<FMA>(bands, &mut synthesis);
|
||||
[bits(analysis.as_flattened()), bits(&synthesis)]
|
||||
}
|
||||
|
||||
/// `analysis` and `synthesis` run the [`NATIVE_FMA`] form.
|
||||
#[test]
|
||||
fn analysis_and_synthesis_use_native_fma() {
|
||||
use std::array::from_fn;
|
||||
|
||||
let input: [f32; FULL_BAND_SIZE] = from_fn(|i| (i as f32 * 0.618_034).fract() - 0.5);
|
||||
let bands: [[f32; SPLIT_BAND_SIZE]; NUM_BANDS] =
|
||||
from_fn(|b| from_fn(|i| ((b * SPLIT_BAND_SIZE + i) as f32 * 0.414_214).fract() - 0.5));
|
||||
// The forms differ on these inputs, so the comparison below can fail.
|
||||
let [fused, plain] = [
|
||||
run_forms::<true>(&input, &bands),
|
||||
run_forms::<false>(&input, &bands),
|
||||
];
|
||||
assert!(fused[0] != plain[0] && fused[1] != plain[1]);
|
||||
|
||||
let mut analysis = [[0.0_f32; SPLIT_BAND_SIZE]; NUM_BANDS];
|
||||
ThreeBandFilterBank::new().analysis(&input, &mut analysis);
|
||||
let mut synthesis = [0.0_f32; FULL_BAND_SIZE];
|
||||
ThreeBandFilterBank::new().synthesis(&bands, &mut synthesis);
|
||||
assert_eq!(
|
||||
[bits(analysis.as_flattened()), bits(&synthesis)],
|
||||
run_forms::<NATIVE_FMA>(&input, &bands)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_input_produces_zero_output() {
|
||||
let mut fb = ThreeBandFilterBank::new();
|
||||
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
//! `AudioProcessingBuilder::echo_canceller3_config`: a caller's AEC3 tuning
|
||||
//! reaches the echo canceller, also for stereo render, and the default path
|
||||
//! is unchanged.
|
||||
|
||||
use sonora::config::{EchoCanceller, EchoCanceller3Config};
|
||||
use sonora::{AudioProcessing, Config, StreamConfig};
|
||||
|
||||
const RATE: usize = 48_000;
|
||||
const FRAME: usize = RATE / 100;
|
||||
|
||||
/// Deterministic white noise in [-0.5, 0.5] (xorshift).
|
||||
fn noise(len: usize, seed: u64) -> Vec<f32> {
|
||||
let mut state = seed.wrapping_mul(0x9E37_79B9_7F4A_7C15) | 1;
|
||||
(0..len)
|
||||
.map(|_| {
|
||||
state ^= state << 13;
|
||||
state ^= state >> 7;
|
||||
state ^= state << 17;
|
||||
((state >> 40) as f32 / (1u64 << 24) as f32) - 0.5
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Runs 4 s of far-end noise with a delayed echo plus near-end bursts
|
||||
/// (double talk) through an APM and returns the processed capture signal.
|
||||
fn run(apm: &mut AudioProcessing) -> Vec<f32> {
|
||||
let len = 4 * RATE;
|
||||
let far = noise(len, 1);
|
||||
let near = noise(len, 2);
|
||||
let mut output = Vec::with_capacity(len);
|
||||
let mut unused = [0.0f32; FRAME];
|
||||
let mut out = [0.0f32; FRAME];
|
||||
for f in 0..len / FRAME {
|
||||
let range = f * FRAME..(f + 1) * FRAME;
|
||||
let mic: Vec<f32> = range
|
||||
.clone()
|
||||
.map(|n| {
|
||||
let echo = if n >= 2400 { 0.3 * far[n - 2400] } else { 0.0 };
|
||||
// Near-end talk in every other half second.
|
||||
let talk = if (n / (RATE / 2)) % 2 == 1 {
|
||||
0.2 * near[n]
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
echo + talk
|
||||
})
|
||||
.collect();
|
||||
apm.process_render_f32(&[&far[range]], &mut [&mut unused])
|
||||
.unwrap();
|
||||
apm.process_capture_f32(&[&mic], &mut [&mut out]).unwrap();
|
||||
output.extend_from_slice(&out);
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
fn apm(aec3: Option<EchoCanceller3Config>) -> AudioProcessing {
|
||||
apm_with_render_channels(aec3, 1)
|
||||
}
|
||||
|
||||
fn apm_with_render_channels(
|
||||
aec3: Option<EchoCanceller3Config>,
|
||||
render_channels: u16,
|
||||
) -> AudioProcessing {
|
||||
let mut builder = AudioProcessing::builder()
|
||||
.config(Config {
|
||||
echo_canceller: Some(EchoCanceller::default()),
|
||||
..Config::default()
|
||||
})
|
||||
.capture_config(StreamConfig::new(RATE as u32, 1))
|
||||
.render_config(StreamConfig::new(RATE as u32, render_channels));
|
||||
if let Some(aec3) = aec3 {
|
||||
builder = builder.echo_canceller3_config(aec3);
|
||||
}
|
||||
builder.build()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_config_gives_the_same_output_as_no_config() {
|
||||
let without = run(&mut apm(None));
|
||||
let with_default = run(&mut apm(Some(EchoCanceller3Config::default())));
|
||||
assert_eq!(without, with_default);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_tuning_reaches_the_echo_canceller() {
|
||||
let default = run(&mut apm(None));
|
||||
let mut tuned_config = EchoCanceller3Config::default();
|
||||
// A much stronger assumed echo path: the suppressor removes more.
|
||||
tuned_config.ep_strength.default_gain = 10.0;
|
||||
let tuned = run(&mut apm(Some(tuned_config)));
|
||||
assert_ne!(default, tuned);
|
||||
}
|
||||
|
||||
/// Runs 8 s of independent far-end noise on two render channels with a
|
||||
/// delayed echo of both on one microphone, and returns the processed capture
|
||||
/// signal of the last 2 s: by then AEC3 has detected stereo render (after 2 s
|
||||
/// of differing channels) and processes with its multichannel config.
|
||||
fn run_stereo(apm: &mut AudioProcessing) -> Vec<f32> {
|
||||
let len = 8 * RATE;
|
||||
let far = [noise(len, 3), noise(len, 4)];
|
||||
let mut output = Vec::with_capacity(2 * RATE);
|
||||
let mut unused = [[0.0f32; FRAME]; 2];
|
||||
let mut out = [0.0f32; FRAME];
|
||||
for f in 0..len / FRAME {
|
||||
let range = f * FRAME..(f + 1) * FRAME;
|
||||
let mic: Vec<f32> = range
|
||||
.clone()
|
||||
.map(|n| {
|
||||
if n >= 2400 {
|
||||
0.3 * far[0][n - 2400] + 0.1 * far[1][n - 2400]
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let [u0, u1] = &mut unused;
|
||||
apm.process_render_f32(
|
||||
&[&far[0][range.clone()], &far[1][range.clone()]],
|
||||
&mut [u0, u1],
|
||||
)
|
||||
.unwrap();
|
||||
apm.process_capture_f32(&[&mic], &mut [&mut out]).unwrap();
|
||||
if range.start >= len - 2 * RATE {
|
||||
output.extend_from_slice(&out);
|
||||
}
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_config_with_a_fixed_capture_delay_builds_and_processes() {
|
||||
// The default multichannel config has no fixed capture delay. Combining
|
||||
// the two used to trip ConfigSelector's compatibility check in debug
|
||||
// builds, even with mono render.
|
||||
let mut config = EchoCanceller3Config::default();
|
||||
config.delay.fixed_capture_delay_samples = 480;
|
||||
let output = run(&mut apm(Some(config)));
|
||||
assert!(output.iter().all(|s| s.is_finite()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_tuning_reaches_the_echo_canceller_with_stereo_render() {
|
||||
let default = run_stereo(&mut apm_with_render_channels(None, 2));
|
||||
let mut tuned_config = EchoCanceller3Config::default();
|
||||
tuned_config.ep_strength.default_gain = 10.0;
|
||||
let tuned = run_stereo(&mut apm_with_render_channels(Some(tuned_config), 2));
|
||||
assert_ne!(default, tuned);
|
||||
}
|
||||
+505
@@ -0,0 +1,505 @@
|
||||
//! Echo cancellation runs in real-time audio callbacks, where allocating
|
||||
//! memory can block. These tests check that steady-state processing with the
|
||||
//! echo canceller enabled does not allocate, through the float and int16
|
||||
//! APIs, at the 16, 32 and 48 kHz processing rates (one, two and three
|
||||
//! bands), with rate conversion, downmixing, stereo, an unused capture output,
|
||||
//! a change of the echo delay, noise suppression and the adaptive digital
|
||||
//! gain (AGC2). They count allocations
|
||||
//! (`alloc` and `realloc`) of the current thread only, so tests running in
|
||||
//! parallel do not interfere.
|
||||
//!
|
||||
//! Frees are not counted. With multichannel render, the echo canceller
|
||||
//! rebuilds its block processor when it detects stereo render, and the new
|
||||
//! comfort noise generator frees its initial noise estimate (one buffer of 260
|
||||
//! bytes per capture channel) 1000 blocks (4 s) later, while allocations are
|
||||
//! counted. Upstream frees the same buffer at the same point.
|
||||
//!
|
||||
//! Each test also checks that the echo canceller found and removed the echo,
|
||||
//! and the noise suppression and gain tests check that their stage changed
|
||||
//! the output, so that a test cannot pass because the processing it covers was
|
||||
//! skipped.
|
||||
|
||||
use std::alloc::{GlobalAlloc, Layout, System};
|
||||
use std::cell::Cell;
|
||||
|
||||
use sonora::config::{
|
||||
AdaptiveDigital, EchoCanceller, GainController2, MaxProcessingRate, NoiseSuppression, Pipeline,
|
||||
};
|
||||
use sonora::{AudioProcessing, Config, StreamConfig};
|
||||
|
||||
thread_local! {
|
||||
static COUNTING: Cell<bool> = const { Cell::new(false) };
|
||||
static ALLOCATIONS: Cell<usize> = const { Cell::new(0) };
|
||||
}
|
||||
|
||||
fn count() {
|
||||
if COUNTING.with(Cell::get) {
|
||||
ALLOCATIONS.with(|a| a.set(a.get() + 1));
|
||||
}
|
||||
}
|
||||
|
||||
struct CountingAllocator;
|
||||
|
||||
// SAFETY: forwards every call unchanged to the system allocator and only
|
||||
// counts calls.
|
||||
unsafe impl GlobalAlloc for CountingAllocator {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
count();
|
||||
// SAFETY: same contract as the caller's.
|
||||
unsafe { System.alloc(layout) }
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
// SAFETY: same contract as the caller's.
|
||||
unsafe { System.dealloc(ptr, layout) }
|
||||
}
|
||||
|
||||
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
||||
count();
|
||||
// SAFETY: same contract as the caller's.
|
||||
unsafe { System.realloc(ptr, layout, new_size) }
|
||||
}
|
||||
}
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOCATOR: CountingAllocator = CountingAllocator;
|
||||
|
||||
/// Deterministic noise in [-1, 1] (xorshift64).
|
||||
struct Noise(u64);
|
||||
|
||||
impl Noise {
|
||||
fn next(&mut self) -> f32 {
|
||||
self.0 ^= self.0 << 13;
|
||||
self.0 ^= self.0 >> 7;
|
||||
self.0 ^= self.0 << 17;
|
||||
((self.0 >> 40) as f32 / (1u64 << 23) as f32) - 1.0
|
||||
}
|
||||
}
|
||||
|
||||
/// The sample format passed to the processing calls.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum Format {
|
||||
/// Deinterleaved float (`process_*_f32`).
|
||||
F32,
|
||||
/// Interleaved int16 (`process_*_i16`), as the C API's
|
||||
/// `wap_process_stream_i16` uses.
|
||||
I16,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Scenario {
|
||||
rate: u32,
|
||||
/// The highest internal processing rate. At the default of 32 kHz, 44.1
|
||||
/// and 48 kHz streams are resampled to 32 kHz and split into two bands;
|
||||
/// processing in three bands needs 48 kHz.
|
||||
max_processing_rate: MaxProcessingRate,
|
||||
format: Format,
|
||||
capture_in_channels: u16,
|
||||
capture_out_channels: u16,
|
||||
render_channels: u16,
|
||||
capture_output_used: bool,
|
||||
/// Whether the echo delay changes from 60 ms to 100 ms after
|
||||
/// `DELAY_CHANGE_SECONDS`, so that the echo canceller has to find the new
|
||||
/// delay while allocations are counted.
|
||||
delay_change: bool,
|
||||
/// Whether noise suppression runs after the echo canceller.
|
||||
noise_suppression: bool,
|
||||
/// Whether AGC2's adaptive digital gain runs at the end of the capture
|
||||
/// path.
|
||||
gain_control: bool,
|
||||
}
|
||||
|
||||
impl Scenario {
|
||||
const fn mono(rate: u32, format: Format) -> Self {
|
||||
Self {
|
||||
rate,
|
||||
max_processing_rate: MaxProcessingRate::Rate32kHz,
|
||||
format,
|
||||
capture_in_channels: 1,
|
||||
capture_out_channels: 1,
|
||||
render_channels: 1,
|
||||
capture_output_used: true,
|
||||
delay_change: false,
|
||||
noise_suppression: false,
|
||||
gain_control: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_CHANNELS: usize = 2;
|
||||
const MAX_FRAME: usize = 480;
|
||||
const SECONDS: usize = 15;
|
||||
/// Lazy initialisation is allowed during the first 5 seconds.
|
||||
const WARM_UP_SECONDS: usize = 5;
|
||||
const DELAY_CHANGE_SECONDS: usize = 9;
|
||||
|
||||
/// Whether near-end talk is present in second `s` (every fourth second, so
|
||||
/// that double talk occurs while allocations are counted).
|
||||
fn near_end_active(s: usize) -> bool {
|
||||
s % 4 == 3
|
||||
}
|
||||
|
||||
struct Outcome {
|
||||
allocations: usize,
|
||||
erle_db: f64,
|
||||
/// Echo removed from the first capture channel over the last 3 seconds
|
||||
/// without near-end talk: microphone energy over output energy.
|
||||
attenuation_db: f64,
|
||||
delay_ms: i32,
|
||||
processing_rate: usize,
|
||||
}
|
||||
|
||||
fn run(scenario: Scenario) -> Outcome {
|
||||
let rate = scenario.rate as usize;
|
||||
let frame = rate / 100;
|
||||
let frames = SECONDS * 100;
|
||||
let samples = frames * frame;
|
||||
let cin = scenario.capture_in_channels as usize;
|
||||
let cout = scenario.capture_out_channels as usize;
|
||||
let rch = scenario.render_channels as usize;
|
||||
|
||||
let mut noise = Noise(0x1234_5678_9abc_def1);
|
||||
// Far end with pauses, independent noise per channel so that stereo
|
||||
// render is detected as stereo. The pauses keep a low noise floor rather
|
||||
// than exact zeros: AEC3 treats render as stereo only after the channels
|
||||
// have differed for 2 s without a break, and identical silent channels in
|
||||
// each pause would restart that count, so stereo render would be
|
||||
// processed as mono.
|
||||
let far: Vec<Vec<f32>> = (0..rch)
|
||||
.map(|_| {
|
||||
(0..samples)
|
||||
.map(|n| {
|
||||
let active = ((n as f32 / rate as f32) * 9.4).sin() > -0.3;
|
||||
if active {
|
||||
0.3 * noise.next()
|
||||
} else {
|
||||
0.001 * noise.next()
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect();
|
||||
// Each microphone picks up every far-end channel, with a different gain,
|
||||
// delayed by 60 ms (100 ms after the delay change), plus near-end talk
|
||||
// and a little noise.
|
||||
let mic: Vec<Vec<f32>> = (0..cin)
|
||||
.map(|c| {
|
||||
(0..samples)
|
||||
.map(|n| {
|
||||
let delay_ms = if scenario.delay_change && n >= DELAY_CHANGE_SECONDS * rate {
|
||||
100
|
||||
} else {
|
||||
60
|
||||
};
|
||||
let delay = delay_ms * rate / 1000;
|
||||
let mut echo = 0.0;
|
||||
if n >= delay {
|
||||
for (r, far_r) in far.iter().enumerate() {
|
||||
let gain = if r == c { 0.3 } else { 0.1 };
|
||||
echo += gain * far_r[n - delay];
|
||||
}
|
||||
}
|
||||
let near = if near_end_active(n / rate) {
|
||||
0.2 * noise.next()
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
echo + near + 0.001 * noise.next()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect();
|
||||
let interleave = |channels: &[Vec<f32>]| -> Vec<i16> {
|
||||
(0..samples)
|
||||
.flat_map(|n| channels.iter().map(move |c| (c[n] * 32767.0) as i16))
|
||||
.collect()
|
||||
};
|
||||
let far_i16 = interleave(&far);
|
||||
let mic_i16 = interleave(&mic);
|
||||
|
||||
let capture_in = StreamConfig::new(scenario.rate, scenario.capture_in_channels);
|
||||
let capture_out = StreamConfig::new(scenario.rate, scenario.capture_out_channels);
|
||||
let render = StreamConfig::new(scenario.rate, scenario.render_channels);
|
||||
let mut apm = AudioProcessing::builder()
|
||||
.config(Config {
|
||||
echo_canceller: Some(EchoCanceller::default()),
|
||||
noise_suppression: scenario.noise_suppression.then(NoiseSuppression::default),
|
||||
gain_controller2: scenario.gain_control.then(|| GainController2 {
|
||||
adaptive_digital: Some(AdaptiveDigital::default()),
|
||||
..GainController2::default()
|
||||
}),
|
||||
pipeline: Pipeline {
|
||||
maximum_internal_processing_rate: scenario.max_processing_rate,
|
||||
..Pipeline::default()
|
||||
},
|
||||
..Config::default()
|
||||
})
|
||||
.capture_config(capture_in)
|
||||
.render_config(render)
|
||||
.build();
|
||||
if !scenario.capture_output_used {
|
||||
apm.set_capture_output_used(false);
|
||||
}
|
||||
|
||||
let mut render_out = [[0.0f32; MAX_FRAME]; MAX_CHANNELS];
|
||||
let mut capture_out_f32 = [[0.0f32; MAX_FRAME]; MAX_CHANNELS];
|
||||
let mut render_out_i16 = [0i16; MAX_FRAME * MAX_CHANNELS];
|
||||
let mut capture_out_i16 = [0i16; MAX_FRAME * MAX_CHANNELS];
|
||||
let [r0, r1] = &mut render_out;
|
||||
let mut render_dest = [&mut r0[..frame], &mut r1[..frame]];
|
||||
let [c0, c1] = &mut capture_out_f32;
|
||||
let mut capture_dest = [&mut c0[..frame], &mut c1[..frame]];
|
||||
|
||||
let mut mic_energy = 0.0f64;
|
||||
let mut out_energy = 0.0f64;
|
||||
for f in 0..frames {
|
||||
if f == WARM_UP_SECONDS * 100 {
|
||||
ALLOCATIONS.with(|a| a.set(0));
|
||||
COUNTING.with(|c| c.set(true));
|
||||
}
|
||||
let range = f * frame..(f + 1) * frame;
|
||||
let measure = f >= (SECONDS - 3) * 100 && !near_end_active(f / 100);
|
||||
match scenario.format {
|
||||
Format::F32 => {
|
||||
let far_src = [&far[0][range.clone()], &far[rch - 1][range.clone()]];
|
||||
let mic_src = [&mic[0][range.clone()], &mic[cin - 1][range.clone()]];
|
||||
apm.process_render_f32(&far_src[..rch], &mut render_dest[..rch])
|
||||
.unwrap();
|
||||
apm.process_capture_f32_with_config(
|
||||
&mic_src[..cin],
|
||||
&capture_in,
|
||||
&capture_out,
|
||||
&mut capture_dest[..cout],
|
||||
)
|
||||
.unwrap();
|
||||
if measure {
|
||||
for (m, o) in mic_src[0].iter().zip(capture_dest[0].iter()) {
|
||||
mic_energy += f64::from(*m) * f64::from(*m);
|
||||
out_energy += f64::from(*o) * f64::from(*o);
|
||||
}
|
||||
}
|
||||
}
|
||||
Format::I16 => {
|
||||
let far_src = &far_i16[f * frame * rch..(f + 1) * frame * rch];
|
||||
let mic_src = &mic_i16[f * frame * cin..(f + 1) * frame * cin];
|
||||
apm.process_render_i16(far_src, &mut render_out_i16[..frame * rch])
|
||||
.unwrap();
|
||||
apm.process_capture_i16_with_config(
|
||||
mic_src,
|
||||
&capture_in,
|
||||
&capture_out,
|
||||
&mut capture_out_i16[..frame * cout],
|
||||
)
|
||||
.unwrap();
|
||||
if measure {
|
||||
for k in 0..frame {
|
||||
let m = f64::from(mic_src[k * cin]);
|
||||
let o = f64::from(capture_out_i16[k * cout]);
|
||||
mic_energy += m * m;
|
||||
out_energy += o * o;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = apm.statistics();
|
||||
}
|
||||
COUNTING.with(|c| c.set(false));
|
||||
|
||||
let stats = apm.statistics();
|
||||
Outcome {
|
||||
allocations: ALLOCATIONS.with(Cell::get),
|
||||
erle_db: stats.echo_return_loss_enhancement.unwrap(),
|
||||
attenuation_db: 10.0 * (mic_energy / out_energy.max(f64::MIN_POSITIVE)).log10(),
|
||||
delay_ms: stats.delay_ms.unwrap(),
|
||||
processing_rate: apm.proc_sample_rate_hz(),
|
||||
}
|
||||
}
|
||||
|
||||
fn check(scenario: Scenario) -> Outcome {
|
||||
let outcome = run(scenario);
|
||||
// Streams above 32 kHz are processed at the maximum processing rate,
|
||||
// which decides whether the scenario covers two bands or three.
|
||||
let expected_rate = if scenario.rate <= 32_000 {
|
||||
scenario.rate
|
||||
} else {
|
||||
scenario.max_processing_rate.as_hz()
|
||||
};
|
||||
assert_eq!(
|
||||
outcome.processing_rate, expected_rate as usize,
|
||||
"processing rate: {scenario:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
outcome.allocations, 0,
|
||||
"steady-state processing allocated: {scenario:?}"
|
||||
);
|
||||
|
||||
// Without echo in the microphone signal the ERLE stays below 1 dB.
|
||||
// Without echo removal the attenuation still reaches about 6.4 dB: the
|
||||
// average of two microphones carries less echo than the first one, which
|
||||
// is the one measured (3.5 dB), and processing 48 kHz at 32 kHz drops the
|
||||
// noise above 16 kHz (2.9 dB). Noise suppression raises that to 7.3 dB.
|
||||
// Here both are above 15 dB, so 10 dB shows that the echo canceller ran
|
||||
// and converged.
|
||||
assert!(
|
||||
outcome.erle_db > 10.0,
|
||||
"ERLE is {:.1} dB: {scenario:?}",
|
||||
outcome.erle_db
|
||||
);
|
||||
if scenario.capture_output_used {
|
||||
assert!(
|
||||
outcome.attenuation_db > 10.0,
|
||||
"echo attenuated by only {:.1} dB: {scenario:?}",
|
||||
outcome.attenuation_db
|
||||
);
|
||||
}
|
||||
// The delay estimate must follow the echo, including after a change.
|
||||
let expected_delay_ms = if scenario.delay_change { 100 } else { 60 };
|
||||
assert!(
|
||||
(outcome.delay_ms - expected_delay_ms).abs() <= 10,
|
||||
"delay estimate {} ms, expected {expected_delay_ms} ms: {scenario:?}",
|
||||
outcome.delay_ms
|
||||
);
|
||||
outcome
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f32_16k_mono() {
|
||||
check(Scenario::mono(16_000, Format::F32));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f32_32k_mono() {
|
||||
check(Scenario::mono(32_000, Format::F32));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f32_48k_mono() {
|
||||
check(Scenario::mono(48_000, Format::F32));
|
||||
}
|
||||
|
||||
/// The only scenario that processes at 48 kHz, in three bands.
|
||||
#[test]
|
||||
fn f32_48k_mono_three_bands() {
|
||||
check(Scenario {
|
||||
max_processing_rate: MaxProcessingRate::Rate48kHz,
|
||||
..Scenario::mono(48_000, Format::F32)
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn i16_16k_mono() {
|
||||
check(Scenario::mono(16_000, Format::I16));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn i16_48k_mono() {
|
||||
check(Scenario::mono(48_000, Format::I16));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f32_48k_stereo_in_mono_out() {
|
||||
check(Scenario {
|
||||
capture_in_channels: 2,
|
||||
..Scenario::mono(48_000, Format::F32)
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f32_48k_stereo() {
|
||||
check(Scenario {
|
||||
capture_in_channels: 2,
|
||||
capture_out_channels: 2,
|
||||
render_channels: 2,
|
||||
..Scenario::mono(48_000, Format::F32)
|
||||
});
|
||||
}
|
||||
|
||||
/// 44.1 kHz is resampled to the 32 kHz processing rate and back, so this
|
||||
/// covers the int16 downmix with resampling.
|
||||
#[test]
|
||||
fn i16_44k_stereo_in_mono_out() {
|
||||
check(Scenario {
|
||||
capture_in_channels: 2,
|
||||
..Scenario::mono(44_100, Format::I16)
|
||||
});
|
||||
}
|
||||
|
||||
/// Covers the int16 multi-channel conversions with resampling.
|
||||
#[test]
|
||||
fn i16_44k_stereo() {
|
||||
check(Scenario {
|
||||
capture_in_channels: 2,
|
||||
capture_out_channels: 2,
|
||||
render_channels: 2,
|
||||
..Scenario::mono(44_100, Format::I16)
|
||||
});
|
||||
}
|
||||
|
||||
/// Noise suppression runs in the same capture callback: here two
|
||||
/// suppressors, one per capture channel, each over two bands.
|
||||
#[test]
|
||||
fn f32_48k_stereo_noise_suppression() {
|
||||
let scenario = Scenario {
|
||||
capture_in_channels: 2,
|
||||
capture_out_channels: 2,
|
||||
render_channels: 2,
|
||||
noise_suppression: true,
|
||||
..Scenario::mono(48_000, Format::F32)
|
||||
};
|
||||
let with_ns = check(scenario);
|
||||
// `check` covers the echo canceller only. If noise suppression were
|
||||
// skipped, the output would equal that of the same run without it, so
|
||||
// require a clear difference in the echo attenuation (about 2.1 dB here).
|
||||
let without_ns = run(Scenario {
|
||||
noise_suppression: false,
|
||||
..scenario
|
||||
});
|
||||
assert!(
|
||||
(with_ns.attenuation_db - without_ns.attenuation_db).abs() > 1.0,
|
||||
"noise suppression did not change the output: {:.2} dB with it, {:.2} dB without",
|
||||
with_ns.attenuation_db,
|
||||
without_ns.attenuation_db
|
||||
);
|
||||
}
|
||||
|
||||
/// AGC2's adaptive digital gain runs in the same capture callback, once per
|
||||
/// capture channel.
|
||||
#[test]
|
||||
fn f32_48k_stereo_gain_control() {
|
||||
let scenario = Scenario {
|
||||
capture_in_channels: 2,
|
||||
capture_out_channels: 2,
|
||||
render_channels: 2,
|
||||
gain_control: true,
|
||||
..Scenario::mono(48_000, Format::F32)
|
||||
};
|
||||
let with_gain = check(scenario);
|
||||
// As for noise suppression: if the gain were skipped, the output would
|
||||
// equal that of the same run without it.
|
||||
let without_gain = run(Scenario {
|
||||
gain_control: false,
|
||||
..scenario
|
||||
});
|
||||
assert!(
|
||||
(with_gain.attenuation_db - without_gain.attenuation_db).abs() > 1.0,
|
||||
"the gain did not change the output: {:.2} dB with it, {:.2} dB without",
|
||||
with_gain.attenuation_db,
|
||||
without_gain.attenuation_db
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f32_48k_capture_output_unused() {
|
||||
check(Scenario {
|
||||
capture_output_used: false,
|
||||
..Scenario::mono(48_000, Format::F32)
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f32_48k_delay_change() {
|
||||
check(Scenario {
|
||||
delay_change: true,
|
||||
..Scenario::mono(48_000, Format::F32)
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user