diff --git a/CHANGELOG.md b/CHANGELOG.md index 49d0bdf..81295ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ ### Codec foundations +- Add an opt-in, allocation-free `no_std` native Rust Codec2 crate for 1600/3200 + bit/s. Initialize in caller-owned storage; isolate decoder randomness; use the + same Rust math on host and MCU; reject wrong native frame sizes. Correct the + inherited real-FFT input-copy truncation. Preserve upstream source/license + provenance. Target audio, CPU/stack and live integration remain separate gates. + - Add a fixed-profile Codec2 packet adapter over caller-owned PCM16/output buffers and an application-supplied native backend. Reject malformed lengths, unexpected modes and insufficient capacity before codec processing; stop diff --git a/Cargo.lock b/Cargo.lock index 3135d60..ab76b5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -526,6 +526,12 @@ version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + [[package]] name = "linux-raw-sys" version = "0.12.1" @@ -547,6 +553,13 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "lxst-codec2" +version = "0.2.0" +dependencies = [ + "libm", +] + [[package]] name = "lxst-core" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 478daf0..70d0794 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ resolver = "2" members = [ "crates/lxst-core", + "crates/lxst-codec2", "crates/lxst-rns", "crates/lxst-telephony", ] diff --git a/README.md b/README.md index 029690b..d10a060 100644 --- a/README.md +++ b/README.md @@ -257,6 +257,14 @@ Applications still own platform integration: Ratspeak uses this boundary for its native voice-call feature. +## Embedded Codec2 backend + +[`lxst-codec2`](crates/lxst-codec2/README.md) supplies bounded native Rust +1600/3200 bit/s encode/decode with in-place initialization and no allocator. +It is separate from the live telephony runtime and requires device timing, +stack and audio qualification before use on hardware. It does not implement +700C or compatible Opus voice memo containers. + ## Contributing If the issue or contribution belongs upstream as well, start there. Python LXST diff --git a/THIRD_PARTY_LICENSES.json b/THIRD_PARTY_LICENSES.json index 5647d4b..3896f32 100644 --- a/THIRD_PARTY_LICENSES.json +++ b/THIRD_PARTY_LICENSES.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, - "scope": "All registry third-party normal/build dependencies reachable from rsLXST workspace members across declared targets; dev-only and first-party path packages are excluded.", - "cargoLockSha256": "a852bb18196793d321a908544d9b1beaafe7947073f7477ae6b6c9e2823c3218", + "scope": "Adapted Codec2 and all registry third-party normal/build dependencies reachable from rsLXST workspace members across declared targets; dev-only and first-party path packages are excluded.", + "cargoLockSha256": "ea2327255af9e42663e04f2a30e3aeca494b339c1ad118205f91636af776bbb5", "packages": [ { "name": "aes", @@ -101,6 +101,23 @@ "repository": "https://github.com/RustCrypto/traits", "source": "registry+https://github.com/rust-lang/crates.io-index" }, + { + "name": "codec2 (adapted as lxst-codec2)", + "version": "0.3.1", + "license": "LGPL-2.1-only AND MIT AND BSD-3-Clause", + "repository": "https://github.com/scriptjunkie/codec2", + "source": "local-adaptation", + "upstreamCommit": "24ec3b7c5b9892c268e180802ee3a5ce7737f214", + "crateChecksum": "3c3c8ba70382a99c0b5ebadf6ad50e7d98fb6eb9bcc4c0e30d422f6321798d99", + "provenance": "crates/lxst-codec2/UPSTREAM.json", + "notices": { + "crates/lxst-codec2/NOTICE": "d0b296649684d3c365a6afd5737fd7183ad3a7b6fa15057333390600f0f920e2", + "crates/lxst-codec2/licenses/KISS-FFT-BSD-3-Clause.txt": "49eea0111dfb7038dc18f74034cc517690395ebac8f7768f999133b16e4bf064", + "crates/lxst-codec2/licenses/LGPL-2.1.txt": "9ebb6f82b7380a62ac74c5f0322c88e6744dedf2ebe1f54d6f088282b39844bf", + "crates/lxst-codec2/licenses/upstream-Cargo.toml": "939e2818dcb2945f52eceb71b37b512bf1796da53a05e0a69276d5a2e55f9eed", + "crates/lxst-codec2/licenses/upstream-README.md": "76fee2b7d3455903f4246e7412ac230a856f58b098861c4c4c9dbdecd371f94a" + } + }, { "name": "combine", "version": "4.6.7", @@ -297,6 +314,13 @@ "repository": "https://github.com/rust-lang/libc", "source": "registry+https://github.com/rust-lang/crates.io-index" }, + { + "name": "libm", + "version": "0.2.16", + "license": "MIT", + "repository": "https://github.com/rust-lang/compiler-builtins", + "source": "registry+https://github.com/rust-lang/crates.io-index" + }, { "name": "lock_api", "version": "0.4.14", diff --git a/THIRD_PARTY_LICENSES.md b/THIRD_PARTY_LICENSES.md index 63168cd..8fcc3cb 100644 --- a/THIRD_PARTY_LICENSES.md +++ b/THIRD_PARTY_LICENSES.md @@ -5,7 +5,7 @@ Third-party components retain their own licenses; the rsLXST license does not replace those terms or notices. [`THIRD_PARTY_LICENSES.json`](THIRD_PARTY_LICENSES.json) is the complete, -CI-checked inventory of registry third-party normal/build +CI-checked inventory of adapted Codec2 and registry third-party normal/build dependencies reachable from the locked workspace across declared targets. It excludes dev-only packages and first-party path packages. The inventory is generated from Cargo metadata and `Cargo.lock` with: @@ -31,3 +31,12 @@ heap-backed codec state. The preserved license and Opus patent notice are in This inventory records source and license evidence; it is not legal advice and does not by itself replace any third-party notice required for a distributed binary or source bundle. + +## Adapted Codec2 implementation + +`crates/lxst-codec2` retains the pure-Rust codec2 0.3.1 implementation's +LGPL-2.1-only AND MIT declaration and embedded KISS FFT BSD-3-Clause notice. +Its [NOTICE](crates/lxst-codec2/NOTICE) and +[immutable provenance](crates/lxst-codec2/UPSTREAM.json) describe the bounded +storage, math and state-ownership modifications. This path dependency is +explicitly inventoried; it is not treated as original first-party DSP. diff --git a/api/fixtures/Cargo.lock b/api/fixtures/Cargo.lock index 00ffb28..b4c36e3 100644 --- a/api/fixtures/Cargo.lock +++ b/api/fixtures/Cargo.lock @@ -376,6 +376,12 @@ version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + [[package]] name = "lock_api" version = "0.4.14" @@ -391,6 +397,13 @@ version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" +[[package]] +name = "lxst-codec2" +version = "0.2.0" +dependencies = [ + "libm", +] + [[package]] name = "lxst-core" version = "0.2.0" @@ -435,6 +448,7 @@ dependencies = [ name = "lxst-telephony-api-fixture" version = "0.0.0" dependencies = [ + "lxst-codec2", "lxst-core", "lxst-telephony", "rns-identity", diff --git a/api/fixtures/Cargo.toml b/api/fixtures/Cargo.toml index 656483d..087c84f 100644 --- a/api/fixtures/Cargo.toml +++ b/api/fixtures/Cargo.toml @@ -7,6 +7,7 @@ publish = false [workspace] [dependencies] +lxst-codec2 = { path = "../../crates/lxst-codec2" } lxst-core = { path = "../../crates/lxst-core" } lxst-telephony = { path = "../../crates/lxst-telephony" } rns-identity = { path = "../../../rsReticulum/crates/rns-identity" } diff --git a/api/fixtures/src/lib.rs b/api/fixtures/src/lib.rs index 4a078fb..ebad8c2 100644 --- a/api/fixtures/src/lib.rs +++ b/api/fixtures/src/lib.rs @@ -53,3 +53,21 @@ pub mod codec2 { codec.decode_into(packet, output) } } + +pub mod bounded_codec2 { + use lxst_codec2::{Codec, Error, Mode}; + use std::mem::MaybeUninit; + + pub fn initialise(storage: &mut MaybeUninit, mode: Mode) -> &mut Codec { + Codec::initialise(storage, mode) + } + pub fn roundtrip( + codec: &mut Codec, + pcm: &[i16], + packet: &mut [u8], + output: &mut [i16], + ) -> Result<(), Error> { + codec.encode(pcm, packet)?; + codec.decode(packet, output) + } +} diff --git a/api/snapshots/manifest-contract.json b/api/snapshots/manifest-contract.json index 34f565a..2a3ffbf 100644 --- a/api/snapshots/manifest-contract.json +++ b/api/snapshots/manifest-contract.json @@ -2,6 +2,38 @@ "schemaVersion": 1, "scope": "library Cargo manifests, public features, targets, and non-dev dependencies", "packages": [ + { + "name": "lxst-codec2", + "version": "0.2.0", + "rustVersion": "1.87", + "edition": "2024", + "features": {}, + "targets": [ + { + "name": "lxst_codec2", + "kind": [ + "lib" + ], + "crateTypes": [ + "lib" + ], + "requiredFeatures": [] + } + ], + "dependencies": [ + { + "name": "libm", + "rename": null, + "kind": null, + "target": null, + "requirement": "=0.2.16", + "optional": false, + "defaultFeatures": false, + "features": [], + "sourceKind": "registry" + } + ] + }, { "name": "lxst-core", "version": "0.2.0", diff --git a/api/stability.json b/api/stability.json index ad1dc43..416428c 100644 --- a/api/stability.json +++ b/api/stability.json @@ -23,6 +23,7 @@ "capturedOn": "2026-10-01", "review": { "areas": [ + "Allocation-free native 1600/3200 Codec2 state initialized in caller storage", "Bounded fixed-profile Codec2 packet processing and caller-owned PCM/output buffers", "Native Codec2 backend contract and failure-state ownership", "Existing Opus and telephony APIs retained" @@ -39,7 +40,7 @@ "TelephonyService::new", "TelephonyService::with_config" ], - "classification": "additive experimental Codec2 backend boundary; no bundled native backend or telephony activation", + "classification": "additive experimental native Codec2 backend and packet boundary; no automatic telephony activation", "publicApiDiff": { "added": 33, "removed": 0 @@ -52,11 +53,25 @@ "stable and Rust 1.87 strict Clippy", "compiled external Codec2 consumer", "24 actual Rust Codec2 packet-boundary cases against native frames and C reference data; codec quality and allocation qualification remain separate", - "separate Rust candidate no_std compile on pinned ESP32-S3 toolchain; no on-device runtime claim" + "separate Rust candidate no_std compile on pinned ESP32-S3 toolchain; no on-device runtime claim", + "Native zero-allocation contract, independent duplex histories and 20000 arbitrary decoder frames", + "12 bounded backend/C reference packet cases, exact locked ESP32-S3 compiler build and stable/MSRV strict Clippy" + ], + "newPackages": [ + "lxst-codec2" ] } }, "packages": [ + { + "name": "lxst-codec2", + "manifestPath": "Cargo.toml", + "tier": "experimental", + "compatibility": "reviewed-snapshot", + "snapshot": "api/snapshots/lxst-codec2.txt", + "itemCount": 0, + "sha256": "0000000000000000000000000000000000000000000000000000000000000000" + }, { "name": "lxst-core", "manifestPath": "Cargo.toml", diff --git a/crates/lxst-codec2/Cargo.toml b/crates/lxst-codec2/Cargo.toml new file mode 100644 index 0000000..429e253 --- /dev/null +++ b/crates/lxst-codec2/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "lxst-codec2" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +publish.workspace = true +license = "LGPL-2.1-only AND MIT AND BSD-3-Clause" +description = "Bounded no_std Codec2 speech backend for LXST" + +[dependencies] +libm = { version = "=0.2.16", default-features = false } + +[[test]] +name = "contract" +harness = false + diff --git a/crates/lxst-codec2/NOTICE b/crates/lxst-codec2/NOTICE new file mode 100644 index 0000000..09c3c7c --- /dev/null +++ b/crates/lxst-codec2/NOTICE @@ -0,0 +1,18 @@ +This is a modified version of the pure-Rust codec2 0.3.1 implementation by +David Rowe and Matt Weeks, https://github.com/scriptjunkie/codec2. +The original manifest declares LGPL-2.1-only AND MIT. The original package +and pinned repository have no separate MIT license file; the original manifest +and README are retained under licenses/. Do not erase the upstream declaration. +Codec2's LGPL-2.1 text and the embedded KISS FFT BSD-3-Clause notice are retained +there as well. Original author/function notices remain in the adapted sources. + +Modified for rsLXST on 2026-10-01: bounded storage and scratch; in-place state +initialisation; per-instance synthesis RNG; exact libm math on all targets; +checked public frame shapes; corrected real-FFT input copying. The public API +exposes only native 1600/3200 modes at 8 kHz mono. Other private upstream modes +are not a supported API. See UPSTREAM.json for immutable original provenance. + +New wrapper, tests and storage adaptation are provided under LGPL-2.1-only. +Third-party libm retains its own MIT license and appears in the workspace's +locked third-party inventory. Packaging must retain the applicable notices and +provide the corresponding modified Codec2 source and relinking materials. diff --git a/crates/lxst-codec2/README.md b/crates/lxst-codec2/README.md new file mode 100644 index 0000000..d8c9e42 --- /dev/null +++ b/crates/lxst-codec2/README.md @@ -0,0 +1,24 @@ +# Bounded Rust Codec2 + +Allocation-free `no_std` native 1600/3200 bit/s speech at mono 8 kHz PCM16. +This is the pinned Rust Codec2 port with fixed storage, per-instance synthesis +randomness and pure-Rust `libm` math. It has no allocator dependency. + +Allocate `MaybeUninit` in final aligned storage, then call +`Codec::initialise`. Do not construct a codec temporary on a small task stack. +One serialized owner can alternate encoding and decoding; predictor histories +are independent. Independent sessions require separate states. `reset` erases +histories in place. Native input/output frame lengths must match `Mode` exactly; +length errors do not advance state or modify output. + +LXST framing and negotiation belong to `lxst-core`, not this backend. 700C, +Opus, memo containers, audio drivers and real-time target qualification are not +provided here. Codec state plus worst-case nested DSP stack and I/O buffers must +fit the selected device budget. A target build is not a timing/stack measurement. + +`cargo test -p lxst-codec2 --release` checks allocation-free initialization, +reset and streaming; rejected inputs; independent duplex histories; hostile +correctly-sized decoder frames; and the real-FFT second-half input regression. + +See [NOTICE](NOTICE), [UPSTREAM.json](UPSTREAM.json) and [licenses](licenses/) +for source provenance, modifications and original license notices. diff --git a/crates/lxst-codec2/UPSTREAM.json b/crates/lxst-codec2/UPSTREAM.json new file mode 100644 index 0000000..ea4f5b9 --- /dev/null +++ b/crates/lxst-codec2/UPSTREAM.json @@ -0,0 +1,19 @@ +{ + "upstream_crate": "codec2", + "version": "0.3.1", + "repository": "https://github.com/scriptjunkie/codec2", + "commit": "24ec3b7c5b9892c268e180802ee3a5ce7737f214", + "crate_sha256": "3c3c8ba70382a99c0b5ebadf6ad50e7d98fb6eb9bcc4c0e30d422f6321798d99", + "declared_license": "LGPL-2.1-only AND MIT", + "additional_embedded_notice": "BSD-3-Clause KISS FFT notice preserved in src/native/kiss_fft.rs", + "original_source_sha256": { + "kiss_fft.rs": "33f9a3f1c2caddaa8e7536d655fd0c20f85d9dd78224f5e117a2c5bec1ca5671", + "codebookd.rs": "5527f6217500f303a551a6e6f2425cf7ea1abe95e43093f73eea467a45c7ba08", + "codebook.rs": "8de6ea51a391982d26a724c3b7e8ef2e6fefed066f295e7f4a745a6aceb0a6d2", + "lib.rs": "5a468ed1b26854be5f1992a215959151e7d3435fe154d212b2c468e4f10744bb", + "codebookge.rs": "0d36228e468f74eb65bbcbbadb9cb66a599466f347f1b7ee436abdb29d4c4378", + "quantise.rs": "f1e831fddee5a657e4139ac0808339cede5f5a8b6e9784eda600f3a714bb81bb", + "codebookjvm.rs": "6a5aba7b9be606b2d7b16054e897d8862f3bd4ec24fa3f78ff5659b361bd7266", + "nlp.rs": "d86f14abc7ce709d1a36a5b4dce3a2bab30ed5999a04548b61548c433897a0c6" + } +} diff --git a/crates/lxst-codec2/licenses/KISS-FFT-BSD-3-Clause.txt b/crates/lxst-codec2/licenses/KISS-FFT-BSD-3-Clause.txt new file mode 100644 index 0000000..09d03f1 --- /dev/null +++ b/crates/lxst-codec2/licenses/KISS-FFT-BSD-3-Clause.txt @@ -0,0 +1,11 @@ +Copyright (c) 2003-2010, Mark Borgerding + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/crates/lxst-codec2/licenses/LGPL-2.1.txt b/crates/lxst-codec2/licenses/LGPL-2.1.txt new file mode 100644 index 0000000..cc40a46 --- /dev/null +++ b/crates/lxst-codec2/licenses/LGPL-2.1.txt @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see + . + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/crates/lxst-codec2/licenses/upstream-Cargo.toml b/crates/lxst-codec2/licenses/upstream-Cargo.toml new file mode 100644 index 0000000..e3412b2 --- /dev/null +++ b/crates/lxst-codec2/licenses/upstream-Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "codec2" +version = "0.3.1" +description = "A pure-Rust implementation of the Codec2 low-bitrate speech compression codec" +authors = ["David Rowe", "Matt Weeks "] +license = "LGPL-2.1-only AND MIT" +edition = "2018" +repository = "https://github.com/scriptjunkie/codec2" +keywords = ["audio", "speech", "compression", "codec"] +categories = ["compression", "multimedia::audio", "multimedia::encoding", "algorithms"] +readme = "README.md" + +[dependencies] +micromath = {version = "2.1.0", optional = true} + +[dev-dependencies] +zerocopy = "0.3.0" + +[features] +micromath = ["dep:micromath"] diff --git a/crates/lxst-codec2/licenses/upstream-README.md b/crates/lxst-codec2/licenses/upstream-README.md new file mode 100644 index 0000000..d7dd5dd --- /dev/null +++ b/crates/lxst-codec2/licenses/upstream-README.md @@ -0,0 +1,61 @@ +# Codec2 + +Add this to your `Cargo.toml`: + +```toml +[dependencies] +codec2 = "0.3" +``` + +## Usage +Currently 3200, 2400, 1600, 1400, 1300 and 1200 bitrates encoding and decoding are implemented. + +Create a Codec2 object e.g. `Codec2::new(Codec2Mode::MODE_3200)` then repeatedly obtain raw 8khz +16-bit audio samples and call `encode` to encode blocks of `samples_per_frame()` samples into +`bits_per_frame()` compressed bits, in order. On the receiving end, create a Codec2 object and +repeatedly call `decode` to decompress each chunk of received bytes into the next samples. + +Complete example below. This example uses zerocopy to interpret the `&[i16]` slices as `&[u8]` for +I/O. + +Cargo.toml: + +```toml +[dependencies] +zerocopy = "0.3.0" +codec2 = "0" +``` + +main.rs: + +```rust +use codec2::*; +use std::env::args; +use std::io::prelude::*; +use zerocopy::AsBytes; + +fn main() -> std::io::Result<()> { + if args().len() != 4 || (args().nth(1).unwrap() != "enc" && args().nth(1).unwrap() != "dec") { + eprintln!("Usage: {} (enc|dec) inputfile outputfilename", args().nth(0).unwrap()); + eprintln!("Files should be raw 16-bit signed 8khz audio"); + return Ok(()); + } + let mut fin = std::fs::File::open(args().nth(2).unwrap())?; + let mut fout = std::fs::File::create(args().nth(3).unwrap())?; + let mut c2 = Codec2::new(Codec2Mode::MODE_3200); + let mut samps = vec![0; c2.samples_per_frame()]; //i16 I/O buffer + let mut packed = vec![0; (c2.bits_per_frame() + 7) / 8]; //u8 I/O buffer for encoded bits + if args().nth(1).unwrap() == "enc" { + while fin.read_exact(samps.as_bytes_mut()).is_ok() { + c2.encode(&mut packed, &samps[..]); + fout.write_all(&packed)?; + } + } else { + while fin.read_exact(&mut packed).is_ok() { + c2.decode(&mut samps[..], &packed); + fout.write_all(samps.as_bytes())?; + } + } + Ok(()) +} +``` diff --git a/crates/lxst-codec2/src/buffer.rs b/crates/lxst-codec2/src/buffer.rs new file mode 100644 index 0000000..79742e1 --- /dev/null +++ b/crates/lxst-codec2/src/buffer.rs @@ -0,0 +1,38 @@ +use core::ops::{Deref, DerefMut}; + +/// Private fixed storage preserving the upstream DSP's slice lengths. +/// Zero initialisation is valid: a zero length exposes no uninitialised data. +#[derive(Clone, Debug)] +pub(crate) struct Buffer { + length: usize, + values: [T; N], +} + +impl Buffer { + pub(crate) fn filled(length: usize, value: T) -> Self { + assert!(length <= N); + Self { + length, + values: [value; N], + } + } + + pub(crate) fn initialise(&mut self, length: usize, value: T) { + assert!(length <= N); + self.length = length; + self.values[..length].fill(value); + } +} + +impl Deref for Buffer { + type Target = [T]; + fn deref(&self) -> &[T] { + &self.values[..self.length] + } +} + +impl DerefMut for Buffer { + fn deref_mut(&mut self) -> &mut [T] { + &mut self.values[..self.length] + } +} diff --git a/crates/lxst-codec2/src/lib.rs b/crates/lxst-codec2/src/lib.rs new file mode 100644 index 0000000..3f189e9 --- /dev/null +++ b/crates/lxst-codec2/src/lib.rs @@ -0,0 +1,119 @@ +//! Fixed-storage, allocation-free Codec2 at 8 kHz mono PCM16. +//! +//! Adapted from the pinned pure-Rust Codec2 port recorded in `UPSTREAM.json`. +//! Initialise directly in caller-owned storage; the state is too large to create +//! as a temporary on an MCU task stack. Encoding/decoding and reset never allocate. +#![no_std] + +mod buffer; +mod math; +use buffer::Buffer; +use math::FloatMath; + +// Preserve the upstream DSP's names, numeric constants and indexing style so +// algorithm changes remain reviewable separately from the storage adaptation. +#[allow( + non_snake_case, + non_camel_case_types, + non_upper_case_globals, + dead_code +)] +#[allow(clippy::all)] +mod native; + +use core::mem::MaybeUninit; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Mode { + Rate1600, + Rate3200, +} + +impl Mode { + pub const fn samples(self) -> usize { + match self { + Self::Rate1600 => 320, + Self::Rate3200 => 160, + } + } + + pub const fn bytes(self) -> usize { + 8 + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Error { + PcmLength, + EncodedLength, +} + +/// Independent encoder and decoder histories at one native mode. +/// +/// One serialized audio owner may alternate transmit and receive with this +/// instance; FFT scratch is reused and the histories remain independent. It +/// must never be accessed concurrently. Independent sessions need independent +/// instances. `Mode` is a codec configuration, not an LXST/LXMF wire identifier. +pub struct Codec { + native: native::Codec2, +} + +impl Codec { + /// Initialise in final, aligned caller storage without a whole-state copy. + pub fn initialise(storage: &mut MaybeUninit, mode: Mode) -> &mut Self { + // SAFETY: all native fields are integers, floats, arrays, fixed buffers + // (zero length is valid), or Codec2Mode (repr(u8), first variant is 0). + // There are no references, pointers, heap owners or Drop implementations. + // Thus zero bytes form a valid value. We finish logical initialisation + // before publishing it. The exclusive borrow prevents concurrent access. + let value = unsafe { + storage.as_mut_ptr().write_bytes(0, 1); + storage.assume_init_mut() + }; + value.initialise_native(mode); + value + } + + fn initialise_native(&mut self, mode: Mode) { + self.native.initialise(match mode { + Mode::Rate1600 => native::Codec2Mode::MODE_1600, + Mode::Rate3200 => native::Codec2Mode::MODE_3200, + }); + } + + pub fn reset(&mut self, mode: Mode) { + // SAFETY: same zero-valid representation as initialise; this type owns + // no resources requiring Drop and self is exclusively borrowed. + unsafe { core::ptr::write_bytes(self, 0, 1) }; + self.initialise_native(mode); + } + + pub fn mode(&self) -> Mode { + match self.native.samples_per_frame() { + 320 => Mode::Rate1600, + _ => Mode::Rate3200, + } + } + + pub fn encode(&mut self, pcm: &[i16], output: &mut [u8]) -> Result<(), Error> { + if pcm.len() != self.mode().samples() { + return Err(Error::PcmLength); + } + if output.len() != self.mode().bytes() { + return Err(Error::EncodedLength); + } + self.native.encode(output, pcm); + Ok(()) + } + + pub fn decode(&mut self, encoded: &[u8], output: &mut [i16]) -> Result<(), Error> { + if encoded.len() != self.mode().bytes() { + return Err(Error::EncodedLength); + } + if output.len() != self.mode().samples() { + return Err(Error::PcmLength); + } + self.native.decode(output, encoded); + Ok(()) + } +} diff --git a/crates/lxst-codec2/src/math.rs b/crates/lxst-codec2/src/math.rs new file mode 100644 index 0000000..141e8ff --- /dev/null +++ b/crates/lxst-codec2/src/math.rs @@ -0,0 +1,47 @@ +// Same pure-Rust libm functions on host and MCU. Do not replace with approximate +// intrinsics without comparing stateful speech and target execution budgets. +pub(crate) trait FloatMath { + fn dsp_acos(self) -> Self; + fn dsp_atan2(self, other: Self) -> Self; + fn dsp_ceil(self) -> Self; + fn dsp_cos(self) -> Self; + fn dsp_floor(self) -> Self; + fn dsp_log10(self) -> Self; + fn dsp_powf(self, other: Self) -> Self; + fn dsp_round(self) -> Self; + fn dsp_sin(self) -> Self; + fn dsp_sqrt(self) -> Self; +} + +impl FloatMath for f32 { + fn dsp_acos(self) -> Self { + libm::acosf(self) + } + fn dsp_atan2(self, other: Self) -> Self { + libm::atan2f(self, other) + } + fn dsp_ceil(self) -> Self { + libm::ceilf(self) + } + fn dsp_cos(self) -> Self { + libm::cosf(self) + } + fn dsp_floor(self) -> Self { + libm::floorf(self) + } + fn dsp_log10(self) -> Self { + libm::log10f(self) + } + fn dsp_powf(self, other: Self) -> Self { + libm::powf(self, other) + } + fn dsp_round(self) -> Self { + libm::roundf(self) + } + fn dsp_sin(self) -> Self { + libm::sinf(self) + } + fn dsp_sqrt(self) -> Self { + libm::sqrtf(self) + } +} diff --git a/crates/lxst-codec2/src/native/codebook.rs b/crates/lxst-codec2/src/native/codebook.rs new file mode 100644 index 0000000..d05a248 --- /dev/null +++ b/crates/lxst-codec2/src/native/codebook.rs @@ -0,0 +1,127 @@ +use super::*; + +/* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */ + +/* + * This intermediary file and the files that used to create it are under + * The LGPL. See the file COPYING. + */ + +/* codebook/lsp1.txt */ +const codes0: [f32; 16] = [ + 225.0, 250.0, 275.0, 300.0, 325.0, 350.0, 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, + 550.0, 575.0, 600.0, +]; +/* codebook/lsp2.txt */ +const codes1: [f32; 16] = [ + 325.0, 350.0, 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, 550.0, 575.0, 600.0, 625.0, + 650.0, 675.0, 700.0, +]; +/* codebook/lsp3.txt */ +const codes2: [f32; 16] = [ + 500.0, 550.0, 600.0, 650.0, 700.0, 750.0, 800.0, 850.0, 900.0, 950.0, 1000.0, 1050.0, 1100.0, + 1150.0, 1200.0, 1250.0, +]; +/* codebook/lsp4.txt */ +const codes3: [f32; 16] = [ + 700.0, 800.0, 900.0, 1000.0, 1100.0, 1200.0, 1300.0, 1400.0, 1500.0, 1600.0, 1700.0, 1800.0, + 1900.0, 2000.0, 2100.0, 2200.0, +]; +/* codebook/lsp5.txt */ +const codes4: [f32; 16] = [ + 950.0, 1050.0, 1150.0, 1250.0, 1350.0, 1450.0, 1550.0, 1650.0, 1750.0, 1850.0, 1950.0, 2050.0, + 2150.0, 2250.0, 2350.0, 2450.0, +]; +/* codebook/lsp6.txt */ +const codes5: [f32; 16] = [ + 1100.0, 1200.0, 1300.0, 1400.0, 1500.0, 1600.0, 1700.0, 1800.0, 1900.0, 2000.0, 2100.0, 2200.0, + 2300.0, 2400.0, 2500.0, 2600.0, +]; +/* codebook/lsp7.txt */ +const codes6: [f32; 16] = [ + 1500.0, 1600.0, 1700.0, 1800.0, 1900.0, 2000.0, 2100.0, 2200.0, 2300.0, 2400.0, 2500.0, 2600.0, + 2700.0, 2800.0, 2900.0, 3000.0, +]; +/* codebook/lsp8.txt */ +const codes7: [f32; 8] = [ + 2300.0, 2400.0, 2500.0, 2600.0, 2700.0, 2800.0, 2900.0, 3000.0, +]; +/* codebook/lsp9.txt */ +const codes8: [f32; 8] = [ + 2500.0, 2600.0, 2700.0, 2800.0, 2900.0, 3000.0, 3100.0, 3200.0, +]; +/* codebook/lsp10.txt */ +const codes9: [f32; 4] = [2900.0, 3100.0, 3300.0, 3500.0]; + +pub const lsp_cb: [lsp_codebook; 10] = [ + /* codebook/lsp1.txt */ + lsp_codebook { + k: 1, + log2m: 4, + m: 16, + cb: &codes0, + }, + /* codebook/lsp2.txt */ + lsp_codebook { + k: 1, + log2m: 4, + m: 16, + cb: &codes1, + }, + /* codebook/lsp3.txt */ + lsp_codebook { + k: 1, + log2m: 4, + m: 16, + cb: &codes2, + }, + /* codebook/lsp4.txt */ + lsp_codebook { + k: 1, + log2m: 4, + m: 16, + cb: &codes3, + }, + /* codebook/lsp5.txt */ + lsp_codebook { + k: 1, + log2m: 4, + m: 16, + cb: &codes4, + }, + /* codebook/lsp6.txt */ + lsp_codebook { + k: 1, + log2m: 4, + m: 16, + cb: &codes5, + }, + /* codebook/lsp7.txt */ + lsp_codebook { + k: 1, + log2m: 4, + m: 16, + cb: &codes6, + }, + /* codebook/lsp8.txt */ + lsp_codebook { + k: 1, + log2m: 3, + m: 8, + cb: &codes7, + }, + /* codebook/lsp9.txt */ + lsp_codebook { + k: 1, + log2m: 3, + m: 8, + cb: &codes8, + }, + /* codebook/lsp10.txt */ + lsp_codebook { + k: 1, + log2m: 2, + m: 4, + cb: &codes9, + }, +]; diff --git a/crates/lxst-codec2/src/native/codebookd.rs b/crates/lxst-codec2/src/native/codebookd.rs new file mode 100644 index 0000000..816207a --- /dev/null +++ b/crates/lxst-codec2/src/native/codebookd.rs @@ -0,0 +1,143 @@ +use super::*; + +/* codebook/dlsp1.txt */ +const codes0: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 225.0, 250.0, 275.0, 300.0, 325.0, 350.0, + 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, 550.0, 575.0, 600.0, 625.0, 650.0, 675.0, + 700.0, 725.0, 750.0, 775.0, 800.0, +]; +/* codebook/dlsp2.txt */ +const codes1: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 225.0, 250.0, 275.0, 300.0, 325.0, 350.0, + 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, 550.0, 575.0, 600.0, 625.0, 650.0, 675.0, + 700.0, 725.0, 750.0, 775.0, 800.0, +]; +/* codebook/dlsp3.txt */ +const codes2: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 225.0, 250.0, 275.0, 300.0, 325.0, 350.0, + 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, 550.0, 575.0, 600.0, 625.0, 650.0, 675.0, + 700.0, 725.0, 750.0, 775.0, 800.0, +]; +/* codebook/dlsp4.txt */ +const codes3: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, + 550.0, 600.0, 650.0, 700.0, 750.0, 800.0, 850.0, 900.0, 950.0, 1000.0, 1050.0, 1100.0, 1150.0, + 1200.0, 1250.0, 1300.0, 1350.0, 1400.0, +]; +/* codebook/dlsp5.txt */ +const codes4: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, + 550.0, 600.0, 650.0, 700.0, 750.0, 800.0, 850.0, 900.0, 950.0, 1000.0, 1050.0, 1100.0, 1150.0, + 1200.0, 1250.0, 1300.0, 1350.0, 1400.0, +]; +/* codebook/dlsp6.txt */ +const codes5: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, + 550.0, 600.0, 650.0, 700.0, 750.0, 800.0, 850.0, 900.0, 950.0, 1000.0, 1050.0, 1100.0, 1150.0, + 1200.0, 1250.0, 1300.0, 1350.0, 1400.0, +]; +/* codebook/dlsp7.txt */ +const codes6: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 225.0, 250.0, 275.0, 300.0, 325.0, 350.0, + 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, 550.0, 575.0, 600.0, 625.0, 650.0, 675.0, + 700.0, 725.0, 750.0, 775.0, 800.0, +]; +/* codebook/dlsp8.txt */ +const codes7: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 225.0, 250.0, 275.0, 300.0, 325.0, 350.0, + 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, 550.0, 575.0, 600.0, 625.0, 650.0, 675.0, + 700.0, 725.0, 750.0, 775.0, 800.0, +]; +/* codebook/dlsp9.txt */ +const codes8: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 225.0, 250.0, 275.0, 300.0, 325.0, 350.0, + 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, 550.0, 575.0, 600.0, 625.0, 650.0, 675.0, + 700.0, 725.0, 750.0, 775.0, 800.0, +]; +/* codebook/dlsp10.txt */ +const codes9: [f32; 32] = [ + 25.0, 50.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 225.0, 250.0, 275.0, 300.0, 325.0, 350.0, + 375.0, 400.0, 425.0, 450.0, 475.0, 500.0, 525.0, 550.0, 575.0, 600.0, 625.0, 650.0, 675.0, + 700.0, 725.0, 750.0, 775.0, 800.0, +]; + +const codesnone: [f32; 0] = []; + +pub const lsp_cbd: [lsp_codebook; 11] = [ + /* codebook/dlsp1.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes0, + }, + /* codebook/dlsp2.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes1, + }, + /* codebook/dlsp3.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes2, + }, + /* codebook/dlsp4.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes3, + }, + /* codebook/dlsp5.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes4, + }, + /* codebook/dlsp6.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes5, + }, + /* codebook/dlsp7.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes6, + }, + /* codebook/dlsp8.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes7, + }, + /* codebook/dlsp9.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes8, + }, + /* codebook/dlsp10.txt */ + lsp_codebook { + k: 1, + log2m: 5, + m: 32, + cb: &codes9, + }, + lsp_codebook { + k: 0, + log2m: 0, + m: 0, + cb: &codesnone, + }, +]; diff --git a/crates/lxst-codec2/src/native/codebookge.rs b/crates/lxst-codec2/src/native/codebookge.rs new file mode 100644 index 0000000..0fd9073 --- /dev/null +++ b/crates/lxst-codec2/src/native/codebookge.rs @@ -0,0 +1,72 @@ +/* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */ + +/* + * This intermediary file and the files that used to create it are under + * The LGPL. See the file COPYING. + */ +use super::*; + +// codebook/gecb.txt +const codes0: [f32; 512] = [ + 2.71, 12.0184, 0.04675, -2.73881, 0.120993, 8.38895, -1.58028, -0.892307, 1.19307, -1.91561, + 0.187101, -3.27679, 0.332251, -7.66455, -1.47944, 31.2461, 1.52761, 27.7095, -0.524379, + 5.25012, 0.55333, 7.4388, -0.843451, -1.95299, 2.26389, 8.61029, 0.143143, 2.36549, 0.616506, + 1.28427, -1.71133, 22.0967, 1.00813, 17.3965, -0.106718, 1.41891, -0.136246, 14.2736, -1.70909, + -20.5319, 1.65787, -3.39107, 0.138049, -4.95785, 0.536729, -1.94375, 0.196307, 36.8519, + 1.27248, 22.5565, -0.670219, -1.90604, 0.382092, 6.40113, -0.756911, -4.90102, 1.82931, 4.6138, + 0.318794, 0.73683, 0.612815, -2.07505, -0.410151, 24.7871, 1.77602, 13.1909, 0.106457, + -0.104492, 0.192206, 10.1838, -1.82442, -7.71565, 0.931346, 4.34835, 0.308813, -4.086, + 0.397143, -11.8089, -0.048715, 41.2273, 0.877342, 35.8503, -0.759794, 0.476634, 0.978593, + 7.67467, -1.19506, 3.03883, 2.63989, -3.41106, 0.191127, 3.60351, 0.402932, 1.0843, -2.15202, + 18.1076, 1.5468, 8.32271, -0.143089, -4.07592, -0.150142, 5.86674, -1.40844, -3.2507, 1.56615, + -10.4132, 0.178171, -10.2267, 0.362164, -0.028556, -0.070125, 24.3907, 0.594752, 17.4828, + -0.28698, -6.90407, 0.464818, 10.2055, -1.00684, -14.3572, 2.32957, -3.69161, 0.335745, + 2.40714, 1.01966, -3.15565, -1.25945, 7.9919, 2.38369, 19.6806, -0.094947, -2.41374, 0.20933, + 6.66477, -2.22103, 1.37986, 1.29239, 2.04633, 0.243626, -0.890741, 0.428773, -7.19366, + -1.11374, 41.3414, 2.6098, 31.1405, -0.446468, 2.53419, 0.490104, 4.62757, -1.11723, -3.24174, + 1.79156, 8.41493, 0.156012, 0.183336, 0.532447, 3.15455, -0.764484, 18.514, 0.952395, 11.7713, + -0.332567, 0.346987, 0.202165, 14.7168, -2.12924, -15.559, 1.35358, -1.92679, -0.010963, + -16.3364, 0.399053, -2.79057, 0.750657, 31.1483, 0.655743, 24.4819, -0.45321, -0.735879, + 0.2869, 6.5467, -0.715673, -12.3578, 1.54849, 3.87217, 0.271874, 0.802339, 0.502073, -4.85485, + -0.497037, 17.7619, 1.19116, 13.9544, 0.01563, 1.33157, 0.341867, 8.93537, -2.31601, -5.39506, + 0.75861, 1.9645, 0.24132, -3.23769, 0.267151, -11.2344, -0.273126, 32.6248, 1.75352, 40.432, + -0.784011, 3.04576, 0.705987, 5.66118, -1.3864, 1.35356, 2.37646, 1.67485, 0.242973, 4.73218, + 0.491227, 0.354061, -1.60676, 8.65895, 1.16711, 5.9871, -0.137601, -12.0417, -0.251375, + 10.3972, -1.43151, -8.90411, 0.98828, -13.209, 0.261484, -6.35497, 0.395932, -0.702529, + 0.283704, 26.8996, 0.420959, 15.4418, -0.355804, -13.7278, 0.527372, 12.3985, -1.16956, + -15.9985, 1.90669, -5.81605, 0.354492, 3.85157, 0.82576, -4.16264, -0.49019, 13.0572, 2.25577, + 13.5264, -0.004956, -3.23713, 0.026709, 7.86645, -1.81037, -0.451183, 1.08383, -0.18362, + 0.135836, -2.26658, 0.375812, -5.51225, -1.96644, 38.6829, 1.97799, 24.5655, -0.704656, + 6.35881, 0.480786, 7.05175, -0.976417, -2.42273, 2.50215, 6.75935, 0.083588, 3.2588, 0.543629, + 0.910013, -1.23196, 23.0915, 0.785492, 14.807, -0.213554, 1.688, 0.004748, 18.1718, -1.54719, + -16.1168, 1.50104, -3.28114, 0.080133, -4.63472, 0.476592, -2.18093, 0.44247, 40.304, 1.07277, + 27.592, -0.594738, -4.16681, 0.42248, 7.61609, -0.927521, -7.27441, 1.99162, 1.29636, 0.291307, + 2.39878, 0.721081, -1.95062, -0.804256, 24.9295, 1.64839, 19.1197, 0.060852, -0.590639, + 0.266085, 9.10325, -1.9574, -2.88461, 1.11693, 2.6724, 0.35458, -2.74854, 0.330733, -14.1561, + -0.527851, 39.5756, 0.991152, 43.195, -0.589619, 1.26919, 0.787401, 8.73071, -1.0138, 1.02507, + 2.8254, 1.89538, 0.24089, 2.74557, 0.427195, 2.54446, -1.95311, 12.244, 1.44862, 12.0607, + -0.210492, -3.37906, -0.056713, 10.204, -1.65237, -5.10274, 1.29475, -12.2708, 0.111608, + -8.67592, 0.326634, -1.16763, 0.021781, 31.1258, 0.455335, 21.4684, -0.37544, -3.37121, + 0.39362, 11.302, -0.851456, -19.4149, 2.10703, -2.22886, 0.373233, 1.92406, 0.884438, -1.72058, + -0.975127, 9.84013, 2.0033, 17.3954, -0.036915, -1.11137, 0.148456, 5.39997, -1.91441, 4.77382, + 1.44791, 0.537122, 0.194979, -1.03818, 0.495771, -9.95502, -1.05899, 32.9471, 2.01122, 32.4544, + -0.30965, 4.71911, 0.436082, 4.63552, -1.23711, -1.25428, 2.02274, 9.42834, 0.190342, 1.46077, + 0.479017, 2.48479, -1.07848, 16.2217, 1.20764, 9.65421, -0.258087, -1.67236, 0.071852, 13.416, + -1.87723, -16.072, 1.28957, -4.87118, 0.067713, -13.4427, 0.435551, -4.1655, 0.46614, 30.5895, + 0.904895, 21.598, -0.518369, -2.53205, 0.337363, 5.63726, -0.554975, -17.4005, 1.69188, + 1.14574, 0.227934, 0.889297, 0.587303, -5.72973, -0.262133, 18.6666, 1.39505, 17.0029, + -0.01909, 4.30838, 0.304235, 12.6699, -2.07406, -6.46084, 0.920546, 1.21296, 0.284927, + -1.78547, 0.209724, -16.024, -0.636067, 31.5768, 1.34989, 34.6775, -0.971625, 5.30086, + 0.590249, 4.44971, -1.56787, 3.60239, 2.1455, 4.51666, 0.296022, 4.12017, 0.445299, 0.868772, + -1.44193, 14.1284, 1.35575, 6.0074, -0.012814, -7.49657, -0.43, 8.50012, -1.20469, -7.11326, + 1.10102, -6.83682, 0.196463, -6.234, 0.436747, -1.12979, 0.141052, 22.8549, 0.290821, 18.8114, + -0.529536, -7.73251, 0.63428, 10.7898, -1.33472, -20.3258, 1.81564, -1.90332, 0.394778, + 3.79758, 0.732682, -8.18382, -0.741244, 11.7683, +]; + +pub const ge_cb: [lsp_codebook; 1] = [lsp_codebook { + k: 2, + log2m: 8, + m: 256, + cb: &codes0, +}]; diff --git a/crates/lxst-codec2/src/native/codebookjvm.rs b/crates/lxst-codec2/src/native/codebookjvm.rs new file mode 100644 index 0000000..ff90c96 --- /dev/null +++ b/crates/lxst-codec2/src/native/codebookjvm.rs @@ -0,0 +1,1134 @@ +/* THIS IS A GENERATED FILE. Edit generate_codebook.c and its input */ + +/* + * This intermediary file and the files that used to create it are under + * The LGPL. See the file COPYING. + */ +use super::*; + +/* codebook/lspjvm1.txt */ +const codes0: [f32; 5120] = [ + 0.435217, 0.668864, 1.0103, 1.22042, 1.50398, 1.78468, 2.13546, 2.35747, 2.61891, 2.73804, + 0.179285, 0.33316, 0.500638, 0.79695, 1.03999, 1.23497, 1.6523, 1.84823, 2.62556, 2.80497, + 0.268785, 0.356576, 0.595753, 1.04434, 1.24938, 1.42868, 1.68699, 1.86469, 2.33991, 2.5138, + 0.12007, 0.165585, 0.484694, 0.95916, 1.23753, 1.52915, 1.83751, 2.10773, 2.48749, 2.76685, + 0.150214, 0.229487, 0.62824, 0.961255, 1.33706, 1.59831, 1.91974, 2.21786, 2.53732, 2.75956, + 0.268624, 0.34598, 0.569637, 0.754737, 0.916538, 1.50854, 1.78635, 1.95442, 2.36953, 2.50182, + 0.246064, 0.468874, 0.662711, 0.890015, 1.14715, 1.51043, 1.78106, 2.09594, 2.65539, 2.80037, + 0.191631, 0.280628, 0.393229, 0.611761, 1.42017, 1.70774, 1.87303, 2.10155, 2.28035, 2.49949, + 0.361668, 0.507047, 0.789974, 1.04599, 1.50238, 1.67703, 1.90534, 2.16255, 2.43226, 2.59087, + 0.20816, 0.294285, 0.448634, 0.694229, 0.872517, 1.07032, 1.70335, 2.16874, 2.42619, 2.60366, + 0.316939, 0.513618, 0.705487, 0.917036, 1.17599, 1.31114, 1.6186, 2.03784, 2.45052, 2.5794, + 0.241068, 0.377728, 0.521595, 0.717203, 1.31041, 1.53999, 1.73643, 2.09893, 2.29792, 2.58735, + 0.234937, 0.281875, 0.780422, 1.44073, 1.60943, 1.75643, 1.97721, 2.14861, 2.60203, 2.7225, + 0.178679, 0.242672, 0.416988, 0.708348, 0.95562, 1.17667, 1.7818, 2.05449, 2.28159, 2.44811, + 0.345036, 0.42108, 0.740887, 1.16544, 1.32494, 1.4888, 1.76346, 1.90617, 2.39505, 2.64916, + 0.249586, 0.357494, 0.520747, 0.847195, 1.42841, 1.59778, 1.77819, 2.1785, 2.41344, 2.56466, + 0.295235, 0.574231, 1.2491, 1.4641, 1.72756, 1.92679, 2.09536, 2.28483, 2.56707, 2.72248, + 0.34193, 0.427307, 0.634001, 0.804212, 0.905629, 1.33337, 1.79033, 1.89276, 2.44582, 2.60283, + 0.363948, 0.508985, 0.667357, 0.946354, 1.43756, 1.62654, 1.81114, 2.03909, 2.29188, 2.43549, + 0.163514, 0.277407, 0.409207, 0.902065, 1.18907, 1.33964, 1.80241, 1.96077, 2.65293, 2.81899, + 0.302643, 0.359753, 0.651207, 1.20802, 1.4237, 1.54815, 1.88213, 2.01559, 2.26054, 2.5789, + 0.155928, 0.216908, 0.381812, 0.654803, 1.11237, 1.58993, 1.84756, 1.97672, 2.22408, 2.72534, + 0.274981, 0.347675, 0.572, 0.736046, 0.894248, 1.63237, 1.89139, 2.05689, 2.6029, 2.72178, + 0.154496, 0.243461, 0.348174, 0.689505, 1.57381, 1.70031, 1.94318, 2.10158, 2.56466, 2.77317, + 0.292612, 0.466612, 0.795936, 1.04747, 1.41369, 1.75085, 2.06289, 2.34007, 2.61361, 2.76949, + 0.242896, 0.3615, 0.555859, 0.793597, 0.932291, 1.40947, 1.86386, 2.00953, 2.4645, 2.67749, + 0.221646, 0.344724, 0.554564, 0.729403, 1.13657, 1.30177, 1.52918, 2.16359, 2.39582, 2.61081, + 0.160969, 0.224467, 0.371545, 0.626879, 1.16095, 1.44423, 1.67597, 1.87978, 2.47859, 2.67202, + 0.214172, 0.341585, 0.676575, 0.977397, 1.32543, 1.7201, 2.07259, 2.36954, 2.63528, 2.77879, + 0.203311, 0.289438, 0.458739, 0.914153, 1.12288, 1.30292, 1.58384, 1.88683, 2.18787, 2.42704, + 0.280383, 0.3716, 0.824827, 1.10025, 1.23623, 1.39892, 1.57804, 2.016, 2.36897, 2.50673, + 0.170627, 0.251778, 0.393686, 0.608347, 1.2876, 1.44667, 1.79328, 2.03655, 2.31015, 2.75244, + 0.18058, 0.288746, 0.987854, 1.43171, 1.67722, 1.91566, 2.12494, 2.28945, 2.58961, 2.75426, + 0.176335, 0.266263, 0.445421, 0.706403, 0.875402, 1.42292, 1.75867, 1.96091, 2.41068, 2.60175, + 0.216173, 0.287404, 0.480696, 1.00977, 1.2913, 1.47664, 1.89558, 2.06429, 2.28406, 2.48311, + 0.176523, 0.273934, 0.403407, 0.966139, 1.30472, 1.43661, 1.94473, 2.08484, 2.54446, 2.76242, + 0.311836, 0.550501, 0.879591, 1.09623, 1.27666, 1.47786, 1.81771, 2.15434, 2.56047, 2.77984, + 0.179765, 0.25056, 0.455939, 1.02389, 1.22513, 1.47566, 1.73462, 1.91871, 2.14734, 2.43824, + 0.271033, 0.457235, 0.599622, 0.821049, 0.940125, 1.20094, 1.84972, 1.98666, 2.54817, 2.75158, + 0.179326, 0.248002, 0.426405, 0.81706, 1.28589, 1.56502, 2.11736, 2.29871, 2.5724, 2.7527, + 0.374409, 0.535936, 0.897009, 1.18507, 1.59157, 1.7572, 1.96794, 2.17999, 2.45739, 2.62264, + 0.185472, 0.282752, 0.409439, 0.657499, 0.856446, 1.0294, 1.87993, 2.06932, 2.34474, 2.7531, + 0.375964, 0.578457, 0.758945, 0.929339, 1.12748, 1.25944, 1.70411, 2.12297, 2.33603, 2.4983, + 0.225641, 0.36103, 0.501679, 0.783379, 1.31485, 1.45262, 1.71415, 1.98716, 2.2257, 2.72436, + 0.144996, 0.252919, 0.632145, 1.22604, 1.57534, 1.90155, 2.17148, 2.39055, 2.68229, 2.80983, + 0.172022, 0.263338, 0.448634, 0.729435, 0.984007, 1.1716, 1.75705, 1.99023, 2.32131, 2.77121, + 0.235731, 0.351117, 0.796871, 1.05571, 1.30022, 1.59182, 1.89587, 2.12292, 2.41789, 2.59982, + 0.254053, 0.319371, 0.455623, 1.08614, 1.66467, 1.91588, 2.05908, 2.23342, 2.45204, 2.58679, + 0.375538, 0.742993, 1.13991, 1.33776, 1.73556, 2.01391, 2.31501, 2.48343, 2.65158, 2.75521, + 0.247245, 0.481131, 0.710366, 0.897602, 1.12109, 1.27171, 1.78735, 2.1995, 2.42966, 2.74067, + 0.226103, 0.311441, 0.501648, 0.844424, 1.36282, 1.53134, 1.77747, 1.98993, 2.18749, 2.3585, + 0.195862, 0.296224, 0.609554, 0.783241, 1.24347, 1.44548, 1.63703, 2.02264, 2.48356, 2.64614, + 0.233302, 0.299441, 0.472792, 1.24946, 1.45788, 1.60186, 1.83143, 1.99372, 2.59719, 2.75543, + 0.168096, 0.224183, 0.3827, 0.596214, 1.06059, 1.29442, 1.60576, 1.84849, 2.3577, 2.56919, + 0.33005, 0.445912, 0.661713, 0.874446, 1.00079, 1.45297, 1.94399, 2.07692, 2.42388, 2.61236, + 0.226382, 0.287303, 0.517631, 0.806229, 1.30901, 1.88528, 2.16051, 2.28641, 2.52638, 2.66082, + 0.20317, 0.499314, 0.887358, 1.23507, 1.46292, 1.69826, 1.99932, 2.22922, 2.57161, 2.76669, + 0.307531, 0.378353, 0.573606, 0.712218, 0.850169, 1.309, 2.05909, 2.26382, 2.49794, 2.67682, + 0.276203, 0.51025, 0.6868, 0.902844, 1.2052, 1.32798, 1.71889, 2.03895, 2.25639, 2.69715, + 0.161948, 0.229115, 0.393619, 0.683613, 1.13781, 1.32269, 1.78372, 1.96158, 2.38907, 2.63608, + 0.201334, 0.276773, 0.468994, 0.967017, 1.47597, 1.63242, 1.96577, 2.19728, 2.48059, 2.70155, + 0.214587, 0.315421, 0.469498, 0.733397, 1.146, 1.27791, 1.72784, 2.22713, 2.44026, 2.68112, + 0.255602, 0.394609, 0.743393, 0.977796, 1.19908, 1.40597, 1.91834, 2.22483, 2.47919, 2.66339, + 0.245989, 0.352625, 0.517055, 0.80283, 1.55871, 1.79565, 1.94405, 2.13364, 2.33327, 2.47998, + 0.337423, 0.480433, 0.869036, 1.13957, 1.63076, 1.82296, 2.07484, 2.29261, 2.47913, 2.62532, + 0.220974, 0.35885, 0.57164, 0.752791, 0.937013, 1.15172, 1.6744, 2.06247, 2.55872, 2.78484, + 0.267518, 0.331708, 0.541111, 1.11655, 1.41112, 1.53287, 1.79295, 1.93352, 2.24894, 2.62864, + 0.084613, 0.105083, 0.297424, 0.916949, 1.2563, 1.56703, 1.88539, 2.18987, 2.52279, 2.7921, + 0.205328, 0.287223, 0.724462, 1.0324, 1.45771, 1.64217, 1.92563, 2.17552, 2.42964, 2.60549, + 0.232554, 0.338724, 0.502115, 0.859975, 1.04409, 1.24565, 1.80656, 1.99964, 2.26116, 2.45998, + 0.291638, 0.379172, 0.626072, 0.792796, 0.959124, 1.50489, 1.73447, 1.91961, 2.61436, 2.72271, + 0.191554, 0.263114, 0.426797, 0.610628, 1.07741, 1.82954, 2.02195, 2.21057, 2.42765, 2.61383, + 0.389151, 0.679476, 0.915414, 1.03664, 1.25085, 1.58661, 2.04097, 2.2815, 2.56794, 2.71882, + 0.2032, 0.30128, 0.470357, 0.668716, 0.851737, 0.980327, 1.57086, 2.03762, 2.28907, 2.69388, + 0.304064, 0.405934, 0.710274, 0.962705, 1.12882, 1.34167, 1.63505, 1.84538, 2.07992, 2.50751, + 0.171777, 0.240705, 0.409371, 0.786432, 1.2232, 1.37569, 1.69176, 1.86608, 2.35041, 2.49394, + 0.231251, 0.277994, 0.557867, 1.32582, 1.66035, 1.77948, 2.00714, 2.17232, 2.44046, 2.65231, + 0.188101, 0.259494, 0.412543, 0.624843, 0.839549, 1.0337, 1.63413, 1.93194, 2.24608, 2.42577, + 0.361304, 0.419465, 0.795676, 1.18461, 1.2968, 1.57845, 1.84175, 1.99736, 2.54054, 2.68714, + 0.274372, 0.338938, 0.492443, 0.963516, 1.50951, 1.70638, 1.86988, 2.07717, 2.26128, 2.44418, + 0.41599, 0.652103, 1.03129, 1.26955, 1.57275, 1.77297, 2.00466, 2.17527, 2.43061, 2.59655, + 0.242045, 0.370942, 0.534392, 0.763529, 1.00117, 1.12976, 1.68219, 2.14464, 2.32448, 2.7157, + 0.377438, 0.588168, 0.765394, 0.976873, 1.35665, 1.49009, 1.73797, 2.00677, 2.21369, 2.38997, + 0.191625, 0.284123, 0.405342, 1.01678, 1.43273, 1.54759, 1.81393, 1.95832, 2.47077, 2.64926, + 0.272672, 0.349555, 0.633911, 1.15223, 1.30394, 1.54764, 1.9195, 2.0477, 2.56278, 2.73058, + 0.168423, 0.23633, 0.421468, 0.831345, 1.08354, 1.55345, 1.88073, 2.0647, 2.37086, 2.63295, + 0.219318, 0.301481, 0.513617, 0.765086, 1.02602, 1.51465, 2.0482, 2.24857, 2.49981, 2.65707, + 0.232695, 0.347947, 0.495203, 0.71883, 1.42301, 1.72249, 1.87958, 2.16504, 2.42025, 2.58966, + 0.270284, 0.336865, 0.684929, 1.15579, 1.69042, 1.87674, 2.02736, 2.22618, 2.44675, 2.582, + 0.149701, 0.193747, 0.352019, 0.520123, 0.823974, 1.43475, 1.68659, 1.96115, 2.37091, 2.69307, + 0.254818, 0.412303, 0.601514, 0.771438, 1.17545, 1.37657, 1.53903, 1.93704, 2.40858, 2.56362, + 0.233713, 0.355886, 0.593725, 0.76288, 1.27148, 1.5639, 1.79752, 2.09469, 2.53863, 2.71173, + 0.179028, 0.237103, 0.396818, 1.04202, 1.63354, 1.76268, 2.12393, 2.32239, 2.58819, 2.75134, + 0.182027, 0.251039, 0.434581, 0.714302, 0.950997, 1.4379, 1.81357, 1.9691, 2.14588, 2.35397, + 0.501538, 0.692148, 0.84886, 1.07131, 1.35054, 1.48948, 1.84164, 2.10428, 2.34154, 2.51529, + 0.27453, 0.38147, 0.526682, 0.922143, 1.44495, 1.5736, 1.85877, 2.06675, 2.2848, 2.62682, + 0.360617, 0.583131, 0.979491, 1.25408, 1.48835, 1.79756, 2.21952, 2.48218, 2.74237, 2.86203, + 0.140913, 0.220301, 0.619552, 0.818307, 1.05243, 1.33997, 1.83073, 2.13395, 2.53638, 2.75113, + 0.293514, 0.391691, 0.79008, 0.96274, 1.16032, 1.5266, 1.80549, 2.04146, 2.36162, 2.56496, + 0.199542, 0.290571, 0.452891, 0.689515, 1.25853, 1.40988, 1.88624, 2.22813, 2.46568, 2.72665, + 0.29692, 0.356356, 0.784287, 0.99654, 1.14618, 1.62387, 1.8155, 2.0383, 2.60063, 2.7057, + 0.206451, 0.276025, 0.537547, 0.802572, 1.22041, 1.64206, 1.86363, 2.00198, 2.21534, 2.58538, + 0.33365, 0.464751, 0.653772, 0.966306, 1.10387, 1.3402, 1.7847, 1.91459, 2.47017, 2.68692, + 0.181861, 0.24487, 0.376456, 0.554383, 1.3299, 1.81044, 2.04784, 2.20232, 2.66086, 2.81706, + 0.450565, 0.647291, 0.951172, 1.22943, 1.51964, 1.68681, 2.04911, 2.26717, 2.50128, 2.6506, + 0.219996, 0.320591, 0.427747, 0.601183, 0.753448, 0.929578, 1.74198, 2.28579, 2.47263, 2.74957, + 0.333848, 0.423373, 0.658791, 1.0313, 1.22263, 1.36577, 1.90189, 2.1211, 2.29031, 2.53118, + 0.166064, 0.233902, 0.383355, 0.661806, 1.22657, 1.39968, 1.77127, 1.97454, 2.17349, 2.56634, + 0.189286, 0.243602, 0.390584, 1.38793, 1.58872, 1.76324, 2.09112, 2.31631, 2.59353, 2.75508, + 0.158404, 0.224878, 0.385, 0.668463, 0.942954, 1.41197, 1.70031, 1.82807, 2.0594, 2.69255, + 0.325989, 0.461263, 0.851471, 1.04571, 1.28403, 1.5162, 1.79734, 2.08839, 2.43767, 2.62721, + 0.223709, 0.28919, 0.632812, 0.858738, 1.5419, 1.74677, 1.93574, 2.18482, 2.40433, 2.58301, + 0.545842, 0.95242, 1.34082, 1.51684, 1.83888, 2.01289, 2.24497, 2.40317, 2.59228, 2.69112, + 0.238526, 0.349079, 0.494582, 0.987665, 1.17075, 1.34823, 1.46864, 2.29696, 2.64416, 2.78738, + 0.270857, 0.442003, 0.655998, 0.881913, 1.25925, 1.42836, 1.76987, 1.99853, 2.39559, 2.65284, + 0.154384, 0.211806, 0.489481, 0.997257, 1.24982, 1.54123, 1.77886, 1.9494, 2.31914, 2.62339, + 0.268258, 0.312888, 0.589114, 1.25863, 1.57271, 1.67543, 1.91278, 2.07046, 2.27993, 2.56423, + 0.170715, 0.224965, 0.374011, 0.540197, 1.16189, 1.49907, 1.92587, 2.08257, 2.24662, 2.46972, + 0.324358, 0.391989, 0.706816, 0.833614, 1.01573, 1.56899, 1.73598, 2.12707, 2.55841, 2.65387, + 0.178059, 0.258575, 0.374125, 0.536831, 1.33483, 1.79863, 1.98698, 2.18925, 2.43227, 2.6267, + 0.198857, 0.420955, 0.817664, 1.17836, 1.46674, 1.8213, 2.20733, 2.47441, 2.73828, 2.85119, + 0.188344, 0.324302, 0.470468, 0.790033, 0.934101, 1.18872, 1.88717, 2.05283, 2.44832, 2.63024, + 0.201295, 0.365646, 0.526513, 0.758388, 1.1401, 1.26733, 1.65017, 1.87934, 2.10289, 2.60029, + 0.135058, 0.169428, 0.307348, 0.50316, 1.01808, 1.44795, 1.81098, 2.134, 2.48028, 2.75985, + 0.178006, 0.26661, 0.390327, 0.928681, 1.50161, 1.62133, 1.87136, 2.02586, 2.58044, 2.7708, + 0.246182, 0.42429, 0.644023, 0.801168, 1.11488, 1.27776, 1.50332, 2.07489, 2.2957, 2.50138, + 0.322996, 0.430355, 0.6316, 1.0477, 1.22184, 1.42673, 1.90308, 2.03222, 2.51673, 2.70845, + 0.292994, 0.430599, 0.619178, 0.794567, 1.28303, 1.65282, 1.84084, 2.06995, 2.38538, 2.52825, + 0.525494, 0.787797, 1.12182, 1.38748, 1.67457, 1.93622, 2.22404, 2.39062, 2.63428, 2.74323, + 0.299504, 0.409196, 0.602235, 0.892336, 1.05643, 1.25377, 1.48914, 1.63988, 2.42748, 2.65037, + 0.423758, 0.52048, 0.758987, 1.04126, 1.17366, 1.42368, 1.81824, 1.93641, 2.363, 2.62664, + 0.155042, 0.247496, 0.641445, 0.954509, 1.22497, 1.46585, 1.83784, 2.09046, 2.4515, 2.71616, + 0.251949, 0.421094, 0.706797, 0.975659, 1.25991, 1.52007, 1.81631, 2.12202, 2.47491, 2.71667, + 0.21522, 0.302248, 0.730598, 0.896343, 1.14557, 1.37019, 1.70069, 2.02256, 2.28327, 2.48922, + 0.28523, 0.453559, 0.66367, 0.861526, 1.0116, 1.24742, 1.65598, 1.86129, 2.57894, 2.73133, + 0.162067, 0.219409, 0.373433, 0.544669, 1.1033, 1.59718, 1.92104, 2.1434, 2.4065, 2.66048, + 0.342367, 0.511499, 0.93135, 1.16322, 1.39365, 1.61115, 1.97277, 2.19442, 2.47077, 2.64926, + 0.25101, 0.364125, 0.560956, 0.746545, 1.01984, 1.17072, 1.53295, 2.28867, 2.57709, 2.72307, + 0.315001, 0.489412, 0.720682, 0.877607, 1.09047, 1.25385, 1.44822, 1.92295, 2.25589, 2.40863, + 0.174666, 0.235793, 0.387644, 0.554402, 1.23109, 1.45614, 1.68803, 2.12745, 2.36703, 2.59727, + 0.215113, 0.341915, 1.04372, 1.32275, 1.49541, 1.74189, 1.96116, 2.23982, 2.5449, 2.70394, + 0.219852, 0.30177, 0.513912, 0.705474, 0.87754, 1.2959, 1.699, 1.98706, 2.28797, 2.49697, + 0.290638, 0.366442, 0.655155, 1.04499, 1.17215, 1.53254, 1.80079, 1.94893, 2.50968, 2.66005, + 0.232252, 0.31377, 0.658552, 0.941977, 1.46317, 1.66549, 1.86246, 2.02784, 2.53402, 2.70124, + 0.326539, 0.552681, 1.12173, 1.33138, 1.52007, 1.86708, 2.08286, 2.33247, 2.60604, 2.73709, + 0.190254, 0.340428, 0.492777, 0.739738, 0.895461, 1.07937, 1.64316, 1.79529, 2.49182, 2.72938, + 0.283586, 0.41844, 0.587306, 0.870866, 1.41855, 1.57703, 1.7995, 2.0694, 2.27448, 2.4381, + 0.235752, 0.35765, 0.502891, 1.01243, 1.25885, 1.40779, 1.82006, 1.95583, 2.5059, 2.73433, + 0.278412, 0.343137, 0.849977, 1.2329, 1.3505, 1.59063, 1.78752, 2.09158, 2.54136, 2.66386, + 0.162966, 0.243159, 0.439238, 0.684821, 0.887783, 1.4629, 1.88174, 2.04425, 2.28939, 2.705, + 0.235063, 0.371799, 0.57821, 0.752199, 1.00855, 1.47628, 1.80491, 2.2714, 2.65504, 2.78965, + 0.154939, 0.223696, 0.344718, 0.667555, 1.49566, 1.66944, 2.06988, 2.30721, 2.62769, 2.81134, + 0.239702, 0.335917, 0.716616, 1.1318, 1.45251, 1.63913, 2.10552, 2.27982, 2.50203, 2.66922, + 0.226818, 0.331261, 0.472705, 0.651974, 0.781639, 1.2198, 1.8229, 2.08273, 2.43933, 2.6109, + 0.223413, 0.359594, 0.534704, 0.741518, 1.22589, 1.38987, 1.61819, 2.00991, 2.207, 2.45984, + 0.171308, 0.268378, 0.383799, 0.858926, 1.37629, 1.51917, 1.7806, 1.92291, 2.62309, 2.8024, + 0.140134, 0.21232, 0.443224, 0.967457, 1.26424, 1.56215, 1.92915, 2.21739, 2.66834, 2.83075, + 0.221323, 0.322124, 0.485563, 0.818589, 1.01184, 1.19898, 1.42362, 1.6694, 2.15752, 2.36319, + 0.369687, 0.525655, 0.719213, 0.939654, 1.13763, 1.31222, 1.59994, 1.82681, 2.35522, 2.58068, + 0.211975, 0.314411, 0.489148, 0.739213, 1.3778, 1.5545, 1.82437, 2.15887, 2.35299, 2.72262, + 0.170698, 0.296368, 0.934285, 1.24313, 1.5559, 1.86654, 2.15994, 2.36344, 2.58503, 2.73853, + 0.189263, 0.305887, 0.439912, 0.78461, 1.22726, 1.34251, 1.58765, 1.75491, 2.43989, 2.72131, + 0.296339, 0.385169, 0.612012, 1.08132, 1.27636, 1.43718, 1.87147, 2.00172, 2.33909, 2.64022, + 0.229588, 0.320544, 0.517278, 0.969137, 1.14256, 1.62609, 1.87792, 2.11546, 2.54674, 2.70802, + 0.248869, 0.420193, 0.732388, 1.04902, 1.30341, 1.60146, 1.94921, 2.23946, 2.64822, 2.82261, + 0.2076, 0.29232, 0.496539, 0.857149, 1.18229, 1.39985, 1.71416, 1.86824, 2.02794, 2.20074, + 0.225558, 0.396897, 0.541783, 0.873366, 1.17897, 1.29958, 1.67719, 1.8496, 2.33048, 2.75272, + 0.176821, 0.231377, 0.372767, 0.508565, 1.15282, 1.80805, 2.11268, 2.25007, 2.57134, 2.74855, + 0.352149, 0.515765, 1.02324, 1.26022, 1.44357, 1.62207, 1.8728, 2.10018, 2.48928, 2.67104, + 0.166138, 0.263444, 0.370151, 0.590066, 0.754819, 0.940533, 1.76187, 1.94661, 2.44501, 2.75819, + 0.342082, 0.476411, 0.656223, 0.851774, 1.00399, 1.15337, 1.6944, 2.06562, 2.25564, 2.44015, + 0.227237, 0.376514, 0.514329, 0.894887, 1.14167, 1.28305, 1.83138, 1.9859, 2.33447, 2.78488, + 0.215891, 0.269548, 0.684111, 1.40566, 1.67481, 1.80093, 2.17209, 2.3394, 2.59157, 2.7301, + 0.23624, 0.400377, 0.533684, 0.750343, 0.910405, 1.08911, 1.73773, 1.91281, 2.19252, 2.68873, + 0.169242, 0.284879, 0.916252, 1.16977, 1.43368, 1.64438, 1.91912, 2.16162, 2.48266, 2.68259, + 0.270731, 0.336506, 0.477594, 1.04271, 1.60584, 1.79686, 1.94591, 2.16004, 2.35491, 2.52095, + 0.420586, 0.652563, 1.11716, 1.40601, 1.74754, 1.94742, 2.20309, 2.35997, 2.5479, 2.68217, + 0.281552, 0.395037, 0.640181, 0.944531, 1.19396, 1.33049, 1.71866, 2.18839, 2.44459, 2.57867, + 0.311824, 0.476892, 0.633431, 0.845825, 1.33252, 1.49166, 1.69361, 2.04108, 2.28932, 2.4394, + 0.133945, 0.20079, 0.647237, 0.927687, 1.18888, 1.36966, 1.69956, 1.97278, 2.29526, 2.67818, + 0.204796, 0.278215, 0.443465, 1.27048, 1.40521, 1.64092, 1.82425, 2.32709, 2.59964, 2.77253, + 0.18397, 0.244116, 0.410594, 0.639103, 1.22159, 1.40487, 1.62836, 1.90244, 2.16863, 2.3068, + 0.343622, 0.434735, 0.666599, 0.868069, 1.04894, 1.53278, 1.81983, 1.97188, 2.2887, 2.44875, + 0.238017, 0.320361, 0.657255, 0.917611, 1.30331, 1.72736, 1.98891, 2.18145, 2.44297, 2.61332, + 0.323613, 0.545056, 0.930173, 1.22606, 1.44018, 1.7723, 2.05689, 2.34781, 2.68938, 2.82062, + 0.28893, 0.401387, 0.617124, 0.836453, 0.990306, 1.26123, 1.91328, 2.11005, 2.32458, 2.55716, + 0.33267, 0.480804, 0.656147, 0.880536, 1.02957, 1.23049, 1.76906, 1.9323, 2.20037, 2.58521, + 0.185551, 0.265352, 0.409432, 0.608847, 1.0347, 1.22282, 1.87697, 2.17165, 2.4035, 2.66644, + 0.155026, 0.223348, 0.401684, 1.07914, 1.41579, 1.62002, 2.04552, 2.25851, 2.63162, 2.80229, + 0.183461, 0.263081, 0.425694, 0.635685, 1.18866, 1.35756, 1.57499, 2.08598, 2.28872, 2.51111, + 0.314738, 0.463011, 0.648733, 0.877651, 1.00289, 1.26581, 2.00541, 2.1981, 2.48153, 2.71418, + 0.244411, 0.318444, 0.546578, 0.793615, 1.32615, 1.73548, 1.9456, 2.11466, 2.31535, 2.47853, + 0.326237, 0.54354, 0.987361, 1.30441, 1.68493, 1.90215, 2.20717, 2.37427, 2.55753, 2.71622, + 0.157795, 0.283302, 0.430398, 0.660379, 0.81106, 1.14254, 1.4793, 1.71871, 2.67026, 2.84756, + 0.220856, 0.283872, 0.779935, 1.07494, 1.31221, 1.62633, 1.83761, 1.96888, 2.15599, 2.60238, + 0.140763, 0.205719, 0.406561, 0.762459, 1.04127, 1.48699, 1.83831, 2.11461, 2.55281, 2.77228, + 0.140451, 0.39592, 0.79211, 1.108, 1.40264, 1.62308, 1.94315, 2.22795, 2.54616, 2.774, + 0.229862, 0.336462, 0.54659, 0.81015, 1.20191, 1.34679, 1.82532, 2.09293, 2.28573, 2.47336, + 0.224913, 0.328246, 0.517269, 0.874793, 1.01259, 1.45218, 1.69578, 2.01493, 2.51145, 2.67257, + 0.247745, 0.335741, 0.546558, 0.710177, 1.17056, 1.72779, 1.97068, 2.15853, 2.48282, 2.62891, + 0.398252, 0.555087, 0.890367, 1.1212, 1.38153, 1.60123, 1.86665, 2.06661, 2.40516, 2.58802, + 0.198563, 0.288867, 0.478054, 0.658477, 0.851841, 1.0271, 1.53974, 2.02111, 2.57946, 2.78418, + 0.304271, 0.371642, 0.66159, 1.06898, 1.22425, 1.41193, 1.68052, 1.86977, 2.10007, 2.30855, + 0.188223, 0.257939, 0.432402, 0.73505, 1.31804, 1.48553, 1.82811, 2.04644, 2.30702, 2.45724, + 0.246723, 0.297276, 0.604475, 1.3109, 1.57044, 1.68885, 1.91366, 2.05133, 2.55601, 2.71497, + 0.158309, 0.234509, 0.435792, 0.6679, 0.957567, 1.23592, 1.59294, 1.81816, 2.30739, 2.76897, + 0.419843, 0.501412, 0.766892, 1.07317, 1.18937, 1.48022, 1.7666, 1.92215, 2.53794, 2.69477, + 0.27514, 0.335563, 0.678421, 1.08152, 1.59238, 1.77263, 1.93124, 2.1407, 2.3338, 2.49086, + 0.372056, 0.856814, 1.23954, 1.40999, 1.6903, 1.86302, 2.0727, 2.27355, 2.53266, 2.69052, + 0.321254, 0.422981, 0.604856, 0.793437, 0.912112, 1.12845, 1.79598, 2.17323, 2.36015, 2.53614, + 0.395214, 0.598779, 0.771997, 0.946713, 1.21378, 1.33043, 1.66033, 1.97715, 2.16506, 2.34402, + 0.225286, 0.317828, 0.464801, 1.11233, 1.36951, 1.512, 1.92195, 2.05341, 2.59352, 2.77729, + 0.330612, 0.407807, 0.730129, 1.25973, 1.45981, 1.60567, 1.98131, 2.13701, 2.46597, 2.67972, + 0.213145, 0.305305, 0.507016, 0.662299, 1.05685, 1.47986, 1.6719, 2.10271, 2.36987, 2.58199, + 0.219658, 0.296096, 0.443507, 0.610973, 0.799691, 1.67658, 1.96549, 2.15323, 2.50223, 2.693, + 0.174947, 0.257739, 0.373547, 0.552567, 1.40532, 1.61425, 1.84892, 2.11779, 2.31788, 2.7119, + 0.209667, 0.297529, 0.756195, 1.0953, 1.5642, 1.84477, 2.1037, 2.29266, 2.52005, 2.67949, + 0.170138, 0.24031, 0.452247, 0.684414, 0.880102, 1.36692, 1.74165, 2.13129, 2.50573, 2.73261, + 0.278164, 0.468635, 0.707518, 0.853693, 1.05478, 1.21046, 1.54094, 2.17456, 2.41066, 2.61214, + 0.155738, 0.23889, 0.352836, 0.621012, 1.44144, 1.6197, 1.82517, 1.97533, 2.52537, 2.74857, + 0.223776, 0.274424, 0.479048, 0.797871, 1.69419, 1.87813, 2.13528, 2.37373, 2.59542, 2.72979, + 0.151088, 0.198286, 0.326558, 0.536276, 0.845893, 1.14165, 1.46056, 1.76287, 2.02585, 2.1773, + 0.434445, 0.614208, 0.887657, 1.02845, 1.19136, 1.3922, 1.78689, 2.06248, 2.4234, 2.61936, + 0.180755, 0.275311, 0.397787, 0.859366, 1.40976, 1.52332, 1.90885, 2.08232, 2.38972, 2.74389, + 0.275975, 0.508416, 0.889894, 1.31893, 1.63331, 1.90473, 2.16901, 2.37466, 2.72697, 2.84767, + 0.156239, 0.262624, 0.406657, 0.739074, 1.04449, 1.20123, 1.81089, 2.0056, 2.5817, 2.80489, + 0.195391, 0.258771, 0.654924, 0.824371, 1.31526, 1.50073, 1.76594, 2.06399, 2.34118, 2.51366, + 0.178034, 0.301047, 0.46302, 0.716172, 1.19887, 1.34045, 1.83456, 2.02213, 2.40075, 2.77629, + 0.340368, 0.404236, 0.843747, 1.03924, 1.20211, 1.70805, 1.91495, 2.16951, 2.52152, 2.62335, + 0.218465, 0.289694, 0.528045, 0.817051, 1.13234, 1.58046, 1.83889, 1.98339, 2.14749, 2.34813, + 0.322509, 0.458058, 0.654679, 0.958976, 1.11821, 1.32157, 1.90139, 2.04641, 2.36093, 2.66422, + 0.191821, 0.252321, 0.389176, 0.581111, 1.52967, 1.93169, 2.08361, 2.27046, 2.56685, 2.71388, + 0.493961, 0.710827, 0.98226, 1.19627, 1.41933, 1.62091, 1.92801, 2.14565, 2.42977, 2.60197, + 0.213148, 0.311589, 0.424636, 0.602664, 0.736895, 1.02216, 1.99228, 2.21853, 2.61163, 2.85032, + 0.288129, 0.434441, 0.629313, 0.856153, 1.28967, 1.42452, 1.8758, 2.15024, 2.35181, 2.53684, + 0.160031, 0.230716, 0.406654, 0.870424, 1.15652, 1.39232, 1.8041, 1.95144, 2.21048, 2.73516, + 0.22934, 0.293962, 0.503222, 1.2421, 1.47582, 1.62465, 1.99868, 2.1445, 2.57855, 2.75327, + 0.15877, 0.220035, 0.363386, 0.577761, 0.96309, 1.17494, 1.73817, 1.9792, 2.16244, 2.66192, + 0.346062, 0.444816, 0.716985, 1.18072, 1.37058, 1.523, 1.89217, 2.06668, 2.3958, 2.62766, + 0.307495, 0.38933, 0.612607, 0.969283, 1.55771, 1.83994, 1.99674, 2.17238, 2.42063, 2.5392, + 0.437804, 0.726957, 1.29117, 1.5033, 1.76543, 1.96212, 2.16365, 2.33623, 2.57962, 2.70852, + 0.232184, 0.333678, 0.528368, 0.706749, 1.20328, 1.37902, 1.61116, 2.15468, 2.5929, 2.75032, + 0.272652, 0.46171, 0.625777, 0.839609, 1.34202, 1.49673, 1.71538, 2.13757, 2.37004, 2.59739, + 0.184908, 0.302324, 0.454883, 0.880307, 1.10438, 1.29253, 1.7772, 1.94336, 2.44417, 2.62273, + 0.265644, 0.341261, 0.553228, 1.13947, 1.42715, 1.56044, 1.93394, 2.08413, 2.39331, 2.65413, + 0.16792, 0.207301, 0.370331, 0.525538, 1.03089, 1.36816, 1.78247, 2.0624, 2.33276, 2.5263, + 0.343172, 0.433912, 0.717501, 0.889734, 1.05206, 1.69528, 2.05316, 2.20846, 2.60887, 2.71832, + 0.216527, 0.305247, 0.44589, 0.729271, 1.63974, 1.90328, 2.05335, 2.22125, 2.43225, 2.56802, + 0.110545, 0.209955, 0.844788, 1.1742, 1.4922, 1.81024, 2.17727, 2.4405, 2.69729, 2.83523, + 0.217384, 0.337412, 0.488999, 0.761842, 0.879715, 1.20953, 1.97075, 2.1208, 2.61165, 2.79176, + 0.190459, 0.296484, 0.469967, 0.800649, 1.10556, 1.27853, 1.51694, 1.69307, 2.11442, 2.71674, + 0.134814, 0.175978, 0.300425, 0.496817, 1.2443, 1.48531, 1.86172, 2.13123, 2.48505, 2.77388, + 0.210174, 0.278266, 0.435508, 0.927538, 1.60691, 1.7539, 1.95755, 2.16628, 2.39852, 2.74961, + 0.213766, 0.3153, 0.509924, 0.70993, 0.964724, 1.10678, 1.38261, 2.00107, 2.32321, 2.56531, + 0.400615, 0.524954, 0.798552, 1.01285, 1.13549, 1.47485, 1.98903, 2.13091, 2.50797, 2.67946, + 0.2494, 0.377023, 0.519635, 0.754227, 1.45956, 1.64276, 1.82896, 2.07788, 2.29823, 2.46753, + 0.473365, 0.683973, 1.05234, 1.37583, 1.54811, 1.74759, 2.1393, 2.31877, 2.60998, 2.73925, + 0.203877, 0.341791, 0.48518, 0.884069, 1.09759, 1.26953, 1.47992, 1.75788, 2.6484, 2.82239, + 0.273046, 0.404254, 0.555403, 0.954547, 1.29123, 1.39902, 1.72289, 1.90344, 2.17198, 2.64531, + 0.040369, 0.117266, 0.617136, 0.892043, 1.26033, 1.54165, 1.85938, 2.1531, 2.49823, 2.76189, + 0.132414, 0.211358, 0.742445, 1.06686, 1.33108, 1.57079, 1.86746, 2.13253, 2.47962, 2.73108, + 0.237329, 0.326529, 0.612538, 0.790663, 0.990133, 1.41374, 1.73823, 1.93691, 2.16773, 2.45163, + 0.27396, 0.405794, 0.57253, 0.933672, 1.05782, 1.39795, 1.85653, 1.99755, 2.59949, 2.76004, + 0.199334, 0.29838, 0.442931, 0.628638, 1.30321, 1.64014, 1.80402, 2.11302, 2.37545, 2.54895, + 0.350188, 0.50201, 0.821298, 1.03864, 1.36929, 1.5924, 1.91082, 2.15649, 2.46051, 2.65326, + 0.281558, 0.399892, 0.573105, 0.753299, 0.900613, 1.05457, 1.58199, 2.17844, 2.43035, 2.61604, + 0.344653, 0.543532, 0.703715, 0.862285, 1.19822, 1.33821, 1.57908, 2.06077, 2.30675, 2.48575, + 0.220701, 0.326795, 0.520618, 0.755133, 1.29555, 1.45189, 1.6905, 2.20005, 2.41427, 2.61591, + 0.279478, 0.332193, 0.801527, 1.34597, 1.48748, 1.6785, 1.9222, 2.10002, 2.58557, 2.71339, + 0.163502, 0.212169, 0.365096, 0.525464, 0.869846, 1.20881, 1.79399, 2.04031, 2.29718, 2.4698, + 0.285531, 0.341488, 0.754059, 1.17002, 1.30084, 1.5137, 1.69986, 1.88992, 2.58146, 2.70687, + 0.249595, 0.366997, 0.626427, 0.945219, 1.40704, 1.56056, 1.83166, 2.23115, 2.46635, 2.65452, + 0.271671, 0.443136, 1.15641, 1.40646, 1.67652, 1.85648, 2.06322, 2.2305, 2.47584, 2.63958, + 0.28662, 0.427806, 0.63732, 0.803409, 0.996161, 1.26638, 1.68175, 2.00397, 2.39465, 2.58855, + 0.314906, 0.440519, 0.612129, 0.896126, 1.47241, 1.71769, 1.88135, 2.09944, 2.36917, 2.49547, + 0.170277, 0.25127, 0.405477, 0.915641, 1.12689, 1.43663, 1.71477, 1.8932, 2.55299, 2.73852, + 0.27941, 0.337137, 0.734563, 1.28105, 1.4806, 1.61188, 1.85321, 1.99488, 2.41605, 2.65483, + 0.165776, 0.226083, 0.417544, 0.744574, 1.04447, 1.53489, 1.80849, 1.94495, 2.13849, 2.60179, + 0.264579, 0.336652, 0.542033, 0.71019, 0.913338, 1.65575, 1.81776, 2.23196, 2.52444, 2.65852, + 0.158194, 0.235588, 0.338347, 0.541657, 1.58338, 1.76629, 2.00914, 2.24334, 2.50394, 2.77516, + 0.332612, 0.50962, 0.822935, 1.07588, 1.45429, 1.65079, 1.97445, 2.25128, 2.53734, 2.74512, + 0.262817, 0.359709, 0.520893, 0.707667, 0.818364, 1.43885, 1.97125, 2.08767, 2.49701, 2.64644, + 0.2332, 0.399599, 0.612456, 0.775547, 1.19919, 1.35576, 1.6469, 2.13625, 2.34249, 2.69574, + 0.149687, 0.238538, 0.372248, 0.63452, 1.25581, 1.43379, 1.77004, 1.92875, 2.61191, 2.82493, + 0.137016, 0.210297, 0.591489, 1.12545, 1.37565, 1.6853, 2.08961, 2.39089, 2.70446, 2.84443, + 0.21349, 0.341024, 0.541716, 0.750061, 1.0882, 1.24458, 1.55534, 1.96557, 2.1879, 2.38371, + 0.300159, 0.489291, 0.825022, 1.0371, 1.19409, 1.34738, 1.68475, 2.02494, 2.46561, 2.74097, + 0.170029, 0.255033, 0.392758, 0.727117, 1.38207, 1.57968, 1.80091, 1.95907, 2.28234, 2.7288, + 0.175883, 0.365509, 1.11217, 1.38587, 1.72039, 1.97781, 2.2453, 2.42161, 2.62957, 2.754, + 0.16259, 0.248164, 0.45463, 0.763209, 0.966031, 1.28234, 1.73074, 1.93805, 2.47938, 2.66756, + 0.258043, 0.345866, 0.55652, 0.981312, 1.36153, 1.48238, 1.87224, 2.15823, 2.36227, 2.55503, + 0.234139, 0.348843, 0.528234, 0.987884, 1.19522, 1.42215, 1.96003, 2.12737, 2.60332, 2.793, + 0.179699, 0.559209, 0.867682, 1.08884, 1.31689, 1.5715, 1.9222, 2.19739, 2.50112, 2.72868, + 0.216784, 0.310791, 0.487492, 0.932903, 1.20195, 1.36655, 1.8004, 1.9775, 2.17426, 2.53707, + 0.186878, 0.400655, 0.580952, 0.846287, 1.10387, 1.26678, 1.84277, 2.01959, 2.488, 2.71722, + 0.164641, 0.248712, 0.389358, 0.772822, 1.21256, 1.36992, 2.02587, 2.27762, 2.61752, 2.80953, + 0.351899, 0.520326, 0.926597, 1.21965, 1.50984, 1.67684, 1.92174, 2.11125, 2.35638, 2.54593, + 0.242182, 0.365285, 0.506156, 0.71602, 0.865221, 1.01169, 1.78692, 2.12298, 2.35088, 2.76773, + 0.413776, 0.559566, 0.7358, 0.928997, 1.07912, 1.26718, 1.88007, 2.15249, 2.32483, 2.53986, + 0.210597, 0.329568, 0.469735, 0.78859, 1.21549, 1.31981, 1.71146, 2.05899, 2.24544, 2.65373, + 0.197937, 0.254148, 0.477985, 1.22709, 1.62992, 1.76743, 2.18698, 2.3851, 2.59487, 2.72554, + 0.205489, 0.333855, 0.523915, 0.706275, 1.10215, 1.24661, 1.6489, 2.02683, 2.28169, 2.75931, + 0.230328, 0.322431, 0.861834, 1.14561, 1.34721, 1.57611, 1.80728, 2.00482, 2.35437, 2.57225, + 0.224898, 0.282022, 0.506636, 1.1523, 1.62656, 1.75209, 2.02818, 2.21882, 2.48896, 2.67046, + 0.313732, 0.625469, 1.16447, 1.49908, 1.74961, 2.01853, 2.26223, 2.4296, 2.69216, 2.8225, + 0.375623, 0.575307, 0.7912, 0.93577, 1.09694, 1.34339, 1.80799, 2.18731, 2.51972, 2.6948, + 0.236981, 0.332412, 0.47927, 0.844461, 1.34764, 1.49073, 1.68394, 2.03914, 2.29762, 2.45843, + 0.129047, 0.20625, 0.636751, 0.865101, 1.13689, 1.35661, 1.7048, 1.91668, 2.51836, 2.75632, + 0.195171, 0.266517, 0.414793, 1.23956, 1.45291, 1.60836, 1.83305, 2.0478, 2.47352, 2.62199, + 0.165853, 0.21272, 0.372757, 0.536136, 1.01394, 1.33963, 1.55512, 1.94574, 2.23628, 2.44095, + 0.256981, 0.368868, 0.635878, 0.802543, 1.08476, 1.43912, 1.81473, 2.12052, 2.45815, 2.62146, + 0.214382, 0.297135, 0.445091, 0.70205, 1.3651, 1.85126, 2.06703, 2.2073, 2.47073, 2.61243, + 0.34071, 0.532103, 0.935278, 1.17102, 1.37789, 1.6386, 1.96527, 2.24616, 2.63127, 2.80634, + 0.310524, 0.412051, 0.582478, 0.768755, 0.871594, 1.11985, 1.92635, 2.20751, 2.40709, 2.63663, + 0.249349, 0.443517, 0.631532, 0.810096, 1.20513, 1.35721, 1.6074, 1.98416, 2.20802, 2.64511, + 0.14309, 0.185312, 0.325214, 0.504, 1.13447, 1.32791, 1.67365, 2.0069, 2.38928, 2.74609, + 0.226575, 0.298946, 0.453938, 0.998061, 1.3946, 1.59728, 2.06418, 2.22325, 2.42547, 2.56946, + 0.183924, 0.255181, 0.415834, 0.624247, 1.04234, 1.20308, 1.55524, 2.12531, 2.40035, 2.66192, + 0.27561, 0.365968, 0.654909, 0.990108, 1.1708, 1.45533, 2.07756, 2.25267, 2.50232, 2.68595, + 0.204334, 0.287844, 0.39481, 0.761295, 1.5012, 1.78471, 1.93557, 2.15283, 2.34926, 2.54564, + 0.342976, 0.527539, 0.917466, 1.16059, 1.49953, 1.76183, 2.09527, 2.30187, 2.54057, 2.69469, + 0.202374, 0.333367, 0.480179, 0.708677, 0.819505, 1.10529, 1.80664, 1.95335, 2.61084, 2.7975, + 0.307033, 0.368471, 0.602486, 1.10861, 1.41335, 1.52864, 1.79852, 1.98614, 2.16905, 2.43726, + 0.144073, 0.196932, 0.386988, 0.819061, 1.28977, 1.62507, 1.90192, 2.13611, 2.48302, 2.70797, + 0.17676, 0.268627, 0.662082, 1.05687, 1.54797, 1.71139, 1.97294, 2.24991, 2.54447, 2.76109, + 0.191409, 0.292985, 0.492193, 0.800526, 1.04184, 1.27855, 1.83663, 2.02868, 2.24939, 2.62778, + 0.324102, 0.399146, 0.687435, 0.868704, 1.02296, 1.58208, 1.85385, 1.98188, 2.55491, 2.67706, + 0.229172, 0.302836, 0.481418, 0.704363, 0.967567, 1.82827, 2.0973, 2.25847, 2.54911, 2.70465, + 0.467124, 0.696788, 0.9395, 1.09499, 1.27754, 1.4885, 1.89628, 2.15847, 2.47418, 2.65999, + 0.175418, 0.234039, 0.367674, 0.513586, 0.747619, 1.0084, 1.58316, 2.05311, 2.36329, 2.68115, + 0.410273, 0.561949, 0.736215, 0.956685, 1.13569, 1.28842, 1.75061, 1.93771, 2.15132, 2.48934, + 0.204541, 0.277613, 0.529607, 0.722971, 1.19998, 1.44734, 1.71563, 1.92105, 2.35778, 2.50749, + 0.253116, 0.311907, 0.696982, 1.32008, 1.57542, 1.70532, 2.00507, 2.16867, 2.46188, 2.66505, + 0.163657, 0.237902, 0.393374, 0.60949, 0.854272, 1.08998, 1.52639, 1.84234, 2.12625, 2.67905, + 0.448627, 0.530664, 0.812719, 1.0952, 1.20764, 1.57541, 1.88421, 2.0343, 2.55301, 2.68835, + 0.262717, 0.338748, 0.512685, 1.00354, 1.48018, 1.62208, 1.82852, 2.14242, 2.35646, 2.51153, + 0.417111, 0.636688, 1.03657, 1.31988, 1.67992, 1.87339, 2.07372, 2.2494, 2.50773, 2.65105, + 0.263698, 0.461151, 0.618737, 0.830471, 1.00404, 1.15887, 1.80157, 2.02022, 2.30656, 2.74304, + 0.387779, 0.575108, 0.729791, 0.932981, 1.36116, 1.50516, 1.75118, 2.06847, 2.33826, 2.48764, + 0.18151, 0.265666, 0.454631, 1.08238, 1.2873, 1.5792, 1.85118, 2.09696, 2.46724, 2.64693, + 0.277668, 0.345119, 0.602341, 1.1792, 1.37899, 1.54562, 1.81386, 1.96259, 2.4918, 2.66445, + 0.17932, 0.24808, 0.456925, 0.722589, 1.12693, 1.57945, 1.7994, 1.95067, 2.48412, 2.70724, + 0.314322, 0.381145, 0.608651, 0.727613, 0.890472, 1.61028, 2.13617, 2.25836, 2.59638, 2.70978, + 0.189539, 0.266068, 0.419729, 0.651693, 1.41016, 1.64311, 1.85481, 2.27558, 2.49205, 2.72201, + 0.254466, 0.313038, 0.594149, 1.01254, 1.68881, 1.93546, 2.11918, 2.28787, 2.53554, 2.66793, + 0.134691, 0.171906, 0.30274, 0.492936, 0.899551, 1.22919, 1.73394, 2.01288, 2.44634, 2.74276, + 0.231556, 0.365068, 0.680761, 0.889142, 1.11134, 1.2959, 1.54264, 1.97178, 2.42756, 2.63191, + 0.222525, 0.305606, 0.527193, 0.687519, 1.18138, 1.67176, 1.86368, 2.07202, 2.63452, 2.77927, + 0.17877, 0.237415, 0.37516, 0.856692, 1.67368, 1.81374, 2.01679, 2.27242, 2.5226, 2.73596, + 0.193532, 0.268731, 0.451328, 0.753471, 0.984854, 1.28535, 1.68565, 1.88412, 2.09168, 2.24342, + 0.476037, 0.65161, 0.801054, 1.01016, 1.24137, 1.35584, 1.77598, 2.08615, 2.27291, 2.45435, + 0.211657, 0.308331, 0.421366, 0.865966, 1.41877, 1.55674, 1.78615, 2.02033, 2.19859, 2.63198, + 0.203789, 0.490794, 1.01014, 1.27501, 1.47221, 1.81014, 2.17064, 2.43766, 2.66212, 2.78806, + 0.174355, 0.252095, 0.674715, 0.842194, 1.05509, 1.278, 1.69868, 2.07056, 2.39938, 2.65743, + 0.245109, 0.324049, 0.628822, 0.92791, 1.1236, 1.58007, 1.87864, 2.0546, 2.35872, 2.54684, + 0.182644, 0.253804, 0.386248, 0.614056, 1.36482, 1.54588, 2.04017, 2.21883, 2.41901, 2.62461, + 0.295605, 0.367794, 0.690701, 1.05516, 1.1866, 1.64445, 1.94415, 2.10144, 2.56212, 2.69127, + 0.220878, 0.289573, 0.640307, 0.822072, 1.14406, 1.5678, 1.76641, 1.90811, 2.10346, 2.56049, + 0.403453, 0.526298, 0.732204, 0.90115, 1.03587, 1.33938, 1.78399, 1.94196, 2.37103, 2.62665, + 0.212825, 0.25857, 0.471588, 0.685549, 1.26374, 1.82105, 2.16382, 2.2884, 2.62806, 2.78816, + 0.401181, 0.642053, 1.03247, 1.23611, 1.44445, 1.68668, 2.00672, 2.22851, 2.57211, 2.72396, + 0.239433, 0.341091, 0.492629, 0.70763, 0.881426, 1.03082, 1.71925, 2.34406, 2.57906, 2.75694, + 0.294093, 0.38277, 0.577412, 1.00928, 1.31304, 1.4193, 1.74467, 2.09423, 2.28904, 2.47584, + 0.169805, 0.236922, 0.403314, 0.638995, 1.17645, 1.35214, 1.66557, 1.90976, 2.15012, 2.71624, + 0.210447, 0.277913, 0.452474, 1.40269, 1.51343, 1.72094, 1.90394, 2.2785, 2.58376, 2.74318, + 0.159574, 0.225382, 0.374008, 0.714137, 1.01125, 1.37171, 1.69916, 1.87159, 2.02706, 2.49119, + 0.258602, 0.557253, 0.81972, 1.03886, 1.30147, 1.44536, 1.83061, 2.09817, 2.32081, 2.54107, + 0.232756, 0.282242, 0.631974, 0.898694, 1.53744, 1.86922, 2.06397, 2.23446, 2.49823, 2.63352, + 0.580133, 0.997946, 1.32096, 1.48187, 1.73161, 1.89858, 2.12071, 2.29013, 2.53009, 2.65166, + 0.21184, 0.307093, 0.45336, 0.945579, 1.25082, 1.49029, 1.72414, 2.2811, 2.5627, 2.7526, + 0.314276, 0.493555, 0.667782, 0.8965, 1.32301, 1.48262, 1.66749, 1.97441, 2.42735, 2.55568, + 0.182455, 0.261592, 0.418011, 1.05093, 1.26139, 1.44337, 1.66547, 1.93903, 2.44469, 2.63845, + 0.24157, 0.306934, 0.491293, 1.10595, 1.55483, 1.66652, 1.92392, 2.08765, 2.3676, 2.65489, + 0.190084, 0.25485, 0.454062, 0.724519, 1.08336, 1.39389, 1.89234, 2.08886, 2.32176, 2.4843, + 0.306497, 0.389831, 0.721793, 0.839714, 1.12475, 1.6524, 1.82292, 2.27331, 2.5692, 2.6696, + 0.1862, 0.27346, 0.383201, 0.564758, 1.51107, 1.84502, 1.99828, 2.1941, 2.38869, 2.58792, + 0.300722, 0.478218, 0.823364, 1.12749, 1.59114, 1.87135, 2.17472, 2.40318, 2.62478, 2.7824, + 0.228884, 0.358342, 0.504622, 0.795874, 1.00562, 1.15261, 1.90805, 2.12479, 2.37247, 2.79758, + 0.171885, 0.248234, 0.432842, 0.833143, 1.04089, 1.26929, 1.66164, 1.91863, 2.15896, 2.6534, + 0.140943, 0.193684, 0.343025, 0.562303, 1.06955, 1.54333, 1.82447, 1.96164, 2.46351, 2.77054, + 0.173053, 0.245656, 0.360656, 0.960618, 1.58953, 1.68991, 1.98414, 2.143, 2.58839, 2.7594, + 0.24018, 0.429951, 0.63744, 0.786596, 1.06915, 1.22657, 1.47088, 1.95205, 2.19506, 2.61597, + 0.367862, 0.471897, 0.730834, 1.08232, 1.22629, 1.46293, 1.92817, 2.05247, 2.40674, 2.66246, + 0.247175, 0.358209, 0.535946, 0.781876, 1.3637, 1.63524, 1.80723, 1.99378, 2.45277, 2.60104, + 0.445578, 0.687898, 1.11411, 1.30103, 1.5774, 1.88604, 2.2249, 2.43653, 2.65969, 2.76103, + 0.214389, 0.336025, 0.487794, 0.759534, 0.970518, 1.1411, 1.45733, 1.62464, 2.30692, 2.71527, + 0.3773, 0.466775, 0.716121, 1.08378, 1.25654, 1.41124, 1.78943, 1.93637, 2.20557, 2.56236, + 0.148362, 0.214593, 0.545023, 0.840437, 1.19333, 1.48066, 1.79187, 2.08342, 2.41054, 2.67613, + 0.150403, 0.278398, 0.792676, 0.97668, 1.21885, 1.40524, 1.77506, 2.16246, 2.54786, 2.74638, + 0.236301, 0.328633, 0.630867, 0.839915, 1.04235, 1.29887, 1.62775, 1.83949, 2.29893, 2.49396, + 0.337889, 0.49792, 0.711277, 0.85042, 0.992027, 1.24688, 1.71075, 2.08668, 2.52716, 2.70716, + 0.172215, 0.23654, 0.372897, 0.525146, 1.18258, 1.73573, 1.92703, 2.11462, 2.31917, 2.54278, + 0.415304, 0.624807, 0.906616, 1.11784, 1.44615, 1.66942, 1.94841, 2.17282, 2.50453, 2.67075, + 0.265417, 0.407241, 0.613894, 0.816534, 0.980063, 1.15606, 1.75675, 2.27485, 2.49719, 2.71224, + 0.27644, 0.468209, 0.649518, 0.816686, 1.19517, 1.35552, 1.54923, 1.93527, 2.21787, 2.42698, + 0.188925, 0.277012, 0.412665, 0.672627, 1.35481, 1.51452, 1.69999, 2.14455, 2.38219, 2.58608, + 0.24263, 0.352485, 0.912974, 1.34378, 1.60443, 1.80187, 2.01479, 2.19307, 2.46081, 2.632, + 0.190903, 0.285841, 0.44907, 0.760328, 0.954285, 1.18294, 1.69264, 1.87816, 2.27684, 2.46596, + 0.220659, 0.300374, 0.721694, 0.947306, 1.29833, 1.56298, 1.76062, 1.88825, 2.50644, 2.68968, + 0.213168, 0.290928, 0.695227, 0.918179, 1.37819, 1.63199, 1.84789, 2.00307, 2.35836, 2.61935, + 0.328586, 0.517244, 0.93732, 1.37624, 1.57484, 1.76435, 2.05863, 2.22433, 2.58444, 2.75665, + 0.248486, 0.367007, 0.562147, 0.750632, 0.902785, 1.14756, 1.63742, 1.91206, 2.41399, 2.6057, + 0.310691, 0.477895, 0.670796, 0.940507, 1.41829, 1.5635, 1.80514, 2.11408, 2.37636, 2.53516, + 0.256555, 0.41421, 0.559427, 0.981289, 1.19165, 1.37831, 1.6784, 1.84931, 2.5767, 2.75663, + 0.291424, 0.335003, 0.750149, 1.28965, 1.43721, 1.59999, 1.80318, 1.96741, 2.60175, 2.73376, + 0.195254, 0.279513, 0.451755, 0.649111, 0.828694, 1.60951, 1.91491, 2.09122, 2.31959, 2.5349, + 0.222304, 0.332624, 0.475678, 0.685205, 1.03033, 1.73722, 1.92098, 2.37829, 2.70672, 2.81773, + 0.164833, 0.240093, 0.359862, 0.801929, 1.51368, 1.64171, 2.04052, 2.24884, 2.48866, 2.71403, + 0.214777, 0.287322, 0.572644, 1.14507, 1.36711, 1.75269, 2.04242, 2.22207, 2.54305, 2.69789, + 0.226099, 0.330382, 0.474439, 0.687757, 0.799187, 1.31984, 1.94457, 2.0781, 2.3678, 2.50846, + 0.24454, 0.392163, 0.553692, 0.729765, 1.24786, 1.44838, 1.61759, 2.07464, 2.34005, 2.51806, + 0.175381, 0.314231, 0.446023, 0.797404, 1.32846, 1.43973, 1.79335, 1.93957, 2.4688, 2.72165, + 0.205808, 0.29367, 0.452447, 1.07427, 1.28823, 1.65563, 1.8575, 2.36469, 2.63981, 2.79814, + 0.253926, 0.392653, 0.587584, 0.800134, 0.97631, 1.18559, 1.57069, 1.82141, 2.09089, 2.34902, + 0.322461, 0.410912, 0.723569, 1.06064, 1.20152, 1.40036, 1.57919, 1.78876, 2.46024, 2.6166, + 0.211266, 0.304981, 0.436011, 0.771978, 1.49062, 1.67775, 1.88623, 2.1135, 2.32635, 2.72726, + 0.235012, 0.406911, 0.864785, 1.29148, 1.70829, 1.93855, 2.1799, 2.3524, 2.56379, 2.71145, + 0.176814, 0.26862, 0.445837, 0.823113, 1.02978, 1.27157, 1.62339, 1.81122, 2.40214, 2.61417, + 0.241865, 0.339268, 0.507509, 1.00368, 1.20435, 1.37256, 1.94079, 2.10137, 2.38561, 2.66998, + 0.230878, 0.334743, 0.50037, 0.879929, 1.02189, 1.53377, 1.97079, 2.12897, 2.56726, 2.71729, + 0.297505, 0.451574, 0.748848, 0.988527, 1.36624, 1.60667, 1.89466, 2.17448, 2.52143, 2.75917, + 0.199265, 0.271145, 0.49816, 0.854679, 1.1721, 1.36415, 1.76208, 1.96909, 2.17354, 2.31163, + 0.222173, 0.424864, 0.564942, 0.829809, 1.03817, 1.19405, 1.7206, 1.85809, 2.43176, 2.74146, + 0.181961, 0.226819, 0.390513, 0.556339, 1.0566, 1.55306, 2.12835, 2.25802, 2.6025, 2.80212, + 0.3576, 0.565047, 1.15301, 1.35031, 1.53358, 1.71854, 1.95789, 2.17535, 2.50565, 2.67849, + 0.162257, 0.236808, 0.374039, 0.570569, 0.748034, 1.17226, 1.82339, 2.05303, 2.51377, 2.77207, + 0.305794, 0.46587, 0.645121, 0.88265, 1.14129, 1.26686, 1.70158, 2.00288, 2.18412, 2.41125, + 0.231652, 0.380738, 0.549642, 0.83741, 1.22527, 1.33297, 1.85158, 2.11937, 2.31508, 2.73211, + 0.235449, 0.286771, 0.684809, 1.34666, 1.52663, 1.70348, 2.10149, 2.25455, 2.57718, 2.71899, + 0.23387, 0.446515, 0.60508, 0.814654, 1.05496, 1.1788, 1.63316, 1.84974, 2.13938, 2.73277, + 0.271706, 0.335152, 0.857227, 1.25374, 1.38719, 1.70217, 1.89677, 2.19111, 2.48, 2.60136, + 0.237386, 0.314549, 0.438339, 0.912164, 1.57776, 1.87779, 2.03279, 2.19704, 2.41232, 2.53648, + 0.361168, 0.574093, 1.02384, 1.46852, 1.69056, 1.91737, 2.18737, 2.33403, 2.6691, 2.80629, + 0.27848, 0.398742, 0.573342, 0.839212, 1.07389, 1.22209, 1.69168, 2.16526, 2.37741, 2.53688, + 0.286018, 0.447947, 0.61506, 0.849446, 1.31947, 1.46358, 1.76995, 2.00103, 2.18943, 2.45038, + 0.21944, 0.301601, 0.668534, 0.861094, 1.21, 1.49867, 1.74512, 1.87777, 2.31438, 2.6196, + 0.223591, 0.352153, 0.598841, 1.21789, 1.35908, 1.59174, 1.77109, 2.21386, 2.56154, 2.73542, + 0.176857, 0.236601, 0.395107, 0.634632, 1.13349, 1.33512, 1.77037, 1.98131, 2.20656, 2.33972, + 0.334735, 0.402265, 0.659168, 0.781639, 0.975228, 1.665, 1.87207, 2.04753, 2.47696, 2.57398, + 0.215968, 0.284755, 0.524241, 0.78146, 1.33481, 1.77238, 1.95388, 2.19421, 2.57825, 2.74194, + 0.298193, 0.489879, 0.812985, 1.18369, 1.49642, 1.67998, 2.10879, 2.31656, 2.67378, 2.85161, + 0.312989, 0.415446, 0.618011, 0.899096, 1.08368, 1.26338, 1.8874, 2.24306, 2.41945, 2.57048, + 0.244471, 0.431115, 0.601512, 0.813139, 1.10216, 1.22106, 1.69244, 2.03316, 2.2218, 2.61984, + 0.150949, 0.21906, 0.349217, 0.611327, 1.07711, 1.25055, 1.91552, 2.08398, 2.45, 2.79254, + 0.161611, 0.218964, 0.445377, 0.927863, 1.45115, 1.76846, 2.13001, 2.36672, 2.666, 2.81405, + 0.196, 0.297256, 0.497266, 0.6919, 1.08988, 1.27368, 1.51372, 2.00647, 2.27378, 2.57222, + 0.335268, 0.460795, 0.685187, 0.867664, 1.01381, 1.47955, 2.01199, 2.16848, 2.57264, 2.71756, + 0.257604, 0.340872, 0.499757, 0.843052, 1.39655, 1.83169, 2.03423, 2.17033, 2.42262, 2.5405, + 0.417663, 0.631718, 0.955424, 1.19732, 1.6598, 1.87988, 2.1688, 2.35905, 2.57809, 2.69825, + 0.162052, 0.251583, 0.4399, 0.660911, 0.903902, 1.3203, 1.62476, 1.77858, 2.53053, 2.79971, + 0.256861, 0.322803, 0.68537, 1.08644, 1.26328, 1.56988, 1.85165, 2.01495, 2.26471, 2.44701, + 0.125192, 0.176171, 0.336135, 0.7816, 1.20022, 1.43997, 1.80542, 2.07752, 2.46247, 2.73819, + 0.102286, 0.191322, 0.774556, 1.07615, 1.36946, 1.62715, 1.97301, 2.236, 2.60937, 2.81298, + 0.173442, 0.232622, 0.491622, 0.844157, 1.09524, 1.3708, 1.69697, 2.05141, 2.31606, 2.50205, + 0.257531, 0.343598, 0.654071, 0.838985, 1.0481, 1.48747, 1.72538, 1.89742, 2.43051, 2.586, + 0.1979, 0.276312, 0.440283, 0.705103, 1.26734, 1.7403, 1.93448, 2.15401, 2.4002, 2.62414, + 0.40959, 0.596785, 0.983751, 1.18177, 1.37115, 1.50238, 1.75828, 2.01857, 2.38005, 2.59215, + 0.231819, 0.33289, 0.483514, 0.644585, 0.816808, 0.926308, 1.4033, 2.23301, 2.46786, 2.67846, + 0.25861, 0.340064, 0.670485, 0.908467, 1.10761, 1.45624, 1.75958, 1.93218, 2.11312, 2.31013, + 0.184377, 0.249203, 0.410806, 0.587907, 1.3025, 1.51032, 1.72443, 1.98189, 2.2829, 2.42213, + 0.25411, 0.313328, 0.659859, 1.26582, 1.41295, 1.66593, 1.92715, 2.10198, 2.55145, 2.67303, + 0.161592, 0.23748, 0.376535, 0.637094, 0.823028, 1.13761, 1.69642, 1.87577, 2.40363, 2.63962, + 0.384501, 0.466812, 0.740791, 0.938093, 1.06235, 1.50928, 1.74914, 1.9178, 2.54816, 2.67151, + 0.333872, 0.419367, 0.638994, 1.09262, 1.52055, 1.64945, 1.86662, 2.14894, 2.34672, 2.50614, + 0.426216, 0.686997, 1.23588, 1.42885, 1.61159, 1.79286, 2.01759, 2.23372, 2.54777, 2.69661, + 0.262949, 0.367509, 0.530429, 0.741867, 0.872474, 1.0696, 1.74557, 2.06119, 2.28384, 2.49418, + 0.335782, 0.547236, 0.716211, 0.919077, 1.27569, 1.40844, 1.68512, 1.96739, 2.21764, 2.44668, + 0.227629, 0.330991, 0.486068, 1.11757, 1.30498, 1.51013, 1.75726, 1.94697, 2.62556, 2.7826, + 0.35985, 0.436633, 0.750634, 1.20151, 1.33757, 1.59484, 1.97027, 2.11384, 2.57381, 2.72996, + 0.211871, 0.304028, 0.512758, 0.663762, 1.08635, 1.63333, 1.81802, 2.12958, 2.39108, 2.60077, + 0.196092, 0.279726, 0.434488, 0.624802, 0.772358, 1.40438, 1.94878, 2.16092, 2.63, 2.77518, + 0.176304, 0.262521, 0.373719, 0.581101, 1.52011, 1.73617, 1.93323, 2.14017, 2.35813, 2.75352, + 0.254932, 0.381411, 0.806187, 1.10229, 1.53452, 1.75028, 1.9709, 2.15987, 2.45592, 2.65841, + 0.190385, 0.288656, 0.449066, 0.678174, 0.812376, 1.44933, 1.72866, 1.96632, 2.63881, 2.78955, + 0.251178, 0.386509, 0.609363, 0.797102, 1.02416, 1.18173, 1.45466, 2.01263, 2.49309, 2.69893, + 0.166654, 0.266226, 0.385171, 0.71199, 1.3979, 1.53235, 1.91597, 2.088, 2.56527, 2.78953, + 0.238453, 0.306036, 0.449309, 0.876277, 1.52144, 1.93398, 2.13442, 2.26799, 2.5376, 2.65825, + 0.161634, 0.219919, 0.353206, 0.524346, 0.961806, 1.20771, 1.68792, 1.91694, 2.16187, 2.32066, + 0.413612, 0.597095, 0.793763, 0.98629, 1.28179, 1.41266, 1.65246, 2.01609, 2.38416, 2.52858, + 0.228655, 0.341562, 0.480989, 0.988605, 1.371, 1.47742, 1.86103, 2.01585, 2.33975, 2.77315, + 0.259092, 0.597012, 0.985224, 1.32174, 1.64335, 1.95737, 2.28868, 2.49747, 2.71649, 2.84447, + 0.185652, 0.304664, 0.446232, 0.864434, 1.09179, 1.27377, 1.94257, 2.09554, 2.52465, 2.76824, + 0.176687, 0.256678, 0.745652, 0.934909, 1.28376, 1.44006, 1.76524, 2.12209, 2.3881, 2.59055, + 0.189805, 0.275637, 0.440995, 0.821356, 1.25602, 1.41098, 1.92978, 2.12014, 2.39603, 2.60464, + 0.266823, 0.337688, 0.819408, 1.13475, 1.2892, 1.77703, 1.98289, 2.22175, 2.59029, 2.6981, + 0.205348, 0.276512, 0.527305, 0.727412, 1.02465, 1.65398, 1.90418, 2.04661, 2.21792, 2.45566, + 0.293498, 0.424494, 0.613795, 0.95613, 1.13398, 1.3248, 1.80903, 1.95392, 2.29385, 2.57588, + 0.18312, 0.24965, 0.376204, 0.543914, 1.35083, 1.90722, 2.09255, 2.25571, 2.51439, 2.6879, + 0.541205, 0.789796, 1.05895, 1.26942, 1.5039, 1.70219, 1.97018, 2.17544, 2.49681, 2.65224, + 0.229326, 0.339475, 0.451881, 0.66121, 0.795832, 1.0738, 2.0271, 2.20637, 2.4789, 2.72678, + 0.330006, 0.506868, 0.673076, 0.887406, 1.22877, 1.34923, 1.78129, 2.08658, 2.27776, 2.48003, + 0.138389, 0.200001, 0.396259, 0.811975, 1.09071, 1.46041, 1.74549, 1.90427, 2.34825, 2.69989, + 0.176584, 0.242161, 0.37827, 1.17785, 1.56472, 1.67817, 1.95162, 2.12141, 2.58011, 2.73713, + 0.145852, 0.198423, 0.335644, 0.550505, 1.01973, 1.37119, 1.79763, 1.94383, 2.20749, 2.74647, + 0.385078, 0.503696, 0.703239, 1.06999, 1.36574, 1.47205, 1.82583, 2.15964, 2.37128, 2.52097, + 0.28495, 0.38805, 0.507352, 0.879125, 1.52353, 1.77624, 1.9296, 2.15756, 2.44799, 2.5864, + 0.491116, 0.756155, 1.2552, 1.52246, 1.77658, 2.02812, 2.28606, 2.42977, 2.67911, 2.77616, + 0.252477, 0.396081, 0.713022, 0.861502, 1.15222, 1.3708, 1.61401, 2.1448, 2.57407, 2.71253, + 0.282756, 0.438437, 0.613566, 0.847746, 1.26077, 1.37906, 1.6422, 2.13754, 2.36837, 2.52216, + 0.203971, 0.322195, 0.479842, 0.953133, 1.21128, 1.39763, 1.80081, 1.95452, 2.40348, 2.57371, + 0.264533, 0.358424, 0.628768, 1.11124, 1.34025, 1.50648, 1.99959, 2.19411, 2.46141, 2.66736, + 0.17773, 0.22368, 0.394553, 0.556177, 0.947415, 1.50064, 1.73353, 1.92605, 2.26147, 2.43605, + 0.314223, 0.363636, 0.727886, 0.85188, 1.05384, 1.79813, 1.97435, 2.1826, 2.538, 2.62968, + 0.201778, 0.2755, 0.404891, 0.747466, 1.50005, 1.84118, 1.99884, 2.22681, 2.48199, 2.66951, + 0.132164, 0.314955, 0.821473, 1.19604, 1.42659, 1.69993, 2.03686, 2.3235, 2.68547, 2.82896, + 0.223374, 0.347335, 0.50773, 0.773547, 0.967916, 1.13413, 1.9914, 2.30657, 2.52136, 2.78875, + 0.312742, 0.449784, 0.583287, 0.934234, 1.26857, 1.36506, 1.5693, 1.68705, 2.0773, 2.59502, + 0.124286, 0.162126, 0.29073, 0.654031, 1.23166, 1.53846, 1.89307, 2.18478, 2.56264, 2.79822, + 0.177049, 0.251654, 0.367891, 0.912504, 1.55758, 1.69305, 1.89899, 2.07214, 2.35016, 2.64604, + 0.240517, 0.378333, 0.547809, 0.754272, 0.973321, 1.10367, 1.57442, 2.02805, 2.21113, 2.56271, + 0.427795, 0.519003, 0.771284, 0.93724, 1.08662, 1.60988, 1.87875, 2.05279, 2.53412, 2.65715, + 0.22437, 0.317969, 0.439666, 0.812931, 1.3985, 1.62663, 1.79418, 2.114, 2.30916, 2.49684, +]; +/* codebook/lspjvm2.txt */ +const codes1: [f32; 2560] = [ + 0.005167, -0.03731, -0.002159, 0.016849, 0.130396, 0.039445, 0.03168, -0.074412, -0.031499, + 0.060536, 0.019479, -0.030564, -0.048137, -0.056279, -0.027829, 0.020585, -0.01127, 0.023913, + -0.005706, 0.011407, -0.023217, 0.107455, -0.037777, 0.00407, -0.017279, -0.090444, 0.007641, + 0.099001, -0.047913, -0.017199, 0.0227, -0.063865, 0.047213, 0.043843, -0.036225, 0.001312, + -0.123861, -0.038988, 0.058666, 0.074541, 0.039508, 0.1103, 0.013954, -0.119228, -0.035807, + -0.047392, 0.027035, -0.004412, -0.03265, -0.03715, 0.002491, -0.045447, 0.15826, 0.022828, + -0.030124, -0.047856, 0.088744, -0.009678, 0.106688, 0.08769, -0.027941, 0.044084, -0.0285, + 0.018736, -0.069969, -0.035358, -0.051568, -0.030459, -0.017899, 0.027632, -0.018607, + -0.123557, 0.019228, 0.057485, -0.028907, 0.019057, 0.038151, -0.08022, 0.034222, 0.023081, + 0.021312, 0.041905, 0.112903, 0.024092, 0.093974, -0.116679, 0.015344, -0.066059, -0.096437, + 0.004041, -0.022464, -0.11626, 0.047819, -0.003921, -0.073504, 0.001975, -0.025869, 0.0282, + 0.12269, 0.010627, -0.035672, 0.078963, -0.009686, 0.000743, -0.147582, 0.016932, -0.020291, + -0.096896, -0.237875, -0.029121, 0.017376, -0.04013, -0.053865, 0.15406, -0.013215, 0.015215, + -0.019023, -0.070604, 0.032265, 0.04034, 0.102365, -0.022746, 0.019895, 0.05057, 0.008845, + -0.034134, 0.044441, -0.049387, -0.140481, 0.07257, 0.013023, -0.006079, 0.037574, 0.004937, + -0.081501, 0.003696, 0.049908, 0.007355, 0.000403, 0.026006, -0.008466, 0.08068, 0.061382, + -0.108985, -0.08806, -0.012275, -0.081061, 0.020333, -0.079001, 0.068724, -0.014081, -0.042609, + 0.093365, 0.04412, 0.000303, 0.063391, 0.096574, -0.105424, 0.039041, 0.010412, -0.054031, + -0.084948, 0.080406, -0.035883, 0.137428, 0.063037, 0.050562, 0.02469, -0.031394, 0.13032, + -0.015501, -0.078884, -0.076886, -0.013864, -0.073587, 0.048778, 0.003814, -0.031125, 0.046897, + 0.028304, 0.048692, 0.132795, 0.06545, 0.059487, -0.042396, -0.176999, 0.056943, -0.004135, + -0.049378, -0.041083, -0.039445, -0.016292, -0.00455, 0.06201, -0.079613, -0.054566, -0.008476, + -0.01671, 0.049202, 0.025758, -0.078723, 0.092091, 0.096536, -0.065079, 0.021161, 0.076657, + 0.009203, -0.036866, -0.016559, 0.012823, 0.008225, -0.003006, 0.108033, 0.04312, -0.06087, + -0.019346, 0.02279, -0.001728, 0.062304, -0.016965, -0.001302, -0.01449, -0.041803, -0.034058, + -0.197066, -0.033655, -0.127217, -0.108681, -0.010571, -0.004705, -0.015553, -0.086069, + 0.034109, -0.101379, 0.002068, -0.004003, -0.044637, -0.068617, 0.052228, -0.047812, -0.043307, + 0.035681, 0.042207, -0.055946, 0.055944, -0.026792, -0.012601, -0.05671, -0.021094, 0.105842, + -0.025598, -0.078858, -0.013487, 0.030728, -0.031956, 0.031444, 0.022763, 0.025364, 0.121366, + 0.070736, -0.084556, 0.098118, -0.024301, -0.058655, -0.043194, -0.011752, -0.043781, 0.091051, + -0.071201, -0.02098, 0.082904, -0.031657, -0.088247, 0.066709, -0.079182, -0.012151, 0.011796, + -0.010589, 0.100656, 0.094539, 0.035967, 0.025338, 0.071826, 0.009741, -0.040209, 0.006866, + -0.015095, -0.168469, -0.056133, 0.060145, 0.04583, -0.068969, 0.034551, 0.015842, -0.092809, + 0.054699, 0.138744, 0.001726, 0.006927, 0.005167, 0.016978, 0.046384, -0.060183, -0.040742, + -0.072692, -0.022489, -0.029728, -0.065018, -0.124741, 0.044927, -0.029057, -0.037154, + 0.031068, 0.060086, 0.009984, 0.009311, -0.006957, -0.105508, 0.059637, -0.019564, -0.068154, + -0.066443, 0.000799, 0.028579, 0.097063, 0.096936, 0.03023, -0.034623, -0.088918, 0.040334, + 0.019439, -0.050707, -0.003294, -0.028505, -0.053599, 0.06246, -0.070688, -0.016465, -0.03568, + 0.017378, 0.009363, 0.048761, 0.043374, 0.039587, -0.023232, -0.067033, 0.042663, 0.05407, + -0.042797, -0.089391, -0.030497, -0.050249, 0.059528, 0.089089, -0.029633, 0.064125, -0.086614, + -0.002005, 0.08062, 0.000502, -0.00349, 0.097336, 0.099565, 0.015648, 0.006691, 0.077668, + 0.016572, 0.035404, -0.046026, 0.017237, -0.048631, 0.009314, 0.141479, 0.017079, 0.043796, + -0.106474, 0.145951, 0.05774, 0.01125, -0.059443, 0.027572, 0.02665, 0.008527, 0.002949, + -0.03768, -0.077991, -0.090617, 0.00342, -0.04601, 0.007354, 0.019056, -0.128651, 0.016464, + 0.004584, -0.030883, -0.092069, 0.038976, -0.08184, 0.066695, -0.04734, 0.003513, 0.040613, + 0.046815, -0.023406, 0.062389, 0.021759, 0.024928, -0.018922, -0.048006, 0.0638, -0.014416, + -0.050333, 0.042628, -0.114934, -0.10145, 0.062139, 0.029295, -0.065908, 0.111463, 0.050781, + -0.022707, 0.135414, 0.003548, 0.134535, -0.048259, -0.092344, -0.027727, 0.016343, -0.060786, + -0.081502, -0.005412, -0.026229, -0.143331, 0.052404, -0.077298, -0.035919, -0.041968, + -0.106108, -0.004369, 0.065028, 0.09637, -0.053299, 0.043317, -0.049735, 0.049815, 0.032324, + 0.051309, -0.009607, -0.205917, 0.005023, -0.054316, -0.022895, 0.099327, -0.006927, -0.076574, + -0.111024, 0.111026, 0.038381, -0.060368, 0.064238, -0.034316, 0.026846, 0.02574, -0.076162, + -0.163904, 0.055955, -0.056885, 0.014831, -0.120715, 0.090938, 0.035289, -0.036439, 0.060012, + 0.080302, 0.036215, 0.06525, 0.08303, -0.058784, 0.104826, -0.051805, -0.011099, -0.00642, + 0.053042, 0.024127, 0.092534, 0.058569, -0.033442, 0.025186, -0.018222, 0.117744, 0.044345, + -0.042456, -0.043767, -0.021378, -0.121965, 0.027371, 0.052731, -0.020316, 0.036912, 0.115357, + 0.03115, 0.041547, 0.059267, -0.039672, -0.086918, -0.162369, 0.024801, 0.031725, 0.0834, + -0.034463, 0.000272, -0.008147, -0.002016, 0.131953, -0.092911, -0.091944, -0.062864, + -0.005221, 0.063647, -0.012658, 0.042685, 0.067952, 0.038644, -0.153221, 0.096841, 0.108299, + 0.089446, -0.047164, 0.004196, -0.043268, -0.035456, 0.050838, 0.070444, 0.084465, -0.07998, + -0.048916, 0.057726, 0.023894, 0.027653, 0.017775, 0.015461, -0.030287, -0.022245, 0.052081, + -0.150947, -0.002682, -0.056774, -0.123366, -0.091754, 0.006536, 0.006473, -0.143025, 0.05469, + -0.043189, 0.03297, 0.027446, 0.033127, -0.132722, -0.010417, -0.080097, -0.018187, 0.001858, + 0.11129, -0.090749, 0.059434, -0.068738, 0.090679, -0.14507, -0.065277, 0.063514, -0.003982, + -0.056382, -0.003673, 0.015845, -0.073396, 0.043688, 0.002836, 0.069211, 0.124852, -0.053313, + -0.040946, 0.07044, -0.107024, -0.019199, -0.033672, -0.00144, 0.02168, 0.110595, -0.053452, + -0.052426, 0.035461, -0.028179, -0.049041, 0.02258, -0.010989, -0.002913, -0.051691, -0.075881, + 0.037241, 0.076377, 0.034735, -0.031556, 0.073516, -0.001427, 0.016296, -0.017537, 0.003346, + -0.099774, -0.067624, -0.044257, -0.018202, 0.030622, 0.012773, 0.046475, -0.121785, -0.057265, + 0.116179, -0.079916, 0.066396, 0.050104, -0.013177, 0.057766, -0.047879, -0.109526, -0.146491, + 0.032675, -0.049318, -0.057045, -0.080068, 0.089621, -0.046564, -0.029992, 0.040828, 0.029281, + -0.037369, -0.009731, -0.082145, -0.117622, 0.117077, 0.037369, 0.00082, -0.106634, -0.007967, + 0.000812, 0.140637, 0.03653, 0.062121, -0.065504, -0.09493, 0.121336, 0.01753, -0.01733, + -0.040402, -0.018255, 0.010992, 0.019746, -0.027564, 0.033588, 0.042466, -0.003143, 0.013767, + 0.084179, 0.033753, -0.017279, -0.009676, -0.006452, 0.032645, 0.031852, -0.030975, -0.043384, + -0.005433, -0.015258, 0.053273, 0.054748, -0.064736, 0.008959, -0.141223, -0.032957, -0.015079, + 0.018198, -0.001681, 0.143079, 0.076, 0.001037, -0.048744, 0.022062, 0.02603, -0.008263, + -0.050353, -0.023037, -0.036477, -0.051733, 0.137823, -0.034438, -0.007573, -0.004256, + 0.064218, 0.075183, 0.095106, 0.026497, 0.02636, 0.009791, -0.058039, 0.053315, -0.077817, + -0.033283, -0.081151, -0.05522, 0.004268, 0.017539, -0.007329, -0.1172, 0.09322, 0.037359, + 0.002718, 0.010749, 0.018281, -0.0758, -0.024889, 0.00572, 0.022129, 0.035613, 0.036187, + 0.032246, 0.105439, -0.073766, 0.016887, -0.059934, -0.049471, 0.07352, -0.024041, -0.104642, + 0.023557, -0.059746, -0.043871, 0.022311, -0.00025, -0.074027, 0.198593, 0.102732, 0.024478, + 0.077658, -0.060042, -0.018229, -0.149648, -0.009871, -0.105822, 0.007585, -0.161459, + -0.041121, -0.02146, 0.00902, -0.065018, 0.111801, -0.024953, 0.074594, -0.026041, -0.062859, + 0.009199, 0.069609, 0.078672, -0.033414, 0.054128, 0.005408, -0.016273, 0.052076, 0.10761, + -0.067518, -0.0964, 0.033703, -0.01435, -0.024676, 0.056254, -0.04377, -0.060847, -0.004185, + 0.07355, -0.05783, -0.016644, 0.029096, 0.005755, 0.026472, 0.040449, -0.09195, -0.048538, + -0.034439, -0.107938, 0.090712, -0.117001, 0.04317, -0.006505, -0.035277, 0.117316, 0.127002, + 0.047906, -0.001441, 0.118379, -0.132165, 0.00738, 0.023823, -0.02012, -0.083725, 0.047284, + 0.023795, 0.074123, -0.013439, 0.024994, 0.060254, -0.06912, 0.166373, -0.024228, -0.06315, + -0.046506, -0.077202, -0.054592, -0.006571, 0.010335, -0.006568, 0.003982, 0.075837, 0.008643, + 0.136339, -0.005502, 0.03391, -0.066379, -0.127371, -0.006954, 0.03977, -0.070123, 0.060925, + -0.046386, -0.02642, -0.00528, 0.103509, -0.02231, -0.00374, -0.014999, -0.03777, 0.080005, + 0.025231, -0.054995, 0.071017, 0.009442, -0.075737, 0.013441, 0.051947, 0.027097, -0.070351, + -0.055705, -0.021115, 0.021387, 0.029232, 0.163331, -0.03238, 0.010008, -0.011987, -0.028631, + 0.002665, 0.01477, -0.009558, -0.034325, 0.01583, -0.091253, -0.012677, -0.107378, -0.034624, + -0.047725, -0.10233, 0.042525, -0.006869, 0.014048, -0.043127, 0.052384, -0.047473, 0.055102, + 0.009744, -0.033646, -0.081755, -0.001464, -0.016223, -0.036697, -0.002279, 0.023279, + -0.036221, 0.101478, -0.058454, 0.065074, 0.003524, 0.00501, 0.097182, -0.038171, -0.037943, + -0.009994, -0.033355, -0.044552, 0.041318, 0.065041, 9.2e-05, 0.100816, 0.029007, -0.031803, + 0.183537, -0.009617, -0.010544, -0.028465, 0.0069, -0.014988, 0.09049, -0.174817, 0.027464, + 0.063314, -0.049281, -0.001567, 0.091421, -0.078603, -0.004869, -0.063266, -0.001922, 0.069338, + 0.081771, 0.058737, 0.073195, 0.081676, -0.047808, -0.025797, -0.004185, 0.033203, -0.125472, + -0.108148, 0.031258, 0.035192, 0.029957, 0.046675, 0.047238, -0.088197, 0.033315, 0.114919, + -0.04918, 0.025707, 0.053843, 0.035182, 0.140206, -0.05866, -0.025978, -0.019658, -0.014847, + -0.021051, -0.034385, -0.121789, 0.173406, -0.112251, -0.022333, 0.071206, 0.028998, 0.046468, + 0.067704, -0.026159, -0.158316, 0.014936, 0.040216, -0.010137, -0.053492, 0.004935, -0.011277, + 0.073852, 0.091261, 0.114794, -0.01406, -0.051545, 0.077316, 0.101258, -0.046137, 0.022994, + -0.066767, -0.065537, 0.049952, -0.043582, 0.012823, 0.009313, 0.036343, 0.054885, 0.037796, + 0.02194, 0.013211, 0.006019, -0.099578, 0.058596, -0.045463, -0.015632, -0.087141, -0.019273, + -0.03314, 0.043796, 0.119057, -0.081813, -0.021538, -0.070453, -0.052551, 0.077213, 9.4e-05, + 0.050268, 0.092271, 0.051688, -0.025224, 0.075437, 0.027983, 0.069205, 0.031787, -0.099975, + 0.004387, -0.002747, -0.056567, 0.161394, 0.000164, 0.084189, -0.124844, 0.050329, 0.009844, + 0.055877, 0.055701, 0.030479, 0.028843, -0.001076, -0.017173, -0.10277, -0.038426, -0.133841, + -0.03584, -0.072046, 0.020206, 0.016438, -0.097885, 0.041857, 0.034601, 0.030422, -0.089192, + -0.014112, -0.052276, 0.012005, -0.029335, -0.011331, 0.101833, 0.063827, 0.044288, 0.101597, + -0.034689, -0.027434, -0.017801, -0.079224, 0.067103, -0.027456, -0.098034, 0.009448, + -0.038986, -0.156729, 0.085023, 0.033136, -0.021343, 0.110701, -0.011901, -0.006484, 0.082023, + -0.027094, 0.091208, -0.013163, -0.012223, 0.005933, 0.010653, -0.098119, -0.005304, -0.021061, + -0.058077, -0.073035, 0.097856, -0.102847, -0.035329, -0.092754, -0.101463, -0.048671, + 0.055015, 0.102145, 0.062017, 0.016002, 0.036489, 0.059, 0.042861, 0.025447, -0.019735, + -0.107841, -0.033752, -0.043982, -0.067059, 0.051092, 0.025235, -0.147107, -0.016269, 0.123009, + 0.035894, -0.020453, 0.040013, 0.015557, 0.015825, 0.080712, -0.06963, -0.149739, 0.022006, + -0.008848, 0.040169, -0.095688, 0.059575, -0.030641, -0.061353, 0.046302, 0.104489, 0.043372, + -0.001579, 0.059737, -0.104073, 0.042342, -0.048611, -0.013811, -0.056255, 0.107179, 0.057433, + 0.084815, 0.030217, 0.02236, -0.040342, -0.028775, 0.120588, 0.04127, -0.045775, -0.030195, + -0.106859, -0.104349, 0.072418, -0.003603, -0.013072, 0.040728, 0.086869, 0.091943, 0.066517, + 0.024442, -0.030929, -0.03292, -0.160336, -0.010347, -0.068458, 0.017458, 0.044823, 0.050694, + 0.067625, 0.040303, 0.113164, -0.038747, -0.065558, -0.106357, -0.028352, 0.121488, 0.026548, + -0.00782, 0.054872, 0.094674, -0.099533, 0.005231, 0.118132, 0.04278, -0.065079, 0.03144, + 0.043229, -0.050024, 0.015943, 0.073917, 0.034049, 0.010548, -0.024979, 0.022639, 0.027795, + 0.049491, 0.048762, -0.002738, -0.010783, -0.027637, -0.006986, -0.104141, -0.066719, + -0.061742, -0.067028, -0.053057, -0.003478, -0.050948, -0.122196, 0.022082, 0.002595, 0.015094, + 0.006014, 0.005784, -0.184537, -0.034872, -0.036104, 0.055412, 0.006886, 0.103488, -0.063001, + 0.096665, -0.035533, 0.009847, -0.095114, 0.008588, 0.023736, -0.034278, -0.11197, -0.041172, + 0.03973, -0.102952, 0.063775, 0.039273, 0.109863, 0.0918, 0.030306, -0.082206, 0.089449, + -0.058478, -0.029341, 0.038389, 0.061057, -0.024711, 0.111044, -0.035079, -0.027985, 0.01457, + 0.002046, -0.031545, 0.058848, -0.0195, -0.002475, -0.025589, -0.144358, 0.063478, 0.124927, + -0.014094, -0.01097, 0.031621, -0.040043, 0.004389, 0.025003, 0.052397, -0.054526, -0.073469, + 0.026795, -0.024697, 0.024739, 0.118299, 0.014948, -0.132109, 0.020192, 0.037815, -0.09027, + 0.049313, 0.082764, -0.022642, -0.006053, -0.038073, -0.057363, -0.107347, 0.033166, -0.027556, + -0.019765, -0.111958, 0.027773, -0.063001, -0.052998, 0.019353, -0.009646, -0.01127, 0.011872, + -0.006508, -0.122226, 0.059824, 0.041779, 0.016445, -0.03189, -0.03631, 0.013085, 0.091631, + 0.062866, 0.054501, -0.117523, -0.010907, 0.087026, -0.014974, -0.03592, -0.048565, -0.019246, + -0.043405, -0.006959, 0.006211, 0.04237, 0.014603, -0.006435, 0.019149, 0.078038, -0.020556, + 0.018114, -0.036521, -0.054036, 0.007325, 0.056349, -0.033497, -0.02596, 0.050184, -0.066536, + 0.091501, 0.071356, -0.049044, -0.032263, -0.095268, -0.008784, 0.049033, 0.036929, 0.020357, + 0.152151, 0.040814, -0.063159, -0.024324, -0.017084, 0.011876, -0.015442, -0.019811, -0.000366, + -0.0027, -0.072981, 0.109288, 0.007473, -0.049442, -0.05404, 0.051947, 0.019359, 0.12916, + 0.021981, 0.002248, 0.035262, -0.023141, 0.064666, -0.078273, -0.031663, -0.031343, -0.006058, + -0.045421, 0.017466, -0.067122, -0.130784, 0.067057, 0.05246, -0.041165, -0.004411, 0.046453, + -0.055461, 0.048162, -0.009687, 0.02153, 0.007211, 0.104764, 0.079849, 0.086248, -0.072791, + 0.001112, -0.027964, -0.071233, -0.013339, 0.007979, -0.118231, 0.076826, -0.060762, -0.084358, + -0.011447, 0.009765, 0.014163, 0.164784, -0.015892, -0.020756, 0.152509, -0.014014, -0.041853, + -0.117008, -0.011755, -0.005766, -0.086896, -0.13965, -0.032342, 0.025651, -0.007843, + -0.039073, 0.103397, -0.042591, -0.005971, -0.001324, -0.053945, -0.000716, 0.048977, 0.130185, + 0.028226, 0.061179, 0.024489, -0.021939, -0.007019, 0.054336, -0.01004, -0.095411, 0.082406, + -0.03213, -0.015054, 0.033059, 0.002802, -0.080159, -0.022452, 0.077426, -0.015314, 0.033583, + 0.028479, 0.023293, 0.035078, 0.006442, -0.110541, -0.106244, -0.034737, -0.10414, -0.03457, + -0.114316, 0.079382, 0.006009, 0.003901, 0.080081, 0.055082, 0.012896, 0.064981, 0.057219, + -0.112986, 0.003906, -0.028414, -0.012383, -0.054541, 0.077483, 0.004267, 0.123567, 0.007369, + 0.099856, 0.023273, -0.028194, 0.12203, -0.036635, -0.126589, -0.034567, -0.028288, -0.06504, + 0.01428, 0.011435, -0.004867, 0.043901, 0.035395, 0.028599, 0.075858, 0.11846, 0.070581, + -0.051903, -0.170905, 0.050352, 0.053514, -0.017139, 0.021748, -0.09661, 0.008904, -0.001049, + 0.078787, -0.101201, -0.026229, -0.019757, -0.035771, 0.054142, 0.068041, -0.020328, 0.099979, + 0.096623, -0.046957, -0.001733, 0.049586, 0.052458, -0.031724, -0.028332, -0.005418, 0.04671, + 0.014238, 0.133125, -0.005428, -0.080055, -0.033226, 0.034007, 0.025272, 0.033924, -0.044662, + -0.03469, -0.079173, -0.160689, -0.153893, -0.228771, -0.00245, -0.083966, -0.168294, 0.010694, + -0.012167, 4e-06, -0.044377, 0.023373, -0.077437, 0.012178, -0.015899, -0.010828, -0.062847, + 0.029927, -0.074557, -0.053306, 0.049688, 0.057017, -0.022571, 0.015337, -0.046545, 0.018895, + -0.024848, -0.004424, 0.165442, -0.060201, -0.098629, -0.06519, 0.036582, -0.038566, 0.051453, + 0.093478, 0.039619, 0.117535, 0.090386, -0.029366, 0.108075, -0.016568, -0.093576, -0.048799, + -0.045599, -0.023619, 0.070072, -0.109294, 0.001548, 0.076285, -0.091274, -0.068829, 0.000215, + -0.046519, -0.022512, -0.027067, 0.014905, 0.079017, 0.140699, 0.061141, 0.009178, 0.097811, + 0.033468, -0.006666, 0.007163, -0.007578, -0.124238, -0.025271, 0.017581, 0.042405, -0.034252, + 0.06489, 0.0025, -0.139083, 0.009733, 0.158179, 0.014474, 0.038913, 0.05629, -0.004998, + 0.075401, -0.030557, -0.038595, -0.04907, -0.01468, -0.076306, -0.132365, -0.177693, 0.09176, + -0.057238, -0.072379, 0.050877, 0.051489, 0.028125, 0.004991, 0.032621, -0.167359, 0.041002, + -0.007072, -0.086405, -0.042263, -0.019757, -0.011524, 0.066004, 0.08567, 0.008071, -0.013614, + -0.062142, 0.08328, 0.000887, -0.07582, 0.008295, -0.020136, -0.016886, 0.089657, -0.10626, + -0.051491, -0.012687, 0.054778, 0.011535, 0.086613, 0.053803, 0.027164, -0.023825, -0.040009, + 0.080987, 0.026309, -0.000334, -0.085288, -0.024208, -0.08504, 0.096077, 0.120527, -0.044181, + 0.003034, -0.091142, 0.006471, 0.115971, -0.026358, 0.003489, 0.083633, 0.109975, -0.029425, + 0.061726, 0.056115, -0.006711, 0.013158, -0.062917, -0.015029, 0.003354, 0.031574, 0.119045, + 0.022859, 0.023777, -0.068292, 0.115604, 0.031617, 0.008953, 0.006943, 0.01442, 0.008569, + -0.031547, -0.006857, -0.05169, -0.086683, -0.108339, 0.005093, -0.108646, -0.03472, 0.054273, + -0.096753, 0.050806, -0.021115, -0.025278, -0.079997, 0.027008, -0.034211, 0.090949, 0.005678, + 0.019288, 0.042083, 0.062119, 0.019301, 0.040859, -0.009113, 0.022427, -0.004019, -0.06089, + 0.032884, -0.012373, -0.037976, 0.017625, -0.079369, -0.050788, 0.07972, -0.039347, -0.085324, + 0.091044, 0.026653, -0.063122, 0.099371, -0.024736, 0.084631, -0.100421, -0.073313, 0.014317, + 0.022555, -0.116051, -0.063966, -0.009688, -0.063666, -0.131709, 0.016744, -0.135028, + -0.003708, -0.043685, -0.121631, -0.03693, 0.125776, 0.084333, 0.010114, 0.071231, -0.010395, + 0.059391, 0.01776, 0.033034, -0.018996, -0.13054, 0.025758, -0.018261, -0.060044, 0.127025, + -0.032724, -0.107299, -0.064538, 0.090073, -0.010186, -0.066127, 0.107025, -0.01094, 0.003083, + 0.01903, -0.023935, -0.140176, 0.003549, -0.042402, -0.010695, -0.185915, 0.060835, 0.005405, + -0.013822, 0.029205, 0.079338, 0.068155, 0.071485, 0.030282, -0.087207, 0.07348, -0.02794, + 0.004896, -0.033246, 0.072637, 0.018017, 0.054712, 0.026184, -0.005287, 0.034456, -0.036753, + 0.079232, 0.072707, 0.004506, -0.039353, -0.01556, -0.071466, 0.010257, 0.067446, -0.006598, + 0.047396, 0.072218, 0.023405, 0.082663, 0.015319, -0.035436, -0.075461, -0.124036, -0.032046, + 0.060837, 0.010231, -0.053024, 0.0228, 0.042891, -0.041549, 0.132395, -0.09533, -0.077091, + -0.058554, -0.070632, 0.04757, 0.031856, 0.000127, 0.114996, 0.05866, -0.092472, 0.064503, + 0.09645, 0.0662, -0.001059, 0.039487, -0.032859, -0.065721, 0.001601, 0.088037, 0.059828, + -0.047411, -0.077714, 0.010275, 0.013629, 0.003304, 0.005407, 0.000665, 0.012927, -0.077525, + 0.069202, -0.157417, 0.014547, -0.095965, -0.087546, -0.067375, -0.027867, 0.005458, -0.095839, + 0.105294, -0.044892, 0.045151, -0.001349, 0.038356, -0.127152, -0.080503, -0.105423, -0.018484, + 0.008439, 0.104398, -0.027959, 0.082086, -0.020605, 0.042785, -0.109139, -0.025958, 0.079733, + 0.036289, -0.083773, -0.033819, 0.032566, -0.065556, 0.006659, 0.00209, 0.097027, 0.115715, + -0.013271, -0.067514, 0.128365, -0.089129, 0.02616, -0.040584, -0.002443, -0.017254, 0.129204, + -0.110078, -0.064943, 0.089215, -0.022299, -0.034959, 0.022446, -0.019254, -0.0389, -0.069862, + -0.07054, 0.069949, 0.111993, -0.006311, -0.009057, 0.094278, -0.014932, 0.003657, -0.019323, + 0.026145, -0.062611, -0.073753, -0.007182, 0.014101, 0.015776, 0.052537, 0.064728, -0.160187, + -0.005122, 0.076356, -0.104763, 0.091493, 0.020225, -0.000433, 0.062698, -0.060457, -0.14754, + -0.066168, 0.007195, -0.061498, -0.037801, -0.039763, 0.059551, -0.02841, -0.07451, 0.057667, + 0.020584, -0.04251, -0.025311, -0.037825, -0.18801, 0.077423, 0.030749, -0.025465, -0.067541, + 0.003073, -0.049778, 0.127789, 0.002786, 0.120009, -0.067812, -0.026565, 0.111272, 0.023219, + -0.024403, -0.014507, -0.048624, 0.022163, 0.014596, -0.052136, 0.00158, 0.064595, 0.017963, + 0.02133, 0.098862, -0.009253, -0.041062, 0.008903, -0.013829, 0.031967, 0.076571, -0.005348, + -0.04401, 0.031252, 0.000369, 0.036818, 0.072854, -0.038569, 0.004161, -0.128017, -0.053152, + 0.050896, -0.015212, -0.036159, 0.097995, 0.068397, -0.048472, -0.056131, -0.01192, 0.059188, + 0.010215, -0.061152, -0.011717, -0.035949, -0.057039, 0.090859, -0.029682, 0.041466, -0.025106, + 0.131191, 0.059327, 0.085383, 0.021699, 0.04923, 0.03663, -0.077086, 0.017806, -0.08879, + 0.00404, -0.069533, -0.026785, 0.009666, 0.014017, -0.055897, -0.096299, 0.120693, 0.029995, + 0.032602, -0.001365, 0.034015, -0.053512, 0.001573, -0.01917, 0.003956, 0.006452, 0.067313, + 0.028301, 0.160615, -0.053111, 0.01399, -0.02706, -0.013638, 0.039376, -0.054462, -0.096553, + 0.079994, -0.043791, -0.025051, -0.003222, 0.019418, -0.049525, 0.151136, 0.034123, 0.055117, + 0.058918, -0.017393, 0.026169, -0.12638, -0.019008, -0.028939, -0.014027, -0.173373, -0.032841, + -0.00337, 0.03968, -0.118311, 0.114094, -0.041869, 0.041121, -0.038391, -0.096074, -0.032479, + 0.060222, 0.063968, -0.024528, 0.018158, -0.009892, -0.043882, -0.005004, 0.1298, -0.025438, + -0.121186, 0.04986, 0.010448, -0.040388, 0.061853, -0.017304, -0.035088, -0.008678, 0.061476, + -0.039493, -0.005055, 0.079169, 0.046134, 0.00977, 0.068294, -0.078965, -0.043792, -0.030529, + -0.053845, 0.053853, -0.140682, 0.111461, 0.003549, -0.014939, 0.148955, 0.072861, 0.004332, + 0.015386, 0.062006, -0.122325, -0.032529, 0.010241, -0.047982, -0.12644, 0.05584, 0.067128, + 0.101189, -0.00263, 0.031969, 0.046076, -0.080194, 0.10474, -0.033486, -0.077818, -0.058697, + -0.095258, -0.111074, 0.037236, 0.011711, 0.001113, -0.005664, 0.048588, 0.041131, 0.098257, + 0.033126, 0.029317, -0.095311, -0.071555, -0.039999, 0.026678, -0.072182, 0.035031, -0.007997, + -0.048174, -0.006796, 0.075959, -0.05206, -0.007645, 0.037076, -0.035574, 0.085576, 0.034126, + -0.050676, 0.05143, 0.031999, -0.134308, -0.001489, 0.084564, -0.018394, -0.09741, -0.042931, + -0.025608, -0.025489, 0.041919, 0.142482, 0.004617, -0.041085, -0.028816, -0.015527, -0.031005, + 0.028405, -0.02224, -0.067737, -0.025241, -0.052578, 0.012322, -0.120556, 0.016278, -0.081744, + -0.09916, 0.025144, 0.025441, 0.003176, -0.073871, 0.031718, -0.028622, 0.029031, 0.01791, + -0.030693, -0.104215, -0.015422, -0.065738, -0.048346, -0.012847, 0.046849, -0.008621, + 0.058771, -0.054495, 0.031597, -0.038844, 0.043138, 0.092588, -0.071371, -0.059093, -0.001197, + 0.001766, -0.074762, 0.02947, 0.089616, 0.005009, 0.052977, 0.015899, -0.045424, 0.158466, + -0.038717, -0.032506, 0.028687, 0.011435, -0.006772, 0.047605, -0.144659, -0.031229, 0.073577, + 0.01153, -0.008172, 0.058883, -0.088412, 0.033615, -0.03412, -0.030701, 0.101215, 0.096645, + 0.027368, 0.041249, 0.081502, -0.02544, 0.007592, 0.059893, 0.012106, -0.112009, -0.114692, + 0.016397, 0.087068, 0.016199, 0.051263, 0.011915, -0.085364, 0.026046, 0.145258, -0.047521, + 0.077134, -0.000345, 0.034532, 0.099801, -0.087591, -0.059719, -0.058671, 0.022737, -0.001887, + -0.107049, -0.116757, 0.134115, -0.055403, 0.005157, 0.067618, 0.081074, 0.071787, 0.063802, + -0.00343, -0.106491, 0.017543, 0.002214, -0.013785, -0.032962, 0.010084, 0.024325, 0.045963, + 0.059883, 0.072282, -0.008608, -0.015127, 0.048225, 0.041752, -0.068845, 0.012227, -0.090748, + -0.035309, 0.045353, -0.078624, -0.019489, 0.035531, 0.058571, 0.045414, 0.039032, -0.011106, + 0.048787, -0.025336, -0.084893, 0.031896, 0.01085, 0.012526, -0.053205, 0.016952, -0.044041, + 0.068766, 0.097328, -0.122229, 0.027016, -0.051759, -0.057246, 0.074566, 0.006201, 0.069904, + 0.100068, 0.076124, 0.004278, 0.029466, 0.045229, 0.055683, 0.01879, -0.067806, 0.039373, + 0.029179, -0.036787, 0.129921, -0.028993, 0.037711, -0.105011, 0.138747, -0.00437, 0.05208, + 0.050835, 0.025511, -0.002962, 0.007852, -0.055234, -0.075055, 0.00046, -0.089231, -0.030467, + -0.080347, 0.007488, 0.06746, -0.076368, 0.084991, 0.039544, 0.033391, -0.044318, 0.00639, + -0.079387, -0.002909, -0.029708, -0.047882, 0.06304, 0.065719, 0.021811, 0.070945, -0.007571, + -0.001302, -0.064119, -0.068005, 0.05104, -0.017747, -0.063938, 0.018673, -0.038391, -0.099966, + 0.057475, -0.007669, 0.009384, 0.109283, 0.012248, -0.048858, 0.092498, 0.011967, 0.061525, + -0.028819, -0.015131, -0.02416, -0.03322, -0.101648, -0.01798, -0.003342, -0.049829, -0.125096, + 0.128241, -0.047377, -0.028943, -0.109072, -0.066133, -0.015454, 0.098334, 0.053371, 0.011324, + 0.042781, 0.044313, 0.06251, 0.098408, 0.06541, -0.040693, -0.116351, -0.032327, -0.013634, + -0.058591, 0.081507, 0.042019, -0.09977, -0.018275, 0.084624, -0.007512, -0.041113, 0.054203, + 0.017879, -0.029747, 0.059865, -0.048281, -0.111513, -0.022478, 0.002059, 0.022383, -0.12536, + 0.058216, 0.002386, -0.0816, 0.049288, 0.157428, 0.057724, 0.005046, 0.102125, -0.083473, + 0.044059, -0.094864, 0.03912, -0.063306, 0.057341, 0.060519, 0.107383, 0.007076, -0.009373, + -0.012555, -0.06663, 0.117121, 0.025254, -0.008796, -0.062102, -0.083164, -0.079007, 0.084839, + 0.042308, -0.055353, 0.036386, 0.132641, 0.084464, 0.056288, -0.011636, -0.059554, -0.087748, + -0.147377, -0.052414, -0.010203, -0.009159, -0.018829, 0.009621, 0.061633, 0.015716, 0.086332, + -0.061465, -0.011833, -0.062998, -0.021168, 0.125194, 0.045025, 0.052316, 0.02572, 0.095155, + -0.093252, 0.02872, 0.056113, 0.063321, -0.045315, 0.025199, 0.023591, -0.070481, 0.07235, + 0.092458, 0.047973, -0.025439, -0.001281, 0.021028, 0.034576, 0.084779, 0.006867, -0.010323, + -0.04633, -0.009172, 0.030485, -0.117679, -0.021782, -0.034737, -0.086292, -0.045885, 0.009655, + -0.037167, -0.123331, 0.017291, -0.028319, 0.071447, -0.05718, -0.032912, -0.139418, -0.025966, + -0.039305, 0.009411, -0.054017, 0.076307, -0.060252, 0.110087, -0.061366, 0.038897, -0.098107, + 0.046119, 0.043021, -0.02913, -0.096885, 0.007623, 0.090513, -0.097416, 0.053264, 0.058296, + 0.054372, 0.060769, 0.015586, -0.067956, 0.059996, -0.03785, 0.005986, 0.000778, 0.045873, + -0.065546, 0.0779, -0.085638, 0.000698, 0.027694, -0.021241, -0.002777, 0.034509, -0.048173, + 0.009988, 0.001008, -0.077434, 0.026002, 0.13949, 0.00891, 0.007791, 0.059292, -0.057047, + 0.014127, -0.022959, 0.08571, -0.068087, -0.081561, 0.005935, 0.007577, 0.061544, 0.076542, + 0.00166, -0.113279, 0.024973, 0.08675, -0.061674, 0.095059, 0.089352, -0.024436, 0.024181, + -0.016117, -0.073634, -0.067986, 0.074701, -0.046868, -0.054634, -0.092485, 0.006662, + -0.033256, -0.053774, 0.049001, -0.002339, 0.013545, -0.006432, -0.012089, -0.086842, 0.104105, + 0.061991, +]; +/* codebook/lspjvm3.txt */ +const codes2: [f32; 2560] = [ + 0.007066, 0.075781, -0.070082, -0.092014, -0.066477, 0.09051, 0.106622, 0.025911, -0.01676, + 0.003724, -0.024628, 0.058332, 0.012876, 0.059557, -0.002092, -0.065092, -0.096975, -0.041837, + -0.002432, 0.058918, 0.014358, 0.080049, -0.008803, -0.002091, -0.097584, 0.085323, -0.026053, + -0.086585, -0.009541, 0.130555, 0.045391, 0.037557, 0.074726, -0.050453, 0.033517, -0.035576, + -0.084211, -0.08643, 0.00891, -0.072674, -0.098699, -0.02454, -0.048972, -0.066975, -0.048791, + 0.032184, 0.070992, -0.014416, 0.141892, -0.044249, -0.108921, -0.02045, 0.115988, 0.011287, + -0.026273, 0.024341, 0.138519, -0.036467, 0.020684, 0.074258, -0.053563, 0.077463, 0.072166, + 0.032112, -0.079303, -0.025039, 0.079675, 0.094211, -0.115754, 0.038892, 0.050897, -0.024639, + 0.057826, -0.110429, 0.071184, 0.015309, -0.034027, -0.055726, 0.043179, -0.063089, 0.043359, + -0.011698, 0.006637, 0.002751, 0.03011, -0.001261, 0.11147, 0.043277, -0.004205, -0.021599, + -0.005698, 0.058842, 0.168422, 0.059313, -0.007971, -0.087599, 0.073891, -0.083238, 0.099279, + -0.017364, -0.018429, 0.01404, -0.014864, -0.111512, 0.08945, -0.028498, -0.087983, -0.07732, + -0.062602, 0.000328, -0.027152, -0.093796, 0.111381, -0.018603, 0.092394, -0.007256, 0.025391, + 0.011454, 0.012802, -0.04168, 0.008078, 0.020905, -0.105401, -0.083265, 0.027756, -0.04963, + -0.044085, -0.051424, 0.104125, -0.000779, -0.063079, -0.130699, 0.0705, 0.033468, -0.019802, + -0.061011, 0.094839, -0.040122, 0.118409, 0.05695, 0.086391, -0.006615, 0.045337, -0.04419, + -0.106474, -0.081912, 0.067557, -0.031649, -0.014437, 0.057585, -0.121755, -0.049113, 0.057109, + -0.049872, 0.044104, 0.064705, -0.091589, 0.037286, -0.048606, -0.045398, 0.003456, 0.05723, + 0.006262, -0.055206, -0.063871, -0.005249, 0.081783, 0.134969, -0.002331, 0.052643, -0.093346, + 0.072093, 0.116025, -0.031453, -0.006012, -0.038574, -0.030841, 0.010288, 0.02442, 0.051657, + -0.086584, 0.046381, 0.00541, 0.052622, -0.072741, 0.079023, 0.078099, -0.093912, 0.005477, + -0.006721, 0.100232, -0.017587, 0.044819, 0.036655, 0.02158, -0.006829, -0.050076, -0.00302, + 0.088246, 0.01356, -0.01569, 0.012477, -0.052595, -0.048861, -0.033688, 0.055615, 0.092298, + -0.066194, 0.016416, -0.066059, 0.046976, 0.003023, 0.104646, 0.109136, 0.018293, -0.016507, + -0.006859, 0.004326, 0.070843, 0.14075, 0.025774, 0.03473, -0.07959, 0.050054, -0.10795, + 0.002378, 0.097498, 0.027111, -0.122953, -0.002423, -0.020539, -0.063263, -0.095493, -0.157361, + -0.039183, 0.025721, 0.026897, -0.0012, 0.033997, -0.001749, 0.061593, -0.013053, -0.106317, + -0.06819, 0.046352, -0.05606, 0.157084, -0.049365, 0.053959, -0.051065, -0.047672, 0.08157, + 0.064342, -0.030705, -0.070806, -0.076503, -0.059471, 0.012419, 0.073968, -0.026179, -0.038473, + 0.059013, -0.035783, -0.030057, -0.036346, -0.052692, -0.015346, -0.022687, -0.035279, + 0.013314, 0.068397, -0.046609, -0.009593, -0.040796, 0.157438, -0.07536, -0.110464, 0.031839, + -0.029035, -0.015222, 0.041013, -0.099212, -0.10892, -0.008627, 0.012095, 0.020855, 0.009935, + -0.086917, 0.058827, -0.006536, 0.022104, -0.005013, 0.003496, 0.046663, -0.051061, -0.036803, + -0.067317, -0.007075, 0.18087, -0.027434, -0.025056, -0.039341, -0.073918, -0.00318, -0.11093, + -0.042711, 0.005519, -0.035005, -0.088419, 0.170942, 0.001503, -0.121485, 0.066383, -0.067346, + 0.005643, 0.080088, -0.042562, -0.006668, -0.036538, 0.020683, 0.042848, 0.027852, -0.029088, + -0.156468, 0.006503, 0.037716, 0.032082, 0.038416, 0.021835, -0.106963, -0.043017, 0.018166, + 0.070409, -0.005426, -0.035585, -0.111071, -0.039986, 0.05043, 0.035157, 0.066902, -0.040684, + 0.060527, 0.036225, 0.002527, -0.015087, 0.059243, 0.021268, -0.010682, -0.018434, 0.059128, + 0.111314, -0.05407, 0.105744, -0.051476, -0.01297, -0.000358, -0.099249, -0.077385, 0.069924, + -0.039101, -0.072139, -0.049069, -0.088018, 0.006144, 0.000712, 0.08103, 0.021987, -0.046031, + 0.058087, -0.00132, -0.046851, -0.011062, 0.108321, -0.001146, -0.071193, 0.044973, -0.002915, + -0.003323, 0.041735, 0.094566, 0.05353, 0.035927, 0.100282, 0.059082, -0.054059, -0.012158, + -0.035417, 0.020412, -0.073193, 0.059296, -0.040489, -0.09525, -0.003821, -0.084904, 0.053925, + 0.109183, -0.005862, -0.036538, 0.080962, -0.040647, 0.02007, 0.057778, -0.020197, -0.079626, + -0.003186, -0.050855, 0.128185, 0.034731, 0.05746, -0.035236, -0.057096, -0.001238, 0.122018, + -0.071204, -0.047253, -0.051767, 0.048301, -0.052678, 0.02599, -0.017481, -0.029379, 0.030738, + 0.047207, -0.047864, -0.033561, 0.029884, -0.091175, -0.085446, -0.02614, 0.092628, 0.067706, + -0.085617, 0.081433, 0.047305, 0.031945, -0.048728, -0.040387, 0.046206, 0.010578, -0.037639, + 0.011328, -0.042458, -0.149597, 0.033882, -0.061869, 0.0088, 0.057754, -0.095876, 0.03823, + 0.096876, -0.033487, -0.141669, -0.014172, 0.028439, -0.092764, -0.053714, 0.086926, 0.034786, + 0.136053, -0.005569, 0.028753, 0.00963, 0.044114, -0.050365, -0.066224, 0.006017, 0.014348, + 0.024471, 0.000489, 0.067234, -0.021678, -0.11876, 0.036349, -0.040295, 0.076358, -0.008444, + -0.086082, -0.044018, -0.025804, 0.028971, -0.009233, 0.053026, -0.035341, -0.182193, + -0.102515, 0.08921, 0.066812, 0.032417, 0.046882, -0.034815, -0.052293, 0.022814, 0.129622, + 0.128232, -0.012105, -0.087084, 0.004762, 0.086538, 0.046566, 0.098359, -0.018713, 0.039204, + -0.021707, -0.06011, -0.117527, -0.005459, 0.060994, -0.057718, -0.021783, 0.035154, 0.100557, + -0.01547, -0.025818, 0.00845, 0.051535, -0.001388, -0.11461, -0.057903, 0.041862, 0.061778, + 0.045701, -0.078563, -0.070166, -0.04845, -0.08853, 0.021375, -0.004598, -0.09071, -0.009399, + -0.073952, -0.035575, -0.05028, 0.11478, 0.137866, 0.065234, 0.003594, -0.066802, -0.144989, + 0.166201, 0.039564, -0.022457, -0.03009, 0.016187, 0.115443, -0.097331, -0.019139, 0.09944, + 0.002198, -0.030953, 0.021099, -0.045399, -0.046871, 0.022533, -0.064657, 0.005776, 0.049063, + -0.028478, 0.019268, 0.054265, 0.028042, 0.045559, -0.005541, -0.01441, -0.024165, -0.054976, + -0.073258, 0.084205, 0.036077, -0.068683, 0.004708, -0.085228, 0.001234, 0.046261, -0.050496, + -0.028227, -0.086828, -0.001218, 0.021865, 0.003791, -0.000568, -0.088733, -0.040041, + -0.035891, -0.054915, 0.073463, -0.132031, -0.012844, -0.068544, 0.013052, 0.087335, 0.038603, + -0.115382, -0.010433, -0.007113, 0.095126, -0.047378, -0.081353, 0.018021, -0.021156, + -0.120774, 0.040038, 0.007633, -0.088728, -0.009928, 0.020142, 0.052024, -0.021063, -0.118121, + 0.102739, -0.055837, 0.005253, -0.061924, 0.06368, -0.014512, -0.020259, 0.029493, -0.013435, + -0.020638, 0.089342, 0.001092, -0.046491, -0.145634, -0.083159, -0.158142, -0.279281, 0.003611, + 0.055863, -0.064655, -0.088773, 0.089283, -0.029619, -0.089949, 0.017197, -0.066633, -0.052347, + 0.090828, -0.087551, 0.000338, 0.085238, -0.005313, 0.096211, 0.071381, -0.076546, -0.077927, + -0.040864, 0.062936, 0.041559, 0.016235, -0.017513, 0.014773, -0.025734, 0.028586, 0.070292, + 0.055794, -0.026131, -0.076954, -0.082228, 0.043947, -0.035921, 0.152668, -0.04951, 0.023159, + 0.008506, -0.044773, -0.160358, 0.024984, -0.025587, -0.071627, -0.038376, 0.088478, 0.120568, + 0.046723, 0.086731, 0.000695, -0.015751, -0.027837, -0.160937, -0.095031, 0.036271, -0.009061, + -0.015078, -0.036281, -0.103665, -0.058258, -0.049573, 0.022021, 0.108296, -0.002586, 0.065655, + -0.018584, -0.046441, -0.031018, 0.06735, 0.014328, 0.00886, -0.000245, 0.0634, -0.00181, + 0.043515, 0.090344, -0.063845, 0.020485, 0.079401, 0.070558, -0.116428, 0.032628, 0.068949, + 0.052238, -0.04453, 0.096813, 0.029911, -0.008814, 0.044352, -0.168172, 0.009604, 0.055828, + -0.100739, -0.026013, 0.021193, -0.051425, 0.035891, -0.004085, 0.030216, -0.060801, 0.037202, + 0.007262, 0.120686, 0.026846, 0.058464, -0.100792, -0.009176, 0.027589, 0.123957, -0.011283, + -0.025744, -0.105081, 0.118244, -0.042122, -0.025404, 0.000873, -0.012703, 0.084159, -0.067539, + -0.140536, 0.041637, -0.014485, -0.043382, -0.048004, -0.075416, 0.054401, -0.018651, + -0.032908, 0.164231, -0.053236, 0.033946, -0.021681, -0.012655, -0.037049, -0.001613, + -0.053393, -0.014635, 0.017954, -0.116115, -0.027232, 0.034005, -0.035376, 0.026492, -0.03725, + 0.070733, 0.074835, -0.021378, -0.14298, 0.123195, 0.003699, 0.025398, 0.015629, 0.07737, + 0.032623, 0.12158, 0.0971, 0.000946, -0.056355, 0.042065, 0.008184, -0.081824, -0.101937, + 0.065473, 0.00336, 0.069241, 0.073002, -0.053844, -0.044301, 0.080351, -0.091833, 0.044288, + 0.007447, -0.120723, -0.013806, -0.023636, -0.064616, 0.030556, 0.07263, 0.074428, -0.087759, + -0.02644, 0.06484, 0.049162, 0.091053, 0.023891, 0.033811, -0.027746, 0.116392, 0.106126, + -0.056644, -0.014781, 0.036137, -0.002632, 0.055512, 0.070077, 0.067819, -0.030625, 0.053772, + -0.078457, -0.021351, -0.113011, 0.052797, 0.044875, -0.077269, -0.009867, 0.101493, 0.073477, + -0.024103, 0.049145, -0.004706, -0.025211, -0.053731, -0.049009, -0.035786, 0.05443, 0.046515, + 0.025154, -0.043569, -0.034789, -0.05861, 0.006931, 0.012049, 0.046809, -0.129441, 0.025541, + -0.030933, 0.000297, -0.054058, 0.179837, 0.081515, 0.004932, -0.028445, -0.073753, 0.010629, + 0.080042, 0.09871, -0.014017, 0.057597, 0.00101, 0.071658, -0.06757, 0.074384, 0.110366, + -0.018121, -0.108754, 0.037793, 0.028041, -0.047508, -0.031359, -0.098913, -0.036486, + -0.017311, -0.001279, -0.013694, 0.051968, 0.036512, 0.088201, 0.031155, -0.043442, -0.065045, + 0.023486, 0.027, 0.104768, -0.015176, -0.038754, -0.004178, 0.003732, 0.062166, 0.085438, + -0.077368, -0.101645, -0.118347, 0.007589, -0.056489, 0.082268, 0.020253, -0.035623, 0.034235, + -0.099354, -0.061237, -0.024285, 0.005441, -0.039694, -0.025957, -0.004411, 0.049903, 0.00304, + 0.036243, 0.023552, -0.007334, 0.128963, -0.077727, -0.059175, -0.019437, -0.024872, 0.004339, + 0.084006, -0.076605, -0.102261, 0.036714, -0.035205, -0.007642, -0.005125, -0.030525, 0.09639, + -0.053138, -0.002192, -0.024851, 0.050645, 0.04149, -0.043183, 0.046796, -0.050894, 0.055023, + 0.133834, -0.024013, 0.000872, -0.057072, -0.00063, 0.04207, -0.129339, -0.064283, 0.037836, + -0.066393, 0.004438, 0.125379, -0.062213, -0.067468, 0.090177, -0.046094, -0.025725, 0.079101, + -0.074909, -0.04373, -0.073483, 0.069672, -0.020413, -7.9e-05, -0.049725, -0.120751, -0.04698, + 0.039894, 0.072305, 0.009798, 0.005613, -0.045217, 0.006862, 0.036285, 0.074819, -0.006747, + 0.015144, -0.071562, 0.012324, -0.001082, 0.014835, 0.07996, -0.027804, 0.103358, -0.017203, + 0.014914, -0.056687, 0.030827, 0.028076, 0.003395, -0.073255, 0.11031, 0.056498, -0.044893, + 0.110122, -0.109058, -0.052302, -0.001604, -0.089977, -0.060548, 0.107808, 0.025463, -0.070203, + -0.000513, -0.123913, 0.046247, -0.085392, 0.096343, 0.09589, -0.06495, 0.070363, 0.034272, + 0.037773, -0.07695, 0.124858, -0.009008, -0.010115, 0.083868, 0.051242, 0.039149, 0.015185, + 0.083375, 0.029773, -0.045961, 0.100395, 0.003743, -0.138294, -0.041755, 0.010806, 0.057797, + -0.147374, 0.095858, -0.009929, -0.103347, -0.03231, -0.11056, 0.121377, 0.145244, 0.017079, + -0.080587, 0.020516, -0.044939, -0.010477, 0.038347, -0.003466, -0.001618, 0.0196, -0.021762, + 0.125482, 0.011074, 0.065815, 0.040298, 0.009202, -0.051686, 0.129684, -0.131135, 0.044536, + 0.009313, 0.102518, -0.075351, 0.054338, 0.020273, -0.045753, 0.031345, 0.000407, -0.097294, + -0.000416, -0.007466, -0.044972, -0.078744, 0.042414, 0.066624, 0.030318, -0.067852, 0.061416, + -0.028992, 0.056606, 0.004038, -0.036253, -0.014279, 0.023123, -0.007832, -0.000137, -0.027684, + -0.127648, -0.007713, -0.008746, -0.0265, 0.049032, -0.183319, 0.059107, 0.0665, 0.016902, + -0.093331, 0.090129, 0.016648, -0.083492, -0.023669, -0.010473, 0.027614, 0.145068, 0.000681, + 0.044133, -0.035809, 0.005668, -0.090461, -0.090732, -0.033927, 0.042997, 0.0217, -0.046955, + 0.044487, -0.026444, -0.061011, 0.01011, -0.023804, 0.030427, -0.015195, -0.155603, -0.016584, + 0.021461, -0.003528, -0.059784, 0.032214, 0.000847, -0.098859, -0.07898, 0.043188, 0.066433, + 0.062309, 0.144507, 0.006865, -0.068953, 0.046698, 0.099369, 0.043354, -0.014309, -0.033202, + -0.00295, 0.040734, 0.083454, 0.039319, 0.051358, 0.006074, -0.073465, -0.090554, -0.120787, + -0.040676, 0.092412, -0.085151, -0.021699, 0.005813, 0.103135, 0.024964, 0.025832, -0.075982, + 0.035699, -0.02731, -0.153007, 0.03642, 0.0576, 0.08163, 0.001605, -0.054191, -0.033043, + -0.01439, -0.071383, 0.03618, 0.03586, -0.04698, 0.038541, -0.044757, -0.078032, -0.029878, + 0.078183, 0.082251, 0.010549, 0.053317, -0.038231, -0.06561, 0.055798, 0.037504, 0.076317, + -0.027605, 0.010349, 0.095361, -0.088636, 0.049089, 0.113316, 0.051084, 0.038589, 0.03433, + -0.055948, -0.037217, -0.015418, -0.139976, 0.036306, 0.039306, -0.009889, -0.04491, 0.016559, + -5e-05, 0.106073, 0.01528, -0.002563, -0.109085, -0.048475, -0.035319, 0.16386, 0.032981, + -0.044932, 0.003227, -0.123233, -0.010638, 0.055479, -0.003666, -0.072249, -0.111158, 0.065365, + 0.010691, 0.039119, -0.001837, -0.118729, 0.06147, -0.002077, -0.033335, -0.060165, -0.026081, + -0.001806, -0.079616, -7.5e-05, 0.080598, 0.032908, -0.03514, -0.003136, -0.029024, 0.094622, + -0.075773, -0.022898, -0.014817, 0.058393, -0.111505, 0.036794, -0.01576, -0.112602, 0.030323, + 0.085897, -0.020834, 0.056079, -0.103762, 0.117671, -0.041205, 0.041684, -0.084336, 0.034186, + 0.011973, -0.006313, 0.040836, -0.035709, 0.03417, 0.122672, 0.090973, -0.053182, -0.059371, + 0.091017, -0.090998, -0.116986, 0.001405, 0.138364, 0.017107, -0.064076, 0.103486, -0.031142, + -0.030068, 0.046547, -0.133471, -0.042055, 0.140418, -0.125084, 0.035218, -0.001162, -0.02113, + -0.012034, 0.097413, -0.079006, -0.03903, -0.054011, 0.143887, 0.078835, -0.000601, -0.021173, + -0.039895, -0.02505, 0.075865, 0.039221, 0.032458, 0.038206, -0.038873, -0.085003, -0.032736, + -0.026956, 0.113525, -0.023933, 0.120794, -0.003862, -0.026459, -0.138724, 0.089559, 0.029002, + -0.052098, -0.085692, 0.115174, 0.083497, 0.024179, 0.119021, -0.067541, 0.019047, -0.02772, + -0.086083, -0.055329, 0.020087, -0.027086, -0.047858, -0.051975, -0.035205, -0.059342, + -0.068582, 0.058936, 0.044141, -0.080315, 0.119744, -0.046518, -0.064588, -0.027212, 0.147823, + 0.032404, 0.01669, 0.024302, 0.08556, -0.001525, 0.016469, 0.038891, -0.020146, 0.019943, + 0.045067, 0.03807, -0.086274, -0.025769, 0.044192, 0.102141, -0.064765, 0.055849, 0.048803, + -0.030066, -0.00922, -0.116655, 0.068295, 0.04758, -0.076138, -0.070307, 0.047582, -0.111342, + 0.004656, -0.004452, 0.029703, -0.004259, 0.01113, 0.014446, 0.166086, 0.059565, 0.000985, + -0.052607, 0.013251, 0.094476, 0.106216, 0.016715, -0.025581, -0.101244, 0.072897, -0.114526, + 0.024681, 0.010784, -0.051759, 0.032389, -0.050202, -0.083316, 0.052334, -0.0351, -0.116721, + -0.110336, -0.053391, 0.065541, -0.02979, -0.020457, 0.135285, -0.004142, 0.111508, -0.030936, + 0.018549, -0.016034, 0.018572, -0.084336, -0.048615, -0.018739, -0.096815, -0.090162, 0.01941, + -0.040821, -0.009925, -0.097427, 0.091891, 0.031793, -0.024598, -0.132848, 0.078353, 0.089339, + -0.068562, -0.020779, 0.040974, -0.055675, 0.169131, 0.029649, 0.078165, -0.050679, -0.005881, + -0.004983, -0.104324, -0.069096, 0.12796, 0.011392, -0.000769, 0.062168, -0.079842, 0.001606, + 0.089284, -0.035465, 0.031075, 0.029519, -0.102956, -0.010902, -0.06403, -0.019669, 0.057492, + 0.075802, -0.008904, -0.060743, -0.053144, 0.005126, 0.06298, 0.085674, 0.019895, 0.104448, + -0.086473, 0.056906, 0.056795, -0.01294, 0.036606, -0.008604, -0.04045, 0.042062, 0.04181, + 0.02768, -0.092256, 0.091237, -0.0395, 0.024761, -0.088978, 0.068585, 0.088295, -0.048033, + -0.017808, 0.04537, 0.1246, -0.03532, 0.056751, 0.092751, 0.054025, -0.015725, -0.061938, + 0.036806, 0.078768, -0.016065, 0.002444, -0.023887, -0.072177, -0.02979, -0.00586, 0.015478, + 0.129142, -0.091024, 0.071482, -0.065445, 0.005867, -0.006051, 0.098646, 0.054089, 0.018713, + 0.033837, -0.008355, -0.051959, 0.05744, 0.160305, -0.001863, 0.016738, -0.033705, 0.062233, + -0.140759, 0.027342, 0.060074, 0.030362, -0.117875, 0.06102, -0.028026, -0.088238, -0.003782, + -0.146288, -0.080395, 0.050048, 0.036136, 0.0195, 0.066902, 0.020355, 0.024817, -0.056254, + -0.140918, -0.085803, 0.02054, -0.00373, 0.161411, -0.049408, 0.000219, -0.002348, -0.055021, + 0.06782, 0.126483, -0.031063, -0.119299, -0.102834, 0.001133, 0.010172, 0.107707, -0.029106, + -0.059813, 0.036698, -0.02172, -0.043189, -0.00227, -0.031694, 0.009605, -0.022459, -0.036417, + 0.053675, 0.061561, -0.012723, 0.05004, -0.02945, 0.131044, -0.124516, -0.107579, -0.012171, + 0.011761, 0.002599, 0.016327, -0.060854, -0.08091, 0.030875, -0.002997, -0.02097, -0.01188, + -0.086096, 0.037912, 0.012421, 0.055253, -0.00725, 0.04174, 0.055596, -0.02442, -0.017564, + -0.079202, 0.008897, 0.180091, 0.05449, 0.001772, -0.022151, -0.082048, -0.010559, -0.163377, + -0.02066, -0.017827, -0.0308, -0.045856, 0.122405, -0.052946, -0.13049, 0.097383, -0.116737, + 0.039855, 0.056504, -0.059549, -0.059931, -0.018658, 0.034898, 0.054889, 0.005373, -0.066796, + -0.12736, 0.04796, 0.071746, 0.02741, -0.006212, 0.024132, -0.094062, 0.005369, -0.008926, + 0.073085, -0.014265, -0.029204, -0.100025, -0.072076, 0.014651, 0.069368, 0.048275, -0.066823, + 0.086074, 0.014921, -0.015395, -0.045138, 0.026224, 0.000902, -0.038208, -0.035221, 0.057397, + 0.097606, -0.073195, 0.051626, -0.033488, 0.027813, 0.00207, -0.09751, -0.057877, 0.12668, + -0.082194, -0.072597, 0.006014, -0.093185, -0.016853, -0.02279, 0.138461, 0.005394, -0.056485, + 0.102778, 0.028918, -0.045604, -0.060041, 0.121251, 0.02926, -0.101404, 0.061194, 0.033039, + -0.016798, 0.064263, 0.065144, 0.010925, 0.023151, 0.107623, 0.027977, -0.090356, -0.024863, + -0.00644, 0.04787, -0.047486, 0.088211, -0.012139, -0.116121, -0.000525, -0.140961, 0.016604, + 0.06349, -0.022732, -0.046944, 0.06697, -0.068838, 0.016143, 0.026202, -0.043344, -0.064881, + 0.024877, -0.072845, 0.120531, 0.077901, 0.047272, 0.011713, -0.044646, 0.040932, 0.076164, + -0.101233, -0.029615, -0.065118, 0.050966, -0.023273, 0.053517, 0.02371, -0.007489, 0.035822, + 0.023439, -0.055528, -0.004033, -0.007662, -0.096546, -0.081662, 0.037141, 0.137562, 0.075526, + -0.097496, 0.12399, 0.013996, 0.087005, -0.019788, -0.082043, 0.020524, 0.007027, -0.021537, + -0.036264, -0.090952, -0.177722, -0.009306, -0.031473, -0.009287, 0.047557, -0.090241, + 0.089347, 0.056375, -0.005506, -0.112128, 0.004356, 0.064421, -0.038478, -0.035674, 0.040616, + 0.007731, 0.160236, -0.054199, -0.007537, 0.012434, 0.022001, -0.021567, -0.075163, -0.026053, + 0.015909, 0.041015, 0.021832, 0.034152, -0.048539, -0.086655, 0.047465, 0.000682, 0.04264, + 0.023697, -0.095971, -0.022874, -0.000369, 0.003413, 0.046005, 0.064807, 0.010131, -0.129517, + -0.092254, 0.116469, 0.053796, 0.03811, 0.09447, 0.018435, -0.034803, 0.073591, 0.108348, + 0.104096, 0.049884, -0.021274, 0.022097, 0.065347, 0.065555, 0.089319, 0.000474, -0.004186, + -0.040493, -0.065543, -0.083167, -0.017425, 0.049177, -0.044248, 0.008399, 0.06818, 0.154778, + 0.027549, -0.008012, 0.01495, 0.043254, 0.039599, -0.136415, -0.018716, 0.0619, 0.031263, + 0.058118, -0.0372, -0.114692, -0.080876, -0.053238, 0.077436, 0.015015, -0.092517, 0.005804, + -0.065541, -0.005653, -0.073184, 0.095594, 0.08247, 0.060989, -0.000262, -0.035766, -0.083441, + 0.122634, 0.088429, -0.014397, -0.055434, -0.005659, 0.069697, -0.064892, 0.008824, 0.082498, + 0.051866, -0.03607, 0.033403, -0.082855, -0.087376, 0.002714, -0.097121, -0.01917, 0.027179, + -0.06987, -0.009316, 0.04745, 0.040657, 0.060527, 0.00462, -0.040264, -0.051228, -0.029023, + -0.071384, 0.101421, 0.009538, -0.099185, 0.0601, -0.048395, -0.024677, 0.025125, -0.056043, + -0.058045, -0.054059, 0.008107, 0.021078, 0.04529, -0.018459, -0.113359, 0.014009, -0.006826, + -0.052747, 0.046922, -0.075976, 0.008538, -0.084411, -0.004369, 0.045801, 0.075392, -0.06734, + 0.014454, 0.032407, 0.092478, -0.061859, -0.083458, 0.051442, 0.031695, -0.080233, 0.054028, + 0.027, -0.073549, 0.0323, 0.036501, -0.011384, -0.02078, -0.124142, 0.093905, -0.028332, + 0.039139, -0.030944, 0.079952, -0.001717, 0.013976, 0.038005, -0.001751, -0.044097, 0.129827, + 0.014385, -0.001682, -0.063458, -0.002511, -0.07815, -0.141236, 0.021955, 0.104851, -0.093246, + -0.060019, 0.069998, 0.004399, -0.096408, 0.059327, -0.062268, -0.074327, 0.108063, -0.090534, + -0.045654, 0.048119, 0.049187, 0.042105, 0.043964, -0.091516, -0.047999, -0.028881, 0.070471, + 0.055401, -0.025605, 0.011176, 0.008475, 0.022254, 0.038266, 0.048106, 0.047176, -0.017967, + -0.010978, -0.088762, 0.034806, 0.019311, 0.126815, -0.010571, 0.053073, 0.032162, -0.00078, + -0.1522, -0.014253, -0.021954, -0.13104, -0.061376, 0.113838, 0.060725, 0.020201, 0.102533, + -0.011392, -0.052046, -0.069625, -0.091011, -0.097954, 0.067847, 0.017856, -0.053461, + -0.040679, -0.121664, -0.077208, -0.106919, 0.057996, 0.069756, -0.012433, 0.069569, -0.055159, + -0.024801, -0.060448, 0.1017, 0.014619, 0.03658, -0.004526, 0.093977, -0.028211, 0.045261, + 0.149736, -0.014691, -0.007959, 0.097708, 0.107128, -0.079723, 0.029157, 0.020116, 0.104828, + -0.064208, 0.119172, 0.039583, -0.029446, 0.006628, -0.110398, 0.004062, 0.048132, -0.060601, + 0.009448, 0.051777, -0.053127, 0.050551, -0.001924, 0.028079, -0.050618, -0.013698, 0.00192, + 0.088162, 0.073078, 0.085795, -0.066788, 0.014025, 0.042699, 0.176241, -0.046674, -0.034822, + -0.051433, 0.121729, -0.057076, 0.023901, 0.045075, -0.057182, 0.05478, -0.01728, -0.146674, + 0.00209, -0.016223, -0.044841, -0.084524, -0.152479, 0.072688, -0.006962, 0.008711, 0.127455, + -0.003876, 0.053162, -0.013682, -0.025386, -0.000427, -0.024811, -0.024474, -0.056267, + 0.062116, -0.121311, -0.053011, 0.065651, -0.075385, -0.00868, -0.063033, 0.083039, 0.110577, + -0.000152, -0.127017, 0.055904, 0.013659, 0.005664, -0.002852, 0.047248, 0.001128, 0.100773, + 0.037274, 0.026368, -0.042205, 0.021887, -0.020247, -0.056678, -0.077475, 0.089799, 0.058003, + 0.039741, 0.106663, -0.016853, -0.015972, 0.075741, -0.048829, 0.015374, -0.032657, -0.125677, + -0.06206, -0.057409, -0.061287, 0.073151, 0.050357, 0.053547, -0.059886, -0.051298, 0.057954, + -0.003817, 0.076028, 0.006757, 0.061109, -0.03803, 0.143209, 0.092207, -0.018493, 0.062291, + 0.005751, -0.036449, 0.067582, 0.031449, 0.101894, -0.080754, 0.011515, -0.049485, -0.016137, + -0.087818, 0.108851, 0.038222, -0.099315, -0.003117, 0.052278, 0.107517, -0.036233, 0.06537, + 0.040409, -0.057029, -0.033167, -0.081758, -0.019502, 0.033438, 0.013365, -0.01776, -0.025906, + -0.020244, -0.078722, -0.011697, -0.028246, 0.068647, -0.106417, 0.026956, -0.064914, 0.062711, + -0.017857, 0.151539, 0.044613, -0.01782, 0.009085, -0.032785, -0.025795, 0.07579, 0.075667, + -0.040398, 0.058556, -0.042634, 0.093973, -0.099529, 0.057103, 0.073562, 0.01264, -0.066141, + 0.029558, 0.060219, -0.083699, -0.054799, -0.120442, -0.000374, 0.006521, 0.034512, -0.039558, + 0.042191, 0.033865, 0.103992, -0.014977, -0.077384, -0.05134, 0.001873, 0.047451, 0.140612, + -0.024885, -0.02142, -0.046604, 0.030606, 0.10066, 0.076356, -0.019288, -0.09857, -0.114463, + -0.010855, -0.034657, 0.025618, -0.003356, -0.087913, 0.064346, -0.07554, -0.091569, -0.024965, + -0.021232, -0.017255, -0.056931, -0.003104, 0.030219, -0.020112, -0.012334, 0.035298, 0.001405, + 0.161753, -0.064618, -0.064401, -0.007218, -0.00012, -0.047208, 0.116105, -0.056464, -0.069645, + -0.007032, -0.01209, -0.023237, 0.016, -0.039802, 0.074319, -0.012604, 0.014863, -0.058081, + 0.093219, 0.062253, -0.040302, 0.027405, -0.128683, 0.039923, 0.116808, -0.011706, 0.012483, + -0.017698, 0.003645, -0.007588, -0.120662, -0.032868, 0.066217, -0.031343, -0.034166, 0.146334, + -0.031228, -0.125921, 0.117756, -0.042686, -0.062094, 0.049375, -0.112262, 0.010166, -0.073599, + 0.04869, 0.028292, 0.020076, -0.062865, -0.106114, -0.0253, 0.066916, 0.029279, 0.028191, + -0.003599, -0.040614, 0.020491, 0.060238, 0.052747, -0.01039, -0.022389, -0.063358, -0.028707, + 0.035907, -0.011898, 0.079703, -0.003758, 0.078051, -0.017869, 0.009045, -0.018982, 0.034974, + 0.069405, -0.018909, -0.038613, 0.083909, 0.033935, -0.036607, 0.088891, -0.052599, -0.059839, + 0.052758, -0.068308, -0.063615, 0.126093, -0.00946, -0.042175, -0.011113, -0.073071, 0.052086, + -0.052619, 0.049226, 0.066898, -0.045666, 0.117923, 0.053656, -0.010739, -0.043962, 0.141903, + 0.001792, -0.035469, 0.090671, 0.043993, -0.013655, 0.018989, 0.127223, 0.00103, -0.001154, + 0.081839, -0.024979, -0.103704, -0.07792, 0.036083, 0.06822, -0.06221, 0.11373, -0.010501, + -0.065801, 0.050885, -0.104304, 0.121937, 0.11185, 0.00968, -0.011791, 0.001677, -0.035029, + 0.010677, 0.024572, -0.01286, -0.030323, -0.010466, 0.011279, 0.167752, 0.003136, 0.109709, + 0.007292, 0.000987, 0.004572, 0.108706, -0.113192, -0.012431, -0.015225, 0.073653, -0.051275, + 0.077928, -0.012752, -0.011708, 0.014172, 0.025162, -0.095378, 0.026382, -0.028889, -0.058569, + -0.129329, 0.011087, 0.061452, 0.056893, -0.058004, 0.103586, -0.060752, 0.081824, -0.042805, + -0.015991, -0.024444, 0.028952, -0.013528, 0.042851, 0.019988, -0.165741, -0.031012, -0.014713, + -0.026059, 0.031698, -0.134343, 0.03209, 0.020828, 0.051674, -0.128006, 0.050856, 0.02222, + -0.073513, -0.00934, 0.013756, 0.036163, 0.098407, -0.023495, 0.023858, 0.008121, 0.02222, + -0.103489, -0.046663, -0.033, 0.063565, 0.029224, -0.012693, 0.084202, 0.012187, -0.051, + 0.026126, -0.043293, 0.008675, -0.019812, -0.16507, -0.014555, -0.047431, 0.01799, -0.040073, + 0.107192, 0.022228, -0.089023, -0.066885, 0.01463, 0.073186, 0.069902, 0.072634, 0.019593, + -0.041539, 0.031788, 0.09231, 0.027223, 0.034027, -0.051855, 0.000391, 0.007869, 0.13191, + 0.069384, 0.046276, 0.04044, -0.037093, -0.031393, -0.112828, 0.015709, 0.096749, -0.103205, + -0.021284, 0.011405, 0.158287, -0.021028, 0.042219, -0.050759, 0.069715, -0.042907, -0.11698, + 0.014224, 0.094648, 0.028395, 0.041535, -0.057033, -0.047607, -0.024419, -0.034905, 0.010125, + 0.036728, -0.052503, -0.001839, -0.033477, -0.053414, -0.070394, 0.092895, 0.1006, -0.026352, + 0.080574, -0.028763, -0.059548, 0.094571, 0.091787, 0.041437, 0.014312, 0.045792, 0.108269, + -0.081586, 0.056288, 0.137447, 0.054718, -0.032474, 0.054502, -0.100144, -0.00646, 0.024739, + -0.117043, -0.008919, 0.070299, -0.036862, -0.014543, 0.0245, -0.015222, 0.114975, -0.043705, + 0.000421, -0.061872, -0.035148, -0.022797, 0.128575, -0.031798, -0.086718, -0.007172, + -0.071706, -0.006833, 0.028645, -0.007011, -0.096745, -0.142269, 0.027996, 0.06521, 0.061381, + 0.000741, -0.140531, 0.01748, -0.014986, -0.040893, -0.012718, -0.012494, -0.021869, -0.032923, + 0.016456, 0.104475, 0.010792, -0.066178, 0.019097, -0.001893, 0.067513, -0.092673, -0.059851, + -0.045936, 0.052642, -0.0625, 0.065013, -0.025659, -0.149301, 0.051705, 0.035692, -0.04579, + -0.007482, -0.069141, 0.149365, -0.042039, 0.018492, -0.081315, 0.05588, 0.058158, 0.019669, + 0.063836, -0.012391, 0.007057, 0.155454, 0.033854, -0.016532, -0.007661, 0.043113, -0.080283, + -0.10867, -0.029344, 0.093781, -0.01584, -0.068134, 0.091804, 0.004148, -0.058507, 0.059633, + -0.095883, -0.004939, 0.086151, -0.113571, -0.019466, -0.009167, 0.003662, +]; + +const codesnone: [f32; 0] = []; + +pub const lsp_cbjvm: [lsp_codebook; 4] = [ + /* codebook/lspjvm1.txt */ + lsp_codebook { + k: 10, + log2m: 9, + m: 512, + cb: &codes0, + }, + /* codebook/lspjvm2.txt */ + lsp_codebook { + k: 5, + log2m: 9, + m: 512, + cb: &codes1, + }, + /* codebook/lspjvm3.txt */ + lsp_codebook { + k: 5, + log2m: 9, + m: 512, + cb: &codes2, + }, + lsp_codebook { + k: 0, + log2m: 0, + m: 0, + cb: &codesnone, + }, +]; diff --git a/crates/lxst-codec2/src/native/kiss_fft.rs b/crates/lxst-codec2/src/native/kiss_fft.rs new file mode 100644 index 0000000..1c14366 --- /dev/null +++ b/crates/lxst-codec2/src/native/kiss_fft.rs @@ -0,0 +1,432 @@ +/* +Copyright (c) 2003-2010, Mark Borgerding + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +use super::*; + +/* + Explanation of functions dealing with complex math: + + C_MUL(m,a,b) : m = a*b + C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise + C_SUB( res, a,b) : res = a - b + C_SUBFROM( res , a) : res -= a + C_ADDTO( res , a) : res += a +* */ + +fn C_MUL(a: &kiss_fft_cpx, b: &kiss_fft_cpx) -> kiss_fft_cpx { + kiss_fft_cpx { + r: a.r * b.r - a.i * b.i, + i: a.r * b.i + a.i * b.r, + } +} +//# define C_FIXDIV(c,div) /* NOOP */ +fn C_MULBYSCALAR(c: &mut kiss_fft_cpx, s: f32) { + c.r *= s; + c.i *= s; +} +/*#ifndef CHECK_OVERFLOW_OP +# define CHECK_OVERFLOW_OP(a,op,b) /* noop */ +#endif*/ + +fn C_ADD(a: &kiss_fft_cpx, b: &kiss_fft_cpx) -> kiss_fft_cpx { + kiss_fft_cpx { + r: a.r + b.r, + i: a.i + b.i, + } +} +fn C_SUB(a: &kiss_fft_cpx, b: &kiss_fft_cpx) -> kiss_fft_cpx { + kiss_fft_cpx { + r: a.r - b.r, + i: a.i - b.i, + } +} +fn C_ADDTO(res: &mut kiss_fft_cpx, a: &kiss_fft_cpx) { + res.r += a.r; + res.i += a.i; +} + +fn HALF_OF(x: f32) -> f32 { + x / 2.0 +} + +fn kf_bfly2( + Fout: &mut [kiss_fft_cpx], + fstride: usize, + st: &kiss_fft_state, + mut m: usize, +) { + let mut tw1 = &st.twiddles[..]; + let (mut Fout, mut Fout2) = Fout.split_at_mut(m); + while m > 0 { + //C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2); + + let t = C_MUL(&Fout2[0], &tw1[0]); + tw1 = &tw1[fstride..]; + Fout2[0] = C_SUB(&Fout[0], &t); + C_ADDTO(&mut Fout[0], &t); + Fout2 = &mut Fout2[1..]; + Fout = &mut Fout[1..]; + m = m - 1; + } +} + +fn kf_bfly4( + mut Fout: &mut [kiss_fft_cpx], + fstride: usize, + st: &kiss_fft_state, + m: usize, +) { + let mut scratch = [kiss_fft_cpx::new(); 6]; + let mut k = m; + let m2 = 2 * m; + let m3 = 3 * m; + + let mut tw1 = &st.twiddles[..]; + let mut tw2 = &st.twiddles[..]; + let mut tw3 = &st.twiddles[..]; + + loop { + // C_FIXDIV(*Fout,4); C_FIXDIV(Fout[m],4); C_FIXDIV(Fout[m2],4); C_FIXDIV(Fout[m3],4); + + scratch[0] = C_MUL(&Fout[m], &tw1[0]); + scratch[1] = C_MUL(&Fout[m2], &tw2[0]); + scratch[2] = C_MUL(&Fout[m3], &tw3[0]); + + scratch[5] = C_SUB(&Fout[0], &scratch[1]); + C_ADDTO(&mut Fout[0], &scratch[1]); + scratch[3] = C_ADD(&scratch[0], &scratch[2]); + scratch[4] = C_SUB(&scratch[0], &scratch[2]); + Fout[m2] = C_SUB(&Fout[0], &scratch[3]); + tw1 = &tw1[fstride..]; + tw2 = &tw2[fstride * 2..]; + tw3 = &tw3[fstride * 3..]; + C_ADDTO(&mut Fout[0], &scratch[3]); + + if st.inverse != 0 { + Fout[m].r = scratch[5].r - scratch[4].i; + Fout[m].i = scratch[5].i + scratch[4].r; + Fout[m3].r = scratch[5].r + scratch[4].i; + Fout[m3].i = scratch[5].i - scratch[4].r; + } else { + Fout[m].r = scratch[5].r + scratch[4].i; + Fout[m].i = scratch[5].i - scratch[4].r; + Fout[m3].r = scratch[5].r - scratch[4].i; + Fout[m3].i = scratch[5].i + scratch[4].r; + } + Fout = &mut Fout[1..]; + k -= 1; + if k == 0 { + break; + } + } +} + +fn kf_bfly3( + mut Fout: &mut [kiss_fft_cpx], + fstride: usize, + st: &kiss_fft_state, + m: usize, +) { + let mut k = m; + let m2 = 2 * m; + let mut scratch = [kiss_fft_cpx::new(); 5]; + let epi3 = st.twiddles[fstride * m]; + + let mut tw1 = 0; + let mut tw2 = 0; + + while k > 0 { + // C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3); + + scratch[1] = C_MUL(&Fout[m], &st.twiddles[tw1]); + scratch[2] = C_MUL(&Fout[m2], &st.twiddles[tw2]); + scratch[3] = C_ADD(&scratch[1], &scratch[2]); + scratch[0] = C_SUB(&scratch[1], &scratch[2]); + tw1 += fstride; + tw2 += fstride * 2; + + Fout[m].r = Fout[0].r - (scratch[3].r / 2.0); + Fout[m].i = Fout[0].i - (scratch[3].i / 2.0); + + C_MULBYSCALAR(&mut scratch[0], epi3.i); + + C_ADDTO(&mut Fout[0], &scratch[3]); + + Fout[m2].r = Fout[m].r + scratch[0].i; + Fout[m2].i = Fout[m].i - scratch[0].r; + + Fout[m].r -= scratch[0].i; + Fout[m].i += scratch[0].r; + + Fout = &mut Fout[1..]; + k -= 1; + } +} + +fn kf_bfly5( + Fout: &mut [kiss_fft_cpx], + fstride: usize, + st: &kiss_fft_state, + m: usize, +) { + let mut scratch = [kiss_fft_cpx::new(); 13]; + let ya = st.twiddles[fstride * m]; + let yb = st.twiddles[fstride * 2 * m]; + + let (mut Fout0, Fout1) = Fout.split_at_mut(m); + let (mut Fout1, Fout2) = Fout1.split_at_mut(m); + let (mut Fout2, Fout3) = Fout2.split_at_mut(m); + let (mut Fout3, mut Fout4) = Fout3.split_at_mut(m); + + let tw = &st.twiddles[..]; + for u in 0..m { + // C_FIXDIV( *Fout0,5); C_FIXDIV( *Fout1,5); C_FIXDIV( *Fout2,5); C_FIXDIV( *Fout3,5); C_FIXDIV( *Fout4,5); + scratch[0] = Fout0[0]; + + scratch[1] = C_MUL(&Fout1[0], &tw[u * fstride]); + scratch[2] = C_MUL(&Fout2[0], &tw[2 * u * fstride]); + scratch[3] = C_MUL(&Fout3[0], &tw[3 * u * fstride]); + scratch[4] = C_MUL(&Fout4[0], &tw[4 * u * fstride]); + + scratch[7] = C_ADD(&scratch[1], &scratch[4]); + scratch[10] = C_SUB(&scratch[1], &scratch[4]); + scratch[8] = C_ADD(&scratch[2], &scratch[3]); + scratch[9] = C_SUB(&scratch[2], &scratch[3]); + + Fout0[0].r += scratch[7].r + scratch[8].r; + Fout0[0].i += scratch[7].i + scratch[8].i; + + scratch[5].r = scratch[0].r + (scratch[7].r * ya.r) + (scratch[8].r * yb.r); + scratch[5].i = scratch[0].i + (scratch[7].i * ya.r) + (scratch[8].i * yb.r); + + scratch[6].r = (scratch[10].i * ya.i) + (scratch[9].i * yb.i); + scratch[6].i = -(scratch[10].r * ya.i) - (scratch[9].r * yb.i); + + Fout1[0] = C_SUB(&scratch[5], &scratch[6]); + Fout4[0] = C_ADD(&scratch[5], &scratch[6]); + + scratch[11].r = scratch[0].r + (scratch[7].r * yb.r) + (scratch[8].r * ya.r); + scratch[11].i = scratch[0].i + (scratch[7].i * yb.r) + (scratch[8].i * ya.r); + scratch[12].r = -(scratch[10].i * yb.i) + (scratch[9].i * ya.i); + scratch[12].i = (scratch[10].r * yb.i) - (scratch[9].r * ya.i); + + Fout2[0] = C_ADD(&scratch[11], &scratch[12]); + Fout3[0] = C_SUB(&scratch[11], &scratch[12]); + + Fout0 = &mut Fout0[1..]; + Fout1 = &mut Fout1[1..]; + Fout2 = &mut Fout2[1..]; + Fout3 = &mut Fout3[1..]; + Fout4 = &mut Fout4[1..]; + } +} + +/* perform the butterfly for one stage of a mixed radix FFT */ +fn kf_bfly_generic( + Fout: &mut [kiss_fft_cpx], + fstride: usize, + st: &kiss_fft_state, + m: usize, + p: usize, +) { + let Norig = st.nfft; + + let mut scratch = Buffer::::filled(p, kiss_fft_cpx::new()); + + for u in 0..m { + let mut k = u; + for q1 in 0..p { + scratch[q1] = Fout[k]; + // C_FIXDIV(scratch[q1],p); + k += m; + } + + k = u; + for _q1 in 0..p { + let mut twidx = 0; + Fout[k] = scratch[0]; + for q in 1..p { + twidx += fstride * k; + if twidx >= Norig { + twidx -= Norig; + } + let t = C_MUL(&scratch[q], &st.twiddles[twidx]); + C_ADDTO(&mut Fout[k], &t); + } + k += m; + } + } +} + +fn kf_work( + Fout: &mut [kiss_fft_cpx], + mut f: &[kiss_fft_cpx], + fstride: usize, + in_stride: i32, + factors: &[usize], + st: &kiss_fft_state, +) { + let p = factors[0]; /* the radix */ + let m = factors[1]; /* stage's fft length/p */ + if m == 1 { + for fout_idx in 0..p * m { + Fout[fout_idx] = f[0]; + f = &f[(fstride * in_stride as usize).min(f.len())..]; + } + } else { + for fout_idx in (0..p * m).step_by(m) { + // recursive call: + // DFT of size m*p performed by doing + // p instances of smaller DFTs of size m, + // each one takes a decimated version of the input + kf_work( + &mut Fout[fout_idx..], + f, + fstride * p, + in_stride, + &factors[2..], + st, + ); + f = &f[(fstride * in_stride as usize).min(f.len())..]; + } + } + + // recombine the p smaller DFTs + match p { + 2 => { + kf_bfly2(Fout, fstride, st, m); + } + 3 => { + kf_bfly3(Fout, fstride, st, m); + } + 4 => { + kf_bfly4(Fout, fstride, st, m); + } + 5 => { + kf_bfly5(Fout, fstride, st, m); + } + _ => { + kf_bfly_generic(Fout, fstride, st, m, p); + } + } +} + +fn kiss_fft_stride( + st: &kiss_fft_state, + fin: &[kiss_fft_cpx], + fout: &mut [kiss_fft_cpx], + in_stride: i32, +) { + kf_work(fout, fin, 1, in_stride, &st.factors[..], st); +} + +pub fn kiss_fft( + cfg: &kiss_fft_state, + fin: &[kiss_fft_cpx], + fout: &mut [kiss_fft_cpx], +) { + kiss_fft_stride(cfg, fin, fout, 1); +} + +pub fn kiss_fftr(st: &mut kiss_fftr_cfg, timedata: &[f32], freqdata: &mut [kiss_fft_cpx]) { + /* input buffer timedata is stored row-wise */ + // assert(st.substate.inverse==0); + + let ncfft = st.substate.nfft; + + /*perform the parallel fft of two real signals packed in real,imag*/ + //could transmute this but UGH so we copy + let mut timedatac = + Buffer::::filled(timedata.len() / 2, kiss_fft_cpx::new()); + for i in 0..timedatac.len() { + timedatac[i] = kiss_fft_cpx { + r: timedata[i * 2], + i: timedata[i * 2 + 1], + }; + } + kiss_fft(&st.substate, &timedatac, &mut st.tmpbuf); + + /* The real part of the DC element of the frequency spectrum in st.tmpbuf + * contains the sum of the even-numbered elements of the input time sequence + * The imag part is the sum of the odd-numbered elements + * + * The sum of tdc.r and tdc.i is the sum of the input time sequence. + * yielding DC of input time sequence + * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... + * yielding Nyquist bin of input time sequence + */ + let mut tdc = kiss_fft_cpx::new(); + tdc.r = st.tmpbuf[0].r; + tdc.i = st.tmpbuf[0].i; + // C_FIXDIV(tdc,2); + // CHECK_OVERFLOW_OP(tdc.r ,+, tdc.i); + // CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i); + freqdata[0].r = tdc.r + tdc.i; + freqdata[ncfft].r = tdc.r - tdc.i; + freqdata[ncfft].i = 0.0; + freqdata[0].i = 0.0; + + for k in 1..ncfft / 2 + 1 { + let fpk = st.tmpbuf[k]; + let mut fpnk = kiss_fft_cpx::new(); + fpnk.r = st.tmpbuf[ncfft - k].r; + fpnk.i = 0.0 - st.tmpbuf[ncfft - k].i; + // C_FIXDIV(fpk,2); + // C_FIXDIV(fpnk,2); + + let f1k = C_ADD(&fpk, &fpnk); + let f2k = C_SUB(&fpk, &fpnk); + let tw = C_MUL(&f2k, &st.super_twiddles[k - 1]); + + freqdata[k].r = HALF_OF(f1k.r + tw.r); + freqdata[k].i = HALF_OF(f1k.i + tw.i); + freqdata[ncfft - k].r = HALF_OF(f1k.r - tw.r); + freqdata[ncfft - k].i = HALF_OF(tw.i - f1k.i); + } +} + +pub fn kiss_fftri(st: &mut kiss_fftr_cfg, freqdata: &[kiss_fft_cpx], timedata: &mut [f32]) { + /* input buffer timedata is stored row-wise */ + // assert(st.substate.inverse == 1); + + let ncfft = st.substate.nfft; + + st.tmpbuf[0].r = freqdata[0].r + freqdata[ncfft].r; + st.tmpbuf[0].i = freqdata[0].r - freqdata[ncfft].r; + // C_FIXDIV(st.tmpbuf[0],2); + + for k in 1..ncfft / 2 + 1 { + let fk = freqdata[k]; + let mut fnkc = kiss_fft_cpx::new(); + fnkc.r = freqdata[ncfft - k].r; + fnkc.i = 0.0 - freqdata[ncfft - k].i; + // C_FIXDIV( fk , 2 ); + // C_FIXDIV( fnkc , 2 ); + + let fek = C_ADD(&fk, &fnkc); + let tmp = C_SUB(&fk, &fnkc); + let fok = C_MUL(&tmp, &st.super_twiddles[k - 1]); + st.tmpbuf[k] = C_ADD(&fek, &fok); + st.tmpbuf[ncfft - k] = C_SUB(&fek, &fok); + st.tmpbuf[ncfft - k].i *= -1.0; + } + //could transmute this but UGH so we copy + let mut timedatac = + Buffer::::filled(timedata.len() / 2, kiss_fft_cpx::new()); + kiss_fft(&st.substate, &st.tmpbuf, &mut timedatac); + for i in 0..timedatac.len() { + timedata[i * 2] = timedatac[i].r; + timedata[i * 2 + 1] = timedatac[i].i; + } +} diff --git a/crates/lxst-codec2/src/native/mod.rs b/crates/lxst-codec2/src/native/mod.rs new file mode 100644 index 0000000..d1985d2 --- /dev/null +++ b/crates/lxst-codec2/src/native/mod.rs @@ -0,0 +1,2332 @@ +use super::{Buffer, FloatMath}; +use core::f32::consts::PI; + +mod kiss_fft; +mod nlp; +mod quantise; +use self::quantise::*; +mod codebook; +use self::codebook::*; +mod codebookd; +use self::codebookd::*; +mod codebookge; +use self::codebookge::*; +mod codebookjvm; +use self::codebookjvm::*; + +const WO_BITS: i32 = 7; +const WO_E_BITS: u32 = 8; +const LSPD_SCALAR_INDEXES: usize = 10; +const LSP_SCALAR_INDEXES: usize = 10; + +const N_S: f32 = 0.01; // internal proc frame length in secs +const TW_S: f32 = 0.005; // trapezoidal synth window overlap +const MAX_AMP: usize = 160; // maximum number of harmonics +const TWO_PI: f32 = 6.283185307; // mathematical constant +const FFT_ENC: usize = 512; // size of FFT used for encoder +const FFT_DEC: usize = 512; // size of FFT used in decoder +const V_THRESH: f32 = 6.0; // voicing threshold in dB +const LPC_ORD: usize = 10; // LPC order +// Pitch estimation constants +const M_PITCH_S: f32 = 0.0400; // pitch analysis window in s +const P_MIN_S: f32 = 0.0025; // minimum pitch period in s +const P_MAX_S: f32 = 0.0200; // maximum pitch period in s +mod inner { + use super::*; + use core::fmt; + + #[derive(Clone, Debug)] + pub struct C2const { + pub Fs: i32, // sample rate of this instance + pub n_samp: usize, // number of samples per 10ms frame at Fs + // pub max_amp: i32, // maximum number of harmonics + pub m_pitch: usize, // pitch estimation window size in samples + pub p_min: i32, // minimum pitch period in samples + pub p_max: i32, // maximum pitch period in samples + pub Wo_min: f32, + pub Wo_max: f32, + pub nw: usize, // analysis window size in samples + pub tw: usize, // trapezoidal synthesis window overlap + } + impl C2const { + pub fn new(Fs: i32, framelength_s: f32) -> Self { + Self { + Fs: Fs, + n_samp: ((Fs as f32) * framelength_s).dsp_round() as usize, + // max_amp: ((Fs as f32) * P_MAX_S / 2.0).dsp_floor() as i32, + p_min: ((Fs as f32) * P_MIN_S).dsp_floor() as i32, + p_max: ((Fs as f32) * P_MAX_S).dsp_floor() as i32, + m_pitch: ((Fs as f32) * M_PITCH_S).dsp_floor() as usize, + Wo_min: TWO_PI / ((Fs as f32) * P_MAX_S).dsp_floor(), + Wo_max: TWO_PI / ((Fs as f32) * P_MIN_S).dsp_floor(), + nw: 279, + tw: ((Fs as f32) * TW_S) as usize, + } + } + + /*---------------------------------------------------------------------------*\ + + FUNCTION....: dft_speech + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 27/5/94 + + Finds the DFT of the current speech input speech frame. + + \*---------------------------------------------------------------------------*/ + // TODO: we can either go for a faster FFT using fftr and some stack usage + // or we can reduce stack usage to almost zero on STM32 by switching to fft_inplace + pub fn dft_speech( + &self, + fft_fwd_cfg: &codec2_fft_cfg, + Sw: &mut [COMP], + Sn: &[f32], + w: &[f32], + ) { + let m_pitch = self.m_pitch; + let nw = self.nw; + + for i in 0..FFT_ENC { + Sw[i].r = 0.0; + Sw[i].i = 0.0; + } + + /* Centre analysis window on time axis, we need to arrange input + to FFT this way to make FFT phases correct */ + + // move 2nd half to start of FFT input vector + + for i in 0..nw / 2 { + Sw[i].r = Sn[i + m_pitch / 2] * w[i + m_pitch / 2]; + } + + // move 1st half to end of FFT input vector + + for i in 0..nw / 2 { + Sw[FFT_ENC - nw / 2 + i].r = + Sn[i + m_pitch / 2 - nw / 2] * w[i + m_pitch / 2 - nw / 2]; + } + + codec2_fft_inplace(fft_fwd_cfg, Sw); + } + } + // describes each codebook + #[derive(Clone, Debug)] + pub struct lsp_codebook { + pub k: usize, // dimension of vector + pub log2m: i32, // number of bits in m + pub m: usize, // elements in codebook + pub cb: &'static [f32], // The elements + } + #[derive(Copy, Clone)] + pub struct kiss_fft_cpx { + pub r: kiss_fft_scalar, + pub i: kiss_fft_scalar, + } + impl kiss_fft_cpx { + pub fn new() -> Self { + Self { r: 0.0, i: 0.0 } + } + pub fn kf_cexp(phase: f32) -> Self { + Self { + r: phase.dsp_cos(), + i: phase.dsp_sin(), + } + } + } + impl fmt::Debug for kiss_fft_cpx { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_fmt(format_args!("{},{}", self.r, self.i)) + } + } + pub type COMP = kiss_fft_cpx; + #[derive(Clone, Debug)] + pub struct kiss_fft_state { + pub nfft: usize, + pub inverse: i32, + pub factors: [usize; 2 * MAXFACTORS], + pub twiddles: Buffer, + } + impl kiss_fft_state { + pub fn initialise(&mut self, nfft: usize, inverse_fft: i32) { + assert!((nfft == 256 || nfft == 512) && nfft <= N); + self.nfft = nfft; + self.inverse = inverse_fft; + self.twiddles.initialise(nfft, kiss_fft_cpx::new()); + for i in 0..nfft { + let mut phase = -2.0 * PI * i as f32 / nfft as f32; + if inverse_fft != 0 { + phase *= -1.0; + } + self.twiddles[i] = kiss_fft_cpx::kf_cexp(phase); + } + let mut n = nfft; + let mut p = 4; + let floor_sqrt = (n as f32).dsp_sqrt().dsp_floor() as usize; + let mut idx = 0; + self.factors.fill(0); + loop { + while n % p != 0 { + p = match p { + 4 => 2, + 2 => 3, + _ => p + 2, + }; + if p > floor_sqrt { + p = n; + } + } + n /= p; + self.factors[idx] = p; + self.factors[idx + 1] = n; + idx += 2; + if n <= 1 { + break; + } + } + } + } + + #[derive(Clone, Debug)] + pub struct kiss_fftr_state { + pub substate: kiss_fft_state<256>, + pub tmpbuf: Buffer, + pub super_twiddles: Buffer, + } + impl kiss_fftr_state { + pub fn initialise(&mut self, nfft: usize, inverse_fft: i32) { + let nfft = nfft / 2; + self.substate.initialise(nfft, inverse_fft); + self.tmpbuf.initialise(nfft, kiss_fft_cpx::new()); + self.super_twiddles + .initialise(nfft / 2, kiss_fft_cpx::new()); + for i in 0..nfft / 2 { + let mut phase = + -3.14159265358979323846264338327 * ((i as f32 + 1.0) / nfft as f32 + 0.5); + if inverse_fft != 0 { + phase *= -1.0; + } + self.super_twiddles[i] = kiss_fft_cpx::kf_cexp(phase); + } + } + } + + #[derive(Clone, Debug)] + pub struct NLP { + pub Fs: i32, // sample rate in Hz + pub m: usize, + pub w: [f32; PMAX_M / DEC], // DFT window + pub sq: [f32; PMAX_M], // squared speech samples + pub mem_x: f32, + pub mem_y: f32, // memory for notch filter + pub mem_fir: [f32; NLP_NTAP], // decimation FIR filter memory + pub fft_cfg: codec2_fft_cfg, // kiss FFT config + pub Sn16k: Buffer, // Fs=16kHz input speech vector + // FILE *f, + } + impl NLP { + pub fn initialise(&mut self, c2const: &C2const) { + assert_eq!(c2const.Fs, 8000); + self.Fs = c2const.Fs; + self.m = c2const.m_pitch; + for i in 0..self.m / DEC { + self.w[i] = 0.5 + - 0.5 * (2.0 * PI * i as f32 / (self.m as f32 / DEC as f32 - 1.0)).dsp_cos(); + } + self.fft_cfg.initialise(PE_FFT_SIZE, 0); + self.Sn16k.initialise(0, 0.0); + } + } + + #[derive(Clone, Debug, Copy)] + pub struct MODEL { + pub Wo: f32, // fundamental frequency estimate in radians + pub L: usize, // number of harmonics + pub A: [f32; MAX_AMP + 1], // amplitiude of each harmonic + pub phi: [f32; MAX_AMP + 1], // phase of each harmonic + pub voiced: i32, // non-zero if this frame is voiced + } + impl MODEL { + pub fn new(p_max: f32) -> Self { + let wo = TWO_PI / p_max; + Self { + Wo: wo, // fundamental frequency estimate in radians + L: (PI / wo).dsp_floor() as usize, // number of harmonics + A: [0.0; MAX_AMP + 1], // amplitiude of each harmonic + phi: [0.0; MAX_AMP + 1], // phase of each harmonic + voiced: 0, // non-zero if this frame is voiced + } + } + } +} +use inner::*; +type kiss_fft_scalar = f32; +type kiss_fft_cfg = kiss_fft_state; + +/* e.g. an fft of length 128 has 4 factors +as far as kissfft is concerned +4*4*4*2 +*/ +const PE_FFT_SIZE: usize = 512; +const MAXFACTORS: usize = 32; + +type codec2_fft_cfg = kiss_fft_state; +type codec2_fftr_cfg = kiss_fftr_state; +type kiss_fftr_cfg = kiss_fftr_state; +fn codec2_fft(cfg: &kiss_fft_cfg, fin: &[kiss_fft_cpx], fout: &mut [kiss_fft_cpx]) { + kiss_fft::kiss_fft(cfg, fin, fout); +} +fn codec2_fftr(cfg: &mut codec2_fftr_cfg, inp: &[f32], out: &mut [kiss_fft_cpx]) { + kiss_fft::kiss_fftr(cfg, inp, out); +} +fn codec2_fftri(cfg: &mut codec2_fftr_cfg, inp: &[kiss_fft_cpx], out: &mut [f32]) { + kiss_fft::kiss_fftri(cfg, inp, out); +} + +fn codec2_fft_inplace(cfg: &codec2_fft_cfg, inout: &mut [kiss_fft_cpx]) { + let mut in_ = [kiss_fft_cpx::new(); 512]; + // decide whether to use the local stack based buffer for in + // or to allow kiss_fft to allocate RAM + // second part is just to play safe since first method + // is much faster and uses less RAM + if cfg.nfft <= 512 { + in_[..cfg.nfft].copy_from_slice(&inout[..cfg.nfft]); + kiss_fft::kiss_fft(cfg, &in_, inout); + } else { + unreachable!("Codec2 FFT exceeds fixed scratch capacity"); + } +} + +const PMAX_M: usize = 320; +const DEC: usize = 5; +const NLP_NTAP: usize = 48; +const BPF_N: usize = 101; +const LPCPF_BETA: f32 = 0.2; +const LPCPF_GAMMA: f32 = 0.5; + +#[derive(Clone, Debug)] +struct Codec2Internal { + mode: Codec2Mode, + random: u32, + c2const: C2const, + Fs: i32, + n_samp: usize, + m_pitch: usize, + fft_fwd_cfg: codec2_fft_cfg, // forward FFT config + fftr_fwd_cfg: codec2_fftr_cfg, // forward real FFT config + w: Buffer, // [m_pitch] time domain hamming window + W: [f32; FFT_ENC], // DFT of w[] + Pn: Buffer, // [2*n_samp] trapezoidal synthesis window + Sn: Buffer, // [m_pitch] input speech + hpf_states: [f32; 2], // high pass filter states + nlp: NLP, // pitch predictor states + gray: i32, // non-zero for gray encoding + + fftr_inv_cfg: codec2_fftr_cfg, // inverse FFT config + Sn_: Buffer, // [2*n_samp] synthesised output speech + ex_phase: f32, // excitation model phase track + bg_est: f32, // background noise estimate for post filter + prev_f0_enc: f32, // previous frame's f0 estimate + prev_model_dec: MODEL, // previous frame's model parameters + prev_lsps_dec: [f32; LPC_ORD], // previous frame's LSPs + prev_e_dec: f32, // previous frame's LPC energy + + lpc_pf: i32, // LPC post filter on + bass_boost: i32, // LPC post filter bass boost + beta: f32, // LPC post filter parameters + gamma: f32, + + xq_enc: [f32; 2], // joint pitch and energy VQ states + xq_dec: [f32; 2], + + smoothing: i32, // enable smoothing for channels with errors + se: f32, // running sum of squared error + nse: u32, // number of terms in sum + post_filter_en: i32, +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: make_synthesis_window + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 11/5/94 + + Init function that generates the trapezoidal (Parzen) sythesis window. + +\*---------------------------------------------------------------------------*/ +fn make_synthesis_window(c2const: &C2const, Pn: &mut [f32]) { + let n_samp = c2const.n_samp; + let tw = c2const.tw; + + // Generate Parzen window in time domain + for i in 0..n_samp / 2 - tw { + Pn[i] = 0.0; + } + let mut win = 0.0; + for i in n_samp / 2 - tw..n_samp / 2 + tw { + Pn[i] = win; + win += 1.0 / (2.0 * tw as f32); + } + for i in n_samp / 2 + tw..3 * n_samp / 2 - tw { + Pn[i] = 1.0; + } + win = 1.0; + for i in 3 * n_samp / 2 - tw..3 * n_samp / 2 + tw { + Pn[i] = win; + win -= 1.0 / (2.0 * tw as f32); + } + for i in 3 * n_samp / 2 + tw..2 * n_samp { + Pn[i] = 0.0; + } +} + +fn make_analysis_window( + c2const: &C2const, + fft_fwd_cfg: &codec2_fft_cfg, + w: &mut [f32], + W: &mut [f32], +) { + let mut wshift = [kiss_fft_cpx::new(); FFT_ENC]; + let m_pitch = c2const.m_pitch; + let nw = c2const.nw; + + /* + Generate Hamming window centered on M-sample pitch analysis window + + 0 M/2 M-1 + |-------------|-------------| + |-------|-------| + nw samples + + All our analysis/synthsis is centred on the M/2 sample. + */ + + let mut m = 0.0; + for i in 0..m_pitch / 2 - nw / 2 { + w[i] = 0.0; + } + let mut j = 0; + for i in m_pitch / 2 - nw / 2..m_pitch / 2 + nw / 2 { + w[i] = 0.5 - 0.5 * (TWO_PI * (j as f32) / ((nw as f32) - 1.0)).dsp_cos(); + m += w[i] * w[i]; + j += 1; + } + for i in m_pitch / 2 + nw / 2..m_pitch { + w[i] = 0.0; + } + + /* Normalise - makes freq domain amplitude estimation straight + forward */ + + m = 1.0 / (m * FFT_ENC as f32).dsp_sqrt(); + for i in 0..m_pitch { + w[i] *= m; + } + + /* + Generate DFT of analysis window, used for later processing. Note + we modulo FFT_ENC shift the time domain window w[], this makes the + imaginary part of the DFT W[] equal to zero as the shifted w[] is + even about the n=0 time axis if nw is odd. Having the imag part + of the DFT W[] makes computation easier. + + 0 FFT_ENC-1 + |-------------------------| + + ----\ /---- + \ / + \ / <- shifted version of window w[n] + \ / + \ / + ------- + + |---------| |---------| + nw/2 nw/2 + */ + + let mut temp = [kiss_fft_cpx::new(); FFT_ENC]; + + for i in 0..FFT_ENC { + wshift[i].r = 0.0; + wshift[i].i = 0.0; + } + for i in 0..(nw / 2) { + wshift[i].r = w[i + (m_pitch) / 2]; + } + let mut j = m_pitch / 2 - nw / 2; + for i in FFT_ENC - nw / 2..FFT_ENC { + wshift[i].r = w[j]; + j += 1; + } + + codec2_fft(fft_fwd_cfg, &wshift[..], &mut temp); + + /* + Re-arrange W[] to be symmetrical about FFT_ENC/2. Makes later + analysis convenient. + + Before: + + + 0 FFT_ENC-1 + |----------|---------| + __ _ + \ / + \_______________/ + + After: + + 0 FFT_ENC-1 + |----------|---------| + ___ + / \ + ________/ \_______ + + */ + + for i in 0..FFT_ENC / 2 { + W[i] = temp[i + FFT_ENC / 2].r; + W[i + FFT_ENC / 2] = temp[i].r; + } +} + +const WordSize: usize = 8; +const IndexMask: usize = 0x7; +const ShiftRight: usize = 3; +fn pack( + bitArray: &mut [u8], // The output bit string. + bitIndex: &mut usize, // Index into the string in BITS, not bytes. + field: i32, // The bit field to be packed. + fieldWidth: u32, // Width of the field in BITS, not bytes. +) { + pack_natural_or_gray(bitArray, bitIndex, field, fieldWidth, 1); +} + +/** Pack a bit field into a bit string, encoding the field in Gray code. + * + * The output is an array of unsigned char data. The fields are efficiently + * packed into the bit string. The Gray coding is a naive attempt to reduce + * the effect of single-bit errors, we expect to do a better job as the + * codec develops. + * + * This code would be simpler if it just set one bit at a time in the string, + * but would hit the same cache line more often. I'm not sure the complexity + * gains us anything here. + * + * Although field is currently of int type rather than unsigned for + * compatibility with the rest of the code, indices are always expected to + * be >= 0. + */ +fn pack_natural_or_gray( + bitArray: &mut [u8], // The output bit string. + bitIndex: &mut usize, // Index into the string in BITS, not bytes. + mut field: i32, // The bit field to be packed. + mut fieldWidth: u32, // Width of the field in BITS, not bytes. + gray: u32, // non-zero for gray coding +) { + if gray > 0 { + // Convert the field to Gray code + field = (field >> 1) ^ field; + } + + while fieldWidth != 0 { + let bI = *bitIndex; + let bitsLeft = (WordSize - (bI & IndexMask)) as u32; + let sliceWidth = if bitsLeft < fieldWidth { + bitsLeft + } else { + fieldWidth + }; + let wordIndex = bI >> ShiftRight; + + bitArray[wordIndex] |= + (((field >> (fieldWidth - sliceWidth)) << (bitsLeft - sliceWidth)) & 0xFF) as u8; + + *bitIndex = bI + sliceWidth as usize; + fieldWidth -= sliceWidth; + } +} + +/** Unpack a field from a bit string, converting from Gray code to binary. + * + */ +fn unpack( + bitArray: &[u8], // The input bit string. + bitIndex: &mut u32, // Index into the string in BITS, not bytes. + fieldWidth: u32, // Width of the field in BITS, not bytes. +) -> i32 { + unpack_natural_or_gray(bitArray, bitIndex, fieldWidth, 1) +} + +/** Unpack a field from a bit string, to binary, optionally using + * natural or Gray code. + * + */ +fn unpack_natural_or_gray( + bitArray: &[u8], // The input bit string. + bitIndex: &mut u32, // Index into the string in BITS, not bytes. + mut fieldWidth: u32, // Width of the field in BITS, not bytes. + gray: u32, // non-zero for Gray coding +) -> i32 { + let mut field = 0; + while fieldWidth != 0 { + let bI = *bitIndex; + let bitsLeft = WordSize as u32 - (bI & IndexMask as u32); + let sliceWidth = if bitsLeft < fieldWidth { + bitsLeft + } else { + fieldWidth + }; + + field |= ((bitArray[(bI >> ShiftRight) as usize] as usize >> (bitsLeft - sliceWidth)) + & ((1 << sliceWidth) - 1)) + << (fieldWidth - sliceWidth); + + *bitIndex = bI + sliceWidth; + fieldWidth -= sliceWidth; + } + + if gray != 0 { + // Convert from Gray code to binary. Works for maximum 8-bit fields. + let mut t = field ^ (field >> 8); + t ^= t >> 4; + t ^= t >> 2; + t ^= t >> 1; + t as i32 + } else { + field as i32 + } +} + +/// Codec mode (bitrate). Currently not all bitrates are implemented +#[derive(Clone, Debug, Copy)] +#[non_exhaustive] +#[repr(u8)] +pub enum Codec2Mode { + MODE_3200, + MODE_2400, + MODE_1600, + MODE_1400, + MODE_1300, + MODE_1200, + //MODE_700C, + //MODE_450, + //MODE_450PWB, +} +use Codec2Mode::*; + +/// A Codec2 object for encoding or decoding audio +#[derive(Clone, Debug)] +pub struct Codec2 { + internal: Codec2Internal, +} + +impl Codec2 { + /// Creates a new Codec2 object suitable for encoding or decoding audio + pub fn initialise(&mut self, mode: Codec2Mode) { + let c2 = self; + let c2const = C2const::new(8000, N_S); + let n_samp = c2const.n_samp; + let m_pitch = c2const.m_pitch; + c2.internal.mode = mode; + c2.internal.Fs = 8000; + c2.internal.n_samp = n_samp; + c2.internal.m_pitch = m_pitch; + c2.internal.fft_fwd_cfg.initialise(FFT_ENC, 0); + c2.internal.fftr_fwd_cfg.initialise(FFT_ENC, 0); + c2.internal.fftr_inv_cfg.initialise(FFT_DEC, 1); + c2.internal.w.initialise(m_pitch, 0.0); + c2.internal.Pn.initialise(2 * n_samp, 0.0); + c2.internal.Sn.initialise(m_pitch, 1.0); + c2.internal.Sn_.initialise(m_pitch, 0.0); + c2.internal.nlp.initialise(&c2const); + c2.internal.gray = 1; + c2.internal.prev_f0_enc = 1.0 / P_MAX_S; + c2.internal.prev_model_dec = MODEL::new(c2const.p_max as f32); + c2.internal.c2const = c2const; + c2.internal.prev_e_dec = 1.0; + c2.internal.lpc_pf = 1; + c2.internal.bass_boost = 1; + c2.internal.beta = LPCPF_BETA; + c2.internal.gamma = LPCPF_GAMMA; + c2.internal.post_filter_en = 1; + c2.internal.random = 1; + for i in 0..LPC_ORD { + c2.internal.prev_lsps_dec[i] = i as f32 * PI / (LPC_ORD as f32 + 1.0); + } + make_analysis_window( + &c2.internal.c2const, + &c2.internal.fft_fwd_cfg, + &mut c2.internal.w, + &mut c2.internal.W, + ); + make_synthesis_window(&c2.internal.c2const, &mut c2.internal.Pn); + } + + /// The number of bits in an encoded (compressed) frame; 64 for the 3200 bitrate, 48 for 2400. + pub fn bits_per_frame(&self) -> usize { + match self.internal.mode { + MODE_3200 => 64, + MODE_2400 => 48, + MODE_1600 => 64, + MODE_1400 => 56, + MODE_1300 => 52, + MODE_1200 => 48, + // MODE_700C => 28, + // MODE_450 => 18, + // MODE_450PWB => 18, + } + } + + /// How many samples an encoded (compressed) frame represents; generally 160 (20ms of speech). + pub fn samples_per_frame(&self) -> usize { + match self.internal.mode { + MODE_3200 | MODE_2400 => 160, + MODE_1600 | MODE_1400 | MODE_1300 | MODE_1200 /* | MODE_700C | MODE_450*/ => 320, + //MODE_450PWB => 640, + } + } + + /// Encodes speech samples at current bitrate into `bits_per_frame()`/8 rounded up output bytes. + /// For MODE_3200, this is 64 bits or 8 bytes, for MODE_2400, it's 48 bits (6 bytes). + pub fn encode(&mut self, bits: &mut [u8], speech: &[i16]) { + match self.internal.mode { + MODE_3200 => self.codec2_encode_3200(bits, speech), + MODE_2400 => self.codec2_encode_2400(bits, speech), + MODE_1600 => self.codec2_encode_1600(bits, speech), + MODE_1400 => self.codec2_encode_1400(bits, speech), + MODE_1300 => self.codec2_encode_1300(bits, speech), + MODE_1200 => self.codec2_encode_1200(bits, speech), + } + } + + /// Decodes `bits_per_frame()` compressed bits into `samples_per_frame()` speech samples. + /// For MODE_3200, the input is 64 bits or 8 bytes, for MODE_2400, it's 48 bits (6 bytes). + pub fn decode(&mut self, speech: &mut [i16], bits: &[u8]) { + match self.internal.mode { + MODE_3200 => self.codec2_decode_3200(speech, bits), + MODE_2400 => self.codec2_decode_2400(speech, bits), + MODE_1600 => self.codec2_decode_1600(speech, bits), + MODE_1400 => self.codec2_decode_1400(speech, bits), + MODE_1300 => self.codec2_decode_1300(speech, bits, 0.0), + MODE_1200 => self.codec2_decode_1200(speech, bits), + } + } + + /*---------------------------------------------------------------------------*\ + + FUNCTION....: codec2_encode_3200 + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 13 Sep 2012 + + Encodes 160 speech samples (20ms of speech) into 64 bits. + + The codec2 algorithm actually operates internally on 10ms (80 + sample) frames, so we run the encoding algorithm twice. On the + first frame we just send the voicing bits. On the second frame we + send all model parameters. Compared to 2400 we use a larger number + of bits for the LSPs and non-VQ pitch and energy. + + The bit allocation is: + + Parameter bits/frame + -------------------------------------- + Harmonic magnitudes (LSPs) 50 + Pitch (Wo) 7 + Energy 5 + Voicing (10ms update) 2 + TOTAL 64 + + \*---------------------------------------------------------------------------*/ + /// Encodes 160 speech samples (20ms of speech) into 64 bits. + fn codec2_encode_3200(&mut self, bits: &mut [u8], speech: &[i16]) { + let mut model = MODEL::new(self.internal.c2const.p_max as f32); + let mut ak = [0.0; LPC_ORD + 1]; //f32 + let mut lsps = [0.0; LPC_ORD]; //f32 + let mut lspd_indexes = [0; LPC_ORD]; + let mut nbit = 0; + + let nbyte = (self.bits_per_frame() + 7) / 8; + for i in 0..nbyte { + bits[i] = 0; + } + + // first 10ms analysis frame - we just want voicing + self.analyse_one_frame(&mut model, speech); + pack(bits, &mut nbit, model.voiced, 1); + + // second 10ms analysis frame + self.analyse_one_frame(&mut model, &speech[self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + let Wo_index = encode_Wo(&self.internal.c2const, model.Wo, WO_BITS); + pack(bits, &mut nbit, Wo_index, WO_BITS as u32); //1+1+7 = 9 bits + + let e = speech_to_uq_lsps( + &mut lsps, + &mut ak, + &self.internal.Sn, + &self.internal.w, + self.internal.m_pitch, + LPC_ORD, + ); + let e_index = encode_energy(e, E_BITS); + pack(bits, &mut nbit, e_index, E_BITS as u32); //9+5 = 14 bits + + encode_lspds_scalar(&mut lspd_indexes, &lsps, LPC_ORD); + for i in 0..LSPD_SCALAR_INDEXES { + pack(bits, &mut nbit, lspd_indexes[i], lspd_bits(i) as u32); + } + } + + /*---------------------------------------------------------------------------*\ + + FUNCTION....: codec2_decode_3200 + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 13 Sep 2012 + + Decodes a frame of 64 bits into 160 samples (20ms) of speech. + + \*---------------------------------------------------------------------------*/ + /// Decodes a frame of 64 bits into 160 samples (20ms) of speech. + fn codec2_decode_3200(&mut self, speech: &mut [i16], bits: &[u8]) { + let mut ak = [[0.0; LPC_ORD + 1]; 2]; + let mut nbit = 0; + let mut Aw = [COMP::new(); FFT_ENC]; + + let mut model = [MODEL::new(self.internal.c2const.p_max as f32); 2]; + + // unpack bits from channel ------------------------------------ + + /* this will partially fill the model params for the 2 x 10ms + frames */ + + model[0].voiced = unpack(bits, &mut nbit, 1); + model[1].voiced = unpack(bits, &mut nbit, 1); + + let Wo_index = unpack(bits, &mut nbit, WO_BITS as u32); + model[1].Wo = decode_Wo(&self.internal.c2const, Wo_index, WO_BITS); + model[1].L = (PI / model[1].Wo) as usize; + + let mut e = [0.0; 2]; + let e_index = unpack(bits, &mut nbit, E_BITS as u32); + e[1] = decode_energy(e_index, E_BITS); + + let mut lspd_indexes = [0; LPC_ORD]; + for i in 0..LSPD_SCALAR_INDEXES { + lspd_indexes[i] = unpack(bits, &mut nbit, lspd_bits(i) as u32) as usize; + } + let mut lsps = [[0.0; LPC_ORD]; 2]; + decode_lspds_scalar(&mut lsps[1][0..], &lspd_indexes, LPC_ORD); + + // interpolate ------------------------------------------------ + + /* Wo and energy are sampled every 20ms, so we interpolate just 1 + 10ms frame between 20ms samples */ + + model[0] = interp_Wo( + &model[0], + &self.internal.prev_model_dec, + &model[1], + self.internal.c2const.Wo_min, + ); + e[0] = interp_energy(self.internal.prev_e_dec, e[1]); + + /* LSPs are sampled every 20ms so we interpolate the frame in + between, then recover spectral amplitudes */ + + let (lsps0, lsps1) = lsps.split_at_mut(1); + interpolate_lsp_ver2( + &mut lsps0[0][0..], + &self.internal.prev_lsps_dec, + &mut lsps1[0][0..], + 0.5, + LPC_ORD, + ); + + for i in 0..2 { + lsp_to_lpc(&lsps[i][0..], &mut ak[i][0..], LPC_ORD); + let mut snr = 0.0; + aks_to_M2( + &mut self.internal.fftr_fwd_cfg, + &ak[i][..], + LPC_ORD, + &mut model[i], + e[i], + &mut snr, + 0, + 0, + self.internal.lpc_pf, + self.internal.bass_boost, + self.internal.beta, + self.internal.gamma, + &mut Aw, + ); + apply_lpc_correction(&mut model[i]); + self.synthesise_one_frame( + &mut speech[self.internal.n_samp * i..], + &mut model[i], + &mut Aw, + 1.0, + ); + } + + // update memories for next frame ---------------------------- + + self.internal.prev_model_dec = model[1]; + self.internal.prev_e_dec = e[1]; + for i in 0..LPC_ORD { + self.internal.prev_lsps_dec[i] = lsps[1][i]; + } + } + + /*---------------------------------------------------------------------------*\ + + FUNCTION....: codec2_encode_2400 + AUTHOR......: David Rowe + DATE CREATED: 21/8/2010 + + Encodes 160 speech samples (20ms of speech) into 48 bits. + + The codec2 algorithm actually operates internally on 10ms (80 + sample) frames, so we run the encoding algorithm twice. On the + first frame we just send the voicing bit. On the second frame we + send all model parameters. + + The bit allocation is: + + Parameter bits/frame + -------------------------------------- + Harmonic magnitudes (LSPs) 36 + Joint VQ of Energy and Wo 8 + Voicing (10ms update) 2 + Spare 2 + TOTAL 48 + + \*---------------------------------------------------------------------------*/ + /// Encodes 160 speech samples (20ms of speech) into 48 bits. + fn codec2_encode_2400(&mut self, bits: &mut [u8], speech: &[i16]) { + let mut model = MODEL::new(self.internal.c2const.p_max as f32); + let mut ak = [0.0; LPC_ORD + 1]; //f32 + let mut lsps = [0.0; LPC_ORD]; //f32 + let mut lsp_indexes = [0; LPC_ORD]; + let mut nbit = 0; + + for i in 0..(self.bits_per_frame() + 7) / 8 { + bits[i] = 0; + } + + // first 10ms analysis frame - we just want voicing + self.analyse_one_frame(&mut model, speech); + pack(bits, &mut nbit, model.voiced, 1); + + // second 10ms analysis frame + self.analyse_one_frame(&mut model, &speech[self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + let e = speech_to_uq_lsps( + &mut lsps, + &mut ak, + &self.internal.Sn, + &self.internal.w, + self.internal.m_pitch, + LPC_ORD, + ); + + let WoE_index = encode_WoE(&model, e, &mut self.internal.xq_enc); + pack(bits, &mut nbit, WoE_index, WO_E_BITS); + + encode_lsps_scalar(&mut lsp_indexes, &lsps, LPC_ORD); + for i in 0..LSP_SCALAR_INDEXES { + pack(bits, &mut nbit, lsp_indexes[i], lsp_bits(i)); + } + let spare = 0; + pack(bits, &mut nbit, spare, 2); + + //assert(nbit == (unsigned)codec2_bits_per_frame(c2)); + } + + /*---------------------------------------------------------------------------*\ + + FUNCTION....: codec2_decode_2400 + AUTHOR......: David Rowe + DATE CREATED: 21/8/2010 + + Decodes frames of 48 bits into 160 samples (20ms) of speech. + + \*---------------------------------------------------------------------------*/ + fn codec2_decode_2400(&mut self, speech: &mut [i16], bits: &[u8]) { + let mut model = [MODEL::new(self.internal.c2const.p_max as f32); 2]; + let mut lsp_indexes = [0; LPC_ORD]; + let mut lsps = [[0.0; LPC_ORD]; 2]; + let mut e = [0.0; 2]; + let mut snr = 0.0; + let mut ak = [[0.0; LPC_ORD + 1]; 2]; + let mut nbit = 0; + let mut Aw = [COMP::new(); FFT_ENC]; + + //assert(c2 != NULL); + + /* unpack bits from channel ------------------------------------*/ + + /* this will partially fill the model params for the 2 x 10ms + frames */ + model[0].voiced = unpack(bits, &mut nbit, 1); + model[1].voiced = unpack(bits, &mut nbit, 1); + + let WoE_index = unpack(bits, &mut nbit, WO_E_BITS) as usize; + decode_WoE( + &self.internal.c2const, + &mut model[1], + &mut e[1], + &mut self.internal.xq_dec, + WoE_index, + ); + + for i in 0..LSP_SCALAR_INDEXES { + lsp_indexes[i] = unpack(bits, &mut nbit, lsp_bits(i)) as usize; + } + decode_lsps_scalar(&mut lsps[1][0..], &lsp_indexes, LPC_ORD); + check_lsp_order(&mut lsps[1][0..], LPC_ORD); + bw_expand_lsps(&mut lsps[1][0..], LPC_ORD, 50.0, 100.0); + + /* interpolate ------------------------------------------------*/ + + /* Wo and energy are sampled every 20ms, so we interpolate just 1 + 10ms frame between 20ms samples */ + + model[0] = interp_Wo( + &model[0], + &self.internal.prev_model_dec, + &model[1], + self.internal.c2const.Wo_min, + ); + e[0] = interp_energy(self.internal.prev_e_dec, e[1]); + + /* LSPs are sampled every 20ms so we interpolate the frame in + between, then recover spectral amplitudes */ + + let (lsps0, lsps1) = lsps.split_at_mut(1); + interpolate_lsp_ver2( + &mut lsps0[0][0..], + &self.internal.prev_lsps_dec, + &mut lsps1[0][0..], + 0.5, + LPC_ORD, + ); + + for i in 0..2 { + lsp_to_lpc(&lsps[i][0..], &mut ak[i][0..], LPC_ORD); + aks_to_M2( + &mut self.internal.fftr_fwd_cfg, + &ak[i][..], + LPC_ORD, + &mut model[i], + e[i], + &mut snr, + 0, + 0, + self.internal.lpc_pf, + self.internal.bass_boost, + self.internal.beta, + self.internal.gamma, + &mut Aw, + ); + apply_lpc_correction(&mut model[i]); + self.synthesise_one_frame( + &mut speech[self.internal.n_samp * i..], + &mut model[i], + &mut Aw, + 1.0, + ); + } + + /* update memories for next frame ----------------------------*/ + self.internal.prev_model_dec = model[1]; + self.internal.prev_e_dec = e[1]; + for i in 0..LPC_ORD { + self.internal.prev_lsps_dec[i] = lsps[1][i]; + } + } + + /*---------------------------------------------------------------------------*\ + FUNCTION....: codec2_encode_1600 + AUTHOR......: David Rowe, conversion by Raphael Peters + DATE CREATED: Feb 28 2013 + + Encodes 320 speech samples (40ms of speech) into 64 bits. + The codec2 algorithm actually operates internally on 10ms (80 + sample) frames, so we run the encoding algorithm 4 times: + frame 0: voicing bit + frame 1: voicing bit, Wo and E + frame 2: voicing bit + frame 3: voicing bit, Wo and E, scalar LSPs + + The bit allocation is: + + Parameter frame 2 frame 4 Total + ------------------------------------------------------- + Harmonic magnitudes (LSPs) 0 36 36 + Pitch (Wo) 7 7 14 + Energy 5 5 10 + Voicing (10ms update) 2 2 4 + TOTAL 14 50 64 + \*---------------------------------------------------------------------------*/ + /// Encodes 320 speech samples (40ms of speech) into 64 bits. + fn codec2_encode_1600(&mut self, bits: &mut [u8], speech: &[i16]) { + let mut model = MODEL::new(self.internal.c2const.p_max as f32); + let mut ak = [0.0; LPC_ORD + 1]; //f32 + let mut lsps = [0.0; LPC_ORD]; //f32 + let mut lsp_indexes = [0; LPC_ORD]; + let mut nbit = 0; + + for i in 0..(self.bits_per_frame() + 7) / 8 { + bits[i] = 0; + } + + // frame 1: - voicing + + self.analyse_one_frame(&mut model, speech); + pack(bits, &mut nbit, model.voiced, 1); + + // frame 2: - voicing, scalar Wo & E + + self.analyse_one_frame(&mut model, &speech[self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + + let mut Wo_index = encode_Wo(&self.internal.c2const, model.Wo, WO_BITS); + pack(bits, &mut nbit, Wo_index, WO_BITS as u32); + + // need to run this just to get LPC energy + let mut e = speech_to_uq_lsps( + &mut lsps, + &mut ak, + &self.internal.Sn, + &self.internal.w, + self.internal.m_pitch, + LPC_ORD, + ); + let mut e_index = encode_energy(e, E_BITS); + pack(bits, &mut nbit, e_index, E_BITS as u32); + + // frame 3: - voicing + + self.analyse_one_frame(&mut model, &speech[2 * self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + + // frame 4: - voicing, scalar Wo & E, scalar LSPs + + self.analyse_one_frame(&mut model, &speech[3 * self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + + Wo_index = encode_Wo(&self.internal.c2const, model.Wo, WO_BITS); + pack(bits, &mut nbit, Wo_index, WO_BITS as u32); + + e = speech_to_uq_lsps( + &mut lsps, + &mut ak, + &self.internal.Sn, + &self.internal.w, + self.internal.m_pitch, + LPC_ORD, + ); + e_index = encode_energy(e, E_BITS); + pack(bits, &mut nbit, e_index, E_BITS as u32); + + encode_lsps_scalar(&mut lsp_indexes, &lsps, LPC_ORD); + for i in 0..LSP_SCALAR_INDEXES { + pack(bits, &mut nbit, lsp_indexes[i], lsp_bits(i)); + } + + assert_eq!(nbit, self.bits_per_frame()); + } + + /*---------------------------------------------------------------------------*\ + + FUNCTION....: codec2_decode_1600 + + AUTHOR......: David Rowe, conversion by Raphael Peters + DATE CREATED: 11 May 2012 + + Decodes frames of 64 bits into 320 samples (40ms) of speech. + + + \*---------------------------------------------------------------------------*/ + fn codec2_decode_1600(&mut self, speech: &mut [i16], bits: &[u8]) { + let mut model = [MODEL::new(self.internal.c2const.p_max as f32); 4]; + let mut lsp_indexes = [0; LPC_ORD]; + let mut lsps = [[0.0; LPC_ORD]; 4]; + let mut e = [0.0; 4]; + let mut snr = 0.0; + let mut ak = [[0.0; LPC_ORD + 1]; 4]; + let mut nbit = 0; + let mut Aw = [COMP::new(); FFT_ENC]; + + /* unpack bits from channel ------------------------------------*/ + + /* this will partially fill the model params for the 4 x 10ms + frames */ + + model[0].voiced = unpack(bits, &mut nbit, 1); + + model[1].voiced = unpack(bits, &mut nbit, 1); + let Wo_index = unpack(bits, &mut nbit, WO_BITS as u32); + model[1].Wo = decode_Wo(&self.internal.c2const, Wo_index, WO_BITS); + model[1].L = (PI / model[1].Wo) as usize; + + let mut e_index = unpack(bits, &mut nbit, E_BITS as u32); + e[1] = decode_energy(e_index, E_BITS); + + model[2].voiced = unpack(bits, &mut nbit, 1); + + model[3].voiced = unpack(bits, &mut nbit, 1); + let Wo_index = unpack(bits, &mut nbit, WO_BITS as u32); + model[3].Wo = decode_Wo(&self.internal.c2const, Wo_index, WO_BITS); + model[3].L = (PI / model[3].Wo) as usize; + + e_index = unpack(bits, &mut nbit, E_BITS as u32); + e[3] = decode_energy(e_index, E_BITS); + + for i in 0..LSP_SCALAR_INDEXES { + lsp_indexes[i] = unpack(bits, &mut nbit, lsp_bits(i)) as usize; + } + decode_lsps_scalar(&mut lsps[3][0..], &lsp_indexes, LPC_ORD); + check_lsp_order(&mut lsps[3][0..], LPC_ORD); + bw_expand_lsps(&mut lsps[3][0..], LPC_ORD, 50.0, 100.0); + + /* interpolate ------------------------------------------------*/ + + /* Wo and energy are sampled every 20ms, so we interpolate just 1 + 10ms frame between 20ms samples */ + + model[0] = interp_Wo( + &model[0], + &self.internal.prev_model_dec, + &model[1], + self.internal.c2const.Wo_min, + ); + e[0] = interp_energy(self.internal.prev_e_dec, e[1]); + model[2] = interp_Wo( + &model[2], + &model[1], + &model[3], + self.internal.c2const.Wo_min, + ); + e[2] = interp_energy(e[1], e[3]); + + /* LSPs are sampled every 40ms so we interpolate the 3 frames in + between, then recover spectral amplitudes */ + + for i in 0..3 { + let weight = 0.25 + i as f32 * 0.25; + let lsps3 = lsps[3]; + interpolate_lsp_ver2( + &mut lsps[i][0..], + &self.internal.prev_lsps_dec, + &lsps3[0..], + weight, + LPC_ORD, + ); + } + for i in 0..4 { + lsp_to_lpc(&lsps[i][0..], &mut ak[i][0..], LPC_ORD); + aks_to_M2( + &mut self.internal.fftr_fwd_cfg, + &ak[i][0..], + LPC_ORD, + &mut model[i], + e[i], + &mut snr, + 0, + 0, + self.internal.lpc_pf, + self.internal.bass_boost, + self.internal.beta, + self.internal.gamma, + &mut Aw, + ); + apply_lpc_correction(&mut model[i]); + self.synthesise_one_frame( + &mut speech[self.internal.n_samp * i..], + &mut model[i], + &Aw, + 1.0, + ); + } + + /* update memories for next frame ----------------------------*/ + + self.internal.prev_model_dec = model[3]; + self.internal.prev_e_dec = e[3]; + for i in 0..LPC_ORD { + self.internal.prev_lsps_dec[i] = lsps[3][i]; + } + } + + /*---------------------------------------------------------------------------*\ + FUNCTION....: codec2_encode_1400 + AUTHOR......: David Rowe, conversion by Raphael Peters + DATE CREATED: May 11 2012 + Encodes 320 speech samples (40ms of speech) into 56 bits. + The codec2 algorithm actually operates internally on 10ms (80 + sample) frames, so we run the encoding algorithm 4 times: + frame 0: voicing bit + frame 1: voicing bit, joint VQ of Wo and E + frame 2: voicing bit + frame 3: voicing bit, joint VQ of Wo and E, scalar LSPs + The bit allocation is: + Parameter frame 2 frame 4 Total + ------------------------------------------------------- + Harmonic magnitudes (LSPs) 0 36 36 + Energy+Wo 8 8 16 + Voicing (10ms update) 2 2 4 + TOTAL 10 46 56 + \*---------------------------------------------------------------------------*/ + fn codec2_encode_1400(&mut self, bits: &mut [u8], speech: &[i16]) { + let mut model = MODEL::new(self.internal.c2const.p_max as f32); + let mut lsps = [0.0; LPC_ORD]; //f32 + let mut ak = [0.0; LPC_ORD + 1]; //f32 + let mut lsp_indexes = [0; LPC_ORD]; + let mut nbit = 0; + + let nbyte = (self.bits_per_frame() + 7) / 8; + for i in 0..nbyte { + bits[i] = 0; + } + + // frame 1: - voicing + + self.analyse_one_frame(&mut model, speech); + pack(bits, &mut nbit, model.voiced, 1); + + // frame 2: - voicing, joint Wo & E + + self.analyse_one_frame(&mut model, &speech[self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + + // need to run this just to get LPC energy + let e = speech_to_uq_lsps( + &mut lsps, + &mut ak, + &self.internal.Sn, + &self.internal.w, + self.internal.m_pitch, + LPC_ORD, + ); + + let WoE_index = encode_WoE(&model, e, &mut self.internal.xq_enc); + pack(bits, &mut nbit, WoE_index, WO_E_BITS); + + // frame 3: - voicing + + self.analyse_one_frame(&mut model, &speech[2 * self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + + // frame 4: - voicing, joint Wo & E, scalar LSPs + + self.analyse_one_frame(&mut model, &speech[3 * self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + + let e = speech_to_uq_lsps( + &mut lsps, + &mut ak, + &self.internal.Sn, + &self.internal.w, + self.internal.m_pitch, + LPC_ORD, + ); + let WoE_index = encode_WoE(&model, e, &mut self.internal.xq_enc); + pack(bits, &mut nbit, WoE_index, WO_E_BITS); + + encode_lsps_scalar(&mut lsp_indexes, &lsps, LPC_ORD); + for i in 0..LSP_SCALAR_INDEXES { + pack(bits, &mut nbit, lsp_indexes[i], lsp_bits(i)); + } + + assert_eq!(nbit, self.bits_per_frame()); + } + + /*---------------------------------------------------------------------------*\ + FUNCTION....: codec2_decode_1400 + AUTHOR......: David Rowe, conversion by Raphael Peters + DATE CREATED: 11 May 2012 + Decodes frames of 56 bits into 320 samples (40ms) of speech. + \*---------------------------------------------------------------------------*/ + fn codec2_decode_1400(&mut self, speech: &mut [i16], bits: &[u8]) { + let mut model = [MODEL::new(self.internal.c2const.p_max as f32); 4]; + let mut lsp_indexes = [0; LPC_ORD]; + let mut lsps = [[0.0; LPC_ORD]; 4]; + let mut e = [0.0; 4]; + let mut snr = 0.0; + let mut ak = [[0.0; LPC_ORD + 1]; 4]; + let mut nbit = 0; + let mut Aw = [COMP::new(); FFT_ENC]; + + /* unpack bits from channel ------------------------------------*/ + + /* this will partially fill the model params for the 4 x 10ms + frames */ + + model[0].voiced = unpack(bits, &mut nbit, 1); + + model[1].voiced = unpack(bits, &mut nbit, 1); + let WoE_index = unpack(bits, &mut nbit, WO_E_BITS); + decode_WoE( + &self.internal.c2const, + &mut model[1], + &mut e[1], + &mut self.internal.xq_dec, + WoE_index as usize, + ); + + model[2].voiced = unpack(bits, &mut nbit, 1); + + model[3].voiced = unpack(bits, &mut nbit, 1); + let WoE_index = unpack(bits, &mut nbit, WO_E_BITS); + decode_WoE( + &self.internal.c2const, + &mut model[3], + &mut e[3], + &mut self.internal.xq_dec, + WoE_index as usize, + ); + + for i in 0..LSP_SCALAR_INDEXES { + lsp_indexes[i] = unpack(bits, &mut nbit, lsp_bits(i)) as usize; + } + decode_lsps_scalar(&mut lsps[3][0..], &lsp_indexes, LPC_ORD); + check_lsp_order(&mut lsps[3][0..], LPC_ORD); + bw_expand_lsps(&mut lsps[3][0..], LPC_ORD, 50.0, 100.0); + + // interpolate + + /* Wo and energy are sampled every 20ms, so we interpolate just 1 + 10ms frame between 20ms samples */ + + model[0] = interp_Wo( + &model[0], + &self.internal.prev_model_dec, + &model[1], + self.internal.c2const.Wo_min, + ); + e[0] = interp_energy(self.internal.prev_e_dec, e[1]); + model[2] = interp_Wo( + &model[2], + &model[1], + &model[3], + self.internal.c2const.Wo_min, + ); + e[2] = interp_energy(e[1], e[3]); + + /* LSPs are sampled every 40ms so we interpolate the 3 frames in + between, then recover spectral amplitudes */ + + for i in 0..3 { + let weight = 0.25 + i as f32 * 0.25; + let lsps3 = lsps[3]; + interpolate_lsp_ver2( + &mut lsps[i][0..], + &self.internal.prev_lsps_dec, + &lsps3[0..], + weight, + LPC_ORD, + ); + } + for i in 0..4 { + lsp_to_lpc(&lsps[i][0..], &mut ak[i][0..], LPC_ORD); + aks_to_M2( + &mut self.internal.fftr_fwd_cfg, + &ak[i][0..], + LPC_ORD, + &mut model[i], + e[i], + &mut snr, + 0, + 0, + self.internal.lpc_pf, + self.internal.bass_boost, + self.internal.beta, + self.internal.gamma, + &mut Aw, + ); + apply_lpc_correction(&mut model[i]); + self.synthesise_one_frame( + &mut speech[self.internal.n_samp * i..], + &mut model[i], + &Aw, + 1.0, + ); + } + + /* update memories for next frame ----------------------------*/ + + self.internal.prev_model_dec = model[3]; + self.internal.prev_e_dec = e[3]; + for i in 0..LPC_ORD { + self.internal.prev_lsps_dec[i] = lsps[3][i]; + } + } + + /*---------------------------------------------------------------------------*\ + FUNCTION....: codec2_encode_1300 + AUTHOR......: David Rowe, conversion by Raphael Peters + DATE CREATED: March 14 2013 + Encodes 320 speech samples (40ms of speech) into 52 bits. + The codec2 algorithm actually operates internally on 10ms (80 + sample) frames, so we run the encoding algorithm 4 times: + frame 0: voicing bit + frame 1: voicing bit, + frame 2: voicing bit + frame 3: voicing bit, Wo and E, scalar LSPs + The bit allocation is: + Parameter frame 2 frame 4 Total + ------------------------------------------------------- + Harmonic magnitudes (LSPs) 0 36 36 + Pitch (Wo) 0 7 7 + Energy 0 5 5 + Voicing (10ms update) 2 2 4 + TOTAL 2 50 52 + \*---------------------------------------------------------------------------*/ + fn codec2_encode_1300(&mut self, bits: &mut [u8], speech: &[i16]) { + let mut model = MODEL::new(self.internal.c2const.p_max as f32); + let mut lsps = [0.0; LPC_ORD]; //f32 + let mut ak = [0.0; LPC_ORD + 1]; //f32 + let mut lsp_indexes = [0; LPC_ORD]; + let mut nbit = 0; + + let nbyte = (self.bits_per_frame() + 7) / 8; + for i in 0..nbyte { + bits[i] = 0; + } + + // frame 1: - voicing + + self.analyse_one_frame(&mut model, speech); + pack_natural_or_gray(bits, &mut nbit, model.voiced, 1, self.internal.gray as u32); + + /* frame 2: - voicing ---------------------------------------------*/ + + self.analyse_one_frame(&mut model, &speech[self.internal.n_samp..]); + pack_natural_or_gray(bits, &mut nbit, model.voiced, 1, self.internal.gray as u32); + + // frame 3: - voicing + + self.analyse_one_frame(&mut model, &speech[2 * self.internal.n_samp..]); + pack_natural_or_gray(bits, &mut nbit, model.voiced, 1, self.internal.gray as u32); + + // frame 4: - voicing, scalar Wo & E, scalar LSPs + + self.analyse_one_frame(&mut model, &speech[3 * self.internal.n_samp..]); + pack_natural_or_gray(bits, &mut nbit, model.voiced, 1, self.internal.gray as u32); + + let Wo_index = encode_Wo(&self.internal.c2const, model.Wo, WO_BITS); + pack_natural_or_gray( + bits, + &mut nbit, + Wo_index, + WO_BITS as u32, + self.internal.gray as u32, + ); + + let e = speech_to_uq_lsps( + &mut lsps, + &mut ak, + &self.internal.Sn, + &self.internal.w, + self.internal.m_pitch, + LPC_ORD, + ); + let e_index = encode_energy(e, E_BITS); + pack_natural_or_gray( + bits, + &mut nbit, + e_index, + E_BITS as u32, + self.internal.gray as u32, + ); + + encode_lsps_scalar(&mut lsp_indexes, &lsps, LPC_ORD); + for i in 0..LSP_SCALAR_INDEXES { + pack_natural_or_gray( + bits, + &mut nbit, + lsp_indexes[i], + lsp_bits(i), + self.internal.gray as u32, + ); + } + + assert_eq!(nbit, self.bits_per_frame()); + } + + /*---------------------------------------------------------------------------*\ + FUNCTION....: codec2_decode_1300 + AUTHOR......: David Rowe, conversion by Raphael Peters + DATE CREATED: 11 May 2012 + Decodes frames of 52 bits into 320 samples (40ms) of speech. + \*---------------------------------------------------------------------------*/ + fn codec2_decode_1300(&mut self, speech: &mut [i16], bits: &[u8], ber_est: f32) { + let mut model = [MODEL::new(self.internal.c2const.p_max as f32); 4]; + let mut lsp_indexes = [0; LPC_ORD]; + let mut lsps = [[0.0; LPC_ORD]; 4]; + let mut e = [0.0; 4]; + let mut snr = 0.0; + let mut ak = [[0.0; LPC_ORD + 1]; 4]; + let mut nbit = 0; + let mut Aw = [COMP::new(); FFT_ENC]; + + /* unpack bits from channel ------------------------------------*/ + + /* this will partially fill the model params for the 4 x 10ms + frames */ + + model[0].voiced = unpack_natural_or_gray(bits, &mut nbit, 1, self.internal.gray as u32); + model[1].voiced = unpack_natural_or_gray(bits, &mut nbit, 1, self.internal.gray as u32); + model[2].voiced = unpack_natural_or_gray(bits, &mut nbit, 1, self.internal.gray as u32); + model[3].voiced = unpack_natural_or_gray(bits, &mut nbit, 1, self.internal.gray as u32); + + let Wo_index = + unpack_natural_or_gray(bits, &mut nbit, WO_BITS as u32, self.internal.gray as u32); + model[3].Wo = decode_Wo(&self.internal.c2const, Wo_index, WO_BITS); + model[3].L = (PI / model[3].Wo) as usize; + + let e_index = + unpack_natural_or_gray(bits, &mut nbit, E_BITS as u32, self.internal.gray as u32); + e[3] = decode_energy(e_index, E_BITS); + + for i in 0..LSP_SCALAR_INDEXES { + lsp_indexes[i] = + unpack_natural_or_gray(bits, &mut nbit, lsp_bits(i), self.internal.gray as u32) + as usize; + } + decode_lsps_scalar(&mut lsps[3][0..], &lsp_indexes, LPC_ORD); + check_lsp_order(&mut lsps[3][0..], LPC_ORD); + bw_expand_lsps(&mut lsps[3][0..], LPC_ORD, 50.0, 100.0); + + if ber_est > 0.15 { + model[0].voiced = 0; + model[1].voiced = 0; + model[2].voiced = 0; + model[3].voiced = 0; + e[3] = decode_energy(10, E_BITS); + bw_expand_lsps(&mut lsps[3][0..], LPC_ORD, 200.0, 200.0); + //fprintf(stderr, "soft mute\n"); + } + + // interpolate + + /* Wo, energy, and LSPs are sampled every 40ms so we interpolate + the 3 frames in between */ + + for i in 0..3 { + let weight = 0.25 + i as f32 * 0.25; + let lsps3 = lsps[3]; + interpolate_lsp_ver2( + &mut lsps[i][0..], + &self.internal.prev_lsps_dec, + &lsps3[0..], + weight, + LPC_ORD, + ); + model[i] = interp_Wo2( + &model[i], + &self.internal.prev_model_dec, + &model[3], + weight, + self.internal.c2const.Wo_min, + ); + e[i] = interp_energy2(self.internal.prev_e_dec, e[3], weight); + } + + /* then recover spectral amplitudes */ + + for i in 0..4 { + lsp_to_lpc(&lsps[i][0..], &mut ak[i][0..], LPC_ORD); + aks_to_M2( + &mut self.internal.fftr_fwd_cfg, + &ak[i][0..], + LPC_ORD, + &mut model[i], + e[i], + &mut snr, + 0, + 0, + self.internal.lpc_pf, + self.internal.bass_boost, + self.internal.beta, + self.internal.gamma, + &mut Aw, + ); + apply_lpc_correction(&mut model[i]); + self.synthesise_one_frame( + &mut speech[self.internal.n_samp * i..], + &mut model[i], + &Aw, + 1.0, + ); + + /* dump parameters for deep learning experiments */ + /* + if (c2 -> fmlfeat != NULL) { + /* 10 LSPs - energy - Wo - voicing flag - 10 LPCs */ + fwrite(&lsps[i][0], LPC_ORD, sizeof(float), self.internal.fmlfeat); + fwrite(&e[i], 1, sizeof(float), self.internal.fmlfeat); + fwrite(&model[i].Wo, 1, sizeof(float), self.internal.fmlfeat); + float + voiced_float = model[i].voiced; + fwrite(&voiced_float, 1, sizeof(float), self.internal.fmlfeat); + fwrite(&ak[i][1], LPC_ORD, sizeof(float), self.internal.fmlfeat); + } + + */ + } + + /* + #ifdef DUMP + dump_lsp_(&lsps[3][0]); + dump_ak_(&ak[3][0], LPC_ORD); + #endif + */ + + /* update memories for next frame ----------------------------*/ + + self.internal.prev_model_dec = model[3]; + self.internal.prev_e_dec = e[3]; + for i in 0..LPC_ORD { + self.internal.prev_lsps_dec[i] = lsps[3][i]; + } + } + + /*---------------------------------------------------------------------------*\ + FUNCTION....: codec2_encode_1200 + AUTHOR......: David Rowe, conversion by Raphael Peters + DATE CREATED: Nov 14 2011 + Encodes 320 speech samples (40ms of speech) into 48 bits. + The codec2 algorithm actually operates internally on 10ms (80 + sample) frames, so we run the encoding algorithm four times: + frame 0: voicing bit + frame 1: voicing bit, joint VQ of Wo and E + frame 2: voicing bit + frame 3: voicing bit, joint VQ of Wo and E, VQ LSPs + The bit allocation is: + Parameter frame 2 frame 4 Total + ------------------------------------------------------- + Harmonic magnitudes (LSPs) 0 27 27 + Energy+Wo 8 8 16 + Voicing (10ms update) 2 2 4 + Spare 0 1 1 + TOTAL 10 38 48 + \*---------------------------------------------------------------------------*/ + fn codec2_encode_1200(&mut self, bits: &mut [u8], speech: &[i16]) { + let mut model = MODEL::new(self.internal.c2const.p_max as f32); + let mut lsps = [0.0; LPC_ORD]; //f32 + let mut lsps_ = [0.0; LPC_ORD]; //f32 + let mut ak = [0.0; LPC_ORD + 1]; //f32 + let mut lsp_indexes = [0; LPC_ORD]; + let spare = 0; + let mut nbit = 0; + + let nbyte = (self.bits_per_frame() + 7) / 8; + for i in 0..nbyte { + bits[i] = 0; + } + + // frame 1: - voicing + + self.analyse_one_frame(&mut model, speech); + pack(bits, &mut nbit, model.voiced, 1); + + // frame 2: - voicing, joint Wo & E + + self.analyse_one_frame(&mut model, &speech[self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + + // need to run this just to get LPC energy + let e = speech_to_uq_lsps( + &mut lsps, + &mut ak, + &self.internal.Sn, + &self.internal.w, + self.internal.m_pitch, + LPC_ORD, + ); + + let WoE_index = encode_WoE(&model, e, &mut self.internal.xq_enc); + pack(bits, &mut nbit, WoE_index, WO_E_BITS); + + // frame 3: - voicing + + self.analyse_one_frame(&mut model, &speech[2 * self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + + // frame 4: - voicing, joint Wo & E, scalar LSPs + + self.analyse_one_frame(&mut model, &speech[3 * self.internal.n_samp..]); + pack(bits, &mut nbit, model.voiced, 1); + + let e = speech_to_uq_lsps( + &mut lsps, + &mut ak, + &self.internal.Sn, + &self.internal.w, + self.internal.m_pitch, + LPC_ORD, + ); + let WoE_index = encode_WoE(&model, e, &mut self.internal.xq_enc); + pack(bits, &mut nbit, WoE_index, WO_E_BITS); + + encode_lsps_vq(&mut lsp_indexes, &mut lsps, &mut lsps_, LPC_ORD); + for i in 0..LSP_PRED_VQ_INDEXES { + pack( + bits, + &mut nbit, + lsp_indexes[i] as i32, + lsp_pred_vq_bits(i) as u32, + ); + } + pack(bits, &mut nbit, spare, 1); + + assert_eq!(nbit, self.bits_per_frame()); + } + + /*---------------------------------------------------------------------------*\ + FUNCTION....: codec2_decode_1200 + AUTHOR......: David Rowe, conversion by Raphael Peters + DATE CREATED: 14 Feb 2012 + Decodes frames of 48 bits into 320 samples (40ms) of speech. + \*---------------------------------------------------------------------------*/ + + fn codec2_decode_1200(&mut self, speech: &mut [i16], bits: &[u8]) { + let mut model = [MODEL::new(self.internal.c2const.p_max as f32); 4]; + let mut lsp_indexes = [0; LPC_ORD]; + let mut lsps = [[0.0; LPC_ORD]; 4]; + let mut e = [0.0; 4]; + let mut snr = 0.0; + let mut ak = [[0.0; LPC_ORD + 1]; 4]; + let mut nbit = 0; + let mut Aw = [COMP::new(); FFT_ENC]; + // only need to zero these out due to (unused) snr calculation + + for i in 0..4 { + for j in 1..MAX_AMP { + model[i].A[j] = 0.0; + } + } + + /* unpack bits from channel ------------------------------------*/ + + /* this will partially fill the model params for the 4 x 10ms + frames */ + + model[0].voiced = unpack(bits, &mut nbit, 1); + + model[1].voiced = unpack(bits, &mut nbit, 1); + let WoE_index = unpack(bits, &mut nbit, WO_E_BITS); + decode_WoE( + &self.internal.c2const, + &mut model[1], + &mut e[1], + &mut self.internal.xq_dec, + WoE_index as usize, + ); + + model[2].voiced = unpack(bits, &mut nbit, 1); + + model[3].voiced = unpack(bits, &mut nbit, 1); + let WoE_index = unpack(bits, &mut nbit, WO_E_BITS); + decode_WoE( + &self.internal.c2const, + &mut model[3], + &mut e[3], + &mut self.internal.xq_dec, + WoE_index as usize, + ); + + for i in 0..LSP_PRED_VQ_INDEXES { + lsp_indexes[i] = unpack(bits, &mut nbit, lsp_pred_vq_bits(i) as u32) as usize; + } + decode_lsps_vq(&lsp_indexes, &mut lsps[3][0..], LPC_ORD, 0); + check_lsp_order(&mut lsps[3][0..], LPC_ORD); + bw_expand_lsps(&mut lsps[3][0..], LPC_ORD, 50.0, 100.0); + + // interpolate + + /* Wo and energy are sampled every 20ms, so we interpolate just 1 + 10ms frame between 20ms samples */ + + model[0] = interp_Wo( + &model[0], + &self.internal.prev_model_dec, + &model[1], + self.internal.c2const.Wo_min, + ); + e[0] = interp_energy(self.internal.prev_e_dec, e[1]); + model[2] = interp_Wo( + &model[2], + &model[1], + &model[3], + self.internal.c2const.Wo_min, + ); + e[2] = interp_energy(e[1], e[3]); + + /* LSPs are sampled every 40ms so we interpolate the 3 frames in + between, then recover spectral amplitudes */ + + for i in 0..3 { + let weight = 0.25 + i as f32 * 0.25; + let lsps3 = lsps[3]; + interpolate_lsp_ver2( + &mut lsps[i][0..], + &self.internal.prev_lsps_dec, + &lsps3[0..], + weight, + LPC_ORD, + ); + } + for i in 0..4 { + lsp_to_lpc(&lsps[i][0..], &mut ak[i][0..], LPC_ORD); + aks_to_M2( + &mut self.internal.fftr_fwd_cfg, + &ak[i][0..], + LPC_ORD, + &mut model[i], + e[i], + &mut snr, + 0, + 0, + self.internal.lpc_pf, + self.internal.bass_boost, + self.internal.beta, + self.internal.gamma, + &mut Aw, + ); + apply_lpc_correction(&mut model[i]); + self.synthesise_one_frame( + &mut speech[self.internal.n_samp * i..], + &mut model[i], + &Aw, + 1.0, + ); + } + + /* update memories for next frame ----------------------------*/ + + self.internal.prev_model_dec = model[3]; + self.internal.prev_e_dec = e[3]; + for i in 0..LPC_ORD { + self.internal.prev_lsps_dec[i] = lsps[3][i]; + } + } + + /*---------------------------------------------------------------------------* \ + + FUNCTION....: analyse_one_frame() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 23/8/2010 + + Extract sinusoidal model parameters from 80 speech samples (10ms of + speech). + + \*---------------------------------------------------------------------------*/ + fn analyse_one_frame(&mut self, model: &mut MODEL, speech: &[i16]) { + let mut Sw = [COMP::new(); FFT_ENC]; + let n_samp = self.internal.n_samp; + let m_pitch = self.internal.m_pitch; + + // Read input speech + for i in 0..m_pitch - n_samp { + self.internal.Sn[i] = self.internal.Sn[i + n_samp]; + } + for i in 0..n_samp { + self.internal.Sn[i + m_pitch - n_samp] = speech[i].into(); + } + self.internal.c2const.dft_speech( + &self.internal.fft_fwd_cfg, + &mut Sw, + &self.internal.Sn, + &self.internal.w, + ); + + // Estimate pitch + let mut pitch = 0.0; + nlp::nlp( + &mut self.internal.nlp, + &self.internal.Sn, + n_samp, + &mut pitch, + &Sw, + &self.internal.W, + &mut self.internal.prev_f0_enc, + ); + model.Wo = TWO_PI / pitch; + model.L = (PI / model.Wo) as usize; + + // estimate model parameters + two_stage_pitch_refinement(&self.internal.c2const, model, &Sw); + + // estimate phases when doing ML experiments + estimate_amplitudes(model, &Sw, &self.internal.W, 0); + est_voicing_mbe(&self.internal.c2const, model, &Sw, &self.internal.W); + } + + /*---------------------------------------------------------------------------* \ + + FUNCTION....: synthesise_one_frame() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 23/8/2010 + + Synthesise 80 speech samples (10ms) from model parameters. + + \*---------------------------------------------------------------------------*/ + fn synthesise_one_frame( + &mut self, + speech: &mut [i16], + model: &mut MODEL, + Aw: &[COMP], + gain: f32, + ) { + // LPC based phase synthesis + let mut H = [COMP::new(); MAX_AMP + 1]; + sample_phase(model, &mut H, Aw); + phase_synth_zero_order( + self.internal.n_samp, + model, + &mut self.internal.ex_phase, + &mut H, + &mut self.internal.random, + ); + + postfilter(model, &mut self.internal.bg_est, &mut self.internal.random); + synthesise( + self.internal.n_samp, + &mut self.internal.fftr_inv_cfg, + &mut self.internal.Sn_, + model, + &self.internal.Pn, + true, + ); + + for i in 0..self.internal.n_samp { + self.internal.Sn_[i] *= gain; + } + + ear_protection(&mut self.internal.Sn_, self.internal.n_samp); + + for i in 0..self.internal.n_samp { + if self.internal.Sn_[i] > 32767.0 { + speech[i] = 32767; + } else if self.internal.Sn_[i] < -32767.0 { + speech[i] = -32767; + } else { + speech[i] = self.internal.Sn_[i] as i16; + } + } + } +} + +/*---------------------------------------------------------------------------* \ + + FUNCTION....: ear_protection() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: Nov 7 2012 + + Limits output level to protect ears when there are bit errors or the input + is overdriven. This doesn't correct or mask bit errors, just reduces the + worst of their damage. + +\*---------------------------------------------------------------------------*/ +fn ear_protection(in_out: &mut [f32], n: usize) { + // find maximum sample in frame + + let mut max_sample = 0.0; + for i in 0..n { + if in_out[i] > max_sample { + max_sample = in_out[i]; + } + } + + // determine how far above set point + + let over = max_sample / 30000.0; + + /* If we are x dB over set point we reduce level by 2x dB, this + attenuates major excursions in amplitude (likely to be caused + by bit errors) more than smaller ones */ + + if over > 1.0 { + let gain = 1.0 / (over * over); + for i in 0..n { + in_out[i] *= gain; + } + } +} + +/*---------------------------------------------------------------------------*\ + + est_voicing_mbe() + + Returns the error of the MBE cost function for a fiven F0. + + Note: I think a lot of the operations below can be simplified as + W[].i = 0 and has been normalised such that den always equals 1. + +\*---------------------------------------------------------------------------*/ +fn est_voicing_mbe(c2const: &C2const, model: &mut MODEL, Sw: &[COMP], W: &[f32]) -> f32 { + let mut Am = COMP::new(); // amplitude sample for this band + let mut Ew = COMP::new(); + + let l_1000hz = (model.L as f32 * 1000.0 / ((c2const.Fs / 2) as f32)) as usize; + let mut sig = 1E-4; + for l in 1..l_1000hz + 1 { + sig += model.A[l] * model.A[l]; + } + + let Wo = model.Wo; + let mut error = 1E-4; //accumulated error between original and synthesised + + // Just test across the harmonics in the first 1000 Hz + + for l in 1..l_1000hz + 1 { + Am.r = 0.0; + Am.i = 0.0; + let mut den = 0.0; //denominator of Am expression + let al = ((l as f32 - 0.5) * Wo * (FFT_ENC as f32) / TWO_PI).dsp_ceil() as usize; + let bl = ((l as f32 + 0.5) * Wo * (FFT_ENC as f32) / TWO_PI).dsp_ceil() as usize; + + // Estimate amplitude of harmonic assuming harmonic is totally voiced + + // centers Hw[] about current harmonic + let offset = + (FFT_ENC as f32 / 2.0 - (l as f32) * Wo * (FFT_ENC as f32) / TWO_PI + 0.5) as usize; + for m in al..bl { + Am.r += Sw[m].r * W[offset + m]; + Am.i += Sw[m].i * W[offset + m]; + den += W[offset + m] * W[offset + m]; + } + + Am.r = Am.r / den; + Am.i = Am.i / den; + + // Determine error between estimated harmonic and original + + for m in al..bl { + Ew.r = Sw[m].r - Am.r * W[offset + m]; + Ew.i = Sw[m].i - Am.i * W[offset + m]; + error += Ew.r * Ew.r; + error += Ew.i * Ew.i; + } + } + + let snr = 10.0 * (sig / error).dsp_log10(); + if snr > V_THRESH { + model.voiced = 1; + } else { + model.voiced = 0; + } + // post processing, helps clean up some voicing errors ------------------ + + /* + Determine the ratio of low freqency to high frequency energy, + voiced speech tends to be dominated by low frequency energy, + unvoiced by high frequency. This measure can be used to + determine if we have made any gross errors. + */ + + let l_2000hz = (model.L as f32 * 2000.0 / (c2const.Fs as f32 / 2.0)) as usize; + let l_4000hz = (model.L as f32 * 4000.0 / (c2const.Fs as f32 / 2.0)) as usize; + let mut ehigh = 1E-4; + let mut elow = ehigh; + for l in 1..l_2000hz + 1 { + elow += model.A[l] * model.A[l]; + } + for l in l_2000hz..l_4000hz + 1 { + ehigh += model.A[l] * model.A[l]; + } + let eratio = 10.0 * (elow / ehigh).dsp_log10(); + + /* Look for Type 1 errors, strongly V speech that has been + accidentally declared UV */ + + if model.voiced == 0 { + if eratio > 10.0 { + model.voiced = 1; + } + } + /* Look for Type 2 errors, strongly UV speech that has been + accidentally declared V */ + + if model.voiced == 1 { + if eratio < -10.0 { + model.voiced = 0; + } + /* A common source of Type 2 errors is the pitch estimator + gives a low (50Hz) estimate for UV speech, which gives a + good match with noise due to the close harmoonic spacing. + These errors are much more common than people with 50Hz3 + pitch, so we have just a small eratio threshold. */ + + let sixty = 60.0 * TWO_PI / (c2const.Fs as f32); + if (eratio < -4.0) && (model.Wo <= sixty) { + model.voiced = 0; + } + } + + return snr; +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: estimate_amplitudes + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 27/5/94 + + Estimates the complex amplitudes of the harmonics. + +\*---------------------------------------------------------------------------*/ +fn estimate_amplitudes(model: &mut MODEL, Sw: &[COMP], _W: &[f32], est_phase: i32) { + let r = TWO_PI / (FFT_ENC as f32); + let one_on_r = 1.0 / r; + + for m in 1..model.L + 1 { + // Estimate ampltude of harmonic + + let mut den = 0.0; // denominator of amplitude expression + // bounds of current harmonic + let am = ((m as f32 - 0.5) * model.Wo * one_on_r + 0.5) as usize; + let bm = ((m as f32 + 0.5) * model.Wo * one_on_r + 0.5) as usize; + + for i in am..bm { + den += Sw[i].r * Sw[i].r + Sw[i].i * Sw[i].i; + } + + model.A[m] = den.dsp_sqrt(); + + if est_phase != 0 { + let b = (m as f32 * model.Wo / r + 0.5) as usize; // DFT bin of centre of current harmonic + + /* Estimate phase of harmonic, this is expensive in CPU for + embedded devicesso we make it an option */ + + model.phi[m] = Sw[b].i.dsp_atan2(Sw[b].r); + } + } +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: two_stage_pitch_refinement + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 27/5/94 + + Refines the current pitch estimate using the harmonic sum pitch + estimation technique. + +\*---------------------------------------------------------------------------*/ +fn two_stage_pitch_refinement(c2const: &C2const, model: &mut MODEL, Sw: &[COMP]) { + // Coarse refinement + // pitch refinment minimum, maximum and step + let mut pmax = TWO_PI / model.Wo + 5.0; + let mut pmin = TWO_PI / model.Wo - 5.0; + let mut pstep = 1.0; + hs_pitch_refinement(model, Sw, pmin, pmax, pstep); + + // Fine refinement + + pmax = TWO_PI / model.Wo + 1.0; + pmin = TWO_PI / model.Wo - 1.0; + pstep = 0.25; + hs_pitch_refinement(model, Sw, pmin, pmax, pstep); + + // Limit range + + if model.Wo < TWO_PI / (c2const.p_max as f32) { + model.Wo = TWO_PI / (c2const.p_max as f32); + } + if model.Wo > TWO_PI / (c2const.p_min as f32) { + model.Wo = TWO_PI / (c2const.p_min as f32); + } + + model.L = (PI / model.Wo).dsp_floor() as usize; + + // trap occasional round off issues with floorf() + if model.Wo * model.L as f32 >= 0.95 * PI { + model.L -= 1; + } + // assert(model.Wo*model.L < PI); +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: hs_pitch_refinement + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 27/5/94 + + Harmonic sum pitch refinement function. + + pmin pitch search range minimum + pmax pitch search range maximum + step pitch search step size + model current pitch estimate in model.Wo + + model refined pitch estimate in model.Wo + +\*---------------------------------------------------------------------------*/ +fn hs_pitch_refinement(model: &mut MODEL, Sw: &[COMP], pmin: f32, pmax: f32, pstep: f32) { + // Initialisation + + model.L = (PI / model.Wo) as usize; // use initial pitch est. for L + let mut Wom = model.Wo; // Wo that maximises E + let mut Em = 0.0; // mamimum energy + let r = TWO_PI / FFT_ENC as f32; // number of rads/bin + let one_on_r = 1.0 / r; + + // Determine harmonic sum for a range of Wo values + let mut p = pmin; // current pitch + while p <= pmax { + let mut E = 0.0; //energy for current pitch + let Wo = TWO_PI / p; // current "test" fundamental freq. + + // Sum harmonic magnitudes + for m in 1..model.L + 1 { + // bin for current harmonic centre + let b = (m as f32 * Wo * one_on_r + 0.5) as usize; + E += Sw[b].r * Sw[b].r + Sw[b].i * Sw[b].i; + } + // Compare to see if this is a maximum + + if E > Em { + Em = E; + Wom = Wo; + } + p += pstep; + } + + model.Wo = Wom; +} + +#[cfg(test)] +mod tests { + extern crate std; + use super::*; + + #[test] + fn real_fft_preserves_second_half_input() { + let mut storage = std::boxed::Box::::new_uninit(); + let codec = crate::Codec::initialise(&mut storage, crate::Mode::Rate1600); + let mut input = [0.0; 512]; + input[400] = 1.0; + let mut frequency = [kiss_fft_cpx::new(); 257]; + codec2_fftr( + &mut codec.native.internal.fftr_fwd_cfg, + &input, + &mut frequency, + ); + assert!((frequency[0].r - 1.0).abs() < 1e-5); + let mut output = [0.0; 512]; + codec2_fftri( + &mut codec.native.internal.fftr_inv_cfg, + &frequency, + &mut output, + ); + for (before, after) in input.iter().zip(output) { + assert!((*before - after / 512.0).abs() < 1e-5); + } + } +} diff --git a/crates/lxst-codec2/src/native/nlp.rs b/crates/lxst-codec2/src/native/nlp.rs new file mode 100644 index 0000000..fce77c8 --- /dev/null +++ b/crates/lxst-codec2/src/native/nlp.rs @@ -0,0 +1,415 @@ +use super::*; +const fdmdv_os_filter: [f32; 48] = [ + -0.0008215855034550382, + -0.0007833023901802921, + 0.001075563790768233, + 0.001199092367787555, + -0.001765309502928316, + -0.002055372115328064, + 0.002986877604154257, + 0.003462567920638414, + -0.004856570111126334, + -0.005563143845031497, + 0.007533613299748122, + 0.008563932468880897, + -0.01126857129039911, + -0.01280782411693687, + 0.01651443896361847, + 0.01894875110322284, + -0.02421604439474981, + -0.02845107338464062, + 0.03672973563400258, + 0.04542046150312214, + -0.06189165826716491, + -0.08721876380763803, + 0.1496157094199961, + 0.4497962274137046, + 0.4497962274137046, + 0.1496157094199961, + -0.08721876380763803, + -0.0618916582671649, + 0.04542046150312216, + 0.03672973563400257, + -0.02845107338464062, + -0.02421604439474984, + 0.01894875110322284, + 0.01651443896361848, + -0.01280782411693687, + -0.0112685712903991, + 0.008563932468880899, + 0.007533613299748123, + -0.005563143845031501, + -0.004856570111126346, + 0.003462567920638419, + 0.002986877604154259, + -0.002055372115328063, + -0.001765309502928318, + 0.001199092367787557, + 0.001075563790768233, + -0.0007833023901802925, + -0.0008215855034550383, +]; + +const nlp_fir: [f32; 48] = [ + -1.0818124e-03, + -1.1008344e-03, + -9.2768838e-04, + -4.2289438e-04, + 5.5034190e-04, + 2.0029849e-03, + 3.7058509e-03, + 5.1449415e-03, + 5.5924666e-03, + 4.3036754e-03, + 8.0284511e-04, + -4.8204610e-03, + -1.1705810e-02, + -1.8199275e-02, + -2.2065282e-02, + -2.0920610e-02, + -1.2808831e-02, + 3.2204775e-03, + 2.6683811e-02, + 5.5520624e-02, + 8.6305944e-02, + 1.1480192e-01, + 1.3674206e-01, + 1.4867556e-01, + 1.4867556e-01, + 1.3674206e-01, + 1.1480192e-01, + 8.6305944e-02, + 5.5520624e-02, + 2.6683811e-02, + 3.2204775e-03, + -1.2808831e-02, + -2.0920610e-02, + -2.2065282e-02, + -1.8199275e-02, + -1.1705810e-02, + -4.8204610e-03, + 8.0284511e-04, + 4.3036754e-03, + 5.5924666e-03, + 5.1449415e-03, + 3.7058509e-03, + 2.0029849e-03, + 5.5034190e-04, + -4.2289438e-04, + -9.2768838e-04, + -1.1008344e-03, + -1.0818124e-03, +]; + +//const PMAX_M: i32 = 320; /* maximum NLP analysis window size */ +const COEFF: f32 = 0.95; /* notch filter parameter */ +const PE_FFT_SIZE: i32 = 512; /* DFT size for pitch estimation */ +const DEC: i32 = 5; /* decimation factor */ +const SAMPLE_RATE: i32 = 8000; +//const PI: f32 = 3.141592654; /* mathematical constant */ +//const T: f32 = 0.1; /* threshold for local minima candidate */ +//const F0_MAX: i32 = 500; +const CNLP: f32 = 0.3; /* post processor constant */ +const NLP_NTAP: i32 = 48; /* Decimation LPF order */ +const FDMDV_OS: i32 = 2; /* oversampling rate */ +pub const FDMDV_OS_TAPS_16K: i32 = 48; /* number of OS filter taps at 16kHz */ +//const FDMDV_OS_TAPS_8K: i32 = FDMDV_OS_TAPS_16K / FDMDV_OS; /* number of OS filter taps at 8kHz */ +/*---------------------------------------------------------------------------*\ + + post_process_sub_multiples() + + Given the global maximma of Fw[] we search integer submultiples for + local maxima. If local maxima exist and they are above an + experimentally derived threshold (OK a magic number I pulled out of + the air) we choose the submultiple as the F0 estimate. + + The rational for this is that the lowest frequency peak of Fw[] + should be F0, as Fw[] can be considered the autocorrelation function + of Sw[] (the speech spectrum). However sometimes due to phase + effects the lowest frequency maxima may not be the global maxima. + + This works OK in practice and favours low F0 values in the presence + of background noise which means the sinusoidal codec does an OK job + of synthesising the background noise. High F0 in background noise + tends to sound more periodic introducing annoying artifacts. + +\*---------------------------------------------------------------------------*/ + +fn post_process_sub_multiples( + Fw: &[COMP], + _pmin: i32, + pmax: i32, + gmax: f32, + gmax_bin: i32, + prev_f0: &f32, +) -> f32 { + /* post process estimate by searching submultiples */ + + let mut mult = 2; + let min_bin = PE_FFT_SIZE * DEC / pmax; + let mut cmax_bin = gmax_bin; + let prev_f0_bin = (*prev_f0) * ((PE_FFT_SIZE * DEC) as f32) / (SAMPLE_RATE as f32); + + while gmax_bin / mult >= min_bin { + let b = gmax_bin / mult; /* determine search interval */ + let mut bmin = (0.8 * (b as f32)) as usize; + let bmax = (1.2 * (b as f32)) as usize; + if bmin < min_bin as usize { + bmin = min_bin as usize; + } + /* lower threshold to favour previous frames pitch estimate, + this is a form of pitch tracking */ + + let thresh = if (prev_f0_bin > bmin as f32) && (prev_f0_bin < bmax as f32) { + CNLP * 0.5 * gmax + } else { + CNLP * gmax + }; + let mut lmax = 0.0; + let mut lmax_bin = bmin; + for b in bmin..bmax { + /* look for maximum in interval */ + if Fw[b].r > lmax { + lmax = Fw[b].r; + lmax_bin = b; + } + } + + if lmax > thresh { + if (lmax > Fw[lmax_bin - 1].r) && (lmax > Fw[lmax_bin + 1].r) { + cmax_bin = lmax_bin as i32; + } + } + mult += 1; + } + + cmax_bin as f32 * SAMPLE_RATE as f32 / (PE_FFT_SIZE as f32 * DEC as f32) +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: fdmdv_16_to_8() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 9 May 2012 + + Changes the sample rate of a signal from 16 to 8 kHz. + + n is the number of samples at the 8 kHz rate, there are FDMDV_OS*n + samples at the 48 kHz rate. As above however a memory of + FDMDV_OS_TAPS samples is reqd for in16k[] (see t16_8.c unit test as example). + + Low pass filter the 16 kHz signal at 4 kHz using the same filter as + the upsampler, then just output every FDMDV_OS-th filtered sample. + + Note: this function copied from fdmdv.c, included in nlp.c as a convenience + to avoid linking with another source file. + +\*---------------------------------------------------------------------------*/ + +fn fdmdv_16_to_8(out8k: &mut [f32], in16k: &mut [f32], in16koff: usize, n: i32) { + let mut i = 0; + for k in 0..n as usize { + let mut acc = 0.0; + for j in 0..FDMDV_OS_TAPS_16K as usize { + acc += fdmdv_os_filter[j] * in16k[in16koff + i - j]; + } + out8k[k] = acc; + i += FDMDV_OS as usize; + } + + /* update filter memory */ + + for i in -FDMDV_OS_TAPS_16K..0 { + in16k[(in16koff as i32 + i) as usize] = + in16k[(in16koff as isize + i as isize + n as isize * FDMDV_OS as isize) as usize]; + } +} +/*---------------------------------------------------------------------------*\ + + nlp() + + Determines the pitch in samples using the Non Linear Pitch (NLP) + algorithm [1]. Returns the fundamental in Hz. Note that the actual + pitch estimate is for the centre of the M sample Sn[] vector, not + the current N sample input vector. This is (I think) a delay of 2.5 + frames with N=80 samples. You should align further analysis using + this pitch estimate to be centred on the middle of Sn[]. + + Two post processors have been tried, the MBE version (as discussed + in [1]), and a post processor that checks sub-multiples. Both + suffer occasional gross pitch errors (i.e. neither are perfect). In + the presence of background noise the sub-multiple algorithm tends + towards low F0 which leads to better sounding background noise than + the MBE post processor. + + A good way to test and develop the NLP pitch estimator is using the + tnlp (codec2/unittest) and the codec2/octave/plnlp.m Octave script. + + A pitch tracker searching a few frames forward and backward in time + would be a useful addition. + + References: + + [1] http://rowetel.com/downloads/1997_rowe_phd_thesis.pdf Chapter 4 + +\*---------------------------------------------------------------------------*/ + +pub fn nlp( + nlp: &mut NLP, + Sn: &[f32], /* input speech vector */ + mut n: usize, /* frames shift (no. new samples in Sn[]) */ + pitch: &mut f32, /* estimated pitch period in samples at current Fs */ + _Sw: &[COMP], /* Freq domain version of Sn[] */ + _W: &[f32], /* Freq domain window */ + prev_f0: &mut f32, /* previous pitch f0 in Hz, memory for pitch tracking */ +) -> f32 { + // notch: f32; /* current notch filter output */ + // let mut Fw[PE_FFT_SIZE]; /* DFT of squared signal (input/output) */ + // PROFILE_VAR(start, tnotch, filter, peakpick, window, fft, magsq, shiftmem); + // assert(nlp_state != NULL); + // nlp = (NLP*)nlp_state; + let mut m = nlp.m; + + /* Square, notch filter at DC, and LP filter vector */ + + /* If running at 16 kHz decimate to 8 kHz, as NLP ws designed for + Fs = 8kHz. The decimating filter introduces about 3ms of delay, + that shouldn't be a problem as pitch changes slowly. */ + + if nlp.Fs == 8000 { + /* Square latest input samples */ + + for i in m - n..m { + nlp.sq[i] = Sn[i] * Sn[i]; + } + } else { + //assert(nlp.Fs == 16000); + + /* re-sample at 8 KHz */ + + for i in 0..n { + nlp.Sn16k[FDMDV_OS_TAPS_16K as usize + i] = Sn[m + i - n]; + } + + m /= 2; + n /= 2; + + let mut Sn8k = Buffer::::filled(n, 0.0); + fdmdv_16_to_8( + &mut Sn8k, + &mut nlp.Sn16k, + FDMDV_OS_TAPS_16K as usize, + n as i32, + ); + + /* Square latest input samples */ + let mut j = 0; + for i in m - n..m { + nlp.sq[i] = Sn8k[j] * Sn8k[j]; + j += 1; + } + // assert(j <= n); + } + //fprintf(stderr, "n: %d m: %d\n", n, m); + + // PROFILE_SAMPLE(start); + for i in m - n..m { + /* notch filter at DC */ + let mut notch = nlp.sq[i] - nlp.mem_x; + notch += COEFF * nlp.mem_y; + nlp.mem_x = nlp.sq[i]; + nlp.mem_y = notch; + nlp.sq[i] = notch + 1.0; /* With 0 input vectors to codec, + kiss_fft() would take a long + time to execute when running in + real time. Problem was traced + to kiss_fft function call in + this function. Adding this small + constant fixed problem. Not + exactly sure why. */ + } + + // PROFILE_SAMPLE_AND_LOG(tnotch, start, " square and notch"); + + for i in m - n..m { + /* FIR filter vector */ + + for j in 0..NLP_NTAP as usize - 1 { + nlp.mem_fir[j] = nlp.mem_fir[j + 1]; + } + nlp.mem_fir[NLP_NTAP as usize - 1] = nlp.sq[i]; + + nlp.sq[i] = 0.0; + for j in 0..NLP_NTAP as usize { + nlp.sq[i] += nlp.mem_fir[j] * nlp_fir[j]; + } + } + + // PROFILE_SAMPLE_AND_LOG(filter, tnotch, " filter"); + + /* Decimate and DFT */ + + let mut Fw = [COMP::new(); PE_FFT_SIZE as usize]; + for i in 0..m / DEC as usize { + Fw[i].r = nlp.sq[i * DEC as usize] * nlp.w[i]; + } + // PROFILE_SAMPLE_AND_LOG(window, filter, " window"); + // #ifdef DUMP + // dump_dec(Fw); + // #endif + + // FIXME: check if this can be converted to a real fft + // since all imag inputs are 0 + super::codec2_fft_inplace(&nlp.fft_cfg, &mut Fw); + // PROFILE_SAMPLE_AND_LOG(fft, window, " fft"); + + for i in 0..PE_FFT_SIZE as usize { + Fw[i].r = Fw[i].r * Fw[i].r + Fw[i].i * Fw[i].i; + } + + // PROFILE_SAMPLE_AND_LOG(magsq, fft, " mag sq"); + // #ifdef DUMP + // dump_sq(m, nlp.sq); + // dump_Fw(Fw); + // #endif + + /* todo: express everything in f0, as pitch in samples is dep on Fs */ + + let pmin = (SAMPLE_RATE as f32 * P_MIN_S).dsp_floor() as i32; + let pmax = (SAMPLE_RATE as f32 * P_MAX_S).dsp_floor() as i32; + + /* find global peak */ + + let mut gmax = 0.0; + let mut gmax_bin = PE_FFT_SIZE * DEC / pmax; + for i in (PE_FFT_SIZE * DEC / pmax) as usize..(PE_FFT_SIZE * DEC / pmin) as usize + 1 { + if Fw[i].r > gmax { + gmax = Fw[i].r; + gmax_bin = i as i32; + } + } + + // PROFILE_SAMPLE_AND_LOG(peakpick, magsq, " peak pick"); + + let best_f0 = post_process_sub_multiples(&Fw, pmin, pmax, gmax, gmax_bin, prev_f0); + + // PROFILE_SAMPLE_AND_LOG(shiftmem, peakpick, " post process"); + + /* Shift samples in buffer to make room for new samples */ + + for i in 0..m - n { + nlp.sq[i] = nlp.sq[i + n]; + } + + /* return pitch period in samples and F0 estimate */ + + *pitch = nlp.Fs as f32 / best_f0; + + // PROFILE_SAMPLE_AND_LOG2(shiftmem, " shift mem"); + + // PROFILE_SAMPLE_AND_LOG2(start, " nlp int"); + + *prev_f0 = best_f0; + + best_f0 +} diff --git a/crates/lxst-codec2/src/native/quantise.rs b/crates/lxst-codec2/src/native/quantise.rs new file mode 100644 index 0000000..a8acada --- /dev/null +++ b/crates/lxst-codec2/src/native/quantise.rs @@ -0,0 +1,1639 @@ +use super::*; + +const LSP_DELTA1: f32 = 0.01; +const E_MIN_DB: f32 = -10.0; +const E_MAX_DB: f32 = 40.0; +pub const E_BITS: i32 = 5; +pub const LSP_PRED_VQ_INDEXES: usize = 3; + +pub fn lspd_bits(i: usize) -> i32 { + lsp_cbd[i].log2m +} + +pub fn lsp_pred_vq_bits(i: usize) -> i32 { + lsp_cbjvm[i].log2m +} + +/*---------------------------------------------------------------------------*\ + + autocorrelate() + + Finds the first P autocorrelation values of an array of windowed speech + samples Sn[]. + +\*---------------------------------------------------------------------------*/ +pub fn autocorrelate( + Sn: &[f32], // frame of Nsam windowed speech samples + Rn: &mut [f32], // array of P+1 autocorrelation coefficients + Nsam: usize, // number of windowed samples to use + order: usize, // order of LPC analysis +) { + for j in 0..order + 1 { + Rn[j] = 0.0; + for i in 0..Nsam - j { + Rn[j] += Sn[i] * Sn[i + j]; + } + } +} + +/*---------------------------------------------------------------------------*\ + + levinson_durbin() + + Given P+1 autocorrelation coefficients, finds P Linear Prediction Coeff. + (LPCs) where P is the order of the LPC all-pole model. The Levinson-Durbin + algorithm is used, and is described in: + + J. Makhoul + "Linear prediction, a tutorial review" + Proceedings of the IEEE + Vol-63, No. 4, April 1975 + +\*---------------------------------------------------------------------------*/ +pub fn levinson_durbin( + R: &[f32], // order+1 autocorrelation coeff + lpcs: &mut [f32], // order+1 LPC's + order: usize, // order of the LPC analysis +) { + assert!(order <= LPC_ORD); + let mut a = [[0.0; LPC_ORD + 1]; LPC_ORD + 1]; + let mut e = R[0]; // Equation 38a, Makhoul + + for i in 1..order + 1 { + let mut sum = 0.0; + for j in 1..i { + sum += a[i - 1][j] * R[i - j]; + } + let mut k = -1.0 * (R[i] + sum) / e; // Equation 38b, Makhoul + if k.abs() > 1.0 { + k = 0.0; + } + a[i][i] = k; + + for j in 1..i { + a[i][j] = a[i - 1][j] + k * a[i - 1][i - j]; // Equation 38c, Makhoul + } + e *= 1.0 - k * k; // Equation 38d, Makhoul + } + + for i in 1..order + 1 { + lpcs[i] = a[order][i]; + } + lpcs[0] = 1.0; +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: cheb_poly_eva() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 24/2/93 + + This function evalutes a series of chebyshev polynomials + + FIXME: performing memory allocation at run time is very inefficient, + replace with stack variables of MAX_P size. + +\*---------------------------------------------------------------------------*/ +fn cheb_poly_eva( + coef: &[f32], // coefficients of the polynomial to be evaluated + x: f32, // the point where polynomial is to be evaluated + order: usize, // order of the polynomial +) -> f32 { + let mut T = Buffer::::filled(order / 2 + 1, 0.0); + + // Initialise offsets + T[0] = 1.0; + T[1] = x; + let mut toff = 0; + let mut uoff = 1; + let mut voff = 2; + // Evaluate chebyshev series formulation using iterative approach + + for _i in 2..order / 2 + 1 { + T[voff] = (2.0 * x) * T[uoff] - T[toff]; // T[i] = 2*x*T[i-1] - T[i-2] + toff += 1; + uoff += 1; + voff += 1; + } + let mut sum = 0.0; // initialise sum to zero + toff = 0; // reset offset + + // Evaluate polynomial and return value also free memory space + + for i in 0..order / 2 + 1 { + sum += coef[(order / 2) - i] * T[toff]; + toff += 1; + } + return sum; +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: lpc_to_lsp() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 24/2/93 + + This function converts LPC coefficients to LSP coefficients. + +\*---------------------------------------------------------------------------*/ +pub fn lpc_to_lsp( + a: &[f32], // float *a lpc coefficients + order: usize, // int order order of LPC coefficients (10) + freq: &mut [f32], // float *freq LSP frequencies in radians + nb: i32, // int nb number of sub-intervals (4) + delta: f32, // float delta grid spacing interval (0.02) +) -> i32 { + let mut roots = 0; // number of roots found + let mut Q = Buffer::::filled(order + 1, 0.0); + let mut P = Buffer::::filled(order + 1, 0.0); + + let m = order / 2; // order of P'(z) & Q'(z) polynimials + + // Allocate memory space for polynomials + + // determine P'(z)'s and Q'(z)'s coefficients where + // P'(z) = P(z)/(1 + z^(-1)) and Q'(z) = Q(z)/(1-z^(-1)) + let mut pxoff = 0; //offsets of respective P'(z) & Q'(z) + let mut qxoff = 0; + let mut poff = pxoff; + let mut qoff = qxoff; + P[pxoff] = 1.0; + pxoff += 1; + Q[qxoff] = 1.0; + qxoff += 1; + for i in 1..m + 1 { + P[pxoff] = a[i] + a[order + 1 - i] - P[poff]; + pxoff += 1; + poff += 1; + Q[qxoff] = a[i] - a[order + 1 - i] + Q[qoff]; + qxoff += 1; + qoff += 1; + } + pxoff = 0; + qxoff = 0; + for _i in 0..m { + P[pxoff] = 2.0 * P[pxoff]; + Q[qxoff] = 2.0 * Q[qxoff]; + pxoff += 1; + qxoff += 1; + } + + // Search for a zero in P'(z) polynomial first and then alternate to Q'(z). + //Keep alternating between the two polynomials as each zero is found + + let mut xr = 0.0; // initialise xr to zero + let mut xl = 1.0; // start at point xl = 1 + + for j in 0..order { + //ptr used for cheb_poly_eval() + let pt = if (j % 2) != 0 { + // determines whether P' or Q' is eval. + &Q[..] + } else { + &P[..] + }; + let mut psuml = cheb_poly_eva(pt, xl, order); // evals poly. at xl + let mut flag = true; + while flag && (xr >= -1.0) { + xr = xl - delta; // interval spacing + let psumr = cheb_poly_eva(pt, xr, order); // poly(xl-delta_x) + let temp_psumr = psumr; + let temp_xr = xr; + + // if no sign change increment xr and re-evaluate + // poly(xr). Repeat til sign change. if a sign change has + // occurred the interval is bisected and then checked again + // for a sign change which determines in which interval the + // zero lies in. If there is no sign change between poly(xm) + // and poly(xl) set interval between xm and xr else set + // interval between xl and xr and repeat till root is located + // within the specified limits + + if ((psumr * psuml) < 0.0) || (psumr == 0.0) { + roots += 1; + + let mut xm = 0.0; + for _k in 0..nb + 1 { + xm = (xl + xr) / 2.0; // bisect the interval + let psumm = cheb_poly_eva(pt, xm, order); + if psumm * psuml > 0. { + psuml = psumm; + xl = xm; + } else { + //psumr = psumm; //TODO: unused? + xr = xm; + } + } + + // once zero is found, reset initial interval to xr + freq[j] = xm; + xl = xm; + flag = false; // reset flag for next search + } else { + psuml = temp_psumr; + xl = temp_xr; + } + } + } + + // convert from x domain to radians + for i in 0..order { + freq[i] = freq[i].dsp_acos(); + } + + return roots; +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: encode_Wo() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22/8/2010 + + Encodes Wo using a WO_LEVELS quantiser. + +\*---------------------------------------------------------------------------*/ +pub fn encode_Wo(c2const: &C2const, Wo: f32, bits: i32) -> i32 { + let mut index = 1 << bits; + let Wo_levels = index; + let Wo_min = c2const.Wo_min; + let Wo_max = c2const.Wo_max; + let norm = (Wo - Wo_min) / (Wo_max - Wo_min); + index = (Wo_levels as f32 * norm + 0.5).dsp_floor() as i32; + if index < 0 { + index = 0; + } + if index > (Wo_levels - 1) { + index = Wo_levels - 1; + } + index +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: encode_WoE() + AUTHOR......: Jean-Marc Valin & David Rowe, conversion by Matt Weeks + DATE CREATED: 11 May 2012 + + Joint Wo and LPC energy vector quantiser developed my Jean-Marc + Valin. Returns index, and updated states xq[]. + +\*---------------------------------------------------------------------------*/ +pub fn encode_WoE(model: &MODEL, mut e: f32, xq: &mut [f32]) -> i32 { + let mut err = [0.0, 0.0]; + let mut w = [0.0, 0.0]; + let codebook1 = ge_cb[0].cb; + let nb_entries = 1 << WO_E_BITS; + let ndim = ge_cb[0].k; + let ge_coeff = [0.8, 0.9]; + //assert((1< u32 { + lsp_cb[i].log2m as u32 +} + +fn compute_weights2(x: &[f32], xp: &[f32], w: &mut [f32]) { + w[0] = 30.0; + w[1] = 1.0; + if x[1] < 0.0 { + w[0] *= 0.6; + w[1] *= 0.3; + } + if x[1] < -10.0 { + w[0] *= 0.3; + w[1] *= 0.3; + } + /* Higher weight if pitch is stable */ + if (x[0] - xp[0]).abs() < 0.2 { + w[0] *= 2.0; + w[1] *= 1.5; + } else if (x[0] - xp[0]).abs() > 0.5 + /* Lower if not stable */ + { + w[0] *= 0.5; + } + + /* Lower weight for low energy */ + if x[1] < xp[1] - 10.0 { + w[1] *= 0.5; + } + if x[1] < xp[1] - 20.0 { + w[1] *= 0.5; + } + + //w[0] = 30; + //w[1] = 1; + + /* Square the weights because it's applied on the squared error */ + w[0] *= w[0]; + w[1] *= w[1]; +} + +fn compute_weights(x: &[f32], w: &mut [f32], ndim: usize) { + w[0] = f32::min(x[0], x[1] - x[0]); + for i in 1..ndim - 1 { + w[i] = f32::min(x[i] - x[i - 1], x[i + 1] - x[i]); + } + w[ndim - 1] = f32::min(x[ndim - 1] - x[ndim - 2], PI - x[ndim - 1]); + + for i in 0..ndim { + w[i] = 1. / (0.01 + w[i]); + } +} + +fn find_nearest(codebook: &[f32], nb_entries: usize, x: &mut [f32], ndim: usize) -> usize { + let mut min_dist = 1e15; + let mut nearest = 0; + + for i in 0..nb_entries { + let mut dist = 0f32; + for j in 0..ndim { + dist += (x[j] - codebook[i * ndim + j]) * (x[j] - codebook[i * ndim + j]); + } + if dist < min_dist { + min_dist = dist; + nearest = i; + } + } + nearest +} + +fn find_nearest_weighted( + codebook: &[f32], + nb_entries: usize, + x: &[f32], + w: &[f32], + ndim: usize, +) -> usize { + let mut min_dist = 1e15; + let mut nearest = 0; + + for i in 0..nb_entries { + let mut dist = 0.0; + for j in 0..ndim { + dist += w[j] * (x[j] - codebook[i * ndim + j]) * (x[j] - codebook[i * ndim + j]); + } + if dist < min_dist { + min_dist = dist; + nearest = i; + } + } + nearest +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: encode_lsps_scalar() + AUTHOR......: David Rowe + DATE CREATED: 22/8/2010 + + Thirty-six bit sclar LSP quantiser. From a vector of unquantised + (floating point) LSPs finds the quantised LSP indexes. + +\*---------------------------------------------------------------------------*/ +pub fn encode_lsps_scalar(indexes: &mut [i32], lsp: &[f32], order: usize) { + let mut lsp_hz = Buffer::::filled(order, 0.0); + let mut se = 0.0; + + /* convert from radians to Hz so we can use human readable + frequencies */ + + for i in 0..order { + lsp_hz[i] = (4000.0 / PI) * lsp[i]; + } + /* scalar quantisers */ + + let mut wt = [1.0; 1]; + for i in 0..order { + let k = lsp_cb[i].k; + indexes[i] = quantise(lsp_cb[i].cb, &lsp_hz[i..], &mut wt, k, &mut se) as i32; + } +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: decode_Wo() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22/8/2010 + + Decodes Wo using a WO_LEVELS quantiser. + +\*---------------------------------------------------------------------------*/ +pub fn decode_Wo(c2const: &C2const, index: i32, bits: i32) -> f32 { + let Wo_min = c2const.Wo_min; + let Wo_max = c2const.Wo_max; + let Wo_levels = 1 << bits; + + let step = (Wo_max - Wo_min) / Wo_levels as f32; + Wo_min + step * index as f32 +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: speech_to_uq_lsps() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22/8/2010 + + Analyse a windowed frame of time domain speech to determine LPCs + which are the converted to LSPs for quantisation and transmission + over the channel. + +\*---------------------------------------------------------------------------*/ +pub fn speech_to_uq_lsps( + lsp: &mut [f32], + ak: &mut [f32], + Sn: &[f32], + w: &[f32], + m_pitch: usize, + order: usize, +) -> f32 { + let mut Wn = Buffer::::filled(m_pitch, 0.0); + let mut R = Buffer::::filled(order + 1, 0.0); + + let mut e = 0.0; + for i in 0..m_pitch { + Wn[i] = Sn[i] * w[i]; + e += Wn[i] * Wn[i]; + } + + // trap 0 energy case as LPC analysis will fail + + if e == 0.0 { + for i in 0..order { + lsp[i] = (PI / order as f32) * (i as f32); + } + return 0.0; + } + + autocorrelate(&Wn, &mut R, m_pitch, order); + levinson_durbin(&R, ak, order); + + let mut E = 0.0; + for i in 0..order + 1 { + E += ak[i] * R[i]; + } + + // 15 Hz BW expansion as I can't hear the difference and it may help + // help occasional fails in the LSP root finding. Important to do this + // after energy calculation to avoid -ve energy values. + + for i in 0..order + 1 { + ak[i] *= 0.994f32.dsp_powf(i as f32); + } + + let roots = lpc_to_lsp(ak, order, lsp, 5, LSP_DELTA1); + if roots != order as i32 { + // if root finding fails use some benign LSP values instead + for i in 0..order { + lsp[i] = (PI / order as f32) * (i as f32); + } + } + + return E; +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: encode_energy() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22/8/2010 + + Encodes LPC energy using an E_LEVELS quantiser. + +\*---------------------------------------------------------------------------*/ +pub fn encode_energy(e: f32, bits: i32) -> i32 { + let e_levels = 1 << bits; + + let e = 10.0 * e.dsp_log10(); + let norm = (e - E_MIN_DB) / (E_MAX_DB - E_MIN_DB); + let mut index = (e_levels as f32 * norm + 0.5).dsp_floor() as i32; + if index < 0 { + index = 0; + } + if index > (e_levels - 1) { + index = e_levels - 1; + } + + return index; +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: decode_energy() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22/8/2010 + + Decodes energy using a E_LEVELS quantiser. + +\*---------------------------------------------------------------------------*/ +pub fn decode_energy(index: i32, bits: i32) -> f32 { + let e_min = E_MIN_DB; + let e_max = E_MAX_DB; + let e_levels = 1 << bits; + + let step = (e_max - e_min) / e_levels as f32; + let e = e_min + step * (index as f32); + 10.0_f32.dsp_powf(e / 10.0) +} + +/*---------------------------------------------------------------------------*\ + + encode_lspds_scalar() + + Scalar/VQ LSP difference quantiser. + +\*---------------------------------------------------------------------------*/ +pub fn encode_lspds_scalar(indexes: &mut [i32], lsp: &[f32], order: usize) { + let mut lsp_hz = Buffer::::filled(order, 0.0); + let mut lsp__hz = Buffer::::filled(order, 0.0); + let mut dlsp = Buffer::::filled(order, 0.0); + let mut dlsp_ = Buffer::::filled(order, 0.0); + let mut wt = Buffer::::filled(order, 1.0); + + // convert from radians to Hz so we can use human readable frequencies + + for i in 0..order { + lsp_hz[i] = (4000.0 / PI) * lsp[i]; + } + wt[0] = 1.0; + for i in 0..order { + // find difference from previous qunatised lsp + + if i != 0 { + dlsp[i] = lsp_hz[i] - lsp__hz[i - 1]; + } else { + dlsp[0] = lsp_hz[0]; + } + let k = lsp_cbd[i].k; + let cb = lsp_cbd[i].cb; + let mut se = 0.0; + indexes[i] = quantise(cb, &mut dlsp[i..], &wt, k, &mut se) as i32; + dlsp_[i] = cb[indexes[i] as usize * k]; + + if i != 0 { + lsp__hz[i] = lsp__hz[i - 1] + dlsp_[i]; + } else { + lsp__hz[0] = dlsp_[0]; + } + } +} + +/*---------------------------------------------------------------------------*\ + + quantise + + Quantises vec by choosing the nearest vector in codebook cb, and + returns the vector index. The squared error of the quantised vector + is added to se. + +\*---------------------------------------------------------------------------*/ +fn quantise( + cb: &[f32], // cb[][K]; current VQ codebook + vec: &[f32], // vec[]; vector to quantise + w: &[f32], // w[]; weighting vector + k: usize, // k; dimension of vectors + se: &mut f32, // *se; accumulated squared error +) -> i64 { + let mut besti = 0; // best index so far + let mut beste = 1E32; // best error so far + for j in 0..cb.len() { + let mut e = 0.0; // current error + for i in 0..k { + let diff = cb[j * k + i] - vec[i]; + e += diff * w[i] * diff * w[i]; + } + if e < beste { + beste = e; + besti = j; + } + } + + *se += beste; + besti as i64 +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: interp_energy() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22 May 2012 + + Interpolates centre 10ms sample of energy given two samples 20ms + apart. + +\*---------------------------------------------------------------------------*/ +pub fn interp_energy(prev_e: f32, next_e: f32) -> f32 { + //return powf(10.0, (log10f(prev_e) + log10f(next_e))/2.0); + (prev_e * next_e).dsp_sqrt() //looks better is math. identical and faster math +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: interp_energy2() + AUTHOR......: David Rowe, conversion by Raphael Peters + DATE CREATED: 22 May 2012 + + Interpolates centre 10ms sample of energy given two samples 20ms + + apart. + +\*---------------------------------------------------------------------------*/ +pub fn interp_energy2(prev_e: f32, next_e: f32, weight: f32) -> f32 { + 10f32.dsp_powf((1.0 - weight) * prev_e.dsp_log10() + weight * next_e.dsp_log10()) +} + +/*---------------------------------------------------------------------------*\ + + aks_to_M2() + + Transforms the linear prediction coefficients to spectral amplitude + samples. This function determines A(m) from the average energy per + band using an FFT. + +\*---------------------------------------------------------------------------*/ +pub fn aks_to_M2( + fftr_fwd_cfg: &mut codec2_fftr_cfg, + ak: &[f32], // LPC's + order: usize, + model: &mut MODEL, // sinusoidal model parameters for this frame + E: f32, // energy term + snr: &mut f32, // signal to noise ratio for this frame in dB + dump: i32, // true to dump sample to dump file + sim_pf: i32, // true to simulate a post filter + pf: i32, // true to enable actual LPC post filter + bass_boost: i32, // enable LPC filter 0-1kHz 3dB boost + beta: f32, + gamma: f32, // LPC post filter parameters + Aw: &mut [COMP], // output power spectrum +) { + //PROFILE_VAR(tstart, tfft, tpw, tpf); + // + //PROFILE_SAMPLE(tstart); + + let r = TWO_PI / FFT_ENC as f32; // no. rads/bin + + // Determine DFT of A(exp(jw)) -------------------------------------------- + { + let mut a = [0.0; FFT_ENC]; // input to FFT for power spectrum + + for i in 0..order + 1 { + a[i] = ak[i]; + } + codec2_fftr(fftr_fwd_cfg, &a, Aw); + } + // PROFILE_SAMPLE_AND_LOG(tfft, tstart, " fft"); + + // Determine power spectrum P(w) = E/(A(exp(jw))^2 ------------------------ + + let mut Pw = [0.0; FFT_ENC / 2]; + + //#ifndef FDV_ARM_MATH + for i in 0..FFT_ENC / 2 { + Pw[i] = 1.0 / (Aw[i].r * Aw[i].r + Aw[i].i * Aw[i].i + 1E-6); + } + /* #else + // this difference may seem strange, but the gcc for STM32F4 generates almost 5 times + // faster code with the two loops: 1120 ms -> 242 ms + // so please leave it as is or improve further + // since this code is called 4 times it results in almost 4ms gain (21ms -> 17ms per audio frame decode @ 1300 ) + + for i in 0..FFT_ENC/2 + { + Pw[i] = Aw[i].r * Aw[i].r + Aw[i].i * Aw[i].i + 1E-6; + } + for i in 0..FFT_ENC/2 { + Pw[i] = 1.0/(Pw[i]); + } + #endif // */ + + // PROFILE_SAMPLE_AND_LOG(tpw, tfft, " Pw"); + + if pf != 0 { + lpc_post_filter( + fftr_fwd_cfg, + &mut Pw, + ak, + order, + dump, + beta, + gamma, + bass_boost, + E, + ); + } else { + for i in 0..FFT_ENC / 2 { + Pw[i] *= E; + } + } + + // PROFILE_SAMPLE_AND_LOG(tpf, tpw, " LPC post filter"); + + // #ifdef DUMP + // if (dump) + // dump_Pw(Pw); + // #endif + + // Determine magnitudes from P(w) ---------------------------------------- + + // when used just by decoder {A} might be all zeroes so init signal + // and noise to prevent log(0) errors + + let mut signal = 1E-30; + let mut noise = 1E-32; + + for m in 1..model.L + 1 { + //limits of current band + let am = ((m as f32 - 0.5) * model.Wo / r + 0.5) as usize; + let mut bm = ((m as f32 + 0.5) * model.Wo / r + 0.5) as usize; + + // FIXME: With arm_rfft_fast_f32 we have to use this + // otherwise sometimes a to high bm is calculated + // which causes trouble later in the calculation + // chain + // it seems for some reason model.Wo is calculated somewhat too high + if bm > FFT_ENC / 2 { + bm = FFT_ENC / 2; + } + let mut Em = 0.0_f32; // energy in band + + for i in am..bm { + Em += Pw[i]; + } + let mut Am = Em.dsp_sqrt(); // spectral amplitude sample + + signal += model.A[m] * model.A[m]; + noise += (model.A[m] - Am) * (model.A[m] - Am); + + // This code significantly improves perf of LPC model, in + // particular when combined with phase0. The LPC spectrum tends + // to track just under the peaks of the spectral envelope, and + // just above nulls. This algorithm does the reverse to + // compensate - raising the amplitudes of spectral peaks, while + // attenuating the null. This enhances the formants, and + // supresses the energy between formants. + + if sim_pf != 0 { + if Am > model.A[m] { + Am *= 0.7; + } + if Am < model.A[m] { + Am *= 1.4; + } + } + model.A[m] = Am; + } + *snr = 10.0 * (signal / noise).dsp_log10(); + + // PROFILE_SAMPLE_AND_LOG2(tpf, " rec"); +} + +fn cconj(a: COMP) -> COMP { + COMP { + r: a.r, + i: 0.0 - a.i, + } +} + +/*---------------------------------------------------------------------------*\ + + sample_phase() + + Samples phase at centre of each harmonic from and array of FFT_ENC + DFT samples. + +\*---------------------------------------------------------------------------*/ +pub fn sample_phase( + model: &MODEL, + H: &mut [COMP], + A: &[COMP], // LPC analysis filter in freq domain +) { + let r = TWO_PI / (FFT_ENC as f32); + + // Sample phase at harmonics + + for m in 1..model.L + 1 { + let b = (m as f32 * model.Wo / r + 0.5) as usize; + H[m] = cconj(A[b]); // synth filter 1/A is opposite phase to analysis filter + } +} + +/*---------------------------------------------------------------------------*\ + + phase_synth_zero_order() + + Synthesises phases based on SNR and a rule based approach. No phase + parameters are required apart from the SNR (which can be reduced to a + 1 bit V/UV decision per frame). + + The phase of each harmonic is modelled as the phase of a synthesis + filter excited by an impulse. In many Codec 2 modes the synthesis + filter is a LPC filter. Unlike the first order model the position + of the impulse is not transmitted, so we create an excitation pulse + train using a rule based approach. + + Consider a pulse train with a pulse starting time n=0, with pulses + repeated at a rate of Wo, the fundamental frequency. A pulse train + in the time domain is equivalent to harmonics in the frequency + domain. We can make an excitation pulse train using a sum of + sinsusoids: + + for m in 1..L + ex[n] = cos(m*Wo*n) + + Note: the Octave script ../octave/phase.m is an example of this if + you would like to try making a pulse train. + + The phase of each excitation harmonic is: + + arg(E[m]) = mWo + + where E[m] are the complex excitation (freq domain) samples, + arg(x), just returns the phase of a complex sample x. + + As we don't transmit the pulse position for this model, we need to + synthesise it. Now the excitation pulses occur at a rate of Wo. + This means the phase of the first harmonic advances by N_SAMP samples + over a synthesis frame of N_SAMP samples. For example if Wo is pi/20 + (200 Hz), then over a 10ms frame (N_SAMP=80 samples), the phase of the + first harmonic would advance (pi/20)*80 = 4*pi or two complete + cycles. + + We generate the excitation phase of the fundamental (first + harmonic): + + arg[E[1]] = Wo*N_SAMP; + + We then relate the phase of the m-th excitation harmonic to the + phase of the fundamental as: + + arg(E[m]) = m*arg(E[1]) + + This E[m] then gets passed through the LPC synthesis filter to + determine the final harmonic phase. + + Comparing to speech synthesised using original phases: + + - Through headphones speech synthesised with this model is not as + good. Through a loudspeaker it is very close to original phases. + + - If there are voicing errors, the speech can sound clicky or + staticy. If V speech is mistakenly declared UV, this model tends to + synthesise impulses or clicks, as there is usually very little shift or + dispersion through the LPC synthesis filter. + + - When combined with LPC amplitude modelling there is an additional + drop in quality. I am not sure why, theory is interformant energy + is raised making any phase errors more obvious. + + NOTES: + + 1/ This synthesis model is effectively the same as a simple LPC-10 + vocoders, and yet sounds much better. Why? Conventional wisdom + (AMBE, MELP) says mixed voicing is required for high quality + speech. + + 2/ I am pretty sure the Lincoln Lab sinusoidal coding guys (like xMBE + also from MIT) first described this zero phase model, I need to look + up the paper. + + 3/ Note that this approach could cause some discontinuities in + the phase at the edge of synthesis frames, as no attempt is made + to make sure that the phase tracks are continuous (the excitation + phases are continuous, but not the final phases after filtering + by the LPC spectra). Technically this is a bad thing. However + this may actually be a good thing, disturbing the phase tracks a + bit. More research needed, e.g. test a synthesis model that adds + a small delta-W to make phase tracks line up for voiced + harmonics. + +\*---------------------------------------------------------------------------*/ +pub fn phase_synth_zero_order( + n_samp: usize, + model: &mut MODEL, + ex_phase: &mut f32, // excitation phase of fundamental + H: &[COMP], // L synthesis filter freq domain samples + random: &mut u32, +) { + let mut Ex = [COMP::new(); MAX_AMP + 1]; // excitation samples + let mut A_ = [COMP::new(); MAX_AMP + 1]; // synthesised harmonic samples + + /* + Update excitation fundamental phase track, this sets the position + of each pitch pulse during voiced speech. After much experiment + I found that using just this frame's Wo improved quality for UV + sounds compared to interpolating two frames Wo like this: + + *ex_phase += (*prev_Wo+model.Wo)*N_SAMP/2; + */ + + *ex_phase += (model.Wo) * n_samp as f32; + *ex_phase -= TWO_PI * (*ex_phase / TWO_PI + 0.5).dsp_floor(); + + for m in 1..model.L + 1 { + // generate excitation + + if model.voiced != 0 { + Ex[m].r = (*ex_phase * m as f32).dsp_cos(); + Ex[m].i = (*ex_phase * m as f32).dsp_sin(); + } else { + // When a few samples were tested I found that LPC filter + // phase is not needed in the unvoiced case, but no harm in + // keeping it. + + let phi = TWO_PI * codec2_rand(random) / CODEC2_RAND_MAX; + Ex[m].r = phi.dsp_cos(); + Ex[m].i = phi.dsp_sin(); + } + + // filter using LPC filter + + A_[m].r = H[m].r * Ex[m].r - H[m].i * Ex[m].i; + A_[m].i = H[m].i * Ex[m].r + H[m].r * Ex[m].i; + + // modify sinusoidal phase + + let new_phi = A_[m].i.dsp_atan2(A_[m].r + 1E-12); + model.phi[m] = new_phi; + } +} + +const CODEC2_RAND_MAX: f32 = 32767.0; + +// Decoder-local state prevents another stream or thread from changing phases. +fn codec2_rand(random: &mut u32) -> f32 { + *random = random.wrapping_mul(1103515245).wrapping_add(12345); + ((*random / 65536) % 32768) as f32 +} + +/*---------------------------------------------------------------------------*\ + + lpc_post_filter() + + Applies a post filter to the LPC synthesis filter power spectrum + Pw, which supresses the inter-formant energy. + + The algorithm is from p267 (Section 8.6) of "Digital Speech", + edited by A.M. Kondoz, 1994 published by Wiley and Sons. Chapter 8 + of this text is on the MBE vocoder, and this is a freq domain + adaptation of post filtering commonly used in CELP. + + I used the Octave simulation lpcpf.m to get an understanding of the + algorithm. + + Requires two more FFTs which is significantly more MIPs. However + it should be possible to implement this more efficiently in the + time domain. Just not sure how to handle relative time delays + between the synthesis stage and updating these coeffs. A smaller + FFT size might also be accetable to save CPU. + + TODO: + [ ] sync var names between Octave and C version + [ ] doc gain normalisation + [ ] I think the first FFT is not rqd as we do the same + thing in aks_to_M2(). + +\*---------------------------------------------------------------------------*/ +fn lpc_post_filter( + fftr_fwd_cfg: &mut codec2_fftr_cfg, + Pw: &mut [f32], + ak: &[f32], + order: usize, + _dump: i32, + beta: f32, + gamma: f32, + bass_boost: i32, + E: f32, +) { + let mut x = [0.0; FFT_ENC]; // input to FFTs + let mut Ww = [COMP::new(); FFT_ENC / 2 + 1]; // weighting spectrum + let mut Rw = [0.0; FFT_ENC / 2 + 1]; // R = WA + // PROFILE_VAR(tstart, tfft1, taw, tfft2, tww, tr); + // + // PROFILE_SAMPLE(tstart); + + // Determine weighting filter spectrum W(exp(jw)) --------------- + + x[0] = ak[0]; + let mut coeff = gamma; + for i in 1..order + 1 { + x[i] = ak[i] * coeff; + coeff *= gamma; + } + codec2_fftr(fftr_fwd_cfg, &x, &mut Ww); + + // PROFILE_SAMPLE_AND_LOG(tfft2, taw, " fft2"); + + for i in 0..FFT_ENC / 2 { + Ww[i].r = Ww[i].r * Ww[i].r + Ww[i].i * Ww[i].i; + } + + // PROFILE_SAMPLE_AND_LOG(tww, tfft2, " Ww"); + + // Determined combined filter R = WA --------------------------- + + let mut max_Rw = 0.0; + let mut min_Rw = 1E32; + for i in 0..FFT_ENC / 2 { + Rw[i] = (Ww[i].r * Pw[i]).dsp_sqrt(); + if Rw[i] > max_Rw { + max_Rw = Rw[i]; + } + if Rw[i] < min_Rw { + min_Rw = Rw[i]; + } + } + + // PROFILE_SAMPLE_AND_LOG(tr, tww, " R"); + + // #ifdef DUMP + // if (dump) + // dump_Rw(Rw); + // #endif + + // create post filter mag spectrum and apply ------------------ + + // measure energy before post filtering + + let mut e_before = 1E-4; + for i in 0..FFT_ENC / 2 { + e_before += Pw[i]; + } + // apply post filter and measure energy + + // #ifdef DUMP + // if (dump) + // dump_Pwb(Pw); + // #endif + + let mut e_after = 1E-4; + for i in 0..FFT_ENC / 2 { + let Pfw = Rw[i].dsp_powf(beta); + Pw[i] *= Pfw * Pfw; + e_after += Pw[i]; + } + let mut gain = e_before / e_after; + + // apply gain factor to normalise energy, and LPC Energy + + gain *= E; + for i in 0..FFT_ENC / 2 { + Pw[i] *= gain; + } + + if bass_boost != 0 { + // add 3dB to first 1 kHz to account for LP effect of PF + + for i in 0..FFT_ENC / 8 { + Pw[i] *= 1.4 * 1.4; + } + } + + // PROFILE_SAMPLE_AND_LOG2(tr, " filt"); +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: interp_Wo() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22 May 2012 + + Interpolates centre 10ms sample of Wo and L samples given two + samples 20ms apart. Assumes voicing is available for centre + (interpolated) frame. + +\*---------------------------------------------------------------------------*/ +#[must_use] +pub fn interp_Wo( + interp: &MODEL, // interpolated model params + prev: &MODEL, // previous frames model params + next: &MODEL, // next frames model params + Wo_min: f32, +) -> MODEL { + interp_Wo2(interp, prev, next, 0.5, Wo_min) +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: interp_Wo2() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22 May 2012 + + Weighted interpolation of two Wo samples. + +\*---------------------------------------------------------------------------*/ +#[must_use] +pub fn interp_Wo2( + interp: &MODEL, // interpolated model params + prev: &MODEL, // previous frames model params + next: &MODEL, // next frames model params + weight: f32, + Wo_min: f32, +) -> MODEL { + let mut interp = *interp; + // trap corner case where voicing est is probably wrong + + if interp.voiced != 0 && prev.voiced == 0 && next.voiced == 0 { + interp.voiced = 0; + } + + // Wo depends on voicing of this and adjacent frames + + if interp.voiced != 0 { + if prev.voiced != 0 && next.voiced != 0 { + interp.Wo = (1.0 - weight) * prev.Wo + weight * next.Wo; + } + if prev.voiced == 0 && next.voiced != 0 { + interp.Wo = next.Wo; + } + if prev.voiced != 0 && next.voiced == 0 { + interp.Wo = prev.Wo; + } + } else { + interp.Wo = Wo_min; + } + interp.L = (PI / interp.Wo) as usize; + interp +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: interpolate_lsp_ver2() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22 May 2012 + + Weighted interpolation of LSPs. + +\*---------------------------------------------------------------------------*/ +pub fn interpolate_lsp_ver2( + interp: &mut [f32], + prev: &[f32], + next: &[f32], + weight: f32, + order: usize, +) { + for i in 0..order { + interp[i] = (1.0 - weight) * prev[i] + weight * next[i]; + } +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: apply_lpc_correction() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 22/8/2010 + + Apply first harmonic LPC correction at decoder. This helps improve + low pitch males after LPC modelling, like hts1a and morig. + +\*---------------------------------------------------------------------------*/ +pub fn apply_lpc_correction(model: &mut MODEL) { + if model.Wo < (PI * 150.0 / 4000.0) { + model.A[1] *= 0.032; + } +} + +pub fn decode_lspds_scalar(lsp_: &mut [f32], indexes: &[usize], order: usize) { + let mut lsp__hz = Buffer::::filled(order, 0.0); + let mut dlsp_ = Buffer::::filled(order, 0.0); + + for i in 0..order { + let k = lsp_cbd[i].k; + dlsp_[i] = lsp_cbd[i].cb[indexes[i] * k]; + + if i != 0 { + lsp__hz[i] = lsp__hz[i - 1] + dlsp_[i]; + } else { + lsp__hz[0] = dlsp_[0]; + } + lsp_[i] = (PI / 4000.0) * lsp__hz[i]; + } +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: lsp_to_lpc() + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 24/2/93 + + This function converts LSP coefficients to LPC coefficients. In the + Speex code we worked out a way to simplify this significantly. + +\*---------------------------------------------------------------------------*/ +pub fn lsp_to_lpc( + lsp: &[f32], + ak: &mut [f32], // array of LPC coefficients + order: usize, // order of LPC coefficients +) { + let mut freq = Buffer::::filled(order, 0.0); // array of LSP frequencies in radians + let mut Wp = Buffer::::filled((order * 4) + 2, 0.0); + + // convert from radians to the x=cos(w) domain + for i in 0..order { + freq[i] = lsp[i].dsp_cos(); + } + + let pwoff = 0; //Wp; + let mut xin1 = 1.0; + let mut xin2 = 1.0; + + // reconstruct P(z) and Q(z) by cascading second order polynomials + // in form 1 - 2xz(-1) +z(-2), where x is the LSP coefficient + + for j in 0..order + 1 { + let mut n4off = 0; + for i in 0..(order / 2) { + let n1off = pwoff + (i * 4); + let n2off = n1off + 1; + let n3off = n2off + 1; + n4off = n3off + 1; + let xout1 = xin1 - 2.0 * (freq[2 * i]) * Wp[n1off] + Wp[n2off]; + let xout2 = xin2 - 2.0 * (freq[2 * i + 1]) * Wp[n3off] + Wp[n4off]; + Wp[n2off] = Wp[n1off]; + Wp[n4off] = Wp[n3off]; + Wp[n1off] = xin1; + Wp[n3off] = xin2; + xin1 = xout1; + xin2 = xout2; + } + let xout1 = xin1 + Wp[n4off + 1]; + let xout2 = xin2 - Wp[n4off + 2]; + ak[j] = (xout1 + xout2) * 0.5; + Wp[n4off + 1] = xin1; + Wp[n4off + 2] = xin2; + + xin1 = 0.0; + xin2 = 0.0; + } +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: synthesise + AUTHOR......: David Rowe, conversion by Matt Weeks + DATE CREATED: 20/2/95 + + Synthesise a speech signal in the frequency domain from the + sinusodal model parameters. Uses overlap-add with a trapezoidal + window to smoothly interpolate betwen frames. + +\*---------------------------------------------------------------------------*/ +pub fn synthesise( + n_samp: usize, + fftr_inv_cfg: &mut codec2_fftr_cfg, + Sn_: &mut [f32], // time domain synthesised signal + model: &MODEL, // ptr to model parameters for this frame + Pn: &[f32], // time domain Parzen window + shift: bool, // flag used to handle transition frames +) { + let mut Sw_ = [COMP::new(); FFT_DEC / 2 + 1]; // DFT of synthesised signal + let mut sw_ = [0.0; FFT_DEC]; // synthesised signal + + if shift { + // Update memories + for i in 0..n_samp - 1 { + Sn_[i] = Sn_[i + n_samp]; + } + Sn_[n_samp - 1] = 0.0; + } + + for i in 0..FFT_DEC / 2 + 1 { + Sw_[i].r = 0.0; + Sw_[i].i = 0.0; + } + + // Now set up frequency domain synthesised speech + for l in 1..model.L + 1 { + let mut b = (l as f32 * model.Wo * FFT_DEC as f32 / TWO_PI + 0.5) as usize; + if b > ((FFT_DEC / 2) - 1) { + b = (FFT_DEC / 2) - 1; + } + Sw_[b].r = model.A[l] * model.phi[l].dsp_cos(); + Sw_[b].i = model.A[l] * model.phi[l].dsp_sin(); + } + + // Perform inverse DFT + codec2_fftri(fftr_inv_cfg, &Sw_, &mut sw_); + + // Overlap add to previous samples + + // #ifdef USE_KISS_FFT + // #define FFTI_FACTOR ((float)1.0) + // #else + // #define FFTI_FACTOR ((float32_t)FFT_DEC) + // #endif + + for i in 0..n_samp - 1 { + Sn_[i] += sw_[FFT_DEC - n_samp + 1 + i] * Pn[i]; // * FFTI_FACTOR; + } + + if shift { + let mut j = 0; + for i in n_samp - 1..2 * n_samp { + Sn_[i] = sw_[j] * Pn[i]; // * FFTI_FACTOR; + j += 1; + } + } else { + let mut j = 0; + for i in n_samp - 1..2 * n_samp { + Sn_[i] += sw_[j] * Pn[i]; // * FFTI_FACTOR; + j += 1; + } + } +} + +const BG_THRESH: f32 = 40.0; // only consider low levels signals for bg_est +const BG_BETA: f32 = 0.1; // averaging filter constant +const BG_MARGIN: f32 = 6.0; // harmonics this far above BG noise are +// randomised. Helped make bg noise less +// spikey (impulsive) for mmt1, but speech was +// perhaps a little rougher. + +/*---------------------------------------------------------------------------*\ + + postfilter() + + The post filter is designed to help with speech corrupted by + background noise. The zero phase model tends to make speech with + background noise sound "clicky". With high levels of background + noise the low level inter-formant parts of the spectrum will contain + noise rather than speech harmonics, so modelling them as voiced + (i.e. a continuous, non-random phase track) is inaccurate. + + Some codecs (like MBE) have a mixed voicing model that breaks the + spectrum into voiced and unvoiced regions. Several bits/frame + (5-12) are required to transmit the frequency selective voicing + information. Mixed excitation also requires accurate voicing + estimation (parameter estimators always break occasionally under + exceptional conditions). + + In our case we use a post filter approach which requires no + additional bits to be transmitted. The decoder measures the average + level of the background noise during unvoiced frames. If a harmonic + is less than this level it is made unvoiced by randomising it's + phases. + + This idea is rather experimental. Some potential problems that may + happen: + + 1/ If someone says "aaaaaaaahhhhhhhhh" will background estimator track + up to speech level? This would be a bad thing. + + 2/ If background noise suddenly dissapears from the source speech does + estimate drop quickly? What is noise suddenly re-appears? + + 3/ Background noise with a non-flat sepctrum. Current algorithm just + comsiders scpetrum as a whole, but this could be broken up into + bands, each with their own estimator. + + 4/ Males and females with the same level of background noise. Check + performance the same. Changing Wo affects width of each band, may + affect bg energy estimates. + + 5/ Not sure what happens during long periods of voiced speech + e.g. "sshhhhhhh" + +\*---------------------------------------------------------------------------*/ +pub fn postfilter(model: &mut MODEL, bg_est: &mut f32, random: &mut u32) { + // determine average energy across spectrum + + let mut e = 1E-12; + for m in 1..model.L + 1 { + e += model.A[m] * model.A[m]; + } + // assert(e > 0.0); + e = 10.0 * (e / model.L as f32).dsp_log10(); + + // If beneath threhold, update bg estimate. The idea + // of the threshold is to prevent updating during high level + // speech. + + if e < BG_THRESH && model.voiced != 0 { + *bg_est = *bg_est * (1.0 - BG_BETA) + e * BG_BETA; + } + // now mess with phases during voiced frames to make any harmonics + // less then our background estimate unvoiced. + + // let mut uv = 0; + let thresh = 10.0_f32.dsp_powf((*bg_est + BG_MARGIN) / 20.0); + if model.voiced != 0 { + for m in 1..model.L + 1 { + if model.A[m] < thresh { + model.phi[m] = (TWO_PI / CODEC2_RAND_MAX) * codec2_rand(random); + //uv++; + } + } + } + //#ifdef DUMP + // dump_bg(e, *bg_est, 100.0*uv/model.L); + //#endif +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: bw_expand_lsps() + AUTHOR......: David Rowe + DATE CREATED: 22/8/2010 + + Applies Bandwidth Expansion (BW) to a vector of LSPs. Prevents any + two LSPs getting too close together after quantisation. We know + from experiment that LSP quantisation errors < 12.5Hz (25Hz step + size) are inaudible so we use that as the minimum LSP separation. + +\*---------------------------------------------------------------------------*/ + +pub fn bw_expand_lsps(lsp: &mut [f32], order: usize, min_sep_low: f32, min_sep_high: f32) { + for i in 1..4 { + if (lsp[i] - lsp[i - 1]) < min_sep_low * (PI / 4000.0) { + lsp[i] = lsp[i - 1] + min_sep_low * (PI / 4000.0); + } + } + + /* As quantiser gaps increased, larger BW expansion was required + to prevent twinkly noises. This may need more experiment for + different quanstisers. + */ + + for i in 4..order { + if lsp[i] - lsp[i - 1] < min_sep_high * (PI / 4000.0) { + lsp[i] = lsp[i - 1] + min_sep_high * (PI / 4000.0); + } + } +} + +pub fn check_lsp_order(lsp: &mut [f32], order: usize) -> i32 { + let mut swaps = 0; + + let mut i = 1; + while i < order { + if lsp[i] < lsp[i - 1] { + //fprintf(stderr, "swap %d\n",i); + swaps += 1; + let tmp = lsp[i - 1]; + lsp[i - 1] = lsp[i] - 0.1; + lsp[i] = tmp + 0.1; + i = 1; /* start check again, as swap may have caused out of order */ + } + i += 1; + } + swaps +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: decode_lsps_scalar() + AUTHOR......: David Rowe + DATE CREATED: 22/8/2010 + + From a vector of quantised LSP indexes, returns the quantised + (floating point) LSPs. + +\*---------------------------------------------------------------------------*/ + +pub fn decode_lsps_scalar(lsp: &mut [f32], indexes: &[usize], order: usize) { + let mut lsp_hz = Buffer::::filled(order, 0.0); + + for i in 0..order { + let k = lsp_cb[i].k; + lsp_hz[i] = lsp_cb[i].cb[indexes[i] * k]; + } + + /* convert back to radians */ + + for i in 0..order { + lsp[i] = (PI / 4000.0) * lsp_hz[i]; + } +} + +/*---------------------------------------------------------------------------*\ + FUNCTION....: encode_lsps_vq() + AUTHOR......: David Rowe + DATE CREATED: 15 Feb 2012 + Multi-stage VQ LSP quantiser developed by Jean-Marc Valin. +\*---------------------------------------------------------------------------*/ + +pub fn encode_lsps_vq(indexes: &mut [usize], x: &mut [f32], xq: &mut [f32], order: usize) { + let mut err = Buffer::::filled(order, 0.0); + let mut err2 = Buffer::::filled(order, 0.0); + let mut err3 = Buffer::::filled(order, 0.0); + let mut w = Buffer::::filled(order, 0.0); + let mut w2 = Buffer::::filled(order, 0.0); + let mut w3 = Buffer::::filled(order, 0.0); + let codebook1 = lsp_cbjvm[0].cb; + let codebook2 = lsp_cbjvm[1].cb; + let codebook3 = lsp_cbjvm[2].cb; + + w[0] = f32::min(x[0], x[1] - x[0]); + for i in 1..order - 1 { + w[i] = f32::min(x[i] - x[i - 1], x[i + 1] - x[i]); + } + w[order - 1] = f32::min(x[order - 1] - x[order - 2], PI - x[order - 1]); + + compute_weights(x, &mut w, order); + + let n1 = find_nearest(codebook1, lsp_cbjvm[0].m, x, order); + + for i in 0..order { + xq[i] = codebook1[order * n1 + i]; + err[i] = x[i] - xq[i]; + } + for i in 0..order / 2 { + err2[i] = err[2 * i]; + err3[i] = err[2 * i + 1]; + w2[i] = w[2 * i]; + w3[i] = w[2 * i + 1]; + } + let n2 = find_nearest_weighted(codebook2, lsp_cbjvm[1].m, &mut err2, &w2, order / 2); + let n3 = find_nearest_weighted(codebook3, lsp_cbjvm[2].m, &mut err3, &w3, order / 2); + + indexes[0] = n1; + indexes[1] = n2; + indexes[2] = n3; +} + +/*---------------------------------------------------------------------------*\ + FUNCTION....: decode_lsps_vq() + AUTHOR......: David Rowe + DATE CREATED: 15 Feb 2012 +\*---------------------------------------------------------------------------*/ +pub fn decode_lsps_vq(indexes: &[usize], xq: &mut [f32], order: usize, stages: usize) { + let codebook1: &[f32] = lsp_cbjvm[0].cb; + let codebook2: &[f32] = lsp_cbjvm[1].cb; + let codebook3: &[f32] = lsp_cbjvm[2].cb; + + let n1 = indexes[0]; + let n2 = indexes[1]; + let n3 = indexes[2]; + + for i in 0..order { + xq[i] = codebook1[order * n1 + i]; + } + + if stages != 1 { + for i in 0..order / 2 { + xq[2 * i] += codebook2[order * n2 / 2 + i]; + xq[2 * i + 1] += codebook3[order * n3 / 2 + i]; + } + } +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: decode_WoE() + AUTHOR......: Jean-Marc Valin & David Rowe + DATE CREATED: 11 May 2012 + + Joint Wo and LPC energy vector quantiser developed my Jean-Marc + Valin. Given index and states xq[], returns Wo & E, and updates + states xq[]. + +\*---------------------------------------------------------------------------*/ +pub fn decode_WoE(c2const: &C2const, model: &mut MODEL, e: &mut f32, xq: &mut [f32], n1: usize) { + let ge_coeff = [0.8, 0.9]; + let ndim = ge_cb[0].k; + let Wo_min = c2const.Wo_min; + let Wo_max = c2const.Wo_max; + + for i in 0..ndim { + xq[i] = ge_coeff[i] * xq[i] + ge_cb[0].cb[ndim * n1 + i]; + } + + //printf("dec: %f %f\n", xq[0], xq[1]); + model.Wo = 2.0_f32.dsp_powf(xq[0]) * (PI * 50.0) / 4000.0; + + /* bit errors can make us go out of range leading to all sorts of + probs like seg faults */ + + if model.Wo > Wo_max { + model.Wo = Wo_max + }; + if model.Wo < Wo_min { + model.Wo = Wo_min + }; + + model.L = (PI / model.Wo) as usize; // if we quantise Wo re-compute L + + *e = 10.0_f32.dsp_powf(xq[1] / 10.0); +} diff --git a/crates/lxst-codec2/tests/contract.rs b/crates/lxst-codec2/tests/contract.rs new file mode 100644 index 0000000..dd75fcd --- /dev/null +++ b/crates/lxst-codec2/tests/contract.rs @@ -0,0 +1,124 @@ +use lxst_codec2::{Codec, Error, Mode}; +use std::alloc::{GlobalAlloc, Layout, System}; +use std::sync::atomic::{AtomicUsize, Ordering::Relaxed}; + +struct Meter; +static ALLOCATIONS: AtomicUsize = AtomicUsize::new(0); +unsafe impl GlobalAlloc for Meter { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + ALLOCATIONS.fetch_add(1, Relaxed); + unsafe { System.alloc(layout) } + } + unsafe fn dealloc(&self, pointer: *mut u8, layout: Layout) { + unsafe { System.dealloc(pointer, layout) } + } +} +#[global_allocator] +static ALLOCATOR: Meter = Meter; + +// One process/thread: unrelated parallel test allocations cannot contaminate +// the count. Large states are allocated before measurement and initialised in place. +fn main() { + for mode in [Mode::Rate1600, Mode::Rate3200] { + let mut duplex_storage = Box::::new_uninit(); + let mut encoder_storage = Box::::new_uninit(); + let mut decoder_storage = Box::::new_uninit(); + let before = ALLOCATIONS.load(Relaxed); + let duplex = Codec::initialise(&mut duplex_storage, mode); + let encoder = Codec::initialise(&mut encoder_storage, mode); + let decoder = Codec::initialise(&mut decoder_storage, mode); + let samples = mode.samples(); + let mut input = [0_i16; 320]; + let mut expected = [0_i16; 320]; + let mut actual = [0_i16; 320]; + let mut encoded = [0_u8; 8]; + let mut same = [0_u8; 8]; + let mut rng = 71_u32; + for frame in 0..1000 { + for sample in &mut input[..samples] { + rng = rng.wrapping_mul(1664525).wrapping_add(1013904223); + *sample = match frame % 5 { + 0 => 0, + 1 => (rng >> 16) as i16, + 2 => { + if rng & 1 == 0 { + i16::MIN + } else { + i16::MAX + } + } + _ => ((rng >> 16) as i16) / 4, + }; + } + // Rejected input cannot alter state or caller outputs. + same.fill(0xA5); + assert_eq!( + duplex.encode(&input[..samples - 1], &mut same), + Err(Error::PcmLength) + ); + assert_eq!(same, [0xA5; 8]); + assert_eq!( + duplex.encode(&input[..samples], &mut same[..7]), + Err(Error::EncodedLength) + ); + actual.fill(123); + assert_eq!( + duplex.decode(&encoded[..7], &mut actual[..samples]), + Err(Error::EncodedLength) + ); + assert_eq!( + duplex.decode(&encoded, &mut actual[..samples - 1]), + Err(Error::PcmLength) + ); + assert!(actual.iter().all(|v| *v == 123)); + encoder.encode(&input[..samples], &mut encoded).unwrap(); + duplex.encode(&input[..samples], &mut same).unwrap(); + assert_eq!(encoded, same, "receive activity changed encoder history"); + decoder.decode(&encoded, &mut expected[..samples]).unwrap(); + duplex.decode(&encoded, &mut actual[..samples]).unwrap(); + assert_eq!( + expected[..samples], + actual[..samples], + "another decoder changed random/history state" + ); + if frame % 127 == 0 { + duplex.reset(mode); + encoder.reset(mode); + decoder.reset(mode); + } + } + // Every 64-bit payload is valid codec data. Exercise decoder indices on + // hostile but correctly-sized frames, including both extrema. + for frame in 0..10000 { + for byte in &mut encoded { + rng = rng.wrapping_mul(1664525).wrapping_add(1013904223); + *byte = match frame % 10 { + 0 => 0, + 1 => 255, + _ => (rng >> 24) as u8, + }; + } + duplex.decode(&encoded, &mut actual[..samples]).unwrap(); + } + assert_eq!( + ALLOCATIONS.load(Relaxed), + before, + "initialisation/reset/stream allocated" + ); + let other = match mode { + Mode::Rate1600 => Mode::Rate3200, + Mode::Rate3200 => Mode::Rate1600, + }; + duplex.reset(other); + assert_eq!(duplex.mode(), other); + assert_eq!(ALLOCATIONS.load(Relaxed), before); + println!( + "{mode:?}: allocation-free construction/reset; isolated duplex histories; 1000 stream pairs; 10000 arbitrary decoder frames PASS" + ); + } + println!( + "codec fixed storage: {} bytes, alignment {}", + size_of::(), + align_of::() + ); +} diff --git a/tools/check-api-compatibility.py b/tools/check-api-compatibility.py index fc89e87..932e122 100644 --- a/tools/check-api-compatibility.py +++ b/tools/check-api-compatibility.py @@ -59,14 +59,19 @@ def main() -> None: floor_snapshots = { package["name"]: package["snapshot"] for package in floor_ledger["packages"] } + current_names = {package["name"] for package in ledger["packages"]} + removed_packages = set(floor_snapshots) - current_names + if removed_packages: + fail(f"compatibility-floor packages removed: {sorted(removed_packages)}") + new_packages = sorted(current_names - set(floor_snapshots)) + if ledger["snapshotSource"]["review"].get("newPackages", []) != new_packages: + fail("new packages require an exact explicit snapshot review") total_added = 0 total_removed = 0 for package in ledger["packages"]: path = package["snapshot"] floor_path = floor_snapshots.get(package["name"]) - if not isinstance(floor_path, str): - fail(f"{package['name']} is absent from the compatibility floor") - before = set(git_show(floor, floor_path).splitlines()) + before = set(git_show(floor, floor_path).splitlines()) if floor_path else set() after = set((ROOT / path).read_text(encoding="utf-8").splitlines()) added = sorted(after - before) removed = sorted(before - after) diff --git a/tools/check-source-release.py b/tools/check-source-release.py index 6c259b6..0ad74e7 100644 --- a/tools/check-source-release.py +++ b/tools/check-source-release.py @@ -11,7 +11,7 @@ import sys ROOT = Path(__file__).resolve().parents[1] -EXPECTED_PACKAGES = {"lxst-core", "lxst-rns", "lxst-telephony"} +EXPECTED_PACKAGES = {"lxst-core", "lxst-codec2", "lxst-rns", "lxst-telephony"} EXPECTED_MSRV = "1.87" EXPECTED_RETICULUM_VERSION = "1.3.0" EXPECTED_RETICULUM_COMMIT = "d4183434fcb969799c208ddcf140bae7550c14fe" diff --git a/tools/check-third-party-licenses.py b/tools/check-third-party-licenses.py index b51cfab..3d1b655 100755 --- a/tools/check-third-party-licenses.py +++ b/tools/check-third-party-licenses.py @@ -129,12 +129,28 @@ def build_inventory() -> dict: if copying_hash != UPSTREAM_OPUS_COPYING_SHA256: fail(f"preserved opus-rs COPYING changed (found {copying_hash})") + adapted = ROOT / "crates/lxst-codec2" + provenance = json.loads((adapted / "UPSTREAM.json").read_text()) + if (provenance["version"], provenance["commit"], provenance["crate_sha256"]) != ( + "0.3.1", "24ec3b7c5b9892c268e180802ee3a5ce7737f214", + "3c3c8ba70382a99c0b5ebadf6ad50e7d98fb6eb9bcc4c0e30d422f6321798d99", + ): + fail("adapted Codec2 immutable upstream provenance changed") + entries.append({ + "name": "codec2 (adapted as lxst-codec2)", "version": provenance["version"], + "license": "LGPL-2.1-only AND MIT AND BSD-3-Clause", + "repository": provenance["repository"], "source": "local-adaptation", + "upstreamCommit": provenance["commit"], "crateChecksum": provenance["crate_sha256"], + "provenance": "crates/lxst-codec2/UPSTREAM.json", + "notices": {str(p.relative_to(ROOT)): hashlib.sha256(p.read_bytes()).hexdigest() + for p in [adapted / "NOTICE", *sorted((adapted / "licenses").iterdir())]}, + }) entries.sort(key=lambda entry: (entry["name"], entry["version"], entry["source"])) lockfile_hash = hashlib.sha256((ROOT / "Cargo.lock").read_bytes()).hexdigest() return { "schemaVersion": 1, "scope": ( - "All registry third-party normal/build dependencies " + "Adapted Codec2 and all registry third-party normal/build dependencies " "reachable from rsLXST workspace members across declared targets; " "dev-only and first-party path packages are excluded." ),