diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index b96f5ca..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "xombe"] - path = xombe - url = https://github.com/x0rro/xombe diff --git a/xombe b/xombe deleted file mode 160000 index 2f0a8e7..0000000 --- a/xombe +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2f0a8e744645b51c1749a39c8a4ee581fef1f20a diff --git a/xombe/.github/workflows/ci.yml b/xombe/.github/workflows/ci.yml new file mode 100644 index 0000000..43484b4 --- /dev/null +++ b/xombe/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: CI + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + linux: + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + cc: [gcc, clang] + env: + CC: ${{ matrix.cc }} + steps: + - uses: actions/checkout@v4 + - run: make check WERROR=ON + + macos: + strategy: + fail-fast: false + matrix: + runner: [macos-15, macos-15-intel] + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v4 + - run: make check + + mingw: + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + shared: ['OFF', 'ON'] + steps: + - uses: actions/checkout@v4 + - run: sudo apt-get update && sudo apt-get install -y --no-install-recommends gcc-mingw-w64-x86-64 + - run: >- + cmake -S . -B build -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc + -DBUILD_SHARED_LIBS=${{ matrix.shared }} -DXOMBE_WERROR=ON + - run: cmake --build build -j4 diff --git a/xombe/.github/workflows/release.yml b/xombe/.github/workflows/release.yml new file mode 100644 index 0000000..254d41f --- /dev/null +++ b/xombe/.github/workflows/release.yml @@ -0,0 +1,67 @@ +name: Release + +on: + push: + tags: ['v*'] + +permissions: + contents: read + +jobs: + source: + runs-on: ubuntu-24.04 + container: docker.io/library/debian@sha256:2dc419c6d7fe3dad0a2f9fd469c34cc90b0f9ba642d8fde837fe3d7d34a0e7f1 + steps: + - name: checkout without git, for the locked packages + uses: actions/checkout@v4 + - run: sh scripts/release_deps.sh + - run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + - name: checkout with git + uses: actions/checkout@v4 + - name: tag matches version + run: | + ver=$(for p in MAJOR MINOR PATCH; do + sed -n "s/^#define XOMBE_VERSION_$p \([0-9][0-9]*\)\$/\1/p" include/xombe.h + done | paste -sd. -) + test "${GITHUB_REF_NAME#v}" = "$ver" + - run: scripts/release_tarball.sh HEAD dist + - uses: actions/upload-artifact@v4 + with: + name: source + path: | + dist/*.tar.xz + dist/*.buildinfo + if-no-files-found: error + + release: + needs: source + runs-on: ubuntu-24.04 + permissions: + contents: write + id-token: write + attestations: write + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: source + path: out + - run: cd out && sha256sum -- xombe-* | LC_ALL=C sort -k2 > SHA256SUMS + - name: sums match the tag + run: | + git fetch -q --depth=1 origin "+$GITHUB_REF:$GITHUB_REF" + git for-each-ref --format='%(contents)' "$GITHUB_REF" | grep -E '^[0-9a-f]{64} xombe-' > tag-sums + diff tag-sums out/SHA256SUMS + - uses: actions/attest-build-provenance@v2 + with: + subject-path: | + out/*.tar.xz + out/*.buildinfo + - name: draft release + env: + GH_TOKEN: ${{ github.token }} + run: | + ver=${GITHUB_REF_NAME#v} + awk -v h="## $ver" '$0 == h { on = 1; next } on && /^## / { exit } on' CHANGELOG.md > notes.md + gh release create "$GITHUB_REF_NAME" --draft --verify-tag \ + --title "xombe $ver" --notes-file notes.md out/xombe-* out/SHA256SUMS diff --git a/xombe/.gitignore b/xombe/.gitignore new file mode 100644 index 0000000..56c0f32 --- /dev/null +++ b/xombe/.gitignore @@ -0,0 +1,6 @@ +/build/ +/build-*/ +/out/ +__pycache__/ +*.pyc +/dist/ diff --git a/xombe/CHANGELOG.md b/xombe/CHANGELOG.md new file mode 100644 index 0000000..69c2ed8 --- /dev/null +++ b/xombe/CHANGELOG.md @@ -0,0 +1,13 @@ +# changelog + +## 0.1.0 + +first release + +- decoder for AMBE 2400 (D-STAR) and AMBE+2 half-rate (DMR) +- encoder for D-STAR and DMR +- single encoder produces both outputs +- one API for both codecs, picked by `enum xombe_codec` +- transcoding between codecs in parameter space (without converting to PCM) +- q15 kernel for Cortex-M33 with DSP extension (RP2350) +- conformance and test suites diff --git a/xombe/CMakeLists.txt b/xombe/CMakeLists.txt new file mode 100644 index 0000000..9048a4d --- /dev/null +++ b/xombe/CMakeLists.txt @@ -0,0 +1,282 @@ +cmake_minimum_required(VERSION 3.13) + +# The version lives in xombe.h; CMake reads it from there. +file(STRINGS include/xombe.h XOMBE_VERSION_LINES REGEX "^#define XOMBE_VERSION_(MAJOR|MINOR|PATCH) ") +foreach(part MAJOR MINOR PATCH) + string(REGEX REPLACE ".*#define XOMBE_VERSION_${part} ([0-9]+).*" "\\1" XOMBE_VERSION_${part} + "${XOMBE_VERSION_LINES}") +endforeach() +project(xombe VERSION ${XOMBE_VERSION_MAJOR}.${XOMBE_VERSION_MINOR}.${XOMBE_VERSION_PATCH} LANGUAGES C) +include(GNUInstallDirs) + +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) + +option(XOMBE_ENCODER "Build the encoder" ON) +option(XOMBE_DSTAR "Build the D-STAR (AMBE 2400) codec: decoder, FEC, encoder output and the transcoders" ON) +option(XOMBE_SANITIZE "Build with address and undefined-behaviour sanitizers" OFF) +option(XOMBE_WERROR "Treat warnings as errors" OFF) +# Built into a parent project (add_subdirectory, FetchContent), xombe is the library alone by default. +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(XOMBE_TOP_LEVEL ON) +else() + set(XOMBE_TOP_LEVEL OFF) +endif() +# the tools and tests are POSIX-only test tools (fork, sh), only the library is portable +if(XOMBE_TOP_LEVEL AND NOT WIN32) + set(XOMBE_POSIX_DEFAULT ON) +else() + set(XOMBE_POSIX_DEFAULT OFF) +endif() +option(XOMBE_BUILD_TOOLS "Build the xombe-enc, xombe-dec and xombe-xc tools (POSIX only)" ${XOMBE_POSIX_DEFAULT}) +option(XOMBE_BUILD_TESTS "Build the tests (POSIX only)" ${XOMBE_POSIX_DEFAULT}) +if(WIN32 AND (XOMBE_BUILD_TOOLS OR XOMBE_BUILD_TESTS)) + message(WARNING "xombe: the tools and tests are POSIX-only, unsupported on Windows") +endif() +option(XOMBE_INSTALL "Generate the install rules" ${XOMBE_TOP_LEVEL}) +set(XOMBE_KERNELS float CACHE STRING "Codec kernel backend: float, or q15 (fixed point with the Arm DSP extension)") +set_property(CACHE XOMBE_KERNELS PROPERTY STRINGS float q15) +if(NOT XOMBE_KERNELS MATCHES "^(float|q15)$") + message(FATAL_ERROR "XOMBE_KERNELS must be float or q15, not ${XOMBE_KERNELS}") +endif() + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +# Warning and sanitizer flags apply to xombe's own targets only, so a project that adds xombe with +# add_subdirectory() keeps its own flags. +function(xombe_target_options target) + if(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") + # no a*b+c -> FMA contraction (clang's default), so output is bit-identical with and without FMA hardware + target_compile_options(${target} PRIVATE -Wall -Wextra -ffp-contract=off) + if(XOMBE_WERROR) + target_compile_options(${target} PRIVATE -Werror) + endif() + elseif(MSVC) + target_compile_options(${target} PRIVATE /W4) + if(XOMBE_WERROR) + target_compile_options(${target} PRIVATE /WX) + endif() + endif() + if(XOMBE_SANITIZE) + target_compile_options(${target} PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer + -fno-sanitize-recover=all) + target_link_options(${target} PRIVATE -fsanitize=address,undefined) + endif() +endfunction() + +set(XOMBE_HAVE_ENCODER ${XOMBE_ENCODER}) +set(XOMBE_HAVE_DSTAR ${XOMBE_DSTAR}) +if(XOMBE_KERNELS STREQUAL q15) + set(XOMBE_KERNELS_Q15 1) +else() + set(XOMBE_KERNELS_Q15 0) +endif() +configure_file(src/xombe_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/xombe_config.h) + +set(XOMBE_COMMON + src/common/bits.c src/common/params.c src/common/tone_table.c src/common/version.c src/common/voicing.c + src/dsp/fft.c src/dsp/window.c src/dsp/biquad.c src/dsp/lcg.c + src/tables/tables.c src/tables/dsp_tables.c src/tables/cq_q15_tables.c) +set(XOMBE_DEC + src/dec/decoder.c src/dec/smooth.c src/dec/enhance.c src/dec/synth_voiced.c + src/dec/synth_unvoiced.c src/dec/synth_tone.c src/dec/conceal.c src/dec/dkern_${XOMBE_KERNELS}.c) +set(XOMBE_KERN_float src/enc/kern_float.c) +set(XOMBE_KERN_q15 src/enc/kern_q15_spec.c src/enc/kern_q15_lf.c src/enc/kern_q15_pitch.c) +set(XOMBE_ENC + src/enc/encoder.c src/enc/analysis.c src/enc/pitch.c src/enc/voicing_metric.c ${XOMBE_KERN_${XOMBE_KERNELS}} + src/enc/vad.c src/enc/ns.c src/enc/comfort.c src/enc/tone_detect.c src/enc/quant.c src/enc/frontend.c + src/enc/ambe2_enc.c) +set(XOMBE_FECSRC src/fec/golay.c src/fec/pn.c src/fec/interleave.c src/fec/stats.c) +set(XOMBE_DSTARSRC src/dstar/fec.c src/dstar/params.c src/dstar/decoder.c src/common/cquant.c + src/tables/dstar_tables.c) + +set(XOMBE_SOURCES ${XOMBE_COMMON} ${XOMBE_DEC} ${XOMBE_FECSRC}) +if(XOMBE_ENCODER) + list(APPEND XOMBE_SOURCES ${XOMBE_ENC}) + if(NOT XOMBE_DSTAR) + list(APPEND XOMBE_SOURCES src/common/cquant.c) # AMBE+2 closed-loop quantizer, in XOMBE_DSTARSRC otherwise + endif() +endif() +if(XOMBE_DSTAR) + list(APPEND XOMBE_SOURCES ${XOMBE_DSTARSRC}) + if(XOMBE_ENCODER) + list(APPEND XOMBE_SOURCES src/dstar/dstar_enc.c src/dstar/dstar_tone.c src/tables/dstar_enc_tables.c) + endif() + list(APPEND XOMBE_SOURCES src/dstar/xc.c src/dstar/xcode.c) + if(XOMBE_ENCODER) + list(APPEND XOMBE_SOURCES src/dstar/xrev.c) + endif() +endif() + +# static or shared by BUILD_SHARED_LIBS (static when unset) +add_library(xombe ${XOMBE_SOURCES}) +add_library(xombe::xombe ALIAS xombe) +function(xombe_library_options target) + target_include_directories(${target} + PUBLIC $ + $ + $ + PRIVATE src) + # MSVC's C runtime has the math functions, and there is no libm + if(NOT MSVC) + target_link_libraries(${target} PUBLIC m) + endif() + xombe_target_options(${target}) +endfunction() +xombe_library_options(xombe) +# symbols are hidden but the XOMBE_API functions (xombe_config.h). the ABI can change with each minor version +# while the major is 0, so the soname carries the minor version too +if(PROJECT_VERSION_MAJOR EQUAL 0) + set(XOMBE_SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) +else() + set(XOMBE_SOVERSION ${PROJECT_VERSION_MAJOR}) +endif() +set_target_properties(xombe PROPERTIES C_VISIBILITY_PRESET hidden VERSION ${PROJECT_VERSION} + SOVERSION ${XOMBE_SOVERSION}) +get_target_property(XOMBE_TYPE xombe TYPE) +if(XOMBE_TYPE STREQUAL SHARED_LIBRARY) + # XOMBE_API's dllimport on Windows (xombe_config.h) + target_compile_definitions(xombe INTERFACE XOMBE_SHARED) + set(XOMBE_PC_CFLAGS " -DXOMBE_SHARED") +endif() +# libm: a shared libxombe brings its own, a static one needs it on every link line, not only with --static +if(NOT MSVC) + if(XOMBE_TYPE STREQUAL SHARED_LIBRARY) + set(XOMBE_PC_LIBS_PRIVATE -lm) + else() + set(XOMBE_PC_LIBS " -lm") + endif() +endif() + +function(xombe_executable name) + add_executable(${name} ${ARGN}) + target_link_libraries(${name} xombe) + xombe_target_options(${name}) +endfunction() + +if(XOMBE_BUILD_TOOLS) + xombe_executable(xombe-dec tools/xombe-dec.c tools/io.c) + if(XOMBE_ENCODER) + xombe_executable(xombe-enc tools/xombe-enc.c tools/io.c) + endif() + if(XOMBE_DSTAR) + xombe_executable(xombe-xc tools/xombe-xc.c tools/io.c) + endif() +endif() + +if(XOMBE_INSTALL) + install(TARGETS xombe EXPORT xombeTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(FILES include/xombe.h ${CMAKE_CURRENT_BINARY_DIR}/include/xombe_config.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + install(EXPORT xombeTargets NAMESPACE xombe:: FILE xombeConfig.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/xombe) + include(CMakePackageConfigHelpers) + write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/xombeConfigVersion.cmake + COMPATIBILITY SameMinorVersion) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xombeConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/xombe) + # xombe.pc finds the prefix from its own directory, so it holds under cmake --install --prefix. an absolute + # CMAKE_INSTALL_LIBDIR or INCLUDEDIR stays absolute + if(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR}) + set(XOMBE_PC_PREFIX ${CMAKE_INSTALL_PREFIX}) + else() + file(RELATIVE_PATH XOMBE_PC_PREFIX ${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig ${CMAKE_INSTALL_PREFIX}) + string(REGEX REPLACE "/$" "" XOMBE_PC_PREFIX "\${pcfiledir}/${XOMBE_PC_PREFIX}") + endif() + foreach(d LIBDIR INCLUDEDIR) + if(IS_ABSOLUTE ${CMAKE_INSTALL_${d}}) + set(XOMBE_PC_${d} ${CMAKE_INSTALL_${d}}) + else() + set(XOMBE_PC_${d} "\${prefix}/${CMAKE_INSTALL_${d}}") + endif() + endforeach() + configure_file(xombe.pc.in ${CMAKE_CURRENT_BINARY_DIR}/xombe.pc @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xombe.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + if(XOMBE_BUILD_TOOLS) + install(TARGETS xombe-dec RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + if(XOMBE_ENCODER) + install(TARGETS xombe-enc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + if(XOMBE_DSTAR) + install(TARGETS xombe-xc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + endif() +endif() + +if(NOT XOMBE_BUILD_TESTS) + return() +endif() +enable_testing() +set(VEC ${CMAKE_CURRENT_SOURCE_DIR}/vectors) +# tests of the internals (xombe__*, src/) link a static build, the shared one exports only the API +if(XOMBE_TYPE STREQUAL SHARED_LIBRARY) + add_library(xombe_static_for_tests STATIC ${XOMBE_SOURCES}) + xombe_library_options(xombe_static_for_tests) +else() + add_library(xombe_static_for_tests ALIAS xombe) +endif() +function(xombe_internal_executable name) + add_executable(${name} ${ARGN}) + target_link_libraries(${name} xombe_static_for_tests) + target_include_directories(${name} PRIVATE src) + xombe_target_options(${name}) +endfunction() +xombe_executable(test_api test/test_api.c) +add_test(NAME api COMMAND test_api) +xombe_executable(sizes test/sizes.c) +add_test(NAME sizes COMMAND sizes) +xombe_internal_executable(test_fec test/test_fec.c) +add_test(NAME t1_fec COMMAND test_fec ${VEC}/fec) +xombe_executable(test_stream test/test_stream.c tools/io.c) +add_test(NAME t4a_decisions COMMAND test_stream + ${VEC}/stream/mixed_stream_0.jsonl.gz ${VEC}/stream/mixed_stream_1.jsonl.gz + ${VEC}/stream/mixed_stream_2.jsonl.gz ${VEC}/stream/mixed_stream_3.jsonl.gz) +xombe_internal_executable(test_tones test/test_tones.c) +add_test(NAME t5_tones COMMAND test_tones ${VEC}/tones) +xombe_internal_executable(test_tables test/test_tables.c) +add_test(NAME tables COMMAND test_tables) +xombe_internal_executable(test_q15ops test/test_q15ops.c) +add_test(NAME q15ops COMMAND test_q15ops) +# The same test of the intrinsics, when an Arm cross compiler and qemu-arm are at hand. +find_program(XOMBE_ARM_CC arm-none-eabi-gcc) +find_program(XOMBE_QEMU_ARM qemu-arm) +if(XOMBE_ARM_CC AND XOMBE_QEMU_ARM) + add_test(NAME q15ops_arm COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/test/q15ops_arm.sh ${XOMBE_ARM_CC} + ${XOMBE_QEMU_ARM} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +endif() +# Stage dumps for test/trace_cmp.py; not a test itself. +xombe_internal_executable(trace_dump test/trace_dump.c tools/io.c) +if(XOMBE_ENCODER) + xombe_internal_executable(test_mirror test/test_mirror.c) + add_test(NAME e1_e2_encoder COMMAND test_mirror ${VEC}) + xombe_internal_executable(test_enc_tone test/test_enc_tone.c) + add_test(NAME enc_tone COMMAND test_enc_tone ${VEC}) + xombe_internal_executable(tone_cmp test/tone_cmp.c) + add_test(NAME tone_cmp COMMAND tone_cmp ${VEC}) +endif() +# kernel backends against float (test/test_kern_*.c), one file per q15 track +set(XOMBE_KERN_TESTS dec) +if(XOMBE_ENCODER) + list(APPEND XOMBE_KERN_TESTS spec tone) +endif() +if(XOMBE_DSTAR) + list(APPEND XOMBE_KERN_TESTS cq) +endif() +foreach(t ${XOMBE_KERN_TESTS}) + xombe_internal_executable(test_kern_${t} test/test_kern_${t}.c) + add_test(NAME kern_${t} COMMAND test_kern_${t} ${VEC}) +endforeach() +if(XOMBE_BUILD_TOOLS) + add_test(NAME tools COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/test/tools.sh ${CMAKE_CURRENT_BINARY_DIR} ${VEC}) +endif() +include(test/dstar.cmake) +get_property(skipped GLOBAL PROPERTY XOMBE_SKIPPED_TESTS) +if(skipped) + list(LENGTH skipped n) + string(REPLACE ";" " " skipped "${skipped}") + message(WARNING "xombe: no Python 3, ${n} D-STAR comparison tests skipped: ${skipped}") +endif() diff --git a/xombe/LICENSE b/xombe/LICENSE new file mode 100644 index 0000000..592d658 --- /dev/null +++ b/xombe/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 x0rro + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/xombe/Makefile b/xombe/Makefile new file mode 100644 index 0000000..7a4fec5 --- /dev/null +++ b/xombe/Makefile @@ -0,0 +1,39 @@ +BUILD ?= build +SAN_BUILD ?= build-asan +Q15_BUILD ?= build-q15 +CMAKE ?= cmake +PYTHON ?= python3 +CMAKE_FLAGS ?= +# WERROR=ON turns warnings into errors in every build +WERROR ?= OFF +JOBS ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4) + +.PHONY: all check check-q15 conformance conformance-dstar clean + +all: + $(CMAKE) -S . -B $(BUILD) -DCMAKE_BUILD_TYPE=Release -DXOMBE_WERROR=$(WERROR) $(CMAKE_FLAGS) + $(CMAKE) --build $(BUILD) -j$(JOBS) + +# release, q15 (check-q15), and ASan/UBSan builds +check: all check-q15 + cd $(BUILD) && ctest --output-on-failure -j$(JOBS) + $(CMAKE) -S . -B $(SAN_BUILD) -DCMAKE_BUILD_TYPE=Debug -DXOMBE_SANITIZE=ON -DXOMBE_WERROR=$(WERROR) $(CMAKE_FLAGS) + $(CMAKE) --build $(SAN_BUILD) -j$(JOBS) + cd $(SAN_BUILD) && ctest --output-on-failure -j$(JOBS) + @n=$$(cd $(BUILD) && ctest -N -L no_python | sed -n 's/^Total Tests: //p'); \ + if [ "$${n:-0}" -gt 0 ]; then echo "make check: $$n tests skipped per build (no Python 3)"; fi + +# the q15 kernels, with q15ops_arm when arm-none-eabi-gcc and qemu-arm are installed +check-q15: + $(CMAKE) -S . -B $(Q15_BUILD) -DCMAKE_BUILD_TYPE=Release -DXOMBE_WERROR=$(WERROR) -DXOMBE_KERNELS=q15 $(CMAKE_FLAGS) + $(CMAKE) --build $(Q15_BUILD) -j$(JOBS) + cd $(Q15_BUILD) && ctest --output-on-failure -j$(JOBS) + +conformance: all + sh test/conformance.sh $(BUILD) $(PYTHON) + +conformance-dstar: all + sh test/conformance_dstar.sh $(BUILD) $(PYTHON) + +clean: + rm -rf $(BUILD) $(SAN_BUILD) $(Q15_BUILD) diff --git a/xombe/README.md b/xombe/README.md new file mode 100644 index 0000000..1087af0 --- /dev/null +++ b/xombe/README.md @@ -0,0 +1,181 @@ +# xombe + +C99 library implementing AMBE 2400 and AMBE+2 used by D-STAR and DMR. decoders, +a single input dual output encoder, parameter-space transcoders, and FEC. + +## minimum usage + +play a DMR call saved by dsd (`.amb`): + + xombe-dec call.amb - | aplay -q -f S16_LE -r 8000 + +encode a wav for DMR: + + sox talk.wav -t raw -r 8000 -c 1 -b 16 -e signed -L - | xombe-enc - talk.amb + +to decode DMR air frames in C: + + #include + + static xombe_dec_mem mem; + xombe_dec *dec = xombe_dec_init(&mem, XOMBE_DMR); /* or XOMBE_DSTAR */ + + xombe_dec_frame(dec, frame, 0, pcm); /* 9 bytes in, 160 samples out */ + +when a frame is lost set flags to `XOMBE_FLAG_LOST` (frame can be NULL). frames +with FEC applied (49 bits, `.amb`) are decoded by `xombe_dec_frame_bits`. + +to encode: + + static xombe_enc_mem mem; + xombe_enc *enc = xombe_enc_init(&mem, NULL); /* NULL: default settings */ + + if (xombe_enc_frame(enc, pcm, NULL, dmr, NULL) == 1) /* 160 samples in */ + send(dmr); /* lags input by 3 frames */ + + for (i = 0; i < xombe_enc_delay(enc); i++) { /* at end of input */ + xombe_enc_frame(enc, NULL, NULL, dmr, NULL); + send(dmr); + } + +for D-STAR output, set `cfg.outputs` and pass a buffer as the last argument. +every call is documented in `include/xombe.h`. + +## features + + - AMBE+2 and AMBE 2400 decoders with frame-loss concealment + - encoders with noise suppression, DTX, and tone detection + - send DTMF, Knox and call-progress tones from the encoder + - DMR and D-STAR channel FEC, both directions + - transcode DMR to D-STAR and back in parameter space (no PCM) + - no malloc or globals: all state is caller-managed + - fixed-point build for Cortex-M with the DSP extension + - hardened against malformed and malicious inputs + +benchmarks on a raspberry pi pico 2 (RP2350): + + - 150 MHz (stock), q15 encoder uses 41% of one core, decoder 6% + - 200 MHz (no overvolt), three full-duplex channels fit across two cores + +## building + +needs cmake 3.13 and a C99 compiler. + + git clone https://github.com/x0rro/xombe && cd xombe + make + make check # optional + sudo cmake --install build + +pass build options to `make` as `CMAKE_FLAGS="-DXOMBE_KERNELS=q15 ..."`, or run +cmake yourself. + +once installed, there are two main ways of using the library. + + - cmake: `find_package(xombe)` and link `xombe::xombe` + - `pkg-config xombe` for the compile and link flags. + +the library builds on all platforms. the tools and tests require POSIX. + +### build options + + -DXOMBE_KERNELS=float|q15 q15 is fixed point for M33 DSP (default float) + -DBUILD_SHARED_LIBS=ON shared library (default static) + + -DXOMBE_ENCODER=OFF decoder only + -DXOMBE_DSTAR=OFF DMR only + +float and q15 builds encode slightly differently, and their decoded audio +differs by a few LSB. both pass the same tests. + +### testing + + make check # release, q15 and sanitizer builds + make conformance PYTHON=python3 # scores encoded and decoded speech + make conformance-dstar PYTHON=python3 + +`make check` runs a few more tests if python 3 is installed. the conformance +targets need numpy, scipy, pesq, pystoi and visqol. + +## file formats + + .raw 8 kHz signed 16-bit little-endian mono + .amb dsd's format: ".amb", then 8 bytes per frame + .bits 49 bytes per frame, one bit per byte + .air 72-bit DMR air frames (xombe does FEC and interleaving) + .r33 same as .air + .dstar 72-bit D-STAR voice frames (xombe does FEC and interleaving) + +## xombe-dec + + xombe-dec [options] IN OUT.raw + + --bits IN is .bits + --air IN is .air, decoded through the FEC + --dstar IN is .dstar + (default: .amb) + + --lost LIST treat these frames as lost, from 0, e.g. 3,10-12 + --decisions print each frame's class and concealment on stderr + --help list all options + +## xombe-enc + + xombe-enc [options] IN.raw OUT + + --bits write .bits + --air write .air + --dstar write .dstar only + --dual DSTAR_OUT write .dstar to DSTAR_OUT as well as AMBE+2 to OUT + (default: .amb) + + --ns on|off noise suppression (default on) + --ns-strength S how hard to suppress (0-1, default 0.5) + --dtx on|off send silence frames for background noise (default on) + --dstar-dtx on|off same for D-STAR (default off) + --tones on|off detect tones and send as tone frames (default on) + --vscale S voicing decision scale, 0.6 voices less (default 0.35) + --quant closed|open open is faster but sounds worse (default closed) + + --help list all options + +## xombe-xc + + xombe-xc [options] IN.r33 OUT.dstar # DMR to D-STAR + xombe-xc --reverse [options] IN.dstar OUT.r33 # D-STAR to DMR + + --amb DMR side is .amb instead of .r33 (for D-STAR in dsd) + --lost LIST treat these frames as lost, from 0, e.g. 3,10-12 + --decisions print each frame's class and concealment on stderr + +## verifying a release + +each release is a tag signed by x0rro (`x0rroRF@proton.me`), key fingerprint +`638C 5D53 640A CEFB 79B6 87AA 3E93 43F0 B819 4BFF`. the tag message has the +hashes of the release tarball and its buildinfo: + + git tag -v v0.1.0 + +### reproducing a release + +release tarballs are reproducible. rebuild one on x86_64 in the debian container +named in `scripts/release_lock.sh`: + + git clone -b v0.1.0 https://github.com/x0rro/xombe && cd xombe && mkdir out + podman run --rm -v "$PWD:/src" -v "$PWD/out:/out" \ + docker.io/library/debian@sha256:2dc419c6d7fe3dad0a2f9fd469c34cc90b0f9ba642d8fde837fe3d7d34a0e7f1 \ + sh -c 'cd /src && scripts/release_deps.sh && git config --global safe.directory /src && + scripts/release_tarball.sh HEAD /out && cd /out && sha256sum *' + +the hashes it prints match the tag's. + +## patent note + +patents covering methods used in this code may still be in force in some +jurisdictions. if that applies to you, get a license from the patent holder +before using it. + +## copyright + +copyright (c) 2026 x0rro + +released under MIT license, see LICENSE diff --git a/xombe/include/xombe.h b/xombe/include/xombe.h new file mode 100644 index 0000000..9ec39b1 --- /dev/null +++ b/xombe/include/xombe.h @@ -0,0 +1,362 @@ +#ifndef XOMBE_H +#define XOMBE_H + +#include +#include +#include "xombe_config.h" + +/* DMR (AMBE+2 half rate) and D-STAR (AMBE 2400) decoders, encoder, channel FEC, and transcoders between the two. + every call that handles frames takes the codec as an enum xombe_codec, at init or as an argument, and treats + both codecs the same way + + build options, recorded in xombe_config.h as 0/1 and guarding the declarations below: + XOMBE_HAVE_ENCODER the encoder (CMake XOMBE_ENCODER, default on) + XOMBE_HAVE_DSTAR the D-STAR codec and the transcoders (XOMBE_DSTAR, default on). without it an init for + XOMBE_DSTAR returns NULL + XOMBE_KERNELS_Q15 fixed-point kernels (XOMBE_KERNELS=q15), larger encoder state + the decoder and the FEC are always built + + frames: a frame is the 72-bit channel frame as sent, XOMBE_FRAME_BYTES bytes MSB first, FEC included: DMR's + rate-33 frame or D-STAR's voice frame. the voice bits without FEC are XOMBE_BITS_BYTES bytes MSB first, DMR + d0..d48, D-STAR d0..d47 and a zero bit. the *_bits calls and xombe_fec_* take them, everything else frames + + conventions, for every object here: + - state is opaque and caller-allocated, the library never allocates and has no mutable globals. pass init + the *_SIZE bytes, aligned for any scalar type: the matching *_mem union (static, automatic, or a struct + member) or malloc(*_size()). init returns the handle (the same address), or NULL if mem is NULL or the + settings are invalid. there is no deinit: drop or reuse the memory, init again to reset + - *_size() is the exact size, at most *_SIZE. sizes can change between versions, compare xombe_version() + with XOMBE_VERSION when the library may come from elsewhere + - no thread safety inside an instance: one thread at a time per instance. distinct instances are independent + - handles and required buffers must be valid, they are not checked. buffers are caller-owned and only + accessed during the call + - PCM frames are 20 ms: 160 samples of 8 kHz signed 16-bit PCM + - *_frame calls return 1 when the output holds the frame for an input, 0 when it holds something else (the + encoder's silence frame while its delay fills, a decoder's pending half-frame), -1 for a call the object + cannot take (nothing written or consumed) + - decoders and transcoders take the XOMBE_FLAG_* flags and report each frame through *_decision_get + - unknown flag bits are reserved, pass 0 + - the calls that take a codec at init are inline here and pick a per-codec function (xombe__*, not part of the + API), so a program that names one codec as a constant links none of the other's code */ + +#ifdef __cplusplus +extern "C" { +#endif + +#define XOMBE_VERSION_MAJOR 0 +#define XOMBE_VERSION_MINOR 1 +#define XOMBE_VERSION_PATCH 0 +#define XOMBE_VERSION (XOMBE_VERSION_MAJOR * 10000 + XOMBE_VERSION_MINOR * 100 + XOMBE_VERSION_PATCH) + +/* the XOMBE_VERSION the library was built with */ +XOMBE_API int xombe_version(void); + +enum xombe_codec { + XOMBE_DMR = 0, /* AMBE+2 half rate, 49 voice bits, DMR rate-33 FEC */ + XOMBE_DSTAR = 1 /* AMBE 2400, 48 voice bits, D-STAR FEC */ +}; + +#define XOMBE_FRAME_BYTES 9 +#define XOMBE_BITS_BYTES 7 + +/* flags of every call that decodes or transcodes a frame + LOST: the frame was not received, its input is not read (may be NULL). concealed as a bad frame (repeat, mute + after three concealed frames in a row), the error counts and the running error rate are left alone + BF, HB: the *_bits calls only, the error rule's flags as xombe_fec_decode returns them. calls that take frames + compute them */ +#define XOMBE_FLAG_LOST 0x1u +#define XOMBE_FLAG_BF 0x4u /* bad frame: conceal by repeating */ +#define XOMBE_FLAG_HB 0x8u /* high error rate: mute */ + +#define XOMBE_HALF_MIN 76 +#define XOMBE_HALF_MAX 84 + +enum xombe_class { + XOMBE_CLASS_VOICE = 0, + XOMBE_CLASS_ERASURE = 1, + XOMBE_CLASS_SILENCE = 2, + XOMBE_CLASS_TONE = 3 +}; + +enum xombe_conceal { + XOMBE_CONCEAL_NONE = 0, + XOMBE_CONCEAL_REPEAT = 1, + XOMBE_CONCEAL_MUTE = 2 +}; + +/* decoder noise source: production (the default), or the conformance generator, which reproduces the test vectors */ +enum xombe_noise_mode { + XOMBE_NOISE_PRODUCTION = 0, + XOMBE_NOISE_CONFORMANCE = 1 +}; + +/* a decoder's account of the last frame. before the first frame all 0 but mute_src = e0 = e1 = -1 */ +typedef struct { + enum xombe_class cls; /* ERASURE for a DMR erasure frame or a lost one, SILENCE for a DMR silence frame + or a D-STAR null frame */ + enum xombe_conceal conceal; /* what played in place of the frame: NONE, REPEAT, or MUTE */ + int run; /* concealed frames in a row up to this one, 0 if it was not concealed */ + int64_t mute_src; /* with MUTE: frame (0 = first) the muted set came from, -1 for the initial set */ + int e0, e1; /* as xombe_fec_stats eps0 and eps1, -1 if lost or from a *_bits call */ + int bf, hb; /* error rule: bad frame, high error rate (*_bits calls: the flags passed), 0 if + lost */ +} xombe_decision; + +/* channel FEC: voice bits <-> frames, stateless but for the running error rate + eps0, eps1: Golay corrections in the two protected words, DMR 0..4 and 0..3, D-STAR 0..4 each, 4 = + uncorrectable. eps_t: their sum. bf, hb: the codec's error rule + eps_r: running error rate 0.95*eps_r + 0.05*eps_t/n per frame, n 47 (DMR) or 48 (D-STAR), Q24 (1 << 24 = 1.0) */ +typedef struct { + int eps0, eps1, eps_t; + int bf, hb; + uint32_t eps_r; +} xombe_fec_stats; + +typedef struct { + int codec; + uint32_t eps_r; + float er; +} xombe_fec; /* contents private, set by xombe_fec_init */ + +XOMBE_API int xombe__fec_init_dmr(xombe_fec *f); +XOMBE_API int xombe__fec_init_dstar(xombe_fec *f); +XOMBE_API void xombe__fec_encode_dmr(const uint8_t bits[XOMBE_BITS_BYTES], uint8_t frame[XOMBE_FRAME_BYTES]); +XOMBE_API int xombe__fec_encode_dstar(const uint8_t bits[XOMBE_BITS_BYTES], uint8_t frame[XOMBE_FRAME_BYTES]); +/* returns 0, -1 for a codec not built (f unchanged) */ +static inline int xombe_fec_init(xombe_fec *f, enum xombe_codec codec) +{ + return codec == XOMBE_DMR ? xombe__fec_init_dmr(f) : codec == XOMBE_DSTAR ? xombe__fec_init_dstar(f) : -1; +} +/* returns 0, -1 with nothing written for a codec not built */ +static inline int xombe_fec_encode(enum xombe_codec codec, const uint8_t bits[XOMBE_BITS_BYTES], + uint8_t frame[XOMBE_FRAME_BYTES]) +{ + if (codec == XOMBE_DMR) { + xombe__fec_encode_dmr(bits, frame); + return 0; + } + return codec == XOMBE_DSTAR ? xombe__fec_encode_dstar(bits, frame) : -1; +} +/* fills st (may be NULL), returns the frame's XOMBE_FLAG_* word */ +XOMBE_API unsigned xombe_fec_decode(xombe_fec *f, const uint8_t frame[XOMBE_FRAME_BYTES], + uint8_t bits[XOMBE_BITS_BYTES], xombe_fec_stats *st); + +/* decoder: frames or voice bits in, PCM out, no delay. FEC decoded here, classes, concealment, then synthesis + DMR: an erasure frame or a bad one repeats the last played set, a high running error rate mutes + D-STAR: classes voice, tone, or null frame (b0 124 or 125, and the DTX fill b0 127, ff x 9). a bad voice frame + repeats the last played set, a high running error rate mutes */ +typedef struct xombe_dec xombe_dec; +#define XOMBE_DEC_SIZE 5248 +typedef union { + int64_t align_i; + void *align_p; + unsigned char bytes[XOMBE_DEC_SIZE]; +} xombe_dec_mem; + +XOMBE_API size_t xombe_dec_size(void); +XOMBE_API xombe_dec *xombe__dec_init_dmr(void *mem); +XOMBE_API xombe_dec *xombe__dec_init_dstar(void *mem); +static inline xombe_dec *xombe_dec_init(void *mem, enum xombe_codec codec) +{ + return codec == XOMBE_DMR ? xombe__dec_init_dmr(mem) : codec == XOMBE_DSTAR ? xombe__dec_init_dstar(mem) : NULL; +} +/* noise source and its seed (0: default), restarts the source. init sets XOMBE_NOISE_PRODUCTION, seed 0. + call before the first frame, returns 0, -1 for an unknown mode */ +XOMBE_API int xombe_dec_set_noise(xombe_dec *d, enum xombe_noise_mode mode, uint32_t seed); +/* flags: 0 or XOMBE_FLAG_LOST. writes 160 samples, returns 1. after an unpaired first half it only ends that + frame and returns 0: pcm[0..79] zeros, pcm[80..159] the pending second half, in unread, so pass it again */ +XOMBE_API int xombe_dec_frame(xombe_dec *d, const uint8_t in[XOMBE_FRAME_BYTES], unsigned flags, int16_t pcm[160]); +/* one half-frame of n samples, n clamped to 76..84 (pcm holds XOMBE_HALF_MAX whatever n), returns the count + written. calls alternate first half (second_half 0, reads in and flags) and second half (in unread, may be + NULL), a call out of that order writes nothing and returns -1. two halves of 80 equal xombe_dec_frame */ +XOMBE_API int xombe_dec_half(xombe_dec *d, const uint8_t in[XOMBE_FRAME_BYTES], unsigned flags, int second_half, + int n, int16_t *pcm); +/* xombe_dec_frame and xombe_dec_half for voice bits, FEC done by the caller. flags: XOMBE_FLAG_LOST, or + XOMBE_FLAG_BF | XOMBE_FLAG_HB as xombe_fec_decode returns them */ +XOMBE_API int xombe_dec_frame_bits(xombe_dec *d, const uint8_t bits[XOMBE_BITS_BYTES], unsigned flags, + int16_t pcm[160]); +XOMBE_API int xombe_dec_half_bits(xombe_dec *d, const uint8_t bits[XOMBE_BITS_BYTES], unsigned flags, + int second_half, int n, int16_t *pcm); +/* *_bits calls: FEC error counts for adaptive smoothing (xombe_fec_stats eps_t, eps1), kept until set again. + the frame calls set them from their own FEC */ +XOMBE_API void xombe_dec_set_errors(xombe_dec *d, int eps_t, int eps1); +XOMBE_API void xombe_dec_decision_get(const xombe_dec *d, xombe_decision *out); + +/* tone frame of AMBE+2 tone ID id (5..122, 128..163) at level ad (0..127), as xombe_enc_tone. D-STAR sends the + tone at AD max(ad, 8), as the encoder and the transcoder do. returns 0, -1 with nothing written for an id or ad + out of range, a codec not built, or a D-STAR id without a tone code (Knox IDs 144..159) */ +XOMBE_API int xombe__tone_frame_dmr(int id, int ad, uint8_t out[XOMBE_FRAME_BYTES]); +XOMBE_API int xombe__tone_frame_dstar(int id, int ad, uint8_t out[XOMBE_FRAME_BYTES]); +static inline int xombe_tone_frame(enum xombe_codec codec, int id, int ad, uint8_t out[XOMBE_FRAME_BYTES]) +{ + return codec == XOMBE_DMR ? xombe__tone_frame_dmr(id, ad, out) + : codec == XOMBE_DSTAR ? xombe__tone_frame_dstar(id, ad, out) + : -1; +} + +/* encoder outputs, xombe_enc_cfg.outputs. XOMBE_ENC_DSTAR needs XOMBE_HAVE_DSTAR, init refuses it otherwise */ +#define XOMBE_ENC_DMR 0x1u +#define XOMBE_ENC_DSTAR 0x2u + +/* DMR amplitude quantizers, xombe_enc_cfg.dmr_quant */ +#define XOMBE_ENC_QUANT_CLOSED 0 /* weighted closed-loop search, better quality */ +#define XOMBE_ENC_QUANT_OPEN 1 /* open loop, faster */ + +#if XOMBE_HAVE_ENCODER +/* encoder delay, frames: DMR alone, and with the D-STAR output on. D-STAR's tone rules look one frame further + ahead than the pitch tracker (a tone-in-noise frame needs the next frame's tone decision). both outputs share + the delay: with both on the DMR frames are those of a DMR-only encoder, one call later */ +#define XOMBE_ENC_DELAY 3 +#define XOMBE_ENC_DSTAR_DELAY (XOMBE_ENC_DELAY + 1) + +typedef struct xombe_enc xombe_enc; +/* state size: larger with q15 kernels, and XOMBE_ENC_DSTAR_SIZE more with D-STAR, whether or not used. without + D-STAR, XOMBE_ENC_CQ_SIZE more for the closed-loop quantizer's workspace (with D-STAR it shares the D-STAR's) */ +#if XOMBE_HAVE_DSTAR +#define XOMBE_ENC_DSTAR_SIZE 21504 +#define XOMBE_ENC_CQ_SIZE 0 +#else +#define XOMBE_ENC_DSTAR_SIZE 0 +#define XOMBE_ENC_CQ_SIZE 19968 +#endif +#if XOMBE_KERNELS_Q15 +#define XOMBE_ENC_SIZE (39424 + XOMBE_ENC_DSTAR_SIZE + XOMBE_ENC_CQ_SIZE) +#else +#define XOMBE_ENC_SIZE (25088 + XOMBE_ENC_DSTAR_SIZE + XOMBE_ENC_CQ_SIZE) +#endif +typedef union { + int64_t align_i; + void *align_p; + unsigned char bytes[XOMBE_ENC_SIZE]; +} xombe_enc_mem; + +/* xombe_enc_cfg_default's values in parentheses, flags are on when nonzero */ +typedef struct { + int ns; /* noise suppression (on) */ + int ns_strength_permille; /* noise suppression strength, 0..1000 (500) */ + int tones; /* tone detection, both outputs (on) */ + int voicing_scale_permille; /* voicing decision scale, > 0 (350, 600 is less heavily voiced) */ + unsigned outputs; /* XOMBE_ENC_DMR and/or XOMBE_ENC_DSTAR (DMR, 0 means DMR) */ + int dmr_dtx; /* DMR silence frames for background (on) */ + int dstar_dtx; /* D-STAR null frames for background (off) */ + int dmr_quant; /* DMR amplitude quantizer, XOMBE_ENC_QUANT_* (CLOSED) */ +} xombe_enc_cfg; + +/* tone sent in place of one input frame's speech, xombe_enc_frame */ +typedef struct { + int id; /* AMBE+2 tone ID: 5..122 single tones at 31.25 Hz * id, 128..163 dual tones (DTMF 128..143, Knox + 144..159, call progress 160..163) */ + int ad; /* level 0..127, each component's amplitude 16384 * 10^(0.03555 * (ad - 127)), 0.711 dB per step */ +} xombe_enc_tone; + +/* encoder: PCM in, frames of either or both codecs out from one analysis, xombe_enc_delay(e) frames late */ +XOMBE_API void xombe_enc_cfg_default(xombe_enc_cfg *cfg); +XOMBE_API size_t xombe_enc_size(void); +/* cfg NULL: the defaults, cfg is copied. returns NULL if mem is NULL or cfg is invalid: ns_strength_permille + outside 0..1000, voicing_scale_permille <= 0, an unknown outputs bit, XOMBE_ENC_DSTAR without + XOMBE_HAVE_DSTAR, or an unknown dmr_quant */ +XOMBE_API xombe_enc *xombe_enc_init(void *mem, const xombe_enc_cfg *cfg); +/* XOMBE_ENC_DELAY, or XOMBE_ENC_DSTAR_DELAY when the D-STAR output is on */ +XOMBE_API int xombe_enc_delay(const xombe_enc *e); +/* returns 1 when the frames hold the input xombe_enc_delay(e) calls earlier, else 0. pcm NULL: 160 zeros, at the + end of input call it xombe_enc_delay(e) times so every input frame has its output. tone: this frame sent as a + tone, even with cfg.tones 0, NULL for none. the tone frame is the output xombe_enc_delay(e) calls later, pcm is + still analysed. D-STAR gets the tone at AD max(ad, 8), or for a Knox ID a voice frame from the tone table + dmr and dstar may be NULL. an output the encoder does not produce, or any output before the delay has elapsed, + is written as that codec's silence frame (D-STAR: the null frame). with both on the D-STAR frames differ + slightly from a D-STAR-only encoder's: the DMR voicing then drives the shared noise tracking + returns -1 with nothing consumed for a tone id or ad out of range */ +XOMBE_API int xombe_enc_frame(xombe_enc *e, const int16_t *pcm, const xombe_enc_tone *tone, + uint8_t dmr[XOMBE_FRAME_BYTES], uint8_t dstar[XOMBE_FRAME_BYTES]); +/* xombe_enc_frame writing voice bits */ +XOMBE_API int xombe_enc_frame_bits(xombe_enc *e, const int16_t *pcm, const xombe_enc_tone *tone, + uint8_t dmr[XOMBE_BITS_BYTES], uint8_t dstar[XOMBE_BITS_BYTES]); +#endif + +#if XOMBE_HAVE_DSTAR +/* transcoder between DMR and D-STAR frames, in the parameter domain: the source decoder's FEC, error rule, + classes, concealment, and dequantization, then the parameters requantized against the target decoder's + prediction memory. one frame out per frame in, no delay, nothing to flush. from D-STAR needs + XOMBE_HAVE_ENCODER, init returns NULL without it + DMR -> D-STAR + voice nearest D-STAR pitch, per-kHz voicing, amplitudes resampled to the D-STAR harmonics + silence all-unvoiced voice frame from the comfort-noise amplitudes + tone D-STAR tone frame, same tone and level. Knox tones (IDs 144..159, no D-STAR code) become voice + frames at the tone table's f0 + concealed what the DMR decoder plays (its repeat or mute set), for a concealed tone the last output frame + again + D-STAR -> DMR + voice nearest DMR pitch, voicing from the previous and current D-STAR b1, amplitudes resampled to the + DMR harmonics + pulse an all-unvoiced D-STAR frame whose b0 maps to a pulse: DMR pulse frame (b1 18..31) + tone DMR tone frame, same tone ID and level (Knox tones arrive as voice frames and stay voice) + silence null frames and mutes: the standard DMR silence frame + concealed the D-STAR decoder's repeat set, requantized with the last good frame's voicing and pitch */ +#define XOMBE_XC_DELAY 0 + +typedef struct xombe_xc xombe_xc; +#define XOMBE_XC_SIZE 23168 +#define XOMBE_XC_SHARED_SIZE 3712 /* without the workspace, for xombe_xc_init_shared */ +typedef union { + int64_t align_i; + void *align_p; + unsigned char bytes[XOMBE_XC_SIZE]; +} xombe_xc_mem; +typedef union { + int64_t align_i; + void *align_p; + unsigned char bytes[XOMBE_XC_SHARED_SIZE]; +} xombe_xc_shared_mem; + +/* a transcoder's quantizer workspace: scratch only, nothing in it lives between calls, so transcoders that never + run at the same time can share one (xombe_xc_init_shared). XOMBE_XC_SIZE includes its own */ +#define XOMBE_QWS_SIZE 19968 +typedef union { + int64_t align_i; + void *align_p; + unsigned char bytes[XOMBE_QWS_SIZE]; +} xombe_qws_mem; + +enum xombe_xc_out { + XOMBE_XC_OUT_VOICE = 0, /* voice frame (to D-STAR: also for DMR silence) */ + XOMBE_XC_OUT_PULSE = 1, /* to DMR: pulse frame, b1 18..31 */ + XOMBE_XC_OUT_TONE = 2, /* tone frame */ + XOMBE_XC_OUT_KNOX = 3, /* to D-STAR: voice frame for a Knox tone */ + XOMBE_XC_OUT_SILENCE = 4, /* to DMR: the standard silence frame */ + XOMBE_XC_OUT_RESEND = 5 /* to D-STAR: the previous output again (initially the D-STAR null frame) */ +}; + +typedef struct { + xombe_decision in; /* the source decoder's account of the input frame */ + enum xombe_xc_out out; +} xombe_xc_decision; + +XOMBE_API size_t xombe_xc_size(void); +XOMBE_API xombe_xc *xombe__xc_init_dmr(void *mem); +XOMBE_API xombe_xc *xombe__xc_init_dstar(void *mem); +XOMBE_API xombe_xc *xombe__xc_init_shared_dmr(void *mem, void *ws); +XOMBE_API xombe_xc *xombe__xc_init_shared_dstar(void *mem, void *ws); +/* from: the input frames' codec, the output is the other one */ +static inline xombe_xc *xombe_xc_init(void *mem, enum xombe_codec from) +{ + return from == XOMBE_DMR ? xombe__xc_init_dmr(mem) : from == XOMBE_DSTAR ? xombe__xc_init_dstar(mem) : NULL; +} +/* mem: XOMBE_XC_SHARED_SIZE bytes (an xombe_xc_shared_mem). ws: XOMBE_QWS_SIZE bytes (an xombe_qws_mem), + zeroed here, shared only between transcoders called from one thread. NULL if either is NULL */ +static inline xombe_xc *xombe_xc_init_shared(void *mem, enum xombe_codec from, void *ws) +{ + return from == XOMBE_DMR ? xombe__xc_init_shared_dmr(mem, ws) + : from == XOMBE_DSTAR ? xombe__xc_init_shared_dstar(mem, ws) + : NULL; +} +/* flags: 0 or XOMBE_FLAG_LOST. returns 1, out holds this input's frame */ +XOMBE_API int xombe_xc_frame(xombe_xc *x, const uint8_t in[XOMBE_FRAME_BYTES], unsigned flags, + uint8_t out[XOMBE_FRAME_BYTES]); +XOMBE_API void xombe_xc_decision_get(const xombe_xc *x, xombe_xc_decision *out); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/xombe/scripts/data/dstar_tables.json b/xombe/scripts/data/dstar_tables.json new file mode 100644 index 0000000..c5c5394 --- /dev/null +++ b/xombe/scripts/data/dstar_tables.json @@ -0,0 +1,1471 @@ +{ + "p0": -4.24503, + "p1": -0.021815, + "rho": 0.8, + "grho": 0.0, + "DG": [-0.060636551320569984, 0.10086983504082943, 0.3712785528659137, 0.5124143707126033, 1.1065796898672082, 1.232482328752463, 1.65990622969119, 1.8118765582787475, 2.0820803676867454, 2.196141953374924, 2.3387635515034657, 2.5125581630632756, 2.6142699049411258, 2.7644776063530316, 2.9164439704742393, 3.0710747870111743, 3.2599786441345855, 3.34685529270061, 3.4904042236345503, 3.616641967263226, 3.7773619105341636, 3.9108302236844805, 4.05696215101577, 4.1980712006714445, 4.4026860537300205, 4.533867343746086, 4.692012428713642, 4.831709905783685, 5.0273547839033865, 5.1395692210020245, 5.3511055948254045, 5.493972504441072, 5.681913046545386, 5.770165012472249, 5.90700949028622, 6.035242213796449, 6.153890161582781, 6.290110309386782, 6.443694978127296, 6.5614034867906765, 6.705003387131954, 6.835834065493252, 7.0022074894910125, 7.116421898825831, 7.303905290421896, 7.406933159641687, 7.555188431190937, 7.722834082222852, 7.9014070028870815, 8.023899232265126, 8.190899212782876, 8.364096443159461, 8.538737619130048, 8.703124049056026, 8.896083187871104, 9.023341894693727, 9.24797081383917, 9.382517599038614, 9.638368922186363, 9.768255750702142, 10.08481855658683, 10.192847795600684, 10.617107751845372, 10.755733156214404], + "ok_DG": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + "PRBA24": [ + [-1.0283036131852046, -0.2671861082649364, -0.5524678689635637], + [-0.6984862899761023, -0.3860018892333299, -0.37303710058674056], + [-0.43696301468067017, -0.3565394184010918, -0.29006714943751627], + [-0.3701926479073414, -0.5868730861241741, -0.4530267083686827], + [-0.9577053117540917, -0.15904677289909466, -0.18277171324252353], + [-0.6044167636879061, -0.6034559460996806, -0.11622425696724743], + [-0.511834932925399, -0.18310116540623333, -0.19666751106656286], + [-0.36872263834421615, -0.4193885589715811, -0.18035088794377496], + [-0.9743019437032587, -0.6827342494775853, -0.07860068672190659], + [-0.5991698035459274, -0.2770505758565841, -0.052710855287098214], + [-0.39152377903197344, -0.7298433598533599, -0.016532400738661048], + [-0.3917862857863372, -0.31513660193513, -0.05581299439443799], + [-0.6234583913987987, -0.21889457629919792, 0.19470519362087518], + [-0.38574370624503773, -0.46343149129193917, 0.35454931566765185], + [-0.3739580790594837, -0.37769662449006464, 0.06662826191676617], + [-0.3055790289184261, -0.18129608830678665, 0.0069829445285278955], + [-0.6280116611813216, -0.19489692360842903, -0.17426146461419792], + [-0.46003615417683713, -0.05867189986418091, -0.2398246590308525], + [-0.5321283225884854, -0.12479856767004756, -0.4545498642063651], + [-0.34002990630677155, -0.07213338137100947, -0.3211422275255763], + [-0.5436366131695708, -0.17618981833800076, -0.04372297683590535], + [-0.37913462986053986, -0.19908812419405753, -0.05917387906819025], + [-0.37591034734170015, -0.12474823943970179, -0.18295363919668298], + [-0.3299351045108271, -0.18638076580555712, -0.13012117681194366], + [-0.5264288083922252, 0.012384862859638184, 0.11963588208106646], + [-0.4195808352116024, 0.007978953774353184, 0.05928319585963719], + [-0.30604893284727597, -0.13040678583052995, 0.11136149047523015], + [-0.30995741084938644, -0.06242671108674263, -0.007035093061525515], + [-0.8513613287499909, -0.0581890342052787, 0.13075626279845212], + [-0.71449038481836, -0.10513165015814514, 0.3951751916379296], + [-0.41586484210678926, -0.050887971119983874, 0.2758851114459305], + [-0.3240780362701026, -0.04908377123651729, 0.6013676445819365], + [-0.8905412638201101, 0.056748522622747294, -0.3093666190041499], + [-0.5098552975069515, 0.1345891347795243, -0.4025484815104277], + [-0.3099614545073398, 0.08083483430048222, -0.25272651665792084], + [-0.35486969592389966, -0.008239587240400616, -0.319394403637974], + [-0.6684454278436344, 0.09870890472168871, -0.19966378527414474], + [-0.4497701481448422, 0.07255991922924894, -0.07220029203839778], + [-0.3942646010795638, 0.13866034675928135, -0.13073358516774067], + [-0.3114594060654499, 0.06928842800675589, -0.13682290011758794], + [-0.6951956067529753, 0.028936458742458572, -0.060641612334518404], + [-0.46507613393694913, 0.18777970135340072, 0.060407612182122886], + [-0.31998905592104415, 0.0612429346497228, 0.0004571981106327945], + [-0.26456748078155756, -0.003618631704920465, 0.10793856345334692], + [-1.2823408672024514, 0.09574446041703269, 0.3154496150894892], + [-0.5183098741483554, 0.12280419668330575, 0.2420305419853169], + [-0.38368791514329853, 0.07464432138460045, 0.3848150787697118], + [-0.28993460520951747, 0.14427406976751078, 0.09289596451903016], + [-1.2426897485359436, 0.20771630161942753, -0.23469034750036474], + [-0.6745487529070427, 0.46691287732218806, -0.3793835580545309], + [-0.554932492913721, 0.29176437089496426, -0.2699447411588727], + [-0.32964011827807493, 0.37758127475918063, -0.5760848052748891], + [-0.8065097937843266, 0.4265546834561579, -0.09377995706766122], + [-0.6224308005810467, 0.18792450136741318, -0.07308491038191459], + [-0.519336753025049, 0.3515447264590453, -0.09559750237478633], + [-0.40659231883026636, 0.35854736206670157, -0.26690059035274666], + [-0.8113293429473128, 0.17310955033712436, 0.2096422210239796], + [-0.5649074964138722, 0.6490459071409779, 0.03878948654649199], + [-0.47434067402506414, 0.3446517767318128, 0.11324375787265804], + [-0.2895234939038698, 0.29322331177947397, 0.04814537481535262], + [-0.5093815009989444, 0.284906274213139, 0.6536296924408687], + [-0.35790576399439705, 0.2381656437709063, 0.3182005591873156], + [-0.2868240235441577, 0.5235213988491945, 0.4927939866761858], + [-0.2973524806881183, 0.48332332453982135, 0.2651712354222655], + [-0.24553787229913185, -0.4134485242362607, -0.33733979695378], + [-0.25901515017563465, -0.24670684200025222, -0.2943644488694357], + [-0.271431460301105, -0.5641882585768475, -0.24888528027882073], + [-0.1293756326935429, -0.47825002577797915, -0.22794249843553405], + [-0.25411581350516815, -0.3770088759880172, -0.11183855421596535], + [-0.1680972461475528, -0.30479424163661256, -0.19511654963850295], + [-0.13195722688391617, -0.24201532645836907, -0.24216637753848846], + [-0.06811350289660201, -0.20108292813122805, -0.1287567400113862], + [-0.1836337445007228, -0.18294727014466108, -0.06347336109455733], + [-0.17135863715583877, -0.4467413807944095, 0.013609798277685511], + [-0.1336053203139223, -0.38816659958296634, -0.06854526127755421], + [-0.06835290642491794, -0.24016188313316722, -0.0006270935546406144], + [-0.27023550663259305, -0.306241573674626, 0.24131013637750992], + [-0.18610155381889415, -0.2574655549004647, 0.1204429031176265], + [-0.15636968322392447, -0.2394958340445981, 0.019660943461852244], + [-0.08852633737397753, -0.5673972622091653, 0.1661720596018347], + [-0.19241385057762267, -0.052039321028720165, -0.2432804258521529], + [-0.1410295313456482, -0.06597587338121735, -0.19357340557730807], + [-0.04652383771119092, -0.00019123437533453836, -0.2930546969377278], + [-0.0565212750123008, -0.0022722352133493044, -0.7891549945893264], + [-0.2531457217760503, -0.13212571185100147, -0.06158323960817758], + [-0.24072161802073233, -0.06215899878553091, -0.14540994425108922], + [-0.20411195964407058, -0.003377098352166989, -0.07271819493421924], + [-0.1266096023064497, -0.0657833219631626, -0.06728554908715036], + [-0.18936163192675587, -0.0028087670761858304, 0.1269741651910329], + [-0.18731552454978828, -0.05892739192136351, 0.056799386637127296], + [-0.11149908850018739, -0.1280965170032097, 0.12832588376349474], + [-0.09622910790904153, -0.17341559887534713, 0.06436526764780288], + [-0.19234524030657318, -0.0366982163075071, 0.43338550918454405], + [-0.18904566452333596, -0.0982906388039347, 0.186904699978686], + [-0.12293054048062506, 0.007141339234894794, 0.1930582344530612], + [-0.0702656602828249, 0.007848185047272395, 0.35272050091938223], + [-0.18817439656312754, 0.008518624490003141, -0.1718642773118163], + [-0.18252300533326943, 0.1330915507297686, -0.11562703310485449], + [-0.176792865209024, 0.15197683480723262, -0.19898340587237187], + [-0.1341473166944481, 0.12167282060366588, -0.39665598234549587], + [-0.25951037158163653, 0.19121044169457146, -0.0024116455584805387], + [-0.14727852080619824, -0.0014687295528712945, -0.1298992753199739], + [-0.05931789998219976, 0.003763086286251082, -0.06250419927662307], + [-0.06426591475692696, 0.12134298024034193, -0.06195192387292164], + [-0.20260155884828918, 0.0980012211917004, 0.13133941309381322], + [-0.1896472900848388, 0.0608514183259266, -0.00918179796369361], + [-0.10543665951162008, 0.12275601339644039, 0.06231811539677042], + [-0.062259344082474084, 0.00019118003679169225, -0.005214888967511664], + [-0.24590414248291487, 0.051563555008794434, 0.25287500867014173], + [-0.13235411986227752, 0.12410502683849028, 0.3094445225754551], + [-0.09260893148201606, 0.14987011598116107, 0.13503490476832783], + [-0.06470679944859142, 0.0021604276637147476, 0.12195172251537366], + [-0.2479391876970322, 0.24999899175122792, -0.19358515728299133], + [-0.18925779287617667, 0.7044247115430098, -0.2052627856734413], + [-0.1447158185490075, 0.2689824504659258, -0.1297928740783401], + [-0.05617567818220929, 0.3663281364887986, -0.34053685138010303], + [-0.16701897236248078, 0.20863918891117622, -0.05259098101848711], + [-0.1735750475352162, 0.4271189204768371, -0.08058654039983022], + [-0.1363283629952401, 0.3729226446883466, 0.055559622918161966], + [-0.04894541405978594, 0.5193447309207017, -0.009745294436543749], + [-0.24564390805154954, 0.250525602628254, 0.17519732104320856], + [-0.140774554866819, 0.5688103707912836, 0.23820083966830735], + [-0.15012750927193008, 0.4203132308113054, 0.11013191602613795], + [-0.07476297603690349, 0.30697555607645904, 0.11640381883394695], + [-0.28253455092746493, 0.18274573685168602, 0.44890630698796913], + [-0.18087748753377067, 0.253005218541756, 0.29466200738724596], + [-0.07685644923757672, 0.31286853823919114, 0.24216931877896586], + [-0.0407279548734406, 0.40736269401566383, 0.5450584680640901], + [-0.06981379726840928, -0.3561353605010851, -0.2378805831031084], + [0.031822672335659295, -0.24764215070622228, -0.3445429051109843], + [0.08257102387183685, -0.2646898360047349, -0.29056015550067504], + [0.05483199343120702, -0.32548630275355706, -0.25606179522505523], + [-0.011356819801298533, -0.3211689225277405, -0.1440586845913858], + [-0.00881581520910852, -0.25634928028367515, -0.061256259531569136], + [-0.002790866980550074, -0.530908632290854, -0.14362986644025777], + [0.03422569065091494, -0.26022298599058824, -0.19197436483790126], + [0.00919612660547995, -0.4178164293291927, -0.0009319265909585205], + [-0.005469206314692178, -0.2549663876605801, 0.000666683676288901], + [0.007265332801020514, -0.19142766371482672, 0.05817141760654481], + [0.05493149059613246, -0.4012274135483867, -0.018323263263888036], + [-0.06890232430805117, -0.1855755037055967, 0.1149278782868855], + [-0.04010852056604561, -0.36998854708020507, 0.06863576312396935], + [-0.01628970415088739, -0.27887780868060147, 0.19287321897306475], + [0.014270822831637551, -0.3076578969210795, 0.11477787338305707], + [-0.061045177222708795, -0.1173454413482386, -0.23895419406561041], + [-0.015929408910665552, -0.11228642237663233, -0.5050864695968461], + [-0.018361722767205838, -0.06449792959845944, -0.25056180075727186], + [0.054489347609918394, -0.1952197333032298, -0.19287164898473932], + [-0.06829572194201573, -0.12462389302430704, -0.058656908612521555], + [-0.05693208231652547, -0.184727944640615, 0.00317574432691251], + [-0.006608806798728623, -0.13284357994839543, -0.12504430860531338], + [-2.071446092124425e-05, -0.199078479962077, -0.12739154461729005], + [-0.0661025846084065, -0.06635736441878677, 0.12183149252582881], + [-0.0008412987438523248, -0.12151551862388744, -0.0025734924392760796], + [0.060324533792721166, -0.060047248553800045, -0.0007746169334495401], + [0.05801485767017232, -0.1329008476598101, -0.0013429229776273396], + [-0.05026792803839633, -0.11598113513578166, 0.43571104828611185], + [-0.004599003608856352, -0.05422098457637525, 0.25866513525990725], + [0.0022627832993341616, -0.1364933550538258, 0.17809959721777752], + [0.0664931801885497, -0.1979320617210573, 0.32145139793275623], + [-0.06887158916001601, 0.0734371011836901, -0.190529321767705], + [-0.07243863074911011, -0.0008473621041796819, -0.12890544291438494], + [0.06798545982995963, 0.06644936513810541, -0.12699419275030305], + [0.041622953333494896, 0.06696617110701826, -0.32605148044523147], + [0.000381145043662157, 0.06870261868686842, -0.06470495411448417], + [-0.0015771715241100245, -0.0007581928972510044, -0.0007314186657103448], + [0.06067799239643432, -0.0016687840605563765, -0.12395300986475317], + [0.04647673422804237, 0.13672875115815278, -0.13921850740877784], + [-0.0002053364182444473, 0.06767293854582512, 0.1248656891302146], + [-0.0006001796158565344, 0.13159520832843188, 0.05841557480365903], + [0.05788034513631591, 0.0029401432924083966, 0.12330020621993457], + [0.0684655564121826, 0.06416839224210293, 0.0006027227896232305], + [-0.06048067796009499, 0.03745779245692393, 0.18605321314255385], + [-0.08218000973788492, 0.06382257730209151, 0.4517169439594502], + [0.003345882868380334, 0.08796580377367225, 0.2536793919709296], + [0.05924531687047184, 0.11540673001484815, 0.192599767714115], + [0.0022874641447054467, 0.2571238755781315, -0.2505312061486981], + [0.021890756115794077, 0.37635472154113825, -0.06223564991321069], + [-0.005024208865094447, 0.18836511646557735, -0.12542033602029765], + [0.05255279236501526, 0.5166399975606102, -0.18567527685824148], + [0.005429382945306278, 0.2616584126561541, -0.010330916311199142], + [-0.016803962611180827, 0.18941702006325856, 0.056130079078819436], + [0.08037163206845639, 0.3177032477522015, 0.05863070381252312], + [0.0593779578760679, 0.2063006424942977, 0.006309158834369804], + [-0.0676523482990955, 0.1936605248246555, 0.17771426213721975], + [0.0019079911023264324, 0.2667972065261044, 0.12950157164183893], + [0.06245208497151228, 0.3637315895095272, 0.1849794917703564], + [0.0476333117791536, 0.25455445898145623, 0.243128885525946], + [-0.049105436520961554, 0.1794663924565838, 0.4698739347814759], + [-0.022990021272908216, 0.29029092195453454, 0.36672207524427414], + [0.004376078601157142, 0.12364205681149429, 0.31631083839237245], + [0.0631783084939423, 0.19314089428959338, 0.233124530153179], + [0.1107134330704533, -0.10395439670096251, -0.31229559802244583], + [0.07962870373551666, -0.33868656768075134, -0.17298200307439054], + [0.14722263730312993, -0.34717188974726887, -0.21990292765438266], + [0.17586040882909498, -0.1890312341194001, -0.11872410577780357], + [0.12728592011862983, -0.19419476700583496, -0.06152213781456265], + [0.11551246639411218, -0.641738042415248, -0.030699951107938047], + [0.0, 0.0, 0.0], + [0.13145700507421076, -0.385342107052001, -0.08217924693260231], + [0.062866308776662, -0.2434490407485948, 0.06388351798919079], + [0.12092608589831941, -0.19326184883513212, 0.003393588594032039], + [0.11504775674662955, -0.18253058582777573, 0.12080601328773767], + [0.18466526031359673, -0.2484138440370458, 0.1245044801999697], + [0.07360699103271215, -0.18889725783751005, 0.18718627207963562], + [0.10494752729531454, -0.29806282402912243, 0.2245414877738987], + [0.14331206358965834, -0.34883284876324966, 0.13466089428758227], + [0.18110142882754668, -0.19011436295157885, 0.17716972074924708], + [0.05994231319152296, -0.12242810103560815, -0.11877853108094716], + [0.04778331440550325, -0.007840142253449587, -0.20247291162857758], + [0.11533166601537292, -0.07454535702940565, -0.19020799750581383], + [0.12465484977996083, -0.12601927177651218, -0.06219100491764281], + [0.06387928470137304, -0.0641683615319253, 0.05857672961490648], + [0.12636422299053357, -0.06010685418144244, 0.00030867289917316015], + [0.12309461573681811, -0.12295851576715083, 0.003230904396814972], + [0.19131829965400107, -0.06224251226311666, 0.002662750282085878], + [0.0751859842090598, -0.015660234087110918, 0.18429983413622034], + [0.1238839843622486, -0.1290220142421109, 0.12052103451094423], + [0.12906979557115453, -0.06826889088506863, 0.12410729532041545], + [0.1839564939128543, -0.12402962420879421, 0.12736865127006453], + [0.04719805179200432, -0.06642139635459089, 0.2349380080345709], + [0.04850221227802232, 0.012169377367818314, 0.451041086845408], + [0.1956805907396906, -0.12419370723786832, 0.3747706274860729], + [0.18678544653575432, -0.11303125213261982, 0.25551595268313665], + [0.05273806511397053, 0.13865369452728768, -0.49244654269392346], + [0.12461428700231537, 0.12333201896667517, -0.1382479393940204], + [0.13032191702895088, 0.0003176444999787593, -0.12261418310309703], + [0.19702729518192144, -0.030076999621093347, -0.3140930840472002], + [0.06727679648554084, 0.06114499280171455, 0.06530363202347987], + [0.06211003935210637, 0.11760386510679885, 0.0011211632291509275], + [0.19023060881196555, 0.0611734624978746, -0.057621692808403735], + [0.187484200528134, 0.1238534582877129, 0.06294973773944093], + [0.12295282609547367, 0.12888865430209567, 0.11994669565325863], + [0.11708738418626669, 0.004874161536445764, 0.1297489143282436], + [0.18520889124154322, -0.0020188832640884885, 0.06328435457498438], + [0.1950249201063052, 0.12093973762771697, 0.11614315966978885], + [0.07013253828465993, 0.1378047463168338, 0.3786937379062014], + [0.16203474159065187, 0.04793568943975227, 0.6939625062126431], + [0.12846096373281096, 0.059171396002733405, 0.19889122068352055], + [0.12678659569486386, 0.00848211476921255, 0.2525205983749301], + [0.06018727414418077, 0.17491887513171436, -0.1378031987787795], + [0.12115677972115103, 0.1996954692918518, -0.2593558543974927], + [0.18545015520118424, 0.31457108549062496, -0.3190331640588817], + [0.1927480737571828, 0.26195731873332617, -0.13254010336594663], + [0.053587938899371114, 0.4374064945937329, -0.02039532003782068], + [0.11644229523074844, 0.25045806400584214, -0.019659731493770233], + [0.18378399134799173, 0.1899089986832487, 0.06597450209001793], + [0.1904641955084727, 0.18040117722181379, -0.05651325773926373], + [0.06909823083767172, 0.21227936172240505, 0.1851255634190868], + [0.12212594743947601, 0.3806211950363516, 0.06413506938288915], + [0.17699378647939668, 0.2540993360818257, 0.12143153244918069], + [0.21718503140261516, 0.244832112858669, 0.1947888077201437], + [0.12626858215431427, 0.2953565927643681, 0.3699456662984293], + [0.2093074278971924, 0.6727586955534502, 0.2639430672800563], + [0.18166640607360698, 0.19198269041046154, 0.24818307356181768], + [0.18192571517337752, 0.2920949999986607, 0.25431597118150767], + [0.2379047743368653, -0.5265144469566857, -0.2060515026470915], + [0.14990340890860931, -0.7555417110965764, -0.5822189975531847], + [0.3017383868089426, -0.3547862899367328, -0.3486154898260964], + [0.25962286747291313, -0.4320976337529224, -0.5435221995169605], + [0.17933456593275218, -0.30057267514089575, -0.01080944533001907], + [0.19571161887848446, -0.22910538289730484, -0.2496706644856752], + [0.2437411381613518, -0.29640064377928327, -0.13117157894606138], + [0.3002232411564291, -0.19355186750067974, -0.002730144564285316], + [0.183557373547081, -0.40273009390527725, 0.10779498587573397], + [0.23510205204253629, -0.229720531602721, 0.0014407803633058678], + [0.23587984981114746, -0.29934426034360995, 0.11862065105698631], + [0.47600898776380446, -1.0224567792896775, 0.2175632760573143], + [0.19310816998373756, -0.30367385108586736, 0.4415231580443994], + [0.12353802030567121, -0.6551390221229593, 0.16208619913178895], + [0.16909695718428322, -0.24165529731979765, 0.1711941776154009], + [0.3063683081529886, -0.31409759445415925, 0.2528998439973982], + [0.19285009507304374, -0.06187284924599511, -0.19231635663728938], + [0.1771246268629863, -0.1185828701121947, -0.42608756944991477], + [0.2622953735121128, -0.18486697449109898, -0.13066404394035724], + [0.2588954498604702, -0.14737840474480698, -0.2559241011472753], + [0.24682433892706818, -0.19383759780669851, -0.05897244886167371], + [0.24957176141166731, -0.06494703053278474, -0.06871129055695047], + [0.25248797374929716, -0.07793663513033246, -0.12595057489885852], + [0.31629391275810037, -0.12472124988771274, -0.06733204123910098], + [0.18436098319632724, -0.1835342821493835, 0.054229264263626994], + [0.23682051964737638, -0.059433377500039616, 0.004916470582592755], + [0.25977005853527263, -0.12254429622003536, 0.0034515850958308325], + [0.24552955445990585, -0.11248593464935762, 0.12542243381793625], + [0.23333643772954643, -0.05897859450504416, 0.3056362935554619], + [0.25867257253374454, -0.2070292864951642, 0.31759253124546494], + [0.25005936667541057, -0.07062820657982007, 0.2439405855300714], + [0.3120761680429918, -0.19276667322647514, 0.18912213815153522], + [0.17801918342867598, 0.12667476910313463, -0.19280697705215344], + [0.18010102380770246, 0.0649802815005016, -0.1322288387908978], + [0.30021326106414287, 0.0446255581062867, -0.31100053437873326], + [0.3208327301131329, 0.06843964192146826, -0.17641854347870353], + [0.2499666409154592, -0.061244998920011985, 0.06159306166896812], + [0.2553138291197604, -0.007604281729493465, -0.052715928031933514], + [0.25335508484100777, 0.062161690978438496, -0.00010681772412424795], + [0.3135775144614078, 0.006849266082494418, -0.00316093358197118], + [0.1849522639068532, -0.006723309967410234, 0.19078097598829752], + [0.20146998255062853, 0.06401131612269038, 0.14354182213596794], + [0.3120086457290628, -0.003369307076640225, 0.1284365983591613], + [0.31942596033706777, 0.0654406595873673, 0.18982153406850616], + [0.18383324408501772, 0.06483224769082227, 0.1832926007833056], + [0.24875621702509487, 0.06770676558339506, 0.326934780254866], + [0.2635871467960033, -0.0023698441372938363, 0.2540165717496873], + [0.2436193284122828, 0.06618806159919437, 0.45028127822001507], + [0.24644245427604858, 0.2361680037729949, -0.18579466537177577], + [0.2620562863987258, 0.25433468794871794, -0.06449076200739429], + [0.25223532001205695, 0.1278759603815905, -0.06630512713683219], + [0.3302199269892893, 0.5929040826331738, -0.08382862863443528], + [0.17434487213880417, 0.3145337954524723, 0.058570229432892806], + [0.24836112645363417, 0.3588222976522555, -0.06280584922437443], + [0.24510706430274196, 0.1269939052434267, 0.05642950881071475], + [0.32085042940976094, 0.18789148571744066, -0.07761663165995561], + [0.25099062270835726, 0.4565859372100933, 0.1287363925759971], + [0.24336812143598507, 0.17019446232907276, 0.18403711206826928], + [0.25262664265009405, 0.19657416180545959, 0.06042261503600869], + [0.311113313669389, 0.2534507895017208, 0.18377106238539126], + [0.18076666033023395, 0.2004648314615298, 0.37216680411446373], + [0.26788556083702075, 0.17146183952326421, 0.26059120261179824], + [0.24878832159979744, 0.31531758462124787, 0.4313517879912329], + [0.2281327838419191, 0.35984593396899234, 0.6103858588064753], + [0.29293270854877324, -0.24040883402088753, -0.12110528824280775], + [0.3221030367244909, -0.31009877733500163, -0.1938344931611834], + [0.35437369350948733, -0.20946854602220982, -0.05176446781434636], + [0.4961413973634901, -0.5471557695657016, -0.21564054925350074], + [0.29382872124691606, -0.3033925690053932, 0.07179462439970016], + [0.26642404456105145, -0.3020456959055716, 0.007032132587096638], + [0.2568054625461089, -0.38337967246876814, -0.07009932709344739], + [0.345316656891322, -0.23132397574991811, 0.05338892628748243], + [0.28650026505888043, -0.4414769794266292, 0.18545351892434078], + [0.29804112411457456, -0.16707193633465967, 0.07122751734342687], + [0.3072417304944519, -0.3354876685843288, 0.1357107869915631], + [0.39473275021242, -0.25792261032916125, 0.12184752243349112], + [0.4072392878917179, -0.4108625339642536, 0.4044719303997008], + [0.3463601899806027, -0.20984886113038248, 0.4137323767712169], + [0.34656983589198753, -0.25105962631294054, 0.25093252640642627], + [0.3597395262990511, -0.2718222139794412, 0.5934358194039164], + [0.3635395741737264, -0.12609225536137866, -0.06888799455982414], + [0.3646267563416976, -0.12224046359416142, -0.13203202889984625], + [0.3617870143285281, -0.06190109121614064, -0.11238975917012589], + [0.44026557637833186, -0.0017690542953064051, -0.32804239442743927], + [0.30898564770841214, -0.12348541502483754, 0.06796351947268783], + [0.0, 0.0, 0.0], + [0.3653640794877501, -0.05529882429498321, -0.0005782173883743483], + [0.38203129702721483, -0.1925820825903085, -0.004544872826320138], + [0.3168625531470055, -0.05820256184652277, 0.05722603593033484], + [0.3968848069438796, -0.06976758267283205, 0.19254561986213495], + [0.3814388142221534, -0.14814103802782247, 0.13925309981879525], + [0.43281655083155757, -0.06336339807332775, 0.06287907832436317], + [0.30876547252488856, -0.12506990977943755, 0.31612351509117864], + [0.40033325196764225, -0.1035069897580217, 0.556868623498039], + [0.39090028341288285, -0.20115743792187094, 0.2585479527518355], + [0.45438385649182106, -0.06361302777645393, 0.18780693754937447], + [0.30606210478605295, -0.005264706116142922, -0.18141690641055885], + [0.30263007785448587, 0.0031132614920656703, -0.06010569012010816], + [0.3563656233233968, 0.06957773483902506, -0.19073158563039452], + [0.33219819233442044, 0.13325698733000385, -0.2521069044573329], + [0.30738995235181327, 0.06383847122092136, -0.06060110296197299], + [0.3798621151601914, 0.06145294832863631, -0.003373017396138032], + [0.3789872011848561, 0.11154530619030664, 0.0013707078372120112], + [0.42408033877543505, 0.0009802966955310532, 8.473210413309817e-05], + [0.3137872237438058, 0.06658188052548658, 0.058960028874271146], + [0.30878447839156575, 0.1254713257184501, 0.12528112993477403], + [0.3839652335583626, -0.00010351864286987376, 0.05858466276672727], + [0.46509288558931144, 0.12296766701410262, 0.05351529384790746], + [0.3114768700518261, 0.07999339062154658, 0.25553965075309265], + [0.37845669616933936, -0.0034976751807593628, 0.3094395842470371], + [0.36818549710686743, -0.0005246364526521909, 0.18652723868871993], + [0.37351799962228804, 0.11955196380578809, 0.18074365016443075], + [0.2920843291357578, 0.18156478783971663, -0.4477188147799647], + [0.3232377427069229, 0.19231008151358336, -0.25680545035929386], + [0.39494796751167627, 0.4918605983015721, -0.38111575762558225], + [0.4290309038554279, 0.2335283279735721, -0.1917883114663785], + [0.30815237534190737, 0.2507929175749215, -0.11259655610583416], + [0.30740837223732237, 0.18278320280945787, 0.06211097236101559], + [0.3168619260227277, 0.3069875786522106, 0.0055557485396956355], + [0.3872737975811151, 0.12001535900937464, -0.13526677340959403], + [0.3204987619509608, 0.24377921357007634, 0.05820715547127705], + [0.3610548888706922, 0.32922001865776224, 0.11693072518782599], + [0.3639290136041201, 0.19000405737073817, 0.12563726539692083], + [0.41569664380999877, 0.28978132862665534, 0.23774341520194953], + [0.3367979106163099, 0.4262277564226109, 0.31213866088428555], + [0.378392671802769, 0.11247471623322096, 0.3914509148274129], + [0.37770333357906205, 0.75747883218744, 0.6590864164692091], + [0.4275465868859057, 0.1211373796488278, 0.6283674016481546], + [0.430124877735975, -0.2563762154928218, -0.3109679826693675], + [0.4428003833541438, -0.23995051239138673, -0.1533942605911765], + [0.37971426092044663, -0.37594187364121195, -0.25646442059695124], + [0.5775587260169532, -0.2687722739490971, -0.12862910193410365], + [0.42806496575747904, -0.23305951266709074, 0.013737743033625365], + [0.5116798593558051, -0.4554844978880442, -0.05591086837689801], + [0.49645100540823206, -0.3102234480988466, -0.1374039163215288], + [0.5279487882790136, -0.35266384907952086, 0.01391419391020529], + [0.4705190263612911, -0.3151498788871682, 0.18566253226425006], + [0.3930487420237906, -0.3625475712445257, 0.13180805133478976], + [0.49507528992106054, -0.209998553134488, 0.08335211574403667], + [0.6344232159267956, -0.27477118924305716, 0.2015654688198906], + [0.4734297493320723, -0.31329535087325044, 0.3108590786916656], + [0.48620401714763467, -0.25545800560847487, 0.3880618155426998], + [0.6311848099097385, -0.5737549933444511, 0.2948580400328214], + [0.6176473477456108, -0.43104467562571175, 0.20658990173876005], + [0.43668698899955755, -0.19800508576520756, -0.25960063889850216], + [0.46540152472549723, -0.18106245883697156, -0.05224564186785583], + [0.4137274767456518, -0.05610057985548646, -0.11176839337437287], + [0.6105162780884127, -0.18230671318099878, -0.12640753958597292], + [0.4484508048975682, -0.12029157453873977, 0.014576248986403067], + [0.507582008329083, -0.13151936604466877, -0.06160477670178556], + [0.5662997314082179, -0.11205542649735595, 0.011312487457617756], + [0.5791465912077995, -0.0828115327943598, -0.049256618638203915], + [0.42196526369044257, -0.0719263788352904, 0.13136617102970496], + [0.5239214748805083, -0.184829732890868, 0.12688605388173707], + [0.5968072269849141, -0.05610847181842859, 0.14067602728338946], + [0.6566691227468723, -0.22152254482309028, 0.18752009371619], + [0.451738820264754, -0.06839342765236191, 0.369928273925618], + [0.5151577254695215, -0.12977516002622255, 0.17425883907551568], + [0.5802111069233887, -0.16607250513277433, 0.5620023949612472], + [0.5434026617650991, -0.13104881509996488, 0.2661077367458016], + [0.42485459466461, 0.05064671871173524, -0.18097943111121068], + [0.48555859830246445, 0.10445924339060556, -0.1944921568804114], + [0.534010973388509, -0.0072184434739387595, -0.17634501750876294], + [0.6064228785521029, 0.00704221373850581, -0.31431964925296174], + [0.44814562272568104, 0.04792100497725338, -0.07308854244845267], + [0.48665393187144607, 0.07210737518232668, 0.0018228318680952734], + [0.5101097923113616, 0.11440462238151565, -0.06141004747807075], + [0.5048631151107241, -0.058235402722358644, 0.008337934126703807], + [0.43307326318940403, 0.06702606019134504, 0.1747479517144148], + [0.5228492916458249, -0.011041924965536014, 0.1062815313016573], + [0.4903133852542357, 0.06524865183295726, 0.1184409088525723], + [0.5648420720098392, 0.12077418223798853, 0.012303490217630475], + [0.46356793852846556, 0.0765708309493321, 0.4718999852006602], + [0.5225973628092269, -0.08475711630292589, 0.32254449497202997], + [0.5875800720017704, -0.015246826160527104, 0.2585978414343249], + [0.5833181165974213, 0.04231582274273297, 0.3834489426261142], + [0.43629168212942404, 0.29985299863088877, -0.1326431858302452], + [0.4516950898710371, 0.18468412256142178, -0.13461594563230786], + [0.5722626781337753, 0.4786172135921705, -0.13170212058972022], + [0.5247526377705553, 0.2727256399505961, -0.1250629331293589], + [0.4331514531818492, 0.2519743972306341, -0.06219542642396448], + [0.4432422409419186, 0.2495304544969467, 0.05211224208798823], + [0.5087009527784507, 0.23288811101175802, -0.061575495160975824], + [0.6378271764783549, 0.11413020433564731, -0.13917577153843583], + [0.5182546416790978, 0.37670674137075066, 0.05256622297465254], + [0.502201592666999, 0.13401873309952259, 0.11367291298436293], + [0.5055289888639426, 0.5377060932865153, 0.10092884366106677], + [0.5803848399534649, 0.19699319479507812, 0.12256860590622605], + [0.5063507594653625, 0.164387630997151, 0.25849559456336496], + [0.5103103799722174, 0.5772607656186648, 0.35672828050104083], + [0.5324691965920911, 0.23394825999014865, 0.18047114270302192], + [0.548258643729832, 0.2875873640235663, 0.3827871344219778], + [0.6296645941632402, -0.3175661917546695, -0.1672848887471576], + [0.5961789438293958, -0.20880193968681535, -0.3117263990883959], + [0.8046227939997149, -0.43456711409533305, -0.38020516767248613], + [1.3420896505172681, -0.2048760373090365, -0.3238358933454639], + [0.6957339741820671, -0.3331170302242934, -0.055460932331901906], + [0.7877252847626742, -0.24667824894709936, -0.04924856364590067], + [1.0898268202633012, -0.20128028421377683, 0.06897180640285862], + [1.0015984466820722, -0.43317614635557694, -0.03350884270291738], + [0.6010169390607991, -0.25835573954961916, 0.14268202771333494], + [0.7404911072452663, -0.15569904764334178, 0.06399449438436462], + [0.7931448511522405, -0.3253529130042968, 0.1401287485123613], + [1.1590359482393386, -0.14956853218882124, 0.30896226348495087], + [0.6620631864757286, -0.34052949645903646, 0.5869832515396731], + [0.7504623083053079, -0.2587362821100911, 0.33007946851096787], + [0.8526602734678297, -0.5189724982265909, 0.34248380461010963], + [0.9999908722108704, -0.3155417979256972, 0.5001953372272983], + [0.6083164823324358, -0.08420560776167689, -0.15853960859875052], + [0.6958719124111105, 0.04719016379864609, -0.18927374073957656], + [0.7979932364807368, -0.08086156024638388, -0.19737710510784834], + [1.1007232382682361, -0.13440624783075303, -0.1560385766048004], + [0.6505644456236719, 0.060593205861388416, -0.05581155274310426], + [0.6746678023179425, -0.1257906821553251, -0.07159697581196155], + [0.8563241605967692, -0.15368129002717837, 0.021015087280306755], + [1.4091458548560385, -0.035699698188107316, 0.01664295437910036], + [0.6383130263682824, -0.010092282087357546, 0.0652638285934699], + [0.6951961770756201, -0.08424981988931661, 0.19242573999410661], + [0.7866013764212921, 0.025286589918613014, 0.0019667492716714087], + [0.8405001846035041, -0.02766030446701932, 0.13378988623472254], + [0.6183857506167953, 0.04632824556235049, 0.24980844312603503], + [0.6916678205410006, -0.08120165252105707, 0.38740991803823166], + [0.6703513425616832, -0.002098202068560062, 0.4720467430929059], + [0.9497335631193413, -0.08055670223073114, 0.27051324571977103], + [0.6862508097782307, 0.18284855838926314, -0.2956872372091554], + [0.7615864036986668, 0.1382959027995314, -0.5007667313752929], + [0.9791753635234395, 0.18130399591122784, -0.2709732741627507], + [1.7894731394888446, 0.09585785568193536, -0.26579211937339725], + [0.7557933624889395, 0.17615621892082295, -0.11253527033890962], + [0.8714076167228566, 0.16402741241241417, -0.04810756308056509], + [0.9435405022415306, 0.11513677147623584, -0.005622663925241235], + [1.1586813238277722, 0.150599694793572, -0.1868985169454276], + [0.6481741610127111, 0.1995059227976009, 0.2640019058781095], + [0.609803668722309, 0.17728343678098923, 0.10593183966579775], + [0.7191388630092789, 0.16467288527374943, -0.007780993919261772], + [0.937683582490841, 0.23312333505645202, 0.26221980852196386], + [0.7005645016630068, 0.16795581851338487, 0.4246987645632371], + [0.7712031463396831, 0.03000443633629534, 0.31692675525007324], + [0.9354750573569682, 0.11213032710319931, 0.39597059099887105], + [1.4122836330257944, 0.17292721015094473, 0.42423793787282876], + [0.634470347354299, 0.2113597479262934, -0.07510617097213139], + [0.7055040407489003, 0.34293757018614246, 0.0011760184185905273], + [1.0635817275185153, 0.9275070618619365, -0.3055440569606113], + [1.348260971879387, 0.33011385413439936, -0.24280245858211638], + [0.8532924789781371, 0.29806269835282906, 0.09641593880333457], + [0.8879525714786658, 0.44859436046110684, 0.008089413080893773], + [1.1085025775577073, 0.3403561632465263, 0.03181923102812545], + [1.5050735756391185, 0.41154990930958774, 0.11200471588770505], + [0.6326933124166291, 0.3599207180606128, 0.2448691368298742], + [0.8809980729909634, 0.3628136970062086, 0.288463172165537], + [1.1174409910615446, 0.6031343876796391, 0.16032973777345388], + [1.1916234360077667, 0.215550340456355, 0.17979830738497543], + [0.6771108024143487, 0.39453487840691176, 0.4099115059762074], + [0.7784294333022357, 0.3648372912976967, 0.6698474028301322], + [0.9336023960196871, 0.7248897856494854, 0.465190998447004], + [1.3394291871647444, 0.6578665744980723, 0.5872072697819417] + ], + "ok_PRBA24": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + "PRBA58": [ + [-0.4200514339848457, -0.24263042803381735, -0.25676478238661815, -0.05272401948331154], + [-0.3481804161096019, -0.11126161318827323, -0.07572678462915161, -0.04656090641892953], + [-0.23628597172195587, -0.2879112473373222, -0.14810173834789328, -0.10030238761647353], + [-0.15197012879733918, -0.08006457240476096, -0.07990790498745358, -0.19245254730033232], + [-0.45404648843286255, -0.07454741743348917, -0.16245161723470294, 0.15338857794369487], + [-0.21134100537519712, -0.042086200962798685, -0.11820587005587367, 0.08234931291576815], + [-0.1679076058186054, -0.13962497398507406, -0.2642209251695529, 0.07024802705568682], + [-0.18364435871676404, -0.11472435369861511, -0.14867119887587432, -0.04363284099762593], + [-0.3201383429685447, -0.034857432277677375, 0.13389637918238395, -0.1194822257400122], + [-0.2885619592936976, -0.13646259142864506, 0.17475045430326216, 0.006507664155071895], + [-0.17869351343814202, -0.22308171889342146, -0.0064069078707442466, -0.10038645616783039], + [-0.15929873657347016, -0.029511991061604324, 0.014138387202977923, -0.09666232781377307], + [-0.38904856834312224, -0.26893198532274964, 0.04785665195080539, 0.03173880169125718], + [-0.1991415707137069, -0.20313119536053278, -0.07391700577171262, 0.04118640481312968], + [-0.16340177811346798, -0.14888557621675014, -0.045612284203349424, 0.16279328690752795], + [-0.14838322280897073, -0.08025155608774323, 0.08120193417088978, 0.12045830190089611], + [-0.2998950513587096, 0.05891543762897498, -0.19972133684971613, -0.0824980634057598], + [-0.26295904039161405, 0.147793552956286, -0.0378424639313591, -0.12799131589887733], + [-0.23769127034789195, 0.07928613832601068, -0.031969704749907554, 0.0114292708096022], + [-0.20458263404765195, -0.0005974058480650336, -0.08953666454590974, -0.06872799923616595], + [-0.4538805215760112, 0.17236768110328726, -0.06576515427956173, 0.033609268980397254], + [-0.30712569159828523, 0.12713007035218551, -0.16576896763825855, 0.09267660582263351], + [-0.18101206310608395, 0.2658429350057382, -0.058178119690441926, 0.2656230192320801], + [-0.17619751489629387, 0.22877794546017446, -0.1157199070521056, 0.016318122973654817], + [-0.31291229595785064, -0.002649771254209981, -0.000962914118413099, 0.08796643441734911], + [-0.2607020270388309, 0.2644310049562731, 0.03945627434601261, 0.09779582514283464], + [-0.24314552012016083, 0.10804897305412679, 0.12065774575783227, -0.04450378711028717], + [-0.17485305110801674, -0.01300518023966662, 0.09002956860761287, 0.007482896570870206], + [-0.4088396185548862, 0.05512243660517608, 0.09555326683848304, 0.19920186111998078], + [-0.16967180646570476, 0.0982829677778393, 0.20885142561058026, 0.11531911869862163], + [-0.1857664410579246, 0.0035267757519997023, 0.0032140670794205315, 0.26776206916453], + [-0.1752472911458623, 0.08604599494219599, 0.006856729224618713, 0.12913705675967427], + [-0.05866368731609202, -0.11759315472957434, -0.24729617186546632, -0.15001706891306232], + [-0.05446242923324676, -0.2226969611432587, -0.11246420926721103, -0.02273023147795833], + [-0.043292198652675404, -0.16814609461791832, -0.06473177253586025, -0.12047987913838747], + [-0.04238146203930867, -0.031794568624414404, -0.09440073032823798, -0.08172211013712535], + [-0.15904664623946924, -0.029615574488311546, -0.017593549766297643, 0.03621124909987433], + [-0.08682086288876177, 0.013995804204755869, -0.17264675158041443, 0.16038291322909282], + [-0.07718124167531246, -0.0778301246447927, -0.06992426799956294, 0.047227680466455], + [-0.04554615300942975, -0.1934995436504821, -0.05784097975108678, 0.1038161557847826], + [-0.09600974076221835, -0.04921573142139842, 0.10482664662873789, -0.09522674396999087], + [-0.057164372725172934, -0.008494319360866068, 0.005592145422548724, -0.010980074562129061], + [-0.035886726277946444, -0.12986711061254036, 0.033004342596499835, -0.03209589787356218], + [-0.021648699174059274, -0.14714171651536587, 0.1997711956628156, -0.09256361511401205], + [-0.15083289347641043, -0.10820369215087126, 0.021501217809149594, 0.0023042325260256478], + [-0.036314454038937634, -0.08576340611294168, 0.033033853832175886, 0.08344589642639005], + [-0.03245389978287286, -0.22449243821559756, 0.12352260143469158, 0.061192176606759664], + [-0.01777345113677424, -0.012025922208242801, 0.16183235851321606, 0.14993296609843848], + [-0.11087401670132609, 0.12547489764261865, -0.11535767128009769, -0.13183106379581966], + [-0.09667622698038401, 0.02280225160185129, -0.18762792638728037, -0.0018934756146443317], + [-0.08575398074694097, 0.38120978153945556, -0.07175590630523965, -0.09155713099251078], + [-0.023693463904407436, 0.09827926512384436, -0.06179637835538445, -0.007300489916086017], + [-0.13970258423199003, 0.203520188651126, -0.27608663248362075, 0.13220244429082795], + [-0.11004471778075407, 0.123979136838089, -0.1211675031343163, 0.05834142662754658], + [-0.08666675872381033, 0.01876086690851651, -0.0784086062448669, 0.03274883510307435], + [-0.035114399606442095, 0.203343113737508, -0.023452910479217368, 0.1207554775363019], + [-0.1258790415490992, 0.15862107937645606, 0.06867507000909079, -0.13719964405596333], + [-0.10835346929341619, 0.08003548009919262, 0.31175405881759904, -0.103117844295392], + [-0.0926254161715312, 0.06471314968179212, 0.008088780134581974, -0.07620273972919377], + [-0.046197241377120724, 0.051240935994102454, 0.1441424970537192, -0.022211529942305575], + [-0.1275613604334274, 0.14795081088348336, 0.0035614923197637236, 0.01246039992623803], + [-0.08502550799405965, 0.05002926049593914, 0.05365222654876924, 0.03763707027709429], + [-0.05156068701468853, 0.13916187447256942, 0.11633040980020136, 0.09784270468105039], + [-0.0551304191319547, 0.04349488771567491, -0.018116208893748778, 0.10491371540119686], + [0.053150991607270895, -0.06256847086936289, -0.058309072953046666, -0.22600456098175656], + [0.06140452406999613, -0.12912573600251342, -0.08910730643299274, -0.09741950375404583], + [0.08123334966052924, -0.017388159857787334, -0.12903217664497713, -0.017204932263860852], + [0.09102237688417579, -0.4216994442674059, -0.14340548138339562, -0.049852172735670636], + [-0.011551261470755888, -0.052661909686281275, -0.04712560103904524, 0.17170774896593152], + [0.015024645396854244, -0.08080782352349336, -0.19850911657993592, 0.05353529597656003], + [0.015067206262182909, -0.09113935261311663, -0.07532360845390748, 0.023736576858248946], + [0.055685494551406964, -0.1859949335778624, -0.17308292835301273, 0.14634967910285987], + [0.006583327046390892, -0.034996798036470156, 0.045784727470961434, -0.08893275349358036], + [0.026871351183173155, 0.02753707923313864, 0.10764589813398671, -0.17173981987430825], + [0.11020839657918707, -0.1734683295420081, 0.09789408118237687, -0.17535615395747656], + [0.10036609214265749, -0.02930812958753216, -0.02315842808068653, -0.12007100723513364], + [-0.007999162628015049, -0.03933703132443067, 0.10584207537262563, 0.021974167756311235], + [0.04443996028652198, -0.01739827626299338, 0.017264137075239428, 0.0765378273324338], + [0.05113280980826019, -0.05084479952654763, -0.0229229223154522, -0.02407513043856075], + [0.07342023497251828, -0.13910103067591698, 0.06639895771571291, -0.01615330452930237], + [0.004380156547362564, 0.06670731422131052, -0.035395117240477905, -0.20577981138696835], + [0.008440074375404366, 0.14126699993760894, -0.183740965716313, -0.0389067313688276], + [0.021841367030090958, 0.03572400638947211, -0.03988436222483696, -0.038924337610599546], + [0.053235533952774354, 0.11532065281742272, -0.012418003424484628, -0.10248896881088135], + [0.010052956284229907, 0.042106979782565536, -0.11680383254144149, 0.07822304443037653], + [0.051821270064998044, 0.06276461964651313, -0.2852999093984982, 0.17281250837205095], + [0.053945487728535794, 0.26620996365972777, -0.12688736597440095, 0.08421209748780352], + [0.09478876181833361, 0.1014719950585741, -0.0739801561756529, 0.048178804573618235], + [-0.01616480865135702, 0.12061857896951172, 0.04169199033337119, -0.03184932510029343], + [0.001015473609763264, 0.2749313391974564, 0.050796008383678586, 0.0015088545916886404], + [0.07282938797293916, 0.036471688086690796, 0.0694234292307082, -0.019140861506658006], + [0.10685836083683042, 0.18305843700310565, 0.09137376183177894, -0.21252419715823812], + [0.04837732463290045, 0.07829357248385314, 0.038177105757681636, 0.07034668720874873], + [0.053773046267083346, 0.09929930272756961, 0.011465565997160618, 0.26302114959947925], + [0.06842227231511253, 0.13620372529100272, 0.26317470121256514, 0.023785075892744777], + [0.08230588300875692, 0.33541608857321203, 0.15894692733075208, 0.13167827015814398], + [0.1977263253550615, -0.11030534097343737, 0.016528976158421728, -0.045270287301597906], + [0.22658752952457403, -0.17338665492180497, -0.1527397862245376, -0.11673099054510681], + [0.30228114310252974, -0.09853326979459497, -0.111220767896878, 0.035391069938604525], + [0.49818250349593984, -0.1947173269095915, -0.11863977915620635, 0.02327745076969436], + [0.10222320189167164, -0.18082305173069382, -0.038380952791341044, 0.04205195790699446], + [0.13215148390954357, -0.057115361975071735, -0.03562054667043068, 0.06872128491079095], + [0.16277764446394555, -0.000969906900318314, -0.11297732771588366, 0.17169210638096316], + [0.4273494001142847, 0.014838555877822478, -0.035304270402859786, 0.20826416737097603], + [0.13535771123420737, -0.020602767165461798, 0.14759754242817372, -0.0915468465456157], + [0.15287465986548862, -0.12983486244508627, 0.221109708609476, -0.005750716840513378], + [0.28606529086270865, -0.26812001870122737, 0.12626729973637213, -0.09110943801552629], + [0.380848193130777, -0.1278930592881957, 0.10222082012902786, -0.13351609106990486], + [0.11701814070309108, -0.07964068303474954, 0.09183170449876121, 0.1798143672172824], + [0.21610408764975347, -0.2258786542454473, 0.06940855269412992, 0.13125381241699993], + [0.2660046149449228, -0.037423332852993846, 0.05450342415508454, 0.13841580120835695], + [0.2901935886438043, -0.0033457640775016308, 0.24658832965280866, 0.006910745483741838], + [0.12394131322351486, 0.2772293688238003, -0.22885867021415515, -0.0988021957070906], + [0.12934662785479903, 0.01590554080489883, -0.18775941643656033, -0.13100596509686405], + [0.16957863248185662, 0.18194704293141126, -0.079508971329066, -0.06845197042447095], + [0.284134380664525, 0.043654566270370815, -0.11723372582387712, -0.2468924904767126], + [0.1636615185396205, 0.02331619832044705, -0.020237861725849966, -0.0374578747670952], + [0.1673210901713704, 0.13762024625341035, -0.26143464103012926, 0.0499675339216833], + [0.20847118552617694, 0.026546636609498, -0.14531653612510165, 0.0013090757296978991], + [0.3754584049057246, 0.1712071185525003, -0.09980818156365005, -0.01886019455931081], + [0.23382155812498562, 0.07573029405951408, 0.024322437611495433, -0.14367833220114784], + [0.24324374218227923, 0.25391755791649817, 0.1625868470662002, -0.063714946708812], + [0.305057704050022, 0.04719615877055772, 0.0881381718972862, -0.0027222463437992406], + [0.5194722573202742, 0.18993061923690002, 0.0693198285480341, -0.006458368364726148], + [0.11593829634517817, 0.17615971229539712, 0.05022848315585478, 0.03093080613982305], + [0.1301949161438323, 0.035815966601946504, 0.13690597875598348, 0.06635631599288937], + [0.21372238883845, 0.064017808973788, 0.0064121320470338595, 0.04019151174134195], + [0.21955841009016233, 0.2367623980306797, 0.00711718230362405, 0.13904087178095162] + ], + "ok_PRBA58": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + "HOC": [ + [ + [-0.5990236501569216, -0.015244925870449798, 0.010788867143319624, -0.035585584929490696], + [-0.4628267502238494, -0.29900433812683175, -0.27193713673980635, -0.08497930303202557], + [-0.3194239595741829, 0.04184064027477536, 0.005935716953728274, -0.020602969107601593], + [-0.30729198716315387, -0.2535347620078778, -0.024712074526732776, 0.010740877358728113], + [-0.170344985168298, 0.13616974576279228, -0.18411793278154426, -0.021147496981009248], + [-0.1472506021757565, 0.22327334259576287, 0.04810902305459139, -0.03341322458544891], + [-0.14175657939883887, -0.013312589191542294, -0.011160118104292727, -0.01911690939216944], + [-0.11178268486284249, -0.10228206498349117, 0.16673981622692, -0.06274876328270376], + [-0.11546054095639774, -0.11067921079822612, -0.03535184529248888, 0.17706737183571394], + [-0.10043975479596523, -0.19279526677199205, -0.23408346858391538, -0.1037209867368118], + [0.007312543122702817, -0.01052992478468389, -0.022932593395776094, -0.014468817839753142], + [0.07647363219109964, -0.25941956432933333, -0.01318698002124503, 0.007650208810026331], + [0.10012079496012088, 0.04854949365637981, -0.21012686469739578, -0.011463000118689596], + [0.15725356584921588, 0.22733898477766726, 0.07470445253625767, 0.027493054488091778], + [0.1788586452057142, -0.02341112948896394, 0.004752045831770516, -0.012025785788362437], + [0.4375061736900847, 0.007496925938360731, -0.016950746169872386, 0.00012195814441571585] + ], + [ + [-0.4220285661618479, -0.03360257704346447, 0.030492726591216986, 0.008660798920373266], + [-0.2859352696416744, 0.17990831871134438, 0.12468094346363098, 0.02064491254527509], + [-0.19928371332371367, -0.21092019647190183, -0.0422050661652889, -0.009076179368111687], + [-0.17304372508402963, 0.0033415774200130574, -0.009128655321611475, 0.001051263063932255], + [-0.1565969736477594, 0.23706304438192247, -0.08306684558672704, -0.04507600270003425], + [-0.046460029504323166, -0.05293859920340914, 0.19237642682393177, -0.019857670089892598], + [-0.01663228169353445, 0.11666299561029723, 0.035961415546919825, -0.019787195601136086], + [-0.008210526574142014, -0.016337256138449732, -0.18927585575197095, -0.005456376851215988], + [0.005098808255571285, -0.047694228784031796, -0.0030770053596092376, -0.013016944364443646], + [0.013327677545674594, -0.02616557662527525, 0.0406207327151025, 0.19725581792612967], + [0.023517328647098566, -0.2653026232543367, -0.01676898899081802, -0.01772447709987925], + [0.13990021412966488, 0.24295400996018215, 0.022637653353097278, 0.007913718993160363], + [0.16058401798275562, 0.013922666906085672, 0.005808551334990309, -0.02322392018352545], + [0.19816207535412073, -0.15061291692751955, -0.18483552366153413, 0.04285947876557969], + [0.2502692205459511, -0.16936401336034576, 0.05545099965506476, -0.008422704231661074], + [0.405032532626187, 0.03959520592024227, -0.03824344495887376, 0.009813369725349139] + ], + [ + [-0.37081770536543146, -0.09560085977199105, 0.013168453954321244, 0.016924022729094827], + [-0.3202565592765443, 0.2233571562879583, 0.011228709392197701, -0.008500119944554825], + [-0.15223954831745193, 0.03175694534936315, -0.03131417447469201, -0.043340022464593536], + [-0.15017265894439416, -0.009843109737254078, 0.18051738937313397, -0.021158041872003677], + [-0.08909561885138895, -0.24041080450334534, 0.031170690326362376, -0.00680770416559044], + [-0.07450012300817982, -0.1389845529346756, -0.17737897443100523, -0.0016790871348345987], + [-0.027773589997179306, 0.1807885779841033, -0.1540170248132347, 0.010533185317216916], + [-0.024283212046803702, -0.0080614640179174, -0.006782658988675296, 0.16401074686058845], + [-0.010117416186162267, 0.1934885590396588, 0.05835488256115978, -0.02013382912706765], + [4.045199355413339e-05, -0.03787061988708384, -0.0022025619409778525, -0.01898497906079183], + [0.13919526645002642, -0.07545758920425126, 0.17132812446443313, -0.011678476471934885], + [0.1595957417518141, 0.018479118066312496, -0.008834104583741325, -0.017178879387513054], + [0.17942920548975846, -0.01027682122797216, -0.20737782457226173, -0.0057433291715728585], + [0.2178251551625741, 0.22050042760155503, 0.004479630685140451, 0.023249449602637893], + [0.22095271828235238, -0.22997134583740653, -0.03350774342857381, 0.013696773238111103], + [0.42935372119660375, 0.046324653991911234, -0.010237702937559844, -0.0011108307286457476] + ], + [ + [-0.45816556837500855, 0.1846709712707959, 0.06726456353557493, -0.0014341116146947945], + [-0.2858314760344795, 0.1896130737633464, -0.2032237653654037, 0.051854302669571375], + [-0.14709975139356582, -0.02635274843464839, 0.2058411019514564, -0.045291837869303506], + [-0.11400190136882746, 0.23215171971184512, 0.02544486132779012, -0.04748765629836928], + [-0.05475153213319262, 0.09069630941547471, -0.07233683420682267, 0.07519665259520121], + [0.02250772932497155, 0.0006132704326069448, 0.02280973940292966, -0.0404667457412536], + [0.16165581066184703, -0.05538566480650118, -0.08672204366466198, 0.07085654640963651], + [0.21220019646113758, -0.16751429603812634, 0.13252741192597028, -0.01098605067663194] + ] + ], + "ok_HOC": [ + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1] + ], + "VUV0": ["00000000", "00000011", "00001100", "00001111", "11110000", "00110011", "00111100", "00111111", "11000000", "11000011", "11001100", "11001111", "11110000", "11110011", "11111100", "11111111"], + "tone_id": [129, 132, 135, 142, 130, 133, 136, 128, 131, 134, 137, 143, 138, 139, 140, 141, 160, 161, 162, 163, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null], + "knox_b0": [120, 68, 121, 104, 98, 61, 121, 114, 91, 100, 94, 106, 121, 93, 84, 84], + "m_noise": [ + { + "N": 199, + "b0_lo": 0, + "rows": [ + [0.8336179954796323, 0.8233030431649094, 0.812638365173181, 0.8352488072118218, 0.7199014558178732, 0.6465114425988738, 0.5960135233445241, 0.603884330390626], + [0.7628962233777113, 0.7561791561286565, 0.7834858927700737, 0.6708576456871221, 0.7217891202567501, 0.6210582748823597, 0.6718252077829516, 0.6487267828122032], + [0.7757565107158452, 0.7226551747963342, 0.6844242248267147, 0.7688278126986334, 0.691013925777336, 0.7047792050926515, 0.7347383886478728, 0.7163000639160991], + [0.8028437231869509, 0.7222827312862251, 0.6733411740785626, 0.7199289871605388, 0.7183837989359403, 0.7731957430757426, 0.7281519271021912, 0.7570607128623406], + [0.7182919623463386, 0.8025120231548329, 0.667494291942108, 0.8034556612796143, 0.7346819353913271, 0.6229887733484513, 0.5571772504113022, 0.5765981976027424], + [0.8076544299779256, 0.8476262539055601, 0.7884616142540535, 0.7621392674190083, 0.6568706323207549, 0.6290747045407663, 0.638546650520434, 0.5363337911485009], + [0.7868494817754654, 0.8506909243789652, 0.7802584866086875, 0.7232089266569304, 0.6281377504128727, 0.6192629649895119, 0.6636337485321684, 0.5929586749441492], + [0.7691823985019188, 0.6565178869300874, 0.6936639401750125, 0.7519270116494152, 0.5826065319575845, 0.6755986536999447, 0.7003237041481393, 0.5677060872984818], + [0.8472108493727798, 0.8726087186894101, 0.6198592770634278, 0.6658080159253859, 0.7819627186003827, 0.6428144321541704, 0.5733000973160529, 0.6085761027679428], + [0.8121489966532995, 0.8364499760157396, 0.6919960984024698, 0.6562126927982082, 0.694838367283604, 0.7487622349792831, 0.6859395335785176, 0.632062950215257], + [0.7365049879735358, 0.7687123865158274, 0.6696700099969847, 0.606493786192629, 0.6456595649739656, 0.6969737997247498, 0.6828634652305902, 0.6890712222678526], + [0.6956110759601614, 0.6703365068090759, 0.7957012168069475, 0.670115381873074, 0.6411689725622687, 0.5925682037514232, 0.5964491989869506, 0.6035451020545572], + [0.6769627785704615, 0.7967841123864905, 0.7740334376086295, 0.7588141171295477, 0.6455559798734588, 0.5577374309734431, 0.708640271301839, 0.5562035507560386], + [0.8455736313057214, 0.7628298188469639, 0.7311268197121104, 0.706627205239761, 0.6786187784937349, 0.5906252459104329, 0.5989037757630411, 0.6215122900968172], + [0.6390384079301994, 0.6388484796880031, 0.6905996500944241, 0.6444918900876827, 0.6433600758632438, 0.6044664935718749, 0.5947686510119602, 0.5312770235653429], + [0.8463673186169112, 0.8310867331055694, 0.7453432901619547, 0.6215030474138105, 0.6803584129457921, 0.6521254122399347, 0.5716307820825683, 0.6584249426781984], + [0.7877483005102679, 0.6940407552839949, 0.6647917660860745, 0.7136324922885336, 0.658122732855045, 0.6594117249189602, 0.6546213996634584, 0.5846031420093388], + [0.7203019463300467, 0.7780152147875473, 0.7660659458626098, 0.6741518119407413, 0.7078221864717915, 0.6889219565278721, 0.5494111166215468, 0.5337729562604436], + [0.7259652340210878, 0.7196393233135567, 0.6431238845893383, 0.6715549811401763, 0.6327796304170298, 0.690318289087168, 0.70746712059436, 0.508236347927169], + [0.7667608915142105, 0.7227291310350702, 0.6801602233236408, 0.6889610129587482, 0.6706642481300047, 0.5134827321673707, 0.5716192350130631, 0.6302972220057192], + [0.8022012429083725, 0.7483969460064179, 0.6839758040902741, 0.5809389789083709, 0.6665029924967502, 0.6316165408365281, 0.6376277521418255, 0.5617453797249843], + [0.8751673938105894, 0.7274233778156667, 0.696159198305711, 0.7215253361641772, 0.6173663529869455, 0.7203020279019587, 0.6756049702102018, 0.5548421627801179], + [0.8601012993777413, 0.7368800820057316, 0.6927174280517245, 0.643436753267044, 0.6937631591870689, 0.6691967483134025, 0.6048790057357649, 0.5231260739789956], + [0.6630404783777041, 0.732221076786709, 0.5804580184687245, 0.627593220880807, 0.6510093342957582, 0.5451163236496428, 0.5805707355171977, 0.5429226718419907], + [0.6841797981811649, 0.7605745019379775, 0.6086381470735301, 0.585792066186416, 0.6544211132398636, 0.600862625683899, 0.5847278949897874, 0.5140005010608683], + [0.823623017400958, 0.6862232168045931, 0.6382087758929433, 0.6090307827103921, 0.6347201921166048, 0.6504435344062287, 0.548379021181342, 0.5424467023913557], + [0.5494945255222077, 0.7700129051683791, 0.7052921940981149, 0.6003611579728678, 0.5934566395859144, 0.5306277654391942, 0.5869247031350258, 0.4827559276457394], + [0.8261370641045586, 0.8019330112882169, 0.6350840840128634, 0.6109402276393257, 0.4774199090615, 0.5729390581223703, 0.5867001423703049, 0.51901709913385], + [0.7622534603117316, 0.6904786414920673, 0.6228639068848573, 0.6495255483316351, 0.5868259895893388, 0.521430695038289, 0.6108764734140559, 0.544590830554843], + [0.7068870318647787, 0.6440593494817409, 0.6773542576264237, 0.6064466777971832, 0.5192501471458495, 0.5185867349138459, 0.5661056830385044, 0.5184488198620354], + [0.7333564221824794, 0.7615189726106266, 0.5817541558590487, 0.5997630302866173, 0.5895554759285986, 0.6012570499183884, 0.6304118216935919, 0.5887622485575773], + [0.7318321781223107, 0.6715286120795583, 0.6049285027357836, 0.6614976806542435, 0.5802381553873868, 0.6056052136123391, 0.5138245016812081, 0.5175063715451558], + [0.6416138802276449, 0.6574693458012355, 0.5776277684380365, 0.7056732094551772, 0.5270414955150569, 0.506858715752044, 0.5764824589178921, 0.45026199786648624], + [0.6753327174769188, 0.5906105523582973, 0.5026719941058578, 0.64926655603696, 0.5452308599139463, 0.5164940060121364, 0.5484542872638829, 0.475859578823564], + [0.5774178478151557, 0.6373147151732965, 0.6135537002868244, 0.6139901394549873, 0.5289459836819296, 0.5706550162639311, 0.5780982997642415, 0.4609199629120332], + [0.6555149847867596, 0.5506627597788862, 0.5440837155968378, 0.5058166935952467, 0.6330734644621496, 0.4454309699221382, 0.5037729851404226, 0.49912128817828555], + [0.6533591364255238, 0.7244906557703039, 0.6660575053894298, 0.5902356652877282, 0.5489535217893781, 0.48252077488878875, 0.556771063045265, 0.41067783115649215], + [0.7544098264144438, 0.5887682531375475, 0.5431476615523647, 0.5617691735838451, 0.5628113219934032, 0.5470542134301568, 0.4141053068860011, 0.47636042767188996], + [0.6280311187152211, 0.5753516080969485, 0.5692306500051887, 0.5239692196612387, 0.616702583286726, 0.46854722136062904, 0.5499537342307039, 0.40026967890541854], + [0.642175945857224, 0.6543998541902659, 0.7092437967084767, 0.5762127924984974, 0.5450957253045868, 0.5047583835685999, 0.4672570324268943, 0.5199729755767123], + [0.6426019772889748, 0.6906787319363052, 0.6304252118766347, 0.5636955527871426, 0.5059094560844115, 0.46848454680034174, 0.4634209755055484, 0.5138261863332606], + [0.7056203669059355, 0.5828221040882352, 0.5261957667484884, 0.5985779057789677, 0.5027945519158294, 0.524455988859401, 0.5216683371122044, 0.47742687442357284], + [0.6844950490655214, 0.5655844203884752, 0.4884291543779739, 0.4194331114126143, 0.48106484590481124, 0.5025002422508494, 0.4870367683369581, 0.4359740001566715], + [0.5954110586976167, 0.6623556888908373, 0.4952962065456168, 0.5320385903599051, 0.4747672345209797, 0.5112689006402203, 0.48191998321368085, 0.4828348901869278], + [0.5472020112785441, 0.6581625976781683, 0.6237120623621384, 0.4958153024546905, 0.4443212167305114, 0.5333922191628303, 0.5070813055243126, 0.4379175233092124], + [0.6374017623248753, 0.5883219057374864, 0.6007850650157043, 0.5299405975486023, 0.4740545944727045, 0.5092303702262452, 0.46242016483717935, 0.48838782697472843], + [0.6795404117981856, 0.6792539705117304, 0.6493878335305985, 0.4812543518521506, 0.507177729462171, 0.447362439457858, 0.43366768798568095, 0.4844163169474449], + [0.6229704077444443, 0.6028606923885909, 0.48951793912803954, 0.4763573129947267, 0.4301958288835029, 0.5359143506333321, 0.4348104416997684, 0.4491322097827509], + [0.5398548970717612, 0.5146123192630944, 0.5063669561584444, 0.510840158247467, 0.43748734467023576, 0.482818561982702, 0.45153303427043284, 0.4254994377591873], + [0.6471796392560472, 0.497295712036665, 0.5538635575924234, 0.5855285175104212, 0.5049048111205973, 0.46560734395194353, 0.43065984599983465, 0.4451266993012721], + [0.619868049834515, 0.6183279783166308, 0.5167058883469987, 0.5253582780567979, 0.5132353195216948, 0.4700241927273562, 0.46288739336633195, 0.44027894516203664], + [0.6523508666544899, 0.5279569854084031, 0.46716837552498347, 0.5171289920736931, 0.42564873395038144, 0.43121801198039234, 0.47004100089838646, 0.3491376300565451], + [0.5888332395677267, 0.6161401151009287, 0.46106537055491104, 0.5162091203340478, 0.43173161440776486, 0.45595998585561054, 0.368868294584449, 0.41215122237097096], + [0.541684347475185, 0.4946136950085852, 0.44248154518455807, 0.5205597892648519, 0.4805017408602674, 0.4110153274737743, 0.3850912297571302, 0.38390508605525353], + [0.6317809097746135, 0.5941848468365657, 0.46746648613044495, 0.387651566505487, 0.4914113048867178, 0.4405027989960472, 0.3612062876509882, 0.3899828572512228], + [0.64446343676862, 0.5759785660699334, 0.5166375414604016, 0.5252443163647965, 0.49340832583093586, 0.4389394429938794, 0.35910712571508396, 0.33172153127212645], + [0.5515758025540705, 0.528751332714269, 0.448144362316809, 0.3925856405583419, 0.40285227869699747, 0.39224400029927897, 0.3968799975461178, 0.43660102692711894], + [0.5465137500032907, 0.6126215782883977, 0.5092374908181505, 0.4716413100257112, 0.4653667990031258, 0.4105861994534079, 0.3608324736924887, 0.3939132941704523], + [0.56470712242641, 0.49256849606216685, 0.4984902625495518, 0.43747191305258004, 0.4249731632196449, 0.4045952072414494, 0.32753105325062565, 0.37457299517837905], + [0.5605288573169807, 0.5216361828647783, 0.47839934767439746, 0.42564359925052114, 0.43500336355035407, 0.34101375495342423, 0.3317927396497347, 0.32092077507592814], + [0.5408982031826419, 0.5032545120578389, 0.4809437941950666, 0.46766045164132536, 0.37055531429717814, 0.44133767905612636, 0.3852443868634706, 0.34112477153237514], + [0.5304413804347111, 0.4067759700132101, 0.33678808573003427, 0.4027060238017119, 0.41402899584429015, 0.40850478193232087, 0.35802729692461815, 0.3549627211517397], + [0.6249492129236803, 0.5181085475869497, 0.39117150830741104, 0.37635491979094415, 0.3464080563234699, 0.3329698763435948, 0.3482138586884797, 0.37620033649631596], + [0.5074649196327587, 0.5438404460244848, 0.48079897047406517, 0.3906098297329924, 0.40523574817504615, 0.34554331512923536, 0.37630747610730236, 0.3641764469637913], + [0.4904856350499361, 0.46493549821924923, 0.4679238624646637, 0.4282230377529626, 0.3152852410389918, 0.38040012224648495, 0.4023175694728389, 0.3435332793499048], + [0.49606252167338905, 0.449059112383048, 0.38346157997872204, 0.3518854051956575, 0.39370120337087117, 0.3354437937289667, 0.35821620643742463, 0.3377868282266765], + [0.5423017382931865, 0.4916556807055808, 0.3181752151509628, 0.3539640356540037, 0.29467582331475206, 0.3283332698213434, 0.34260559918416544, 0.26732871171033623], + [0.5156194332017318, 0.3527951993185428, 0.3718688481634136, 0.3983499339897642, 0.31546227988929987, 0.34483286048175127, 0.3670736100150094, 0.2698043382585701], + [0.43919024478646623, 0.4619882787602239, 0.41835723966290317, 0.2780897819019269, 0.39478815114749716, 0.3030890399791011, 0.3690786103238159, 0.33761785083429896], + [0.4173594130720072, 0.4793675535592946, 0.4079874135841434, 0.33734317768577493, 0.3230157568841733, 0.348908295559469, 0.33387742804214077, 0.3638048564475182], + [0.5074816020845082, 0.42611227079220704, 0.39554619580800865, 0.35159985606655725, 0.3736326634256167, 0.3091563875021339, 0.31208166899500306, 0.27104237792020947], + [0.5239613680029376, 0.4219019286410936, 0.3752625042676975, 0.347928157189356, 0.34468170479372323, 0.36509707080961706, 0.31530835037340244, 0.3256897620270819], + [0.4585297019229132, 0.4033381249968155, 0.4464491092167807, 0.306402245691809, 0.2867586328577326, 0.30207463892177416, 0.27599279787405095, 0.30549007706569775], + [0.3706174801033297, 0.38832078070558823, 0.321734716180308, 0.33175112838573523, 0.22804268009451514, 0.2753355972794096, 0.255811389862752, 0.32772038751042104], + [0.39290426426279224, 0.44825367557976037, 0.3874170477813727, 0.3326861453800205, 0.2772844949777903, 0.3001204952762139, 0.28745038222233027, 0.2659326714924216], + [0.461609340649794, 0.43159327931134633, 0.3271858504383378, 0.3342906712865878, 0.3029333471636635, 0.307953826884733, 0.2887875650330086, 0.30239731903025313], + [0.3775041401861008, 0.3523515582672179, 0.3943156916024935, 0.32368172934665734, 0.29020522317458974, 0.3249628458221511, 0.29941504331423363, 0.24984101591410493], + [0.520225761886593, 0.408401064519391, 0.326133986769853, 0.31748507558568756, 0.2622552007202989, 0.28034443926300845, 0.31735525789405394, 0.2861141334547913], + [0.4000839947303275, 0.348524518689443, 0.3217427372916911, 0.283278628269085, 0.26083164308308215, 0.28438553758043783, 0.2740999446372625, 0.23894495838958377], + [0.41564549342827234, 0.3375151264337993, 0.36726842944406984, 0.2830352268023042, 0.2106767736885138, 0.3240994257995883, 0.3033398615601698, 0.21805858111675114], + [0.3913168979952685, 0.3884680241485523, 0.30946594276512646, 0.2749894578048263, 0.24443754594689046, 0.2544498853444693, 0.23824809944922914, 0.2107901101164269], + [0.3778705720843728, 0.30050423734320364, 0.24464703740794652, 0.23797684555255116, 0.2635352552653506, 0.2889319535784882, 0.26709475243711395, 0.23176636073293297], + [0.3379196296729047, 0.31879990645939815, 0.3093930235421466, 0.23408318895991845, 0.25289021914973636, 0.24937850409451934, 0.25941164317088006, 0.24362395978082602], + [0.3768787118255419, 0.3620044647335183, 0.2693670267005054, 0.23038220548302837, 0.2243770186160862, 0.28248603010399975, 0.25782068485526927, 0.2210823804932991], + [0.3337641741958608, 0.31411924277250136, 0.28845728073022536, 0.23418737134831313, 0.242154611716081, 0.3184702410598658, 0.26540863610092547, 0.21836344665683938], + [0.409904155073706, 0.35096223692705686, 0.2818767006256243, 0.21674810102190725, 0.26274073189244035, 0.21680035754864366, 0.2343041113853016, 0.24455127481320596], + [0.3824260643710144, 0.28717304464595556, 0.2537841108758626, 0.21355167159652316, 0.23605195405389987, 0.26220264679544136, 0.2599779637132335, 0.24161642208392478], + [0.2982321140482322, 0.2970298277661672, 0.27806414416438907, 0.27812252138547244, 0.22310361455420227, 0.2195606003515508, 0.23192864093625803, 0.22760776986967135], + [0.32060545953950426, 0.3197845202250166, 0.32253989242440323, 0.24590235576201067, 0.20561925268937986, 0.2336868857253856, 0.2127653050603155, 0.19164004412517405], + [0.3150847225212071, 0.3122979151735093, 0.24850529147781658, 0.2531513617167727, 0.23499720386505712, 0.2535268962268208, 0.1793758920075285, 0.2044606137476074], + [0.3540266801231235, 0.28546358459256127, 0.2852850317914067, 0.2631211422875979, 0.2654781180340852, 0.22800109959428036, 0.2552489354254362, 0.21809505266407886], + [0.3507339823918298, 0.2777529890378376, 0.2686909382514299, 0.22047983554831674, 0.19952635479580672, 0.23721909864484672, 0.2722441464244281, 0.17186782793328204], + [0.23938701773388918, 0.2296884718030357, 0.27322762921114585, 0.24070266313416572, 0.2039072687227158, 0.22057149556141367, 0.1978873515350131, 0.17545470203564542], + [0.3640515754965942, 0.30693179484017774, 0.2446191583022888, 0.19375289296185502, 0.2503210952234104, 0.24318521811710597, 0.22797178871233956, 0.17778960187029552], + [0.3083798789367477, 0.2607398388741933, 0.20925740219954805, 0.22267355401965894, 0.24247217226441697, 0.24920534460173124, 0.22015649716113167, 0.15880231676119502], + [0.22552557680824323, 0.2666649007672622, 0.2133204956291052, 0.22055561964088488, 0.1937301634491157, 0.18314887427160226, 0.1839614067614604, 0.17774268845850377], + [0.26300774578674596, 0.2208816592839637, 0.191337092002067, 0.20736747460894955, 0.2054628836878531, 0.20630262597634186, 0.1771280183329124, 0.18198604142789443] + ] + }, + { + "N": 201, + "b0_lo": 93, + "rows": [ + [0.2917593681414562, 0.36695007868361684, 0.2637786089375999, 0.21968203059634558, 0.192208832325381, 0.22500021155768737, 0.22628952257637255, 0.1797545264052969], + [0.3168868030082868, 0.24311396643822575, 0.21506182168518287, 0.20349609900087234, 0.23369979520484402, 0.1978510851027234, 0.19304304215833207, 0.23594267898240134], + [0.3221758479112635, 0.2462906522065257, 0.21642987005778197, 0.1970963773608928, 0.16337074838194482, 0.21457993996004546, 0.21227768959032056, 0.18401438299221012], + [0.236613135638277, 0.25727797414353715, 0.16212553299604665, 0.2023034280451318, 0.22103885980049406, 0.16937822489748522, 0.17942234718148548, 0.1708226876561325], + [0.2508397413000126, 0.273599218493586, 0.21761960235513694, 0.2270308322397695, 0.22628221576565397, 0.22262012817747642, 0.2050450809097887, 0.20758571733005332] + ] + }, + { + "N": 203, + "b0_lo": 94, + "rows": [ + [0.27359175140419156, 0.278941814871947, 0.24043982872719297, 0.19998824612966576, 0.2135304262559361, 0.22533287827339038, 0.2253763935342887, 0.193786281695578], + [0.2768850588495018, 0.2270326317536475, 0.23000564097840173, 0.2373160553173531, 0.23071948421712743, 0.21353424846470626, 0.19933322991670768, 0.20352494656777126], + [0.30722260094901155, 0.22872501730210537, 0.22302491952998021, 0.2130262983768455, 0.18588390952469297, 0.2150998480171948, 0.18452015960264817, 0.22424567196427914], + [0.2912197699685813, 0.24723924351326385, 0.23096713233705365, 0.2016332551817467, 0.16343039264778117, 0.17781644113456901, 0.19281446381705397, 0.21111332409277836], + [0.3016669397966705, 0.23696570622231747, 0.16792896217567427, 0.22270477071953412, 0.19014638545819756, 0.19497221431572068, 0.18084737938020354, 0.17888561705164338] + ] + }, + { + "N": 205, + "b0_lo": 94, + "rows": [ + [0.2413122603607156, 0.2940682236678396, 0.23397925575858936, 0.23132076131752916, 0.20693510305025076, 0.22464639940231895, 0.2275958398060901, 0.2037608228139221], + [0.23831910513518034, 0.22962977985581168, 0.24972128305069793, 0.18355302777222626, 0.2169777451608575, 0.23963178888058673, 0.22341391920852233, 0.20016046218665637], + [0.23775834671956367, 0.2945449412176874, 0.21988931106916607, 0.24145900175092355, 0.18766357162096697, 0.2562939111413017, 0.24860577993725758, 0.20864715969488898], + [0.2848724055944989, 0.27580139956596955, 0.25327549123887505, 0.19264790519202063, 0.24432539681786553, 0.1797668044096011, 0.2388301574561874, 0.17163030704165821], + [0.3379886813740876, 0.20800851441484897, 0.2588504062901699, 0.2069477378461379, 0.17976267525449094, 0.16725548041833238, 0.21285704996349566, 0.15893170885236624] + ] + }, + { + "N": 207, + "b0_lo": 95, + "rows": [ + [0.3271643701549077, 0.23989196245952718, 0.2721142853109348, 0.20930746414966875, 0.2417178021867868, 0.1980746258557003, 0.21271659026941803, 0.22046461499720948], + [0.28524003436337436, 0.23986326294872576, 0.2153447462664874, 0.21063485968755208, 0.2597325881271722, 0.18295936468883656, 0.22838188492465664, 0.1914392490705246], + [0.34262622535777, 0.2673249766136929, 0.19197489897545536, 0.16556974339454147, 0.2021373818580725, 0.19773460693517614, 0.16407140939080916, 0.18821059788784672], + [0.3658697135451665, 0.24974452888450804, 0.23977295809239707, 0.193335992353865, 0.15968070242265814, 0.16428100744357899, 0.17208404421243145, 0.17970097763414733], + [0.25115847793901613, 0.2864687070840341, 0.21509684452905628, 0.2205992685847226, 0.20438368267678345, 0.23261992250873348, 0.19824818305036407, 0.15336656041748728] + ] + }, + { + "N": 209, + "b0_lo": 96, + "rows": [ + [0.2957323682487892, 0.26281318271257714, 0.23604331882808777, 0.22554153820823397, 0.2286668883412285, 0.23213826621290207, 0.2532393339425565, 0.2063029194265159], + [0.25201409737828545, 0.2713857280074512, 0.1735254098614177, 0.21919998351453687, 0.2127564526370581, 0.22190011600410262, 0.2023656080269875, 0.19881272494050276], + [0.2601932704631835, 0.26737489578801743, 0.22063165473489124, 0.23836202744664564, 0.21278806713617826, 0.2234307889512701, 0.2145146202252801, 0.19025823151473648], + [0.3433170582323817, 0.24408372676142323, 0.22817235466962685, 0.22740604701364275, 0.23485586094010372, 0.17252793005253245, 0.2404958120502521, 0.18137315189693842], + [0.3156508279839425, 0.293490429855727, 0.207136514633652, 0.2026538736109986, 0.19520682060574993, 0.18689389884296934, 0.19749467293719578, 0.15939453830552053] + ] + }, + { + "N": 211, + "b0_lo": 96, + "rows": [ + [0.34907254367095564, 0.2744795041496303, 0.25830831636319806, 0.26931020902026803, 0.19739125568180482, 0.25165328071717014, 0.2517957417202482, 0.1468069334229038], + [0.2911008251394761, 0.37505518534922266, 0.16291042603070363, 0.22468907322723225, 0.18810597048247837, 0.21518249973884626, 0.17823162731871833, 0.16723491187269324], + [0.2755458922367119, 0.2566932191378327, 0.2125523932862679, 0.24852736748700927, 0.21519290615478523, 0.1997867386159775, 0.21896362070530254, 0.23218842970465825], + [0.32643440947624847, 0.27101759153605504, 0.22149152574400263, 0.2223227031988473, 0.1937226663653841, 0.17519865018344238, 0.1750339544709298, 0.21991829883912214], + [0.2640130658152632, 0.22670344982840576, 0.2575162672361227, 0.20332763064482523, 0.2098583373914966, 0.1878829313672511, 0.21437886286329474, 0.16544317472712108] + ] + }, + { + "N": 213, + "b0_lo": 97, + "rows": [ + [0.33157765133080896, 0.2466925329140583, 0.2365017030978751, 0.2663434422578085, 0.19717614165446012, 0.23148729108652288, 0.268389297115604, 0.2085286111098557], + [0.27085491736843736, 0.2408421748144113, 0.25000758435227444, 0.235554811880249, 0.17254787614149197, 0.16951599469628234, 0.22191547820947505, 0.21827678203578943], + [0.3174639350339985, 0.3037937776640531, 0.25875248204623635, 0.22488257872096962, 0.21590643857453032, 0.19016803245883115, 0.20263151956763598, 0.19949543806115871], + [0.2603099823599402, 0.2885715651881757, 0.2223610008931938, 0.19494783335560087, 0.20548490542401537, 0.20086897344604362, 0.20859957163908274, 0.2476333538734957], + [0.2847498187011716, 0.2029156592397397, 0.23844310614166742, 0.195391406110886, 0.1809854952483817, 0.23449569608784274, 0.222533916344972, 0.1721992388658504] + ] + }, + { + "N": 215, + "b0_lo": 97, + "rows": [ + [0.4122772445411869, 0.3255961703691071, 0.28113210337922395, 0.20801584983150007, 0.21588419511812873, 0.24729741816702874, 0.2372475662049642, 0.22949926206020005], + [0.29806693133866935, 0.27534041268144244, 0.22541750493963475, 0.21614753620498806, 0.1957773399747885, 0.2204652698270934, 0.1906266179673534, 0.22048785907572022], + [0.2542082876776601, 0.29089121965435993, 0.19900742261861323, 0.17793278658998252, 0.21803689298707027, 0.21505772793109418, 0.18745271756263948, 0.1871984507284159], + [0.33987881192025965, 0.235055650493576, 0.21680353070271305, 0.2107773121671713, 0.1862622069567656, 0.215987001783631, 0.1754314333379778, 0.14885414292289895], + [0.3583027576890667, 0.24365945386776708, 0.2610419190338279, 0.2011079229790872, 0.19610293877135046, 0.2097995694630469, 0.21734048149662397, 0.213344661771396], + [0.23603584300108435, 0.2091969763846766, 0.1985713911908567, 0.19257890245350426, 0.18129798472732106, 0.19582044761932496, 0.23214239666295533, 0.20390939893960686] + ] + }, + { + "N": 217, + "b0_lo": 98, + "rows": [ + [0.3424896767331734, 0.24329657015234718, 0.22382955059327955, 0.21797331293163447, 0.2209597606664775, 0.20570727954808235, 0.1960496057109687, 0.23711642633514288], + [0.3064040012778316, 0.2402781576495982, 0.21713375180267266, 0.22247826852230715, 0.23491296933290587, 0.2030297679930068, 0.23485116271367903, 0.19262425400334873], + [0.28592460784649937, 0.28309810840973354, 0.20953906418619267, 0.22154931498656832, 0.20889010659676532, 0.23258829471837925, 0.23784064140655856, 0.23389260587160332], + [0.26777271914740164, 0.19798449603746313, 0.2284983112778047, 0.22944310368017792, 0.20722087337315515, 0.2025827742766746, 0.21214575218147289, 0.18850895947860097], + [0.32728340773186637, 0.2357980415841069, 0.18019813597578177, 0.1647251555316468, 0.20239942795082702, 0.2087422778133142, 0.21182837863444975, 0.16202644942081276] + ] + }, + { + "N": 219, + "b0_lo": 99, + "rows": [ + [0.26177226537095255, 0.2413339836888493, 0.23713486557676422, 0.2544671398903494, 0.22551322294439077, 0.19703652294831192, 0.20755191165928905, 0.1948621148088724], + [0.2812183934846384, 0.2808199593722218, 0.2186047193913945, 0.25701119691472507, 0.17466630599114474, 0.2110921110070324, 0.2234613726100266, 0.19833544828357136], + [0.30694653206605815, 0.2558844253889232, 0.23130471022472873, 0.1829991880407825, 0.21485608933548356, 0.20294922937796733, 0.20413265571646363, 0.19221712618346243], + [0.24994315509992462, 0.2320604307534428, 0.22695494243870903, 0.2291071382558248, 0.2090942805605136, 0.20813482750122134, 0.22091220751579305, 0.2000298461900069], + [0.29135401966529323, 0.2515567825857381, 0.19629762252419797, 0.2052211968718681, 0.2030311862816215, 0.20331124787021942, 0.20293784426158326, 0.18858855910085573] + ] + }, + { + "N": 221, + "b0_lo": 99, + "rows": [ + [0.32858393559679927, 0.25631592646029633, 0.236436181736432, 0.23347454070699117, 0.2024916081039733, 0.1890395545184375, 0.23562264551111606, 0.23115300020683], + [0.29444934260667427, 0.3405596723995368, 0.2639001250805833, 0.22349635978249552, 0.21947189552905746, 0.23814637394053134, 0.2316208901726331, 0.21435357069383112], + [0.3287042230508521, 0.29364552000113187, 0.2468385541273192, 0.19356443782145125, 0.17094240451537107, 0.20005586330616085, 0.19424817934458932, 0.1651053016399608], + [0.2790489121745106, 0.2428550470454833, 0.261212740697372, 0.2055886870223601, 0.23518746263771212, 0.18692554123265215, 0.19687644345888333, 0.20264823505884583], + [0.3164533772126673, 0.21910476085713382, 0.17091312820729598, 0.1790243688431575, 0.2328935589436309, 0.21838207925750944, 0.23253152745722067, 0.19572055792853374] + ] + }, + { + "N": 223, + "b0_lo": 100, + "rows": [ + [0.2996891505647606, 0.24278567753093347, 0.20151899346593816, 0.19608912756738167, 0.20850184878775524, 0.21832595018858186, 0.23767039987214567, 0.20807223226775814], + [0.34126286779681736, 0.23436755888237906, 0.2024371684362668, 0.21572636373223072, 0.17159544971729535, 0.20183428857569724, 0.2261660020782863, 0.21367319809249335], + [0.3664991789733405, 0.25699771551196376, 0.1969036951585018, 0.23032583409475418, 0.23718242204194853, 0.18589000797584587, 0.23153919514233762, 0.1667595099213542], + [0.29899990834641665, 0.23996153741002413, 0.19664665157294867, 0.17770724103897625, 0.23530840025350583, 0.19591672236176905, 0.17884908322568918, 0.19038788261155531], + [0.32146606912936393, 0.25664657879747155, 0.23663156016110917, 0.19994208463258809, 0.20470044989181269, 0.17346779742914425, 0.18286171812356297, 0.2086873249458913] + ] + }, + { + "N": 225, + "b0_lo": 100, + "rows": [ + [0.32011106605544326, 0.28148155402850916, 0.2283961221342132, 0.16901294275988787, 0.20622086220560795, 0.2028956946074672, 0.2154139601465982, 0.18834282732065413], + [0.2961959377546113, 0.23937026919554064, 0.23001907444782307, 0.23169878887266587, 0.1892305426890828, 0.24816614465128173, 0.2220090931797306, 0.23548975841532532], + [0.3098861257690971, 0.23058974145690955, 0.18500719070364174, 0.21386375737645283, 0.19221447367313116, 0.1970107713074203, 0.18782421823931994, 0.16860116332733388], + [0.23513253367691567, 0.2814485355084201, 0.25240604618098267, 0.20296388770641163, 0.23352584217027933, 0.19511933896807487, 0.21257338462403597, 0.18269072670456904], + [0.31935015717131054, 0.22604472619015564, 0.22871520980992638, 0.1940461119776471, 0.19717125724265622, 0.19460855316384823, 0.1785988949224331, 0.21876690552031436] + ] + }, + { + "N": 227, + "b0_lo": 101, + "rows": [ + [0.29500976499570264, 0.30896227189501374, 0.26191387106201713, 0.20816115530247917, 0.19735362406725132, 0.18119636900214575, 0.2451394125327648, 0.2276243820258902], + [0.23278732197880214, 0.29604791743537906, 0.27285680419016234, 0.21884056604595367, 0.1918326018879336, 0.2174089552052344, 0.21324994300497807, 0.1720505161002982], + [0.28424086349473915, 0.23105855583407453, 0.2393730208386801, 0.2067010358151886, 0.186362162488958, 0.20376006166440117, 0.23523804647354324, 0.19902151005929292], + [0.21671045450605944, 0.26166186230462035, 0.21818425487768844, 0.24818460340628284, 0.20914379050293663, 0.2064807060096618, 0.21621685168382332, 0.19311324703815014], + [0.2358890116927819, 0.23165428291299306, 0.20511568488557494, 0.23790597916272732, 0.24555258699286664, 0.2357144445047524, 0.2471250843740429, 0.172905939559581] + ] + }, + { + "N": 229, + "b0_lo": 102, + "rows": [ + [0.35603580522465933, 0.27144988721773133, 0.2170824873083303, 0.21454499344074418, 0.2104418389805922, 0.20886000028241214, 0.20873406005141637, 0.20406121064059604], + [0.2933485029911047, 0.21431201010570516, 0.21816624101071508, 0.21074511020621656, 0.1739819176447681, 0.19372016062638764, 0.21226954570017398, 0.1846462168259217], + [0.26231431783507836, 0.22528115329556633, 0.20556474863489882, 0.1836699644276947, 0.17335845754143286, 0.19082400550171033, 0.15984431981215577, 0.16203769432005966], + [0.22215484282126965, 0.24048304304601503, 0.2333128711783277, 0.2074062080786665, 0.19921891237361616, 0.21805750358219997, 0.2237774777610617, 0.21584336788526826], + [0.3280114496678159, 0.26195868531523303, 0.2339059473439583, 0.23486272051936916, 0.1990137414304536, 0.16299238263523702, 0.21536405739516304, 0.17966403995170346] + ] + }, + { + "N": 231, + "b0_lo": 102, + "rows": [ + [0.2487833508238739, 0.32073530865927585, 0.21246610770249075, 0.20893492133604005, 0.2026515280238076, 0.22407068293130997, 0.23568464291868407, 0.23955908129963113], + [0.26797394571224087, 0.27640149645785694, 0.23286169888453262, 0.19813306069247494, 0.22855536929349246, 0.2268356361672187, 0.19351659436110952, 0.17796766518716753], + [0.2780341598390995, 0.26600900541629113, 0.22404368488773588, 0.18026247168709292, 0.19474003255657643, 0.24795222409094836, 0.1877869654885015, 0.20447210005458238], + [0.32903314272229184, 0.22891927507467016, 0.21674818873700719, 0.21795508704670918, 0.19700643247807398, 0.22984075114201336, 0.1575334283443844, 0.19117924064216862], + [0.2950601189549087, 0.24353611048275114, 0.21939330497328013, 0.19837079118546502, 0.22557059138437854, 0.2000379505180219, 0.19833513649448012, 0.22429152542952405] + ] + }, + { + "N": 233, + "b0_lo": 103, + "rows": [ + [0.2888051749981039, 0.23982360721942586, 0.2103421643879249, 0.186250735738773, 0.19477473909503035, 0.23651715591257488, 0.22736251419537806, 0.25875787280480606], + [0.29784559005396255, 0.25263719091021836, 0.20403036535344174, 0.2334258793070104, 0.2086185894308182, 0.22673159594835895, 0.21934086136580977, 0.2033832889245598], + [0.31866640201413315, 0.31997484352594163, 0.21338688947991635, 0.1879314873216149, 0.2166651379255972, 0.21267856489692305, 0.22589629004870615, 0.2296250715346098], + [0.2862681917948226, 0.22699287479969127, 0.2584892506946508, 0.1457078921507478, 0.1789058136124469, 0.1604755229009412, 0.191680523365802, 0.18446148674114848], + [0.3289892775016272, 0.19107304225700023, 0.21549596121128933, 0.19792850071100251, 0.22682794847686846, 0.21368638674636975, 0.19404116329002793, 0.20249407459643864] + ] + }, + { + "N": 235, + "b0_lo": 103, + "rows": [ + [0.30130365243135276, 0.29139504849747516, 0.26718887963343635, 0.20356757570917708, 0.2196445167141682, 0.21682224583252974, 0.20950595695131075, 0.2114753662718324], + [0.28270835158919433, 0.2761964227603687, 0.24996208204835024, 0.26109593939636055, 0.2157157042909218, 0.2484627708092156, 0.24015430775588523, 0.21901748851576314], + [0.33832429229919386, 0.209334680189727, 0.2279697942782858, 0.1940633025839939, 0.234682648712102, 0.23164519975738052, 0.22991326876296922, 0.22012419034333533], + [0.22666675073536158, 0.27853495007246337, 0.2111716252915788, 0.2110101077027396, 0.20635462749378763, 0.19878577251235985, 0.20390059991657428, 0.20270438490871065], + [0.2486681749385025, 0.28190692903344794, 0.185599762615789, 0.24076433935147667, 0.206199032124842, 0.1747402289929018, 0.21223729372103345, 0.19126211145550515] + ] + }, + { + "N": 237, + "b0_lo": 104, + "rows": [ + [0.27791479911856587, 0.2461349258742206, 0.23518876054672583, 0.19490687423812622, 0.2443787380405682, 0.21347895322976612, 0.2193371120809854, 0.21958503880442362], + [0.31139432518364, 0.2151329870650486, 0.254331154988053, 0.24346488051254409, 0.23725309559310914, 0.2290134331813404, 0.1787521036736554, 0.20634747220465965], + [0.2820049619083172, 0.2524643739942472, 0.20458226485841643, 0.1913739351542551, 0.18961053042067685, 0.2029411900296257, 0.21320693547484396, 0.20463168457280795], + [0.2775938489242381, 0.2417041460965889, 0.21678212878222533, 0.21744885728867236, 0.17069541109802105, 0.20156726689504997, 0.2589672451026719, 0.18488958436109776], + [0.3017139170667567, 0.2194175203420175, 0.23611907141995445, 0.22661172171111876, 0.23115623510007538, 0.20484717807606007, 0.18514217087585957, 0.2090780632058989] + ] + }, + { + "N": 239, + "b0_lo": 105, + "rows": [ + [0.2511026697034, 0.2513766634616959, 0.2155710609758742, 0.20823175661903517, 0.19417307107106474, 0.205322487669144, 0.24550311117973458, 0.21935389044104064], + [0.2951880522858262, 0.28804216119217085, 0.19567187900703759, 0.23241795950924343, 0.24146266870277033, 0.18717809196833413, 0.21468881200351847, 0.24156770036876773], + [0.30180431293726034, 0.20602191651965332, 0.23824587107853296, 0.22183495647738888, 0.21873989246948933, 0.19520304692591467, 0.22138519495917108, 0.18796783501459804], + [0.3157825002892672, 0.24690293901262117, 0.23328105509587174, 0.17379723005023576, 0.21743537698142695, 0.22366524910814556, 0.2175025063614129, 0.19750938748081628] + ] + }, + { + "N": 241, + "b0_lo": 105, + "rows": [ + [0.27912627562798664, 0.23170870017863768, 0.25581985371283344, 0.2575301573544175, 0.22059414307812097, 0.2106623674405145, 0.20668130196507678, 0.17565850783134634], + [0.22262146877982147, 0.2540565538757557, 0.1911921062886084, 0.18768151237740743, 0.19414795546808125, 0.22169702394803498, 0.20923639419126477, 0.22722076112032208], + [0.269277966760903, 0.26997055027875416, 0.22837815165150827, 0.22059223761135105, 0.2113772436713305, 0.18063194061849996, 0.1890826369120171, 0.18173893630506785], + [0.21435798901655811, 0.2555405913472205, 0.2002931290577749, 0.1913386238039941, 0.19887066868527487, 0.23097212424207242, 0.24923237073693386, 0.22085461837498405], + [0.3233035137805933, 0.24707056532806312, 0.21761302966730423, 0.21729408064703318, 0.2106642191316616, 0.19817264851553623, 0.21557436822715761, 0.1920152723993662] + ] + }, + { + "N": 243, + "b0_lo": 106, + "rows": [ + [0.26169945015952695, 0.2786049188201379, 0.23200822737774177, 0.20077247416279717, 0.18208627540478234, 0.20029784828765626, 0.18275877138860067, 0.21286837012569268], + [0.23954524103170877, 0.2799219095061111, 0.23558855686219196, 0.2875430446791365, 0.19447819899468238, 0.2535057570282933, 0.22614751200510957, 0.18723578338868557], + [0.3050700698667722, 0.23084478970670863, 0.21072531225105046, 0.2275356341263286, 0.22535652975891568, 0.20242057526732116, 0.1824175090919049, 0.21545886817489143], + [0.2870128664929126, 0.2642527494898802, 0.2298242976460898, 0.2303487040462824, 0.21237816495335848, 0.2040822395021227, 0.22570937599131713, 0.21125371343116575] + ] + }, + { + "N": 245, + "b0_lo": 106, + "rows": [ + [0.2883906021502362, 0.21807174051039296, 0.29150995045545264, 0.2545955581637943, 0.24158684252526536, 0.23141132846476012, 0.23057265095377175, 0.21192204932753636], + [0.2819792807349674, 0.24402255052376762, 0.22242824726047095, 0.22583067153721653, 0.23616408048206355, 0.2573057700078916, 0.20424473512877533, 0.1786193141722568], + [0.27299923293573747, 0.2695371868794039, 0.23571033483479095, 0.2090746295239387, 0.22118032461276005, 0.21007145735640045, 0.20866043275650517, 0.188832248661488], + [0.28849782536732876, 0.2093509137025501, 0.25759049090835956, 0.20374585463052752, 0.23128887459164843, 0.19192833267541784, 0.16942426925728835, 0.17949252782532324], + [0.26991548410613436, 0.25116015502134353, 0.23491659914740673, 0.18991518786742168, 0.2073868842223692, 0.2481808017809699, 0.20347726453694215, 0.24408362349574553] + ] + }, + { + "N": 247, + "b0_lo": 107, + "rows": [ + [0.2740379138521059, 0.27543876349150026, 0.21192209939229578, 0.20154488478538848, 0.23102091334055375, 0.2214665947453258, 0.23646653475895701, 0.23894473185925336], + [0.2646233739369289, 0.22589090825600971, 0.20972696822717052, 0.23371346086979355, 0.18637690471937907, 0.23239118487710395, 0.22739402010721277, 0.20233612249117877], + [0.29139907085095956, 0.23385589205330334, 0.2328803815298691, 0.21006996855621005, 0.21194937063195332, 0.20190175042365807, 0.18638921510155468, 0.19856333198608417], + [0.2902989718254509, 0.22132400998400129, 0.22506750831160668, 0.1987371918383289, 0.16667392857916963, 0.17559618950416697, 0.24138441880813583, 0.2007455175078969], + [0.29787799518162345, 0.23982451165508106, 0.20798307939797575, 0.19673669033019053, 0.21311330810350082, 0.20695276342718535, 0.17154446098100637, 0.18524488896449423] + ] + }, + { + "N": 249, + "b0_lo": 107, + "rows": [ + [0.2249932034234989, 0.28003822910731113, 0.23942840109415495, 0.23430962717378645, 0.24489306317065365, 0.2209597874495311, 0.23041181599747307, 0.1916348141116429], + [0.3281991345444048, 0.1744944661927034, 0.2282800033012164, 0.19313123103472904, 0.2241862799968468, 0.21872650521720854, 0.2410843493009837, 0.22441376888977738], + [0.2864021177040775, 0.26729876902395727, 0.21186647874259693, 0.19388739609263264, 0.221717609504048, 0.2082245447094656, 0.22416441722356725, 0.17669408088496158], + [0.28488869521634014, 0.2516114002417964, 0.22150921486930056, 0.22511843962846234, 0.20538741646116643, 0.20040132189842946, 0.20751277251741054, 0.2100878234859643], + [0.2510133134575218, 0.24808763626702812, 0.1826951684822738, 0.1851979172821516, 0.1867050799623338, 0.22564081482155315, 0.19729717981484302, 0.1998732516674006] + ] + }, + { + "N": 251, + "b0_lo": 108, + "rows": [ + [0.26575084255227993, 0.2343138691694798, 0.2423212336533756, 0.17263612094680228, 0.19575180399684494, 0.22072279168845602, 0.22418063527691798, 0.20184626316611393], + [0.353591298843048, 0.2577911275858609, 0.188400177485733, 0.2309910412558373, 0.20149735900260698, 0.25780880150163954, 0.20333714231810843, 0.18054899565597404], + [0.3055193208372805, 0.26271785551105875, 0.26561187806973097, 0.18929066303562242, 0.21592733076445095, 0.22235820992744293, 0.19718433201100355, 0.2034030042598905], + [0.323351566884222, 0.24576403988741832, 0.219411163931876, 0.19773660178134497, 0.20445689396960884, 0.18536059851100808, 0.19298706218513015, 0.21782344006745963], + [0.24415565685332852, 0.23465558406991346, 0.2015732344113231, 0.19924294342598237, 0.15420035289074321, 0.15234269107963083, 0.19782197541993915, 0.19106739966199662] + ] + }, + { + "N": 253, + "b0_lo": 108, + "rows": [ + [0.2869343613542891, 0.24666950537091253, 0.23845952976797444, 0.2453463754576165, 0.224888373618426, 0.2355085445348202, 0.17783640631259592, 0.216142649992675], + [0.26447377310063114, 0.2335230650909745, 0.22963838020253627, 0.21418490545137106, 0.2091389158296566, 0.23522981372177665, 0.25500151072261446, 0.18298957467434093], + [0.3366590755159359, 0.2134917488375495, 0.23094721951019614, 0.20452122350058588, 0.19279833297444177, 0.21656527043675972, 0.20852830649844262, 0.18603337934857841], + [0.26424633699606676, 0.24244044402639695, 0.21483092548461813, 0.17521356196498572, 0.19664474563548207, 0.20198198334468395, 0.2012687581606145, 0.21848306992200212], + [0.25991997797292304, 0.17904795434649767, 0.19129013560831154, 0.17856467618885752, 0.23494243480970906, 0.19442261025610863, 0.21797153042464174, 0.17390694450720523] + ] + }, + { + "N": 255, + "b0_lo": 109, + "rows": [ + [0.3089100980061218, 0.26545834936157514, 0.245607716577632, 0.23697232223587605, 0.22654321417612158, 0.2309026181402319, 0.23281517307192004, 0.22181015119816397], + [0.3229624773381106, 0.26688146836670695, 0.22473887347930974, 0.23822705307255915, 0.22408615097678533, 0.18392474620665603, 0.2916775321811573, 0.2073075867546625], + [0.23105889344249902, 0.282547147573299, 0.269031737375621, 0.18112426592276437, 0.1976698852237882, 0.2152501016726012, 0.20562767688538564, 0.22069821147514995], + [0.23178590047686823, 0.2375240385406273, 0.17858197631491943, 0.1832640892946331, 0.21122813517155264, 0.19019200777040846, 0.21591987043599942, 0.23001070903236417], + [0.3201994867566954, 0.24461842895500113, 0.18480750306659535, 0.20033341619172312, 0.22774452953921787, 0.2309842472923474, 0.19976448729124147, 0.2062129260978026] + ] + }, + { + "N": 257, + "b0_lo": 109, + "rows": [ + [0.28210331631578833, 0.23400217811205704, 0.25113601574187133, 0.23797073512593186, 0.21841444423500722, 0.2075044237915027, 0.24079758667819015, 0.24041645214289942], + [0.3087721227863272, 0.241714715349057, 0.25401330020776103, 0.23469991994130457, 0.22244019323210384, 0.2370140631887581, 0.24387842720142744, 0.21993373701011518], + [0.3452940769621767, 0.23660368544854973, 0.205025689560685, 0.19621338284333179, 0.21680303301049525, 0.19552367938483511, 0.1858508870378876, 0.19080953711588008], + [0.2746405187734666, 0.24520028270760857, 0.25866265475419814, 0.18181177453353004, 0.23136072731439442, 0.2540412974511057, 0.22114956376879874, 0.2168509176561219], + [0.2971894190995779, 0.21547881393015705, 0.21188800509482308, 0.20930832916443695, 0.2402975685761706, 0.22677234733847265, 0.22021176602054698, 0.19404265606566756] + ] + }, + { + "N": 259, + "b0_lo": 110, + "rows": [ + [0.3762250084144472, 0.25290898532174483, 0.2800697370252781, 0.2237431178343096, 0.22652080635871147, 0.23775379382756345, 0.23376688107337884, 0.21056956878454705], + [0.24300443989872605, 0.29375706297166665, 0.29095688180950224, 0.19723675343902164, 0.21423973135529126, 0.19481545621419916, 0.20119422408508825, 0.2273152694286413], + [0.2825979607636622, 0.2457796612128259, 0.2242747981566025, 0.19222351506498586, 0.22067176248496895, 0.1984480461914847, 0.2544751701831729, 0.20808828051056347], + [0.25285907943501745, 0.23003393807508024, 0.21967482952723988, 0.2208720461229063, 0.1947944333716537, 0.19903885117966996, 0.16668855141058478, 0.2273580158935481], + [0.2935232699458296, 0.21868451311030218, 0.20665378554683006, 0.23478876595893783, 0.18812620167167002, 0.17712200336965253, 0.20715556336549795, 0.1648827081720724] + ] + }, + { + "N": 261, + "b0_lo": 110, + "rows": [ + [0.29329790738448414, 0.2627796875377327, 0.26959687308353947, 0.21446340758975863, 0.23654251239152924, 0.2524727995464645, 0.2415682618089828, 0.20806989672485293], + [0.29209324878579085, 0.30509983214227937, 0.21612191939842798, 0.2468937462464292, 0.24071377452501347, 0.2316023405568524, 0.2127762934279789, 0.21472720155259944], + [0.30401857195803605, 0.22604196376571245, 0.24519903367317256, 0.2447567097569494, 0.21294893253191094, 0.2405904500746219, 0.21353952424721948, 0.2326109770397591], + [0.2551977096578958, 0.22690372762825767, 0.2308497414631694, 0.2193922440713829, 0.21300293266887435, 0.19189613200569436, 0.18597045649628308, 0.25375370213124615], + [0.27824720727560187, 0.25485311523904686, 0.21403628576507558, 0.2006188239905446, 0.17935325146164818, 0.20825730228640318, 0.18378641970275073, 0.18355128407711144] + ] + }, + { + "N": 263, + "b0_lo": 111, + "rows": [ + [0.27750940188385825, 0.2686962974039615, 0.2296304203976175, 0.2313825018909917, 0.22501223463365289, 0.19974234776924854, 0.22581869740100463, 0.18249997422954814], + [0.3175078179638459, 0.29456204661656793, 0.2522643976170761, 0.2313047168034374, 0.2155422765559412, 0.2461827093826906, 0.23303338211436891, 0.21081077307694018], + [0.2704059106963972, 0.26017538358934966, 0.22902549421028212, 0.2118667052244548, 0.2164088549192442, 0.19202911914837992, 0.16135967351645597, 0.1894512108688483], + [0.2707399673301733, 0.24431558745189738, 0.2001502317916412, 0.1959247934985149, 0.19810008362974152, 0.2030947202894842, 0.23562999289407818, 0.22580296444304038], + [0.26116407911841366, 0.22131892327211478, 0.21116005483480316, 0.23756904661768352, 0.21719395032966066, 0.21343150660380897, 0.22892557180806772, 0.20260323850343334] + ] + }, + { + "N": 265, + "b0_lo": 111, + "rows": [ + [0.2666323595329533, 0.2728107046053371, 0.21941915510218254, 0.258710320218872, 0.19173568781886663, 0.20499024982277783, 0.23763270129097347, 0.22967317094887155], + [0.3181857690264556, 0.2293955010544849, 0.2376689317445908, 0.1892183313143304, 0.20436221506521088, 0.2009372896596598, 0.22226326767658422, 0.170500130684859], + [0.29282749266347946, 0.2446377951422236, 0.22901288924126173, 0.2261171294532681, 0.17737421342758553, 0.21305178535296454, 0.22001609173297831, 0.23124018253467027], + [0.31968281544436966, 0.26968174472469325, 0.16889367729569615, 0.20047597721790214, 0.22826988763406272, 0.20324150842982952, 0.20641473923015252, 0.21380944333006563], + [0.26861131065962673, 0.24157069425910133, 0.22714658548033356, 0.2067078678926456, 0.19484832211477576, 0.1835865576018143, 0.2036884908851185, 0.19583599080463537] + ] + }, + { + "N": 267, + "b0_lo": 112, + "rows": [ + [0.38355804175218094, 0.2222687317829387, 0.2276030280046592, 0.2093324844846562, 0.23933676102946172, 0.2065598032904362, 0.21653558260399572, 0.1953777742106134], + [0.2688849464023017, 0.2601676143614225, 0.28062805303982896, 0.2117108232933153, 0.22130692697801582, 0.21519206967065813, 0.19380853736274592, 0.21475942112028573], + [0.3015323100032113, 0.2535783783380857, 0.24789896754377236, 0.2210100891092799, 0.23352723988585897, 0.21597864626393468, 0.21600130630988185, 0.1877186577691683], + [0.26790816505315274, 0.23533155595496502, 0.2602183670715611, 0.19857993077623864, 0.2029722885048918, 0.2144870888469346, 0.24152046371740715, 0.20841502924458066], + [0.2519913662729167, 0.2951154651774088, 0.19915352436199735, 0.184497813558447, 0.19244246532257758, 0.2182263732207392, 0.1930243122784305, 0.22263593732496353] + ] + }, + { + "N": 269, + "b0_lo": 112, + "rows": [ + [0.3118682854924856, 0.28855268176282767, 0.21603285595722402, 0.24277452033634514, 0.22254299185521412, 0.21019428539132434, 0.24953475235428518, 0.21158576735865076], + [0.2705859119912315, 0.23318503036781238, 0.21936418013776915, 0.21463515152148732, 0.24505224332152512, 0.19262493948700127, 0.22805727231940334, 0.2264967542716193], + [0.2991885796340772, 0.2607844633781312, 0.2576801379662259, 0.23499929335984412, 0.22880218293461746, 0.2000588411382471, 0.25345922868126414, 0.22245385838762996], + [0.2777484270260305, 0.2556207386159245, 0.23329462738259776, 0.23397955612343882, 0.18490463674210908, 0.22249663845524853, 0.2425261306951691, 0.16539885885392072], + [0.2997182969430803, 0.19925589464974103, 0.23834029479925853, 0.2341653651648429, 0.2243295632641701, 0.2030709326057101, 0.2084799293446465, 0.19981138898318063] + ] + }, + { + "N": 271, + "b0_lo": 113, + "rows": [ + [0.3178982765526408, 0.21004906767318818, 0.2158556561263692, 0.2377306093137618, 0.2174296242831346, 0.20727414533540559, 0.23172009295946738, 0.18929483954844212], + [0.2699235696711508, 0.24008809746503948, 0.20109653631983834, 0.2245402904631899, 0.23869147489462228, 0.21783682344864452, 0.21710478738606764, 0.1921458577970478], + [0.290703466357225, 0.239910468621539, 0.23336025207349276, 0.1924217400508653, 0.21906373909757829, 0.24420830912441188, 0.16526286521542563, 0.22344736001064425], + [0.2553446321807119, 0.2433815874552678, 0.17599598728675653, 0.19736674093111545, 0.20020285033659105, 0.21932068776134983, 0.2271049477601575, 0.19111005539321574], + [0.32691635747305714, 0.24993940600284822, 0.21831041631347647, 0.20926299192366998, 0.19427563267751854, 0.1879404100011847, 0.230232097348594, 0.2077346654566428] + ] + }, + { + "N": 273, + "b0_lo": 113, + "rows": [ + [0.33531245931259634, 0.23327111667178, 0.2578678683611337, 0.2591060543989239, 0.23104729296480125, 0.24970430653249023, 0.2395643888788634, 0.22996400306498693], + [0.30337232327615454, 0.26989683760625466, 0.21039025054265062, 0.20041728459520963, 0.21601420602543767, 0.23534476754651953, 0.23289355192616693, 0.20748093301005172], + [0.274752235801585, 0.23529713720843284, 0.2064583031278226, 0.2053995701900281, 0.25806358898187765, 0.19900840165992556, 0.23507840287451226, 0.22533811804599285], + [0.2504130108735363, 0.25712665013218483, 0.22138782553409586, 0.15716385557814017, 0.22266072778342136, 0.24267456621018252, 0.21293671845193465, 0.1793691855573333], + [0.2610367137648398, 0.24206233479520078, 0.20119515899947182, 0.17145105890755843, 0.20516873972415192, 0.22357904115965738, 0.20866296335690285, 0.21571432017303882] + ] + }, + { + "N": 275, + "b0_lo": 114, + "rows": [ + [0.24247922384211945, 0.2696606461776451, 0.2669163002043345, 0.2548631870746678, 0.2260966975325021, 0.21222495526479812, 0.19089025968385576, 0.2543761079243998], + [0.2582016674904827, 0.2269621089874379, 0.2227321491476725, 0.25520542823485975, 0.18271965334974036, 0.2646404082680899, 0.25645670441485885, 0.20468808627923918], + [0.2454029938721628, 0.22709106492034875, 0.19707630382746072, 0.25440178658537743, 0.18182468020738063, 0.24470183910217874, 0.213118291427351, 0.18296467931662788], + [0.23822539485841135, 0.23932352471711432, 0.20661286575453716, 0.23809074882505235, 0.23814801596167431, 0.21480204218409357, 0.23958284203453614, 0.23203736027850488], + [0.2360483184890703, 0.2665676664618921, 0.20250771306459184, 0.21402510203572872, 0.21551185548307009, 0.20085927504384204, 0.24491801068535413, 0.2136411572990054] + ] + }, + { + "N": 277, + "b0_lo": 114, + "rows": [ + [0.25936414382964357, 0.29391028924888984, 0.2175887515345169, 0.2263992099530886, 0.23153478725942775, 0.27706476955506826, 0.2082256770800373, 0.24746484780720762], + [0.29429586202947466, 0.25795616086440404, 0.2461479348996264, 0.2433885982995098, 0.22138614635450263, 0.19100856759673657, 0.19484796819674058, 0.201945265574197], + [0.2518367665464057, 0.24172301228750034, 0.2285008559795343, 0.21786463968240913, 0.21775627795547908, 0.24231776572775404, 0.1835278827020086, 0.2064563965467701], + [0.27792186147547393, 0.23852391737238846, 0.21308919411891553, 0.20915839535721192, 0.1833496702260473, 0.19875220595785903, 0.22576678824509283, 0.2027568098984096], + [0.2919736514834901, 0.21462740913942688, 0.20272323252836236, 0.21334566227836363, 0.2038841892167259, 0.2138895778916845, 0.22527863677936383, 0.1872110160900284] + ] + }, + { + "N": 279, + "b0_lo": 115, + "rows": [ + [0.38382408499755305, 0.2621917484866667, 0.23423278407256254, 0.21038024393896101, 0.2155918292503502, 0.2403671711747647, 0.17792884933699066, 0.20030240236203428], + [0.2452376360494372, 0.2594155120526501, 0.24334711988149196, 0.18010920196507663, 0.17811111889360032, 0.24574790931545742, 0.2170014429176716, 0.21119025685549475], + [0.3153243718481097, 0.24217981564073712, 0.2097392790156639, 0.20277080363544273, 0.2250157842600895, 0.23082070328021373, 0.24745804277915406, 0.20165590165320685], + [0.3229593386367108, 0.21414623394174173, 0.1861079834854038, 0.21065719260963223, 0.18633014432508072, 0.19837584310379386, 0.19285638061507346, 0.18378592159203339] + ] + }, + { + "N": 281, + "b0_lo": 115, + "rows": [ + [0.305853420044792, 0.2630279622827219, 0.256664229858259, 0.21934789090319512, 0.20562648814122375, 0.26143949929530685, 0.21249648953699143, 0.17554791306998707], + [0.31719441733675713, 0.23826170690880535, 0.2149164371434097, 0.19684291580918017, 0.24871605897241447, 0.2329894993034799, 0.23301592960075262, 0.18181804109924368], + [0.2679232833398653, 0.21904144970886685, 0.24723223991603624, 0.20311755501480835, 0.2499066290633571, 0.24045327233660976, 0.21811125872527767, 0.19113367156095176], + [0.22898614888973337, 0.273238216728107, 0.2063528899505721, 0.21932307504091905, 0.21208638402469038, 0.21692047741312212, 0.23286966721861507, 0.20681851027324982], + [0.27603682954364983, 0.2686409102172501, 0.192227127078548, 0.19679521693909646, 0.18150138122378137, 0.1872305775687349, 0.2043885804536637, 0.2148928068555687] + ] + }, + { + "N": 283, + "b0_lo": 116, + "rows": [ + [0.2845867330107849, 0.23786808699347306, 0.22726072372880457, 0.23360558767154332, 0.2225272166114461, 0.22348656891989754, 0.18238681181013, 0.22786538196394215], + [0.3083279543894729, 0.24472702503808674, 0.23445432186830334, 0.20154251734534612, 0.2021417309320234, 0.22990342545218778, 0.22376802360091436, 0.21149564666196735], + [0.3031128930084237, 0.2390013857256978, 0.23801537570757317, 0.21238595913407754, 0.18185342973793095, 0.24409132481466148, 0.2212459648794265, 0.2066086776053903], + [0.257685570940523, 0.1926010431159219, 0.2000763516094509, 0.19917315349955783, 0.18837661079492857, 0.2032765379438204, 0.2126705534958056, 0.191084283387646] + ] + }, + { + "N": 285, + "b0_lo": 116, + "rows": [ + [0.32367503089433736, 0.29024886387813364, 0.22648751302715114, 0.19466892880770598, 0.26049729892051987, 0.23905739447415458, 0.2192158911529961, 0.24224914516923157], + [0.3062098649585804, 0.24712962932991897, 0.22651625881758547, 0.19975932744908598, 0.23462028049454972, 0.22228901947903118, 0.23350649391890102, 0.21652477942276133], + [0.27687256559314555, 0.22338491374822494, 0.19473511976754268, 0.23386151530163207, 0.2258097598865348, 0.24677455680062738, 0.21658601520898613, 0.19750457815096306], + [0.29210060787309194, 0.23939879393010272, 0.22995787804593265, 0.2071097486138045, 0.2558982892030273, 0.22440532595535356, 0.2216773769999861, 0.19037527619378763], + [0.2981742788991695, 0.26852257191003165, 0.240026778072751, 0.2092845758012652, 0.18142575655144214, 0.1859221392662507, 0.21742683653916126, 0.1918523103932682] + ] + }, + { + "N": 287, + "b0_lo": 117, + "rows": [ + [0.32198207562949893, 0.23678965017637937, 0.2583167674176182, 0.23398910990970007, 0.24300814618336566, 0.23973265094665755, 0.15475109986796873, 0.23597672908798156], + [0.2566044392312215, 0.24613791439359253, 0.22274030349191815, 0.23838626275315397, 0.22869240951707806, 0.18942977616838158, 0.23064403965200347, 0.22322255441587158], + [0.33800543845027614, 0.24543403495699972, 0.24781954485012986, 0.2014170146873012, 0.21842381798131189, 0.21382773667984212, 0.21228946649848124, 0.195089953465718], + [0.24768653974577096, 0.23723133983726036, 0.21808851300617424, 0.22089624695431576, 0.19254209076260512, 0.2041952680069959, 0.22533813436060923, 0.15554771757692568] + ] + }, + { + "N": 289, + "b0_lo": 117, + "rows": [ + [0.24669125381074306, 0.2672461746898362, 0.23827455035685313, 0.21654498020907767, 0.21095662732396037, 0.1960891675802989, 0.25241764858535837, 0.2226337460298833], + [0.24540903688567053, 0.2970416683984142, 0.22620739811550333, 0.21271211711927146, 0.2346614201973446, 0.22336637026612657, 0.21633968548711185, 0.21900024632945272], + [0.3519274029968323, 0.3033814391956315, 0.24948307583784388, 0.23363073478977817, 0.24605044022018727, 0.2532817458808134, 0.228672896370951, 0.1845051730327845], + [0.2627905597132484, 0.2933646310791214, 0.2189741091313529, 0.22967761898271158, 0.21595699073637598, 0.1896873715910585, 0.1931878094418924, 0.16191700822590066], + [0.24377774285242332, 0.2573649199561809, 0.2220678401978295, 0.22309236147692557, 0.21612741132575855, 0.19133769156619349, 0.18684539667795863, 0.21377507504757154] + ] + }, + { + "N": 291, + "b0_lo": 118, + "rows": [ + [0.322320985463079, 0.26595715579103685, 0.20468663191884, 0.21586588618893934, 0.23286640162639, 0.2401437683250698, 0.2085612220171335, 0.23562777566084012], + [0.2346520455791432, 0.24521455779031803, 0.20103458642453348, 0.20412277038035043, 0.2408379927968675, 0.2382804101635048, 0.23908520881162595, 0.214890410510262], + [0.32325408580240816, 0.267718798750076, 0.2014761108504044, 0.20614355459383352, 0.23972506681250144, 0.2595377854022147, 0.20767907044408246, 0.2428943709113073], + [0.33379149100547734, 0.29410540643803584, 0.21815877997713057, 0.23662793665804924, 0.19372556392942591, 0.2154698623660461, 0.18578978223948808, 0.21485540315985932] + ] + }, + { + "N": 293, + "b0_lo": 118, + "rows": [ + [0.31125693737828425, 0.29054906224721966, 0.20326773662921585, 0.20673754538366199, 0.2266714194619303, 0.214259256339501, 0.22654638220688178, 0.2043960932762789], + [0.2896034598658346, 0.270493057157777, 0.2189578373900508, 0.21974316157937818, 0.21990605956524376, 0.2278746098126171, 0.2450751848972121, 0.23998158527117408], + [0.26901589001009096, 0.25922219795411905, 0.222820699979446, 0.19979536286175564, 0.2631352339602338, 0.19834878595654942, 0.22914987969105832, 0.19872935981069406], + [0.2952082708681362, 0.22025389880737195, 0.22610450521796743, 0.2165332970590056, 0.20061888212849444, 0.20465650697297622, 0.19846816583995408, 0.20214892263836054], + [0.22983191298531486, 0.2950736750020853, 0.21271570649285945, 0.20047387673951783, 0.20401920220155534, 0.18945798703295305, 0.2585787665484091, 0.18666684685472734] + ] + }, + { + "N": 295, + "b0_lo": 119, + "rows": [ + [0.318765988869425, 0.22565052515560913, 0.21322471938505003, 0.25268115890319626, 0.19925512516974092, 0.19884333076452815, 0.19238408581587746, 0.22942306991107822], + [0.33812538359447314, 0.2244838934918618, 0.18651476387225327, 0.22008047727229024, 0.24068991054560498, 0.18249008826316251, 0.2651999376424997, 0.1732137712475236], + [0.25712799811811055, 0.23840561243596659, 0.21917113933971064, 0.23319923282451996, 0.1946703514096431, 0.24730808925103842, 0.24347356686867985, 0.1921911767634853], + [0.2819416813510629, 0.2086050853669479, 0.1961903390168254, 0.1637003468055721, 0.21819931967839787, 0.22757993008371985, 0.22082308060976366, 0.17803180356196718] + ] + }, + { + "N": 297, + "b0_lo": 119, + "rows": [ + [0.2670743907600258, 0.2695175205660095, 0.24772770278405679, 0.24860305050635378, 0.2127802704902637, 0.23846412834077174, 0.20314738119459164, 0.21715549835275455], + [0.33831746355762266, 0.2638216513493069, 0.20758521896914703, 0.2022942037241389, 0.234852108849012, 0.21803678325826814, 0.22585372332085465, 0.19485361794955375], + [0.28925688548655976, 0.22290258118767198, 0.20361524645002618, 0.23657083288776543, 0.20752656235727546, 0.2348886967118399, 0.2213120614602165, 0.19689680078063776], + [0.2769074294404606, 0.22934279636709318, 0.2258703134778708, 0.22124175162736168, 0.21051238793958713, 0.19709693844277207, 0.2109890459998458, 0.19850002791256854], + [0.285379638125949, 0.2615570705382852, 0.21203434840446006, 0.21515076166994385, 0.19551531758543372, 0.1819314637019746, 0.20350298291722993, 0.21994916672548576] + ] + }, + { + "N": 299, + "b0_lo": 120, + "rows": [ + [0.2666664985426736, 0.2173015004870582, 0.22506981128156944, 0.2113550273406058, 0.265814929048805, 0.2289187985993449, 0.23932378677876437, 0.21671230446595763], + [0.33475716314319104, 0.22841102115155532, 0.20650103945083775, 0.21012199991924074, 0.24610540722144608, 0.27782654137494817, 0.22078677089070325, 0.2601525340211194], + [0.2986667362204532, 0.1973574254090416, 0.2437004539897542, 0.2197316695808511, 0.20714175514232644, 0.21092954733560743, 0.20094723409246243, 0.2359176528172911], + [0.3108665307818383, 0.22127385932944452, 0.2277212921890085, 0.2106644199672094, 0.21291300666417398, 0.21157684243728292, 0.20322950883797875, 0.19596421927162536] + ] + }, + { + "N": 301, + "b0_lo": 120, + "rows": [ + [0.22217030036081065, 0.24508734782903033, 0.21397758661268443, 0.2222675013309965, 0.2097824498238369, 0.1974441531027671, 0.24015853886814714, 0.2593123480504106], + [0.25078015278496324, 0.2514429416012059, 0.22924690968839462, 0.21628304445637453, 0.2162454002393237, 0.21546627552468597, 0.1984230903586011, 0.21958765122489135], + [0.34655576985433745, 0.2656715324347654, 0.19513629850158007, 0.25663002780497235, 0.20420991743803707, 0.22776231337012937, 0.21955668080848306, 0.2497897416257275], + [0.24918119164208688, 0.24085938433511733, 0.1944716544004566, 0.25711659279832183, 0.19828279936090476, 0.2339957180602628, 0.22771585925693102, 0.17713297233262615] + ] + }, + { + "N": 303, + "b0_lo": 120, + "rows": [ + [0.2542327868640018, 0.25370423342952436, 0.23726243414500173, 0.23686150701893816, 0.2385768669976622, 0.22732713402960883, 0.25373764286394274, 0.2785119657853219], + [0.2529723306018339, 0.20800221380959763, 0.259458173525506, 0.2149704899272138, 0.23795551270049525, 0.23932584434321663, 0.19452506641484232, 0.23003129026146482], + [0.2551841059937278, 0.25250410927487854, 0.18913796038907094, 0.24667969157243408, 0.22396639772403518, 0.21731430746876051, 0.22929930426918688, 0.21530977136789248], + [0.2767038421710545, 0.2485589433673473, 0.205295639771968, 0.23633124252593501, 0.22772571941228317, 0.21697159450025383, 0.18297713415979283, 0.20254708964481533] + ] + }, + { + "N": 305, + "b0_lo": 121, + "rows": [ + [0.331612733314657, 0.21032332221716363, 0.23939237383045386, 0.2196762229026675, 0.2494177001400169, 0.2395955294429843, 0.23508065673330097, 0.18459211698391995], + [0.2695122738486368, 0.26117569976440796, 0.24368629789122254, 0.2132223078335061, 0.20238317334405168, 0.2126037496747764, 0.22631428522165567, 0.1818713074995826], + [0.2886861219676466, 0.2365672964471278, 0.20464273589538182, 0.18314673572472756, 0.20636749761899098, 0.2157591313648314, 0.22749514445072566, 0.1929694431956297] + ] + }, + { + "N": 307, + "b0_lo": 121, + "rows": [ + [0.32949365207204895, 0.24672429231890233, 0.28640454341685917, 0.23009050883816423, 0.2400111458706022, 0.21424188444994538, 0.21872117026579208, 0.2421484179172545], + [0.2795498911089336, 0.3018127235668589, 0.20916694848532244, 0.22592847987122006, 0.21981384804589385, 0.23733603582021853, 0.1844686481102455, 0.23205613104057185], + [0.28331771078152584, 0.28857370698479023, 0.22574914329298681, 0.21246583587324658, 0.2287035702355123, 0.25014237997248684, 0.22007194313322734, 0.22127812517153694] + ] + }, + { + "N": 309, + "b0_lo": 122, + "rows": [ + [0.2584344784062883, 0.23010544748965336, 0.2223315329131495, 0.21462335081653236, 0.24058533807133028, 0.19328298509251587, 0.21654196751069518, 0.2546062269782929], + [0.3020329033520607, 0.2507743199035046, 0.2282261427797338, 0.20753702700618382, 0.20325882593337857, 0.2212800357085042, 0.20845651128364462, 0.22074581003880603] + ] + }, + { + "N": 311, + "b0_lo": 122, + "rows": [ + [0.26734565039943325, 0.2832066068775716, 0.24522572344195565, 0.21834640543414463, 0.23011086499023178, 0.24837180949410678, 0.2363549610115264, 0.22485981595397345], + [0.27572173500721564, 0.25344101701266947, 0.2414830281260012, 0.19175623919947868, 0.2507461870135391, 0.22620987551588798, 0.22695323568305337, 0.2091063120330613] + ] + }, + { + "N": 313, + "b0_lo": 122, + "rows": [ + [0.2589635838340885, 0.24000248632156837, 0.25340773461164684, 0.2265274654941468, 0.19704911818011767, 0.2410512941091723, 0.2344888810157196, 0.24607213005765113], + [0.3524731814076035, 0.2689212537484152, 0.19541630404675364, 0.2478256889127285, 0.2643560102076955, 0.2279982225150599, 0.2159725233314469, 0.2338711418311582] + ] + }, + { + "N": 315, + "b0_lo": 122, + "rows": [ + [0.2887114453854842, 0.30545668266426734, 0.2721750026019528, 0.24631254573686548, 0.24865356798090582, 0.25703903412195245, 0.2113479614841037, 0.21758889539279566], + [0.28340603958560806, 0.2145325858098788, 0.2414691115283559, 0.2529376902226596, 0.2093454796979493, 0.23084064491283365, 0.226938135678945, 0.24497278446168577] + ] + }, + { + "N": 317, + "b0_lo": 122, + "rows": [ + [0.33579288845692945, 0.2946521371445372, 0.2304748504059269, 0.2504785370077069, 0.2273686918477732, 0.22118957447323323, 0.22533879683412672, 0.23651132030196176], + [0.36026839346942974, 0.2603175129625226, 0.24999757889720217, 0.22360085989365278, 0.20052495629154748, 0.19248865181756317, 0.22914640036806283, 0.2362537528404985] + ] + }, + { + "N": 319, + "b0_lo": 122, + "rows": [ + [0.2750902444426802, 0.2591721802857402, 0.2207475959316392, 0.2571057272220908, 0.2418271027524675, 0.21143131130913517, 0.208874264182274, 0.2206429282191841], + [0.2748059840624128, 0.2855141390792487, 0.2552228219666222, 0.22911761265336833, 0.24998622857674077, 0.2380730004228577, 0.2280863363470963, 0.25346984577616066] + ] + }, + { + "N": 321, + "b0_lo": 122, + "rows": [ + [0.3043966019007659, 0.24616537509353095, 0.2056281787705077, 0.24222511831825735, 0.23661462402886302, 0.287425859704383, 0.24191461678222198, 0.25325398220358175], + [0.251738258084702, 0.28323627540083995, 0.26099056734331155, 0.23267320518122475, 0.18542334241474706, 0.2242354527628414, 0.24427008260783634, 0.20450235562921912] + ] + } + ] +} diff --git a/xombe/scripts/fetch_librispeech.sh b/xombe/scripts/fetch_librispeech.sh new file mode 100755 index 0000000..c2563e2 --- /dev/null +++ b/xombe/scripts/fetch_librispeech.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# fetch_librispeech.sh [OUT]: four LibriSpeech dev-clean-2 utterances as 8 kHz raw at -26 dBov +# (OUT defaults to build/librispeech in the source tree), needs curl, sox, and a Python with numpy and scipy +set -eu +ROOT=$(cd "$(dirname "$0")/.." && pwd) +OUT=${1:-$ROOT/build/librispeech} +PY=${PYTHON:-python3} +URL=https://www.openslr.org/resources/31/dev-clean-2.tar.gz +SHA256=176ec501490eced2d6c1f89f4f0ddc7dfe799e649e5322f8ba49fe3ff50c8012 +for t in curl sox; do + command -v $t > /dev/null || { echo "$t not found" >&2; exit 1; } +done +if command -v sha256sum > /dev/null; then + sha() { sha256sum "$1"; } +elif command -v shasum > /dev/null; then + sha() { shasum -a 256 "$1"; } +else + echo "sha256sum or shasum not found" >&2; exit 1 +fi +"$PY" -c 'import numpy, scipy' 2> /dev/null || { echo "$PY has no numpy or scipy (set PYTHON)" >&2; exit 1; } +mkdir -p "$OUT" +cd "$OUT" +if [ ! -f dev-clean-2.tar.gz ]; then + curl -L -o dev-clean-2.tar.gz.part "$URL" + mv dev-clean-2.tar.gz.part dev-clean-2.tar.gz +fi +digest=$(sha dev-clean-2.tar.gz | cut -d' ' -f1) +[ "$digest" = "$SHA256" ] || { echo "unexpected SHA-256 $digest for dev-clean-2.tar.gz" >&2; exit 1; } +for spec in lsf1:2035-147960-0000 lsm1:6295-244435-0010 lsm2:1272-135031-0010 lsf2:84-121550-0001; do + name=${spec%%:*} + utt=${spec#*:} + spk=$(echo "$utt" | cut -d- -f1) + chap=$(echo "$utt" | cut -d- -f2) + member=LibriSpeech/dev-clean-2/$spk/$chap/$utt.flac + tar -xzf dev-clean-2.tar.gz "$member" + sox "$member" -r 8000 -b 16 -e signed-integer -c 1 -t raw "$name.raw" rate -v + "$PY" - "$ROOT/tools" "$name.raw" <<'PYEOF' +import sys +sys.path.insert(0, sys.argv[1]) +import numpy as np +from common import p56 +x = np.fromfile(sys.argv[2], '= x, x >= 0""" + v = fl32(x) + if v < x: + v = struct.unpack('f', struct.pack('I', struct.unpack('I', struct.pack('f', v))[0] + 1))[0] + return v + + +def table(src, name, cols): + body = re.search(name + r'\[\d+\]\[%d\] = \{(.*?)\};' % cols, src, re.S).group(1) + v = [fl32(float(t.rstrip('f'))) for t in re.findall(r'[-+0-9.eE]+f', body)] + return [v[i:i + cols] for i in range(0, len(v), cols)] + + +def mask(src, name, n): + if not name: + return [1] * n + body = re.search(name + r'\[%d\] = \{(.*?)\};' % n, src, re.S).group(1) + return [int(t) for t in body.replace(',', ' ').split()] + + +def rnd(v): + """nearest integer, halves away from zero: |v - rnd(v)| <= 1/2""" + return int(v + 0.5) if v >= 0 else -int(-v + 0.5) + + +def scale(maxabs): + """largest t with maxabs * 2^t <= 32767""" + t = 0 + while maxabs * 2.0 ** (t + 1) <= 32767: + t += 1 + while maxabs * 2.0 ** t > 32767: + t -= 1 + return t + + +def image(rows, pairs, words): + """monomials x_a x_b (a < b doubled) at 2^-tm, then x at 2^-tx, as int16 pairs padded to words""" + dim = len(rows[0]) + mono = [[(1.0 if a == b else 2.0) * r[a] * r[b] for a, b in pairs] for r in rows] # exact in double + tm = scale(max(abs(v) for m in mono for v in m)) + tx = scale(max(abs(v) for r in rows for v in r)) + ints = [] + for r, m in zip(rows, mono): + h = [rnd(v * 2.0 ** tm) for v in m] + [rnd(v * 2.0 ** tx) for v in r] + h += [0] * (2 * words - len(h)) + ints.append(h) + mmax = [max(abs(h[k]) for h in ints) / 2.0 ** tm for k in range(len(pairs))] + xmax = [max(abs(h[len(pairs) + a]) for h in ints) / 2.0 ** tx for a in range(dim)] + return ints, tm, tx, mmax, xmax + + +def words_c(h): + return '{' + ', '.join('0x%08xu' % ((h[2 * k] & 0xffff) | (h[2 * k + 1] & 0xffff) << 16) + for k in range(len(h) // 2)) + '}' + + +def floats(v): + return '{' + ', '.join(f32(f32_up(x)) for x in v) + '}' + + +def emit(out, name, src, n24, n58, ok24, ok58): + p24, p58 = table(src, n24, 3), table(src, n58, 4) + u24, u58 = mask(src, ok24, len(p24)), mask(src, ok58, len(p58)) + i24, tm24, tx24, m24, x24 = image(p24, PAIRS24, 5) + i58, tm58, tx58, m58, x58 = image(p58, PAIRS58, 8) + # n3, n4 as the float code forms them, rounded up past its rounding + n3 = max(sum(v * v for v in r) for r, u in zip(p24, u24) if u) * (1 + 2.0 ** -20) + n4 = max(sum(v * v for v in r) for r, u in zip(p58, u58) if u) * (1 + 2.0 ** -20) + used = [r for r, u in zip(p58, u58) if u] + sx = [sum(r[a] for r in used) for a in range(4)] + sxx = [[sum(r[a] * r[b] for r in used) for b in range(4)] for a in range(4)] + out.append('static const uint32_t r24_%s[%d][5] = {' % (name, len(i24))) + out += [' ' + words_c(h) + ',' for h in i24] + out.append('};') + out.append('static const uint32_t r58_%s[%d][8] = {' % (name, len(i58))) + out += [' ' + words_c(h) + ',' for h in i58] + out.append('};') + out.append('const xombe_cq_q15_tab xombe__cq_q15_%s = {' % name) + out.append(' r24_%s, r58_%s, %d, %d, %d, %d,' % (name, name, tm24, tx24, tm58, tx58)) + tail = [floats(m24), floats(x24), floats(m58), floats(x58), f32(f32_up(n3)), f32(f32_up(n4)), str(len(used)), + '{' + ', '.join(f32(v) for v in sx) + '}', + '{' + ', '.join('{' + ', '.join(f32(v) for v in row) + '}' for row in sxx) + '}'] + line = ' ' + for i, t in enumerate(tail): + for tok in t.split(' '): + if len(line) + 1 + len(tok) > 116: + out.append(line) + line = ' ' + line += ' ' + tok + line += ',' if i < len(tail) - 1 else '};' + out.append(line) + + +def main(): + out = ['/* generated by scripts/gen_cq_tables.py, do not edit */', '#include "cq_q15_tables.h"', '', + '#if XOMBE_KERNELS_Q15 && (XOMBE_HAVE_ENCODER || XOMBE_HAVE_DSTAR)'] + for name, fn, n24, n58, ok24, ok58 in SETS: + src = open(os.path.join(ROOT, 'src', 'tables', fn)).read() + if name == 'dstar': + out.append('#if XOMBE_HAVE_DSTAR') + emit(out, name, src, n24, n58, ok24, ok58) + if name == 'dstar': + out.append('#endif') + out.append('#else') + out.append('typedef int xombe__cq_q15_tables_unused;') + out.append('#endif') + with open(OUT, 'w') as f: + f.write('\n'.join(out) + '\n') + + +if __name__ == '__main__': + main() diff --git a/xombe/scripts/gen_dsp_tables.py b/xombe/scripts/gen_dsp_tables.py new file mode 100644 index 0000000..2ea0bf2 --- /dev/null +++ b/xombe/scripts/gen_dsp_tables.py @@ -0,0 +1,230 @@ +#!/usr/bin/env python3 +"""writes src/tables/dsp_tables.c, closed-form values computed in double and rounded to float""" +import math +import os +import re +import struct + +ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') +OUT = os.path.join(ROOT, 'src', 'tables', 'dsp_tables.c') +TABLES = os.path.join(ROOT, 'src', 'tables', 'tables.c') + +DCT_BLK_J_MAX = 17 # XOMBE_DCT_BLK_J_MAX, largest spectral block length (xombe__blk) +DCT_BLK_ROWS = 6 # XOMBE_DCT_BLK_ROWS, one kernel row per DCT coefficient m = 0..5 +GRAIN_RAMP = 16 # XOMBE_GRAIN_RAMP +HALF_MIN, HALF_MAX = 76, 84 +LMAX = 56 +B0_COUNT = 120 +TW_N = 1024 # analysis FFT, smaller transforms take every (TW_N/n)-th twiddle +FFT = 1024 # XOMBE_FFT +BASE_WINDOW = 199 +PITCH_LPF_HALF = 10 +PITCH_WIN = 301 +TONE_SEG = 240 +TONE_FFT = 512 # XOMBE_TONE_FFT + + +def f32(x): + """x rounded to the nearest float, printed to read back exactly""" + if abs(x) < 1e-12: # cos(pi/2) and similar are exactly 0 + x = 0.0 + v = struct.unpack('f', struct.pack('f', x))[0] + s = '%.9g' % v + if 'e' not in s and '.' not in s: + s += '.0' + return s + 'f' + + +def fl32(x): + """x rounded to float, the result of a float operation whose exact value is x""" + return struct.unpack('f', struct.pack('f', x))[0] + + +def round_q(v): + """(int)(v + (v < 0 ? -0.5f : 0.5f)) for float v""" + return int(fl32(v + (-0.5 if v < 0 else 0.5))) + + +def rows(values, per_line=6, indent=' '): + lines = [] + for i in range(0, len(values), per_line): + lines.append(indent + ', '.join(values[i:i + per_line]) + ',') + return '\n'.join(lines) + + +def w0_table(): + """xombe__w0 as spelled in tables.c (the standard's pitch table as float)""" + src = open(TABLES).read() + body = re.search(r'xombe__w0\[XOMBE_B0_COUNT\] = \{(.*?)\};', src, re.S).group(1) + vals = [struct.unpack('f', struct.pack('f', float(v.rstrip('f'))))[0] for v in body.replace(',', ' ').split()] + assert len(vals) == B0_COUNT and all(a > b for a, b in zip(vals, vals[1:])) + return vals + + +def hamming(i, n): + return 0.54 - 0.46 * math.cos(2.0 * math.pi * i / (n - 1)) + + +def dct(J, m, i): + return math.cos(math.pi * m * (i + 0.5) / J) + + +def main(): + out = ['/* generated by scripts/gen_dsp_tables.py, do not edit */', '#include "dsp_tables.h"', ''] + + out.append('const float xombe__dct8[8][8] = {') + for m in range(8): + out.append(' {' + ', '.join(f32(dct(8, m, i)) for i in range(8)) + '},') + out.append('};') + out.append('') + + offs, vals = [], [] + for J in range(DCT_BLK_J_MAX + 1): + offs.append(str(len(vals))) + for m in range(DCT_BLK_ROWS): + vals.extend(f32(dct(J, m, i)) for i in range(J)) + out.append('const unsigned short xombe__dct_blk_off[XOMBE_DCT_BLK_J_MAX + 1] = {') + out.append(rows(offs, 12)) + out.append('};') + out.append('') + out.append('const float xombe__dct_blk[XOMBE_DCT_BLK_SIZE] = {') + out.append(rows(vals)) + out.append('};') + out.append('') + + out.append('const float xombe__ramp_cos[XOMBE_GRAIN_RAMP] = {') + out.append(rows([f32(math.cos(math.pi * j / GRAIN_RAMP)) for j in range(GRAIN_RAMP)])) + out.append('};') + out.append('') + out.append('const float xombe__ramp_sin[XOMBE_GRAIN_RAMP] = {') + out.append(rows([f32(math.sin(math.pi * j / GRAIN_RAMP)) for j in range(GRAIN_RAMP)])) + out.append('};') + out.append('') + + out.append('const float xombe__sqrt_n[XOMBE_HALF_MAX + 1] = {') + out.append(rows([f32(math.sqrt(n)) for n in range(HALF_MAX + 1)])) + out.append('};') + out.append('') + out.append('const float xombe__rsqrt_half[XOMBE_HALF_MAX - XOMBE_HALF_MIN + 1] = {') + out.append(rows([f32(1.0 / math.sqrt(N)) for N in range(HALF_MIN, HALF_MAX + 1)])) + out.append('};') + out.append('') + + out.append('const float xombe__half_log2[XOMBE_LMAX + 1] = {') + out.append(rows(['0.0f'] + [f32(0.5 * math.log2(L)) for L in range(1, LMAX + 1)])) + out.append('};') + out.append('') + + w0 = w0_table() + out.append('const float xombe__w0_mid[XOMBE_B0_COUNT - 1] = {') + out.append(rows([f32(math.sqrt(w0[b] * w0[b + 1])) for b in range(B0_COUNT - 1)])) + out.append('};') + out.append('') + + out.append('const xombe_cpx xombe__fft_tw[XOMBE_TW_N / 2] = {') + tw = [] + for k in range(TW_N // 2): + ang = -2.0 * math.pi * k / TW_N + tw.append('{%s, %s}' % (f32(math.cos(ang)), f32(math.sin(ang)))) + out.append(rows(tw, 3)) + out.append('};') + out.append('') + + out.append('#if XOMBE_HAVE_ENCODER') + out.append('const float xombe__base_win[XOMBE_BASE_WINDOW] = {') + out.append(rows([f32(hamming(i, BASE_WINDOW)) for i in range(BASE_WINDOW)])) + out.append('};') + out.append('') + + h = [] + for j in range(-PITCH_LPF_HALF, PITCH_LPF_HALF + 1): + x = 0.25 * j + sinc = 1.0 if j == 0 else math.sin(math.pi * x) / (math.pi * x) + h.append(0.25 * sinc * (0.54 + 0.46 * math.cos(math.pi * j / PITCH_LPF_HALF))) + s = 0.0 + for v in h: + s += v + lpf = [f32(float(f32(v)[:-1]) / s) for v in h] + out.append('const float xombe__pitch_lpf[2 * XOMBE_PITCH_LPF_HALF + 1] = {') + out.append(rows(lpf)) + out.append('};') + out.append('') + + # q15 low-pass taps (kern_q15_pitch.c) from the float taps, in float arithmetic as C computes it + # g[m] = h[20 - m] scaled so sum |g| <= 65536 after rounding (a 32-bit SMLAD sum of int16 can't overflow), + # paired, and again shifted by one + lpf = [fl32(float(v[:-1])) for v in lpf] + total = 0.0 + for v in lpf: + total = fl32(total + abs(v)) + gain = fl32(65000.0 / total) + g = [round_q(fl32(lpf[2 * PITCH_LPF_HALF - m] * gain)) for m in range(2 * PITCH_LPF_HALF + 1)] + taps = 2 * PITCH_LPF_HALF + 2 + ga = g + [0] * (taps - len(g)) + gb = [0] + g + [0] * (taps - 1 - len(g)) + def pairs(t): + return ['0x%08xu' % ((t[i] & 0xffff) | (t[i + 1] & 0xffff) << 16) for i in range(0, taps, 2)] + out.append('#if XOMBE_KERNELS_Q15') + out.append('const uint32_t xombe__pitch_lpf_q15[2][XOMBE_PITCH_LPF_PAIRS] = {') + for t in (ga, gb): + out.append(' {') + out.append(rows(pairs(t), 6, ' ' * 8)) + out.append(' },') + out.append('};') + out.append('const float xombe__pitch_lpf_q15_gain = %s;' % f32(gain)) + def q15(v): + return min(32767, math.floor(v * 32768.0 + 0.5)) & 0xffff + tq = [] + for j in range(FFT // 4): + ang = -2.0 * math.pi * j / (FFT // 2) + tq.append('0x%08xu' % (q15(math.cos(ang)) | q15(math.sin(ang)) << 16)) + out.append('const uint32_t xombe__fft_tw_q15[XOMBE_FFT / 4] = {') + out.append(rows(tq, 6)) + out.append('};') + tq = [] + for j in range(TONE_FFT // 4): + ang = -2.0 * math.pi * j / (TONE_FFT // 2) + tq.append('0x%08xu' % (q15(math.cos(ang)) | q15(math.sin(ang)) << 16)) + out.append('const uint32_t xombe__tone_tw_q15[XOMBE_TONE_FFT / 4] = {') + out.append(rows(tq, 6)) + out.append('};') + out.append('#endif') + out.append('') + + w = [hamming(j, PITCH_WIN) for j in range(PITCH_WIN)] + s2 = s4 = 0.0 + for v in w: + s2 += v * v + w2 = [v * v / s2 for v in w] + for v in w2: + s4 += v * v + out.append('const float xombe__pitch_w2[XOMBE_PITCH_WIN] = {') + out.append(rows([f32(v) for v in w2])) + out.append('};') + out.append('const float xombe__pitch_sum_w4 = %s;' % f32(s4)) + # q15 pitch window (kern_q15_pitch.c) from the float table, scaled to peak 32767, first half (symmetric) + w2f = [fl32(float(f32(v)[:-1])) for v in w2] + w2_gain = fl32(32767.0 / max(w2f)) + w2q = [round_q(fl32(v * w2_gain)) for v in w2f] + assert w2q == w2q[::-1] + w2q = w2q[:PITCH_WIN // 2 + 1] + out.append('#if XOMBE_KERNELS_Q15') + out.append('const int16_t xombe__pitch_w2_q15[XOMBE_PITCH_HALF + 1] = {') + out.append(rows([str(v) for v in w2q], 12)) + out.append('};') + out.append('const float xombe__pitch_w2_q15_gain = %s;' % f32(w2_gain)) + out.append('#endif') + out.append('') + + out.append('const float xombe__tone_win[XOMBE_TONE_SEG] = {') + out.append(rows([f32(0.5 - 0.5 * math.cos(2.0 * math.pi * i / (TONE_SEG - 1))) for i in range(TONE_SEG)])) + out.append('};') + out.append('#endif') + + assert len(vals) == DCT_BLK_ROWS * sum(range(DCT_BLK_J_MAX + 1)) + with open(OUT, 'w') as f: + f.write('\n'.join(out) + '\n') + + +if __name__ == '__main__': + main() diff --git a/xombe/scripts/gen_dstar_enc_tables.py b/xombe/scripts/gen_dstar_enc_tables.py new file mode 100644 index 0000000..128a186 --- /dev/null +++ b/xombe/scripts/gen_dstar_enc_tables.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +"""writes src/tables/dstar_enc_tables.c and dstar_enc_tables.h, the D-STAR encoder's noise reference and windows + +m_noise(N, b0) in scripts/data/dstar_tables.json is the fitted encoder model's mean voicing metric over 8 seeded +numpy white-noise draws, which C cannot reproduce, so it is tabulated for the (N, b0) pairs the encoder can reach, +as round(m*65536) in 16 bits (m < 1, smallest 0.18, relative error <= 3e-5)""" +import json +import math +import os +import struct + +ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') +OUT_C = os.path.join(ROOT, 'src', 'tables', 'dstar_enc_tables.c') +OUT_H = os.path.join(ROOT, 'src', 'tables', 'dstar_enc_tables.h') +DATA = os.path.join(ROOT, 'scripts', 'data', 'dstar_tables.json') + +N_MIN, N_MAX = 199, 321 +N_COUNT = (N_MAX - N_MIN) // 2 + 1 +B0_VOICE_MAX = 123 +SCALE = 65536 +TONE_LEN, NZ_LEN = 160, 134 + + +def f32(x): + t = '%.9g' % struct.unpack(' flags of 500 Hz bands 0..7 as the decoder plays them (code 4 plays as 12) + vuv = [[int(ch) for ch in s] for s in T['VUV0']] + # D-STAR tone index T -> AMBE+2 tone ID: T 0..15 DTMF (T = 4*column + row), 16..19 call progress, + # 37..154 single tones at 31.25*(T - 32) Hz, every other T invalid + tone = [TONE_NONE if t is None else t for t in T['tone_id']] + # b0 of the D-STAR voice frame carrying Knox tone ID 144 + i (observed) + knox_b0 = T['knox_b0'] + assert (len(vuv), len(tone), len(knox_b0)) == (16, 256, 16) + + c = ['/* generated by scripts/gen_dstar_tables.py, do not edit */', + '#include "dstar_tables.h"', ''] + c += c_matrix('xombe__ds_w0', 'float', ['XOMBE_DS_B0_COUNT'], w0, f32) + [''] + c += c_matrix('xombe__ds_lt', 'unsigned char', ['XOMBE_DS_B0_COUNT'], lt, str) + [''] + c += c_matrix('xombe__ds_dg', 'float', ['64'], dg, f32) + [''] + c += c_matrix('xombe__ds_prba24', 'float', ['512', '3'], p24, f32) + [''] + c += c_matrix('xombe__ds_prba58', 'float', ['128', '4'], p58, f32) + [''] + for k, n in enumerate([16, 16, 16, 8]): + c += c_matrix('xombe__ds_hoc%d' % (k + 5), 'float', [str(n), '4'], hoc[k], f32) + [''] + c += c_matrix('xombe__ds_ok_dg', 'unsigned char', ['64'], ok_dg, str) + [''] + c += c_matrix('xombe__ds_ok_prba24', 'unsigned char', ['512'], ok24, str) + [''] + c += c_matrix('xombe__ds_ok_prba58', 'unsigned char', ['128'], ok58, str) + [''] + for k, n in enumerate([16, 16, 16, 8]): + c += c_matrix('xombe__ds_ok_hoc%d' % (k + 5), 'unsigned char', [str(n)], ok_hoc[k], str) + [''] + c += c_matrix('xombe__ds_vuv', 'unsigned char', ['16', '8'], vuv, str) + [''] + c += c_matrix('xombe__ds_tone_id', 'unsigned char', ['256'], tone, str) + [''] + c += c_matrix('xombe__ds_knox_b0', 'unsigned char', ['16'], knox_b0, str) + + h = '''#ifndef XOMBE_DSTAR_TABLES_H +#define XOMBE_DSTAR_TABLES_H + +/* D-STAR (AMBE 2400) tables, generated by scripts/gen_dstar_tables.py, do not edit + each value is a fitted double rounded once to float, spectral block lengths are AMBE+2's xombe__blk */ + +#define XOMBE_DS_B0_COUNT %(nb0)d + +/* pitch grid f0 = 2^(P0 + P1*(b0 + 1/2)) cycles/sample, from doubles %(p0)r and %(p1)r */ +#define XOMBE_DS_P0 %(p0f)s +#define XOMBE_DS_P1 %(p1f)s +/* amplitude prediction weight and gain recursion (0: b2 is an absolute gain index) */ +#define XOMBE_DS_RHO %(rho)s +#define XOMBE_DS_GRHO %(grho)s +#define XOMBE_DS_TONE_NONE %(none)d + +/* f0 in cycles/sample and L = floor(0.4627/f0) clamped to 9..56, both from the double f0 (voice b0 0..123) */ +extern const float xombe__ds_w0[XOMBE_DS_B0_COUNT]; +extern const unsigned char xombe__ds_lt[XOMBE_DS_B0_COUNT]; +/* gain (b2), PRBA (b3, b4), and HOC (b5..b8, rows of 4, first min(J, 6) - 2 used) codebooks */ +extern const float xombe__ds_dg[64]; +extern const float xombe__ds_prba24[512][3]; +extern const float xombe__ds_prba58[128][4]; +extern const float xombe__ds_hoc5[16][4]; +extern const float xombe__ds_hoc6[16][4]; +extern const float xombe__ds_hoc7[16][4]; +extern const float xombe__ds_hoc8[8][4]; +/* 1 where the fit had data for the entry, the closed-loop quantizer skips the others */ +extern const unsigned char xombe__ds_ok_dg[64]; +extern const unsigned char xombe__ds_ok_prba24[512]; +extern const unsigned char xombe__ds_ok_prba58[128]; +extern const unsigned char xombe__ds_ok_hoc5[16]; +extern const unsigned char xombe__ds_ok_hoc6[16]; +extern const unsigned char xombe__ds_ok_hoc7[16]; +extern const unsigned char xombe__ds_ok_hoc8[8]; +/* b1 -> eight 500 Hz band flags as the decoder plays them (code 4 plays as 12) */ +extern const unsigned char xombe__ds_vuv[16][8]; +/* tone index T (8 bits) -> AMBE+2 tone ID, or XOMBE_DS_TONE_NONE */ +extern const unsigned char xombe__ds_tone_id[256]; +/* encoder sends Knox tones (AMBE+2 IDs 144..159, no D-STAR tone code) as voice frames at this b0 per ID */ +extern const unsigned char xombe__ds_knox_b0[16]; + +#endif +''' % dict(nb0=B0_COUNT, p0=p0, p1=p1, p0f=f32(p0), p1f=f32(p1), rho=f32(rho), grho=f32(grho), + none=TONE_NONE) + with open(OUT_C, 'w') as f: + f.write('\n'.join(c) + '\n') + with open(OUT_H, 'w') as f: + f.write(h) + print('wrote', OUT_C, OUT_H) + + +if __name__ == '__main__': + main() diff --git a/xombe/scripts/gen_inputs.py b/xombe/scripts/gen_inputs.py new file mode 100755 index 0000000..61c7328 --- /dev/null +++ b/xombe/scripts/gen_inputs.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +import argparse +import hashlib +import os +import struct +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'tools')) +from common import CLIPS, DITHER_DB as GAINS_DB, E3IN, E3V + + +def dither(samples, gain_db): + g = 10.0 ** (gain_db / 20.0) + out = [] + for x in samples: + y = round(g * x) + out.append(32767 if y > 32767 else -32768 if y < -32768 else y) + return out + + +def main(): + ap = argparse.ArgumentParser(description='Regenerate the dithered E3 inputs and check them against SHA256SUMS') + ap.add_argument('--dir', default=E3V) + ap.add_argument('--out', default=E3IN, help='output directory (default $XOMBE_BUILD/e3in)') + ap.add_argument('--write-manifest', action='store_true') + a = ap.parse_args() + out_dir = a.out + os.makedirs(out_dir, exist_ok=True) + manifest_path = os.path.join(a.dir, 'SHA256SUMS') + expected = {} + if not a.write_manifest and not os.path.exists(manifest_path): + print('%s is missing; regenerate it with --write-manifest' % manifest_path, file=sys.stderr) + return 1 + if not a.write_manifest: + for line in open(manifest_path): + digest, name = line.split() + expected[name] = digest + lines, bad = [], 0 + for clip in CLIPS: + raw = open(os.path.join(a.dir, clip + '_orig.raw'), 'rb').read() + x = struct.unpack('<%dh' % (len(raw) // 2), raw) + for k, g in enumerate(GAINS_DB): + data = struct.pack('<%dh' % len(x), *dither(x, g)) + name = '%s.d%d.raw' % (clip, k) + open(os.path.join(out_dir, name), 'wb').write(data) + digest = hashlib.sha256(data).hexdigest() + lines.append('%s %s' % (digest, name)) + if not a.write_manifest and expected.get(name) != digest: + print('MISMATCH %s' % name) + bad += 1 + if a.write_manifest: + open(manifest_path, 'w').write('\n'.join(lines) + '\n') + print('wrote %s' % manifest_path) + else: + print('%d inputs regenerated, %d mismatches against SHA256SUMS' % (len(lines), bad)) + return 1 if bad else 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/xombe/scripts/release_buildinfo.sh b/xombe/scripts/release_buildinfo.sh new file mode 100755 index 0000000..55dfc45 --- /dev/null +++ b/xombe/scripts/release_buildinfo.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# release_buildinfo.sh: the tools behind a release tarball and, on Debian, every installed package +set -eu +git --version +xz --version | head -n 1 +if command -v dpkg-query > /dev/null; then + dpkg-query -W -f='${db:Status-Abbrev} ${Package}:${Architecture} ${Version}\n' | + awk '$1 == "ii" { print $2, $3 }' | LC_ALL=C sort +fi diff --git a/xombe/scripts/release_deps.sh b/xombe/scripts/release_deps.sh new file mode 100755 index 0000000..927029b --- /dev/null +++ b/xombe/scripts/release_deps.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# release_deps.sh: installs release_packages.lock into the release container (release_lock.sh's base), from +# deb.debian.org or else the snapshot +set -eu +here=$(cd "$(dirname "$0")" && pwd) +rm -f /etc/apt/sources.list.d/* +printf '%s\n' 'deb http://deb.debian.org/debian trixie main' \ + 'deb [check-valid-until=no] http://snapshot.debian.org/archive/debian/20261111T000000Z trixie main' \ + > /etc/apt/sources.list +apt-get -o Acquire::Retries=5 update || true +# shellcheck disable=SC2046 +DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $(cat "$here/release_packages.lock") +rm -rf /var/lib/apt/lists/* diff --git a/xombe/scripts/release_lock.sh b/xombe/scripts/release_lock.sh new file mode 100755 index 0000000..f919a6d --- /dev/null +++ b/xombe/scripts/release_lock.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# release_lock.sh: prints the packages (name=version) that release_deps.sh's snapshot adds to the base image, the +# contents of release_packages.lock. CONTAINER picks the engine (podman) +set -eu +base=docker.io/library/debian@sha256:2dc419c6d7fe3dad0a2f9fd469c34cc90b0f9ba642d8fde837fe3d7d34a0e7f1 +here=$(cd "$(dirname "$0")" && pwd) +engine=${CONTAINER:-podman} +snap=$(grep -o 'http://snapshot\.debian\.org/archive/debian/[0-9TZ]*' "$here/release_deps.sh") +"$engine" run --rm "$base" sh -euc ' + export DEBIAN_FRONTEND=noninteractive + q() { dpkg-query -W -f="\${Package}=\${Version}\n" | LC_ALL=C sort; } + q > /tmp/base + rm -f /etc/apt/sources.list.d/* + echo "deb [check-valid-until=no] $1 trixie main" > /etc/apt/sources.list + apt-get -qq -o Acquire::Retries=5 update + apt-get -qq install -y --no-install-recommends ca-certificates git xz-utils > /dev/null + q | LC_ALL=C comm -13 /tmp/base - +' _ "$snap" diff --git a/xombe/scripts/release_packages.lock b/xombe/scripts/release_packages.lock new file mode 100644 index 0000000..d9d3eff --- /dev/null +++ b/xombe/scripts/release_packages.lock @@ -0,0 +1,36 @@ +ca-certificates=20250419 +git-man=1:2.47.3-0+deb13u1 +git=1:2.47.3-0+deb13u1 +libbrotli1=1.1.0-2+b7 +libcom-err2=1.47.2-3+b12 +libcurl3t64-gnutls=8.14.1-2+deb13u5 +liberror-perl=0.17030-1 +libexpat1=2.8.3-1~deb13u1 +libffi8=3.4.8-2 +libgdbm-compat4t64=1.24-2 +libgdbm6t64=1.24-2 +libgnutls30t64=3.8.9-3+deb13u4 +libgssapi-krb5-2=1.21.3-5+deb13u1 +libidn2-0=2.3.8-2 +libk5crypto3=1.21.3-5+deb13u1 +libkeyutils1=1.6.3-6 +libkrb5-3=1.21.3-5+deb13u1 +libkrb5support0=1.21.3-5+deb13u1 +libldap2=2.6.10+dfsg-1 +libnghttp2-14=1.64.0-1.1+deb13u1 +libnghttp3-9=1.8.0-1 +libngtcp2-16=1.11.0-1+deb13u1 +libngtcp2-crypto-gnutls8=1.11.0-1+deb13u1 +libp11-kit0=0.25.5-3 +libperl5.40=5.40.1-6+deb13u1 +libpsl5t64=0.21.2-1.1+b1 +librtmp1=2.4+20151223.gitfa8646d.1-2+b5 +libsasl2-2=2.1.28+dfsg1-9 +libsasl2-modules-db=2.1.28+dfsg1-9 +libssh2-1t64=1.11.1-1+deb13u2 +libtasn1-6=4.20.0-2+deb13u1 +libunistring5=1.3-2 +openssl=3.5.7-1~deb13u2 +perl-modules-5.40=5.40.1-6+deb13u1 +perl=5.40.1-6+deb13u1 +xz-utils=5.8.1-1+deb13u1 diff --git a/xombe/scripts/release_tarball.sh b/xombe/scripts/release_tarball.sh new file mode 100755 index 0000000..bf4a19e --- /dev/null +++ b/xombe/scripts/release_tarball.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# release_tarball.sh [REF [OUT]]: writes xombe-X.Y.Z.tar.xz (git archive of REF, default HEAD) and +# xombe-X.Y.Z.buildinfo to OUT (default dist). byte-identical across hosts in the release container +# (release_deps.sh), the version is REF's include/xombe.h +set -eu +ref=${1:-HEAD} +root=$(cd "$(dirname "$0")/.." && pwd) +out=${2:-$root/dist} +part() { git -C "$root" show "$ref:include/xombe.h" | sed -n "s/^#define XOMBE_VERSION_$1 \([0-9][0-9]*\)\$/\1/p"; } +ver=$(part MAJOR).$(part MINOR).$(part PATCH) +case $ver in +*[!0-9.]* | .* | *..* | *.) echo "no XOMBE_VERSION_MAJOR/MINOR/PATCH in $ref:include/xombe.h" >&2; exit 1 ;; +esac +name=xombe-$ver +mkdir -p "$out" +git -C "$root" archive --format=tar --prefix="$name/" "$ref" -- . ':!.gitignore' | xz -9 -T1 > "$out/$name.tar.xz" +"$root/scripts/release_buildinfo.sh" > "$out/$name.buildinfo" diff --git a/xombe/scripts/size_table.sh b/xombe/scripts/size_table.sh new file mode 100755 index 0000000..2363a0b --- /dev/null +++ b/xombe/scripts/size_table.sh @@ -0,0 +1,188 @@ +#!/bin/sh +# size_table.sh [WORKDIR]: state sizes (test/sizes.c) and worst-case stack per public call for the four builds +# (float and q15 kernels, XOMBE_DSTAR off and on), as Markdown tables. stack is from -fcallgraph-info=su +# (GCC 10 or later) walked over the library's call graph, on the host and, when arm-none-eabi-gcc is installed, +# on a Cortex-M33 build. WORKDIR (default: a temporary directory, removed at the end) holds the builds. +# needs cmake and python3, CC picks the host compiler, ARM_CC the cross compiler +set -eu +ROOT=$(cd "$(dirname "$0")/.." && pwd) +PY=${PYTHON:-python3} +ARM_CC=${ARM_CC:-arm-none-eabi-gcc} +JOBS=${JOBS:-4} +if [ $# -gt 0 ]; then + W=$1 + mkdir -p "$W" +else + W=$(mktemp -d) + trap 'rm -rf "$W"' EXIT +fi +CI="-fstack-usage -fcallgraph-info=su" +ARM_FLAGS="-mcpu=cortex-m33 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16" +CONFIGS="float:OFF float:ON q15:OFF q15:ON" +command -v "$ARM_CC" > /dev/null && arm=1 || arm=0 + +build() { # build DIR KERNELS DSTAR [cmake options] + d=$1 k=$2 ds=$3 + shift 3 + cmake -S "$ROOT" -B "$d" -DCMAKE_BUILD_TYPE=Release -DXOMBE_KERNELS=$k -DXOMBE_DSTAR=$ds -DXOMBE_BUILD_TOOLS=OFF \ + -DXOMBE_INSTALL=OFF "$@" > "$d.log" 2>&1 && cmake --build "$d" -j "$JOBS" >> "$d.log" 2>&1 || + { cat "$d.log" >&2; exit 1; } +} + +for c in $CONFIGS; do + k=${c%:*} ds=${c#*:} + build "$W/host-$k-$ds" $k $ds -DXOMBE_BUILD_TESTS=ON "-DCMAKE_C_FLAGS=$CI" + if [ $arm = 1 ]; then + build "$W/m33-$k-$ds" $k $ds -DXOMBE_BUILD_TESTS=OFF -DCMAKE_SYSTEM_NAME=Generic -DCMAKE_C_COMPILER="$ARM_CC" \ + -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY "-DCMAKE_C_FLAGS_RELEASE=-O2 -DNDEBUG" "-DCMAKE_C_FLAGS=$ARM_FLAGS $CI" + fi +done + +echo "### State (bytes) and encoder delay (frames), $(uname -m)" +echo +"$W/host-float-OFF/sizes" --header +for c in $CONFIGS; do + "$W/host-${c%:*}-${c#*:}/sizes" +done +echo +targets="x86-64" +[ $arm = 1 ] && targets="$targets M33" +echo "### Worst-case stack per public call (bytes)" +echo +"$PY" - "$ROOT" "$W" "$targets" $CONFIGS << 'EOF' +import glob, os, re, sys + +root, work, targets, configs = sys.argv[1], sys.argv[2], sys.argv[3].split(), sys.argv[4:] +node_re = re.compile(r'node: \{ title: "([^"]*)" label: "([^"]*)"') +edge_re = re.compile(r'edge: \{ sourcename: "([^"]*)" targetname: "([^"]*)"(?: label: "([^"]*)")?') +comment_re = re.compile(r'/\*.*?\*/|//[^\n]*', re.S) + + +def short(title): + return title.rsplit(':', 1)[-1] + + +def address_taken(stack): + """functions named in the library sources other than in a call or declaration: the targets an indirect call + may reach, for a static function only in its own file""" + text = {} + for f in glob.glob(os.path.join(root, 'src', '**', '*.[ch]'), recursive=True): + text[os.path.realpath(f)] = comment_re.sub(' ', open(f).read()) + out = set() + for t in stack: + name = short(t) + files = [os.path.realpath(t.rsplit(':', 1)[0])] if ':' in t else list(text) + pat = re.compile(r'(?\w])%s\b(?!\s*\()' % re.escape(name)) + if any(pat.search(text.get(f, '')) for f in files): + out.add(t) + return out + + +def load(build): + """call graph of the library's objects: {fn: bytes}, {fn: [callees]}, flags, unresolved indirect calls""" + stack, calls, flag, src_lines, where_def = {}, {}, {}, {}, {} + for ci in glob.glob(os.path.join(build, 'CMakeFiles', '*', 'src', '**', '*.ci'), recursive=True): + for line in open(ci): + m = node_re.match(line) + if m: + parts = m.group(2).split('\\n') + if len(parts) > 2: + n, kind = re.match(r'(\d+) bytes \((.*)\)', parts[2]).groups() + t = m.group(1) + stack[t] = max(stack.get(t, 0), int(n)) + where_def[t] = parts[1].rsplit(':', 2)[0] + if kind == 'dynamic': + flag[t] = 'unbounded' + calls.setdefault(t, set()) + continue + m = edge_re.match(line) + if m: + src, dst, where = m.groups() + if dst == '__indirect_call': + dst = 'indirect@' + (where or '?') + calls.setdefault(src, set()).add(dst) + by_short = {} + for t in stack: + by_short.setdefault(short(t), []).append(t) + taken = address_taken(stack) + unresolved = set() + for src in list(calls): + out = set() + for dst in calls[src]: + if dst.startswith('indirect@'): + f, l = dst[len('indirect@'):].rsplit(':', 2)[:2] + text = src_lines.setdefault(f, open(f).read().split('\n') if os.path.exists(f) else []) + text = text[int(l) - 1] if int(l) <= len(text) else '' + if 'XOMBE_TAP' in text: + continue # test tap callback, runs on the caller's own stack + if taken: + out.update(taken) + else: + unresolved.add('%s:%s' % (os.path.relpath(f, root), l)) + elif dst in stack: + out.add(dst) + elif dst in by_short and len(by_short[dst]) == 1: + out.add(by_short[dst][0]) + # otherwise a library outside xombe (libc, libm), not counted + calls[src] = out + return stack, calls, flag, unresolved, taken, where_def + + +def worst(fn, stack, calls, memo, path): + if fn in path: + return None # recursion + if fn in memo: + return memo[fn] + path.add(fn) + best = 0 + for c in calls.get(fn, ()): + w = worst(c, stack, calls, memo, path) + if w is None: + path.discard(fn) + return None + best = max(best, w) + path.discard(fn) + memo[fn] = stack.get(fn, 0) + best + return memo[fn] + + +cols, notes = [], [] +for t in targets: + for c in configs: + k, ds = c.split(':') + b = os.path.join(work, '%s-%s-%s' % ('host' if t == 'x86-64' else 'm33', k, ds)) + stack, calls, flag, unresolved, taken, where_def = load(b) + memo, res = {}, {} + for fn in stack: + if fn.startswith('xombe_') and not fn.startswith('xombe__') and ':' not in fn: + w = worst(fn, stack, calls, memo, set()) + res[fn] = 'recursive' if w is None else str(w) + if ds == 'ON': + # the DMR-only encoder never enters src/dstar: the same walk without those functions + dsdir = os.path.join(os.path.realpath(root), 'src', 'dstar') + os.sep + amb = {f: {c for c in cs if not os.path.realpath(where_def.get(c, '')).startswith(dsdir)} + for f, cs in calls.items()} + for fn in ('xombe_enc_frame', 'xombe_enc_frame_bits'): + if fn in stack: + w = worst(fn, stack, amb, {}, set()) + res[fn + ', DMR output only'] = 'recursive' if w is None else str(w) + cols.append(('%s %s D-STAR %s' % (t, k, ds.lower()), res)) + if unresolved: + notes.append('%s %s D-STAR %s: unresolved indirect calls at %s' % (t, k, ds.lower(), + ', '.join(sorted(unresolved)))) + notes.append('%s %s D-STAR %s: indirect calls bounded by %s' % (t, k, ds.lower(), + ', '.join(sorted(map(short, taken))))) + if flag: + notes.append('%s %s D-STAR %s: unbounded dynamic stack in %s' % (t, k, ds.lower(), + ', '.join(sorted(flag)))) +names = sorted(set().union(*[set(r) for _, r in cols])) +print('| call | ' + ' | '.join(c for c, _ in cols) + ' |') +print('|---|' + '---|' * len(cols)) +for n in names: + fn, _, what = n.partition(', ') + print('| `%s`%s | ' % (fn, ' (%s)' % what if what else '') + ' | '.join(r.get(n, '-') for _, r in cols) + ' |') +print() +print('stack of libc and libm callees not included, test tap callbacks not included') +for n in notes: + print(n) +EOF diff --git a/xombe/src/common/bits.c b/xombe/src/common/bits.c new file mode 100644 index 0000000..a5582c2 --- /dev/null +++ b/xombe/src/common/bits.c @@ -0,0 +1,99 @@ +#include "bits.h" +#include "xombe.h" + +static const uint8_t b0_bits[] = {0, 1, 2, 3, 37, 38, 39}; +static const uint8_t b1_bits[] = {4, 5, 6, 7, 35}; +static const uint8_t b2_bits[] = {8, 9, 10, 11, 36}; +static const uint8_t b3_bits[] = {12, 13, 14, 15, 16, 17, 18, 19, 43}; +static const uint8_t b4_bits[] = {20, 21, 22, 23, 40, 41, 42}; +static const uint8_t b5_bits[] = {24, 25, 26, 27, 44}; +static const uint8_t b6_bits[] = {28, 29, 30, 45}; +static const uint8_t b7_bits[] = {31, 32, 33, 46}; +static const uint8_t b8_bits[] = {34, 47, 48}; + +static const uint8_t *const field_bits[9] = {b0_bits, b1_bits, b2_bits, b3_bits, b4_bits, + b5_bits, b6_bits, b7_bits, b8_bits}; +static const uint8_t field_width[9] = {7, 5, 5, 9, 7, 5, 4, 4, 3}; + +void xombe__unpack_bits(const uint8_t *bytes, int count, uint8_t *bits) +{ + int i; + for (i = 0; i < count; i++) + bits[i] = (uint8_t)((bytes[i >> 3] >> (7 - (i & 7))) & 1); +} + +void xombe__pack_bits(const uint8_t *bits, int count, uint8_t *bytes) +{ + int i; + for (i = 0; i < (count + 7) / 8; i++) + bytes[i] = 0; + for (i = 0; i < count; i++) + if (bits[i]) + bytes[i >> 3] |= (uint8_t)(0x80 >> (i & 7)); +} + +void xombe__unpack49(const uint8_t bytes[7], uint8_t d[49]) +{ + xombe__unpack_bits(bytes, 49, d); +} + +void xombe__pack49(const uint8_t d[49], uint8_t bytes[7]) +{ + xombe__pack_bits(d, 49, bytes); +} + +int xombe__popcount32(uint32_t v) +{ + int n = 0; + for (; v; v &= v - 1) + n++; + return n; +} + +int xombe__get_bits(const uint8_t *d, int first, int count) +{ + int v = 0, i; + for (i = 0; i < count; i++) + v = (v << 1) | d[first + i]; + return v; +} + +void xombe__put_bits(uint8_t *d, int first, int count, int value) +{ + int i; + for (i = 0; i < count; i++) + d[first + i] = (uint8_t)((value >> (count - 1 - i)) & 1); +} + +int xombe__frame_class(const uint8_t d[49]) +{ + int c = xombe__get_bits(d, 0, 6); + if (c < 60) + return XOMBE_CLASS_VOICE; + if (c < 62) + return XOMBE_CLASS_ERASURE; + if (c == 62) + return XOMBE_CLASS_SILENCE; + return XOMBE_CLASS_TONE; +} + +void xombe__get_fields(const uint8_t d[49], int b[9]) +{ + int f, i; + for (f = 0; f < 9; f++) { + int v = 0; + for (i = 0; i < field_width[f]; i++) + v = (v << 1) | d[field_bits[f][i]]; + b[f] = v; + } +} + +void xombe__put_fields(const int b[9], uint8_t d[49]) +{ + int f, i; + for (f = 0; f < 9; f++) { + int w = field_width[f]; + for (i = 0; i < w; i++) + d[field_bits[f][i]] = (uint8_t)((b[f] >> (w - 1 - i)) & 1); + } +} diff --git a/xombe/src/common/bits.h b/xombe/src/common/bits.h new file mode 100644 index 0000000..203187d --- /dev/null +++ b/xombe/src/common/bits.h @@ -0,0 +1,19 @@ +#ifndef XOMBE_BITS_H +#define XOMBE_BITS_H + +#include + +/* one bit per byte <-> packed MSB first */ +void xombe__unpack_bits(const uint8_t *bytes, int count, uint8_t *bits); +void xombe__pack_bits(const uint8_t *bits, int count, uint8_t *bytes); +void xombe__unpack49(const uint8_t bytes[7], uint8_t d[49]); +void xombe__pack49(const uint8_t d[49], uint8_t bytes[7]); +int xombe__popcount32(uint32_t v); +int xombe__frame_class(const uint8_t d[49]); +void xombe__get_fields(const uint8_t d[49], int b[9]); +void xombe__put_fields(const int b[9], uint8_t d[49]); +/* count <= 24 bits starting at d[first], MSB first */ +int xombe__get_bits(const uint8_t *d, int first, int count); +void xombe__put_bits(uint8_t *d, int first, int count, int value); + +#endif diff --git a/xombe/src/common/consts.h b/xombe/src/common/consts.h new file mode 100644 index 0000000..a4d08a3 --- /dev/null +++ b/xombe/src/common/consts.h @@ -0,0 +1,31 @@ +#ifndef XOMBE_CONSTS_H +#define XOMBE_CONSTS_H + +#define XOMBE_FS 8000.0f +/* Hz -> cycles/sample, the unit of every frequency (f0 = 1/period) but the tone tables and tone detector */ +#define XOMBE_HZ(f) ((f) / XOMBE_FS) +#define XOMBE_DB(db) ((db) / 3.01029996f) /* dB -> log2 power units */ +/* 8 voicing bands of 500 Hz, 16 = 8000/500 per cycle/sample, so the band of f is floor(16*f), exact in binary */ +#define XOMBE_BANDS_PER_UNIT 16.0f +/* decoder boosts harmonics above this by f/XOMBE_HF_CORNER, encoder targets pre-compensate half of that */ +#define XOMBE_HF_CORNER XOMBE_HZ(2400.0f) +#define XOMBE_RHO 0.65f +#define XOMBE_AMP_MIN (-15.0f) +#define XOMBE_AMP_MAX (15.0f - 1.0f / 2048.0f) +#define XOMBE_GAIN_MAX 13.0f +#define XOMBE_SILENCE_F0 0.031324f +#define XOMBE_SILENCE_L 15 +#define XOMBE_SILENCE_GAIN_OFFSET 2.0f +#define XOMBE_PULSE_F0 (64.346f / 8000.0f) +#define XOMBE_PULSE_L 56 +#define XOMBE_PULSE_B1_MIN 18 +#define XOMBE_SILENCE_B0 124 +#define XOMBE_SILENCE_B1 16 +/* AMBE+2 silence frame, 7 bytes as xombe_dec_frame takes them */ +#define XOMBE_SILENCE_FRAME {0xF8, 0x01, 0xA9, 0x9F, 0x8C, 0xE0, 0x80} +#define XOMBE_UNVOICED_B1 16 +#define XOMBE_PI 3.14159265358979323846 +#define XOMBE_PI_F 3.14159265f +#define XOMBE_LOG2_10 3.32192809f + +#endif diff --git a/xombe/src/common/cquant.c b/xombe/src/common/cquant.c new file mode 100644 index 0000000..20142c2 --- /dev/null +++ b/xombe/src/common/cquant.c @@ -0,0 +1,1636 @@ +#include +#include +#include "cquant.h" +#include "../tables/tables.h" +#include "../tables/dsp_tables.h" +#if XOMBE_KERNELS_Q15 +#include "../dsp/q15ops.h" +#if XOMBE_HAVE_DSTAR +#include "../dstar/dstar_internal.h" +#endif +#endif + +#define CQ_INF 3.0e38f +#define CQ_AMIN (-15.0f) +#define CQ_SQRT2 1.41421356f +/* relative slack of the pair search's row bound against float rounding (float eps is 6e-8) */ +#define CQ_BOUND_SLACK 1e-5f +#define CQ_BANDS 32 /* bound bands of the pair search's row order */ +#define CQ_ROW_COST 4 /* cap units of a row, a pair is 1 (Cortex-M33: ~280 cycles a row, ~85 a pair) */ + +#if XOMBE_KERNELS_Q15 +#define CQ_BIAS 0x40000000u /* 2^30: |v| <= 2^29 shifted to unsigned, so v >> k floors without a signed shift */ +#endif + +#ifdef XOMBE_CQ_STATS +long xombe__cq_stat[4]; /* pair searches, rows evaluated, pairs evaluated, columns scanned */ +#define CQ_STAT(k) (xombe__cq_stat[k]++) +#else +#define CQ_STAT(k) ((void)0) +#endif + +static int usable(const unsigned char *mask, int i) +{ + return !mask || mask[i]; +} + +static float clip(float v, float lo, float hi) +{ + return v < lo ? lo : v > hi ? hi : v; +} + +void xombe__cq_amp_weights(const float *t, int L, float gamma, float floor_, float *w) +{ + float mx = t[1]; + int l; + for (l = 2; l <= L; l++) + if (t[l] > mx) + mx = t[l]; + w[0] = 0.0f; + for (l = 1; l <= L; l++) { + float v = exp2f(gamma * (t[l] - mx)); + w[l] = v > floor_ ? v : floor_; + } +} + +#if XOMBE_KERNELS_Q15 +/* int16 pair (lo, hi) of values in range */ +static uint32_t pair16(int32_t lo, int32_t hi) +{ + return ((uint32_t)lo & 0xffffu) | (uint32_t)hi << 16; +} + +/* 2^e, -126 <= e <= 127 */ +static float pow2i(int e) +{ + uint32_t b = (uint32_t)(e + 127) << 23; + float f; + memcpy(&f, &b, sizeof(f)); + return f; +} + +/* E with |v| < 2^E (2^(E-1) <= |v| for normal v) */ +static int expo(float v) +{ + uint32_t b; + memcpy(&b, &v, sizeof(b)); + return (int)(b >> 23 & 255) - 126; +} + +/* (int)(v rounded to nearest), |v| < 2^22 so v +/- 1/2 is exact and the error is at most 1/2 */ +static int32_t round_i(float v) +{ + return (int32_t)(v + (v < 0.0f ? -0.5f : 0.5f)); +} + +/* rounds c[0..n) to ci = c*2^s, s the largest at most min(smax, 13 - E(max |c|)) with + sum (|c| 2^s + 1/2)*mx*2^t <= lim, mx the image columns' maxima (units of 2^-t). returns s, and in *err a bound + on |sum c*m - 2^-(s+t) sum ci*mi| over the rows (each mi within 1/2 of m*2^t): sum |c| 2^-(t+1) + 2^-(s+1) sum mx + s = -100: c too large */ +static int quant_coef(const float *c, int n, const float *mx, int t, int smax, float lim, int32_t *ci, float *err) +{ + float cm = 0.0f, sc = 0.0f, sm = 0.0f, u, f; + int k, s; + for (k = 0; k < n; k++) { + float a = fabsf(c[k]); + cm = a > cm ? a : cm; + sc += a; + sm += mx[k]; + } + s = 13 - expo(cm); + s = s > smax ? smax : s; + s = s > 100 ? 100 : s < -100 ? -100 : s; + u = pow2i(t); + for (;; s--) { + float tot = 0.0f; + f = pow2i(s); + for (k = 0; k < n; k++) + tot += (fabsf(c[k]) * f + 0.5f) * mx[k] * u; + if (tot <= lim || s == -100) + break; + } + for (k = 0; k < n; k++) + ci[k] = round_i(c[k] * f); + *err = (sc * pow2i(-t - 1) + pow2i(-s - 1) * sm) * 1.0001f; + return s; +} + +/* sorts v[0..n-1] ascending with its tags, ties in input order (the stable order): buckets by value, the + bucket index being monotonic in v, then insertion within them */ +static void sort_proj(float *v, short *tag, int n) +{ + float tv[128], lo, hi, sc; + short tt[128]; + unsigned char bk[128]; + int cnt[129], i, j; + if (n < 2) + return; + lo = hi = v[0]; + for (i = 1; i < n; i++) { + lo = v[i] < lo ? v[i] : lo; + hi = v[i] > hi ? v[i] : hi; + } + if (!(hi > lo)) + return; + sc = (float)(n - 1) / (hi - lo); + memset(cnt, 0, sizeof(int) * (n + 1)); + for (i = 0; i < n; i++) { + int b = (int)((v[i] - lo) * sc); + b = b < n - 1 ? b : n - 1; + bk[i] = (unsigned char)b; + cnt[b + 1]++; + } + for (i = 0; i < n; i++) + cnt[i + 1] += cnt[i]; + for (i = 0; i < n; i++) { + int p = cnt[bk[i]]++; + tv[p] = v[i]; + tt[p] = tag[i]; + } + for (i = 1; i < n; i++) { + float x = tv[i]; + short g = tt[i]; + for (j = i; j > 0 && tv[j - 1] > x; j--) { + tv[j] = tv[j - 1]; + tt[j] = tt[j - 1]; + } + tv[j] = x; + tt[j] = g; + } + memcpy(v, tv, sizeof(float) * n); + memcpy(tag, tt, sizeof(short) * n); +} +#else +/* sorts v[0..n-1] ascending with its tags (bottom-up merge sort, stable) */ +static void sort_proj(float *v, short *tag, int n) +{ + float tv[128]; + short tt[128]; + int w, i; + for (w = 1; w < n; w *= 2) { + for (i = 0; i < n; i += 2 * w) { + int a = i, am = i + w < n ? i + w : n, b = am, bm = i + 2 * w < n ? i + 2 * w : n, o = i; + while (a < am || b < bm) + if (b >= bm || (a < am && v[a] <= v[b])) { + tv[o] = v[a]; + tt[o++] = tag[a++]; + } else { + tv[o] = v[b]; + tt[o++] = tag[b++]; + } + } + memcpy(v, tv, sizeof(float) * n); + memcpy(tag, tt, sizeof(short) * n); + } +} + +#endif + +/* pair-search bounds (prba_pairs): Lc, Mz = Lc^-1 Q43, the principal direction of the usable p(j), and the rows + sorted along it. returns 0 if Q44 is not safely positive definite, the search is then exhaustive */ +static int prepare_bounds(xombe_cq_ws *ws) +{ + const xombe_amp_tables *ts = ws->ts; + float tr = 0.0f, C[4][4], d[4] = {0.5f, 0.5f, 0.5f, 0.5f}; + int a, b, k, j, it, cnt = 0; +#if XOMBE_KERNELS_Q15 + const xombe_cq_q15_tab *qt = ws->qt; + if (!qt) + return 0; +#endif + for (a = 0; a < 4; a++) + tr += ws->Q[3 + a][3 + a]; + for (a = 0; a < 4; a++) + for (b = 0; b < 4; b++) { + float s = b <= a ? ws->Q[3 + a][3 + b] : 0.0f; + if (b > a) { + ws->Lc[a][b] = 0.0f; + continue; + } + for (k = 0; k < b; k++) + s -= ws->Lc[a][k] * ws->Lc[b][k]; + if (a == b) { + if (!(s > 1e-6f * tr)) + return 0; + ws->Lc[a][a] = sqrtf(s); + } else + ws->Lc[a][b] = s / ws->Lc[b][b]; + } + for (b = 0; b < 3; b++) + for (a = 0; a < 4; a++) { + float s = ws->Q[3 + a][b]; + for (k = 0; k < a; k++) + s -= ws->Lc[a][k] * ws->Mz[k][b]; + ws->Mz[a][b] = s / ws->Lc[a][a]; + } + /* principal axis of p = Lc^T x4 over the usable rows, covariance Lc^T cov(x4) Lc, p itself not needed + (dir*p = (Lc dir)*x4, |p|^2 = e4q) */ + { +#if XOMBE_KERNELS_Q15 + const float *sx = qt->sx; + float cx[4][4], T[4][4], u[4], emax = 0.0f; + for (j = 0; j < ts->n_prba58; j++) + if (usable(ts->ok_prba58, j) && ws->e4q[j] > emax) + emax = ws->e4q[j]; + cnt = qt->cnt; +#define sxx qt->sxx +#else + float sx[4] = {0, 0, 0, 0}, sxx[4][4], cx[4][4], T[4][4], u[4], emax = 0.0f; + for (a = 0; a < 4; a++) + for (b = 0; b < 4; b++) + sxx[a][b] = 0.0f; + for (j = 0; j < ts->n_prba58; j++) { + const float *x = ts->prba58[j]; + if (!usable(ts->ok_prba58, j)) + continue; + cnt++; + for (a = 0; a < 4; a++) { + sx[a] += x[a]; + for (b = 0; b <= a; b++) + sxx[a][b] += x[a] * x[b]; + } + if (ws->e4q[j] > emax) + emax = ws->e4q[j]; + } +#endif + if (!cnt) + return 0; + ws->pmax = 1.001f * sqrtf(emax); + for (a = 0; a < 4; a++) + for (b = 0; b <= a; b++) + cx[a][b] = cx[b][a] = sxx[a][b] - sx[a] * sx[b] / (float)cnt; +#undef sxx + /* T = cov(x4) Lc, C = Lc^T T */ + for (a = 0; a < 4; a++) + for (b = 0; b < 4; b++) { + float s = 0.0f; + for (k = b; k < 4; k++) + s += cx[a][k] * ws->Lc[k][b]; + T[a][b] = s; + } + for (a = 0; a < 4; a++) + for (b = 0; b < 4; b++) { + float s = 0.0f; + for (k = a; k < 4; k++) + s += ws->Lc[k][a] * T[k][b]; + C[a][b] = s; + } + /* power iteration, any unit direction gives a valid bound, the principal one a tight one */ + for (it = 0; it < 16; it++) { + float nd[4], nn = 0.0f; + for (a = 0; a < 4; a++) { + nd[a] = C[a][0] * d[0] + C[a][1] * d[1] + C[a][2] * d[2] + C[a][3] * d[3]; + nn += nd[a] * nd[a]; + } + if (!(nn > 0.0f)) + break; + nn = 1.0f / sqrtf(nn); + for (a = 0; a < 4; a++) + d[a] = nd[a] * nn; + } + { + float nn = sqrtf(d[0] * d[0] + d[1] * d[1] + d[2] * d[2] + d[3] * d[3]); + for (a = 0; a < 4; a++) + ws->dir[a] = d[a] / nn; + } + /* u = Lc dir, Lc lower triangular */ + for (a = 0; a < 4; a++) { + float s = 0.0f; + for (k = 0; k <= a; k++) + s += ws->Lc[a][k] * ws->dir[k]; + u[a] = s; + } + ws->n4 = 0; + for (j = 0; j < ts->n_prba58; j++) + if (usable(ts->ok_prba58, j)) { + const float *x = ts->prba58[j]; + ws->ps[ws->n4] = u[0] * x[0] + u[1] * x[1] + u[2] * x[2] + u[3] * x[3]; + ws->pord[ws->n4++] = (short)j; + } + } + sort_proj(ws->ps, ws->pord, ws->n4); + /* per prba24 row: dir*(Mz x3), so dir*z(i) = dir*zq - dz(i) */ + { + float md[3]; + int i; + for (b = 0; b < 3; b++) + md[b] = ws->Mz[0][b] * ws->dir[0] + ws->Mz[1][b] * ws->dir[1] + ws->Mz[2][b] * ws->dir[2] + + ws->Mz[3][b] * ws->dir[3]; +#if XOMBE_KERNELS_Q15 + int32_t mi[3]; + uint32_t p0, p1; + float e; + int sm = quant_coef(md, 3, qt->x24, qt->tx24, 100, 1073741824.0f, mi, &e); + if (sm == -100) + return 0; + p0 = pair16(mi[0], mi[1]); + p1 = pair16(mi[2], 0); + for (i = 0; i < ts->n_prba24; i++) + ws->dz[i] = q15_smlad(qt->r24[i][3], p0, q15_smuad(qt->r24[i][4], p1)); + /* |dz| <= 2^30, so its float conversion is within 2^6 units */ + ws->dz_s = pow2i(-(sm + qt->tx24)); + ws->dz_e = e + 64.0f * ws->dz_s; +#else + for (i = 0; i < ts->n_prba24; i++) { + const float *x = ts->prba24[i]; + ws->dz[i] = md[0] * x[0] + md[1] * x[1] + md[2] * x[2]; + } +#endif + } + /* per prba24 row: Schur quadratic x3^T(Q33 - Mz^T Mz)x3 (unusable rows: CQ_INF), and a rounding magnitude + bound mw >= x3^T(|Q33| + 2|Mz^T Mz|)x3 for every row */ + { + float Sc[3][3], sa = 0.0f, n3 = 0.0f; + int i; + for (a = 0; a < 3; a++) + for (b = 0; b < 3; b++) { + float mm = ws->Mz[0][a] * ws->Mz[0][b] + ws->Mz[1][a] * ws->Mz[1][b] + ws->Mz[2][a] * ws->Mz[2][b] + + ws->Mz[3][a] * ws->Mz[3][b]; + Sc[a][b] = ws->Q[a][b] - mm; + sa += fabsf(ws->Q[a][b]) + 2.0f * fabsf(mm); + } +#if XOMBE_KERNELS_Q15 + { + const float c[6] = {Sc[0][0], Sc[1][1], Sc[2][2], Sc[0][1], Sc[0][2], Sc[1][2]}; + int32_t ci[6]; + uint32_t p0, p1, p2; + int sc = quant_coef(c, 6, qt->m24, qt->tm24, 100, 536870912.0f, ci, &ws->sq_d); + if (sc == -100) + return 0; + p0 = pair16(ci[0], ci[1]); + p1 = pair16(ci[2], ci[3]); + p2 = pair16(ci[4], ci[5]); + for (i = 0; i < ts->n_prba24; i++) { + const uint32_t *r = qt->r24[i]; + ws->sq[i] = q15_smlad(r[0], p0, q15_smlad(r[1], p1, q15_smuad(r[2], p2))); + } + ws->sq_x = sc + qt->tm24; + n3 = qt->n3; + } +#else + for (i = 0; i < ts->n_prba24; i++) { + const float *x = ts->prba24[i]; + float xx = x[0] * x[0] + x[1] * x[1] + x[2] * x[2]; + if (!usable(ts->ok_prba24, i)) { + ws->sq[i] = CQ_INF; + continue; + } + ws->sq[i] = Sc[0][0] * x[0] * x[0] + Sc[1][1] * x[1] * x[1] + Sc[2][2] * x[2] * x[2] + + 2.0f * (Sc[0][1] * x[0] * x[1] + Sc[0][2] * x[0] * x[2] + Sc[1][2] * x[1] * x[2]); + if (xx > n3) + n3 = xx; + } +#endif + ws->n3max = sqrtf(n3); + ws->mw = sa * n3; /* |x|^T S|x| <= (sum S) |x|^2 for S >= 0 */ + } + /* column bound, roles swapped: Q33 = L3 L3^T, M3 = L3^-1 Q34, + S'(j) = x4^T(Q44 - M3^T M3)x4 - 2 x4*(q4 - M3^T zq') - |zq'|^2, zq' = L3^-1 q3 */ + ws->col_ok = 0; + { + float tr3 = ws->Q[0][0] + ws->Q[1][1] + ws->Q[2][2], Sc[4][4], sa = 0.0f, n4 = 0.0f; + for (a = 0; a < 3; a++) + for (b = 0; b <= a; b++) { + float s = ws->Q[a][b]; + for (k = 0; k < b; k++) + s -= ws->L3[a][k] * ws->L3[b][k]; + if (a == b) { + if (!(s > 1e-6f * tr3)) + return 1; + ws->L3[a][a] = sqrtf(s); + } else + ws->L3[a][b] = s / ws->L3[b][b]; + } + for (b = 0; b < 4; b++) + for (a = 0; a < 3; a++) { + float s = ws->Q[a][3 + b]; + for (k = 0; k < a; k++) + s -= ws->L3[a][k] * ws->M3[k][b]; + ws->M3[a][b] = s / ws->L3[a][a]; + } + for (a = 0; a < 4; a++) + for (b = 0; b < 4; b++) { + float mm = ws->M3[0][a] * ws->M3[0][b] + ws->M3[1][a] * ws->M3[1][b] + ws->M3[2][a] * ws->M3[2][b]; + Sc[a][b] = ws->Q[3 + a][3 + b] - mm; + sa += fabsf(ws->Q[3 + a][3 + b]) + 2.0f * fabsf(mm); + } +#if XOMBE_KERNELS_Q15 + { + const float c[10] = {Sc[0][0], Sc[1][1], Sc[2][2], Sc[3][3], Sc[0][1], + Sc[0][2], Sc[0][3], Sc[1][2], Sc[1][3], Sc[2][3]}; + int32_t ci[10]; + uint32_t p[5]; + int sc = quant_coef(c, 10, qt->m58, qt->tm58, 100, 536870912.0f, ci, &ws->sq4_d); + if (sc == -100) + return 1; + for (k = 0; k < 5; k++) + p[k] = pair16(ci[2 * k], ci[2 * k + 1]); + for (j = 0; j < ts->n_prba58; j++) { + const uint32_t *r = qt->r58[j]; + ws->sq4[j] = q15_smlad(r[0], p[0], q15_smlad(r[1], p[1], q15_smlad(r[2], p[2], q15_smlad(r[3], p[3], + q15_smuad(r[4], p[4]))))); + } + ws->sq4_x = sc + qt->tm58; + n4 = qt->n4; + } +#else + for (j = 0; j < ts->n_prba58; j++) { + const float *x = ts->prba58[j]; + float s = 0.0f, xx = x[0] * x[0] + x[1] * x[1] + x[2] * x[2] + x[3] * x[3]; + for (a = 0; a < 4; a++) + for (b = 0; b < 4; b++) + s += x[a] * Sc[a][b] * x[b]; + ws->sq4[j] = s; + if (usable(ts->ok_prba58, j) && xx > n4) + n4 = xx; + } +#endif + ws->n4max = sqrtf(n4); + ws->mw4 = sa * n4; + ws->col_ok = 1; + } + return 1; +} + +#if XOMBE_KERNELS_Q15 +static const xombe_cq_q15_tab *q15_tab(const xombe_amp_tables *ts) +{ + if (ts == &xombe__amp_ambe2) + return &xombe__cq_q15_ambe2; +#if XOMBE_HAVE_DSTAR + if (ts == &xombe__amp_dstar) + return &xombe__cq_q15_dstar; +#endif + return 0; +} + +/* the map's block form: within block k, A[l] = c0[k] + b1[l] c1[k], so its weighted moments need only the + block sums of w, w b1, and w b1^2 */ +void xombe__cq_prepare(xombe_cq_ws *ws, const xombe_amp_tables *ts, int L, const float *w) +{ + float W0[4], W1[4], W2[4]; + int k, l, g, h, i, m, j, pos = 1, off = 0, same = ws->ts == ts && ws->L == L; + ws->ts = ts; + ws->qt = q15_tab(ts); + ws->L = L; + ws->work = 0; + ws->sw = 0.0f; + ws->w[0] = 0.0f; + for (l = 1; l <= L; l++) { + ws->w[l] = w ? w[l] : 1.0f; + ws->sw += ws->w[l]; + } + for (k = 0; k < 4 && !same; k++) { + int J = ts->blk[L][k], M = J < 6 ? J : 6; + const float *kern = xombe__dct_blk + xombe__dct_blk_off[J]; + ws->pos[k] = pos; + ws->J[k] = J; + ws->M[k] = M; + /* block means C0, C1 of (R_2k, R_2k+1), R = S8 G with S8[i][m] = alpha_m cos(pi m (i + 1/2)/8) */ + for (g = 0; g < 7; g++) { + float s0 = 2.0f * xombe__dct8[g + 1][2 * k], s1 = 2.0f * xombe__dct8[g + 1][2 * k + 1]; + ws->c0[k][g] = 0.5f * (s0 + s1); + ws->c1[k][g] = (0.5f / CQ_SQRT2) * (s0 - s1); + } + for (i = 0; i < J; i++) { + ws->b1[pos + i] = 2.0f * kern[J + i]; + for (m = 2; m < 6; m++) + ws->H[pos + i][m - 2] = m < M ? 2.0f * kern[m * J + i] : 0.0f; + } + pos += J; + } + for (k = 0; k < 4; k++) { + float s0 = 0.0f, s1 = 0.0f, s2 = 0.0f; + for (l = ws->pos[k]; l < ws->pos[k] + ws->J[k]; l++) { + float wb = ws->w[l] * ws->b1[l]; + s0 += ws->w[l]; + s1 += wb; + s2 += wb * ws->b1[l]; + } + W0[k] = s0; + W1[k] = s1; + W2[k] = s2; + } + for (g = 0; g < 7; g++) { + float s = 0.0f; + for (k = 0; k < 4; k++) + s += ws->c0[k][g] * W0[k] + ws->c1[k][g] * W1[k]; + ws->mu[g] = s / ws->sw; + } + for (g = 0; g < 7; g++) + for (h = g; h < 7; h++) { + float s = 0.0f; + for (k = 0; k < 4; k++) { + float dg = ws->c0[k][g] - ws->mu[g], dh = ws->c0[k][h] - ws->mu[h]; + s += dg * dh * W0[k] + (dg * ws->c1[k][h] + ws->c1[k][g] * dh) * W1[k] + + ws->c1[k][g] * ws->c1[k][h] * W2[k]; + } + ws->Q[g][h] = ws->Q[h][g] = s; + } + { + const float q00 = ws->Q[3][3], q11 = ws->Q[4][4], q22 = ws->Q[5][5], q33 = ws->Q[6][6]; + const float q01 = 2.0f * ws->Q[3][4], q02 = 2.0f * ws->Q[3][5], q03 = 2.0f * ws->Q[3][6]; + const float q12 = 2.0f * ws->Q[4][5], q13 = 2.0f * ws->Q[4][6], q23 = 2.0f * ws->Q[5][6]; + for (j = 0; j < ts->n_prba58; j++) { + const float *x = ts->prba58[j]; + ws->e4q[j] = x[0] * (q00 * x[0] + q01 * x[1] + q02 * x[2] + q03 * x[3]) + + x[1] * (q11 * x[1] + q12 * x[2] + q13 * x[3]) + x[2] * (q22 * x[2] + q23 * x[3]) + + q33 * x[3] * x[3]; + } + } + ws->chol_ok = prepare_bounds(ws); + /* HOC rows' w-only terms, G = H^T W H and H^T w per block (H is zero past M - 2 columns) */ + for (k = 0; k < 4; k++) { + float G[4][4], h1[4]; + int n, pk = ws->pos[k]; + ws->hoc_off[k] = off; + off += ts->n_hoc[k]; + if (ws->M[k] <= 2) + continue; + for (g = 0; g < 4; g++) { + float s = 0.0f; + for (i = 0; i < ws->J[k]; i++) + s += ws->w[pk + i] * ws->H[pk + i][g]; + h1[g] = s; + for (h = g; h < 4; h++) { + s = 0.0f; + for (i = 0; i < ws->J[k]; i++) + s += ws->w[pk + i] * ws->H[pk + i][g] * ws->H[pk + i][h]; + G[g][h] = s; + } + } + for (n = 0; n < ts->n_hoc[k]; n++) { + const float *c = ts->hoc[k] + 4 * n; + ws->hq[ws->hoc_off[k] + n] = G[0][0] * c[0] * c[0] + G[1][1] * c[1] * c[1] + G[2][2] * c[2] * c[2] + + G[3][3] * c[3] * c[3] + + 2.0f * (G[0][1] * c[0] * c[1] + G[0][2] * c[0] * c[2] + G[0][3] * c[0] * c[3] + + G[1][2] * c[1] * c[2] + G[1][3] * c[1] * c[3] + G[2][3] * c[2] * c[3]); + ws->hl[ws->hoc_off[k] + n] = h1[0] * c[0] + h1[1] * c[1] + h1[2] * c[2] + h1[3] * c[3]; + } + } +} +#else +void xombe__cq_prepare(xombe_cq_ws *ws, const xombe_amp_tables *ts, int L, const float *w) +{ + float mu[7]; + int k, l, g, h, i, m, j, pos = 1, off = 0, same = ws->ts == ts && ws->L == L; + ws->ts = ts; + ws->L = L; + ws->work = 0; + ws->sw = 0.0f; + ws->w[0] = 0.0f; + for (l = 1; l <= L; l++) { + ws->w[l] = w ? w[l] : 1.0f; + ws->sw += ws->w[l]; + } + for (k = 0; k < 4 && !same; k++) { + int J = ts->blk[L][k], M = J < 6 ? J : 6; + const float *kern = xombe__dct_blk + xombe__dct_blk_off[J]; + float c0[7], c1[7]; + ws->pos[k] = pos; + ws->J[k] = J; + ws->M[k] = M; + for (g = 0; g < 7; g++) { + float s0 = 2.0f * xombe__dct8[g + 1][2 * k], s1 = 2.0f * xombe__dct8[g + 1][2 * k + 1]; + c0[g] = 0.5f * (s0 + s1); + c1[g] = (0.5f / CQ_SQRT2) * (s0 - s1); + } + for (i = 0; i < J; i++) { + float b1 = 2.0f * kern[J + i]; + for (g = 0; g < 7; g++) + ws->A[pos + i][g] = c0[g] + b1 * c1[g]; + for (m = 2; m < 6; m++) + ws->H[pos + i][m - 2] = m < M ? 2.0f * kern[m * J + i] : 0.0f; + } + pos += J; + } + for (g = 0; g < 7; g++) { + float s = 0.0f; + for (l = 1; l <= L; l++) + s += ws->w[l] * ws->A[l][g]; + mu[g] = s / ws->sw; + } + for (l = 1; l <= L; l++) + for (g = 0; g < 7; g++) + ws->Wm[l][g] = ws->w[l] * (ws->A[l][g] - mu[g]); + for (g = 0; g < 7; g++) + for (h = g; h < 7; h++) { + float s = 0.0f; + for (l = 1; l <= L; l++) + s += (ws->A[l][g] - mu[g]) * ws->Wm[l][h]; + ws->Q[g][h] = ws->Q[h][g] = s; + } + for (j = 0; j < ts->n_prba58; j++) { + const float *x = ts->prba58[j]; + float e = 0.0f; + for (g = 0; g < 4; g++) { + float s = 0.0f; + for (h = 0; h < 4; h++) + s += ws->Q[3 + g][3 + h] * x[h]; + e += x[g] * s; + } + ws->e4q[j] = e; + } + ws->chol_ok = prepare_bounds(ws); + /* HOC candidates in the harmonic domain, block-local */ + for (k = 0; k < 4 && !same; k++) { + int J = ws->J[k], M = ws->M[k], n; + ws->hv_off[k] = off; + if (M <= 2) + continue; + for (n = 0; n < ts->n_hoc[k]; n++) { + const float *hc = ts->hoc[k] + 4 * n; + for (i = 0; i < J; i++) { + float s = 0.0f; + for (m = 2; m < M; m++) + s += ws->H[ws->pos[k] + i][m - 2] * hc[m - 2]; + ws->hv[off + n * J + i] = s; + } + } + off += ts->n_hoc[k] * J; + } +} + +#endif + +/* (b3, b4) pair search + E(i, j) = e3(i) + e4(j) + v(i)*x4(j), e3 = x3^T Q33 x3 - 2 x3*q3, e4 = x4^T Q44 x4 - 2 x4*q4, v = 2 Q43 x3, + evaluated in that order. the exhaustive search over usable pairs is pruned by bounds that never exclude a + pair it would keep: with Q44 = Lc Lc^T, p = Lc^T x4, and z(i) = Lc^-1(q4 - Q43 x3), + E(i, j) = S(i) + |p(j) - z(i)|^2, S(i) = e3(i) - |z(i)|^2, + so S(i) bounds row i and (dir*p(j) - dir*z(i))^2 bounds pair (i, j) for a unit direction dir (the rows' + principal axis, sorted along it). each bound is lowered by a rounding slack, which also covers dir*z(i) + taken as dir*zq - dir*(Mz x3) */ + +typedef struct { + float e; + int i, j; +} cq_pair; + +static void pair_insert(cq_pair *top, int n, int n58, float e, int i, int j) +{ + int key = i * n58 + j, p; + if (!(e < top[n - 1].e || (e == top[n - 1].e && key < top[n - 1].i * n58 + top[n - 1].j))) + return; + for (p = n - 1; p > 0; p--) { + const cq_pair *q = &top[p - 1]; + if (!(e < q->e || (e == q->e && key < q->i * n58 + q->j))) + break; + top[p] = top[p - 1]; + } + top[p].e = e; + top[p].i = i; + top[p].j = j; +} + +static float row_e3(const xombe_cq_ws *ws, const float *x3, const float q3[3]) +{ + float e = 0.0f, d = 0.0f; + int a, b; + for (a = 0; a < 3; a++) { + float s = 0.0f; + for (b = 0; b < 3; b++) + s += ws->Q[a][b] * x3[b]; + e += x3[a] * s; + d += x3[a] * q3[a]; + } + return e - 2.0f * d; +} + +static void row_v(const xombe_cq_ws *ws, const float *x3, float v[4]) +{ + int b; + for (b = 0; b < 4; b++) + v[b] = 2.0f * (x3[0] * ws->Q[0][3 + b] + x3[1] * ws->Q[1][3 + b] + x3[2] * ws->Q[2][3 + b]); +} + +static float pair_e(const xombe_cq_ws *ws, float e3, const float v[4], int j) +{ + const float *x = ws->ts->prba58[j]; + return (e3 + ws->e4[j]) + (v[0] * x[0] + v[1] * x[1] + v[2] * x[2] + v[3] * x[3]); +} + +static void eval_row(const xombe_cq_ws *ws, int i, float e3, const float v[4], cq_pair *top, int n) +{ + const xombe_amp_tables *ts = ws->ts; + int j, n58 = ts->n_prba58; + for (j = 0; j < n58; j++) + if (usable(ts->ok_prba58, j)) { + CQ_STAT(2); + pair_insert(top, n, n58, pair_e(ws, e3, v, j), i, j); + } +} + +/* row i with bound sb = S(i) - slack: columns outward from dir*z(i) = zdq - dz(i) along the sorted projections, + each side until the projection bound exceeds the n-th best, e3 and v computed at the row's first pair + returns the number of columns skipped by their own bound */ +static int eval_row_proj(const xombe_cq_ws *ws, int i, const float q3[3], float sb, float zdq, const float *ps, + const short *pord, int n4, cq_pair *top, int n, int *left_) +{ + const xombe_amp_tables *ts = ws->ts; + const float *x3 = ts->prba24[i]; +#if XOMBE_KERNELS_Q15 + /* dz within dz_e: the true centre is in zd +/- ze, distances shrink by ze on either side */ + float e3 = 0.0f, v[4], zd = zdq - (float)ws->dz[i] * ws->dz_s, ze = ws->dz_e; +#else + float e3 = 0.0f, v[4], zd = zdq - ws->dz[i]; +#endif + int lo = 0, hi = n4, t, n58 = ts->n_prba58, skip = 0, ready = 0, left = *left_ - CQ_ROW_COST; + CQ_STAT(1); + while (lo < hi) { + int mid = (lo + hi) >> 1; + if (ps[mid] < zd) + lo = mid + 1; + else + hi = mid; + } + for (t = lo; t < n4; t++) { +#if XOMBE_KERNELS_Q15 + float d = ps[t] - zd - ze > 0.0f ? ps[t] - zd - ze : 0.0f; +#else + float d = ps[t] - zd; +#endif + int j = pord[t]; + float e; + CQ_STAT(3); + if (sb + d * d > top[n - 1].e) + break; + if (ws->colb[j] > top[n - 1].e) { + skip++; + continue; + } + if (!ready) { + e3 = row_e3(ws, x3, q3); + row_v(ws, x3, v); + ready = 1; + } + if (--left < 0) + break; + CQ_STAT(2); + e = pair_e(ws, e3, v, j); + if (e <= top[n - 1].e) + pair_insert(top, n, n58, e, i, j); + } + for (t = lo - 1; t >= 0 && left >= 0; t--) { +#if XOMBE_KERNELS_Q15 + float d = zd - ze - ps[t] > 0.0f ? zd - ze - ps[t] : 0.0f; +#else + float d = zd - ps[t]; +#endif + int j = pord[t]; + float e; + CQ_STAT(3); + if (sb + d * d > top[n - 1].e) + break; + if (ws->colb[j] > top[n - 1].e) { + skip++; + continue; + } + if (!ready) { + e3 = row_e3(ws, x3, q3); + row_v(ws, x3, v); + ready = 1; + } + if (--left < 0) + break; + CQ_STAT(2); + e = pair_e(ws, e3, v, j); + if (e <= top[n - 1].e) + pair_insert(top, n, n58, e, i, j); + } + *left_ = left; + return skip; +} + +#if XOMBE_KERNELS_Q15 +static float row_sb(const xombe_cq_ws *ws, int i) +{ + return (float)ws->sb[i] * ws->sb_s - ws->sb_k; +} + +static void pairs_all(const xombe_cq_ws *ws, const float q[7], int n, cq_pair *top) +{ + const xombe_amp_tables *ts = ws->ts; + int i; + for (i = 0; i < ts->n_prba24; i++) { + float v[4]; + if (!usable(ts->ok_prba24, i)) + continue; + CQ_STAT(1); + row_v(ws, ts->prba24[i], v); + eval_row(ws, i, row_e3(ws, ts->prba24[i], q), v, top, n); + } +} + +/* n best pairs by weighted mean-removed error of A3 x3 + A4 x4 against y, ascending, ties by row-major index + the bounds' linear terms in int16 at the largest scale that keeps every sum within 2^30, the row bound's + quadratic part (scale 2^-sq_x) shifted down to it */ +static void prba_pairs(xombe_cq_ws *ws, const float *y, int n, cq_pair *top) +{ + const xombe_amp_tables *ts = ws->ts; + const xombe_cq_q15_tab *qt = ws->qt; + float q[7], zq[4], my = 0.0f, e4abs = 0.0f, pm = ws->pmax, zdq, sb0; + int l, g, i, j, m, k, i0 = -1, left = 1 << 30, budget = ws->cap > 0 ? ws->cap : 1 << 30; + short cand[512], ord[512]; /* band << 9 | row, then rows by band */ + CQ_STAT(0); + for (l = 1; l <= ws->L; l++) + my += ws->w[l] * y[l]; + my /= ws->sw; + for (g = 0; g < 7; g++) + q[g] = 0.0f; + for (k = 0; k < 4; k++) { + float u0 = 0.0f, u1 = 0.0f; + for (l = ws->pos[k]; l < ws->pos[k] + ws->J[k]; l++) { + float wu = ws->w[l] * (y[l] - my); + u0 += wu; + u1 += wu * ws->b1[l]; + } + for (g = 0; g < 7; g++) + q[g] += (ws->c0[k][g] - ws->mu[g]) * u0 + ws->c1[k][g] * u1; + } + for (j = 0; j < ts->n_prba58; j++) { + const float *x = ts->prba58[j]; + ws->e4[j] = ws->e4q[j] - 2.0f * (x[0] * q[3] + x[1] * q[4] + x[2] * q[5] + x[3] * q[6]); + if (usable(ts->ok_prba58, j) && fabsf(ws->e4[j]) > e4abs) + e4abs = fabsf(ws->e4[j]); + } + for (m = 0; m < n; m++) { + top[m].e = CQ_INF; + top[m].i = top[m].j = 1 << 20; + } + if (ws->brute || !ws->chol_ok) { + pairs_all(ws, q, n, top); + return; + } + /* zq = Lc^-1 q4 */ + for (m = 0; m < 4; m++) { + float s = q[3 + m]; + for (g = 0; g < m; g++) + s -= ws->Lc[m][g] * zq[g]; + zq[m] = s / ws->Lc[m][m]; + } + /* S(i) = x3^T(Q33 - Mz^T Mz)x3 - 2 x3*h - |zq|^2, h = q3 - Mz^T zq, the slack covers the rounding of S and of + E (|e3| <= x3^T|Q33|x3 + 2|x3||q3|, |v*x4| <= |e4| + |p|^2 + 2|z||p| <= |e4| + 2|p|^2 + |z|^2, + |z|^2 <= 2|zq|^2 + 2|Mz x3|^2), the integer parts' errors are added to it */ + { + float h[3], zzq = 0.0f, nq = 0.0f, nh = 0.0f, K, lh[3], el; + int32_t hi[4]; + uint32_t h01, h2; + int sl, x; + for (m = 0; m < 4; m++) + zzq += zq[m] * zq[m]; + for (g = 0; g < 3; g++) { + h[g] = q[g] - (ws->Mz[0][g] * zq[0] + ws->Mz[1][g] * zq[1] + ws->Mz[2][g] * zq[2] + ws->Mz[3][g] * zq[3]); + nq += q[g] * q[g]; + nh += h[g] * h[g]; + lh[g] = -2.0f * h[g]; + } + K = 2.0f * ws->n3max * (sqrtf(nq) + sqrtf(nh)) + 3.0f * zzq + 3.0f * e4abs + 3.0f * pm * pm; + /* colb[j] = S'(j) - slack, or -CQ_INF without the bound. |sq4| <= 2^29 and |lin| <= 2^30 convert to + float within 2^5 and 2^6 units */ + if (ws->col_ok) { + float zq3[3], h4[4], zz3 = 0.0f, n4q = 0.0f, nh4 = 0.0f, K4, l4[4], e4l, s4, sx4; + uint32_t p0, p1; + int s; + for (m = 0; m < 3; m++) { + float t = q[m]; + for (g = 0; g < m; g++) + t -= ws->L3[m][g] * zq3[g]; + zq3[m] = t / ws->L3[m][m]; + zz3 += zq3[m] * zq3[m]; + } + for (g = 0; g < 4; g++) { + h4[g] = q[3 + g] - (ws->M3[0][g] * zq3[0] + ws->M3[1][g] * zq3[1] + ws->M3[2][g] * zq3[2]); + n4q += q[3 + g] * q[3 + g]; + nh4 += h4[g] * h4[g]; + l4[g] = -2.0f * h4[g]; + } + s = quant_coef(l4, 4, qt->x58, qt->tx58, 100, 1073741824.0f, hi, &e4l); + if (s == -100) { + pairs_all(ws, q, n, top); + return; + } + s4 = pow2i(-(s + qt->tx58)); + sx4 = pow2i(-ws->sq4_x); + K4 = zz3 + CQ_BOUND_SLACK * (ws->mw4 + ws->mw + K + 2.0f * ws->n4max * (sqrtf(n4q) + sqrtf(nh4)) + + 3.0f * zz3) + + ws->sq4_d + e4l + 32.0f * sx4 + 64.0f * s4; + p0 = pair16(hi[0], hi[1]); + p1 = pair16(hi[2], hi[3]); + for (j = 0; j < ts->n_prba58; j++) { + const uint32_t *r = qt->r58[j]; + ws->colb[j] = (float)ws->sq4[j] * sx4 + (float)q15_smlad(r[5], p0, q15_smuad(r[6], p1)) * s4 - K4; + } + } else + for (j = 0; j < ts->n_prba58; j++) + ws->colb[j] = -CQ_INF; + K = zzq + CQ_BOUND_SLACK * (ws->mw + K); + /* sb = (sq >> k) + lin at 2^-x, x = sq_x - k: within sq_d + el, 1 unit for the floor of the shift, and + 2^7 units for the float conversion of |sb| < 2^31 */ + sl = quant_coef(lh, 3, qt->x24, qt->tx24, ws->sq_x - qt->tx24, 1073741824.0f, hi, &el); + x = sl + qt->tx24; + k = ws->sq_x - x; + if (sl == -100 || k > 30) { + pairs_all(ws, q, n, top); + return; + } + ws->sb_s = pow2i(-x); + ws->sb_k = K + ws->sq_d + el + (k ? ws->sb_s : 0.0f) + 128.0f * ws->sb_s; + h01 = pair16(hi[0], hi[1]); + h2 = pair16(hi[2], 0); + { + const uint32_t(*r24)[5] = qt->r24; + const unsigned char *ok = ts->ok_prba24; + int32_t mn = INT32_MAX, bk = (int32_t)(CQ_BIAS >> k), *sb = ws->sb; + const int32_t *sq = ws->sq; + if (k) + for (i = 0; i < ts->n_prba24; i++) + sb[i] = q15_smlad(r24[i][3], h01, + q15_smlad(r24[i][4], h2, (int32_t)(((uint32_t)sq[i] + CQ_BIAS) >> k) - bk)); + else + for (i = 0; i < ts->n_prba24; i++) + sb[i] = q15_smlad(r24[i][3], h01, q15_smlad(r24[i][4], h2, sq[i])); + for (i = 0; i < ts->n_prba24; i++) { + if (ok && !ok[i]) + sb[i] = INT32_MAX; + else if (sb[i] < mn) { + mn = sb[i]; + i0 = i; + } + } + } + } + if (i0 < 0) + return; + sb0 = row_sb(ws, i0); + zdq = ws->dir[0] * zq[0] + ws->dir[1] * zq[1] + ws->dir[2] * zq[2] + ws->dir[3] * zq[3]; + eval_row_proj(ws, i0, q, sb0, zdq, ws->ps, ws->pord, ws->n4, top, n, &left); + left = budget - ((1 << 30) - left); /* the first row always runs to completion */ + /* columns with bound within the n-th best so far, in projection order (the n-th best only drops), refiltered + when the rows have skipped more columns by their bound than the list holds. other rows within the n-th + best go by ascending bound in CQ_BANDS bands (index order within a band), so a cap cuts the least + promising. without a cap the order changes only how fast the n-th best drops, not the n best + the integer pre-filter sb <= T keeps a superset of the rows with bound <= t0 (T is past (t0 + sb_k)/sb_s by + more than its float rounding, and INT32_MAX - 1 at most so it drops the unusable rows) */ + { + float t0 = top[n - 1].e, scale = t0 > sb0 ? (float)CQ_BANDS / (t0 - sb0) : 0.0f, X = (t0 + ws->sb_k) / ws->sb_s; + float Xm = X + (fabsf(X) + (fabsf(t0) + fabsf(ws->sb_k)) / ws->sb_s) * 1e-6f + 512.0f; + int32_t T = Xm >= 2147483000.0f ? INT32_MAX - 1 : Xm <= -2147483000.0f ? INT32_MIN : (int32_t)Xm; + int nf = 0, nh = 0, t, skip = 0, cnt[CQ_BANDS + 1] = {0}; + for (t = 0; t < ws->n4; t++) + if (ws->colb[ws->pord[t]] <= top[n - 1].e) { + ws->fps[nf] = ws->ps[t]; + ws->ford[nf++] = ws->pord[t]; + } + for (i = 0; i < ts->n_prba24; i++) + if (ws->sb[i] <= T && i != i0) { + float sb = row_sb(ws, i); + int b; + if (!(sb <= t0)) + continue; + b = (int)((sb - sb0) * scale); + b = b < CQ_BANDS ? b : CQ_BANDS - 1; + cand[nh++] = (short)(b << 9 | i); + cnt[b + 1]++; + } + for (k = 0; k < CQ_BANDS; k++) + cnt[k + 1] += cnt[k]; + for (t = 0; t < nh; t++) + ord[cnt[cand[t] >> 9]++] = (short)(cand[t] & 511); + for (t = 0; t < nh && left > 0; t++) { + float sb; + i = ord[t]; + sb = row_sb(ws, i); + if (sb > top[n - 1].e) + continue; + skip += eval_row_proj(ws, i, q, sb, zdq, ws->fps, ws->ford, nf, top, n, &left); + if (skip > nf) { + int f = 0; + for (k = 0; k < nf; k++) + if (ws->colb[ws->ford[k]] <= top[n - 1].e) { + ws->fps[f] = ws->fps[k]; + ws->ford[f++] = ws->ford[k]; + } + nf = f; + skip = 0; + } + } + } + if (budget - left > ws->work) + ws->work = budget - left; +} +#else +static void prba_pairs(xombe_cq_ws *ws, const float *y, int n, cq_pair *top) +{ + const xombe_amp_tables *ts = ws->ts; + float u[XOMBE_LMAX + 1], q[7], zq[4], my = 0.0f, e4abs = 0.0f, pm = ws->pmax, zdq, sb0 = CQ_INF; + int l, g, i, j, m, L = ws->L, i0 = -1, left = 1 << 30, budget = ws->cap > 0 ? ws->cap : 1 << 30; + short cand[512], ord[512]; + CQ_STAT(0); + for (l = 1; l <= L; l++) + my += ws->w[l] * y[l]; + my /= ws->sw; + for (l = 1; l <= L; l++) + u[l] = y[l] - my; + for (g = 0; g < 7; g++) { + float s = 0.0f; + for (l = 1; l <= L; l++) + s += ws->Wm[l][g] * u[l]; + q[g] = s; + } + for (j = 0; j < ts->n_prba58; j++) { + const float *x = ts->prba58[j]; + ws->e4[j] = ws->e4q[j] - 2.0f * (x[0] * q[3] + x[1] * q[4] + x[2] * q[5] + x[3] * q[6]); + if (usable(ts->ok_prba58, j) && fabsf(ws->e4[j]) > e4abs) + e4abs = fabsf(ws->e4[j]); + } + for (m = 0; m < n; m++) { + top[m].e = CQ_INF; + top[m].i = top[m].j = 1 << 20; + } + if (ws->brute || !ws->chol_ok) { + for (i = 0; i < ts->n_prba24; i++) { + float v[4]; + if (!usable(ts->ok_prba24, i)) + continue; + CQ_STAT(1); + row_v(ws, ts->prba24[i], v); + eval_row(ws, i, row_e3(ws, ts->prba24[i], q), v, top, n); + } + return; + } + for (m = 0; m < 4; m++) { + float s = q[3 + m]; + for (g = 0; g < m; g++) + s -= ws->Lc[m][g] * zq[g]; + zq[m] = s / ws->Lc[m][m]; + } + { + float h[3], zzq = 0.0f, nq = 0.0f, nh = 0.0f, K; + for (m = 0; m < 4; m++) + zzq += zq[m] * zq[m]; + for (g = 0; g < 3; g++) { + h[g] = q[g] - (ws->Mz[0][g] * zq[0] + ws->Mz[1][g] * zq[1] + ws->Mz[2][g] * zq[2] + ws->Mz[3][g] * zq[3]); + nq += q[g] * q[g]; + nh += h[g] * h[g]; + } + K = 2.0f * ws->n3max * (sqrtf(nq) + sqrtf(nh)) + 3.0f * zzq + 3.0f * e4abs + 3.0f * pm * pm; + if (ws->col_ok) { + float zq3[3], h4[4], zz3 = 0.0f, n4q = 0.0f, nh4 = 0.0f, K4; + for (m = 0; m < 3; m++) { + float t = q[m]; + for (g = 0; g < m; g++) + t -= ws->L3[m][g] * zq3[g]; + zq3[m] = t / ws->L3[m][m]; + zz3 += zq3[m] * zq3[m]; + } + for (g = 0; g < 4; g++) { + h4[g] = q[3 + g] - (ws->M3[0][g] * zq3[0] + ws->M3[1][g] * zq3[1] + ws->M3[2][g] * zq3[2]); + n4q += q[3 + g] * q[3 + g]; + nh4 += h4[g] * h4[g]; + } + K4 = zz3 + CQ_BOUND_SLACK * (ws->mw4 + ws->mw + K + 2.0f * ws->n4max * (sqrtf(n4q) + sqrtf(nh4)) + + 3.0f * zz3); + for (j = 0; j < ts->n_prba58; j++) { + const float *x = ts->prba58[j]; + ws->colb[j] = ws->sq4[j] - 2.0f * (x[0] * h4[0] + x[1] * h4[1] + x[2] * h4[2] + x[3] * h4[3]) - K4; + } + } else + for (j = 0; j < ts->n_prba58; j++) + ws->colb[j] = -CQ_INF; + K = zzq + CQ_BOUND_SLACK * (ws->mw + K); + for (i = 0; i < ts->n_prba24; i++) { + const float *x3 = ts->prba24[i]; + float sb = ws->sq[i] - 2.0f * (x3[0] * h[0] + x3[1] * h[1] + x3[2] * h[2]) - K; + ws->sb[i] = sb; + if (sb < sb0) { + sb0 = sb; + i0 = i; + } + } + } + if (i0 < 0) + return; + zdq = ws->dir[0] * zq[0] + ws->dir[1] * zq[1] + ws->dir[2] * zq[2] + ws->dir[3] * zq[3]; + eval_row_proj(ws, i0, q, sb0, zdq, ws->ps, ws->pord, ws->n4, top, n, &left); + left = budget - ((1 << 30) - left); + { + float t0 = top[n - 1].e, scale = t0 > sb0 ? (float)CQ_BANDS / (t0 - sb0) : 0.0f; + int nf = 0, nh = 0, t, k, skip = 0, cnt[CQ_BANDS + 1] = {0}; + for (t = 0; t < ws->n4; t++) + if (ws->colb[ws->pord[t]] <= top[n - 1].e) { + ws->fps[nf] = ws->ps[t]; + ws->ford[nf++] = ws->pord[t]; + } + for (i = 0; i < ts->n_prba24; i++) + if (i != i0 && ws->sb[i] <= t0) { + int b = (int)((ws->sb[i] - sb0) * scale); + b = b < CQ_BANDS ? b : CQ_BANDS - 1; + cand[nh++] = (short)(b << 9 | i); + cnt[b + 1]++; + } + for (k = 0; k < CQ_BANDS; k++) + cnt[k + 1] += cnt[k]; + for (t = 0; t < nh; t++) + ord[cnt[cand[t] >> 9]++] = (short)(cand[t] & 511); + for (t = 0; t < nh && left > 0; t++) { + i = ord[t]; + if (ws->sb[i] > top[n - 1].e) + continue; + skip += eval_row_proj(ws, i, q, ws->sb[i], zdq, ws->fps, ws->ford, nf, top, n, &left); + if (skip > nf) { + int f = 0; + for (k = 0; k < nf; k++) + if (ws->colb[ws->ford[k]] <= top[n - 1].e) { + ws->fps[f] = ws->fps[k]; + ws->ford[f++] = ws->ford[k]; + } + nf = f; + skip = 0; + } + } + } + if (budget - left > ws->work) + ws->work = budget - left; +} + +#endif + +#if XOMBE_KERNELS_Q15 +/* per block, the HOC row minimizing the weighted mean-removed error against y with the other blocks fixed, + up to passes sweeps until nothing changes. a block whose others are unchanged since its last search is + skipped. with y centred, row c of block k costs + e = O2 + Y2 - 2 c*b + c^T G c - (O1 + Y1 - c*H^T w)^2 / sw + Y1, Y2, b = sum w y, sum w y^2, H^T W y over block k, O1, O2 the same sums of the other blocks' residuals */ +static void hoc_search(const xombe_cq_ws *ws, const float *y, int hoc[4], int passes) +{ + const xombe_amp_tables *ts = ws->ts; + float Y1[4], Y2[4], B[4][4], P1[4], P2[4], cy = 0.0f, isw = 1.0f / ws->sw; + int p, k, kk, i, n, l, step = 0, last[4] = {-1, -1, -1, -1}, chg[4] = {-1, -1, -1, -1}; + for (l = 1; l <= ws->L; l++) + cy += ws->w[l] * y[l]; + cy *= isw; + for (k = 0; k < 4; k++) { + float s1 = 0.0f, s2 = 0.0f, b[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + int pos = ws->pos[k], m; + for (i = 0; i < ws->J[k]; i++) { + float d = y[pos + i] - cy, wd = ws->w[pos + i] * d; + s1 += wd; + s2 += wd * d; + for (m = 0; m < 4; m++) + b[m] += wd * ws->H[pos + i][m]; + } + Y1[k] = P1[k] = s1; + Y2[k] = P2[k] = s2; + memcpy(B[k], b, sizeof(b)); + if (ws->M[k] > 2) { + const float *c = ts->hoc[k] + 4 * hoc[k]; + P1[k] = s1 - ws->hl[ws->hoc_off[k] + hoc[k]]; + P2[k] = s2 - 2.0f * (c[0] * b[0] + c[1] * b[1] + c[2] * b[2] + c[3] * b[3]) + + ws->hq[ws->hoc_off[k] + hoc[k]]; + } + } + for (p = 0; p < passes; p++) { + int changed = 0; + for (k = 0; k < 4; k++) { + const float *b = B[k], *hq = ws->hq + ws->hoc_off[k], *hl = ws->hl + ws->hoc_off[k]; + float a1 = Y1[k], best = CQ_INF; + int bi = 0; + if (ws->M[k] <= 2) + continue; + if (last[k] >= 0) { + for (kk = 0; kk < 4 && (kk == k || chg[kk] < last[k]); kk++) + ; + if (kk == 4) + continue; + } + last[k] = step++; + for (kk = 0; kk < 4; kk++) + if (kk != k) + a1 += P1[kk]; + /* O2 + Y2 is the same for every row */ + for (n = 0; n < ts->n_hoc[k]; n++) { + const float *c = ts->hoc[k] + 4 * n; + float r1, e; + if (!usable(ts->ok_hoc[k], n)) + continue; + r1 = a1 - hl[n]; + e = hq[n] - 2.0f * (c[0] * b[0] + c[1] * b[1] + c[2] * b[2] + c[3] * b[3]) - r1 * r1 * isw; + if (e < best) { + best = e; + bi = n; + } + } + if (bi != hoc[k]) { + const float *c = ts->hoc[k] + 4 * bi; + hoc[k] = bi; + chg[k] = last[k]; + changed = 1; + P1[k] = Y1[k] - hl[bi]; + P2[k] = Y2[k] - 2.0f * (c[0] * b[0] + c[1] * b[1] + c[2] * b[2] + c[3] * b[3]) + hq[bi]; + } + } + if (!changed) + break; + } +} + +/* block k's HOC row n in the harmonic domain, v[0..J) */ +static void hoc_vals(const xombe_cq_ws *ws, int k, int n, float *v) +{ + const float *c = ws->ts->hoc[k] + 4 * n; + int i, pos = ws->pos[k]; + for (i = 0; i < ws->J[k]; i++) { + const float *H = ws->H[pos + i]; + v[i] = H[0] * c[0] + H[1] * c[1] + H[2] * c[2] + H[3] * c[3]; + } +} +#else +static const float *hv_row(const xombe_cq_ws *ws, int k, int n) +{ + return ws->hv + ws->hv_off[k] + n * ws->J[k]; +} + +static void hoc_search(const xombe_cq_ws *ws, const float *y, int hoc[4], int passes) +{ + const xombe_amp_tables *ts = ws->ts; + float rest[XOMBE_LMAX + 1]; + int p, k, kk, i, n, L = ws->L, step = 0, last[4] = {-1, -1, -1, -1}, chg[4] = {-1, -1, -1, -1}; + for (p = 0; p < passes; p++) { + int changed = 0; + for (k = 0; k < 4; k++) { + float c = 0.0f, so1 = 0.0f, so2 = 0.0f, best = CQ_INF; + int bi = 0, pos = ws->pos[k], J = ws->J[k], l; + if (ws->M[k] <= 2) + continue; + if (last[k] >= 0) { + for (kk = 0; kk < 4 && (kk == k || chg[kk] < last[k]); kk++) + ; + if (kk == 4) + continue; + } + last[k] = step++; + for (kk = 0; kk < 4; kk++) { + const float *h = kk != k && ws->M[kk] > 2 ? hv_row(ws, kk, hoc[kk]) : 0; + for (i = 0; i < ws->J[kk]; i++) { + l = ws->pos[kk] + i; + rest[l] = h ? y[l] - h[i] : y[l]; + } + } + /* error is shift invariant, centre rest on its weighted mean before the one-pass sums */ + for (l = 1; l <= L; l++) + c += ws->w[l] * rest[l]; + c /= ws->sw; + for (l = 1; l <= L; l++) { + rest[l] -= c; + if (l < pos || l >= pos + J) { + so1 -= ws->w[l] * rest[l]; + so2 += ws->w[l] * rest[l] * rest[l]; + } + } + for (n = 0; n < ts->n_hoc[k]; n++) { + const float *v = hv_row(ws, k, n); + float s1 = so1, s2 = so2, e; + if (!usable(ts->ok_hoc[k], n)) + continue; + for (i = 0; i < J; i++) { + float d = v[i] - rest[pos + i], wd = ws->w[pos + i] * d; + s1 += wd; + s2 += wd * d; + } + e = s2 - s1 * s1 / ws->sw; + if (e < best) { + best = e; + bi = n; + } + } + if (bi != hoc[k]) { + hoc[k] = bi; + chg[k] = last[k]; + changed = 1; + } + } + if (!changed) + break; + } +} + +#endif + +/* G2..G8 (g[2..8]) and block DCT coefficients C[k][0..M-1] of r */ +static void forward(const xombe_cq_ws *ws, const float *r, float g[9], float C[4][6]) +{ + float R[8]; + int k, m, i; + for (k = 0; k < 4; k++) { + int J = ws->J[k], M = ws->M[k], pos = ws->pos[k]; + const float *kern = xombe__dct_blk + xombe__dct_blk_off[J]; + for (m = 0; m < M; m++) { + float s = 0.0f; + for (i = 0; i < J; i++) + s += r[pos + i] * kern[m * J + i]; + C[k][m] = s / (float)J; + } + R[2 * k] = C[k][0] + CQ_SQRT2 * C[k][1]; + R[2 * k + 1] = C[k][0] - CQ_SQRT2 * C[k][1]; + } + for (m = 0; m < 8; m++) { + float s = 0.0f; + for (i = 0; i < 8; i++) + s += xombe__dct8[m][i] * R[i]; + g[m + 1] = s / 8.0f; + } +} + +/* open-loop HOC choice */ +static void hoc_open(const xombe_cq_ws *ws, float C[4][6], int hoc[4]) +{ + int k; + for (k = 0; k < 4; k++) + hoc[k] = ws->M[k] <= 2 ? 0 + : xombe__nearest_row(ws->ts->hoc[k], ws->ts->n_hoc[k], 4, ws->M[k] - 2, &C[k][2], + ws->ts->ok_hoc[k]); +} + +/* k usable gain indices nearest g, by distance then index */ +static int nearest_gains(const xombe_amp_tables *ts, float g, float Gprev, int k, int *out) +{ + float d[XOMBE_CQ_MAX_GAIN]; + int i, p, n = 0; + for (i = 0; i < ts->n_dg; i++) { + float e; + if (!usable(ts->ok_dg, i)) + continue; + e = fabsf(xombe__gain_ts(ts, i, Gprev) - g); + if (n == k && !(e < d[k - 1])) + continue; + p = n < k ? n++ : k - 1; + for (; p > 0 && e < d[p - 1]; p--) { + d[p] = d[p - 1]; + out[p] = out[p - 1]; + } + d[p] = e; + out[p] = i; + } + return n; +} + +#if XOMBE_KERNELS_Q15 +/* t[l] = A3 x3 + A4 x4, plus block k's HOC row hk[k] unless hk is NULL */ +static void shape(const xombe_cq_ws *ws, int i3, int i4, const int *hk, float *t) +{ + const float *x3 = ws->ts->prba24[i3], *x4 = ws->ts->prba58[i4]; + int k, i; + for (k = 0; k < 4; k++) { + const float *c0 = ws->c0[k], *c1 = ws->c1[k]; + float a0 = (c0[0] * x3[0] + c0[1] * x3[1] + c0[2] * x3[2]) + + (c0[3] * x4[0] + c0[4] * x4[1] + c0[5] * x4[2] + c0[6] * x4[3]), + a1 = (c1[0] * x3[0] + c1[1] * x3[1] + c1[2] * x3[2]) + + (c1[3] * x4[0] + c1[4] * x4[1] + c1[5] * x4[2] + c1[6] * x4[3]); + float v[XOMBE_CQ_J_MAX]; + int pos = ws->pos[k], hv = hk && ws->M[k] > 2; + if (hv) + hoc_vals(ws, k, hk[k], v); + for (i = 0; i < ws->J[k]; i++) + t[pos + i] = a0 + ws->b1[pos + i] * a1 + (hv ? v[i] : 0.0f); + } +} + +static void sub_prba(const xombe_cq_ws *ws, const float *r, int i3, int i4, float *y) +{ + int l; + shape(ws, i3, i4, 0, y); + for (l = 1; l <= ws->L; l++) + y[l] = r[l] - y[l]; +} + +static void sub_hoc(const xombe_cq_ws *ws, const float *r, const int hoc[4], float *y) +{ + float v[XOMBE_CQ_J_MAX]; + int k, i; + for (k = 0; k < 4; k++) { + int pos = ws->pos[k], hv = ws->M[k] > 2; + if (hv) + hoc_vals(ws, k, hoc[k], v); + for (i = 0; i < ws->J[k]; i++) + y[pos + i] = hv ? r[pos + i] - v[i] : r[pos + i]; + } +} +#else +static void sub_prba(const xombe_cq_ws *ws, const float *r, int i3, int i4, float *y) +{ + const float *x3 = ws->ts->prba24[i3], *x4 = ws->ts->prba58[i4]; + int l; + for (l = 1; l <= ws->L; l++) { + const float *A = ws->A[l]; + y[l] = r[l] - (A[0] * x3[0] + A[1] * x3[1] + A[2] * x3[2]) - + (A[3] * x4[0] + A[4] * x4[1] + A[5] * x4[2] + A[6] * x4[3]); + } +} + +static void sub_hoc(const xombe_cq_ws *ws, const float *r, const int hoc[4], float *y) +{ + int k, i; + for (k = 0; k < 4; k++) { + const float *h = ws->M[k] > 2 ? hv_row(ws, k, hoc[k]) : 0; + for (i = 0; i < ws->J[k]; i++) + y[ws->pos[k] + i] = h ? r[ws->pos[k] + i] - h[i] : r[ws->pos[k] + i]; + } +} + +#endif + +void xombe__cq_closed(xombe_cq_ws *ws, const float *r, const float *target, const float *base, float Gprev, + int n_pairs, int n_gain, int iters, xombe_cq_result *res) +{ + const xombe_amp_tables *ts = ws->ts; + float g[9], C[4][6], y[XOMBE_LMAX + 1], best = CQ_INF; + cq_pair top[XOMBE_CQ_MAX_PAIRS]; + int hoc[4], shoc[4], it, p, l, k, L = ws->L, pi = -1, pj = -1, searched = 0; + forward(ws, r, g, C); + hoc_open(ws, C, hoc); + /* a pair search depends only on HOC (y = r - HOC's part). every search takes n_pairs, the best pair is the + first whatever n is, so the last search is reused, HOC unchanged, by the next iteration (which then + stops) and by the final step */ + for (it = 0; it < iters; it++) { + if (!searched || memcmp(hoc, shoc, sizeof(hoc))) { + sub_hoc(ws, r, hoc, y); + prba_pairs(ws, y, n_pairs, top); + memcpy(shoc, hoc, sizeof(hoc)); + searched = 1; + } + if (top[0].i == pi && top[0].j == pj) + break; + pi = top[0].i; + pj = top[0].j; + sub_prba(ws, r, pi, pj, y); + hoc_search(ws, y, hoc, 2); + } + if (!searched || memcmp(hoc, shoc, sizeof(hoc))) { + sub_hoc(ws, r, hoc, y); + prba_pairs(ws, y, n_pairs, top); + } + res->err = CQ_INF; + for (p = 0; p < n_pairs; p++) { + float tv[XOMBE_LMAX + 1], s[XOMBE_LMAX + 1], mt = 0.0f, gc = 0.0f; + int hk[4], gi[XOMBE_CQ_MAX_GAIN], ng, q; + if (top[p].e >= CQ_INF) + break; + sub_prba(ws, r, top[p].i, top[p].j, y); + memcpy(hk, hoc, sizeof(hk)); + hoc_search(ws, y, hk, 2); + /* tv = A3 x3 + A4 x4 + sum H h */ +#if XOMBE_KERNELS_Q15 + shape(ws, top[p].i, top[p].j, hk, tv); +#else + { + const float *x3 = ts->prba24[top[p].i], *x4 = ts->prba58[top[p].j]; + for (k = 0; k < 4; k++) { + const float *h = ws->M[k] > 2 ? hv_row(ws, k, hk[k]) : 0; + int i; + for (i = 0; i < ws->J[k]; i++) { + const float *A; + l = ws->pos[k] + i; + A = ws->A[l]; + tv[l] = (A[0] * x3[0] + A[1] * x3[1] + A[2] * x3[2]) + + (A[3] * x4[0] + A[4] * x4[1] + A[5] * x4[2] + A[6] * x4[3]) + (h ? h[i] : 0.0f); + } + } + } +#endif + for (l = 1; l <= L; l++) + mt += tv[l]; + mt /= (float)L; + for (l = 1; l <= L; l++) { + s[l] = tv[l] - mt + base[l]; + gc += ws->w[l] * (r[l] - (tv[l] - mt)); + } + gc = gc / ws->sw + xombe__half_log2[L]; + ng = nearest_gains(ts, gc, Gprev, n_gain, gi); + for (q = 0; q < ng; q++) { + float G = xombe__gain_ts(ts, gi[q], Gprev), e = 0.0f; + for (l = 1; l <= L; l++) { + float d = clip(s[l] + G, CQ_AMIN, XOMBE_CQ_AMAX) - target[l]; + e += ws->w[l] * d * d; + } + if (e < best) { + best = e; + res->err = e; + res->b[0] = res->b[1] = 0; + res->b[2] = gi[q]; + res->b[3] = top[p].i; + res->b[4] = top[p].j; + for (k = 0; k < 4; k++) + res->b[5 + k] = hk[k]; + res->u[0] = 0.0f; + for (l = 1; l <= L; l++) + res->u[l] = s[l] + G; + } + } + } +} + +void xombe__cq_quantize(xombe_cq_ws *ws, const xombe_amp_tables *ts, const float *target, int L, const float *pt, + float Gprev, const float *w, int closed, int n_pairs, int n_gain, int iters, int clip_passes, + xombe_cq_result *res) +{ + float tg[XOMBE_LMAX + 1], pred[XOMBE_LMAX + 1], base[XOMBE_LMAX + 1], r[XOMBE_LMAX + 1]; + float teff[XOMBE_LMAX + 1], mp = 0.0f, best = CQ_INF; + int l, cp; + for (l = 1; l <= L; l++) { + tg[l] = clip(target[l], CQ_AMIN, XOMBE_CQ_AMAX); + mp += pt[l]; + } + mp /= (float)L; + tg[0] = pred[0] = base[0] = r[0] = teff[0] = 0.0f; + for (l = 1; l <= L; l++) { + pred[l] = ts->rho * (pt[l] - mp); + base[l] = pred[l] - xombe__half_log2[L]; + r[l] = tg[l] - pred[l]; + } + xombe__cq_prepare(ws, ts, L, w); + if (!closed) { + float g[9], C[4][6], mt = 0.0f; + int gi; + for (l = 1; l <= L; l++) + mt += tg[l]; + nearest_gains(ts, mt / (float)L + xombe__half_log2[L], Gprev, 1, &gi); + forward(ws, r, g, C); + res->b[0] = res->b[1] = 0; + res->b[2] = gi; + res->b[3] = xombe__nearest_row(&ts->prba24[0][0], ts->n_prba24, 3, 3, &g[2], ts->ok_prba24); + res->b[4] = xombe__nearest_row(&ts->prba58[0][0], ts->n_prba58, 4, 4, &g[5], ts->ok_prba58); + hoc_open(ws, C, res->b + 5); + return; + } + memcpy(teff, tg, sizeof(float) * (L + 1)); + for (cp = 0; cp <= clip_passes; cp++) { + xombe_cq_result cur; + int any = 0; + if (cp > 0) + for (l = 1; l <= L; l++) + r[l] = teff[l] - pred[l]; + xombe__cq_closed(ws, r, tg, base, Gprev, n_pairs, n_gain, iters, &cur); + if (cur.err < best) { + best = cur.err; + *res = cur; + } + /* clip-aware refinement: a harmonic whose target sits on a clip bound and whose unclipped + reconstruction is already beyond it costs nothing, stop pulling it back */ + for (l = 1; l <= L; l++) { + int hi = tg[l] >= XOMBE_CQ_AMAX - 1e-6f && cur.u[l] > tg[l]; + int lo = tg[l] <= CQ_AMIN + 1e-6f && cur.u[l] < tg[l]; + teff[l] = hi || lo ? cur.u[l] : tg[l]; + any |= hi || lo; + } + if (!any || best == 0.0f) + break; + } +} + +#if XOMBE_HAVE_ENCODER +int xombe__cq_search_ambe2(xombe_cq_ws *ws, const xombe_pred *pi, const float *target, int L, const float *w, + int n_pairs, int n_gain, xombe_cq_result *res, int *bclosed, int *bopen) +{ + float tg[XOMBE_LMAX + 1], pt[XOMBE_LMAX + 1], base[XOMBE_LMAX + 1], r[XOMBE_LMAX + 1]; + float t[XOMBE_LMAX + 1], a[XOMBE_LMAX + 1], mp = 0.0f, eo = 0.0f; + int bo[9], l, k; + tg[0] = 0.0f; + for (l = 1; l <= L; l++) + tg[l] = clip(target[l], XOMBE_AMP_MIN, XOMBE_AMP_MAX); + xombe__quantize(pi, 0, L, tg, bo); + xombe__predict(pi, L, pt); + for (l = 1; l <= L; l++) + mp += pt[l]; + mp /= (float)L; + r[0] = base[0] = 0.0f; + for (l = 1; l <= L; l++) { + float pred = XOMBE_RHO * (pt[l] - mp); + base[l] = pred - xombe__half_log2[L]; + r[l] = tg[l] - pred; + } + xombe__cq_prepare(ws, &xombe__amp_ambe2, L, w); + xombe__cq_closed(ws, r, tg, base, pi->gamma, n_pairs, n_gain, XOMBE_CQ_ITERS, res); + if (bclosed) + memcpy(bclosed, res->b, sizeof(res->b)); + if (bopen) + memcpy(bopen, bo, sizeof(bo)); + for (k = 2; k < 9 && bo[k] == res->b[k]; k++) + ; + if (k == 9) + return 0; /* same fields count as the closed choice */ + /* open choice's error against the decoder's reconstruction (clamp 15 - 2^-11) */ + xombe__spectral_shape(bo, L, t); + xombe__assemble(t, pt, L, xombe__gain(bo[2], pi->gamma, 0), a); + for (l = 1; l <= L; l++) { + float d = a[l] - tg[l]; + eo += ws->w[l] * d * d; + } + if (res->err <= eo) + return 0; + for (k = 2; k < 9; k++) + res->b[k] = bo[k]; + res->err = eo; + return 1; +} +#endif diff --git a/xombe/src/common/cquant.h b/xombe/src/common/cquant.h new file mode 100644 index 0000000..0facaf0 --- /dev/null +++ b/xombe/src/common/cquant.h @@ -0,0 +1,158 @@ +#ifndef XOMBE_CQUANT_H +#define XOMBE_CQUANT_H + +/* weighted closed-loop spectral-amplitude quantizer (b2..b8) in float32, on either table set + model (params.h): a = clip((Tv - mean Tv) + base + G), base = rho*(Pt - mean Pt) - 1/2 log2 L, + G = min(dg[b2] + grho*Gprev, gmax), Tv = A3*prba24[b3] + A4*prba58[b4] + sum_k H_k*hoc_k[b5+k], matrices per L + search, all errors weighted by w and mean-removed: + 1. HOC open loop (nearest in the block-DCT domain), then up to iters rounds of the best (b3, b4) pair over + all 512 x 128 given HOC, then HOC per block given the pair (two passes) + 2. the best n_pairs pairs given that HOC, each with its own HOC search and the n_gain gains nearest the + weighted continuous gain, scored by the exact clipped reconstruction + entries an ok mask marks unusable are skipped. the search clips to [-15, 15] for both sets, not to amax + with ws->cap > 0 a pair search stops after cap units of work (a pair 1, a row 4), keeping the best pairs so + far. its lowest-bound row always completes, the others run in ascending bound order, so a search takes at + most max(cap + 4, 132) units. cap 0 is exact + arrays are indexed 1..L (0 unused), fields come back in b[2..8] */ + +#include "../internal.h" +#if XOMBE_KERNELS_Q15 +#include "../tables/cq_q15_tables.h" +#endif + +#define XOMBE_CQ_MAX_PAIRS 8 +#define XOMBE_CQ_MAX_GAIN 8 +#define XOMBE_CQ_HOC_ROWS 72 /* sum of the HOC row counts, AMBE+2's 32 + 16 + 16 + 8 */ +#define XOMBE_CQ_J_MAX 17 /* longest spectral block */ +#define XOMBE_CQ_AMAX 15.0f /* search's upper clip, both sets */ +#define XOMBE_CQ_CAP 1250 /* encoder and transcoder ws.cap */ +/* encoder and transcoder settings: weights gamma and floor, then n_pairs, n_gain, iters, and clip_passes */ +#define XOMBE_CQ_QWEIGHT 0.5f +#define XOMBE_CQ_WEIGHT_FLOOR 0.05f +#define XOMBE_CQ_N_PAIRS 4 +#define XOMBE_CQ_N_GAIN 3 +#define XOMBE_CQ_ITERS 2 +#define XOMBE_CQ_CLIP_PASSES 2 + +#if XOMBE_KERNELS_Q15 +/* q15 kernels: the same search with the pair-search bounds in int16 SIMD against the codebook images + (cq_q15_tables.h) and the HOC errors as quadratic forms, every bound lowered by its proven rounding error, so + pruning still never excludes a pair the exhaustive search keeps. pair errors and the final scoring stay float. + about 12 KB, keep it off the stack on small targets. zero it before first use, xombe__cq_prepare keeps the + maps of L across calls with the same set and L */ +typedef struct { + const xombe_amp_tables *ts; + const xombe_cq_q15_tab *qt; /* ts's images, NULL: exhaustive pair search */ + int L; + int pos[4], J[4], M[4]; /* block k: harmonics pos..pos+J-1, M = min(J, 6) */ + float w[XOMBE_LMAX + 1], sw; /* weights, sw = sum w */ + float b1[XOMBE_LMAX + 1]; /* Tv's map from (G2..G8) at harmonic l of block k: c0[k] + b1[l] c1[k] */ + float c0[4][7], c1[4][7]; + float mu[7]; /* weighted column means of that map */ + float Q[7][7]; /* (A - mean)^T W (A - mean) */ + float H[XOMBE_LMAX + 1][4]; /* HOC synthesis: 2cos(pi m (i + 1/2)/J), m = 2..M-1, block-local i */ + float hq[XOMBE_CQ_HOC_ROWS]; /* every HOC row c: c^T H^T W H c, over its block */ + float hl[XOMBE_CQ_HOC_ROWS]; /* and c*H^T w */ + int hoc_off[4]; /* block k's first row in hq, hl */ + float e4q[128]; /* prba58 rows' quadratic terms x4^T Q44 x4 */ + float e4[128]; /* e4 of the current pair search */ + /* pair-search bounds (prba_pairs), integers v stand for v * 2^-exponent */ + int chol_ok; /* 0: Q44 not safely positive definite, or no images: exhaustive */ + float Lc[4][4]; /* Q44 = Lc Lc^T */ + float Mz[4][3]; /* Lc^-1 Q43 */ + float dir[4], pmax; /* principal direction of the rows p = Lc^T x4, max |p| */ + float ps[128]; /* usable rows' projections dir*p, ascending */ + short pord[128]; /* their prba58 rows */ + int n4; /* their count */ + int col_ok; /* the column bound (roles swapped) is available */ + float L3[3][3], M3[3][4]; /* Q33 = L3 L3^T, M3 = L3^-1 Q34 */ + int32_t sq4[128]; /* per prba58 row: x4^T(Q44 - M3^T M3)x4 at 2^-sq4_x, |.| <= 2^29 */ + int sq4_x; + float sq4_d, mw4, n4max; /* its error bound, rounding magnitude, max |x4| */ + float colb[128]; /* per prba58 row: bound S' - slack in the current search */ + float fps[128]; /* columns left after the first row, in projection order */ + short ford[128]; + int32_t sq[512]; /* per prba24 row: x3^T(Q33 - Mz^T Mz)x3 at 2^-sq_x, |.| <= 2^29 */ + int sq_x; + float sq_d, mw, n3max; /* its error bound, rounding magnitude, max |x3| */ + int32_t sb[512]; /* per prba24 row: bound S - slack = sb * sb_s - sb_k, INT32_MAX unusable */ + float sb_s, sb_k; + int32_t dz[512]; /* per prba24 row: dir*(Mz x3) = dz * dz_s within dz_e */ + float dz_s, dz_e; + int brute; /* 1: no pruning in the pair search (testing) */ + int cap; /* pair-search cap in units, 0: none (set after zeroing) */ + int work; /* most units a pair search took since xombe__cq_prepare */ +} xombe_cq_ws; +#else +/* one search's workspace: per-L maps, w-only terms, and HOC candidates, filled by xombe__cq_prepare + about 19 KB, keep it off the stack on small targets. zero it before first use, xombe__cq_prepare keeps the + maps of L across calls with the same set and L */ +typedef struct { + const xombe_amp_tables *ts; + int L; + int pos[4], J[4], M[4]; + float w[XOMBE_LMAX + 1], sw; + float A[XOMBE_LMAX + 1][7]; /* Tv's linear map from (G2..G8) = (prba24, prba58) */ + float Wm[XOMBE_LMAX + 1][7]; /* w*(A - weighted column mean) */ + float Q[7][7]; + float H[XOMBE_LMAX + 1][4]; + float hv[XOMBE_CQ_HOC_ROWS * XOMBE_CQ_J_MAX]; /* every HOC row's block values (H_k @ hoc_k[n]) */ + int hv_off[4]; + float e4q[128]; + float e4[128]; + int chol_ok; + float Lc[4][4]; + float Mz[4][3]; + float dir[4], pmax; + float ps[128]; + short pord[128]; + int n4; + int col_ok; + float L3[3][3], M3[3][4]; + float sq4[128], mw4, n4max; + float colb[128]; + float fps[128]; + short ford[128]; + float sq[512], mw, n3max; + float sb[512]; + float dz[512]; + int brute; + int cap; + int work; +} xombe_cq_ws; +#endif + +typedef struct { + int b[9]; /* b[2..8] */ + float err; /* sum w (a - clip(target))^2, a the search's clipped reconstruction */ + float u[XOMBE_LMAX + 1]; /* winner's unclipped reconstruction */ +} xombe_cq_result; + +/* w[l] = max(2^(gamma (t[l] - max t)), floor), l = 1..L */ +void xombe__cq_amp_weights(const float *target, int L, float gamma, float floor_, float *w); + +/* fills the workspace for set ts, L harmonics, and weights w[1..L] (NULL: unweighted) */ +void xombe__cq_prepare(xombe_cq_ws *ws, const xombe_amp_tables *ts, int L, const float *w); + +/* closed-loop search on a prepared workspace: residual r = target - rho(Pt - mean Pt), clipped target, + base = rho(Pt - mean Pt) - 1/2 log2 L, previous gain Gprev + n_pairs <= XOMBE_CQ_MAX_PAIRS, n_gain <= XOMBE_CQ_MAX_GAIN */ +void xombe__cq_closed(xombe_cq_ws *ws, const float *r, const float *target, const float *base, float Gprev, + int n_pairs, int n_gain, int iters, xombe_cq_result *res); + +/* quantizes target[1..L] (clipped here to [-15, XOMBE_CQ_AMAX]) on set ts against prediction pt[1..L] + (xombe__predict_from of the memory) and its gain Gprev. closed 0 is open loop, res->err and res->u unset */ +void xombe__cq_quantize(xombe_cq_ws *ws, const xombe_amp_tables *ts, const float *target, int L, const float *pt, + float Gprev, const float *w, int closed, int n_pairs, int n_gain, int iters, int clip_passes, + xombe_cq_result *res); + +#if XOMBE_HAVE_ENCODER +/* closed-loop search on the AMBE+2 set against predictor pi vs the encoder's open-loop choice (xombe__quantize), + closed wins unless open's weighted error against the decoder's reconstruction is smaller, ties go closed + target clipped to [-15, 15 - 2^-11]. returns 1 if the open-loop choice won, res->b holds the pick, res->err + its error (the closed search's own for a closed pick), bclosed/bopen (b[2..8]) may be NULL */ +int xombe__cq_search_ambe2(xombe_cq_ws *ws, const xombe_pred *pi, const float *target, int L, const float *w, + int n_pairs, int n_gain, xombe_cq_result *res, int *bclosed, int *bopen); +#endif + +#endif diff --git a/xombe/src/common/params.c b/xombe/src/common/params.c new file mode 100644 index 0000000..f512e1c --- /dev/null +++ b/xombe/src/common/params.c @@ -0,0 +1,223 @@ +#include +#include +#include "params.h" +#include "consts.h" +#include "../tables/tables.h" +#include "../tables/dsp_tables.h" + +const xombe_amp_tables xombe__amp_ambe2 = { + xombe__dg, 32, xombe__prba24, 512, xombe__prba58, 128, + {&xombe__hoc5[0][0], &xombe__hoc6[0][0], &xombe__hoc7[0][0], &xombe__hoc8[0][0]}, {32, 16, 16, 8}, + xombe__blk, 0, 0, 0, {0, 0, 0, 0}, + XOMBE_RHO, 0.5f, XOMBE_GAIN_MAX, XOMBE_AMP_MIN, XOMBE_AMP_MAX}; + +float xombe__clamp_amp(float a) +{ + if (a < XOMBE_AMP_MIN) + return XOMBE_AMP_MIN; + if (a > XOMBE_AMP_MAX) + return XOMBE_AMP_MAX; + return a; +} + +float xombe__hf_tilt(float f) +{ + return f > XOMBE_HF_CORNER ? log2f(f / XOMBE_HF_CORNER) : 0.0f; +} + +/* L = floor(0.4627/f0): harmonics below about 3.7 kHz, clamped to 9..XOMBE_LMAX */ +#define L_SCALE 0.4627f +#define L_MIN 9 + +int xombe__L_from_f0(float f0) +{ + int L = (int)floorf(L_SCALE / f0); + if (L < L_MIN) + L = L_MIN; + if (L > XOMBE_LMAX) + L = XOMBE_LMAX; + return L; +} + +int xombe__nearest_row(const float *tab, int rows, int stride, int used, const float *t, const unsigned char *mask) +{ + float best = 0.0f; + int j, m, bi = 0, found = 0; + for (j = 0; j < rows; j++) { + float d = 0.0f; + if (mask && !mask[j]) + continue; + for (m = 0; m < used; m++) { + float e = tab[j * stride + m] - t[m]; + d += e * e; + } + if (!found || d < best) { + found = 1; + best = d; + bi = j; + } + } + return bi; +} + +void xombe__pred_init(xombe_pred *pi) +{ + memset(pi, 0, sizeof(*pi)); + pi->cls = XOMBE_CLASS_VOICE; + pi->L = XOMBE_SILENCE_L; + pi->f0 = XOMBE_SILENCE_F0; +} + +float xombe__harmonic_lerp(const float a[XOMBE_LMAX + 1], int i, float f) +{ + if (i < 1) + return a[1]; + if (i >= XOMBE_LMAX) + return a[XOMBE_LMAX]; + return (1.0f - f) * a[i] + f * a[i + 1]; +} + +void xombe__predict(const xombe_pred *pi, int L, float pt[XOMBE_LMAX + 1]) +{ + xombe__predict_from(pi->L, pi->a, L, pt); +} + +void xombe__predict_from(int Lp, const float ap[XOMBE_LMAX + 1], int L, float pt[XOMBE_LMAX + 1]) +{ + int l; + pt[0] = 0.0f; + for (l = 1; l <= L; l++) { + /* harmonic l maps to l*Lp/L of the previous frame, split exactly into i + num % L / L */ + int num = l * Lp; + int i = num / L; + float f = (float)(num % L) / (float)L; + /* i reaches XOMBE_LMAX only for l = L with Lp = XOMBE_LMAX, so f = 0 and a[XOMBE_LMAX] is in bounds */ + pt[l] = xombe__harmonic_lerp(ap, i, f); + } +} + +const float *xombe__hoc_table(int k, int *rows) +{ + *rows = xombe__amp_ambe2.n_hoc[k]; + return xombe__amp_ambe2.hoc[k]; +} + +void xombe__spectral_shape(const int b[9], int L, float t[XOMBE_LMAX + 1]) +{ + xombe__spectral_shape_ts(&xombe__amp_ambe2, b, L, t); +} + +void xombe__spectral_shape_ts(const xombe_amp_tables *ts, const int b[9], int L, float t[XOMBE_LMAX + 1]) +{ + float g[9], r[8]; + int i, m, k, pos = 1; + g[1] = 0.0f; + for (m = 0; m < 3; m++) + g[2 + m] = ts->prba24[b[3]][m]; + for (m = 0; m < 4; m++) + g[5 + m] = ts->prba58[b[4]][m]; + for (i = 0; i < 8; i++) { + float s = 0.0f; + for (m = 1; m <= 8; m++) + s += (m == 1 ? 1.0f : 2.0f) * g[m] * xombe__dct8[m - 1][i]; + r[i] = s; + } + for (k = 0; k < 4; k++) { + int J = ts->blk[L][k]; + int top = J < 6 ? J : 6; + float c[7]; + const float *hoc = ts->hoc[k] + 4 * b[5 + k]; + const float *kern = xombe__dct_blk + xombe__dct_blk_off[J]; + c[1] = (r[2 * k] + r[2 * k + 1]) * 0.5f; + c[2] = (r[2 * k] - r[2 * k + 1]) * 0.35355339f; /* 1/(2*sqrt 2) */ + + for (m = 3; m <= 6; m++) + c[m] = m <= top ? hoc[m - 3] : 0.0f; + for (i = 0; i < J; i++) { + float s = 0.0f; + for (m = 2; m <= top; m++) + s += c[m] * kern[(m - 1) * J + i]; + t[pos++] = c[1] + 2.0f * s; + } + } + t[0] = 0.0f; +} + +void xombe__assemble(const float t[XOMBE_LMAX + 1], const float pt[XOMBE_LMAX + 1], int L, float gamma, + float a[XOMBE_LMAX + 1]) +{ + xombe__assemble_ts(&xombe__amp_ambe2, t, pt, L, gamma, a); +} + +void xombe__assemble_ts(const xombe_amp_tables *ts, const float t[XOMBE_LMAX + 1], const float pt[XOMBE_LMAX + 1], + int L, float gamma, float a[XOMBE_LMAX + 1]) +{ + float mt = 0.0f, mp = 0.0f, off; + int l; + for (l = 1; l <= L; l++) { + mt += t[l]; + mp += pt[l]; + } + mt /= (float)L; + mp /= (float)L; + off = gamma - xombe__half_log2[L]; + a[0] = 0.0f; + for (l = 1; l <= L; l++) { + float v = (t[l] - mt) + ts->rho * (pt[l] - mp) + off; + a[l] = v < ts->amin ? ts->amin : v > ts->amax ? ts->amax : v; + } + for (l = L + 1; l <= XOMBE_LMAX; l++) + a[l] = a[L]; +} + +float xombe__gain_ts(const xombe_amp_tables *ts, int b2, float Gprev) +{ + float G = ts->dg[b2] + ts->grho * Gprev; + return G < ts->gmax ? G : ts->gmax; +} + +float xombe__gain(int b2, float prev_gamma, int silence) +{ + const xombe_amp_tables *ts = &xombe__amp_ambe2; + float g = ts->dg[b2] + ts->grho * prev_gamma - (silence ? XOMBE_SILENCE_GAIN_OFFSET : 0.0f); + return g < ts->gmax ? g : ts->gmax; +} + +void xombe__dequant(const int b[9], const xombe_pred *pi, int silence, xombe_params *out) +{ + float t[XOMBE_LMAX + 1], pt[XOMBE_LMAX + 1]; + out->pulse = 0; + if (silence) { + out->f0 = XOMBE_SILENCE_F0; + out->L = XOMBE_SILENCE_L; + } else if (b[1] >= XOMBE_PULSE_B1_MIN) { + out->pulse = 1; + out->f0 = XOMBE_PULSE_F0; + out->L = XOMBE_PULSE_L; + } else { + out->f0 = xombe__w0[b[0]]; + out->L = xombe__lt[b[0]]; + } + out->gamma = xombe__gain(b[2], pi->gamma, silence); + xombe__spectral_shape(b, out->L, t); + xombe__predict(pi, out->L, pt); + xombe__assemble(t, pt, out->L, out->gamma, out->a); +} + +void xombe__pred_store_voice(xombe_pred *pi, const xombe_params *p, const uint8_t v2[8]) +{ + int l; + pi->cls = XOMBE_CLASS_VOICE; + pi->L = p->L; + pi->f0 = p->f0; + pi->gamma = p->gamma; + for (l = 0; l <= XOMBE_LMAX; l++) + pi->a[l] = l <= p->L ? p->a[l] : p->a[p->L]; + memcpy(pi->v2, v2, 8); +} + +void xombe__pred_store_other(xombe_pred *pi, int cls) +{ + pi->cls = cls; + memset(pi->v2, 0, 8); +} diff --git a/xombe/src/common/params.h b/xombe/src/common/params.h new file mode 100644 index 0000000..0384fb7 --- /dev/null +++ b/xombe/src/common/params.h @@ -0,0 +1,71 @@ +#ifndef XOMBE_PARAMS_H +#define XOMBE_PARAMS_H + +#include "../state.h" + +/* spectral-amplitude tables and constants of one codec, AMBE+2 (xombe__amp_ambe2) or D-STAR (xombe__amp_dstar) + t = block-DCT spectral shape of b3..b8 (xombe__spectral_shape_ts), harmonics 1..L + G = min(dg[b2] + grho*G_prev, gmax) + a = clamp((t - mean t) + rho*(pt - mean pt) + G - 1/2 log2 L, amin, amax), pt = prediction from the previous frame + ok_* mark entries the closed-loop quantizer may pick (1) and unfitted ones it skips (0), NULL means all */ +typedef struct { + const float *dg; + int n_dg; + const float (*prba24)[3]; + int n_prba24; + const float (*prba58)[4]; + int n_prba58; + const float *hoc[4]; /* b5..b8: rows of 4 floats, the first min(J, 6) - 2 used */ + int n_hoc[4]; + const unsigned char (*blk)[4]; /* block lengths J per L, [57][4] */ + const unsigned char *ok_dg, *ok_prba24, *ok_prba58, *ok_hoc[4]; + float rho, grho, gmax, amin, amax; +} xombe_amp_tables; + +extern const xombe_amp_tables xombe__amp_ambe2; + +typedef struct { + int L; + int pulse; + float f0; + float gamma; + float a[XOMBE_LMAX + 1]; +} xombe_params; + +/* log amplitude of harmonics with no component (tone sets' other harmonics), synthesizes as 0 */ +#define XOMBE_AMP_OFF (-1000.0f) + +float xombe__clamp_amp(float a); +/* decoder's high-frequency boost: log2(f/XOMBE_HF_CORNER) above the corner, else 0 */ +float xombe__hf_tilt(float f); +int xombe__L_from_f0(float f0); +/* row of tab (rows x stride floats) nearest t[0..used) in squared error, first on ties, rows with mask[j] 0 + skipped (mask NULL: none), 0 if every row is */ +int xombe__nearest_row(const float *tab, int rows, int stride, int used, const float *t, const unsigned char *mask); +void xombe__pred_init(xombe_pred *pi); +/* (1 - f)*a[i] + f*a[i + 1] over log amplitudes a[1..XOMBE_LMAX], holding a[1] below harmonic 1 and + a[XOMBE_LMAX] from harmonic XOMBE_LMAX up */ +float xombe__harmonic_lerp(const float a[XOMBE_LMAX + 1], int i, float f); +void xombe__predict(const xombe_pred *pi, int L, float pt[XOMBE_LMAX + 1]); +/* prediction pt[1..L] from a previous frame of Lp harmonics, ap[1..XOMBE_LMAX] extended past Lp */ +void xombe__predict_from(int Lp, const float ap[XOMBE_LMAX + 1], int L, float pt[XOMBE_LMAX + 1]); +/* HOC codebook of block k (b5..b8) and its row count, rows of 4 floats, bound to the AMBE+2 tables */ +const float *xombe__hoc_table(int k, int *rows); +/* xombe__spectral_shape_ts bound to the AMBE+2 tables */ +void xombe__spectral_shape(const int b[9], int L, float t[XOMBE_LMAX + 1]); +void xombe__spectral_shape_ts(const xombe_amp_tables *ts, const int b[9], int L, float t[XOMBE_LMAX + 1]); +/* xombe__assemble_ts bound to the AMBE+2 tables */ +void xombe__assemble(const float t[XOMBE_LMAX + 1], const float pt[XOMBE_LMAX + 1], int L, float gamma, + float a[XOMBE_LMAX + 1]); +/* a[1..L] by the xombe_amp_tables model on set ts, a[L + 1..XOMBE_LMAX] = a[L] */ +void xombe__assemble_ts(const xombe_amp_tables *ts, const float t[XOMBE_LMAX + 1], const float pt[XOMBE_LMAX + 1], + int L, float gamma, float a[XOMBE_LMAX + 1]); +/* G = min(dg[b2] + grho*Gprev, gmax) on set ts */ +float xombe__gain_ts(const xombe_amp_tables *ts, int b2, float Gprev); +/* AMBE+2 gain, as xombe__gain_ts but a silence frame takes off XOMBE_SILENCE_GAIN_OFFSET before the cap */ +float xombe__gain(int b2, float prev_gamma, int silence); +void xombe__dequant(const int b[9], const xombe_pred *pi, int silence, xombe_params *out); +void xombe__pred_store_voice(xombe_pred *pi, const xombe_params *p, const uint8_t v2[8]); +void xombe__pred_store_other(xombe_pred *pi, int cls); + +#endif diff --git a/xombe/src/common/prof.h b/xombe/src/common/prof.h new file mode 100644 index 0000000..b4e50e5 --- /dev/null +++ b/xombe/src/common/prof.h @@ -0,0 +1,30 @@ +#ifndef XOMBE_PROF_H +#define XOMBE_PROF_H + +/* encoder stage cycles for a Cortex-M bench (-DXOMBE_PROF_DWT): XOMBE_PF(k, stmt) runs stmt and adds its DWT + cycles to xombe__pf[k], without XOMBE_PROF_DWT it runs stmt alone + stages: 0 push, 1 analyze, 2 AMBE+2 voicing, 3 D-STAR voicing, 4 background, 5 AMBE+2 emit, 6 D-STAR emit, + 7 D-STAR tone push + nested: 8 front end voicing and 9 voicing metric in 3, 10 AMBE+2 tone detector in 1, 11 detection and + 12 tone-in-noise pass in 7, 13 D-STAR quantizer, 14 D-STAR targets in 6 + 15 sums L over the D-STAR quantizer calls */ + +#ifdef XOMBE_PROF_DWT +extern unsigned long xombe__pf[16]; +#define XOMBE_PF_NOW() (*(volatile unsigned long *)0xE0001004u) /* DWT_CYCCNT, counter enabled by the caller */ +#define XOMBE_PF(k, ...) \ + do { \ + unsigned long xombe_pf_t0 = XOMBE_PF_NOW(); \ + __VA_ARGS__; \ + xombe__pf[k] += XOMBE_PF_NOW() - xombe_pf_t0; \ + } while (0) +#define XOMBE_PF_ADD(k, n) (xombe__pf[k] += (unsigned long)(n)) +#else +#define XOMBE_PF(k, ...) \ + do { \ + __VA_ARGS__; \ + } while (0) +#define XOMBE_PF_ADD(k, n) ((void)0) +#endif + +#endif diff --git a/xombe/src/common/tone_table.c b/xombe/src/common/tone_table.c new file mode 100644 index 0000000..fe0370f --- /dev/null +++ b/xombe/src/common/tone_table.c @@ -0,0 +1,137 @@ +#include +#include "tone_table.h" +#include "bits.h" +#include "../state.h" +#if XOMBE_HAVE_DSTAR +#include "../dstar/dstar_internal.h" +#endif + +/* single tones synthesize as harmonic l1 of an f0 at most this */ +#define SINGLE_F0_MAX_HZ 250.0f +#define DUAL_FIRST XOMBE_TONE_DUAL_FIRST +#define DUAL_IDS XOMBE_TONE_DUALS + +/* dual tones 128..163 by id - 128, low and high frequencies in Hz + DTMF 128..143 and call progress 160..162: DVSI AMBE-3000R Vocoder Chip Users Manual, Table 103 + Knox 144..159 and call progress 163: US 7,970,606 B2, Table 1 ("MBE tone parameters") */ +static const short dual_low[DUAL_IDS] = {941, 697, 697, 697, 770, 770, 770, 852, 852, 852, 697, 770, + 852, 941, 941, 941, 820, 606, 606, 606, 672, 672, 672, 743, + 743, 743, 606, 672, 743, 820, 820, 820, 350, 440, 480, 350}; +static const short dual_high[DUAL_IDS] = {1336, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1336, 1477, 1633, 1633, + 1633, 1633, 1209, 1477, 1162, 1052, 1162, 1297, 1052, 1162, 1297, 1052, + 1162, 1297, 1430, 1430, 1430, 1430, 1052, 1297, 440, 480, 620, 490}; + +/* f0 (Hz) and harmonic numbers l1 < l2 synthesizing each dual tone, US 7,970,606 B2, Table 1 */ +static const float dual_f0[DUAL_IDS] = { + /* 128..143, DTMF */ + 78.50f, 173.48f, 70.0f, 87.0f, 109.95f, 191.68f, 70.17f, 71.06f, 121.58f, 212.0f, 116.41f, 96.15f, + 71.0f, 234.26f, 134.38f, 134.35f, + /* 144..159, Knox */ + 68.33f, 150.89f, 67.82f, 86.50f, 95.79f, 166.92f, 67.70f, 74.74f, 105.90f, 92.78f, 101.55f, 84.02f, + 67.83f, 102.30f, 117.0f, 117.49f, + /* 160..163, call progress */ + 87.78f, 70.83f, 122.0f, 70.0f}; +static const unsigned char dual_l[DUAL_IDS][2] = { + {12, 17}, {4, 7}, {10, 19}, {8, 17}, {7, 11}, {4, 7}, {11, 21}, {12, 17}, + {7, 11}, {4, 7}, {6, 14}, {8, 17}, {12, 23}, {4, 7}, {7, 9}, {7, 11}, + {12, 17}, {4, 7}, {9, 17}, {7, 15}, {7, 11}, {4, 7}, {10, 19}, {10, 14}, + {7, 11}, {8, 14}, {6, 14}, {8, 17}, {11, 21}, {8, 14}, {7, 9}, {7, 11}, + {4, 5}, {6, 7}, {4, 5}, {5, 7}}; + +int xombe__tone_id_accepted(int id) +{ + return (id >= 5 && id <= 122) || (id >= DUAL_FIRST && id < DUAL_FIRST + DUAL_IDS); +} + +int xombe__tone_valid(int id, int ad) +{ + return xombe__tone_id_accepted(id) && ad >= 0 && ad <= 127; +} + +int xombe__tone_freqs(int id, float *f_low, float *f_high) +{ + if (id >= 5 && id <= 122) { + *f_low = *f_high = 31.25f * (float)id; + return 1; + } + if (id >= DUAL_FIRST && id < DUAL_FIRST + DUAL_IDS) { + *f_low = dual_low[id - DUAL_FIRST]; + *f_high = dual_high[id - DUAL_FIRST]; + return 2; + } + return 0; +} + +void xombe__tone_harmonics(int id, float *f0_hz, int *l1, int *l2) +{ + float lo, hi; + int kind = xombe__tone_freqs(id, &lo, &hi); + *l1 = *l2 = 0; + *f0_hz = SINGLE_F0_MAX_HZ; + if (kind == 1) { + *l1 = (int)ceilf(lo / SINGLE_F0_MAX_HZ); + *f0_hz = lo / (float)*l1; + } else if (kind == 2) { + *f0_hz = dual_f0[id - DUAL_FIRST]; + *l1 = dual_l[id - DUAL_FIRST][0]; + *l2 = dual_l[id - DUAL_FIRST][1]; + } +} + +/* 16384*10^(0.03555*(ad - 127)), in log2 */ +#define TONE_LOG2_FULL 14.0f +#define TONE_LOG2_PER_AD 0.118094543f /* 0.03555*log2 10 */ + +float xombe__tone_log2_amp(int ad) +{ + return TONE_LOG2_FULL + TONE_LOG2_PER_AD * (float)(ad - 127); +} + +int xombe__tone_frame_parse(const uint8_t d[49], int *id, int *ad) +{ + int c[4], i, dist = 0; + for (i = 0; i < 4; i++) + c[i] = xombe__get_bits(d, 12 + 8 * i, 8); + *id = c[0]; + *ad = (xombe__get_bits(d, 6, 6) << 1) | d[44]; + for (i = 1; i < 4; i++) + dist += xombe__popcount32((uint32_t)(c[0] ^ c[i])); + if ((c[1] >> 4) != (c[0] >> 4) || dist > 5 || !xombe__tone_id_accepted(c[0])) + return 0; + return 1; +} + +int xombe__tone_frame_dmr(int id, int ad, uint8_t out[9]) +{ + uint8_t d[49], bits[7]; + if (!xombe__tone_valid(id, ad)) + return -1; + xombe__tone_frame_bits(id, ad, d); + xombe__pack49(d, bits); + xombe__fec_encode_dmr(bits, out); + return 0; +} + +int xombe__tone_frame_dstar(int id, int ad, uint8_t out[9]) +{ +#if XOMBE_HAVE_DSTAR + return xombe__ds_tone_frame_id(id, ad, out); +#else + (void)id; + (void)ad; + (void)out; + return -1; +#endif +} + +void xombe__tone_frame_bits(int id, int ad, uint8_t d[49]) +{ + int i; + for (i = 0; i < 49; i++) + d[i] = 0; + xombe__put_bits(d, 0, 6, 63); + xombe__put_bits(d, 6, 6, ad >> 1); + for (i = 0; i < 4; i++) + xombe__put_bits(d, 12 + 8 * i, 8, id); + d[44] = (uint8_t)(ad & 1); +} diff --git a/xombe/src/common/tone_table.h b/xombe/src/common/tone_table.h new file mode 100644 index 0000000..315a5fe --- /dev/null +++ b/xombe/src/common/tone_table.h @@ -0,0 +1,26 @@ +#ifndef XOMBE_TONE_TABLE_H +#define XOMBE_TONE_TABLE_H + +#include + +/* tone level ad: amplitude 16384 * 10^(XOMBE_TONE_AD_LOG10 * (ad - 127)) */ +#define XOMBE_TONE_AD_LOG10 0.03555f +#define XOMBE_TONE_DB_PER_AD 0.7110f +#define XOMBE_TONE_DUAL_FIRST 128 +#define XOMBE_TONE_DUALS 36 +#define XOMBE_TONE_KNOX_FIRST 144 +#define XOMBE_TONE_KNOX_COUNT 16 + +int xombe__tone_id_accepted(int id); +/* id accepted and level code ad 0..127, what a public tone request may name */ +int xombe__tone_valid(int id, int ad); +int xombe__tone_freqs(int id, float *f_low, float *f_high); +void xombe__tone_harmonics(int id, float *f0_hz, int *l1, int *l2); +/* log2 synthesized amplitude of each tone component for level code ad */ +float xombe__tone_log2_amp(int ad); +/* tone frame: class 63, AD in d6..d11 + d44, the ID four times from d12 + returns 0 if the copies disagree too much or the ID is not accepted */ +int xombe__tone_frame_parse(const uint8_t d[49], int *id, int *ad); +void xombe__tone_frame_bits(int id, int ad, uint8_t d[49]); + +#endif diff --git a/xombe/src/common/version.c b/xombe/src/common/version.c new file mode 100644 index 0000000..04e1aae --- /dev/null +++ b/xombe/src/common/version.c @@ -0,0 +1,6 @@ +#include "xombe.h" + +int xombe_version(void) +{ + return XOMBE_VERSION; +} diff --git a/xombe/src/common/voicing.c b/xombe/src/common/voicing.c new file mode 100644 index 0000000..0bf7e4d --- /dev/null +++ b/xombe/src/common/voicing.c @@ -0,0 +1,47 @@ +#include "voicing.h" +#include "consts.h" +#include "../state.h" +#include "../tables/tables.h" + +void xombe__v2_from_b1(int b1, uint8_t v2[8]) +{ + int j; + for (j = 0; j < 8; j++) + v2[j] = xombe__vuv[b1][j]; +} + +void xombe__f3_first_half(const uint8_t v2_prev[8], const uint8_t v2[8], uint8_t v1[8]) +{ + int j; + for (j = 0; j < 8; j++) + v1[j] = (uint8_t)(v2_prev[j] && v2[j]); +} + +static int band_of(float f) +{ + int j = (int)(f * XOMBE_BANDS_PER_UNIT); + return j > 7 ? 7 : j; +} + +int xombe__voiced_at(const uint8_t vb[8], float f) +{ + return vb[band_of(f)] || vb[band_of(f + 0.5f / XOMBE_BANDS_PER_UNIT)]; +} + +void xombe__harmonic_voicing(const uint8_t vb[8], float f0, int L, uint8_t vh[XOMBE_LMAX + 1]) +{ + int l; + vh[0] = 0; + for (l = 1; l <= XOMBE_LMAX; l++) { + float f = (float)l * f0; + vh[l] = (uint8_t)(l <= L && xombe__voiced_at(vb, f)); + } +} + +int xombe__count_voiced(const uint8_t vb[8]) +{ + int j, n = 0; + for (j = 0; j < 8; j++) + n += vb[j] != 0; + return n; +} diff --git a/xombe/src/common/voicing.h b/xombe/src/common/voicing.h new file mode 100644 index 0000000..aa2299e --- /dev/null +++ b/xombe/src/common/voicing.h @@ -0,0 +1,14 @@ +#ifndef XOMBE_VOICING_H +#define XOMBE_VOICING_H + +#include +#include "../state.h" + +void xombe__v2_from_b1(int b1, uint8_t v2[8]); +void xombe__f3_first_half(const uint8_t v2_prev[8], const uint8_t v2[8], uint8_t v1[8]); +/* 1 if the band holding f, or the one half a band higher, is voiced */ +int xombe__voiced_at(const uint8_t vb[8], float f); +void xombe__harmonic_voicing(const uint8_t vb[8], float f0, int L, uint8_t vh[XOMBE_LMAX + 1]); +int xombe__count_voiced(const uint8_t vb[8]); + +#endif diff --git a/xombe/src/dec/conceal.c b/xombe/src/dec/conceal.c new file mode 100644 index 0000000..07ecb54 --- /dev/null +++ b/xombe/src/dec/conceal.c @@ -0,0 +1,15 @@ +#include +#include "../internal.h" + +int xombe__conceal_decide(xombe_dec_core *d, int bad, int hb) +{ + int last_three_concealed = (d->hist & 7u) == 7u; + int c = XOMBE_CONCEAL_NONE; + if (hb) + c = XOMBE_CONCEAL_MUTE; + else if (bad) + c = last_three_concealed ? XOMBE_CONCEAL_MUTE : XOMBE_CONCEAL_REPEAT; + d->hist = ((d->hist << 1) | (c != XOMBE_CONCEAL_NONE ? 1u : 0u)) & 7u; + d->run = c == XOMBE_CONCEAL_NONE ? 0 : d->run < INT_MAX ? d->run + 1 : INT_MAX; + return c; +} diff --git a/xombe/src/dec/decoder.c b/xombe/src/dec/decoder.c new file mode 100644 index 0000000..1e07ece --- /dev/null +++ b/xombe/src/dec/decoder.c @@ -0,0 +1,445 @@ +#include +#include +#include "../internal.h" +#include "../dsp/fmath.h" +#if XOMBE_HAVE_DSTAR +#include "../dstar/dsd_state.h" +#endif + +#define AVG_F0_INIT XOMBE_HZ(111.63f) +#define LAMBDA_INIT 7.0f +#define INIT_SET_F0 XOMBE_HZ(250.0f) +#define INIT_SET_L 14 +#define INIT_SET_LOG2_AMP (-3.321928095f) /* log2(0.1) */ +#define DEFAULT_PRNG_SEED 0x12345678u + +static const struct xombe_dec_rules ambe2_rules = {xombe__harmonic_voicing, 0.0098f}; + +void xombe__dec_silence_set(xombe_set *s) +{ + int l; + memset(s, 0, sizeof(*s)); + s->cls = XOMBE_CLASS_SILENCE; + s->prepared = 1; + s->L = INIT_SET_L; + s->f0 = INIT_SET_F0; + s->e[0] = XOMBE_AMP_OFF; + for (l = 1; l <= XOMBE_LMAX; l++) + s->a[l] = s->e[l] = INIT_SET_LOG2_AMP; +} + +XOMBE_STATIC_ASSERT(sizeof(struct xombe_dec) <= XOMBE_DEC_SIZE, decoder_state_fits_XOMBE_DEC_SIZE); + +size_t xombe_dec_size(void) +{ + return sizeof(struct xombe_dec); +} + +void xombe__dec_core_reset(xombe_dec_core *d) +{ + memset(d, 0, sizeof(*d)); + d->rules = &ambe2_rules; + xombe__pred_init(&d->pi); + d->lambda = LAMBDA_INIT; + d->avg_f0 = AVG_F0_INIT; + d->frame = -1; + d->mute_src = -1; + d->decision.mute_src = -1; + d->decision.e0 = d->decision.e1 = -1; + xombe__dec_silence_set(&d->mute); + xombe__dec_silence_set(&d->played); + d->p1 = d->p2 = d->played; +} + +void xombe__dec_reset(xombe_dec *d) +{ + memset(d, 0, sizeof(*d)); + xombe__dec_core_reset(&d->c); + d->prev_f0 = INIT_SET_F0; + d->noise_mode = XOMBE_NOISE_PRODUCTION; + d->prng = DEFAULT_PRNG_SEED; + xombe__noise_init(d); + xombe__hpf_init(&d->hpf, 1.0f); + xombe__fec_init_dmr(&d->fec); +} + +static void dmr_start_bits(xombe_dec *d, const uint8_t bits[7], unsigned flags) +{ + d->c.eps_t = d->err_t; + d->c.eps_1 = d->err_1; + xombe__dec_start_frame(&d->c, bits, flags); +} + +static const struct xombe_dec_ops dmr_ops = {dmr_start_bits}; + +xombe_dec *xombe__dec_init_dmr(void *mem) +{ + xombe_dec *d = mem; + if (!d) + return NULL; + xombe__dec_reset(d); + d->ops = &dmr_ops; + return d; +} + +xombe_dec *xombe__dec_init_dstar(void *mem) +{ +#if XOMBE_HAVE_DSTAR + xombe_dec *d = mem; + if (!d) + return NULL; + xombe__dec_reset(d); + xombe__fec_init_dstar(&d->fec); + xombe__dsd_logic_init(&d->ds, &d->c); + d->ops = &xombe__dsd_ops; + return d; +#else + (void)mem; + return NULL; +#endif +} + +int xombe_dec_set_noise(xombe_dec *d, enum xombe_noise_mode mode, uint32_t seed) +{ + if (mode != XOMBE_NOISE_CONFORMANCE && mode != XOMBE_NOISE_PRODUCTION) + return -1; + d->noise_mode = mode; + d->prng = seed ? seed : DEFAULT_PRNG_SEED; + xombe__noise_init(d); + return 0; +} + +void xombe__dec_set_tap(xombe_dec *d, xombe_tap_fn fn, void *ctx) +{ + d->c.tap = fn; + d->c.tap_ctx = ctx; +} + +void xombe_dec_set_errors(xombe_dec *d, int eps_t, int eps1) +{ + d->err_t = eps_t; + d->err_1 = eps1; +} + +void xombe_dec_decision_get(const xombe_dec *d, xombe_decision *out) +{ + *out = d->c.decision; +} + +/* log amplitude of a at harmonic position x >= 0 */ +static float harmonic_interp(const float *a, float x) +{ + int i = (int)x; + return xombe__harmonic_lerp(a, i, x - (float)i); +} + +void xombe__dec_set_from_params(xombe_set *s, int cls, float f0, int L, const float *a, const uint8_t *vb) +{ + memset(s, 0, sizeof(*s)); + s->cls = cls; + s->f0 = f0; + s->L = L; + memcpy(s->a, a, sizeof(s->a)); + if (vb) + memcpy(s->vb, vb, 8); +} + +static void first_half_voice_after_voice(const xombe_dec_core *d, const xombe_set *c, const uint8_t *v1, xombe_set *p1) +{ + float f1, rc, rp, a1[XOMBE_LMAX + 1]; + int l, L1; + if (!xombe__count_voiced(d->pi.v2)) + f1 = c->f0; + else if (!xombe__count_voiced(c->vb)) + f1 = d->pi.f0; + else + f1 = sqrtf(d->pi.f0 * c->f0); + L1 = xombe__L_from_f0(f1); + rc = f1 / c->f0; + rp = f1 / d->pi.f0; + a1[0] = 0.0f; + for (l = 1; l <= L1; l++) { + float sc = harmonic_interp(c->a, (float)l * rc); + float sp = harmonic_interp(d->pi.a, (float)l * rp); + a1[l] = xombe__clamp_amp(0.5f * (sc + sp)); + } + for (l = L1 + 1; l <= XOMBE_LMAX; l++) + a1[l] = a1[L1]; + xombe__dec_set_from_params(p1, XOMBE_CLASS_VOICE, f1, L1, a1, v1); +} + +static void decode_normal(xombe_dec_core *d, const uint8_t bits[49], int cls) +{ + xombe_set c; + xombe_params p; + uint8_t v2[8], v1[8]; + int b[9]; + memset(v2, 0, sizeof(v2)); + memset(v1, 0, sizeof(v1)); + xombe__get_fields(bits, b); + if (cls == XOMBE_CLASS_VOICE) { + xombe__dequant(b, &d->pi, 0, &p); + XOMBE_TAP(d, XOMBE_STAGE_DEQUANT, p.f0, p.a + 1, p.L); + xombe__v2_from_b1(b[1], v2); + xombe__f3_first_half(d->pi.v2, v2, v1); + xombe__smooth(d, p.a, p.L, p.f0); + XOMBE_TAP(d, XOMBE_STAGE_SMOOTH, p.f0, p.a + 1, p.L); + xombe__dec_set_from_params(&c, XOMBE_CLASS_VOICE, p.f0, p.L, p.a, v2); + } else if (cls == XOMBE_CLASS_SILENCE) { + xombe__dequant(b, &d->pi, 1, &p); + XOMBE_TAP(d, XOMBE_STAGE_DEQUANT, p.f0, p.a + 1, p.L); + xombe__smooth(d, p.a, p.L, p.f0); + XOMBE_TAP(d, XOMBE_STAGE_SMOOTH, p.f0, p.a + 1, p.L); + xombe__dec_set_from_params(&c, XOMBE_CLASS_SILENCE, p.f0, p.L, p.a, NULL); + } else { + int id, ad; + xombe__tone_frame_parse(bits, &id, &ad); + xombe__tone_set(&c, id, ad); + } + xombe__dec_play(d, &c, v1, &p, v2); +} + +void xombe__dec_play(xombe_dec_core *d, const xombe_set *cur, const uint8_t v1[8], const xombe_params *p, + const uint8_t v2[8]) +{ + const xombe_set c = *cur; + int l, last = d->pi.cls; + if (c.cls == XOMBE_CLASS_TONE || last == XOMBE_CLASS_TONE) { + d->p1 = c; + } else if (last == XOMBE_CLASS_SILENCE) { + d->p1 = c; + memcpy(d->p1.vb, v1, 8); + if (c.cls == XOMBE_CLASS_VOICE) + for (l = 0; l <= XOMBE_LMAX; l++) + d->p1.a[l] = 0.5f * c.a[l]; + } else if (c.cls == XOMBE_CLASS_SILENCE) { + if (!d->prev_concealed) + xombe__dec_set_from_params(&d->p1, XOMBE_CLASS_VOICE, d->pi.f0, d->pi.L, d->pi.a, d->pi.v2); + else + d->p1 = c; + } else { + first_half_voice_after_voice(d, &c, v1, &d->p1); + } + d->p2 = c; + + if (c.cls == XOMBE_CLASS_VOICE) + xombe__pred_store_voice(&d->pi, p, v2); + else + xombe__pred_store_other(&d->pi, c.cls); +} + +void xombe__dec_conceal_sets(xombe_dec_core *d, int conceal) +{ + d->p1 = conceal == XOMBE_CONCEAL_MUTE ? d->mute : d->played; + d->p1.repeat = 1; + d->p2 = d->p1; +} + +void xombe__dec_start_frame(xombe_dec_core *d, const uint8_t bytes[7], unsigned flags) +{ + uint8_t bits[49]; + int cls, bad, hb, conceal, tone_ok = 1; + d->frame++; + if (flags & XOMBE_FLAG_LOST) { + memset(bits, 0, sizeof(bits)); + cls = XOMBE_CLASS_ERASURE; + flags = 0; + } else { + xombe__unpack49(bytes, bits); + cls = xombe__frame_class(bits); + } + if (cls == XOMBE_CLASS_TONE) { + int id, ad; + tone_ok = xombe__tone_frame_parse(bits, &id, &ad); + } + hb = (flags & XOMBE_FLAG_HB) != 0; + bad = (flags & XOMBE_FLAG_BF) || cls == XOMBE_CLASS_ERASURE || !tone_ok; + conceal = xombe__conceal_decide(d, bad, hb); + d->decision.cls = cls; + d->decision.conceal = conceal; + d->decision.run = d->run; + d->decision.mute_src = conceal == XOMBE_CONCEAL_MUTE ? d->mute_src : -1; + d->decision.e0 = d->decision.e1 = -1; + d->decision.bf = (flags & XOMBE_FLAG_BF) != 0; + d->decision.hb = hb; + if (conceal != XOMBE_CONCEAL_NONE) + xombe__dec_conceal_sets(d, conceal); + else + decode_normal(d, bits, cls); + d->prev_concealed = conceal != XOMBE_CONCEAL_NONE; +} + +static void prepare_set(xombe_set *s) +{ + int l; + if (s->prepared || s->repeat) + return; + for (l = 0; l <= XOMBE_LMAX; l++) + s->e[l] = l >= 1 && l <= s->L ? s->a[l] : XOMBE_AMP_OFF; + if (s->cls == XOMBE_CLASS_VOICE) { + xombe__phases(s->a, s->L, s->phi); + xombe__enhance(s->a, s->L, s->f0, s->e); + } else { + memset(s->phi, 0, sizeof(s->phi)); + } + s->prepared = 1; +} + +static void synth_half(xombe_dec *d, xombe_set *s, int first_half, int N, int16_t *pcm) +{ + float M[XOMBE_LMAX + 1], x[XOMBE_HALF_MAX]; + uint8_t vh[XOMBE_LMAX + 1]; + int n, l, tone = s->cls == XOMBE_CLASS_TONE, voiced; + prepare_set(s); + if (!tone && d->c.tap) { + float lin[XOMBE_LMAX + 1]; + for (l = 1; l <= s->L; l++) + lin[l] = xombe__exp2f(s->e[l]); + XOMBE_TAP(&d->c, XOMBE_STAGE_SET, s->f0, s->a + 1, s->L); + XOMBE_TAP(&d->c, XOMBE_STAGE_ENHANCED, s->f0, lin + 1, s->L); + } + if (s->cls == XOMBE_CLASS_VOICE) + XOMBE_TAP(&d->c, XOMBE_STAGE_PHASE, s->f0, s->phi + 1, s->L); + if (s->cls == XOMBE_CLASS_SILENCE && !s->repeat) { + d->c.mute = *s; + d->c.mute_src = d->c.frame; + } + if (tone) { + for (l = 0; l <= XOMBE_LMAX; l++) + vh[l] = (uint8_t)(l >= 1 && l <= s->L); + } else { + d->c.rules->harm_voicing(s->vb, s->f0, s->L, vh); + } + memset(M, 0, sizeof(M)); + if (tone) { + for (l = 1; l <= s->L; l++) + if (s->e[l] > XOMBE_AMP_OFF) + M[l] = xombe__exp2f(s->e[l]); + } else { + if (first_half && xombe__count_voiced(s->vb) >= 4) + d->c.avg_f0 = 0.9f * d->c.avg_f0 + 0.1f * s->f0; + xombe__shape(s->e, M, s->L, s->f0, d->c.avg_f0); + } + XOMBE_TAP(&d->c, XOMBE_STAGE_SHAPED, s->f0, M + 1, s->L); + memset(x, 0, sizeof(x)); + xombe__synth_unvoiced(d, s, M, vh, N, x); + voiced = tone || xombe__count_voiced(s->vb) > 0; + xombe__synth_voiced(d, s, M, vh, voiced, N, x); + XOMBE_TAP(&d->c, XOMBE_STAGE_SYNTH, s->f0, x, N); + for (n = 0; n < N; n++) { + float y = floorf(xombe__hpf_step(&d->hpf, x[n]) + 0.5f); + if (y > 32767.0f) + y = 32767.0f; + if (y < -32768.0f) + y = -32768.0f; + pcm[n] = (int16_t)y; + } +} + +void xombe__dec_synth(xombe_dec *d, int second_half, int N, int16_t *pcm) +{ + if (!second_half) { + synth_half(d, &d->c.p1, 1, N, pcm); + } else { + synth_half(d, &d->c.p2, 0, N, pcm); + d->c.played = d->c.p2; + } +} + +void xombe__dec_skip_synth(xombe_dec_core *d) +{ + const xombe_set *h[2]; + int i; + h[0] = &d->p1; + h[1] = &d->p2; + for (i = 0; i < 2; i++) + if (h[i]->cls == XOMBE_CLASS_SILENCE && !h[i]->repeat) { + d->mute = *h[i]; + d->mute_src = d->frame; + } + d->played = d->p2; +} + +int xombe__dec_half_begin(xombe_dec *d, int second_half, int n) +{ + if ((second_half != 0) != d->second_half_next) + return -1; + d->second_half_next = !second_half; + return n < XOMBE_HALF_MIN ? XOMBE_HALF_MIN : n > XOMBE_HALF_MAX ? XOMBE_HALF_MAX : n; +} + +/* the codec's start_bits of a frame through the decoder's FEC */ +static void start_frame(xombe_dec *d, const uint8_t in[9], unsigned flags) +{ + uint8_t bits[7]; + xombe_fec_stats st; + memset(bits, 0, sizeof(bits)); + if (flags & XOMBE_FLAG_LOST) { + d->ops->start_bits(d, bits, XOMBE_FLAG_LOST); + return; + } + flags = xombe_fec_decode(&d->fec, in, bits, &st); + d->err_t = st.eps_t; + d->err_1 = st.eps1; + d->ops->start_bits(d, bits, flags); + d->c.decision.e0 = st.eps0; + d->c.decision.e1 = st.eps1; +} + +int xombe_dec_half_bits(xombe_dec *d, const uint8_t bits[7], unsigned flags, int second_half, int n, int16_t *pcm) +{ + int N = xombe__dec_half_begin(d, second_half, n); + if (N < 0) + return -1; + second_half = second_half != 0; + if (!second_half) + d->ops->start_bits(d, bits, flags); + xombe__dec_synth(d, second_half, N, pcm); + return N; +} + +int xombe_dec_half(xombe_dec *d, const uint8_t in[9], unsigned flags, int second_half, int n, int16_t *pcm) +{ + int N = xombe__dec_half_begin(d, second_half, n); + if (N < 0) + return -1; + second_half = second_half != 0; + if (!second_half) + start_frame(d, in, flags); + xombe__dec_synth(d, second_half, N, pcm); + return N; +} + +int xombe_dec_frame_bits(xombe_dec *d, const uint8_t bits[XOMBE_BITS_BYTES], unsigned flags, int16_t pcm[160]) +{ + int fresh = xombe_dec_half_bits(d, bits, flags, 0, 80, pcm) >= 0; + if (!fresh) + memset(pcm, 0, 80 * sizeof(*pcm)); + xombe_dec_half_bits(d, bits, flags, 1, 80, pcm + 80); + return fresh; +} + +int xombe_dec_frame(xombe_dec *d, const uint8_t in[XOMBE_FRAME_BYTES], unsigned flags, int16_t pcm[160]) +{ + int fresh = xombe_dec_half(d, in, flags, 0, 80, pcm) >= 0; + if (!fresh) + memset(pcm, 0, 80 * sizeof(*pcm)); + xombe_dec_half(d, in, flags, 1, 80, pcm + 80); + return fresh; +} + +void xombe__dec_start_air(xombe_dec_core *d, xombe_fec *fec, const uint8_t air[9], unsigned flags, uint8_t bits[7]) +{ + xombe_fec_stats st; + memset(bits, 0, 7); + if (flags & XOMBE_FLAG_LOST) { + xombe__dec_start_frame(d, bits, XOMBE_FLAG_LOST); + return; + } + flags = xombe_fec_decode(fec, air, bits, &st); + d->eps_t = st.eps_t; + d->eps_1 = st.eps1; + xombe__dec_start_frame(d, bits, flags); + d->decision.e0 = st.eps0; + d->decision.e1 = st.eps1; +} diff --git a/xombe/src/dec/dkern_float.c b/xombe/src/dec/dkern_float.c new file mode 100644 index 0000000..3cf9aaf --- /dev/null +++ b/xombe/src/dec/dkern_float.c @@ -0,0 +1,133 @@ +#include +#include +#include "dkernels.h" +#include "../tables/dsp_tables.h" + +#define GRAIN_RAMP XOMBE_GRAIN_RAMP +#define WT_SIZE XOMBE_WT_SIZE +#define UV_FFT XOMBE_UV_FFT +#define UV_BINS XOMBE_UV_BINS + +XOMBE_STATIC_ASSERT(WT_SIZE <= XOMBE_IRFFT_MAX, wavetable_fits_irfft); +XOMBE_STATIC_ASSERT(XOMBE_TW_N % WT_SIZE == 0, twiddles_cover_wavetable); +XOMBE_STATIC_ASSERT(UV_FFT <= XOMBE_IRFFT_MAX, uv_fft_fits_irfft); +XOMBE_STATIC_ASSERT(XOMBE_TW_N % UV_FFT == 0, twiddles_cover_uv_fft); +XOMBE_STATIC_ASSERT(XOMBE_LMAX <= XOMBE_HALF_MAX, sqrt_table_covers_L); + +void xombe__dk_wavetable(const xombe_set *s, const float *M, const uint8_t *vh, float tab[XOMBE_WT_SIZE]) +{ + xombe_cpx spec[WT_SIZE / 2 + 1]; + int l; + memset(spec, 0, sizeof(spec)); + for (l = 1; l <= s->L && l <= XOMBE_LMAX; l++) { + float psi; + if (!vh[l] || M[l] == 0.0f) + continue; + psi = s->phi[l] - 2.0f * XOMBE_PI_F * l * XOMBE_EPOCH_REF * s->f0; + spec[l].re = WT_SIZE * M[l] * cosf(psi); + spec[l].im = WT_SIZE * M[l] * sinf(psi); + } + xombe__irfft(spec, tab, WT_SIZE, xombe__fft_tw, XOMBE_TW_N); +} + +/* 0.5*(1 - cos(pi*(j + frac)/GRAIN_RAMP)) for integer j, cf and sf the cos and sin of pi*frac/GRAIN_RAMP */ +static float ramp(int j, float cf, float sf) +{ + return 0.5f * (1.0f - (xombe__ramp_cos[j] * cf - xombe__ramp_sin[j] * sf)); +} + +void xombe__dk_add_grain(float *buf, int N, float P, float fhat, float period, const float *tab) +{ + float E = P + period; + int nb = (int)ceilf(P), ne = (int)floorf(E), n0 = nb, n1 = ne + GRAIN_RAMP, n; + /* fade-in over n - P = (n - nb) + (nb - P), fade-out over E + GRAIN_RAMP - n = (GRAIN_RAMP + ne - n) + (E - ne): + integer table steps rotated by a fraction fixed for the grain */ + float ai = XOMBE_PI_F * ((float)nb - P) / GRAIN_RAMP, ao = XOMBE_PI_F * (E - (float)ne) / GRAIN_RAMP; + float cs = cosf(ai), ss = sinf(ai), ce = cosf(ao), se = sinf(ao); + if (n0 < 0) + n0 = 0; + if (n1 > N + XOMBE_TAIL - 1) + n1 = N + XOMBE_TAIL - 1; + for (n = n0; n <= n1; n++) { + float th = (n - P) * fhat, x, fr, w; + int i; + th -= floorf(th); + x = th * WT_SIZE; + i = (int)x; + fr = x - i; + if (n < P + GRAIN_RAMP) + w = ramp(n - nb, cs, ss); + else if (n <= E) + w = 1.0f; + else + w = ramp(GRAIN_RAMP + ne - n, ce, se); + buf[n] += w * (tab[i & (WT_SIZE - 1)] * (1.0f - fr) + tab[(i + 1) & (WT_SIZE - 1)] * fr); + } +} + +/* sqrt(n/N), crossfade gain n samples into a half-frame of N, rs = 1/sqrt(N) */ +static float fade(int n, float rs) +{ + return xombe__sqrt_n[n] * rs; +} + +static int round_half_up(float x) +{ + return (int)floorf(x + 0.5f); +} + +void xombe__dk_unvoiced(const int16_t *seg, int N, const xombe_set *cur, const float *M, const uint8_t *vh, + float avg_f0, float y[XOMBE_UV_FFT]) +{ + float buf[UV_FFT]; + xombe_cpx X[UV_BINS], Y[UV_BINS]; + float beta = UV_FFT * cur->f0, rs = xombe__rsqrt_half[N - XOMBE_HALF_MIN], sqrt_L = xombe__sqrt_n[cur->L]; + int n, k, l, upper = 0, low; + int silence = cur->cls == XOMBE_CLASS_SILENCE; + memset(buf, 0, sizeof(buf)); + for (n = 0; n < 2 * N; n++) { + float w = n < N ? fade(n, rs) : fade(2 * N - n, rs); + buf[n] = w * (float)seg[n]; + } + xombe__rfft(buf, X, UV_FFT, xombe__fft_tw, XOMBE_TW_N); + memset(Y, 0, sizeof(Y)); + for (l = 1; l <= cur->L; l++) { + int lo = round_half_up((l - 0.5f) * beta), hi = round_half_up((l + 0.5f) * beta); + if (lo > UV_BINS - 1) + lo = UV_BINS - 1; + if (hi > UV_BINS - 1) + hi = UV_BINS - 1; + if (l == cur->L) + upper = hi; + if (hi <= lo) + continue; + if (silence) { + float g = XOMBE_CN_GAIN * sqrt_L * M[l]; + for (k = lo; k < hi; k++) { + Y[k].re = X[k].re * g; + Y[k].im = X[k].im * g; + } + } else if (!vh[l]) { + float e = 0.0f; + float g; + for (k = lo; k < hi; k++) + e += X[k].re * X[k].re + X[k].im * X[k].im; + e /= (hi - lo); + if (e <= 0.0f) + continue; + g = XOMBE_UV_GAIN * (sqrt_L * xombe__sqrt_n[N]) * M[l] / sqrtf(e); + for (k = lo; k < hi; k++) { + Y[k].re = X[k].re * g; + Y[k].im = X[k].im * g; + } + } + } + if (upper > XOMBE_UV_TOP_BIN) + upper = XOMBE_UV_TOP_BIN; + for (k = upper; k < UV_BINS; k++) + Y[k].re = Y[k].im = 0.0f; + low = (int)(UV_FFT * avg_f0); + for (k = 0; k < low && k < UV_BINS; k++) + Y[k].re = Y[k].im = 0.0f; + xombe__irfft(Y, y, UV_FFT, xombe__fft_tw, XOMBE_TW_N); +} diff --git a/xombe/src/dec/dkern_q15.c b/xombe/src/dec/dkern_q15.c new file mode 100644 index 0000000..23b0ad0 --- /dev/null +++ b/xombe/src/dec/dkern_q15.c @@ -0,0 +1,342 @@ +/* q15 decoder kernels (dkernels.h, XOMBE_KERNELS=q15): unvoiced transforms through the block-floating-point Q15 + FFT. the wavetable keeps the float one, Q15's ~65 dB on its sparse spectra moves PCM by up to 10 LSB */ +#include +#include +#include +#include "dkernels.h" +#include "../tables/dsp_tables.h" +#include "../dsp/fft_q15.h" +#include "../dsp/fmath.h" + +#define GRAIN_RAMP XOMBE_GRAIN_RAMP +#define WT_SIZE XOMBE_WT_SIZE +#define UV_FFT XOMBE_UV_FFT +#define UV_BINS XOMBE_UV_BINS +#define QM (UV_FFT / 2) /* complex points of the unvoiced transforms */ +#define QM_LOG2 7 +#define TW_STEP (XOMBE_TW_N / UV_FFT) /* xombe__fft_tw[k*TW_STEP] = exp(-2 pi i k/UV_FFT) */ + +XOMBE_STATIC_ASSERT(WT_SIZE <= XOMBE_IRFFT_MAX, wavetable_fits_irfft); +XOMBE_STATIC_ASSERT(XOMBE_TW_N % WT_SIZE == 0, twiddles_cover_wavetable); +XOMBE_STATIC_ASSERT(1 << QM_LOG2 == QM, qm_log2); +XOMBE_STATIC_ASSERT(XOMBE_TW_N % UV_FFT == 0, twiddles_cover_uv_fft); +XOMBE_STATIC_ASSERT(2 * XOMBE_HALF_MAX <= UV_FFT, segment_fits_uv_fft); +XOMBE_STATIC_ASSERT(XOMBE_LMAX <= XOMBE_HALF_MAX, sqrt_table_covers_L); + +/* exp(-2 pi i j/QM) for j < QM/2, Q15 rounded and held below 1, as int16 pairs (re, im) */ +static const uint32_t tw_q15[QM / 2] = { + 0x00007fffu, 0xf9b87fd9u, 0xf3747f62u, 0xed387e9du, 0xe7077d8au, 0xe0e67c2au, + 0xdad87a7du, 0xd4e17885u, 0xcf047642u, 0xc94673b6u, 0xc3a970e3u, 0xbe326dcau, + 0xb8e36a6eu, 0xb3c066d0u, 0xaecc62f2u, 0xaa0a5ed7u, 0xa57e5a82u, 0xa12955f6u, + 0x9d0e5134u, 0x99304c40u, 0x9592471du, 0x923641ceu, 0x8f1d3c57u, 0x8c4a36bau, + 0x89be30fcu, 0x877b2b1fu, 0x85832528u, 0x83d61f1au, 0x827618f9u, 0x816312c8u, + 0x809e0c8cu, 0x80270648u, 0x80000000u, 0x8027f9b8u, 0x809ef374u, 0x8163ed38u, + 0x8276e707u, 0x83d6e0e6u, 0x8583dad8u, 0x877bd4e1u, 0x89becf04u, 0x8c4ac946u, + 0x8f1dc3a9u, 0x9236be32u, 0x9592b8e3u, 0x9930b3c0u, 0x9d0eaeccu, 0xa129aa0au, + 0xa57ea57eu, 0xaa0aa129u, 0xaecc9d0eu, 0xb3c09930u, 0xb8e39592u, 0xbe329236u, + 0xc3a98f1du, 0xc9468c4au, 0xcf0489beu, 0xd4e1877bu, 0xdad88583u, 0xe0e683d6u, + 0xe7078276u, 0xed388163u, 0xf374809eu, 0xf9b88027u +}; + +/* nearest integer (ties to even), |v| < 2^22 */ +static int32_t round_q(float v) +{ + uint32_t u; + v += 12582912.0f; + memcpy(&u, &v, sizeof(u)); + return (int32_t)(u & 0x7fffffu) - 0x400000; +} + +static uint32_t pack(int32_t lo, int32_t hi) +{ + return ((uint32_t)lo & 0xffffu) | (uint32_t)hi << 16; +} + +static float block_gain(float m) +{ + float g = m > 0.0f ? (float)XOMBE_CFFT_Q15_PEAK / m : 0.0f; + return g <= FLT_MAX ? g : 0.0f; +} + +static uint32_t rev(int k) +{ + return q15_rbit((uint32_t)k) >> (32 - QM_LOG2); +} + +/* xombe__irfft for UV_FFT points: float pre-twiddle, then the inverse complex transform as the forward one on + swapped halves (swap(FFT(swap(z))) is the unscaled inverse) */ +static void irfft_q15(const xombe_cpx *in, float *out) +{ + xombe_cpx z[QM]; + uint32_t x[QM]; + float m = 0.0f, g, sc; + int k, s; + /* points k and QM - k from the same two bins, w[QM - k] = -conj(w[k]) */ + for (k = 0; k <= QM / 2; k++) { + xombe_cpx a = in[k], b = in[QM - k], w = xombe__fft_tw[k * TW_STEP]; + float er = 0.5f * (a.re + b.re), ei = 0.5f * (a.im - b.im), dr = 0.5f * (a.re - b.re), di = 0.5f * (a.im + b.im); + float pr = dr * w.re + di * w.im, pi = di * w.re - dr * w.im; + z[k].re = er - pi; + z[k].im = ei + pr; + m = fmaxf(m, fmaxf(fabsf(z[k].re), fabsf(z[k].im))); + if (k == 0 || k == QM / 2) + continue; + /* bins swapped: er, -ei, -dr, and di against -conj(w), the same pr */ + pi = dr * w.im - di * w.re; + z[QM - k].re = er - pi; + z[QM - k].im = pr - ei; + m = fmaxf(m, fmaxf(fabsf(z[QM - k].re), fabsf(z[QM - k].im))); + } + g = block_gain(m); + if (g == 0.0f) { + memset(out, 0, sizeof(float) * UV_FFT); + return; + } + for (k = 0; k < QM; k++) + x[rev(k)] = pack(round_q(z[k].im * g), round_q(z[k].re * g)); + s = xombe__cfft_q15(x, QM, tw_q15, XOMBE_CFFT_Q15_PEAK); + sc = (float)(1 << s) / (g * (float)QM); + for (k = 0; k < QM; k++) { + out[2 * k] = (float)q15_hi(x[k]) * sc; + out[2 * k + 1] = (float)q15_lo(x[k]) * sc; + } +} + +/* xombe__rfft of UV_FFT samples q[] times 1/g (q block-scaled to XOMBE_CFFT_Q15_PEAK), bins 0..QM */ +static void rfft_q15(const int16_t *q, float g, xombe_cpx *X) +{ + uint32_t x[QM]; + float h; + int k, s; + for (k = 0; k < QM; k++) + x[rev(k)] = q15_ld2(q + 2 * k); + s = xombe__cfft_q15(x, QM, tw_q15, XOMBE_CFFT_Q15_PEAK); + h = 0.5f * (float)(1 << s) / g; + for (k = 0; k <= QM / 2; k++) { + uint32_t a = x[k], b = x[(QM - k) & (QM - 1)]; + float er = (float)(q15_lo(a) + q15_lo(b)), ei = (float)(q15_hi(a) - q15_hi(b)); + float orr = (float)(q15_hi(a) + q15_hi(b)), oi = (float)(q15_lo(b) - q15_lo(a)), pr, pi; + xombe_cpx w; + if (k < QM / 2) { + w = xombe__fft_tw[k * TW_STEP]; + } else { + w.re = 0.0f; + w.im = -1.0f; + } + pr = w.re * orr - w.im * oi; + pi = w.re * oi + w.im * orr; + X[k].re = h * (er + pr); + X[k].im = h * (ei + pi); + X[QM - k].re = h * (er - pr); + X[QM - k].im = h * (pi - ei); + } +} + +/* float wavetable transform: z of QM points (bit-reversed order) transformed in place, forward, radix-2^2 passes + as in fft_q15.h, twiddles exp(-2 pi i j/QM) = xombe__fft_tw[j*2*TW_STEP] */ +static void cfft_wt(xombe_cpx *x) +{ + const int ts = 2 * TW_STEP; + int len, i, j; + for (i = 0; i < QM; i += 4) { + xombe_cpx x0 = x[i], x1 = x[i + 1], x2 = x[i + 2], x3 = x[i + 3]; + float ar = x0.re + x1.re, ai = x0.im + x1.im, br = x0.re - x1.re, bi = x0.im - x1.im; + float cr = x2.re + x3.re, ci = x2.im + x3.im, dr = x2.re - x3.re, di = x2.im - x3.im; + x[i].re = ar + cr; + x[i].im = ai + ci; + x[i + 2].re = ar - cr; + x[i + 2].im = ai - ci; + x[i + 1].re = br + di; /* b + (-i)*d */ + x[i + 1].im = bi - dr; + x[i + 3].re = br - di; + x[i + 3].im = bi + dr; + } + for (len = 8; 2 * len <= QM; len <<= 2) { + int q = len >> 1, sa = ts * (QM / len), sb = sa >> 1; + for (i = 0; i < QM; i += 2 * len) { + xombe_cpx *p = x + i; + for (j = 0; j < q; j++) { + xombe_cpx wa = xombe__fft_tw[j * sa], wb = xombe__fft_tw[j * sb]; + xombe_cpx u0 = p[j], u1 = p[j + q], u2 = p[j + 2 * q], u3 = p[j + 3 * q]; + float t1r = u1.re * wa.re - u1.im * wa.im, t1i = u1.re * wa.im + u1.im * wa.re; + float t3r = u3.re * wa.re - u3.im * wa.im, t3i = u3.re * wa.im + u3.im * wa.re; + float y0r = u0.re + t1r, y0i = u0.im + t1i, y1r = u0.re - t1r, y1i = u0.im - t1i; + float y2r = u2.re + t3r, y2i = u2.im + t3i, y3r = u2.re - t3r, y3i = u2.im - t3i; + float t2r = y2r * wb.re - y2i * wb.im, t2i = y2r * wb.im + y2i * wb.re; + float t4r = y3r * wb.re - y3i * wb.im, t4i = y3r * wb.im + y3i * wb.re; + p[j].re = y0r + t2r; + p[j].im = y0i + t2i; + p[j + 2 * q].re = y0r - t2r; + p[j + 2 * q].im = y0i - t2i; + p[j + q].re = y1r + t4i; /* y1 + (-i)*t4 */ + p[j + q].im = y1i - t4r; + p[j + 3 * q].re = y1r - t4i; + p[j + 3 * q].im = y1i + t4r; + } + } + } + if (len <= QM) { + int q = QM >> 1; + for (j = 0; j < q; j++) { + xombe_cpx w = xombe__fft_tw[j * ts], a = x[j], b = x[j + q]; + float tr = b.re * w.re - b.im * w.im, ti = b.re * w.im + b.im * w.re; + x[j].re = a.re + tr; + x[j].im = a.im + ti; + x[j + q].re = a.re - tr; + x[j + q].im = a.im - ti; + } + } +} + +XOMBE_STATIC_ASSERT(WT_SIZE == UV_FFT && XOMBE_LMAX < QM / 2, wavetable_bins_below_mirror); + +/* xombe__irfft of a wavetable spectrum, bins above XOMBE_LMAX zero: pre-twiddle into swapped halves, the forward + transform above, scaled by 1/QM */ +static void irfft_wt(const xombe_cpx *in, float *out) +{ + xombe_cpx z[QM]; + int k; + memset(z, 0, sizeof(z)); + for (k = 1; k <= XOMBE_LMAX; k++) { + xombe_cpx a = in[k], w = xombe__fft_tw[k * TW_STEP]; + /* in[QM - k] = 0, so z[k] and z[QM - k] both come from in[k] alone, w[QM - k] = -conj(w) */ + float er = 0.5f * a.re, ei = 0.5f * a.im; + float pr = er * w.re + ei * w.im, pi = ei * w.re - er * w.im; + z[rev(k)].re = ei + pr; /* swapped (im, re) */ + z[rev(k)].im = er - pi; + pi = er * w.im - ei * w.re; + z[rev(QM - k)].re = pr - ei; + z[rev(QM - k)].im = er - pi; + } + cfft_wt(z); + for (k = 0; k < QM; k++) { + out[2 * k] = z[k].im * (1.0f / QM); + out[2 * k + 1] = z[k].re * (1.0f / QM); + } +} + +void xombe__dk_wavetable(const xombe_set *s, const float *M, const uint8_t *vh, float tab[XOMBE_WT_SIZE]) +{ + xombe_cpx spec[WT_SIZE / 2 + 1]; + int l; + memset(spec, 0, sizeof(spec)); + for (l = 1; l <= s->L && l <= XOMBE_LMAX; l++) { + float psi, cp, sp; + if (!vh[l] || M[l] == 0.0f) + continue; + psi = s->phi[l] - 2.0f * XOMBE_PI_F * l * XOMBE_EPOCH_REF * s->f0; + xombe__sincosf(psi, &sp, &cp); + spec[l].re = WT_SIZE * M[l] * cp; + spec[l].im = WT_SIZE * M[l] * sp; + } + irfft_wt(spec, tab); +} + +static float ramp(int j, float cf, float sf) +{ + return 0.5f * (1.0f - (xombe__ramp_cos[j] * cf - xombe__ramp_sin[j] * sf)); +} + +/* tab at phase ph (cycles in 2^-32 units), linear between entries */ +static float tab_at(const float *tab, uint32_t ph) +{ + int i = (int)(ph >> 24); + float t0 = tab[i], t1 = tab[(i + 1) & (WT_SIZE - 1)]; + return t0 + (float)(ph & 0xffffffu) * (1.0f / 16777216.0f) * (t1 - t0); +} + +XOMBE_STATIC_ASSERT(WT_SIZE == 256, wavetable_index_is_top_byte); + +/* phase (n - P)*fhat as a 32-bit fraction accumulated from n0, fade-in, flat, and fade-out runs split ahead */ +void xombe__dk_add_grain(float *buf, int N, float P, float fhat, float period, const float *tab) +{ + float E = P + period, th; + int nb = (int)ceilf(P), ne = (int)floorf(E), n0 = nb, n1 = ne + GRAIN_RAMP, nin = (int)ceilf(P + GRAIN_RAMP), n; + float ai = XOMBE_PI_F * ((float)nb - P) / GRAIN_RAMP, ao = XOMBE_PI_F * (E - (float)ne) / GRAIN_RAMP; + float cs, ss, ce, se; + uint32_t ph, inc = (uint32_t)(fhat * 4294967296.0f); /* fhat < 1/16 */ + xombe__sincosf(ai, &ss, &cs); + xombe__sincosf(ao, &se, &ce); + if (n0 < 0) + n0 = 0; + if (n1 > N + XOMBE_TAIL - 1) + n1 = N + XOMBE_TAIL - 1; + th = ((float)n0 - P) * fhat; + th -= floorf(th); + ph = ((uint32_t)(th * 16777216.0f) & 0xffffffu) << 8; + for (n = n0; n <= n1 && n < nin; n++, ph += inc) + buf[n] += ramp(n - nb, cs, ss) * tab_at(tab, ph); + for (; n <= n1 && n <= ne; n++, ph += inc) + buf[n] += tab_at(tab, ph); + for (; n <= n1; n++, ph += inc) + buf[n] += ramp(GRAIN_RAMP + ne - n, ce, se) * tab_at(tab, ph); +} + +/* noise samples to the FFT's input peak, the fades are at most 1 */ +#define NOISE_Q ((float)XOMBE_CFFT_Q15_PEAK / 32768.0f) + +static float fade(int n, float rs) +{ + return xombe__sqrt_n[n] * rs; +} + +static int round_half_up(float x) +{ + return (int)floorf(x + 0.5f); +} + +void xombe__dk_unvoiced(const int16_t *seg, int N, const xombe_set *cur, const float *M, const uint8_t *vh, + float avg_f0, float y[XOMBE_UV_FFT]) +{ + int16_t q[UV_FFT]; + xombe_cpx X[UV_BINS], Y[UV_BINS]; + float beta = UV_FFT * cur->f0, rs = xombe__rsqrt_half[N - XOMBE_HALF_MIN], sqrt_L = xombe__sqrt_n[cur->L]; + int n, k, l, upper = 0, low; + int silence = cur->cls == XOMBE_CLASS_SILENCE; + memset(q, 0, sizeof(q)); + for (n = 0; n < N; n++) + q[n] = (int16_t)round_q((float)seg[n] * (fade(n, rs) * NOISE_Q)); + for (; n < 2 * N; n++) + q[n] = (int16_t)round_q((float)seg[n] * (fade(2 * N - n, rs) * NOISE_Q)); + rfft_q15(q, NOISE_Q, X); + memset(Y, 0, sizeof(Y)); + for (l = 1; l <= cur->L; l++) { + int lo = round_half_up((l - 0.5f) * beta), hi = round_half_up((l + 0.5f) * beta); + if (lo > UV_BINS - 1) + lo = UV_BINS - 1; + if (hi > UV_BINS - 1) + hi = UV_BINS - 1; + if (l == cur->L) + upper = hi; + if (hi <= lo) + continue; + if (silence) { + float g = XOMBE_CN_GAIN * sqrt_L * M[l]; + for (k = lo; k < hi; k++) { + Y[k].re = X[k].re * g; + Y[k].im = X[k].im * g; + } + } else if (!vh[l]) { + float e = 0.0f; + float g; + for (k = lo; k < hi; k++) + e += X[k].re * X[k].re + X[k].im * X[k].im; + e /= (hi - lo); + if (e <= 0.0f) + continue; + g = XOMBE_UV_GAIN * (sqrt_L * xombe__sqrt_n[N]) * M[l] / sqrtf(e); + for (k = lo; k < hi; k++) { + Y[k].re = X[k].re * g; + Y[k].im = X[k].im * g; + } + } + } + if (upper > XOMBE_UV_TOP_BIN) + upper = XOMBE_UV_TOP_BIN; + for (k = upper; k < UV_BINS; k++) + Y[k].re = Y[k].im = 0.0f; + low = (int)(UV_FFT * avg_f0); + for (k = 0; k < low && k < UV_BINS; k++) + Y[k].re = Y[k].im = 0.0f; + irfft_q15(Y, y); +} diff --git a/xombe/src/dec/dkernels.h b/xombe/src/dec/dkernels.h new file mode 100644 index 0000000..e551d1e --- /dev/null +++ b/xombe/src/dec/dkernels.h @@ -0,0 +1,29 @@ +#ifndef XOMBE_DKERNELS_H +#define XOMBE_DKERNELS_H + +/* decoder inner loops, dkern_float.c or dkern_q15.c (XOMBE_KERNELS=q15) */ + +#include "../internal.h" + +#define XOMBE_EPOCH_REF 16 /* sample of a grain the wavetable's phases refer to */ + +#define XOMBE_UV_FFT 256 +#define XOMBE_UV_BINS (XOMBE_UV_FFT / 2 + 1) +/* sqrt(12)/2^16 takes uniform 16-bit noise to unit variance. unvoiced bands are normalized by their energy, so only + the comfort-noise gain carries this scale */ +#define XOMBE_UV_NOISE_SCALE (3.4641016151377544f / 65536.0f) +#define XOMBE_UV_GAIN 1.449f +#define XOMBE_CN_GAIN (1.147f * XOMBE_UV_NOISE_SCALE) +#define XOMBE_UV_TOP_BIN 121 + +/* one period of set s's voiced harmonics (vh[l], amplitudes M[l]) in XOMBE_WT_SIZE samples */ +void xombe__dk_wavetable(const xombe_set *s, const float *M, const uint8_t *vh, float tab[XOMBE_WT_SIZE]); +/* adds one pitch period (period = 1/fhat samples) of tab starting at P to buf[0..N + XOMBE_TAIL), faded in over + the first XOMBE_GRAIN_RAMP samples and out over XOMBE_GRAIN_RAMP samples after its end */ +void xombe__dk_add_grain(float *buf, int N, float P, float fhat, float period, const float *tab); +/* y[0..2N): noise seg[0..2N) under sqrt(n/N) fades in and out, its spectrum shaped to set cur's unvoiced bands + (every band for silence) with gains M[l], cleared below avg_f0 and above band L and XOMBE_UV_TOP_BIN */ +void xombe__dk_unvoiced(const int16_t *seg, int N, const xombe_set *cur, const float *M, const uint8_t *vh, + float avg_f0, float y[XOMBE_UV_FFT]); + +#endif diff --git a/xombe/src/dec/enhance.c b/xombe/src/dec/enhance.c new file mode 100644 index 0000000..9b7f593 --- /dev/null +++ b/xombe/src/dec/enhance.c @@ -0,0 +1,137 @@ +#include +#include "../internal.h" +#include "../dsp/fmath.h" + +#define PHASE_TAIL_SLOPE 0.7212f +#define PHASE_MIRROR 64 + +static float phase_seq(const float *a, int L, int n) +{ + if (n < 0) + n = -n; + if (n > PHASE_MIRROR) + n = 2 * PHASE_MIRROR - n; + if (n == 0) + return 0.0f; + if (n <= L) + return a[n]; + return a[L] - PHASE_TAIL_SLOPE * (float)(n - L); +} + +#define PHASE_TAPS 19 /* odd m = 1..PHASE_TAPS */ + +/* d/m, a reciprocal multiply in q15 builds */ +static float tap(float d, int m) +{ +#if XOMBE_KERNELS_Q15 + static const float inv_m[PHASE_TAPS + 1] = {0.0f, 1.0f, 0.0f, 1.0f / 3, 0.0f, 1.0f / 5, 0.0f, 1.0f / 7, 0.0f, + 1.0f / 9, 0.0f, 1.0f / 11, 0.0f, 1.0f / 13, 0.0f, 1.0f / 15, 0.0f, + 1.0f / 17, 0.0f, 1.0f / 19}; + return d * inv_m[m]; +#else + return d / (float)m; +#endif +} + +void xombe__phases(const float *a, int L, float *phi) +{ + const float k = (float)(2.0 * 0.69314718055994531 / XOMBE_PI); /* 2 ln 2 / pi */ + float t[XOMBE_LMAX + PHASE_TAPS + 1]; /* phase_seq at 0..L + PHASE_TAPS */ + int l, m; + for (l = 0; l <= L + PHASE_TAPS; l++) + t[l] = phase_seq(a, L, l); + phi[0] = 0.0f; + for (l = 1; l <= XOMBE_LMAX; l++) { + float s = 0.0f; + if (l <= L) + for (m = 1; m <= PHASE_TAPS; m += 2) + s += tap(t[l + m] - t[l >= m ? l - m : m - l], m); + phi[l] = k * s; + } +} + +#define ENH_GAIN (0.96f * XOMBE_PI_F) +#define ENH_LOG2_W_MIN (-1.0f) /* log2 0.5 */ +#define ENH_LOG2_W_MAX 0.263034406f /* log2 1.2 */ + +/* c[l], s[l] = cos, sin of w0*l for l = 1..L, by rotation in q15 builds (error about l ulp) */ +static void harmonic_cs(float w0, int L, float *c, float *s) +{ + int l; +#if XOMBE_KERNELS_Q15 + float c1, s1; + xombe__sincosf(w0, &s1, &c1); + c[1] = c1; + s[1] = s1; + for (l = 2; l <= L; l++) { + c[l] = c[l - 1] * c1 - s[l - 1] * s1; + s[l] = s[l - 1] * c1 + c[l - 1] * s1; + } +#else + for (l = 1; l <= L; l++) + xombe__sincosf(w0 * (float)l, &s[l], &c[l]); +#endif +} + +/* spectral enhancement in the log domain: e = a + log2 W + log2 gamma + W = sqrt(M)*(num/den)^(1/4) above harmonic L/8 (else 1), clamped to 0.5..1.2, + num/den = 0.96 pi (r0^2 + r1^2 - 2 r0 r1 cos(w0 l))/(w0 r0 (r0^2 - r1^2)), r0, r1 the power and first + autocorrelation of M = 2^a, gamma restores the power r0 + powers are relative to the strongest harmonic so every sum is scale-free: with p = 2^(2(a - amax)) and + rho = r1/r0, num/den = 0.96 pi ((1 - rho cos)^2 + (rho sin)^2)/(w0 r0 (1 - rho)(1 + rho)) * 2^(-2 amax) */ +void xombe__enhance(const float *a, int L, float f0, float *e) +{ + float w0 = 2.0f * XOMBE_PI_F * f0, amax = a[1], r0 = 0.0f, r1 = 0.0f, sum = 0.0f, rho, lg; + float lw[XOMBE_LMAX + 1], c[XOMBE_LMAX + 1], s[XOMBE_LMAX + 1]; + int l; + for (l = 2; l <= L; l++) + if (a[l] > amax) + amax = a[l]; + harmonic_cs(w0, L, c, s); + for (l = 1; l <= L; l++) { + float p = xombe__exp2f(2.0f * (a[l] - amax)); + r0 += p; + r1 += p * c[l]; + } + rho = r1 / r0; /* r0 >= 1, the strongest harmonic contributes 1 */ + for (l = 1; l <= L; l++) { + float w = 0.0f; + if (8 * l > L) { + float u = 1.0f - rho * c[l], v = rho * s[l]; + float den = w0 * r0 * ((1.0f - rho) * (1.0f + rho)); + if (den > 0.0f) { + w = 0.5f * (a[l] - amax) + 0.25f * xombe__log2f(ENH_GAIN * (u * u + v * v) / den); + if (w < ENH_LOG2_W_MIN) + w = ENH_LOG2_W_MIN; + if (w > ENH_LOG2_W_MAX) + w = ENH_LOG2_W_MAX; + } + } + lw[l] = w; + sum += xombe__exp2f(2.0f * (w + a[l] - amax)); + } + lg = 0.5f * (xombe__log2f(r0) - xombe__log2f(sum)); /* sum >= 1/4 from the strongest harmonic, W >= 1/2 */ + for (l = 1; l <= L; l++) + e[l] = a[l] + lw[l] + lg; +} + +#define SHAPE_LOW_MAX XOMBE_HZ(200.0f) /* low roll-off corner: the average pitch, at most this */ + +/* xombe__hf_tilt through fmath.h, must match it */ +static float hf_tilt(float f) +{ + return f > XOMBE_HF_CORNER ? xombe__log2f(f / XOMBE_HF_CORNER) : 0.0f; +} + +void xombe__shape(const float *e, float *M, int L, float f0, float avg_f0) +{ + float fc = avg_f0 < SHAPE_LOW_MAX ? avg_f0 : SHAPE_LOW_MAX; + int l; + for (l = 1; l <= L; l++) { + float f = (float)l * f0, g = e[l]; + if (f < fc) + g += 2.0f * xombe__log2f(f / fc); + g += hf_tilt(f); + M[l] = xombe__exp2f(g); + } +} diff --git a/xombe/src/dec/smooth.c b/xombe/src/dec/smooth.c new file mode 100644 index 0000000..0527b90 --- /dev/null +++ b/xombe/src/dec/smooth.c @@ -0,0 +1,38 @@ +#include +#include "../internal.h" + +#define LAMBDA_FAST 0.98f +#define SMOOTH_GAP 2.0f +#define SMOOTH_MARGIN 5.5f + +void xombe__smooth(xombe_dec_core *d, float *a, int L, float f0) +{ + float sum = 0.0f, r, tau; + int l; + for (l = 1; l <= L; l++) + sum += a[l] * a[l]; + r = sqrtf(sum / (float)L); + if (r > d->lambda - 1.0f) + d->lambda = LAMBDA_FAST * d->lambda + (1.0f - LAMBDA_FAST) * r; + else + d->lambda -= d->rules->lambda_decay; + if (d->eps_t > 3 || d->eps_1 > 1) { + float ratio = f0 / d->pi.f0; + tau = d->lambda + SMOOTH_MARGIN - 0.5f * (float)d->eps_1; + for (l = 1; l <= L; l++) { + float x = (float)l * ratio; + int i = (int)x; + float ps = xombe__harmonic_lerp(d->pi.a, i, x - (float)i); + float g = 6.0f * (float)l * f0; + float e; + if (g > 2.0f) + g = 2.0f; + e = a[l] - (tau - g); + if (a[l] - ps > SMOOTH_GAP && e > 0.0f) + a[l] += (ps - a[l]) * (e < 0.5f ? e : 0.5f); + a[l] = xombe__clamp_amp(a[l]); + } + } + for (l = L + 1; l <= XOMBE_LMAX; l++) + a[l] = a[L]; +} diff --git a/xombe/src/dec/synth_tone.c b/xombe/src/dec/synth_tone.c new file mode 100644 index 0000000..7ffb764 --- /dev/null +++ b/xombe/src/dec/synth_tone.c @@ -0,0 +1,21 @@ +#include +#include "../internal.h" + +void xombe__tone_set(xombe_set *s, int id, int ad) +{ + float f0_hz, amp = xombe__tone_log2_amp(ad); + int l, l1, l2, top; + memset(s, 0, sizeof(*s)); + for (l = 0; l <= XOMBE_LMAX; l++) + s->e[l] = XOMBE_AMP_OFF; + xombe__tone_harmonics(id, &f0_hz, &l1, &l2); + s->cls = XOMBE_CLASS_TONE; + s->prepared = 1; + s->f0 = XOMBE_HZ(f0_hz); + top = l2 > l1 ? l2 : l1; + s->L = top > 9 ? top : 9; + if (l1 > 0) + s->e[l1] = amp; + if (l2 > 0) + s->e[l2] = amp; +} diff --git a/xombe/src/dec/synth_unvoiced.c b/xombe/src/dec/synth_unvoiced.c new file mode 100644 index 0000000..4b12f47 --- /dev/null +++ b/xombe/src/dec/synth_unvoiced.c @@ -0,0 +1,67 @@ +#include +#include "dkernels.h" +#include "../tables/dsp_tables.h" + +static int16_t noise_draw(xombe_dec *d) +{ + if (d->noise_mode == XOMBE_NOISE_PRODUCTION) { + uint32_t x = d->prng; + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + d->prng = x; + return (int16_t)((int)(x >> 16) - 32768); + } + return xombe__lcg_draw(&d->lcg); +} + +void xombe__noise_init(xombe_dec *d) +{ + int i; + d->lcg = 0; + for (i = 0; i < XOMBE_TAIL; i++) + d->noise_hist[i] = noise_draw(d); + memset(d->uv_overlap, 0, sizeof(d->uv_overlap)); +} + +static void noise_reset(xombe_dec *d) +{ + memset(d->noise_hist, 0, sizeof(d->noise_hist)); +} + +static void noise_segment(xombe_dec *d, int N, int16_t *seg) +{ + int16_t buf[XOMBE_TAIL + XOMBE_HALF_MAX]; + int i; + memcpy(buf, d->noise_hist, sizeof(d->noise_hist)); + for (i = 0; i < N; i++) + buf[XOMBE_TAIL + i] = noise_draw(d); + memcpy(seg, buf, sizeof(buf[0]) * 2 * N); + memcpy(d->noise_hist, buf + N, sizeof(d->noise_hist)); +} + +static float fade(int n, float rs) +{ + return xombe__sqrt_n[n] * rs; +} + +void xombe__synth_unvoiced(xombe_dec *d, const xombe_set *cur, const float *M, const uint8_t *vh, int N, + float *out) +{ + int16_t seg[2 * XOMBE_HALF_MAX]; + float y[XOMBE_UV_FFT], rs = xombe__rsqrt_half[N - XOMBE_HALF_MIN]; + int n; + if (cur->cls == XOMBE_CLASS_TONE) { + noise_reset(d); + for (n = 0; n < N; n++) + out[n] += d->uv_overlap[n] * fade(N - n, rs); + memset(d->uv_overlap, 0, sizeof(d->uv_overlap)); + return; + } + noise_segment(d, N, seg); + xombe__dk_unvoiced(seg, N, cur, M, vh, d->c.avg_f0, y); + for (n = 0; n < N; n++) + out[n] += d->uv_overlap[n] * fade(N - n, rs) + y[n] * fade(n, rs); + memset(d->uv_overlap, 0, sizeof(d->uv_overlap)); + memcpy(d->uv_overlap, y + N, sizeof(float) * N); +} diff --git a/xombe/src/dec/synth_voiced.c b/xombe/src/dec/synth_voiced.c new file mode 100644 index 0000000..2ac20cf --- /dev/null +++ b/xombe/src/dec/synth_voiced.c @@ -0,0 +1,122 @@ +#include +#include "dkernels.h" + +#define WT_SIZE XOMBE_WT_SIZE +/* epochs per half-frame: tracks stay below 0.0625 cycles/sample (500 Hz), so at most 6 in 84 samples */ +#define EPOCH_MAX 8 +/* octave jumps below OCTAVE_MAX, the epoch track follows the octave instead of jumping + doubled: previous f0 between OCTAVE_UP_LO and OCTAVE_UP_HI of the current + halved: current f0 between OCTAVE_DOWN_LO and OCTAVE_DOWN_HI of the previous */ +#define OCTAVE_UP_LO 0.4f +#define OCTAVE_UP_HI 0.6f +#define OCTAVE_DOWN_LO 0.41667f +#define OCTAVE_DOWN_HI 0.625f +#define OCTAVE_MAX XOMBE_HZ(250.0f) + +/* epochs of a pitch track over a half-frame of N samples: phase (in periods) starts at th0, frequency ramps + linearly from fs to fs + delta, so the phase at n is th0 + n*(fs + n*delta/(2N)), the running sum of the + midpoint frequencies fs + (n + 1/2)*delta/N, evaluated in closed form so float rounding does not accumulate + each integer the phase reaches is an epoch. within its sample the phase is th + u*inc + h*u*(u - 1), inc the + sample's increment, h = delta/(2N), the epoch placed by linear interpolation u = (k - th)/inc, then one + Newton step on the curvature term. returns the epoch count (floor of the phase at N), that phase in *th_end */ +static int epoch_track(float th0, float fs, float delta, int N, float t[EPOCH_MAX], float *th_end) +{ + float h = 0.5f * delta / (float)N, th = th0; + int n, k = 1, count = 0; + for (n = 0; n < N; n++) { + float m = (float)(n + 1), next = th0 + m * (fs + h * m), inc = next - th; + while ((float)k <= next && count < EPOCH_MAX) { + float u = ((float)k - th) / inc; + u -= h * u * (u - 1.0f) / (inc + h * (2.0f * u - 1.0f)); + t[count++] = (float)n + u; + k++; + } + th = next; + } + *th_end = th; + return count; +} + +void xombe__synth_voiced(xombe_dec *d, const xombe_set *cur, const float *M, const uint8_t *vh, int cur_voiced, + int N, float *out) +{ + float wcur[WT_SIZE], old[XOMBE_HALF_MAX + XOMBE_TAIL], fresh[XOMBE_HALF_MAX + XOMBE_TAIL]; + int pv = d->prev_voiced, cv = cur_voiced, any = pv || cv; + float fp = d->prev_f0, fc = cur->f0, fs = 0.0f, fe = 0.0f; + float pc = d->pitch_phase, ec_start = d->epoch, ec = d->epoch; + float delta, phi = pc, phi_new = 0.0f, inv_N = 1.0f / (float)N, t_old[EPOCH_MAX], t_new[EPOCH_MAX]; + float per_p = 1.0f / fp, per_c = 1.0f / fc; + int up = 0, down = 0, K = 0, K_new = 0, k, n; + + if (pv && cv) { + fs = fp; + if (OCTAVE_UP_LO * fc < fp && fp < OCTAVE_UP_HI * fc && fp < OCTAVE_MAX) { + up = 1; + fe = fc / 2.0f; + } else if (OCTAVE_DOWN_LO * fp < fc && fc < OCTAVE_DOWN_HI * fp && fc < OCTAVE_MAX) { + down = 1; + fe = 2.0f * fc; + } else { + fe = fc; + } + } else if (pv) { + fs = fe = fp; + } else if (cv) { + fs = fe = fc; + } + delta = fe - fs; + if (any) + K = epoch_track(pc, fs, delta, N, t_old, &phi); + + memset(old, 0, sizeof(old)); + memcpy(old, d->tail, sizeof(d->tail)); + if (pv) + for (k = 0; k < K; k++) + xombe__dk_add_grain(old, N, t_old[k], fp, per_p, d->wprev); + for (n = 0; n < N; n++) + out[n] += (1.0f - (float)n * inv_N) * old[n]; + + memset(fresh, 0, sizeof(fresh)); + if (cv) { + float pp = pc, dp = delta, fsp = fs; + xombe__dk_wavetable(cur, M, vh, wcur); + /* across an octave jump the new track runs at twice (up) or half (down) the old one's rate */ + if (up) { + pp = 2.0f * pc; + if (pp >= 1.0f) { + pp -= 1.0f; + ec = -(pp / 2.0f) * per_p; + } + dp = 2.0f * delta; + fsp = 2.0f * fs; + } else if (down) { + pp = pc / 2.0f; + dp = delta / 2.0f; + fsp = fs / 2.0f; + } + K_new = epoch_track(pp, fsp, dp, N, t_new, &phi_new); + xombe__dk_add_grain(fresh, N, ec, fc, per_c, wcur); + for (k = 0; k < K_new; k++) + xombe__dk_add_grain(fresh, N, t_new[k], fc, per_c, wcur); + } + for (n = 0; n < N; n++) + out[n] += ((float)n * inv_N) * fresh[n]; + memcpy(d->tail, fresh + N, sizeof(d->tail)); + + if (!any) { + d->pitch_phase = 0.0f; + d->epoch = 0.0f; + } else { + d->pitch_phase = cv ? phi_new - K_new : phi - K; + if (cv && K_new > 0) + d->epoch = t_new[K_new - 1] - N; + else if (pv && K > 0) + d->epoch = t_old[K - 1] - N; + else + d->epoch = ec_start - N; + } + if (cv) + memcpy(d->wprev, wcur, sizeof(wcur)); + d->prev_f0 = cur->f0; + d->prev_voiced = cv; +} diff --git a/xombe/src/dsp/biquad.c b/xombe/src/dsp/biquad.c new file mode 100644 index 0000000..244e1c3 --- /dev/null +++ b/xombe/src/dsp/biquad.c @@ -0,0 +1,20 @@ +#include "../internal.h" +#include "biquad.h" + +void xombe__hpf_init(xombe_hpf *f, float gain) +{ + f->x1 = f->s1 = f->s2 = f->y1 = f->y2 = 0.0f; + f->gain = gain; +} + +float xombe__hpf_step(xombe_hpf *f, float x) +{ + float s = x - f->x1 + (float)HPF_POLE1 * f->s1; + float y = s - 2.0f * f->s1 + f->s2 + (float)HPF_A1 * f->y1 - (float)HPF_A2 * f->y2; + f->x1 = x; + f->s2 = f->s1; + f->s1 = s; + f->y2 = f->y1; + f->y1 = y; + return y * f->gain; +} diff --git a/xombe/src/dsp/biquad.h b/xombe/src/dsp/biquad.h new file mode 100644 index 0000000..7bc55d6 --- /dev/null +++ b/xombe/src/dsp/biquad.h @@ -0,0 +1,10 @@ +#ifndef XOMBE_BIQUAD_H +#define XOMBE_BIQUAD_H + +/* high-pass: first-order section (pole HPF_POLE1) and second-order (1 - HPF_A1 z^-1 + HPF_A2 z^-2), + three zeros at DC */ +#define HPF_POLE1 0.9428 +#define HPF_A1 1.9394 +#define HPF_A2 0.9428 + +#endif diff --git a/xombe/src/dsp/fft.c b/xombe/src/dsp/fft.c new file mode 100644 index 0000000..2e55181 --- /dev/null +++ b/xombe/src/dsp/fft.c @@ -0,0 +1,95 @@ +#include "../internal.h" + +static void cfft(xombe_cpx *x, int m, const xombe_cpx *tw, int stride, int inverse) +{ + int i, j, len; + for (i = 1, j = 0; i < m; i++) { + int bit = m >> 1; + for (; j & bit; bit >>= 1) + j ^= bit; + j |= bit; + if (i < j) { + xombe_cpx t = x[i]; + x[i] = x[j]; + x[j] = t; + } + } + for (len = 2; len <= m; len <<= 1) { + int half = len >> 1, step = stride * (m / len); + for (i = 0; i < m; i += len) { + for (j = 0; j < half; j++) { + xombe_cpx w = tw[j * step]; + xombe_cpx a = x[i + j], b = x[i + j + half], t; + if (inverse) + w.im = -w.im; + t.re = b.re * w.re - b.im * w.im; + t.im = b.re * w.im + b.im * w.re; + x[i + j].re = a.re + t.re; + x[i + j].im = a.im + t.im; + x[i + j + half].re = a.re - t.re; + x[i + j + half].im = a.im - t.im; + } + } + } +} + +void xombe__rfft(const float *in, xombe_cpx *out, int n, const xombe_cpx *tw, int tw_n_real) +{ + int k; + for (k = 0; k < n / 2; k++) { + out[k].re = in[2 * k]; + out[k].im = in[2 * k + 1]; + } + xombe__rfft_packed(out, n, tw, tw_n_real); +} + +void xombe__rfft_packed(xombe_cpx *out, int n, const xombe_cpx *tw, int tw_n_real) +{ + int m = n / 2, k, s = tw_n_real / n; + cfft(out, m, tw, 2 * s, 0); + out[m] = out[0]; + for (k = 0; k <= m / 2; k++) { + xombe_cpx z1 = out[k], z2 = out[m - k], e, o, w, r1, r2; + e.re = 0.5f * (z1.re + z2.re); + e.im = 0.5f * (z1.im - z2.im); + o.re = 0.5f * (z1.im + z2.im); + o.im = -0.5f * (z1.re - z2.re); + if (k < m / 2 || k == 0) { + w = tw[k * s]; + } else { + w.re = 0.0f; + w.im = -1.0f; + } + r1.re = e.re + w.re * o.re - w.im * o.im; + r1.im = e.im + w.re * o.im + w.im * o.re; + r2.re = e.re - w.re * o.re + w.im * o.im; + r2.im = -(e.im - (w.re * o.im + w.im * o.re)); + out[k] = r1; + out[m - k] = r2; + } +} + +void xombe__irfft(const xombe_cpx *in, float *out, int n, const xombe_cpx *tw, int tw_n_real) +{ + xombe_cpx z[XOMBE_IRFFT_MAX / 2]; + int m = n / 2, k, s = tw_n_real / n; + float scale = 1.0f / (float)m; + for (k = 0; k < m; k++) { + xombe_cpx a = in[k], b = in[m - k], fe, fo, d, w; + fe.re = 0.5f * (a.re + b.re); + fe.im = 0.5f * (a.im - b.im); + d.re = 0.5f * (a.re - b.re); + d.im = 0.5f * (a.im + b.im); + w = tw[k * s]; + w.im = -w.im; + fo.re = d.re * w.re - d.im * w.im; + fo.im = d.re * w.im + d.im * w.re; + z[k].re = fe.re - fo.im; + z[k].im = fe.im + fo.re; + } + cfft(z, m, tw, 2 * s, 1); + for (k = 0; k < m; k++) { + out[2 * k] = z[k].re * scale; + out[2 * k + 1] = z[k].im * scale; + } +} diff --git a/xombe/src/dsp/fft_q15.h b/xombe/src/dsp/fft_q15.h new file mode 100644 index 0000000..fed96d1 --- /dev/null +++ b/xombe/src/dsp/fft_q15.h @@ -0,0 +1,186 @@ +#ifndef XOMBE_FFT_Q15_H +#define XOMBE_FFT_Q15_H + +/* block-floating-point complex FFT on packed Q15 pairs (q15ops.h: re low, im high), decimation in time in + radix-2^2 passes: stages 2 and 4 with twiddles 1 and -i, then stage pairs (len, 2*len), then a radix-2 stage + when log2 m is odd + a bound b on the magnitudes decides halving: a stage halves (SHADD16/SHSUB16 and the exchanged forms) only + when unhalved outputs (QADD16/QSUB16) could pass 32767. b doubles through an unhalved stage, holds through a + halved one, and is tightened after each pass from the largest output component, read off the OR of + v ^ (v << 1). twiddle products are rounded in Q30 by SMLSD/SMLADX */ + +#include "q15ops.h" + +/* largest bound a stage passes unhalved, its outputs reach 2b + 2 with the twiddle's rounding */ +#define XOMBE_CFFT_Q15_FREE 16382 +/* largest input peak, sqrt 2 * peak <= XOMBE_CFFT_Q15_FREE so the first stage runs unhalved */ +#define XOMBE_CFFT_Q15_PEAK 11583 + +/* ceil(sqrt 2 * v) for 0 <= v < 2^16 */ +static inline int32_t xombe__q15_sqrt2_up(int32_t v) +{ + return (int32_t)(((uint32_t)v * 46341u + 32767u) >> 15); +} + +#if defined(__GNUC__) +#define XOMBE_Q15_INLINE static inline __attribute__((always_inline)) +#else +#define XOMBE_Q15_INLINE static inline +#endif + +/* b*w, rounded */ +XOMBE_Q15_INLINE uint32_t xombe__q15_cmul(uint32_t b, uint32_t w) +{ + return q15_pack_lsl1((uint32_t)(q15_smlsd(b, w, 0x4000) >> 15), (uint32_t)q15_smladx(b, w, 0x4000)); +} + +/* a + b, a - b, a + (-i)*b, and a - (-i)*b, halved when h */ +XOMBE_Q15_INLINE uint32_t xombe__q15_add(uint32_t a, uint32_t b, int h) +{ + return h ? q15_shadd16(a, b) : q15_qadd16(a, b); +} + +XOMBE_Q15_INLINE uint32_t xombe__q15_sub(uint32_t a, uint32_t b, int h) +{ + return h ? q15_shsub16(a, b) : q15_qsub16(a, b); +} + +XOMBE_Q15_INLINE uint32_t xombe__q15_addni(uint32_t a, uint32_t b, int h) +{ + return h ? q15_shsax(a, b) : q15_qsax(a, b); +} + +XOMBE_Q15_INLINE uint32_t xombe__q15_subni(uint32_t a, uint32_t b, int h) +{ + return h ? q15_shasx(a, b) : q15_qasx(a, b); +} + +/* detector bits of v: bit q of each half set where bits q and q - 1 differ */ +XOMBE_Q15_INLINE uint32_t xombe__q15_det(uint32_t v) +{ + return v ^ (v << 1); +} + +/* stages 2 and 4 (twiddles 1 and -i) on each group of four points, halved per h1 and h2 */ +XOMBE_Q15_INLINE uint32_t xombe__cfft_q15_first(uint32_t *x, int m, int h1, int h2) +{ + uint32_t det = 0; + int i; + for (i = 0; i < m; i += 4) { + uint32_t x0 = x[i], x1 = x[i + 1], x2 = x[i + 2], x3 = x[i + 3], y0, y1, y2, y3, z0, z1, z2, z3; + y0 = xombe__q15_add(x0, x1, h1); + y1 = xombe__q15_sub(x0, x1, h1); + y2 = xombe__q15_add(x2, x3, h1); + y3 = xombe__q15_sub(x2, x3, h1); + x[i] = z0 = xombe__q15_add(y0, y2, h2); + x[i + 1] = z1 = xombe__q15_addni(y1, y3, h2); + x[i + 2] = z2 = xombe__q15_sub(y0, y2, h2); + x[i + 3] = z3 = xombe__q15_subni(y1, y3, h2); + det |= xombe__q15_det(z0) | xombe__q15_det(z1) | xombe__q15_det(z2) | xombe__q15_det(z3); + } + return det; +} + +/* stages len and 2*len as one radix-2^2 pass, halved per h1 and h2: in each block of 2*len, points j, j + q, + j + 2q, and j + 3q for j < q = len/2, the second stage's odd twiddle the first's times -i */ +XOMBE_Q15_INLINE uint32_t xombe__cfft_q15_r22(uint32_t *x, int m, int len, const uint32_t *tw, int h1, int h2) +{ + uint32_t det = 0; + int q = len >> 1, sa = m / len, sb = sa >> 1, i, j; + for (i = 0; i < m; i += 2 * len) { + uint32_t *p = x + i; + for (j = 0; j < q; j++) { + uint32_t wa = tw[j * sa], wb = tw[j * sb], y0, y1, y2, y3, z0, z1, z2, z3, t; + t = xombe__q15_cmul(p[j + q], wa); + y0 = xombe__q15_add(p[j], t, h1); + y1 = xombe__q15_sub(p[j], t, h1); + t = xombe__q15_cmul(p[j + 3 * q], wa); + y2 = xombe__q15_add(p[j + 2 * q], t, h1); + y3 = xombe__q15_sub(p[j + 2 * q], t, h1); + t = xombe__q15_cmul(y2, wb); + p[j] = z0 = xombe__q15_add(y0, t, h2); + p[j + 2 * q] = z2 = xombe__q15_sub(y0, t, h2); + t = xombe__q15_cmul(y3, wb); + p[j + q] = z1 = xombe__q15_addni(y1, t, h2); + p[j + 3 * q] = z3 = xombe__q15_subni(y1, t, h2); + det |= xombe__q15_det(z0) | xombe__q15_det(z1) | xombe__q15_det(z2) | xombe__q15_det(z3); + } + } + return det; +} + +/* last stage (len = m) alone */ +XOMBE_Q15_INLINE uint32_t xombe__cfft_q15_r2(uint32_t *x, int m, const uint32_t *tw, int h) +{ + uint32_t det = 0; + int q = m >> 1, j; + for (j = 0; j < q; j++) { + uint32_t t = xombe__q15_cmul(x[j + q], tw[j]), a = x[j], u, v; + x[j] = u = xombe__q15_add(a, t, h); + x[j + q] = v = xombe__q15_sub(a, t, h); + det |= xombe__q15_det(u) | xombe__q15_det(v); + } + return det; +} + +/* whether the next stage halves, updating bound b and halving count s */ +static inline int xombe__cfft_q15_halve(int32_t *b, int *s) +{ + if (*b > XOMBE_CFFT_Q15_FREE) { + *b += 1; + ++*s; + return 1; + } + *b = 2 * *b + 2; + return 0; +} + +/* tightens b from a pass's detector bits: every component has |v| <= 2^q for the top bit q (bit 0 of each half + may hold the other half's sign) */ +static inline void xombe__cfft_q15_tighten(int32_t *b, uint32_t det) +{ + uint32_t d = (det | det >> 16) & 0xfffeu; + int32_t bq = xombe__q15_sqrt2_up((int32_t)1 << (d ? 31 - q15_clz32(d) : 0)); + if (*b > bq) + *b = bq; +} + +/* transforms m points x (m a power of two >= 4, bit-reversed order) in place into natural order, twiddles + tw[j] = exp(-2 pi i j/m) for j < m/2 in Q15. no input component may exceed peak, sqrt 2 * peak <= + XOMBE_CFFT_Q15_FREE. returns the halving count s, x holds the transform times 2^-s + each pass decides its stages' halvings from the bound alone and is checked once at its end */ +static int xombe__cfft_q15(uint32_t *x, int m, const uint32_t *tw, int32_t peak) +{ + int32_t b = xombe__q15_sqrt2_up(peak); + int len, s = 0, h1, h2; + uint32_t det; + h1 = xombe__cfft_q15_halve(&b, &s); + h2 = xombe__cfft_q15_halve(&b, &s); + switch (h1 << 1 | h2) { + case 0: det = xombe__cfft_q15_first(x, m, 0, 0); break; + case 1: det = xombe__cfft_q15_first(x, m, 0, 1); break; + case 2: det = xombe__cfft_q15_first(x, m, 1, 0); break; + default: det = xombe__cfft_q15_first(x, m, 1, 1); break; + } + xombe__cfft_q15_tighten(&b, det); + for (len = 8; 2 * len <= m; len <<= 2) { + h1 = xombe__cfft_q15_halve(&b, &s); + h2 = xombe__cfft_q15_halve(&b, &s); + switch (h1 << 1 | h2) { + case 0: det = xombe__cfft_q15_r22(x, m, len, tw, 0, 0); break; + case 1: det = xombe__cfft_q15_r22(x, m, len, tw, 0, 1); break; + case 2: det = xombe__cfft_q15_r22(x, m, len, tw, 1, 0); break; + default: det = xombe__cfft_q15_r22(x, m, len, tw, 1, 1); break; + } + xombe__cfft_q15_tighten(&b, det); + } + if (len <= m) { + if (xombe__cfft_q15_halve(&b, &s)) + xombe__cfft_q15_r2(x, m, tw, 1); + else + xombe__cfft_q15_r2(x, m, tw, 0); + } + return s; +} + +#endif diff --git a/xombe/src/dsp/fmath.h b/xombe/src/dsp/fmath.h new file mode 100644 index 0000000..e9443fc --- /dev/null +++ b/xombe/src/dsp/fmath.h @@ -0,0 +1,139 @@ +#ifndef XOMBE_FMATH_H +#define XOMBE_FMATH_H + +/* exp2, log2, and sincos for the inner loops: libm in float builds, which keep it as the reference, polynomials + within a few ulp of libm in q15 builds (XOMBE_KERNELS=q15) */ + +#include +#include +#include +#include "xombe_config.h" + +#if XOMBE_KERNELS_Q15 + +/* round to nearest for |x| < 2^22: x + 1.5*2^23 holds the integer in its fraction field, offset by 2^22 */ +#define XOMBE_FMATH_RND 12582912.0f + +static inline float xombe__fmath_from_bits(uint32_t u) +{ + float f; + memcpy(&f, &u, sizeof(f)); + return f; +} + +static inline int32_t xombe__fmath_rnd_int(float t) +{ + uint32_t u; + memcpy(&u, &t, sizeof(u)); + return (int32_t)(u & 0x7fffffu) - 0x400000; +} + +/* x = k + f, |f| <= 1/2, 2^f by the Cephes exp2f polynomial, 2^k in the exponent field. libm outside + (-126, 128), where the result may be subnormal, infinite, or NaN */ +static inline float xombe__exp2f(float x) +{ + float t, f, p; + int32_t k; + if (!(x > -126.0f && x < 128.0f)) + return exp2f(x); + t = x + XOMBE_FMATH_RND; + k = xombe__fmath_rnd_int(t); + f = x - (t - XOMBE_FMATH_RND); + p = 1.535336188319500e-4f; + p = p * f + 1.339887440266574e-3f; + p = p * f + 9.618437357674640e-3f; + p = p * f + 5.550332471162809e-2f; + p = p * f + 2.402264791363012e-1f; + p = p * f + 6.931472028550421e-1f; + p = p * f + 1.0f; + if (k > 127) /* x >= 127.5, 2^128 is not a float */ + return p * xombe__fmath_from_bits((uint32_t)(127 + 127) << 23) * 2.0f; + return p * xombe__fmath_from_bits((uint32_t)(k + 127) << 23); +} + +/* x = 2^e * (1 + m), 1 + m in [sqrt(1/2), sqrt 2), ln(1 + m) by the Cephes logf polynomial, times log2(e) in two + parts (1 and log2(e) - 1) so m and e enter unrounded. libm for zero, subnormals, negatives, infinity, and NaN */ +static inline float xombe__log2f(float x) +{ + uint32_t u; + int32_t e; + float m, z, y, p; + if (!(x >= 1.17549435e-38f && x <= 3.40282347e38f)) + return log2f(x); + memcpy(&u, &x, sizeof(u)); + e = (int32_t)(u >> 23) - 127; + u = (u & 0x7fffffu) | 0x3f800000u; + if (u > 0x3fb504f3u) { /* above sqrt 2 */ + u -= 0x00800000u; + e++; + } + m = xombe__fmath_from_bits(u) - 1.0f; + z = m * m; + p = 7.0376836292e-2f; + p = p * m - 1.1514610310e-1f; + p = p * m + 1.1676998740e-1f; + p = p * m - 1.2420140846e-1f; + p = p * m + 1.4249322787e-1f; + p = p * m - 1.6668057665e-1f; + p = p * m + 2.0000714765e-1f; + p = p * m - 2.4999993993e-1f; + p = p * m + 3.3333331174e-1f; + y = m * z * p - 0.5f * z; + return y * 0.44269504088896341f + m * 0.44269504088896341f + y + m + (float)e; +} + +/* x = q*pi/2 + r, |r| <= pi/4, with pi/2 in three parts (Cody-Waite), the first two short enough that q*part is + exact for |q| < 2^11, then the Cephes sinf and cosf polynomials. libm for |x| >= 2^11 */ +static inline void xombe__sincosf(float x, float *s, float *c) +{ + float t, r, z, sp, cp; + int32_t q; + if (!(fabsf(x) < 2048.0f)) { + *s = sinf(x); + *c = cosf(x); + return; + } + t = x * 0.636619772f + XOMBE_FMATH_RND; + q = xombe__fmath_rnd_int(t); + t -= XOMBE_FMATH_RND; + r = x - t * 1.5703125f; + r -= t * 4.837512969970703125e-4f; + r -= t * 7.54978995489188216e-8f; + z = r * r; + sp = -1.9515295891e-4f; + sp = sp * z + 8.3321608736e-3f; + sp = sp * z - 1.6666654611e-1f; + sp = r + r * z * sp; + cp = 2.443315711809948e-5f; + cp = cp * z - 1.388731625493765e-3f; + cp = cp * z + 4.166664568298827e-2f; + cp = 1.0f - 0.5f * z + z * z * cp; + switch (q & 3) { + case 0: *s = sp; *c = cp; break; + case 1: *s = cp; *c = -sp; break; + case 2: *s = -sp; *c = -cp; break; + default: *s = -cp; *c = sp; break; + } +} + +#else + +static inline float xombe__exp2f(float x) +{ + return exp2f(x); +} + +static inline float xombe__log2f(float x) +{ + return log2f(x); +} + +static inline void xombe__sincosf(float x, float *s, float *c) +{ + *s = sinf(x); + *c = cosf(x); +} + +#endif + +#endif diff --git a/xombe/src/dsp/lcg.c b/xombe/src/dsp/lcg.c new file mode 100644 index 0000000..bd7ddb5 --- /dev/null +++ b/xombe/src/dsp/lcg.c @@ -0,0 +1,12 @@ +#include "../internal.h" + +uint16_t xombe__lcg_next(uint16_t u) +{ + return (uint16_t)((173u * u + 13849u) & 0xFFFFu); +} + +int16_t xombe__lcg_draw(uint16_t *u) +{ + *u = xombe__lcg_next(*u); + return (int16_t)(*u >= 32768 ? (int)*u - 65536 : (int)*u); +} diff --git a/xombe/src/dsp/q15ops.h b/xombe/src/dsp/q15ops.h new file mode 100644 index 0000000..4e6c0f3 --- /dev/null +++ b/xombe/src/dsp/q15ops.h @@ -0,0 +1,297 @@ +#ifndef XOMBE_Q15OPS_H +#define XOMBE_Q15OPS_H + +/* fixed-point kernel DSP operations on packed int16 pairs (low half first) with ACLE semantics: Arm DSP + extension instructions where the target has them (__ARM_FEATURE_DSP), the same arithmetic in C elsewhere + a pair is a uint32_t of the two halves' bits, 32-bit results wrap modulo 2^32 as the instructions do (they + only set the Q flag) */ + +#include +#include + +static inline int32_t q15_lo(uint32_t a) +{ + return (int16_t)(uint16_t)(a & 0xffffu); +} + +static inline int32_t q15_hi(uint32_t a) +{ + return (int16_t)(uint16_t)(a >> 16); +} + +#if defined(__ARM_FEATURE_DSP) +#include + +/* lo(a)*lo(b) + hi(a)*hi(b) */ +static inline int32_t q15_smuad(uint32_t a, uint32_t b) +{ + return __smuad((int16x2_t)a, (int16x2_t)b); +} + +/* acc + lo(a)*lo(b) + hi(a)*hi(b) */ +static inline int32_t q15_smlad(uint32_t a, uint32_t b, int32_t acc) +{ + return __smlad((int16x2_t)a, (int16x2_t)b, acc); +} + +/* acc + lo(a)*lo(b) + hi(a)*hi(b) in 64 bits */ +static inline int64_t q15_smlald(uint32_t a, uint32_t b, int64_t acc) +{ + return __smlald((int16x2_t)a, (int16x2_t)b, acc); +} + +/* pair (lo(a), lo(b << 2)), PKHBT with a shifted top operand */ +static inline uint32_t q15_pack_lsl2(uint32_t a, uint32_t b) +{ + uint32_t r; + __asm__("pkhbt %0, %1, %2, lsl #2" : "=r"(r) : "r"(a), "r"(b)); + return r; +} + +/* x != 0 */ +static inline int q15_clz32(uint32_t x) +{ + return (int)__clz(x); +} + +/* lo(a)*lo(b) - hi(a)*hi(b) + acc */ +static inline int32_t q15_smlsd(uint32_t a, uint32_t b, int32_t acc) +{ + return __smlsd((int16x2_t)a, (int16x2_t)b, acc); +} + +/* lo(a)*hi(b) + hi(a)*lo(b) + acc */ +static inline int32_t q15_smladx(uint32_t a, uint32_t b, int32_t acc) +{ + return __smladx((int16x2_t)a, (int16x2_t)b, acc); +} + +/* halves' sums and differences, saturated (QADD16, QSUB16) or halved and rounded down (SHADD16, SHSUB16) */ +static inline uint32_t q15_qadd16(uint32_t a, uint32_t b) +{ + return (uint32_t)__qadd16((int16x2_t)a, (int16x2_t)b); +} + +static inline uint32_t q15_qsub16(uint32_t a, uint32_t b) +{ + return (uint32_t)__qsub16((int16x2_t)a, (int16x2_t)b); +} + +static inline uint32_t q15_shadd16(uint32_t a, uint32_t b) +{ + return (uint32_t)__shadd16((int16x2_t)a, (int16x2_t)b); +} + +static inline uint32_t q15_shsub16(uint32_t a, uint32_t b) +{ + return (uint32_t)__shsub16((int16x2_t)a, (int16x2_t)b); +} + +/* exchanged forms a + (-i)*b and a - (-i)*b for complex pairs (re, im): (lo(a) + hi(b), hi(a) - lo(b)) + (QSAX) and (lo(a) - hi(b), hi(a) + lo(b)) (QASX), saturated or halved */ +static inline uint32_t q15_qsax(uint32_t a, uint32_t b) +{ + return (uint32_t)__qsax((int16x2_t)a, (int16x2_t)b); +} + +static inline uint32_t q15_qasx(uint32_t a, uint32_t b) +{ + return (uint32_t)__qasx((int16x2_t)a, (int16x2_t)b); +} + +static inline uint32_t q15_shsax(uint32_t a, uint32_t b) +{ + return (uint32_t)__shsax((int16x2_t)a, (int16x2_t)b); +} + +static inline uint32_t q15_shasx(uint32_t a, uint32_t b) +{ + return (uint32_t)__shasx((int16x2_t)a, (int16x2_t)b); +} + +/* pair (lo(a), lo(b << 1)) */ +static inline uint32_t q15_pack_lsl1(uint32_t a, uint32_t b) +{ + uint32_t r; + __asm__("pkhbt %0, %1, %2, lsl #1" : "=r"(r) : "r"(a), "r"(b)); + return r; +} + +static inline uint32_t q15_rbit(uint32_t x) +{ + return __rbit(x); +} + +/* per-half unsigned max (USUB16 then SEL on its GE bits) */ +static inline uint32_t q15_umax16(uint32_t a, uint32_t b) +{ + uint32_t r; + __asm__("usub16 %0, %1, %2\n\tsel %0, %1, %2" : "=&r"(r) : "r"(a), "r"(b) : "cc"); + return r; +} + +/* a*b / 2^32 rounded to nearest, halves up */ +static inline int32_t q15_smmulr(int32_t a, int32_t b) +{ + int32_t r; + __asm__("smmulr %0, %1, %2" : "=r"(r) : "r"(a), "r"(b)); + return r; +} + +#else + +/* each product fits in int32, sums wrap in uint32 as the instructions do */ +static inline int32_t q15_smuad(uint32_t a, uint32_t b) +{ + return (int32_t)((uint32_t)(q15_lo(a) * q15_lo(b)) + (uint32_t)(q15_hi(a) * q15_hi(b))); +} + +static inline int32_t q15_smlad(uint32_t a, uint32_t b, int32_t acc) +{ + return (int32_t)((uint32_t)acc + (uint32_t)(q15_lo(a) * q15_lo(b)) + (uint32_t)(q15_hi(a) * q15_hi(b))); +} + +static inline int64_t q15_smlald(uint32_t a, uint32_t b, int64_t acc) +{ + return (int64_t)((uint64_t)acc + (uint64_t)(int64_t)(q15_lo(a) * q15_lo(b)) + + (uint64_t)(int64_t)(q15_hi(a) * q15_hi(b))); +} + +static inline uint32_t q15_pack_lsl2(uint32_t a, uint32_t b) +{ + return (a & 0xffffu) | ((b << 2) & 0xffff0000u); +} + +static inline int q15_clz32(uint32_t x) +{ + int n = 0; + if (!(x & 0xffff0000u)) { + n += 16; + x <<= 16; + } + if (!(x & 0xff000000u)) { + n += 8; + x <<= 8; + } + if (!(x & 0xf0000000u)) { + n += 4; + x <<= 4; + } + if (!(x & 0xc0000000u)) { + n += 2; + x <<= 2; + } + return x & 0x80000000u ? n : n + 1; +} + +static inline int32_t q15_smlsd(uint32_t a, uint32_t b, int32_t acc) +{ + return (int32_t)((uint32_t)acc + (uint32_t)(q15_lo(a) * q15_lo(b)) - (uint32_t)(q15_hi(a) * q15_hi(b))); +} + +static inline int32_t q15_smladx(uint32_t a, uint32_t b, int32_t acc) +{ + return (int32_t)((uint32_t)acc + (uint32_t)(q15_lo(a) * q15_hi(b)) + (uint32_t)(q15_hi(a) * q15_lo(b))); +} + +static inline uint32_t q15_pair(int32_t lo, int32_t hi) +{ + return ((uint32_t)lo & 0xffffu) | (uint32_t)hi << 16; +} + +static inline int32_t q15_sat(int32_t v) +{ + return v > 32767 ? 32767 : v < -32768 ? -32768 : v; +} + +/* right shift of a negative value is implementation-defined in C, these halve with a floor */ +static inline int32_t q15_half(int32_t v) +{ + return (v - (v & 1)) / 2; +} + +static inline uint32_t q15_qadd16(uint32_t a, uint32_t b) +{ + return q15_pair(q15_sat(q15_lo(a) + q15_lo(b)), q15_sat(q15_hi(a) + q15_hi(b))); +} + +static inline uint32_t q15_qsub16(uint32_t a, uint32_t b) +{ + return q15_pair(q15_sat(q15_lo(a) - q15_lo(b)), q15_sat(q15_hi(a) - q15_hi(b))); +} + +static inline uint32_t q15_shadd16(uint32_t a, uint32_t b) +{ + return q15_pair(q15_half(q15_lo(a) + q15_lo(b)), q15_half(q15_hi(a) + q15_hi(b))); +} + +static inline uint32_t q15_shsub16(uint32_t a, uint32_t b) +{ + return q15_pair(q15_half(q15_lo(a) - q15_lo(b)), q15_half(q15_hi(a) - q15_hi(b))); +} + +static inline uint32_t q15_qsax(uint32_t a, uint32_t b) +{ + return q15_pair(q15_sat(q15_lo(a) + q15_hi(b)), q15_sat(q15_hi(a) - q15_lo(b))); +} + +static inline uint32_t q15_qasx(uint32_t a, uint32_t b) +{ + return q15_pair(q15_sat(q15_lo(a) - q15_hi(b)), q15_sat(q15_hi(a) + q15_lo(b))); +} + +static inline uint32_t q15_shsax(uint32_t a, uint32_t b) +{ + return q15_pair(q15_half(q15_lo(a) + q15_hi(b)), q15_half(q15_hi(a) - q15_lo(b))); +} + +static inline uint32_t q15_shasx(uint32_t a, uint32_t b) +{ + return q15_pair(q15_half(q15_lo(a) - q15_hi(b)), q15_half(q15_hi(a) + q15_lo(b))); +} + +static inline uint32_t q15_pack_lsl1(uint32_t a, uint32_t b) +{ + return (a & 0xffffu) | ((b << 1) & 0xffff0000u); +} + +static inline uint32_t q15_rbit(uint32_t x) +{ + x = (x >> 1 & 0x55555555u) | (x & 0x55555555u) << 1; + x = (x >> 2 & 0x33333333u) | (x & 0x33333333u) << 2; + x = (x >> 4 & 0x0f0f0f0fu) | (x & 0x0f0f0f0fu) << 4; + x = (x >> 8 & 0x00ff00ffu) | (x & 0x00ff00ffu) << 8; + return x >> 16 | x << 16; +} + +static inline uint32_t q15_umax16(uint32_t a, uint32_t b) +{ + uint32_t l = (a & 0xffffu) > (b & 0xffffu) ? a & 0xffffu : b & 0xffffu; + return ((a >> 16) > (b >> 16) ? a & 0xffff0000u : b & 0xffff0000u) | l; +} + +static inline int32_t q15_smmulr(int32_t a, int32_t b) +{ + return (int32_t)(((int64_t)a * b + 0x80000000) >> 32); +} + +#endif + +/* 64 for x = 0 */ +static inline int q15_clz64(uint64_t x) +{ + uint32_t h = (uint32_t)(x >> 32), l = (uint32_t)x; + if (h) + return q15_clz32(h); + return l ? 32 + q15_clz32(l) : 64; +} + +/* p need only be 2-byte aligned */ +static inline uint32_t q15_ld2(const int16_t *p) +{ + uint32_t v; + memcpy(&v, p, 4); + return v; +} + +#endif diff --git a/xombe/src/dsp/window.c b/xombe/src/dsp/window.c new file mode 100644 index 0000000..0b26415 --- /dev/null +++ b/xombe/src/dsp/window.c @@ -0,0 +1,65 @@ +#include +#include "../internal.h" + +/* sin(pi*r/m) for m > 0, r reduced exactly to |r| <= m/2 first so the argument carries a single rounding + however large r is (the reduced |r| must be exact in float: m < 2^24) */ +float xombe__sin_ratio(long r, long m) +{ + r %= 2 * m; + if (r > m) + r -= 2 * m; + else if (r < -m) + r += 2 * m; + if (2 * r > m) + r = m - r; + else if (2 * r < -m) + r = -m - r; + return sinf(XOMBE_PI_F * ((float)r / (float)m)); +} + +/* cos(2 pi i/(n - 1)) as sin(pi (4i + n - 1)/(2(n - 1))) */ +void xombe__hamming(float *w, int n) +{ + int i; + for (i = 0; i < n; i++) + w[i] = 0.54f - 0.46f * xombe__sin_ratio(4L * i + (n - 1), 2L * (n - 1)); +} + +/* over i = 0..n-1 the cosine sums to 1 and its square to (n + 1)/2 (n > 3) */ +float xombe__hamming_sum2(int n) +{ + return 0.2916f * (float)n + 0.1058f * (float)(n + 1) - 0.4968f; +} + +/* sin(n*x)/sin(x) at x = pi*p/m, |p| < m */ +static float dirichlet(int n, long p, long m) +{ + return p == 0 ? (float)n : xombe__sin_ratio((long)n * p, m) / xombe__sin_ratio(p, m); +} + +/* xombe__sin_ratio(t, g) for g a power of two, without divisions */ +static float sin_ratio_pow2(long t, long g) +{ + t &= 2 * g - 1; + if (t > g) + t -= 2 * g; + if (2 * t > g) + t = g - t; + else if (2 * t < -g) + t = -g - t; + return sinf(XOMBE_PI_F * ((float)t * (1.0f / (float)g))); +} + +/* transform of the centred xombe__hamming(n) at q/g cycles/sample (0 <= q < g/2): Dirichlet kernels at + x = pi*q/g and x +/- pi/(n - 1), over the common denominator g*(n - 1) */ +float xombe__hamming_dtft(int n, long q, long g) +{ + long p = q * (n - 1), m = g * (n - 1); + /* for g a power of two the centre kernel's ratios reduce exactly to multiples of 1/g: sin_ratio(n*p, m) + reduces n*p to (n - 1) times n*q reduced mod 2g, and the float quotient r/m equals the exact product + t*(1/g) */ + if (q > 0 && (g & (g - 1)) == 0) + return 0.54f * (sin_ratio_pow2((long)n * q, g) / sin_ratio_pow2(q, g)) + + 0.23f * (dirichlet(n, p - g, m) + dirichlet(n, p + g, m)); + return 0.54f * dirichlet(n, p, m) + 0.23f * (dirichlet(n, p - g, m) + dirichlet(n, p + g, m)); +} diff --git a/xombe/src/dstar/decoder.c b/xombe/src/dstar/decoder.c new file mode 100644 index 0000000..9ac885e --- /dev/null +++ b/xombe/src/dstar/decoder.c @@ -0,0 +1,154 @@ +#include +#include "../internal.h" +#include "dsd_state.h" + +/* D-STAR decoder on the AMBE+2 set machinery and synthesis (dec/decoder.c), differing in frame logic here, + parameters (params.c), and ds_rules */ + +/* xombe__ds_harm_voicing leaves vh above L alone */ +static void harm_voicing(const uint8_t vb[8], float f0, int L, uint8_t vh[XOMBE_LMAX + 1]) +{ + memset(vh, 0, XOMBE_LMAX + 1); + xombe__ds_harm_voicing(vb, f0, L, vh); +} + +static const struct xombe_dec_rules ds_rules = {harm_voicing, XOMBE_DS_LAMBDA_DECAY}; + +void xombe__dsd_logic_init(xombe_dsd_logic *s, xombe_dec_core *d) +{ + memset(s, 0, sizeof(*s)); + d->rules = &ds_rules; +} + +static void voice(xombe_dec_core *d, const int b[9]) +{ + xombe_params p; + xombe_set c; + uint8_t v1[8]; + const uint8_t *v2 = xombe__ds_vuv[b[1] & 15]; + memset(&p, 0, sizeof(p)); + p.f0 = xombe__ds_f0(b[0]); + p.L = xombe__ds_L(b[0]); + xombe__ds_amps(b, p.L, d->pi.L, d->pi.a, d->pi.gamma, NULL, &p.gamma, p.a); + XOMBE_TAP(d, XOMBE_STAGE_DEQUANT, p.f0, p.a + 1, p.L); + xombe__f3_first_half(d->pi.v2, v2, v1); + xombe__smooth(d, p.a, p.L, p.f0); + XOMBE_TAP(d, XOMBE_STAGE_SMOOTH, p.f0, p.a + 1, p.L); + xombe__dec_set_from_params(&c, XOMBE_CLASS_VOICE, p.f0, p.L, p.a, v2); + xombe__dec_play(d, &c, v1, &p, v2); +} + +/* concealed and null frames: the second half is a fresh copy without the repeat flag, so a silence set there + plays as the mute set */ +static void play_pair(xombe_dec_core *d, const xombe_set *s) +{ + d->p1 = *s; + d->p1.repeat = 1; + d->p2 = *s; + d->p2.repeat = 0; +} + +static void conceal(xombe_dsd_logic *s, xombe_dec_core *d, int c) +{ + play_pair(d, c == XOMBE_CONCEAL_MUTE ? &d->mute : &d->played); + s->log = c == XOMBE_CONCEAL_MUTE ? XOMBE_DSD_LOG_MUTE : XOMBE_DSD_LOG_REPEAT; +} + +/* the rest of the frame's decision once c, what plays, is known */ +static void decided(xombe_dec_core *d, int c) +{ + d->decision.conceal = (enum xombe_conceal)c; + d->decision.run = d->run; + d->decision.mute_src = c == XOMBE_CONCEAL_MUTE ? d->mute_src : -1; + d->prev_concealed = c != XOMBE_CONCEAL_NONE; +} + +void xombe__dsd_start_frame(xombe_dsd_logic *s, xombe_dec_core *d, const xombe_ds_frame *f, unsigned flags, + int eps_t, int eps1) +{ + xombe_decision *dc = &d->decision; + xombe_ds_flags ef; + int c = XOMBE_CONCEAL_NONE; + d->frame++; + dc->e0 = dc->e1 = -1; + if (!f) { + dc->cls = XOMBE_CLASS_ERASURE; + dc->bf = dc->hb = 0; + s->eT = s->e1 = 0; + c = xombe__conceal_decide(d, 1, 0); + conceal(s, d, c); + decided(d, c); + return; + } + ef.bf = (flags & XOMBE_FLAG_BF) != 0; + ef.hb = (flags & XOMBE_FLAG_HB) != 0; + ef.eT = eps_t < 6 ? 0 : eps_t; + ef.e1 = eps_t < 6 ? 0 : eps1; + dc->bf = ef.bf; + dc->hb = ef.hb; + s->eT = d->eps_t = ef.eT; + s->e1 = d->eps_1 = ef.e1; + if (f->cls == XOMBE_DS_NULL) { + /* fixed silence set, the memory keeps its amplitudes but its class becomes silence, so the next voice + frame starts at half amplitude. bf and hb are ignored */ + xombe_set z; + dc->cls = XOMBE_CLASS_SILENCE; + xombe__conceal_decide(d, 0, 0); + xombe__dec_silence_set(&z); + play_pair(d, &z); + xombe__pred_store_other(&d->pi, XOMBE_CLASS_SILENCE); + s->log = XOMBE_DSD_LOG_NULL; + } else if (f->cls == XOMBE_DS_VOICE && ef.bf) { + /* bad voice frame updates the memory as if good (unless hb, then nothing changes) and plays a repeat of + the last played set, never a mute */ + xombe_set last = d->played; + dc->cls = XOMBE_CLASS_VOICE; + xombe__conceal_decide(d, 1, 0); /* counts as concealed */ + c = XOMBE_CONCEAL_REPEAT; + if (ef.hb) { + s->log = XOMBE_DSD_LOG_MUTE; + } else { + voice(d, f->b); + s->log = XOMBE_DSD_LOG_VOICE; + } + play_pair(d, &last); + } else if (f->cls == XOMBE_DS_VOICE) { + dc->cls = XOMBE_CLASS_VOICE; + c = xombe__conceal_decide(d, 0, ef.hb); + if (c != XOMBE_CONCEAL_NONE) { + conceal(s, d, c); + } else { + voice(d, f->b); + s->log = XOMBE_DSD_LOG_VOICE; + } + } else { + /* played as the AMBE+2 tone frame of its ID and level, an unknown tone index is a bad frame */ + dc->cls = XOMBE_CLASS_TONE; + c = xombe__conceal_decide(d, ef.bf || f->tid < 0, ef.hb); + if (c != XOMBE_CONCEAL_NONE) { + conceal(s, d, c); + } else { + static const uint8_t none[8]; + xombe_set t; + xombe__tone_set(&t, f->tid, f->AD); + xombe__dec_play(d, &t, none, NULL, none); + s->log = XOMBE_DSD_LOG_TONE; + } + } + decided(d, c); +} + +static void start_bits(xombe_dec *d, const uint8_t bits[7], unsigned flags) +{ + xombe_ds_frame f; + uint8_t data[XOMBE_DS_DATA_BITS]; + if (flags & XOMBE_FLAG_LOST) { + xombe__dsd_start_frame(&d->ds, &d->c, NULL, flags, d->err_t, d->err_1); + return; + } + xombe__ds_unpack(bits, data); + xombe__ds_frame_from_data(data, &f); + xombe__dsd_start_frame(&d->ds, &d->c, &f, flags, d->err_t, d->err_1); +} + +const struct xombe_dec_ops xombe__dsd_ops = {start_bits}; diff --git a/xombe/src/dstar/dsd_state.h b/xombe/src/dstar/dsd_state.h new file mode 100644 index 0000000..2531295 --- /dev/null +++ b/xombe/src/dstar/dsd_state.h @@ -0,0 +1,28 @@ +#ifndef XOMBE_DSD_STATE_H +#define XOMBE_DSD_STATE_H + +/* D-STAR frame logic on the shared decoder core (decoder.c), state xombe_dsd_logic in state.h */ + +#include "dstar_internal.h" + +/* what a frame logged, a bad voice frame logs voice (or mute with hb set) but plays a repeat */ +enum { + XOMBE_DSD_LOG_VOICE, + XOMBE_DSD_LOG_TONE, + XOMBE_DSD_LOG_NULL, + XOMBE_DSD_LOG_REPEAT, + XOMBE_DSD_LOG_MUTE +}; + +/* sets up s and the D-STAR rules of a reset d */ +void xombe__dsd_logic_init(xombe_dsd_logic *s, xombe_dec_core *d); +/* frame logic of one frame up to its sets. f from xombe__ds_frame_from_bits, NULL for a lost frame. flags: the + error rule's XOMBE_FLAG_BF and XOMBE_FLAG_HB, eps_t and eps1 its error counts (xombe_fec_stats). sets the + decision's e0 and e1 to -1 */ +void xombe__dsd_start_frame(xombe_dsd_logic *s, xombe_dec_core *d, const xombe_ds_frame *f, unsigned flags, + int eps_t, int eps1); + +/* xombe_dec's frame logic for D-STAR */ +extern const struct xombe_dec_ops xombe__dsd_ops; + +#endif diff --git a/xombe/src/dstar/dstar_enc.c b/xombe/src/dstar/dstar_enc.c new file mode 100644 index 0000000..f07cafd --- /dev/null +++ b/xombe/src/dstar/dstar_enc.c @@ -0,0 +1,179 @@ +#include +#include +#include "dstar_enc.h" +#include "../tables/dstar_enc_tables.h" +#include "../common/prof.h" + +#define DS_GAIN_DB 0.2f +#define DS_GAIN_LOG2 (DS_GAIN_DB / 6.02059991f) /* dB -> log2 amplitude */ + +XOMBE_STATIC_ASSERT(sizeof(xombe_ds_enc) <= XOMBE_DS_ENC_STATE, ds_enc_state_fits_XOMBE_DS_ENC_STATE); + +void xombe__ds_enc_reset(xombe_ds_enc *s) +{ + s->s_vn = XOMBE_DS_S_VN; + xombe__ds_mirror_init(&s->mirror); +} + +void xombe__ds_enc_init(xombe_enc *e) +{ + xombe__ds_enc_reset(XOMBE_DS_ENC(e)); + xombe__ds_tone_init(&XOMBE_DS_ENC(e)->tones); + XOMBE_DS_ENC(e)->ws.cap = XOMBE_CQ_CAP; +} + +void xombe__ds_m_noise(int N, int b0, float mn[8]) +{ + int i = (N - XOMBE_DS_MN_N_MIN) / 2, lo, hi, j; + const unsigned short *r; + if (i < 0) + i = 0; + if (i > XOMBE_DS_MN_WINDOWS - 1) + i = XOMBE_DS_MN_WINDOWS - 1; + lo = xombe__ds_mn_lo[i]; + hi = lo + xombe__ds_mn_cnt[i] - 1; + if (b0 < lo) + b0 = lo; + if (b0 > hi) + b0 = hi; + r = xombe__ds_mn[xombe__ds_mn_off[i] + b0 - lo]; + for (j = 0; j < 8; j++) + mn[j] = (float)r[j] * (1.0f / XOMBE_DS_MN_SCALE); +} + +int xombe__ds_b1_search(const float a[8], const float w[8]) +{ + float best = 0.0f; + int c, j, bi = 0; + for (c = 0; c < 16; c++) { + const unsigned char *V = xombe__ds_vuv[c]; + float cost = 0.0f; + if (c == XOMBE_DS_B1_SKIP) + continue; + for (j = 0; j < 8; j++) { + float d = V[j] ? 1.0f - a[j] : a[j]; + cost += w[j] * d * d; + } + if (c == 0 || cost < best) { + best = cost; + bi = c; + } + } + return bi; +} + +int xombe__ds_soft(const float m[8], const float mn[8], float s_vn, int speech2, float a[8]) +{ + int j, any = 0; + for (j = 0; j < 8; j++) { + a[j] = speech2 ? xombe__voicing_map(s_vn * (m[j] / mn[j])) : 0.0f; + any |= a[j] > 0.5f; + } + return !any; +} + +void xombe__ds_enc_voicing(xombe_enc *e, xombe_fe_frame *a, xombe_be_ns *ns) +{ + xombe_ds_enc *s = XOMBE_DS_ENC(e); + xombe_ds_enc_frame *fr = &s->fr; + memset(fr, 0, sizeof(*fr)); + fr->no_band_voiced = 1; + fr->cls = XOMBE_DS_CLS_NULL; + if (e->cfg.tones) { + fr->det = s->tones.ndet; + fr->trk = s->tones.ntrk; + fr->tone = s->tones.tone; + } + if (fr->tone.on) { + fr->cls = fr->tone.T < 0 ? XOMBE_DS_CLS_KNOX : XOMBE_DS_CLS_TONE; + } else if (a->active || !e->cfg.dstar_dtx) { + fr->cls = XOMBE_DS_CLS_VOICE; + fr->voice = 1; + XOMBE_PF(8, xombe__fe_voice(e, a)); + fr->b0 = xombe__ds_b0_from_f0(a->fstar); + fr->f0 = xombe__ds_f0(fr->b0); + fr->L = xombe__ds_L(fr->b0); + XOMBE_PF(9, xombe__voicing_metric_sp(e, xombe__fe_s2_prepared(e, a), fr->f0, fr->m, fr->w)); + xombe__ds_m_noise(a->nw, fr->b0, fr->mn); + fr->no_band_voiced = xombe__ds_soft(fr->m, fr->mn, s->s_vn, a->speech2, fr->a); + fr->b1 = xombe__ds_b1_search(fr->a, fr->w); + memcpy(fr->V, xombe__ds_vuv[fr->b1], 8); + } + ns->no_band_voiced[0] = ns->no_band_voiced[1] = fr->no_band_voiced; + ns->mem = &s->ns_mem; + if (e->cfg.ns) + xombe__ns_bin_voicing(fr->V, 0, ns->vbin); +} + +void xombe__ds_enc_targets(const xombe_spec *S, float win_sum2, float f0, int L, const float *G, const uint8_t V[8], + float at[XOMBE_LMAX + 1]) +{ + float P[XOMBE_SPEC_BINS]; + int l; + xombe__kern_bin_power(S, win_sum2, P); + xombe__enc_integrate(P, L, f0, at); + xombe__enc_hf_precomp(at, L, f0); + if (G) { + uint8_t vh[XOMBE_LMAX + 1]; + float da[XOMBE_LMAX + 1]; + xombe__ds_harm_voicing(V, f0, L, vh); + xombe__ns_harmonic_offsets(G, L, f0, vh, da); + for (l = 1; l <= L; l++) + at[l] += da[l]; + } + for (l = 1; l <= L; l++) { + at[l] += DS_GAIN_LOG2; + if (at[l] < XOMBE_AMP_MIN) + at[l] = XOMBE_AMP_MIN; + } +} + +void xombe__ds_enc_amps(xombe_ds_enc *s, int b0, int b1, const float at[XOMBE_LMAX + 1], int b[9]) +{ + float w[XOMBE_LMAX + 1], pt[XOMBE_LMAX + 1]; + xombe_cq_result res; + int L = xombe__ds_L(b0), k; + xombe__cq_amp_weights(at, L, XOMBE_CQ_QWEIGHT, XOMBE_CQ_WEIGHT_FLOOR, w); + xombe__ds_mirror_predict(&s->mirror, L, pt); + XOMBE_PF(13, xombe__cq_quantize(&s->ws, &xombe__amp_dstar, at, L, pt, s->mirror.G, w, 1, XOMBE_CQ_N_PAIRS, + XOMBE_CQ_N_GAIN, XOMBE_CQ_ITERS, XOMBE_CQ_CLIP_PASSES, &res)); + XOMBE_PF_ADD(15, L); + b[0] = b0; + b[1] = b1; + for (k = 2; k < 9; k++) + b[k] = res.b[k]; + xombe__ds_mirror_commit(&s->mirror, b, NULL); +} + +void xombe__ds_enc_frame(xombe_enc *e, const xombe_fe_frame *a, const xombe_be_ns *ns, uint8_t out[7]) +{ + static const uint8_t null_bits[7] = XOMBE_DS_NULL_BITS; + xombe_ds_enc *s = XOMBE_DS_ENC(e); + const xombe_ds_enc_frame *fr = &s->fr; + float at[XOMBE_LMAX + 1]; + int b[9]; + if (fr->cls == XOMBE_DS_CLS_KNOX) { /* voice frame from the tone table, no VAD gate or suppression */ + int k; + for (k = 0; s->tones.knox[k].id != -fr->tone.T; k++) + ; + xombe__ds_knox_amps(s, k, fr->tone.level, b); + s->fr.b0 = b[0]; + s->fr.b1 = b[1]; + xombe__ds_fields_bits(b, out); + return; + } + if (!fr->voice) { /* tone and NULL frames leave the mirror alone */ + if (fr->cls == XOMBE_DS_CLS_TONE) { + uint8_t d[XOMBE_DS_DATA_BITS]; + xombe__ds_tone_bits(fr->tone.T, xombe__ds_tone_q(fr->tone.level), d); + xombe__ds_pack(d, out); + } else { + memcpy(out, null_bits, 7); + } + return; + } + XOMBE_PF(14, xombe__ds_enc_targets(&a->S2, a->win_sum2, fr->f0, fr->L, e->cfg.ns ? ns->G2 : NULL, fr->V, + at)); + xombe__ds_enc_amps(s, fr->b0, fr->b1, at, b); + xombe__ds_fields_bits(b, out); +} diff --git a/xombe/src/dstar/dstar_enc.h b/xombe/src/dstar/dstar_enc.h new file mode 100644 index 0000000..723ef06 --- /dev/null +++ b/xombe/src/dstar/dstar_enc.h @@ -0,0 +1,103 @@ +#ifndef XOMBE_DSTAR_ENC_H +#define XOMBE_DSTAR_ENC_H + +/* D-STAR back end, phases B and D of enc/frontend.h (voice, NULL, tone, and Knox frames). encoder.c calls: + xombe__ds_tone_push every call with cfg.tones, right after the input is taken, even before the delay + has passed + xombe__ds_enc_voicing phase B, after xombe__fe_analyze and the AMBE+2 phase B: class (tone or Knox from + the tone pipeline, else NULL when cfg.dstar_dtx and inactive, else voice), b0, and + band voicing. tone and Knox frames count as unvoiced like NULL frames. voice frames + share the prepared S2 with AMBE+2. fills ns->no_band_voiced[2] (no a_j above 1/2), + ns->mem, and with cfg.ns ns->vbin (band flags without the +250 Hz OR) + xombe__fe_background phase C, D-STAR gains in ns->G1/G2 when cfg.ns, the frame uses G2 + xombe__ds_enc_force_tone phase D for a forced tone, before xombe__ds_enc_frame: tone frame at the AMBE+2 + level ad, a Knox ID a Knox frame + xombe__ds_enc_frame phase D, writes the voice bits + state: e->ds, zeroed by xombe_enc_init before xombe__ds_enc_init, XOMBE_DS_ENC(e) is the typed view */ + +#include "../enc/frontend.h" +#include "../common/cquant.h" +#include "dstar_internal.h" + +#define XOMBE_DS_S_VN 0.35f /* voicing scale on the noise-normalised metric */ + +/* tone pipeline (dstar_tone.c). after the call appending input frame t, the detector has run on t - 1 (segment + ends 20 samples into t), the run rule has decided t - 3 (reads two detections ahead), and t - 4, the encoded + frame, has its final tone (tone-in-noise reads the next frame's decision) */ +#define XOMBE_DS_TONE_RING 4 /* indexed by frame mod 4 */ +#define XOMBE_DS_NZ_FLOOR 50 /* noise floor is the quietest of the last N + 1 frames */ + +typedef struct { + int on; /* 0: no tone */ + int T; /* D-STAR tone index, or -ID for a Knox tone */ + float level; /* real-valued AMBE+2 level, 127 + level term / 0.711 + TONE_ADOFF */ +} xombe_ds_tone; + +typedef struct { + int n_frames; + xombe_ds_tone detected[XOMBE_DS_TONE_RING]; + int run[XOMBE_DS_TONE_RING]; /* run length ending at each detection, capped at 3 */ + xombe_ds_tone confirmed[XOMBE_DS_TONE_RING]; /* detections the run rule keeps, and held tones */ + xombe_ds_tone held; + int hold_left; + float level_db[XOMBE_DS_NZ_FLOOR + 1]; /* ring of frame levels */ + int n_levels, level_pos; + xombe_ds_tone ndet, ntrk, tone; /* encoded frame's detection, run-rule tone, and final tone */ + int nknox; /* Knox IDs in the tone table, with their pairs */ + xombe_tone_pair knox[XOMBE_TONE_KNOX_COUNT]; + float knox_f0[XOMBE_TONE_KNOX_COUNT]; /* table f0 in cycles/sample, and harmonics */ + uint8_t knox_l[XOMBE_TONE_KNOX_COUNT][2]; +} xombe_ds_tones; + +#define XOMBE_DS_CLS_VOICE 0 +#define XOMBE_DS_CLS_NULL 1 +#define XOMBE_DS_CLS_TONE 2 +#define XOMBE_DS_CLS_KNOX 3 + +/* phase B result */ +typedef struct { + int cls; /* XOMBE_DS_CLS_* */ + xombe_ds_tone det, trk, tone; /* detection, run rule, final */ + int voice; /* 1 voice, 0 NULL (dtx) */ + int b0, b1, L; + float f0; + float m[8], mn[8]; /* band metric and its white-noise reference */ + float a[8], w[8]; /* soft voicing after the VAD gate, band weights */ + uint8_t V[8]; /* xombe__ds_vuv[b1], 0 on NULL frames */ + int no_band_voiced; /* no a_j above 1/2, 1 on NULL frames */ +} xombe_ds_enc_frame; + +typedef struct { + float s_vn; + xombe_ns_mem ns_mem; /* D-STAR gain smoothing */ + xombe_ds_mirror mirror; /* decoder's prediction memory */ + xombe_ds_tones tones; + xombe_ds_enc_frame fr; /* phase B -> D */ + xombe_cq_ws ws; /* only the last L's maps live between frames */ +} xombe_ds_enc; + +#define XOMBE_DS_ENC(e) ((xombe_ds_enc *)(void *)(e)->ds.bytes) + +void xombe__ds_enc_init(xombe_enc *e); +/* every call with cfg.tones, even when the front end returns no frame */ +void xombe__ds_tone_push(xombe_enc *e); +void xombe__ds_tone_init(xombe_ds_tones *s); +/* Knox voice frame fields for entry k at level AD, committed to the mirror */ +void xombe__ds_knox_amps(xombe_ds_enc *s, int k, float AD, int b[9]); +void xombe__ds_enc_voicing(xombe_enc *e, xombe_fe_frame *a, xombe_be_ns *ns); +void xombe__ds_enc_force_tone(xombe_enc *e, int id, int ad); +void xombe__ds_enc_frame(xombe_enc *e, const xombe_fe_frame *a, const xombe_be_ns *ns, uint8_t out[7]); + +/* pieces run by test/dstar_dump_enc_be.c on recorded inputs */ +void xombe__ds_enc_reset(xombe_ds_enc *s); /* s_vn default, mirror reset */ +void xombe__ds_m_noise(int N, int b0, float mn[8]); /* tables/dstar_enc_tables.h */ +int xombe__ds_b1_search(const float a[8], const float w[8]); +/* noise normalisation and VAD gate, returns no_band_voiced */ +int xombe__ds_soft(const float m[8], const float mn[8], float s_vn, int speech2, float a[8]); +/* targets at[1..L], G NULL for no noise suppression */ +void xombe__ds_enc_targets(const xombe_spec *S, float win_sum2, float f0, int L, const float *G, const uint8_t V[8], + float at[XOMBE_LMAX + 1]); +/* weights, closed-loop quantization against the mirror, and commit */ +void xombe__ds_enc_amps(xombe_ds_enc *s, int b0, int b1, const float at[XOMBE_LMAX + 1], int b[9]); + +#endif diff --git a/xombe/src/dstar/dstar_internal.h b/xombe/src/dstar/dstar_internal.h new file mode 100644 index 0000000..786a0a8 --- /dev/null +++ b/xombe/src/dstar/dstar_internal.h @@ -0,0 +1,171 @@ +#ifndef XOMBE_DSTAR_INTERNAL_H +#define XOMBE_DSTAR_INTERNAL_H + +/* D-STAR (AMBE 2400) core + frame: 72 bits (9 bytes, MSB first), three interleaved 24-bit words: + A = Golay(24,12)(da), B = Golay(24,12)(db) ^ pn24(da), C = 24 uncoded bits + data: d[0..47] = da, db, C (MSB first) + fields: b0..b8 are 7, 4, 6, 9, 7, 4, 4, 4, 3 bits, scattered over d */ + +#include +#include "../internal.h" +#include "../tables/tables.h" +#include "../tables/dstar_tables.h" + +#define XOMBE_DS_FRAME_BYTES 9 +#define XOMBE_DS_DATA_BITS 48 +#define XOMBE_DS_GOLAY_BAD 4 /* error count of an uncorrectable Golay(24,12) word */ + +/* special b0 codes, b0 0..123 are voice */ +#define XOMBE_DS_B0_VOICE_MAX 123 +#define XOMBE_DS_B0_SILENCE 124 /* standard silence frame, XOMBE_DS_NULL_FRAME */ +#define XOMBE_DS_B0_NULL125 125 /* plays as 124 */ +#define XOMBE_DS_B0_TONE 126 +#define XOMBE_DS_B0_FILL 127 /* DTX fill (ff x 9), plays as 124 */ +/* fields 124 0 4 165 41 10 7 7 5, both Golay words clean */ +#define XOMBE_DS_NULL_FRAME {0x9E, 0x8D, 0x32, 0x88, 0x26, 0x1A, 0x3F, 0x61, 0xE8} +#define XOMBE_DS_NULL_BITS {0xF8, 0x54, 0xAA, 0x9D, 0xE8, 0x0A, 0x00} /* its voice bits */ +/* null frames play f0 250 Hz, L 14, all unvoiced, M 0.1 */ +#define XOMBE_DS_NULL_F0 (250.0f / 8000.0f) +#define XOMBE_DS_NULL_L 14 +#define XOMBE_DS_NULL_M 0.1f + +#define XOMBE_DS_B1_SKIP 4 /* plays as 12, never sent */ +#define XOMBE_DS_B1_VOICED 15 /* all bands voiced */ + +#define XOMBE_DS_GAIN_MAX 13.0f +/* D-STAR clamps a to [-15, 15 - 1e-9], which rounds to 15.0f (AMBE+2: 15 - 2^-11) */ +#define XOMBE_DS_AMP_MAX 15.0f +#define XOMBE_DS_LAMBDA_DECAY (20.0f / 2048.0f) /* smoothing level decay per frame (AMBE+2: 0.0098) */ + +/* every 7-bit b0 is voice, tone, or null, so xombe__ds_classify never returns XOMBE_DS_ERASURE, it is for + callers that lose a frame */ +enum { + XOMBE_DS_VOICE = 0, + XOMBE_DS_TONE, + XOMBE_DS_NULL, + XOMBE_DS_ERASURE +}; + +/* everything the receive side learns from 9 bytes */ +typedef struct { + uint32_t A, B, C; /* deinterleaved 24-bit words as received */ + uint32_t pn; /* pn24(da) */ + int da, db; /* corrected 12-bit data of A and of B ^ pn */ + int ea, eb; /* corrected errors, XOMBE_DS_GOLAY_BAD = uncorrectable */ + uint8_t d[XOMBE_DS_DATA_BITS]; /* one bit per byte */ + int b[9]; + int cls; /* XOMBE_DS_VOICE, TONE, or NULL */ + int T, AD; /* tone frames: 8-bit tone index and AMBE+2 level 8..127, else -1 */ + int tid; /* AMBE+2 tone ID, -1 for invalid T or not a tone frame */ +} xombe_ds_frame; + +/* Golay(24,12) = Golay(23,12) (data in bits 23..12) || even parity. decode returns the error count 0..3, or 4 + when uncorrectable (three corrections and a parity mismatch), and the data bits as the 23-bit decoder + corrected them */ +uint32_t xombe__ds_golay24_encode(uint32_t data12); +int xombe__ds_golay24_decode(uint32_t cw24, int *data12); +/* B's 24-bit whitening sequence seeded from A's data, AMBE+2's LCG, 24 steps */ +uint32_t xombe__ds_pn24(int da); +/* A = bits 0, 6, ..., 66, 1, 7, ..., 67, B = A + 2, C = A + 4, MSB first */ +void xombe__ds_deinterleave(const uint8_t in[9], uint32_t *A, uint32_t *B, uint32_t *C); +void xombe__ds_interleave(uint32_t A, uint32_t B, uint32_t C, uint8_t out[9]); +void xombe__ds_get_fields(const uint8_t d[48], int b[9]); +void xombe__ds_put_fields(const int b[9], uint8_t d[48]); /* each field masked to its width */ +int xombe__ds_classify(int b0); +/* full receive path: FEC, data bits, fields, class, and tone fields */ +void xombe__ds_fec_decode(const uint8_t in[9], xombe_ds_frame *f); +/* the part after FEC: d, fields, class, and tone fields (A, B, C, pn, da, db, ea, eb untouched) */ +void xombe__ds_frame_from_data(const uint8_t d[48], xombe_ds_frame *f); +/* data bits <-> voice bits (7 bytes, MSB first, the last bit zero) */ +void xombe__ds_pack(const uint8_t d[48], uint8_t bits[7]); +void xombe__ds_unpack(const uint8_t bits[7], uint8_t d[48]); +/* xombe_fec_encode and xombe_fec_decode for D-STAR, st not NULL */ +void xombe__ds_fec_encode_bits(const uint8_t bits[7], uint8_t frame[9]); +unsigned xombe__ds_fec_decode_bits(xombe_fec *fec, const uint8_t frame[9], uint8_t bits[7], xombe_fec_stats *st); +/* xombe_tone_frame for D-STAR */ +int xombe__ds_tone_frame_id(int id, int ad, uint8_t out[9]); +void xombe__ds_encode_bits(const uint8_t d[48], uint8_t out[9]); +/* always writes out, a field out of range clamped to its width. returns 0, or -1 if any was clamped */ +int xombe__ds_encode_fields(const int b[9], uint8_t out[9]); +/* xombe__ds_encode_fields writing voice bits */ +int xombe__ds_fields_bits(const int b[9], uint8_t bits[7]); +/* tone frames carry the level in half steps q = floor(2*level) clamped to 16..254: F = q/2 - 8 in bits + 12..16, 43, 44 and q & 1 in bit 17, so the decoder plays AD = q/2 + (q & 1), rounded half up, capped at 127 */ +int xombe__ds_tone_q(float level); +/* AMBE+2 level ad as a tone level: q = 2*ad - 1, which plays as AD ad */ +#define XOMBE_DS_AD_LEVEL(ad) ((float)(ad) - 0.5f) +/* D-STAR tone index of an AMBE+2 tone ID, -1 if it has none (Knox) */ +int xombe__ds_tone_code(int id); +void xombe__ds_tone_bits(int T, int q, uint8_t d[48]); +void xombe__ds_tone_frame(int T, int q, uint8_t out[9]); +/* level AD = 4*bits(12..16) + bit 17 + bits(43,44) + 8, capped at 127 */ +int xombe__ds_tone_index(const uint8_t d[48]); +int xombe__ds_tone_level(const uint8_t d[48]); + +/* fitted error rule, stateful over the stream. per frame, with eT = ea + eb: + er = 0.95*er + 0.05*eT/48, bf (repeat) iff ea >= 4, hb (mute) iff er > 0.096, + smoothing inputs eT and e1 = eb, both 0 when eT < 6. null frames ignore bf and hb but still advance er */ +typedef struct { + float er; +} xombe_ds_err; + +typedef struct { + int bf, hb, eT, e1; +} xombe_ds_flags; + +void xombe__ds_err_init(xombe_ds_err *s); +void xombe__ds_err_update(xombe_ds_err *s, int ea, int eb, xombe_ds_flags *out); + +/* D-STAR amplitude tables: rho 0.8, gain recursion 0, gmax 13, clamp [-15, XOMBE_DS_AMP_MAX], fitted codebooks, + and their ok masks */ +extern const xombe_amp_tables xombe__amp_dstar; + +/* voice frames fill everything up to a, others only cls, b, and the tone fields */ +typedef struct { + int cls; + int b[9]; + float f0; /* cycles/sample */ + int L; + uint8_t V[8]; /* 500 Hz band flags, xombe__ds_vuv[b1] */ + uint8_t vl[XOMBE_LMAX + 1]; /* per-harmonic voicing vl[1..L] */ + float Tv[XOMBE_LMAX + 1]; /* spectral shape before mean removal, Tv[1..L] */ + float G; + float a[XOMBE_LMAX + 1]; /* log2 amplitudes a[1..L], a[L + 1..XOMBE_LMAX] = a[L] */ + int T, tid, AD; /* tone frames, else -1 */ +} xombe_ds_params; + +/* dequantizer prediction memory, a extended to a[L + 1..XOMBE_LMAX] = a[L], reset L 15, a 0, G 0, copyable by + assignment */ +typedef struct { + int L; + float G; + float a[XOMBE_LMAX + 1]; +} xombe_ds_mirror; + +/* any b0 0..127 */ +float xombe__ds_f0(int b0); +int xombe__ds_L(int b0); +int xombe__ds_b0_from_f0(float f0); /* nearest pitch index in log f0, 0..123 */ +/* harmonic l takes band min(floor(l*f0*16), 7) of V, without AMBE+2's +250 Hz OR, vl[0] = 0 */ +void xombe__ds_harm_voicing(const uint8_t V[8], float f0, int L, uint8_t vl[XOMBE_LMAX + 1]); + +/* Tv, G, and a of fields b at L harmonics against an explicit memory (Lp, ap extended, Gp), Tv may be NULL. + the decoder's memory is smoothed on error frames, so it calls this, smooths a, then stores its own memory, + the mirror never smooths */ +void xombe__ds_amps(const int b[9], int L, int Lp, const float ap[XOMBE_LMAX + 1], float Gp, + float Tv[XOMBE_LMAX + 1], float *G, float a[XOMBE_LMAX + 1]); + +void xombe__ds_mirror_init(xombe_ds_mirror *m); +/* prediction pt[1..L] for a frame of L harmonics */ +void xombe__ds_mirror_predict(const xombe_ds_mirror *m, int L, float pt[XOMBE_LMAX + 1]); +/* decodes b against the memory without changing it. b0 > 123 gives only the class, tone fields need the data + bits (xombe__ds_params_from_frame) */ +void xombe__ds_dequant(const int b[9], const xombe_ds_mirror *m, xombe_ds_params *p); +/* decodes b and stores L, a, and G for a voice frame. returns 1 for voice, 0 otherwise (memory unchanged), + p may be NULL */ +int xombe__ds_mirror_commit(xombe_ds_mirror *m, const int b[9], xombe_ds_params *p); +/* received frame's parameters against the mirror, committing voice frames */ +int xombe__ds_params_from_frame(xombe_ds_mirror *m, const xombe_ds_frame *f, xombe_ds_params *p); + +#endif diff --git a/xombe/src/dstar/dstar_tone.c b/xombe/src/dstar/dstar_tone.c new file mode 100644 index 0000000..53ecef1 --- /dev/null +++ b/xombe/src/dstar/dstar_tone.c @@ -0,0 +1,264 @@ +#include +#include +#include "dstar_enc.h" +#include "../tables/dstar_enc_tables.h" +#include "../common/tone_table.h" +#include "../common/prof.h" + +/* D-STAR encoder tone pipeline + detect least-squares detector (xombe__tone_search) on XOMBE_DS_TONE_LEN samples from 160t + TONE_OFF, over + single tones and the dual tones with a D-STAR code (DTMF, call progress, and 163), then if none a + second pass over the Knox pairs alone (T = -ID), so a Knox candidate never changes a D-STAR decision + run rule a tone frame lies in a run of at least MINRUN detections of the same T (MINRUN_SINGLE for single + tones, whose runs also continue across one 31.25 Hz step), after which HOLD frames without a + detection repeat the last tone + in noise with no tone on the frame or either neighbour after the run rule, a DTMF detection on the + XOMBE_DS_NZ_LEN-sample window from 160n + NZ_OFF at threshold NZ_EMIN is a tone frame when its + residual is within NZ_RES_DB of the noise floor + detection level is the AMBE+2 level 127 + L/0.711 + TONE_ADOFF, L the detector's level in dB */ + +#define TONE_EMIN 0.99f /* minimum explained energy fraction */ +#define TONE_OFF 20 +#define TONE_ADOFF 0.6f +#define MINRUN 2 +#define MINRUN_SINGLE 3 +#define HOLD 1 +#define SINGLE_T_MIN 37 /* D-STAR T of the lowest single tone */ +#define NZ_OFF (-80) +#define NZ_EMIN 0.85f +#define NZ_RES_DB 10.0f +#define KNOX_REST 5.5f /* encoder's other Knox harmonics this far below the tone level, log2 */ +#define KNOX_GAIN 0.9f /* target offset, log2 */ +#define RING XOMBE_DS_TONE_RING + +/* encoded frame is 4 behind the newest, the run rule decides the frame after it from two detections ahead */ +XOMBE_STATIC_ASSERT(XOMBE_ENC_DELAY + XOMBE_ENC_LOOKAHEAD == 4, tone_pipeline_matches_the_delay); +XOMBE_STATIC_ASSERT(-NZ_OFF <= XOMBE_ENC_RAW_LEAD, tone_in_noise_window_in_raw_lead); +XOMBE_STATIC_ASSERT(XOMBE_DS_TONE_LEN <= XOMBE_TONE_SEG && XOMBE_DS_NZ_LEN <= XOMBE_TONE_SEG, ds_tone_segments_fit); + +/* DTMF 128..143, call progress 160..162, and 163, high component first */ +static int dual_pairs(xombe_tone_pair p[20]) +{ + int id, n = 0; + for (id = 128; id <= 162; id++) { + float lo, hi; + if (id > 143 && id < 160) + continue; + xombe__tone_freqs(id, &lo, &hi); + p[n].id = (short)id; + p[n].hz[0] = hi; + p[n].hz[1] = lo; + n++; + } + /* D-STAR T 19 (AMBE+2 163) is detected as 340 + 550 Hz, not the AMBE+2 table's 350 + 490 Hz */ + p[n].id = 163; + p[n].hz[0] = 550.0f; + p[n].hz[1] = 340.0f; + return n + 1; +} + +/* tone-in-noise candidates, the 16 DTMF pairs in D-STAR T order */ +static void dtmf_pairs(xombe_tone_pair p[16]) +{ + int T; + for (T = 0; T < 16; T++) { + float lo, hi; + p[T].id = xombe__ds_tone_id[T]; + xombe__tone_freqs(p[T].id, &lo, &hi); + p[T].hz[0] = hi; + p[T].hz[1] = lo; + } +} + +static void set_tone(xombe_ds_tone *d, int T, float level) +{ + d->on = 1; + d->T = T; + d->level = 127.0f + level / XOMBE_TONE_DB_PER_AD + TONE_ADOFF; +} + +/* run continues on the same T, or single tones one step apart */ +static int same_tone(int a, int b) +{ + return a == b || (a >= SINGLE_T_MIN && b >= SINGLE_T_MIN && (a - b <= 1 && b - a <= 1)); +} + +void xombe__ds_tone_init(xombe_ds_tones *s) +{ + int id; + memset(s, 0, sizeof(*s)); + /* Knox IDs that the AMBE+2 tone table gives a harmonic pair for */ + for (id = XOMBE_TONE_KNOX_FIRST; id < XOMBE_TONE_KNOX_FIRST + XOMBE_TONE_KNOX_COUNT; id++) { + float f0; + int l1, l2; + xombe__tone_harmonics(id, &f0, &l1, &l2); + if (l1 <= 0 || l2 <= 0) + continue; + s->knox[s->nknox].id = (short)id; + s->knox[s->nknox].hz[0] = f0 * (float)l2; + s->knox[s->nknox].hz[1] = f0 * (float)l1; + s->knox_f0[s->nknox] = f0 / XOMBE_FS; + s->knox_l[s->nknox][0] = (uint8_t)l1; + s->knox_l[s->nknox][1] = (uint8_t)l2; + s->nknox++; + } +} + +static void detect(xombe_enc *e, xombe_ds_tones *s, int m, const int16_t *seg) +{ + xombe_tone_pair pairs[20]; + xombe_tone_search ts; + xombe_tone_seg sg; + xombe_tone_hit h; + xombe_ds_tone *d = &s->detected[m % RING]; + const xombe_ds_tone *p = &s->detected[(m + RING - 1) % RING]; + int run = 0; + ts.len = XOMBE_DS_TONE_LEN; + ts.win = xombe__ds_tone_win; + ts.emin = TONE_EMIN; + ts.singles = 1; + ts.fine_peak = 1; + ts.pairs = pairs; + ts.npairs = dual_pairs(pairs); + d->on = 0; + xombe__tone_prepare(e, seg, &ts, &sg); + if (xombe__tone_search(&sg, &ts, &h)) { + set_tone(d, xombe__ds_tone_code(h.id), h.level); + } else if (s->nknox) { + ts.singles = 0; + ts.pairs = s->knox; + ts.npairs = s->nknox; + if (xombe__tone_search(&sg, &ts, &h)) + set_tone(d, -h.id, h.level); + } + if (d->on) { + run = 1; + if (m > 0 && p->on && same_tone(d->T, p->T)) { + run = s->run[(m + RING - 1) % RING] + 1; + run = run > MINRUN_SINGLE ? MINRUN_SINGLE : run; + } + } + s->run[m % RING] = run; +} + +/* run rule on frame m, detections of m + 1 and m + 2 already in the ring */ +static void decide(xombe_ds_tones *s, int m) +{ + const xombe_ds_tone *d = &s->detected[m % RING]; + xombe_ds_tone *o = &s->confirmed[m % RING]; + o->on = 0; + if (d->on) { + int need = d->T >= SINGLE_T_MIN ? MINRUN_SINGLE : MINRUN, len = s->run[m % RING], k; + for (k = 1; k <= MINRUN_SINGLE - 1 && len < need; k++) { + const xombe_ds_tone *a = &s->detected[(m + k - 1) % RING], *b = &s->detected[(m + k) % RING]; + if (!b->on || !same_tone(b->T, a->T)) + break; + len++; + } + if (len >= need) { + *o = *d; + s->held = *d; + s->hold_left = HOLD; + } else { + s->hold_left = 0; + } + } else if (s->hold_left > 0) { + *o = s->held; + s->hold_left--; + } +} + +/* frame n's final tone from the run rule or the tone-in-noise pass, raw is frame n's input */ +static void finish(xombe_enc *e, xombe_ds_tones *s, int n, const int16_t *raw) +{ + int64_t sum = 0; + float floor_db; + int i; + for (i = 0; i < XOMBE_FRAME; i++) + sum += (int32_t)raw[i] * raw[i]; + s->level_db[s->level_pos] = 10.0f * log10f((float)sum / XOMBE_FRAME + 1e-9f); + s->level_pos = (s->level_pos + 1) % (XOMBE_DS_NZ_FLOOR + 1); + if (s->n_levels <= XOMBE_DS_NZ_FLOOR) + s->n_levels++; + s->ndet = s->detected[n % RING]; + s->ntrk = s->confirmed[n % RING]; + s->tone = s->ntrk; + if (s->tone.on || (n > 0 && s->confirmed[(n + RING - 1) % RING].on) || s->confirmed[(n + 1) % RING].on) + return; + { + xombe_tone_pair pairs[16]; + xombe_tone_search ts; + xombe_tone_seg sg; + xombe_tone_hit h; + dtmf_pairs(pairs); + ts.len = XOMBE_DS_NZ_LEN; + ts.win = xombe__ds_nz_win; + ts.emin = NZ_EMIN; + ts.singles = 0; + ts.fine_peak = 0; + ts.pairs = pairs; + ts.npairs = 16; + xombe__tone_prepare(e, raw + NZ_OFF, &ts, &sg); + if (!xombe__tone_search(&sg, &ts, &h)) + return; + floor_db = s->level_db[0]; + for (i = 1; i < s->n_levels; i++) + floor_db = s->level_db[i] < floor_db ? s->level_db[i] : floor_db; + if (10.0f * log10f((h.res > 1e-9f ? h.res : 1e-9f) / XOMBE_DS_NZ_LEN) > floor_db + NZ_RES_DB) + return; + set_tone(&s->tone, xombe__ds_tone_code(h.id), h.level); + } +} + +void xombe__ds_tone_push(xombe_enc *e) +{ + xombe_ds_tones *s = &XOMBE_DS_ENC(e)->tones; + int t = s->n_frames++; + if (t >= 1) + XOMBE_PF(11, detect(e, s, t - 1, xombe__fe_raw(e, 1) + TONE_OFF)); + if (t >= 3) + decide(s, t - 3); + if (t >= 4) + XOMBE_PF(12, finish(e, s, t - 4, xombe__fe_raw(e, 4))); +} + +void xombe__ds_enc_force_tone(xombe_enc *e, int id, int ad) +{ + xombe_ds_enc_frame *fr = &XOMBE_DS_ENC(e)->fr; + int T = xombe__ds_tone_code(id); + fr->voice = 0; + fr->tone.on = 1; + if (T >= 0) { + fr->cls = XOMBE_DS_CLS_TONE; + fr->tone.T = T; + fr->tone.level = XOMBE_DS_AD_LEVEL(ad); + } else { + fr->cls = XOMBE_DS_CLS_KNOX; + fr->tone.T = -id; + fr->tone.level = (float)ad; + } +} + +void xombe__ds_knox_amps(xombe_ds_enc *s, int k, float AD, int b[9]) +{ + const xombe_ds_tones *t = &s->tones; + float f0 = t->knox_f0[k], lm = XOMBE_TONE_AD_LOG10 * (AD - 127.0f) * XOMBE_LOG2_10, at[XOMBE_LMAX + 1], f0d; + int L = xombe__L_from_f0(f0), b0 = xombe__ds_knox_b0[t->knox[k].id - XOMBE_TONE_KNOX_FIRST], Ld, l, j; + /* target peak, log2 min(16384*10^(0.03555*(AD - 127)), 2^14) */ + lm = (lm > 0.0f ? 0.0f : lm) + 14.0f; + if (t->knox_l[k][0] > L && t->knox_l[k][1] > L) + lm -= KNOX_REST; + f0d = xombe__ds_f0(b0); + Ld = xombe__ds_L(b0); + for (l = 1; l <= Ld; l++) + at[l] = lm - KNOX_REST; + /* each tone on its nearest D-STAR harmonic */ + for (j = 0; j < 2; j++) { + int h = (int)floorf((float)t->knox_l[k][j] * f0 / f0d + 0.5f); + if (h >= 1 && h <= Ld) + at[h] = lm; + } + for (l = 1; l <= Ld; l++) + at[l] += KNOX_GAIN; + xombe__ds_enc_amps(s, b0, XOMBE_DS_B1_VOICED, at, b); +} diff --git a/xombe/src/dstar/fec.c b/xombe/src/dstar/fec.c new file mode 100644 index 0000000..e820cda --- /dev/null +++ b/xombe/src/dstar/fec.c @@ -0,0 +1,324 @@ +#include +#include +#include "dstar_internal.h" + +/* data bits of b0..b8, MSB first */ +static const uint8_t field_width[9] = {7, 4, 6, 9, 7, 4, 4, 4, 3}; +static const uint8_t field_bits[48] = { + 0, 1, 2, 3, 4, 5, 47, /* b0 */ + 37, 38, 39, 40, /* b1 */ + 6, 7, 8, 9, 41, 42, /* b2 */ + 10, 11, 12, 13, 14, 15, 16, 43, 44, /* b3 */ + 17, 18, 19, 20, 21, 45, 46, /* b4 */ + 22, 23, 24, 25, /* b5 */ + 26, 27, 28, 29, /* b6 */ + 30, 31, 32, 33, /* b7 */ + 34, 35, 36, /* b8 */ +}; +/* tone frames: index T at these data bits, 7-bit level F at the next, half step at bit 17 */ +static const uint8_t tone_t_bits[8] = {6, 7, 8, 9, 41, 42, 10, 11}; +static const uint8_t tone_f_bits[7] = {12, 13, 14, 15, 16, 43, 44}; +#define TONE_HALF_BIT 17 + +uint32_t xombe__ds_golay24_encode(uint32_t data12) +{ + uint32_t c23 = xombe__golay23_encode(data12 & 0xFFFu); + return (c23 << 1) | (uint32_t)(xombe__popcount32(c23) & 1); +} + +int xombe__ds_golay24_decode(uint32_t cw24, int *data12) +{ + uint32_t c23; + int w = xombe__golay23_decode((cw24 >> 1) & 0x7FFFFFu, &c23); + int parity_ok = ((xombe__popcount32(c23) + (int)(cw24 & 1u)) & 1) == 0; + *data12 = (int)(c23 >> 11); + if (w == 3 && !parity_ok) + return XOMBE_DS_GOLAY_BAD; + return w + !parity_ok; +} + +uint32_t xombe__ds_pn24(int da) +{ + uint16_t u = (uint16_t)(16u * ((unsigned)da & 0xFFFu)); + uint32_t out = 0; + int n; + for (n = 0; n < 24; n++) { + u = xombe__lcg_next(u); + out = (out << 1) | ((u >> 15) & 1u); + } + return out; +} + +/* air bit of A's word bit n (n = 0 the MSB), B and C are 2 and 4 later */ +static int pos_a(int n) +{ + return n < 12 ? 6 * n : 6 * (n - 12) + 1; +} + +void xombe__ds_deinterleave(const uint8_t in[9], uint32_t *A, uint32_t *B, uint32_t *C) +{ + uint32_t w[3] = {0, 0, 0}; + int n, k; + for (n = 0; n < 24; n++) + for (k = 0; k < 3; k++) { + int p = pos_a(n) + 2 * k; + w[k] = (w[k] << 1) | (uint32_t)((in[p >> 3] >> (7 - (p & 7))) & 1); + } + *A = w[0]; + *B = w[1]; + *C = w[2]; +} + +void xombe__ds_interleave(uint32_t A, uint32_t B, uint32_t C, uint8_t out[9]) +{ + uint32_t w[3]; + int n, k; + w[0] = A; + w[1] = B; + w[2] = C; + memset(out, 0, 9); + for (n = 0; n < 24; n++) + for (k = 0; k < 3; k++) { + int p = pos_a(n) + 2 * k; + out[p >> 3] |= (uint8_t)(((w[k] >> (23 - n)) & 1u) << (7 - (p & 7))); + } +} + +void xombe__ds_get_fields(const uint8_t d[48], int b[9]) +{ + int k, j, i = 0; + for (k = 0; k < 9; k++) { + int v = 0; + for (j = 0; j < field_width[k]; j++) + v = (v << 1) | (d[field_bits[i++]] & 1); + b[k] = v; + } +} + +void xombe__ds_put_fields(const int b[9], uint8_t d[48]) +{ + int k, j, i = 0; + for (k = 0; k < 9; k++) + for (j = 0; j < field_width[k]; j++) + d[field_bits[i++]] = (uint8_t)((b[k] >> (field_width[k] - 1 - j)) & 1); +} + +int xombe__ds_classify(int b0) +{ + if (b0 <= XOMBE_DS_B0_VOICE_MAX) + return XOMBE_DS_VOICE; + if (b0 == XOMBE_DS_B0_TONE) + return XOMBE_DS_TONE; + return XOMBE_DS_NULL; +} + +static int bits_at(const uint8_t d[48], const uint8_t *idx, int n) +{ + int v = 0, i; + for (i = 0; i < n; i++) + v = (v << 1) | (d[idx[i]] & 1); + return v; +} + +int xombe__ds_tone_index(const uint8_t d[48]) +{ + return bits_at(d, tone_t_bits, 8); +} + +int xombe__ds_tone_level(const uint8_t d[48]) +{ + /* 4*bits(12..16) + bits(43, 44) is the 7-bit F */ + int ad = bits_at(d, tone_f_bits, 7) + d[TONE_HALF_BIT] + 8; + return ad < 127 ? ad : 127; +} + +void xombe__ds_fec_decode(const uint8_t in[9], xombe_ds_frame *f) +{ + uint8_t d[XOMBE_DS_DATA_BITS]; + int i; + xombe__ds_deinterleave(in, &f->A, &f->B, &f->C); + f->ea = xombe__ds_golay24_decode(f->A, &f->da); + f->pn = xombe__ds_pn24(f->da); + f->eb = xombe__ds_golay24_decode(f->B ^ f->pn, &f->db); + for (i = 0; i < 12; i++) { + d[i] = (uint8_t)((f->da >> (11 - i)) & 1); + d[12 + i] = (uint8_t)((f->db >> (11 - i)) & 1); + } + for (i = 0; i < 24; i++) + d[24 + i] = (uint8_t)((f->C >> (23 - i)) & 1u); + xombe__ds_frame_from_data(d, f); +} + +void xombe__ds_frame_from_data(const uint8_t d[48], xombe_ds_frame *f) +{ + memcpy(f->d, d, XOMBE_DS_DATA_BITS); + xombe__ds_get_fields(f->d, f->b); + f->cls = xombe__ds_classify(f->b[0]); + f->T = f->AD = f->tid = -1; + if (f->cls == XOMBE_DS_TONE) { + f->T = xombe__ds_tone_index(f->d); + f->AD = xombe__ds_tone_level(f->d); + if (xombe__ds_tone_id[f->T] != XOMBE_DS_TONE_NONE) + f->tid = xombe__ds_tone_id[f->T]; + } +} + +void xombe__ds_encode_bits(const uint8_t d[48], uint8_t out[9]) +{ + uint32_t da = 0, db = 0, c = 0; + int i; + for (i = 0; i < 12; i++) { + da = (da << 1) | (d[i] & 1u); + db = (db << 1) | (d[12 + i] & 1u); + } + for (i = 24; i < 48; i++) + c = (c << 1) | (d[i] & 1u); + xombe__ds_interleave(xombe__ds_golay24_encode(da), xombe__ds_golay24_encode(db) ^ xombe__ds_pn24((int)da), c, + out); +} + +/* d of fields b, each clamped to its width, returns 0, or -1 if any was clamped */ +static int clamped_fields(const int b[9], uint8_t d[48]) +{ + int c[9], k, r = 0; + for (k = 0; k < 9; k++) { + int top = (1 << field_width[k]) - 1; + c[k] = b[k] < 0 ? 0 : b[k] > top ? top : b[k]; + r |= c[k] != b[k]; + } + xombe__ds_put_fields(c, d); + return r ? -1 : 0; +} + +int xombe__ds_encode_fields(const int b[9], uint8_t out[9]) +{ + uint8_t d[48]; + int r = clamped_fields(b, d); + xombe__ds_encode_bits(d, out); + return r; +} + +int xombe__ds_fields_bits(const int b[9], uint8_t bits[7]) +{ + uint8_t d[48]; + int r = clamped_fields(b, d); + xombe__ds_pack(d, bits); + return r; +} + +int xombe__ds_tone_q(float level) +{ + /* 2*level is exact in float, so no epsilon against double rounding */ + float q = floorf(2.0f * level); + if (!(q >= 16.0f)) /* also NaN */ + return 16; + return q > 254.0f ? 254 : (int)q; +} + +int xombe__ds_tone_code(int id) +{ + int T; + for (T = 0; T < 256; T++) + if (xombe__ds_tone_id[T] == id) + return T; + return -1; +} + +void xombe__ds_pack(const uint8_t d[48], uint8_t bits[7]) +{ + memset(bits, 0, 7); + xombe__pack_bits(d, XOMBE_DS_DATA_BITS, bits); +} + +void xombe__ds_unpack(const uint8_t bits[7], uint8_t d[48]) +{ + xombe__unpack_bits(bits, XOMBE_DS_DATA_BITS, d); +} + +void xombe__ds_fec_encode_bits(const uint8_t bits[7], uint8_t frame[9]) +{ + uint8_t d[XOMBE_DS_DATA_BITS]; + xombe__ds_unpack(bits, d); + xombe__ds_encode_bits(d, frame); +} + +unsigned xombe__ds_fec_decode_bits(xombe_fec *fec, const uint8_t frame[9], uint8_t bits[7], xombe_fec_stats *st) +{ + uint32_t A, B, C; + int da, db, ea, eb; + xombe_ds_err er; + xombe_ds_flags fl; + xombe__ds_deinterleave(frame, &A, &B, &C); + ea = xombe__ds_golay24_decode(A, &da); + eb = xombe__ds_golay24_decode(B ^ xombe__ds_pn24(da), &db); + da &= 0xFFF; + db &= 0xFFF; + bits[0] = (uint8_t)(da >> 4); + bits[1] = (uint8_t)(((da & 15) << 4) | (db >> 8)); + bits[2] = (uint8_t)db; + bits[3] = (uint8_t)(C >> 16); + bits[4] = (uint8_t)(C >> 8); + bits[5] = (uint8_t)C; + bits[6] = 0; + er.er = fec->er; + xombe__ds_err_update(&er, ea, eb, &fl); + fec->er = er.er; + st->eps0 = ea; + st->eps1 = eb; + st->eps_t = ea + eb; + st->bf = fl.bf; + st->hb = fl.hb; + st->eps_r = (uint32_t)(er.er * 16777216.0f + 0.5f); + return (fl.bf ? XOMBE_FLAG_BF : 0u) | (fl.hb ? XOMBE_FLAG_HB : 0u); +} + +int xombe__ds_tone_frame_id(int id, int ad, uint8_t out[9]) +{ + int T = xombe__tone_valid(id, ad) ? xombe__ds_tone_code(id) : -1; + if (T < 0) + return -1; + xombe__ds_tone_frame(T, xombe__ds_tone_q(XOMBE_DS_AD_LEVEL(ad)), out); + return 0; +} + +void xombe__ds_tone_bits(int T, int q, uint8_t d[48]) +{ + int j, F; + if (q < 16) + q = 16; + if (q > 254) + q = 254; + F = q / 2 - 8; + memset(d, 0, 48); + for (j = 0; j < 6; j++) + d[j] = 1; /* b0 = 126: bits 0..5 set, bit 47 clear */ + for (j = 0; j < 8; j++) + d[tone_t_bits[j]] = (uint8_t)((T >> (7 - j)) & 1); + for (j = 0; j < 7; j++) + d[tone_f_bits[j]] = (uint8_t)((F >> (6 - j)) & 1); + d[TONE_HALF_BIT] = (uint8_t)(q & 1); +} + +void xombe__ds_tone_frame(int T, int q, uint8_t out[9]) +{ + uint8_t d[48]; + xombe__ds_tone_bits(T, q, d); + xombe__ds_encode_bits(d, out); +} + +void xombe__ds_err_init(xombe_ds_err *s) +{ + s->er = 0.0f; +} + +void xombe__ds_err_update(xombe_ds_err *s, int ea, int eb, xombe_ds_flags *out) +{ + int eT = ea + eb; + s->er = 0.95f * s->er + 0.05f * (float)eT / 48.0f; + out->bf = ea >= 4; + out->hb = s->er > 0.096f; + if (eT < 6) + eT = eb = 0; + out->eT = eT; + out->e1 = eb; +} diff --git a/xombe/src/dstar/params.c b/xombe/src/dstar/params.c new file mode 100644 index 0000000..bcd6bb1 --- /dev/null +++ b/xombe/src/dstar/params.c @@ -0,0 +1,104 @@ +#include +#include +#include "dstar_internal.h" + +const xombe_amp_tables xombe__amp_dstar = { + xombe__ds_dg, 64, xombe__ds_prba24, 512, xombe__ds_prba58, 128, + {&xombe__ds_hoc5[0][0], &xombe__ds_hoc6[0][0], &xombe__ds_hoc7[0][0], &xombe__ds_hoc8[0][0]}, {16, 16, 16, 8}, + xombe__blk, xombe__ds_ok_dg, xombe__ds_ok_prba24, xombe__ds_ok_prba58, + {xombe__ds_ok_hoc5, xombe__ds_ok_hoc6, xombe__ds_ok_hoc7, xombe__ds_ok_hoc8}, + XOMBE_DS_RHO, XOMBE_DS_GRHO, XOMBE_DS_GAIN_MAX, XOMBE_AMP_MIN, XOMBE_DS_AMP_MAX}; + +#define DS_RESET_L 15 + +float xombe__ds_f0(int b0) +{ + return xombe__ds_w0[b0 & (XOMBE_DS_B0_COUNT - 1)]; +} + +int xombe__ds_b0_from_f0(float f0) +{ + int b = (int)floorf((log2f(f0) - XOMBE_DS_P0) / XOMBE_DS_P1); + return b < 0 ? 0 : b > XOMBE_DS_B0_VOICE_MAX ? XOMBE_DS_B0_VOICE_MAX : b; +} + +int xombe__ds_L(int b0) +{ + return xombe__ds_lt[b0 & (XOMBE_DS_B0_COUNT - 1)]; +} + +void xombe__ds_harm_voicing(const uint8_t V[8], float f0, int L, uint8_t vl[XOMBE_LMAX + 1]) +{ + int l; + vl[0] = 0; + for (l = 1; l <= L; l++) { + /* scripts/gen_dstar_tables.py checks this float index matches the double one for every voice b0 and + harmonic */ + int j = (int)((float)l * f0 * XOMBE_BANDS_PER_UNIT); + vl[l] = V[j < 7 ? j : 7]; + } +} + +void xombe__ds_amps(const int b[9], int L, int Lp, const float ap[XOMBE_LMAX + 1], float Gp, + float Tv[XOMBE_LMAX + 1], float *G, float a[XOMBE_LMAX + 1]) +{ + const xombe_amp_tables *ts = &xombe__amp_dstar; + float t[XOMBE_LMAX + 1], pt[XOMBE_LMAX + 1], g; + xombe__spectral_shape_ts(ts, b, L, t); + xombe__predict_from(Lp, ap, L, pt); + g = xombe__gain_ts(ts, b[2], Gp); + xombe__assemble_ts(ts, t, pt, L, g, a); + *G = g; + if (Tv) + memcpy(Tv, t, sizeof(t)); +} + +void xombe__ds_mirror_init(xombe_ds_mirror *m) +{ + memset(m, 0, sizeof(*m)); + m->L = DS_RESET_L; +} + +void xombe__ds_mirror_predict(const xombe_ds_mirror *m, int L, float pt[XOMBE_LMAX + 1]) +{ + xombe__predict_from(m->L, m->a, L, pt); +} + +void xombe__ds_dequant(const int b[9], const xombe_ds_mirror *m, xombe_ds_params *p) +{ + memcpy(p->b, b, sizeof(p->b)); + p->cls = xombe__ds_classify(b[0]); + p->T = p->tid = p->AD = -1; + if (p->cls != XOMBE_DS_VOICE) { + p->L = 0; + return; + } + p->f0 = xombe__ds_f0(b[0]); + p->L = xombe__ds_L(b[0]); + memcpy(p->V, xombe__ds_vuv[b[1] & 15], 8); + xombe__ds_harm_voicing(p->V, p->f0, p->L, p->vl); + xombe__ds_amps(b, p->L, m->L, m->a, m->G, p->Tv, &p->G, p->a); +} + +int xombe__ds_mirror_commit(xombe_ds_mirror *m, const int b[9], xombe_ds_params *p) +{ + xombe_ds_params tmp; + if (!p) + p = &tmp; + xombe__ds_dequant(b, m, p); + if (p->cls != XOMBE_DS_VOICE) + return 0; + m->L = p->L; + m->G = p->G; + memcpy(m->a, p->a, sizeof(m->a)); + return 1; +} + +int xombe__ds_params_from_frame(xombe_ds_mirror *m, const xombe_ds_frame *f, xombe_ds_params *p) +{ + int voice = xombe__ds_mirror_commit(m, f->b, p); + p->T = f->T; + p->tid = f->tid; + p->AD = f->AD; + return voice; +} diff --git a/xombe/src/dstar/trace.h b/xombe/src/dstar/trace.h new file mode 100644 index 0000000..8dd3126 --- /dev/null +++ b/xombe/src/dstar/trace.h @@ -0,0 +1,45 @@ +#ifndef XOMBE_DSTAR_TRACE_H +#define XOMBE_DSTAR_TRACE_H + +/* transcoder per-frame records for tests, filled when the state's trace pointer is set */ + +#include "../state.h" + +/* DMR -> D-STAR half of xombe_xc (xcode.c), dumped by test/dstar_dump_xc.c */ +typedef struct xombe_xc_trace { + int cls; /* AMBE+2 class, XOMBE_CLASS_ERASURE for a concealed frame */ + int conceal; /* enum xombe_conceal */ + int cls_out; /* class of the set transcoded (the played set when concealed) */ + int has_rb, rb[9]; /* AMBE+2 fields, frames decoded normally */ + int has_par; /* voice and silence sets: f0, L, a, V2 */ + float f0; /* cycles/sample */ + int L; + float a[XOMBE_LMAX + 1]; + uint8_t V2[8], V1[8]; + int has_v1; /* frames decoded normally: V1 and G */ + float G; + int pulse, tid, AD; /* tid, AD -1 when none */ + int has_soft; + float soft[4]; /* per-kHz voiced fraction */ + int tL, tb0; /* quantizer target tgt[1..tL] and its pitch, tb0 -1 when not quantized */ + float tgt[XOMBE_LMAX + 1]; + int has_b, b[9]; /* D-STAR fields of the output (of the resent frame for a resend) */ +} xombe_xc_trace; + +/* D-STAR -> DMR half of xombe_xc (xrev.c), dumped by test/dstar_dump_xrev.c */ +typedef struct xombe_xr_trace { + int in_cls; /* XOMBE_XR_IN_* (xc_state.h) */ + int scls; /* class of the D-STAR decoder's played set */ + int has_db, db[9]; /* D-STAR fields, frames not lost */ + int has_par; /* voice and silence sets: f0, L, a */ + float f0; + int L; + float a[XOMBE_LMAX + 1]; + int tid, AD; /* -1 when none */ + int tL; /* quantizer target tgt[1..tL], 0 when not quantized */ + float tgt[XOMBE_LMAX + 1]; + int has_b, b[9]; /* AMBE+2 fields of voice and pulse frames */ + uint8_t d49[49]; +} xombe_xr_trace; + +#endif diff --git a/xombe/src/dstar/xc.c b/xombe/src/dstar/xc.c new file mode 100644 index 0000000..7dbb239 --- /dev/null +++ b/xombe/src/dstar/xc.c @@ -0,0 +1,81 @@ +#include +#include "../internal.h" +#include "xc_state.h" + +/* xombe_xc: the DMR -> D-STAR half (xcode.c) or the D-STAR -> DMR half (xrev.c) by the input codec, each reached + only through its own init so a program using one leaves the other out */ + +XOMBE_STATIC_ASSERT(sizeof(struct xombe_xc_own) <= XOMBE_XC_SIZE, xc_state_fits_XOMBE_XC_SIZE); +XOMBE_STATIC_ASSERT(sizeof(struct xombe_xc) <= XOMBE_XC_SHARED_SIZE, xc_state_fits_XOMBE_XC_SHARED_SIZE); +XOMBE_STATIC_ASSERT(sizeof(xombe_cq_ws) <= XOMBE_QWS_SIZE, cq_ws_fits_XOMBE_QWS_SIZE); + +size_t xombe_xc_size(void) +{ + return sizeof(struct xombe_xc_own); +} + +static int fwd_frame(xombe_xc *x, const uint8_t in[9], unsigned flags, uint8_t out[9]) +{ + return xombe__xc_fwd_frame(&x->u.f, in, flags, out); +} + +xombe_xc *xombe__xc_init_shared_dmr(void *mem, void *ws) +{ + xombe_xc *x = mem; + if (!x || !ws) + return NULL; + xombe__xc_fwd_init(&x->u.f, ws); + x->from = XOMBE_DMR; + x->frame = fwd_frame; + return x; +} + +#if XOMBE_HAVE_ENCODER +static int rev_frame(xombe_xc *x, const uint8_t in[9], unsigned flags, uint8_t out[9]) +{ + return xombe__xc_rev_frame(&x->u.r, in, flags, out); +} +#endif + +xombe_xc *xombe__xc_init_shared_dstar(void *mem, void *ws) +{ +#if XOMBE_HAVE_ENCODER + xombe_xc *x = mem; + if (!x || !ws) + return NULL; + xombe__xc_rev_init(&x->u.r, ws); + x->from = XOMBE_DSTAR; + x->frame = rev_frame; + return x; +#else + (void)mem; + (void)ws; + return NULL; +#endif +} + +xombe_xc *xombe__xc_init_dmr(void *mem) +{ + return mem ? xombe__xc_init_shared_dmr(mem, &((struct xombe_xc_own *)mem)->ws) : NULL; +} + +xombe_xc *xombe__xc_init_dstar(void *mem) +{ + return mem ? xombe__xc_init_shared_dstar(mem, &((struct xombe_xc_own *)mem)->ws) : NULL; +} + +int xombe_xc_frame(xombe_xc *x, const uint8_t in[XOMBE_FRAME_BYTES], unsigned flags, uint8_t out[XOMBE_FRAME_BYTES]) +{ + return x->frame(x, in, flags, out); +} + +void xombe_xc_decision_get(const xombe_xc *x, xombe_xc_decision *out) +{ + if (x->from == XOMBE_DSTAR) { + out->in = x->u.r.d.decision; + out->out = (enum xombe_xc_out)x->u.r.out; + } else { + out->in = x->u.f.d.decision; + out->out = (enum xombe_xc_out)x->u.f.out; + } +} diff --git a/xombe/src/dstar/xc_state.h b/xombe/src/dstar/xc_state.h new file mode 100644 index 0000000..7a96f3a --- /dev/null +++ b/xombe/src/dstar/xc_state.h @@ -0,0 +1,65 @@ +#ifndef XOMBE_XC_STATE_H +#define XOMBE_XC_STATE_H + +/* transcoder state behind xombe.h's xombe_xc handle (xc.c), the DMR -> D-STAR half (xcode.c) and the + D-STAR -> DMR half (xrev.c) */ + +#include "dstar_internal.h" +#include "dsd_state.h" +#include "../common/cquant.h" + +struct xombe_xc_trace; +struct xombe_xr_trace; + +/* DMR -> D-STAR */ +typedef struct { + xombe_dec_core d; /* DMR frame logic and sets */ + xombe_fec fec; + xombe_ds_mirror mirror; /* D-STAR decoder's prediction memory */ + uint8_t last[XOMBE_DS_FRAME_BYTES]; + int have_last_b, last_b[9]; /* fields of last, if it was a voice frame */ + int out; /* enum xombe_xc_out of the last frame */ + struct xombe_xc_trace *trace; /* trace.h */ + xombe_cq_ws *ws; /* quantizer workspace, own or shared, nothing in it lives between frames */ +} xombe_xc_fwd; + +enum { XOMBE_XR_IN_VOICE, XOMBE_XR_IN_TONE, XOMBE_XR_IN_NULL, XOMBE_XR_IN_REPEAT, XOMBE_XR_IN_MUTE }; + +/* D-STAR -> DMR */ +typedef struct { + xombe_dec_core d; /* D-STAR frame logic and sets (with s) */ + xombe_dsd_logic s; + xombe_fec fec; + xombe_pred pi; /* DMR decoder's prediction memory */ + int prev_b1; /* previous D-STAR voice frame's b1, -1 after any other frame but a repeat */ + int have_last, last_db[9]; /* fields of the last good D-STAR voice frame */ + int have_tone, tone_id, tone_ad; + int out; + struct xombe_xr_trace *trace; + xombe_cq_ws *ws; +} xombe_xc_rev; + +struct xombe_xc { + int from; /* enum xombe_codec */ + int (*frame)(struct xombe_xc *x, const uint8_t in[9], unsigned flags, uint8_t out[9]); + union { + xombe_xc_fwd f; + xombe_xc_rev r; + } u; +}; + +/* xombe_xc_init's layout: the state, then its own workspace */ +struct xombe_xc_own { + struct xombe_xc x; + xombe_cq_ws ws; +}; + +/* each half's init (ws zeroed here), frame, and output class */ +void xombe__xc_fwd_init(xombe_xc_fwd *x, xombe_cq_ws *ws); +int xombe__xc_fwd_frame(xombe_xc_fwd *x, const uint8_t in[9], unsigned flags, uint8_t out[9]); +#if XOMBE_HAVE_ENCODER +void xombe__xc_rev_init(xombe_xc_rev *x, xombe_cq_ws *ws); +int xombe__xc_rev_frame(xombe_xc_rev *x, const uint8_t in[9], unsigned flags, uint8_t out[9]); +#endif + +#endif diff --git a/xombe/src/dstar/xcode.c b/xombe/src/dstar/xcode.c new file mode 100644 index 0000000..cfd76c6 --- /dev/null +++ b/xombe/src/dstar/xcode.c @@ -0,0 +1,254 @@ +#include +#include +#include "../internal.h" +#include "../common/tone_table.h" +#include "xc_state.h" +#include "trace.h" + +/* AMBE+2 rate-33 -> D-STAR parameter transcoder */ + +#define XC_VTHR 0.5f /* band voiced if its energy-weighted voiced fraction is above this */ +#define XC_KNOX_REST 4.0f /* transcoder's other Knox harmonics this far below the tones, log2 */ +#define XC_PULSE_FIRST 18 /* AMBE+2 pulse frames: b1 18..31 */ +#define XC_PULSE_LAST 31 + +/* AMBE+2 pulse frame b1 18..31 -> D-STAR b0 as DVSI converts it, 30 -> 80 inferred as the one unused value of + the 64..116 step-4 grid */ +static const uint8_t pulse_b0[XC_PULSE_LAST - XC_PULSE_FIRST + 1] = {88, 92, 96, 100, 64, 68, 112, 116, + 72, 76, 104, 108, 80, 84}; + +void xombe__xc_fwd_init(xombe_xc_fwd *x, xombe_cq_ws *ws) +{ + static const uint8_t null_frame[XOMBE_DS_FRAME_BYTES] = XOMBE_DS_NULL_FRAME; + memset(x, 0, sizeof(*x)); + x->ws = ws; + memset(x->ws, 0, sizeof(*x->ws)); + x->ws->cap = XOMBE_CQ_CAP; + xombe__dec_core_reset(&x->d); + xombe__fec_init_dmr(&x->fec); + xombe__ds_mirror_init(&x->mirror); + memcpy(x->last, null_frame, XOMBE_DS_FRAME_BYTES); +} + +/* energy-weighted voiced fraction per 1 kHz band of harmonics 1..L, harmonic voicing with AMBE+2's +250 Hz OR */ +static void band_soft(const float *a, int L, float f0, const uint8_t V[8], float s[4]) +{ + float num[4] = {0.0f, 0.0f, 0.0f, 0.0f}, den[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + float f = f0 * XOMBE_FS; + int l, j; + for (l = 1; l <= L; l++) { + float fr = (float)l * f, w; + int j1, j2; + j = (int)(fr / 1000.0f); + if (j > 3) + continue; + j1 = (int)(fr / 500.0f); + j2 = (int)((fr + 250.0f) / 500.0f); + w = exp2f(2.0f * a[l]); + num[j] += (V[j1 > 7 ? 7 : j1] || V[j2 > 7 ? 7 : j2]) ? w : 0.0f; + den[j] += w; + } + for (j = 0; j < 4; j++) + s[j] = den[j] > 0.0f ? num[j] / den[j] : 0.0f; +} + +/* the code nearest the per-band decisions s > XC_VTHR (bit 3 = 0..1 kHz), never XOMBE_DS_B1_SKIP: least sum of + |s - XC_VTHR| over the bands it flips, first on ties */ +static int b1_from_soft(const float s[4]) +{ + float best = 0.0f; + int c, j, want = 0, bc = -1; + for (j = 0; j < 4; j++) + want |= (s[j] > XC_VTHR) << (3 - j); + for (c = 0; c < 16; c++) { + float cost = 0.0f; + if (c == XOMBE_DS_B1_SKIP) + continue; + for (j = 0; j < 4; j++) + if (((c ^ want) >> (3 - j)) & 1) + cost += fabsf(s[j] - XC_VTHR); + if (bc < 0 || cost < best) { + best = cost; + bc = c; + } + } + return bc; +} + +/* a[1..L] at harmonics of f0 -> D-STAR voice frame: resampled linearly in harmonic number to the harmonics of + b0 (nearest pitch of f0 if b0 < 0), quantized against the mirror and committed */ +static void requant(xombe_xc_fwd *x, float f0, const float *a, int L, int b1, int b0, int b[9]) +{ + float tgt[XOMBE_LMAX + 1], w[XOMBE_LMAX + 1], pt[XOMBE_LMAX + 1], f0d; + xombe_cq_result res; + int Ld, l, k; + if (b0 < 0) + b0 = xombe__ds_b0_from_f0(f0); + f0d = xombe__ds_f0(b0); + Ld = xombe__ds_L(b0); + tgt[0] = 0.0f; + for (l = 1; l <= Ld; l++) { + float h = (float)l * f0d / f0, fr; + int i; + h = h < 1.0f ? 1.0f : h > (float)L ? (float)L : h; + i = (int)h; + fr = h - (float)i; + tgt[l] = (1.0f - fr) * a[i] + fr * a[i < L ? i + 1 : L]; + } + xombe__cq_amp_weights(tgt, Ld, XOMBE_CQ_QWEIGHT, XOMBE_CQ_WEIGHT_FLOOR, w); + xombe__ds_mirror_predict(&x->mirror, Ld, pt); + xombe__cq_quantize(x->ws, &xombe__amp_dstar, tgt, Ld, pt, x->mirror.G, w, 1, XOMBE_CQ_N_PAIRS, XOMBE_CQ_N_GAIN, + XOMBE_CQ_ITERS, XOMBE_CQ_CLIP_PASSES, &res); + b[0] = b0; + b[1] = b1; + for (k = 2; k < 9; k++) + b[k] = res.b[k]; + xombe__ds_mirror_commit(&x->mirror, b, NULL); + if (x->trace) { + x->trace->tL = Ld; + x->trace->tb0 = b0; + memcpy(x->trace->tgt, tgt, sizeof(tgt)); + } +} + +/* Knox tone as a voice frame at the table f0: the two tone harmonics at the tone level + log2 min(16384 * 10^(0.03555 (AD - 127)), 2^14), the others XC_KNOX_REST below, all bands voiced. + returns 0 if the tone table has no pair for id */ +static int knox(xombe_xc_fwd *x, int id, int AD, int b[9]) +{ + float f0hz, f0, lm, a[XOMBE_LMAX + 1]; + int l1, l2, L, l; + xombe__tone_harmonics(id, &f0hz, &l1, &l2); + if (l1 <= 0 || l2 <= 0) + return 0; + f0 = f0hz / XOMBE_FS; + lm = XOMBE_TONE_AD_LOG10 * (float)(AD - 127) * XOMBE_LOG2_10; + lm = (lm > 0.0f ? 0.0f : lm) + 14.0f; + L = xombe__L_from_f0(f0); + for (l = 1; l <= L; l++) + a[l] = lm - XC_KNOX_REST; + if (l1 <= L) + a[l1] = lm; + if (l2 <= L) + a[l2] = lm; + requant(x, f0, a, L, XOMBE_DS_B1_VOICED, -1, b); + return 1; +} + +/* silence and pulse pitches 250.60 Hz and 64.346 Hz as the 2^-19 fractions consts.h rounds, the resampling + positions l * f0d / f0 otherwise move by up to 1.2e-5 relative, enough to change quantizer picks */ +static float exact_f0(float f0) +{ + if (f0 == XOMBE_SILENCE_F0) + return 16423.0f / 524288.0f; + if (f0 == XOMBE_PULSE_F0) + return 4217.0f / 524288.0f; + return f0; +} + +int xombe__xc_fwd_frame(xombe_xc_fwd *x, const uint8_t in[9], unsigned flags, uint8_t out[9]) +{ + xombe_dec_core *d = &x->d; + const xombe_decision *dc = &d->decision; + xombe_xc_trace *tr = x->trace; + const xombe_set *s = &d->p2; + uint8_t bits[7]; + int b[9], id = -1, ad = -1, voice_b = 0, cls; + memset(bits, 0, sizeof(bits)); + xombe__dec_start_air(d, &x->fec, in, flags, bits); + xombe__dec_skip_synth(d); + cls = s->cls; + if (cls == XOMBE_CLASS_TONE && dc->conceal == XOMBE_CONCEAL_NONE) { + uint8_t d49[49]; + xombe__unpack49(bits, d49); + xombe__tone_frame_parse(d49, &id, &ad); + } + if (tr) { + uint8_t d49[49]; + memset(tr, 0, sizeof(*tr)); + tr->cls = dc->cls; + tr->conceal = dc->conceal; + tr->cls_out = cls; + tr->tid = tr->AD = tr->tb0 = -1; + if (dc->conceal == XOMBE_CONCEAL_NONE) { + xombe__unpack49(bits, d49); + if (cls != XOMBE_CLASS_TONE) { + tr->has_rb = tr->has_v1 = 1; + xombe__get_fields(d49, tr->rb); + memcpy(tr->V1, d->p1.vb, 8); + tr->G = d->pi.gamma; + } + } + } + if (cls == XOMBE_CLASS_TONE && dc->conceal != XOMBE_CONCEAL_NONE) { + /* the AMBE+2 decoder replays the tone set: resend the last frame, which the D-STAR decoder decodes anew */ + if (x->have_last_b) + xombe__ds_mirror_commit(&x->mirror, x->last_b, NULL); + memcpy(out, x->last, XOMBE_DS_FRAME_BYTES); + x->out = XOMBE_XC_OUT_RESEND; + if (tr && x->have_last_b) { + tr->has_b = 1; + memcpy(tr->b, x->last_b, sizeof(tr->b)); + } + return 1; + } + if (cls == XOMBE_CLASS_TONE) { + int T = xombe__ds_tone_code(id); + if (tr) { + tr->tid = id; + tr->AD = ad; + } + if (T >= 0) { + xombe__ds_tone_frame(T, xombe__ds_tone_q(XOMBE_DS_AD_LEVEL(ad)), out); + x->out = XOMBE_XC_OUT_TONE; + } else if (id >= XOMBE_TONE_KNOX_FIRST && id < XOMBE_TONE_KNOX_FIRST + XOMBE_TONE_KNOX_COUNT && + knox(x, id, ad, b)) { + voice_b = 1; + x->out = XOMBE_XC_OUT_KNOX; + } else { + memcpy(out, x->last, XOMBE_DS_FRAME_BYTES); + x->out = XOMBE_XC_OUT_RESEND; + x->have_last_b = 0; + return 1; + } + } else { + /* voice, or silence as an all-unvoiced voice frame from its comfort-noise amplitudes */ + float soft[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + int pulse = 0, b0 = -1; + if (cls == XOMBE_CLASS_VOICE && dc->conceal == XOMBE_CONCEAL_NONE) { + uint8_t d49[49]; + int rb[9]; + xombe__unpack49(bits, d49); + xombe__get_fields(d49, rb); + pulse = rb[1] >= XC_PULSE_FIRST && rb[1] <= XC_PULSE_LAST; + if (pulse) + b0 = pulse_b0[rb[1] - XC_PULSE_FIRST]; + } + if (cls == XOMBE_CLASS_VOICE && !pulse) + band_soft(s->a, s->L, s->f0, s->vb, soft); + if (tr) { + tr->has_par = 1; + tr->f0 = s->f0; + tr->L = s->L; + memcpy(tr->a, s->a, sizeof(tr->a)); + memcpy(tr->V2, s->vb, 8); + tr->pulse = pulse; + tr->has_soft = cls == XOMBE_CLASS_VOICE && !pulse; + memcpy(tr->soft, soft, sizeof(soft)); + } + requant(x, exact_f0(s->f0), s->a, s->L, b1_from_soft(soft), b0, b); + voice_b = 1; + x->out = XOMBE_XC_OUT_VOICE; + } + if (voice_b) + xombe__ds_encode_fields(b, out); + memcpy(x->last, out, XOMBE_DS_FRAME_BYTES); + x->have_last_b = voice_b; + if (voice_b) + memcpy(x->last_b, b, sizeof(b)); + if (tr && voice_b) { + tr->has_b = 1; + memcpy(tr->b, b, sizeof(b)); + } + return 1; +} diff --git a/xombe/src/dstar/xrev.c b/xombe/src/dstar/xrev.c new file mode 100644 index 0000000..d9fa6b5 --- /dev/null +++ b/xombe/src/dstar/xrev.c @@ -0,0 +1,205 @@ +#include +#include "../internal.h" +#include "../common/bits.h" +#include "../common/tone_table.h" +#include "../tables/dsp_tables.h" +#include "xc_state.h" +#include "trace.h" + +/* D-STAR -> AMBE+2 rate-33 parameter transcoder */ + +#define XR_OCTAVE_F0 (400.0f / 8000.0f) /* pitches above take the AMBE+2 index of half their f0 */ +#define XR_PULSE_F0 (4217.0f / 524288.0f) /* the pulse pitch as the 2^-19 fraction XOMBE_PULSE_F0 rounds */ + +/* all-unvoiced D-STAR b0 -> AMBE+2 pulse code b1 18..31, DVSI's conversion where seen, else the pulse whose + AMBE+2 -> D-STAR b0 is nearest, first on ties. 0: a plain all-unvoiced frame */ +static const uint8_t pulse_code[XOMBE_DS_B0_VOICE_MAX + 1] = { + 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, + 22, 22, 22, 22, 22, 22, 22, 22, 22, 0, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, + 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 0, 22, 0, 23, 23, 0, 26, 26, 0, 0, + 27, 0, 28, 27, 30, 30, 30, 0, 0, 31, 31, 0, 18, 18, 20, 19, 19, 19, 20, 23, 21, 20, 0, 21, 21, + 0, 20, 20, 20, 28, 28, 27, 28, 29, 31, 27, 28, 24, 24, 24, 25, 25, 25, 19, 0, 25, 25, 25, 25}; + +/* D-STAR b1 -> AMBE+2 b1 by the previous D-STAR frame: DVSI's conversion where seen, else the code nearest in + Hamming distance to the D-STAR bands each split in two. rows: previous b1 <= 0 or not a voice frame, 15, + anything else */ +static const uint8_t vuv_map[3][16] = {{16, 16, 14, 5, 16, 0, 4, 0, 12, 8, 6, 6, 10, 7, 9, 0}, + {16, 16, 14, 5, 16, 0, 4, 0, 12, 8, 6, 6, 9, 7, 4, 0}, + {16, 16, 14, 5, 16, 0, 4, 0, 12, 8, 6, 6, 8, 7, 0, 0}}; + +static const uint8_t std_silence[7] = XOMBE_SILENCE_FRAME; + +void xombe__xc_rev_init(xombe_xc_rev *x, xombe_cq_ws *ws) +{ + memset(x, 0, sizeof(*x)); + xombe__dec_core_reset(&x->d); + xombe__dsd_logic_init(&x->s, &x->d); + xombe__fec_init_dstar(&x->fec); + xombe__pred_init(&x->pi); + x->ws = ws; + memset(x->ws, 0, sizeof(*x->ws)); + x->ws->cap = XOMBE_CQ_CAP; + x->prev_b1 = -1; +} + +/* nearest AMBE+2 pitch index in log f0, the lower index on ties */ +static int a2_b0(float f0) +{ + int b = 0; + if (f0 > XR_OCTAVE_F0) + f0 *= 0.5f; + while (b < XOMBE_B0_COUNT - 1 && f0 < xombe__w0_mid[b]) + b++; + return b; +} + +/* a[1..L] at harmonics of f0 -> AMBE+2 frame b0, b1 at L2 harmonics of f2: resampled linearly in harmonic + number, quantized against the prediction memory and stored */ +static void requant(xombe_xc_rev *x, float f0, const float *a, int L, int b0, int b1, int L2, float f2, + const uint8_t v2[8], uint8_t d49[49]) +{ + float tgt[XOMBE_LMAX + 1], w[XOMBE_LMAX + 1]; + xombe_cq_result res; + xombe_params rec; + int b[9], l, k; + tgt[0] = 0.0f; + for (l = 1; l <= L2; l++) { + float h = (float)l * f2 / f0, fr; + int i; + h = h < 1.0f ? 1.0f : h > (float)L ? (float)L : h; + i = (int)h; + fr = h - (float)i; + tgt[l] = (1.0f - fr) * a[i] + fr * a[i < L ? i + 1 : L]; + } + xombe__cq_amp_weights(tgt, L2, XOMBE_CQ_QWEIGHT, XOMBE_CQ_WEIGHT_FLOOR, w); + xombe__cq_search_ambe2(x->ws, &x->pi, tgt, L2, w, XOMBE_CQ_N_PAIRS, XOMBE_CQ_N_GAIN, &res, NULL, NULL); + b[0] = b0; + b[1] = b1; + for (k = 2; k < 9; k++) + b[k] = res.b[k]; + xombe__dequant(b, &x->pi, 0, &rec); + xombe__pred_store_voice(&x->pi, &rec, v2); + memset(d49, 0, 49); + xombe__put_fields(b, d49); + if (x->trace) { + x->trace->tL = L2; + memcpy(x->trace->tgt, tgt, sizeof(tgt)); + x->trace->has_b = 1; + memcpy(x->trace->b, b, sizeof(b)); + } +} + +/* the voice set (f0, a[1..L]) with fields db of its D-STAR frame -> AMBE+2 voice or pulse frame */ +static int voice(xombe_xc_rev *x, const int db[9], float f0, const float *a, int L, uint8_t d49[49]) +{ + static const uint8_t unvoiced[8]; + int code = db[1] == 0 ? pulse_code[db[0]] : 0, b0, b1; + if (code) { + /* pulse positions by code, DVSI's choice for 26..31 varies (24 or 103) */ + b0 = code <= 23 ? 103 : code <= 25 ? 30 : 24; + requant(x, f0, a, L, b0, code, XOMBE_PULSE_L, XR_PULSE_F0, unvoiced, d49); + return XOMBE_XC_OUT_PULSE; + } + b1 = vuv_map[x->prev_b1 <= 0 ? 0 : x->prev_b1 == 15 ? 1 : 2][db[1]]; + /* DVSI's first-half codebook choice by the previous output's bands */ + if (b1 == 0 && memchr(x->pi.v2, 0, 8)) + b1 = 1; + else if (b1 == XOMBE_UNVOICED_B1 && memchr(x->pi.v2, 1, 8)) + b1 = XOMBE_UNVOICED_B1 + 1; + b0 = a2_b0(f0); + requant(x, f0, a, L, b0, b1, xombe__lt[b0], xombe__w0[b0], xombe__vuv[b1], d49); + return XOMBE_XC_OUT_VOICE; +} + +static int tone(xombe_xc_rev *x, int id, int ad, uint8_t d49[49]) +{ + xombe__tone_frame_bits(id, ad, d49); + xombe__pred_store_other(&x->pi, XOMBE_CLASS_TONE); + return XOMBE_XC_OUT_TONE; +} + +static int silence(xombe_xc_rev *x, uint8_t d49[49]) +{ + xombe__unpack49(std_silence, d49); + xombe__pred_store_other(&x->pi, XOMBE_CLASS_SILENCE); + return XOMBE_XC_OUT_SILENCE; +} + +int xombe__xc_rev_frame(xombe_xc_rev *x, const uint8_t in[9], unsigned flags, uint8_t out[9]) +{ + xombe_dsd_logic *s = &x->s; + const xombe_set *p = &x->d.p2; + xombe_xr_trace *tr = x->trace; + xombe_ds_frame f; + xombe_fec_stats st; + uint8_t d49[49], bits[7]; + int lost = (flags & XOMBE_FLAG_LOST) != 0, ic, o; + if (lost) { + xombe__dsd_start_frame(s, &x->d, NULL, 0, 0, 0); + } else { + uint8_t data[XOMBE_DS_DATA_BITS]; + unsigned fl = xombe_fec_decode(&x->fec, in, bits, &st); + xombe__ds_unpack(bits, data); + xombe__ds_frame_from_data(data, &f); + xombe__dsd_start_frame(s, &x->d, &f, fl, st.eps_t, st.eps1); + x->d.decision.e0 = st.eps0; + x->d.decision.e1 = st.eps1; + } + xombe__dec_skip_synth(&x->d); + if (s->log == XOMBE_DSD_LOG_MUTE) + ic = XOMBE_XR_IN_MUTE; + else if (s->log == XOMBE_DSD_LOG_NULL) + ic = XOMBE_XR_IN_NULL; + else if (x->d.decision.conceal != XOMBE_CONCEAL_NONE) + ic = XOMBE_XR_IN_REPEAT; + else + ic = s->log == XOMBE_DSD_LOG_TONE ? XOMBE_XR_IN_TONE : XOMBE_XR_IN_VOICE; + if (tr) { + memset(tr, 0, sizeof(*tr)); + tr->in_cls = ic; + tr->scls = p->cls; + tr->tid = tr->AD = -1; + if (!lost) { + tr->has_db = 1; + memcpy(tr->db, f.b, sizeof(f.b)); + } + if (p->cls == XOMBE_CLASS_VOICE || p->cls == XOMBE_CLASS_SILENCE) { + tr->has_par = 1; + tr->f0 = p->f0; + tr->L = p->L; + memcpy(tr->a, p->a, sizeof(tr->a)); + } + } + if (ic == XOMBE_XR_IN_VOICE) { + x->have_last = 1; + memcpy(x->last_db, f.b, sizeof(f.b)); + o = voice(x, f.b, p->f0, p->a, p->L, d49); + x->prev_b1 = f.b[1]; + } else if (ic == XOMBE_XR_IN_TONE) { + x->have_tone = 1; + x->tone_id = f.tid; + x->tone_ad = f.AD; + x->prev_b1 = -1; + o = tone(x, f.tid, f.AD, d49); + if (tr) { + tr->tid = f.tid; + tr->AD = f.AD; + } + } else if (ic == XOMBE_XR_IN_REPEAT && p->cls == XOMBE_CLASS_VOICE && x->have_last) { + o = voice(x, x->last_db, p->f0, p->a, p->L, d49); + } else if (ic == XOMBE_XR_IN_REPEAT && p->cls == XOMBE_CLASS_TONE && x->have_tone) { + o = tone(x, x->tone_id, x->tone_ad, d49); + if (tr) + tr->tid = x->tone_id; + } else { + if (ic != XOMBE_XR_IN_REPEAT) + x->prev_b1 = -1; + o = silence(x, d49); + } + xombe__pack49(d49, bits); + xombe__fec_encode_dmr(bits, out); + x->out = o; + if (tr) + memcpy(tr->d49, d49, 49); + return 1; +} diff --git a/xombe/src/enc/ambe2_enc.c b/xombe/src/enc/ambe2_enc.c new file mode 100644 index 0000000..9554117 --- /dev/null +++ b/xombe/src/enc/ambe2_enc.c @@ -0,0 +1,146 @@ +#include +#include +#include "frontend.h" +#include "../tables/dsp_tables.h" +#include "../common/cquant.h" +#if XOMBE_HAVE_DSTAR +#include "../dstar/dstar_enc.h" + +/* D-STAR back end's workspace: the two emits never overlap, and xombe__cq_prepare rebuilds its maps when the + table set changes, so D-STAR output is unaffected */ +#define A2_CQ_WS(e) (&XOMBE_DS_ENC(e)->ws) +#else +#define A2_CQ_WS(e) ((xombe_cq_ws *)(void *)(e)->cq.bytes) +XOMBE_STATIC_ASSERT(sizeof(xombe_cq_ws) <= XOMBE_ENC_CQ_SIZE, cq_ws_fits_XOMBE_ENC_CQ_SIZE); +#endif + +/* AMBE+2 back end, phases B and D of frontend.h */ + +/* pitch index nearest fhat on a log scale, ties to the higher pitch (xombe__w0 descends) */ +static int nearest_pitch_index(float fhat) +{ + int b = 0; + while (b < XOMBE_B0_COUNT - 1 && fhat < xombe__w0_mid[b]) + b++; + return b; +} + +static int any_above_half(const float a[8]) +{ + int j; + for (j = 0; j < 8; j++) + if (a[j] > 0.5f) + return 1; + return 0; +} + +static void choose_pitch_and_voicing(xombe_enc *e, xombe_fe_frame *a, xombe_a2_frame *f) +{ + float w1[8], w2[8], f0, fh1; + int *b = f->b; + xombe__fe_voice(e, a); + b[0] = nearest_pitch_index(a->fstar); + f0 = xombe__w0[b[0]]; + fh1 = e->pi.cls == XOMBE_CLASS_VOICE ? sqrtf(e->pi.f0 * f0) : f0; + xombe__voicing_soft(e, &a->S1, fh1, e->voicing_scale, f->soft1, w1); + xombe__voicing_soft_sp(e, xombe__fe_s2_prepared(e, a), f0, e->voicing_scale, f->soft2, w2); + if (!a->speech1) + memset(f->soft1, 0, sizeof(f->soft1)); + if (!a->speech2) + memset(f->soft2, 0, sizeof(f->soft2)); + b[1] = xombe__choose_b1(f->soft2, w2, f->soft1, w1, e->pi.v2); + xombe__v2_from_b1(b[1], f->v2); +} + +/* voice frames only, silence's gain offset and fixed L stay open loop. the workspace starts zeroed + (xombe_enc_init), cap is set on every call */ +static void quantize_closed(xombe_enc *e, int L, const float *target, int b[9]) +{ + xombe_cq_ws *ws = A2_CQ_WS(e); + float w[XOMBE_LMAX + 1]; + xombe_cq_result res; + int k; + ws->cap = XOMBE_CQ_CAP; + xombe__cq_amp_weights(target, L, XOMBE_CQ_QWEIGHT, XOMBE_CQ_WEIGHT_FLOOR, w); + xombe__cq_search_ambe2(ws, &e->pi, target, L, w, XOMBE_CQ_N_PAIRS, XOMBE_CQ_N_GAIN, &res, NULL, NULL); + for (k = 2; k < 9; k++) + b[k] = res.b[k]; +} + +static void emit_quantized(xombe_enc *e, int silence, int L, float target[XOMBE_LMAX + 1], int b[9], + const uint8_t v2[8], uint8_t d[49]) +{ + int l; + for (l = 1; l <= L; l++) + target[l] = xombe__clamp_amp(target[l]); + XOMBE_TAP(e, XOMBE_STAGE_TARGET, silence ? XOMBE_SILENCE_F0 : xombe__w0[b[0]], target + 1, L); + if (!silence && e->cfg.dmr_quant == XOMBE_ENC_QUANT_CLOSED) + quantize_closed(e, L, target, b); + else + xombe__quantize(&e->pi, silence, L, target, b); + memset(d, 0, 49); + xombe__put_fields(b, d); + if (silence) { + xombe__pred_store_other(&e->pi, XOMBE_CLASS_SILENCE); + } else { + xombe_params rec; + xombe__dequant(b, &e->pi, 0, &rec); + xombe__pred_store_voice(&e->pi, &rec, v2); + } +} + +static void emit_voice(xombe_enc *e, const xombe_fe_frame *a, const xombe_a2_frame *f, const xombe_be_ns *ns, + int b[9], uint8_t d[49]) +{ + float f0 = xombe__w0[b[0]], Pw[XOMBE_SPEC_BINS], target[XOMBE_LMAX + 1]; + int L = xombe__lt[b[0]]; + xombe__kern_bin_power(&a->S2, a->win_sum2, Pw); + xombe__enc_integrate(Pw, L, f0, target); + xombe__enc_hf_precomp(target, L, f0); + if (e->cfg.ns) + xombe__ns_apply_voice(ns->G2, target, L, f0, f->v2); + emit_quantized(e, 0, L, target, b, f->v2, d); +} + +static void emit_silence(xombe_enc *e, uint8_t d[49]) +{ + static const uint8_t no_voicing[8]; + float target[XOMBE_LMAX + 1]; + int b[9]; + xombe__cn_targets(e, target); + if (e->cfg.ns) + xombe__ns_apply_silence(e, target, XOMBE_SILENCE_L, XOMBE_SILENCE_F0); + b[0] = XOMBE_SILENCE_B0; + b[1] = XOMBE_SILENCE_B1; + emit_quantized(e, 1, XOMBE_SILENCE_L, target, b, no_voicing, d); +} + +void xombe__a2_voicing(xombe_enc *e, xombe_fe_frame *a, xombe_a2_frame *f, xombe_be_ns *ns) +{ + f->cls = a->tone ? XOMBE_CLASS_TONE : (a->active || !e->cfg.dmr_dtx) ? XOMBE_CLASS_VOICE : XOMBE_CLASS_SILENCE; + memset(f->v2, 0, sizeof(f->v2)); + memset(f->soft1, 0, sizeof(f->soft1)); + memset(f->soft2, 0, sizeof(f->soft2)); + if (f->cls == XOMBE_CLASS_VOICE) + choose_pitch_and_voicing(e, a, f); + ns->no_band_voiced[0] = !any_above_half(f->soft1); + ns->no_band_voiced[1] = !any_above_half(f->soft2); + ns->mem = &e->ns_mem; + if (e->cfg.ns) + xombe__ns_bin_voicing(f->v2, 1, ns->vbin); +} + +void xombe__a2_emit(xombe_enc *e, const xombe_fe_frame *a, xombe_a2_frame *f, const xombe_be_ns *ns, + uint8_t bits[7]) +{ + uint8_t d[49]; + if (f->cls == XOMBE_CLASS_TONE) { + xombe__tone_frame_bits(a->tone_id, a->tone_ad, d); + xombe__pred_store_other(&e->pi, XOMBE_CLASS_TONE); + } else if (f->cls == XOMBE_CLASS_VOICE) { + emit_voice(e, a, f, ns, f->b, d); + } else { + emit_silence(e, d); + } + xombe__pack49(d, bits); +} diff --git a/xombe/src/enc/analysis.c b/xombe/src/enc/analysis.c new file mode 100644 index 0000000..867577d --- /dev/null +++ b/xombe/src/enc/analysis.c @@ -0,0 +1,53 @@ +#include +#include +#include "../internal.h" +#include "../tables/dsp_tables.h" +#include "kernels.h" + +void xombe__enc_set_window(xombe_enc *e, int n) +{ + if (e->win_len == n) + return; + e->win_len = n; + e->win_sum2 = xombe__hamming_sum2(n); +#if !XOMBE_KERNELS_Q15 /* q15: the kernel builds e->win and its own table, e->wtab stays unused */ + { + int q; + xombe__hamming(e->win, n); + for (q = 0; q < XOMBE_WTAB_LEN; q++) + e->wtab[q] = xombe__hamming_dtft(n, q, (long)XOMBE_WTAB_OVERSAMPLE * XOMBE_FFT); + } +#endif + xombe__kern_window_init(e); +} + +void xombe__enc_integrate(const float *P, int L, float f0, float *a) +{ + float step = f0 * XOMBE_FFT; + int l, k; + a[0] = 0.0f; + for (l = 1; l <= L; l++) { + float lo = ((float)l - 0.5f) * step, hi = ((float)l + 0.5f) * step, m2 = 0.0f; + int k0 = (int)floorf(lo + 0.5f), k1 = (int)ceilf(hi + 0.5f); + if (k0 < 0) + k0 = 0; + if (k1 > XOMBE_SPEC_BINS - 1) + k1 = XOMBE_SPEC_BINS - 1; + /* bin overlap with [lo, hi], bounds may include bins that do not overlap */ + for (k = k0; k <= k1; k++) { + float c = fminf((float)k + 0.5f, hi) - fmaxf((float)k - 0.5f, lo); + if (c > 0.0f) + m2 += (c > 1.0f ? 1.0f : c) * P[k]; + } + a[l] = m2 > 0.0f ? 0.5f * log2f(m2) : XOMBE_AMP_MIN; + if (a[l] < XOMBE_AMP_MIN) + a[l] = XOMBE_AMP_MIN; + } +} + +void xombe__enc_hf_precomp(float *a, int L, float f0) +{ + int l; + for (l = 1; l <= L; l++) + a[l] -= 0.5f * xombe__hf_tilt((float)l * f0); +} diff --git a/xombe/src/enc/comfort.c b/xombe/src/enc/comfort.c new file mode 100644 index 0000000..af42b95 --- /dev/null +++ b/xombe/src/enc/comfort.c @@ -0,0 +1,37 @@ +#include +#include "../internal.h" + +#define CN_FAST_UPDATES 16 +#define CN_CLIP_RATIO 4.0f +#define CN_CLIP_MIN_POWER 1.0f +#define CN_LEVEL_OFFSET 0.21f + +void xombe__cn_half(xombe_enc *e, const float *P, int noise, int confident_run) +{ + int k; + if (!e->cn_ready) { + if (noise) { + memcpy(e->cn_power, P, sizeof(e->cn_power)); + e->cn_ready = 1; + e->cn_updates = 0; + } + return; + } + if (confident_run >= XOMBE_CONFIDENT_RUN) { + float alpha = e->cn_updates < CN_FAST_UPDATES ? 0.5f : 0.1f; + for (k = 0; k < XOMBE_SPEC_BINS; k++) { + float ceiling = CN_CLIP_RATIO * (e->cn_power[k] > CN_CLIP_MIN_POWER ? e->cn_power[k] : CN_CLIP_MIN_POWER); + float p = P[k] < ceiling ? P[k] : ceiling; + e->cn_power[k] = (1.0f - alpha) * e->cn_power[k] + alpha * p; + } + e->cn_updates++; + } +} + +void xombe__cn_targets(const xombe_enc *e, float *a) +{ + int l; + xombe__enc_integrate(e->cn_power, XOMBE_SILENCE_L, XOMBE_SILENCE_F0, a); + for (l = 1; l <= XOMBE_SILENCE_L; l++) + a[l] = xombe__clamp_amp(a[l] + CN_LEVEL_OFFSET); +} diff --git a/xombe/src/enc/encoder.c b/xombe/src/enc/encoder.c new file mode 100644 index 0000000..5143218 --- /dev/null +++ b/xombe/src/enc/encoder.c @@ -0,0 +1,199 @@ +#include +#include "frontend.h" +#include "../common/prof.h" +#include "../dstar/dstar_internal.h" +#if XOMBE_HAVE_DSTAR +#include "../dstar/dstar_enc.h" +#endif + +#define INPUT_HPF_GAIN 0.9427f +#if XOMBE_HAVE_DSTAR +#define ALL_OUTPUTS (XOMBE_ENC_DMR | XOMBE_ENC_DSTAR) +#else +#define ALL_OUTPUTS XOMBE_ENC_DMR +#endif + +static const uint8_t silence_frame_bytes[7] = XOMBE_SILENCE_FRAME; +static const uint8_t null_bits[7] = XOMBE_DS_NULL_BITS; +#if !XOMBE_HAVE_DSTAR +static const uint8_t null_frame_bytes[XOMBE_DS_FRAME_BYTES] = XOMBE_DS_NULL_FRAME; +#endif + +void xombe_enc_cfg_default(xombe_enc_cfg *cfg) +{ + cfg->ns = 1; + cfg->ns_strength_permille = 500; + cfg->dmr_dtx = 1; + cfg->tones = 1; + cfg->voicing_scale_permille = 350; + cfg->outputs = XOMBE_ENC_DMR; + cfg->dstar_dtx = 0; + cfg->dmr_quant = XOMBE_ENC_QUANT_CLOSED; +} + +XOMBE_STATIC_ASSERT(sizeof(struct xombe_enc) <= XOMBE_ENC_SIZE, encoder_state_fits_XOMBE_ENC_SIZE); +#if XOMBE_HAVE_DSTAR +XOMBE_STATIC_ASSERT(XOMBE_ENC_DSTAR_DELAY == XOMBE_ENC_DELAY + XOMBE_ENC_LOOKAHEAD, dstar_delay_is_the_lookahead); +#endif + +int xombe_enc_delay(const xombe_enc *e) +{ + return XOMBE_ENC_DELAY + e->lookahead; +} + +size_t xombe_enc_size(void) +{ + return sizeof(struct xombe_enc); +} + +static int cfg_valid(const xombe_enc_cfg *cfg) +{ + return cfg->ns_strength_permille >= 0 && cfg->ns_strength_permille <= 1000 && cfg->voicing_scale_permille > 0 && + (cfg->outputs & ~ALL_OUTPUTS) == 0 && + (cfg->dmr_quant == XOMBE_ENC_QUANT_CLOSED || cfg->dmr_quant == XOMBE_ENC_QUANT_OPEN); +} + +xombe_enc *xombe_enc_init(void *mem, const xombe_enc_cfg *cfg) +{ + xombe_enc *e = mem; + xombe_enc_cfg c; + if (cfg) + c = *cfg; + else + xombe_enc_cfg_default(&c); + if (!e || !cfg_valid(&c)) + return NULL; + c.ns = c.ns != 0; + c.dmr_dtx = c.dmr_dtx != 0; + c.tones = c.tones != 0; + c.dstar_dtx = c.dstar_dtx != 0; + if (!c.outputs) + c.outputs = XOMBE_ENC_DMR; + memset(e, 0, sizeof(*e)); + e->cfg = c; + e->ns_strength = (float)c.ns_strength_permille / 1000.0f; + e->voicing_scale = (float)c.voicing_scale_permille / 1000.0f; + xombe__hpf_init(&e->hpf, INPUT_HPF_GAIN); + xombe__pitch_init(e); + e->base_win_sum2 = xombe__hamming_sum2(XOMBE_BASE_WINDOW); + xombe__enc_set_window(e, XOMBE_BASE_WINDOW); + xombe__pred_init(&e->pi); + e->tone_prev_id = -1; +#if XOMBE_HAVE_DSTAR + if (c.outputs & XOMBE_ENC_DSTAR) + e->lookahead = XOMBE_ENC_LOOKAHEAD; + xombe__ds_enc_init(e); +#endif + return e; +} + +void xombe__enc_set_tap(xombe_enc *e, xombe_tap_fn fn, void *ctx) +{ + e->tap = fn; + e->tap_ctx = ctx; +} + +#ifdef XOMBE_PROF_DWT +unsigned long xombe__pf[16]; +#endif + +static int tone_valid(const xombe_enc_tone *t) +{ + return !t || xombe__tone_valid(t->id, t->ad); +} + +/* ambe2 and dstar may be NULL, a disabled output gets its silence frame. a forced tone replaces only phase D's + class, so analysis and background tracking see the frame as unforced */ +static int encode(xombe_enc *e, const int16_t pcm[XOMBE_FRAME], const xombe_enc_tone *tone, uint8_t *ambe2, + uint8_t *dstar) +{ + xombe_fe_frame a; + xombe_a2_frame f2; + xombe_be_ns ns[XOMBE_BE_COUNT], *be[XOMBE_BE_COUNT]; + const uint8_t *req; + int i, ready; + memmove(e->tone_req[1], e->tone_req[0], sizeof(e->tone_req) - sizeof(e->tone_req[0])); + e->tone_req[0][0] = (uint8_t)(tone ? tone->id : 0); + e->tone_req[0][1] = (uint8_t)(tone ? tone->ad : 0); + req = e->tone_req[XOMBE_ENC_DELAY + e->lookahead]; + XOMBE_PF(0, ready = xombe__fe_push(e, pcm)); +#if XOMBE_HAVE_DSTAR + if ((e->cfg.outputs & XOMBE_ENC_DSTAR) && e->cfg.tones) + XOMBE_PF(7, xombe__ds_tone_push(e)); +#endif + if (!ready) { + if (ambe2) + memcpy(ambe2, silence_frame_bytes, 7); + if (dstar) + memcpy(dstar, null_bits, 7); + return 0; + } + for (i = 0; i < XOMBE_BE_COUNT; i++) + be[i] = NULL; + XOMBE_PF(1, xombe__fe_analyze(e, &a)); + if (e->cfg.outputs & XOMBE_ENC_DMR) { + be[XOMBE_BE_AMBE2] = &ns[XOMBE_BE_AMBE2]; + XOMBE_PF(2, xombe__a2_voicing(e, &a, &f2, be[XOMBE_BE_AMBE2])); + } +#if XOMBE_HAVE_DSTAR + if (e->cfg.outputs & XOMBE_ENC_DSTAR) { + be[XOMBE_BE_DSTAR] = &ns[XOMBE_BE_DSTAR]; + XOMBE_PF(3, xombe__ds_enc_voicing(e, &a, be[XOMBE_BE_DSTAR])); + } +#endif + XOMBE_PF(4, xombe__fe_background(e, &a, be)); + if (be[XOMBE_BE_AMBE2]) { + uint8_t tmp[7]; + if (req[0]) { + f2.cls = XOMBE_CLASS_TONE; + a.tone_id = req[0]; + a.tone_ad = req[1]; + } + XOMBE_PF(5, xombe__a2_emit(e, &a, &f2, be[XOMBE_BE_AMBE2], ambe2 ? ambe2 : tmp)); + } else if (ambe2) { + memcpy(ambe2, silence_frame_bytes, 7); + } +#if XOMBE_HAVE_DSTAR + if (be[XOMBE_BE_DSTAR]) { + uint8_t tmp[7]; + if (req[0]) + xombe__ds_enc_force_tone(e, req[0], req[1]); + XOMBE_PF(6, xombe__ds_enc_frame(e, &a, be[XOMBE_BE_DSTAR], dstar ? dstar : tmp)); + } else if (dstar) { + memcpy(dstar, null_bits, 7); + } +#else + if (dstar) + memcpy(dstar, null_bits, 7); +#endif + return 1; +} + +static const int16_t zeros[XOMBE_FRAME]; + +int xombe_enc_frame(xombe_enc *e, const int16_t *pcm, const xombe_enc_tone *tone, uint8_t dmr[XOMBE_FRAME_BYTES], + uint8_t dstar[XOMBE_FRAME_BYTES]) +{ + uint8_t a[7], d[7]; + int r = xombe_enc_frame_bits(e, pcm, tone, dmr ? a : NULL, dstar ? d : NULL); + if (r < 0) + return r; + if (dmr) + xombe__fec_encode_dmr(a, dmr); +#if XOMBE_HAVE_DSTAR + if (dstar) + xombe__ds_fec_encode_bits(d, dstar); +#else + if (dstar) + memcpy(dstar, null_frame_bytes, XOMBE_DS_FRAME_BYTES); +#endif + return r; +} + +int xombe_enc_frame_bits(xombe_enc *e, const int16_t *pcm, const xombe_enc_tone *tone, + uint8_t dmr[XOMBE_BITS_BYTES], uint8_t dstar[XOMBE_BITS_BYTES]) +{ + if (!tone_valid(tone)) + return -1; + return encode(e, pcm ? pcm : zeros, tone, dmr, dstar); +} diff --git a/xombe/src/enc/frontend.c b/xombe/src/enc/frontend.c new file mode 100644 index 0000000..cd6beae --- /dev/null +++ b/xombe/src/enc/frontend.c @@ -0,0 +1,166 @@ +#include +#include +#include "frontend.h" +#include "../tables/dsp_tables.h" +#include "../common/prof.h" + +/* each call appends one frame to the XOMBE_ENC_BUF-sample history. the encoded frame starts at frame_base(e) + <= FRAME_BASE, pitch analysis runs on the frame before the newest (so its one-frame look-ahead is complete) */ +#define FRAME XOMBE_FRAME +#define FRAME_BASE (XOMBE_ENC_BUF - (XOMBE_ENC_DELAY + 1 + XOMBE_ENC_LOOKAHEAD) * FRAME) +#define PITCH_FRAME_BASE (XOMBE_ENC_BUF - 2 * FRAME) +#define HALF1_CENTRE 40 +#define HALF2_CENTRE 120 +#define BASE_WINDOW XOMBE_BASE_WINDOW + +XOMBE_STATIC_ASSERT(FRAME_BASE + HALF1_CENTRE - (XOMBE_MAX_WINDOW - 1) / 2 >= 0, analysis_window_in_buffer); +XOMBE_STATIC_ASSERT(FRAME_BASE + HALF2_CENTRE + (XOMBE_MAX_WINDOW - 1) / 2 < XOMBE_ENC_BUF, analysis_window_end); +XOMBE_STATIC_ASSERT(FRAME_BASE == XOMBE_ENC_BUF - XOMBE_ENC_RAW, raw_history_starts_at_frame); +XOMBE_STATIC_ASSERT(HALF1_CENTRE - (BASE_WINDOW - 1) / 2 >= -XOMBE_ENC_RAW_LEAD, vad_flat_window_in_raw_lead); +XOMBE_STATIC_ASSERT(XOMBE_TONE_SEG <= XOMBE_ENC_RAW, tone_segment_in_buffer); +XOMBE_STATIC_ASSERT(PITCH_FRAME_BASE + HALF2_CENTRE - XOMBE_PITCH_HALF - XOMBE_PITCH_LPF_HALF >= 0, + pitch_window_in_buffer); +XOMBE_STATIC_ASSERT(PITCH_FRAME_BASE + HALF2_CENTRE + XOMBE_PITCH_HALF + XOMBE_PITCH_LPF_HALF < XOMBE_ENC_BUF, + pitch_window_end); +/* one twiddle table serves both transform sizes */ +XOMBE_STATIC_ASSERT(XOMBE_TW_N % XOMBE_FFT == 0, twiddles_cover_analysis_fft); +XOMBE_STATIC_ASSERT(XOMBE_TW_N % XOMBE_TONE_FFT == 0, twiddles_cover_tone_fft); + +#define HANGOVER_FRAMES 2 + +/* returns 1 if active, counting hangover */ +static int detect_activity(xombe_enc *e, xombe_fe_frame *f) +{ + float tap[2]; + const int h = (BASE_WINDOW - 1) / 2; + xombe__kern_spectrum(f->xh + HALF1_CENTRE, xombe__base_win, BASE_WINDOW, &f->S1); + xombe__kern_spectrum(f->xh + HALF2_CENTRE, xombe__base_win, BASE_WINDOW, &f->S2); + xombe__kern_bin_power(&f->S1, e->base_win_sum2, f->P1); + xombe__kern_bin_power(&f->S2, e->base_win_sum2, f->P2); + + xombe__vad_half(e, f->P1, xombe__vad_flat(f->raw + HALF1_CENTRE - h, BASE_WINDOW), &f->speech1, &f->vad1); + e->confident_run = (!f->speech1 && f->vad1 < XOMBE_CONFIDENT) ? e->confident_run + 1 : 0; + f->run1 = e->confident_run; + xombe__vad_half(e, f->P2, xombe__vad_flat(f->raw + HALF2_CENTRE - h, BASE_WINDOW), &f->speech2, &f->vad2); + e->confident_run = (!f->speech2 && f->vad2 < XOMBE_CONFIDENT) ? e->confident_run + 1 : 0; + f->run2 = e->confident_run; + tap[0] = (float)f->speech1; + tap[1] = f->vad1; + XOMBE_TAP(e, XOMBE_STAGE_VAD, 0.0f, tap, 2); + tap[0] = (float)f->speech2; + tap[1] = f->vad2; + XOMBE_TAP(e, XOMBE_STAGE_VAD, 0.0f, tap, 2); + if (f->speech1 || f->speech2) { + e->hangover = HANGOVER_FRAMES; + return 1; + } + if (e->hangover > 0) { + e->hangover--; + return 1; + } + return 0; +} + +static int frame_base(const xombe_enc *e) +{ + return XOMBE_ENC_BUF - (XOMBE_ENC_DELAY + 1 + e->lookahead) * FRAME; +} + +/* pitch analyses sit in a ring of XOMBE_ENC_DELAY slots, the tracked frame is the oldest, whose slot the next + call overwrites. its period goes to e->period[0], the encoded frame is e->lookahead older */ +int xombe__fe_push(xombe_enc *e, const int16_t pcm[XOMBE_FRAME]) +{ + int k = e->calls; + int i; + memmove(e->raw, e->raw + FRAME, sizeof(e->raw[0]) * (XOMBE_ENC_RAW_LEAD + XOMBE_ENC_RAW - FRAME)); + memmove(e->xh, e->xh + FRAME, sizeof(float) * (XOMBE_ENC_BUF - FRAME)); + for (i = 0; i < FRAME; i++) { + e->raw[XOMBE_ENC_RAW_LEAD + XOMBE_ENC_RAW - FRAME + i] = pcm[i]; + e->xh[XOMBE_ENC_BUF - FRAME + i] = xombe__hpf_step(&e->hpf, (float)pcm[i]); + } + if (k < XOMBE_ENC_DELAY + e->lookahead) + e->calls++; + if (k >= 1) { + xombe__pitch_errors(e, e->xh + PITCH_FRAME_BASE + HALF2_CENTRE, e->pitch_slot); + e->pitch_slot = (e->pitch_slot + 1) % XOMBE_ENC_DELAY; + } + if (k >= XOMBE_ENC_DELAY) { + int cur = e->pitch_slot; +#if XOMBE_ENC_LOOKAHEAD + for (i = e->lookahead; i > 0; i--) + e->period[i] = e->period[i - 1]; +#endif + e->period[0] = xombe__pitch_track(e, cur, (cur + 1) % XOMBE_ENC_DELAY, (cur + 2) % XOMBE_ENC_DELAY); + } + return k >= XOMBE_ENC_DELAY + e->lookahead; +} + +const int16_t *xombe__fe_raw(const xombe_enc *e, int back) +{ + return e->raw + XOMBE_ENC_RAW_LEAD + XOMBE_ENC_RAW - (back + 1) * FRAME; +} + +void xombe__fe_analyze(xombe_enc *e, xombe_fe_frame *a) +{ + a->xh = e->xh + frame_base(e); + a->raw = xombe__fe_raw(e, XOMBE_ENC_DELAY + e->lookahead); + a->active = detect_activity(e, a); + a->tone_det = a->tone_det_id = a->tone_det_ad = 0; + a->tone = a->tone_id = a->tone_ad = 0; + if (e->cfg.tones && (e->cfg.outputs & XOMBE_ENC_DMR)) { + XOMBE_PF(10, a->tone_det = xombe__tone_detect(e, a->raw, &a->tone_det_id, &a->tone_det_ad)); + a->tone = xombe__tone_decide(e, a->tone_det, a->tone_det_id, a->tone_det_ad, &a->tone_id, &a->tone_ad); + } + a->period = e->period[e->lookahead]; + a->have_voice = 0; + a->have_lf2 = 0; + a->nw = BASE_WINDOW; + a->fstar = 0.0f; + a->win_sum2 = e->base_win_sum2; +} + +void xombe__fe_voice(xombe_enc *e, xombe_fe_frame *a) +{ + if (a->have_voice) + return; + a->nw = xombe__pitch_window_len(a->period); + xombe__enc_set_window(e, a->nw); + if (a->nw != BASE_WINDOW) { + xombe__kern_spectrum(a->xh + HALF1_CENTRE, e->win, a->nw, &a->S1); + xombe__kern_spectrum(a->xh + HALF2_CENTRE, e->win, a->nw, &a->S2); + } + a->fstar = 1.0f / xombe__pitch_refine(e, &a->S2, a->period); + a->win_sum2 = e->win_sum2; + a->have_voice = 1; + a->have_lf2 = 0; +} + +const xombe_lf_spec *xombe__fe_s2_prepared(xombe_enc *e, xombe_fe_frame *a) +{ + if (!a->have_lf2) { + xombe__voicing_prepare(e, &a->S2, &a->lf2); + a->have_lf2 = 1; + } + return &a->lf2; +} + +void xombe__fe_background(xombe_enc *e, const xombe_fe_frame *a, xombe_be_ns *be[XOMBE_BE_COUNT]) +{ + if (e->cfg.ns) { + float X1[XOMBE_NS_BINS], X2[XOMBE_NS_BINS]; + const xombe_be_ns *primary = be[XOMBE_BE_AMBE2] ? be[XOMBE_BE_AMBE2] : be[XOMBE_BE_DSTAR]; + int i; + xombe__ns_bins(a->P1, X1); + xombe__ns_bins(a->P2, X2); + xombe__ns_update(e, X1, a->speech1, a->run1, primary->no_band_voiced[0]); + for (i = 0; i < XOMBE_BE_COUNT; i++) + if (be[i]) + xombe__ns_gain(e, be[i]->mem, X1, a->speech1, a->vad1, be[i]->vbin, be[i]->G1); + xombe__ns_update(e, X2, a->speech2, a->run2, primary->no_band_voiced[1]); + for (i = 0; i < XOMBE_BE_COUNT; i++) + if (be[i]) + xombe__ns_gain(e, be[i]->mem, X2, a->speech2, a->vad2, be[i]->vbin, be[i]->G2); + } + xombe__cn_half(e, a->P1, !a->speech1, a->run1); + xombe__cn_half(e, a->P2, !a->speech2, a->run2); +} diff --git a/xombe/src/enc/frontend.h b/xombe/src/enc/frontend.h new file mode 100644 index 0000000..df88c0e --- /dev/null +++ b/xombe/src/enc/frontend.h @@ -0,0 +1,90 @@ +#ifndef XOMBE_FRONTEND_H +#define XOMBE_FRONTEND_H + +/* encoder front end, shared by the back ends (AMBE+2 ambe2_enc.c, D-STAR dstar/dstar_enc.c) enabled in + e->cfg.outputs. encoder.c runs each frame in four phases: + A front end once per frame: xombe__fe_push, xombe__fe_analyze, and on demand xombe__fe_voice (costly, + later calls free) + B voicing per back end, filling its xombe_be_ns + C shared background tracking (xombe__fe_background): one noise update per half, no_band_voiced taken from + the primary back end (AMBE+2 if enabled, else D-STAR), then per back end gains, then comfort noise + D emit per back end with its own gains, a forced tone (encoder.c) replaces the class here, B and C saw the + frame as unforced + a disabled back end does no B or D work and keeps no gain memory, so AMBE+2 output does not depend on + whether D-STAR is enabled. + after xombe__fe_voice a back end may also read nw, fstar, win_sum2, and S1/S2 under nw, and e->win, e->wtab, + and the kernels' window tables stay set to nw until the next frame */ + +#include "kernels.h" + +/* phase A record of the frame being encoded */ +typedef struct { + const float *xh; /* high-passed input at frame start */ + const int16_t *raw; /* unfiltered input at frame start, XOMBE_ENC_RAW_LEAD samples of history before it */ + /* half-frame spectra centred on samples 40 and 120, under XOMBE_BASE_WINDOW until xombe__fe_voice, then + under the nw-point pitch-adaptive window */ + xombe_spec S1, S2; + float P1[XOMBE_SPEC_BINS], P2[XOMBE_SPEC_BINS]; /* bin powers under the base window */ + int speech1, speech2; /* per-half VAD decisions */ + float vad1, vad2; /* per-half VAD metrics, log2 units */ + int run1, run2; /* confident-background run after each half */ + int active; /* either half speech, or within hangover */ + /* AMBE+2 tone detector result (all 0 when cfg.tones or AMBE+2 is off), then the decision after confirmation + and hold: tone 1 with the ID and amplitude to send */ + int tone_det, tone_det_id, tone_det_ad; + int tone, tone_id, tone_ad; + float period; /* tracked pitch period, samples */ + /* valid when have_voice */ + int have_voice; + int nw; /* pitch-adaptive window length, e->win, e->wtab, and the kernels' window follow it */ + float fstar; /* refined fundamental, cycles/sample */ + float win_sum2; /* window sum of squares */ + /* S2 under nw prepared for the voicing metric, valid when have_lf2 */ + int have_lf2; + xombe_lf_spec lf2; +} xombe_fe_frame; + +/* back end indexes into the xombe__fe_background array */ +#define XOMBE_BE_AMBE2 0 +#define XOMBE_BE_DSTAR 1 +#define XOMBE_BE_COUNT 2 + +/* one back end's part in background tracking, phase B -> C -> D */ +typedef struct { + /* in, from phase B */ + int no_band_voiced[2]; /* per half: no band clearly voiced, noise update input when primary */ + uint8_t vbin[XOMBE_NS_BINS]; /* voicing at each suppression bin centre, both halves, + needed only when cfg.ns */ + xombe_ns_mem *mem; /* back end's own gain smoothing memory */ + /* out, from phase C when cfg.ns: per-half suppression gains */ + float G1[XOMBE_NS_BINS], G2[XOMBE_NS_BINS]; +} xombe_be_ns; + +/* returns 1 once a frame is ready to encode, after XOMBE_ENC_DELAY + e->lookahead calls */ +int xombe__fe_push(xombe_enc *e, const int16_t pcm[XOMBE_FRAME]); +/* unfiltered input from the start of the frame `back` frames before the newest (0 = newest, the encoded frame is + XOMBE_ENC_DELAY + e->lookahead back), XOMBE_ENC_RAW_LEAD samples of history before the oldest */ +const int16_t *xombe__fe_raw(const xombe_enc *e, int back); +/* call once for each push that returned 1 */ +void xombe__fe_analyze(xombe_enc *e, xombe_fe_frame *a); +/* sets a->have_voice, no-op when already done */ +void xombe__fe_voice(xombe_enc *e, xombe_fe_frame *a); +/* S2 under nw prepared for the voicing metric, shared by the back ends. kernels keep one prepared spectrum, so + call right before the S2 line fits */ +const xombe_lf_spec *xombe__fe_s2_prepared(xombe_enc *e, xombe_fe_frame *a); +/* phase C, be[XOMBE_BE_*] NULL for disabled back ends, at least one enabled */ +void xombe__fe_background(xombe_enc *e, const xombe_fe_frame *a, xombe_be_ns *be[XOMBE_BE_COUNT]); + +/* AMBE+2 back end (ambe2_enc.c) */ +typedef struct { + int cls; /* XOMBE_CLASS_VOICE, SILENCE or TONE */ + int b[9]; /* voice frames: b0 and b1 after phase B, all after phase D */ + float soft1[8], soft2[8]; /* soft band voicing per half, 0 unless voice */ + uint8_t v2[8]; /* second-half band voicing, 0 unless voice */ +} xombe_a2_frame; + +void xombe__a2_voicing(xombe_enc *e, xombe_fe_frame *a, xombe_a2_frame *f, xombe_be_ns *ns); +void xombe__a2_emit(xombe_enc *e, const xombe_fe_frame *a, xombe_a2_frame *f, const xombe_be_ns *ns, + uint8_t bits[7]); + +#endif diff --git a/xombe/src/enc/kern_float.c b/xombe/src/enc/kern_float.c new file mode 100644 index 0000000..86676e6 --- /dev/null +++ b/xombe/src/enc/kern_float.c @@ -0,0 +1,131 @@ +#include +#include "kernels.h" +#include "../tables/dsp_tables.h" + +void xombe__kern_spectrum(const float *centre, const float *w, int n, xombe_spec *S) +{ + float buf[XOMBE_FFT]; + int half = (n - 1) / 2, j; + memset(buf, 0, sizeof(buf)); + for (j = -half; j <= half; j++) + buf[(j + XOMBE_FFT) % XOMBE_FFT] = centre[j] * w[half + j]; + xombe__rfft(buf, S->b, XOMBE_FFT, xombe__fft_tw, XOMBE_TW_N); +} + +void xombe__kern_bin_power(const xombe_spec *S, float sum_w2, float *P) +{ + int k; + float scale = 1.0f / (XOMBE_FFT * sum_w2); + for (k = 0; k < XOMBE_SPEC_BINS; k++) + P[k] = (S->b[k].re * S->b[k].re + S->b[k].im * S->b[k].im) * scale; +} + +void xombe__kern_window_init(xombe_enc *e) +{ + (void)e; +} + +void xombe__kern_pitch_acf(xombe_enc *e, const float *centre, int slot) +{ + float u[XOMBE_PITCH_WIN], e0 = 0.0f; + int i, j, t; + for (i = 0; i < XOMBE_PITCH_WIN; i++) { + float s = 0.0f; + for (j = -XOMBE_PITCH_LPF_HALF; j <= XOMBE_PITCH_LPF_HALF; j++) + s += xombe__pitch_lpf[j + XOMBE_PITCH_LPF_HALF] * centre[i - XOMBE_PITCH_HALF - j]; + e0 += s * s * xombe__pitch_w2[i]; + u[i] = s * xombe__pitch_w2[i]; + } + for (t = 0; t < XOMBE_PITCH_WIN; t++) { + float r = 0.0f; + for (i = 0; i + t < XOMBE_PITCH_WIN; i++) + r += u[i] * u[i + t]; + e->pacf[slot].f[t] = r; + } + e->pe0[slot] = e0; +} + +/* P on a quarter-sample grid, so K, k*P, and its integer part are exact */ +float xombe__kern_error_at(const xombe_enc *e, int slot, float P) +{ + const float *r = e->pacf[slot].f; + float e0 = e->pe0[slot], sum = r[0], val; + int k, K = (int)((float)(XOMBE_PITCH_WIN - 1) / P); + for (k = 1; k <= K; k++) { + float t = (float)k * P, f; + int i = (int)t; + f = t - (float)i; + sum += 2.0f * (f > 0.0f ? (1.0f - f) * r[i] + f * r[i + 1] : r[i]); + } + val = (e0 - P * sum) / (e0 * (1.0f - P * xombe__pitch_sum_w4)); + return val > 0.0f ? val : 0.0f; +} + +void xombe__kern_lf_prepare(xombe_enc *e, const xombe_spec *S, int kmin, int kmax, xombe_lf_spec *sp) +{ + (void)e; + (void)kmin; + (void)kmax; + sp->S = S; + sp->g = 1.0f; +} + +/* window values kept per harmonic for the residual pass, a wider harmonic recomputes the rest */ +#define LINE_FIT_KEEP 64 + +/* window transform nu_bins from its centre, interpolated in e->wtab */ +static float window_value(const xombe_enc *e, float nu_bins) +{ + float x = fabsf(nu_bins) * XOMBE_WTAB_OVERSAMPLE; + int i = (int)x; + float f = x - (float)i; + if (i >= XOMBE_WTAB_LEN - 1) + return e->wtab[XOMBE_WTAB_LEN - 1]; + return (1.0f - f) * e->wtab[i] + f * e->wtab[i + 1]; +} + +float xombe__kern_line_fit(const xombe_enc *e, const xombe_lf_spec *sp, float period, int kmin, int kmax, + float band_resid[8], float band_energy[8]) +{ + const xombe_cpx *S = sp->S->b; + float per_harm = XOMBE_FFT / period, total = 0.0f, wk[LINE_FIT_KEEP]; + int k = kmin < 1 ? 1 : kmin, l = xombe__harmonic_of(k, period), next = l; + memset(band_resid, 0, 8 * sizeof(float)); + memset(band_energy, 0, 8 * sizeof(float)); + while (k <= kmax) { + int k0 = k, n = 0, band; + float sw_re = 0.0f, sw_im = 0.0f, ww = 0.0f, ee = 0.0f, resid = 0.0f, A_re = 0.0f, A_im = 0.0f; + do { + float w = window_value(e, (float)k - (float)l * per_harm); + sw_re += S[k].re * w; + sw_im += S[k].im * w; + ww += w * w; + ee += S[k].re * S[k].re + S[k].im * S[k].im; + if (n < LINE_FIT_KEEP) + wk[n] = w; + n++; + k++; + } while (k <= kmax && (next = xombe__harmonic_of(k, period)) == l); + if (l == 0) { + l = next; + continue; + } + /* residual summed term by term, ee - |sw|^2/ww cancels on a strongly harmonic band (relative error 1e-3 + against 1e-4 in float) */ + if (ww > 0.0f) { + A_re = sw_re / ww; + A_im = sw_im / ww; + } + for (n = 0; k0 < k; k0++, n++) { + float w = n < LINE_FIT_KEEP ? wk[n] : window_value(e, (float)k0 - (float)l * per_harm), + dr = S[k0].re - A_re * w, di = S[k0].im - A_im * w; + resid += dr * dr + di * di; + } + band = xombe__band_of(l, period); + band_resid[band] += resid; + band_energy[band] += ee; + total += resid; + l = next; + } + return total; +} diff --git a/xombe/src/enc/kern_q15.h b/xombe/src/enc/kern_q15.h new file mode 100644 index 0000000..712fa12 --- /dev/null +++ b/xombe/src/enc/kern_q15.h @@ -0,0 +1,32 @@ +#ifndef XOMBE_KERN_Q15_H +#define XOMBE_KERN_Q15_H + +/* helpers shared by the q15 kernels (kern_q15_*.c) */ + +#include +#include "kernels.h" +#include "../dsp/q15ops.h" + +static inline int round_q(float v) +{ + return (int)(v + (v < 0.0f ? -0.5f : 0.5f)); +} + +/* block scale taking peak magnitude m to peak, 0 when m is 0 or subnormal enough to overflow the scale (block + counts as zero) */ +static inline float q15_gain(float m, float peak) +{ + float g = m > 0.0f ? peak / m : 0.0f; + return g <= FLT_MAX ? g : 0.0f; +} + +/* |v| < 2^63 to float without the library call, top 31 bits through a 32-bit conversion */ +static inline float i64_to_float(int64_t v) +{ + int64_t a = v < 0 ? -v : v; + int sh = (a >> 31) ? 33 - q15_clz64((uint64_t)a) : 0; + float f = (float)(int32_t)(a >> sh) * (float)(1u << sh); + return v < 0 ? -f : f; +} + +#endif diff --git a/xombe/src/enc/kern_q15_lf.c b/xombe/src/enc/kern_q15_lf.c new file mode 100644 index 0000000..0a0ddfb --- /dev/null +++ b/xombe/src/enc/kern_q15_lf.c @@ -0,0 +1,130 @@ +/* q15 line fit (kernels.h, XOMBE_KERNELS=q15): int16 block-scaled spectrum with exact prefix sums of |S|^2 and + exact 64-bit MACs, so the residual comes from ee - |sw|^2/ww in one pass without float cancellation */ +#include +#include +#include "kern_q15.h" + +/* line fit table runs past the float table's end on its clamped last value, interpolating equal tail values + is exact */ +XOMBE_STATIC_ASSERT(XOMBE_LF_WT_OFF >= XOMBE_WTAB_LEN, lf_table_padded); + +/* weights (1 - f, f) in Q14 for the fraction f of Q16 position x */ +static uint32_t lf_coef(int32_t x) +{ + uint32_t f = (uint32_t)(x & 0xffff) >> 2; + return (f << 16) | (16384u - f); +} + +/* n bins of re (im at XOMBE_LF_IM) against the window from entries w, w + XOMBE_WTAB_OVERSAMPLE, ..., weight + pair c, two bins per MAC */ +static void lf_run(const int16_t *re, int n, const uint32_t *w, uint32_t c, int64_t *psr, int64_t *psi, + int64_t *pww) +{ + int64_t sr = 0, si = 0, ww = 0; + const int16_t *end = re + (n & ~1); + for (; re != end; re += 2, w += 2 * XOMBE_WTAB_OVERSAMPLE) { + uint32_t wp = q15_pack_lsl2((uint32_t)(q15_smuad(w[0], c) >> 14), + (uint32_t)q15_smuad(w[XOMBE_WTAB_OVERSAMPLE], c)); + sr = q15_smlald(q15_ld2(re), wp, sr); + si = q15_smlald(q15_ld2(re + XOMBE_LF_IM), wp, si); + ww = q15_smlald(wp, wp, ww); + } + if (n & 1) { + int32_t v = q15_smuad(w[0], c) >> 14; + sr += (int32_t)re[0] * v; + si += (int32_t)re[XOMBE_LF_IM] * v; + ww += v * v; + } + *psr = sr; + *psi = si; + *pww = ww; +} + +/* low 32 bits of x >> sh, 0 < sh < 32 */ +static uint32_t lf_shr(uint64_t x, int sh) +{ + return (uint32_t)x >> sh | (uint32_t)(x >> 32) << (32 - sh); +} + +float xombe__kern_line_fit(const xombe_enc *e, const xombe_lf_spec *sp, float period, int kmin, int kmax, + float band_resid[8], float band_energy[8]) +{ + const int16_t *re = sp->S->v; + const uint64_t *ep = e->kq.ep; + float per_harm = XOMBE_FFT / period, total = 0.0f, inv_g2, g = sp->g; + uint64_t be[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + /* period exact in Q19 for 16 <= period <= XOMBE_FFT (24-bit mantissa), so harmonic and band edges compare + exactly in integers: bin j is past harmonic l when j*period >= (l + 1/2)*XOMBE_FFT, as xombe__harmonic_of + (midway goes up), band b = floor(l*XOMBE_BANDS_PER_UNIT/period). H = per_harm in Q20 (< 2^27) from 2^49/pq, + taken 64 low so 56..73 under the true value (float rounding <= 8), and (2l + 1)*73 < 2^21 for l <= 513, so + the edge estimates are exact or one low */ + int32_t pq = (int32_t)(period * 524288.0f), H = (int32_t)(562949953421312.0f / (float)pq) - 64; + int k = kmin < 1 ? 1 : kmin, l = xombe__harmonic_of(k, period); + /* bins lie within per_harm/2 + 1 of their harmonic, inside the table's padding. callers' periods are >= 18 + samples: pitch refinement >= 20, voicing metric at table f0 <= 0.0524 with 2 % jitter. per_harm >= 1 gives + every harmonic a bin */ + assert(per_harm <= 2.0f * (XOMBE_LF_PAD_BINS - 2) && per_harm >= 1.0f && kmax <= XOMBE_FFT / 2); + memset(band_resid, 0, 8 * sizeof(float)); + memset(band_energy, 0, 8 * sizeof(float)); + if (g == 0.0f) + return 0.0f; /* all-zero spectrum fits exactly */ + inv_g2 = 1.0f / (g * g); + for (; k <= kmax; l++) { + int64_t sr = 0, si = 0, ww = 0, t = (int64_t)(2 * l + 1) << 28; /* (l + 1/2)*XOMBE_FFT in Q19 */ + uint64_t ee; + float resid, pos; + int64_t lb = (int64_t)l << 23; /* l*XOMBE_BANDS_PER_UNIT in Q19 */ + int32_t xs; + int kend = (int)(((2 * l + 1) * H + 2097151) >> 21), band; + if ((int64_t)kend * pq < t) + kend++; + if (kend > kmax + 1) + kend = kmax + 1; + if (l == 0) { + k = kend; + continue; + } + ee = ep[kend] - ep[k]; + /* table position of the first bin, in bins, the rest lie within per_harm/2 + 1 bins. in Q16 entries it + steps exactly XOMBE_WTAB_OVERSAMPLE per bin */ + pos = (float)k - (float)l * per_harm; + xs = (int32_t)(pos * (XOMBE_WTAB_OVERSAMPLE * 65536.0f)); + lf_run(re + k, kend - k, &e->kq.wt[XOMBE_LF_WT_OFF + (xs >> 16)], lf_coef(xs), &sr, &si, &ww); + k = kend; + if (ww > 0) { + /* sums to 31 bits so products fit in 64: |sr|, |si| <= sqrt(ee*ww) need no say in the shift. + numerator >= 0 up to rounding */ + int32_t e3, w3, r3, i3; + int64_t num; + int sh = 33 - q15_clz64(ee | (uint64_t)ww); + if (sh <= 0) { + sh = 0; + e3 = (int32_t)ee; + w3 = (int32_t)ww; + r3 = (int32_t)sr; + i3 = (int32_t)si; + } else { /* sh <= 32 - 22, sums below 2^41 */ + e3 = (int32_t)lf_shr(ee, sh); + w3 = (int32_t)lf_shr((uint64_t)ww, sh); + r3 = (int32_t)lf_shr((uint64_t)sr, sh); + i3 = (int32_t)lf_shr((uint64_t)si, sh); + } + num = (int64_t)e3 * w3 - (int64_t)r3 * r3 - (int64_t)i3 * i3; + resid = num > 0 ? i64_to_float(num) / (float)w3 * (float)(1u << sh) : 0.0f; + } else { + resid = i64_to_float((int64_t)ee); + } + resid *= inv_g2; + band = (int)(((int64_t)l * H) >> 26); + if ((int64_t)(band + 1) * pq <= lb) + band++; + if (band > 7) + band = 7; + band_resid[band] += resid; + be[band] += ee; + total += resid; + } + for (l = 0; l < 8; l++) + band_energy[l] = i64_to_float((int64_t)be[l]) * inv_g2; + return total; +} diff --git a/xombe/src/enc/kern_q15_pitch.c b/xombe/src/enc/kern_q15_pitch.c new file mode 100644 index 0000000..d7bffc8 --- /dev/null +++ b/xombe/src/enc/kern_q15_pitch.c @@ -0,0 +1,228 @@ +/* q15 pitch kernels (kernels.h, XOMBE_KERNELS=q15): int16 block-scaled input, SMLAD low-pass two outputs per + pass, low-pass output and its windowed product block-shifted to int16, energy and autocorrelation exact in 64 + bits, lags normalized to r[0] = 32767 by one reciprocal (float scale in pacf_scale). quarter-sample periods make + the interpolation exact in Q2. also the analysis window and the line fit's window table */ +#include "kern_q15.h" +#include "../tables/dsp_tables.h" + +#define PE_N (XOMBE_PITCH_WIN + 1) /* window padded to even */ +#define PE_X (XOMBE_PITCH_WIN + 2 * XOMBE_PITCH_LPF_HALF + 1) /* input samples with one pad, even */ +#define PE_P (PE_N / 2 + 1) /* pairs of the window, zero-padded by one */ + +XOMBE_STATIC_ASSERT(PE_N % 2 == 0 && PE_X % 2 == 0, pe_even); +XOMBE_STATIC_ASSERT(PE_N <= XOMBE_PITCH_WIN + 1, pe_rq_fits_pacf); +XOMBE_STATIC_ASSERT((long)XOMBE_WTAB_OVERSAMPLE * XOMBE_FFT * (XOMBE_MAX_WINDOW - 1) < (1L << 23), window_phase_fits); + +/* 2^k, -126 <= k <= 127 */ +static float pow2f(int k) +{ + uint32_t b = (uint32_t)(k + 127) << 23; + float f; + memcpy(&f, &b, sizeof(f)); + return f; +} + +/* v * 2^-sh rounded, held below 2^15, |v| < 2^(15 + sh) */ +static int16_t shr_q15(int32_t v, int sh) +{ + if (sh > 0) + v = ((v >> (sh - 1)) + 1) >> 1; + else + v = (int32_t)((uint32_t)v << -sh); + return (int16_t)(v > 32767 ? 32767 : v); +} + +/* Q15 pitch window at i, mirrored */ +static int32_t w2q(int i) +{ + return xombe__pitch_w2_q15[i <= XOMBE_PITCH_HALF ? i : XOMBE_PITCH_WIN - 1 - i]; +} + +static int mag_bits(uint32_t m) +{ + return m ? 32 - q15_clz32(m) : 0; +} + +void xombe__kern_pitch_acf(xombe_enc *e, const float *centre, int slot) +{ + int16_t x[PE_X], *rq = e->pacf[slot].q; + int32_t sv[PE_N]; + uint32_t up[2 * PE_P]; /* up[j] = (u[2j], u[2j + 1]), up[PE_P + j] = (u[2j + 1], u[2j + 2]) */ + float m = 0.0f, gx, cs, cu, b = 0.0f; + const float *c = centre - XOMBE_PITCH_HALF - XOMBE_PITCH_LPF_HALF; + int i, t, sh1, sh2, sh = 0; + uint32_t smax = 0, umax = 0; + int64_t e0 = 0; + for (i = 0; i < PE_X - 1; i++) + if (fabsf(c[i]) > m) + m = fabsf(c[i]); + gx = q15_gain(m, 32767.0f); + for (i = 0; i < PE_X - 1; i++) + x[i] = (int16_t)round_q(c[i] * gx); + x[PE_X - 1] = 0; + /* |sv| < 2^31: sum |taps| <= 65536 */ + for (i = 0; i < XOMBE_PITCH_WIN; i += 2) { + int32_t sa = 0, sb = 0; + const int16_t *p = x + i; + int q; + for (q = 0; q < XOMBE_PITCH_LPF_PAIRS; q++) { + uint32_t d = q15_ld2(p + 2 * q); + sa = q15_smlad(d, xombe__pitch_lpf_q15[0][q], sa); + sb = q15_smlad(d, xombe__pitch_lpf_q15[1][q], sb); + } + if (i + 1 == XOMBE_PITCH_WIN) + sb = 0; + sv[i] = sa; + sv[i + 1] = sb; + smax |= (uint32_t)(sa < 0 ? -sa : sa) | (uint32_t)(sb < 0 ? -sb : sb); + } + /* the OR of the magnitudes has the max's top bit, so s = sv * 2^-sh1 and u = s*w2 * 2^-sh2 peak in + [2^14, 2^15). s*(s*w2) < 2^45, e0 < 2^54. x holds s, then u */ + sh1 = mag_bits(smax) - 15; + for (i = 0; i < XOMBE_PITCH_WIN; i++) { + int32_t s = shr_q15(sv[i], sh1), p = s * w2q(i); + x[i] = (int16_t)s; + e0 += (int64_t)s * p; + umax |= (uint32_t)(p < 0 ? -p : p); + } + sh2 = mag_bits(umax) - 15; + for (i = 0; i < XOMBE_PITCH_WIN; i++) + x[i] = shr_q15(x[i] * w2q(i), sh2); + for (; i < 2 * PE_P + 1; i++) + x[i] = 0; + for (i = 0; i < PE_P; i++) { + up[i] = (uint16_t)x[2 * i] | (uint32_t)(uint16_t)x[2 * i + 1] << 16; + up[PE_P + i] = (uint16_t)x[2 * i + 1] | (uint32_t)(uint16_t)x[2 * i + 2] << 16; + } + /* float value of one unit of s and of u */ + cs = gx > 0.0f ? pow2f(sh1) / (gx * xombe__pitch_lpf_q15_gain) : 0.0f; + cu = cs * pow2f(sh2) / xombe__pitch_w2_q15_gain; + e->pe0[slot] = i64_to_float(e0) * cs * cs / xombe__pitch_w2_q15_gain; + e->pacf_scale[slot] = 0.0f; + /* lags t..t + 3 over the pairs of lag t, zero padding makes the extra products vanish. all four read at one + pointer, so the loop's accumulators stay in registers */ + for (t = 0; t < XOMBE_PITCH_WIN; t += 4) { + int64_t a[4] = {0, 0, 0, 0}; + int k; + const uint32_t *pv = up, *pe = up + (XOMBE_PITCH_WIN - t + 1) / 2, *pb = up + t / 2; + for (; pv != pe; pv++, pb++) { + uint32_t v = *pv; + a[0] = q15_smlald(v, pb[0], a[0]); + a[2] = q15_smlald(v, pb[1], a[2]); + a[1] = q15_smlald(v, pb[PE_P], a[1]); + a[3] = q15_smlald(v, pb[PE_P + 1], a[3]); + } + if (t == 0) { + if (a[0] <= 0) { /* all-zero input */ + memset(rq, 0, PE_N * sizeof(*rq)); + return; + } + /* r[0] >= 2^28 (u peaks >= 2^14) shifted below 2^31, |r[t]| <= r[0] (Cauchy-Schwarz), + b = 32767*2^44/r[0] < 2^31 */ + sh = 33 - q15_clz64((uint64_t)a[0]); + sh = sh > 0 ? sh : 0; + e->pacf_scale[slot] = i64_to_float(a[0]) * cu * cu * (1.0f / (32767.0f * 4.0f)); + b = 32767.0f * 17592186044416.0f / (float)(int32_t)(a[0] >> sh); + } + for (k = 0; k < 4 && t + k < XOMBE_PITCH_WIN; k++) + rq[t + k] = (int16_t)(((int64_t)(int32_t)(a[k] >> sh) * (int32_t)b + ((int64_t)1 << 43)) >> 44); + } + rq[0] = 32767; + rq[PE_N - 1] = 0; /* lag XOMBE_PITCH_WIN, past the window */ +} + +/* reads lags in pairs (r[i], r[i + 1]) at any i */ +float xombe__kern_error_at(const xombe_enc *e, int slot, float P) +{ + const int16_t *rq = e->pacf[slot].q; + float e0 = e->pe0[slot], val; + /* K = floor((XOMBE_PITCH_WIN - 1)/P) for P = p4/4 */ + int k, p4 = (int)(4.0f * P + 0.5f), K = 4 * (XOMBE_PITCH_WIN - 1) / p4, t4 = p4; + int32_t sum = 0; + for (k = 1; k <= K; k++, t4 += p4) { + uint32_t f = (uint32_t)t4 & 3u; + sum = q15_smlad(q15_ld2(rq + (t4 >> 2)), (f << 16) | (4u - f), sum); + } + /* sum is in quarters, r[0] = 32767 */ + val = (e0 - P * e->pacf_scale[slot] * (float)(2 * sum + 4 * 32767)) / (e0 * (1.0f - P * xombe__pitch_sum_w4)); + return val > 0.0f ? val : 0.0f; +} + +/* sin(pi*y), |y| <= 1/2, minimax fit of sin(pi*y)/y, relative error < 2e-7 in float */ +static float sinpi(float y) +{ + float y2 = y * y; + return y * (3.141592741f + y2 * (-5.167709827f + y2 * (2.550069809f + y2 * (-0.598242104f + y2 * 0.0775603801f)))); +} + +/* sin(pi*y), |y| < 0.032, Taylor to y^5, relative error < 3e-10 */ +static float sinpi_small(float y) +{ + float y2 = y * y; + return y * (3.14159274f + y2 * (-5.16771278f + y2 * 2.55016404f)); +} + +/* xombe__sin_ratio for 0 <= r < 2m, m < 2^23, im = 1/m */ +static float sin_frac(int32_t r, int32_t m, float im) +{ + if (r > m) + r -= 2 * m; + if (2 * r > m) + r = m - r; + else if (2 * r < -m) + r = -m - r; + return sinpi((float)r * im); +} + +/* e->win = xombe__hamming(n), n = e->win_len, and the line fit's table of its transform, xombe__hamming_dtft at + q/g cycles/sample (g = XOMBE_WTAB_OVERSAMPLE*XOMBE_FFT), 0.54*D(x) + 0.23*(D(x - b) + D(x + b)) with + D(x) = sin(n*x)/sin(x), x = pi*q/g, b = pi/(n - 1). every phase is an exact integer ratio stepped in q: + x -/+ b = pi*(q*(n - 1) -/+ g)/(g*(n - 1)). + table in Q15 scaled to peak, mirrored into kq.wt indexed by the integer part s of the signed Q16 position, so it + steps XOMBE_WTAB_OVERSAMPLE per bin across the centre. s >= 0 holds (wq[s], wq[s + 1]), s < 0 holds + (wq[-s], wq[-s - 1]), past XOMBE_WTAB_LEN entries it holds the last value as the float fit's table does */ +void xombe__kern_window_init(xombe_enc *e) +{ + enum { G = XOMBE_WTAB_OVERSAMPLE * XOMBE_FFT }; + uint32_t *wt = e->kq.wt + XOMBE_LF_WT_OFF; + int16_t wq[XOMBE_WTAB_LEN]; + int n = e->win_len, i, q, cur, next; + /* m < 2^23 for n <= XOMBE_MAX_WINDOW. |rm|, |rp| = |q*(n - 1) -/+ g| < 0.032 m (q/g < 0.027, 1/(n - 1) < 0.0051), + tc, tm, tp = n*q, n*rm, n*rp mod 2g or 2m */ + int32_t m = G * (n - 1), rm = -G, rp = G, tc = 0, tm = 2 * m - n * G, tp = n * G; + float im = 1.0f / (float)m, ih = 1.0f / (float)(2 * (n - 1)), gain = 0.0f; + /* cos(2*pi*i/(n - 1)) = sin(pi*(n - 1 - 4i)/(2(n - 1))), symmetric */ + for (i = 0; i <= (n - 1) / 2; i++) + e->win[i] = e->win[n - 1 - i] = 0.54f - 0.46f * sinpi((float)(n - 1 - 4 * i) * ih); + for (q = 0; q < XOMBE_WTAB_LEN; q++) { + float a = sinpi_small((float)q * (1.0f / G)), bm = sinpi_small((float)rm * im); + float bp = sinpi_small((float)rp * im); + float A = sin_frac(tc, G, 1.0f / G), Bm = sin_frac(tm, m, im), Bp = sin_frac(tp, m, im), w; + if (q > 0 && rm != 0) /* one division, a*bm*bp >= 1e-12 */ + w = (0.54f * A * bm * bp + 0.23f * a * (Bm * bp + Bp * bm)) / (a * bm * bp); + else + w = 0.54f * (q > 0 ? A / a : (float)n) + 0.23f * ((rm != 0 ? Bm / bm : (float)n) + Bp / bp); + if (q == 0) + gain = q15_gain(w, 32767.0f); /* a positive window's transform peaks at 0 */ + wq[q] = (int16_t)round_q(w * gain); + rm += n - 1; + rp += n - 1; + tc += n; + if (tc >= 2 * G) + tc -= 2 * G; + tm += n * (n - 1); + if (tm >= 2 * m) + tm -= 2 * m; + tp += n * (n - 1); + if (tp >= 2 * m) + tp -= 2 * m; + } + /* wq[q] = entry q, last entry past the end, entry -q is entry q - 1 swapped */ + cur = wq[0]; + for (q = 0; q <= XOMBE_LF_WT_OFF; q++, cur = next) { + next = wq[q + 1 < XOMBE_WTAB_LEN ? q + 1 : XOMBE_WTAB_LEN - 1]; + wt[q] = (uint16_t)cur | (uint32_t)(uint16_t)next << 16; + if (q > 0) + wt[-q] = wt[q - 1] >> 16 | wt[q - 1] << 16; + } +} diff --git a/xombe/src/enc/kern_q15_spec.c b/xombe/src/enc/kern_q15_spec.c new file mode 100644 index 0000000..41c7d1d --- /dev/null +++ b/xombe/src/enc/kern_q15_spec.c @@ -0,0 +1,217 @@ +/* q15 analysis spectrum and its line fit preparation (kernels.h, XOMBE_KERNELS=q15) */ +#include +#include "kern_q15.h" +#include "../dsp/fft_q15.h" +#include "../tables/dsp_tables.h" + +/* the XOMBE_FFT-point real transform runs as an SP_M-point complex one on sample pairs, then a real-input split */ +#define SP_M (XOMBE_FFT / 2) +#define SP_LOG2 9 +XOMBE_STATIC_ASSERT(1 << SP_LOG2 == SP_M, sp_log2); +XOMBE_STATIC_ASSERT(XOMBE_MAX_WINDOW < XOMBE_FFT, sp_window_fits); +XOMBE_STATIC_ASSERT(XOMBE_LF_BINS == XOMBE_SPEC_BINS, sp_bins); + +/* keeps one copy of the bulky stages when the compiler clones kern_spectrum for constant arguments */ +#if defined(__GNUC__) +#define SP_NOINLINE __attribute__((noinline)) +#else +#define SP_NOINLINE +#endif +#if defined(__GNUC__) && !defined(__clang__) +#define SP_NOCLONE __attribute__((noclone)) +#else +#define SP_NOCLONE +#endif + +/* 2^e, -126 <= e <= 127 */ +static float sp_pow2(int e) +{ + uint32_t u = (uint32_t)(e + 127) << 23; + float f; + memcpy(&f, &u, sizeof f); + return f; +} + +static inline uint32_t sp_abs(int32_t v) +{ + return (uint32_t)(v < 0 ? -v : v); +} + +/* bins k and SP_M - k from transform pairs a = x[k], b = x[SP_M - k] and split twiddle w, as r[0..3] = re, im of + bin k then of bin SP_M - k, in Q14 of the bins. no overflow: a dual product is at most |w| * |a| <= 2^15.5 * 2^15, + a bin component at most (1 + sqrt 2) * 2^15 * 2^14 */ +static inline void sp_bins(uint32_t a, uint32_t b, uint32_t w, int32_t r[4]) +{ + uint32_t bx = b >> 16 | b << 16; + int32_t er = (q15_lo(a) + q15_lo(b)) * 8192, ei = (q15_hi(a) - q15_hi(b)) * 8192; + /* w * (a - conj b) / i: re = wr*ai + wi*ar + wr*bi - wi*br, im = wr*br + wi*bi - (wr*ar - wi*ai) */ + int32_t pr = (q15_smladx(w, a, 0) >> 2) + (q15_smlsd(w, bx, 0) >> 2); + int32_t pi = (q15_smuad(w, b) >> 2) - (q15_smlsd(w, a, 0) >> 2); + r[0] = er + pr; + r[1] = ei + pi; + r[2] = er - pr; + r[3] = pi - ei; +} + +/* top halves of |v0| and |v1| as a pair, each |v| taken as v ^ (v >> 31), which is |v| or |v| - 1 */ +static inline uint32_t sp_top(int32_t v0, int32_t v1) +{ + return ((uint32_t)(v1 ^ (v1 >> 31)) & 0xffff0000u) | (uint32_t)(v0 ^ (v0 >> 31)) >> 16; +} + +/* splits transform x of the pairs in place, returns h with every |component| <= (h + 1) * 2^16. layout after: + bin 0 re at x[0] (im 0), bins 1..SP_M/2 - 1 re at x[k] and im at x[SP_M - k], x[SP_M/2] a copy of bin + SP_M/2's im, bins SP_M/2..SP_M re then im at x[SP_M + 2*(k - SP_M/2)]. every write lands on a word already read. + split twiddle exp(-2 pi i k/XOMBE_FFT) is xombe__fft_tw_q15[k/2] for even k, times SP_W1 for odd k */ +#define SP_W1 0xff377fffu /* exp(-2 pi i/XOMBE_FFT) in Q15 */ +static SP_NOINLINE uint32_t sp_split(uint32_t *x) +{ + const uint32_t *tw = xombe__fft_tw_q15; + int32_t r[4]; + uint32_t m = 0; + int k; + /* k = 0 pairs x[0] with itself, its im (0) lands on x[SP_M] before k = SP_M/2 writes there */ + for (k = 0; k <= SP_M / 2; k++) { + uint32_t *u = x + SP_M + 2 * (SP_M / 2 - k), w = tw[k >> 1]; + if (k & 1) + w = xombe__q15_cmul(w, SP_W1); + sp_bins(x[k], x[(SP_M - k) & (SP_M - 1)], w, r); + x[k] = (uint32_t)r[0]; + x[SP_M - k] = (uint32_t)r[1]; + u[0] = (uint32_t)r[2]; + u[1] = (uint32_t)r[3]; + m = q15_umax16(m, q15_umax16(sp_top(r[0], r[1]), sp_top(r[2], r[3]))); + } + return (m >> 16) > (m & 0xffffu) ? m >> 16 : m & 0xffffu; +} + +/* (v0, v1) * 2^p * c / 2^32 rounded, as an int16 pair */ +static inline uint32_t sp_q2(int32_t v0, int32_t v1, int p, int32_t c) +{ + return (uint16_t)q15_smmulr((int32_t)((uint32_t)v0 << p), c) | + (uint32_t)q15_smmulr((int32_t)((uint32_t)v1 << p), c) << 16; +} + +static inline void sp_st2(int16_t *d, uint32_t v) +{ + memcpy(d, &v, sizeof v); +} + +/* packs centre[j] * w[half + j] * g rounded, |j| <= half, as sample j mod XOMBE_FFT of pairs in bit-reversed order */ +static SP_NOINLINE void sp_input(uint32_t *x, const float *centre, const float *w, int half, float g) +{ + int j; + memset(x, 0, SP_M * sizeof(x[0])); + for (j = -half; j <= half; j++) { + int i = (j + XOMBE_FFT) & (XOMBE_FFT - 1); + int16_t q = (int16_t)round_q(centre[j] * w[half + j] * g); + memcpy((char *)x + (q15_rbit((uint32_t)(i >> 1)) >> (32 - SP_LOG2)) * 4 + (i & 1) * 2, &q, sizeof q); + } +} + +/* S->v from split output v, |v| <= mx, mx * 2^p in [2^30, 2^31), c = 32767 * 2^32 / (mx * 2^p) */ +static SP_NOINLINE void sp_store(xombe_spec *S, const int32_t *v, int p, int32_t c) +{ + int16_t *re = S->v, *im = re + XOMBE_LF_IM; + int k; + for (k = 0; k < SP_M / 2; k += 2) { + sp_st2(re + k, sp_q2(v[k], v[k + 1], p, c)); + sp_st2(im + k, sp_q2(v[SP_M - k], v[SP_M - k - 1], p, c)); + } + for (k = SP_M / 2; k < SP_M; k += 2) { + const int32_t *u = v + SP_M + 2 * (k - SP_M / 2); + sp_st2(re + k, sp_q2(u[0], u[2], p, c)); + sp_st2(im + k, sp_q2(u[1], u[3], p, c)); + } + sp_st2(re + SP_M, sp_q2(v[2 * SP_M], 0, p, c)); + sp_st2(im + SP_M, 0); + im[0] = 0; /* the loop took it from x[SP_M] */ +} + +/* samples block-scaled to XOMBE_CFFT_Q15_PEAK, packed in pairs in bit-reversed order for the block-floating-point + FFT, split in integer, bins scaled to int16 */ +SP_NOINLINE SP_NOCLONE void xombe__kern_spectrum(const float *centre, const float *w, int n, xombe_spec *S) +{ + uint32_t x[2 * SP_M + 2]; + const int32_t *v = (const int32_t *)x; + float m = 0.0f, g; + uint32_t mx; + int32_t c; + int half = (n - 1) / 2, j, k, s, p; + for (j = -half; j <= half; j++) { + float a = fabsf(centre[j] * w[half + j]); + if (a > m) + m = a; + } + g = q15_gain(m, (float)XOMBE_CFFT_Q15_PEAK); + S->sc = 0.0f; + if (g == 0.0f) + goto zero; + sp_input(x, centre, w, half, g); + s = xombe__cfft_q15(x, SP_M, xombe__fft_tw_q15, XOMBE_CFFT_Q15_PEAK); + /* the bound from the top halves is within 2^-10 of the largest component, else an exact scan */ + mx = sp_split(x); + if (mx >= 1024) { + mx = (mx + 1) << 16; + } else { + for (mx = 0, k = 0; k < 2 * SP_M + 2; k++) + if (sp_abs(v[k]) > mx) + mx = sp_abs(v[k]); + if (mx == 0) + goto zero; + } + /* |v| * 2^p <= mx * 2^p < 2^31, so |v| * 2^p * c / 2^32 <= 32767 after rounding for either sign. the largest + component rounds to 32767 for an exact mx */ + p = q15_clz32(mx) - 1; + c = (int32_t)(((uint64_t)32767 << 32) / (mx << p)); + sp_store(S, v, p, c); + /* x held the transform of the scaled input times 2^-s, v is Q14 of it */ + S->sc = sp_pow2(18 + s - p) / ((float)c * g); + return; +zero: + memset(S->v, 0, sizeof(S->v)); +} + +/* exact |S[k]|^2 < 2^31, one rounding to float */ +void xombe__kern_bin_power(const xombe_spec *S, float sum_w2, float *P) +{ + const int16_t *re = S->v, *im = re + XOMBE_LF_IM; + float scale = S->sc * S->sc / (XOMBE_FFT * sum_w2); + int k; + for (k = 0; k < XOMBE_SPEC_BINS; k++) + P[k] = (float)((int32_t)re[k] * re[k] + (int32_t)im[k] * im[k]) * scale; +} + +/* prefix sums of |S|^2 over kmin..kmax. the line fit's residual cancels in 31-bit sums, so a range whose peak is + below 16384 is shifted up into e->kq.spec, otherwise the bins are read in place */ +void xombe__kern_lf_prepare(xombe_enc *e, const xombe_spec *S, int kmin, int kmax, xombe_lf_spec *sp) +{ + const int16_t *re = S->v, *im = re + XOMBE_LF_IM; + uint64_t *ep = e->kq.ep, acc = 0; + uint32_t det = 0, d; + int32_t f; + int k, l; + /* every component fits q + 1 signed bits for the top detector bit q (bit 0 of each half may hold the other + half's sign), shifted up by 15 - q it stays within int16 */ + for (k = kmin; k <= kmax; k += 2) /* may take in bin kmax + 1 <= XOMBE_SPEC_BINS - 1 */ + det |= xombe__q15_det(q15_ld2(re + k)) | xombe__q15_det(q15_ld2(im + k)); + d = (det | det >> 16) & 0xfffeu; + l = d ? q15_clz32(d) - 16 : 14; + f = (int32_t)1 << l; + ep[kmin] = 0; + for (k = kmin; k <= kmax; k++) { + int32_t r = re[k] * f, i = im[k] * f; + if (l) { + e->kq.spec.v[k] = (int16_t)r; + e->kq.spec.v[XOMBE_LF_IM + k] = (int16_t)i; + } + acc += (uint32_t)(r * r) + (uint32_t)(i * i); + ep[k + 1] = acc; + } + sp->S = S; + if (l) { + e->kq.spec.sc = S->sc * sp_pow2(-l); + sp->S = &e->kq.spec; + } + sp->g = sp->S->sc > 0.0f ? 1.0f / sp->S->sc : 0.0f; +} diff --git a/xombe/src/enc/kern_state.h b/xombe/src/enc/kern_state.h new file mode 100644 index 0000000..6ba26cb --- /dev/null +++ b/xombe/src/enc/kern_state.h @@ -0,0 +1,35 @@ +#ifndef XOMBE_KERN_STATE_H +#define XOMBE_KERN_STATE_H + +/* kernel backend state, last member of struct xombe_enc, empty for float, and the analysis spectrum's layout, + which only the backend reads (kernels.h) */ +#if XOMBE_KERNELS_Q15 +#define XOMBE_LF_BINS (XOMBE_FFT / 2 + 1) +#define XOMBE_LF_IM (XOMBE_LF_BINS + 1) +/* block floating point, bin k = (v[k], v[XOMBE_LF_IM + k]) * sc, components within +/-32767 and the largest + within 2^-10 of it, sc 0 and v all zero for an all-zero spectrum. XOMBE_LF_IM even, so re[k] and im[k] share + alignment for the line fit's pair loads */ +typedef struct xombe_spec { + int16_t v[XOMBE_LF_IM + XOMBE_LF_BINS + 1]; + float sc; +} xombe_spec; +/* q15 line fit window table and prepared spectrum, off the stack. + wt: indexed by signed table position, out to XOMBE_LF_PAD_BINS bins either side of a harmonic + ep: prefix sums of |S|^2 in the prepared spectrum's units + spec: a prepared range shifted up, when its peak is below 16384 */ +#define XOMBE_LF_PAD_BINS 64 +#define XOMBE_LF_WT_OFF (XOMBE_LF_PAD_BINS * XOMBE_WTAB_OVERSAMPLE) +typedef struct { + uint32_t wt[2 * XOMBE_LF_WT_OFF + 1]; + uint64_t ep[XOMBE_LF_BINS + 1]; + xombe_spec spec; +} xombe_kern_q15; +#define XOMBE_KERN_STATE xombe_kern_q15 kq; +#else +typedef struct xombe_spec { + xombe_cpx b[XOMBE_SPEC_BINS]; +} xombe_spec; +#define XOMBE_KERN_STATE +#endif + +#endif diff --git a/xombe/src/enc/kernels.h b/xombe/src/enc/kernels.h new file mode 100644 index 0000000..d12189a --- /dev/null +++ b/xombe/src/enc/kernels.h @@ -0,0 +1,55 @@ +#ifndef XOMBE_KERNELS_H +#define XOMBE_KERNELS_H + +/* encoder inner loops, kern_float.c or kern_q15_*.c (XOMBE_KERNELS=q15) */ + +#include +#include "../internal.h" + +/* analysis spectrum S (xombe_spec, layout per backend in kern_state.h): XOMBE_SPEC_BINS bins of the + XOMBE_FFT-point transform of centre[-h..h] under window w of n = 2h + 1 points, centred on sample 0 */ +void xombe__kern_spectrum(const float *centre, const float *w, int n, xombe_spec *S); +/* P[k] = |S[k]|^2 / (XOMBE_FFT * sum_w2), XOMBE_SPEC_BINS float bins */ +void xombe__kern_bin_power(const xombe_spec *S, float sum_w2, float *P); + +/* called by xombe__enc_set_window for a new e->win_len, after it rebuilds e->win and e->wtab (float), or to build + e->win itself (q15, which leaves e->wtab unused) */ +void xombe__kern_window_init(xombe_enc *e); + +/* autocorrelation of the low-passed, windowed signal around centre into slot's pacf, energy into pe0[slot] */ +void xombe__kern_pitch_acf(xombe_enc *e, const float *centre, int slot); +/* P on the quarter-sample grid, slot not silent */ +float xombe__kern_error_at(const xombe_enc *e, int slot, float P); + +/* spectrum prepared for line fits, may keep data in e so valid only until the next prepare */ +typedef struct { + const xombe_spec *S; + float g; +} xombe_lf_spec; +/* kmin >= 1, later fits must stay within kmin..kmax */ +void xombe__kern_lf_prepare(xombe_enc *e, const xombe_spec *S, int kmin, int kmax, xombe_lf_spec *sp); +/* returns the residual of the least-squares fit of the window transform, one complex amplitude per harmonic, + to bins kmin..kmax, with per-band residual and bin energy. + q15: XOMBE_FFT / (2*XOMBE_LF_PAD_BINS - 4) <= period <= XOMBE_FFT, kmax <= XOMBE_FFT / 2 */ +float xombe__kern_line_fit(const xombe_enc *e, const xombe_lf_spec *sp, float period, int kmin, int kmax, + float band_resid[8], float band_energy[8]); + +/* voicing metric on a spectrum prepared once, to try several pitches, valid until the next prepare */ +void xombe__voicing_prepare(xombe_enc *e, const xombe_spec *S, xombe_lf_spec *sp); +void xombe__voicing_metric_sp(xombe_enc *e, const xombe_lf_spec *sp, float fhat, float m[8], float w[8]); +void xombe__voicing_soft_sp(xombe_enc *e, const xombe_lf_spec *sp, float fhat, float scale, float a[8], float w[8]); + +/* nearest harmonic of bin k, midway goes up. computed from period, not 1/period, so 1/8-sample grid periods + are exact and midway bins assign the same in any precision */ +static inline int xombe__harmonic_of(int k, float period) +{ + return (int)floorf((float)k * period / XOMBE_FFT + 0.5f); +} + +static inline int xombe__band_of(int l, float period) +{ + int band = (int)floorf((float)l * XOMBE_BANDS_PER_UNIT / period); + return band > 7 ? 7 : band; +} + +#endif diff --git a/xombe/src/enc/ns.c b/xombe/src/enc/ns.c new file mode 100644 index 0000000..cbeaf26 --- /dev/null +++ b/xombe/src/enc/ns.c @@ -0,0 +1,172 @@ +#include +#include +#include "../internal.h" + +/* 100 Hz suppression bins, NS_BINS_PER_UNIT per cycle/sample */ +#define NS_BINS_PER_UNIT 80.0f +/* voiced harmonics take half the suppression below NS_VOICED_FULL, a share rising with frequency up to + NS_VOICED_RAMP */ +#define NS_VOICED_FULL XOMBE_HZ(400.0f) +#define NS_VOICED_RAMP XOMBE_HZ(800.0f) +#define NS_GAIN_SLOPE 1.35f +#define NS_FAST 0.25f +#define NS_SLOW 0.1f +#define NS_FLOOR_UP 1.0444f +#define NS_FLOOR_DOWN 0.9591f +#define NS_MIN_LOG2 (-16.0f) + +void xombe__ns_bins(const float *P, float Xm[XOMBE_NS_BINS]) +{ + float acc[XOMBE_NS_BINS]; + int k; + memset(acc, 0, sizeof(acc)); + for (k = 0; k < XOMBE_SPEC_BINS; k++) { + int b = (int)((float)k / XOMBE_FFT * NS_BINS_PER_UNIT); + if (b < XOMBE_NS_BINS) + acc[b] += P[k]; + } + for (k = 0; k < XOMBE_NS_BINS; k++) + Xm[k] = sqrtf(acc[k]); +} + +float xombe__ns_shape(float f) +{ + static const float fx[6] = {0.0f, XOMBE_HZ(500.0f), XOMBE_HZ(1400.0f), XOMBE_HZ(3000.0f), XOMBE_HZ(3900.0f), + XOMBE_HZ(4000.0f)}; + static const float fy[6] = {0.25f, 0.25f, 1.0f, 1.0f, 0.5f, 0.5f}; + int i; + if (f <= fx[0]) + return fy[0]; + for (i = 1; i < 6; i++) + if (f <= fx[i]) + return fy[i - 1] + (fy[i] - fy[i - 1]) * (f - fx[i - 1]) / (fx[i] - fx[i - 1]); + return fy[5]; +} + +void xombe__ns_update(xombe_enc *e, const float Xm[XOMBE_NS_BINS], int speech, int confident_run, + int no_band_voiced) +{ + float s = e->ns_strength; + int k; + if (!e->ns_ready) { + memcpy(e->ns_noise, Xm, sizeof(e->ns_noise)); + e->ns_floor = 0.5f * s; + e->ns_ready = 1; + } else if (confident_run >= XOMBE_CONFIDENT_RUN) { + for (k = 0; k < XOMBE_NS_BINS; k++) + e->ns_noise[k] = (1.0f - NS_FAST) * e->ns_noise[k] + NS_FAST * Xm[k]; + } else if (no_band_voiced) { + for (k = 0; k < XOMBE_NS_BINS; k++) + if (e->ns_noise[k] > Xm[k] / 3.0f) + e->ns_noise[k] = (1.0f - NS_SLOW) * e->ns_noise[k] + NS_SLOW * Xm[k]; + } + e->ns_floor *= speech ? NS_FLOOR_UP : NS_FLOOR_DOWN; + if (e->ns_floor < 0.5f * s) + e->ns_floor = 0.5f * s; + if (e->ns_floor > s) + e->ns_floor = s; +} + +void xombe__ns_bin_voicing(const uint8_t vb[8], int ambe2_rule, uint8_t vbin[XOMBE_NS_BINS]) +{ + int k; + for (k = 0; k < XOMBE_NS_BINS; k++) { + float fc = ((float)k + 0.5f) / NS_BINS_PER_UNIT; + int j = (int)(fc * XOMBE_BANDS_PER_UNIT); + vbin[k] = (uint8_t)(ambe2_rule ? xombe__voiced_at(vb, fc) : vb[j > 7 ? 7 : j]); + } +} + +void xombe__ns_gain(const xombe_enc *e, xombe_ns_mem *m, const float Xm[XOMBE_NS_BINS], int speech, float v, + const uint8_t vbin[XOMBE_NS_BINS], float G[XOMBE_NS_BINS]) +{ + float g[XOMBE_NS_BINS], gf[XOMBE_NS_BINS], mu; + int k; + for (k = 0; k < XOMBE_NS_BINS; k++) { + float fc = ((float)k + 0.5f) / NS_BINS_PER_UNIT; + float xp = vbin[k] ? Xm[k] : Xm[k] * (1.0f + xombe__ns_shape(fc)) * 0.5f; + float gk = 0.0f; + if (xp > e->ns_noise[k]) { + gk = NS_GAIN_SLOPE * (1.0f - e->ns_noise[k] / xp); + if (gk > 1.0f) + gk = 1.0f; + } + g[k] = gk; + } + for (k = 0; k < XOMBE_NS_BINS; k++) { + float lo = g[k > 0 ? k - 1 : 0], hi = g[k < XOMBE_NS_BINS - 1 ? k + 1 : XOMBE_NS_BINS - 1]; + gf[k] = 0.25f * lo + 0.5f * g[k] + 0.25f * hi; + } + mu = speech ? 0.0f : (XOMBE_VAD_THRESHOLD - v) / XOMBE_VAD_THRESHOLD; + if (mu < 0.0f) + mu = 0.0f; + if (mu > 1.0f) + mu = 1.0f; + for (k = 0; k < XOMBE_NS_BINS; k++) { + float fc = ((float)k + 0.5f) / NS_BINS_PER_UNIT; + float gs = m->have_prev ? 0.5f * (gf[k] + m->prev_gain[k]) : gf[k]; + float fk = vbin[k] ? e->ns_floor : e->ns_floor * xombe__ns_shape(fc); + float mx = gs > fk ? gs : fk; + if (mx > 1.0f) + mx = 1.0f; + G[k] = (1.0f - mu) * mx + mu * fk; + } + memcpy(m->prev_gain, gf, sizeof(gf)); + m->have_prev = 1; +} + +static float log2_floored(float x) +{ + float d = x > 0.0f ? log2f(x) : NS_MIN_LOG2; + return d < NS_MIN_LOG2 ? NS_MIN_LOG2 : d; +} + +void xombe__ns_harmonic_offsets(const float G[XOMBE_NS_BINS], int L, float f0, const uint8_t *vh, float *da) +{ + int l; + for (l = 1; l <= L; l++) { + float f = (float)l * f0, pos = f * NS_BINS_PER_UNIT - 0.5f, gl, d; + int i; + if (pos <= 0.0f) { + gl = G[0]; + } else if (pos >= XOMBE_NS_BINS - 1) { + gl = G[XOMBE_NS_BINS - 1]; + } else { + i = (int)pos; + gl = G[i] + (G[i + 1] - G[i]) * (pos - (float)i); + } + d = log2_floored(gl); + if (vh[l]) { + if (f < NS_VOICED_FULL) + d *= 0.5f; + else if (f < NS_VOICED_RAMP) + d *= f / NS_VOICED_RAMP; + } + da[l] = d; + } +} + +void xombe__ns_apply_voice(const float G[XOMBE_NS_BINS], float *a, int L, float f0, const uint8_t v2[8]) +{ + uint8_t vh[XOMBE_LMAX + 1]; + float da[XOMBE_LMAX + 1]; + int l; + xombe__harmonic_voicing(v2, f0, L, vh); + xombe__ns_harmonic_offsets(G, L, f0, vh, da); + for (l = 1; l <= L; l++) { + a[l] += da[l]; + if (a[l] < XOMBE_AMP_MIN) + a[l] = XOMBE_AMP_MIN; + } +} + +void xombe__ns_apply_silence(const xombe_enc *e, float *a, int L, float f0) +{ + int l; + for (l = 1; l <= L; l++) { + float f = (float)l * f0; + a[l] += log2_floored(e->ns_floor * xombe__ns_shape(f)); + if (a[l] < XOMBE_AMP_MIN) + a[l] = XOMBE_AMP_MIN; + } +} diff --git a/xombe/src/enc/pitch.c b/xombe/src/enc/pitch.c new file mode 100644 index 0000000..12ea615 --- /dev/null +++ b/xombe/src/enc/pitch.c @@ -0,0 +1,185 @@ +#include +#include +#include "kernels.h" + +/* period grid from 21 samples in half-sample steps, index i is period (GRID_BASE + i)/2 */ +#define GRID_BASE 42 +#define DIGITAL_SILENCE_E0 1e-2f +/* tracking range 0.8..1.2 of a period, as TRACK_*_NUM/TRACK_DEN */ +#define TRACK_LO_NUM 4 +#define TRACK_HI_NUM 6 +#define TRACK_DEN 5 +#define BACKWARD_ACCEPT 0.48f +#define HALVING_PERIOD 100.0f +#define HALVING_MARGIN 0.1f +#define INITIAL_PERIOD 100.0f +#define REFINE_TOP XOMBE_HZ(2000.0f) /* refinement fits harmonics below this */ +/* refinement tries period +/-1 sample in 1/REFINE_STEPS steps, none below REFINE_MIN_PERIOD */ +#define REFINE_STEPS 8 +#define REFINE_MIN_PERIOD 20.0f +/* submultiple P/n replaces the forward estimate P when its cumulative error c has c <= LOOSE and c/c(P) <= + LOOSE_RATIO, c <= TIGHT and c/c(P) <= TIGHT_RATIO, or c <= ANY */ +#define SUBMULT_LOOSE 0.85f +#define SUBMULT_LOOSE_RATIO 1.7f +#define SUBMULT_TIGHT 0.4f +#define SUBMULT_TIGHT_RATIO 3.5f +#define SUBMULT_ANY 0.05f + +void xombe__pitch_init(xombe_enc *e) +{ + e->p_prev = INITIAL_PERIOD; + e->e_prev1 = e->e_prev2 = 0.0f; +} + +static float grid_period(int i) +{ + return 0.5f * (float)(GRID_BASE + i); +} + +static int grid_index(float P) +{ + return (int)(2.0f * P + 0.5f) - GRID_BASE; +} + +/* b > 0 */ +static int floor_div(int a, int b) +{ + return a >= 0 ? a / b : -((-a + b - 1) / b); +} + +static float error_at(const xombe_enc *e, int slot, float P) +{ + return e->psilent[slot] ? 1.0f : xombe__kern_error_at(e, slot, P); +} + +void xombe__pitch_errors(xombe_enc *e, const float *centre, int slot) +{ + int i; + xombe__kern_pitch_acf(e, centre, slot); + e->psilent[slot] = e->pe0[slot] < DIGITAL_SILENCE_E0; + for (i = 0; i < XOMBE_PITCH_GRID; i++) + e->perr[slot][i] = error_at(e, slot, grid_period(i)); +} + +/* in exact arithmetic, since 0.8*P and 1.2*P land on the grid for some P and those ends are included */ +static void grid_range(int i, int *lo, int *hi) +{ + *lo = -floor_div(TRACK_DEN * GRID_BASE - TRACK_LO_NUM * (GRID_BASE + i), TRACK_DEN); + *hi = floor_div(TRACK_HI_NUM * (GRID_BASE + i) - TRACK_DEN * GRID_BASE, TRACK_DEN); + if (*lo < 0) + *lo = 0; + if (*hi > XOMBE_PITCH_GRID - 1) + *hi = XOMBE_PITCH_GRID - 1; +} + +static int argmin_range(const float *v, int lo, int hi) +{ + int i, best = lo; + for (i = lo + 1; i <= hi; i++) + if (v[i] < v[best]) + best = i; + return best; +} + +XOMBE_STATIC_ASSERT(XOMBE_PITCH_GRID <= 256, grid_index_fits_uchar); + +/* argmin_range(v, lo[i], hi[i]) for every i, lo[i] when empty, first on ties. linear time with a monotonic deque, + both ends being nondecreasing in i */ +static void sliding_argmin(const float *v, const unsigned char *lo, const unsigned char *hi, unsigned char *out) +{ + unsigned char dq[XOMBE_PITCH_GRID]; + int i, head = 0, tail = 0, next = 0; + for (i = 0; i < XOMBE_PITCH_GRID; i++) { + if (lo[i] > hi[i]) { + out[i] = lo[i]; + continue; + } + if (next < lo[i]) + next = lo[i]; + for (; next <= hi[i]; next++) { + while (tail > head && v[dq[tail - 1]] > v[next]) + tail--; + dq[tail++] = (unsigned char)next; + } + while (dq[head] < lo[i]) + head++; + out[i] = dq[head]; + } +} + +float xombe__pitch_track(xombe_enc *e, int cur, int next1, int next2) +{ + const float *E0 = e->perr[cur], *E1 = e->perr[next1], *E2 = e->perr[next2]; + float min2[XOMBE_PITCH_GRID], ce_f[XOMBE_PITCH_GRID], ce_b, period; + unsigned char rlo[XOMBE_PITCH_GRID], rhi[XOMBE_PITCH_GRID], am[XOMBE_PITCH_GRID]; + int i, lo, hi, pb, pf, n; + if (e->psilent[cur]) + return e->p_prev; + grid_range(grid_index(e->p_prev), &lo, &hi); + pb = lo <= hi ? argmin_range(E0, lo, hi) : 0; + ce_b = E0[pb] + e->e_prev1 + e->e_prev2; + for (i = 0; i < XOMBE_PITCH_GRID; i++) { + grid_range(i, &lo, &hi); + rlo[i] = (unsigned char)lo; + rhi[i] = (unsigned char)hi; + } + sliding_argmin(E2, rlo, rhi, am); + for (i = 0; i < XOMBE_PITCH_GRID; i++) + min2[i] = E2[am[i]]; + sliding_argmin(E1, rlo, rhi, am); + for (i = 0; i < XOMBE_PITCH_GRID; i++) + ce_f[i] = E0[i] + E1[am[i]] + min2[am[i]]; + pf = argmin_range(ce_f, 0, XOMBE_PITCH_GRID - 1); + for (n = (GRID_BASE + pf) / GRID_BASE; n >= 2; n--) { + /* grid index nearest P/n, halves up: floor((GRID_BASE + pf)/n - GRID_BASE + 1/2) */ + int idx = floor_div(2 * (GRID_BASE + pf - n * GRID_BASE) + n, 2 * n); + float c, ratio; + if (idx < 0) + idx = 0; + c = ce_f[idx]; + ratio = c / (ce_f[pf] > 1e-9f ? ce_f[pf] : 1e-9f); + if ((c <= SUBMULT_LOOSE && ratio <= SUBMULT_LOOSE_RATIO) || (c <= SUBMULT_TIGHT && ratio <= SUBMULT_TIGHT_RATIO) || + c <= SUBMULT_ANY) { + pf = idx; + break; + } + } + i = (ce_b <= BACKWARD_ACCEPT || ce_b <= ce_f[pf]) ? pb : pf; + period = grid_period(i); + e->e_prev2 = e->e_prev1; + e->e_prev1 = E0[i]; + e->p_prev = period; + if (period > HALVING_PERIOD && error_at(e, cur, 0.5f * period) <= E0[i] + HALVING_MARGIN) + period /= 2.0f; + return period; +} + +int xombe__pitch_window_len(float period) +{ + int n = 2 * (int)floorf((2.5f * period - 1.0f) / 2.0f + 0.5f) + 1; + if (n < XOMBE_BASE_WINDOW) + n = XOMBE_BASE_WINDOW; + if (n > XOMBE_MAX_WINDOW) + n = XOMBE_MAX_WINDOW; + return n; +} + +float xombe__pitch_refine(xombe_enc *e, const xombe_spec *S, float period) +{ + float best = 0.0f, band_r[8], band_e[8], best_p = period; + int d, found = 0, kmax = (int)(REFINE_TOP * XOMBE_FFT); + xombe_lf_spec sp; + xombe__kern_lf_prepare(e, S, 1, kmax, &sp); + for (d = -REFINE_STEPS; d <= REFINE_STEPS; d++) { + float p = period + (float)d / REFINE_STEPS, r; + if (p < REFINE_MIN_PERIOD) + continue; + r = xombe__kern_line_fit(e, &sp, p, (int)ceilf(0.5f * XOMBE_FFT / p), kmax, band_r, band_e); + if (!found || r < best) { + found = 1; + best = r; + best_p = p; + } + } + return best_p; +} diff --git a/xombe/src/enc/quant.c b/xombe/src/enc/quant.c new file mode 100644 index 0000000..8dc2199 --- /dev/null +++ b/xombe/src/enc/quant.c @@ -0,0 +1,54 @@ +#include "../internal.h" +#include "../tables/tables.h" +#include "../tables/dsp_tables.h" + +void xombe__quantize(const xombe_pred *pi, int silence, int L, const float *target, int b[9]) +{ + float pt[XOMBE_LMAX + 1]; + float r[XOMBE_LMAX + 1], mean_t = 0.0f, mean_p = 0.0f, R[8], G[9], C[4][7]; + int l, k, m, i, pos = 1; + xombe__predict(pi, L, pt); + for (l = 1; l <= L; l++) { + mean_t += target[l]; + mean_p += pt[l]; + } + mean_t /= (float)L; + mean_p /= (float)L; + { + float dgamma = mean_t + xombe__half_log2[L] - xombe__amp_ambe2.grho * pi->gamma; + if (silence) + dgamma += XOMBE_SILENCE_GAIN_OFFSET; + b[2] = xombe__nearest_row(xombe__dg, 32, 1, 1, &dgamma, NULL); + } + for (l = 1; l <= L; l++) + r[l] = target[l] - XOMBE_RHO * (pt[l] - mean_p); + for (k = 0; k < 4; k++) { + int J = xombe__blk[L][k], top = J < 6 ? J : 6; + const float *kern = xombe__dct_blk + xombe__dct_blk_off[J]; + for (m = 1; m <= 6; m++) { + float s = 0.0f; + if (m <= top) + for (i = 0; i < J; i++) + s += r[pos + i] * kern[(m - 1) * J + i]; + C[k][m] = m <= top ? s / (float)J : 0.0f; + } + if (J < 2) + C[k][2] = 0.0f; + pos += J; + R[2 * k] = C[k][1] + 1.41421356f * C[k][2]; + R[2 * k + 1] = C[k][1] - 1.41421356f * C[k][2]; + } + for (m = 1; m <= 8; m++) { + float s = 0.0f; + for (i = 0; i < 8; i++) + s += R[i] * xombe__dct8[m - 1][i]; + G[m] = s / 8.0f; + } + b[3] = xombe__nearest_row(&xombe__prba24[0][0], 512, 3, 3, &G[2], NULL); + b[4] = xombe__nearest_row(&xombe__prba58[0][0], 128, 4, 4, &G[5], NULL); + for (k = 0; k < 4; k++) { + int J = xombe__blk[L][k], used = (J < 6 ? J : 6) - 2, rows; + const float *tab = xombe__hoc_table(k, &rows); + b[5 + k] = used > 0 ? xombe__nearest_row(tab, rows, 4, used, &C[k][3], NULL) : 0; + } +} diff --git a/xombe/src/enc/tone_detect.c b/xombe/src/enc/tone_detect.c new file mode 100644 index 0000000..bb7e988 --- /dev/null +++ b/xombe/src/enc/tone_detect.c @@ -0,0 +1,720 @@ +#include +#include +#include "../internal.h" +#include "../tables/dsp_tables.h" +#include "../dsp/biquad.h" +#if XOMBE_KERNELS_Q15 +#include "kern_q15.h" +#include "../dsp/fft_q15.h" +#endif + +#define EXPLAINED_MIN 0.99f +#define DUAL_GATE_SHARE 0.7f +#define DUAL_GATE_SPAN 0.10f +#define DUAL_TWIST_DB 10.0f +#define DUAL_PREFERENCE 0.01f +#define SINGLE_ID_HZ 31.25f /* single-tone IDs are multiples of this frequency */ +#define GATE_LO_HZ 100.0f /* dual-tone gate reference band GATE_LO_HZ..GATE_HI_HZ */ +#define GATE_HI_HZ 3900.0f +#define BIN_HZ (XOMBE_FS / XOMBE_TONE_FFT) + +XOMBE_STATIC_ASSERT(XOMBE_TONE_FFT >= 2 * XOMBE_TONE_SEG, tone_fft_pads_the_segment); + +#if XOMBE_KERNELS_Q15 +#define DUAL_SLACK 1e-3f /* rounding allowance on an explained fraction of 1 */ +#define TWIST_RATIO 3.16227766f /* 10^(DUAL_TWIST_DB/20) */ +#define GATE_NUM 7u /* DUAL_GATE_SHARE = GATE_NUM/GATE_DEN */ +#define GATE_DEN 10u +typedef uint64_t pow_sum; + +/* sin and cos of 2*pi*t for |t| < 2^21, reduced exactly to a quarter turn q/4 plus f, |f| <= 1/8, Taylor + polynomials to a^9 and a^8 in a = 2*pi*f, truncation under 1e-9 */ +static void sincos_turn(float t, float *s, float *c) +{ + int q = round_q(4.0f * t); + float a = 2.0f * XOMBE_PI_F * (t - 0.25f * (float)q), a2 = a * a, sn, cs; + sn = a * (1.0f + a2 * (-1.0f / 6 + a2 * (1.0f / 120 + a2 * (-1.0f / 5040 + a2 * (1.0f / 362880))))); + cs = 1.0f + a2 * (-0.5f + a2 * (1.0f / 24 + a2 * (-1.0f / 720 + a2 * (1.0f / 40320)))); + switch (q & 3) { + case 0: *s = sn; *c = cs; break; + case 1: *s = cs; *c = -sn; break; + case 2: *s = -sn; *c = -cs; break; + default: *s = -cs; *c = sn; break; + } +} +#else +typedef float pow_sum; +#endif + +/* one sinusoid of the fit */ +typedef struct { + float hz; /* Hz, w below is radians/sample */ + float rc, rs; /* sum of x[n]*cos(w*n) and of x[n]*sin(w*n) */ + float h[2]; /* cos and sin of w/2 */ + float m[2]; /* cos and sin of (2*len - 1)*w/2 */ + float g[4]; /* own Gram block gram(c, c), set by fit_component */ +} component; + +#if XOMBE_KERNELS_Q15 +/* hz, h, and m of c */ +static void angles(int len, float hz, component *c) +{ + float u = hz * (0.5f / XOMBE_FS); /* w/2 in turns */ + c->hz = hz; + sincos_turn(u, &c->h[1], &c->h[0]); + sincos_turn((float)(2 * len - 1) * u, &c->m[1], &c->m[0]); +} +#endif + +/* correlates x with cos and sin at hz, Goertzel run from x[len - 1] down so its final states need no rotation, + in Reinsch's form (d = s[n] -/+ s[n - 1]), as plain Goertzel loses about 5 bits near 0 Hz and fs/2 */ +static void correlate(const float *x, int len, float hz, component *c) +{ +#if XOMBE_KERNELS_Q15 + float hc, hs; + angles(len, hz, c); + hc = c->h[0]; + hs = c->h[1]; +#else + float w = 2.0f * XOMBE_PI_F * hz / XOMBE_FS, hc = cosf(0.5f * w), hs = sinf(0.5f * w); +#endif + float cw = hc * hc - hs * hs, s = 0.0f, d = 0.0f, prev; + int n = len - 1; + if (cw >= 0.0f) { + float l = -4.0f * hs * hs; + for (; n > 0; n -= 2) { + d += x[n] + l * s; + s += d; + d += x[n - 1] + l * s; + s += d; + } + if (n == 0) { + d += x[0] + l * s; + s += d; + } + prev = s - d; + } else { + float l = 4.0f * hc * hc; + for (; n > 0; n -= 2) { + d = x[n] + l * s - d; + s = d - s; + d = x[n - 1] + l * s - d; + s = d - s; + } + if (n == 0) { + d = x[0] + l * s - d; + s = d - s; + } + prev = d - s; + } + c->rc = s - cw * prev; + c->rs = 2.0f * hs * hc * prev; +#if !XOMBE_KERNELS_Q15 + c->hz = hz; + c->h[0] = hc; + c->h[1] = hs; + c->m[0] = cosf((float)(2 * len - 1) * 0.5f * w); + c->m[1] = sinf((float)(2 * len - 1) * 0.5f * w); +#endif +} + +/* sums of cos(th*n) and sin(th*n) over the segment, a Dirichlet kernel, from cos and sin of th/2 (h) and of + (2*len - 1)*th/2 (m) */ +static void dsum(const float h[2], const float m[2], int len, float *c, float *s) +{ + if (fabsf(h[1]) < 1e-6f) { + *c = (float)len; + *s = 0.0f; + return; + } + *c = 0.5f + 0.5f * m[1] / h[1]; + *s = 0.5f * (h[0] - m[0]) / h[1]; +} + +/* Gram block of a and b, rows cos_a, sin_a, columns cos_b, sin_b, row-major, dsum angles by angle addition */ +static void gram(const component *a, const component *b, int len, float g[4]) +{ + float cd, sd, cs, ss, hd[2], md[2], hs[2], ms[2]; + hd[0] = a->h[0] * b->h[0] + a->h[1] * b->h[1]; + hd[1] = a->h[1] * b->h[0] - a->h[0] * b->h[1]; + md[0] = a->m[0] * b->m[0] + a->m[1] * b->m[1]; + md[1] = a->m[1] * b->m[0] - a->m[0] * b->m[1]; + hs[0] = a->h[0] * b->h[0] - a->h[1] * b->h[1]; + hs[1] = a->h[1] * b->h[0] + a->h[0] * b->h[1]; + ms[0] = a->m[0] * b->m[0] - a->m[1] * b->m[1]; + ms[1] = a->m[1] * b->m[0] + a->m[0] * b->m[1]; + dsum(hd, md, len, &cd, &sd); + dsum(hs, ms, len, &cs, &ss); + g[0] = 0.5f * (cd + cs); + g[1] = 0.5f * (ss - sd); + g[2] = 0.5f * (ss + sd); + g[3] = 0.5f * (cd - cs); +} + +/* correlate plus own Gram block, so a trial moving one component recomputes only its own */ +static void fit_component(const float *x, int len, float hz, component *c) +{ + correlate(x, len, hz, c); + gram(c, c, len, c->g); +} + +#if XOMBE_KERNELS_Q15 +/* correlations of x already taken in one search, keyed by frequency (hz 0: empty slot). pairs share + frequencies (DTMF rows and columns) and revisit trial steps, so on the worst frames over half the + correlations repeat */ +#define MEMO_LOG2 7 +#define MEMO_SLOTS (1 << MEMO_LOG2) +#define MEMO_PROBES 8 +typedef struct { + float hz[MEMO_SLOTS], rc[MEMO_SLOTS], rs[MEMO_SLOTS]; +} corr_memo; + +/* fit_component through the memo, a full probe run computes without storing */ +static void memo_component(corr_memo *mo, const float *x, int len, float hz, component *c) +{ + uint32_t bits; + int i, probe; + memcpy(&bits, &hz, sizeof(bits)); + i = (int)((bits * 2654435761u) >> (32 - MEMO_LOG2)); + for (probe = 0; probe < MEMO_PROBES; probe++, i = (i + 1) & (MEMO_SLOTS - 1)) { + if (mo->hz[i] == hz) { + angles(len, hz, c); + c->rc = mo->rc[i]; + c->rs = mo->rs[i]; + gram(c, c, len, c->g); + return; + } + if (mo->hz[i] == 0.0f) { + fit_component(x, len, hz, c); + mo->hz[i] = hz; + mo->rc[i] = c->rc; + mo->rs[i] = c->rs; + return; + } + } + fit_component(x, len, hz, c); +} +/* pair_fit's memo parameter and argument, absent in float builds */ +#define PAIR_COMPONENT(x, len, hz, c) memo_component(mo, x, len, hz, c) +#define PAIR_MEMO corr_memo *mo, +#define PAIR_MEMO_ARG &memo, +#else +#define PAIR_COMPONENT(x, len, hz, c) fit_component(x, len, hz, c) +#define PAIR_MEMO +#define PAIR_MEMO_ARG +#endif + +/* solves 2x2 m*p = r, returns 0 if m is singular */ +static int solve2(const float m[4], const float r[2], float p[2]) +{ + float det = m[0] * m[3] - m[1] * m[2]; + if (fabsf(det) <= 1e-6f * (m[0] * m[0] + m[3] * m[3])) + return 0; + p[0] = (m[3] * r[0] - m[1] * r[1]) / det; + p[1] = (m[0] * r[1] - m[2] * r[0]) / det; + return 1; +} + +static float magnitude(const float p[2]) +{ +#if XOMBE_KERNELS_Q15 + return sqrtf(p[0] * p[0] + p[1] * p[1]); +#else + return hypotf(p[0], p[1]); +#endif +} + +/* least-squares fit of nf (1 or 2) sinusoids, returns the fraction of energy explained and each amplitude, + 0 and amplitudes 0 for a singular system. two components solved by blocks (Schur complement of the first block) */ +static float fit(float energy, const component *c, int nf, int len, float amp[2]) +{ + const float *A = c[0].g; + float ra[2], pa[2], explained; + amp[0] = amp[1] = 0.0f; + ra[0] = c[0].rc; + ra[1] = c[0].rs; + if (nf == 1) { + if (!solve2(A, ra, pa)) + return 0.0f; + explained = pa[0] * ra[0] + pa[1] * ra[1]; + } else { + const float *B = c[1].g; + float C[4], Y[4], y[2], S[4], rhs[2], pb[2], col[2], cj[2], rb[2]; + int j; + rb[0] = c[1].rc; + rb[1] = c[1].rs; + gram(&c[0], &c[1], len, C); + if (!solve2(A, ra, y)) + return 0.0f; + for (j = 0; j < 2; j++) { /* Y = A^-1*C, column by column */ + cj[0] = C[j]; + cj[1] = C[2 + j]; + if (!solve2(A, cj, col)) + return 0.0f; + Y[j] = col[0]; + Y[2 + j] = col[1]; + } + /* S = B - C^T*Y, rhs = rb - C^T*y */ + S[0] = B[0] - (C[0] * Y[0] + C[2] * Y[2]); + S[1] = B[1] - (C[0] * Y[1] + C[2] * Y[3]); + S[2] = B[2] - (C[1] * Y[0] + C[3] * Y[2]); + S[3] = B[3] - (C[1] * Y[1] + C[3] * Y[3]); + rhs[0] = rb[0] - (C[0] * y[0] + C[2] * y[1]); + rhs[1] = rb[1] - (C[1] * y[0] + C[3] * y[1]); + if (!solve2(S, rhs, pb)) + return 0.0f; + pa[0] = y[0] - (Y[0] * pb[0] + Y[1] * pb[1]); + pa[1] = y[1] - (Y[2] * pb[0] + Y[3] * pb[1]); + amp[1] = magnitude(pb); + explained = pa[0] * ra[0] + pa[1] * ra[1] + pb[0] * rb[0] + pb[1] * rb[1]; + } + amp[0] = magnitude(pa); + return explained / energy; +} + +static int in_gate(int k, float nominal) +{ + return fabsf((float)k * BIN_HZ - nominal) <= DUAL_GATE_SPAN * nominal; +} + +/* bins *lo..*hi of nominal's dual-tone gate, empty when *lo > *hi. the gate is at least a bin wide and k*BIN_HZ + is exact, so in_gate holds on one run of k containing the nearest bin, each end a step or two from its estimate */ +static void gate_run(float nominal, int *lo, int *hi) +{ + int k0 = (int)(nominal / BIN_HZ + 0.5f), k; + if (k0 > XOMBE_TONE_FFT / 2) + k0 = XOMBE_TONE_FFT / 2; + if (!in_gate(k0, nominal)) { + *lo = 1; + *hi = 0; + return; + } + k = (int)ceilf((1.0f - DUAL_GATE_SPAN) * nominal / BIN_HZ); + k = k < 0 ? 0 : k > k0 ? k0 : k; + while (k > 0 && in_gate(k - 1, nominal)) + k--; + while (k < k0 && !in_gate(k, nominal)) + k++; + *lo = k; + k = (int)floorf((1.0f + DUAL_GATE_SPAN) * nominal / BIN_HZ); + k = k < k0 ? k0 : k > XOMBE_TONE_FFT / 2 ? XOMBE_TONE_FFT / 2 : k; + while (k < XOMBE_TONE_FFT / 2 && in_gate(k + 1, nominal)) + k++; + while (k > k0 && !in_gate(k, nominal)) + k--; + *hi = k; +} + +static int ad_from_level(float level_db_minus_filter) +{ + int ad = (int)floorf(127.0f + level_db_minus_filter / XOMBE_TONE_DB_PER_AD + 0.5f); + return ad < 0 ? 0 : ad > 127 ? 127 : ad; +} + +static float peak_db(float amp) +{ + return 20.0f * log10f(amp / 32768.0f + 1e-30f); +} + +#if !XOMBE_KERNELS_Q15 +static void spectrum(xombe_enc *e, const float *x, int len, const float *win, float pw[XOMBE_TONE_FFT / 2 + 1]) +{ + xombe_cpx *X = e->tone_spec; + int n, k; + /* packed two samples per bin for xombe__rfft_packed */ + memset(e->tone_spec, 0, sizeof(e->tone_spec)); + for (n = 0; n < len; n++) { + float v = x[n] * win[n]; + if (n & 1) + X[n >> 1].im = v; + else + X[n >> 1].re = v; + } + xombe__rfft_packed(X, XOMBE_TONE_FFT, xombe__fft_tw, XOMBE_TW_N); + for (k = 0; k <= XOMBE_TONE_FFT / 2; k++) + pw[k] = X[k].re * X[k].re + X[k].im * X[k].im; +} +#else +#define SPEC_M (XOMBE_TONE_FFT / 2) +#define SPEC_LOG2 8 +XOMBE_STATIC_ASSERT(1 << SPEC_LOG2 == SPEC_M, spec_log2); + +/* bin powers of the windowed segment through the SPEC_M point block-floating-point FFT of sample pairs, in + place over pw: samples block-scaled to XOMBE_CFFT_Q15_PEAK, real-input split in integer, one power unit for + every bin of the segment */ +static void spectrum(xombe_enc *e, const float *x, int len, const float *win, uint32_t pw[XOMBE_TONE_FFT / 2 + 1]) +{ + uint32_t *z = pw; + float m = 0.0f, g; + int n, k; + (void)e; + for (n = 0; n < len; n++) { + float a = fabsf(x[n] * win[n]); + m = a > m ? a : m; + } + g = q15_gain(m, (float)XOMBE_CFFT_Q15_PEAK); + memset(z, 0, SPEC_M * sizeof(*z)); + if (g == 0.0f) { + pw[SPEC_M] = 0; + return; + } + for (n = 0; n < len; n += 2) { + int32_t lo = round_q(x[n] * win[n] * g), hi = n + 1 < len ? round_q(x[n + 1] * win[n + 1] * g) : 0; + z[q15_rbit((uint32_t)(n >> 1)) >> (32 - SPEC_LOG2)] = ((uint32_t)lo & 0xffffu) | (uint32_t)hi << 16; + } + xombe__cfft_q15(z, SPEC_M, xombe__tone_tw_q15, XOMBE_CFFT_Q15_PEAK); + /* bins k and SPEC_M - k from Z[k] and Z[SPEC_M - k], 2*X[k] = E + W^k*O with W^k = xombe__fft_tw_q15[k]: + components of E and O within +/-2^16, so |2*X| <= 2^17.5 and |2*X|^2 >> 4 <= 2^31. the Q15 product + sums reach 2^32 and take 64 bits */ + for (k = 0; k <= SPEC_M / 2; k++) { + uint32_t a = z[k], b = z[(SPEC_M - k) & (SPEC_M - 1)]; + int32_t er = q15_lo(a) + q15_lo(b), ei = q15_hi(a) - q15_hi(b); + int32_t orr = q15_hi(a) + q15_hi(b), oi = q15_lo(b) - q15_lo(a), wr = 0, wi = -32768, pr, pi, r0, i0, r1, i1; + if (k < SPEC_M / 2) { + wr = q15_lo(xombe__fft_tw_q15[k]); + wi = q15_hi(xombe__fft_tw_q15[k]); + } + pr = (int32_t)(((int64_t)wr * orr - (int64_t)wi * oi + 16384) >> 15); + pi = (int32_t)(((int64_t)wr * oi + (int64_t)wi * orr + 16384) >> 15); + r0 = er + pr; + i0 = ei + pi; + r1 = er - pr; + i1 = pi - ei; + pw[k] = (uint32_t)(((uint64_t)((int64_t)r0 * r0) + (uint64_t)((int64_t)i0 * i0)) >> 4); + pw[SPEC_M - k] = (uint32_t)(((uint64_t)((int64_t)r1 * r1) + (uint64_t)((int64_t)i1 * i1)) >> 4); + } +} +#endif + +/* mean-removed segment into x, returns its energy or 0 below the -50 dBFS sinusoid floor. above it, fills pw + with the zero-padded bin powers of the segment under win */ +static float prepare(xombe_enc *e, const int16_t *seg, int len, const float *win, float *x, + xombe_tone_pow pw[XOMBE_TONE_FFT / 2 + 1]) +{ + static const float min_amp = 32768.0f * 0.0031622777f; /* -50 dBFS peak */ + float mean, energy = 0.0f; + long sum = 0; + int n; + for (n = 0; n < len; n++) + sum += seg[n]; + mean = (float)sum / len; + for (n = 0; n < len; n++) { + x[n] = (float)seg[n] - mean; + energy += x[n] * x[n]; + } + if (energy / len < 0.5f * min_amp * min_amp) + return 0.0f; + spectrum(e, x, len, win, pw); + return energy; +} + +static pow_sum band_total(const xombe_tone_pow *pw) +{ + pow_sum total = 0; + int k; + for (k = (int)ceilf(GATE_LO_HZ / BIN_HZ); k <= (int)floorf(GATE_HI_HZ / BIN_HZ); k++) + total += pw[k]; + return total; +} + +/* at least DUAL_GATE_SHARE of total within DUAL_GATE_SPAN of either nominal frequency */ +static int gate_pass(const xombe_tone_pow *pw, const float nominal[2], pow_sum total) +{ + pow_sum near = 0; + int k, r0lo, r0hi, r1lo, r1hi, klo, khi; + /* summed in ascending bins over the union of the two runs */ + gate_run(nominal[0], &r0lo, &r0hi); + gate_run(nominal[1], &r1lo, &r1hi); + klo = r0lo <= r0hi ? r0lo : r1lo; + khi = r0lo <= r0hi ? r0hi : r1hi; + if (r1lo <= r1hi) { + klo = r1lo < klo ? r1lo : klo; + khi = r1hi > khi ? r1hi : khi; + } + for (k = klo; k <= khi; k++) + if ((k >= r0lo && k <= r0hi) || (k >= r1lo && k <= r1hi)) + near += pw[k]; +#if XOMBE_KERNELS_Q15 + return near * GATE_DEN >= total * GATE_NUM; +#else + return !(near < DUAL_GATE_SHARE * total); +#endif +} + +#define FINE_FFT 8192 /* single-tone peak grid */ +#define FINE_HZ (XOMBE_FS / FINE_FFT) +#define FINE_LO 103 /* FINE_FFT bins in GATE_LO_HZ..GATE_HI_HZ */ +#define FINE_HI 3993 +#define REFINE_SPAN 0.4f /* single-tone refinement, +/- fine bins around the peak */ +#define REFINE_ITERS 12 +/* explained fraction moves at most ~0.15 per Hz for a 160-sample segment (the fit subspace turns at most + 2*pi*rms(n)/fs radians per Hz), so refining within REFINE_SPAN (0.39 Hz) gains under 0.06 and a fit this far + below the threshold cannot reach it */ +#define REFINE_REACH 0.1f +#define DUAL_STEP 0.0025f /* relative dual search step, steps are 4, 2, and 1 of these */ +#define DUAL_STEPS_MAX 10 /* +/-2.5% of nominal in steps */ +#define PAIR_TRIALS 24 /* pair_fit trials, 2 passes x 3 steps x 2 components x 2 signs */ + +float xombe__tone_hpf_gain_db(float hz) +{ + const float p1 = (float)HPF_POLE1, a1 = (float)HPF_A1, a2 = (float)HPF_A2; + float w = 2.0f * XOMBE_PI_F * hz / XOMBE_FS, cr = cosf(w), ci = -sinf(w), c2r = cosf(2.0f * w), + c2i = -sinf(2.0f * w); + float zr = 1.0f - cr, zi = -ci, nr = zr * zr - zi * zi, ni = 2.0f * zr * zi; + float n3r = nr * zr - ni * zi, n3i = nr * zi + ni * zr; + float d1r = 1.0f - p1 * cr, d1i = -p1 * ci, d2r = 1.0f - a1 * cr + a2 * c2r, d2i = -a1 * ci + a2 * c2i; + float num = n3r * n3r + n3i * n3i, den = (d1r * d1r + d1i * d1i) * (d2r * d2r + d2i * d2i); + return 10.0f * log10f(num / den); +} + +/* windowed segment power at FINE_FFT bin k */ +static float fine_power(const float *xw, int len, int k) +{ + component c; + correlate(xw, len, (float)k * FINE_HZ, &c); + return c.rc * c.rc + c.rs * c.rs; +} + +/* largest pw bin in the gate band, in bins, placed by a parabola through log magnitudes: the Hann peak is + near-Gaussian, so within 0.1 Hz */ +static float coarse_peak(const xombe_tone_pow *pw) +{ + int k, kc = -1, klo = (int)ceilf(GATE_LO_HZ / BIN_HZ), khi = (int)floorf(GATE_HI_HZ / BIN_HZ); + float la, lb, lc, d; + for (k = klo; k <= khi; k++) + if (kc < 0 || pw[k] > pw[kc]) + kc = k; + la = 0.5f * logf((float)pw[kc - 1] + 1e-30f); + lb = 0.5f * logf((float)pw[kc] + 1e-30f); + lc = 0.5f * logf((float)pw[kc + 1] + 1e-30f); + d = la - 2.0f * lb + lc; + return (float)kc + (d != 0.0f ? 0.5f * (la - lc) / d : 0.0f); +} + +/* largest FINE_FFT bin in the gate band plus a parabola through log magnitudes, found by climbing the fine grid + from the coarse peak */ +static float peak_hz(const float *x, const float *win, int len, const xombe_tone_pow *pw) +{ + int kf = (int)floorf(coarse_peak(pw) * (float)(FINE_FFT / XOMBE_TONE_FFT) + 0.5f), n; + float xw[XOMBE_TONE_SEG], pm, pl, pr, a, b, c, den; + for (n = 0; n < len; n++) + xw[n] = x[n] * win[n]; + kf = kf < FINE_LO ? FINE_LO : kf > FINE_HI ? FINE_HI : kf; + pm = fine_power(xw, len, kf); + pl = fine_power(xw, len, kf - 1); + pr = fine_power(xw, len, kf + 1); + while (pr > pm && kf < FINE_HI) { + kf++; + pl = pm; + pm = pr; + pr = fine_power(xw, len, kf + 1); + } + while (pl > pm && kf > FINE_LO) { + kf--; + pr = pm; + pm = pl; + pl = fine_power(xw, len, kf - 1); + } + a = 0.5f * logf(pl + 1e-30f); + b = 0.5f * logf(pm + 1e-30f); + c = 0.5f * logf(pr + 1e-30f); + den = a - 2.0f * b + c; + return ((float)kf + (den != 0.0f ? 0.5f * (a - c) / den : 0.0f)) * FINE_HZ; +} + +/* ternary search for the best single-tone fit within REFINE_SPAN fine bins of f1 */ +static float fit_refined(const float *x, int len, float energy, float f1, float amp[2]) +{ + float lo = f1 - REFINE_SPAN * FINE_HZ, hi = f1 + REFINE_SPAN * FINE_HZ, unused[2]; + component c; + int it; + for (it = 0; it < REFINE_ITERS; it++) { + float fa = lo + (hi - lo) / 3.0f, fb = hi - (hi - lo) / 3.0f, ea, eb; + fit_component(x, len, fa, &c); + ea = fit(energy, &c, 1, len, unused); + fit_component(x, len, fb, &c); + eb = fit(energy, &c, 1, len, unused); + if (ea > eb) + hi = fb; + else + lo = fa; + } + fit_component(x, len, 0.5f * (lo + hi), &c); + return fit(energy, &c, 1, len, amp); +} + +/* coordinate search in relative steps of 4, 2, and 1 DUAL_STEP, each pass trying each step on the first + component then the second, up then down */ +static float pair_fit(PAIR_MEMO const float *x, int len, float energy, const float nominal[2], float hz[2], + float amp[2]) +{ + static const int steps[3] = {4, 2, 1}; + component comp[2]; + int d[2] = {0, 0}, seen[PAIR_TRIALS + 1], pass, s, c, sign, nseen = 1; + float best, trial_amp[2] = {0.0f, 0.0f}; + PAIR_COMPONENT(x, len, nominal[0], &comp[0]); + PAIR_COMPONENT(x, len, nominal[1], &comp[1]); + best = fit(energy, comp, 2, len, amp); + seen[0] = 0; + for (pass = 0; pass < 2; pass++) + for (s = 0; s < 3; s++) + for (c = 0; c < 2; c++) + for (sign = 1; sign >= -1; sign -= 2) { + int nd = d[c] + sign * steps[s], key, i; + component keep = comp[c]; + float te; + if (nd > DUAL_STEPS_MAX || nd < -DUAL_STEPS_MAX) + continue; + key = c ? d[0] * 64 + nd : nd * 64 + d[1]; + for (i = 0; i < nseen && seen[i] != key; i++) + ; + if (i < nseen) /* a pair already evaluated explains no more than best */ + continue; + seen[nseen++] = key; + PAIR_COMPONENT(x, len, nominal[c] * (1.0f + DUAL_STEP * (float)nd), &comp[c]); + te = fit(energy, comp, 2, len, trial_amp); + if (te > best) { + best = te; + d[c] = nd; + amp[0] = trial_amp[0]; + amp[1] = trial_amp[1]; + } else { + comp[c] = keep; + } + } + hz[0] = comp[0].hz; + hz[1] = comp[1].hz; + return best; +} + +/* components more than DUAL_TWIST_DB apart, amp > 0 */ +static int twisted(const float amp[2]) +{ +#if XOMBE_KERNELS_Q15 + return amp[0] > TWIST_RATIO * amp[1] || amp[1] > TWIST_RATIO * amp[0]; +#else + return fabsf(20.0f * log10f(amp[0] / amp[1])) > DUAL_TWIST_DB; +#endif +} + +void xombe__tone_prepare(xombe_enc *e, const int16_t *seg, const xombe_tone_search *ts, xombe_tone_seg *sg) +{ + sg->energy = prepare(e, seg, ts->len, ts->win, sg->x, sg->pw); +} + +int xombe__tone_search(const xombe_tone_seg *sg, const xombe_tone_search *ts, xombe_tone_hit *hit) +{ + const float *x = sg->x; + const xombe_tone_pow *pw = sg->pw; + pow_sum total; + float energy = sg->energy, e1 = 0.0f, best = -1.0f, best_level = 0.0f, best_res = 0.0f; + int i, single = 0, dual = -1, len = ts->len, npairs = ts->npairs; +#if XOMBE_KERNELS_Q15 + corr_memo memo; + int memo_ready = 0; +#endif + hit->id = -1; + if (energy == 0.0f) + return 0; + if (ts->singles) { + float f1 = ts->fine_peak ? peak_hz(x, ts->win, len, pw) : coarse_peak(pw) * BIN_HZ, amp[2]; + int cand = (int)floorf(f1 / SINGLE_ID_HZ + 0.5f); + component c; + fit_component(x, len, f1, &c); + e1 = fit(energy, &c, 1, len, amp); + if (ts->fine_peak && e1 >= ts->emin - REFINE_REACH) + e1 = fit_refined(x, len, energy, f1, amp); + if (e1 >= ts->emin && cand >= 5 && cand <= 122) { + single = 1; + hit->id = cand; + hit->e = e1; + hit->level = peak_db(amp[0] > 1e-9f ? amp[0] : 1e-9f) - xombe__tone_hpf_gain_db(f1); + hit->res = energy * (1.0f - e1); + } + } +#if XOMBE_KERNELS_Q15 + /* a least-squares fit explains at most the whole energy, so a dual cannot beat e1 + DUAL_PREFERENCE past 1 + plus rounding slack */ + if (single && e1 + DUAL_PREFERENCE > 1.0f + DUAL_SLACK) + npairs = 0; +#endif + total = band_total(pw); + for (i = 0; i < npairs; i++) { + const xombe_tone_pair *p = &ts->pairs[i]; + float hz[2], amp[2], ex; + if (!gate_pass(pw, p->hz, total)) + continue; +#if XOMBE_KERNELS_Q15 + if (!memo_ready) { + memset(memo.hz, 0, sizeof(memo.hz)); + memo_ready = 1; + } +#endif + ex = pair_fit(PAIR_MEMO_ARG x, len, energy, p->hz, hz, amp); + if (ex < ts->emin || amp[0] <= 0.0f || amp[1] <= 0.0f || twisted(amp)) + continue; + if (ex > best) { + best = ex; + dual = p->id; + best_level = 0.5f * ((peak_db(amp[0]) - xombe__tone_hpf_gain_db(hz[0])) + + (peak_db(amp[1]) - xombe__tone_hpf_gain_db(hz[1]))); + best_res = energy * (1.0f - ex); + } + } + if (dual >= 0 && (!single || best > e1 + DUAL_PREFERENCE)) { + hit->id = dual; + hit->e = best; + hit->level = best_level; + hit->res = best_res; + } + return hit->id >= 0; +} + +int xombe__tone_detect(xombe_enc *e, const int16_t *seg, int *id, int *ad) +{ + xombe_tone_pair pairs[XOMBE_TONE_DUALS]; + xombe_tone_search ts; + xombe_tone_seg sg; + xombe_tone_hit h; + int i; + ts.len = XOMBE_TONE_SEG; + ts.win = xombe__tone_win; + ts.emin = EXPLAINED_MIN; + ts.singles = 1; + ts.fine_peak = 0; + ts.pairs = pairs; + ts.npairs = XOMBE_TONE_DUALS; + xombe__tone_prepare(e, seg, &ts, &sg); + if (sg.energy == 0.0f) + return 0; + for (i = 0; i < ts.npairs; i++) { + pairs[i].id = (short)(XOMBE_TONE_DUAL_FIRST + i); + xombe__tone_freqs(pairs[i].id, &pairs[i].hz[0], &pairs[i].hz[1]); + } + if (!xombe__tone_search(&sg, &ts, &h)) + return 0; + *id = h.id; + *ad = ad_from_level(h.level); + return 1; +} + +int xombe__tone_decide(xombe_enc *e, int detected, int det_id, int det_ad, int *id, int *ad) +{ + int tone = 0; + if (detected && det_id == e->tone_prev_id) { + e->tone_confirmed = 1; + e->tone_hold_used = 0; + e->tone_last_id = det_id; + e->tone_last_ad = det_ad; + tone = 1; + } else if (!detected && e->tone_confirmed && !e->tone_hold_used) { + e->tone_hold_used = 1; + tone = 1; + } else { + e->tone_confirmed = 0; + } + e->tone_prev_id = detected ? det_id : -1; + *id = e->tone_last_id; + *ad = e->tone_last_ad; + return tone; +} diff --git a/xombe/src/enc/vad.c b/xombe/src/enc/vad.c new file mode 100644 index 0000000..15214d5 --- /dev/null +++ b/xombe/src/enc/vad.c @@ -0,0 +1,184 @@ +#include +#include +#include "../internal.h" + +#define VAD_BAND_OFFSET 1e-3f +#define VAD_FLOOR_REL 1e-3f +#define VAD_FLOOR_ABS 1.0f +#define ABSORB_SPREAD XOMBE_DB(4.0f) +/* digital silence (any constant code): FLAT_RUN equal consecutive input samples in a window */ +#define FLAT_RUN 16 +/* history: log2 powers in Q10, their sum in linear Q20. smoothed powers lie in [VAD_BAND_OFFSET, 2^30] (int16 + input's total power), so logs fit int16 and 300 linear values int64, and a value leaving the history removes + exactly what it added */ +#define HIST_LOG_ONE 1024 +#define HIST_LIN_ONE 1048576.0f +#define VAD_LOW XOMBE_HZ(100.0f) +#define VAD_HIGH XOMBE_HZ(4000.0f) + +static void band_powers(const float *P, float E[8]) +{ + int k, b; + for (b = 0; b < 8; b++) + E[b] = VAD_BAND_OFFSET; + for (k = 0; k < XOMBE_SPEC_BINS; k++) { + float f = (float)k / XOMBE_FFT; + if (f < VAD_LOW || f >= VAD_HIGH) + continue; + b = (int)(f * XOMBE_BANDS_PER_UNIT); + E[b] += P[k]; + } +} + +static int16_t hist_log(float x) +{ + return (int16_t)floorf(log2f(x) * HIST_LOG_ONE + 0.5f); +} + +static int64_t hist_lin(int16_t q) +{ + return (int64_t)(exp2f((float)q / HIST_LOG_ONE) * HIST_LIN_ONE + 0.5f); +} + +static float noise_floor(const float nl[8]) +{ + float m = 0.0f; + int b; + for (b = 0; b < 8; b++) + if (nl[b] > m) + m = nl[b]; + m *= VAD_FLOOR_REL; + return m > VAD_FLOOR_ABS ? m : VAD_FLOOR_ABS; +} + +static float vad_metric(const float E[8], const float nl[8], float fl) +{ + float best = 0.0f, second = 0.0f; + int b; + for (b = 0; b < 8; b++) { + float snr = log2f((E[b] > fl ? E[b] : fl) / (nl[b] > fl ? nl[b] : fl)); + if (snr < 0.0f) + snr = 0.0f; + if (snr > best) { + second = best; + best = snr; + } else if (snr > second) { + second = snr; + } + } + return 0.5f * (best + second); +} + +/* minimum-statistics release (Martin, 2001), returns 1 if any band moved. a band above its noise level in every + half of the 3 s history is locked (its background reads as speech, so the noise update can't raise it), and its + level rises to the minimum smoothed power over the history. clean speech dips to the background in pauses, so + the level overshoots only when a pauseless sound fills the whole history */ +static int vad_release(xombe_enc *e) +{ + int b, i, moved = 0; + for (b = 0; b < 8; b++) { + int lo = INT16_MAX; + if (e->vad_above[b] < XOMBE_VAD_HIST) + continue; + for (i = 0; i < XOMBE_VAD_HIST; i++) + if (e->vad_hist[i][b] < lo) + lo = e->vad_hist[i][b]; + if ((float)lo > log2f(e->vad_nl[b]) * HIST_LOG_ONE) { + e->vad_nl[b] = exp2f((float)lo / HIST_LOG_ONE); + moved = 1; + } + } + return moved; +} + +/* returns 1 if x[0..n) holds FLAT_RUN equal consecutive samples */ +int xombe__vad_flat(const int16_t *x, int n) +{ + int i, run = 1; + for (i = 1; i < n; i++) { + run = x[i] == x[i - 1] ? run + 1 : 1; + if (run >= FLAT_RUN) + return 1; + } + return 0; +} + +/* flat: window holds digital silence (xombe__vad_flat), which can't lower the noise levels */ +void xombe__vad_half(xombe_enc *e, const float *P, int flat, int *speech, float *v) +{ + float E[8], fl; + int16_t *row; + int b, i, redo = 0; + band_powers(P, E); + if (!e->vad_ready) { + memcpy(e->vad_nl, E, sizeof(E)); + memcpy(e->vad_smooth, E, sizeof(E)); + e->vad_ready = 1; + } else { + for (b = 0; b < 8; b++) + e->vad_smooth[b] = 0.8f * e->vad_smooth[b] + 0.2f * E[b]; + } + fl = noise_floor(e->vad_nl); + *v = vad_metric(E, e->vad_nl, fl); + *speech = *v >= XOMBE_VAD_THRESHOLD; + for (b = 0; b < 8; b++) { + if ((E[b] > fl ? E[b] : fl) > (e->vad_nl[b] > fl ? e->vad_nl[b] : fl)) { + if (e->vad_above[b] < XOMBE_VAD_HIST) + e->vad_above[b]++; + } else { + e->vad_above[b] = 0; + } + } + if (!*speech) { + for (b = 0; b < 8; b++) { + float nl; + if (E[b] < e->vad_nl[b] / 4.0f) + nl = 0.5f * e->vad_nl[b] + 0.5f * E[b]; + else + nl = 0.9f * e->vad_nl[b] + 0.1f * E[b]; + if (!flat || nl > e->vad_nl[b]) + e->vad_nl[b] = nl; + } + } + /* stationarity test floors stored smoothed powers at each half's own fl */ + row = e->vad_hist[e->vad_hist_pos]; + for (b = 0; b < 8; b++) { + if (e->vad_hist_n == XOMBE_VAD_HIST) + e->vad_hist_sum[b] -= hist_lin(row[b]); + row[b] = hist_log(e->vad_smooth[b]); + e->vad_hist_sum[b] += hist_lin(row[b]); + } + e->vad_hist_fl[e->vad_hist_pos] = hist_log(fl); + e->vad_hist_pos = (e->vad_hist_pos + 1) % XOMBE_VAD_HIST; + if (e->vad_hist_n < XOMBE_VAD_HIST) + e->vad_hist_n++; + if (e->vad_hist_n == XOMBE_VAD_HIST) { + int steady = 1; + for (b = 0; b < 8 && steady; b++) { + int lo = INT16_MAX, hi = INT16_MIN; + for (i = 0; i < XOMBE_VAD_HIST; i++) { + int x = e->vad_hist[i][b] > e->vad_hist_fl[i] ? e->vad_hist[i][b] : e->vad_hist_fl[i]; + if (x < lo) + lo = x; + if (x > hi) + hi = x; + } + steady = hi - lo <= ABSORB_SPREAD * HIST_LOG_ONE; + } + if (steady) { + for (b = 0; b < 8; b++) { + float mean = (float)e->vad_hist_sum[b] / (XOMBE_VAD_HIST * HIST_LIN_ONE); + if (mean > e->vad_nl[b]) + e->vad_nl[b] = mean; + } + redo = 1; + } + redo |= vad_release(e); + } + /* redecide after absorption or release, without a second noise update */ + if (redo) { + fl = noise_floor(e->vad_nl); + *v = vad_metric(E, e->vad_nl, fl); + *speech = *v >= XOMBE_VAD_THRESHOLD; + } +} diff --git a/xombe/src/enc/voicing_metric.c b/xombe/src/enc/voicing_metric.c new file mode 100644 index 0000000..c3f192f --- /dev/null +++ b/xombe/src/enc/voicing_metric.c @@ -0,0 +1,92 @@ +#include +#include "kernels.h" + +#define METRIC_TOP XOMBE_HZ(3950.0f) /* metric fits harmonics below this */ +#define JITTER_STEPS 9 +#define JITTER_STEP 0.005f +#define SOFT_OFFSET (-0.661f) +#define WEIGHT_FLOOR 1e-3f +#define FIRST_HALF_WEIGHT 0.5f +#define B1_SEARCH_MAX 17 + +#define METRIC_KMAX ((int)(METRIC_TOP * XOMBE_FFT) - 1) + +void xombe__voicing_prepare(xombe_enc *e, const xombe_spec *S, xombe_lf_spec *sp) +{ + xombe__kern_lf_prepare(e, S, 1, METRIC_KMAX, sp); +} + +void xombe__voicing_metric_sp(xombe_enc *e, const xombe_lf_spec *sp, float fhat, float m[8], float w[8]) +{ + float br[8], be[8], be0[8]; + int kmax = METRIC_KMAX, j, s; + for (j = 0; j < 8; j++) + m[j] = 1e30f; + for (s = 0; s < JITTER_STEPS; s++) { + float eps = (float)(s - JITTER_STEPS / 2) * JITTER_STEP; + xombe__kern_line_fit(e, sp, 1.0f / (fhat * (1.0f + eps)), 1, kmax, br, be); + if (s == JITTER_STEPS / 2) + memcpy(be0, be, sizeof(be0)); + for (j = 0; j < 8; j++) { + float mj = be[j] > 0.0f ? br[j] / be[j] : 1.0f; + if (mj < m[j]) + m[j] = mj; + } + } + for (j = 0; j < 8; j++) { + float wj = be0[j] / (XOMBE_FFT * e->win_sum2); + w[j] = wj > WEIGHT_FLOOR ? wj : WEIGHT_FLOOR; + } +} + +void xombe__voicing_metric(xombe_enc *e, const xombe_spec *S, float fhat, float m[8], float w[8]) +{ + xombe_lf_spec sp; + xombe__voicing_prepare(e, S, &sp); + xombe__voicing_metric_sp(e, &sp, fhat, m, w); +} + +float xombe__voicing_map(float sm) +{ + float soft = sm > 0.0f ? SOFT_OFFSET - 0.5f * log2f(sm) : 1.0f; + return soft < 0.0f ? 0.0f : soft > 1.0f ? 1.0f : soft; +} + +void xombe__voicing_soft_sp(xombe_enc *e, const xombe_lf_spec *sp, float fhat, float scale, float a[8], float w[8]) +{ + float m[8]; + int j; + xombe__voicing_metric_sp(e, sp, fhat, m, w); + for (j = 0; j < 8; j++) + a[j] = xombe__voicing_map(scale * m[j]); +} + +void xombe__voicing_soft(xombe_enc *e, const xombe_spec *S, float fhat, float scale, float a[8], float w[8]) +{ + xombe_lf_spec sp; + xombe__voicing_prepare(e, S, &sp); + xombe__voicing_soft_sp(e, &sp, fhat, scale, a, w); +} + +int xombe__choose_b1(const float a2[8], const float w2[8], const float a1[8], const float w1[8], + const uint8_t v2_prev[8]) +{ + float best = 0.0f; + int b1, j, choice = XOMBE_UNVOICED_B1; + for (b1 = 0; b1 <= B1_SEARCH_MAX; b1++) { + uint8_t v2[8], v1[8]; + float c = 0.0f; + xombe__v2_from_b1(b1, v2); + xombe__f3_first_half(v2_prev, v2, v1); + for (j = 0; j < 8; j++) { + float d2 = v2[j] ? 1.0f - a2[j] : a2[j]; + float d1 = v1[j] ? 1.0f - a1[j] : a1[j]; + c += w2[j] * d2 * d2 + FIRST_HALF_WEIGHT * w1[j] * d1 * d1; + } + if (b1 == 0 || c < best) { + best = c; + choice = b1; + } + } + return choice; +} diff --git a/xombe/src/fec/golay.c b/xombe/src/fec/golay.c new file mode 100644 index 0000000..263395e --- /dev/null +++ b/xombe/src/fec/golay.c @@ -0,0 +1,54 @@ +#include "../internal.h" + +#define GOLAY_POLY 0xC75u + +static uint32_t golay_remainder(uint32_t v) +{ + int bit; + for (bit = 22; bit >= 11; bit--) + if (v & (1u << bit)) + v ^= GOLAY_POLY << (bit - 11); + return v; +} + +uint32_t xombe__golay23_encode(uint32_t data12) +{ + uint32_t shifted = (data12 & 0xFFFu) << 11; + return shifted | golay_remainder(shifted); +} + +int xombe__golay23_decode(uint32_t received, uint32_t *codeword) +{ + uint32_t syn = golay_remainder(received & 0x7FFFFFu), data_syn[12]; + int i, j, k; + if (xombe__popcount32(syn) <= 3) { + *codeword = (received ^ syn) & 0x7FFFFFu; + return xombe__popcount32(syn); + } + for (i = 0; i < 12; i++) + data_syn[i] = golay_remainder(1u << (11 + i)); + for (i = 0; i < 12; i++) { + uint32_t s = syn ^ data_syn[i]; + if (xombe__popcount32(s) <= 2) { + *codeword = (received ^ (1u << (11 + i)) ^ s) & 0x7FFFFFu; + return 1 + xombe__popcount32(s); + } + } + for (i = 0; i < 12; i++) + for (j = i + 1; j < 12; j++) { + uint32_t s = syn ^ data_syn[i] ^ data_syn[j]; + if (xombe__popcount32(s) <= 1) { + *codeword = (received ^ (1u << (11 + i)) ^ (1u << (11 + j)) ^ s) & 0x7FFFFFu; + return 2 + xombe__popcount32(s); + } + } + for (i = 0; i < 12; i++) + for (j = i + 1; j < 12; j++) + for (k = j + 1; k < 12; k++) + if ((syn ^ data_syn[i] ^ data_syn[j] ^ data_syn[k]) == 0) { + *codeword = (received ^ (1u << (11 + i)) ^ (1u << (11 + j)) ^ (1u << (11 + k))) & 0x7FFFFFu; + return 3; + } + *codeword = received & 0x7FFFFFu; + return 3; +} diff --git a/xombe/src/fec/interleave.c b/xombe/src/fec/interleave.c new file mode 100644 index 0000000..328864a --- /dev/null +++ b/xombe/src/fec/interleave.c @@ -0,0 +1,17 @@ +#include "../internal.h" + +void xombe__interleave(const uint8_t w[72], uint8_t air_bits[72]) +{ + int i, k; + for (i = 0; i < 18; i++) + for (k = 0; k < 4; k++) + air_bits[4 * i + k] = w[18 * k + i]; +} + +void xombe__deinterleave(const uint8_t air_bits[72], uint8_t w[72]) +{ + int i, k; + for (i = 0; i < 18; i++) + for (k = 0; k < 4; k++) + w[18 * k + i] = air_bits[4 * i + k]; +} diff --git a/xombe/src/fec/pn.c b/xombe/src/fec/pn.c new file mode 100644 index 0000000..fbd1f14 --- /dev/null +++ b/xombe/src/fec/pn.c @@ -0,0 +1,13 @@ +#include "../internal.h" + +uint32_t xombe__pn_mask(uint32_t d0_12) +{ + uint16_t u = (uint16_t)(16u * (d0_12 & 0xFFFu)); + uint32_t mask = 0; + int n; + for (n = 0; n < 23; n++) { + u = xombe__lcg_next(u); + mask = (mask << 1) | ((u >> 15) & 1u); + } + return mask; +} diff --git a/xombe/src/fec/stats.c b/xombe/src/fec/stats.c new file mode 100644 index 0000000..cece1ac --- /dev/null +++ b/xombe/src/fec/stats.c @@ -0,0 +1,131 @@ +#include "../internal.h" +#if XOMBE_HAVE_DSTAR +#include "../dstar/dstar_internal.h" +#endif + +/* running error rate in Q24: eps_r <- 0.95*eps_r + 0.05*eps_t/47 = (893*eps_r + 2^24*eps_t)/940, rounded once + HB above 0.096, from ceil(0.096*2^24) */ +#define EPS_R_ONE (1ull << 24) +#define EPS_R_HB_MIN 1610613u + +static uint32_t take(const uint8_t *bits, int count) +{ + return (uint32_t)xombe__get_bits(bits, 0, count); +} + +static void put(uint8_t *bits, int count, uint32_t v) +{ + xombe__put_bits(bits, 0, count, (int)v); +} + +static int parity(uint32_t v) +{ + return xombe__popcount32(v) & 1; +} + +static void dmr_encode(const uint8_t bits[7], uint8_t air[9]) +{ + uint8_t d[49], w[72], a[72]; + uint32_t data0, data1, c0, c1; + int i; + xombe__unpack49(bits, d); + data0 = take(d, 12); + data1 = take(d + 12, 12); + c0 = xombe__golay23_encode(data0); + c0 = (c0 << 1) | (uint32_t)parity(c0); + c1 = xombe__golay23_encode(data1) ^ xombe__pn_mask(data0); + put(w, 24, c0); + put(w + 24, 23, c1); + for (i = 0; i < 25; i++) + w[47 + i] = d[24 + i]; + xombe__interleave(w, a); + xombe__pack_bits(a, 72, air); +} + +void xombe__fec_encode_dmr(const uint8_t bits[7], uint8_t frame[9]) +{ + dmr_encode(bits, frame); +} + +int xombe__fec_encode_dstar(const uint8_t bits[7], uint8_t frame[9]) +{ +#if XOMBE_HAVE_DSTAR + xombe__ds_fec_encode_bits(bits, frame); + return 0; +#else + (void)bits; + (void)frame; + return -1; +#endif +} + +void xombe__fec_stats_update(xombe_fec *f, xombe_fec_stats *st) +{ + st->eps_t = st->eps0 + st->eps1; + st->bf = st->eps0 >= 4 || (st->eps0 >= 2 && st->eps_t >= 6); + f->eps_r = (uint32_t)((893u * (uint64_t)f->eps_r + EPS_R_ONE * (uint64_t)st->eps_t + 470u) / 940u); + st->eps_r = f->eps_r; + st->hb = f->eps_r >= EPS_R_HB_MIN; +} + +static unsigned dmr_decode(xombe_fec *f, const uint8_t air[9], uint8_t bits[7], xombe_fec_stats *st) +{ + uint8_t a[72], w[72], d[49]; + uint32_t c0, c1, cw0, cw1; + int i, w0, received_parity; + xombe__unpack_bits(air, 72, a); + xombe__deinterleave(a, w); + c0 = take(w, 24); + received_parity = (int)(c0 & 1u); + w0 = xombe__golay23_decode(c0 >> 1, &cw0); + if ((parity(cw0) ^ received_parity) == 0) + st->eps0 = w0; + else + st->eps0 = w0 <= 2 ? w0 + 1 : 4; + c1 = take(w + 24, 23) ^ xombe__pn_mask(cw0 >> 11); + st->eps1 = xombe__golay23_decode(c1, &cw1); + put(d, 12, cw0 >> 11); + put(d + 12, 12, cw1 >> 11); + for (i = 0; i < 25; i++) + d[24 + i] = w[47 + i]; + xombe__pack49(d, bits); + xombe__fec_stats_update(f, st); + return (st->bf ? XOMBE_FLAG_BF : 0u) | (st->hb ? XOMBE_FLAG_HB : 0u); +} + +static void reset(xombe_fec *f, int codec) +{ + f->codec = codec; + f->eps_r = 0; + f->er = 0.0f; +} + +int xombe__fec_init_dmr(xombe_fec *f) +{ + reset(f, XOMBE_DMR); + return 0; +} + +int xombe__fec_init_dstar(xombe_fec *f) +{ +#if XOMBE_HAVE_DSTAR + reset(f, XOMBE_DSTAR); + return 0; +#else + (void)f; + return -1; +#endif +} + +/* both codecs' decoders behind one call: the decoder's frame calls reach it, its *_bits calls do not */ +unsigned xombe_fec_decode(xombe_fec *f, const uint8_t frame[9], uint8_t bits[7], xombe_fec_stats *st) +{ + xombe_fec_stats local; + if (!st) + st = &local; +#if XOMBE_HAVE_DSTAR + if (f->codec == XOMBE_DSTAR) + return xombe__ds_fec_decode_bits(f, frame, bits, st); +#endif + return dmr_decode(f, frame, bits, st); +} diff --git a/xombe/src/internal.h b/xombe/src/internal.h new file mode 100644 index 0000000..4584412 --- /dev/null +++ b/xombe/src/internal.h @@ -0,0 +1,201 @@ +#ifndef XOMBE_INTERNAL_H +#define XOMBE_INTERNAL_H + +#include +#include "xombe.h" +#include "state.h" +#include "common/consts.h" +#include "common/bits.h" +#include "common/params.h" +#include "common/voicing.h" +#include "common/tone_table.h" + +/* C99 has no _Static_assert, a negative array size fails the build */ +#define XOMBE_STATIC_ASSERT(cond, name) typedef char xombe_static_assert_##name[(cond) ? 1 : -1] + +/* largest xombe__irfft size, it keeps n/2 points of scratch on the stack */ +#define XOMBE_IRFFT_MAX 256 + +/* n real samples in, n/2 + 1 bins out */ +void xombe__rfft(const float *in, xombe_cpx *out, int n, const xombe_cpx *tw, int tw_n_real); +/* in place: io[k] holds samples 2k and 2k + 1 for k < n/2 on entry, bin k for k <= n/2 on return */ +void xombe__rfft_packed(xombe_cpx *io, int n, const xombe_cpx *tw, int tw_n_real); +/* n <= XOMBE_IRFFT_MAX */ +void xombe__irfft(const xombe_cpx *in, float *out, int n, const xombe_cpx *tw, int tw_n_real); + +float xombe__sin_ratio(long r, long m); +void xombe__hamming(float *w, int n); +float xombe__hamming_sum2(int n); +float xombe__hamming_dtft(int n, long q, long g); + +void xombe__hpf_init(xombe_hpf *f, float gain); +float xombe__hpf_step(xombe_hpf *f, float x); + +uint16_t xombe__lcg_next(uint16_t u); +int16_t xombe__lcg_draw(uint16_t *u); /* next value as a signed 16-bit sample */ + +uint32_t xombe__golay23_encode(uint32_t data12); +/* corrects up to 3 errors in a 23-bit word, returns the count, *codeword gets the word (data in bits 22..11) + an uncorrectable word also returns 3 and comes back unchanged, the FEC statistics depend on that count */ +int xombe__golay23_decode(uint32_t received, uint32_t *codeword); +uint32_t xombe__pn_mask(uint32_t d0_12); +void xombe__interleave(const uint8_t w[72], uint8_t air_bits[72]); +void xombe__deinterleave(const uint8_t air_bits[72], uint8_t w[72]); +/* DMR error rule and running error rate from st->eps0 and eps1 */ +void xombe__fec_stats_update(xombe_fec *f, xombe_fec_stats *st); + +/* installs a stage tap (state.h), fn NULL removes it */ +void xombe__dec_set_tap(xombe_dec *d, xombe_tap_fn fn, void *ctx); + +/* where the D-STAR decoder's rules differ from AMBE+2's in the shared decoder, set at reset */ +struct xombe_dec_rules { + /* vh[0..XOMBE_LMAX] from the band voicing, 0 above L */ + void (*harm_voicing)(const uint8_t vb[8], float f0, int L, uint8_t vh[XOMBE_LMAX + 1]); + float lambda_decay; /* smoothing level decay per frame */ +}; +/* a codec's frame logic, set by its init: start_bits begins a frame from voice bits (unread if lost) and the + error counts in err_t and err_1 */ +struct xombe_dec_ops { + void (*start_bits)(xombe_dec *d, const uint8_t bits[7], unsigned flags); +}; +void xombe__smooth(xombe_dec_core *d, float *a, int L, float f0); +void xombe__phases(const float *a, int L, float *phi); +/* e[1..L]: log2 amplitudes a[1..L] after spectral enhancement */ +void xombe__enhance(const float *a, int L, float f0, float *e); +/* M[1..L] = 2^(e + spectral tilt): low harmonics rolled off below the average pitch, high ones boosted */ +void xombe__shape(const float *e, float *M, int L, float f0, float avg_f0); +void xombe__tone_set(xombe_set *s, int id, int ad); +void xombe__synth_voiced(xombe_dec *d, const xombe_set *cur, const float *M, const uint8_t *vh, int cur_voiced, + int N, float *out); +void xombe__synth_unvoiced(xombe_dec *d, const xombe_set *cur, const float *M, const uint8_t *vh, int N, + float *out); +void xombe__noise_init(xombe_dec *d); +int xombe__conceal_decide(xombe_dec_core *d, int bad, int hb); + +/* frame-independent decoder machinery, shared by the AMBE+2 parser (dec/decoder.c) and dstar/decoder.c + a parser either conceals (xombe__dec_conceal_sets: mute or last played set, first half flagged repeat) or plays + the frame's set (xombe__dec_play: picks the first-half set from the previous class, makes cur the second half, + stores voice parameters p and band flags v2 in the prediction memory, v1 is a voice frame's first-half + voicing), then xombe__dec_synth synthesizes each half. the frame logic takes the core, synthesis the whole + decoder */ +void xombe__dec_core_reset(xombe_dec_core *d); +void xombe__dec_reset(xombe_dec *d); +void xombe__dec_silence_set(xombe_set *s); /* initial silence set: f0 250 Hz, L 14, every amplitude 0.1 */ +void xombe__dec_set_from_params(xombe_set *s, int cls, float f0, int L, const float *a, const uint8_t *vb); +void xombe__dec_play(xombe_dec_core *d, const xombe_set *cur, const uint8_t v1[8], const xombe_params *p, + const uint8_t v2[8]); +void xombe__dec_conceal_sets(xombe_dec_core *d, int conceal); +/* half-call order check: -1 if second_half is not the half due, else advances it and returns n clamped to + XOMBE_HALF_MIN..XOMBE_HALF_MAX */ +int xombe__dec_half_begin(xombe_dec *d, int second_half, int n); +void xombe__dec_synth(xombe_dec *d, int second_half, int N, int16_t *pcm); +/* AMBE+2 frame logic without synthesis: xombe__dec_start_frame classifies, conceals, or decodes 7 bytes (unread if + lost) into p1 and p2, then xombe__dec_skip_synth updates the mute and played sets as the two half-frame calls + would */ +void xombe__dec_start_frame(xombe_dec_core *d, const uint8_t bytes[7], unsigned flags); +void xombe__dec_skip_synth(xombe_dec_core *d); +/* xombe__dec_start_frame of a DMR frame through fec, flags 0 or XOMBE_FLAG_LOST, bits gets the decoded voice + bits (zeros if lost) */ +void xombe__dec_start_air(xombe_dec_core *d, xombe_fec *fec, const uint8_t air[9], unsigned flags, uint8_t bits[7]); + +#if XOMBE_HAVE_ENCODER +/* VAD threshold, metric in log2 power units + confident noise half: metric below XOMBE_CONFIDENT, noise suppression and comfort noise + adapt from the XOMBE_CONFIDENT_RUN-th in a row */ +#define XOMBE_VAD_THRESHOLD XOMBE_DB(4.0f) +#define XOMBE_CONFIDENT XOMBE_DB(2.0f) +#define XOMBE_CONFIDENT_RUN 4 + +void xombe__enc_set_tap(xombe_enc *e, xombe_tap_fn fn, void *ctx); + +void xombe__enc_set_window(xombe_enc *e, int n); +void xombe__enc_integrate(const float *P, int L, float f0, float *a); +void xombe__enc_hf_precomp(float *a, int L, float f0); + +void xombe__pitch_init(xombe_enc *e); +void xombe__pitch_errors(xombe_enc *e, const float *centre, int slot); +float xombe__pitch_track(xombe_enc *e, int cur, int next1, int next2); +float xombe__pitch_refine(xombe_enc *e, const xombe_spec *S, float period); +int xombe__pitch_window_len(float period); + +/* voicing metric per 500 Hz band (residual over energy of the harmonic line fit, min over +/-2% pitch jitter) + and band weights, soft value of a scaled metric sm = clip(-0.661 - log2(sm)/2, 0, 1), and both for one scale */ +void xombe__voicing_metric(xombe_enc *e, const xombe_spec *S, float fhat, float m[8], float w[8]); +float xombe__voicing_map(float sm); +void xombe__voicing_soft(xombe_enc *e, const xombe_spec *S, float fhat, float scale, float a[8], float w[8]); +int xombe__choose_b1(const float a2[8], const float w2[8], const float a1[8], const float w1[8], + const uint8_t v2_prev[8]); + +int xombe__vad_flat(const int16_t *x, int n); +void xombe__vad_half(xombe_enc *e, const float *P, int flat, int *speech, float *v); + +void xombe__ns_bins(const float *P, float Xm[XOMBE_NS_BINS]); +float xombe__ns_shape(float f); +/* noise suppression per half-frame (enc/frontend.h phase C) + xombe__ns_update: shared noise estimate (from the confident_run-th confident noise half, or slowly in halves + with no band voiced) and suppression floor (up in speech, down otherwise) + xombe__ns_gain: one back end's gains G from that estimate, its own smoothing memory m, and vbin, the voicing it + codes at each bin's centre + xombe__ns_bin_voicing: vbin from 500 Hz band flags, ambe2_rule voices a bin if its band or the band 250 Hz + above is (xombe__voiced_at), else the band alone */ +void xombe__ns_update(xombe_enc *e, const float Xm[XOMBE_NS_BINS], int speech, int confident_run, + int no_band_voiced); +void xombe__ns_bin_voicing(const uint8_t vb[8], int ambe2_rule, uint8_t vbin[XOMBE_NS_BINS]); +void xombe__ns_gain(const xombe_enc *e, xombe_ns_mem *m, const float Xm[XOMBE_NS_BINS], int speech, float v, + const uint8_t vbin[XOMBE_NS_BINS], float G[XOMBE_NS_BINS]); +/* log2 gain offsets da[1..L] of the harmonics of f0 from gains G, voicing vh[1..L] (voiced harmonics below + 800 Hz take part of the suppression), xombe__ns_apply_voice adds them to a[1..L] with AMBE+2 band voicing v2, + floored at XOMBE_AMP_MIN */ +void xombe__ns_harmonic_offsets(const float G[XOMBE_NS_BINS], int L, float f0, const uint8_t *vh, float *da); +void xombe__ns_apply_voice(const float G[XOMBE_NS_BINS], float *a, int L, float f0, const uint8_t v2[8]); +void xombe__ns_apply_silence(const xombe_enc *e, float *a, int L, float f0); + +void xombe__cn_half(xombe_enc *e, const float *P, int noise, int confident_run); +void xombe__cn_targets(const xombe_enc *e, float *a); + +/* AMBE+2 tone detector on XOMBE_TONE_SEG samples from seg, gives tone ID and level code + (xombe__tone_search with singles, the 36 dual tones, emin 0.99, coarse peak) */ +int xombe__tone_detect(xombe_enc *e, const int16_t *seg, int *id, int *ad); +/* least-squares tone detector over a segment length and tone set, the level at each component's own frequency */ +typedef struct { + short id; + float hz[2]; /* in the fit's order */ +} xombe_tone_pair; +typedef struct { + int len; /* segment length, at most XOMBE_TONE_SEG */ + const float *win; /* its Hann window */ + float emin; /* explained-fraction threshold */ + int singles; /* single tones (IDs 5..122) are candidates */ + int fine_peak; /* single-tone peak on an 8192-point grid refined in the fit (ternary search, +/-0.4 bin), + else the parabola on the XOMBE_TONE_FFT grid */ + const xombe_tone_pair *pairs; + int npairs; +} xombe_tone_search; +typedef struct { + int id; /* -1: none */ + float e; /* fit's explained fraction */ + float level; /* dB re full scale less the decoder filter's gain, AD = 127 + level/0.711 */ + float res; /* fit's residual energy */ +} xombe_tone_hit; +#if XOMBE_KERNELS_Q15 +typedef uint32_t xombe_tone_pow; /* bin power in a per-segment unit, only ratios within a segment mean anything */ +#else +typedef float xombe_tone_pow; +#endif +/* segment as the search reads it: x less its mean, pw bin powers of x under the window, zero-padded */ +typedef struct { + float x[XOMBE_TONE_SEG]; + xombe_tone_pow pw[XOMBE_TONE_FFT / 2 + 1]; + float energy; /* of x, 0 below the detector's floor */ +} xombe_tone_seg; +/* sg for ts->len samples from seg under ts->win, which any search on sg must share */ +void xombe__tone_prepare(xombe_enc *e, const int16_t *seg, const xombe_tone_search *ts, xombe_tone_seg *sg); +int xombe__tone_search(const xombe_tone_seg *sg, const xombe_tone_search *ts, xombe_tone_hit *hit); +/* decoder output filter's gain at hz, dB */ +float xombe__tone_hpf_gain_db(float hz); +int xombe__tone_decide(xombe_enc *e, int detected, int det_id, int det_ad, int *id, int *ad); + +void xombe__quantize(const xombe_pred *pi, int silence, int L, const float *target, int b[9]); +#endif + +#endif diff --git a/xombe/src/state.h b/xombe/src/state.h new file mode 100644 index 0000000..a73dd95 --- /dev/null +++ b/xombe/src/state.h @@ -0,0 +1,236 @@ +#ifndef XOMBE_STATE_H +#define XOMBE_STATE_H + +/* decoder and encoder state behind the opaque handles of xombe.h */ + +#include +#include "xombe.h" + +#define XOMBE_LMAX 56 +#define XOMBE_TAIL 84 + +#define XOMBE_WT_SIZE 256 /* voiced wavetable length, a power of 2 */ + +typedef struct { + float re, im; +} xombe_cpx; + +/* per-stage taps for tests (test/trace_dump.c), each passes n values and their f0 */ +enum xombe_stage { + XOMBE_STAGE_DEQUANT, /* a[1..L] after dequantization */ + XOMBE_STAGE_SMOOTH, /* a[1..L] after smoothing */ + XOMBE_STAGE_SET, /* a[1..L] of the set a half-frame plays (silence and voice sets) */ + XOMBE_STAGE_ENHANCED, /* linear M[1..L] after enhancement (silence sets: 2^a) */ + XOMBE_STAGE_PHASE, /* phi[1..L] (voice sets) */ + XOMBE_STAGE_SHAPED, /* M[1..L] as synthesized, after the tilt (tone sets: tone amplitudes) */ + XOMBE_STAGE_SYNTH, /* a half-frame's N samples before the output high-pass */ + XOMBE_STAGE_TARGET, /* encoder amplitude targets a[1..L] as quantized */ + XOMBE_STAGE_VAD, /* encoder VAD per half: decision (1 = speech) and metric v in log2 units, f0 = 0 */ + XOMBE_STAGE_COUNT +}; +typedef void (*xombe_tap_fn)(void *ctx, enum xombe_stage stage, float f0, const float *v, int n); +#define XOMBE_TAP(o, stage, f0, v, n) \ + do { \ + if ((o)->tap) \ + (o)->tap((o)->tap_ctx, (stage), (f0), (v), (n)); \ + } while (0) + +typedef struct { + int cls; + int L; + float f0; + float gamma; + float a[XOMBE_LMAX + 1]; + uint8_t v2[8]; +} xombe_pred; + +typedef struct { + int cls; + int repeat; + int prepared; + int L; + float f0; + float a[XOMBE_LMAX + 1]; + float e[XOMBE_LMAX + 1]; /* log2 amplitudes before the tilt: enhanced a (voice), a (silence), or tone + harmonics (tone, XOMBE_AMP_OFF elsewhere) */ + float phi[XOMBE_LMAX + 1]; + uint8_t vb[8]; +} xombe_set; + +typedef struct { + float x1, s1, s2, y1, y2; + float gain; +} xombe_hpf; + +struct xombe_dec_rules; +struct xombe_dec_ops; + +/* frame logic up to the sets a frame plays, all the transcoders keep of a decoder */ +typedef struct { + const struct xombe_dec_rules *rules; /* AMBE+2's, or D-STAR's (xombe__dsd_logic_init) */ + xombe_pred pi; + float lambda; + float avg_f0; /* synthesis reads and updates it, here it fills the core's padding */ + int eps_t, eps_1; + int prev_concealed; + unsigned hist; + int run; + int64_t frame; + int64_t mute_src; + xombe_decision decision; + xombe_set p1, p2, played, mute; + xombe_tap_fn tap; + void *tap_ctx; +} xombe_dec_core; + +#if XOMBE_HAVE_DSTAR +/* D-STAR frame logic state besides the core (dstar/decoder.c) */ +typedef struct { + int log; /* XOMBE_DSD_LOG_* of the last frame */ + int eT, e1; /* error rule smoothing inputs for the last frame */ +} xombe_dsd_logic; +#endif + +struct xombe_dec { + xombe_dec_core c; + const struct xombe_dec_ops *ops; /* the codec's frame logic */ + int second_half_next; /* 1 between the two half calls of a frame */ + int err_t, err_1; /* error counts of the next *_bits frame, xombe_dec_set_errors or the FEC */ + float tail[XOMBE_TAIL]; + float pitch_phase, epoch; + float wprev[XOMBE_WT_SIZE]; + float prev_f0; + int prev_voiced; + float uv_overlap[XOMBE_TAIL]; + int16_t noise_hist[XOMBE_TAIL]; + uint16_t lcg; + uint32_t prng; + int noise_mode; + xombe_hpf hpf; + xombe_fec fec; /* for the frame calls */ +#if XOMBE_HAVE_DSTAR + xombe_dsd_logic ds; +#endif +}; + +#if XOMBE_HAVE_ENCODER +#define XOMBE_FRAME 160 +#define XOMBE_ENC_BUF 1024 /* input history in samples, newest last */ +/* frames of look-ahead beyond XOMBE_ENC_DELAY for the D-STAR tone rules (dstar/dstar_enc.h), with the D-STAR + output on the encoder codes a frame this many frames older */ +#if XOMBE_HAVE_DSTAR +#define XOMBE_ENC_LOOKAHEAD 1 +#else +#define XOMBE_ENC_LOOKAHEAD 0 +#endif +/* unfiltered history from the frame being encoded through the newest */ +#define XOMBE_ENC_RAW ((XOMBE_ENC_DELAY + 1 + XOMBE_ENC_LOOKAHEAD) * XOMBE_FRAME) +/* unfiltered samples kept before that frame: the VAD's digital-silence test reads 59, D-STAR's tone-in-noise + window 80 */ +#if XOMBE_HAVE_DSTAR +#define XOMBE_ENC_RAW_LEAD 80 +#else +#define XOMBE_ENC_RAW_LEAD 64 +#endif +#define XOMBE_FFT 1024 +#define XOMBE_SPEC_BINS (XOMBE_FFT / 2 + 1) +#define XOMBE_TONE_FFT 512 /* uses the analysis FFT's twiddles */ +#define XOMBE_TONE_IDS 164 +#define XOMBE_TONE_SEG 240 +/* analysis window widens to XOMBE_MAX_WINDOW for long periods, its transform tabulated to XOMBE_WTAB_BINS bins: + fits read at most half a harmonic spacing away, the widest about 52.2 bins (xombe__w0[0] with +2% jitter) */ +#define XOMBE_BASE_WINDOW 199 +#define XOMBE_MAX_WINDOW 321 +#define XOMBE_WTAB_OVERSAMPLE 16 +#define XOMBE_WTAB_BINS 27 +#define XOMBE_WTAB_LEN (XOMBE_WTAB_BINS * XOMBE_WTAB_OVERSAMPLE + 1) +/* pitch grid: 21, 21.5, ..., 123 samples */ +#define XOMBE_PITCH_LPF_HALF 10 +#define XOMBE_PITCH_HALF 150 +#define XOMBE_PITCH_WIN (2 * XOMBE_PITCH_HALF + 1) +#define XOMBE_PITCH_GRID 205 +#define XOMBE_VAD_HIST 300 /* half-frames of band levels for the stationarity rule */ +#define XOMBE_NS_BINS 40 + +#include "enc/kern_state.h" + +#if XOMBE_HAVE_DSTAR +/* D-STAR back end state bytes (dstar/dstar_enc.h checks its struct fits): XOMBE_ENC_DSTAR_SIZE less what the + front end's longer input history (XOMBE_ENC_LOOKAHEAD) takes, so growing one grows the other */ +#define XOMBE_ENC_LOOKAHEAD_STATE 512 +#define XOMBE_DS_ENC_STATE (XOMBE_ENC_DSTAR_SIZE - XOMBE_ENC_LOOKAHEAD_STATE) +#endif + +/* a back end's noise-suppression gain smoothing (xombe__ns_gain): last half's gains before the floor */ +typedef struct { + float prev_gain[XOMBE_NS_BINS]; + int have_prev; +} xombe_ns_mem; + +struct xombe_enc { + xombe_enc_cfg cfg; + float ns_strength, voicing_scale; /* cfg's, as fractions */ + int calls; /* counted up to the delay */ + int lookahead; /* XOMBE_ENC_LOOKAHEAD with the D-STAR output, else 0 */ + int pitch_slot; /* perr/pacf slot the next pitch analysis writes */ + int16_t raw[XOMBE_ENC_RAW_LEAD + XOMBE_ENC_RAW]; + float xh[XOMBE_ENC_BUF]; + xombe_hpf hpf; + float perr[XOMBE_ENC_DELAY][XOMBE_PITCH_GRID]; + /* pitch autocorrelation per slot, float lags or int16 lags (padded by one) scaled by pacf_scale */ + union { + float f[XOMBE_PITCH_WIN]; + int16_t q[XOMBE_PITCH_WIN + 1]; + } pacf[XOMBE_ENC_DELAY]; + float pacf_scale[XOMBE_ENC_DELAY]; + float pe0[XOMBE_ENC_DELAY]; + int psilent[XOMBE_ENC_DELAY]; + float p_prev, e_prev1, e_prev2; + float period[XOMBE_ENC_LOOKAHEAD + 1]; /* tracked periods, newest first, the frame encoded takes [lookahead] */ + float base_win_sum2; + float win[XOMBE_MAX_WINDOW]; + int win_len; + float win_sum2; + float wtab[XOMBE_WTAB_LEN]; + float vad_nl[8], vad_smooth[8]; + int16_t vad_hist[XOMBE_VAD_HIST][8]; /* log2 of the smoothed band powers, Q10 (vad.c) */ + int16_t vad_hist_fl[XOMBE_VAD_HIST]; /* log2 of each half's floor, Q10 */ + int64_t vad_hist_sum[8]; /* history's band powers, dequantized to Q20 and summed */ + int16_t vad_above[8]; /* halves in a row with band SNR > 0 dB, up to XOMBE_VAD_HIST */ + int vad_hist_n, vad_hist_pos, vad_ready, hangover; + int confident_run; + float ns_noise[XOMBE_NS_BINS], ns_floor; /* shared background estimate (xombe__ns_update) */ + int ns_ready; + xombe_ns_mem ns_mem; /* AMBE+2 back end's gain smoothing */ + float cn_power[XOMBE_SPEC_BINS]; + int cn_ready, cn_updates; + xombe_cpx tone_spec[XOMBE_TONE_FFT / 2 + 1]; /* scratch, not carried between frames */ + int tone_prev_id, tone_confirmed, tone_hold_used, tone_last_id, tone_last_ad; + uint8_t tone_req[XOMBE_ENC_DELAY + XOMBE_ENC_LOOKAHEAD + 1][2]; /* forced tone ID (0: none) and AD of each + input frame in the delay, newest first */ + xombe_pred pi; /* AMBE+2 back end's prediction memory */ + xombe_tap_fn tap; + void *tap_ctx; + XOMBE_KERN_STATE +#if !XOMBE_HAVE_DSTAR + /* AMBE+2 closed-loop quantizer workspace, opaque here (enc/ambe2_enc.c: A2_CQ_WS(e)) */ + union { + int64_t align_i; + void *align_p; + float align_f; + unsigned char bytes[XOMBE_ENC_CQ_SIZE]; + } cq; +#endif +#if XOMBE_HAVE_DSTAR + /* D-STAR back end state, opaque here (dstar/dstar_enc.h: XOMBE_DS_ENC(e)) */ + union { + int64_t align_i; + void *align_p; + float align_f; + unsigned char bytes[XOMBE_DS_ENC_STATE]; + } ds; +#endif +}; +#endif + +#endif diff --git a/xombe/src/tables/cq_q15_tables.c b/xombe/src/tables/cq_q15_tables.c new file mode 100644 index 0000000..16ce4e7 --- /dev/null +++ b/xombe/src/tables/cq_q15_tables.c @@ -0,0 +1,1315 @@ +/* generated by scripts/gen_cq_tables.py, do not edit */ +#include "cq_q15_tables.h" + +#if XOMBE_KERNELS_Q15 && (XOMBE_HAVE_ENCODER || XOMBE_HAVE_DSTAR) +static const uint32_t r24_ambe2[512][5] = { + {0x037408dbu, 0xf4f002f9u, 0x0668f5beu, 0xeaf921abu, 0x0000ec7fu}, + {0x02f1063au, 0xf772014bu, 0x03e7fa53u, 0xec9a1c3au, 0x0000f321u}, + {0x03602202u, 0xea93050cu, 0x0841e5cbu, 0xeb3841fau, 0x0000e694u}, + {0x03f71690u, 0xed16019eu, 0x0511f3eau, 0xe97a35beu, 0x0000f19bu}, + {0x00fe0262u, 0xfcec0050u, 0x011dfe46u, 0xf4ba1178u, 0x0000f9acu}, + {0x00d20192u, 0xfdbb001fu, 0x00a0ff23u, 0xf5c20e2cu, 0x0000fc18u}, + {0x016e07e4u, 0xf9470012u, 0xff5c0181u, 0xf2771fc8u, 0x00000307u}, + {0x019a05c3u, 0xf9ec0028u, 0xff0001e6u, 0xf1ae1b29u, 0x00000479u}, + {0x03ff023du, 0xfa05037fu, 0x0779fa68u, 0xe96310eeu, 0x0000ead9u}, + {0x020c0265u, 0xfb920201u, 0x040dfb9eu, 0xefcf1183u, 0x0000effcu}, + {0x02d60783u, 0xf6c50029u, 0x015afdccu, 0xecf41f03u, 0x0000fb74u}, + {0x019f0567u, 0xfa16003bu, 0x0139fdc4u, 0xf19a1a4bu, 0x0000fa8fu}, + {0x020c000du, 0xff5c006du, 0x01ddffb5u, 0xefd00287u, 0x0000f8a2u}, + {0x02d00002u, 0xffab0011u, 0x00dffff3u, 0xed06011du, 0x0000fd10u}, + {0x019c019fu, 0xfcc4000cu, 0xff75008cu, 0xf1a40e68u, 0x0000026du}, + {0x022c0114u, 0xfcf10015u, 0xff290098u, 0xef540bbdu, 0x0000033bu}, + {0x002c030du, 0xfe8e0546u, 0x01e7f7fbu, 0xfb5113c2u, 0x0000e606u}, + {0x00550174u, 0xfe9d038eu, 0x022bfb74u, 0xf97f0da4u, 0x0000eaadu}, + {0x009a0c36u, 0xfa920176u, 0x01e1f78du, 0xf7362789u, 0x0000f253u}, + {0x00830878u, 0xfbd600edu, 0x0161fa66u, 0xf7e820ecu, 0x0000f51bu}, + {0x0031008au, 0xff5c01afu, 0x0121fe18u, 0xfb130852u, 0x0000f153u}, + {0x0060001fu, 0xff920155u, 0x016aff32u, 0xf91203f4u, 0x0000f2f4u}, + {0x006301eau, 0xfe470016u, 0x005dff31u, 0xf8f40fa5u, 0x0000fcb1u}, + {0x003001b3u, 0xfee00007u, 0x0023ff96u, 0xfb200ec0u, 0x0000fe32u}, + {0x0213001du, 0xff060a22u, 0x092bfdd8u, 0xefb503d4u, 0x0000dbfdu}, + {0x00960001u, 0xffe605feu, 0x03bfffaeu, 0xf75900bfu, 0x0000e44du}, + {0x00be015fu, 0xfdfb00b4u, 0x0172fe09u, 0xf6420d41u, 0x0000f681u}, + {0x008800cdu, 0xfeb2007au, 0x0102fec4u, 0xf7c20a1eu, 0x0000f82fu}, + {0x00ac0244u, 0x02770147u, 0x01da0367u, 0xf6bdeefau, 0x0000f335u}, + {0x01570411u, 0x04ac00c9u, 0x020d0392u, 0xf2e6e92fu, 0x0000f5fcu}, + {0x00a00000u, 0xffff0024u, 0x00980000u, 0xf7120005u, 0x0000fbbfu}, + {0x00ee0000u, 0xfffb0005u, 0x0046ffffu, 0xf516001fu, 0x0000fe66u}, + {0x0ad20532u, 0xf101026au, 0x0a38f8ebu, 0xdac919c9u, 0x0000ee6du}, + {0x0958012cu, 0xf9630131u, 0x06adfda3u, 0xdd6b0c3eu, 0x0000f3a5u}, + {0x05280cd2u, 0xefbe0000u, 0x002cffbbu, 0xe64f2882u, 0x0000ff93u}, + {0x06dd071au, 0xf209001fu, 0xfe2d01dbu, 0xe25c1e26u, 0x000003efu}, + {0x06270010u, 0xfebe0009u, 0xff100019u, 0xe3f002deu, 0x00000224u}, + {0x09500002u, 0xff770000u, 0x003bfffeu, 0xdd7900feu, 0x0000ff92u}, + {0x03f3039eu, 0xf8710177u, 0xfb30049bu, 0xe9841585u, 0x00000db4u}, + {0x04a401d8u, 0xfa2700ccu, 0xfc28026cu, 0xe7a00f5cu, 0x00000a17u}, + {0x1a0303deu, 0xebf10f2bu, 0x27baf0afu, 0xc64c163fu, 0x0000d3f1u}, + {0x15df0022u, 0xfc9c07c0u, 0x1a0afdfbu, 0xcb16041au, 0x0000e082u}, + {0x050a02f1u, 0xf84e0060u, 0x02c1fde5u, 0xe69c1366u, 0x0000f90fu}, + {0x065e01c7u, 0xf9460000u, 0xffd10019u, 0xe3730f14u, 0x00000069u}, + {0x0da001ccu, 0x09e50096u, 0x05a9020eu, 0xd63df0d6u, 0x0000f754u}, + {0x14200599u, 0x153b000au, 0x01c300eeu, 0xcd3fe53bu, 0x0000fdc7u}, + {0x088d000cu, 0x01440266u, 0xf6f2ff54u, 0xdeeafd8du, 0x00001184u}, + {0x1d61000bu, 0x024b017au, 0xf2d5ff7cu, 0xc2adfd9bu, 0x00000dbeu}, + {0x01d1001fu, 0xff0f01cdu, 0x039eff11u, 0xf0c103f2u, 0x0000f0d2u}, + {0x01c70002u, 0x00360158u, 0x0317002fu, 0xf0eaff1cu, 0x0000f2e4u}, + {0x016b02a0u, 0xfc240007u, 0x0066ff75u, 0xf2861255u, 0x0000fe1bu}, + {0x02320220u, 0xfbaf001au, 0x00f3ff11u, 0xef3e107du, 0x0000fc61u}, + {0x031701c8u, 0x04b100dfu, 0x0349027eu, 0xec1df0e8u, 0x0000f56eu}, + {0x04c40397u, 0x0846013fu, 0x04e0043bu, 0xe74eea90u, 0x0000f35eu}, + {0x01dc004au, 0xfe89001du, 0xff16005cu, 0xf0910612u, 0x000003c9u}, + {0x01a2001eu, 0xff210008u, 0xff8d001fu, 0xf18b03dau, 0x000001feu}, + {0x030202e7u, 0x05e9065fu, 0x08c1089au, 0xec62ecb9u, 0x0000e372u}, + {0x082202c2u, 0x097905eau, 0x0dde0813u, 0xdfbced37u, 0x0000e47du}, + {0x04990019u, 0x01560082u, 0x030e0072u, 0xe7befc7au, 0x0000f7f1u}, + {0x0480006du, 0x02c5001du, 0x01700071u, 0xe800f89du, 0x0000fc2au}, + {0x0b391357u, 0x1d77005fu, 0x0414055au, 0xda1ace3fu, 0x0000f91du}, + {0x19911ce9u, 0x3660010fu, 0x0a660b0fu, 0xc6cbc32bu, 0x0000f45eu}, + {0x05090227u, 0x06960001u, 0xffbdffd4u, 0xe69cef66u, 0x000000aau}, + {0x0674045bu, 0x0a9a000cu, 0xfee6ff19u, 0xe343e864u, 0x00000273u}, + {0x00210281u, 0xfede0117u, 0x00bffcb2u, 0xfbf511e7u, 0x0000f42fu}, + {0x00250216u, 0xfee70078u, 0x0085fe05u, 0xfbb21056u, 0x0000f840u}, + {0x005806bau, 0xfcf50001u, 0xffef004cu, 0xf95c1d57u, 0x000000a5u}, + {0x0046061eu, 0xfd690008u, 0x002fff22u, 0xfa151bfcu, 0x0000fe04u}, + {0x00060037u, 0xffda000eu, 0x0013ffc8u, 0xfe340544u, 0x0000fd5cu}, + {0x00160011u, 0xffd90007u, 0x001affe9u, 0xfcb102f0u, 0x0000fe12u}, + {0x0010025au, 0xff3e0067u, 0xffb001f2u, 0xfd35115bu, 0x0000072cu}, + {0x002301f3u, 0xfef8005bu, 0xff8f01aau, 0xfbd30fcdu, 0x000006bfu}, + {0x0072001au, 0xff9300a6u, 0x0113ff7cu, 0xf876039fu, 0x0000f6e5u}, + {0x0059001cu, 0xff9b0051u, 0x00aaffa0u, 0xf95103c4u, 0x0000f9a0u}, + {0x00670176u, 0xfe780008u, 0xffc7006eu, 0xf8d50dafu, 0x00000200u}, + {0x00290120u, 0xff280001u, 0xfff20024u, 0xfb800c01u, 0x000000c2u}, + {0x0036011au, 0x00f7002du, 0x006200e1u, 0xfacff41du, 0x0000fb47u}, + {0x002d0244u, 0x0143003cu, 0x00680174u, 0xfb41eef8u, 0x0000fa89u}, + {0x00120007u, 0x0016007fu, 0xffa1ffc4u, 0xfd06fe1fu, 0x000007fbu}, + {0x00570002u, 0x001d00a2u, 0xff13ffd8u, 0xf96afee3u, 0x000008feu}, + {0x0046006cu, 0x00ae01e9u, 0xfe8dfe35u, 0x05ef0757u, 0x0000f05eu}, + {0x0001002cu, 0x000901b7u, 0xffe2feebu, 0x008104abu, 0x0000f12fu}, + {0x00080255u, 0x008d0049u, 0xffcffe5fu, 0x02091148u, 0x0000f9f8u}, + {0x00050212u, 0x00670015u, 0xffecff2eu, 0x01961048u, 0x0000fcc6u}, + {0x00040112u, 0xffbf00e9u, 0xffc401f9u, 0x0162f44bu, 0x0000f538u}, + {0x000101a2u, 0x0025008bu, 0x001601e2u, 0xff5af18bu, 0x0000f7a8u}, + {0x0002000du, 0x00090002u, 0x0004000bu, 0x00e50291u, 0x00000107u}, + {0x00010000u, 0x00000009u, 0x00060001u, 0x00ad0018u, 0x0000021cu}, + {0x000b02a5u, 0x00aa02d2u, 0x00b00576u, 0xfdb0ed9au, 0x0000ed01u}, + {0x00610389u, 0x025103bfu, 0x02620747u, 0xf908eabbu, 0x0000ea19u}, + {0x00040001u, 0x00050017u, 0xffecfff5u, 0x017700d0u, 0x0000fca4u}, + {0x0000000eu, 0x00010015u, 0x00010022u, 0xffe2fd65u, 0x0000fcc4u}, + {0x001f1085u, 0x02d1027du, 0x01180cd2u, 0xfc15d204u, 0x0000ee28u}, + {0x017618bcu, 0x0c0502f3u, 0x04261114u, 0xf255c7bbu, 0x0000ec93u}, + {0x002301c1u, 0x00fb0002u, 0xfff1ffccu, 0xfbd0f104u, 0x000000e0u}, + {0x002f0288u, 0x015f0012u, 0xffc6ff28u, 0xfb21ee00u, 0x000002ffu}, + {0x013300a5u, 0xfe3e0019u, 0x00b1ff7eu, 0xf39b0916u, 0x0000fc6fu}, + {0x00d50052u, 0xfef70021u, 0x00a7ff98u, 0xf5af066cu, 0x0000fbf7u}, + {0x00900243u, 0xfdbe0032u, 0xff560155u, 0xf7811104u, 0x00000501u}, + {0x00a001ebu, 0xfdcf007au, 0xfee801eau, 0xf70e0fabu, 0x000007d1u}, + {0x0109007au, 0x01670008u, 0xffa2ffc1u, 0xf47bf834u, 0x00000208u}, + {0x01770119u, 0x028a0003u, 0xffc0ffc9u, 0xf24ef424u, 0x00000129u}, + {0x00c20012u, 0xff890186u, 0xfdda00a8u, 0xf6260302u, 0x00000df5u}, + {0x01200012u, 0xff6f028cu, 0xfc9e00dbu, 0xf4020307u, 0x0000120eu}, + {0x05890006u, 0x00bc0391u, 0x08e30097u, 0xe562fe3du, 0x0000eaa2u}, + {0x03950082u, 0x02b202b2u, 0x06370257u, 0xea98f7f1u, 0x0000ed6bu}, + {0x012b0008u, 0x0060004eu, 0xfecfffcfu, 0xf3c8fe0bu, 0x0000063du}, + {0x01690019u, 0x00bd00cfu, 0xfdddff71u, 0xf290fc7cu, 0x00000a2du}, + {0x02cd083cu, 0x099b0182u, 0x041d070du, 0xed10df8au, 0x0000f21au}, + {0x05340ad4u, 0x0f030166u, 0x056407c7u, 0xe632dac5u, 0x0000f2a1u}, + {0x02af02e0u, 0x058e02d3u, 0xfa7efa4du, 0xed76ecd1u, 0x00001304u}, + {0x04360438u, 0x086e0619u, 0xf5def5dbu, 0xe8c9e8c2u, 0x00001bf0u}, + {0x000f007fu, 0x005600cau, 0x006c0141u, 0xfd4ef806u, 0x0000f5f4u}, + {0x004700d6u, 0x00f60114u, 0x011701e6u, 0xfa0ff5a9u, 0x0000f43fu}, + {0x0052003bu, 0xff750000u, 0x0001ffffu, 0xf9960569u, 0x0000fff1u}, + {0x00980019u, 0xff840009u, 0xffb7001eu, 0xf7460390u, 0x00000219u}, + {0x01400982u, 0x06e60006u, 0x005700f0u, 0xf359dd1du, 0x0000fe47u}, + {0x01090e0eu, 0x07a10006u, 0xffb2fee1u, 0xf47ed595u, 0x000001b1u}, + {0x00b600e1u, 0x01940043u, 0xff23ff0bu, 0xf678f567u, 0x000005c9u}, + {0x011201dbu, 0x02d1005bu, 0xfec4fe60u, 0xf44df097u, 0x000006c0u}, + {0x04230aa1u, 0x0d4206aeu, 0x0a8310dau, 0xe8fedb1eu, 0x0000e2c3u}, + {0x09d4104au, 0x194d0746u, 0x10e815c5u, 0xdc89d257u, 0x0000e17du}, + {0x019a026eu, 0x03f20016u, 0x00bd00e9u, 0xf1b0ee5cu, 0x0000fcb3u}, + {0x01b40423u, 0x054f0006u, 0x0066009fu, 0xf13be8feu, 0x0000fe46u}, + {0x029834a3u, 0x176101c0u, 0x04431330u, 0xedc6adebu, 0x0000f10au}, + {0x051e23fdu, 0x1b240a22u, 0x0e672631u, 0xe668bc21u, 0x0000dbfdu}, + {0x025f1854u, 0x0f310002u, 0xffb8ff1au, 0xee94c832u, 0x00000108u}, + {0x037911e7u, 0x0fc50273u, 0xfa2bf2c1u, 0xeaebd022u, 0x000011b5u}, + {0x00110d3cu, 0x01e70df1u, 0xfe0de4d5u, 0x02f52928u, 0x0000d5c1u}, + {0x00861170u, 0xf9f60605u, 0x038ceb82u, 0xf7d12f3fu, 0x0000e43eu}, + {0x00052aebu, 0x01e50103u, 0xffb5f2d1u, 0x01a34a1eu, 0x0000f49eu}, + {0x00011e69u, 0xff6a0067u, 0x0011f8feu, 0xff663e64u, 0x0000f8cfu}, + {0x00090597u, 0x00e0007fu, 0xffbdfcabu, 0x02181ac1u, 0x0000f807u}, + {0x000004a8u, 0xfff6003cu, 0x0002fdeau, 0xffe61869u, 0x0000fa87u}, + {0x001a12e3u, 0x02c2004bu, 0x005804b1u, 0x0397312cu, 0x0000061bu}, + {0x00160eccu, 0x024400beu, 0x008206a1u, 0x03552b85u, 0x000009c0u}, + {0x0001072au, 0x0061023cu, 0xffcaf800u, 0x00ce1e49u, 0x0000ef17u}, + {0x000b03d0u, 0x00cf01fbu, 0xff6bfa81u, 0x02581617u, 0x0000f014u}, + {0x000511d2u, 0xfec4005cu, 0x002dfaefu, 0xfe582fc2u, 0x0000f936u}, + {0x001c0d49u, 0xfd99004au, 0x005bfc14u, 0xfc46293du, 0x0000f9e9u}, + {0x0004011bu, 0xffbc0029u, 0x001aff29u, 0xfe940be6u, 0x0000fb7cu}, + {0x000100afu, 0xffe9001bu, 0x0009ff76u, 0xff640959u, 0x0000fc4cu}, + {0x000103abu, 0x00480028u, 0x000f0184u, 0x00d515aau, 0x0000047au}, + {0x001202dcu, 0x00e80017u, 0x00290102u, 0x03091322u, 0x0000035eu}, + {0x021a03d5u, 0x05ad04a1u, 0xf9c3f794u, 0x10661625u, 0x0000e7aau}, + {0x00dc0323u, 0x03480328u, 0xfcb5f9b5u, 0x0a7c140au, 0x0000ebe7u}, + {0x0057108du, 0x04bf020bu, 0xfe55f45fu, 0x06992e07u, 0x0000efd5u}, + {0x00f40c5cu, 0x06dc0240u, 0xfd13f574u, 0x0b0927c5u, 0x0000ef07u}, + {0x005a01dau, 0x019c0150u, 0xfea5fce2u, 0x06b30f64u, 0x0000f309u}, + {0x00a0015fu, 0x01d9009cu, 0xfec4fe2cu, 0x08f00d3fu, 0x0000f72bu}, + {0x00540425u, 0x02550017u, 0xffa8fec7u, 0x067b1709u, 0x0000fc9cu}, + {0x0082033du, 0x02900000u, 0xfff9ffeeu, 0x080f145cu, 0x0000ffc7u}, + {0x001500b9u, 0x007c055bu, 0xfeaffc0fu, 0x033709a1u, 0x0000e5d0u}, + {0x00450124u, 0x011c0365u, 0xfe16fc11u, 0x05e20c15u, 0x0000eb27u}, + {0x00070397u, 0x00a00050u, 0xffd1fde3u, 0x01dd156fu, 0x0000f9b1u}, + {0x0002035fu, 0x00540096u, 0xffddfd30u, 0x010314c5u, 0x0000f755u}, + {0x000c000fu, 0xffe50164u, 0xff7c0091u, 0x027afd48u, 0x0000f2a7u}, + {0x004a0038u, 0xff7f00f8u, 0xfef200edu, 0x0611fab0u, 0x0000f4dcu}, + {0x0056004au, 0x009f0005u, 0xffd5ffd8u, 0x06920611u, 0x0000fe5bu}, + {0x00730021u, 0x007b0000u, 0x00000000u, 0x0799040du, 0x0000ffffu}, + {0x009f040eu, 0xfcd4012du, 0x01b5fba2u, 0xf71716c8u, 0x0000f3bbu}, + {0x005b04f0u, 0xfd59008fu, 0x00e4fcaeu, 0xf9401923u, 0x0000f78cu}, + {0x01570e18u, 0xf74f0008u, 0x0069feacu, 0xf2e72a7au, 0x0000fe00u}, + {0x00b10be2u, 0xfa450034u, 0xff40031bu, 0xf6992700u, 0x00000518u}, + {0x009100bdu, 0xfeb50000u, 0x0010ffeeu, 0xf78009b8u, 0x0000ff8bu}, + {0x00d700b0u, 0xfe7c0005u, 0xffbe003cu, 0xf5a3095fu, 0x00000197u}, + {0x00960522u, 0xfc8901bau, 0xfdfd05f4u, 0xf75919a2u, 0x00000edeu}, + {0x006f0361u, 0xfd93020eu, 0xfe1c0545u, 0xf88a14ccu, 0x00001039u}, + {0x017b00eau, 0xfdac011au, 0x028efdfeu, 0xf23b0ad2u, 0x0000f41fu}, + {0x01260088u, 0xfe7100d2u, 0x01f1feaeu, 0xf3e1083cu, 0x0000f5beu}, + {0x0070040fu, 0xfd55000cu, 0x004aff20u, 0xf88316ccu, 0x0000fd8bu}, + {0x00ab03c3u, 0xfcd30003u, 0xffd00072u, 0xf6bd15f2u, 0x0000014cu}, + {0x01500023u, 0x00da0010u, 0x0091002fu, 0xf309fbceu, 0x0000fd34u}, + {0x022b007fu, 0x0212000au, 0x00970048u, 0xef58f80cu, 0x0000fdbcu}, + {0x01c50039u, 0xfebf00c1u, 0xfdb100d1u, 0xf0f30554u, 0x000009d0u}, + {0x03110012u, 0xff15012bu, 0xfc370091u, 0xec2f02f6u, 0x00000c38u}, + {0x00010120u, 0xffe70143u, 0x001bfd9eu, 0xff7a0bfeu, 0x0000f34bu}, + {0x00030129u, 0xffc60099u, 0x002afe55u, 0xfece0c30u, 0x0000f73eu}, + {0x00050512u, 0xff580000u, 0x0003ffcfu, 0xfe5b1979u, 0x0000ff86u}, + {0x000403dau, 0xff810004u, 0x0008ff89u, 0xfe931634u, 0x0000fea9u}, + {0x003c0012u, 0x00420035u, 0x0071003eu, 0xfa85fcfdu, 0x0000fad6u}, + {0x00880025u, 0x008f0075u, 0x00fd0084u, 0xf7bffbaeu, 0x0000f859u}, + {0x0002011cu, 0xffcd0028u, 0xffed00d5u, 0xfeec0be9u, 0x0000047bu}, + {0x00020120u, 0x0035002fu, 0x001500e9u, 0x01190bfeu, 0x000004dcu}, + {0x000b0068u, 0x004502dcu, 0x00b70228u, 0xfd9bf8cau, 0x0000ecdeu}, + {0x006b0026u, 0x00800243u, 0x01f30129u, 0xf8acfba1u, 0x0000eefdu}, + {0x000e00b2u, 0xff9e0002u, 0x0009ffdfu, 0xfd670971u, 0x0000ff20u}, + {0x00200091u, 0xff770009u, 0x0022ffb9u, 0xfbfa0884u, 0x0000fde9u}, + {0x000e058eu, 0x011c0080u, 0x00550356u, 0xfd57e557u, 0x0000f7ffu}, + {0x0010082cu, 0x016e00ccu, 0x00720519u, 0xfd2cdfa9u, 0x0000f5e9u}, + {0x002e00c3u, 0x00be0015u, 0xffc2ff81u, 0xfb31f623u, 0x0000033bu}, + {0x001d00b4u, 0x00910079u, 0xff89fed9u, 0xfc2ef687u, 0x000007c7u}, + {0x00cc07b3u, 0x04f30194u, 0xfdc2f906u, 0x0a171f65u, 0x0000f1c7u}, + {0x0077061au, 0x035e015bu, 0xfe6afa3fu, 0x07b61bf3u, 0x0000f2d3u}, + {0x02521238u, 0x0d010011u, 0x00ca0236u, 0x113d304au, 0x000002efu}, + {0x025e0d51u, 0x0b3a0002u, 0x003e0093u, 0x11672949u, 0x000000e4u}, + {0x006d01ccu, 0x01c00006u, 0xffceff99u, 0x07620f2bu, 0x0000fe4fu}, + {0x00780158u, 0x01960001u, 0xffefffe3u, 0x07bf0d1du, 0x0000ff74u}, + {0x00c204b8u, 0x03c900f2u, 0x01b10439u, 0x09db1893u, 0x00000afeu}, + {0x019404beu, 0x057901d7u, 0x036805e8u, 0x0e3618a4u, 0x00000f58u}, + {0x002c0142u, 0x00ed0060u, 0xff7ffea1u, 0x04ac0cb0u, 0x0000f914u}, + {0x002e00b3u, 0x00b5007du, 0xff69fed5u, 0x04c90977u, 0x0000f81bu}, + {0x002e04e4u, 0x01e20037u, 0x0065020cu, 0x04d01905u, 0x0000053du}, + {0x004103bcu, 0x01f40027u, 0x00660184u, 0x05b915ddu, 0x00000471u}, + {0x00d10000u, 0xfff70002u, 0xffd60001u, 0x0a38ffc9u, 0x0000fef9u}, + {0x015f0010u, 0xff6c000eu, 0xff76001du, 0x0d3dfd35u, 0x0000fd65u}, + {0x005f0096u, 0x00ef0107u, 0x013d018eu, 0x06e708acu, 0x00000b7au}, + {0x00750036u, 0x009f00f9u, 0x015600e8u, 0x07a90531u, 0x00000b27u}, + {0x05210130u, 0x04f003beu, 0xf73dfbc9u, 0x199f0c54u, 0x0000ea1eu}, + {0x029900f0u, 0x031f0192u, 0xfbf6fd93u, 0x123c0af5u, 0x0000f1d3u}, + {0x04200491u, 0x08af00bcu, 0xfc85fc56u, 0x16fb182eu, 0x0000f64du}, + {0x02d70568u, 0x07d60052u, 0xfe19fd60u, 0x13111a4fu, 0x0000f99du}, + {0x02320001u, 0xffd500b7u, 0xfd7e0019u, 0x10c3ff5bu, 0x0000f66du}, + {0x02a6005fu, 0xfe030070u, 0xfdd800cfu, 0x126bf919u, 0x0000f883u}, + {0x016800cdu, 0x021f0032u, 0x010c00cau, 0x0d6c0a1du, 0x000004feu}, + {0x01ba0063u, 0x01a20040u, 0x014f009eu, 0x0ede0705u, 0x000005a4u}, + {0x01670000u, 0x00020500u, 0xfab4fffbu, 0x0d66000bu, 0x0000e6b5u}, + {0x01b30048u, 0xfe9d0282u, 0xfbe001afu, 0x0ebef9fcu, 0x0000ee16u}, + {0x01b5009bu, 0x0208007eu, 0xfe2bfee9u, 0x0ec708cau, 0x0000f80eu}, + {0x00e40057u, 0x011a0053u, 0xfeeeff56u, 0x0aae0699u, 0x0000f993u}, + {0x02fc02fau, 0xfa0900feu, 0xfc8f0370u, 0x138cec7au, 0x0000f4bcu}, + {0x03a305b3u, 0xf6e502c1u, 0xf9ac07ecu, 0x1594e4fdu, 0x0000ed3bu}, + {0x01190079u, 0xfe8f0013u, 0x0092ffa0u, 0x0bd9f835u, 0x00000314u}, + {0x014900f0u, 0xfdcf0017u, 0x00adff6cu, 0x0cd2f50du, 0x00000361u}, + {0x0001019bu, 0xffd90003u, 0x0003ffb8u, 0xff510e58u, 0x0000febdu}, + {0x00030149u, 0xffbe0000u, 0xffff0006u, 0xfeb60cd1u, 0x0000001du}, + {0x000904b0u, 0x00cb00d6u, 0x005603f6u, 0x0212187fu, 0x00000a59u}, + {0x000303d3u, 0xff9000deu, 0xffcb03a3u, 0xfebd161fu, 0x00000a86u}, + {0x00110007u, 0x0016002au, 0x00350022u, 0x02e101e2u, 0x00000494u}, + {0x00010008u, 0x0006003eu, 0x0010002eu, 0x00b2020bu, 0x00000592u}, + {0x000d010fu, 0x0075014fu, 0x0082025bu, 0x02810ba5u, 0x00000cf3u}, + {0x0009010fu, 0x0063020eu, 0x008a02f3u, 0x02200ba3u, 0x00001038u}, + {0x00240001u, 0x000900acu, 0x009e0015u, 0xfbbcff72u, 0x0000f6bdu}, + {0x00040004u, 0x00080082u, 0x002c002du, 0xfea3fe9bu, 0x0000f7f1u}, + {0x00000099u, 0x0000001du, 0x00000085u, 0x000208c1u, 0x000003ceu}, + {0x00030096u, 0xffd30058u, 0xffdd00e6u, 0xfeb108aau, 0x000006a5u}, + {0x000d02adu, 0xff440001u, 0xfff8003au, 0x028bed7fu, 0x0000ff37u}, + {0x000503acu, 0xff70000au, 0xfff200bdu, 0x01a8ea53u, 0x0000fdd2u}, + {0x00130002u, 0xfff30141u, 0x009effcau, 0x031cfef1u, 0x00000cacu}, + {0x00010012u, 0xfff70148u, 0x0027ff67u, 0x00c2fd01u, 0x00000cccu}, + {0x00850049u, 0x00c500edu, 0xfe9dfefau, 0x08280608u, 0x0000f520u}, + {0x004c0013u, 0x004c00b4u, 0xff17ff8bu, 0x06280317u, 0x0000f685u}, + {0x00370183u, 0x01230002u, 0x00120031u, 0x053b0deau, 0x000000e0u}, + {0x003b0108u, 0x00f90008u, 0x002c005du, 0x056b0b7fu, 0x00000203u}, + {0x007201a7u, 0xfe48000du, 0xffb30094u, 0x0790f173u, 0x0000fd74u}, + {0x00d1036cu, 0xfca80003u, 0xffce0065u, 0x0a39eb11u, 0x0000fecau}, + {0x00690000u, 0x00020081u, 0x00e80002u, 0x073d000eu, 0x00000805u}, + {0x00880002u, 0xffe100dcu, 0x015affd9u, 0x0840ff11u, 0x00000a7bu}, + {0x00c30213u, 0xfd7c01b9u, 0xfdb503c8u, 0x09e1efb5u, 0x0000f127u}, + {0x007f03fdu, 0xfd3100f9u, 0xfe9d03f1u, 0x07f5e967u, 0x0000f4d6u}, + {0x005f001eu, 0xff94000bu, 0x0042ffdbu, 0x06e5fc19u, 0x00000262u}, + {0x00350054u, 0xff7b0020u, 0x0052ff98u, 0x0524f989u, 0x00000403u}, + {0x029c1b80u, 0xef0d01dau, 0xfb9a0e46u, 0x1248c4acu, 0x0000f09bu}, + {0x02762a8fu, 0xeb8a0354u, 0xfa4717ceu, 0x11beb632u, 0x0000eb5cu}, + {0x00600a5cu, 0xfc1000f4u, 0x0132f9b7u, 0x06ecdb95u, 0x00000b0cu}, + {0x008e09deu, 0xfb540366u, 0x02bef46bu, 0x086adc76u, 0x000014dcu}, + {0x0023089du, 0x022e0091u, 0xff71fb96u, 0x04342135u, 0x0000f77fu}, + {0x0000080bu, 0xffca004au, 0x000afcf5u, 0xff942016u, 0x0000f9edu}, + {0x00b92460u, 0xf5bd014eu, 0xfe0f0dc5u, 0xf660443cu, 0x00000ceau}, + {0x00e31794u, 0xf6dc0037u, 0xff21047du, 0xf55936f0u, 0x0000053au}, + {0x0008034au, 0xff5b000du, 0xffec00d0u, 0xfdfc1484u, 0x00000288u}, + {0x002e031bu, 0xfe810006u, 0xffe00085u, 0xfb3113efu, 0x000001aau}, + {0x00030c88u, 0xff3403d5u, 0xff8f0ddcu, 0xfebb280eu, 0x00001626u}, + {0x000008d4u, 0xffde0299u, 0xffee0994u, 0xffbf219eu, 0x0000123bu}, + {0x002f0320u, 0xfe7c0024u, 0x0053feabu, 0xfb281402u, 0x0000fbbcu}, + {0x001b02ccu, 0xfee7000fu, 0x0028ff33u, 0xfc4b12edu, 0x0000fd4cu}, + {0x000709b2u, 0xfef90012u, 0xffea01a7u, 0xfe23233bu, 0x00000300u}, + {0x002706efu, 0xfdf2004cu, 0xff9302ddu, 0xfb961dcau, 0x00000628u}, + {0x0016007bu, 0xff980010u, 0xffda0059u, 0xfcb007dau, 0x000002d6u}, + {0x00100034u, 0xffc60011u, 0xffdf003cu, 0xfd2d0519u, 0x000002eeu}, + {0x000801d3u, 0xff8300f1u, 0xffa602a0u, 0xfdf60f48u, 0x00000afdu}, + {0x002b014au, 0xff110106u, 0xff2b024cu, 0xfb5a0cd9u, 0x00000b70u}, + {0x008d03c1u, 0x02e100dau, 0xfea1fc6du, 0x086715ecu, 0x0000f591u}, + {0x006602c4u, 0x021a0082u, 0xff1afda2u, 0x072712d1u, 0x0000f7f3u}, + {0x007a0b1fu, 0x04990014u, 0xff9dfe23u, 0x07cc25bbu, 0x0000fcd7u}, + {0x008f09b3u, 0x04a90003u, 0x0026009eu, 0x0878233bu, 0x0000011eu}, + {0x001300ddu, 0x0080001cu, 0xffd3ff63u, 0x030b0a84u, 0x0000fc43u}, + {0x00140076u, 0x00610016u, 0xffd6ff99u, 0x032707b0u, 0x0000fca5u}, + {0x000a0252u, 0x009a0058u, 0x003b01c8u, 0x023d113au, 0x000006a0u}, + {0x000c02d5u, 0x00bc009fu, 0x005802a7u, 0x0277130au, 0x000008eau}, + {0x00080049u, 0xffd000c1u, 0x004eff12u, 0xfe06060du, 0x0000f62fu}, + {0x00050035u, 0x00200085u, 0xffcdff58u, 0x018f0525u, 0x0000f7d6u}, + {0x00190288u, 0x00fe0000u, 0x00000001u, 0x03881202u, 0x00000003u}, + {0x000d01c4u, 0x00980002u, 0x00090036u, 0x02870f09u, 0x000000e5u}, + {0x00010072u, 0xffe9000au, 0xfff90042u, 0x00c4f870u, 0x0000fdcfu}, + {0x000600ccu, 0xffb80000u, 0xfffe000du, 0x01c7f5e9u, 0x0000ffaeu}, + {0x00060056u, 0x002e0051u, 0x002d00a8u, 0x01bf0692u, 0x00000662u}, + {0x00170031u, 0x0043006du, 0x00630092u, 0x035d04f2u, 0x00000766u}, + {0x027c0379u, 0xfa210002u, 0xffb60058u, 0xee2c1515u, 0x0000010bu}, + {0x024c02ffu, 0xfac1004au, 0xfe5f01dcu, 0xeedb1395u, 0x00000614u}, + {0x04fe133cu, 0xec6702b5u, 0xf8a60e6du, 0xe6b8319eu, 0x0000129cu}, + {0x02090ae2u, 0xf697029bu, 0xfb650aa7u, 0xefdd2553u, 0x00001244u}, + {0x0110012fu, 0xfdc20084u, 0xfe850190u, 0xf4560c4du, 0x0000081eu}, + {0x01ef011bu, 0xfd1300d2u, 0xfd7c01e7u, 0xf0450be6u, 0x00000a3cu}, + {0x020203d6u, 0xfa73040cu, 0xfa4d07e2u, 0xeff9162au, 0x000016c3u}, + {0x04410404u, 0xf7bd0724u, 0xf4fb0ab5u, 0xe8ac16abu, 0x00001e3bu}, + {0x03260095u, 0xfd4b006du, 0x0250ff01u, 0xebed08a3u, 0x0000f8a1u}, + {0x02a10082u, 0xfdb0000du, 0x00bbffaeu, 0xeda90812u, 0x0000fd72u}, + {0x016f0544u, 0xfa810145u, 0xfd4d052bu, 0xf27219f6u, 0x00000cbeu}, + {0x0176031eu, 0xfbbc012bu, 0xfd6403d1u, 0xf25413f9u, 0x00000c39u}, + {0x02d4002au, 0x015c0036u, 0xfe73ffa1u, 0xecf8fb6eu, 0x00000536u}, + {0x02eb00e1u, 0x033500d3u, 0xfce5fe4cu, 0xecacf563u, 0x00000a48u}, + {0x02b400b3u, 0xfd4002d8u, 0xfa7402d2u, 0xed650976u, 0x00001316u}, + {0x03140021u, 0xfebe0507u, 0xf822019bu, 0xec27040du, 0x0000195du}, + {0x003600a4u, 0xff430030u, 0x0066ff4eu, 0xfacb090du, 0x0000fb19u}, + {0x0059006eu, 0xff3a000du, 0x0044ffb4u, 0xf951076bu, 0x0000fd73u}, + {0x003e0450u, 0xfdf3004cu, 0xff760244u, 0xfa6a177du, 0x0000062bu}, + {0x0072037cu, 0xfd820084u, 0xff0a02afu, 0xf873151fu, 0x00000822u}, + {0x00200000u, 0xfffd0005u, 0xffe60001u, 0xfc01002fu, 0x0000019cu}, + {0x00370016u, 0x0047000eu, 0xffc7ffdcu, 0xfabdfca5u, 0x000002b0u}, + {0x009a010eu, 0xfe6801b3u, 0xfdfb02aeu, 0xf73b0b9fu, 0x00000ec0u}, + {0x004900a2u, 0xff260243u, 0xfe640265u, 0xf9f20902u, 0x00001105u}, + {0x01680055u, 0x015d0097u, 0x01d300e3u, 0xf296f97du, 0x0000f74cu}, + {0x012b00cfu, 0x01f2004bu, 0x012b00f9u, 0xf3c7f5d2u, 0x0000f9e3u}, + {0x00360011u, 0xffc4002fu, 0xff9b0038u, 0xfac802e2u, 0x000004dcu}, + {0x00680002u, 0xffe10027u, 0xff820013u, 0xf8cd0113u, 0x00000464u}, + {0x00900558u, 0x03760033u, 0xff54fdeeu, 0xf787e5dau, 0x00000511u}, + {0x017905f6u, 0x05ee00ccu, 0xfdd5fba5u, 0xf243e462u, 0x00000a18u}, + {0x0055004du, 0x00a20149u, 0xfeb1fec2u, 0xf97af9ccu, 0x00000cd2u}, + {0x006c00e7u, 0x013c0236u, 0xfe11fd2du, 0xf8a6f542u, 0x000010d4u}, + {0x003d04f7u, 0x022b0001u, 0x000d003au, 0x05811935u, 0x00000093u}, + {0x001303acu, 0x010d0000u, 0xfffdffe9u, 0x031915aeu, 0x0000ffbbu}, + {0x047c18a9u, 0x150800f0u, 0x0419099cu, 0x17f6382fu, 0x00000af2u}, + {0x035f1190u, 0x0f6301e1u, 0x05080b7cu, 0x14c52f69u, 0x00000f81u}, + {0x00280148u, 0x00e6003cu, 0x0063011au, 0x047d0cd0u, 0x0000057fu}, + {0x004300f2u, 0x00ff0056u, 0x00980121u, 0x05cb0afeu, 0x00000691u}, + {0x00830329u, 0x028b0356u, 0x029d067eu, 0x0817141du, 0x000014a9u}, + {0x00230325u, 0x01500538u, 0x01b1081bu, 0x04301411u, 0x000019d9u}, + {0x001b00ddu, 0x009b0000u, 0xfffbfff1u, 0x03b20a83u, 0x0000ffa6u}, + {0x0005007au, 0x00300001u, 0x00040012u, 0x018b07d1u, 0x00000097u}, + {0x0032030au, 0x018c010bu, 0x00e80390u, 0x050513bau, 0x00000b8fu}, + {0x002d0205u, 0x013000d3u, 0x00c20294u, 0x04ba1014u, 0x00000a45u}, + {0x00050013u, 0xffee003du, 0x0022ffbdu, 0x0185fcf5u, 0x00000587u}, + {0x00000045u, 0xfff80047u, 0x0008ff74u, 0x005bfa23u, 0x000005f7u}, + {0x00100034u, 0x0039015eu, 0x0095010du, 0x02d30514u, 0x00000d3bu}, + {0x00010059u, 0x001301d8u, 0x002c019au, 0x00b906abu, 0x00000f5du}, + {0x011c01a5u, 0x02b3001bu, 0xff52ff2du, 0x0beb0e81u, 0x0000fc5cu}, + {0x00cd00f6u, 0x01c1001du, 0xff66ff57u, 0x0a1f0b17u, 0x0000fc33u}, + {0x017903b0u, 0x04a90017u, 0x00ba0126u, 0x0dba15b9u, 0x00000363u}, + {0x0122030fu, 0x03b9001cu, 0x00b30126u, 0x0c0b13c9u, 0x000003b7u}, + {0x01370002u, 0x002e0014u, 0x009c000cu, 0x0c7600edu, 0x00000322u}, + {0x01370007u, 0xffa40041u, 0x011cffd6u, 0x0c77fe28u, 0x000005b3u}, + {0x015e0028u, 0x00ec0133u, 0x029000ddu, 0x0d3b0474u, 0x00000c63u}, + {0x01510045u, 0x01300254u, 0x03800194u, 0x0cfa05dcu, 0x00001142u}, + {0x0097002au, 0xff620058u, 0xff1a0079u, 0x08aefb72u, 0x0000f95cu}, + {0x00bf0073u, 0xfed8001eu, 0xff690075u, 0x09c8f86eu, 0x0000fc26u}, + {0x00a800b1u, 0x0158001fu, 0x00910095u, 0x092a0966u, 0x000003f4u}, + {0x00a90059u, 0x00f6001au, 0x00860061u, 0x093206aeu, 0x000003a3u}, + {0x02000965u, 0xf7540003u, 0xffb8009cu, 0x1001dd53u, 0x0000fee0u}, + {0x027b0d2cu, 0xf4910067u, 0xfe020498u, 0x11d1d6f0u, 0x0000f8d6u}, + {0x00d00049u, 0xff0900dfu, 0x01aeff01u, 0x0a33f9f5u, 0x00000a8du}, + {0x0077006au, 0xff1f0192u, 0x01b6fe63u, 0x07baf8bbu, 0x00000e30u}, + {0x00330158u, 0xfef7002fu, 0xff9e00feu, 0xfaf30d1du, 0x000004d5u}, + {0x004300d5u, 0xff120040u, 0xff7d00eau, 0xfa390a52u, 0x000005adu}, + {0x00090495u, 0xff2f0313u, 0xff550782u, 0xfdd81839u, 0x000013d6u}, + {0x0014031cu, 0xff010337u, 0xfefc0652u, 0xfccd13f3u, 0x00001448u}, + {0x00150003u, 0xfff00172u, 0xff520043u, 0xfccc013cu, 0x00000d98u}, + {0x00200000u, 0xfffd027bu, 0xfee1000bu, 0xfbfa0029u, 0x000011d2u}, + {0x004300bcu, 0xff1f0561u, 0xfd9f03f9u, 0xfa3309b1u, 0x00001a3eu}, + {0x002a00d9u, 0xff420908u, 0xfd930589u, 0xfb700a6bu, 0x00002200u}, + {0x00300039u, 0x00690004u, 0x001a001du, 0xfb15faa5u, 0x0000feabu}, + {0x000f0047u, 0x00420007u, 0xffebffd4u, 0xfd37fa0fu, 0x000001deu}, + {0x00320099u, 0xff52011du, 0xff1201a2u, 0xfb0508c2u, 0x00000bf0u}, + {0x003e0042u, 0xff810117u, 0xfef9010fu, 0xfa7105bbu, 0x00000bd2u}, + {0x001c0256u, 0x010500f5u, 0xff59fd02u, 0xfc3ceeb4u, 0x00000b13u}, + {0x000103eeu, 0x00350264u, 0xffd7f9dfu, 0xff69e993u, 0x0000117du}, + {0x015a005bu, 0x016205c9u, 0xfa68fd23u, 0xf2d9f944u, 0x00001b36u}, + {0x013f0095u, 0x01b50c71u, 0xf81ffa9du, 0xf35df75cu, 0x000027e8u}, + {0x00280016u, 0xffc50010u, 0xffce0025u, 0x0477fcb1u, 0x0000fd32u}, + {0x001b0036u, 0xffb40000u, 0x00000000u, 0x03a5fad0u, 0x0000fffdu}, + {0x00020129u, 0x003300aeu, 0x002701c7u, 0x010c0c2fu, 0x00000957u}, + {0x000000a7u, 0x000600d0u, 0x00070174u, 0x002a0921u, 0x00000a30u}, + {0x000103fcu, 0xffc00044u, 0x0011fdf2u, 0x00b6e96au, 0x000005d4u}, + {0x001a0452u, 0xfeac00b2u, 0x0088fc8au, 0x039ee87du, 0x0000096cu}, + {0x00060000u, 0xffff028eu, 0x007bfff1u, 0x01b3ffccu, 0x00001215u}, + {0x00000028u, 0x000603a6u, 0xffe3fe7du, 0xffabfb86u, 0x0000159du}, + {0x000607e1u, 0xff290003u, 0x0008ff62u, 0x01b2e03fu, 0x0000013eu}, + {0x00270f41u, 0xfcf00000u, 0xfffb002fu, 0x0470d3d1u, 0x0000ffbcu}, + {0x001200afu, 0xff9100d7u, 0x007bfe7du, 0x02f8f6a6u, 0x00000a5cu}, + {0x000a0140u, 0xff9201dcu, 0x0087fcf4u, 0x022ff35bu, 0x00000f6du}, + {0x000e1f56u, 0xfd670014u, 0x0021fcdfu, 0x02a0c0abu, 0x00000329u}, + {0x016b2a66u, 0xf07d01ceu, 0x0333ee83u, 0x0d7ab655u, 0x00000f31u}, + {0x001c0399u, 0x01400761u, 0xfe36f5b2u, 0xfc46ea89u, 0x00001ebbu}, + {0x00480814u, 0x03040e97u, 0xfbf3ea4au, 0xfa00dfd8u, 0x00002b37u}, + {0x023c17cfu, 0x0e9502c8u, 0xfb04efb8u, 0x10e83734u, 0x0000ed20u}, + {0x0205139au, 0x0c97007au, 0xfe09f9e2u, 0x10163217u, 0x0000f82fu}, + {0x06e251b2u, 0x2f6e0091u, 0xfc0cf262u, 0x1daf6642u, 0x0000f77au}, + {0x001e538bu, 0x0646003bu, 0x005408c4u, 0x03e26769u, 0x0000056du}, + {0x01690612u, 0x05da004au, 0x014702a6u, 0x0d6e1be1u, 0x00000615u}, + {0x00e005f2u, 0x048f0013u, 0x00820152u, 0x0a951b96u, 0x00000311u}, + {0x024331dau, 0x153e07a0u, 0x084f26fdu, 0x11054fe2u, 0x00001f3du}, + {0x03d220a4u, 0x1654072eu, 0x0a791e9eu, 0x161c40a3u, 0x00001e51u}, + {0x01350748u, 0x05ee001cu, 0xff47fe3bu, 0x0c6e1e87u, 0x0000fc4au}, + {0x011e0528u, 0x04cd0018u, 0xff5afe9cu, 0x0bf619b0u, 0x0000fc89u}, + {0x02982e3fu, 0x15e90024u, 0xfecafae2u, 0x123a4cf0u, 0x0000fbbeu}, + {0x0154244au, 0x0de30012u, 0x009b0329u, 0x0d0b4427u, 0x000002f8u}, + {0x00920218u, 0x022f0011u, 0x006500c1u, 0x088a1060u, 0x000002f2u}, + {0x00880188u, 0x01ce0023u, 0x008a00eau, 0x083f0dffu, 0x0000042eu}, + {0x010f07b5u, 0x05b802a1u, 0x03570901u, 0x0ba71f6au, 0x00001257u}, + {0x005d0637u, 0x030202e7u, 0x020e087eu, 0x06d21c35u, 0x00001346u}, + {0x08c00bafu, 0x143901d2u, 0xf804f6c6u, 0x217826acu, 0x0000f0bau}, + {0x049008ddu, 0x0cb80141u, 0xfb37f954u, 0x182a21afu, 0x0000f352u}, + {0x0bc32285u, 0x284c0078u, 0xfb4cf7f1u, 0x26cd4279u, 0x0000f83du}, + {0x09c21fb3u, 0x232d0064u, 0x03ea070du, 0x23573fb3u, 0x00000716u}, + {0x03260233u, 0x0544003eu, 0xfe41fe8bu, 0x141310c8u, 0x0000fa70u}, + {0x026401b5u, 0x040a0018u, 0xff0dff33u, 0x117f0ec6u, 0x0000fc87u}, + {0x07b509a0u, 0x113a027au, 0x08bd09c4u, 0x1f68231au, 0x000011ceu}, + {0x040d06fau, 0x0aa302adu, 0x069608a4u, 0x16c61de3u, 0x00001282u}, + {0x01c90450u, 0x058d01aau, 0xfc8dfaa4u, 0x0f1d177fu, 0x0000f167u}, + {0x01c00310u, 0x04a100f0u, 0xfd70fc9cu, 0x0ef713cdu, 0x0000f509u}, + {0x027306edu, 0x083c0001u, 0x00320053u, 0x11b31dc7u, 0x000000b3u}, + {0x02010493u, 0x060e0001u, 0x002e0045u, 0x10041833u, 0x000000b6u}, + {0x02d2001fu, 0x012d0001u, 0xffc8fff4u, 0x12ff03f6u, 0x0000ff45u}, + {0x03ec0000u, 0x00010001u, 0xffbf0000u, 0x16670002u, 0x0000ff47u}, + {0x022f00dcu, 0x02bd00fdu, 0x02f101d8u, 0x10b70a7cu, 0x00000b41u}, + {0x030d00dfu, 0x034301a9u, 0x04810268u, 0x13c30a92u, 0x00000e94u}, + {0x001606d0u, 0x018a0002u, 0xfff2ff83u, 0x03551d88u, 0x0000fef1u}, + {0x00120724u, 0x016b0011u, 0x00230162u, 0x03011e3bu, 0x000002eeu}, + {0x00981778u, 0x077a01ecu, 0x02240d6fu, 0x08bb36cfu, 0x00000fafu}, + {0x0000164au, 0x002c0472u, 0x001413e8u, 0x0035356au, 0x000017d9u}, + {0x000b03a7u, 0x00cd01bbu, 0x008d0507u, 0x025e15a0u, 0x00000ee1u}, + {0x0006024au, 0x0079020bu, 0x00720454u, 0x01c4111du, 0x0000102eu}, + {0x00690af3u, 0x043b0ae2u, 0x043815d5u, 0x073c2570u, 0x00002552u}, + {0x0005073bu, 0xff430dbbu, 0xfefc13eeu, 0xfe731e6du, 0x000029edu}, + {0x0007023fu, 0xff810000u, 0xfffe0013u, 0xfe2010f3u, 0x00000046u}, + {0x000301f0u, 0xffb30007u, 0xfff70079u, 0xfec70fc0u, 0x000001ecu}, + {0x0004074bu, 0x00a500c6u, 0x003604c0u, 0x01591e8eu, 0x000009f3u}, + {0x001006bau, 0xfeb60121u, 0xff790583u, 0xfd301d57u, 0x00000c06u}, + {0x001f0025u, 0xffbd0084u, 0xff81008bu, 0xfc15044bu, 0x0000081fu}, + {0x000a0010u, 0xffe700b9u, 0xffab006eu, 0xfdca02dbu, 0x0000099du}, + {0x0000012cu, 0xfff40336u, 0xffec03e1u, 0xffc20c3eu, 0x00001446u}, + {0x000700c0u, 0x004b042du, 0x00b1038au, 0x01ea09ccu, 0x00001720u}, + {0x0106034bu, 0x03ac0041u, 0xfefcfe2du, 0x0b741486u, 0x0000fa51u}, + {0x009b02e6u, 0x02a7001bu, 0xff80fee8u, 0x08cf1341u, 0x0000fc5cu}, + {0x00d809cdu, 0x05c0008fu, 0x015f04adu, 0x0a64236cu, 0x00000872u}, + {0x007d07b0u, 0x03e100afu, 0x01280496u, 0x07ea1f5eu, 0x0000095bu}, + {0x00390074u, 0x00a20009u, 0x002e0042u, 0x0552079du, 0x0000022eu}, + {0x00240051u, 0x006c0018u, 0x003b0058u, 0x043d065cu, 0x0000037au}, + {0x007b01abu, 0x01ca030fu, 0x026c0485u, 0x07d60e9du, 0x000013cau}, + {0x009700f3u, 0x017f0359u, 0x02cf0390u, 0x08b00b04u, 0x000014b2u}, + {0x00210022u, 0x0043001cu, 0xffc3ffc3u, 0x040f041cu, 0x0000fc46u}, + {0x00410001u, 0x00110028u, 0xff9bfff2u, 0x05af00c3u, 0x0000fb8au}, + {0x00890135u, 0x019b0081u, 0x010a0190u, 0x08450c6eu, 0x0000080cu}, + {0x00f800c5u, 0x01ba00aau, 0x019b016eu, 0x0b2309efu, 0x00000939u}, + {0x00680182u, 0xfe6f0048u, 0x00adfeb3u, 0x0737f21cu, 0x000005fcu}, + {0x00f00307u, 0xfca20064u, 0x0137fdd2u, 0x0af4ec50u, 0x00000716u}, + {0x009c0002u, 0xffde01bbu, 0x020effc7u, 0x08d7ff0cu, 0x00000ee1u}, + {0x00ed000bu, 0xff99027eu, 0x030aff57u, 0x0ae3fda3u, 0x000011deu}, + {0x061d0ee1u, 0x13140032u, 0x0232036du, 0x1bfa2ba4u, 0x00000505u}, + {0x048c09a1u, 0x0d3c0046u, 0x023b033fu, 0x181f231cu, 0x000005ebu}, + {0x1a0232bdu, 0x48a60219u, 0x0ec614a3u, 0x39b25097u, 0x00001064u}, + {0x0bd435c2u, 0x326e02ecu, 0x0bc21911u, 0x26e952f4u, 0x00001357u}, + {0x03050345u, 0x06490051u, 0x01f6020au, 0x13aa1475u, 0x00000661u}, + {0x042202a4u, 0x069b011eu, 0x044c036fu, 0x17001262u, 0x00000bf5u}, + {0x0ea71210u, 0x208a07fbu, 0x15a11803u, 0x2b4f3015u, 0x00001ff6u}, + {0x09c9075cu, 0x10fa0a0du, 0x13d61134u, 0x23651eb2u, 0x000023deu}, + {0x01770272u, 0x03c90000u, 0xfff3ffefu, 0x0db311b0u, 0x0000ffc4u}, + {0x019a01d1u, 0x03680007u, 0x006a0070u, 0x0e4f0f3eu, 0x000001d8u}, + {0x0245096du, 0x093f00f1u, 0x02ec05f4u, 0x110a22bbu, 0x00000af8u}, + {0x029506c7u, 0x085d00cdu, 0x02e004a9u, 0x122d1d74u, 0x00000a21u}, + {0x0313001bu, 0x012300abu, 0x02de0088u, 0x13d503acu, 0x00000940u}, + {0x03e10000u, 0xffd9004eu, 0x022bfff5u, 0x1648ff8fu, 0x0000063au}, + {0x01f501e9u, 0x03de0355u, 0x051b050cu, 0x0fd40fa5u, 0x000014a5u}, + {0x039a0210u, 0x0574052du, 0x08a3068au, 0x15781041u, 0x000019beu}, + {0x0ac20403u, 0x0d23008bu, 0xfb2bfd0du, 0x251b16a8u, 0x0000f7abu}, + {0x06d40248u, 0x07e5001cu, 0xfe48ff01u, 0x1d911117u, 0x0000fc47u}, + {0x0c900920u, 0x156a0012u, 0x01e00199u, 0x2819222eu, 0x000002feu}, + {0x0704063fu, 0x0d3e001bu, 0x01ba01a1u, 0x1df81c47u, 0x000003afu}, + {0x0ca70064u, 0x04720057u, 0x042500bau, 0x283e0712u, 0x00000697u}, + {0x07a70008u, 0x00fc0043u, 0x02d6002fu, 0x1f4d0203u, 0x000005ccu}, + {0x08d701b0u, 0x07b90364u, 0x0af304c8u, 0x21a40eb1u, 0x000014d4u}, + {0x0ad8005bu, 0x03ef0851u, 0x12fe0372u, 0x254206c2u, 0x000020a0u}, + {0x08b40000u, 0x003100ccu, 0xfabbfff1u, 0x2160005du, 0x0000f5e5u}, + {0x05c10059u, 0x02d60035u, 0xfdd0ff76u, 0x1b2306b0u, 0x0000fad7u}, + {0x04dd019au, 0x0595001eu, 0x018500dfu, 0x18f30e52u, 0x000003e6u}, + {0x03b600d1u, 0x037c0020u, 0x015a00a2u, 0x15cc0a3au, 0x000003f9u}, + {0x0a8600f8u, 0xf99d0006u, 0x0101ffb2u, 0x24b3f4deu, 0x000001c1u}, + {0x0b0f0486u, 0xf1da0091u, 0x0501fcccu, 0x25a0e7efu, 0x00000884u}, + {0x03e20016u, 0xfed901b9u, 0x052cff3bu, 0x164bfcb0u, 0x00000ed8u}, + {0x0729007bu, 0xfc4a0205u, 0x079bfe08u, 0x1e46f828u, 0x00001013u}, + {0x00b5035eu, 0x0315006eu, 0x011a0268u, 0x098114c2u, 0x0000076du}, + {0x0079028du, 0x0233006au, 0x00e3020fu, 0x07ca1211u, 0x0000074cu}, + {0x021a0f3du, 0x0b520598u, 0x06dc1278u, 0x10682c2bu, 0x00001ac3u}, + {0x02c6096bu, 0x0a3906d4u, 0x08b5100au, 0x12d822b9u, 0x00001d91u}, + {0x005f001bu, 0x0064028bu, 0x01f10107u, 0x06e403a5u, 0x00001209u}, + {0x005e0006u, 0x00310409u, 0x026e00a2u, 0x06d701c8u, 0x000016b9u}, + {0x010300d3u, 0x01d308f3u, 0x0603056eu, 0x0b5f0a45u, 0x000021d8u}, + {0x010301a8u, 0x02970f36u, 0x07da0a0au, 0x0b640e90u, 0x00002c20u}, + {0x004f0066u, 0x00b30062u, 0x00af00c8u, 0x06440724u, 0x000006feu}, + {0x0091003au, 0x00b7006eu, 0x00fd009fu, 0x08870560u, 0x00000769u}, + {0x00a50165u, 0x01e60166u, 0x01e602cbu, 0x09180d5cu, 0x00000d5fu}, + {0x00a800c8u, 0x016e01b7u, 0x021f0250u, 0x092c09fdu, 0x00000ecfu}, + {0x0178011bu, 0xfd730312u, 0x0440fc51u, 0x0db8f41bu, 0x000013d3u}, + {0x01da0319u, 0xfb360374u, 0x050ff976u, 0x0f65ec18u, 0x00001506u}, + {0x0044000eu, 0xffc2085eu, 0x02fafea2u, 0x05d1fd54u, 0x000020bau}, + {0x004f00c8u, 0xff040750u, 0x0303fb39u, 0x064ef601u, 0x00001e98u}, + {0x023700bcu, 0x028d0009u, 0xff70ffadu, 0x10d609b3u, 0x0000fddcu}, + {0x01740083u, 0x01b90000u, 0xffe8fff1u, 0x0da20816u, 0x0000ff8du}, + {0x018401edu, 0x036a0076u, 0x01ac01e3u, 0x0ded0fb3u, 0x000007b2u}, + {0x01a10226u, 0x03be00ffu, 0x028d02eeu, 0x0e6f1096u, 0x00000b4du}, + {0x022b012au, 0xfcd300a5u, 0x025cfe45u, 0x10a7f3cdu, 0x00000913u}, + {0x03860125u, 0xfbfb00eeu, 0x039ffdefu, 0x153cf3e3u, 0x00000aebu}, + {0x02c80019u, 0x01080419u, 0x06c00141u, 0x12dd0381u, 0x000016e6u}, + {0x02200009u, 0xff720444u, 0x0605ff36u, 0x107dfdd7u, 0x0000175du}, + {0x05080118u, 0xfb4e001bu, 0x0177ff51u, 0x1961f429u, 0x000003b2u}, + {0x052002c1u, 0xf87c0000u, 0x0007fffbu, 0x199eed3au, 0x00000012u}, + {0x01ba0002u, 0xffc60103u, 0x02a5ffd4u, 0x0edeff07u, 0x00000b63u}, + {0x01eb0004u, 0xffa601dbu, 0x03c5ffa7u, 0x0faafe8fu, 0x00000f68u}, + {0x03e008aau, 0xf46a01fdu, 0x058df7b3u, 0x1645deb3u, 0x00000ff4u}, + {0x05660e73u, 0xee5500c1u, 0x0409f967u, 0x1a4ad4feu, 0x000009d2u}, + {0x0571020du, 0xf95207aeu, 0x0cedf811u, 0x1a64efcdu, 0x00001f5au}, + {0x0a200567u, 0xf1350977u, 0x1394f1b2u, 0x23ffe5b3u, 0x000022cfu}, +}; +static const uint32_t r58_ambe2[128][8] = { + {0x04950580u, 0x03670017u, 0x0165f5f5u, 0xfebaf759u, 0xfee707e5u, 0x1838e577u, 0x14ddfca2u, 0x00000000u}, + {0x08a60eecu, 0x067601afu, 0x0a05e948u, 0xf85fec5du, 0xf9680ef3u, 0x2145d44cu, 0x1cc1f154u, 0x00000000u}, + {0x035a04a2u, 0x00010064u, 0x02aff81fu, 0xfdb8ffacu, 0xffe80047u, 0x14b5e7a7u, 0x00ddf8f2u, 0x00000000u}, + {0x06970c2bu, 0x000202d8u, 0x0bc3ee18u, 0xf758ff75u, 0xffbd0066u, 0x1d0ad889u, 0x00e2ececu, 0x00000000u}, + {0x0c110625u, 0x00dc0006u, 0xff3beec7u, 0x0114fb69u, 0x004a066fu, 0x274de3f4u, 0x0a7a01c1u, 0x00000000u}, + {0x184e10f2u, 0x00d20030u, 0x038cd769u, 0xfbc0f88au, 0xff3808efu, 0x37c7d16du, 0x0a41fb20u, 0x00000000u}, + {0x0aa504beu, 0x00a2004cu, 0x0261f1cau, 0xfc6f0376u, 0x00defad1u, 0x24eae75cu, 0xf702f9d2u, 0x00000000u}, + {0x13240fa5u, 0x02a20182u, 0x09b7dd63u, 0xf5420cd6u, 0x03fcf1ceu, 0x3180d340u, 0xeda5f21cu, 0x00000000u}, + {0x016e1131u, 0x007e071fu, 0xe9e009eau, 0xf99ffa31u, 0x03bdfe53u, 0xf279d117u, 0x07ed1e30u, 0x00000000u}, + {0x000b1e24u, 0x044d04ebu, 0xe7a6fdbfu, 0x00e9e93bu, 0x093200dau, 0x0253c1e3u, 0x17761917u, 0x00000000u}, + {0x006b0a98u, 0x000100d4u, 0xfa150434u, 0xfed4006au, 0xffe20015u, 0xf8b2db2du, 0xff480a49u, 0x00000000u}, + {0x0006143du, 0x005d0038u, 0xfbcbfe94u, 0x0026fa94u, 0x00900031u, 0x01cacd1bu, 0x06d2054au, 0x00000000u}, + {0x006d1bd6u, 0x02a60a0eu, 0xde8b06e0u, 0xfbde112du, 0xf5ae021fu, 0xf8a1c44fu, 0xed9623e0u, 0x00000000u}, + {0x01a830fcu, 0x002f0600u, 0xddb6edfcu, 0x064e05ffu, 0xfde7fee6u, 0x0e8fb0d1u, 0xfb271bb7u, 0x00000000u}, + {0x00010f49u, 0x03e20138u, 0xf760005cu, 0xffe60f68u, 0xfba7002eu, 0xff7bd3c5u, 0xe9b60c7bu, 0x00000000u}, + {0x00ab1e35u, 0x021f001eu, 0xfc41f707u, 0x008e1003u, 0xff02fd9fu, 0x093cc1d1u, 0xef8603dbu, 0x00000000u}, + {0x0f45030bu, 0x04dd0d19u, 0x0ca10da3u, 0x1c4807b2u, 0x0ff6113cu, 0x2c3513bdu, 0x18f328f2u, 0x00000000u}, + {0x16820051u, 0x05ab03e8u, 0x02380554u, 0x12c102adu, 0x09691697u, 0x35ad065bu, 0x1aef165cu, 0x00000000u}, + {0x0bc603b6u, 0x004403a3u, 0x07580d37u, 0x0d1601fcu, 0x01f70388u, 0x26d215cau, 0x05d31593u, 0x00000000u}, + {0x13cf012eu, 0x007600c5u, 0x01e809aau, 0x07cf0179u, 0x01300608u, 0x325b0c48u, 0x07ab09edu, 0x00000000u}, + {0x1cb706a5u, 0x00240fe2u, 0x148c1ba0u, 0x2ab501f1u, 0x03000409u, 0x3ca01d2au, 0x04422d16u, 0x00000000u}, + {0x24c4000cu, 0x00210858u, 0x014502aau, 0x23080028u, 0x0213045bu, 0x449a027cu, 0x041020aeu, 0x00000000u}, + {0x14f506a9u, 0x00f304cfu, 0x0b5117a0u, 0x1413faf8u, 0xfbbaf714u, 0x33cb1d32u, 0xf4f918ceu, 0x00000000u}, + {0x22b70124u, 0x01210154u, 0x02770c97u, 0x0d96fdbau, 0xfd8cf378u, 0x42a90c17u, 0xf3f80d0bu, 0x00000000u}, + {0x0098018eu, 0x00c81493u, 0xf4b1fe14u, 0x06fdfdccu, 0x0804015cu, 0x08b7f1e5u, 0x09ff3352u, 0x00000000u}, + {0x027a01f1u, 0x0063068bu, 0xf8dffb9du, 0x080efe44u, 0x032f01f6u, 0x11cff03cu, 0x070b1cf1u, 0x00000000u}, + {0x00d60055u, 0x00c80907u, 0xfc8afef2u, 0x05800105u, 0xfaaffe62u, 0x0a5af97bu, 0xf5fe21feu, 0x00000000u}, + {0x02190081u, 0x00260256u, 0xfdd4fdf1u, 0x046e008du, 0xfed1fee1u, 0x1063f7f7u, 0xfb9e114cu, 0x00000000u}, + {0x03d702d5u, 0x01931aacu, 0xee9ef968u, 0x143c0439u, 0xf30afb15u, 0x162aecf5u, 0xf1cd3a6du, 0x00000000u}, + {0x077b05e7u, 0x007809a9u, 0xf0e6f2b6u, 0x11010353u, 0xfbbffc41u, 0x1ef2e485u, 0xf841232au, 0x00000000u}, + {0x042500b2u, 0x08730c6fu, 0xfa1dfc9au, 0x0e5b04dbu, 0xeb80f42au, 0x1708f68eu, 0xdf1c27e5u, 0x00000000u}, + {0x04e801c9u, 0x02f203a8u, 0xfae4fa14u, 0x08780496u, 0xf971f867u, 0x190ff0e1u, 0xec9715a1u, 0x00000000u}, + {0x00530153u, 0x001103d8u, 0x04830150u, 0x023cff6au, 0xff00ffb6u, 0xf98ff2fbu, 0x02e2e9d2u, 0x00000000u}, + {0x0017015bu, 0x00c30ab7u, 0x079eff4du, 0xfe08fdf8u, 0xfa4a0086u, 0x0368f2d6u, 0x09dedaf7u, 0x00000000u}, + {0x006e02cau, 0x00540a62u, 0x0ac40230u, 0x043801e9u, 0x03af00c0u, 0xf899ed19u, 0xf988db8bu, 0x00000000u}, + {0x001e039bu, 0x00011a69u, 0x1384feb6u, 0xfc83003eu, 0x00a7fff5u, 0x03d7ea85u, 0xff48c5dcu, 0x00000000u}, + {0x000b007du, 0x00e0028cu, 0x023a004bu, 0x00ac014eu, 0x02fc0065u, 0xfd9df81bu, 0xf56dedf3u, 0x00000000u}, + {0x00710040u, 0x008307ffu, 0x02d1ff56u, 0xfc3e00b7u, 0x040cff0cu, 0x0786fa5du, 0xf7e7e003u, 0x00000000u}, + {0x001c021du, 0x045e060fu, 0x072800f6u, 0x01a20613u, 0x0a4a0162u, 0xfc41ef8fu, 0xe85ce426u, 0x00000000u}, + {0x00bf00c5u, 0x048c124au, 0x0782fe7cu, 0xf89f03beu, 0x123cfc52u, 0x09c3f611u, 0xe7e1cf9eu, 0x00000000u}, + {0x11520c27u, 0x03740034u, 0x03231d04u, 0x03bff30cu, 0xfe54f089u, 0xd0ead890u, 0x1505fae8u, 0x00000000u}, + {0x068c121au, 0x043b070eu, 0x169a15c5u, 0x0d97ee7fu, 0xf513f579u, 0xe30ecfdeu, 0x1746e1f3u, 0x00000000u}, + {0x15f51e4fu, 0x0001017au, 0x0d633398u, 0x0b65007eu, 0x001c006bu, 0xcafcc1b7u, 0xff7ff23eu, 0x00000000u}, + {0x078026fcu, 0x00020d51u, 0x2d912233u, 0x13fdfeceu, 0xff4dff7au, 0xe104b95du, 0x0115d6b8u, 0x00000000u}, + {0x0cb50725u, 0x000a00b0u, 0x046d130fu, 0x05e7010du, 0x00530166u, 0xd7ace1c1u, 0xfdc7f6a2u, 0x00000000u}, + {0x065a0c15u, 0x000c0571u, 0x10381185u, 0x0bc2017du, 0x01000114u, 0xe37dd8acu, 0xfd94e59cu, 0x00000000u}, + {0x109e0f68u, 0x057401acu, 0x0a262000u, 0x0a8a1255u, 0x060a130au, 0xd1e1d398u, 0xe595f160u, 0x00000000u}, + {0x08591642u, 0x061e0b6bu, 0x1fe31b43u, 0x13861756u, 0x10b60e4au, 0xdf50ca9fu, 0xe406d9c5u, 0x00000000u}, + {0x012d04c0u, 0x01aa004cu, 0xfda004bau, 0xfed1fa60u, 0x0168fd34u, 0x0c4518a8u, 0xf167f9d5u, 0x00000000u}, + {0x02eb0101u, 0x02580009u, 0xff9d036cu, 0xff58fcefu, 0x0097fac6u, 0x13530b57u, 0xeeaffdd3u, 0x00000000u}, + {0x00560304u, 0x056e0242u, 0xfac70202u, 0xfe43f7e8u, 0x0701fd4eu, 0x068b13a6u, 0xe5a2eeffu, 0x00000000u}, + {0x04300053u, 0x06b001c2u, 0xfe7d0256u, 0xfa93fd0du, 0x06dcf56bu, 0x17260674u, 0xe2bef0ffu, 0x00000000u}, + {0x02840820u, 0x06770023u, 0x021a090au, 0x012bf181u, 0xfe20f7f0u, 0x11f12040u, 0xe33d042bu, 0x00000000u}, + {0x07400292u, 0x06ef0000u, 0x001608a2u, 0x0025f78fu, 0xffdcf1d3u, 0x1e761224u, 0xe236004du, 0x00000000u}, + {0x01cc04dfu, 0x0f4c005eu, 0xfd5205eau, 0xfe60eebdu, 0x04bff585u, 0x0f2918f7u, 0xd3c0f922u, 0x00000000u}, + {0x0ad50131u, 0x12430149u, 0xfd87072fu, 0xf88af6acu, 0x09b0e3dfu, 0x253d0c59u, 0xcfa7f32du, 0x00000000u}, + {0x09710007u, 0x00980b30u, 0x0119fefeu, 0xeb71ffbfu, 0xfad704bdu, 0xdd3c01dbu, 0xf74725d8u, 0x00000000u}, + {0x027b0016u, 0x012d030cu, 0x0104ff16u, 0xfa80ff5fu, 0xfc37036au, 0xee2e034au, 0xf3bc13bfu, 0x00000000u}, + {0x06ee0154u, 0x01a0037du, 0xfbb30610u, 0xf62c02f0u, 0xfb3d06b7u, 0xe239f2f7u, 0xf1921520u, 0x00000000u}, + {0x019600ceu, 0x025e00aau, 0xfe890242u, 0xfdf202c2u, 0xfd7d03e0u, 0xf1bff5dbu, 0xee98093cu, 0x00000000u}, + {0x044a00efu, 0x07e70baau, 0x0699fc00u, 0xf1dafa92u, 0xeccd0ba5u, 0xe8920aeeu, 0xe03326a4u, 0x00000000u}, + {0x00cb0070u, 0x069d02a1u, 0x0225fed2u, 0xfd1cfc99u, 0xf7a90496u, 0xf5ea077bu, 0xe2e71259u, 0x00000000u}, + {0x05050052u, 0x09d902dau, 0xfe15028bu, 0xf86f0390u, 0xf5670e0fu, 0xe6a7f994u, 0xdc80131au, 0x00000000u}, + {0x00a70080u, 0x0a860039u, 0xff550124u, 0xff3d0495u, 0xfcf0053eu, 0xf6dbf802u, 0xdb4c0558u, 0x00000000u}, + {0x03f500d8u, 0x04950141u, 0xfdf103a8u, 0xfb8b03f0u, 0xfb340884u, 0x16810a67u, 0x1838f354u, 0x00000000u}, + {0x081e005fu, 0x0a29057bu, 0xfd280377u, 0xf2a903e0u, 0xf113122bu, 0x203d06e0u, 0x2411e584u, 0x00000000u}, + {0x063702e5u, 0x025206cbu, 0xf723087bu, 0xf301052fu, 0xf80f0799u, 0x1c35133eu, 0x113de284u, 0x00000000u}, + {0x0da300b0u, 0x0582123eu, 0xf8eb0620u, 0xe07503e4u, 0xebf31155u, 0x29c70961u, 0x1a8ecfadu, 0x00000000u}, + {0x04a20068u, 0x006d0174u, 0xfe7702bfu, 0xfad000d5u, 0xfe6d02d1u, 0x185a0737u, 0x0766f25eu, 0x00000000u}, + {0x0b3f0001u, 0x011804b9u, 0xffc6005au, 0xf16d001cu, 0xfb750703u, 0x25f10097u, 0x0bd3e76au, 0x00000000u}, + {0x09b202acu, 0x000004afu, 0xf8ed0a2du, 0xf2870019u, 0xffde0030u, 0x2339127du, 0x0058e785u, 0x00000000u}, + {0x191e0091u, 0x00130bdcu, 0xfacf078eu, 0xdd7b006au, 0xfe1c02c0u, 0x38b30887u, 0x031bd909u, 0x00000000u}, + {0x03b50002u, 0x06a300e6u, 0x0026ffb3u, 0xfc5a0067u, 0x04e1f614u, 0xea3600e3u, 0x1d240ab7u, 0x00000000u}, + {0x010800d8u, 0x100b0074u, 0xfec301deu, 0xfea2f8a4u, 0x0564f7ddu, 0xf483f59bu, 0x2d51079du, 0x00000000u}, + {0x01830011u, 0x031a0014u, 0xffdbff5eu, 0x00b100e9u, 0xff03fbacu, 0xf21802ebu, 0x13ecfcd2u, 0x00000000u}, + {0x007d00ecu, 0x07bd009fu, 0x01830158u, 0x011bfaa9u, 0xfb9dfc1bu, 0xf815f524u, 0x1f79f714u, 0x00000000u}, + {0x01120001u, 0x018b0150u, 0xffe3001au, 0xfda1ffe0u, 0x02d9fd6eu, 0xf44dff6fu, 0x0e0d0cf7u, 0x00000000u}, + {0x002200e4u, 0x0557012eu, 0xfdf300b0u, 0xff35fba3u, 0x0505fe51u, 0xfbe0f551u, 0x1a250c4au, 0x00000000u}, + {0x0041001au, 0x006e0000u, 0x0006ffafu, 0xfff7006au, 0x000cff57u, 0xfa510393u, 0x076c006au, 0x00000000u}, + {0x00010078u, 0x02300002u, 0x00230010u, 0x0002fdfau, 0xffb5ffddu, 0xff7af844u, 0x10bafee2u, 0x00000000u}, + {0x01182dcau, 0x029102fbu, 0x175f0e2bu, 0x039e15adu, 0x0588035au, 0x0bd84c8eu, 0x121f138au, 0x00000000u}, + {0x04f6200au, 0x09ad0015u, 0x033a1937u, 0x01452338u, 0x01c60ddcu, 0x1933400au, 0x23320339u, 0x00000000u}, + {0x04a72114u, 0x0002002eu, 0x04e118ceu, 0x01d4011eu, 0x0015006bu, 0x18664111u, 0x011904cdu, 0x00000000u}, + {0x0ad91888u, 0x027e00a2u, 0xf81e20a0u, 0xfac20fa4u, 0xfd7d0a67u, 0x25433809u, 0x11ddf700u, 0x00000000u}, + {0x05442f28u, 0x00160978u, 0x2a431f85u, 0x0e20fbeeu, 0xfe2dfea4u, 0x19f74db1u, 0xfca622d1u, 0x00000000u}, + {0x0df62365u, 0x02a2030eu, 0x14cb2c75u, 0x0d0f134fu, 0x05ac0c21u, 0x2a46434fu, 0x125c13c6u, 0x00000000u}, + {0x0ed93438u, 0x02ab0186u, 0x11d737b0u, 0x0983e863u, 0xfbf7f369u, 0x2b9851c1u, 0xed840df7u, 0x00000000u}, + {0x1b5d2627u, 0x0012001bu, 0xfbf440a0u, 0xfc930344u, 0xffd402c4u, 0x3b2f45e2u, 0x02fefc4cu, 0x00000000u}, + {0x005d0936u, 0x063a0d56u, 0x162afc56u, 0xfb970f26u, 0x123afcfcu, 0xf92b2255u, 0x1c3c2952u, 0x00000000u}, + {0x005c0529u, 0x08b703cfu, 0x08dd02bau, 0x02570d69u, 0x0b86038bu, 0x06ca19b2u, 0x21671614u, 0x00000000u}, + {0x00000ab9u, 0x01040480u, 0x0de5ffdeu, 0xffea0699u, 0x0446fff6u, 0xffc5250cu, 0x0b651801u, 0x00000000u}, + {0x004006c4u, 0x027400a9u, 0x0439029bu, 0x00d00825u, 0x028b0192u, 0x05ab1d6du, 0x11b7092fu, 0x00000000u}, + {0x001007a1u, 0x00441308u, 0x18190161u, 0x022e02d9u, 0x04800042u, 0x02d41f3fu, 0x05d6315cu, 0x00000000u}, + {0x005a033cu, 0x01a30719u, 0x09950221u, 0x0327049bu, 0x06d20184u, 0x06b21459u, 0x0e7b1e23u, 0x00000000u}, + {0x006207f4u, 0x005407beu, 0x0fb1037fu, 0x0373fcc3u, 0xfcceff4au, 0x07031fe8u, 0xf9811f7au, 0x00000000u}, + {0x00620436u, 0x00160220u, 0x05fd028bu, 0x01ce0137u, 0x00dd005eu, 0x07011739u, 0x03581080u, 0x00000000u}, + {0x018f0d12u, 0x0bc40434u, 0xf12df6f8u, 0x051f18ceu, 0xf1f0f76eu, 0xf1de28e7u, 0x26cfe8cfu, 0x00000000u}, + {0x00b503aau, 0x07570838u, 0xf507fcc7u, 0x04d40a5fu, 0xf077fb70u, 0xf67a15a7u, 0x1ea7df91u, 0x00000000u}, + {0x052412f8u, 0x058e0d73u, 0xe00eec40u, 0x10a11487u, 0xeeb7f550u, 0xe65a3147u, 0x1aa9d683u, 0x00000000u}, + {0x011906b9u, 0x052018aeu, 0xe63efa92u, 0x0a670bbeu, 0xe981fb42u, 0xf4281d55u, 0x199ec7ccu, 0x00000000u}, + {0x000d0c00u, 0x026a03cfu, 0xf27afe6au, 0x00e50ac3u, 0xf9f0ff4au, 0xfd682730u, 0x1193e9eau, 0x00000000u}, + {0x000e03fcu, 0x01190559u, 0xf6c5ff0du, 0x011a042eu, 0xfb28ff80u, 0xfd4f1694u, 0x0bd9e5d6u, 0x00000000u}, + {0x01af0ddbu, 0x004c090au, 0xe99ff658u, 0x07cd040fu, 0xfcb9fe96u, 0xf1532a1cu, 0x062bddfdu, 0x00000000u}, + {0x001a0621u, 0x00370ebau, 0xecfffe6eu, 0x026e0249u, 0xfc75ffb5u, 0xfc6b1c03u, 0x053ad495u, 0x00000000u}, + {0x166700c9u, 0x03f600a9u, 0xfe90f79cu, 0x07af0387u, 0xfcc5ed2au, 0xca740a08u, 0x1684f6d1u, 0x00000000u}, + {0x102c0015u, 0x02c108a7u, 0xfe4cfdacu, 0x17a800f6u, 0xf63cf2a6u, 0xd2810346u, 0x12c8deb9u, 0x00000000u}, + {0x21bd010du, 0x000203fbu, 0xfbeaf41au, 0x172e0032u, 0xff9ffee5u, 0xbe490b96u, 0x0114e96du, 0x00000000u}, + {0x1b5e0004u, 0x000112cfu, 0x010b0142u, 0x2d610004u, 0x0084009fu, 0xc4d0fea4u, 0xff54ceefu, 0x00000000u}, + {0x0c0500bdu, 0x0001010eu, 0xfe3dfa0bu, 0x071e0021u, 0xffd8ff7bu, 0xd8c609b8u, 0x00daf463u, 0x00000000u}, + {0x0830007cu, 0x000e06afu, 0xfc65fc03u, 0x0eccffacu, 0x01380159u, 0xdfa107e3u, 0xfd56e2bfu, 0x00000000u}, + {0x115d00ffu, 0x03100364u, 0xfc52f7aeu, 0x0f59fc81u, 0x06720e95u, 0xd0dc0b4cu, 0xec33eb29u, 0x00000000u}, + {0x0caf0070u, 0x04210f26u, 0xfadbfb4bu, 0x1bb9fd50u, 0x0fd20e7au, 0xd7b5077au, 0xe902d3f7u, 0x00000000u}, + {0x00f54f49u, 0x0000065au, 0xd320ee95u, 0x04eeffb4u, 0x00160008u, 0xf4ef64beu, 0xffd0e37eu, 0x00000000u}, + {0x002f2aefu, 0x000007c4u, 0xdb7c059du, 0xfd9d0036u, 0xffe90004u, 0x04d84a22u, 0x002fe07au, 0x00000000u}, + {0x01d43198u, 0x036a1446u, 0xc096ecf6u, 0x0c2ce5f9u, 0x10a404ffu, 0xf0b54fadu, 0xeb18cd10u, 0x00000000u}, + {0x01692241u, 0x00a016feu, 0xc7df0de8u, 0xf49bf6c0u, 0x0794fe1fu, 0x0d714237u, 0xf70fc9c0u, 0x00000000u}, + {0x00112e4bu, 0x03d90393u, 0xe6470381u, 0xff07e54fu, 0x076afefdu, 0x02ea4cfau, 0xe9cfea9du, 0x00000000u}, + {0x017c1790u, 0x01e8053eu, 0xe9c50bd6u, 0xfa6bf299u, 0x0653fca2u, 0x0dcb36ebu, 0xf061e618u, 0x00000000u}, + {0x006a20e2u, 0x0da90c95u, 0xd7520765u, 0xfb6dd59du, 0x1a38fb3cu, 0x074c40e0u, 0xd62fd7dfu, 0x00000000u}, + {0x06a4144du, 0x05630e25u, 0xde1b1738u, 0xec9eeb15u, 0x1176f40au, 0x1d2732fau, 0xe5bdd573u, 0x00000000u}, + {0x0df61fc7u, 0x0160006eu, 0x0761d5dfu, 0xfb1c0d39u, 0x0189f73cu, 0xd5ba3fc7u, 0x0d450767u, 0x00000000u}, + {0x07d60c88u, 0x00f30026u, 0x02bbec2fu, 0xfdd706e5u, 0x00c0fa8cu, 0xe055280cu, 0x0b05045eu, 0x00000000u}, + {0x0540179du, 0x00380004u, 0xfec6e9bcu, 0x0094fb72u, 0x001e0225u, 0xe61536fbu, 0xfab3fe92u, 0x00000000u}, + {0x02a90a1du, 0x0010001eu, 0xfdd5f5a1u, 0x011dfe65u, 0x002c00d3u, 0xed8d23fbu, 0xfd24fc25u, 0x00000000u}, + {0x0bd61defu, 0x012005ccu, 0x1a58da5bu, 0xef6ff466u, 0xfae5074cu, 0xd9133de6u, 0xf4011b3du, 0x00000000u}, + {0x08e80a5fu, 0x005c017fu, 0x07e1ecc7u, 0xf8b2fc24u, 0xfe890394u, 0xde3c246fu, 0xf9380dd8u, 0x00000000u}, + {0x03cc15d7u, 0x04e1011du, 0x09ddedcau, 0xfbe3eb5bu, 0xfb57089cu, 0xe9f434dfu, 0xe7030bf1u, 0x00000000u}, + {0x036f089fu, 0x02be0003u, 0x00a0f51fu, 0xff9bf647u, 0xffa60622u, 0xeb0a2138u, 0xed450134u, 0x00000000u}, +}; +const xombe_cq_q15_tab xombe__cq_q15_ambe2 = { + r24_ambe2, r58_ambe2, 13, 14, 17, 16, + {2.61071777f, 0.91809082f, 0.475341797f, 2.27026367f, 1.21838379f, 1.24145508f}, {1.61578369f, 0.958190918f, + 0.689453125f}, {0.154853821f, 0.0718078613f, 0.0520935059f, 0.0356674194f, 0.126220703f, 0.123855591f, + 0.0827865601f, 0.0886306763f, 0.05493927f, 0.0512084961f}, {0.39352417f, 0.267974854f, 0.228225708f, + 0.188858032f}, 2.785815f, 0.169128761f, 128, {4.13683701f, 1.62223196f, -1.47773695f, -0.102371953f}, + {{2.84134197f, 0.272371352f, -0.171895787f, 0.0128391804f}, {0.272371352f, 1.71811736f, 0.285478443f, + 0.033373341f}, {-0.171895787f, 0.285478443f, 1.42351925f, -0.00304957479f}, {0.0128391804f, 0.033373341f, + -0.00304957479f, 0.759661198f}}}; +#if XOMBE_HAVE_DSTAR +static const uint32_t r24_dstar[512][5] = { + {0x024921d6u, 0x119509c4u, 0x0972245cu, 0xeee6be30u, 0x0000dca4u}, + {0x04c50f9du, 0x11410474u, 0x093710adu, 0xe74cd34cu, 0x0000e820u}, + {0x0411061cu, 0x09f902b1u, 0x069e081du, 0xe92ee409u, 0x0000ed70u}, + {0x0b050463u, 0x0de80691u, 0x11040abcu, 0xda71e84fu, 0x0000e302u}, + {0x00cf1d5au, 0x09c00112u, 0x01dc0b34u, 0xf5d2c2b5u, 0x0000f44du}, + {0x0ba70bb1u, 0x1758006fu, 0x047d047fu, 0xd961d951u, 0x0000f890u}, + {0x01130862u, 0x05ff013du, 0x024e0671u, 0xf448df3eu, 0x0000f36au}, + {0x05a1045au, 0x09e6010au, 0x04d70442u, 0xe529e867u, 0x0000f475u}, + {0x0eeb1e60u, 0x2a920033u, 0x036f04e7u, 0xd44ec1a5u, 0x0000faf8u}, + {0x02750b7du, 0x0aa00017u, 0x00ef0205u, 0xee45d9a7u, 0x0000fca0u}, + {0x110c04e8u, 0x124a0002u, 0x00c6006au, 0xd14ae6f1u, 0x0000fef1u}, + {0x032e04e9u, 0x07e7001au, 0x01200166u, 0xebd5e6edu, 0x0000fc6eu}, + {0x01890c70u, 0x08bc0137u, 0xfd46f83bu, 0xf1fed819u, 0x00000c76u}, + {0x06df04c3u, 0x0b710406u, 0xf57cf73fu, 0xe257e750u, 0x000016b1u}, + {0x0491047au, 0x090a0024u, 0xfe64fe68u, 0xe7d4e811u, 0x00000444u}, + {0x010d02fdu, 0x038c0000u, 0xffebffddu, 0xf466ec71u, 0x00000072u}, + {0x01370c9fu, 0x07d500f9u, 0x022c0701u, 0xf387d7cfu, 0x0000f4d9u}, + {0x001c06c6u, 0x01ba01d7u, 0x00e70710u, 0xfc3fe28fu, 0x0000f0a7u}, + {0x00800910u, 0x0440069du, 0x03a10f7bu, 0xf803ddf2u, 0x0000e2e9u}, + {0x002b03b3u, 0x0192034du, 0x017c06fdu, 0xfb62ea3du, 0x0000eb72u}, + {0x00fe0975u, 0x06210010u, 0x007e0185u, 0xf4b9dd35u, 0x0000fd34u}, + {0x0145049au, 0x04d5001du, 0x00c10170u, 0xf342e7bcu, 0x0000fc36u}, + {0x007f0486u, 0x03000112u, 0x01760467u, 0xf804e7f1u, 0x0000f44au}, + {0x011d037cu, 0x03f0008bu, 0x018d02bfu, 0xf412eae2u, 0x0000f7acu}, + {0x000108deu, 0xff950075u, 0x0018fbf8u, 0x00cbde4fu, 0x000007a8u}, + {0x000105a2u, 0xffc9001du, 0x0008fe68u, 0x0083e526u, 0x000003cbu}, + {0x008b02ffu, 0x028e0066u, 0xff12fdd2u, 0xf7a7ec6au, 0x00000721u}, + {0x00200313u, 0x013d0000u, 0x00070024u, 0xfc01ec2au, 0x0000ff8du}, + {0x001c1732u, 0x032c008cu, 0xff83f8e0u, 0xfc47c983u, 0x0000085eu}, + {0x005b1056u, 0x04cf04ffu, 0xfd57edeeu, 0xf946d246u, 0x0000194bu}, + {0x00150589u, 0x015b0270u, 0xff1af8a8u, 0xfcbee562u, 0x000011a8u}, + {0x0014035cu, 0x01050b93u, 0xfe1cf387u, 0xfcdceb42u, 0x0000267du}, + {0x001a1961u, 0xfcc40310u, 0xfee011a2u, 0x03a2c701u, 0x0000ec33u}, + {0x00940852u, 0xfb9c052fu, 0xfc880d23u, 0x089ddf5fu, 0x0000e63du}, + {0x00360313u, 0xfe65020bu, 0xfeb10503u, 0x052cec2au, 0x0000efd3u}, + {0x00010408u, 0x00300344u, 0x002b0741u, 0xff79e94au, 0x0000eb8fu}, + {0x00500e4cu, 0xfbc70147u, 0xfebd088bu, 0x0651d538u, 0x0000f339u}, + {0x002b0679u, 0xfde9002bu, 0xffaa0214u, 0x04a5e337u, 0x0000fb61u}, + {0x009e04f9u, 0xfc80008cu, 0xfed7034cu, 0x08e0e6c4u, 0x0000f7a2u}, + {0x0027031bu, 0xfe9e0099u, 0xff6502bau, 0x046fec11u, 0x0000f73eu}, + {0x00070f77u, 0xfeb6001eu, 0xffe302b3u, 0x01dad382u, 0x0000fc1eu}, + {0x012106ecu, 0xfa69001eu, 0x00bafe34u, 0x0c05e23cu, 0x000003deu}, + {0x001f0347u, 0xfebf0000u, 0x0000fffeu, 0x03ebeb85u, 0x00000007u}, + {0x0000023du, 0x0010005fu, 0xfffafe2cu, 0xffc5ef11u, 0x000006e8u}, + {0x004b349fu, 0xf824032fu, 0x01efe61cu, 0x0621adeeu, 0x00001430u}, + {0x007c0899u, 0xfbed01e0u, 0x01e7f7f9u, 0x07dcded4u, 0x00000f7du}, + {0x002e04b6u, 0xfe2b04bdu, 0x01d7f68du, 0x04c7e772u, 0x000018a1u}, + {0x00ab02b1u, 0xfd530047u, 0x00dcfe47u, 0x093ced72u, 0x000005f2u}, + {0x0161316bu, 0xef7b01c3u, 0xfce112aau, 0x0d4bb078u, 0x0000f0fbu}, + {0x06fa0e8fu, 0xebd8049bu, 0xf4aa1061u, 0x1de2d4d4u, 0x0000e7b8u}, + {0x02b909dbu, 0xf5a30255u, 0xfaf60996u, 0x12acdc7cu, 0x0000eeb9u}, + {0x0490037au, 0xf8090a9fu, 0xf2140c27u, 0x182aeae7u, 0x0000db21u}, + {0x05d314d1u, 0xe9fc0048u, 0xfd7104d7u, 0x1b4dcc62u, 0x0000fa00u}, + {0x01210c66u, 0xf884002cu, 0xff1f02e9u, 0x0c07d82au, 0x0000fb53u}, + {0x03f408a1u, 0xf451004bu, 0xfdd9032du, 0x1680dec3u, 0x0000f9e2u}, + {0x041d054au, 0xf6ab0248u, 0xf9e006f2u, 0x16f2e5fau, 0x0000eeebu}, + {0x00f51510u, 0xf7030168u, 0x0253f51du, 0x0b14cc13u, 0x00000d6bu}, + {0x0d7b0a36u, 0xe889000cu, 0x019cfe99u, 0x298adbd9u, 0x0000027cu}, + {0x03cd0733u, 0xf58a0069u, 0x027ffc90u, 0x160fe1a4u, 0x0000073fu}, + {0x02c002afu, 0xfa910013u, 0x00e7ff1cu, 0x12c4ed78u, 0x00000315u}, + {0x0299084eu, 0xf6b60dacu, 0x0bebeab1u, 0x123cdf66u, 0x000029d5u}, + {0x01d10419u, 0xfa8b033du, 0x04daf8b6u, 0x0f3ee918u, 0x0000145du}, + {0x08c502a2u, 0xf66407c5u, 0x1083f6f4u, 0x2181eda5u, 0x00001f8au}, + {0x077a02d4u, 0xf6cd0240u, 0x0834faf4u, 0x1eefecf8u, 0x000010f9u}, + {0x057801eeu, 0x067f03a4u, 0x08ed054du, 0xe58af049u, 0x0000ea69u}, + {0x01f30226u, 0x041702c6u, 0x04a604e1u, 0xf036ef6cu, 0x0000ed29u}, + {0x0a30025cu, 0x09cd01fbu, 0x08fd0453u, 0xdbe4eea1u, 0x0000f012u}, + {0x07520089u, 0x03f601aau, 0x06fa01e3u, 0xe164f7b8u, 0x0000f169u}, + {0x048c0211u, 0x06220066u, 0x02b301d2u, 0xe7dfefbdu, 0x0000f8d8u}, + {0x02f900e7u, 0x03470138u, 0x03ce0219u, 0xec7ef53eu, 0x0000f383u}, + {0x01e0008fu, 0x020b01e0u, 0x03c0020cu, 0xf083f78eu, 0x0000f080u}, + {0x014b0026u, 0x00e00088u, 0x01a80090u, 0xf321fba4u, 0x0000f7c2u}, + {0x01120114u, 0x02260021u, 0x00be00bfu, 0xf44bf43fu, 0x0000fbf0u}, + {0x066300f1u, 0x04e60002u, 0xff9cffdau, 0xe369f508u, 0x000000dfu}, + {0x04d20092u, 0x03520026u, 0x01b40096u, 0xe728f773u, 0x0000fb9du}, + {0x01d80026u, 0x010d0000u, 0x00020001u, 0xf0a1fba0u, 0x0000fff6u}, + {0x03000256u, 0x054c01ddu, 0xfb45fbd4u, 0xec67eeb4u, 0x00000f72u}, + {0x021f011cu, 0x03110077u, 0xfe04fe91u, 0xef86f417u, 0x000007b5u}, + {0x01d600c8u, 0x02660003u, 0xffb3ffceu, 0xf0acf5feu, 0x00000142u}, + {0x0a4d0040u, 0x033700e2u, 0xf9f7ff0fu, 0xdbb0fa56u, 0x00000aa3u}, + {0x0016012fu, 0x00a401e5u, 0x00cf02ffu, 0xfcabf3afu, 0x0000f06eu}, + {0x002400a3u, 0x00980133u, 0x00d101bfu, 0xfbc7f6f9u, 0x0000f39cu}, + {0x00000012u, 0x000002c0u, 0x000100dfu, 0xfffdfd06u, 0x0000ed3fu}, + {0x0000001au, 0x000213eeu, 0x001d02dbu, 0xffdbfc62u, 0x0000cd7eu}, + {0x008f020du, 0x0224001fu, 0x008500ffu, 0xf78befccu, 0x0000fc0fu}, + {0x002001dbu, 0x00f500adu, 0x0094023du, 0xfc06f098u, 0x0000f6b2u}, + {0x00000155u, 0x000b002bu, 0x000400f3u, 0xffc9f2f0u, 0x0000fb59u}, + {0x00230083u, 0x00880025u, 0x0049008cu, 0xfbcaf7e6u, 0x0000fbb2u}, + {0x00000126u, 0x00090084u, 0xfffafe76u, 0xffd2f3e1u, 0x00000820u}, + {0x001c011fu, 0x00b5001au, 0xffc9ff52u, 0xfc3bf403u, 0x000003a3u}, + {0x00860066u, 0x00ea0087u, 0xfef3ff16u, 0xf7cdf8ddu, 0x00000836u}, + {0x00f6004cu, 0x01110022u, 0xff49ff9bu, 0xf4e7f9d7u, 0x0000041fu}, + {0x000b012fu, 0x00740603u, 0xfefbfaaau, 0xfda7f3b1u, 0x00001bbdu}, + {0x004f0125u, 0x0130011eu, 0xfed3fdbdu, 0xf9b6f3e7u, 0x00000bf6u}, + {0x0000007cu, 0xfff20131u, 0x0017fe7bu, 0x0075f822u, 0x00000c5bu}, + {0x00010028u, 0xfff703fbu, 0x002dfe6au, 0x0081fb81u, 0x00001693u}, + {0x00010122u, 0xffe600f2u, 0xffe80212u, 0x008cf3f5u, 0x0000f500u}, + {0x00910111u, 0xfe72006eu, 0xff04015au, 0x0885f452u, 0x0000f89au}, + {0x00bd0100u, 0xfe480144u, 0xfe110240u, 0x09baf4afu, 0x0000f344u}, + {0x00790093u, 0xfef50509u, 0xfce90368u, 0x07c9f76au, 0x0000e69du}, + {0x012c0228u, 0xfcd30000u, 0xfff8000au, 0x0c3def64u, 0x0000ffd8u}, + {0x000000b2u, 0x0004008au, 0x00030139u, 0xffe8f693u, 0x0000f7b0u}, + {0x0000001du, 0xfffc0020u, 0xfffc003du, 0x003efc34u, 0x0000fc00u}, + {0x00790022u, 0xff80001fu, 0xff850041u, 0x07c4fbe3u, 0x0000fc09u}, + {0x004f0150u, 0xfebb008du, 0x00d3fe4cu, 0x0646f309u, 0x00000868u}, + {0x001e0127u, 0xff430001u, 0xfff7001du, 0x03e5f3ddu, 0x0000ff6au}, + {0x007b005bu, 0xff2c0020u, 0x007dff94u, 0x07dbf941u, 0x000003fdu}, + {0x00000020u, 0x00000000u, 0x00000005u, 0x0003fc04u, 0x0000ffabu}, + {0x001601efu, 0xff30020cu, 0x00d6fc05u, 0x034df043u, 0x0000102fu}, + {0x007e0090u, 0xfef30310u, 0x0275fd61u, 0x07f1f788u, 0x000013ceu}, + {0x00b80046u, 0xff1d0095u, 0x014cff33u, 0x0997fa13u, 0x000008a4u}, + {0x00000022u, 0xfffe007au, 0x0004ff7fu, 0x0023fbdcu, 0x000007ceu}, + {0x020001f8u, 0xfc080133u, 0xfce70312u, 0x1000f022u, 0x0000f39cu}, + {0x0fe10125u, 0xf7780159u, 0xf6bf027cu, 0x2d15f3e3u, 0x0000f2ddu}, + {0x025100acu, 0xfd82008au, 0xfdc40134u, 0x1137f6bdu, 0x0000f7b1u}, + {0x044b001au, 0xfeaf03b6u, 0xf8040139u, 0x1772fc68u, 0x0000ea35u}, + {0x016500e5u, 0xfdc50017u, 0xff4c0090u, 0x0d5af550u, 0x0000fca2u}, + {0x05d600f7u, 0xfb410035u, 0xfdcc00e5u, 0x1b56f4e4u, 0x0000fad8u}, + {0x04730098u, 0xfcbf0019u, 0x0153ff84u, 0x17def746u, 0x0000038eu}, + {0x08a20014u, 0xfe600001u, 0xffad0008u, 0x213dfcdeu, 0x0000ff60u}, + {0x020201eeu, 0xfc1000fbu, 0x02cffd3fu, 0x1009f047u, 0x00000b36u}, + {0x0a5a00a2u, 0xfae001d1u, 0x08acfddbu, 0x2467f6feu, 0x00000f3fu}, + {0x05a700b9u, 0xfbf60063u, 0x02f6fef1u, 0x1ae6f664u, 0x0000070cu}, + {0x0304002eu, 0xfe88006fu, 0x0249ff71u, 0x13a5fb37u, 0x00000773u}, + {0x0112028eu, 0xfcb20673u, 0x0540f7e2u, 0x0bb2edebu, 0x00001cbbu}, + {0x020c010cu, 0xfd1202c7u, 0x04c5fc97u, 0x1031f46du, 0x000012dcu}, + {0x03220030u, 0xfe7601e0u, 0x04d9fecfu, 0x1406fb15u, 0x00000f80u}, + {0x054f000eu, 0xfef00982u, 0x0e36fe94u, 0x1a12fd65u, 0x000022e2u}, + {0x040f0028u, 0x019701d0u, 0x056c0110u, 0xe935fb88u, 0x0000f0c7u}, + {0x01f60008u, 0xff7f03ccu, 0x0576ff4cu, 0xf0270209u, 0x0000e9f3u}, + {0x023e0038u, 0xfe9a02b4u, 0x04ecfe77u, 0xef0f0549u, 0x0000ed67u}, + {0x03640019u, 0xfedc0219u, 0x0556ff1au, 0xeb2b0382u, 0x0000ef9du}, + {0x034d0001u, 0x003c00aau, 0x02f6001bu, 0xeb72ff46u, 0x0000f6c8u}, + {0x021a0001u, 0x0025001fu, 0x01010009u, 0xef98ff70u, 0x0000fc14u}, + {0x09050000u, 0x001800a9u, 0x04e10007u, 0xde06ffd2u, 0x0000f6cfu}, + {0x022b000au, 0xff6e012eu, 0x0332ff94u, 0xef590231u, 0x0000f3b7u}, + {0x05960001u, 0xffc10000u, 0x00060000u, 0xe5420097u, 0x0000fff1u}, + {0x02150000u, 0x00170000u, 0xfffd0000u, 0xefafffa6u, 0x0000000bu}, + {0x012c0000u, 0xffe9001cu, 0xff4a0007u, 0xf3c00077u, 0x000003b9u}, + {0x05270019u, 0xfe970003u, 0x0078fff0u, 0xe6520384u, 0x0000fed4u}, + {0x011a0027u, 0x00d1006cu, 0xfea3ff7eu, 0xf420fb97u, 0x0000075bu}, + {0x0461000du, 0x00f30027u, 0xfe60ffd3u, 0xe852fd6fu, 0x00000465u}, + {0x027d0002u, 0x004a0131u, 0xfc8fffcdu, 0xee27fef5u, 0x00000c58u}, + {0x03070002u, 0xffb8006cu, 0xfdbd001bu, 0xec4f00eau, 0x00000759u}, + {0x0071001fu, 0x007501d4u, 0x01cb00efu, 0xf87dfc18u, 0x0000f0b5u}, + {0x00670002u, 0x001d082au, 0x03a10084u, 0xf8d0fefbu, 0x0000dfadu}, + {0x00220003u, 0x00130202u, 0x0109004bu, 0xfbdffed3u, 0x0000eff7u}, + {0x01380018u, 0xff520131u, 0x0269ff54u, 0xf382037du, 0x0000f3a8u}, + {0x007f0026u, 0x008b001cu, 0x00780042u, 0xf806fba1u, 0x0000fc3fu}, + {0x0118001bu, 0x00ac0000u, 0xfff6fffdu, 0xf42dfc5bu, 0x00000034u}, + {0x00910000u, 0x000e0080u, 0x0110000eu, 0xf77fff94u, 0x0000f7ffu}, + {0x01450000u, 0x00000085u, 0x01a00000u, 0xf3420000u, 0x0000f7d9u}, + {0x00240024u, 0x0048007au, 0xff7cff7cu, 0xfbc1fbc5u, 0x000007ccu}, + {0x00790000u, 0x00020000u, 0x00050000u, 0xf839fff2u, 0x0000ffd6u}, + {0x001e001eu, 0xffc50000u, 0x0001ffffu, 0xfc2803dcu, 0x0000fff3u}, + {0x0091001cu, 0xff820000u, 0x0003ffffu, 0xf77f03b7u, 0x0000ffeau}, + {0x006e0015u, 0x00600613u, 0xfcc4fe99u, 0xf894fcc8u, 0x00001be3u}, + {0x00180000u, 0x00040224u, 0xff1affedu, 0xfc88ffb5u, 0x0000108eu}, + {0x00990000u, 0xfffb0104u, 0xfe720007u, 0xf7440025u, 0x00000b66u}, + {0x01410024u, 0xff28034eu, 0xfbee015eu, 0xf3550441u, 0x00001493u}, + {0x002c0027u, 0xffad0129u, 0xff1b00d7u, 0x04b3fb98u, 0x0000f3ceu}, + {0x0000002bu, 0x00010088u, 0x00020099u, 0xfff2fb5du, 0x0000f7c0u}, + {0x00240026u, 0x004a0084u, 0xff76ff73u, 0x0441045au, 0x0000f7dfu}, + {0x0025000eu, 0x002e0367u, 0xfe9aff22u, 0x044902aau, 0x0000eb22u}, + {0x00270000u, 0x00000022u, 0xffb70000u, 0x04660006u, 0x0000fbdcu}, + {0x00000000u, 0x00000000u, 0x00000000u, 0xfff4ffe6u, 0x0000fff4u}, + {0x0000001eu, 0xfffe007eu, 0x0003ff85u, 0xffe503e2u, 0x0000f811u}, + {0x00990012u, 0x0068009fu, 0xfec8ff96u, 0x08c002f9u, 0x0000f717u}, + {0x00260000u, 0x00000080u, 0x008a0000u, 0x0455fffdu, 0x000007feu}, + {0x008e0000u, 0xffff001cu, 0x007effffu, 0x086cfff6u, 0x000003bdu}, + {0x0000001bu, 0x0003007du, 0x00060075u, 0x003003b4u, 0x000007e4u}, + {0x00220026u, 0x00480000u, 0x00010001u, 0x041b0462u, 0x0000000au}, + {0x000b001eu, 0xffdb011cu, 0x0072ff48u, 0x0266fc21u, 0x00000be8u}, + {0x00210037u, 0xffaa0688u, 0x01d8fda0u, 0x0416fabeu, 0x00001ce9u}, + {0x003f0000u, 0x0005020fu, 0x016e000eu, 0x05a10037u, 0x0000103cu}, + {0x006d001du, 0x00700130u, 0x016c00bbu, 0x076303cbu, 0x00000c54u}, + {0x021e0000u, 0x000a0202u, 0xfbe1fff7u, 0x10750025u, 0x0000eff7u}, + {0x04880004u, 0x00870020u, 0xfe80ffeau, 0x18160167u, 0x0000fc04u}, + {0x01230000u, 0xfff00081u, 0xfe7d000au, 0x0c0effaeu, 0x0000f7f9u}, + {0x088b0017u, 0x01bd011au, 0xf9dcff60u, 0x2111035du, 0x0000f41eu}, + {0x02310000u, 0x00170001u, 0xffd4ffffu, 0x10bf0059u, 0x0000ff57u}, + {0x01260002u, 0xffcc001au, 0x00aefff1u, 0x0c1ffeedu, 0x00000398u}, + {0x033b0035u, 0x01a2001cu, 0x0131004du, 0x14550525u, 0x000003c1u}, + {0x015d001du, 0x00c90000u, 0x00150006u, 0x0d3403cdu, 0x00000067u}, + {0x01330025u, 0xff290103u, 0x0234ff3bu, 0x0c65fbacu, 0x00000b60u}, + {0x02470000u, 0x00080089u, 0x02360004u, 0x1113001fu, 0x0000084au}, + {0x043c0020u, 0x01740118u, 0x044e00bdu, 0x174703ffu, 0x00000bd7u}, + {0x02130013u, 0x00c701e4u, 0x03f600beu, 0x104b030cu, 0x00000f8fu}, + {0x01080014u, 0xff700711u, 0x0566fe86u, 0x0b7cfcdbu, 0x00001e12u}, + {0x02b20004u, 0xff93044eu, 0x06d0ff76u, 0x1294fe87u, 0x00001778u}, + {0x007d0000u, 0x00090334u, 0x02810017u, 0x07ea0048u, 0x0000143eu}, + {0x01320021u, 0x00c801bdu, 0x02e200f1u, 0x0c5c040bu, 0x00000eecu}, + {0x00590064u, 0xff43031fu, 0x0214fdcau, 0xf9590716u, 0x0000ec03u}, + {0x03ac0034u, 0xfe4600f5u, 0x03c0ff1eu, 0xea530519u, 0x0000f4eeu}, + {0x03db00b2u, 0xfcbb018cu, 0x04e3fdeeu, 0xe9c8096cu, 0x0000f1edu}, + {0x012500fdu, 0xfddf0073u, 0x0170feaau, 0xf3e70b41u, 0x0000f867u}, + {0x01350085u, 0xfe6b001fu, 0x00c4ff80u, 0xf3920825u, 0x0000fc10u}, + {0x0d2e006du, 0xfb410008u, 0x0143ffc6u, 0xd6ee0765u, 0x0000fe09u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0x04c0008eu, 0xfcc20037u, 0x0207ff4fu, 0xe757086au, 0x0000fabeu}, + {0x01e60020u, 0xff050021u, 0xff010042u, 0xf06b0406u, 0x00000417u}, + {0x01320078u, 0xfe810000u, 0xfff50007u, 0xf3a207bdu, 0x00000038u}, + {0x0111006cu, 0xfea80078u, 0xfe9700e4u, 0xf451075du, 0x000007bbu}, + {0x01fa0117u, 0xfd10007fu, 0xfe050179u, 0xf01a0bd2u, 0x000007f8u}, + {0x0124002cu, 0xff1c011fu, 0xfdbd00e2u, 0xf3e904b6u, 0x00000bfbu}, + {0x02d8005au, 0xfdff019du, 0xfbb70182u, 0xeced06b7u, 0x00000e5fu}, + {0x03e500a8u, 0xfccd0095u, 0xfcfe013cu, 0xe9ad092cu, 0x0000089eu}, + {0x0128010du, 0xfdcc0101u, 0xfdd8020eu, 0xf3d50b97u, 0x00000b57u}, + {0x007b001du, 0xff880074u, 0x00eeff8bu, 0xf82a03d6u, 0x0000f866u}, + {0x00010013u, 0xfffa0150u, 0x001aff61u, 0xff80030fu, 0x0000f30bu}, + {0x002e006du, 0xff730128u, 0x00e8fe99u, 0xfb3b0762u, 0x0000f3d4u}, + {0x0082007fu, 0xfeff0020u, 0x0080ff81u, 0xf7ef07fau, 0x0000fc05u}, + {0x00220021u, 0xffbd001cu, 0xffc2003du, 0xfbe50417u, 0x000003c0u}, + {0x001e0083u, 0xff840000u, 0x00000001u, 0xfc270816u, 0x00000005u}, + {0x007c007cu, 0xff080000u, 0xfff90007u, 0xf82107e1u, 0x00000035u}, + {0x0020012cu, 0xff3d0000u, 0xfffd0008u, 0xfc040c3fu, 0x0000002cu}, + {0x0002002eu, 0xffed0116u, 0xffd100e3u, 0xfeff04d0u, 0x00000bccu}, + {0x0088007eu, 0xfefa0077u, 0xff0100f5u, 0xf7be07eeu, 0x000007b7u}, + {0x00260088u, 0xff70007eu, 0xff750106u, 0xfba10843u, 0x000007f1u}, + {0x007e0115u, 0xfe8a0085u, 0xfefd0180u, 0xf8100bc6u, 0x00000827u}, + {0x00240012u, 0xffcd01c4u, 0xff0000b6u, 0xfbc00305u, 0x00000f09u}, + {0x00010013u, 0x000a0683u, 0x005a0166u, 0x00c7031bu, 0x00001cdeu}, + {0x007e013au, 0xfe72047fu, 0xfd0504b2u, 0xf80d0c86u, 0x000017fcu}, + {0x0069011eu, 0xfea60217u, 0xfe27030eu, 0xf8c40bf4u, 0x0000105au}, + {0x009d0017u, 0x007807c3u, 0xfba1fe56u, 0x08e00360u, 0x0000e07cu}, + {0x007d007fu, 0x00fc009du, 0xfee9fee6u, 0x07e507fau, 0x0000f727u}, + {0x0000008bu, 0x0001007bu, 0xfffffefau, 0x00050857u, 0x0000f827u}, + {0x0007013eu, 0xff9f0328u, 0x009bfc0au, 0xfe130c9cu, 0x0000ebe6u}, + {0x001f0025u, 0x00430023u, 0x00410048u, 0x03ea044eu, 0x0000042eu}, + {0x00710020u, 0x00780000u, 0x00020001u, 0x078703fau, 0x00000012u}, + {0x001f0128u, 0x00bf001bu, 0xffc6ff4cu, 0x03ea0c2du, 0x0000fc50u}, + {0x007e0120u, 0x017c0020u, 0x008000c1u, 0x07ed0c00u, 0x00000407u}, + {0x0088007cu, 0x01040076u, 0x00fd00f2u, 0x084007deu, 0x000007adu}, + {0x00000070u, 0x0009008au, 0x000a00f9u, 0x0050077eu, 0x0000084eu}, + {0x00000119u, 0xfffa0021u, 0xfffe00c0u, 0xffdf0bdau, 0x0000040du}, + {0x00780138u, 0x0182006fu, 0x00e60173u, 0x07bd0c7bu, 0x0000076fu}, + {0x009c0028u, 0x009e0497u, 0x035701b3u, 0x08d2047du, 0x0000183du}, + {0x001300d7u, 0x007f0f69u, 0x02210732u, 0x03110a5fu, 0x00002c6au}, + {0x001d0087u, 0x007d0144u, 0x00c101a3u, 0x03c90839u, 0x00000cbbu}, + {0x00010084u, 0x0012020au, 0x0023020du, 0x008b081du, 0x00001029u}, + {0x00fb001eu, 0x00ac009cu, 0xfe75ff78u, 0x0b3203dau, 0x0000f72eu}, + {0x01470078u, 0x018c0227u, 0xfcaffdfdu, 0x0cc807c1u, 0x0000ef67u}, + {0x032b011au, 0x03bc0342u, 0xf994fc37u, 0x14220bdeu, 0x0000eb95u}, + {0x02320130u, 0x033b0090u, 0xfdc7fe5du, 0x10c40c56u, 0x0000f784u}, + {0x061f0018u, 0x01800003u, 0xff6effeeu, 0x1bfe036eu, 0x0000feb2u}, + {0x0202006fu, 0x01de0003u, 0xffafffdau, 0x10080774u, 0x0000febeu}, + {0x01270115u, 0x023c0024u, 0x00cd00c7u, 0x0c270bc3u, 0x00000439u}, + {0x010b0129u, 0x0233001au, 0xff59ff50u, 0x0b8c0c31u, 0x0000fc62u}, + {0x01710027u, 0x00f00119u, 0x028400d2u, 0x0d96046cu, 0x00000bd9u}, + {0x04a3007au, 0x02fa0022u, 0x01900080u, 0x185c07d1u, 0x0000041bu}, + {0x02110101u, 0x02e10079u, 0x01fa0160u, 0x10430b54u, 0x000007c6u}, + {0x01eb0182u, 0x03670137u, 0x030d02b5u, 0x0fab0de6u, 0x00000c77u}, + {0x02cb0083u, 0x02630461u, 0x06fe02fdu, 0x12e70815u, 0x000017adu}, + {0x0e7c0167u, 0x0903023bu, 0x0b5d0389u, 0x2b0e0d65u, 0x000010e4u}, + {0x012e010eu, 0x023b01f9u, 0x030d02e3u, 0x0c490ba0u, 0x00000fe2u}, + {0x02bb010fu, 0x03670212u, 0x04c102f6u, 0x12b20ba5u, 0x00001047u}, + {0x08df01d0u, 0xf7fc015cu, 0x06f1fcddu, 0xde4e0f3au, 0x0000f2d0u}, + {0x124400b8u, 0xf8c00ad9u, 0x1c27fa6au, 0xcfa50998u, 0x0000dabdu}, + {0x040702eau, 0xf92603e4u, 0x07eaf945u, 0xe94b1350u, 0x0000e9b0u}, + {0x05fa0228u, 0xf8d20974u, 0x0f08f6f8u, 0xe459109eu, 0x0000dd37u}, + {0x02e40107u, 0xfc8d0001u, 0x0035ffe0u, 0xecc30b7au, 0x0000ff4fu}, + {0x01ae013au, 0xfd2101ffu, 0x03a9fcdfu, 0xf1560c87u, 0x0000f005u}, + {0x02d001e7u, 0xfb60008du, 0x027dfdf4u, 0xed080f99u, 0x0000f79bu}, + {0x013302e2u, 0xfc480000u, 0x0009fff3u, 0xf39d1337u, 0x0000ffd3u}, + {0x05310114u, 0xfb45005fu, 0xfd390144u, 0xe63a0bbfu, 0x000006e6u}, + {0x01b001c5u, 0xfc8b0000u, 0xfffb0006u, 0xf14c0f0cu, 0x00000018u}, + {0x02de01c8u, 0xfb7b0073u, 0xfdba01cau, 0xecd80f19u, 0x00000797u}, + {0x21740740u, 0xe0da0184u, 0xf1c306a1u, 0xbe901e77u, 0x00000dedu}, + {0x02f30131u, 0xfc3f063du, 0xf76b0575u, 0xec910c5cu, 0x00001c42u}, + {0x0dbc007du, 0xfad200d7u, 0xf9340148u, 0xd61207e8u, 0x00000a60u}, + {0x01de00eau, 0xfd6200f0u, 0xfd5a01dau, 0xf0890ad2u, 0x00000af5u}, + {0x03280301u, 0xf9d7020cu, 0xfaeb04f5u, 0xebe6139cu, 0x00001030u}, + {0x001f0131u, 0xff3d012fu, 0x00c3fda0u, 0xfc0a0c58u, 0x0000f3b1u}, + {0x00730101u, 0xfea805cfu, 0x033cfb2bu, 0xf8690b56u, 0x0000e4bbu}, + {0x01180234u, 0xfce6008cu, 0x018cfdceu, 0xf42b10c9u, 0x0000f7a3u}, + {0x00b20225u, 0xfd8f0219u, 0x026afbc2u, 0xf6911092u, 0x0000ef9fu}, + {0x013401f3u, 0xfcf0001cu, 0x00bbff12u, 0xf3980fccu, 0x0000fc3au}, + {0x002301feu, 0xfef60027u, 0x0049fee7u, 0xfbd80ff9u, 0x0000fb9au}, + {0x0032020au, 0xfebe0082u, 0x00a1fdf7u, 0xfb031029u, 0x0000f7f0u}, + {0x007f0334u, 0xfd7a0025u, 0x008afea3u, 0xf805143eu, 0x0000fbb1u}, + {0x01140116u, 0xfdd60018u, 0xff5d00a4u, 0xf4410bcdu, 0x00000378u}, + {0x001d01cbu, 0xff190000u, 0xfffb0013u, 0xfc320f28u, 0x00000051u}, + {0x007b0229u, 0xfdf60000u, 0xfff9000fu, 0xf82810a0u, 0x00000039u}, + {0x006801eeu, 0xfe3b0081u, 0xff1901f9u, 0xf8cd0fb7u, 0x00000807u}, + {0x001c01beu, 0xff1f02fdu, 0xfed90490u, 0xfc3a0eefu, 0x00001390u}, + {0x015f0224u, 0xfc93033au, 0xfbcb0542u, 0xf2c0108eu, 0x00001453u}, + {0x00290200u, 0xfedf01e7u, 0xfee603e7u, 0xfb7b1001u, 0x00000f9du}, + {0x0130031eu, 0xfc260125u, 0xfdab03c7u, 0xf3aa13f9u, 0x00000c1bu}, + {0x00830104u, 0x01710131u, 0xfe70fdceu, 0x081b0b65u, 0x0000f3a9u}, + {0x0023010au, 0x00c0008fu, 0xff73fe7au, 0x04290b87u, 0x0000f78au}, + {0x001002e2u, 0x00db0318u, 0xff1dfa06u, 0x02db1337u, 0x0000ec19u}, + {0x0026034bu, 0x016800ffu, 0xff3afc61u, 0x04611489u, 0x0000f4b6u}, + {0x001f0200u, 0xff05001fu, 0xffc200fcu, 0xfc150fffu, 0x000003f1u}, + {0x00000216u, 0xffe00017u, 0x0007ff23u, 0xff831057u, 0x0000fca0u}, + {0x0020020eu, 0x01020000u, 0x00000000u, 0x03fa1037u, 0x0000fffeu}, + {0x00000326u, 0x00230000u, 0x0000fff0u, 0x00701412u, 0x0000ffccu}, + {0x00000118u, 0xffec012au, 0xffeb0242u, 0xff920bd6u, 0x00000c36u}, + {0x0022014du, 0x00d300a9u, 0x009701dau, 0x04190ce5u, 0x00000930u}, + {0x0000031du, 0xffef0087u, 0xfff90291u, 0xffc913f8u, 0x00000838u}, + {0x00230344u, 0x01560127u, 0x00cc03e1u, 0x04301471u, 0x00000c26u}, + {0x00220115u, 0x00c30113u, 0x00c30228u, 0x04260bc4u, 0x00000bbbu}, + {0x002601fbu, 0x0114036cu, 0x016b0534u, 0x04550fecu, 0x000014ecu}, + {0x00000239u, 0xfff60211u, 0xfff60449u, 0xffd910dfu, 0x00001042u}, + {0x002401e6u, 0x0108067du, 0x01e80705u, 0x043c0f97u, 0x00001cd1u}, + {0x01c901f2u, 0x03ba011bu, 0xfd31fd12u, 0x0f1d0fc6u, 0x0000f41cu}, + {0x02120233u, 0x04440022u, 0xfef3feebu, 0x104710c6u, 0x0000fbdfu}, + {0x00860209u, 0x02100024u, 0xff75feeeu, 0x082f1025u, 0x0000fbc2u}, + {0x0b40037du, 0x0c88003au, 0xfcd2fe3au, 0x25f21522u, 0x0000faa3u}, + {0x032a00f9u, 0x0382001cu, 0x012e00a7u, 0x14210b28u, 0x000003c0u}, + {0x041f01f9u, 0x05b40020u, 0xfe8fff00u, 0x16f70fe5u, 0x0000fbfbu}, + {0x008401ecu, 0x01fe001au, 0x007500e3u, 0x08210fb0u, 0x0000039du}, + {0x0121034bu, 0x03dc0031u, 0xff11fe68u, 0x0c061489u, 0x0000fb08u}, + {0x06ac0204u, 0x07560088u, 0x03c30211u, 0x1d391010u, 0x0000083du}, + {0x00ed01e5u, 0x02a70115u, 0x020102deu, 0x0ae40f93u, 0x00000bc7u}, + {0x013d020bu, 0x032e001eu, 0x00c300fau, 0x0c95102bu, 0x000003deu}, + {0x020e0319u, 0x050c0115u, 0x02fb03a9u, 0x103913e9u, 0x00000bc3u}, + {0x0149010cu, 0x0252046fu, 0x04c6044eu, 0x0cd40b92u, 0x000017d2u}, + {0x00f1024cu, 0x02f1022cu, 0x02dc0478u, 0x0af91125u, 0x000010aeu}, + {0x032e01fbu, 0x050505f4u, 0x08b406deu, 0x142e0fecu, 0x00001b9bu}, + {0x042501aau, 0x05410becu, 0x0e0f08e9u, 0x17080e9au, 0x00002711u}, + {0x01d902bfu, 0xfb7e0078u, 0x01ddfdbbu, 0xf09d12bfu, 0x0000f840u}, + {0x03140352u, 0xf99c0134u, 0x03d9fc01u, 0xec27149du, 0x0000f398u}, + {0x01670405u, 0xfb400016u, 0x00b2fed3u, 0xf29816aeu, 0x0000fcb0u}, + {0x099507e1u, 0xeea0017du, 0x078df927u, 0xdcfb1fc1u, 0x0000f233u}, + {0x02f202c3u, 0xfa4b002au, 0xfe9b015au, 0xec9512ceu, 0x00000498u}, + {0x02eb0245u, 0xfada0000u, 0xffdd001fu, 0xecab110du, 0x00000073u}, + {0x04b4021cu, 0xf9b30028u, 0x01b8fed9u, 0xe7771070u, 0x0000fb83u}, + {0x01b603d1u, 0xfae30017u, 0xff36012eu, 0xf132161au, 0x0000036bu}, + {0x063d02a0u, 0xf7e8011au, 0xfac30367u, 0xe3bf1256u, 0x00000bdeu}, + {0x00e502d8u, 0xfcd0002au, 0xff3d015cu, 0xf54f1313u, 0x0000048fu}, + {0x039a0305u, 0xf9670097u, 0xfd1602abu, 0xea8713aau, 0x000008afu}, + {0x022104fcu, 0xf97c007au, 0xfdfd0314u, 0xef7e1943u, 0x000007ccu}, + {0x0567054fu, 0xf54b053cu, 0xf55d0a8bu, 0xe5b41a10u, 0x000019e3u}, + {0x016903d7u, 0xfb59057au, 0xfa72092cu, 0xf292162bu, 0x00001a7bu}, + {0x020403d8u, 0xfa6e0204u, 0xfbf80591u, 0xefef162eu, 0x0000100fu}, + {0x025d0424u, 0xf9be0b45u, 0xf5ad0daau, 0xee9a1706u, 0x000025fbu}, + {0x0082043bu, 0xfd110027u, 0x008efe66u, 0xf7ee1744u, 0x0000fb97u}, + {0x007a0441u, 0xfd26008fu, 0x0108fcebu, 0xf82d1756u, 0x0000f78du}, + {0x001f0430u, 0xfe910067u, 0x0072fd66u, 0xfc0a1728u, 0x0000f8cfu}, + {0x00000634u, 0xfff30372u, 0x000af6c2u, 0xffe31c2du, 0x0000eb01u}, + {0x007d030eu, 0xfd8f0026u, 0xff760158u, 0xf81913c6u, 0x0000045au}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0x00190446u, 0xfeb50000u, 0x0001fffdu, 0xfc761762u, 0x0000fff7u}, + {0x013004acu, 0xfb4b0000u, 0x000effe4u, 0xf3ad1873u, 0x0000ffb6u}, + {0x001c0336u, 0xfed2001bu, 0xffc90129u, 0xfc461447u, 0x000003aau}, + {0x0028050au, 0xfe3a0130u, 0xff2404e4u, 0xfb891967u, 0x00000c53u}, + {0x00b404a8u, 0xfc62009fu, 0xfeae0366u, 0xf6851869u, 0x000008eau}, + {0x002105ffu, 0xfe3f0020u, 0xffbf01beu, 0xfbf21bb3u, 0x00000406u}, + {0x0080030du, 0xfd870333u, 0xfd78063fu, 0xf7ff13c3u, 0x0000143bu}, + {0x00580521u, 0xfd5909ecu, 0xfc500e45u, 0xf960199fu, 0x000023a4u}, + {0x014b04e4u, 0xfaf80224u, 0xfcac0678u, 0xf3201905u, 0x0000108cu}, + {0x0021069bu, 0xfe260121u, 0xff3c0576u, 0xfbee1d15u, 0x00000c05u}, + {0x000002ffu, 0xffe6010eu, 0x0010fc72u, 0xffaa1397u, 0x0000f464u}, + {0x000002eeu, 0x000f001eu, 0xfffdfed6u, 0x0033135eu, 0x0000fc27u}, + {0x00280410u, 0x0196012au, 0xff27fba6u, 0x047416cfu, 0x0000f3cbu}, + {0x00910388u, 0x02d50209u, 0xfddafaa4u, 0x08871543u, 0x0000efddu}, + {0x00210306u, 0x0142001eu, 0xffc1fecfu, 0x041613acu, 0x0000fc1fu}, + {0x001f049eu, 0x017e0000u, 0xfffdffebu, 0x03ef1850u, 0x0000ffc9u}, + {0x00660499u, 0x02b50000u, 0x00030009u, 0x07241841u, 0x00000016u}, + {0x000005c1u, 0x00070000u, 0x00000001u, 0x00101b24u, 0x00000001u}, + {0x00240327u, 0x0156001cu, 0x0040012fu, 0x04431415u, 0x000003c6u}, + {0x0081030du, 0x027b0081u, 0x0102027au, 0x080813c3u, 0x00000805u}, + {0x000004b8u, 0xffff001cu, 0x00000171u, 0xfffe1893u, 0x000003c0u}, + {0x007c06ecu, 0x03a90017u, 0x006c0198u, 0x07df1dc4u, 0x0000036du}, + {0x0034031bu, 0x01980217u, 0x014f0518u, 0x051f13efu, 0x0000105bu}, + {0x00000495u, 0xffea0310u, 0xffee077fu, 0xffc71839u, 0x000013ceu}, + {0x00000457u, 0xfffd011du, 0xfffe0465u, 0xfff71790u, 0x00000bf0u}, + {0x00750477u, 0x02dc010cu, 0x01620452u, 0x07a717e8u, 0x00000b91u}, + {0x010e02bbu, 0x0365066au, 0xfaccf7a1u, 0x0b9f12b2u, 0x0000e359u}, + {0x012f0358u, 0x03fa021cu, 0xfcd7fab0u, 0x0c4f14b0u, 0x0000ef90u}, + {0x07be04feu, 0x0c6f04a6u, 0xf401f65eu, 0x1f7b1947u, 0x0000e79cu}, + {0x01bf05e4u, 0x066a012du, 0xfd22fabcu, 0x0ef21b75u, 0x0000f3bau}, + {0x0203030au, 0x04f20068u, 0xfe31fdc8u, 0x100d13b9u, 0x0000f8cbu}, + {0x01120306u, 0x03990020u, 0x00ba0139u, 0x0bb313adu, 0x000003fau}, + {0x03040336u, 0x063a0000u, 0x001c001du, 0x13a61447u, 0x0000005bu}, + {0x007604cdu, 0x02fa0096u, 0xfef6fca6u, 0x07ae18c9u, 0x0000f758u}, + {0x01e70349u, 0x0500001cu, 0x00e80132u, 0x0f9a1483u, 0x000003bau}, + {0x0378042cu, 0x079c0070u, 0x027702b4u, 0x1512171cu, 0x0000077cu}, + {0x0128043du, 0x046d0081u, 0x018702edu, 0x0c29174bu, 0x0000080au}, + {0x02b00588u, 0x07b601cfu, 0x04690653u, 0x128c1a9bu, 0x00000f37u}, + {0x05d003a1u, 0x0930031eu, 0x088406bau, 0x1b47158eu, 0x000013fau}, + {0x00680495u, 0x02b904e7u, 0x02d1097bu, 0x07331838u, 0x0000190eu}, + {0x125c0491u, 0x124f0de7u, 0x1ff40fefu, 0x307b182cu, 0x00002a2eu}, + {0x007805d9u, 0x03510ca3u, 0x04df1132u, 0x07c11b5du, 0x00002837u}, + {0x021a05ecu, 0xf8f10318u, 0x051af771u, 0xef981b87u, 0x0000ec19u}, + {0x01d80646u, 0xf93300c1u, 0x025bfba7u, 0xf0a51c57u, 0x0000f62fu}, + {0x0486049du, 0xf6dd021bu, 0x062cf9c4u, 0xe7f1184du, 0x0000ef96u}, + {0x02500aadu, 0xf6110088u, 0x0236fb3fu, 0xeecc24f7u, 0x0000f7c5u}, + {0x01bd05ddu, 0xf99d0002u, 0xffcc0060u, 0xf1161b65u, 0x000000e1u}, + {0x06a40861u, 0xf116001au, 0x01a1fe2bu, 0xe2d920bfu, 0x0000fc6cu}, + {0x031407e3u, 0xf625009bu, 0x02bafba2u, 0xec251fc6u, 0x0000f735u}, + {0x03fb08ebu, 0xf4150002u, 0xffb00078u, 0xe96e21cau, 0x000000e4u}, + {0x032e0716u, 0xf683011au, 0xfc410597u, 0xebd51e1du, 0x00000be2u}, + {0x043504f2u, 0xf6e1008eu, 0xfcf10351u, 0xe8cc1928u, 0x00000870u}, + {0x016907d8u, 0xf9590039u, 0xfee102a4u, 0xf28f1fafu, 0x00000556u}, + {0x026a0ce1u, 0xf4d8014du, 0xfc75082fu, 0xee6a289au, 0x00000ce6u}, + {0x0324072cu, 0xf6820318u, 0xf9c4096bu, 0xebf31e4du, 0x000013e5u}, + {0x02170791u, 0xf80d04d2u, 0xf9a80c13u, 0xefa71f1eu, 0x000018d6u}, + {0x0a890cc0u, 0xe8d302c8u, 0xf52c0be9u, 0xdb482865u, 0x000012dfu}, + {0x05f20c35u, 0xeef6015eu, 0xfa4d082bu, 0xe46a2788u, 0x00000d39u}, + {0x0141061au, 0xfa770228u, 0x034af8bfu, 0xf3541bf3u, 0x0000ef63u}, + {0x010d06eeu, 0xfa9b0016u, 0x009bfe72u, 0xf4691dc9u, 0x0000fca8u}, + {0x001a057au, 0xfe840066u, 0x0067fd0au, 0xfc691a7bu, 0x0000f8d9u}, + {0x01100bedu, 0xf8e00083u, 0x017afb10u, 0xf4552713u, 0x0000f7e9u}, + {0x0077066fu, 0xfc8c0002u, 0xffe3006bu, 0xf84d1cb3u, 0x000000efu}, + {0x008e083fu, 0xfbba001fu, 0x0085fe00u, 0xf795207cu, 0x0000fc0fu}, + {0x00670a43u, 0xfbf00001u, 0xffeb0069u, 0xf8d4243eu, 0x000000b9u}, + {0x00380abcu, 0xfcee0014u, 0x0043fe2du, 0xfab32511u, 0x0000fcd9u}, + {0x002a05b3u, 0xfe0f008du, 0xff65038cu, 0xfb661b01u, 0x00000868u}, + {0x011808c9u, 0xf9cd0084u, 0xfe800441u, 0xf42c2188u, 0x0000081fu}, + {0x001a0b66u, 0xfddb00a2u, 0xff7f0560u, 0xfc692632u, 0x00000901u}, + {0x01920dcdu, 0xf6b10120u, 0xfd5707e2u, 0xf1d32a07u, 0x00000c00u}, + {0x00260688u, 0xfe060461u, 0xfe610ab2u, 0xfb9f1ce9u, 0x000017adu}, + {0x008a087eu, 0xfbb900f9u, 0xfe8d05bfu, 0xf7b220f8u, 0x00000b27u}, + {0x00e20ac6u, 0xf9d50a1bu, 0xfa0714deu, 0xf55f2522u, 0x000023f8u}, + {0x008d0973u, 0xfb710244u, 0xfdc50941u, 0xf79d22c7u, 0x00001108u}, + {0x001505c7u, 0x0161010cu, 0xff6afb14u, 0x033e1b31u, 0x0000f46bu}, + {0x0059078bu, 0x033f0136u, 0xfeb3f9f5u, 0x06af1f13u, 0x0000f38du}, + {0x00000920u, 0xffc100ffu, 0x0015f9f9u, 0xff8a222du, 0x0000f4b7u}, + {0x00000bc5u, 0x00460329u, 0xffdcf3cdu, 0x007326d0u, 0x0000ebe2u}, + {0x0013066du, 0x0160002cu, 0xffc7fde7u, 0x03111caeu, 0x0000fb53u}, + {0x002b0794u, 0x023f0000u, 0x0002000fu, 0x049d1f25u, 0x0000001eu}, + {0x006b0854u, 0x03bc001fu, 0xff8dfdffu, 0x075220a6u, 0x0000fc12u}, + {0x001c0828u, 0xfe1e0001u, 0xfff80045u, 0xfc462050u, 0x00000089u}, + {0x00250600u, 0x01dc00fau, 0x00c004d8u, 0x044a1bb7u, 0x00000b2fu}, + {0x000108bfu, 0xffa1005du, 0xffed038eu, 0xff4b2176u, 0x000006cdu}, + {0x002307b1u, 0x020c0073u, 0x007f03b7u, 0x042d1f61u, 0x00000795u}, + {0x00770a36u, 0x045e0001u, 0x00180072u, 0x07bb2426u, 0x000000cau}, + {0x003006e0u, 0x02460720u, 0x02500e00u, 0x04e71dabu, 0x00001e34u}, + {0x003b08bdu, 0xfd2a0354u, 0xfe400acau, 0xfa932172u, 0x000014a5u}, + {0x00020b0cu, 0xff6d0224u, 0xffbf09b9u, 0xff06259bu, 0x0000108du}, + {0x000f0ae3u, 0x019404b4u, 0x010a0e51u, 0x02b52555u, 0x0000188au}, + {0x02e10617u, 0x085f0090u, 0xfd74fc4cu, 0x13311becu, 0x0000f783u}, + {0x01170687u, 0x05570094u, 0xfe69fc1cu, 0x0bd21ce9u, 0x0000f762u}, + {0x07550a7bu, 0x1187008eu, 0xfbf7fb2du, 0x1ea224a0u, 0x0000f792u}, + {0x026108d0u, 0x09290080u, 0xfdd1fbcdu, 0x11742196u, 0x0000f7ffu}, + {0x02080601u, 0x06fc0020u, 0xfefffe47u, 0x10201bb9u, 0x0000fc05u}, + {0x01fe0649u, 0x07140016u, 0x00d5017au, 0x0ff81c5eu, 0x00000356u}, + {0x01bc0848u, 0x0795001fu, 0xff15fdffu, 0x0ee8208fu, 0x0000fc0fu}, + {0x006b0d05u, 0x04a9009fu, 0xfefcfa52u, 0x074e28d2u, 0x0000f718u}, + {0x048b0898u, 0x0c7f0017u, 0x014401beu, 0x181c212bu, 0x0000035du}, + {0x00930812u, 0x044f006au, 0x00fa03a7u, 0x08942024u, 0x00000746u}, + {0x0941082eu, 0x11660053u, 0x03790344u, 0x226a205bu, 0x00000676u}, + {0x013e0ac7u, 0x0751007bu, 0x018c048eu, 0x0c9c2525u, 0x000007d8u}, + {0x00dd0834u, 0x05540223u, 0x02b80860u, 0x0a852068u, 0x0000108bu}, + {0x0aaa0855u, 0x12da0412u, 0x0d2e0ba7u, 0x24f220a9u, 0x000016d5u}, + {0x01c00913u, 0x07f9010bu, 0x02b40626u, 0x0ef92214u, 0x00000b8du}, + {0x02a6099eu, 0x0a1704b0u, 0x070c0d6eu, 0x12682317u, 0x00001880u}, + {0x033a0cb0u, 0xf33400e5u, 0x0366f942u, 0xebad284cu, 0x0000f54bu}, + {0x01650b60u, 0xf808031cu, 0x042af41bu, 0xf2a32628u, 0x0000ec0du}, + {0x060b14b8u, 0xe99f04a0u, 0x0a93ec6cu, 0xe430337fu, 0x0000e7abu}, + {0x015839a3u, 0xee67035bu, 0x043fe42fu, 0xf2e355e5u, 0x0000eb46u}, + {0x038d0f7du, 0xf12b0019u, 0x012ffd88u, 0xeaae2c87u, 0x0000fc73u}, + {0x01f213dbu, 0xf3900014u, 0x00c7fd84u, 0xf036326au, 0x0000fcd9u}, + {0x014c2602u, 0xf1f60027u, 0xff1d04d0u, 0xf31e45c0u, 0x0000046au}, + {0x0601201au, 0xe43b0009u, 0x00eefddau, 0xe447401au, 0x0000fddbu}, + {0x02230b8fu, 0xf61000a7u, 0xfda4057du, 0xef772677u, 0x00000922u}, + {0x00c7118cu, 0xf89f0022u, 0xff5d0308u, 0xf6092f64u, 0x00000418u}, + {0x03631421u, 0xef7c00a1u, 0xfd15071du, 0xeb2d32c3u, 0x000008f8u}, + {0x00b72afdu, 0xf4e8030eu, 0xfd0b16ebu, 0xf66d4a2eu, 0x000013c6u}, + {0x03b60e07u, 0xf1920b07u, 0xf33518dfu, 0xea352a5fu, 0x00002591u}, + {0x02241206u, 0xf393037du, 0xfa890fdbu, 0xef713008u, 0x00001520u}, + {0x089e1744u, 0xe3ae03c1u, 0xf4a012b0u, 0xdec93692u, 0x000015ebu}, + {0x03302000u, 0xebce0802u, 0xf5e62003u, 0xebce4000u, 0x00002003u}, + {0x003a0bd7u, 0xfcb900ceu, 0x00dbf9d4u, 0xfa9c26efu, 0x0000f5dau}, + {0x00120f7fu, 0x021a0125u, 0xff6ef792u, 0x03052c89u, 0x0000f3e3u}, + {0x00361461u, 0xfbdf013fu, 0x0105f5ebu, 0xfad33312u, 0x0000f35eu}, + {0x009426c5u, 0xf68800c7u, 0x0158f502u, 0xf7664672u, 0x0000f603u}, + {0x001e0d8bu, 0x0286001au, 0xffc9fdadu, 0x03e129a3u, 0x0000fc6eu}, + {0x00820e91u, 0xfa92002au, 0x0094fce9u, 0xf7f32b2eu, 0x0000fb6bu}, + {0x00c11777u, 0xf7940004u, 0xffcb0127u, 0xf62a36ceu, 0x00000158u}, + {0x000a3f8bu, 0xfcc80002u, 0xfff60180u, 0xfdb75a2fu, 0x00000111u}, + {0x00010d0au, 0xff960023u, 0xfff502abu, 0xff5b28dau, 0x0000042du}, + {0x003a0f77u, 0xfc40012fu, 0xfef60890u, 0xfa9c2c7eu, 0x00000c51u}, + {0x000513cdu, 0x01460000u, 0x00010019u, 0x019e3258u, 0x00000020u}, + {0x0006169bu, 0xfe830093u, 0xffc30732u, 0xfe3b35cbu, 0x00000890u}, + {0x00120c3du, 0x01d501ffu, 0x00be09e3u, 0x02f72794u, 0x00000ffdu}, + {0x00360f4fu, 0xfc6804ceu, 0xfdfd1126u, 0xface2c44u, 0x000018cbu}, + {0x00000e61u, 0xffe90721u, 0xfff01441u, 0xffde2ae7u, 0x00001e36u}, + {0x00351cddu, 0xfb1b0257u, 0xfe9b1071u, 0xfad83cc8u, 0x00001150u}, + {0x01120f12u, 0x080802ccu, 0xfc8af303u, 0x0bb42becu, 0x0000ed13u}, + {0x009d128fu, 0x06be0806u, 0xfb91e798u, 0x08da30beu, 0x0000dff3u}, + {0x010d1eaeu, 0x0b5d025au, 0xfcdbef05u, 0x0b9a3eabu, 0x0000eea8u}, + {0x004b6679u, 0x0afa0243u, 0xfe5fe18fu, 0x06237287u, 0x0000eefdu}, + {0x00fe1247u, 0x08850068u, 0xfebbfa8eu, 0x0b46305fu, 0x0000f8ccu}, + {0x00dc184du, 0x09260013u, 0xff7ffd51u, 0x0a7f37c5u, 0x0000fcecu}, + {0x006d1c7du, 0x06f40000u, 0xfff5ffa9u, 0x075e3c63u, 0x0000ffa4u}, + {0x00ba2af6u, 0x0b2b011eu, 0xfe33f224u, 0x09a34a28u, 0x0000f40au}, + {0x01460d72u, 0x0847023bu, 0x035f0af4u, 0x0cc5297cu, 0x000010e5u}, + {0x01010be6u, 0x06eb005cu, 0x01340422u, 0x0b592707u, 0x000006c8u}, + {0x00de108du, 0x07940000u, 0xffebffa4u, 0x0a8a2e06u, 0x0000ff81u}, + {0x01bd1c23u, 0x0dfd0233u, 0x03ea0fbcu, 0x0eeb3c03u, 0x000010c8u}, + {0x00e70fb5u, 0x078805c6u, 0x0491130bu, 0x0ac02cd6u, 0x00001b2eu}, + {0x00071308u, 0x017b0337u, 0x009c0fa4u, 0x01ec315bu, 0x00001449u}, + {0x00671c01u, 0x06b70504u, 0x02d717b5u, 0x072d3bdfu, 0x00001958u}, + {0x00f53fd3u, 0x0fa105c2u, 0x04b22658u, 0x0b115a63u, 0x00001b27u}, + {0x016e0ce2u, 0x0895002eu, 0xfefcfcf3u, 0x0d87289bu, 0x0000fb31u}, + {0x03c30fedu, 0x0f7c0000u, 0x0007000eu, 0x15f32d27u, 0x00000013u}, + {0x1b872433u, 0x3f2202fdu, 0xedddeb34u, 0x3b5c4412u, 0x0000ec72u}, + {0x037d3a2bu, 0x1c7c01e3u, 0xfadfeb0du, 0x1521564au, 0x0000f076u}, + {0x02d8174du, 0x1047004cu, 0x01d70544u, 0x1313369cu, 0x0000062cu}, + {0x0671193bu, 0x197e0001u, 0x003b0076u, 0x1cb638d4u, 0x00000085u}, + {0x03b52752u, 0x18250008u, 0x00b10242u, 0x15c846f2u, 0x00000209u}, + {0x056c487du, 0x27a40067u, 0x02f30acau, 0x1a576053u, 0x0000072bu}, + {0x04250ccfu, 0x0e9301ebu, 0x05a409eau, 0x1709287eu, 0x00000facu}, + {0x043618d6u, 0x147502aau, 0x06b31044u, 0x17383862u, 0x00001276u}, + {0x0ba427f5u, 0x2b2200d3u, 0x06300b77u, 0x269a4784u, 0x00000a43u}, + {0x017d2d70u, 0x10700109u, 0x027b0db6u, 0x0dcc4c44u, 0x00000b82u}, + {0x04fb0eacu, 0x11190560u, 0x0a5a11c3u, 0x19402b56u, 0x00001a3cu}, + {0x04421364u, 0x122d0e5cu, 0x0fa4215fu, 0x175931d2u, 0x00002adfu}, + {0x10d11be4u, 0x2b5006edu, 0x15951bccu, 0x2e653bc0u, 0x00001dc6u}, + {0x0dd93969u, 0x38650b09u, 0x18b93256u, 0x2a1a55b9u, 0x00002595u}, +}; +static const uint32_t r58_dstar[128][8] = { + {0x0f122d2bu, 0x00b610e1u, 0x3739342eu, 0x1fe60b57u, 0x06ee068du, 0xe0f1ca3cu, 0xf940df22u, 0x00000000u}, + {0x032b1f09u, 0x008e0178u, 0x0d8013d6u, 0x0450084du, 0x01ce02a7u, 0xf1c2d36fu, 0xfa0af64fu, 0x00000000u}, + {0x15380e4bu, 0x0293059du, 0x11eb22d5u, 0x15d50c22u, 0x079b0ec9u, 0xdb26e1c1u, 0xf329ed0bu, 0x00000000u}, + {0x01a405eau, 0x097b01a2u, 0x0638063bu, 0x03470ef9u, 0x07e007e4u, 0xf5c0ec8cu, 0xe75ef5c6u, 0x00000000u}, + {0x016c34c7u, 0x060606c2u, 0x25c41155u, 0x0633dc57u, 0xf33efa25u, 0xf675c5e2u, 0x13a2eb35u, 0x00000000u}, + {0x00740b6fu, 0x01bc0394u, 0x0cca048eu, 0x028cf717u, 0xfb04fe3au, 0xfa9de4f3u, 0x0a8af0dfu, 0x00000000u}, + {0x04fe0738u, 0x014311dfu, 0x16b70c01u, 0x12e3f9f6u, 0xf67ffafau, 0xee21ea82u, 0x08fede2eu, 0x00000000u}, + {0x035f08a2u, 0x007d05a9u, 0x0dfb0ac9u, 0x08bc041au, 0x03520290u, 0xf151e87eu, 0xfa6aecf8u, 0x00000000u}, + {0x00501a3du, 0x03a80497u, 0xea0e05b7u, 0xfd9c1396u, 0xf7cf0222u, 0xfb8ad706u, 0xf0b51124u, 0x00000000u}, + {0x04c41551u, 0x000307d1u, 0xe62f1429u, 0xf3caff0au, 0x0095ff8cu, 0xee88db10u, 0x00d5165eu, 0x00000000u}, + {0x0cbd082du, 0x02940003u, 0x00961469u, 0x00bb092fu, 0x00540b77u, 0xe372e921u, 0xf327ff2eu, 0x00000000u}, + {0x0039067fu, 0x0264000du, 0xfed90268u, 0xffc907e2u, 0xff4d0176u, 0xfc39eb9cu, 0xf3a101cfu, 0x00000000u}, + {0x128426bfu, 0x00420096u, 0xf6783592u, 0xf969f9aeu, 0x00c7fba1u, 0xdd94ce34u, 0x04100620u, 0x00000000u}, + {0x0a900a27u, 0x006f0166u, 0x078914b6u, 0x07b0fbcdu, 0xfe71fbb7u, 0xe600e683u, 0x0546f68au, 0x00000000u}, + {0x05ad06d6u, 0x06c90088u, 0x03d10c75u, 0x037af261u, 0xfc33f397u, 0xecf1eb16u, 0x14d6fa29u, 0x00000000u}, + {0x01a605a3u, 0x03b701b0u, 0xf9d50619u, 0xfcaaf6d9u, 0x0502fb0du, 0xf5baed02u, 0x0f6b0a65u, 0x00000000u}, + {0x00e31706u, 0x01be0a36u, 0x1eabf6f4u, 0xf9fa0cabu, 0x0870fd83u, 0x078bd99du, 0xf571e670u, 0x00000000u}, + {0x059711b4u, 0x0432005eu, 0x0518ec1au, 0xfd23113bu, 0x027bf651u, 0x12ebde57u, 0xef9efb28u, 0x00000000u}, + {0x019c0e77u, 0x00090043u, 0x03e4f65au, 0xfeb4fe9cu, 0xffd00077u, 0x0a26e193u, 0x0177fbe8u, 0x00000000u}, + {0x00000ab7u, 0x0136020du, 0x09610010u, 0x00070733u, 0x03270005u, 0xffece5d0u, 0xf734f48au, 0x00000000u}, + {0x079b34bdu, 0x004a011bu, 0x0f48d7f2u, 0xfa32f831u, 0xfede02f7u, 0x1610c5e7u, 0x044df795u, 0x00000000u}, + {0x04231826u, 0x02330709u, 0x1a11ec02u, 0xf536f16du, 0xf8220608u, 0x1046d8b0u, 0x0bddeac8u, 0x00000000u}, + {0x12180863u, 0x121000deu, 0x0564e75du, 0xf815e762u, 0xf8162428u, 0x2207e8d5u, 0x2200f88eu, 0x00000000u}, + {0x0d6607f3u, 0x0011036eu, 0x0a71eb5cu, 0xf272fe87u, 0xff0801e9u, 0x1d49e972u, 0x0217f130u, 0x00000000u}, + {0x00001911u, 0x01fb0000u, 0x0027006du, 0x0000f1e8u, 0xfff5ffe1u, 0xffa9d7f2u, 0x0b42ffe0u, 0x00000000u}, + {0x11e71166u, 0x02730066u, 0xfabcdcb4u, 0x0558f2f2u, 0x01fa0d3eu, 0x21d9dea1u, 0x0c85050du, 0x00000000u}, + {0x02fd0f22u, 0x008203bau, 0xf0fbf28du, 0x06ad058au, 0xfd40fd8au, 0x0dd5e0e1u, 0xfa4e0f72u, 0x00000000u}, + {0x000b07d4u, 0x00040213u, 0xf7f1012au, 0xff67ff55u, 0x0058fff3u, 0xfe56e99eu, 0x00f50b86u, 0x00000000u}, + {0x00c72acau, 0x0a290256u, 0xec00f476u, 0x02b2d64du, 0x09bf059fu, 0x070ecbabu, 0x197f0c3bu, 0x00000000u}, + {0x0279075fu, 0x03680b2bu, 0xeddbf776u, 0x0a82f5fbu, 0x0c5505ceu, 0x0c95ea48u, 0x0ec31abcu, 0x00000000u}, + {0x000108d6u, 0x125b0001u, 0xffb2ffaau, 0x0001e688u, 0x0071007cu, 0x0074e839u, 0x22460069u, 0x00000000u}, + {0x01e507ddu, 0x04450003u, 0xff63f848u, 0x004df46au, 0x007405b0u, 0x0b04e991u, 0x108800e1u, 0x00000000u}, + {0x038a00e2u, 0x05c30fa8u, 0x076e0388u, 0x0ee40482u, 0x12ff0908u, 0xf0f3f87eu, 0xeccce059u, 0x00000000u}, + {0x0cb200c2u, 0x0022033du, 0x03230636u, 0x0cd300a2u, 0x014f0297u, 0xe37ff907u, 0xfd17f19bu, 0x00000000u}, + {0x073d007bu, 0x03b70113u, 0x016f03bau, 0x059302acu, 0x03fe0a5fu, 0xea7afa75u, 0xf094f7b7u, 0x00000000u}, + {0x00420076u, 0x01b60248u, 0x020c00b1u, 0x018901c6u, 0x03f30155u, 0xfbeefa93u, 0xf58af3ebu, 0x00000000u}, + {0x0039067au, 0x00560014u, 0x016f0269u, 0x0044fd0du, 0xffacff73u, 0xfc36eba4u, 0x04a3fdbfu, 0x00000000u}, + {0x000d01eeu, 0x069607a1u, 0x07adff61u, 0xfec3f8dfu, 0xf1d30126u, 0x01cbf4e3u, 0x1487e9e7u, 0x00000000u}, + {0x018d0186u, 0x00920140u, 0x02c30313u, 0x02c9fe22u, 0xfe4ffe1eu, 0xf60af61fu, 0x060cf70du, 0x00000000u}, + {0x09960088u, 0x02c200dbu, 0x01590483u, 0x05bbfd94u, 0xfcedf5b7u, 0xe73bfa2cu, 0x0d4af899u, 0x00000000u}, + {0x009f025cu, 0x025202d0u, 0xfad9026bu, 0xfd5c04aeu, 0xfae40266u, 0xf9b3f3b6u, 0xf3d00d6bu, 0x00000000u}, + {0x000500d6u, 0x00080002u, 0xffd60040u, 0xfffa0052u, 0xfff8000cu, 0xfeeaf8afu, 0xfe9800b7u, 0x00000000u}, + {0x04510054u, 0x00440047u, 0xff650263u, 0xfdce0097u, 0xff750222u, 0xef61fb68u, 0xfbe40439u, 0x00000000u}, + {0x058b001fu, 0x02320a37u, 0xfdc901a2u, 0xf0f30107u, 0xf68806f9u, 0xed2afd3bu, 0xf4271992u, 0x00000000u}, + {0x02ff05d3u, 0x0000001eu, 0xfe57085bu, 0xfecfffd2u, 0x0006ffdfu, 0xf226ecb2u, 0x004c02c1u, 0x00000000u}, + {0x01e20056u, 0x01c80048u, 0xff630198u, 0xfe8dfe73u, 0x0169fc56u, 0xf506fb5au, 0x0aae043au, 0x00000000u}, + {0x0ce70045u, 0x00f503e8u, 0xfdf303bbu, 0xf1cdfefcu, 0x03dff8f7u, 0xe344fbd9u, 0x07d50fd0u, 0x00000000u}, + {0x00090015u, 0x05c106b4u, 0xfe87001cu, 0xff01fea3u, 0x0c6cff14u, 0xfe76fdbau, 0x133114b7u, 0x00000000u}, + {0x04080326u, 0x04730368u, 0x068cf8e1u, 0xf897077cu, 0x07c9f788u, 0x1010f1cfu, 0xef20f13cu, 0x00000000u}, + {0x00220265u, 0x00000903u, 0x094afedfu, 0xfdcf0018u, 0x002ffffau, 0x02ebf3a0u, 0xffc2e7fcu, 0x00000000u}, + {0x253401e2u, 0x02250151u, 0x0327ef43u, 0xf1ff0405u, 0x035dee21u, 0x30cbf506u, 0xf448f6d1u, 0x00000000u}, + {0x02790025u, 0x000300fau, 0x00c0fecfu, 0xfce40017u, 0x003bffa2u, 0x0c94fcf8u, 0xff11f817u, 0x00000000u}, + {0x0a9b04ffu, 0x04791383u, 0x13bff171u, 0xe33bf68bu, 0xed500dc7u, 0x1a0dee1eu, 0x10ecdca9u, 0x00000000u}, + {0x03ef031au, 0x00df03c2u, 0x06d4f904u, 0xf84ffcb6u, 0xfc6103b4u, 0x0fdff1eau, 0x0778f07eu, 0x00000000u}, + {0x001701ecu, 0x00460193u, 0x037bff2bu, 0xff3ffe8cu, 0xfeaf0051u, 0x0267f4e8u, 0x0431f5f7u, 0x00000000u}, + {0x0a960051u, 0x03bc0024u, 0x006cfc58u, 0xfd8ffdd4u, 0xfe8d0c92u, 0x1a07fb81u, 0x0f75fcffu, 0x00000000u}, + {0x0671040eu, 0x04d20135u, 0xfb93f5c7u, 0x059408d8u, 0xfb2df4dcu, 0x144eefe3u, 0xee7008cau, 0x00000000u}, + {0x01a40301u, 0x02b918e1u, 0xeeb4fb8fu, 0x0cc605b8u, 0xef8afbc6u, 0x0a3ff221u, 0xf2cd27e8u, 0x00000000u}, + {0x01120232u, 0x017d0004u, 0xff9efceeu, 0x0045039du, 0xffaffd7au, 0x0849f425u, 0xf63f0109u, 0x00000000u}, + {0x00ac008cu, 0x00200552u, 0xfc97fecau, 0x03c80086u, 0xfe5cff6bu, 0x068ffa16u, 0xfd281273u, 0x00000000u}, + {0x059b042au, 0x000a0001u, 0xffc4f656u, 0x0045ff30u, 0x000600f2u, 0x12f0efacu, 0x01980075u, 0x00000000u}, + {0x00a401dau, 0x005d00bdu, 0xfdaafdd2u, 0x0160fe5du, 0x010900f7u, 0x0667f51eu, 0x04d106deu, 0x00000000u}, + {0x04f500aeu, 0x02730377u, 0xfceefc54u, 0x084afd6bu, 0x05d406f9u, 0x11d0f966u, 0x0c860ee4u, 0x00000000u}, + {0x007c00c7u, 0x02d10016u, 0x0083fec6u, 0xff99fd0au, 0xff070256u, 0x0591f8f1u, 0x0d6efdaeu, 0x00000000u}, + {0x010100b9u, 0x0d1300dfu, 0xfe6afe4cu, 0x01def9dau, 0x06bf073du, 0xf7fe06ceu, 0xe312f889u, 0x00000000u}, + {0x044500f7u, 0x026e0208u, 0xfd33fbf1u, 0x05e4fcf0u, 0x04720671u, 0xef7907dcu, 0xf388f498u, 0x00000000u}, + {0x001401b0u, 0x00130443u, 0xfaa2ff47u, 0x0126ff49u, 0x01230027u, 0xfdc60a66u, 0xfdccef7cu, 0x00000000u}, + {0x2d86021fu, 0x00a30544u, 0xf951ec59u, 0x1ef6fdadu, 0x03a90ac3u, 0xca060ba7u, 0xf99eeda5u, 0x00000000u}, + {0x00b60009u, 0x078c0092u, 0x00470050u, 0x0145fefcu, 0xfbdbfb5fu, 0xf942fe85u, 0x15fbf9f8u, 0x00000000u}, + {0x01ac000fu, 0x00bc0a17u, 0xfe79ff61u, 0x08370069u, 0xfa8ffdc9u, 0xf5a801ecu, 0x06dae697u, 0x00000000u}, + {0x0220000fu, 0x00250174u, 0xff6bff4cu, 0x0384002fu, 0xff16fee4u, 0xf45601eeu, 0x030af65cu, 0x00000000u}, + {0x08db00cbu, 0x057c07abu, 0xfb11fab2u, 0x107c042cu, 0xf308f210u, 0xe8310721u, 0x12bce9d8u, 0x00000000u}, + {0x00500003u, 0x02060089u, 0x0028ffe2u, 0xff2effb3u, 0xfdea0198u, 0xfb8500d8u, 0xf49e05dcu, 0x00000000u}, + {0x0032002fu, 0x078d02f7u, 0x017b0061u, 0x0185fda3u, 0xf689fd94u, 0x03860371u, 0xea040dc7u, 0x00000000u}, + {0x07b4031cu, 0x07df0274u, 0x0586f636u, 0xf74ef61bu, 0xf7360f93u, 0xe9cc0e1bu, 0xe98e0c88u, 0x00000000u}, + {0x00380294u, 0x03b10023u, 0xfecffe7eu, 0x0059f9d4u, 0x016c01cdu, 0xfc400cd9u, 0xf0a2fd09u, 0x00000000u}, + {0x00650004u, 0x002002deu, 0xff910029u, 0xfddeffe9u, 0x0131ff8fu, 0xfaf7fefau, 0x02d00d8cu, 0x00000000u}, + {0x00140081u, 0x01800014u, 0x0065ff9bu, 0xffd901beu, 0x00adff51u, 0xfdc605b0u, 0x09cc0236u, 0x00000000u}, + {0x00a900abu, 0x00260022u, 0xff66feabu, 0x0099ff5fu, 0x004800a0u, 0xf97e068cu, 0xfcebfd11u, 0x00000000u}, + {0x04f40161u, 0x00110121u, 0x027ffac5u, 0xfb45ff65u, 0xff730127u, 0xee320966u, 0xfdef0880u, 0x00000000u}, + {0x01240001u, 0x0ad70052u, 0xffec0026u, 0xfecbff8au, 0x03bbf8f9u, 0x088a0090u, 0xe5a9fb78u, 0x00000000u}, + {0x051c0005u, 0x006308a5u, 0xff35009cu, 0xf2b6ffd5u, 0x03a9fd30u, 0x12150115u, 0xfb05e87bu, 0x00000000u}, + {0x0054001fu, 0x00630068u, 0xff8e0066u, 0xff45ff91u, 0x00cbff4au, 0x049302ccu, 0xfb05fae5u, 0x00000000u}, + {0x036800bau, 0x02b0000au, 0xffa90325u, 0xff44fd35u, 0x00a7f9f3u, 0x0ec306d0u, 0xf2e2fe69u, 0x00000000u}, + {0x00740007u, 0x0191037eu, 0xff660037u, 0xfd7b0067u, 0xfb5201b0u, 0x05640149u, 0x0a03f10du, 0x00000000u}, + {0x010200b0u, 0x07a514d6u, 0xf86e01aau, 0xf6d50496u, 0xe6c2058eu, 0x080906a2u, 0x161fdb7bu, 0x00000000u}, + {0x122400bfu, 0x01d1041fu, 0xfc7f075au, 0xeeb50253u, 0xfa870b7au, 0x221306e8u, 0x0ac7efc2u, 0x00000000u}, + {0x02a3024du, 0x00980167u, 0xfc6904edu, 0xfc280257u, 0xfe2d0281u, 0x0cfd0c22u, 0x062bf688u, 0x00000000u}, + {0x03b90011u, 0x00420072u, 0xffa8ff00u, 0x02930043u, 0xff52fe08u, 0x0f70fdeeu, 0xfbec0556u, 0x00000000u}, + {0x135a0000u, 0x000000a9u, 0x00070025u, 0x07260000u, 0x000a0036u, 0x23310021u, 0x00310680u, 0x00000000u}, + {0x0057015cu, 0x0018013cu, 0x0297015cu, 0x014cff49u, 0xff52ffa4u, 0x04ab0952u, 0xfd8d08e3u, 0x00000000u}, + {0x089402ecu, 0x0b900223u, 0x05000a04u, 0x0890f45fu, 0xf60fec15u, 0x176e0daeu, 0xe4cc0bb2u, 0x00000000u}, + {0x01920099u, 0x01440060u, 0x00f201f0u, 0x018801beu, 0x016002d2u, 0x0a060631u, 0x090104e3u, 0x00000000u}, + {0x028600bdu, 0x11b60009u, 0x005102bcu, 0x0095073eu, 0x018b0d5fu, 0x0cb606e2u, 0x21ab0178u, 0x00000000u}, + {0x04c00133u, 0x002511bbu, 0x093804c6u, 0x125a00d5u, 0x033401a9u, 0x116f08c2u, 0x030b21b0u, 0x00000000u}, + {0x1ccd01bcu, 0x04700678u, 0x06b30e22u, 0x1b4c058du, 0x0ab7169du, 0x2aef0a89u, 0x10db1458u, 0x00000000u}, + {0x031d0a02u, 0x00860012u, 0x01acf4d5u, 0xff11fb6bu, 0xff9e028fu, 0xf1e2194fu, 0xfa35021eu, 0x00000000u}, + {0x07b20d25u, 0x037d05f9u, 0xee48ebe3u, 0x0d8ff275u, 0x09210a5du, 0xe9ce1d01u, 0xf10fec73u, 0x00000000u}, + {0x027c1764u, 0x0052032bu, 0xeec9f0c0u, 0x059c057au, 0xfdfcfe37u, 0xf36326b1u, 0x0488f1c4u, 0x00000000u}, + {0x09b53f89u, 0x0024039au, 0xe1bdce55u, 0x0bd405f0u, 0xfe96fdaeu, 0xe7143fc4u, 0x02fbf0d0u, 0x00000000u}, + {0x085f02adu, 0x00740061u, 0xfdfef689u, 0x038e0233u, 0xff2cfc1bu, 0xe8db0d16u, 0x0562fb16u, 0x00000000u}, + {0x00d60479u, 0x01360053u, 0xfd97fc23u, 0x010b04a6u, 0xfebffdfeu, 0xf8b010eau, 0x08ccfb71u, 0x00000000u}, + {0x000006c8u, 0x078c0344u, 0xf696ffebu, 0x000e0e4fu, 0xf612ffeau, 0xffe014d6u, 0x15faf18au, 0x00000000u}, + {0x000e2ec1u, 0x0b1b0052u, 0xf846033fu, 0xffbb2d92u, 0xfc3c0195u, 0x01e636b3u, 0x1aa8fb7bu, 0x00000000u}, + {0x001c04b1u, 0x02250594u, 0x0a3bfe92u, 0xfe71f9a8u, 0xf91500f7u, 0xfd5d1153u, 0xf44812e4u, 0x00000000u}, + {0x045105fcu, 0x00020c84u, 0x114ff5d6u, 0xf14dff8du, 0xff590062u, 0xef621391u, 0xff441c4du, 0x00000000u}, + {0x126714f3u, 0x02200415u, 0x127ed8bbu, 0xeeabf2a8u, 0xfa1c0c82u, 0xddae249eu, 0xf457102au, 0x00000000u}, + {0x04302522u, 0x049002adu, 0x13efe710u, 0xf94ee5f7u, 0xf90308beu, 0xefa130c0u, 0xeee90d16u, 0x00000000u}, + {0x01a00381u, 0x08470229u, 0x0580fb3au, 0xfc410ac6u, 0x0874f8abu, 0xf5ce0efau, 0x17040bc1u, 0x00000000u}, + {0x0d100bf5u, 0x0469013cu, 0x07aee702u, 0xf7f90e86u, 0x04aaf0d2u, 0xe3161ba9u, 0x10cd08e2u, 0x00000000u}, + {0x005c121du, 0x04e800c3u, 0x076cfae7u, 0xfef512dau, 0x03ddfd59u, 0xfb36220cu, 0x11b806fau, 0x00000000u}, + {0x0001158fu, 0x00030f91u, 0x24a3ff81u, 0xff940107u, 0x00dffffdu, 0xff922525u, 0x00e21f90u, 0x00000000u}, + {0x13ad03efu, 0x02800d69u, 0xf17a1198u, 0xdf84f9bbu, 0x0b94f1fau, 0x237c0fddu, 0xf35ae2b5u, 0x00000000u}, + {0x00110448u, 0x04650906u, 0xf391010eu, 0xfe79f753u, 0x0c98feefu, 0x0209108eu, 0xef3be7f7u, 0x00000000u}, + {0x087a075du, 0x0133019eu, 0xf9190fccu, 0xf898fa0fu, 0x02c9f9a0u, 0x174a15b5u, 0xf73df5d3u, 0x00000000u}, + {0x007d14abu, 0x0f9b0385u, 0xeef2065au, 0xfd61dc15u, 0x0ed2fa7bu, 0x0596245fu, 0xe066f0feu, 0x00000000u}, + {0x002406dbu, 0x005c001bu, 0xfe4e01f4u, 0xffc2fcdcu, 0x0063ff8eu, 0x02fc14f3u, 0xfb35fd69u, 0x00000000u}, + {0x04d9072bu, 0x00a4117fu, 0xe99a0bcau, 0xed940448u, 0xf9500385u, 0x119e156bu, 0x0665de89u, 0x00000000u}, + {0x002e0b20u, 0x00000568u, 0xf07d02d5u, 0xfe060024u, 0xffe70005u, 0x03661aafu, 0x002bed66u, 0x00000000u}, + {0x07812417u, 0x0017028du, 0xecd020e9u, 0xf740fc60u, 0x00f7fe59u, 0x15ea300fu, 0xfd96f339u, 0x00000000u}, + {0x01780dffu, 0x05490027u, 0x02e90911u, 0x00f1eecdu, 0xfe36fa6eu, 0x09b21deeu, 0xed9c031du, 0x00000000u}, + {0x10810f26u, 0x010a06c4u, 0x14401fa0u, 0x1523f811u, 0xfab2f7b7u, 0x20801f23u, 0xf7d814d0u, 0x00000000u}, + {0x009217d3u, 0x000001fdu, 0x0dc4075fu, 0x0221ff93u, 0xffe1ffefu, 0x060b270cu, 0xffa70b48u, 0x00000000u}, + {0x093c4515u, 0x0003013bu, 0x12703284u, 0x06befe48u, 0xffc5ff5fu, 0x1850427eu, 0xff2c08dfu, 0x00000000u}, + {0x07f20371u, 0x003f00a5u, 0x02fb0a75u, 0x048801d6u, 0x00cc02cau, 0x168c0ed7u, 0x03f6066eu, 0x00000000u}, + {0x00540457u, 0x012104ccu, 0x09200263u, 0x0283046cu, 0x04a70138u, 0x049610aau, 0x087e1186u, 0x00000000u}, + {0x010d0bb2u, 0x006a0003u, 0x00b40701u, 0x00360466u, 0x00220151u, 0x08321b5bu, 0x052500d2u, 0x00000000u}, + {0x0e5a0c57u, 0x04f30003u, 0x00cd1a9eu, 0x00dd0fa1u, 0x008210dbu, 0x1e4e1c1au, 0x11cc00e9u, 0x00000000u}, +}; +const xombe_cq_q15_tab xombe__cq_q15_dstar = { + r24_dstar, r58_dstar, 13, 14, 16, 15, + {3.20227051f, 1.04541016f, 0.622802734f, 1.97290039f, 1.57299805f, 0.998535156f}, {1.78948975f, 1.02246094f, + 0.78918457f}, {0.269851685f, 0.177825928f, 0.0971832275f, 0.0717010498f, 0.209259033f, 0.215713501f, + 0.178009033f, 0.12689209f, 0.141235352f, 0.0986022949f}, {0.519470215f, 0.421691895f, 0.311767578f, + 0.26776123f}, 3.2820518f, 0.3107723f, 128, {-1.49226427f, 0.642354965f, -2.32282948f, 0.744157016f}, + {{4.78123951f, 0.110020585f, 0.368776828f, -0.266162425f}, {0.110020585f, 2.6756959f, 0.101844303f, + 0.212454453f}, {0.368776828f, 0.101844303f, 1.93063045f, -0.06583976f}, {-0.266162425f, 0.212454453f, + -0.06583976f, 1.48771954f}}}; +#endif +#else +typedef int xombe__cq_q15_tables_unused; +#endif diff --git a/xombe/src/tables/cq_q15_tables.h b/xombe/src/tables/cq_q15_tables.h new file mode 100644 index 0000000..b13be64 --- /dev/null +++ b/xombe/src/tables/cq_q15_tables.h @@ -0,0 +1,27 @@ +#ifndef XOMBE_CQ_Q15_TABLES_H +#define XOMBE_CQ_Q15_TABLES_H + +/* int16 images of one set's PRBA codebooks for the q15 closed-loop quantizer's bounds (cquant.c), generated by + scripts/gen_cq_tables.py. entries are rounded to nearest, so each is within 1/2 unit of its exact value + r24 row i, pairs: (x0^2, x1^2), (x2^2, 2 x0 x1), (2 x0 x2, 2 x1 x2) at 2^-tm24, then (x0, x1), (x2, 0) at 2^-tx24 + r58 row j, pairs: (x0^2, x1^2), (x2^2, x3^2), (2 x0 x1, 2 x0 x2), (2 x0 x3, 2 x1 x2), (2 x1 x3, 2 x2 x3) at 2^-tm58, + then (x0, x1), (x2, x3) at 2^-tx58, and a zero pair */ + +#include +#include "../internal.h" + +typedef struct { + const uint32_t (*r24)[5]; + const uint32_t (*r58)[8]; + int tm24, tx24, tm58, tx58; + float m24[6], x24[3]; /* max |entry| of each column over all rows, real units */ + float m58[10], x58[4]; + float n3, n4; /* max |x|^2 over the usable rows, rounded up */ + int cnt; /* usable prba58 rows: count, sums, and sums of products */ + float sx[4], sxx[4][4]; +} xombe_cq_q15_tab; + +extern const xombe_cq_q15_tab xombe__cq_q15_ambe2; +extern const xombe_cq_q15_tab xombe__cq_q15_dstar; + +#endif diff --git a/xombe/src/tables/dsp_tables.c b/xombe/src/tables/dsp_tables.c new file mode 100644 index 0000000..284d7a3 --- /dev/null +++ b/xombe/src/tables/dsp_tables.c @@ -0,0 +1,664 @@ +/* generated by scripts/gen_dsp_tables.py, do not edit */ +#include "dsp_tables.h" + +const float xombe__dct8[8][8] = { + {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, + {0.980785251f, 0.831469595f, 0.555570245f, 0.195090324f, -0.195090324f, -0.555570245f, -0.831469595f, -0.980785251f}, + {0.923879504f, 0.382683426f, -0.382683426f, -0.923879504f, -0.923879504f, -0.382683426f, 0.382683426f, 0.923879504f}, + {0.831469595f, -0.195090324f, -0.980785251f, -0.555570245f, 0.555570245f, 0.980785251f, 0.195090324f, -0.831469595f}, + {0.707106769f, -0.707106769f, -0.707106769f, 0.707106769f, 0.707106769f, -0.707106769f, -0.707106769f, 0.707106769f}, + {0.555570245f, -0.980785251f, 0.195090324f, 0.831469595f, -0.831469595f, -0.195090324f, 0.980785251f, -0.555570245f}, + {0.382683426f, -0.923879504f, 0.923879504f, -0.382683426f, -0.382683426f, 0.923879504f, -0.923879504f, 0.382683426f}, + {0.195090324f, -0.555570245f, 0.831469595f, -0.980785251f, 0.980785251f, -0.831469595f, 0.555570245f, -0.195090324f}, +}; + +const unsigned short xombe__dct_blk_off[XOMBE_DCT_BLK_J_MAX + 1] = { + 0, 0, 6, 18, 36, 60, 90, 126, 168, 216, 270, 330, + 396, 468, 546, 630, 720, 816, +}; + +const float xombe__dct_blk[XOMBE_DCT_BLK_SIZE] = { + 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 1.0f, 0.707106769f, -0.707106769f, 0.0f, 0.0f, + -0.707106769f, 0.707106769f, -1.0f, -1.0f, -0.707106769f, 0.707106769f, + 1.0f, 1.0f, 1.0f, 0.866025388f, 0.0f, -0.866025388f, + 0.5f, -1.0f, 0.5f, 0.0f, 0.0f, 0.0f, + -0.5f, 1.0f, -0.5f, -0.866025388f, 0.0f, 0.866025388f, + 1.0f, 1.0f, 1.0f, 1.0f, 0.923879504f, 0.382683426f, + -0.382683426f, -0.923879504f, 0.707106769f, -0.707106769f, -0.707106769f, 0.707106769f, + 0.382683426f, -0.923879504f, 0.923879504f, -0.382683426f, 0.0f, 0.0f, + 0.0f, 0.0f, -0.382683426f, 0.923879504f, -0.923879504f, 0.382683426f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.95105654f, + 0.587785244f, 0.0f, -0.587785244f, -0.95105654f, 0.809017003f, -0.309017003f, + -1.0f, -0.309017003f, 0.809017003f, 0.587785244f, -0.95105654f, 0.0f, + 0.95105654f, -0.587785244f, 0.309017003f, -0.809017003f, 1.0f, -0.809017003f, + 0.309017003f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 0.965925813f, 0.707106769f, 0.258819044f, -0.258819044f, -0.707106769f, -0.965925813f, + 0.866025388f, 0.0f, -0.866025388f, -0.866025388f, 0.0f, 0.866025388f, + 0.707106769f, -0.707106769f, -0.707106769f, 0.707106769f, 0.707106769f, -0.707106769f, + 0.5f, -1.0f, 0.5f, 0.5f, -1.0f, 0.5f, + 0.258819044f, -0.707106769f, 0.965925813f, -0.965925813f, 0.707106769f, -0.258819044f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 0.974927902f, 0.781831503f, 0.433883727f, 0.0f, -0.433883727f, + -0.781831503f, -0.974927902f, 0.90096885f, 0.222520933f, -0.623489797f, -1.0f, + -0.623489797f, 0.222520933f, 0.90096885f, 0.781831503f, -0.433883727f, -0.974927902f, + 0.0f, 0.974927902f, 0.433883727f, -0.781831503f, 0.623489797f, -0.90096885f, + -0.222520933f, 1.0f, -0.222520933f, -0.90096885f, 0.623489797f, 0.433883727f, + -0.974927902f, 0.781831503f, 0.0f, -0.781831503f, 0.974927902f, -0.433883727f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 0.980785251f, 0.831469595f, 0.555570245f, 0.195090324f, + -0.195090324f, -0.555570245f, -0.831469595f, -0.980785251f, 0.923879504f, 0.382683426f, + -0.382683426f, -0.923879504f, -0.923879504f, -0.382683426f, 0.382683426f, 0.923879504f, + 0.831469595f, -0.195090324f, -0.980785251f, -0.555570245f, 0.555570245f, 0.980785251f, + 0.195090324f, -0.831469595f, 0.707106769f, -0.707106769f, -0.707106769f, 0.707106769f, + 0.707106769f, -0.707106769f, -0.707106769f, 0.707106769f, 0.555570245f, -0.980785251f, + 0.195090324f, 0.831469595f, -0.831469595f, -0.195090324f, 0.980785251f, -0.555570245f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 0.98480773f, 0.866025388f, 0.642787635f, + 0.342020154f, 0.0f, -0.342020154f, -0.642787635f, -0.866025388f, -0.98480773f, + 0.939692616f, 0.5f, -0.173648179f, -0.766044438f, -1.0f, -0.766044438f, + -0.173648179f, 0.5f, 0.939692616f, 0.866025388f, 0.0f, -0.866025388f, + -0.866025388f, 0.0f, 0.866025388f, 0.866025388f, 0.0f, -0.866025388f, + 0.766044438f, -0.5f, -0.939692616f, 0.173648179f, 1.0f, 0.173648179f, + -0.939692616f, -0.5f, 0.766044438f, 0.642787635f, -0.866025388f, -0.342020154f, + 0.98480773f, 0.0f, -0.98480773f, 0.342020154f, 0.866025388f, -0.642787635f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 0.987688363f, 0.891006529f, + 0.707106769f, 0.453990489f, 0.156434461f, -0.156434461f, -0.453990489f, -0.707106769f, + -0.891006529f, -0.987688363f, 0.95105654f, 0.587785244f, 0.0f, -0.587785244f, + -0.95105654f, -0.95105654f, -0.587785244f, 0.0f, 0.587785244f, 0.95105654f, + 0.891006529f, 0.156434461f, -0.707106769f, -0.987688363f, -0.453990489f, 0.453990489f, + 0.987688363f, 0.707106769f, -0.156434461f, -0.891006529f, 0.809017003f, -0.309017003f, + -1.0f, -0.309017003f, 0.809017003f, 0.809017003f, -0.309017003f, -1.0f, + -0.309017003f, 0.809017003f, 0.707106769f, -0.707106769f, -0.707106769f, 0.707106769f, + 0.707106769f, -0.707106769f, -0.707106769f, 0.707106769f, 0.707106769f, -0.707106769f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.989821434f, + 0.909631968f, 0.755749583f, 0.540640831f, 0.281732559f, 0.0f, -0.281732559f, + -0.540640831f, -0.755749583f, -0.909631968f, -0.989821434f, 0.959492981f, 0.654860735f, + 0.142314836f, -0.415415019f, -0.841253519f, -1.0f, -0.841253519f, -0.415415019f, + 0.142314836f, 0.654860735f, 0.959492981f, 0.909631968f, 0.281732559f, -0.540640831f, + -0.989821434f, -0.755749583f, 0.0f, 0.755749583f, 0.989821434f, 0.540640831f, + -0.281732559f, -0.909631968f, 0.841253519f, -0.142314836f, -0.959492981f, -0.654860735f, + 0.415415019f, 1.0f, 0.415415019f, -0.654860735f, -0.959492981f, -0.142314836f, + 0.841253519f, 0.755749583f, -0.540640831f, -0.909631968f, 0.281732559f, 0.989821434f, + 0.0f, -0.989821434f, -0.281732559f, 0.909631968f, 0.540640831f, -0.755749583f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 0.991444886f, 0.923879504f, 0.793353319f, 0.60876143f, 0.382683426f, 0.130526185f, + -0.130526185f, -0.382683426f, -0.60876143f, -0.793353319f, -0.923879504f, -0.991444886f, + 0.965925813f, 0.707106769f, 0.258819044f, -0.258819044f, -0.707106769f, -0.965925813f, + -0.965925813f, -0.707106769f, -0.258819044f, 0.258819044f, 0.707106769f, 0.965925813f, + 0.923879504f, 0.382683426f, -0.382683426f, -0.923879504f, -0.923879504f, -0.382683426f, + 0.382683426f, 0.923879504f, 0.923879504f, 0.382683426f, -0.382683426f, -0.923879504f, + 0.866025388f, 0.0f, -0.866025388f, -0.866025388f, 0.0f, 0.866025388f, + 0.866025388f, 0.0f, -0.866025388f, -0.866025388f, 0.0f, 0.866025388f, + 0.793353319f, -0.382683426f, -0.991444886f, -0.130526185f, 0.923879504f, 0.60876143f, + -0.60876143f, -0.923879504f, 0.130526185f, 0.991444886f, 0.382683426f, -0.793353319f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 0.992708862f, 0.935016215f, 0.822983861f, 0.663122654f, 0.46472317f, + 0.239315659f, 0.0f, -0.239315659f, -0.46472317f, -0.663122654f, -0.822983861f, + -0.935016215f, -0.992708862f, 0.970941842f, 0.748510778f, 0.3546049f, -0.120536678f, + -0.568064749f, -0.885456026f, -1.0f, -0.885456026f, -0.568064749f, -0.120536678f, + 0.3546049f, 0.748510778f, 0.970941842f, 0.935016215f, 0.46472317f, -0.239315659f, + -0.822983861f, -0.992708862f, -0.663122654f, 0.0f, 0.663122654f, 0.992708862f, + 0.822983861f, 0.239315659f, -0.46472317f, -0.935016215f, 0.885456026f, 0.120536678f, + -0.748510778f, -0.970941842f, -0.3546049f, 0.568064749f, 1.0f, 0.568064749f, + -0.3546049f, -0.970941842f, -0.748510778f, 0.120536678f, 0.885456026f, 0.822983861f, + -0.239315659f, -0.992708862f, -0.46472317f, 0.663122654f, 0.935016215f, 0.0f, + -0.935016215f, -0.663122654f, 0.46472317f, 0.992708862f, 0.239315659f, -0.822983861f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 0.993712187f, 0.943883359f, 0.846724212f, 0.707106769f, + 0.532032073f, 0.330279052f, 0.111964479f, -0.111964479f, -0.330279052f, -0.532032073f, + -0.707106769f, -0.846724212f, -0.943883359f, -0.993712187f, 0.974927902f, 0.781831503f, + 0.433883727f, 0.0f, -0.433883727f, -0.781831503f, -0.974927902f, -0.974927902f, + -0.781831503f, -0.433883727f, 0.0f, 0.433883727f, 0.781831503f, 0.974927902f, + 0.943883359f, 0.532032073f, -0.111964479f, -0.707106769f, -0.993712187f, -0.846724212f, + -0.330279052f, 0.330279052f, 0.846724212f, 0.993712187f, 0.707106769f, 0.111964479f, + -0.532032073f, -0.943883359f, 0.90096885f, 0.222520933f, -0.623489797f, -1.0f, + -0.623489797f, 0.222520933f, 0.90096885f, 0.90096885f, 0.222520933f, -0.623489797f, + -1.0f, -0.623489797f, 0.222520933f, 0.90096885f, 0.846724212f, -0.111964479f, + -0.943883359f, -0.707106769f, 0.330279052f, 0.993712187f, 0.532032073f, -0.532032073f, + -0.993712187f, -0.330279052f, 0.707106769f, 0.943883359f, 0.111964479f, -0.846724212f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 0.994521916f, 0.95105654f, 0.866025388f, + 0.74314481f, 0.587785244f, 0.406736642f, 0.207911685f, 0.0f, -0.207911685f, + -0.406736642f, -0.587785244f, -0.74314481f, -0.866025388f, -0.95105654f, -0.994521916f, + 0.978147626f, 0.809017003f, 0.5f, 0.104528464f, -0.309017003f, -0.669130623f, + -0.91354543f, -1.0f, -0.91354543f, -0.669130623f, -0.309017003f, 0.104528464f, + 0.5f, 0.809017003f, 0.978147626f, 0.95105654f, 0.587785244f, 0.0f, + -0.587785244f, -0.95105654f, -0.95105654f, -0.587785244f, 0.0f, 0.587785244f, + 0.95105654f, 0.95105654f, 0.587785244f, 0.0f, -0.587785244f, -0.95105654f, + 0.91354543f, 0.309017003f, -0.5f, -0.978147626f, -0.809017003f, -0.104528464f, + 0.669130623f, 1.0f, 0.669130623f, -0.104528464f, -0.809017003f, -0.978147626f, + -0.5f, 0.309017003f, 0.91354543f, 0.866025388f, 0.0f, -0.866025388f, + -0.866025388f, 0.0f, 0.866025388f, 0.866025388f, 0.0f, -0.866025388f, + -0.866025388f, 0.0f, 0.866025388f, 0.866025388f, 0.0f, -0.866025388f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 0.99518472f, 0.956940353f, + 0.881921291f, 0.773010433f, 0.634393275f, 0.471396744f, 0.290284663f, 0.0980171412f, + -0.0980171412f, -0.290284663f, -0.471396744f, -0.634393275f, -0.773010433f, -0.881921291f, + -0.956940353f, -0.99518472f, 0.980785251f, 0.831469595f, 0.555570245f, 0.195090324f, + -0.195090324f, -0.555570245f, -0.831469595f, -0.980785251f, -0.980785251f, -0.831469595f, + -0.555570245f, -0.195090324f, 0.195090324f, 0.555570245f, 0.831469595f, 0.980785251f, + 0.956940353f, 0.634393275f, 0.0980171412f, -0.471396744f, -0.881921291f, -0.99518472f, + -0.773010433f, -0.290284663f, 0.290284663f, 0.773010433f, 0.99518472f, 0.881921291f, + 0.471396744f, -0.0980171412f, -0.634393275f, -0.956940353f, 0.923879504f, 0.382683426f, + -0.382683426f, -0.923879504f, -0.923879504f, -0.382683426f, 0.382683426f, 0.923879504f, + 0.923879504f, 0.382683426f, -0.382683426f, -0.923879504f, -0.923879504f, -0.382683426f, + 0.382683426f, 0.923879504f, 0.881921291f, 0.0980171412f, -0.773010433f, -0.956940353f, + -0.290284663f, 0.634393275f, 0.99518472f, 0.471396744f, -0.471396744f, -0.99518472f, + -0.634393275f, 0.290284663f, 0.956940353f, 0.773010433f, -0.0980171412f, -0.881921291f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.995734155f, + 0.961825669f, 0.895163298f, 0.798017204f, 0.673695624f, 0.526432157f, 0.361241668f, + 0.183749512f, 0.0f, -0.183749512f, -0.361241668f, -0.526432157f, -0.673695624f, + -0.798017204f, -0.895163298f, -0.961825669f, -0.995734155f, 0.982973099f, 0.850217164f, + 0.602634609f, 0.273662984f, -0.0922683626f, -0.445738345f, -0.739008904f, -0.932472229f, + -1.0f, -0.932472229f, -0.739008904f, -0.445738345f, -0.0922683626f, 0.273662984f, + 0.602634609f, 0.850217164f, 0.982973099f, 0.961825669f, 0.673695624f, 0.183749512f, + -0.361241668f, -0.798017204f, -0.995734155f, -0.895163298f, -0.526432157f, 0.0f, + 0.526432157f, 0.895163298f, 0.995734155f, 0.798017204f, 0.361241668f, -0.183749512f, + -0.673695624f, -0.961825669f, 0.932472229f, 0.445738345f, -0.273662984f, -0.850217164f, + -0.982973099f, -0.602634609f, 0.0922683626f, 0.739008904f, 1.0f, 0.739008904f, + 0.0922683626f, -0.602634609f, -0.982973099f, -0.850217164f, -0.273662984f, 0.445738345f, + 0.932472229f, 0.895163298f, 0.183749512f, -0.673695624f, -0.995734155f, -0.526432157f, + 0.361241668f, 0.961825669f, 0.798017204f, 0.0f, -0.798017204f, -0.961825669f, + -0.361241668f, 0.526432157f, 0.995734155f, 0.673695624f, -0.183749512f, -0.895163298f, +}; + +const float xombe__ramp_cos[XOMBE_GRAIN_RAMP] = { + 1.0f, 0.980785251f, 0.923879504f, 0.831469595f, 0.707106769f, 0.555570245f, + 0.382683426f, 0.195090324f, 0.0f, -0.195090324f, -0.382683426f, -0.555570245f, + -0.707106769f, -0.831469595f, -0.923879504f, -0.980785251f, +}; + +const float xombe__ramp_sin[XOMBE_GRAIN_RAMP] = { + 0.0f, 0.195090324f, 0.382683426f, 0.555570245f, 0.707106769f, 0.831469595f, + 0.923879504f, 0.980785251f, 1.0f, 0.980785251f, 0.923879504f, 0.831469595f, + 0.707106769f, 0.555570245f, 0.382683426f, 0.195090324f, +}; + +const float xombe__sqrt_n[XOMBE_HALF_MAX + 1] = { + 0.0f, 1.0f, 1.41421354f, 1.73205078f, 2.0f, 2.23606801f, + 2.44948983f, 2.64575124f, 2.82842708f, 3.0f, 3.1622777f, 3.31662488f, + 3.46410155f, 3.60555124f, 3.7416575f, 3.87298346f, 4.0f, 4.12310553f, + 4.2426405f, 4.35889912f, 4.47213602f, 4.5825758f, 4.69041586f, 4.79583168f, + 4.89897966f, 5.0f, 5.09901953f, 5.19615221f, 5.29150248f, 5.38516474f, + 5.47722578f, 5.56776428f, 5.65685415f, 5.74456263f, 5.83095169f, 5.91608f, + 6.0f, 6.08276272f, 6.16441393f, 6.24499798f, 6.3245554f, 6.40312433f, + 6.48074055f, 6.55743837f, 6.63324976f, 6.70820379f, 6.78233004f, 6.85565472f, + 6.92820311f, 7.0f, 7.07106781f, 7.14142847f, 7.21110249f, 7.28010988f, + 7.34846926f, 7.41619825f, 7.48331499f, 7.54983425f, 7.6157732f, 7.68114567f, + 7.74596691f, 7.81024981f, 7.8740077f, 7.93725395f, 8.0f, 8.06225777f, + 8.1240387f, 8.18535233f, 8.24621105f, 8.30662346f, 8.36660004f, 8.42614937f, + 8.48528099f, 8.54400349f, 8.60232544f, 8.66025448f, 8.71779823f, 8.77496433f, + 8.83176041f, 8.88819408f, 8.94427204f, 9.0f, 9.05538559f, 9.11043358f, + 9.1651516f, +}; + +const float xombe__rsqrt_half[XOMBE_HALF_MAX - XOMBE_HALF_MIN + 1] = { + 0.114707865f, 0.113960579f, 0.113227703f, 0.112508789f, 0.111803398f, 0.111111112f, + 0.11043153f, 0.109764263f, 0.109108947f, +}; + +const float xombe__half_log2[XOMBE_LMAX + 1] = { + 0.0f, 0.0f, 0.5f, 0.792481244f, 1.0f, 1.16096401f, + 1.2924813f, 1.40367746f, 1.5f, 1.58496249f, 1.66096401f, 1.72971582f, + 1.7924813f, 1.85021985f, 1.90367746f, 1.95344532f, 2.0f, 2.04373145f, + 2.08496261f, 2.12396383f, 2.16096401f, 2.19615865f, 2.22971582f, 2.26178098f, + 2.29248118f, 2.32192802f, 2.35021996f, 2.37744379f, 2.40367746f, 2.4289906f, + 2.4534452f, 2.47709823f, 2.5f, 2.52219701f, 2.54373145f, 2.56464148f, + 2.58496261f, 2.60472679f, 2.62396383f, 2.64270115f, 2.66096401f, 2.67877603f, + 2.69615865f, 2.71313238f, 2.72971582f, 2.74592662f, 2.76178098f, 2.7772944f, + 2.79248118f, 2.80735493f, 2.82192802f, 2.83621264f, 2.85021996f, 2.86396027f, + 2.87744379f, 2.89067984f, 2.90367746f, +}; + +const float xombe__w0_mid[XOMBE_B0_COUNT - 1] = { + 0.0495915599f, 0.0488415845f, 0.0481036082f, 0.0473730974f, 0.0466531441f, 0.045948673f, + 0.04525166f, 0.0445642062f, 0.0438907295f, 0.0432277471f, 0.0425717421f, 0.0419262908f, + 0.0412927978f, 0.0406663083f, 0.0400503427f, 0.0394463614f, 0.0388523825f, 0.0382638723f, + 0.0376839153f, 0.0371179469f, 0.0365574248f, 0.0360039659f, 0.0354639962f, 0.0349340104f, + 0.0344074927f, 0.0338895433f, 0.033383552f, 0.0328830555f, 0.0323905833f, 0.0319081061f, + 0.0313948058f, 0.0308835879f, 0.0304146204f, 0.0299551319f, 0.0294991173f, 0.0290506631f, + 0.0286121704f, 0.0281796847f, 0.0277511757f, 0.0273292083f, 0.0269162189f, 0.0265072156f, + 0.0261042416f, 0.0257097557f, 0.0253212638f, 0.0249367654f, 0.024558289f, 0.0241862927f, + 0.0238182973f, 0.0234568212f, 0.0231018271f, 0.0227528457f, 0.0224078372f, 0.0220673606f, + 0.0217343736f, 0.0214043651f, 0.0210793931f, 0.0207619015f, 0.0204489082f, 0.0201378986f, + 0.0198329352f, 0.0195344314f, 0.0192394461f, 0.0189489499f, 0.0186619554f, 0.0183804743f, + 0.01810297f, 0.0178299937f, 0.0175630003f, 0.0173000079f, 0.0170400087f, 0.0167835206f, + 0.0165325347f, 0.0162855368f, 0.0160425529f, 0.0158040561f, 0.0155478921f, 0.0152935525f, + 0.0150610572f, 0.0148330731f, 0.0146080665f, 0.014386083f, 0.0141685884f, 0.0139535898f, + 0.0137410956f, 0.0135326087f, 0.0133281136f, 0.0131256115f, 0.0129266288f, 0.0127311265f, + 0.0125386398f, 0.0123481303f, 0.0121601485f, 0.0119771576f, 0.0117946416f, 0.0116151711f, + 0.0114401653f, 0.0112676797f, 0.0110966666f, 0.0109276846f, 0.0107626878f, 0.0105986828f, + 0.0104377009f, 0.0102802003f, 0.0101257144f, 0.00997219887f, 0.00982072111f, 0.00967322104f, + 0.00952621643f, 0.00938223489f, 0.00924173463f, 0.00910223462f, 0.00896423776f, 0.00882874615f, + 0.0086972611f, 0.00856674556f, 0.00843776483f, 0.00831176154f, 0.00818676502f, +}; + +const xombe_cpx xombe__fft_tw[XOMBE_TW_N / 2] = { + {1.0f, 0.0f}, {0.999981165f, -0.00613588467f}, {0.999924719f, -0.0122715384f}, + {0.999830604f, -0.0184067301f}, {0.999698818f, -0.024541229f}, {0.999529421f, -0.030674804f}, + {0.999322355f, -0.0368072242f}, {0.999077737f, -0.0429382585f}, {0.99879545f, -0.0490676761f}, + {0.998475552f, -0.0551952459f}, {0.998118103f, -0.061320737f}, {0.997723043f, -0.0674439222f}, + {0.997290432f, -0.0735645667f}, {0.996820271f, -0.0796824396f}, {0.996312618f, -0.0857973099f}, + {0.995767415f, -0.0919089541f}, {0.99518472f, -0.0980171412f}, {0.994564593f, -0.104121633f}, + {0.993906975f, -0.110222206f}, {0.993211925f, -0.116318628f}, {0.992479563f, -0.122410677f}, + {0.991709769f, -0.128498107f}, {0.990902662f, -0.134580702f}, {0.990058184f, -0.140658244f}, + {0.989176512f, -0.146730468f}, {0.988257587f, -0.152797192f}, {0.987301409f, -0.15885815f}, + {0.986308098f, -0.164913118f}, {0.985277653f, -0.170961887f}, {0.984210074f, -0.177004218f}, + {0.983105481f, -0.183039889f}, {0.981963873f, -0.18906866f}, {0.980785251f, -0.195090324f}, + {0.979569793f, -0.201104641f}, {0.97831738f, -0.207111374f}, {0.977028131f, -0.213110313f}, + {0.975702107f, -0.219101235f}, {0.974339366f, -0.225083917f}, {0.972939968f, -0.231058106f}, + {0.971503913f, -0.237023607f}, {0.970031261f, -0.242980182f}, {0.968522072f, -0.248927608f}, + {0.966976464f, -0.254865646f}, {0.965394437f, -0.260794103f}, {0.963776052f, -0.266712755f}, + {0.962121427f, -0.272621363f}, {0.960430503f, -0.27851969f}, {0.958703458f, -0.284407526f}, + {0.956940353f, -0.290284663f}, {0.955141187f, -0.296150893f}, {0.953306019f, -0.302005947f}, + {0.95143503f, -0.307849646f}, {0.949528158f, -0.313681751f}, {0.947585583f, -0.319502026f}, + {0.945607305f, -0.32531029f}, {0.943593442f, -0.331106305f}, {0.941544056f, -0.336889863f}, + {0.939459205f, -0.342660725f}, {0.937339008f, -0.348418683f}, {0.935183525f, -0.354163527f}, + {0.932992816f, -0.359895051f}, {0.93076694f, -0.365612984f}, {0.928506076f, -0.371317208f}, + {0.926210225f, -0.377007425f}, {0.923879504f, -0.382683426f}, {0.921514034f, -0.388345033f}, + {0.919113874f, -0.393992037f}, {0.916679084f, -0.399624199f}, {0.914209783f, -0.405241311f}, + {0.91170603f, -0.410843164f}, {0.909168005f, -0.416429549f}, {0.906595707f, -0.422000259f}, + {0.903989315f, -0.427555084f}, {0.901348829f, -0.433093816f}, {0.898674488f, -0.438616246f}, + {0.895966232f, -0.444122136f}, {0.893224299f, -0.449611336f}, {0.890448749f, -0.455083579f}, + {0.887639642f, -0.460538715f}, {0.884797096f, -0.465976506f}, {0.881921291f, -0.471396744f}, + {0.879012227f, -0.47679922f}, {0.876070082f, -0.482183784f}, {0.873094976f, -0.487550169f}, + {0.870086968f, -0.492898196f}, {0.867046237f, -0.498227656f}, {0.863972843f, -0.50353837f}, + {0.860866964f, -0.50883013f}, {0.857728601f, -0.514102757f}, {0.854557991f, -0.519356012f}, + {0.851355195f, -0.524589658f}, {0.848120332f, -0.529803634f}, {0.84485358f, -0.534997642f}, + {0.841554999f, -0.540171444f}, {0.838224709f, -0.545324981f}, {0.834862888f, -0.550457954f}, + {0.831469595f, -0.555570245f}, {0.82804507f, -0.560661554f}, {0.824589312f, -0.565731823f}, + {0.8211025f, -0.570780754f}, {0.817584813f, -0.575808167f}, {0.81403631f, -0.580813944f}, + {0.81045717f, -0.585797846f}, {0.806847572f, -0.590759695f}, {0.803207517f, -0.59569931f}, + {0.799537241f, -0.600616455f}, {0.795836926f, -0.605511069f}, {0.792106569f, -0.610382795f}, + {0.78834641f, -0.615231574f}, {0.784556568f, -0.620057225f}, {0.780737221f, -0.624859512f}, + {0.77688849f, -0.629638255f}, {0.773010433f, -0.634393275f}, {0.769103348f, -0.639124453f}, + {0.765167236f, -0.643831551f}, {0.761202395f, -0.64851439f}, {0.757208824f, -0.653172851f}, + {0.753186822f, -0.657806695f}, {0.749136388f, -0.662415802f}, {0.745057762f, -0.666999936f}, + {0.740951121f, -0.671558976f}, {0.736816585f, -0.676092684f}, {0.732654274f, -0.680601001f}, + {0.728464365f, -0.685083687f}, {0.724247098f, -0.689540565f}, {0.720002532f, -0.693971455f}, + {0.715730846f, -0.698376238f}, {0.711432219f, -0.702754736f}, {0.707106769f, -0.707106769f}, + {0.702754736f, -0.711432219f}, {0.698376238f, -0.715730846f}, {0.693971455f, -0.720002532f}, + {0.689540565f, -0.724247098f}, {0.685083687f, -0.728464365f}, {0.680601001f, -0.732654274f}, + {0.676092684f, -0.736816585f}, {0.671558976f, -0.740951121f}, {0.666999936f, -0.745057762f}, + {0.662415802f, -0.749136388f}, {0.657806695f, -0.753186822f}, {0.653172851f, -0.757208824f}, + {0.64851439f, -0.761202395f}, {0.643831551f, -0.765167236f}, {0.639124453f, -0.769103348f}, + {0.634393275f, -0.773010433f}, {0.629638255f, -0.77688849f}, {0.624859512f, -0.780737221f}, + {0.620057225f, -0.784556568f}, {0.615231574f, -0.78834641f}, {0.610382795f, -0.792106569f}, + {0.605511069f, -0.795836926f}, {0.600616455f, -0.799537241f}, {0.59569931f, -0.803207517f}, + {0.590759695f, -0.806847572f}, {0.585797846f, -0.81045717f}, {0.580813944f, -0.81403631f}, + {0.575808167f, -0.817584813f}, {0.570780754f, -0.8211025f}, {0.565731823f, -0.824589312f}, + {0.560661554f, -0.82804507f}, {0.555570245f, -0.831469595f}, {0.550457954f, -0.834862888f}, + {0.545324981f, -0.838224709f}, {0.540171444f, -0.841554999f}, {0.534997642f, -0.84485358f}, + {0.529803634f, -0.848120332f}, {0.524589658f, -0.851355195f}, {0.519356012f, -0.854557991f}, + {0.514102757f, -0.857728601f}, {0.50883013f, -0.860866964f}, {0.50353837f, -0.863972843f}, + {0.498227656f, -0.867046237f}, {0.492898196f, -0.870086968f}, {0.487550169f, -0.873094976f}, + {0.482183784f, -0.876070082f}, {0.47679922f, -0.879012227f}, {0.471396744f, -0.881921291f}, + {0.465976506f, -0.884797096f}, {0.460538715f, -0.887639642f}, {0.455083579f, -0.890448749f}, + {0.449611336f, -0.893224299f}, {0.444122136f, -0.895966232f}, {0.438616246f, -0.898674488f}, + {0.433093816f, -0.901348829f}, {0.427555084f, -0.903989315f}, {0.422000259f, -0.906595707f}, + {0.416429549f, -0.909168005f}, {0.410843164f, -0.91170603f}, {0.405241311f, -0.914209783f}, + {0.399624199f, -0.916679084f}, {0.393992037f, -0.919113874f}, {0.388345033f, -0.921514034f}, + {0.382683426f, -0.923879504f}, {0.377007425f, -0.926210225f}, {0.371317208f, -0.928506076f}, + {0.365612984f, -0.93076694f}, {0.359895051f, -0.932992816f}, {0.354163527f, -0.935183525f}, + {0.348418683f, -0.937339008f}, {0.342660725f, -0.939459205f}, {0.336889863f, -0.941544056f}, + {0.331106305f, -0.943593442f}, {0.32531029f, -0.945607305f}, {0.319502026f, -0.947585583f}, + {0.313681751f, -0.949528158f}, {0.307849646f, -0.95143503f}, {0.302005947f, -0.953306019f}, + {0.296150893f, -0.955141187f}, {0.290284663f, -0.956940353f}, {0.284407526f, -0.958703458f}, + {0.27851969f, -0.960430503f}, {0.272621363f, -0.962121427f}, {0.266712755f, -0.963776052f}, + {0.260794103f, -0.965394437f}, {0.254865646f, -0.966976464f}, {0.248927608f, -0.968522072f}, + {0.242980182f, -0.970031261f}, {0.237023607f, -0.971503913f}, {0.231058106f, -0.972939968f}, + {0.225083917f, -0.974339366f}, {0.219101235f, -0.975702107f}, {0.213110313f, -0.977028131f}, + {0.207111374f, -0.97831738f}, {0.201104641f, -0.979569793f}, {0.195090324f, -0.980785251f}, + {0.18906866f, -0.981963873f}, {0.183039889f, -0.983105481f}, {0.177004218f, -0.984210074f}, + {0.170961887f, -0.985277653f}, {0.164913118f, -0.986308098f}, {0.15885815f, -0.987301409f}, + {0.152797192f, -0.988257587f}, {0.146730468f, -0.989176512f}, {0.140658244f, -0.990058184f}, + {0.134580702f, -0.990902662f}, {0.128498107f, -0.991709769f}, {0.122410677f, -0.992479563f}, + {0.116318628f, -0.993211925f}, {0.110222206f, -0.993906975f}, {0.104121633f, -0.994564593f}, + {0.0980171412f, -0.99518472f}, {0.0919089541f, -0.995767415f}, {0.0857973099f, -0.996312618f}, + {0.0796824396f, -0.996820271f}, {0.0735645667f, -0.997290432f}, {0.0674439222f, -0.997723043f}, + {0.061320737f, -0.998118103f}, {0.0551952459f, -0.998475552f}, {0.0490676761f, -0.99879545f}, + {0.0429382585f, -0.999077737f}, {0.0368072242f, -0.999322355f}, {0.030674804f, -0.999529421f}, + {0.024541229f, -0.999698818f}, {0.0184067301f, -0.999830604f}, {0.0122715384f, -0.999924719f}, + {0.00613588467f, -0.999981165f}, {0.0f, -1.0f}, {-0.00613588467f, -0.999981165f}, + {-0.0122715384f, -0.999924719f}, {-0.0184067301f, -0.999830604f}, {-0.024541229f, -0.999698818f}, + {-0.030674804f, -0.999529421f}, {-0.0368072242f, -0.999322355f}, {-0.0429382585f, -0.999077737f}, + {-0.0490676761f, -0.99879545f}, {-0.0551952459f, -0.998475552f}, {-0.061320737f, -0.998118103f}, + {-0.0674439222f, -0.997723043f}, {-0.0735645667f, -0.997290432f}, {-0.0796824396f, -0.996820271f}, + {-0.0857973099f, -0.996312618f}, {-0.0919089541f, -0.995767415f}, {-0.0980171412f, -0.99518472f}, + {-0.104121633f, -0.994564593f}, {-0.110222206f, -0.993906975f}, {-0.116318628f, -0.993211925f}, + {-0.122410677f, -0.992479563f}, {-0.128498107f, -0.991709769f}, {-0.134580702f, -0.990902662f}, + {-0.140658244f, -0.990058184f}, {-0.146730468f, -0.989176512f}, {-0.152797192f, -0.988257587f}, + {-0.15885815f, -0.987301409f}, {-0.164913118f, -0.986308098f}, {-0.170961887f, -0.985277653f}, + {-0.177004218f, -0.984210074f}, {-0.183039889f, -0.983105481f}, {-0.18906866f, -0.981963873f}, + {-0.195090324f, -0.980785251f}, {-0.201104641f, -0.979569793f}, {-0.207111374f, -0.97831738f}, + {-0.213110313f, -0.977028131f}, {-0.219101235f, -0.975702107f}, {-0.225083917f, -0.974339366f}, + {-0.231058106f, -0.972939968f}, {-0.237023607f, -0.971503913f}, {-0.242980182f, -0.970031261f}, + {-0.248927608f, -0.968522072f}, {-0.254865646f, -0.966976464f}, {-0.260794103f, -0.965394437f}, + {-0.266712755f, -0.963776052f}, {-0.272621363f, -0.962121427f}, {-0.27851969f, -0.960430503f}, + {-0.284407526f, -0.958703458f}, {-0.290284663f, -0.956940353f}, {-0.296150893f, -0.955141187f}, + {-0.302005947f, -0.953306019f}, {-0.307849646f, -0.95143503f}, {-0.313681751f, -0.949528158f}, + {-0.319502026f, -0.947585583f}, {-0.32531029f, -0.945607305f}, {-0.331106305f, -0.943593442f}, + {-0.336889863f, -0.941544056f}, {-0.342660725f, -0.939459205f}, {-0.348418683f, -0.937339008f}, + {-0.354163527f, -0.935183525f}, {-0.359895051f, -0.932992816f}, {-0.365612984f, -0.93076694f}, + {-0.371317208f, -0.928506076f}, {-0.377007425f, -0.926210225f}, {-0.382683426f, -0.923879504f}, + {-0.388345033f, -0.921514034f}, {-0.393992037f, -0.919113874f}, {-0.399624199f, -0.916679084f}, + {-0.405241311f, -0.914209783f}, {-0.410843164f, -0.91170603f}, {-0.416429549f, -0.909168005f}, + {-0.422000259f, -0.906595707f}, {-0.427555084f, -0.903989315f}, {-0.433093816f, -0.901348829f}, + {-0.438616246f, -0.898674488f}, {-0.444122136f, -0.895966232f}, {-0.449611336f, -0.893224299f}, + {-0.455083579f, -0.890448749f}, {-0.460538715f, -0.887639642f}, {-0.465976506f, -0.884797096f}, + {-0.471396744f, -0.881921291f}, {-0.47679922f, -0.879012227f}, {-0.482183784f, -0.876070082f}, + {-0.487550169f, -0.873094976f}, {-0.492898196f, -0.870086968f}, {-0.498227656f, -0.867046237f}, + {-0.50353837f, -0.863972843f}, {-0.50883013f, -0.860866964f}, {-0.514102757f, -0.857728601f}, + {-0.519356012f, -0.854557991f}, {-0.524589658f, -0.851355195f}, {-0.529803634f, -0.848120332f}, + {-0.534997642f, -0.84485358f}, {-0.540171444f, -0.841554999f}, {-0.545324981f, -0.838224709f}, + {-0.550457954f, -0.834862888f}, {-0.555570245f, -0.831469595f}, {-0.560661554f, -0.82804507f}, + {-0.565731823f, -0.824589312f}, {-0.570780754f, -0.8211025f}, {-0.575808167f, -0.817584813f}, + {-0.580813944f, -0.81403631f}, {-0.585797846f, -0.81045717f}, {-0.590759695f, -0.806847572f}, + {-0.59569931f, -0.803207517f}, {-0.600616455f, -0.799537241f}, {-0.605511069f, -0.795836926f}, + {-0.610382795f, -0.792106569f}, {-0.615231574f, -0.78834641f}, {-0.620057225f, -0.784556568f}, + {-0.624859512f, -0.780737221f}, {-0.629638255f, -0.77688849f}, {-0.634393275f, -0.773010433f}, + {-0.639124453f, -0.769103348f}, {-0.643831551f, -0.765167236f}, {-0.64851439f, -0.761202395f}, + {-0.653172851f, -0.757208824f}, {-0.657806695f, -0.753186822f}, {-0.662415802f, -0.749136388f}, + {-0.666999936f, -0.745057762f}, {-0.671558976f, -0.740951121f}, {-0.676092684f, -0.736816585f}, + {-0.680601001f, -0.732654274f}, {-0.685083687f, -0.728464365f}, {-0.689540565f, -0.724247098f}, + {-0.693971455f, -0.720002532f}, {-0.698376238f, -0.715730846f}, {-0.702754736f, -0.711432219f}, + {-0.707106769f, -0.707106769f}, {-0.711432219f, -0.702754736f}, {-0.715730846f, -0.698376238f}, + {-0.720002532f, -0.693971455f}, {-0.724247098f, -0.689540565f}, {-0.728464365f, -0.685083687f}, + {-0.732654274f, -0.680601001f}, {-0.736816585f, -0.676092684f}, {-0.740951121f, -0.671558976f}, + {-0.745057762f, -0.666999936f}, {-0.749136388f, -0.662415802f}, {-0.753186822f, -0.657806695f}, + {-0.757208824f, -0.653172851f}, {-0.761202395f, -0.64851439f}, {-0.765167236f, -0.643831551f}, + {-0.769103348f, -0.639124453f}, {-0.773010433f, -0.634393275f}, {-0.77688849f, -0.629638255f}, + {-0.780737221f, -0.624859512f}, {-0.784556568f, -0.620057225f}, {-0.78834641f, -0.615231574f}, + {-0.792106569f, -0.610382795f}, {-0.795836926f, -0.605511069f}, {-0.799537241f, -0.600616455f}, + {-0.803207517f, -0.59569931f}, {-0.806847572f, -0.590759695f}, {-0.81045717f, -0.585797846f}, + {-0.81403631f, -0.580813944f}, {-0.817584813f, -0.575808167f}, {-0.8211025f, -0.570780754f}, + {-0.824589312f, -0.565731823f}, {-0.82804507f, -0.560661554f}, {-0.831469595f, -0.555570245f}, + {-0.834862888f, -0.550457954f}, {-0.838224709f, -0.545324981f}, {-0.841554999f, -0.540171444f}, + {-0.84485358f, -0.534997642f}, {-0.848120332f, -0.529803634f}, {-0.851355195f, -0.524589658f}, + {-0.854557991f, -0.519356012f}, {-0.857728601f, -0.514102757f}, {-0.860866964f, -0.50883013f}, + {-0.863972843f, -0.50353837f}, {-0.867046237f, -0.498227656f}, {-0.870086968f, -0.492898196f}, + {-0.873094976f, -0.487550169f}, {-0.876070082f, -0.482183784f}, {-0.879012227f, -0.47679922f}, + {-0.881921291f, -0.471396744f}, {-0.884797096f, -0.465976506f}, {-0.887639642f, -0.460538715f}, + {-0.890448749f, -0.455083579f}, {-0.893224299f, -0.449611336f}, {-0.895966232f, -0.444122136f}, + {-0.898674488f, -0.438616246f}, {-0.901348829f, -0.433093816f}, {-0.903989315f, -0.427555084f}, + {-0.906595707f, -0.422000259f}, {-0.909168005f, -0.416429549f}, {-0.91170603f, -0.410843164f}, + {-0.914209783f, -0.405241311f}, {-0.916679084f, -0.399624199f}, {-0.919113874f, -0.393992037f}, + {-0.921514034f, -0.388345033f}, {-0.923879504f, -0.382683426f}, {-0.926210225f, -0.377007425f}, + {-0.928506076f, -0.371317208f}, {-0.93076694f, -0.365612984f}, {-0.932992816f, -0.359895051f}, + {-0.935183525f, -0.354163527f}, {-0.937339008f, -0.348418683f}, {-0.939459205f, -0.342660725f}, + {-0.941544056f, -0.336889863f}, {-0.943593442f, -0.331106305f}, {-0.945607305f, -0.32531029f}, + {-0.947585583f, -0.319502026f}, {-0.949528158f, -0.313681751f}, {-0.95143503f, -0.307849646f}, + {-0.953306019f, -0.302005947f}, {-0.955141187f, -0.296150893f}, {-0.956940353f, -0.290284663f}, + {-0.958703458f, -0.284407526f}, {-0.960430503f, -0.27851969f}, {-0.962121427f, -0.272621363f}, + {-0.963776052f, -0.266712755f}, {-0.965394437f, -0.260794103f}, {-0.966976464f, -0.254865646f}, + {-0.968522072f, -0.248927608f}, {-0.970031261f, -0.242980182f}, {-0.971503913f, -0.237023607f}, + {-0.972939968f, -0.231058106f}, {-0.974339366f, -0.225083917f}, {-0.975702107f, -0.219101235f}, + {-0.977028131f, -0.213110313f}, {-0.97831738f, -0.207111374f}, {-0.979569793f, -0.201104641f}, + {-0.980785251f, -0.195090324f}, {-0.981963873f, -0.18906866f}, {-0.983105481f, -0.183039889f}, + {-0.984210074f, -0.177004218f}, {-0.985277653f, -0.170961887f}, {-0.986308098f, -0.164913118f}, + {-0.987301409f, -0.15885815f}, {-0.988257587f, -0.152797192f}, {-0.989176512f, -0.146730468f}, + {-0.990058184f, -0.140658244f}, {-0.990902662f, -0.134580702f}, {-0.991709769f, -0.128498107f}, + {-0.992479563f, -0.122410677f}, {-0.993211925f, -0.116318628f}, {-0.993906975f, -0.110222206f}, + {-0.994564593f, -0.104121633f}, {-0.99518472f, -0.0980171412f}, {-0.995767415f, -0.0919089541f}, + {-0.996312618f, -0.0857973099f}, {-0.996820271f, -0.0796824396f}, {-0.997290432f, -0.0735645667f}, + {-0.997723043f, -0.0674439222f}, {-0.998118103f, -0.061320737f}, {-0.998475552f, -0.0551952459f}, + {-0.99879545f, -0.0490676761f}, {-0.999077737f, -0.0429382585f}, {-0.999322355f, -0.0368072242f}, + {-0.999529421f, -0.030674804f}, {-0.999698818f, -0.024541229f}, {-0.999830604f, -0.0184067301f}, + {-0.999924719f, -0.0122715384f}, {-0.999981165f, -0.00613588467f}, +}; + +#if XOMBE_HAVE_ENCODER +const float xombe__base_win[XOMBE_BASE_WINDOW] = { + 0.0799999982f, 0.0802315921f, 0.0809261277f, 0.0820829123f, 0.0837007836f, 0.0857781097f, + 0.0883127972f, 0.091302298f, 0.0947435945f, 0.0986332297f, 0.102967285f, 0.107741393f, + 0.11295075f, 0.118590109f, 0.124653794f, 0.131135687f, 0.138029292f, 0.145327628f, + 0.153023377f, 0.161108777f, 0.169575676f, 0.178415582f, 0.187619552f, 0.197178349f, + 0.207082346f, 0.217321545f, 0.227885664f, 0.238764063f, 0.249945775f, 0.261419535f, + 0.273173809f, 0.285196781f, 0.297476292f, 0.310000002f, 0.322755307f, 0.335729361f, + 0.34890908f, 0.362281233f, 0.375832349f, 0.389548749f, 0.403416634f, 0.417422056f, + 0.43155089f, 0.44578892f, 0.46012184f, 0.474535167f, 0.489014417f, 0.503545046f, + 0.518112302f, 0.532701671f, 0.547298372f, 0.561887681f, 0.576454997f, 0.590985596f, + 0.605464816f, 0.619878173f, 0.634211063f, 0.648449123f, 0.662577927f, 0.67658335f, + 0.690451264f, 0.704167664f, 0.71771878f, 0.731090903f, 0.744270623f, 0.757244706f, + 0.769999981f, 0.782523692f, 0.794803202f, 0.806826174f, 0.818580449f, 0.830054224f, + 0.841235936f, 0.85211432f, 0.862678468f, 0.872917652f, 0.88282162f, 0.892380416f, + 0.901584446f, 0.910424292f, 0.918891251f, 0.926976621f, 0.934672356f, 0.941970706f, + 0.948864281f, 0.955346227f, 0.961409867f, 0.967049241f, 0.972258627f, 0.977032721f, + 0.981366754f, 0.985256374f, 0.988697708f, 0.991687179f, 0.994221866f, 0.996299207f, + 0.997917056f, 0.999073863f, 0.999768436f, 1.0f, 0.999768436f, 0.999073863f, + 0.997917056f, 0.996299207f, 0.994221866f, 0.991687179f, 0.988697708f, 0.985256374f, + 0.981366754f, 0.977032721f, 0.972258627f, 0.967049241f, 0.961409867f, 0.955346227f, + 0.948864281f, 0.941970706f, 0.934672356f, 0.926976621f, 0.918891251f, 0.910424292f, + 0.901584446f, 0.892380416f, 0.88282162f, 0.872917652f, 0.862678468f, 0.85211432f, + 0.841235936f, 0.830054224f, 0.818580449f, 0.806826174f, 0.794803202f, 0.782523692f, + 0.769999981f, 0.757244706f, 0.744270623f, 0.731090903f, 0.71771878f, 0.704167664f, + 0.690451264f, 0.67658335f, 0.662577927f, 0.648449123f, 0.634211063f, 0.619878173f, + 0.605464816f, 0.590985596f, 0.576454997f, 0.561887681f, 0.547298372f, 0.532701671f, + 0.518112302f, 0.503545046f, 0.489014417f, 0.474535167f, 0.46012184f, 0.44578892f, + 0.43155089f, 0.417422056f, 0.403416634f, 0.389548749f, 0.375832349f, 0.362281233f, + 0.34890908f, 0.335729361f, 0.322755307f, 0.310000002f, 0.297476292f, 0.285196781f, + 0.273173809f, 0.261419535f, 0.249945775f, 0.238764063f, 0.227885664f, 0.217321545f, + 0.207082346f, 0.197178349f, 0.187619552f, 0.178415582f, 0.169575676f, 0.161108777f, + 0.153023377f, 0.145327628f, 0.138029292f, 0.131135687f, 0.124653794f, 0.118590109f, + 0.11295075f, 0.107741393f, 0.102967285f, 0.0986332297f, 0.0947435945f, 0.091302298f, + 0.0883127972f, 0.0857781097f, 0.0837007836f, 0.0820829123f, 0.0809261277f, 0.0802315921f, + 0.0799999982f, +}; + +const float xombe__pitch_lpf[2 * XOMBE_PITCH_LPF_HALF + 1] = { + 0.00253628287f, 0.00255348557f, 0.0f, -0.00863465201f, -0.0210222024f, -0.0242112093f, + 0.0f, 0.0605565086f, 0.14459157f, 0.219130725f, 0.248999f, 0.219130725f, + 0.14459157f, 0.0605565086f, 0.0f, -0.0242112093f, -0.0210222024f, -0.00863465201f, + 0.0f, 0.00255348557f, 0.00253628287f, +}; + +#if XOMBE_KERNELS_Q15 +const uint32_t xombe__pitch_lpf_q15[2][XOMBE_PITCH_LPF_PAIRS] = { + { + 0x00890088u, 0xfe320000u, 0xfaf1fb9cu, 0x0ca60000u, 0x2dc61e34u, 0x2dc63404u, + 0x0ca61e34u, 0xfaf10000u, 0xfe32fb9cu, 0x00890000u, 0x00000088u, + }, + { + 0x00880000u, 0x00000089u, 0xfb9cfe32u, 0x0000faf1u, 0x1e340ca6u, 0x34042dc6u, + 0x1e342dc6u, 0x00000ca6u, 0xfb9cfaf1u, 0x0000fe32u, 0x00880089u, + }, +}; +const float xombe__pitch_lpf_q15_gain = 53477.1523f; +const uint32_t xombe__fft_tw_q15[XOMBE_FFT / 4] = { + 0x00007fffu, 0xfe6e7ffeu, 0xfcdc7ff6u, 0xfb4a7feau, 0xf9b87fd9u, 0xf8277fc2u, + 0xf6957fa7u, 0xf5057f87u, 0xf3747f62u, 0xf1e47f38u, 0xf0557f0au, 0xeec67ed6u, + 0xed387e9du, 0xebab7e60u, 0xea1e7e1eu, 0xe8927dd6u, 0xe7077d8au, 0xe57d7d3au, + 0xe3f47ce4u, 0xe26d7c89u, 0xe0e67c2au, 0xdf617bc6u, 0xdddc7b5du, 0xdc597aefu, + 0xdad87a7du, 0xd9587a06u, 0xd7d9798au, 0xd65c790au, 0xd4e17885u, 0xd36777fbu, + 0xd1ef776cu, 0xd07976d9u, 0xcf047642u, 0xcd9275a6u, 0xcc217505u, 0xcab27460u, + 0xc94673b6u, 0xc7db7308u, 0xc6737255u, 0xc50d719eu, 0xc3a970e3u, 0xc2487023u, + 0xc0e96f5fu, 0xbf8c6e97u, 0xbe326dcau, 0xbcda6cf9u, 0xbb856c24u, 0xba336b4bu, + 0xb8e36a6eu, 0xb796698cu, 0xb64c68a7u, 0xb50567bdu, 0xb3c066d0u, 0xb27f65deu, + 0xb14064e9u, 0xb00563efu, 0xaecc62f2u, 0xad9761f1u, 0xac6560ecu, 0xab365fe4u, + 0xaa0a5ed7u, 0xa8e25dc8u, 0xa7bd5cb4u, 0xa69c5b9du, 0xa57e5a82u, 0xa4635964u, + 0xa34c5843u, 0xa238571eu, 0xa12955f6u, 0xa01c54cau, 0x9f14539bu, 0x9e0f5269u, + 0x9d0e5134u, 0x9c114ffbu, 0x9b174ec0u, 0x9a224d81u, 0x99304c40u, 0x98434afbu, + 0x975949b4u, 0x9674486au, 0x9592471du, 0x94b545cdu, 0x93dc447bu, 0x93074326u, + 0x923641ceu, 0x91694074u, 0x90a13f17u, 0x8fdd3db8u, 0x8f1d3c57u, 0x8e623af3u, + 0x8dab398du, 0x8cf83825u, 0x8c4a36bau, 0x8ba0354eu, 0x8afb33dfu, 0x8a5a326eu, + 0x89be30fcu, 0x89272f87u, 0x88942e11u, 0x88052c99u, 0x877b2b1fu, 0x86f629a4u, + 0x86762827u, 0x85fa26a8u, 0x85832528u, 0x851123a7u, 0x84a32224u, 0x843a209fu, + 0x83d61f1au, 0x83771d93u, 0x831c1c0cu, 0x82c61a83u, 0x827618f9u, 0x822a176eu, + 0x81e215e2u, 0x81a01455u, 0x816312c8u, 0x812a113au, 0x80f60fabu, 0x80c80e1cu, + 0x809e0c8cu, 0x80790afbu, 0x8059096bu, 0x803e07d9u, 0x80270648u, 0x801604b6u, + 0x800a0324u, 0x80020192u, 0x80000000u, 0x8002fe6eu, 0x800afcdcu, 0x8016fb4au, + 0x8027f9b8u, 0x803ef827u, 0x8059f695u, 0x8079f505u, 0x809ef374u, 0x80c8f1e4u, + 0x80f6f055u, 0x812aeec6u, 0x8163ed38u, 0x81a0ebabu, 0x81e2ea1eu, 0x822ae892u, + 0x8276e707u, 0x82c6e57du, 0x831ce3f4u, 0x8377e26du, 0x83d6e0e6u, 0x843adf61u, + 0x84a3dddcu, 0x8511dc59u, 0x8583dad8u, 0x85fad958u, 0x8676d7d9u, 0x86f6d65cu, + 0x877bd4e1u, 0x8805d367u, 0x8894d1efu, 0x8927d079u, 0x89becf04u, 0x8a5acd92u, + 0x8afbcc21u, 0x8ba0cab2u, 0x8c4ac946u, 0x8cf8c7dbu, 0x8dabc673u, 0x8e62c50du, + 0x8f1dc3a9u, 0x8fddc248u, 0x90a1c0e9u, 0x9169bf8cu, 0x9236be32u, 0x9307bcdau, + 0x93dcbb85u, 0x94b5ba33u, 0x9592b8e3u, 0x9674b796u, 0x9759b64cu, 0x9843b505u, + 0x9930b3c0u, 0x9a22b27fu, 0x9b17b140u, 0x9c11b005u, 0x9d0eaeccu, 0x9e0fad97u, + 0x9f14ac65u, 0xa01cab36u, 0xa129aa0au, 0xa238a8e2u, 0xa34ca7bdu, 0xa463a69cu, + 0xa57ea57eu, 0xa69ca463u, 0xa7bda34cu, 0xa8e2a238u, 0xaa0aa129u, 0xab36a01cu, + 0xac659f14u, 0xad979e0fu, 0xaecc9d0eu, 0xb0059c11u, 0xb1409b17u, 0xb27f9a22u, + 0xb3c09930u, 0xb5059843u, 0xb64c9759u, 0xb7969674u, 0xb8e39592u, 0xba3394b5u, + 0xbb8593dcu, 0xbcda9307u, 0xbe329236u, 0xbf8c9169u, 0xc0e990a1u, 0xc2488fddu, + 0xc3a98f1du, 0xc50d8e62u, 0xc6738dabu, 0xc7db8cf8u, 0xc9468c4au, 0xcab28ba0u, + 0xcc218afbu, 0xcd928a5au, 0xcf0489beu, 0xd0798927u, 0xd1ef8894u, 0xd3678805u, + 0xd4e1877bu, 0xd65c86f6u, 0xd7d98676u, 0xd95885fau, 0xdad88583u, 0xdc598511u, + 0xdddc84a3u, 0xdf61843au, 0xe0e683d6u, 0xe26d8377u, 0xe3f4831cu, 0xe57d82c6u, + 0xe7078276u, 0xe892822au, 0xea1e81e2u, 0xebab81a0u, 0xed388163u, 0xeec6812au, + 0xf05580f6u, 0xf1e480c8u, 0xf374809eu, 0xf5058079u, 0xf6958059u, 0xf827803eu, + 0xf9b88027u, 0xfb4a8016u, 0xfcdc800au, 0xfe6e8002u, +}; +const uint32_t xombe__tone_tw_q15[XOMBE_TONE_FFT / 4] = { + 0x00007fffu, 0xfcdc7ff6u, 0xf9b87fd9u, 0xf6957fa7u, 0xf3747f62u, 0xf0557f0au, + 0xed387e9du, 0xea1e7e1eu, 0xe7077d8au, 0xe3f47ce4u, 0xe0e67c2au, 0xdddc7b5du, + 0xdad87a7du, 0xd7d9798au, 0xd4e17885u, 0xd1ef776cu, 0xcf047642u, 0xcc217505u, + 0xc94673b6u, 0xc6737255u, 0xc3a970e3u, 0xc0e96f5fu, 0xbe326dcau, 0xbb856c24u, + 0xb8e36a6eu, 0xb64c68a7u, 0xb3c066d0u, 0xb14064e9u, 0xaecc62f2u, 0xac6560ecu, + 0xaa0a5ed7u, 0xa7bd5cb4u, 0xa57e5a82u, 0xa34c5843u, 0xa12955f6u, 0x9f14539bu, + 0x9d0e5134u, 0x9b174ec0u, 0x99304c40u, 0x975949b4u, 0x9592471du, 0x93dc447bu, + 0x923641ceu, 0x90a13f17u, 0x8f1d3c57u, 0x8dab398du, 0x8c4a36bau, 0x8afb33dfu, + 0x89be30fcu, 0x88942e11u, 0x877b2b1fu, 0x86762827u, 0x85832528u, 0x84a32224u, + 0x83d61f1au, 0x831c1c0cu, 0x827618f9u, 0x81e215e2u, 0x816312c8u, 0x80f60fabu, + 0x809e0c8cu, 0x8059096bu, 0x80270648u, 0x800a0324u, 0x80000000u, 0x800afcdcu, + 0x8027f9b8u, 0x8059f695u, 0x809ef374u, 0x80f6f055u, 0x8163ed38u, 0x81e2ea1eu, + 0x8276e707u, 0x831ce3f4u, 0x83d6e0e6u, 0x84a3dddcu, 0x8583dad8u, 0x8676d7d9u, + 0x877bd4e1u, 0x8894d1efu, 0x89becf04u, 0x8afbcc21u, 0x8c4ac946u, 0x8dabc673u, + 0x8f1dc3a9u, 0x90a1c0e9u, 0x9236be32u, 0x93dcbb85u, 0x9592b8e3u, 0x9759b64cu, + 0x9930b3c0u, 0x9b17b140u, 0x9d0eaeccu, 0x9f14ac65u, 0xa129aa0au, 0xa34ca7bdu, + 0xa57ea57eu, 0xa7bda34cu, 0xaa0aa129u, 0xac659f14u, 0xaecc9d0eu, 0xb1409b17u, + 0xb3c09930u, 0xb64c9759u, 0xb8e39592u, 0xbb8593dcu, 0xbe329236u, 0xc0e990a1u, + 0xc3a98f1du, 0xc6738dabu, 0xc9468c4au, 0xcc218afbu, 0xcf0489beu, 0xd1ef8894u, + 0xd4e1877bu, 0xd7d98676u, 0xdad88583u, 0xdddc84a3u, 0xe0e683d6u, 0xe3f4831cu, + 0xe7078276u, 0xea1e81e2u, 0xed388163u, 0xf05580f6u, 0xf374809eu, 0xf6958059u, + 0xf9b88027u, 0xfcdc800au, +}; +#endif + +const float xombe__pitch_w2[XOMBE_PITCH_WIN] = { + 5.3679385e-05f, 5.38148597e-05f, 5.42222406e-05f, 5.49044235e-05f, 5.58662214e-05f, 5.71143501e-05f, + 5.86574351e-05f, 6.05059613e-05f, 6.26722685e-05f, 6.51705195e-05f, 6.80166559e-05f, 7.12283945e-05f, + 7.48251405e-05f, 7.88279722e-05f, 8.32595906e-05f, 8.81442393e-05f, 9.35077042e-05f, 9.93771901e-05f, + 0.000105781291f, 0.000112749927f, 0.000120314246f, 0.000128506596f, 0.000137360388f, 0.000146910053f, + 0.000157190996f, 0.000168239407f, 0.000180092291f, 0.000192787295f, 0.00020636266f, 0.000220857095f, + 0.000236309701f, 0.000252759899f, 0.000270247285f, 0.00028881157f, 0.000308492425f, 0.000329329428f, + 0.000351361959f, 0.000374629104f, 0.000399169512f, 0.00042502131f, 0.000452222012f, 0.000480808434f, + 0.000510816579f, 0.000542281428f, 0.000575237034f, 0.000609716401f, 0.000645751075f, 0.00068337156f, + 0.000722606725f, 0.000763484102f, 0.000806029537f, 0.000850267243f, 0.000896219572f, 0.000943907187f, + 0.000993348658f, 0.00104456081f, 0.00109755783f, 0.00115235255f, 0.00120895484f, 0.00126737263f, + 0.00132761162f, 0.00138967496f, 0.00145356311f, 0.00151927443f, 0.00158680452f, 0.00165614625f, + 0.00172729034f, 0.0018002243f, 0.00187493325f, 0.00195139961f, 0.00202960288f, 0.0021095199f, + 0.00219112495f, 0.00227438915f, 0.00235928129f, 0.00244576694f, 0.00253380951f, 0.00262336922f, + 0.0027144039f, 0.00280686794f, 0.00290071429f, 0.0029958922f, 0.00309234904f, 0.00319002918f, + 0.00328887464f, 0.00338882511f, 0.00348981773f, 0.00359178754f, 0.00369466678f, 0.00379838631f, + 0.00390287419f, 0.0040080566f, 0.0041138581f, 0.00422020117f, 0.00432700617f, 0.00443419209f, + 0.00454167603f, 0.00464937417f, 0.0047572013f, 0.00486506987f, 0.00497289188f, 0.00508057838f, + 0.00518803997f, 0.00529518444f, 0.00540192099f, 0.00550815696f, 0.00561379967f, 0.005718756f, + 0.00582293281f, 0.00592623604f, 0.0060285721f, 0.00612984831f, 0.00622997107f, 0.00632884772f, + 0.00642638607f, 0.0065224939f, 0.00661708089f, 0.00671005668f, 0.00680133281f, 0.0068908208f, + 0.00697843451f, 0.00706408871f, 0.00714769913f, 0.0072291838f, 0.00730846263f, 0.00738545693f, + 0.00746008987f, 0.00753228692f, 0.00760197546f, 0.0076690861f, 0.00773355085f, 0.00779530359f, + 0.00785428286f, 0.00791042764f, 0.00796368066f, 0.00801398791f, 0.00806129724f, 0.00810555927f, + 0.00814673025f, 0.00818476733f, 0.00821962953f, 0.00825128239f, 0.00827969145f, 0.00830482971f, + 0.00832666829f, 0.00834518578f, 0.00836036354f, 0.00837218482f, 0.00838063657f, 0.00838571228f, + 0.00838740449f, 0.00838571228f, 0.00838063657f, 0.00837218482f, 0.00836036354f, 0.00834518578f, + 0.00832666829f, 0.00830482971f, 0.00827969145f, 0.00825128239f, 0.00821962953f, 0.00818476733f, + 0.00814673025f, 0.00810555927f, 0.00806129724f, 0.00801398791f, 0.00796368066f, 0.00791042764f, + 0.00785428286f, 0.00779530359f, 0.00773355085f, 0.0076690861f, 0.00760197546f, 0.00753228692f, + 0.00746008987f, 0.00738545693f, 0.00730846263f, 0.0072291838f, 0.00714769913f, 0.00706408871f, + 0.00697843451f, 0.0068908208f, 0.00680133281f, 0.00671005668f, 0.00661708089f, 0.0065224939f, + 0.00642638607f, 0.00632884772f, 0.00622997107f, 0.00612984831f, 0.0060285721f, 0.00592623604f, + 0.00582293281f, 0.005718756f, 0.00561379967f, 0.00550815696f, 0.00540192099f, 0.00529518444f, + 0.00518803997f, 0.00508057838f, 0.00497289188f, 0.00486506987f, 0.0047572013f, 0.00464937417f, + 0.00454167603f, 0.00443419209f, 0.00432700617f, 0.00422020117f, 0.0041138581f, 0.0040080566f, + 0.00390287419f, 0.00379838631f, 0.00369466678f, 0.00359178754f, 0.00348981773f, 0.00338882511f, + 0.00328887464f, 0.00319002918f, 0.00309234904f, 0.0029958922f, 0.00290071429f, 0.00280686794f, + 0.0027144039f, 0.00262336922f, 0.00253380951f, 0.00244576694f, 0.00235928129f, 0.00227438915f, + 0.00219112495f, 0.0021095199f, 0.00202960288f, 0.00195139961f, 0.00187493325f, 0.0018002243f, + 0.00172729034f, 0.00165614625f, 0.00158680452f, 0.00151927443f, 0.00145356311f, 0.00138967496f, + 0.00132761162f, 0.00126737263f, 0.00120895484f, 0.00115235255f, 0.00109755783f, 0.00104456081f, + 0.000993348658f, 0.000943907187f, 0.000896219572f, 0.000850267243f, 0.000806029537f, 0.000763484102f, + 0.000722606725f, 0.00068337156f, 0.000645751075f, 0.000609716401f, 0.000575237034f, 0.000542281428f, + 0.000510816579f, 0.000480808434f, 0.000452222012f, 0.00042502131f, 0.000399169512f, 0.000374629104f, + 0.000351361959f, 0.000329329428f, 0.000308492425f, 0.00028881157f, 0.000270247285f, 0.000252759899f, + 0.000236309701f, 0.000220857095f, 0.00020636266f, 0.000192787295f, 0.000180092291f, 0.000168239407f, + 0.000157190996f, 0.000146910053f, 0.000137360388f, 0.000128506596f, 0.000120314246f, 0.000112749927f, + 0.000105781291f, 9.93771901e-05f, 9.35077042e-05f, 8.81442393e-05f, 8.32595906e-05f, 7.88279722e-05f, + 7.48251405e-05f, 7.12283945e-05f, 6.80166559e-05f, 6.51705195e-05f, 6.26722685e-05f, 6.05059613e-05f, + 5.86574351e-05f, 5.71143501e-05f, 5.58662214e-05f, 5.49044235e-05f, 5.42222406e-05f, 5.38148597e-05f, + 5.3679385e-05f, +}; +const float xombe__pitch_sum_w4 = 0.00605550827f; +#if XOMBE_KERNELS_Q15 +const int16_t xombe__pitch_w2_q15[XOMBE_PITCH_HALF + 1] = { + 210, 210, 212, 214, 218, 223, 229, 236, 245, 255, 266, 278, + 292, 308, 325, 344, 365, 388, 413, 440, 470, 502, 537, 574, + 614, 657, 704, 753, 806, 863, 923, 987, 1056, 1128, 1205, 1287, + 1373, 1464, 1559, 1660, 1767, 1878, 1996, 2119, 2247, 2382, 2523, 2670, + 2823, 2983, 3149, 3322, 3501, 3688, 3881, 4081, 4288, 4502, 4723, 4951, + 5187, 5429, 5679, 5935, 6199, 6470, 6748, 7033, 7325, 7624, 7929, 8241, + 8560, 8885, 9217, 9555, 9899, 10249, 10604, 10966, 11332, 11704, 12081, 12462, + 12849, 13239, 13634, 14032, 14434, 14839, 15247, 15658, 16072, 16487, 16904, 17323, + 17743, 18164, 18585, 19006, 19428, 19848, 20268, 20687, 21104, 21519, 21931, 22341, + 22748, 23152, 23552, 23947, 24339, 24725, 25106, 25481, 25851, 26214, 26571, 26920, + 27263, 27597, 27924, 28242, 28552, 28853, 29144, 29426, 29699, 29961, 30213, 30454, + 30684, 30904, 31112, 31308, 31493, 31666, 31827, 31975, 32112, 32235, 32346, 32444, + 32530, 32602, 32661, 32708, 32741, 32760, 32767, +}; +const float xombe__pitch_w2_q15_gain = 3906691.25f; +#endif + +const float xombe__tone_win[XOMBE_TONE_SEG] = { + 0.0f, 0.00017277422f, 0.000690977438f, 0.00155425165f, 0.00276200008f, 0.00431338791f, + 0.00620734366f, 0.00844255742f, 0.0110174855f, 0.0139303477f, 0.0171791315f, 0.0207615905f, + 0.0246752501f, 0.0289174058f, 0.033485122f, 0.038375251f, 0.0435844027f, 0.0491089821f, + 0.0549451709f, 0.0610889383f, 0.0675360337f, 0.0742820054f, 0.0813221857f, 0.0886517167f, + 0.0962655246f, 0.104158357f, 0.112324752f, 0.12075907f, 0.129455477f, 0.138407975f, + 0.147610351f, 0.157056287f, 0.16673921f, 0.176652446f, 0.186789155f, 0.197142333f, + 0.207704797f, 0.218469277f, 0.229428321f, 0.24057436f, 0.25189966f, 0.263396442f, + 0.27505675f, 0.286872506f, 0.298835546f, 0.310937643f, 0.323170364f, 0.335525304f, + 0.34799391f, 0.36056757f, 0.37323758f, 0.385995209f, 0.398831606f, 0.411737949f, + 0.424705267f, 0.43772465f, 0.450787038f, 0.46388346f, 0.477004826f, 0.490142077f, + 0.503286183f, 0.516427994f, 0.52955842f, 0.542668462f, 0.555748999f, 0.568790972f, + 0.58178544f, 0.594723403f, 0.607595861f, 0.620393991f, 0.633108914f, 0.645731866f, + 0.658254087f, 0.670666933f, 0.682961822f, 0.695130289f, 0.70716387f, 0.719054282f, + 0.730793357f, 0.74237287f, 0.753784895f, 0.765021563f, 0.776075065f, 0.786937773f, + 0.797602117f, 0.808060884f, 0.818306684f, 0.828332543f, 0.838131487f, 0.847696722f, + 0.857021689f, 0.866099894f, 0.874925137f, 0.883491218f, 0.891792297f, 0.899822593f, + 0.907576561f, 0.915048897f, 0.922234356f, 0.929128051f, 0.935725152f, 0.942021132f, + 0.948011637f, 0.953692496f, 0.959059834f, 0.964109898f, 0.968839228f, 0.973244548f, + 0.977322817f, 0.981071174f, 0.984487116f, 0.9875682f, 0.990312338f, 0.992717624f, + 0.994782388f, 0.996505201f, 0.99788487f, 0.9989205f, 0.999611259f, 0.999956787f, + 0.999956787f, 0.999611259f, 0.9989205f, 0.99788487f, 0.996505201f, 0.994782388f, + 0.992717624f, 0.990312338f, 0.9875682f, 0.984487116f, 0.981071174f, 0.977322817f, + 0.973244548f, 0.968839228f, 0.964109898f, 0.959059834f, 0.953692496f, 0.948011637f, + 0.942021132f, 0.935725152f, 0.929128051f, 0.922234356f, 0.915048897f, 0.907576561f, + 0.899822593f, 0.891792297f, 0.883491218f, 0.874925137f, 0.866099894f, 0.857021689f, + 0.847696722f, 0.838131487f, 0.828332543f, 0.818306684f, 0.808060884f, 0.797602117f, + 0.786937773f, 0.776075065f, 0.765021563f, 0.753784895f, 0.74237287f, 0.730793357f, + 0.719054282f, 0.70716387f, 0.695130289f, 0.682961822f, 0.670666933f, 0.658254087f, + 0.645731866f, 0.633108914f, 0.620393991f, 0.607595861f, 0.594723403f, 0.58178544f, + 0.568790972f, 0.555748999f, 0.542668462f, 0.52955842f, 0.516427994f, 0.503286183f, + 0.490142077f, 0.477004826f, 0.46388346f, 0.450787038f, 0.43772465f, 0.424705267f, + 0.411737949f, 0.398831606f, 0.385995209f, 0.37323758f, 0.36056757f, 0.34799391f, + 0.335525304f, 0.323170364f, 0.310937643f, 0.298835546f, 0.286872506f, 0.27505675f, + 0.263396442f, 0.25189966f, 0.24057436f, 0.229428321f, 0.218469277f, 0.207704797f, + 0.197142333f, 0.186789155f, 0.176652446f, 0.16673921f, 0.157056287f, 0.147610351f, + 0.138407975f, 0.129455477f, 0.12075907f, 0.112324752f, 0.104158357f, 0.0962655246f, + 0.0886517167f, 0.0813221857f, 0.0742820054f, 0.0675360337f, 0.0610889383f, 0.0549451709f, + 0.0491089821f, 0.0435844027f, 0.038375251f, 0.033485122f, 0.0289174058f, 0.0246752501f, + 0.0207615905f, 0.0171791315f, 0.0139303477f, 0.0110174855f, 0.00844255742f, 0.00620734366f, + 0.00431338791f, 0.00276200008f, 0.00155425165f, 0.000690977438f, 0.00017277422f, 0.0f, +}; +#endif diff --git a/xombe/src/tables/dsp_tables.h b/xombe/src/tables/dsp_tables.h new file mode 100644 index 0000000..905147c --- /dev/null +++ b/xombe/src/tables/dsp_tables.h @@ -0,0 +1,69 @@ +#ifndef XOMBE_DSP_TABLES_H +#define XOMBE_DSP_TABLES_H + +/* constant-argument trigonometry, roots, and init-time tables, generated by scripts/gen_dsp_tables.py */ + +#include "../state.h" +#include "tables.h" + +#define XOMBE_GRAIN_RAMP 16 /* grain fade length, samples */ + +/* DCT-II kernels cos(pi*m*(i + 1/2)/J): 8-point one between PRBA vector and block means, and one per spectral + block length J 1..XOMBE_DCT_BLK_J_MAX for m = 0..XOMBE_DCT_BLK_ROWS - 1 + block J's kernel starts at xombe__dct_blk + xombe__dct_blk_off[J], row m at offset m*J */ +#define XOMBE_DCT_BLK_J_MAX 17 +#define XOMBE_DCT_BLK_ROWS 6 +#define XOMBE_DCT_BLK_SIZE (XOMBE_DCT_BLK_ROWS * XOMBE_DCT_BLK_J_MAX * (XOMBE_DCT_BLK_J_MAX + 1) / 2) +extern const float xombe__dct8[8][8]; +extern const unsigned short xombe__dct_blk_off[XOMBE_DCT_BLK_J_MAX + 1]; +extern const float xombe__dct_blk[XOMBE_DCT_BLK_SIZE]; + +/* cos, sin of pi*j/XOMBE_GRAIN_RAMP: grain fades at integer offsets, rotated by the grain's fractional start */ +extern const float xombe__ramp_cos[XOMBE_GRAIN_RAMP]; +extern const float xombe__ramp_sin[XOMBE_GRAIN_RAMP]; + +/* half-frame crossfades: sqrt(n/N) = xombe__sqrt_n[n] * xombe__rsqrt_half[N - XOMBE_HALF_MIN] */ +extern const float xombe__sqrt_n[XOMBE_HALF_MAX + 1]; +extern const float xombe__rsqrt_half[XOMBE_HALF_MAX - XOMBE_HALF_MIN + 1]; + +/* 1/2*log2(L), per-harmonic share of the frame gain, entry 0 unused */ +extern const float xombe__half_log2[XOMBE_LMAX + 1]; + +/* sqrt(xombe__w0[b]*xombe__w0[b + 1]), log-scale midpoint of neighbouring pitches */ +extern const float xombe__w0_mid[XOMBE_B0_COUNT - 1]; + +/* FFT twiddles exp(-2*pi*i*k/XOMBE_TW_N), an n-point transform takes every (XOMBE_TW_N/n)-th */ +#define XOMBE_TW_N 1024 +extern const xombe_cpx xombe__fft_tw[XOMBE_TW_N / 2]; + +#if XOMBE_HAVE_ENCODER +/* base analysis window, Hamming 0.54 - 0.46*cos(2*pi*i/(n - 1)) */ +extern const float xombe__base_win[XOMBE_BASE_WINDOW]; +/* pitch tracker low-pass, quarter-band sinc under a Hamming taper, unit DC gain */ +extern const float xombe__pitch_lpf[2 * XOMBE_PITCH_LPF_HALF + 1]; +/* pitch tracker window w^2/sum(w^2) for Hamming w of XOMBE_PITCH_WIN, and the sum of its squares */ +extern const float xombe__pitch_w2[XOMBE_PITCH_WIN]; +extern const float xombe__pitch_sum_w4; +#if XOMBE_KERNELS_Q15 +/* xombe__pitch_w2[0..XOMBE_PITCH_HALF] * xombe__pitch_w2_q15_gain rounded (peak 32767), the rest mirrors it + (kern_q15_pitch.c) */ +extern const int16_t xombe__pitch_w2_q15[XOMBE_PITCH_HALF + 1]; +extern const float xombe__pitch_w2_q15_gain; +#endif +#if XOMBE_KERNELS_Q15 +/* pitch low-pass taps for kern_q15_pitch.c, g[m] = h[2*XOMBE_PITCH_LPF_HALF - m] * xombe__pitch_lpf_q15_gain rounded, + as int16 pairs, row 0 (g[0], g[1]), (g[2], g[3]), ... zero-padded, row 1 one later, (0, g[0]), (g[1], g[2]), ... */ +#define XOMBE_PITCH_LPF_PAIRS (XOMBE_PITCH_LPF_HALF + 1) +extern const uint32_t xombe__pitch_lpf_q15[2][XOMBE_PITCH_LPF_PAIRS]; +extern const float xombe__pitch_lpf_q15_gain; +/* encoder analysis FFT twiddles for XOMBE_FFT / 2 complex points (kern_q15_spec.c), exp(-2*pi*i*j/(XOMBE_FFT / 2)) + for j < XOMBE_FFT / 4, Q15 rounded and held below 1, as int16 pairs (re, im) */ +extern const uint32_t xombe__fft_tw_q15[XOMBE_FFT / 4]; +/* tone detector FFT twiddles for XOMBE_TONE_FFT / 2 complex points (tone_detect.c), as xombe__fft_tw_q15 */ +extern const uint32_t xombe__tone_tw_q15[XOMBE_TONE_FFT / 4]; +#endif +/* tone detector Hann window, 0.5 - 0.5*cos(2*pi*i/(n - 1)) */ +extern const float xombe__tone_win[XOMBE_TONE_SEG]; +#endif + +#endif diff --git a/xombe/src/tables/dstar_enc_tables.c b/xombe/src/tables/dstar_enc_tables.c new file mode 100644 index 0000000..eb59efe --- /dev/null +++ b/xombe/src/tables/dstar_enc_tables.c @@ -0,0 +1,437 @@ +/* generated by scripts/gen_dstar_enc_tables.py, do not edit */ +#include "dstar_enc_tables.h" + +const unsigned char xombe__ds_mn_lo[62] = { + 0, 93, 94, 94, 95, 96, 96, 97, 97, 98, 99, 99, 100, 100, 101, 102, + 102, 103, 103, 104, 105, 105, 106, 106, 107, 107, 108, 108, 109, 109, 110, 110, + 111, 111, 112, 112, 113, 113, 114, 114, 115, 115, 116, 116, 117, 117, 118, 118, + 119, 119, 120, 120, 120, 121, 121, 122, 122, 122, 122, 122, 122, 122, +}; + +const unsigned char xombe__ds_mn_cnt[62] = { + 97, 5, 5, 5, 5, 5, 5, 5, 6, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 4, 5, 4, 5, 4, 5, + 4, 5, 4, 4, 4, 3, 3, 2, 2, 2, 2, 2, 2, 2, +}; + +const unsigned short xombe__ds_mn_off[62] = { + 0, 97, 102, 107, 112, 117, 122, 127, 132, 138, 143, 148, 153, 158, 163, 168, + 173, 178, 183, 188, 193, 197, 202, 206, 211, 216, 221, 226, 231, 236, 241, 246, + 251, 256, 261, 266, 271, 276, 281, 286, 291, 295, 300, 304, 309, 313, 318, 322, + 327, 331, 336, 340, 344, 348, 351, 354, 356, 358, 360, 362, 364, 366, +}; + +const unsigned short xombe__ds_mn[XOMBE_DS_MN_ROWS][8] = { + {54632, 53956, 53257, 54739, 47179, 42370, 39060, 39576}, + {49997, 49557, 51347, 43965, 47303, 40702, 44029, 42515}, + {50840, 47360, 44854, 50386, 45286, 46188, 48152, 46943}, + {52615, 47336, 44128, 47181, 47080, 50672, 47720, 49615}, + {47074, 52593, 43745, 52655, 48148, 40828, 36515, 37788}, + {52930, 55550, 51673, 49948, 43049, 41227, 41848, 35149}, + {51567, 55751, 51135, 47396, 41166, 40584, 43492, 38860}, + {50409, 43026, 45460, 49278, 38182, 44276, 45896, 37205}, + {55523, 57187, 40623, 43634, 51247, 42127, 37572, 39884}, + {53225, 54818, 45351, 43006, 45537, 49071, 44954, 41423}, + {48268, 50378, 43887, 39747, 42314, 45677, 44752, 45159}, + {45588, 43931, 52147, 43917, 42020, 38835, 39089, 39554}, + {44365, 52218, 50727, 49730, 42307, 36552, 46441, 36451}, + {55416, 49993, 47915, 46310, 44474, 38707, 39250, 40731}, + {41880, 41868, 45259, 42237, 42163, 39614, 38979, 34818}, + {55468, 54466, 48847, 40731, 44588, 42738, 37462, 43151}, + {51626, 45485, 43568, 46769, 43131, 43215, 42901, 38313}, + {47206, 50988, 50205, 44181, 46388, 45149, 36006, 34981}, + {47577, 47162, 42148, 44011, 41470, 45241, 46365, 33308}, + {50250, 47365, 44575, 45152, 43953, 33652, 37462, 41307}, + {52573, 49047, 44825, 38072, 43680, 41394, 41788, 36815}, + {57355, 47672, 45623, 47286, 40460, 47206, 44276, 36362}, + {56368, 48292, 45398, 42168, 45466, 43856, 39641, 34284}, + {43453, 47987, 38041, 41130, 42665, 35725, 38048, 35581}, + {44838, 49845, 39888, 38390, 42888, 39378, 38321, 33686}, + {53977, 44972, 41826, 39913, 41597, 42627, 35939, 35550}, + {36012, 50464, 46222, 39345, 38893, 34775, 38465, 31638}, + {54142, 52555, 41621, 40039, 31288, 37548, 38450, 34014}, + {49955, 45251, 40820, 42567, 38458, 34172, 40034, 35690}, + {46327, 42209, 44391, 39744, 34030, 33986, 37100, 33977}, + {48061, 49907, 38126, 39306, 38637, 39404, 41315, 38585}, + {47961, 44009, 39645, 43352, 38026, 39689, 33674, 33915}, + {42049, 43088, 37855, 46247, 34540, 33217, 37780, 29508}, + {44259, 38706, 32943, 42550, 35732, 33849, 35944, 31186}, + {37842, 41767, 40210, 40238, 34665, 37398, 37886, 30207}, + {42960, 36088, 35657, 33149, 41489, 29192, 33015, 32710}, + {42819, 47480, 43651, 38682, 35976, 31622, 36489, 26914}, + {49441, 38586, 35596, 36816, 36884, 35852, 27139, 31219}, + {41159, 37706, 37305, 34339, 40416, 30707, 36042, 26232}, + {42086, 42887, 46481, 37763, 35723, 33080, 30622, 34077}, + {42114, 45264, 41316, 36942, 33155, 30703, 30371, 33674}, + {46244, 38196, 34485, 39228, 32951, 34371, 34188, 31289}, + {44859, 37066, 32010, 27488, 31527, 32932, 31918, 28572}, + {39021, 43408, 32460, 34868, 31114, 33507, 31583, 31643}, + {35861, 43133, 40876, 32494, 29119, 34956, 33232, 28699}, + {41773, 38556, 39373, 34730, 31068, 33373, 30305, 32007}, + {44534, 44516, 42558, 31539, 33238, 29318, 28421, 31747}, + {40827, 39509, 32081, 31219, 28193, 35122, 28496, 29434}, + {35380, 33726, 33185, 33478, 28671, 31642, 29592, 27886}, + {42414, 32591, 36298, 38373, 33089, 30514, 28224, 29172}, + {40624, 40523, 33863, 34430, 33635, 30804, 30336, 28854}, + {42752, 34600, 30616, 33891, 27895, 28260, 30805, 22881}, + {38590, 40379, 30216, 33830, 28294, 29882, 24174, 27011}, + {35500, 32415, 28998, 34115, 31490, 26936, 25237, 25160}, + {41404, 38940, 30636, 25405, 32205, 28869, 23672, 25558}, + {42236, 37747, 33858, 34422, 32336, 28766, 23534, 21740}, + {36148, 34652, 29370, 25728, 26401, 25706, 26010, 28613}, + {35816, 40149, 33373, 30909, 30498, 26908, 23648, 25816}, + {37009, 32281, 32669, 28670, 27851, 26516, 21465, 24548}, + {36735, 34186, 31352, 27895, 28508, 22349, 21744, 21032}, + {35448, 32981, 31519, 30649, 24285, 28924, 25247, 22356}, + {34763, 26658, 22072, 26392, 27134, 26772, 23464, 23263}, + {40957, 33955, 25636, 24665, 22702, 21822, 22821, 24655}, + {33257, 35641, 31510, 25599, 26558, 22646, 24662, 23867}, + {32144, 30470, 30666, 28064, 20663, 24930, 26366, 22514}, + {32510, 29430, 25131, 23061, 25802, 21984, 23476, 22137}, + {35540, 32221, 20852, 23197, 19312, 21518, 22453, 17520}, + {33792, 23121, 24371, 26106, 20674, 22599, 24057, 17682}, + {28783, 30277, 27417, 18225, 25873, 19863, 24188, 22126}, + {27352, 31416, 26738, 22108, 21169, 22866, 21881, 23842}, + {33258, 27926, 25923, 23042, 24486, 20261, 20453, 17763}, + {34338, 27650, 24593, 22802, 22589, 23927, 20664, 21344}, + {30050, 26433, 29258, 20080, 18793, 19797, 18087, 20021}, + {24289, 25449, 21085, 21742, 14945, 18044, 16765, 21477}, + {25749, 29377, 25390, 21803, 18172, 19669, 18838, 17428}, + {30252, 28285, 21442, 21908, 19853, 20182, 18926, 19818}, + {24740, 23092, 25842, 21213, 19019, 21297, 19622, 16374}, + {34094, 26765, 21374, 20807, 17187, 18373, 20798, 18751}, + {26220, 22841, 21086, 18565, 17094, 18637, 17963, 15659}, + {27240, 22119, 24069, 18549, 13807, 21240, 19880, 14291}, + {25645, 25459, 20281, 18022, 16019, 16676, 15614, 13814}, + {24764, 19694, 16033, 15596, 17271, 18935, 17504, 15189}, + {22146, 20893, 20276, 15341, 16573, 16343, 17001, 15966}, + {24699, 23724, 17653, 15098, 14705, 18513, 16897, 14489}, + {21874, 20586, 18904, 15348, 15870, 20871, 17394, 14311}, + {26863, 23001, 18473, 14205, 17219, 14208, 15355, 16027}, + {25063, 18820, 16632, 13995, 15470, 17184, 17038, 15835}, + {19545, 19466, 18223, 18227, 14621, 14389, 15200, 14917}, + {21011, 20957, 21138, 16115, 13475, 15315, 13944, 12559}, + {20649, 20467, 16286, 16591, 15401, 16615, 11756, 13400}, + {23201, 18708, 18696, 17244, 17398, 14942, 16728, 14293}, + {22986, 18203, 17609, 14449, 13076, 15546, 17842, 11264}, + {15688, 15053, 17906, 15775, 13363, 14455, 12969, 11499}, + {23858, 20115, 16031, 12698, 16405, 15937, 14940, 11652}, + {20210, 17088, 13714, 14593, 15891, 16332, 14428, 10407}, + {14780, 17476, 13980, 14454, 12696, 12003, 12056, 11649}, + {17236, 14476, 12539, 13590, 13465, 13520, 11608, 11927}, + {19121, 24048, 17287, 14397, 12597, 14746, 14830, 11780}, + {20767, 15933, 14094, 13336, 15316, 12966, 12651, 15463}, + {21114, 16141, 14184, 12917, 10707, 14063, 13912, 12060}, + {15507, 16861, 10625, 13258, 14486, 11100, 11759, 11195}, + {16439, 17931, 14262, 14879, 14830, 14590, 13438, 13604}, + {17930, 18281, 15757, 13106, 13994, 14767, 14770, 12700}, + {18146, 14879, 15074, 15553, 15120, 13994, 13064, 13338}, + {20134, 14990, 14616, 13961, 12182, 14097, 12093, 14696}, + {19085, 16203, 15137, 13214, 10711, 11653, 12636, 13836}, + {19770, 15530, 11005, 14595, 12461, 12778, 11852, 11723}, + {15815, 19272, 15334, 15160, 13562, 14722, 14916, 13354}, + {15618, 15049, 16366, 12029, 14220, 15705, 14642, 13118}, + {15582, 19303, 14411, 15824, 12299, 16796, 16293, 13674}, + {18669, 18075, 16599, 12625, 16012, 11781, 15652, 11248}, + {22150, 13632, 16964, 13563, 11781, 10961, 13950, 10416}, + {21441, 15722, 17833, 13717, 15841, 12981, 13941, 14448}, + {18693, 15720, 14113, 13804, 17022, 11990, 14967, 12546}, + {22454, 17519, 12581, 10851, 13247, 12959, 10753, 12335}, + {23978, 16367, 15714, 12670, 10465, 10766, 11278, 11777}, + {16460, 18774, 14097, 14457, 13394, 15245, 12992, 10051}, + {19381, 17224, 15469, 14781, 14986, 15213, 16596, 13520}, + {16516, 17786, 11372, 14365, 13943, 14542, 13262, 13029}, + {17052, 17523, 14459, 15621, 13945, 14643, 14058, 12469}, + {22500, 15996, 14954, 14903, 15392, 11307, 15761, 11886}, + {20686, 19234, 13575, 13281, 12793, 12248, 12943, 10446}, + {22877, 17988, 16928, 17650, 12936, 16492, 16502, 9621}, + {19078, 24580, 10676, 14725, 12328, 14102, 11681, 10960}, + {18058, 16823, 13930, 16287, 14103, 13093, 14350, 15217}, + {21393, 17761, 14516, 14570, 12696, 11482, 11471, 14413}, + {17302, 14857, 16877, 13325, 13753, 12313, 14050, 10842}, + {21730, 16167, 15499, 17455, 12922, 15171, 17589, 13666}, + {17751, 15784, 16384, 15437, 11308, 11109, 14543, 14305}, + {20805, 19909, 16958, 14738, 14150, 12463, 13280, 13074}, + {17060, 18912, 14573, 12776, 13467, 13164, 13671, 16229}, + {18661, 13298, 15627, 12805, 11861, 15368, 14584, 11285}, + {27019, 21338, 18424, 13633, 14148, 16207, 15548, 15040}, + {19534, 18045, 14773, 14165, 12830, 14448, 12493, 14450}, + {16660, 19064, 13042, 11661, 14289, 14094, 12285, 12268}, + {22274, 15405, 14208, 13814, 12207, 14155, 11497, 9755}, + {23482, 15968, 17108, 13180, 12852, 13749, 14244, 13982}, + {15469, 13710, 13014, 12621, 11882, 12833, 15214, 13363}, + {22445, 15945, 14669, 14285, 14481, 13481, 12848, 15540}, + {20080, 15747, 14230, 14580, 15395, 13306, 15391, 12624}, + {18738, 18553, 13732, 14519, 13690, 15243, 15587, 15328}, + {17549, 12975, 14975, 15037, 13580, 13276, 13903, 12354}, + {21449, 15453, 11809, 10795, 13264, 13680, 13882, 10619}, + {17156, 15816, 15541, 16677, 14779, 12913, 13602, 12770}, + {18430, 18404, 14326, 16843, 11447, 13834, 14645, 12998}, + {20116, 16770, 15159, 11993, 14081, 13300, 13378, 12597}, + {16380, 15208, 14874, 15015, 13703, 13640, 14478, 13109}, + {19094, 16486, 12865, 13449, 13306, 13324, 13300, 12359}, + {21534, 16798, 15495, 15301, 13270, 12389, 15442, 15149}, + {19297, 22319, 17295, 14647, 14383, 15607, 15180, 14048}, + {21542, 19244, 16177, 12685, 11203, 13111, 12730, 10820}, + {18288, 15916, 17119, 13473, 15413, 12250, 12902, 13281}, + {20739, 14359, 11201, 11733, 15263, 14312, 15239, 12827}, + {19640, 15911, 13207, 12851, 13664, 14308, 15576, 13636}, + {22365, 15360, 13267, 14138, 11246, 13227, 14822, 14003}, + {24019, 16843, 12904, 15095, 15544, 12182, 15174, 10929}, + {19595, 15726, 12887, 11646, 15421, 12840, 11721, 12477}, + {21068, 16820, 15508, 13103, 13415, 11368, 11984, 13677}, + {20979, 18447, 14968, 11076, 13515, 13297, 14117, 12343}, + {19411, 15687, 15075, 15185, 12401, 16264, 14550, 15433}, + {20309, 15112, 12125, 14016, 12597, 12911, 12309, 11049}, + {15410, 18445, 16542, 13301, 15304, 12787, 13931, 11973}, + {20929, 14814, 14989, 12717, 12922, 12754, 11705, 14337}, + {19334, 20248, 17165, 13642, 12934, 11875, 16065, 14918}, + {15256, 19402, 17882, 14342, 12572, 14248, 13976, 11276}, + {18628, 15143, 15688, 13546, 12213, 13354, 15417, 13043}, + {14202, 17148, 14299, 16265, 13706, 13532, 14170, 12656}, + {15459, 15182, 13442, 15591, 16093, 15448, 16196, 11332}, + {23333, 17790, 14227, 14060, 13792, 13688, 13680, 13373}, + {19225, 14045, 14298, 13811, 11402, 12696, 13911, 12101}, + {17191, 14764, 13472, 12037, 11361, 12506, 10476, 10619}, + {14559, 15760, 15290, 13593, 13056, 14291, 14665, 14146}, + {21497, 17168, 15329, 15392, 13043, 10682, 14114, 11774}, + {16304, 21020, 13924, 13693, 13281, 14685, 15446, 15700}, + {17562, 18114, 15261, 12985, 14979, 14866, 12682, 11663}, + {18221, 17433, 14683, 11814, 12762, 16250, 12307, 13400}, + {21564, 15002, 14205, 14284, 12911, 15063, 10324, 12529}, + {19337, 15960, 14378, 13000, 14783, 13110, 12998, 14699}, + {18927, 15717, 13785, 12206, 12765, 15500, 14900, 16958}, + {19520, 16557, 13371, 15298, 13672, 14859, 14375, 13329}, + {20884, 20970, 13985, 12316, 14199, 13938, 14804, 15049}, + {18761, 14876, 16940, 9549, 11725, 10517, 12562, 12089}, + {21561, 12522, 14123, 12971, 14865, 14004, 12717, 13271}, + {19746, 19097, 17510, 13341, 14395, 14210, 13730, 13859}, + {18528, 18101, 16382, 17111, 14137, 16283, 15739, 14354}, + {22172, 13719, 14940, 12718, 15380, 15181, 15068, 14426}, + {14855, 18254, 13839, 13829, 13524, 13028, 13363, 13284}, + {16297, 18475, 12163, 15779, 13513, 11452, 13909, 12535}, + {18213, 16131, 15413, 12773, 16016, 13991, 14374, 14391}, + {20408, 14099, 16668, 15956, 15549, 15009, 11715, 13523}, + {18481, 16546, 13408, 12542, 12426, 13300, 13973, 13411}, + {18192, 15840, 14207, 14251, 11187, 13210, 16972, 12117}, + {19773, 14380, 15474, 14851, 15149, 13425, 12133, 13702}, + {16456, 16474, 14128, 13647, 12725, 13456, 16089, 14376}, + {19345, 18877, 12824, 15232, 15824, 12267, 14070, 15831}, + {19779, 13502, 15614, 14538, 14335, 12793, 14509, 12319}, + {20695, 16181, 15288, 11390, 14250, 14658, 14254, 12944}, + {18293, 15185, 16765, 16877, 14457, 13806, 13545, 11512}, + {14590, 16650, 12530, 12300, 12724, 14529, 13713, 14891}, + {17647, 17693, 14967, 14457, 13853, 11838, 12392, 11910}, + {14048, 16747, 13126, 12540, 13033, 15137, 16334, 14474}, + {21188, 16192, 14261, 14241, 13806, 12987, 14128, 12584}, + {17151, 18259, 15205, 13158, 11933, 13127, 11977, 13951}, + {15699, 18345, 15440, 18844, 12745, 16614, 14821, 12271}, + {19993, 15129, 13810, 14912, 14769, 13266, 11955, 14120}, + {18810, 17318, 15062, 15096, 13918, 13375, 14792, 13845}, + {18900, 14292, 19104, 16685, 15833, 15166, 15111, 13889}, + {18480, 15992, 14577, 14800, 15477, 16863, 13385, 11706}, + {17891, 17664, 15448, 13702, 14495, 13767, 13675, 12375}, + {18907, 13720, 16881, 13353, 15158, 12578, 11103, 11763}, + {17689, 16460, 15395, 12446, 13591, 16265, 13335, 15996}, + {17959, 18051, 13889, 13208, 15140, 14514, 15497, 15659}, + {17342, 14804, 13745, 15317, 12214, 15230, 14902, 13260}, + {19097, 15326, 15262, 13767, 13890, 13232, 12215, 13013}, + {19025, 14505, 14750, 13024, 10923, 11508, 15819, 13156}, + {19522, 15717, 13630, 12893, 13967, 13563, 11242, 12140}, + {14745, 18353, 15691, 15356, 16049, 14481, 15100, 12559}, + {21509, 11436, 14961, 12657, 14692, 14334, 15800, 14707}, + {18770, 17518, 13885, 12707, 14530, 13646, 14691, 11580}, + {18670, 16490, 14517, 14753, 13460, 13134, 13600, 13768}, + {16450, 16259, 11973, 12137, 12236, 14788, 12930, 13099}, + {17416, 15356, 15881, 11314, 12829, 14465, 14692, 13228}, + {23173, 16895, 12347, 15138, 13205, 16896, 13326, 11832}, + {20023, 17217, 17407, 12405, 14151, 14572, 12923, 13330}, + {21191, 16106, 14379, 12959, 13399, 12148, 12648, 14275}, + {16001, 15378, 13210, 13058, 10106, 9984, 12964, 12522}, + {18805, 16166, 15628, 16079, 14738, 15434, 11655, 14165}, + {17333, 15304, 15050, 14037, 13706, 15416, 16712, 11992}, + {22063, 13991, 15135, 13404, 12635, 14193, 13666, 12192}, + {17318, 15889, 14079, 11483, 12887, 13237, 13190, 14319}, + {17034, 11734, 12536, 11702, 15397, 12742, 14285, 11397}, + {20245, 17397, 16096, 15530, 14847, 15132, 15258, 14537}, + {21166, 17490, 14728, 15612, 14686, 12054, 19115, 13586}, + {15143, 18517, 17631, 11870, 12954, 14107, 13476, 14464}, + {15190, 15566, 11704, 12010, 13843, 12464, 14151, 15074}, + {20985, 16031, 12112, 13129, 14925, 15138, 13092, 13514}, + {18488, 15336, 16458, 15596, 14314, 13599, 15781, 15756}, + {20236, 15841, 16647, 15381, 14578, 15533, 15983, 14414}, + {22629, 15506, 13437, 12859, 14208, 12814, 12180, 12505}, + {17999, 16069, 16952, 11915, 15162, 16649, 14493, 14212}, + {19477, 14122, 13886, 13717, 15748, 14862, 14432, 12717}, + {24656, 16575, 18355, 14663, 14845, 15581, 15320, 13800}, + {15926, 19252, 19068, 12926, 14040, 12767, 13185, 14897}, + {18520, 16107, 14698, 12598, 14462, 13005, 16677, 13637}, + {16571, 15076, 14397, 14475, 12766, 13044, 10924, 14900}, + {19236, 14332, 13543, 15387, 12329, 11608, 13576, 10806}, + {19222, 17222, 17668, 14055, 15502, 16546, 15831, 13636}, + {19143, 19995, 14164, 16180, 15775, 15178, 13945, 14072}, + {19924, 14814, 16069, 16040, 13956, 15767, 13995, 15244}, + {16725, 14870, 15129, 14378, 13959, 12576, 12188, 16630}, + {18235, 16702, 14027, 13148, 11754, 13648, 12045, 12029}, + {18187, 17609, 15049, 15164, 14746, 13090, 14799, 11960}, + {20808, 19304, 16532, 15159, 14126, 16134, 15272, 13816}, + {17721, 17051, 15009, 13885, 14183, 12585, 10575, 12416}, + {17743, 16011, 13117, 12840, 12983, 13310, 15442, 14798}, + {17116, 14504, 13839, 15569, 14234, 13987, 15003, 13278}, + {17474, 17879, 14380, 16955, 12566, 13434, 15573, 15052}, + {20853, 15034, 15576, 12401, 13393, 13169, 14566, 11174}, + {19191, 16033, 15009, 14819, 11624, 13963, 14419, 15155}, + {20951, 17674, 11069, 13138, 14960, 13320, 13528, 14012}, + {17604, 15832, 14886, 13547, 12770, 12032, 13349, 12834}, + {25137, 14567, 14916, 13719, 15685, 13537, 14191, 12804}, + {17622, 17050, 18391, 13875, 14504, 14103, 12701, 14074}, + {19761, 16619, 16246, 14484, 15304, 14154, 14156, 12302}, + {17558, 15423, 17054, 13014, 13302, 14057, 15828, 13659}, + {16515, 19341, 13052, 12091, 12612, 14302, 12650, 14591}, + {20439, 18911, 14158, 15910, 14585, 13775, 16354, 13866}, + {17733, 15282, 14376, 14066, 16060, 12624, 14946, 14844}, + {19608, 17091, 16887, 15401, 14995, 13111, 16611, 14579}, + {18203, 16752, 15289, 15334, 12118, 14582, 15894, 10840}, + {19642, 13058, 15620, 15346, 14702, 13308, 13663, 13095}, + {20834, 13766, 14146, 15580, 14249, 13584, 15186, 12406}, + {17690, 15734, 13179, 14715, 15643, 14276, 14228, 12592}, + {19052, 15723, 15293, 12611, 14357, 16004, 10831, 14644}, + {16734, 15950, 11534, 12935, 13120, 14373, 14884, 12525}, + {21425, 16380, 14307, 13714, 12732, 12317, 15088, 13614}, + {21975, 15288, 16900, 16981, 15142, 16365, 15700, 15071}, + {19882, 17688, 13788, 13135, 14157, 15424, 15263, 13597}, + {18006, 15420, 13530, 13461, 16912, 13042, 15406, 14768}, + {16411, 16851, 14509, 10300, 14592, 15904, 13955, 11755}, + {17107, 15864, 13186, 11236, 13446, 14652, 13675, 14137}, + {15891, 17672, 17493, 16703, 14817, 13908, 12510, 16671}, + {16922, 14874, 14597, 16725, 11975, 17343, 16807, 13414}, + {16083, 14883, 12916, 16672, 11916, 16037, 13967, 11991}, + {15612, 15684, 13541, 15604, 15607, 14077, 15701, 15207}, + {15470, 17470, 13272, 14026, 14124, 13164, 16051, 14001}, + {16998, 19262, 14260, 14837, 15174, 18158, 13646, 16218}, + {19287, 16905, 16132, 15951, 14509, 12518, 12770, 13235}, + {16504, 15842, 14975, 14278, 14271, 15881, 12028, 13530}, + {18214, 15632, 13965, 13707, 12016, 13025, 14796, 13288}, + {19135, 14066, 13286, 13982, 13362, 14017, 14764, 12269}, + {25154, 17183, 15351, 13787, 14129, 15753, 11661, 13127}, + {16072, 17001, 15948, 11804, 11673, 16105, 14221, 13841}, + {20665, 15871, 13745, 13289, 14747, 15127, 16217, 13216}, + {21165, 14034, 12197, 13806, 12211, 13001, 12639, 12045}, + {20044, 17238, 16821, 14375, 13476, 17134, 13926, 11505}, + {20788, 15615, 14085, 12900, 16300, 15269, 15271, 11916}, + {17559, 14355, 16203, 13312, 16378, 15758, 14294, 12526}, + {15007, 17907, 13524, 14374, 13899, 14216, 15261, 13554}, + {18090, 17606, 12598, 12897, 11895, 12270, 13395, 14083}, + {18651, 15589, 14894, 15310, 14584, 14646, 11953, 14933}, + {20207, 16038, 15365, 13208, 13248, 15067, 14665, 13861}, + {19865, 15663, 15599, 13919, 11918, 15997, 14500, 13540}, + {16888, 12622, 13112, 13053, 12345, 13322, 13938, 12523}, + {21212, 19022, 14843, 12758, 17072, 15667, 14367, 15876}, + {20068, 16196, 14845, 13091, 15376, 14568, 15303, 14190}, + {18145, 14640, 12762, 15326, 14799, 16173, 14194, 12944}, + {19143, 15689, 15071, 13573, 16771, 14707, 14528, 12476}, + {19541, 17598, 15730, 13716, 11890, 12185, 14249, 12573}, + {21101, 15518, 16929, 15335, 15926, 15711, 10142, 15465}, + {16817, 16131, 14598, 15623, 14988, 12414, 15115, 14629}, + {22152, 16085, 16241, 13200, 14315, 14013, 13913, 12785}, + {16232, 15547, 14293, 14477, 12618, 13382, 14768, 10194}, + {16167, 17514, 15616, 14191, 13825, 12851, 16542, 14591}, + {16083, 19467, 14825, 13940, 15379, 14639, 14178, 14352}, + {23064, 19882, 16350, 15311, 16125, 16599, 14986, 12092}, + {17222, 19226, 14351, 15052, 14153, 12431, 12661, 10611}, + {15976, 16867, 14553, 14621, 14164, 12540, 12245, 14010}, + {21124, 17430, 13414, 14147, 15261, 15738, 13668, 15442}, + {15378, 16070, 13175, 13377, 15784, 15616, 15669, 14083}, + {21185, 17545, 13204, 13510, 15711, 17009, 13610, 15918}, + {21875, 19274, 14297, 15508, 12696, 14121, 12176, 14081}, + {20399, 19041, 13321, 13549, 14855, 14042, 14847, 13395}, + {18979, 17727, 14350, 14401, 14412, 14934, 16061, 15727}, + {17630, 16988, 14603, 13094, 17245, 12999, 15018, 13024}, + {19347, 14435, 14818, 14191, 13148, 13412, 13007, 13248}, + {15062, 19338, 13941, 13138, 13371, 12416, 16946, 12233}, + {20891, 14788, 13974, 16560, 13058, 13031, 12608, 15035}, + {22159, 14712, 12223, 14423, 15774, 11960, 17380, 11352}, + {16851, 15624, 14364, 15283, 12758, 16208, 15956, 12595}, + {18477, 13671, 12858, 10728, 14300, 14915, 14472, 11667}, + {17503, 17663, 16235, 16292, 13945, 15628, 13313, 14232}, + {22172, 17290, 13604, 13258, 15391, 14289, 14802, 12770}, + {18957, 14608, 13344, 15504, 13600, 15394, 14504, 12904}, + {18147, 15030, 14803, 14499, 13796, 12917, 13827, 13009}, + {18703, 17141, 13896, 14100, 12813, 11923, 13337, 14415}, + {17476, 14241, 14750, 13851, 17420, 15002, 15684, 14202}, + {21939, 14969, 13533, 13771, 16129, 18208, 14469, 17049}, + {19573, 12934, 15971, 14400, 13575, 13823, 13169, 15461}, + {20373, 14501, 14924, 13806, 13953, 13866, 13319, 12843}, + {14560, 16062, 14023, 14567, 13748, 12940, 15739, 16994}, + {16435, 16479, 15024, 14174, 14172, 14121, 13004, 14391}, + {22712, 17411, 12788, 16819, 13383, 14927, 14389, 16370}, + {16330, 15785, 12745, 16850, 12995, 15335, 14924, 11609}, + {16661, 16627, 15549, 15523, 15635, 14898, 16629, 18253}, + {16579, 13632, 17004, 14088, 15595, 15684, 12748, 15075}, + {16724, 16548, 12395, 16166, 14678, 14242, 15027, 14111}, + {18134, 16290, 13454, 15488, 14924, 14219, 11992, 13274}, + {21733, 13784, 15689, 14397, 16346, 15702, 15406, 12097}, + {17663, 17116, 15970, 13974, 13263, 13933, 14832, 11919}, + {18919, 15504, 13411, 12003, 13525, 14140, 14909, 12646}, + {21594, 16169, 18770, 15079, 15729, 14041, 14334, 15869}, + {18321, 19780, 13708, 14806, 14406, 15554, 12089, 15208}, + {18568, 18912, 14795, 13924, 14988, 16393, 14423, 14502}, + {16937, 15080, 14571, 14066, 15767, 12667, 14191, 16686}, + {19794, 16435, 14957, 13601, 13321, 14502, 13661, 14467}, + {17521, 18560, 16071, 14310, 15081, 16277, 15490, 14736}, + {18070, 16610, 15826, 12567, 16433, 14825, 14874, 13704}, + {16971, 15729, 16607, 14846, 12914, 15798, 15367, 16127}, + {23100, 17624, 12807, 16242, 17325, 14942, 14154, 15327}, + {18921, 20018, 17837, 16142, 16296, 16845, 13851, 14260}, + {18573, 14060, 15825, 16577, 13720, 15128, 14873, 16055}, + {22007, 19310, 15104, 16415, 14901, 14496, 14768, 15500}, + {23611, 17060, 16384, 14654, 13142, 12615, 15017, 15483}, + {18028, 16985, 14467, 16850, 15848, 13856, 13689, 14460}, + {18010, 18711, 16726, 15015, 16383, 15602, 14948, 16611}, + {19949, 16133, 13476, 15874, 15507, 18837, 15854, 16597}, + {16498, 18562, 17104, 15248, 12152, 14695, 16008, 13402}, +}; + +const float xombe__ds_tone_win[XOMBE_DS_TONE_LEN] = { + 0.0f, 0.000390345318f, 0.00156077184f, 0.0035094521f, 0.00623334339f, 0.00972819235f, 0.0139885433f, 0.0190077424f, + 0.0247779544f, 0.0312901698f, 0.0385342203f, 0.0464987941f, 0.0551714562f, 0.0645386651f, 0.0745857954f, 0.0852971599f, + 0.0966560319f, 0.108644679f, 0.121244378f, 0.13443546f, 0.148197338f, 0.162508503f, 0.177346617f, 0.192688525f, + 0.208510265f, 0.224787116f, 0.241493702f, 0.258603901f, 0.276091009f, 0.293927729f, 0.312086195f, 0.330538094f, + 0.349254578f, 0.368206412f, 0.38736406f, 0.406697541f, 0.426176727f, 0.445771158f, 0.465450287f, 0.485183328f, + 0.504939556f, 0.524688005f, 0.54439795f, 0.564038575f, 0.583579183f, 0.602989316f, 0.622238636f, 0.641297102f, + 0.660134912f, 0.678722739f, 0.697031498f, 0.715032578f, 0.732697964f, 0.75f, 0.766911685f, 0.783406615f, + 0.79945904f, 0.815043926f, 0.830136895f, 0.844714344f, 0.858753622f, 0.872232735f, 0.885130644f, 0.897427201f, + 0.909103274f, 0.920140505f, 0.930521786f, 0.940230846f, 0.949252546f, 0.957572818f, 0.965178609f, 0.972058058f, + 0.978200495f, 0.983596265f, 0.988236904f, 0.992115319f, 0.995225251f, 0.997561991f, 0.999121845f, 0.999902427f, + 0.999902427f, 0.999121845f, 0.997561991f, 0.995225251f, 0.992115319f, 0.988236904f, 0.983596265f, 0.978200495f, + 0.972058058f, 0.965178609f, 0.957572818f, 0.949252546f, 0.940230846f, 0.930521786f, 0.920140505f, 0.909103274f, + 0.897427201f, 0.885130644f, 0.872232735f, 0.858753622f, 0.844714344f, 0.830136895f, 0.815043926f, 0.79945904f, + 0.783406615f, 0.766911685f, 0.75f, 0.732697964f, 0.715032578f, 0.697031498f, 0.678722739f, 0.660134912f, + 0.641297102f, 0.622238636f, 0.602989316f, 0.583579183f, 0.564038575f, 0.54439795f, 0.524688005f, 0.504939556f, + 0.485183328f, 0.465450287f, 0.445771158f, 0.426176727f, 0.406697541f, 0.38736406f, 0.368206412f, 0.349254578f, + 0.330538094f, 0.312086195f, 0.293927729f, 0.276091009f, 0.258603901f, 0.241493702f, 0.224787116f, 0.208510265f, + 0.192688525f, 0.177346617f, 0.162508503f, 0.148197338f, 0.13443546f, 0.121244378f, 0.108644679f, 0.0966560319f, + 0.0852971599f, 0.0745857954f, 0.0645386651f, 0.0551714562f, 0.0464987941f, 0.0385342203f, 0.0312901698f, 0.0247779544f, + 0.0190077424f, 0.0139885433f, 0.00972819235f, 0.00623334339f, 0.0035094521f, 0.00156077184f, 0.000390345318f, 0.0f, +}; + +const float xombe__ds_nz_win[XOMBE_DS_NZ_LEN] = { + 0.0f, 0.000557847728f, 0.0022301462f, 0.00501316413f, 0.00890069082f, 0.0138840526f, 0.0199521277f, 0.0270913783f, + 0.0352858752f, 0.0445173271f, 0.0547651425f, 0.0660064444f, 0.0782161653f, 0.0913670436f, 0.105429746f, 0.120372884f, + 0.13616313f, 0.152765229f, 0.170142144f, 0.188255101f, 0.207063675f, 0.226525918f, 0.246598393f, 0.267236292f, + 0.288393587f, 0.31002304f, 0.33207643f, 0.354504526f, 0.377257258f, 0.400283873f, 0.423533022f, 0.44695279f, + 0.470490903f, 0.494094878f, 0.517712057f, 0.541289687f, 0.564775169f, 0.588116109f, 0.611260474f, 0.634156525f, + 0.656753242f, 0.679000199f, 0.700847685f, 0.722247064f, 0.743150473f, 0.76351136f, 0.783284247f, 0.802424967f, + 0.820890903f, 0.838640809f, 0.855635047f, 0.871835709f, 0.887206674f, 0.901713669f, 0.915324271f, 0.92800808f, + 0.939736903f, 0.950484455f, 0.960226774f, 0.968942165f, 0.976611197f, 0.983216703f, 0.988743961f, 0.993180633f, + 0.996516883f, 0.998745143f, 0.999860525f, 0.999860525f, 0.998745143f, 0.996516883f, 0.993180633f, 0.988743961f, + 0.983216703f, 0.976611197f, 0.968942165f, 0.960226774f, 0.950484455f, 0.939736903f, 0.92800808f, 0.915324271f, + 0.901713669f, 0.887206674f, 0.871835709f, 0.855635047f, 0.838640809f, 0.820890903f, 0.802424967f, 0.783284247f, + 0.76351136f, 0.743150473f, 0.722247064f, 0.700847685f, 0.679000199f, 0.656753242f, 0.634156525f, 0.611260474f, + 0.588116109f, 0.564775169f, 0.541289687f, 0.517712057f, 0.494094878f, 0.470490903f, 0.44695279f, 0.423533022f, + 0.400283873f, 0.377257258f, 0.354504526f, 0.33207643f, 0.31002304f, 0.288393587f, 0.267236292f, 0.246598393f, + 0.226525918f, 0.207063675f, 0.188255101f, 0.170142144f, 0.152765229f, 0.13616313f, 0.120372884f, 0.105429746f, + 0.0913670436f, 0.0782161653f, 0.0660064444f, 0.0547651425f, 0.0445173271f, 0.0352858752f, 0.0270913783f, 0.0199521277f, + 0.0138840526f, 0.00890069082f, 0.00501316413f, 0.0022301462f, 0.000557847728f, 0.0f, +}; diff --git a/xombe/src/tables/dstar_enc_tables.h b/xombe/src/tables/dstar_enc_tables.h new file mode 100644 index 0000000..960a003 --- /dev/null +++ b/xombe/src/tables/dstar_enc_tables.h @@ -0,0 +1,25 @@ +#ifndef XOMBE_DSTAR_ENC_TABLES_H +#define XOMBE_DSTAR_ENC_TABLES_H + +/* D-STAR encoder white-noise voicing reference m_noise(N, b0), generated by scripts/gen_dstar_enc_tables.py, + do not edit + window N = 199 + 2i (i < XOMBE_DS_MN_WINDOWS) has rows for b0 lo[i]..lo[i] + cnt[i] - 1 from row off[i], + each row the 8 band values x 65536 */ + +#define XOMBE_DS_MN_N_MIN 199 +#define XOMBE_DS_MN_WINDOWS 62 +#define XOMBE_DS_MN_ROWS 368 +#define XOMBE_DS_MN_SCALE 65536.0f + +extern const unsigned char xombe__ds_mn_lo[XOMBE_DS_MN_WINDOWS]; +extern const unsigned char xombe__ds_mn_cnt[XOMBE_DS_MN_WINDOWS]; +extern const unsigned short xombe__ds_mn_off[XOMBE_DS_MN_WINDOWS]; +extern const unsigned short xombe__ds_mn[XOMBE_DS_MN_ROWS][8]; + +/* tone detector segment and tone-in-noise window lengths in samples, Hann windows 0.5 - 0.5*cos(2*pi*i/(n - 1)) */ +#define XOMBE_DS_TONE_LEN 160 +#define XOMBE_DS_NZ_LEN 134 +extern const float xombe__ds_tone_win[XOMBE_DS_TONE_LEN]; +extern const float xombe__ds_nz_win[XOMBE_DS_NZ_LEN]; + +#endif diff --git a/xombe/src/tables/dstar_tables.c b/xombe/src/tables/dstar_tables.c new file mode 100644 index 0000000..7552e9b --- /dev/null +++ b/xombe/src/tables/dstar_tables.c @@ -0,0 +1,877 @@ +/* generated by scripts/gen_dstar_tables.py, do not edit */ +#include "dstar_tables.h" + +const float xombe__ds_w0[XOMBE_DS_B0_COUNT] = { + 0.0523401722f, 0.051554691f, 0.0507809967f, 0.050018914f, 0.0492682643f, 0.0485288836f, + 0.0478006005f, 0.0470832437f, 0.046376653f, 0.0456806645f, 0.0449951254f, 0.0443198718f, + 0.043654751f, 0.042999614f, 0.0423543081f, 0.0417186841f, 0.0410926007f, 0.0404759161f, + 0.0398684815f, 0.0392701663f, 0.0386808291f, 0.0381003357f, 0.0375285521f, 0.0369653516f, + 0.0364106037f, 0.0358641818f, 0.0353259593f, 0.0347958133f, 0.0342736244f, 0.0337592699f, + 0.0332526341f, 0.0327536054f, 0.0322620645f, 0.031777896f, 0.0313009992f, 0.0308312569f, + 0.0303685647f, 0.0299128145f, 0.0294639058f, 0.0290217325f, 0.0285861976f, 0.0281571969f, + 0.0277346335f, 0.0273184124f, 0.0269084387f, 0.0265046172f, 0.0261068549f, 0.0257150624f, + 0.0253291503f, 0.0249490291f, 0.0245746132f, 0.024205815f, 0.0238425527f, 0.0234847404f, + 0.0231323f, 0.0227851477f, 0.0224432051f, 0.0221063942f, 0.0217746366f, 0.0214478597f, + 0.0211259853f, 0.0208089426f, 0.0204966571f, 0.0201890599f, 0.0198860765f, 0.0195876416f, + 0.0192936845f, 0.01900414f, 0.0187189393f, 0.0184380189f, 0.0181613155f, 0.0178887639f, + 0.0176203027f, 0.0173558705f, 0.0170954056f, 0.0168388505f, 0.0165861454f, 0.0163372327f, + 0.0160920564f, 0.0158505589f, 0.0156126851f, 0.0153783821f, 0.0151475947f, 0.0149202701f, + 0.0146963578f, 0.0144758057f, 0.0142585635f, 0.0140445819f, 0.0138338115f, 0.0136262039f, + 0.0134217115f, 0.0132202888f, 0.0130218882f, 0.012826466f, 0.0126339756f, 0.0124443742f, + 0.0122576179f, 0.0120736649f, 0.0118924724f, 0.0117139993f, 0.0115382038f, 0.0113650477f, + 0.011194489f, 0.0110264905f, 0.0108610131f, 0.0106980195f, 0.0105374716f, 0.010379333f, + 0.0102235675f, 0.0100701395f, 0.00991901476f, 0.00977015682f, 0.00962353405f, 0.00947911106f, + 0.00933685526f, 0.00919673499f, 0.00905871764f, 0.00892277062f, 0.00878886413f, 0.00865696743f, + 0.00852705073f, 0.00839908235f, 0.00827303529f, 0.00814887974f, 0.00802658778f, 0.00790613052f, + 0.00778748142f, 0.00767061254f, +}; + +const unsigned char xombe__ds_lt[XOMBE_DS_B0_COUNT] = { + 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, + 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, + 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, + 18, 18, 18, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 22, 22, 22, + 23, 23, 23, 24, 24, 25, 25, 25, 26, 26, 27, 27, 27, 28, 28, 29, + 29, 30, 30, 31, 31, 31, 32, 32, 33, 33, 34, 34, 35, 36, 36, 37, + 37, 38, 38, 39, 40, 40, 41, 41, 42, 43, 43, 44, 45, 45, 46, 47, + 48, 48, 49, 50, 51, 51, 52, 53, 54, 55, 55, 56, 56, 56, 56, 56, +}; + +const float xombe__ds_dg[64] = { + -0.0606365502f, 0.100869834f, 0.371278554f, 0.512414396f, 1.10657966f, 1.23248231f, + 1.65990627f, 1.81187654f, 2.08208036f, 2.19614196f, 2.33876348f, 2.51255822f, + 2.61426997f, 2.76447749f, 2.91644406f, 3.07107472f, 3.25997853f, 3.3468554f, + 3.49040413f, 3.616642f, 3.77736187f, 3.91083026f, 4.05696201f, 4.198071f, + 4.40268612f, 4.53386736f, 4.69201231f, 4.83170986f, 5.02735472f, 5.13956928f, + 5.35110569f, 5.4939723f, 5.6819129f, 5.77016497f, 5.9070096f, 6.03524208f, + 6.15389013f, 6.29011011f, 6.44369507f, 6.56140327f, 6.70500326f, 6.83583403f, + 7.00220728f, 7.1164217f, 7.30390549f, 7.40693331f, 7.55518866f, 7.72283411f, + 7.90140676f, 8.02389908f, 8.1908989f, 8.36409664f, 8.5387373f, 8.70312405f, + 8.89608288f, 9.02334213f, 9.24797058f, 9.38251781f, 9.63836861f, 9.76825619f, + 10.0848188f, 10.1928482f, 10.6171074f, 10.7557335f, +}; + +const float xombe__ds_prba24[512][3] = { + {-1.02830362f, -0.267186105f, -0.552467883f}, + {-0.698486269f, -0.386001885f, -0.3730371f}, + {-0.436963022f, -0.356539428f, -0.290067136f}, + {-0.370192647f, -0.586873114f, -0.453026712f}, + {-0.957705319f, -0.159046769f, -0.182771713f}, + {-0.604416788f, -0.603455961f, -0.116224259f}, + {-0.511834919f, -0.183101162f, -0.196667507f}, + {-0.368722647f, -0.419388562f, -0.180350885f}, + {-0.974301934f, -0.682734251f, -0.0786006898f}, + {-0.599169791f, -0.277050585f, -0.0527108535f}, + {-0.391523778f, -0.729843378f, -0.0165324006f}, + {-0.391786277f, -0.315136611f, -0.0558129959f}, + {-0.623458385f, -0.218894571f, 0.194705188f}, + {-0.385743707f, -0.463431478f, 0.354549319f}, + {-0.373958081f, -0.377696633f, 0.0666282624f}, + {-0.305579036f, -0.181296095f, 0.00698294444f}, + {-0.628011644f, -0.194896922f, -0.174261466f}, + {-0.460036159f, -0.0586718991f, -0.239824653f}, + {-0.532128334f, -0.124798566f, -0.454549879f}, + {-0.340029895f, -0.0721333846f, -0.321142226f}, + {-0.54363662f, -0.176189825f, -0.043722976f}, + {-0.379134625f, -0.199088126f, -0.0591738783f}, + {-0.375910342f, -0.124748237f, -0.182953641f}, + {-0.329935104f, -0.186380759f, -0.130121171f}, + {-0.526428819f, 0.0123848626f, 0.11963588f}, + {-0.419580847f, 0.00797895342f, 0.0592831969f}, + {-0.30604893f, -0.130406782f, 0.111361489f}, + {-0.309957415f, -0.0624267124f, -0.00703509292f}, + {-0.851361334f, -0.0581890345f, 0.130756259f}, + {-0.714490414f, -0.105131648f, 0.395175189f}, + {-0.415864855f, -0.0508879721f, 0.275885105f}, + {-0.324078023f, -0.049083773f, 0.601367652f}, + {-0.890541255f, 0.0567485243f, -0.309366614f}, + {-0.50985527f, 0.134589136f, -0.402548492f}, + {-0.309961468f, 0.0808348358f, -0.252726525f}, + {-0.354869694f, -0.00823958684f, -0.31939441f}, + {-0.668445408f, 0.0987089053f, -0.199663788f}, + {-0.449770153f, 0.0725599229f, -0.0722002909f}, + {-0.394264609f, 0.138660342f, -0.130733579f}, + {-0.311459392f, 0.0692884251f, -0.136822894f}, + {-0.695195615f, 0.0289364588f, -0.0606416129f}, + {-0.465076149f, 0.187779695f, 0.0604076125f}, + {-0.319989055f, 0.0612429343f, 0.000457198097f}, + {-0.264567494f, -0.00361863174f, 0.107938565f}, + {-1.28234088f, 0.0957444608f, 0.315449625f}, + {-0.518309891f, 0.122804195f, 0.242030546f}, + {-0.383687913f, 0.0746443197f, 0.384815067f}, + {-0.289934605f, 0.144274071f, 0.0928959623f}, + {-1.24268973f, 0.207716301f, -0.234690353f}, + {-0.674548745f, 0.466912866f, -0.379383564f}, + {-0.554932475f, 0.291764379f, -0.269944727f}, + {-0.32964012f, 0.377581269f, -0.576084793f}, + {-0.806509793f, 0.42655468f, -0.0937799588f}, + {-0.622430801f, 0.187924504f, -0.0730849132f}, + {-0.51933676f, 0.351544738f, -0.0955975056f}, + {-0.406592309f, 0.35854736f, -0.266900599f}, + {-0.811329365f, 0.173109546f, 0.209642217f}, + {-0.564907491f, 0.649045885f, 0.0387894884f}, + {-0.474340677f, 0.344651788f, 0.113243759f}, + {-0.289523482f, 0.293223321f, 0.0481453761f}, + {-0.509381473f, 0.284906268f, 0.65362972f}, + {-0.357905775f, 0.238165647f, 0.318200558f}, + {-0.286824018f, 0.523521423f, 0.492793977f}, + {-0.297352493f, 0.483323336f, 0.26517123f}, + {-0.245537877f, -0.413448513f, -0.337339789f}, + {-0.259015143f, -0.246706843f, -0.294364452f}, + {-0.271431446f, -0.564188242f, -0.248885274f}, + {-0.129375637f, -0.478250027f, -0.227942497f}, + {-0.25411582f, -0.377008885f, -0.111838557f}, + {-0.168097243f, -0.304794252f, -0.19511655f}, + {-0.131957233f, -0.242015332f, -0.24216637f}, + {-0.0681135058f, -0.20108293f, -0.128756747f}, + {-0.183633745f, -0.182947263f, -0.0634733588f}, + {-0.17135863f, -0.446741372f, 0.0136097986f}, + {-0.133605316f, -0.388166606f, -0.0685452595f}, + {-0.0683529079f, -0.240161881f, -0.000627093541f}, + {-0.270235509f, -0.306241572f, 0.241310135f}, + {-0.186101556f, -0.257465541f, 0.120442905f}, + {-0.156369686f, -0.239495829f, 0.0196609441f}, + {-0.0885263383f, -0.567397237f, 0.166172057f}, + {-0.192413852f, -0.0520393215f, -0.243280426f}, + {-0.141029537f, -0.0659758747f, -0.1935734f}, + {-0.0465238392f, -0.000191234372f, -0.2930547f}, + {-0.0565212741f, -0.00227223523f, -0.789155006f}, + {-0.253145725f, -0.132125705f, -0.0615832396f}, + {-0.240721613f, -0.0621589981f, -0.145409942f}, + {-0.204111964f, -0.00337709836f, -0.0727181956f}, + {-0.126609609f, -0.0657833219f, -0.0672855526f}, + {-0.189361632f, -0.00280876714f, 0.126974165f}, + {-0.187315524f, -0.0589273907f, 0.0567993857f}, + {-0.111499086f, -0.128096521f, 0.12832588f}, + {-0.0962291062f, -0.173415601f, 0.0643652678f}, + {-0.192345247f, -0.0366982147f, 0.433385521f}, + {-0.189045668f, -0.0982906371f, 0.186904699f}, + {-0.122930542f, 0.00714133913f, 0.193058237f}, + {-0.0702656582f, 0.00784818549f, 0.352720499f}, + {-0.188174397f, 0.00851862412f, -0.171864271f}, + {-0.182523012f, 0.133091554f, -0.115627035f}, + {-0.17679286f, 0.151976839f, -0.198983401f}, + {-0.134147316f, 0.121672824f, -0.396655977f}, + {-0.259510368f, 0.191210449f, -0.0024116456f}, + {-0.147278517f, -0.00146872958f, -0.129899278f}, + {-0.0593179017f, 0.0037630864f, -0.0625042021f}, + {-0.0642659143f, 0.121342979f, -0.0619519241f}, + {-0.202601552f, 0.0980012193f, 0.131339416f}, + {-0.189647287f, 0.0608514175f, -0.0091817975f}, + {-0.10543666f, 0.122756012f, 0.0623181164f}, + {-0.0622593425f, 0.000191180035f, -0.00521488907f}, + {-0.245904148f, 0.0515635535f, 0.252875f}, + {-0.132354125f, 0.124105029f, 0.309444517f}, + {-0.0926089287f, 0.149870113f, 0.135034904f}, + {-0.0647068024f, 0.00216042763f, 0.121951722f}, + {-0.247939184f, 0.249998987f, -0.193585157f}, + {-0.189257786f, 0.704424739f, -0.20526278f}, + {-0.144715816f, 0.26898244f, -0.129792869f}, + {-0.056175679f, 0.36632815f, -0.340536863f}, + {-0.16701898f, 0.20863919f, -0.0525909811f}, + {-0.173575044f, 0.427118927f, -0.0805865377f}, + {-0.136328369f, 0.372922659f, 0.055559624f}, + {-0.0489454158f, 0.519344747f, -0.00974529423f}, + {-0.245643914f, 0.250525594f, 0.175197318f}, + {-0.140774548f, 0.568810344f, 0.238200843f}, + {-0.150127515f, 0.420313239f, 0.110131919f}, + {-0.0747629777f, 0.306975543f, 0.116403818f}, + {-0.28253454f, 0.18274574f, 0.448906302f}, + {-0.180877492f, 0.253005207f, 0.294661999f}, + {-0.0768564492f, 0.312868536f, 0.242169321f}, + {-0.0407279544f, 0.4073627f, 0.545058489f}, + {-0.0698137954f, -0.356135368f, -0.237880588f}, + {0.031822674f, -0.247642145f, -0.344542891f}, + {0.0825710222f, -0.264689833f, -0.290560156f}, + {0.0548319928f, -0.325486302f, -0.256061792f}, + {-0.0113568194f, -0.321168929f, -0.144058689f}, + {-0.00881581567f, -0.256349266f, -0.0612562597f}, + {-0.00279086689f, -0.530908644f, -0.143629864f}, + {0.0342256911f, -0.260222971f, -0.191974372f}, + {0.00919612683f, -0.41781643f, -0.000931926596f}, + {-0.00546920625f, -0.254966378f, 0.000666683656f}, + {0.00726533262f, -0.191427663f, 0.0581714176f}, + {0.0549314916f, -0.401227415f, -0.0183232632f}, + {-0.0689023212f, -0.1855755f, 0.11492788f}, + {-0.0401085205f, -0.369988561f, 0.0686357617f}, + {-0.0162897035f, -0.278877795f, 0.192873225f}, + {0.0142708225f, -0.307657897f, 0.11477787f}, + {-0.0610451773f, -0.117345445f, -0.238954201f}, + {-0.0159294084f, -0.112286419f, -0.505086482f}, + {-0.0183617231f, -0.0644979328f, -0.250561804f}, + {0.0544893481f, -0.19521974f, -0.192871645f}, + {-0.0682957247f, -0.124623895f, -0.0586569086f}, + {-0.0569320805f, -0.184727952f, 0.00317574432f}, + {-0.00660880702f, -0.132843584f, -0.125044316f}, + {-2.07144603e-05f, -0.199078485f, -0.127391547f}, + {-0.0661025867f, -0.0663573667f, 0.121831492f}, + {-0.000841298723f, -0.12151552f, -0.00257349247f}, + {0.0603245348f, -0.0600472502f, -0.000774616958f}, + {0.0580148585f, -0.132900849f, -0.00134292303f}, + {-0.0502679273f, -0.115981132f, 0.435711056f}, + {-0.00459900359f, -0.0542209856f, 0.258665144f}, + {0.00226278324f, -0.136493355f, 0.178099602f}, + {0.0664931834f, -0.197932065f, 0.321451396f}, + {-0.0688715875f, 0.0734371021f, -0.190529317f}, + {-0.0724386275f, -0.000847362098f, -0.128905445f}, + {0.0679854602f, 0.0664493665f, -0.126994193f}, + {0.0416229516f, 0.0669661686f, -0.326051474f}, + {0.000381145044f, 0.0687026158f, -0.0647049546f}, + {-0.0015771715f, -0.000758192909f, -0.000731418666f}, + {0.060677994f, -0.00166878407f, -0.123953007f}, + {0.0464767329f, 0.136728749f, -0.139218509f}, + {-0.000205336415f, 0.0676729381f, 0.124865688f}, + {-0.000600179599f, 0.131595209f, 0.0584155731f}, + {0.0578803457f, 0.00294014323f, 0.12330021f}, + {0.0684655532f, 0.0641683936f, 0.000602722808f}, + {-0.0604806766f, 0.037457794f, 0.186053216f}, + {-0.0821800083f, 0.0638225749f, 0.45171693f}, + {0.00334588275f, 0.0879658014f, 0.253679395f}, + {0.0592453182f, 0.115406729f, 0.192599773f}, + {0.00228746422f, 0.257123888f, -0.250531197f}, + {0.0218907557f, 0.376354724f, -0.0622356497f}, + {-0.00502420869f, 0.188365117f, -0.125420332f}, + {0.0525527932f, 0.516640007f, -0.185675278f}, + {0.0054293829f, 0.2616584f, -0.0103309164f}, + {-0.0168039631f, 0.189417019f, 0.0561300777f}, + {0.0803716332f, 0.317703247f, 0.0586307049f}, + {0.0593779571f, 0.206300646f, 0.00630915863f}, + {-0.0676523447f, 0.193660527f, 0.177714258f}, + {0.00190799113f, 0.266797215f, 0.129501566f}, + {0.0624520853f, 0.363731593f, 0.184979498f}, + {0.0476333126f, 0.254554451f, 0.243128881f}, + {-0.0491054356f, 0.179466397f, 0.469873935f}, + {-0.0229900219f, 0.290290922f, 0.366722077f}, + {0.00437607849f, 0.123642057f, 0.316310853f}, + {0.0631783083f, 0.193140894f, 0.233124524f}, + {0.11071343f, -0.103954397f, -0.312295586f}, + {0.079628706f, -0.338686556f, -0.172982007f}, + {0.147222638f, -0.347171903f, -0.219902933f}, + {0.175860405f, -0.189031228f, -0.118724108f}, + {0.127285928f, -0.194194764f, -0.0615221374f}, + {0.115512468f, -0.641738057f, -0.0306999516f}, + {0.0f, 0.0f, 0.0f}, + {0.131457001f, -0.385342121f, -0.0821792483f}, + {0.0628663078f, -0.243449047f, 0.0638835207f}, + {0.12092609f, -0.193261847f, 0.00339358859f}, + {0.11504776f, -0.182530582f, 0.120806016f}, + {0.184665263f, -0.248413846f, 0.124504477f}, + {0.0736069903f, -0.188897252f, 0.187186271f}, + {0.10494753f, -0.298062831f, 0.224541485f}, + {0.143312067f, -0.348832846f, 0.1346609f}, + {0.181101426f, -0.190114364f, 0.177169725f}, + {0.0599423125f, -0.122428104f, -0.118778534f}, + {0.0477833152f, -0.00784014259f, -0.20247291f}, + {0.115331665f, -0.0745453537f, -0.190208003f}, + {0.124654852f, -0.126019269f, -0.0621910058f}, + {0.0638792813f, -0.0641683638f, 0.0585767291f}, + {0.126364216f, -0.0601068549f, 0.000308672898f}, + {0.123094618f, -0.122958519f, 0.00323090446f}, + {0.191318303f, -0.0622425117f, 0.00266275019f}, + {0.0751859844f, -0.0156602338f, 0.184299842f}, + {0.123883985f, -0.129022017f, 0.120521031f}, + {0.12906979f, -0.0682688877f, 0.124107294f}, + {0.183956489f, -0.124029621f, 0.127368644f}, + {0.0471980534f, -0.066421397f, 0.234938011f}, + {0.0485022105f, 0.0121693769f, 0.451041073f}, + {0.195680588f, -0.124193706f, 0.374770641f}, + {0.186785445f, -0.113031253f, 0.255515963f}, + {0.0527380668f, 0.138653696f, -0.492446542f}, + {0.124614283f, 0.123332016f, -0.138247937f}, + {0.13032192f, 0.000317644503f, -0.122614183f}, + {0.197027296f, -0.0300769992f, -0.314093083f}, + {0.0672767982f, 0.0611449927f, 0.0653036311f}, + {0.0621100403f, 0.117603868f, 0.00112116325f}, + {0.190230608f, 0.0611734614f, -0.0576216914f}, + {0.187484205f, 0.12385346f, 0.0629497394f}, + {0.122952826f, 0.128888652f, 0.119946696f}, + {0.117087387f, 0.00487416144f, 0.129748911f}, + {0.185208887f, -0.00201888336f, 0.0632843524f}, + {0.195024922f, 0.120939739f, 0.11614316f}, + {0.0701325387f, 0.137804747f, 0.37869373f}, + {0.162034735f, 0.0479356907f, 0.693962514f}, + {0.128460959f, 0.0591713972f, 0.198891222f}, + {0.12678659f, 0.00848211441f, 0.252520591f}, + {0.0601872727f, 0.174918875f, -0.137803197f}, + {0.121156782f, 0.199695468f, -0.259355843f}, + {0.185450152f, 0.314571083f, -0.319033176f}, + {0.19274807f, 0.261957318f, -0.132540107f}, + {0.0535879396f, 0.43740648f, -0.0203953199f}, + {0.116442293f, 0.250458062f, -0.0196597315f}, + {0.183783993f, 0.189908996f, 0.0659745038f}, + {0.190464199f, 0.180401176f, -0.0565132573f}, + {0.0690982342f, 0.212279364f, 0.18512556f}, + {0.122125946f, 0.380621195f, 0.0641350672f}, + {0.176993787f, 0.254099339f, 0.12143153f}, + {0.217185035f, 0.244832113f, 0.194788814f}, + {0.126268581f, 0.295356601f, 0.369945675f}, + {0.209307432f, 0.672758698f, 0.263943076f}, + {0.181666404f, 0.191982687f, 0.248183072f}, + {0.181925714f, 0.292095006f, 0.254315972f}, + {0.237904772f, -0.526514471f, -0.206051499f}, + {0.149903402f, -0.755541682f, -0.582219005f}, + {0.301738381f, -0.354786277f, -0.348615497f}, + {0.259622872f, -0.432097644f, -0.543522179f}, + {0.179334566f, -0.300572664f, -0.0108094458f}, + {0.195711613f, -0.229105383f, -0.249670669f}, + {0.24374114f, -0.296400636f, -0.131171584f}, + {0.300223231f, -0.193551868f, -0.00273014465f}, + {0.183557376f, -0.402730107f, 0.107794985f}, + {0.235102057f, -0.229720533f, 0.00144078035f}, + {0.235879853f, -0.299344271f, 0.118620649f}, + {0.476008981f, -1.02245677f, 0.217563272f}, + {0.193108171f, -0.303673863f, 0.441523165f}, + {0.123538017f, -0.655139029f, 0.162086204f}, + {0.169096962f, -0.24165529f, 0.171194181f}, + {0.306368321f, -0.314097583f, 0.252899855f}, + {0.192850098f, -0.0618728511f, -0.192316353f}, + {0.177124619f, -0.118582867f, -0.426087558f}, + {0.262295365f, -0.18486698f, -0.130664051f}, + {0.258895457f, -0.1473784f, -0.255924106f}, + {0.246824339f, -0.193837598f, -0.0589724481f}, + {0.249571756f, -0.0649470314f, -0.0687112883f}, + {0.252487987f, -0.0779366344f, -0.125950575f}, + {0.316293925f, -0.124721251f, -0.0673320442f}, + {0.184360981f, -0.183534279f, 0.0542292632f}, + {0.236820519f, -0.0594333783f, 0.0049164705f}, + {0.259770066f, -0.122544296f, 0.00345158507f}, + {0.245529547f, -0.112485938f, 0.125422433f}, + {0.233336434f, -0.0589785948f, 0.305636287f}, + {0.258672565f, -0.207029283f, 0.317592531f}, + {0.250059366f, -0.0706282035f, 0.243940592f}, + {0.312076181f, -0.192766666f, 0.18912214f}, + {0.178019181f, 0.126674771f, -0.192806974f}, + {0.180101022f, 0.0649802834f, -0.132228836f}, + {0.300213248f, 0.044625558f, -0.311000526f}, + {0.320832729f, 0.0684396401f, -0.176418543f}, + {0.249966636f, -0.0612449981f, 0.0615930632f}, + {0.255313843f, -0.00760428188f, -0.0527159274f}, + {0.253355086f, 0.0621616915f, -0.000106817723f}, + {0.313577503f, 0.00684926612f, -0.0031609335f}, + {0.184952259f, -0.00672330987f, 0.190780982f}, + {0.201469988f, 0.064011313f, 0.143541828f}, + {0.312008649f, -0.00336930715f, 0.128436595f}, + {0.31942597f, 0.0654406622f, 0.189821541f}, + {0.183833241f, 0.0648322478f, 0.183292598f}, + {0.248756215f, 0.0677067637f, 0.326934785f}, + {0.263587147f, -0.00236984412f, 0.254016578f}, + {0.243619323f, 0.0661880597f, 0.450281292f}, + {0.246442452f, 0.236167997f, -0.185794666f}, + {0.262056291f, 0.254334688f, -0.0644907653f}, + {0.252235323f, 0.127875954f, -0.0663051307f}, + {0.330219924f, 0.592904091f, -0.0838286281f}, + {0.174344867f, 0.3145338f, 0.0585702285f}, + {0.248361126f, 0.358822286f, -0.0628058463f}, + {0.24510707f, 0.126993909f, 0.0564295091f}, + {0.320850432f, 0.187891483f, -0.077616632f}, + {0.250990629f, 0.456585944f, 0.128736392f}, + {0.243368119f, 0.170194462f, 0.184037119f}, + {0.252626657f, 0.196574166f, 0.0604226142f}, + {0.311113328f, 0.253450781f, 0.183771059f}, + {0.180766657f, 0.20046483f, 0.372166812f}, + {0.267885566f, 0.171461836f, 0.260591209f}, + {0.248788327f, 0.315317571f, 0.431351781f}, + {0.228132784f, 0.359845936f, 0.610385835f}, + {0.292932719f, -0.240408838f, -0.121105291f}, + {0.322103024f, -0.310098767f, -0.193834499f}, + {0.354373693f, -0.209468544f, -0.0517644696f}, + {0.496141404f, -0.547155797f, -0.215640545f}, + {0.293828726f, -0.303392559f, 0.0717946216f}, + {0.26642403f, -0.302045703f, 0.00703213271f}, + {0.25680545f, -0.383379668f, -0.070099324f}, + {0.345316648f, -0.231323972f, 0.0533889271f}, + {0.286500275f, -0.441476971f, 0.185453519f}, + {0.298041135f, -0.167071939f, 0.0712275207f}, + {0.307241738f, -0.335487664f, 0.135710791f}, + {0.394732744f, -0.25792262f, 0.121847525f}, + {0.407239288f, -0.410862535f, 0.404471934f}, + {0.346360177f, -0.209848866f, 0.41373238f}, + {0.346569836f, -0.251059622f, 0.250932515f}, + {0.359739512f, -0.271822214f, 0.593435824f}, + {0.363539577f, -0.126092255f, -0.0688879937f}, + {0.364626765f, -0.122240461f, -0.132032022f}, + {0.361787021f, -0.0619010925f, -0.112389758f}, + {0.440265566f, -0.00176905433f, -0.328042388f}, + {0.308985651f, -0.123485416f, 0.0679635182f}, + {0.0f, 0.0f, 0.0f}, + {0.365364075f, -0.0552988239f, -0.000578217383f}, + {0.382031292f, -0.192582086f, -0.00454487279f}, + {0.316862553f, -0.058202561f, 0.0572260357f}, + {0.396884799f, -0.0697675794f, 0.192545623f}, + {0.381438822f, -0.148141041f, 0.139253095f}, + {0.432816565f, -0.0633633956f, 0.0628790781f}, + {0.308765471f, -0.125069916f, 0.316123515f}, + {0.400333256f, -0.10350699f, 0.556868613f}, + {0.390900284f, -0.201157436f, 0.258547962f}, + {0.45438385f, -0.0636130273f, 0.187806934f}, + {0.306062102f, -0.00526470598f, -0.181416899f}, + {0.302630067f, 0.00311326142f, -0.0601056889f}, + {0.356365621f, 0.0695777312f, -0.190731585f}, + {0.332198203f, 0.133256987f, -0.252106905f}, + {0.307389945f, 0.0638384745f, -0.0606011041f}, + {0.37986213f, 0.0614529476f, -0.0033730173f}, + {0.378987193f, 0.111545309f, 0.00137070788f}, + {0.424080342f, 0.000980296638f, 8.47321062e-05f}, + {0.313787222f, 0.0665818825f, 0.058960028f}, + {0.308784485f, 0.125471324f, 0.125281125f}, + {0.383965224f, -0.000103518643f, 0.058584664f}, + {0.465092897f, 0.122967668f, 0.0535152927f}, + {0.311476856f, 0.0799933895f, 0.255539656f}, + {0.378456682f, -0.00349767529f, 0.30943957f}, + {0.36818549f, -0.000524636474f, 0.186527237f}, + {0.37351799f, 0.119551964f, 0.18074365f}, + {0.292084336f, 0.181564793f, -0.447718829f}, + {0.323237747f, 0.19231008f, -0.25680545f}, + {0.394947976f, 0.491860598f, -0.381115764f}, + {0.429030895f, 0.233528331f, -0.191788316f}, + {0.308152378f, 0.250792921f, -0.112596557f}, + {0.307408363f, 0.182783201f, 0.0621109717f}, + {0.316861928f, 0.306987584f, 0.00555574847f}, + {0.387273788f, 0.12001536f, -0.135266781f}, + {0.320498765f, 0.243779212f, 0.0582071543f}, + {0.361054897f, 0.329220027f, 0.116930723f}, + {0.363929003f, 0.190004051f, 0.125637263f}, + {0.415696651f, 0.289781332f, 0.237743422f}, + {0.336797923f, 0.426227748f, 0.312138647f}, + {0.378392667f, 0.112474717f, 0.391450912f}, + {0.377703339f, 0.757478833f, 0.659086406f}, + {0.427546591f, 0.121137381f, 0.628367424f}, + {0.430124879f, -0.256376207f, -0.310967982f}, + {0.442800373f, -0.239950508f, -0.153394267f}, + {0.379714251f, -0.375941873f, -0.256464422f}, + {0.577558696f, -0.268772274f, -0.128629103f}, + {0.428064972f, -0.233059511f, 0.0137377428f}, + {0.511679888f, -0.455484509f, -0.0559108667f}, + {0.49645102f, -0.31022346f, -0.13740392f}, + {0.527948797f, -0.352663845f, 0.013914194f}, + {0.470519036f, -0.315149873f, 0.185662538f}, + {0.393048733f, -0.362547576f, 0.131808057f}, + {0.495075285f, -0.209998548f, 0.0833521187f}, + {0.634423196f, -0.274771184f, 0.201565474f}, + {0.473429739f, -0.313295364f, 0.310859084f}, + {0.486204028f, -0.255457997f, 0.388061821f}, + {0.631184816f, -0.573754966f, 0.294858038f}, + {0.61764735f, -0.431044668f, 0.206589907f}, + {0.436686993f, -0.19800508f, -0.259600639f}, + {0.46540153f, -0.18106246f, -0.052245643f}, + {0.413727462f, -0.0561005808f, -0.111768395f}, + {0.61051625f, -0.182306707f, -0.126407534f}, + {0.448450804f, -0.120291576f, 0.0145762488f}, + {0.507582009f, -0.131519362f, -0.0616047755f}, + {0.566299736f, -0.112055428f, 0.0113124875f}, + {0.579146564f, -0.0828115344f, -0.0492566191f}, + {0.421965271f, -0.0719263777f, 0.131366178f}, + {0.52392149f, -0.184829727f, 0.126886055f}, + {0.596807241f, -0.056108471f, 0.140676022f}, + {0.65666914f, -0.22152254f, 0.187520087f}, + {0.451738834f, -0.0683934242f, 0.369928271f}, + {0.5151577f, -0.129775167f, 0.174258843f}, + {0.580211103f, -0.166072503f, 0.56200242f}, + {0.543402672f, -0.131048813f, 0.266107738f}, + {0.424854606f, 0.0506467186f, -0.180979431f}, + {0.485558599f, 0.104459241f, -0.194492161f}, + {0.534010947f, -0.00721844332f, -0.176345021f}, + {0.606422901f, 0.00704221381f, -0.31431964f}, + {0.448145628f, 0.0479210056f, -0.0730885416f}, + {0.486653924f, 0.0721073747f, 0.00182283192f}, + {0.510109782f, 0.114404619f, -0.0614100471f}, + {0.504863143f, -0.0582354032f, 0.0083379345f}, + {0.433073252f, 0.0670260638f, 0.174747959f}, + {0.522849321f, -0.0110419253f, 0.106281534f}, + {0.490313381f, 0.0652486533f, 0.118440911f}, + {0.564842045f, 0.12077418f, 0.0123034902f}, + {0.463567942f, 0.0765708312f, 0.471899986f}, + {0.522597373f, -0.0847571194f, 0.322544485f}, + {0.587580085f, -0.0152468262f, 0.258597851f}, + {0.583318114f, 0.0423158221f, 0.383448929f}, + {0.436291695f, 0.299852997f, -0.132643193f}, + {0.451695085f, 0.184684128f, -0.134615943f}, + {0.572262704f, 0.478617221f, -0.131702125f}, + {0.524752617f, 0.272725642f, -0.125062928f}, + {0.433151454f, 0.251974404f, -0.0621954277f}, + {0.443242252f, 0.24953045f, 0.0521122403f}, + {0.508700967f, 0.232888117f, -0.0615754947f}, + {0.637827158f, 0.114130206f, -0.139175773f}, + {0.518254638f, 0.376706749f, 0.0525662228f}, + {0.502201617f, 0.134018734f, 0.113672912f}, + {0.505528986f, 0.537706077f, 0.100928843f}, + {0.580384851f, 0.196993202f, 0.122568607f}, + {0.506350756f, 0.164387628f, 0.258495599f}, + {0.510310352f, 0.577260792f, 0.356728286f}, + {0.532469213f, 0.233948261f, 0.180471137f}, + {0.548258662f, 0.287587374f, 0.382787138f}, + {0.6296646f, -0.317566186f, -0.167284891f}, + {0.596178949f, -0.20880194f, -0.311726391f}, + {0.804622769f, -0.434567124f, -0.380205154f}, + {1.34208965f, -0.204876035f, -0.32383588f}, + {0.695733964f, -0.333117038f, -0.0554609336f}, + {0.78772527f, -0.246678248f, -0.049248565f}, + {1.08982682f, -0.201280281f, 0.0689718053f}, + {1.00159848f, -0.43317616f, -0.0335088409f}, + {0.601016939f, -0.258355737f, 0.142682031f}, + {0.740491092f, -0.155699044f, 0.0639944971f}, + {0.793144822f, -0.325352907f, 0.140128747f}, + {1.15903592f, -0.149568528f, 0.308962256f}, + {0.662063181f, -0.340529501f, 0.586983263f}, + {0.750462294f, -0.258736283f, 0.330079466f}, + {0.852660298f, -0.518972516f, 0.342483819f}, + {0.99999088f, -0.315541804f, 0.500195324f}, + {0.608316481f, -0.0842056051f, -0.158539608f}, + {0.69587189f, 0.0471901633f, -0.189273745f}, + {0.797993243f, -0.080861561f, -0.197377101f}, + {1.10072327f, -0.134406254f, -0.156038582f}, + {0.650564432f, 0.0605932064f, -0.0558115542f}, + {0.674667776f, -0.125790685f, -0.0715969726f}, + {0.856324136f, -0.153681293f, 0.0210150871f}, + {1.40914583f, -0.0356996991f, 0.0166429542f}, + {0.638313055f, -0.0100922817f, 0.0652638301f}, + {0.695196152f, -0.0842498168f, 0.192425743f}, + {0.786601365f, 0.0252865907f, 0.00196674932f}, + {0.840500176f, -0.0276603047f, 0.133789882f}, + {0.618385732f, 0.0463282466f, 0.249808446f}, + {0.691667795f, -0.0812016502f, 0.387409925f}, + {0.670351326f, -0.00209820201f, 0.472046733f}, + {0.949733555f, -0.0805567056f, 0.270513237f}, + {0.686250806f, 0.182848558f, -0.295687228f}, + {0.761586428f, 0.138295904f, -0.500766754f}, + {0.979175389f, 0.181303993f, -0.270973265f}, + {1.78947318f, 0.0958578587f, -0.265792131f}, + {0.755793333f, 0.176156223f, -0.112535268f}, + {0.871407628f, 0.164027408f, -0.0481075644f}, + {0.943540514f, 0.115136772f, -0.005622664f}, + {1.15868127f, 0.150599688f, -0.186898515f}, + {0.648174167f, 0.199505925f, 0.264001906f}, + {0.609803677f, 0.177283436f, 0.105931841f}, + {0.719138861f, 0.164672881f, -0.00778099382f}, + {0.937683582f, 0.233123332f, 0.262219816f}, + {0.700564504f, 0.167955816f, 0.42469877f}, + {0.77120316f, 0.0300044362f, 0.316926748f}, + {0.935475051f, 0.112130329f, 0.395970583f}, + {1.41228366f, 0.172927216f, 0.424237937f}, + {0.634470344f, 0.211359754f, -0.0751061738f}, + {0.70550406f, 0.342937559f, 0.00117601838f}, + {1.06358171f, 0.927507043f, -0.305544049f}, + {1.348261f, 0.330113858f, -0.242802456f}, + {0.853292465f, 0.298062712f, 0.0964159369f}, + {0.887952566f, 0.448594362f, 0.00808941294f}, + {1.10850263f, 0.340356171f, 0.0318192318f}, + {1.50507355f, 0.411549896f, 0.112004712f}, + {0.632693291f, 0.35992071f, 0.244869143f}, + {0.880998075f, 0.362813711f, 0.288463175f}, + {1.11744094f, 0.603134394f, 0.160329744f}, + {1.19162345f, 0.215550333f, 0.179798305f}, + {0.677110791f, 0.394534886f, 0.409911513f}, + {0.778429449f, 0.364837289f, 0.669847429f}, + {0.933602393f, 0.724889815f, 0.465191007f}, + {1.33942914f, 0.657866597f, 0.587207258f}, +}; + +const float xombe__ds_prba58[128][4] = { + {-0.420051426f, -0.242630422f, -0.25676477f, -0.0527240187f}, + {-0.348180413f, -0.111261614f, -0.0757267848f, -0.0465609059f}, + {-0.23628597f, -0.287911236f, -0.148101732f, -0.100302391f}, + {-0.151970133f, -0.0800645724f, -0.0799079016f, -0.19245255f}, + {-0.454046488f, -0.0745474175f, -0.16245161f, 0.153388575f}, + {-0.211341009f, -0.0420862027f, -0.118205868f, 0.0823493153f}, + {-0.167907611f, -0.139624968f, -0.264220923f, 0.0702480301f}, + {-0.183644354f, -0.114724353f, -0.148671195f, -0.0436328426f}, + {-0.320138335f, -0.0348574333f, 0.133896381f, -0.119482227f}, + {-0.28856197f, -0.136462584f, 0.174750447f, 0.00650766399f}, + {-0.178693518f, -0.223081723f, -0.00640690792f, -0.100386456f}, + {-0.159298733f, -0.0295119919f, 0.0141383875f, -0.0966623276f}, + {-0.389048576f, -0.268931985f, 0.0478566512f, 0.0317388028f}, + {-0.199141577f, -0.203131199f, -0.0739170089f, 0.0411864035f}, + {-0.163401783f, -0.148885578f, -0.0456122831f, 0.162793294f}, + {-0.14838323f, -0.0802515596f, 0.0812019333f, 0.120458305f}, + {-0.299895048f, 0.0589154363f, -0.199721336f, -0.0824980661f}, + {-0.262959033f, 0.147793546f, -0.0378424637f, -0.127991319f}, + {-0.237691268f, 0.0792861357f, -0.0319697037f, 0.0114292707f}, + {-0.204582632f, -0.000597405829f, -0.0895366669f, -0.0687279999f}, + {-0.453880519f, 0.172367677f, -0.0657651573f, 0.0336092673f}, + {-0.307125688f, 0.127130076f, -0.165768966f, 0.0926766023f}, + {-0.181012064f, 0.265842944f, -0.0581781194f, 0.265623033f}, + {-0.176197514f, 0.228777945f, -0.115719907f, 0.0163181238f}, + {-0.312912285f, -0.00264977128f, -0.000962914142f, 0.0879664347f}, + {-0.260702014f, 0.264431f, 0.0394562744f, 0.0977958217f}, + {-0.243145525f, 0.108048975f, 0.120657749f, -0.0445037857f}, + {-0.174853057f, -0.0130051803f, 0.0900295675f, 0.00748289656f}, + {-0.408839613f, 0.0551224351f, 0.095553264f, 0.199201867f}, + {-0.169671804f, 0.0982829705f, 0.208851427f, 0.115319118f}, + {-0.185766444f, 0.00352677586f, 0.00321406708f, 0.267762065f}, + {-0.175247297f, 0.0860459954f, 0.00685672928f, 0.129137054f}, + {-0.0586636886f, -0.117593154f, -0.247296169f, -0.150017068f}, + {-0.0544624291f, -0.22269696f, -0.112464212f, -0.0227302313f}, + {-0.0432921983f, -0.168146089f, -0.0647317693f, -0.120479882f}, + {-0.0423814617f, -0.0317945704f, -0.0944007337f, -0.0817221105f}, + {-0.15904665f, -0.0296155736f, -0.0175935496f, 0.0362112485f}, + {-0.0868208632f, 0.0139958039f, -0.172646746f, 0.160382912f}, + {-0.0771812424f, -0.0778301209f, -0.0699242651f, 0.0472276807f}, + {-0.0455461517f, -0.19349955f, -0.0578409806f, 0.103816159f}, + {-0.0960097387f, -0.0492157303f, 0.104826644f, -0.0952267423f}, + {-0.057164371f, -0.00849431939f, 0.00559214549f, -0.0109800743f}, + {-0.0358867273f, -0.129867107f, 0.0330043435f, -0.0320958979f}, + {-0.0216486994f, -0.14714171f, 0.199771196f, -0.0925636142f}, + {-0.150832891f, -0.108203694f, 0.021501217f, 0.00230423245f}, + {-0.0363144539f, -0.0857634097f, 0.0330338553f, 0.0834458992f}, + {-0.0324538983f, -0.224492446f, 0.123522602f, 0.0611921772f}, + {-0.0177734513f, -0.0120259225f, 0.161832362f, 0.149932966f}, + {-0.11087402f, 0.1254749f, -0.115357675f, -0.131831065f}, + {-0.0966762304f, 0.0228022523f, -0.187627926f, -0.00189347565f}, + {-0.0857539773f, 0.381209791f, -0.0717559084f, -0.0915571302f}, + {-0.0236934647f, 0.0982792675f, -0.0617963783f, -0.00730049005f}, + {-0.139702588f, 0.203520194f, -0.276086628f, 0.132202446f}, + {-0.110044718f, 0.123979136f, -0.121167503f, 0.0583414249f}, + {-0.0866667554f, 0.0187608674f, -0.0784086064f, 0.0327488333f}, + {-0.0351144001f, 0.203343108f, -0.0234529097f, 0.120755479f}, + {-0.125879034f, 0.158621073f, 0.068675071f, -0.13719964f}, + {-0.108353466f, 0.0800354779f, 0.311754048f, -0.103117846f}, + {-0.0926254168f, 0.0647131503f, 0.00808878057f, -0.0762027428f}, + {-0.046197243f, 0.0512409359f, 0.144142494f, -0.0222115293f}, + {-0.127561361f, 0.147950813f, 0.00356149231f, 0.0124604004f}, + {-0.0850255117f, 0.0500292592f, 0.0536522269f, 0.0376370698f}, + {-0.0515606888f, 0.13916187f, 0.116330408f, 0.0978427082f}, + {-0.0551304184f, 0.0434948877f, -0.0181162097f, 0.104913719f}, + {0.0531509928f, -0.0625684708f, -0.0583090745f, -0.226004556f}, + {0.0614045225f, -0.129125729f, -0.0891073048f, -0.0974195004f}, + {0.0812333524f, -0.0173881594f, -0.12903218f, -0.0172049329f}, + {0.0910223797f, -0.421699435f, -0.143405482f, -0.0498521738f}, + {-0.0115512619f, -0.0526619107f, -0.0471256003f, 0.171707749f}, + {0.0150246453f, -0.08080782f, -0.198509112f, 0.0535352975f}, + {0.0150672067f, -0.0911393538f, -0.0753236115f, 0.0237365775f}, + {0.0556854941f, -0.185994938f, -0.173082933f, 0.146349683f}, + {0.00658332696f, -0.0349967964f, 0.0457847267f, -0.0889327526f}, + {0.0268713515f, 0.0275370795f, 0.107645899f, -0.171739817f}, + {0.1102084f, -0.173468336f, 0.09789408f, -0.17535615f}, + {0.100366093f, -0.0293081291f, -0.0231584273f, -0.120071009f}, + {-0.00799916219f, -0.0393370315f, 0.105842076f, 0.0219741669f}, + {0.0444399603f, -0.0173982754f, 0.017264137f, 0.0765378252f}, + {0.0511328094f, -0.0508447997f, -0.0229229219f, -0.02407513f}, + {0.073420234f, -0.139101028f, 0.0663989559f, -0.0161533039f}, + {0.00438015675f, 0.0667073131f, -0.0353951156f, -0.205779806f}, + {0.00844007451f, 0.141267002f, -0.183740959f, -0.0389067307f}, + {0.0218413677f, 0.0357240066f, -0.0398843624f, -0.0389243364f}, + {0.0532355346f, 0.115320653f, -0.0124180038f, -0.102488972f}, + {0.0100529566f, 0.0421069786f, -0.116803832f, 0.0782230422f}, + {0.0518212691f, 0.0627646223f, -0.285299897f, 0.172812507f}, + {0.0539454892f, 0.26620996f, -0.126887366f, 0.0842120945f}, + {0.0947887599f, 0.101471998f, -0.0739801526f, 0.0481788032f}, + {-0.0161648095f, 0.120618582f, 0.0416919887f, -0.0318493247f}, + {0.00101547362f, 0.274931341f, 0.0507960096f, 0.00150885456f}, + {0.0728293881f, 0.0364716873f, 0.0694234297f, -0.0191408619f}, + {0.106858358f, 0.183058441f, 0.091373764f, -0.212524191f}, + {0.0483773239f, 0.0782935694f, 0.0381771065f, 0.0703466907f}, + {0.0537730455f, 0.0992993042f, 0.0114655662f, 0.263021141f}, + {0.0684222728f, 0.136203721f, 0.263174713f, 0.0237850752f}, + {0.0823058859f, 0.335416079f, 0.158946931f, 0.131678268f}, + {0.197726324f, -0.110305339f, 0.0165289771f, -0.0452702865f}, + {0.226587534f, -0.173386648f, -0.152739793f, -0.116730988f}, + {0.302281141f, -0.0985332727f, -0.11122077f, 0.0353910699f}, + {0.498182505f, -0.194717333f, -0.118639782f, 0.0232774504f}, + {0.102223203f, -0.180823058f, -0.0383809544f, 0.0420519561f}, + {0.132151484f, -0.0571153611f, -0.0356205478f, 0.068721287f}, + {0.162777647f, -0.00096990692f, -0.112977326f, 0.171692103f}, + {0.427349389f, 0.0148385558f, -0.0353042707f, 0.208264172f}, + {0.135357708f, -0.0206027664f, 0.147597536f, -0.0915468484f}, + {0.152874663f, -0.129834861f, 0.221109703f, -0.00575071666f}, + {0.28606528f, -0.268120021f, 0.126267299f, -0.0911094397f}, + {0.380848199f, -0.12789306f, 0.102220818f, -0.133516088f}, + {0.117018141f, -0.0796406865f, 0.0918317065f, 0.179814368f}, + {0.21610409f, -0.225878656f, 0.0694085509f, 0.131253809f}, + {0.266004622f, -0.0374233313f, 0.054503426f, 0.138415799f}, + {0.290193588f, -0.00334576401f, 0.246588334f, 0.00691074552f}, + {0.12394131f, 0.277229369f, -0.228858665f, -0.098802194f}, + {0.129346624f, 0.0159055404f, -0.187759414f, -0.131005958f}, + {0.169578627f, 0.181947038f, -0.0795089677f, -0.0684519708f}, + {0.284134388f, 0.0436545648f, -0.117233723f, -0.246892497f}, + {0.163661525f, 0.023316199f, -0.0202378612f, -0.0374578759f}, + {0.167321086f, 0.13762024f, -0.261434644f, 0.0499675348f}, + {0.208471179f, 0.0265466366f, -0.145316541f, 0.00130907574f}, + {0.375458419f, 0.171207115f, -0.0998081788f, -0.0188601948f}, + {0.233821556f, 0.075730294f, 0.0243224371f, -0.143678337f}, + {0.243243739f, 0.253917545f, 0.162586853f, -0.0637149438f}, + {0.305057704f, 0.0471961573f, 0.0881381705f, -0.00272224634f}, + {0.519472241f, 0.189930618f, 0.0693198293f, -0.00645836815f}, + {0.115938298f, 0.17615971f, 0.050228484f, 0.030930806f}, + {0.130194917f, 0.0358159654f, 0.136905983f, 0.0663563162f}, + {0.213722393f, 0.0640178099f, 0.00641213218f, 0.0401915126f}, + {0.219558403f, 0.236762404f, 0.00711718248f, 0.139040872f}, +}; + +const float xombe__ds_hoc5[16][4] = { + {-0.59902364f, -0.0152449263f, 0.0107888673f, -0.035585586f}, + {-0.462826759f, -0.299004346f, -0.271937132f, -0.0849793032f}, + {-0.319423974f, 0.041840639f, 0.00593571691f, -0.0206029695f}, + {-0.307291985f, -0.253534764f, -0.0247120745f, 0.0107408771f}, + {-0.170344979f, 0.136169747f, -0.184117928f, -0.021147497f}, + {-0.147250608f, 0.223273337f, 0.0481090248f, -0.0334132239f}, + {-0.141756579f, -0.0133125894f, -0.0111601185f, -0.0191169102f}, + {-0.111782685f, -0.102282062f, 0.166739821f, -0.06274876f}, + {-0.115460537f, -0.110679209f, -0.0353518464f, 0.177067369f}, + {-0.100439757f, -0.192795262f, -0.234083474f, -0.103720985f}, + {0.00731254322f, -0.0105299251f, -0.0229325928f, -0.014468818f}, + {0.076473631f, -0.25941956f, -0.01318698f, 0.00765020866f}, + {0.100120798f, 0.0485494919f, -0.210126862f, -0.0114630004f}, + {0.157253563f, 0.227338985f, 0.0747044533f, 0.027493054f}, + {0.178858638f, -0.0234111287f, 0.00475204596f, -0.0120257856f}, + {0.437506169f, 0.007496926f, -0.016950747f, 0.000121958146f}, +}; + +const float xombe__ds_hoc6[16][4] = { + {-0.422028571f, -0.0336025767f, 0.0304927267f, 0.00866079889f}, + {-0.285935283f, 0.17990832f, 0.124680944f, 0.0206449125f}, + {-0.199283719f, -0.2109202f, -0.0422050655f, -0.00907617901f}, + {-0.173043728f, 0.00334157748f, -0.00912865531f, 0.00105126307f}, + {-0.156596974f, 0.23706305f, -0.0830668435f, -0.0450760014f}, + {-0.0464600287f, -0.0529385991f, 0.19237642f, -0.0198576692f}, + {-0.0166322812f, 0.116662994f, 0.0359614156f, -0.0197871961f}, + {-0.00821052678f, -0.0163372569f, -0.189275861f, -0.00545637682f}, + {0.00509880809f, -0.0476942286f, -0.00307700527f, -0.0130169448f}, + {0.0133276777f, -0.0261655767f, 0.0406207331f, 0.19725582f}, + {0.0235173292f, -0.265302628f, -0.0167689882f, -0.0177244768f}, + {0.139900208f, 0.242954016f, 0.0226376541f, 0.00791371893f}, + {0.160584018f, 0.0139226671f, 0.00580855133f, -0.0232239198f}, + {0.198162079f, -0.150612921f, -0.184835523f, 0.0428594798f}, + {0.250269234f, -0.16936402f, 0.0554509982f, -0.00842270441f}, + {0.405032545f, 0.0395952053f, -0.0382434465f, 0.00981337018f}, +}; + +const float xombe__ds_hoc7[16][4] = { + {-0.370817691f, -0.0956008583f, 0.0131684542f, 0.0169240236f}, + {-0.320256561f, 0.223357156f, 0.0112287095f, -0.00850011967f}, + {-0.152239546f, 0.031756945f, -0.0313141756f, -0.0433400236f}, + {-0.150172666f, -0.00984311011f, 0.18051739f, -0.0211580414f}, + {-0.0890956223f, -0.240410805f, 0.0311706904f, -0.00680770399f}, + {-0.0745001212f, -0.138984546f, -0.177378967f, -0.00167908717f}, + {-0.0277735908f, 0.180788577f, -0.154017031f, 0.0105331857f}, + {-0.0242832117f, -0.00806146394f, -0.00678265886f, 0.164010748f}, + {-0.0101174163f, 0.193488553f, 0.0583548844f, -0.0201338287f}, + {4.04519924e-05f, -0.0378706194f, -0.00220256206f, -0.018984979f}, + {0.139195263f, -0.0754575878f, 0.171328127f, -0.0116784768f}, + {0.159595743f, 0.0184791181f, -0.00883410498f, -0.0171788801f}, + {0.179429203f, -0.0102768214f, -0.207377821f, -0.00574332895f}, + {0.217825159f, 0.220500425f, 0.00447963085f, 0.0232494492f}, + {0.220952719f, -0.229971349f, -0.033507742f, 0.013696773f}, + {0.429353714f, 0.0463246554f, -0.0102377031f, -0.00111083069f}, +}; + +const float xombe__ds_hoc8[8][4] = { + {-0.458165556f, 0.18467097f, 0.0672645643f, -0.00143411162f}, + {-0.285831481f, 0.189613074f, -0.203223765f, 0.0518543012f}, + {-0.147099748f, -0.0263527483f, 0.205841109f, -0.0452918373f}, + {-0.1140019f, 0.232151717f, 0.0254448615f, -0.0474876575f}, + {-0.0547515303f, 0.0906963125f, -0.0723368376f, 0.0751966536f}, + {0.022507729f, 0.000613270444f, 0.0228097402f, -0.0404667445f}, + {0.161655813f, -0.0553856641f, -0.0867220461f, 0.0708565488f}, + {0.212200195f, -0.167514294f, 0.132527411f, -0.0109860506f}, +}; + +const unsigned char xombe__ds_ok_dg[64] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +const unsigned char xombe__ds_ok_prba24[512] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +const unsigned char xombe__ds_ok_prba58[128] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +const unsigned char xombe__ds_ok_hoc5[16] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +const unsigned char xombe__ds_ok_hoc6[16] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +const unsigned char xombe__ds_ok_hoc7[16] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +const unsigned char xombe__ds_ok_hoc8[8] = { + 1, 1, 1, 1, 1, 1, 1, 1, +}; + +const unsigned char xombe__ds_vuv[16][8] = { + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 1, 1}, + {0, 0, 0, 0, 1, 1, 0, 0}, + {0, 0, 0, 0, 1, 1, 1, 1}, + {1, 1, 1, 1, 0, 0, 0, 0}, + {0, 0, 1, 1, 0, 0, 1, 1}, + {0, 0, 1, 1, 1, 1, 0, 0}, + {0, 0, 1, 1, 1, 1, 1, 1}, + {1, 1, 0, 0, 0, 0, 0, 0}, + {1, 1, 0, 0, 0, 0, 1, 1}, + {1, 1, 0, 0, 1, 1, 0, 0}, + {1, 1, 0, 0, 1, 1, 1, 1}, + {1, 1, 1, 1, 0, 0, 0, 0}, + {1, 1, 1, 1, 0, 0, 1, 1}, + {1, 1, 1, 1, 1, 1, 0, 0}, + {1, 1, 1, 1, 1, 1, 1, 1}, +}; + +const unsigned char xombe__ds_tone_id[256] = { + 129, 132, 135, 142, 130, 133, 136, 128, 131, 134, 137, 143, 138, 139, 140, 141, + 160, 161, 162, 163, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, +}; + +const unsigned char xombe__ds_knox_b0[16] = { + 120, 68, 121, 104, 98, 61, 121, 114, 91, 100, 94, 106, 121, 93, 84, 84, +}; diff --git a/xombe/src/tables/dstar_tables.h b/xombe/src/tables/dstar_tables.h new file mode 100644 index 0000000..2a4cc9f --- /dev/null +++ b/xombe/src/tables/dstar_tables.h @@ -0,0 +1,43 @@ +#ifndef XOMBE_DSTAR_TABLES_H +#define XOMBE_DSTAR_TABLES_H + +/* D-STAR (AMBE 2400) tables, generated by scripts/gen_dstar_tables.py, do not edit + each value is a fitted double rounded once to float, spectral block lengths are AMBE+2's xombe__blk */ + +#define XOMBE_DS_B0_COUNT 128 + +/* pitch grid f0 = 2^(P0 + P1*(b0 + 1/2)) cycles/sample, from doubles -4.24503 and -0.021815 */ +#define XOMBE_DS_P0 -4.24502993f +#define XOMBE_DS_P1 -0.0218150001f +/* amplitude prediction weight and gain recursion (0: b2 is an absolute gain index) */ +#define XOMBE_DS_RHO 0.800000012f +#define XOMBE_DS_GRHO 0.0f +#define XOMBE_DS_TONE_NONE 255 + +/* f0 in cycles/sample and L = floor(0.4627/f0) clamped to 9..56, both from the double f0 (voice b0 0..123) */ +extern const float xombe__ds_w0[XOMBE_DS_B0_COUNT]; +extern const unsigned char xombe__ds_lt[XOMBE_DS_B0_COUNT]; +/* gain (b2), PRBA (b3, b4), and HOC (b5..b8, rows of 4, first min(J, 6) - 2 used) codebooks */ +extern const float xombe__ds_dg[64]; +extern const float xombe__ds_prba24[512][3]; +extern const float xombe__ds_prba58[128][4]; +extern const float xombe__ds_hoc5[16][4]; +extern const float xombe__ds_hoc6[16][4]; +extern const float xombe__ds_hoc7[16][4]; +extern const float xombe__ds_hoc8[8][4]; +/* 1 where the fit had data for the entry, the closed-loop quantizer skips the others */ +extern const unsigned char xombe__ds_ok_dg[64]; +extern const unsigned char xombe__ds_ok_prba24[512]; +extern const unsigned char xombe__ds_ok_prba58[128]; +extern const unsigned char xombe__ds_ok_hoc5[16]; +extern const unsigned char xombe__ds_ok_hoc6[16]; +extern const unsigned char xombe__ds_ok_hoc7[16]; +extern const unsigned char xombe__ds_ok_hoc8[8]; +/* b1 -> eight 500 Hz band flags as the decoder plays them (code 4 plays as 12) */ +extern const unsigned char xombe__ds_vuv[16][8]; +/* tone index T (8 bits) -> AMBE+2 tone ID, or XOMBE_DS_TONE_NONE */ +extern const unsigned char xombe__ds_tone_id[256]; +/* encoder sends Knox tones (AMBE+2 IDs 144..159, no D-STAR tone code) as voice frames at this b0 per ID */ +extern const unsigned char xombe__ds_knox_b0[16]; + +#endif diff --git a/xombe/src/tables/tables.c b/xombe/src/tables/tables.c new file mode 100644 index 0000000..0427704 --- /dev/null +++ b/xombe/src/tables/tables.c @@ -0,0 +1,869 @@ +#include "tables.h" + +const float xombe__w0[XOMBE_B0_COUNT] = { + 0.049971f, 0.049215f, 0.048471f, 0.047739f, 0.04701f, 0.046299f, + 0.045601f, 0.044905f, 0.044226f, 0.043558f, 0.0429f, 0.042246f, + 0.041609f, 0.040979f, 0.040356f, 0.039747f, 0.039148f, 0.038559f, + 0.037971f, 0.037399f, 0.036839f, 0.036278f, 0.035732f, 0.035198f, + 0.034672f, 0.034145f, 0.033636f, 0.033133f, 0.032635f, 0.032148f, + 0.03167f, 0.031122f, 0.030647f, 0.030184f, 0.029728f, 0.029272f, + 0.028831f, 0.028395f, 0.027966f, 0.027538f, 0.027122f, 0.026712f, + 0.026304f, 0.025906f, 0.025515f, 0.025129f, 0.024746f, 0.024372f, + 0.024002f, 0.023636f, 0.023279f, 0.022926f, 0.022581f, 0.022236f, + 0.0219f, 0.02157f, 0.02124f, 0.02092f, 0.020605f, 0.020294f, + 0.019983f, 0.019684f, 0.019386f, 0.019094f, 0.018805f, 0.01852f, + 0.018242f, 0.017965f, 0.017696f, 0.017431f, 0.01717f, 0.016911f, + 0.016657f, 0.016409f, 0.016163f, 0.015923f, 0.015686f, 0.015411f, + 0.015177f, 0.014946f, 0.014721f, 0.014496f, 0.014277f, 0.014061f, + 0.013847f, 0.013636f, 0.01343f, 0.013227f, 0.013025f, 0.012829f, + 0.012634f, 0.012444f, 0.012253f, 0.012068f, 0.011887f, 0.011703f, + 0.011528f, 0.011353f, 0.011183f, 0.011011f, 0.010845f, 0.010681f, + 0.010517f, 0.010359f, 0.010202f, 0.01005f, 0.009895f, 0.009747f, + 0.0096f, 0.009453f, 0.009312f, 0.009172f, 0.009033f, 0.008896f, + 0.008762f, 0.008633f, 0.008501f, 0.008375f, 0.008249f, 0.008125f, +}; + +const unsigned char xombe__lt[XOMBE_B0_COUNT] = { + 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, + 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, + 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, + 23, 23, 23, 24, 24, 24, 25, 25, 26, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 30, + 31, 31, 32, 32, 33, 33, 34, 34, 35, 36, 36, 37, 37, 38, 38, 39, 40, 40, 41, 42, + 42, 43, 43, 44, 45, 46, 46, 47, 48, 48, 49, 50, 51, 52, 52, 53, 54, 55, 56, 56, +}; + +const unsigned char xombe__vuv[32][8] = { + {1, 1, 1, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 0, 0}, + {1, 1, 0, 1, 1, 1, 1, 1}, + {1, 1, 1, 0, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 0, 1, 1}, + {1, 1, 1, 1, 0, 0, 0, 0}, + {1, 1, 1, 1, 1, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 1}, + {1, 1, 0, 0, 0, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 0}, + {1, 0, 0, 0, 0, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, +}; + +const unsigned char xombe__blk[57][4] = { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {2, 2, 2, 3}, + {2, 2, 3, 3}, + {2, 3, 3, 3}, + {2, 3, 3, 4}, + {3, 3, 3, 4}, + {3, 3, 4, 4}, + {3, 3, 4, 5}, + {3, 4, 4, 5}, + {3, 4, 5, 5}, + {4, 4, 5, 5}, + {4, 4, 5, 6}, + {4, 4, 6, 6}, + {4, 5, 6, 6}, + {4, 5, 6, 7}, + {5, 5, 6, 7}, + {5, 5, 7, 7}, + {5, 6, 7, 7}, + {5, 6, 7, 8}, + {5, 6, 8, 8}, + {6, 6, 8, 8}, + {6, 6, 8, 9}, + {6, 7, 8, 9}, + {6, 7, 9, 9}, + {6, 7, 9, 10}, + {7, 7, 9, 10}, + {7, 8, 9, 10}, + {7, 8, 10, 10}, + {7, 8, 10, 11}, + {8, 8, 10, 11}, + {8, 9, 10, 11}, + {8, 9, 11, 11}, + {8, 9, 11, 12}, + {8, 9, 11, 13}, + {8, 9, 12, 13}, + {8, 10, 12, 13}, + {9, 10, 12, 13}, + {9, 10, 12, 14}, + {9, 10, 13, 14}, + {9, 11, 13, 14}, + {10, 11, 13, 14}, + {10, 11, 13, 15}, + {10, 11, 14, 15}, + {10, 12, 14, 15}, + {10, 12, 14, 16}, + {11, 12, 14, 16}, + {11, 12, 15, 16}, + {11, 12, 15, 17}, + {11, 13, 15, 17}, +}; + +const float xombe__dg[32] = { + -2.0f, -0.67f, 0.297941f, 0.663728f, + 1.036829f, 1.438136f, 1.890077f, 2.22797f, + 2.478289f, 2.667544f, 2.793619f, 2.893261f, + 3.02063f, 3.138586f, 3.237579f, 3.32257f, + 3.432367f, 3.571863f, 3.69665f, 3.814917f, + 3.920932f, 4.022503f, 4.123569f, 4.228291f, + 4.370569f, 4.5437f, 4.707695f, 4.848879f, + 5.056757f, 5.326468f, 5.777581f, 6.874496f, +}; + +const float xombe__prba24[512][3] = { + {0.526055f, -0.328567f, -0.304727f}, + {0.441044f, -0.303127f, -0.201114f}, + {1.030896f, -0.32473f, -0.397204f}, + {0.839696f, -0.351933f, -0.224909f}, + {0.272958f, -0.176118f, -0.098893f}, + {0.221466f, -0.160045f, -0.061026f}, + {0.496555f, -0.211499f, 0.047305f}, + {0.424376f, -0.223752f, 0.069911f}, + {0.264531f, -0.353355f, -0.330505f}, + {0.27365f, -0.253004f, -0.250241f}, + {0.484531f, -0.297627f, -0.071051f}, + {0.410814f, -0.224961f, -0.084998f}, + {0.039519f, -0.252904f, -0.115128f}, + {0.017423f, -0.296519f, -0.045921f}, + {0.225113f, -0.224371f, 0.037882f}, + {0.183424f, -0.260492f, 0.050491f}, + {0.308704f, -0.073205f, -0.40588f}, + {0.213125f, -0.101632f, -0.333208f}, + {0.617735f, -0.137299f, -0.21367f}, + {0.514382f, -0.126485f, -0.170204f}, + {0.130009f, -0.076955f, -0.229303f}, + {0.06174f, -0.108259f, -0.203887f}, + {0.244473f, -0.110094f, -0.051689f}, + {0.230452f, -0.076147f, -0.02819f}, + {0.059837f, -0.254595f, -0.562704f}, + {0.01163f, -0.135223f, -0.432791f}, + {0.207077f, -0.152248f, -0.148391f}, + {0.158078f, -0.1288f, -0.12215f}, + {-0.265982f, -0.144742f, -0.199894f}, + {-0.356479f, -0.20474f, -0.156465f}, + {0.000324f, -0.139549f, -0.066471f}, + {0.001888f, -0.170557f, -0.025025f}, + {0.402913f, -0.581478f, -0.274626f}, + {0.191289f, -0.540335f, -0.19304f}, + {0.632914f, -0.40141f, -0.006636f}, + {0.471086f, -0.463144f, 0.061489f}, + {0.044829f, -0.438487f, 0.033433f}, + {0.015513f, -0.539475f, -0.006719f}, + {0.336218f, -0.351311f, 0.214087f}, + {0.239967f, -0.380836f, 0.157681f}, + {0.347609f, -0.901619f, -0.688432f}, + {0.064067f, -0.826753f, -0.492089f}, + {0.303089f, -0.396757f, -0.108446f}, + {0.23559f, -0.446122f, 0.006437f}, + {-0.236964f, -0.652532f, -0.13552f}, + {-0.418285f, -0.793014f, -0.03473f}, + {-0.038262f, -0.516984f, 0.273681f}, + {-0.037419f, -0.958198f, 0.214749f}, + {0.061624f, -0.238233f, -0.237184f}, + {-0.013944f, -0.235704f, -0.204811f}, + {0.286428f, -0.210542f, -0.029587f}, + {0.257656f, -0.261837f, -0.056566f}, + {-0.235852f, -0.31076f, -0.165147f}, + {-0.334949f, -0.38587f, -0.197362f}, + {0.09487f, -0.241144f, 0.059122f}, + {0.060177f, -0.225884f, 0.03114f}, + {-0.301184f, -0.306545f, -0.446189f}, + {-0.293528f, -0.504146f, -0.429844f}, + {-0.055084f, -0.379015f, -0.125887f}, + {-0.115434f, -0.375008f, -0.059939f}, + {-0.777425f, -0.592163f, -0.107585f}, + {-0.9505f, -0.893847f, -0.181762f}, + {-0.259402f, -0.396726f, 0.010357f}, + {-0.368905f, -0.449026f, 0.038299f}, + {0.279719f, -0.063196f, -0.184628f}, + {0.255265f, -0.067248f, -0.121124f}, + {0.458433f, -0.103777f, 0.010074f}, + {0.437231f, -0.092496f, -0.031028f}, + {0.082265f, -0.02805f, -0.041262f}, + {0.04592f, -0.051719f, -0.030155f}, + {0.271149f, -0.043613f, 0.112085f}, + {0.246881f, -0.065274f, 0.105436f}, + {0.05659f, -0.117773f, -0.142283f}, + {0.058824f, -0.104418f, -0.099608f}, + {0.213781f, -0.111974f, 0.031269f}, + {0.187554f, -0.07034f, 0.011834f}, + {-0.185701f, -0.081106f, -0.073803f}, + {-0.266112f, -0.074133f, -0.08537f}, + {-0.029368f, -0.04649f, 0.124679f}, + {-0.017378f, -0.102882f, 0.140482f}, + {0.1147f, 0.092738f, -0.244271f}, + {0.072922f, 0.007863f, -0.231476f}, + {0.270022f, 0.031819f, -0.094208f}, + {0.254403f, 0.024805f, -0.050389f}, + {-0.182905f, 0.021629f, -0.168481f}, + {-0.225864f, -0.010109f, -0.130374f}, + {0.040089f, 0.013969f, 0.016028f}, + {0.001442f, 0.010551f, 0.032942f}, + {-0.287472f, -0.03613f, -0.296798f}, + {-0.332344f, -0.108862f, -0.342196f}, + {0.0127f, 0.022917f, -0.052501f}, + {-0.040681f, -0.001805f, -0.050548f}, + {-0.718522f, -0.061234f, -0.27882f}, + {-0.879205f, -0.213588f, -0.303508f}, + {-0.234102f, -0.065407f, 0.013686f}, + {-0.281223f, -0.076139f, 0.04683f}, + {0.141967f, -0.193679f, -0.055697f}, + {0.100318f, -0.161222f, -0.063062f}, + {0.265859f, -0.132747f, 0.078209f}, + {0.244805f, -0.139776f, 0.122123f}, + {-0.121802f, -0.179976f, 0.031732f}, + {-0.185318f, -0.214011f, 0.018117f}, + {0.047014f, -0.153961f, 0.218068f}, + {0.047305f, -0.187402f, 0.282114f}, + {-0.027533f, -0.415868f, -0.333841f}, + {-0.125886f, -0.334492f, -0.290317f}, + {-0.030602f, -0.190918f, 0.097454f}, + {-0.054936f, -0.209948f, 0.158977f}, + {-0.507223f, -0.295876f, -0.217183f}, + {-0.581733f, -0.403194f, -0.208936f}, + {-0.299719f, -0.289679f, 0.297101f}, + {-0.363169f, -0.362718f, 0.436529f}, + {-0.124627f, -0.0421f, -0.157011f}, + {-0.161571f, -0.092846f, -0.183636f}, + {0.08452f, -0.100217f, -0.000901f}, + {0.055655f, -0.136381f, 0.032764f}, + {-0.545087f, -0.197713f, -0.026888f}, + {-0.662772f, -0.179815f, 0.026419f}, + {-0.165583f, -0.148913f, 0.090382f}, + {-0.240772f, -0.18283f, 0.105474f}, + {-0.576315f, -0.359473f, -0.456844f}, + {-0.71343f, -0.554156f, -0.476739f}, + {-0.275628f, -0.22364f, -0.051584f}, + {-0.359501f, -0.230758f, -0.027006f}, + {-1.282559f, -0.284807f, -0.233743f}, + {-1.060476f, -0.399911f, -0.562698f}, + {-0.871952f, -0.272197f, 0.016126f}, + {-0.747922f, -0.329404f, 0.276696f}, + {0.643086f, 0.046175f, -0.660078f}, + {0.738204f, -0.127844f, -0.433708f}, + {1.158072f, 0.025571f, -0.177856f}, + {0.97484f, -0.009417f, -0.112337f}, + {0.418014f, 0.032741f, -0.124545f}, + {0.381422f, -0.001557f, -0.085504f}, + {0.76828f, 0.056085f, 0.095375f}, + {0.680004f, 0.052035f, 0.152318f}, + {0.473182f, 0.01256f, -0.264221f}, + {0.345153f, 0.036627f, -0.248756f}, + {0.746238f, -0.02588f, -0.10605f}, + {0.644319f, -0.058256f, -0.095133f}, + {0.185924f, -0.02223f, -0.07054f}, + {0.146068f, -0.00955f, -0.057871f}, + {0.338488f, 0.013022f, 0.069961f}, + {0.298969f, 0.047403f, 0.052598f}, + {0.346002f, 0.256253f, -0.380261f}, + {0.313092f, 0.163821f, -0.314004f}, + {0.719154f, 0.103108f, -0.252648f}, + {0.621429f, 0.172423f, -0.26518f}, + {0.240461f, 0.104684f, -0.202582f}, + {0.206946f, 0.139642f, -0.138016f}, + {0.359915f, 0.101273f, -0.052997f}, + {0.318117f, 0.125888f, -0.003486f}, + {0.150452f, 0.050219f, -0.409155f}, + {0.188753f, 0.091894f, -0.325733f}, + {0.334922f, 0.029098f, -0.098587f}, + {0.324508f, 0.015809f, -0.135408f}, + {-0.042506f, 0.038667f, -0.208535f}, + {-0.083003f, 0.094758f, -0.174054f}, + {0.094773f, 0.102653f, -0.025701f}, + {0.063284f, 0.118703f, -7.1e-05f}, + {0.355965f, -0.139239f, -0.191705f}, + {0.392742f, -0.105496f, -0.132103f}, + {0.663678f, -0.204627f, -0.031242f}, + {0.609381f, -0.146914f, 0.07961f}, + {0.151855f, -0.132843f, -0.007125f}, + {0.146404f, -0.161917f, 0.024842f}, + {0.400524f, -0.135221f, 0.232289f}, + {0.324931f, -0.116605f, 0.253458f}, + {0.169066f, -0.215132f, -0.185604f}, + {0.128681f, -0.189394f, -0.160279f}, + {0.356194f, -0.116992f, -0.038381f}, + {0.342866f, -0.144687f, 0.020265f}, + {-0.065545f, -0.202593f, -0.043688f}, + {-0.124296f, -0.260225f, -0.03537f}, + {0.083224f, -0.235149f, 0.153301f}, + {0.046256f, -0.309608f, 0.190944f}, + {0.187385f, -0.008168f, -0.198575f}, + {0.190401f, -0.018699f, -0.136858f}, + {0.398009f, -0.0257f, -0.007458f}, + {0.346948f, -0.022258f, -0.020905f}, + {-0.047064f, -0.085629f, -0.080677f}, + {-0.067523f, -0.128972f, -0.119538f}, + {0.186086f, -0.016828f, 0.070014f}, + {0.187364f, 0.017133f, 0.075949f}, + {-0.112669f, -0.037433f, -0.298944f}, + {-0.068276f, -0.114504f, -0.265795f}, + {0.14751f, -0.040616f, -0.013687f}, + {0.133084f, -0.062849f, -0.032637f}, + {-0.416571f, -0.041544f, -0.125088f}, + {-0.505337f, -0.044193f, -0.157651f}, + {-0.154132f, -0.075106f, 0.050466f}, + {-0.148036f, -0.059719f, 0.121516f}, + {0.490555f, 0.157659f, -0.222208f}, + {0.4367f, 0.1205f, -0.205869f}, + {0.754525f, 0.269323f, 0.04581f}, + {0.645077f, 0.271923f, 0.013942f}, + {0.237023f, 0.115337f, -0.026429f}, + {0.204895f, 0.12102f, -0.008541f}, + {0.383999f, 0.153963f, 0.171763f}, + {0.385026f, 0.222074f, 0.239731f}, + {0.198232f, 0.072972f, -0.108179f}, + {0.147882f, 0.074743f, -0.123341f}, + {0.390929f, 0.075205f, 0.081828f}, + {0.341623f, 0.089405f, 0.069389f}, + {-0.003381f, 0.159694f, -0.016026f}, + {-0.043653f, 0.20686f, -0.040729f}, + {0.135515f, 0.107824f, 0.17931f}, + {0.081086f, 0.119673f, 0.174282f}, + {0.192637f, 0.400335f, -0.341906f}, + {0.171196f, 0.284921f, -0.221516f}, + {0.377807f, 0.359087f, -0.151523f}, + {0.411052f, 0.297925f, -0.099774f}, + {-0.01006f, 0.261887f, -0.149567f}, + {-0.107877f, 0.287756f, -0.116982f}, + {0.158003f, 0.209727f, 0.077988f}, + {0.10971f, 0.232272f, 0.088135f}, + {0.000698f, 0.209353f, -0.395208f}, + {-0.094015f, 0.230322f, -0.279928f}, + {0.137355f, 0.230881f, -0.124115f}, + {0.103058f, 0.166855f, -0.100386f}, + {-0.305058f, 0.305422f, -0.176026f}, + {-0.422049f, 0.337137f, -0.293297f}, + {-0.121744f, 0.185124f, 0.048115f}, + {-0.171052f, 0.200312f, 0.052812f}, + {0.224091f, -0.010673f, -0.019727f}, + {0.200266f, -0.020167f, 0.001798f}, + {0.382742f, 0.032362f, 0.161665f}, + {0.345631f, -0.019705f, 0.164451f}, + {0.029431f, 0.04501f, 0.071518f}, + {0.03194f, 0.010876f, 0.087037f}, + {0.181935f, 0.039112f, 0.202316f}, + {0.18181f, 0.033189f, 0.253435f}, + {-0.008677f, -0.066679f, -0.144737f}, + {-0.021768f, -0.021288f, -0.125903f}, + {0.136766f, 0.0001f, 0.059449f}, + {0.135405f, -0.020446f, 0.103793f}, + {-0.289115f, 0.039747f, -0.012256f}, + {-0.338683f, 0.025909f, -0.034058f}, + {-0.016515f, 0.048584f, 0.197981f}, + {-0.04679f, 0.011816f, 0.199964f}, + {0.094214f, 0.127422f, -0.169936f}, + {0.048279f, 0.096189f, -0.148153f}, + {0.217391f, 0.081732f, 0.013677f}, + {0.179656f, 0.084671f, 0.031434f}, + {-0.227367f, 0.118176f, -0.039803f}, + {-0.327096f, 0.159747f, -0.018931f}, + {0.000834f, 0.113118f, 0.125325f}, + {-0.014617f, 0.128924f, 0.163776f}, + {-0.25457f, 0.154329f, -0.232018f}, + {-0.353068f, 0.124341f, -0.174409f}, + {-0.061004f, 0.107744f, 0.037257f}, + {-0.100991f, 0.080302f, 0.062701f}, + {-0.927022f, 0.28566f, -0.240549f}, + {-1.153224f, 0.277232f, -0.322538f}, + {-0.569012f, 0.108135f, 0.172634f}, + {-0.555273f, 0.131461f, 0.32593f}, + {0.518847f, 0.065683f, -0.132877f}, + {0.501324f, -0.006585f, -0.094884f}, + {1.06619f, -0.15038f, 0.201791f}, + {0.858377f, -0.166415f, 0.081686f}, + {0.320584f, -0.031499f, 0.039534f}, + {0.311442f, -0.07512f, 0.026013f}, + {0.625829f, -0.019856f, 0.346041f}, + {0.525271f, -0.003948f, 0.284868f}, + {0.312594f, -0.075673f, -0.066642f}, + {0.295732f, -0.057895f, -0.042207f}, + {0.550446f, -0.02911f, 0.04685f}, + {0.465467f, -0.068987f, 0.096167f}, + {0.122669f, -0.051786f, 0.044283f}, + {0.079669f, -0.044145f, 0.045805f}, + {0.238778f, -0.031835f, 0.171694f}, + {0.200734f, -0.072619f, 0.178726f}, + {0.342512f, 0.13127f, -0.163021f}, + {0.294028f, 0.111759f, -0.125793f}, + {0.589523f, 0.121808f, -0.049372f}, + {0.550506f, 0.132318f, 0.017485f}, + {0.16428f, 0.04756f, -0.058383f}, + {0.12011f, 0.049242f, -0.052403f}, + {0.269181f, 0.035f, 0.103494f}, + {0.297466f, 0.038517f, 0.139289f}, + {0.094549f, -0.03088f, -0.153376f}, + {0.080363f, 0.024359f, -0.127578f}, + {0.281351f, 0.055178f, 0.000155f}, + {0.2349f, 0.039477f, 0.013957f}, + {-0.118161f, 0.011976f, -0.03427f}, + {-0.157654f, 0.027765f, -0.00501f}, + {0.102631f, 0.027283f, 0.099723f}, + {0.077285f, 0.052532f, 0.115583f}, + {0.329398f, -0.278552f, 0.016316f}, + {0.305993f, -0.267896f, 0.094952f}, + {0.77527f, -0.394995f, 0.290748f}, + {0.58318f, -0.252159f, 0.285391f}, + {0.192226f, -0.182242f, 0.126859f}, + {0.185908f, -0.245779f, 0.15994f}, + {0.346293f, -0.250404f, 0.355682f}, + {0.35416f, -0.364521f, 0.472337f}, + {0.134942f, -0.313666f, -0.115181f}, + {0.126077f, -0.286568f, -0.039927f}, + {0.405618f, -0.211792f, 0.199095f}, + {0.312099f, -0.213642f, 0.190972f}, + {-0.071392f, -0.297366f, 0.081426f}, + {-0.165839f, -0.301986f, 0.16064f}, + {0.147808f, -0.290712f, 0.298198f}, + {0.063302f, -0.310149f, 0.396302f}, + {0.141444f, -0.081377f, -0.076621f}, + {0.115936f, -0.10444f, -0.039885f}, + {0.367023f, -0.087281f, 0.09639f}, + {0.330038f, -0.117958f, 0.12705f}, + {0.002897f, -0.062454f, 0.025151f}, + {-0.052404f, -0.0822f, 0.041975f}, + {0.181553f, -0.137004f, 0.230489f}, + {0.140768f, -0.094604f, 0.265928f}, + {-0.101763f, -0.209566f, -0.135964f}, + {-0.159056f, -0.191005f, -0.095509f}, + {0.045016f, -0.081562f, 0.075942f}, + {0.016808f, -0.112482f, 0.068593f}, + {-0.408578f, -0.132377f, 0.079163f}, + {-0.431534f, -0.214646f, 0.157714f}, + {-0.096931f, -0.101938f, 0.200304f}, + {-0.167867f, -0.114851f, 0.262964f}, + {0.393882f, 0.086002f, 0.008961f}, + {0.338747f, 0.048405f, -0.004187f}, + {0.877844f, 0.374373f, 0.171008f}, + {0.74079f, 0.324525f, 0.242248f}, + {0.200218f, 0.07015f, 0.085891f}, + {0.17176f, 0.090531f, 0.102579f}, + {0.314263f, 0.126417f, 0.322833f}, + {0.313523f, 0.065445f, 0.403855f}, + {0.164261f, 0.057745f, -0.00549f}, + {0.122141f, 0.024122f, 0.00919f}, + {0.308248f, 0.078401f, 0.180577f}, + {0.251222f, 0.073868f, 0.160457f}, + {-0.047526f, 0.023725f, 0.086336f}, + {-0.091643f, 0.005539f, 0.093179f}, + {0.079339f, 0.044135f, 0.206697f}, + {0.104213f, 0.011277f, 0.24006f}, + {0.226607f, 0.186234f, -0.056881f}, + {0.173281f, 0.158131f, -0.059413f}, + {0.3394f, 0.214501f, 0.052905f}, + {0.309166f, 0.188181f, 0.058028f}, + {0.014442f, 0.194715f, 0.048945f}, + {-0.028793f, 0.194766f, 0.089078f}, + {0.069564f, 0.206743f, 0.193568f}, + {0.091532f, 0.202786f, 0.26968f}, + {-0.071196f, 0.135604f, -0.103744f}, + {-0.118288f, 0.152837f, -0.060151f}, + {0.146856f, 0.143174f, 0.061789f}, + {0.104379f, 0.143672f, 0.056797f}, + {-0.541832f, 0.250034f, -0.017602f}, + {-0.641583f, 0.278411f, -0.111909f}, + {-0.094447f, 0.159393f, 0.164848f}, + {-0.113612f, 0.120702f, 0.221656f}, + {0.204918f, -0.078894f, 0.075524f}, + {0.161232f, -0.090256f, 0.088701f}, + {0.37846f, -0.033687f, 0.309964f}, + {0.311701f, -0.049984f, 0.316881f}, + {0.019311f, -0.050048f, 0.212387f}, + {0.002473f, -0.062855f, 0.278462f}, + {0.151448f, -0.090652f, 0.410031f}, + {0.162778f, -0.071291f, 0.531252f}, + {-0.083704f, -0.076839f, -0.020798f}, + {-0.092832f, -0.043492f, 0.029202f}, + {0.136844f, -0.077791f, 0.186493f}, + {0.089536f, -0.086826f, 0.184711f}, + {-0.270255f, -0.058858f, 0.173048f}, + {-0.350416f, -0.009219f, 0.27326f}, + {-0.105248f, -0.205534f, 0.425159f}, + {-0.13503f, -0.197464f, 0.62355f}, + {-0.051717f, 0.069756f, -0.043829f}, + {-0.08105f, 0.056947f, -0.000205f}, + {0.190388f, 0.016366f, 0.145922f}, + {0.142662f, 0.002575f, 0.159182f}, + {-0.35289f, 0.011117f, 0.09104f}, + {-0.367374f, 0.056547f, 0.147209f}, + {-0.003179f, 0.02657f, 0.282541f}, + {-0.069934f, -0.005171f, 0.337678f}, + {-0.496181f, 0.026464f, 0.019432f}, + {-0.690384f, 0.069313f, -0.004175f}, + {-0.146138f, 0.046372f, 0.161839f}, + {-0.197581f, 0.034093f, 0.241003f}, + {-0.989567f, 0.040993f, 0.049384f}, + {-1.151075f, 0.210556f, 0.237374f}, + {-0.335366f, -0.058208f, 0.480168f}, + {-0.502419f, -0.093761f, 0.67524f}, + {0.862548f, 0.264137f, -0.294905f}, + {0.782668f, 0.251324f, -0.122108f}, + {1.597797f, 0.463818f, -0.133153f}, + {1.615756f, 0.060653f, 0.084764f}, + {0.435588f, 0.209832f, 0.09505f}, + {0.431013f, 0.165328f, 0.047909f}, + {1.248164f, 0.265923f, 0.488086f}, + {1.009933f, 0.34544f, 0.473702f}, + {0.477017f, 0.194237f, -0.058012f}, + {0.401362f, 0.186915f, -0.054137f}, + {1.202158f, 0.284782f, -0.066531f}, + {1.064907f, 0.203766f, 0.046383f}, + {0.255848f, 0.133398f, 0.046049f}, + {0.21868f, 0.128833f, 0.065326f}, + {0.490817f, 0.182041f, 0.286583f}, + {0.440714f, 0.106576f, 0.30112f}, + {0.604263f, 0.522925f, -0.238629f}, + {0.526329f, 0.377577f, -0.1981f}, + {1.038632f, 0.606242f, -0.121253f}, + {0.995283f, 0.552202f, 0.1107f}, + {0.262232f, 0.313664f, -0.086909f}, + {0.230835f, 0.273385f, -0.054268f}, + {0.548466f, 0.490721f, 0.278201f}, + {0.466984f, 0.355859f, 0.28916f}, + {0.367137f, 0.23616f, -0.228114f}, + {0.309359f, 0.233843f, -0.171325f}, + {0.465268f, 0.276569f, 0.010951f}, + {0.378124f, 0.250237f, 0.011131f}, + {0.061885f, 0.29681f, -0.01142f}, + {0.000125f, 0.350029f, -0.011277f}, + {0.163815f, 0.261191f, 0.175863f}, + {0.165132f, 0.308797f, 0.2278f}, + {0.461418f, 0.052075f, -0.016543f}, + {0.472372f, 0.046962f, 0.045746f}, + {0.856406f, 0.136415f, 0.245074f}, + {0.834616f, 0.003254f, 0.372643f}, + {0.337869f, 0.036994f, 0.232513f}, + {0.267414f, 0.027593f, 0.252779f}, + {0.584983f, 0.113046f, 0.583119f}, + {0.475406f, -0.024234f, 0.65507f}, + {0.264823f, -0.029292f, 0.00427f}, + {0.246071f, -0.019109f, 0.030048f}, + {0.477401f, 0.021039f, 0.155448f}, + {0.458453f, -0.043959f, 0.18785f}, + {0.067059f, -0.061227f, 0.126904f}, + {0.044608f, -0.034575f, 0.150205f}, + {0.191304f, -0.00381f, 0.316776f}, + {0.153078f, 0.029915f, 0.361303f}, + {0.320704f, 0.17895f, -0.088835f}, + {0.300866f, 0.137645f, -0.056893f}, + {0.553442f, 0.162339f, 0.131987f}, + {0.490083f, 0.123682f, 0.146163f}, + {0.11895f, 0.083109f, 0.034052f}, + {0.099344f, 0.066212f, 0.054329f}, + {0.228325f, 0.122445f, 0.309219f}, + {0.172093f, 0.135754f, 0.323361f}, + {0.064213f, 0.063405f, -0.058243f}, + {0.011906f, 0.088795f, -0.069678f}, + {0.194232f, 0.129185f, 0.125708f}, + {0.155182f, 0.174013f, 0.144099f}, + {-0.217068f, 0.112731f, 0.093497f}, + {-0.30759f, 0.171146f, 0.110735f}, + {-0.014897f, 0.138094f, 0.232455f}, + {-0.036936f, 0.170135f, 0.279166f}, + {0.681886f, 0.437121f, 0.078458f}, + {0.548559f, 0.376914f, 0.092485f}, + {1.259194f, 0.901494f, 0.256085f}, + {1.296139f, 0.607949f, 0.302184f}, + {0.319619f, 0.307231f, 0.099647f}, + {0.287232f, 0.359355f, 0.186844f}, + {0.751306f, 0.676688f, 0.499386f}, + {0.479609f, 0.55303f, 0.560447f}, + {0.276377f, 0.214032f, -0.003661f}, + {0.238146f, 0.223595f, 0.028806f}, + {0.542688f, 0.266205f, 0.171393f}, + {0.460188f, 0.283979f, 0.158288f}, + {0.057385f, 0.309853f, 0.144517f}, + {-0.006881f, 0.348152f, 0.09731f}, + {0.244434f, 0.247298f, 0.322601f}, + {0.253992f, 0.33542f, 0.402241f}, + {0.354006f, 0.579776f, -0.130176f}, + {0.267043f, 0.461976f, -0.058178f}, + {0.534049f, 0.626549f, 0.046747f}, + {0.441835f, 0.46826f, 0.057556f}, + {0.110477f, 0.628795f, 0.10295f}, + {0.031409f, 0.489068f, 0.090605f}, + {0.229564f, 0.52564f, 0.325454f}, + {0.10557f, 0.582151f, 0.509738f}, + {0.00569f, 0.521474f, -0.157885f}, + {0.104463f, 0.424022f, -0.080647f}, + {0.223784f, 0.38986f, 0.060904f}, + {0.159806f, 0.340571f, 0.062061f}, + {-0.173976f, 0.573425f, 0.027383f}, + {-0.376008f, 0.587868f, 0.133042f}, + {-0.051773f, 0.348339f, 0.231923f}, + {-0.122571f, 0.473049f, 0.251159f}, + {0.324321f, 0.14851f, 0.116006f}, + {0.282263f, 0.12173f, 0.114016f}, + {0.690108f, 0.256346f, 0.418128f}, + {0.542523f, 0.294427f, 0.461973f}, + {0.056944f, 0.107667f, 0.281797f}, + {0.027844f, 0.106858f, 0.355071f}, + {0.160456f, 0.177656f, 0.528819f}, + {0.227537f, 0.177976f, 0.689465f}, + {0.111585f, 0.097896f, 0.109244f}, + {0.083994f, 0.133245f, 0.115789f}, + {0.20874f, 0.142084f, 0.208953f}, + {0.156072f, 0.143303f, 0.231368f}, + {-0.18583f, 0.214347f, 0.309774f}, + {-0.311053f, 0.240517f, 0.328512f}, + {-0.041749f, 0.090901f, 0.511373f}, + {-0.156164f, 0.098486f, 0.47802f}, + {0.151543f, 0.263073f, -0.033471f}, + {0.126322f, 0.213004f, -0.007014f}, + {0.245313f, 0.217564f, 0.12021f}, + {0.259136f, 0.225542f, 0.176601f}, + {-0.190632f, 0.260214f, 0.141755f}, + {-0.189271f, 0.331768f, 0.170606f}, + {0.054763f, 0.294766f, 0.357775f}, + {-0.033724f, 0.257645f, 0.365069f}, + {-0.184971f, 0.396532f, 0.057728f}, + {-0.293313f, 0.400259f, 0.001123f}, + {-0.015219f, 0.232287f, 0.177913f}, + {-0.022524f, 0.244724f, 0.240753f}, + {-0.520342f, 0.34795f, 0.249265f}, + {-0.671997f, 0.410782f, 0.153434f}, + {-0.253089f, 0.412356f, 0.489854f}, + {-0.410922f, 0.562454f, 0.543891f}, +}; + +const float xombe__prba58[128][4] = { + {-0.10366f, 0.094597f, -0.013149f, 0.081501f}, + {-0.170709f, 0.129958f, -0.057316f, 0.112324f}, + {-0.095113f, 0.080892f, -0.027554f, 0.003371f}, + {-0.154153f, 0.113437f, -0.074522f, 0.003446f}, + {-0.109553f, 0.153519f, 0.006858f, 0.04093f}, + {-0.181931f, 0.217882f, -0.019042f, 0.040049f}, + {-0.096246f, 0.144191f, -0.024147f, -0.03512f}, + {-0.174811f, 0.193357f, -0.054261f, -0.0717f}, + {-0.183241f, -0.05284f, 0.117923f, 0.03096f}, + {-0.242634f, 0.009075f, 0.098007f, 0.091643f}, + {-0.143847f, -0.028529f, 0.040171f, -0.002812f}, + {-0.198809f, 0.00699f, 0.020668f, 0.026641f}, + {-0.233172f, -0.028793f, 0.14013f, -0.071927f}, + {-0.309313f, 0.056873f, 0.108262f, -0.01893f}, + {-0.172782f, -0.002037f, 0.048755f, -0.087065f}, + {-0.242901f, 0.036076f, 0.015064f, -0.064366f}, + {0.077107f, 0.172685f, 0.159939f, 0.097456f}, + {0.02482f, 0.209676f, 0.087347f, 0.105204f}, + {0.085113f, 0.151639f, 0.084272f, 0.022747f}, + {0.047975f, 0.196695f, 0.03877f, 0.029953f}, + {0.113925f, 0.236813f, 0.176121f, 0.016635f}, + {0.009708f, 0.267969f, 0.12766f, 0.015872f}, + {0.114044f, 0.202311f, 0.096892f, -0.043071f}, + {0.047219f, 0.260395f, 0.050952f, -0.046996f}, + {-0.055095f, 0.034041f, 0.200464f, 0.03905f}, + {-0.061582f, 0.069566f, 0.113048f, 0.027511f}, + {-0.025469f, 0.04044f, 0.132777f, -0.039098f}, + {-0.031388f, 0.06401f, 0.067559f, -0.017117f}, + {-0.074386f, 0.086579f, 0.228232f, -0.055461f}, + {-0.107352f, 0.120874f, 0.137364f, -0.030252f}, + {-0.036897f, 0.089972f, 0.155831f, -0.128475f}, + {-0.05907f, 0.097879f, 0.084489f, -0.075821f}, + {-0.050865f, -0.025167f, -0.086636f, 0.011256f}, + {-0.051426f, 0.013301f, -0.144665f, 0.038541f}, + {-0.073831f, -0.028917f, -0.142416f, -0.025268f}, + {-0.08391f, 0.015004f, -0.227113f, -0.002808f}, + {-0.03084f, -0.009326f, -0.070517f, -0.041304f}, + {-0.022018f, 0.029381f, -0.124961f, -0.031624f}, + {-0.064222f, -0.01464f, -0.108798f, -0.092342f}, + {-0.038801f, 0.038133f, -0.188992f, -0.094221f}, + {-0.154059f, -0.183932f, -0.019894f, 0.082105f}, + {-0.188022f, -0.113072f, -0.11738f, 0.090911f}, + {-0.243301f, -0.207086f, -0.053735f, -0.001975f}, + {-0.275931f, -0.121035f, -0.161261f, 0.004231f}, + {-0.118142f, -0.157537f, -0.036594f, -0.008679f}, + {-0.153627f, -0.111372f, -0.103095f, -0.00946f}, + {-0.173458f, -0.180158f, -0.05713f, -0.103198f}, + {-0.208509f, -0.127679f, -0.149336f, -0.109289f}, + {0.09631f, 0.047927f, -0.024094f, -0.057018f}, + {0.044289f, 0.075486f, -0.008505f, -0.067635f}, + {0.076751f, 0.02556f, -0.066428f, -0.102991f}, + {0.025215f, 0.090417f, -0.058616f, -0.114284f}, + {0.12598f, 0.070078f, 0.016282f, -0.112355f}, + {0.070859f, 0.118988f, 0.00118f, -0.116359f}, + {0.09752f, 0.059219f, -0.026821f, -0.17285f}, + {0.048226f, 0.145459f, -0.050093f, -0.188853f}, + {0.007242f, -0.135796f, 0.147832f, -0.03408f}, + {0.012843f, -0.069616f, 0.077139f, -0.047909f}, + {-0.050911f, -0.116323f, 0.082521f, -0.056362f}, + {-0.03963f, -0.055678f, 0.036066f, -0.067992f}, + {0.042694f, -0.091527f, 0.15094f, -0.124225f}, + {0.029225f, -0.039401f, 0.071664f, -0.113665f}, + {-0.025085f, -0.099013f, 0.074622f, -0.138674f}, + {-0.03122f, -0.035717f, 0.02087f, -0.143376f}, + {0.040638f, 0.087903f, -0.0495f, 0.094607f}, + {0.02686f, 0.125924f, -0.103449f, 0.140882f}, + {0.075166f, 0.110186f, -0.115173f, 0.06733f}, + {0.036642f, 0.163193f, -0.188762f, 0.103724f}, + {0.028179f, 0.095124f, -0.053258f, 0.0289f}, + {0.002307f, 0.148211f, -0.096037f, 0.046189f}, + {0.072227f, 0.137595f, -0.095629f, 0.001339f}, + {0.033308f, 0.22148f, -0.152201f, 0.012125f}, + {0.003458f, -0.085112f, 0.04185f, 0.113836f}, + {-0.04061f, -0.04488f, 0.029732f, 0.177011f}, + {0.011404f, -0.054324f, -0.012426f, 0.077815f}, + {-0.042413f, -0.03093f, -0.034844f, 0.122946f}, + {-0.002206f, -0.045698f, 0.050651f, 0.054886f}, + {-0.041729f, -0.01611f, 0.048005f, 0.102125f}, + {0.013963f, -0.022204f, 0.001613f, 0.028997f}, + {-0.030218f, -0.002052f, -0.004365f, 0.065343f}, + {0.299049f, 0.04626f, 0.07632f, 0.070784f}, + {0.25016f, 0.09844f, 0.01259f, 0.137479f}, + {0.25417f, 0.09531f, 0.018749f, 0.004288f}, + {0.218892f, 0.145554f, -0.035161f, 0.069784f}, + {0.303486f, 0.101424f, 0.135996f, -0.013096f}, + {0.262919f, 0.165133f, 0.077237f, 0.071721f}, + {0.319358f, 0.170283f, 0.054554f, -0.07221f}, + {0.272983f, 0.231181f, -0.014471f, 0.011689f}, + {0.134116f, -0.026693f, 0.1614f, 0.110292f}, + {0.100379f, 0.026517f, 0.086236f, 0.130478f}, + {0.144718f, -0.000895f, 0.093767f, 0.044514f}, + {0.114943f, 0.022145f, 0.035871f, 0.069193f}, + {0.122051f, 0.011043f, 0.192803f, 0.022796f}, + {0.079482f, 0.026156f, 0.117725f, 0.056565f}, + {0.124641f, 0.027387f, 0.122956f, -0.025369f}, + {0.090708f, 0.027357f, 0.06445f, 0.013058f}, + {0.159781f, -0.055202f, -0.090597f, 0.151598f}, + {0.084577f, -0.037203f, -0.126698f, 0.119739f}, + {0.192484f, -0.100195f, -0.162066f, 0.104148f}, + {0.114579f, -0.04627f, -0.219547f, 0.100067f}, + {0.153083f, -0.010127f, -0.086266f, 0.068648f}, + {0.088202f, -0.010515f, -0.102196f, 0.046281f}, + {0.164494f, -0.057325f, -0.13286f, 0.024093f}, + {0.109419f, -0.013999f, -0.169596f, 0.020412f}, + {0.03918f, -0.209168f, -0.035872f, 0.087949f}, + {0.01279f, -0.177723f, -0.129986f, 0.073364f}, + {0.045261f, -0.256694f, -0.088186f, 0.004212f}, + {-0.005314f, -0.231202f, -0.191671f, -0.002628f}, + {0.037963f, -0.153227f, -0.045364f, 0.003322f}, + {0.0308f, -0.126452f, -0.114266f, -0.010414f}, + {0.044125f, -0.184146f, -0.0814f, -0.077341f}, + {0.029204f, -0.157393f, -0.172017f, -0.089814f}, + {0.393519f, -0.043228f, -0.111365f, -0.00074f}, + {0.289581f, 0.018928f, -0.12314f, 0.000713f}, + {0.311229f, -0.059735f, -0.198982f, -0.081664f}, + {0.258659f, 0.052505f, -0.211913f, -0.034928f}, + {0.300693f, 0.011381f, -0.083545f, -0.086683f}, + {0.214523f, 0.053878f, -0.101199f, -0.061018f}, + {0.253422f, 0.028496f, -0.156752f, -0.163342f}, + {0.199123f, 0.113877f, -0.16622f, -0.102584f}, + {0.249134f, -0.165135f, 0.028917f, 0.051838f}, + {0.156434f, -0.123708f, 0.017053f, 0.043043f}, + {0.214763f, -0.101243f, -0.005581f, -0.020703f}, + {0.140554f, -0.072067f, -0.015063f, -0.011165f}, + {0.241791f, -0.152048f, 0.106403f, -0.046857f}, + {0.142316f, -0.131899f, 0.054076f, -0.026485f}, + {0.206535f, -0.086116f, 0.04664f, -0.097615f}, + {0.129759f, -0.081874f, 0.004693f, -0.073169f}, +}; + +const float xombe__hoc5[32][4] = { + {0.264108f, 0.045976f, -0.200999f, -0.122344f}, + {0.479006f, 0.227924f, -0.016114f, -0.006835f}, + {0.077297f, 0.080775f, -0.068936f, 0.041733f}, + {0.185486f, 0.23184f, 0.18241f, 0.101613f}, + {-0.012442f, 0.223718f, -0.277803f, -0.03437f}, + {-0.059507f, 0.139621f, -0.024708f, -0.104205f}, + {-0.248676f, 0.255502f, -0.134894f, -0.058338f}, + {-0.055122f, 0.427253f, 0.025059f, -0.045051f}, + {-0.058898f, -0.061945f, 0.02803f, -0.022242f}, + {0.084153f, 0.025327f, 0.06678f, -0.180839f}, + {-0.193125f, -0.082632f, 0.140899f, -0.089559f}, + {0.0f, 0.033758f, 0.276623f, 0.002493f}, + {-0.396582f, -0.049543f, -0.1181f, -0.208305f}, + {-0.287112f, 0.09662f, 0.04965f, -0.079312f}, + {-0.54376f, 0.171107f, -0.062173f, -0.010483f}, + {-0.353572f, 0.22744f, 0.230128f, -0.032089f}, + {0.248579f, -0.279824f, -0.209589f, 0.070903f}, + {0.377604f, -0.119639f, 0.008463f, -0.005589f}, + {0.102127f, -0.093666f, -0.061325f, 0.052082f}, + {0.154134f, -0.105724f, 0.099317f, 0.187972f}, + {-0.139232f, -0.091146f, -0.275479f, -0.038435f}, + {-0.144169f, 0.034314f, -0.03084f, 0.022207f}, + {-0.143985f, 0.079414f, -0.194701f, 0.175312f}, + {-0.195329f, 0.087467f, 0.067711f, 0.186783f}, + {-0.123515f, -0.377873f, -0.209929f, -0.212677f}, + {0.068698f, -0.255933f, 0.120463f, -0.095629f}, + {-0.10681f, -0.319964f, -0.089322f, 0.106947f}, + {-0.158605f, -0.309606f, 0.1909f, 0.08934f}, + {-0.489162f, -0.432784f, -0.151215f, -0.005786f}, + {-0.370883f, -0.154342f, -0.022545f, 0.114054f}, + {-0.742866f, -0.204364f, -0.123865f, -0.038888f}, + {-0.573077f, -0.115287f, 0.208879f, -0.027698f}, +}; + +const float xombe__hoc6[16][4] = { + {-0.143886f, 0.235528f, -0.116707f, 0.025541f}, + {-0.170182f, -0.063822f, -0.096934f, 0.109704f}, + {0.232915f, 0.269793f, 0.047064f, -0.032761f}, + {0.153458f, 0.06813f, -0.033513f, 0.126553f}, + {-0.440712f, 0.132952f, 0.081378f, -0.01321f}, + {-0.480433f, -0.249687f, -0.01228f, 0.007112f}, + {-0.088001f, 0.167609f, 0.148323f, -0.119892f}, + {-0.104628f, 0.102639f, 0.18356f, 0.121674f}, + {0.047408f, -0.000908f, -0.214196f, -0.109372f}, + {0.113418f, -0.24034f, -0.12142f, 0.041117f}, + {0.385609f, 0.042913f, -0.184584f, -0.017851f}, + {0.45383f, -0.180745f, 0.050455f, 0.030984f}, + {-0.155984f, -0.144212f, 0.018226f, -0.146356f}, + {-0.104028f, -0.260377f, 0.146472f, 0.101389f}, + {0.012376f, -0.000267f, 0.006657f, -0.013941f}, + {0.165852f, -0.103467f, 0.119713f, -0.075455f}, +}; + +const float xombe__hoc7[16][4] = { + {0.182478f, 0.271794f, -0.057639f, 0.026115f}, + {0.110795f, 0.092854f, 0.078125f, -0.082726f}, + {0.057964f, 0.000833f, 0.176048f, 0.135404f}, + {-0.027315f, 0.098668f, -0.065801f, 0.116421f}, + {-0.222796f, 0.062967f, 0.20174f, -0.089975f}, + {-0.193571f, 0.309225f, -0.014101f, -0.034574f}, + {-0.389053f, -0.181476f, 0.107682f, 0.050169f}, + {-0.345604f, 0.0649f, -0.065014f, 0.065642f}, + {0.319393f, -0.055491f, -0.220727f, -0.067499f}, + {0.460572f, 0.084686f, 0.048453f, -0.01105f}, + {0.201623f, -0.068994f, -0.067101f, 0.10832f}, + {0.227528f, -0.1739f, 0.092417f, -0.066515f}, + {-0.016927f, 0.047757f, -0.177686f, -0.102163f}, + {-0.052553f, -0.065689f, 0.019328f, -0.03306f}, + {-0.14491f, -0.238617f, -0.195206f, -0.063917f}, + {-0.024159f, -0.338822f, 0.003581f, 0.060995f}, +}; + +const float xombe__hoc8[8][4] = { + {0.323968f, 0.008964f, -0.063117f, 0.027909f}, + {0.0109f, -0.00403f, -0.125016f, -0.080818f}, + {0.109969f, 0.256272f, 0.04247f, 0.000749f}, + {-0.135446f, 0.201769f, -0.083426f, 0.093888f}, + {-0.441995f, 0.038159f, 0.022784f, 0.003943f}, + {-0.155951f, 0.032467f, 0.145309f, -0.041725f}, + {-0.149182f, -0.223356f, -0.065793f, 0.075016f}, + {0.096949f, -0.0964f, 0.083194f, 0.049306f}, +}; diff --git a/xombe/src/tables/tables.h b/xombe/src/tables/tables.h new file mode 100644 index 0000000..340f713 --- /dev/null +++ b/xombe/src/tables/tables.h @@ -0,0 +1,18 @@ +#ifndef XOMBE_TABLES_H +#define XOMBE_TABLES_H + +#define XOMBE_B0_COUNT 120 + +extern const float xombe__w0[XOMBE_B0_COUNT]; +extern const unsigned char xombe__lt[XOMBE_B0_COUNT]; +extern const unsigned char xombe__vuv[32][8]; +extern const unsigned char xombe__blk[57][4]; +extern const float xombe__dg[32]; +extern const float xombe__prba24[512][3]; +extern const float xombe__prba58[128][4]; +extern const float xombe__hoc5[32][4]; +extern const float xombe__hoc6[16][4]; +extern const float xombe__hoc7[16][4]; +extern const float xombe__hoc8[8][4]; + +#endif diff --git a/xombe/src/xombe_config.h.in b/xombe/src/xombe_config.h.in new file mode 100644 index 0000000..3d7ffda --- /dev/null +++ b/xombe/src/xombe_config.h.in @@ -0,0 +1,26 @@ +#ifndef XOMBE_CONFIG_H +#define XOMBE_CONFIG_H + +/* generated by CMake: optional parts built, 0 or 1 (xombe.h describes them) */ +#cmakedefine01 XOMBE_HAVE_ENCODER +#cmakedefine01 XOMBE_HAVE_DSTAR +/* encoder and decoder kernels: 0 float, 1 fixed point (XOMBE_KERNELS=q15) */ +#cmakedefine01 XOMBE_KERNELS_Q15 + +/* marks the public functions. on Windows: xombe_EXPORTS (set by CMake) while building the DLL, XOMBE_SHARED + (set by the xombe::xombe target and xombe.pc) in its consumers, neither for the static library */ +#if defined(_WIN32) || defined(__CYGWIN__) +#if defined(xombe_EXPORTS) +#define XOMBE_API __declspec(dllexport) +#elif defined(XOMBE_SHARED) +#define XOMBE_API __declspec(dllimport) +#else +#define XOMBE_API +#endif +#elif defined(__GNUC__) +#define XOMBE_API __attribute__((visibility("default"))) +#else +#define XOMBE_API +#endif + +#endif diff --git a/xombe/test/conformance.sh b/xombe/test/conformance.sh new file mode 100755 index 0000000..0475113 --- /dev/null +++ b/xombe/test/conformance.sh @@ -0,0 +1,137 @@ +#!/bin/sh +set -u +BUILD=${1:-build} +PY=${2:-python3} +ROOT=$(cd "$(dirname "$0")/.." && pwd) +case $BUILD in /*) ;; *) BUILD=$ROOT/$BUILD ;; esac +VEC=$ROOT/vectors +OUT=$BUILD/conformance +IN=$BUILD/e3in # dithered E3 inputs, from gen_inputs.py +JOBS=4 +export XOMBE_BUILD=$BUILD +mkdir -p "$OUT/t3" "$OUT/e3" "$OUT/e5" "$OUT/e6in" "$OUT/e6" "$OUT/e7" +status=0 +summary="" + +record() { + if [ "$2" -eq 0 ]; then summary="$summary +$1: PASS"; else summary="$summary +$1: FAIL"; status=1; fi +} + +# runs a command, reports it on stderr and returns 1 if it fails +run() { + "$@" || { echo "FAILED ($?): $*" >&2; return 1; } +} + +echo "== inputs" +run "$PY" "$ROOT/scripts/gen_inputs.py" --out "$IN" +record inputs $? + +echo "== T3" +t3=0 +for s in es1_nsdtx_off es1_nsdtx_on es2 es3 es4; do + run "$BUILD/xombe-dec" --conformance-noise "$VEC/perceptual/$s.amb" "$OUT/t3/$s.raw" || t3=1 +done +# each scorer's stderr goes to its own log, printed if that scorer fails +for s in es1_nsdtx_off es1_nsdtx_on es2 es3 es4; do + echo "$s" +done | xargs -P $JOBS -I{} sh -c "\"$PY\" \"$ROOT/tools/score.py\" \"$VEC/perceptual/{}_ref.raw\" \"$OUT/t3/{}.raw\" --json > \"$OUT/t3/{}.json\" 2> \"$OUT/t3/{}.log\" || { echo 'score.py failed for {}:' >&2; cat \"$OUT/t3/{}.log\" >&2; exit 1; }" || t3=1 +"$PY" - "$OUT/t3" <<'EOF' || t3=1 +import json, sys, os +d = sys.argv[1] +sets = ['es1_nsdtx_off', 'es1_nsdtx_on', 'es2', 'es3', 'es4'] +keys = ['pesq_nb', 'visqol_speech', 'stoi', 'lsd_db'] +ok = True +rows = [] +print('%-14s %7s %7s %7s %7s' % ('set', 'PESQ', 'ViSQOL', 'STOI', 'LSD')) +for s in sets: + try: + r = json.load(open(os.path.join(d, s + '.json'))) + bad = [k for k in keys if not isinstance(r.get(k), (int, float))] + except (OSError, ValueError) as e: + r, bad = {}, ['unreadable scores (%s)' % e] + if bad: + print('%-14s missing or failed: %s FAIL' % (s, ', '.join(bad))) + ok = False + continue + good = r['pesq_nb'] >= 4.05 and r['visqol_speech'] >= 4.15 and r['stoi'] >= 0.98 and r['lsd_db'] <= 1.30 + ok &= good + rows.append(r) + print('%-14s %7.3f %7.3f %7.3f %7.3f %s' % (s, r['pesq_nb'], r['visqol_speech'], r['stoi'], r['lsd_db'], + 'ok' if good else 'FAIL')) +if len(rows) == len(sets): + mp = sum(r['pesq_nb'] for r in rows) / len(rows) + ml = sum(r['lsd_db'] for r in rows) / len(rows) + mv = sum(r['visqol_speech'] for r in rows) / len(rows) + ms = sum(r['stoi'] for r in rows) / len(rows) + print('%-14s %7.3f %7.3f %7.3f %7.3f' % ('mean (5 sets)', mp, mv, ms, ml)) + ok &= mp >= 4.25 and ml <= 1.00 +print('limits: each PESQ >= 4.05, ViSQOL >= 4.15, STOI >= 0.98, LSD <= 1.30; mean PESQ >= 4.25, mean LSD <= 1.00') +print('T3: ' + ('PASS' if ok else 'FAIL')) +sys.exit(0 if ok else 1) +EOF +record T3 $t3 + +echo "== T4" +run "$BUILD/test_stream" --metrics "$VEC"/stream/mixed_stream_0.jsonl.gz "$VEC"/stream/mixed_stream_1.jsonl.gz \ + "$VEC"/stream/mixed_stream_2.jsonl.gz "$VEC"/stream/mixed_stream_3.jsonl.gz +record T4 $? + +echo "== T5" +run "$BUILD/test_tones" "$VEC/tones" +record T5 $? + +echo "== encodes" +enc=0 +for c in es1 es2 es3 sn10 ttsf ttsc ttsl; do + for k in 0 1 2 3 4; do echo "$c.d$k"; done +done | xargs -P $JOBS -I{} sh -c "\"$BUILD/xombe-enc\" \"$IN/{}.raw\" \"$OUT/e3/{}.amb\" || { echo 'xombe-enc failed for {}' >&2; exit 1; }" || enc=1 +for n in low5 hp5; do run "$BUILD/xombe-enc" "$VEC/e5/$n.raw" "$OUT/e5/$n.amb" || enc=1; done +for n in glide mix saw150 tones; do run "$BUILD/xombe-enc" "$VEC/e7/$n.raw" "$OUT/e7/$n.amb" || enc=1; done +record encodes $enc + +echo "== E1" +e1=0 +for f in "$OUT"/e3/*.amb; do + b=$(basename "$f" .amb) + "$PY" "$ROOT/tools/e1.py" "$f" --input "$IN/$b.raw" --quiet > /dev/null || { echo "E1 fail: $f"; e1=1; } +done +for d in e5 e7; do + for f in "$OUT"/$d/*.amb; do + b=$(basename "$f" .amb) + "$PY" "$ROOT/tools/e1.py" "$f" --input "$VEC/$d/$b.raw" --quiet > /dev/null || { echo "E1 fail: $f"; e1=1; } + done +done +echo "E1 (e1.py): $(ls "$OUT"/e3/*.amb "$OUT"/e5/*.amb "$OUT"/e7/*.amb | wc -l) streams checked" +record "E1 (streams)" $e1 + +echo "== E1/E2/E7" +run "$BUILD/test_mirror" "$VEC" --e7 --inputs "$IN" --stress 600 +record "E1/E2/E7" $? + +echo "== E3" +run "$PY" "$ROOT/tools/e3.py" "$OUT/e3" --jobs $JOBS --quiet --json "$OUT/e3.json" +record E3 $? + +echo "== E4" +run "$PY" "$ROOT/tools/e4.py" "$OUT/e3" --json "$OUT/e4.json" +record E4 $? + +echo "== E5" +run "$PY" "$ROOT/tools/e5.py" "$OUT/e3" --e5-cand "$OUT/e5" --inputs "$IN" --json "$OUT/e5.json" +record E5 $? + +echo "== E6" +e6=0 +run "$PY" "$ROOT/tools/e6.py" gen "$OUT/e6in" > /dev/null || e6=1 +for f in "$OUT"/e6in/*.raw; do run "$BUILD/xombe-enc" "$f" "$OUT/e6/$(basename "$f" .raw).amb" || e6=1; done +run "$PY" "$ROOT/tools/e6.py" check "$OUT/e6in/cases.json" "$OUT/e6" > "$OUT/e6.txt" || e6=1 +tail -2 "$OUT/e6.txt" +run "$PY" "$ROOT/tools/e6.py" check pkg "$OUT/e7" > "$OUT/e6pkg.txt" || e6=1 +tail -2 "$OUT/e6pkg.txt" +run "$PY" "$ROOT/tools/e6.py" speech "$OUT/e3" "$OUT/e5" "$OUT/e7" || e6=1 +record E6 $e6 + +echo "== summary$summary" +exit $status diff --git a/xombe/test/conformance_dstar.sh b/xombe/test/conformance_dstar.sh new file mode 100644 index 0000000..0654214 --- /dev/null +++ b/xombe/test/conformance_dstar.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# conformance_dstar.sh [BUILD [PYTHON]]: D-STAR gates from the repository's own vectors (tools/dstar_conf.py) +set -u +BUILD=${1:-build} +PY=${2:-python3} +ROOT=$(cd "$(dirname "$0")/.." && pwd) +case $BUILD in /*) ;; *) BUILD=$ROOT/$BUILD ;; esac +OUT=$BUILD/conformance-dstar +export XOMBE_BUILD=$BUILD +mkdir -p "$OUT" +status=0 +summary="" + +record() { + if [ "$2" -eq 0 ]; then summary="$summary +$1: PASS"; else summary="$summary +$1: FAIL"; status=1; fi +} + +for t in xombe-enc xombe-dec xombe-xc dstar_dump_fec; do + if [ ! -x "$BUILD/$t" ]; then + echo "$BUILD/$t missing: conformance-dstar needs XOMBE_DSTAR, XOMBE_ENCODER and the tests" >&2 + exit 1 + fi +done +echo "== inputs" +"$PY" "$ROOT/scripts/gen_inputs.py" --out "$BUILD/e3in" > /dev/null +record inputs $? + +echo "== refs" +"$PY" "$ROOT/tools/dstar_conf.py" refs "$BUILD" --json "$OUT/refs.json" +record refs $? + +echo "== speech" +"$PY" "$ROOT/tools/dstar_conf.py" speech "$BUILD" "$OUT/speech" --inputs "$BUILD/e3in" --json "$OUT/speech.json" +record speech $? + +echo "== tones" +"$PY" "$ROOT/tools/dstar_conf.py" tones "$BUILD" "$OUT/tones" --inputs "$BUILD/e3in" --json "$OUT/tones.json" +record tones $? + +echo "== summary$summary" +exit $status diff --git a/xombe/test/dstar.cmake b/xombe/test/dstar.cmake new file mode 100644 index 0000000..bf9d6f4 --- /dev/null +++ b/xombe/test/dstar.cmake @@ -0,0 +1,220 @@ +# D-STAR (AMBE 2400) reference harness, record format in test/dstar_ref.h +set(XOMBE_DSTAR_REFS ${CMAKE_CURRENT_SOURCE_DIR}/vectors/dstar) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dstar_out) # outputs, also of the tool tests that need no Python +find_package(Python3 COMPONENTS Interpreter QUIET) + +add_library(xombe_dstar_ref STATIC test/dstar_ref.c) +xombe_target_options(xombe_dstar_ref) +xombe_executable(test_dstar_refs test/test_dstar_refs.c) +target_link_libraries(test_dstar_refs xombe_dstar_ref) +add_test(NAME dstar_refs COMMAND test_dstar_refs ${XOMBE_DSTAR_REFS}) + +# xombe_dstar_test( [DIR ] [CLIPS ...] INPUT REF +# RUN [...] [CMP ...]) +# +# Adds one ctest per clip (or one test without CLIPS), named dstar_[_], that runs +# / +# and then compares with / using test/dstar_cmp.py ; a REF ending +# in .raw is compared as PCM (--pcm). is vectors/dstar unless DIR gives another. may be a +# target name. The program reads the input (a stream, or a reference file it takes its inputs from) and writes +# its dump with test/dstar_ref.h's writer, using the reference file's column names. Needs Python 3 (standard +# library only): without it each test is a placeholder that ctest reports as skipped (label no_python). +function(xombe_dstar_test name) + cmake_parse_arguments(A "" "DIR;INPUT;REF" "CLIPS;RUN;CMP" ${ARGN}) + if(A_DIR) + set(dir ${A_DIR}) + else() + set(dir ${XOMBE_DSTAR_REFS}) + endif() + list(GET A_RUN 0 prog) + list(REMOVE_AT A_RUN 0) + if(TARGET ${prog}) + set(prog $) + endif() + set(pcm "") + if(A_REF MATCHES "\\.raw$") + set(pcm --pcm) + endif() + if(NOT A_CLIPS) + set(A_CLIPS "-") + endif() + foreach(clip ${A_CLIPS}) + if(clip STREQUAL "-") + set(clip "") + set(tname dstar_${name}) + else() + set(tname dstar_${name}_${clip}) + endif() + if(NOT Python3_Interpreter_FOUND) + add_test(NAME ${tname} COMMAND sh -c "exit 77") + set_tests_properties(${tname} PROPERTIES SKIP_RETURN_CODE 77 LABELS no_python) + set_property(GLOBAL APPEND PROPERTY XOMBE_SKIPPED_TESTS ${tname}) + continue() + endif() + set(out ${CMAKE_CURRENT_BINARY_DIR}/dstar_out/${tname}.out) + add_test(NAME ${tname} COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/dstar_cmp.py + ${pcm} ${A_CMP} ${dir}/${clip}${A_REF} ${out} --run ${prog} ${A_RUN} ${dir}/${clip}${A_INPUT} ${out}) + endforeach() +endfunction() + +# In-repo clips: sp (speech), nz (speech in noise), tn (tones), kx (Knox tones, near silence) and +# sper (sp with special frames and bit errors; D-Star input only); rate-33 inputs: sp, tn, kx, sper, tx. +set(XOMBE_DSTAR_CLIPS sp nz tn kx sper) +set(XOMBE_DSTAR_R33_CLIPS sp tn kx sper tx) + +# The comparison machinery itself: each reference against a copy of itself. +xombe_dstar_test(selfcheck CLIPS sp sper INPUT .fec.txt.gz REF .fec.txt.gz RUN ${CMAKE_COMMAND} -E copy) +xombe_dstar_test(selfcheck_pcm CLIPS sper INPUT .dec.raw REF .dec.raw RUN ${CMAKE_COMMAND} -E copy) +xombe_dstar_test(selfcheck_quant INPUT quant_closed.txt.gz REF quant_closed.txt.gz RUN ${CMAKE_COMMAND} -E copy + CMP --key tset,parent,pass) + +# deq floats: float32 against the model's float64, measured max |error|: +# a 3.2e-6 (log2; float32 ulp is 9.5e-7 for |a| in [8, 16)), Tv 1.0e-6, G 4.4e-7, f0 1.8e-9. +set(XOMBE_DSTAR_DEQ_TOL --tol *=1e-5:0) +if(XOMBE_DSTAR) + # P1: FEC, fields, the error rule and the encoder's packer (exact), and dequantization against the mirror. + xombe_internal_executable(test_dstar_tables test/test_dstar_tables.c) + target_link_libraries(test_dstar_tables xombe_dstar_ref) + add_test(NAME dstar_tables COMMAND test_dstar_tables ${XOMBE_DSTAR_REFS}) + xombe_internal_executable(dstar_dump_fec test/dstar_dump_fec.c) + target_link_libraries(dstar_dump_fec xombe_dstar_ref) + xombe_internal_executable(dstar_dump_deq test/dstar_dump_deq.c) + target_link_libraries(dstar_dump_deq xombe_dstar_ref) + xombe_dstar_test(fec CLIPS ${XOMBE_DSTAR_CLIPS} INPUT .dstar REF .fec.txt.gz RUN dstar_dump_fec) + xombe_dstar_test(fec_enc INPUT fec_enc.txt.gz REF fec_enc.txt.gz RUN dstar_dump_fec --enc + CMP --tol level=0:0) + xombe_dstar_test(deq CLIPS ${XOMBE_DSTAR_CLIPS} INPUT .dstar REF .deq.txt.gz RUN dstar_dump_deq + CMP ${XOMBE_DSTAR_DEQ_TOL}) + # P2: the decoder (dstar_dump_dec). + xombe_internal_executable(dstar_dump_dec test/dstar_dump_dec.c) + target_link_libraries(dstar_dump_dec xombe_dstar_ref) + # tolerances, measured: + # dec: float32 against the model's float64: Pia 7.2e-6, PiG 3.5e-6, lam 4.6e-6 (log2 units), Pif0 3.9e-7 + # (the initial memory's f0); fbar 0.0033 Hz (AMBE+2's initial average pitch, 111.63 Hz against 111.6333). + # half: a 5.2e-5 at |a| ~ 12 (6 printed digits), M 3e-5 relative (2^a), rms 0.5 + 0.2%. + # PCM: the AMBE+2 synthesis' own C-vs-Python difference (relative ~1e-3, max 5 LSB on AMBE+2's es2). tn and sper + # meet the gate up to their first dual tone (frames 25 and 31), then drift in phase: xombe's tone table f0 + # (US 7,970,606 B2) and the model's fitted one differ by up to 0.007 Hz. pcm_all bounds the whole clip + set(XOMBE_DSTAR_DEC_TOL --tol *=1e-5:0 --tol fbar=0.01:0) + set(XOMBE_DSTAR_HALF_TOL --tol *=1e-5:1e-5 --tol M=1e-5:3e-5 --tol rms=0.5:2e-3) + set(XOMBE_DSTAR_PCM_GATE --lsb 4 --max-rms 3 --min-within 0.995) + xombe_dstar_test(dec CLIPS ${XOMBE_DSTAR_CLIPS} INPUT .dstar REF .dec.txt.gz RUN dstar_dump_dec + CMP ${XOMBE_DSTAR_DEC_TOL}) + xombe_dstar_test(half CLIPS sp nz tn kx sper INPUT .dstar REF .half.txt.gz RUN dstar_dump_dec --half + CMP ${XOMBE_DSTAR_HALF_TOL}) + xombe_dstar_test(pcm CLIPS sp nz kx INPUT .dstar REF .dec.raw RUN dstar_dump_dec --pcm + CMP ${XOMBE_DSTAR_PCM_GATE}) + xombe_dstar_test(pcm CLIPS tn INPUT .dstar REF .dec.raw RUN dstar_dump_dec --pcm + CMP ${XOMBE_DSTAR_PCM_GATE} --samples 0:4000) + xombe_dstar_test(pcm CLIPS sper INPUT .dstar REF .dec.raw RUN dstar_dump_dec --pcm + CMP ${XOMBE_DSTAR_PCM_GATE} --samples 0:4960) + xombe_dstar_test(pcm_all CLIPS tn INPUT .dstar REF .dec.raw RUN dstar_dump_dec --pcm + CMP --lsb 4 --max-rms 110 --min-within 0.55) + xombe_dstar_test(pcm_all CLIPS sper INPUT .dstar REF .dec.raw RUN dstar_dump_dec --pcm + CMP --lsb 4 --max-rms 4 --min-within 0.94) +endif() + +# P3: the closed-loop amplitude quantizer (src/common/cquant.c) on the quantizer cases. +if(XOMBE_DSTAR AND XOMBE_ENCODER) + xombe_internal_executable(dstar_dump_quant test/dstar_dump_quant.c) + target_link_libraries(dstar_dump_quant xombe_dstar_ref) + set(XOMBE_DSTAR_QUANT_CMP --tol *=1e-5:1e-4) + xombe_dstar_test(quant_closed INPUT quant_closed.txt.gz REF quant_closed.txt.gz RUN dstar_dump_quant closed + CMP --key tset,parent,pass ${XOMBE_DSTAR_QUANT_CMP}) + xombe_dstar_test(quant_dstar INPUT quant_dstar.txt.gz REF quant_dstar.txt.gz RUN dstar_dump_quant dstar + CMP --key id ${XOMBE_DSTAR_QUANT_CMP}) + xombe_dstar_test(quant_ambe2 INPUT quant_ambe2.txt.gz REF quant_ambe2.txt.gz RUN dstar_dump_quant ambe2 + CMP --key id ${XOMBE_DSTAR_QUANT_CMP}) + # capped at 100 units (the encoders use XOMBE_CQ_CAP): the bound per search, the summed error within 1e-3 + # of the exact search's (checked by dstar_dump_quant), and 99% of the calls as the reference + set(cmin_closed --min b=0.99 --min err=0.99) + set(cmin_dstar --min b=0.99 --min ahat=0.99 --min err=0.99) + set(cmin_ambe2 --min bclosed=0.99 --min pick=0.99 --min b=0.99 --min ahat=0.99 --min err=0.99) + set(ckey_closed tset,parent,pass) + set(ckey_dstar id) + set(ckey_ambe2 id) + foreach(k closed dstar ambe2) + xombe_dstar_test(quant_${k}_cap INPUT quant_${k}.txt.gz REF quant_${k}.txt.gz RUN dstar_dump_quant --cap 100 ${k} + CMP --key ${ckey_${k}} ${XOMBE_DSTAR_QUANT_CMP} ${cmin_${k}}) + endforeach() +endif() + +# P4b: the encoder back end (src/dstar/dstar_enc.c) on the model's recorded inputs (test/dstar_dump_enc_be.c). +# Exact: b0 from the refined period, b1 from the recorded a and w, the fields and bytes of the recorded targets +# quantized against the mirror over the stream. m_noise is the generated table (16 bits, relative error < 3e-5). +# --spec: the voicing on the C spectrum of the input (C high-pass, float), against the model's. +if(XOMBE_DSTAR AND XOMBE_ENCODER) + xombe_internal_executable(dstar_dump_enc_be test/dstar_dump_enc_be.c) + target_link_libraries(dstar_dump_enc_be xombe_dstar_ref) + set(XOMBE_DSTAR_ENC_CLIPS sp nz tn kx) + xombe_dstar_test(enc_be CLIPS ${XOMBE_DSTAR_ENC_CLIPS} INPUT .enc.txt.gz REF .enc.txt.gz RUN dstar_dump_enc_be + CMP --tol mn=0:1e-4) + # measured: a within 0.01 on 99.84-100% of frames (worst 0.073), b1 equal on all but one frame, mv and w differ + # by the input high-pass (4-digit coefficients against scipy's Butterworth) + set(XOMBE_DSTAR_ENC_SPEC_CMP --tol mv=0:0.01 --tol w=0:0.01 --tol a=0.01:0 --min mv=0.9 --min w=0.95 --min a=0.995 + --min b1=0.999) + # The q15 kernels' block-floating-point FFT (~60-65 dB) moves the metric further: measured minimums over the + # same clips w 76.7%, mv 79.2%, a 94.8%, b1 99.77% + if(XOMBE_KERNELS STREQUAL "q15") + set(XOMBE_DSTAR_ENC_SPEC_CMP --tol mv=0:0.01 --tol w=0:0.01 --tol a=0.01:0 --min mv=0.78 --min w=0.75 + --min a=0.94 --min b1=0.997) + endif() + xombe_dstar_test(enc_be_spec CLIPS ${XOMBE_DSTAR_ENC_CLIPS} INPUT .enc.txt.gz REF .enc.txt.gz + RUN dstar_dump_enc_be --spec CMP ${XOMBE_DSTAR_ENC_SPEC_CMP}) + + # P4c: the whole encoder with the D-Star output on the clip's PCM (test/dstar_dump_enc.c): the tone pipeline's + # detection, run rule and final tone, and the frame class, exact against the model; levels within 0.02. + xombe_internal_executable(dstar_dump_enc test/dstar_dump_enc.c) + target_link_libraries(dstar_dump_enc xombe_dstar_ref) + set(XOMBE_DSTAR_ENC_TONE_CMP --tol det=0.02:0 --tol trk=0.02:0 --tol tone=0.02:0 --skip b0,b1,out) + # kx's Knox frames take their pairs from xombe's tone table (US 7,970,606 B2's f0 and harmonics); the model's + # are fitted, and every kx frame still matches, bytes included. + xombe_dstar_test(enc CLIPS sp nz tn kx INPUT .in.raw REF .enc.txt.gz RUN dstar_dump_enc CMP ${XOMBE_DSTAR_ENC_TONE_CMP}) + xombe_dstar_test(enc_dual CLIPS tn INPUT .in.raw REF .enc.txt.gz RUN dstar_dump_enc --dual + CMP ${XOMBE_DSTAR_ENC_TONE_CMP}) +endif() + +# P5: the rate-33 -> D-STAR transcoder (src/dstar/xcode.c) on the rate-33 streams (test/dstar_dump_xc.c). +# Floats: f0, a, G, soft and tgt within 1e-5 (float32 against the model's float64). Knox frames (kx, tx) take f0 +# and harmonics from xombe's tone table (US 7,970,606 B2), the model its fitted one: b0 differs for IDs 145, 150, +# 151, 153, 154 and 157, and the mirror carries the difference on +if(XOMBE_DSTAR) + xombe_internal_executable(dstar_dump_xc test/dstar_dump_xc.c) + target_link_libraries(dstar_dump_xc xombe_dstar_ref) + set(XOMBE_DSTAR_XC_CMP --tol *=1e-5:1e-5) + set(XOMBE_DSTAR_XC_KNOX --min tgt=0.4 --min tb0=0.44 --min b=0.17 --min out=0.17) + xombe_dstar_test(xc CLIPS sp tn sper INPUT .r33 REF .xc.txt.gz RUN dstar_dump_xc CMP ${XOMBE_DSTAR_XC_CMP}) + xombe_dstar_test(xc CLIPS kx tx INPUT .r33 REF .xc.txt.gz RUN dstar_dump_xc CMP ${XOMBE_DSTAR_XC_CMP} + ${XOMBE_DSTAR_XC_KNOX}) + # the tool's stream equals the model's output + if(XOMBE_BUILD_TOOLS) + foreach(clip sp tn sper) + add_test(NAME dstar_xc_tool_${clip} COMMAND sh -c "\"$1\" \"$2\" \"$3\" && \"$4\" -E compare_files \"$3\" \"$5\"" + xc $ ${XOMBE_DSTAR_REFS}/${clip}.r33 + ${CMAKE_CURRENT_BINARY_DIR}/dstar_out/xc_tool_${clip}.dstar ${CMAKE_COMMAND} + ${XOMBE_DSTAR_REFS}/${clip}.xc.dstar) + endforeach() + endif() +endif() + +# the D-STAR -> rate-33 transcoder (src/dstar/xrev.c) on the D-STAR streams (test/dstar_dump_xrev.c). +# floats: f0, a and tgt within 1e-5 (float32 against the model's float64) +if(XOMBE_DSTAR AND XOMBE_ENCODER) + xombe_internal_executable(dstar_dump_xrev test/dstar_dump_xrev.c) + target_link_libraries(dstar_dump_xrev xombe_dstar_ref) + set(XOMBE_DSTAR_XREV_CMP --tol *=1e-5:1e-5) + xombe_dstar_test(xrev CLIPS sp tn kx sper INPUT .dstar REF .xrev.txt.gz RUN dstar_dump_xrev + CMP ${XOMBE_DSTAR_XREV_CMP}) + # with the transcoder's XOMBE_CQ_CAP (the tool's search): the same records + xombe_dstar_test(xrev_capped CLIPS sp tn kx sper INPUT .dstar REF .xrev.txt.gz RUN dstar_dump_xrev --capped + CMP ${XOMBE_DSTAR_XREV_CMP}) + if(XOMBE_BUILD_TOOLS) + foreach(clip sp tn kx sper) + add_test(NAME dstar_xrev_tool_${clip} + COMMAND sh -c "\"$1\" --reverse \"$2\" \"$3\" && \"$4\" -E compare_files \"$3\" \"$5\"" + xrev $ ${XOMBE_DSTAR_REFS}/${clip}.dstar + ${CMAKE_CURRENT_BINARY_DIR}/dstar_out/xrev_tool_${clip}.r33 ${CMAKE_COMMAND} + ${XOMBE_DSTAR_REFS}/${clip}.xrev.r33) + endforeach() + endif() +endif() diff --git a/xombe/test/dstar_cmp.py b/xombe/test/dstar_cmp.py new file mode 100644 index 0000000..00af2a8 --- /dev/null +++ b/xombe/test/dstar_cmp.py @@ -0,0 +1,242 @@ +#!/usr/bin/env python3 +"""compares a C stage dump against a D-STAR reference file, standard library only + +records: + dstar_cmp.py REF TEST [--key n,h] [--cols a,b,...] [--skip c,...] [--tol COL=ABS[:REL]]... [--min COL=RATE]... + [--rows N] [--run CMD ARGS...] +rows are matched on the key columns (default n, plus h when both files have it, else row order) +compared columns are those in both files (or --cols), minus --skip. integers, tokens, hex and bit strings, +and integer vectors must be equal, floats and float vectors agree when |test - ref| <= ABS + REL*|ref| for +every element (default 1e-6:1e-6, --tol '*=ABS:REL' changes the default), nan only matches nan +a column passes when its agreement rate is >= its --min (default 1) + +PCM: + dstar_cmp.py --pcm REF.raw TEST.raw [--lsb N] [--max-rms R] [--min-within RATE] [--samples A:B] + [--run CMD ARGS...] +int16 little endian (--samples: only samples A..B-1 of both, B empty for the end), reports the maximum and +rms difference in LSB and the fraction of samples within --lsb (default 1), fails when the rms difference +exceeds --max-rms (default 0) or the fraction is below --min-within (default 1) + +--run (must come last) runs the producer first, e.g. the C dump program that writes TEST +exit status: 0 agree, 1 disagree, 2 usage or I/O error +""" +import gzip +import math +import os +import struct +import subprocess +import sys + + +def read(path): + """-> (meta, [(name, type)], [row dict])""" + with open(path, 'rb') as fh: + gz = fh.read(2) == b'\x1f\x8b' + op = gzip.open if gz else open + meta, cols, rows = {}, None, [] + with op(path, 'rt') as fh: + for ln, line in enumerate(fh, 1): + line = line.rstrip('\n') + if line.startswith('#'): + if '=' in line: + k, v = line[1:].strip().split('=', 1) + meta[k] = v + continue + tok = line.split() + if not tok: + continue + if cols is None: + cols = [tuple(t.rsplit(':', 1)) for t in tok] + continue + r, i = {}, 0 + try: + for name, t in cols: + if t == 'i': + r[name] = int(tok[i]); i += 1 + elif t == 'f': + r[name] = float(tok[i]); i += 1 + elif t in ('s', 'x', 'b'): + r[name] = '' if tok[i] == '-' else tok[i]; i += 1 + elif t in ('i*', 'f*'): + n = int(tok[i]); i += 1 + conv = int if t == 'i*' else float + r[name] = [conv(x) for x in tok[i:i + n]] + if len(r[name]) != n: + raise ValueError('short vector ' + name) + i += n + else: + raise ValueError('bad type ' + t) + except (IndexError, ValueError) as e: + raise ValueError('%s:%d: %s' % (path, ln, e)) + if i != len(tok): + raise ValueError('%s:%d: %d values, %d used' % (path, ln, len(tok), i)) + rows.append(r) + if cols is None: + raise ValueError('%s: no column line' % path) + return meta, cols, rows + + +def fclose(a, b, ab, rel): + if math.isnan(a) or math.isnan(b): + return math.isnan(a) and math.isnan(b), 0.0 + d = abs(a - b) + return d <= ab + rel * abs(a), d + + +def cmp_records(ref, test, opt): + _, rc, rr = read(ref) + _, tc, tr = read(test) + rtypes, ttypes = dict(rc), dict(tc) + key = opt['key'] or (['n', 'h'] if 'h' in rtypes and 'h' in ttypes else ['n']) + key = [k for k in key if k in rtypes and k in ttypes] + cols = opt['cols'] or [c for c, _ in rc if c in ttypes] + cols = [c for c in cols if c not in opt['skip'] and c not in key] + for c in cols: + if c not in rtypes or c not in ttypes: + print('column %s missing from %s' % (c, 'REF' if c not in rtypes else 'TEST')) + return 2 + if rtypes[c] != ttypes[c]: + print('column %s: type %s in REF, %s in TEST' % (c, rtypes[c], ttypes[c])) + return 2 + if key: + tindex = {tuple(r[k] for k in key): r for r in tr} + pairs = [(r, tindex.get(tuple(r[k] for k in key))) for r in rr] + else: + pairs = list(zip(rr, tr)) + [(r, None) for r in rr[len(tr):]] + if opt['rows'] is not None: + pairs = pairs[:opt['rows']] + missing = sum(1 for _, t in pairs if t is None) + print('%s vs %s: %d reference rows, %d test rows, %d unmatched; key %s' % ( + os.path.basename(ref), os.path.basename(test), len(rr), len(tr), missing, ','.join(key) or 'row order')) + status = 0 if pairs else 1 + for c in cols: + t = rtypes[c] + ab, rel = opt['tol'].get(c, opt['tol'].get('*', (1e-6, 1e-6))) + agree, total, worst, wrow = 0, 0, 0.0, None + for r, s in pairs: + total += 1 + if s is None: + continue + a, b = r[c], s[c] + if t == 'f': + ok, d = fclose(a, b, ab, rel) + elif t == 'f*': + ok, d = len(a) == len(b), (math.inf if len(a) != len(b) else 0.0) + if ok: + for x, y in zip(a, b): + o, e = fclose(x, y, ab, rel) + ok, d = ok and o, max(d, e) + else: + ok, d = a == b, 0.0 if a == b else math.inf + agree += ok + if d > worst or (not ok and wrow is None): + worst, wrow = max(d, worst), tuple(r[k] for k in key) if key else None + rate = agree / total if total else 0.0 + need = opt['min'].get(c, opt['min'].get('*', 1.0)) + flag = 'ok' if rate >= need else 'FAIL' + if flag == 'FAIL': + status = 1 + tol = (' tol %g:%g' % (ab, rel)) if t in ('f', 'f*') else '' + wtxt = '' + if worst: + wtxt = ' worst %s at %s' % ('mismatch' if worst == math.inf else '%.3g' % worst, wrow) + print(' %-10s %-2s %6d/%-6d %7.3f%%%s%s %s' % (c, t, agree, total, 100.0 * rate, tol, wtxt, flag)) + return status + + +def read_pcm(path): + b = open(path, 'rb').read() + if len(b) % 2: + raise ValueError('%s: odd size' % path) + return struct.unpack('<%dh' % (len(b) // 2), b) + + +def cmp_pcm(ref, test, opt): + x, y = read_pcm(ref), read_pcm(test) + if opt['samples']: + a, b = opt['samples'] + x, y = x[a:b], y[a:b] + n = min(len(x), len(y)) + if len(x) != len(y): + print('length: REF %d samples, TEST %d' % (len(x), len(y))) + d = [abs(a - b) for a, b in zip(x[:n], y[:n])] + rms = math.sqrt(sum(v * v for v in d) / n) if n else 0.0 + sig = math.sqrt(sum(v * v for v in x[:n]) / n) if n else 0.0 + within = sum(1 for v in d if v <= opt['lsb']) / n if n else 0.0 + snr = 20 * math.log10(sig / rms) if rms > 0 and sig > 0 else math.inf + print('%s vs %s: %d samples, max diff %d LSB, rms diff %.3f LSB, %.3f%% within %d LSB, SNR %.1f dB' % ( + os.path.basename(ref), os.path.basename(test), n, max(d) if d else 0, rms, 100 * within, opt['lsb'], snr)) + ok = len(x) == len(y) and rms <= opt['max_rms'] and within >= opt['min_within'] + print(' %s' % ('ok' if ok else 'FAIL')) + return 0 if ok else 1 + + +def parse(argv): + opt = dict(key=None, cols=None, skip=set(), tol={}, min={}, rows=None, pcm=False, lsb=1, max_rms=0.0, + min_within=1.0, run=None, samples=None) + pos, i = [], 0 + while i < len(argv): + a = argv[i] + if a == '--run': + opt['run'] = argv[i + 1:] + break + if a == '--pcm': + opt['pcm'] = True + elif a in ('--key', '--cols', '--skip', '--tol', '--min', '--rows', '--lsb', '--max-rms', '--min-within', + '--samples'): + i += 1 + v = argv[i] + if a == '--key': + opt['key'] = [s for s in v.split(',') if s] + elif a == '--cols': + opt['cols'] = [s for s in v.split(',') if s] + elif a == '--skip': + opt['skip'] |= set(v.split(',')) + elif a == '--tol': + c, t = v.split('=') + ab, _, rel = t.partition(':') + opt['tol'][c] = (float(ab), float(rel or 0.0)) + elif a == '--min': + c, t = v.split('=') + opt['min'][c] = float(t) + elif a == '--rows': + opt['rows'] = int(v) + elif a == '--samples': + a0, b0 = v.split(':') + opt['samples'] = (int(a0), int(b0) if b0 else None) + elif a == '--lsb': + opt['lsb'] = int(v) + elif a == '--max-rms': + opt['max_rms'] = float(v) + else: + opt['min_within'] = float(v) + elif a.startswith('--'): + raise SystemExit('unknown option %s' % a) + else: + pos.append(a) + i += 1 + if len(pos) != 2: + raise SystemExit(__doc__) + return pos, opt + + +def main(argv): + try: + (ref, test), opt = parse(argv) + except SystemExit as e: + print(e, file=sys.stderr) + return 2 + if opt['run']: + r = subprocess.run(opt['run']) + if r.returncode: + print('producer failed (%d): %s' % (r.returncode, ' '.join(opt['run']))) + return 2 + try: + return cmp_pcm(ref, test, opt) if opt['pcm'] else cmp_records(ref, test, opt) + except (OSError, ValueError) as e: + print(e) + return 2 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/xombe/test/dstar_dump_dec.c b/xombe/test/dstar_dump_dec.c new file mode 100644 index 0000000..b1fd117 --- /dev/null +++ b/xombe/test/dstar_dump_dec.c @@ -0,0 +1,132 @@ +#include +#include +#include +#include +#include "../src/internal.h" +#include "../src/dstar/dsd_state.h" +#include "dstar_ref.h" + +/* D-STAR decoder records: --dec (default) frame level (stage 'dec'), --half half-frame sets (stage 'half'), + --pcm the PCM */ + +static const char *const LOG[] = {"voice", "tone", "null", "repeat", "mute"}; + +static const char *cls_name(int c) +{ + return c == XOMBE_CLASS_VOICE ? "voice" : c == XOMBE_CLASS_SILENCE ? "silence" : c == XOMBE_CLASS_TONE ? "tone" : "?"; +} + +static void write_half(dsref_writer *w, long n, int h, const xombe_set *s, const int16_t *pcm, int N) +{ + char V[9], vl[XOMBE_LMAX + 2]; + uint8_t vh[XOMBE_LMAX + 1]; + float a[XOMBE_LMAX + 1], M[XOMBE_LMAX + 1]; + double e2 = 0.0; + int l, tone = s->cls == XOMBE_CLASS_TONE; + for (l = 0; l < 8; l++) + V[l] = tone || s->vb[l] ? 'V' : 'U'; + V[8] = 0; + memset(vh, 0, sizeof(vh)); + if (!tone) + xombe__ds_harm_voicing(s->vb, s->f0, s->L, vh); + for (l = 1; l <= s->L; l++) { + if (tone) { + int on = s->e[l] > XOMBE_AMP_OFF; + M[l] = on ? exp2f(s->e[l]) : 0.0f; + a[l] = on ? s->e[l] : (float)log2(1e-30); + vh[l] = (uint8_t)on; + } else { + M[l] = exp2f(s->e[l]); + a[l] = s->a[l]; + } + vl[l - 1] = vh[l] ? 'V' : 'U'; + } + vl[s->L] = 0; + for (l = 0; l < N; l++) + e2 += (double)pcm[l] * pcm[l]; + dsref_wi(w, n); + dsref_wi(w, h); + dsref_ws(w, cls_name(s->cls)); + dsref_wi(w, s->repeat); + dsref_wf(w, s->f0); + dsref_wi(w, s->L); + dsref_ws(w, V); + dsref_ws(w, vl); + dsref_wfv_float(w, a + 1, s->L); + dsref_wfv_float(w, M + 1, s->L); + dsref_wf(w, sqrt(e2 / N)); + dsref_wend(w); +} + +int main(int argc, char **argv) +{ + long n, nf; + uint8_t *fr; + dsref_writer w; + xombe_dec_mem mem; + xombe_dec *s; + FILE *pcm_out = NULL; + int mode = 0, ok = 1, a = 1; + if (argc == 4 && !strcmp(argv[1], "--half")) + mode = 1, a = 2; + else if (argc == 4 && !strcmp(argv[1], "--pcm")) + mode = 2, a = 2; + else if (argc == 4 && !strcmp(argv[1], "--dec")) + a = 2; + if (argc != a + 2) { + fprintf(stderr, "usage: dstar_dump_dec [--dec | --half | --pcm] IN.dstar OUT\n"); + return 2; + } + if (!(fr = dsref_read_frames(argv[a], 9, &nf))) + return 1; + if (mode == 2) + ok = (pcm_out = fopen(argv[a + 1], "wb")) != NULL; + else if (mode == 1) + ok = dsref_wopen(&w, argv[a + 1], "half", "n:i h:i cls:s rep:i f0:f L:i V:s vl:s a:f* M:f* rms:f", 0); + else + ok = dsref_wopen(&w, argv[a + 1], "dec", + "n:i log:s ea:i eb:i bf:i hb:i eT:i e1:i Picls:s PiL:i Pif0:f PiG:f lam:f fbar:f Pia:f*", 0); + if (!ok) { + free(fr); + return 1; + } + s = xombe_dec_init(&mem, XOMBE_DSTAR); + xombe_dec_set_noise(s, XOMBE_NOISE_CONFORMANCE, 0); + for (n = 0; n < nf && ok; n++) { + int16_t pcm[160]; + float fbar = s->c.avg_f0 * XOMBE_FS; /* the model records it before the frame's halves */ + xombe_dec_half(s, fr + 9 * n, 0, 0, 80, pcm); + if (mode == 0) { + const xombe_pred *pi = &s->c.pi; + dsref_wi(&w, n); + dsref_ws(&w, LOG[s->ds.log]); + dsref_wi(&w, s->c.decision.e0); + dsref_wi(&w, s->c.decision.e1); + dsref_wi(&w, s->c.decision.bf); + dsref_wi(&w, s->c.decision.hb); + dsref_wi(&w, s->ds.eT); + dsref_wi(&w, s->ds.e1); + dsref_ws(&w, cls_name(pi->cls)); + dsref_wi(&w, pi->L); + dsref_wf(&w, pi->f0); + dsref_wf(&w, pi->gamma); + dsref_wf(&w, s->c.lambda); + dsref_wf(&w, fbar); + dsref_wfv_float(&w, pi->a + 1, pi->L); + dsref_wend(&w); + } else if (mode == 1) { + write_half(&w, n, 1, &s->c.p1, pcm, 80); + } + xombe_dec_half(s, fr + 9 * n, 0, 1, 80, pcm + 80); + if (mode == 1) + write_half(&w, n, 2, &s->c.p2, pcm + 80, 80); + if (mode == 2) + ok = fwrite(pcm, 2, 160, pcm_out) == 160; + } + free(fr); + if (mode == 2) + ok &= fclose(pcm_out) == 0; + else + ok &= dsref_wclose(&w); + return ok ? 0 : 1; +} diff --git a/xombe/test/dstar_dump_deq.c b/xombe/test/dstar_dump_deq.c new file mode 100644 index 0000000..92800f4 --- /dev/null +++ b/xombe/test/dstar_dump_deq.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include "../src/dstar/dstar_internal.h" +#include "dstar_ref.h" + +/* D-STAR dequantization against the mirror (stage 'deq') */ + +int main(int argc, char **argv) +{ + long n, nf; + uint8_t *fr; + dsref_writer w; + xombe_ds_mirror m; + int k, ok; + if (argc != 3) { + fprintf(stderr, "usage: dstar_dump_deq IN.dstar OUT\n"); + return 2; + } + if (!(fr = dsref_read_frames(argv[1], 9, &nf))) + return 1; + if (!dsref_wopen(&w, argv[2], "deq", + "n:i voice:i b0:i b1:i b2:i b3:i b4:i b5:i b6:i b7:i b8:i f0:f L:i vl:b Tv:f* G:f stL:i " + "stG:f sta:f*", 0)) { + free(fr); + return 1; + } + xombe__ds_mirror_init(&m); + for (n = 0; n < nf; n++) { + xombe_ds_frame f; + xombe_ds_params p; + int voice; + xombe__ds_fec_decode(fr + 9 * n, &f); + voice = xombe__ds_params_from_frame(&m, &f, &p); + dsref_wi(&w, n); + dsref_wi(&w, voice); + for (k = 0; k < 9; k++) + dsref_wi(&w, f.b[k]); + if (voice) { + dsref_wf(&w, p.f0); + dsref_wi(&w, p.L); + dsref_wb(&w, p.vl + 1, p.L); + dsref_wfv_float(&w, p.Tv + 1, p.L); + dsref_wf(&w, p.G); + } else { + dsref_wf(&w, NAN); + dsref_wi(&w, 0); + dsref_wb(&w, NULL, 0); + dsref_wfv_float(&w, NULL, 0); + dsref_wf(&w, NAN); + } + dsref_wi(&w, m.L); + dsref_wf(&w, m.G); + dsref_wfv_float(&w, m.a + 1, m.L); + dsref_wend(&w); + } + free(fr); + ok = dsref_wclose(&w); + return ok ? 0 : 1; +} diff --git a/xombe/test/dstar_dump_enc.c b/xombe/test/dstar_dump_enc.c new file mode 100644 index 0000000..0a4c511 --- /dev/null +++ b/xombe/test/dstar_dump_enc.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include "../src/state.h" +#include "../src/dstar/dstar_enc.h" +#include "dstar_ref.h" + +/* whole encoder with the D-STAR output on PCM, against the model's records (enc stage) + columns n cls det trk tone b0 b1 out: + cls voice, tone, knox, or silence (a NULL frame) + det, trk, tone tone pipeline on the frame (T and level, empty when none): detection, after the + run rule, and the final tone after the tone-in-noise pass + b0, b1 the frame's first two fields (126 and -1 on tone frames, 124 and -1 on NULL frames) + --dual: both outputs enabled (the D-STAR output does not depend on it) */ + +static void wtone(dsref_writer *w, const xombe_ds_tone *t) +{ + float v[2]; + v[0] = (float)t->T; + v[1] = t->level; + dsref_wfv_float(w, v, t->on ? 2 : 0); +} + +int main(int argc, char **argv) +{ + static const char *cls_name[4] = {"voice", "silence", "tone", "knox"}; + static xombe_enc_mem mem; + xombe_enc_cfg cfg; + xombe_enc *e; + dsref_writer w; + int16_t pcm[XOMBE_FRAME]; + uint8_t d[9]; + long frames = 0, n = 0; + int dual = argc > 1 && !strcmp(argv[1], "--dual"); + FILE *in; + if (argc != 3 + dual) { + fprintf(stderr, "usage: dstar_dump_enc [--dual] IN.raw OUT\n"); + return 2; + } + in = fopen(argv[1 + dual], "rb"); + if (!in) { + perror(argv[1 + dual]); + return 1; + } + xombe_enc_cfg_default(&cfg); + cfg.outputs = XOMBE_ENC_DSTAR | (dual ? XOMBE_ENC_DMR : 0); + e = xombe_enc_init(&mem, &cfg); + if (!e || !dsref_wopen(&w, argv[2 + dual], "enc", "n:i cls:s det:f* trk:f* tone:f* b0:i b1:i out:x", 7)) + return 1; + for (;;) { + const xombe_ds_enc_frame *fr = &XOMBE_DS_ENC(e)->fr; + size_t k = fread(pcm, sizeof(pcm[0]), XOMBE_FRAME, in); + int got; + if (k > 0) { /* a partial last frame is zero-padded, as the model counts frames */ + memset(pcm + k, 0, (XOMBE_FRAME - k) * sizeof(pcm[0])); + frames++; + got = xombe_enc_frame(e, pcm, NULL, NULL, d); + } else if (n < frames) + got = xombe_enc_frame(e, NULL, NULL, NULL, d); + else + break; + if (!got) + continue; + dsref_wi(&w, n++); + dsref_ws(&w, cls_name[fr->cls]); + wtone(&w, &fr->det); + wtone(&w, &fr->trk); + wtone(&w, &fr->tone); + dsref_wi(&w, fr->cls == XOMBE_DS_CLS_TONE ? 126 : fr->cls == XOMBE_DS_CLS_NULL ? 124 : fr->b0); + dsref_wi(&w, fr->cls == XOMBE_DS_CLS_VOICE ? fr->b1 : fr->cls == XOMBE_DS_CLS_KNOX ? 15 : -1); + dsref_wx(&w, d, 9); + dsref_wend(&w); + } + fclose(in); + return dsref_wclose(&w) ? 0 : 1; +} diff --git a/xombe/test/dstar_dump_enc_be.c b/xombe/test/dstar_dump_enc_be.c new file mode 100644 index 0000000..e1c9d19 --- /dev/null +++ b/xombe/test/dstar_dump_enc_be.c @@ -0,0 +1,246 @@ +#define _POSIX_C_SOURCE 200112L +#include +#include +#include +#include +#include +#include "../src/state.h" +#include "../src/dstar/dstar_enc.h" +#include "dstar_ref.h" +#if defined(XOMBE_CALLGRIND) +#include +#endif + +/* D-STAR encoder back end (src/dstar/dstar_enc.c) on the model's recorded inputs (enc stage): + dstar_dump_enc_be C.enc.txt.gz OUT n cls b0t mn b1 b out + b0t xombe__ds_b0_from_f0(1/Pr) of the recorded refined period + mn xombe__ds_m_noise(N, b0t) of the recorded window and pitch + b1 xombe__ds_b1_search of the recorded a and w + b the recorded targets at, b0 and b1 quantized against the mirror run over the stream (xombe__ds_enc_amps; + the mirror commits these fields, Knox frames commit their recorded fields, tone and NULL frames skip) + out the 9 bytes of b + dstar_dump_enc_be --spec C.enc.txt.gz OUT n cls mv w a b1 + the voicing on the C front end's spectrum: C.in.raw through the input high-pass, spectrum at window N centred + on 160n + 120, the metric and weights at the recorded b0t's f0, a with the recorded second-half VAD + decision (the VAD gate), b1 from those + non-voice frames are written with the reference's values, so rows stay matched + --bench REPS: (default mode) time xombe__ds_enc_amps over the stream REPS times, best to stderr, with + -DXOMBE_CALLGRIND the voice frames run between CALLGRIND_START/STOP_INSTRUMENTATION */ + +#define MAXF 20000 +#define HPF_GAIN 0.9427f /* must match INPUT_HPF_GAIN in enc/encoder.c */ +#define PAD 400 + +typedef struct { + int n, voice, knox, N, b0t, b0, b1, L, vad2; + char cls[8]; + float Pr, a[8], w[8], mn[8], at[XOMBE_LMAX + 1]; + int b[9]; + uint8_t out[9]; +} rec; + +static rec R[MAXF]; +static int nrec; + +static int load(const char *path) +{ + dsref r; + int st; + if (!dsref_open(&r, path)) + return 0; + int c_n = dsref_need(&r, "n", DSREF_INT), c_cls = dsref_need(&r, "cls", DSREF_STR), + c_N = dsref_need(&r, "N", DSREF_INT), c_Pr = dsref_need(&r, "Pr", DSREF_FLOAT), + c_b0t = dsref_need(&r, "b0t", DSREF_INT), c_b0 = dsref_need(&r, "b0", DSREF_INT), + c_L = dsref_need(&r, "L", DSREF_INT), c_w = dsref_need(&r, "w", DSREF_FVEC), + c_mn = dsref_need(&r, "mn", DSREF_FVEC), c_a = dsref_need(&r, "a", DSREF_FVEC), + c_b1 = dsref_need(&r, "b1", DSREF_INT), c_at = dsref_need(&r, "at", DSREF_FVEC), + c_b = dsref_need(&r, "b", DSREF_IVEC), c_out = dsref_need(&r, "out", DSREF_HEX), + c_vad2 = dsref_need(&r, "vad2", DSREF_INT); + while ((st = dsref_next(&r)) > 0 && nrec < MAXF) { + rec *q = &R[nrec++]; + int j; + memset(q, 0, sizeof(*q)); + q->n = (int)dsref_i(&r, c_n); + snprintf(q->cls, sizeof(q->cls), "%s", dsref_s(&r, c_cls)); + q->voice = !strcmp(q->cls, "voice"); + q->knox = !strcmp(q->cls, "knox"); + q->N = (int)dsref_i(&r, c_N); + q->Pr = (float)dsref_f(&r, c_Pr); + q->b0t = (int)dsref_i(&r, c_b0t); + q->b0 = (int)dsref_i(&r, c_b0); + q->b1 = (int)dsref_i(&r, c_b1); + q->L = (int)dsref_i(&r, c_L); + q->vad2 = (int)dsref_i(&r, c_vad2); + if (q->voice) { + if (dsref_len(&r, c_a) != 8 || dsref_len(&r, c_w) != 8 || dsref_len(&r, c_mn) != 8 || + dsref_len(&r, c_at) != q->L) { + fprintf(stderr, "%s: frame %d: bad vector lengths\n", path, q->n); + return 0; + } + for (j = 0; j < 8; j++) { + q->a[j] = (float)dsref_fv(&r, c_a)[j]; + q->w[j] = (float)dsref_fv(&r, c_w)[j]; + q->mn[j] = (float)dsref_fv(&r, c_mn)[j]; + } + for (j = 0; j < q->L; j++) + q->at[j + 1] = (float)dsref_fv(&r, c_at)[j]; + } + for (j = 0; j < dsref_len(&r, c_b) && j < 9; j++) + q->b[j] = (int)dsref_iv(&r, c_b)[j]; + if (dsref_len(&r, c_out) == 9) + memcpy(q->out, dsref_bytes(&r, c_out), 9); + } + return dsref_close(&r) && st == 0; +} + +static xombe_ds_enc ds; + +static void run_amps(int b[][9]) +{ + int i; + xombe__ds_enc_reset(&ds); +#if defined(XOMBE_CALLGRIND) + CALLGRIND_START_INSTRUMENTATION; +#endif + for (i = 0; i < nrec; i++) { + rec *q = &R[i]; + if (q->voice) + xombe__ds_enc_amps(&ds, q->b0, q->b1, q->at, b[i]); + else if (q->knox) + xombe__ds_mirror_commit(&ds.mirror, q->b, NULL); + } +#if defined(XOMBE_CALLGRIND) + CALLGRIND_STOP_INSTRUMENTATION; +#endif +} + +static int dump_exact(const char *out, int bench) +{ + static int b[MAXF][9]; + dsref_writer w; + int i, j; + run_amps(b); + if (!dsref_wopen(&w, out, "enc", "n:i cls:s b0t:i mn:f* b1:i b:i* out:x", 7)) + return 1; + for (i = 0; i < nrec; i++) { + rec *q = &R[i]; + dsref_wi(&w, q->n); + dsref_ws(&w, q->cls); + if (q->voice) { + float mn[8]; + uint8_t o[9]; + xombe__ds_m_noise(q->N, q->b0t, mn); + dsref_wi(&w, xombe__ds_b0_from_f0(1.0f / q->Pr)); + dsref_wfv_float(&w, mn, 8); + dsref_wi(&w, xombe__ds_b1_search(q->a, q->w)); + dsref_wiv_int(&w, b[i], 9); + xombe__ds_encode_fields(b[i], o); + dsref_wx(&w, o, 9); + } else { + long bl[9]; + int nb = q->b[0] >= 124 && !q->knox ? 1 : 9; + for (j = 0; j < nb; j++) + bl[j] = q->b[j]; + dsref_wi(&w, q->b0t); + dsref_wfv_float(&w, q->mn, 0); + dsref_wi(&w, q->b1); + dsref_wiv(&w, bl, nb); + dsref_wx(&w, q->out, 9); + } + dsref_wend(&w); + } + if (bench > 0) { + double best = 1e30; + int k, nv = 0; + for (i = 0; i < nrec; i++) + nv += R[i].voice; + for (k = 0; k < bench; k++) { + struct timespec t0, t1; + double dt; + clock_gettime(CLOCK_MONOTONIC, &t0); + run_amps(b); + clock_gettime(CLOCK_MONOTONIC, &t1); + dt = (double)(t1.tv_sec - t0.tv_sec) + 1e-9 * (double)(t1.tv_nsec - t0.tv_nsec); + if (dt < best) + best = dt; + } + fprintf(stderr, "amps: %d voice frames, %.1f us per frame\n", nv, 1e6 * best / (nv ? nv : 1)); + } + return dsref_wclose(&w) ? 0 : 1; +} + +static int dump_spec(const char *encpath, const char *out) +{ + static unsigned char mem[XOMBE_ENC_SIZE]; + static xombe_spec S; + char pcmpath[1024]; + size_t n = strlen(encpath); + long ns, i; + int16_t *x; + float *xh; + xombe_hpf hpf; + xombe_enc *e = xombe_enc_init(mem, NULL); + dsref_writer w; + if (n < 11 || strcmp(encpath + n - 11, ".enc.txt.gz") || n > sizeof(pcmpath) - 8) { + fprintf(stderr, "%s: expected C.enc.txt.gz\n", encpath); + return 1; + } + memcpy(pcmpath, encpath, n - 11); + strcpy(pcmpath + n - 11, ".in.raw"); + if (!(x = dsref_read_pcm(pcmpath, &ns))) + return 1; + xh = calloc((size_t)(ns + 2 * PAD + 160), sizeof(float)); + xombe__hpf_init(&hpf, HPF_GAIN); + for (i = 0; i < ns; i++) + xh[PAD + i] = xombe__hpf_step(&hpf, (float)x[i]); + for (; i < ns + PAD + 160; i++) + xh[PAD + i] = xombe__hpf_step(&hpf, 0.0f); + if (!dsref_wopen(&w, out, "enc", "n:i cls:s mv:f* w:f* a:f* b1:i", 7)) + return 1; + for (i = 0; i < nrec; i++) { + rec *q = &R[i]; + dsref_wi(&w, q->n); + dsref_ws(&w, q->cls); + if (q->voice) { + float m[8], wv[8], mn[8], a[8], f0 = xombe__ds_f0(q->b0t); + xombe__enc_set_window(e, q->N); + xombe__kern_spectrum(xh + PAD + 160 * q->n + 120, e->win, q->N, &S); + xombe__voicing_metric(e, &S, f0, m, wv); + xombe__ds_m_noise(q->N, q->b0t, mn); + xombe__ds_soft(m, mn, XOMBE_DS_S_VN, q->vad2, a); + dsref_wfv_float(&w, m, 8); + dsref_wfv_float(&w, wv, 8); + dsref_wfv_float(&w, a, 8); + dsref_wi(&w, xombe__ds_b1_search(a, wv)); + } else { + dsref_wfv_float(&w, NULL, 0); + dsref_wfv_float(&w, NULL, 0); + dsref_wfv_float(&w, NULL, 0); + dsref_wi(&w, q->b1); + } + dsref_wend(&w); + } + free(x); + free(xh); + return dsref_wclose(&w) ? 0 : 1; +} + +int main(int argc, char **argv) +{ + int spec = 0, bench = 0, i = 1; + for (; i < argc && !strncmp(argv[i], "--", 2); i++) { + if (!strcmp(argv[i], "--spec")) + spec = 1; + else if (!strcmp(argv[i], "--bench") && i + 1 < argc) + bench = atoi(argv[++i]); + else + break; + } + if (argc - i != 2) { + fprintf(stderr, "usage: dstar_dump_enc_be [--spec] [--bench REPS] C.enc.txt.gz OUT\n"); + return 2; + } + if (!load(argv[i])) + return 1; + return spec ? dump_spec(argv[i], argv[i + 1]) : dump_exact(argv[i + 1], bench); +} diff --git a/xombe/test/dstar_dump_fec.c b/xombe/test/dstar_dump_fec.c new file mode 100644 index 0000000..e59fb83 --- /dev/null +++ b/xombe/test/dstar_dump_fec.c @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include "../src/dstar/dstar_internal.h" +#include "dstar_ref.h" + +/* D-STAR FEC and fields (stage 'fec'): every frame of a stream with the error rule 'ds', --enc re-encodes the + fields and tone cases of a fec_enc file, --ids prints "n class toneid" per frame, toneid -1 if none (conformance) */ + +static const char *class_name(const xombe_ds_frame *f) +{ + switch (f->cls) { + case XOMBE_DS_VOICE: return "voice"; + case XOMBE_DS_TONE: return "tone"; + default: return f->b[0] == 124 ? "null124" : f->b[0] == 125 ? "null125" : "null127"; + } +} + +static int dump_stream(const char *in, const char *out) +{ + long n, nf; + uint8_t *fr = dsref_read_frames(in, 9, &nf), enc[9]; + dsref_writer w; + xombe_ds_err er; + int k, ok; + if (!fr) + return 1; + if (!dsref_wopen(&w, out, "fec", + "n:i in:x A:i B:i C:i pn:i da:i ea:i db:i eb:i d48:b b0:i b1:i b2:i b3:i b4:i b5:i b6:i b7:i " + "b8:i cls:s T:i AD:i bf:i hb:i eT:i e1:i enc:x", 0)) { + free(fr); + return 1; + } + xombe__ds_err_init(&er); + for (n = 0; n < nf; n++) { + xombe_ds_frame f; + xombe_ds_flags fl; + xombe__ds_fec_decode(fr + 9 * n, &f); + xombe__ds_err_update(&er, f.ea, f.eb, &fl); + xombe__ds_encode_fields(f.b, enc); + dsref_wi(&w, n); + dsref_wx(&w, fr + 9 * n, 9); + dsref_wi(&w, (long)f.A); + dsref_wi(&w, (long)f.B); + dsref_wi(&w, (long)f.C); + dsref_wi(&w, (long)f.pn); + dsref_wi(&w, f.da); + dsref_wi(&w, f.ea); + dsref_wi(&w, f.db); + dsref_wi(&w, f.eb); + dsref_wb(&w, f.d, 48); + for (k = 0; k < 9; k++) + dsref_wi(&w, f.b[k]); + dsref_ws(&w, class_name(&f)); + dsref_wi(&w, f.T); + dsref_wi(&w, f.AD); + dsref_wi(&w, fl.bf); + dsref_wi(&w, fl.hb); + dsref_wi(&w, fl.eT); + dsref_wi(&w, fl.e1); + dsref_wx(&w, enc, 9); + dsref_wend(&w); + } + free(fr); + ok = dsref_wclose(&w); + return ok ? 0 : 1; +} + +static int dump_enc(const char *in, const char *out) +{ + dsref r; + dsref_writer w; + int c_kind, c_b, c_T, c_level, st, k, ok; + if (!dsref_open(&r, in)) + return 1; + c_kind = dsref_need(&r, "kind", DSREF_STR); + c_b = dsref_need(&r, "b", DSREF_IVEC); + c_T = dsref_need(&r, "T", DSREF_INT); + c_level = dsref_need(&r, "level", DSREF_FLOAT); + if (c_kind < 0 || c_b < 0 || c_T < 0 || c_level < 0 || + !dsref_wopen(&w, out, "fec_enc", "kind:s b:i* T:i level:f d48:b out:x", 0)) { + dsref_close(&r); + return 1; + } + while ((st = dsref_next(&r)) > 0) { + uint8_t d[48], o[9]; + int b[9]; + if (!strcmp(dsref_s(&r, c_kind), "tone")) { + int T = (int)dsref_i(&r, c_T); + xombe__ds_tone_bits(T, xombe__ds_tone_q((float)dsref_f(&r, c_level)), d); + xombe__ds_tone_frame(T, xombe__ds_tone_q((float)dsref_f(&r, c_level)), o); + xombe__ds_get_fields(d, b); + } else { + if (dsref_len(&r, c_b) != 9) { + fprintf(stderr, "%s: b needs 9 fields\n", in); + st = -1; + break; + } + for (k = 0; k < 9; k++) + b[k] = (int)dsref_iv(&r, c_b)[k]; + xombe__ds_put_fields(b, d); + if (xombe__ds_encode_fields(b, o) != 0) { + fprintf(stderr, "%s: field out of range\n", in); + st = -1; + break; + } + } + dsref_ws(&w, dsref_s(&r, c_kind)); + dsref_wiv_int(&w, b, 9); + dsref_wi(&w, dsref_i(&r, c_T)); + dsref_wf(&w, dsref_f(&r, c_level)); + dsref_wb(&w, d, 48); + dsref_wx(&w, o, 9); + dsref_wend(&w); + } + ok = dsref_close(&r) && st == 0; + ok &= dsref_wclose(&w); + return ok ? 0 : 1; +} + +static int dump_ids(const char *in) +{ + long n, nf; + uint8_t *fr = dsref_read_frames(in, 9, &nf); + if (!fr) + return 1; + for (n = 0; n < nf; n++) { + xombe_ds_frame f; + xombe__ds_fec_decode(fr + 9 * n, &f); + printf("%ld %s %d\n", n, class_name(&f), f.tid); + } + free(fr); + return 0; +} + +int main(int argc, char **argv) +{ + if (argc == 3 && !strcmp(argv[1], "--ids")) + return dump_ids(argv[2]); + if (argc == 4 && !strcmp(argv[1], "--enc")) + return dump_enc(argv[2], argv[3]); + if (argc == 3) + return dump_stream(argv[1], argv[2]); + fprintf(stderr, "usage: dstar_dump_fec IN.dstar OUT | --enc fec_enc.txt.gz OUT | --ids IN.dstar\n"); + return 2; +} diff --git a/xombe/test/dstar_dump_quant.c b/xombe/test/dstar_dump_quant.c new file mode 100644 index 0000000..45bcaa9 --- /dev/null +++ b/xombe/test/dstar_dump_quant.c @@ -0,0 +1,397 @@ +#define _POSIX_C_SOURCE 200112L +#include +#include +#include +#include +#include +#include "../src/common/cquant.h" +#include "../src/dstar/dstar_internal.h" +#include "dstar_ref.h" +#if defined(XOMBE_CALLGRIND) +#include +#endif + +/* closed-loop quantizer against the reference quantizer cases: + dstar_dump_quant [options] closed quant_closed.txt.gz OUT (tset parent pass b err) + dstar_dump_quant [options] dstar quant_dstar.txt.gz OUT (id b ahat err) + dstar_dump_quant [options] ambe2 quant_ambe2.txt.gz OUT (id bopen bclosed pick b ahat err) + extra columns: errpy, the C error of the reference's fields (closed, dstar), for mismatch analysis, and w + (dstar, ambe2), recomputed with xombe__cq_amp_weights from the target and checked against the record + options: + --brute no pruning in the pair search + --bench REPS time the quantizer over every call after the dump, best of REPS, to stderr + --top N with --bench, the N slowest calls' ids + --ids a,b,... only these calls, with -DXOMBE_CALLGRIND a callgrind dump after each + --cap N dump the search capped at N, fail if a pair search exceeds max(N + 4, 132) units or the + summed error grows by more than --cap-tol REL (default 1e-3) against the exact search */ + +typedef struct { + int kind; /* 0 closed, 1 dstar, 2 ambe2 */ + int tset; /* closed: 0 dstar, 1 ambe2 */ + long id, pass; + int L, n_pairs, n_gain, iters, clip_passes, has_w, mode_closed; + float Gprev; + float r[XOMBE_LMAX + 1], target[XOMBE_LMAX + 1], base[XOMBE_LMAX + 1], w[XOMBE_LMAX + 1]; + int Lp; + float ap[XOMBE_LMAX + 1]; + int bref[9]; +} qcall; + +typedef struct { + xombe_cq_result res; + int pick, bopen[9], bclosed[9]; + float ahat[XOMBE_LMAX + 1], err, errpy; +} qout; + +static xombe_cq_ws ws; +static int brute, qcap; + +static void fill(float *dst, const double *src, int n) +{ + int i; + dst[0] = 0.0f; + for (i = 0; i < n; i++) + dst[i + 1] = (float)src[i]; +} + +static const xombe_amp_tables *set_of(const qcall *c) +{ + return c->kind == 1 || (c->kind == 0 && c->tset == 0) ? &xombe__amp_dstar : &xombe__amp_ambe2; +} + +/* decoder's reconstruction of fields b against the memory */ +static void recon(const qcall *c, const int b[9], float *a) +{ + const xombe_amp_tables *ts = set_of(c); + float t[XOMBE_LMAX + 1], pt[XOMBE_LMAX + 1]; + xombe__predict_from(c->Lp, c->ap, c->L, pt); + xombe__spectral_shape_ts(ts, b, c->L, t); + xombe__assemble_ts(ts, t, pt, c->L, xombe__gain_ts(ts, b[2], c->Gprev), a); +} + +static float werr(const qcall *c, const float *a, float amax) +{ + float e = 0.0f; + int l; + for (l = 1; l <= c->L; l++) { + float t = c->target[l] < -15.0f ? -15.0f : c->target[l] > amax ? amax : c->target[l]; + float d = a[l] - t; + e += (c->has_w ? c->w[l] : 1.0f) * d * d; + } + return e; +} + +/* search's clipped error of fields b on a prepared workspace */ +static float closed_err(const qcall *c, const int b[9]) +{ + const xombe_amp_tables *ts = set_of(c); + float t[XOMBE_LMAX + 1], mt = 0.0f, G = xombe__gain_ts(ts, b[2], c->Gprev), e = 0.0f; + int l; + xombe__spectral_shape_ts(ts, b, c->L, t); + for (l = 1; l <= c->L; l++) + mt += t[l]; + mt /= (float)c->L; + for (l = 1; l <= c->L; l++) { + float a = t[l] - mt + c->base[l] + G, d; + a = a < -15.0f ? -15.0f : a > XOMBE_CQ_AMAX ? XOMBE_CQ_AMAX : a; + d = a - c->target[l]; + e += (c->has_w ? c->w[l] : 1.0f) * d * d; + } + return e; +} + +static void run(const qcall *c, qout *o) +{ + const float *w = c->has_w ? c->w : NULL; + ws.brute = brute; + ws.cap = qcap; + if (c->kind == 0) { + xombe__cq_prepare(&ws, set_of(c), c->L, w); + xombe__cq_closed(&ws, c->r, c->target, c->base, c->Gprev, c->n_pairs, c->n_gain, c->iters, &o->res); + } else if (c->kind == 1) { + float pt[XOMBE_LMAX + 1]; + xombe__predict_from(c->Lp, c->ap, c->L, pt); + xombe__cq_quantize(&ws, &xombe__amp_dstar, c->target, c->L, pt, c->Gprev, w, c->mode_closed, c->n_pairs, + c->n_gain, c->iters, c->clip_passes, &o->res); + } else { + xombe_pred pi; + xombe__pred_init(&pi); + pi.L = c->Lp; + pi.gamma = c->Gprev; + memcpy(pi.a, c->ap, sizeof(pi.a)); + o->pick = xombe__cq_search_ambe2(&ws, &pi, c->target, c->L, w, c->n_pairs, c->n_gain, &o->res, o->bclosed, + o->bopen); + } +} + +static int cmp_double(const void *a, const void *b) +{ + double x = *(const double *)a, y = *(const double *)b; + return x < y ? -1 : x > y; +} + +static double now(void) +{ + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); + return t.tv_sec + 1e-9 * t.tv_nsec; +} + +static int in_ids(const char *ids, long id) +{ + const char *p = ids; + while (p && *p) { + char *e; + long v = strtol(p, &e, 10); + if (e == p) + break; + if (v == id) + return 1; + p = *e == ',' ? e + 1 : e; + } + return 0; +} + +int main(int argc, char **argv) +{ + static const char *cols[3] = { + "tset:s parent:i pass:i b:i* err:f errpy:f", + "id:i w:f* b:i* ahat:f* err:f errpy:f", + "id:i w:f* bopen:i* bclosed:i* pick:s b:i* ahat:f* err:f"}; + const char *ids = NULL; + int kind, reps = 0, ntop = 0, ai = 1, st, ok = 1, worst = 0, nchg = 0; + long n = 0, cap = 0, i; + double e_exact = 0.0, e_cap = 0.0, cap_tol = 1e-3; + qcall *calls = NULL; + dsref r; + dsref_writer wr; + while (ai < argc && argv[ai][0] == '-') { + if (!strcmp(argv[ai], "--brute")) + brute = 1; + else if (!strcmp(argv[ai], "--bench") && ai + 1 < argc) + reps = atoi(argv[++ai]); + else if (!strcmp(argv[ai], "--top") && ai + 1 < argc) + ntop = atoi(argv[++ai]); + else if (!strcmp(argv[ai], "--ids") && ai + 1 < argc) + ids = argv[++ai]; + else if (!strcmp(argv[ai], "--cap") && ai + 1 < argc) + qcap = atoi(argv[++ai]); + else if (!strcmp(argv[ai], "--cap-tol") && ai + 1 < argc) + cap_tol = atof(argv[++ai]); + else + break; + ai++; + } + if (argc - ai != 3) { + fprintf(stderr, "usage: dstar_dump_quant [--brute] [--bench REPS [--top N]] [--ids a,b] [--cap N [--cap-tol REL]] " + "closed|dstar|ambe2 IN OUT\n"); + return 2; + } + kind = !strcmp(argv[ai], "closed") ? 0 : !strcmp(argv[ai], "dstar") ? 1 : !strcmp(argv[ai], "ambe2") ? 2 : -1; + if (kind < 0 || !dsref_open(&r, argv[ai + 1])) + return 2; + { + int c_L = dsref_need(&r, "L", DSREF_INT), c_np = dsref_need(&r, "n_pairs", DSREF_INT); + int c_ng = dsref_need(&r, "n_gain", DSREF_INT), c_t = dsref_need(&r, "target", DSREF_FVEC); + int c_w = dsref_need(&r, "w", DSREF_FVEC), c_b = dsref_need(&r, "b", DSREF_IVEC); + int c_id = dsref_need(&r, kind == 0 ? "parent" : "id", DSREF_INT); + int c_ts = -1, c_pass = -1, c_it = -1, c_G = -1, c_r = -1, c_base = -1, c_cp = -1, c_mode = -1; + int c_Lp = -1, c_ap = -1; + if (kind == 0) { + c_ts = dsref_need(&r, "tset", DSREF_STR); + c_pass = dsref_need(&r, "pass", DSREF_INT); + c_it = dsref_need(&r, "iters", DSREF_INT); + c_G = dsref_need(&r, "Gprev", DSREF_FLOAT); + c_r = dsref_need(&r, "r", DSREF_FVEC); + c_base = dsref_need(&r, "base", DSREF_FVEC); + } else if (kind == 1) { + c_it = dsref_need(&r, "iters", DSREF_INT); + c_cp = dsref_need(&r, "clip_passes", DSREF_INT); + c_mode = dsref_need(&r, "mode", DSREF_STR); + c_G = dsref_need(&r, "stG", DSREF_FLOAT); + c_Lp = dsref_need(&r, "stL", DSREF_INT); + c_ap = dsref_need(&r, "sta", DSREF_FVEC); + } else { + c_mode = dsref_need(&r, "mode", DSREF_STR); + c_G = dsref_need(&r, "piG", DSREF_FLOAT); + c_Lp = dsref_need(&r, "piL", DSREF_INT); + c_ap = dsref_need(&r, "pia", DSREF_FVEC); + } + while ((st = dsref_next(&r)) > 0) { + qcall *c; + int k, L; + if (ids && !in_ids(ids, dsref_i(&r, c_id))) + continue; + if (n == cap) { + cap = cap ? 2 * cap : 1024; + calls = realloc(calls, cap * sizeof(*calls)); + if (!calls) + return 2; + } + c = &calls[n++]; + memset(c, 0, sizeof(*c)); + c->kind = kind; + c->id = dsref_i(&r, c_id); + c->L = L = (int)dsref_i(&r, c_L); + c->n_pairs = (int)dsref_i(&r, c_np); + c->n_gain = (int)dsref_i(&r, c_ng); + c->iters = c_it >= 0 ? (int)dsref_i(&r, c_it) : 2; + c->clip_passes = c_cp >= 0 ? (int)dsref_i(&r, c_cp) : 0; + c->mode_closed = c_mode < 0 || !strcmp(dsref_s(&r, c_mode), "closed"); + c->Gprev = (float)dsref_f(&r, c_G); + fill(c->target, dsref_fv(&r, c_t), L); + c->has_w = dsref_len(&r, c_w) > 0; + if (c->has_w) + fill(c->w, dsref_fv(&r, c_w), L); + for (k = 0; k < 7; k++) + c->bref[2 + k] = (int)dsref_iv(&r, c_b)[k]; + if (kind == 0) { + c->tset = strcmp(dsref_s(&r, c_ts), "dstar") ? 1 : 0; + c->pass = dsref_i(&r, c_pass); + fill(c->r, dsref_fv(&r, c_r), L); + fill(c->base, dsref_fv(&r, c_base), L); + } else { + int la = dsref_len(&r, c_ap), l; + c->Lp = (int)dsref_i(&r, c_Lp); + fill(c->ap, dsref_fv(&r, c_ap), la); + for (l = la + 1; l <= XOMBE_LMAX; l++) + c->ap[l] = c->ap[la]; + } + if (c->L < 1 || c->L > XOMBE_LMAX || c->n_pairs > XOMBE_CQ_MAX_PAIRS || c->n_gain > XOMBE_CQ_MAX_GAIN) { + fprintf(stderr, "dstar_dump_quant: bad call %ld\n", c->id); + return 2; + } + } + } + if (!dsref_close(&r) || st < 0) + return 2; + if (!dsref_wopen(&wr, argv[ai + 2], argv[ai], cols[kind], 9)) + return 2; + for (i = 0; i < n; i++) { + const qcall *c = &calls[i]; + qout o; + float a[XOMBE_LMAX + 1]; +#if defined(XOMBE_CALLGRIND) + CALLGRIND_TOGGLE_COLLECT; +#endif + run(c, &o); +#if defined(XOMBE_CALLGRIND) + CALLGRIND_TOGGLE_COLLECT; + if (ids) + CALLGRIND_DUMP_STATS; +#endif + if (qcap > 0) { + qout x; + int k, d = 0, cq; + if (ws.work > worst) + worst = ws.work; + cq = qcap; + qcap = 0; + run(c, &x); + qcap = cq; + for (k = 2; k < 9; k++) + d |= x.res.b[k] != o.res.b[k]; + nchg += d; + e_exact += x.res.err; + e_cap += o.res.err; + } + if (kind == 0) { + dsref_ws(&wr, c->tset ? "ambe2" : "dstar"); + dsref_wi(&wr, c->id); + dsref_wi(&wr, c->pass); + dsref_wiv_int(&wr, o.res.b + 2, 7); + dsref_wf(&wr, o.res.err); + dsref_wf(&wr, closed_err(c, c->bref)); + } else { + recon(c, o.res.b, a); + dsref_wi(&wr, c->id); + if (c->has_w) { /* amp_weights(target, 0.5) against the recorded weights */ + float wc[XOMBE_LMAX + 1]; + xombe__cq_amp_weights(c->target, c->L, XOMBE_CQ_QWEIGHT, XOMBE_CQ_WEIGHT_FLOOR, wc); + dsref_wfv_float(&wr, wc + 1, c->L); + } else + dsref_wfv_float(&wr, NULL, 0); + if (kind == 2) { + dsref_wiv_int(&wr, o.bopen + 2, 7); + dsref_wiv_int(&wr, o.bclosed + 2, 7); + dsref_ws(&wr, o.pick ? "open" : "closed"); + } + dsref_wiv_int(&wr, o.res.b + 2, 7); + dsref_wfv_float(&wr, a + 1, c->L); + dsref_wf(&wr, werr(c, a, kind == 1 ? XOMBE_DS_AMP_MAX : XOMBE_AMP_MAX)); + if (kind == 1) { + recon(c, c->bref, a); + dsref_wf(&wr, werr(c, a, XOMBE_DS_AMP_MAX)); + } + } + dsref_wend(&wr); + } + ok = dsref_wclose(&wr); + if (qcap > 0) { + int bound = qcap + 4 > 132 ? qcap + 4 : 132; + fprintf(stderr, "cap %d: %d of %ld calls changed, error %+.4f%%, most units in a search %d (bound %d)\n", qcap, + nchg, n, 100.0 * (e_cap / e_exact - 1.0), worst, bound); + if (worst > bound || e_cap > (1.0 + cap_tol) * e_exact) + ok = 0; + } + if (reps > 0 && n > 0) { + double best = 1e30, *ct = malloc(n * sizeof(double)); + int rep; + for (i = 0; i < n; i++) + ct[i] = 1e30; + for (rep = 0; rep < reps; rep++) { + double t0 = now(), t1; + for (i = 0; i < n; i++) { + qout o; + double s = ntop ? now() : 0.0; + run(&calls[i], &o); + if (ntop) { + double d = now() - s; + if (d < ct[i]) + ct[i] = d; + } + } + t1 = now() - t0; + if (t1 < best) + best = t1; + } + fprintf(stderr, "bench %s: %ld calls, best of %d: %.3f us/call\n", argv[ai], n, reps, 1e6 * best / n); + if (ntop) { + /* per-call distribution (each call's best time) */ + double *sorted = malloc(n * sizeof(double)); + static const double pc[5] = {0.5, 0.9, 0.99, 0.999, 1.0}; + int p; + memcpy(sorted, ct, n * sizeof(double)); + qsort(sorted, n, sizeof(double), cmp_double); + fprintf(stderr, " per call (us):"); + for (p = 0; p < 5; p++) { + long k = (long)(pc[p] * (n - 1) + 0.5); + fprintf(stderr, " p%g %.2f", 100.0 * pc[p], 1e6 * sorted[k]); + } + fprintf(stderr, "\n"); + free(sorted); + } + for (rep = 0; rep < ntop; rep++) { + long m = -1; + for (i = 0; i < n; i++) + if (ct[i] >= 0 && (m < 0 || ct[i] > ct[m])) + m = i; + if (m < 0) + break; + fprintf(stderr, " slow: id %ld pass %ld L %d %.2f us\n", calls[m].id, calls[m].pass, calls[m].L, + 1e6 * ct[m]); + ct[m] = -1.0; + } + free(ct); + } + free(calls); +#ifdef XOMBE_CQ_STATS + { + extern long xombe__cq_stat[4]; + double n = (double)xombe__cq_stat[0]; + fprintf(stderr, "stats: %ld pair searches, %.1f rows, %.1f pairs, and %.1f columns per search\n", + xombe__cq_stat[0], xombe__cq_stat[1] / n, xombe__cq_stat[2] / n, xombe__cq_stat[3] / n); + } +#endif + return ok ? 0 : 1; +} diff --git a/xombe/test/dstar_dump_xc.c b/xombe/test/dstar_dump_xc.c new file mode 100644 index 0000000..f8e8b48 --- /dev/null +++ b/xombe/test/dstar_dump_xc.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include "../src/internal.h" +#include "../src/dstar/xc_state.h" +#include "../src/dstar/trace.h" +#include "dstar_ref.h" + +/* the rate-33 -> D-STAR transcoder's records (stage 'xc') */ + +static const char *cls_name(int c) +{ + return c == XOMBE_CLASS_VOICE ? "voice" : c == XOMBE_CLASS_SILENCE ? "silence" : c == XOMBE_CLASS_TONE ? "tone" : "?"; +} + +static void bits8(dsref_writer *w, const uint8_t *v, int on) +{ + dsref_wb(w, v, on ? 8 : 0); +} + +int main(int argc, char **argv) +{ + long n, nf; + uint8_t *fr; + dsref_writer w; + xombe_xc_mem mem; + xombe_xc_trace tr; + xombe_xc *x; + int ok; + if (argc != 3) { + fprintf(stderr, "usage: dstar_dump_xc IN.r33 OUT\n"); + return 2; + } + if (!(fr = dsref_read_frames(argv[1], 9, &nf))) + return 1; + ok = dsref_wopen(&w, argv[2], "xc", + "n:i in:x e0:i e1:i cls:s cls_out:s rb:i* f0:f L:i a:f* V2:b V1:b G:f pulse:i tid:i AD:i " + "soft:f* tgt:f* tb0:i b:i* out:x", 7); + if (!ok) { + free(fr); + return 1; + } + x = xombe_xc_init(&mem, XOMBE_DMR); + x->u.f.trace = &tr; + for (n = 0; n < nf && ok; n++) { + uint8_t out[9]; + xombe_xc_decision dc; + xombe_xc_frame(x, fr + 9 * n, 0, out); + xombe_xc_decision_get(x, &dc); + dsref_wi(&w, n); + dsref_wx(&w, fr + 9 * n, 9); + dsref_wi(&w, dc.in.e0); + dsref_wi(&w, dc.in.e1); + dsref_ws(&w, tr.conceal == XOMBE_CONCEAL_REPEAT ? "repeat" + : tr.conceal == XOMBE_CONCEAL_MUTE ? "mute" : cls_name(tr.cls)); + dsref_ws(&w, cls_name(tr.cls_out)); + dsref_wiv_int(&w, tr.rb, tr.has_rb ? 9 : 0); + dsref_wf(&w, tr.has_par ? tr.f0 : NAN); + dsref_wi(&w, tr.has_par ? tr.L : 0); + dsref_wfv_float(&w, tr.a + 1, tr.has_par ? tr.L : 0); + bits8(&w, tr.V2, tr.has_par); + bits8(&w, tr.V1, tr.has_v1); + dsref_wf(&w, tr.has_v1 ? tr.G : NAN); + dsref_wi(&w, tr.pulse); + dsref_wi(&w, tr.tid); + dsref_wi(&w, tr.AD); + dsref_wfv_float(&w, tr.soft, tr.has_soft ? 4 : 0); + dsref_wfv_float(&w, tr.tgt + 1, tr.tb0 >= 0 ? tr.tL : 0); + dsref_wi(&w, tr.tb0); + dsref_wiv_int(&w, tr.b, tr.has_b ? 9 : 0); + dsref_wx(&w, out, 9); + dsref_wend(&w); + } + free(fr); + ok &= dsref_wclose(&w); + return ok ? 0 : 1; +} diff --git a/xombe/test/dstar_dump_xrev.c b/xombe/test/dstar_dump_xrev.c new file mode 100644 index 0000000..e02cbb2 --- /dev/null +++ b/xombe/test/dstar_dump_xrev.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include "../src/internal.h" +#include "../src/dstar/xc_state.h" +#include "../src/dstar/trace.h" +#include "dstar_ref.h" + +/* the D-STAR -> rate-33 transcoder's records (stage 'xrev'), exact quantizer search (ws->cap 0) unless --capped + keeps the transcoder's XOMBE_CQ_CAP */ + +static const char *cls_name(int c) +{ + return c == XOMBE_CLASS_VOICE ? "voice" : c == XOMBE_CLASS_SILENCE ? "silence" : c == XOMBE_CLASS_TONE ? "tone" : "?"; +} + +int main(int argc, char **argv) +{ + static const char *const in_cls[] = {"voice", "tone", "null", "repeat", "mute"}; + static const char *const ocls[] = {"voice", "pulse", "tone", "knox", "silence", "resend"}; /* enum xombe_xc_out */ + static xombe_xc_mem mem; + long n, nf; + uint8_t *fr; + dsref_writer w; + xombe_xr_trace tr; + xombe_xc *x; + int ok, capped = argc == 4 && !strcmp(argv[1], "--capped"); + if (argc != 3 + capped) { + fprintf(stderr, "usage: dstar_dump_xrev [--capped] IN.dstar OUT\n"); + return 2; + } + argv += capped; + if (!(fr = dsref_read_frames(argv[1], 9, &nf))) + return 1; + ok = dsref_wopen(&w, argv[2], "xrev", + "n:i in:x ea:i eb:i cls:s scls:s db:i* f0:f L:i a:f* ocls:s tid:i AD:i tgt:f* b:i* d49:b out:x", + 7); + if (!ok) { + free(fr); + return 1; + } + x = xombe_xc_init(&mem, XOMBE_DSTAR); + x->u.r.trace = &tr; + if (!capped) + x->u.r.ws->cap = 0; + for (n = 0; n < nf && ok; n++) { + uint8_t out[9]; + xombe_xc_decision dc; + xombe_xc_frame(x, fr + 9 * n, 0, out); + xombe_xc_decision_get(x, &dc); + dsref_wi(&w, n); + dsref_wx(&w, fr + 9 * n, 9); + dsref_wi(&w, dc.in.e0); + dsref_wi(&w, dc.in.e1); + dsref_ws(&w, in_cls[tr.in_cls]); + dsref_ws(&w, cls_name(tr.scls)); + dsref_wiv_int(&w, tr.db, tr.has_db ? 9 : 0); + dsref_wf(&w, tr.has_par ? tr.f0 : NAN); + dsref_wi(&w, tr.has_par ? tr.L : 0); + dsref_wfv_float(&w, tr.a + 1, tr.has_par ? tr.L : 0); + dsref_ws(&w, ocls[dc.out]); + dsref_wi(&w, tr.tid); + dsref_wi(&w, tr.AD); + dsref_wfv_float(&w, tr.tgt + 1, tr.tL); + dsref_wiv_int(&w, tr.b, tr.has_b ? 9 : 0); + dsref_wb(&w, tr.d49, 49); + dsref_wx(&w, out, 9); + dsref_wend(&w); + } + free(fr); + ok &= dsref_wclose(&w); + return ok ? 0 : 1; +} diff --git a/xombe/test/dstar_ref.c b/xombe/test/dstar_ref.c new file mode 100644 index 0000000..5d3ac34 --- /dev/null +++ b/xombe/test/dstar_ref.c @@ -0,0 +1,559 @@ +#define _POSIX_C_SOURCE 200809L +#include "dstar_ref.h" +#include +#include +#include +#include +#include +#include +#include +#include + +static void fail(dsref *r, const char *what) +{ + fprintf(stderr, "%s:%ld: %s\n", r->path, r->lineno, what); + r->failed = 1; +} + +static FILE *open_gzip(const char *path, long *pid_out) +{ + int fd[2]; + pid_t pid; + FILE *f; + if (pipe(fd)) + return NULL; + pid = fork(); + if (pid < 0) { + close(fd[0]); + close(fd[1]); + return NULL; + } + if (pid == 0) { + dup2(fd[1], STDOUT_FILENO); + close(fd[0]); + close(fd[1]); + execlp("gzip", "gzip", "-dc", "--", path, (char *)NULL); + _exit(127); + } + close(fd[1]); + f = fdopen(fd[0], "r"); + if (!f) { + close(fd[0]); + waitpid(pid, NULL, 0); + return NULL; + } + *pid_out = (long)pid; + return f; +} + +static int read_line(dsref *r) +{ + ssize_t n = getline(&r->line, &r->line_cap, r->f); + if (n < 0) + return 0; + r->lineno++; + while (n > 0 && (r->line[n - 1] == '\n' || r->line[n - 1] == '\r')) + r->line[--n] = 0; + return 1; +} + +static int parse_type(const char *s, dsref_type *t) +{ + static const char *names[] = {"i", "f", "s", "x", "b", "i*", "f*"}; + int k; + for (k = 0; k < 7; k++) + if (!strcmp(s, names[k])) { + *t = (dsref_type)k; + return 1; + } + return 0; +} + +const char *dsref_type_name(dsref_type t) +{ + static const char *names[] = {"i", "f", "s", "x", "b", "i*", "f*"}; + return (unsigned)t < 7 ? names[t] : "?"; +} + +int dsref_open(dsref *r, const char *path) +{ + size_t n = strlen(path); + memset(r, 0, sizeof(*r)); + r->path = path; + r->pid = -1; + if (n > 3 && !strcmp(path + n - 3, ".gz")) + r->f = open_gzip(path, &r->pid); + else + r->f = fopen(path, "r"); + if (!r->f) { + fprintf(stderr, "%s: cannot open: %s\n", path, strerror(errno)); + r->failed = 1; + return 0; + } + for (;;) { + char *tok, *save = NULL; + if (!read_line(r)) { + fail(r, "no column line"); + return 0; + } + if (r->line[0] == '#') { + char *eq = strchr(r->line, '='); + if (eq && r->nmeta < DSREF_MAX_META) { + char *k = r->line + 1; + while (*k == ' ') + k++; + *eq = 0; + snprintf(r->meta_key[r->nmeta], DSREF_NAME_LEN, "%s", k); + snprintf(r->meta_val[r->nmeta], sizeof(r->meta_val[0]), "%s", eq + 1); + r->nmeta++; + } + continue; + } + for (tok = strtok_r(r->line, " \t", &save); tok; tok = strtok_r(NULL, " \t", &save)) { + char *colon = strrchr(tok, ':'); + dsref_column *c; + if (r->ncol == DSREF_MAX_COLS || !colon || colon == tok || colon - tok >= DSREF_NAME_LEN) { + fail(r, "bad column spec"); + return 0; + } + c = &r->col[r->ncol]; + memcpy(c->name, tok, (size_t)(colon - tok)); + c->name[colon - tok] = 0; + if (!parse_type(colon + 1, &c->type)) { + fail(r, "bad column type"); + return 0; + } + if (dsref_col(r, c->name) >= 0) { + fail(r, "duplicate column"); + return 0; + } + r->ncol++; + } + if (!r->ncol) { + fail(r, "empty column line"); + return 0; + } + return 1; + } +} + +int dsref_col(const dsref *r, const char *name) +{ + int k; + for (k = 0; k < r->ncol; k++) + if (!strcmp(r->col[k].name, name)) + return k; + return -1; +} + +int dsref_need(dsref *r, const char *name, dsref_type type) +{ + int c = dsref_col(r, name); + if (c < 0 || r->col[c].type != type) { + char msg[96]; + snprintf(msg, sizeof(msg), "column %s:%s %s", name, dsref_type_name(type), c < 0 ? "missing" : "has another type"); + fail(r, msg); + return -1; + } + return c; +} + +const char *dsref_meta(const dsref *r, const char *key) +{ + int k; + for (k = 0; k < r->nmeta; k++) + if (!strcmp(r->meta_key[k], key)) + return r->meta_val[k]; + return NULL; +} + +static int grow(dsref_column *c, size_t n, size_t elem) +{ + void *p; + if (n <= c->cap) + return 1; + if (c->type == DSREF_IVEC) + p = realloc(c->iv, n * elem); + else if (c->type == DSREF_FVEC) + p = realloc(c->fv, n * elem); + else + p = realloc(c->bytes, n * elem); + if (!p) + return 0; + if (c->type == DSREF_IVEC) + c->iv = p; + else if (c->type == DSREF_FVEC) + c->fv = p; + else + c->bytes = p; + c->cap = n; + return 1; +} + +static int to_long(const char *s, long *v) +{ + char *end; + errno = 0; + *v = strtol(s, &end, 10); + return end != s && !*end && !errno; +} + +static int to_double(const char *s, double *v) +{ + char *end; + *v = strtod(s, &end); + return end != s && !*end; +} + +static int hexval(int ch) +{ + if (ch >= '0' && ch <= '9') + return ch - '0'; + ch = tolower(ch); + return ch >= 'a' && ch <= 'f' ? ch - 'a' + 10 : -1; +} + +int dsref_next(dsref *r) +{ + char *save = NULL, *tok; + int k; + if (r->failed || !r->f) + return -1; + do { + if (!read_line(r)) + return 0; + } while (r->line[0] == '#' || r->line[0] == 0); + tok = strtok_r(r->line, " \t", &save); + for (k = 0; k < r->ncol; k++) { + dsref_column *c = &r->col[k]; + long n, j; + if (!tok) { + fail(r, "too few values"); + return -1; + } + switch (c->type) { + case DSREF_INT: + if (!to_long(tok, &c->i)) { + fail(r, "bad integer"); + return -1; + } + c->len = 1; + break; + case DSREF_FLOAT: + if (!to_double(tok, &c->f)) { + fail(r, "bad float"); + return -1; + } + c->len = 1; + break; + case DSREF_STR: + case DSREF_HEX: + case DSREF_BITS: + c->s = strcmp(tok, "-") ? tok : ""; + c->len = (int)strlen(c->s); + if (c->type == DSREF_HEX) { + if (c->len % 2 || !grow(c, (size_t)c->len / 2 + 1, 1)) { + fail(r, "bad hex"); + return -1; + } + for (j = 0; j < c->len / 2; j++) { + int hi = hexval(c->s[2 * j]), lo = hexval(c->s[2 * j + 1]); + if (hi < 0 || lo < 0) { + fail(r, "bad hex digit"); + return -1; + } + c->bytes[j] = (uint8_t)(hi << 4 | lo); + } + c->len /= 2; + } else if (c->type == DSREF_BITS) { + if (!grow(c, (size_t)c->len + 1, 1)) { + fail(r, "out of memory"); + return -1; + } + for (j = 0; j < c->len; j++) { + if (c->s[j] != '0' && c->s[j] != '1') { + fail(r, "bad bit string"); + return -1; + } + c->bytes[j] = (uint8_t)(c->s[j] - '0'); + } + } + break; + case DSREF_IVEC: + case DSREF_FVEC: + if (!to_long(tok, &n) || n < 0 || n > 100000 || + !grow(c, (size_t)n + 1, c->type == DSREF_IVEC ? sizeof(long) : sizeof(double))) { + fail(r, "bad vector count"); + return -1; + } + for (j = 0; j < n; j++) { + tok = strtok_r(NULL, " \t", &save); + if (!tok || (c->type == DSREF_IVEC ? !to_long(tok, &c->iv[j]) : !to_double(tok, &c->fv[j]))) { + fail(r, tok ? "bad vector value" : "short vector"); + return -1; + } + } + c->len = (int)n; + break; + } + tok = strtok_r(NULL, " \t", &save); + } + if (tok) { + fail(r, "too many values"); + return -1; + } + r->nrec++; + return 1; +} + +int dsref_close(dsref *r) +{ + int k, ok = !r->failed; + if (r->f) { + if (ferror(r->f)) + ok = 0; + fclose(r->f); + } + if (r->pid >= 0) { + int status = 0; + if (waitpid((pid_t)r->pid, &status, 0) < 0 || !WIFEXITED(status) || WEXITSTATUS(status)) { + fprintf(stderr, "%s: gzip failed\n", r->path); + ok = 0; + } + } + for (k = 0; k < r->ncol; k++) { + free(r->col[k].iv); + free(r->col[k].fv); + free(r->col[k].bytes); + } + free(r->line); + memset(r, 0, sizeof(*r)); + r->pid = -1; + return ok; +} + +static void *read_all(const char *path, long *size) +{ + FILE *f = fopen(path, "rb"); + char *buf = NULL; + long n = 0, cap = 0; + size_t k; + if (!f) { + fprintf(stderr, "%s: cannot open: %s\n", path, strerror(errno)); + return NULL; + } + for (;;) { + if (n + 65536 > cap) { + char *p = realloc(buf, (size_t)(cap = 2 * cap + 65536)); + if (!p) { + free(buf); + fclose(f); + return NULL; + } + buf = p; + } + k = fread(buf + n, 1, (size_t)(cap - n), f); + n += (long)k; + if (k == 0) + break; + } + if (ferror(f)) { + fprintf(stderr, "%s: read error\n", path); + free(buf); + buf = NULL; + } + fclose(f); + *size = n; + return buf; +} + +int16_t *dsref_read_pcm(const char *path, long *nsamples) +{ + long n, i; + uint8_t *b = read_all(path, &n); + int16_t *x; + if (!b) + return NULL; + if (n % 2) { + fprintf(stderr, "%s: odd size %ld for int16 PCM\n", path, n); + free(b); + return NULL; + } + x = malloc((size_t)(n / 2 + 1) * sizeof(int16_t)); + if (x) + for (i = 0; i < n / 2; i++) + x[i] = (int16_t)(uint16_t)(b[2 * i] | b[2 * i + 1] << 8); + free(b); + *nsamples = n / 2; + return x; +} + +uint8_t *dsref_read_frames(const char *path, int frame_bytes, long *nframes) +{ + long n; + uint8_t *b = read_all(path, &n); + if (!b) + return NULL; + if (n % frame_bytes) { + fprintf(stderr, "%s: size %ld is not a multiple of %d\n", path, n, frame_bytes); + free(b); + return NULL; + } + *nframes = n / frame_bytes; + return b; +} + +int dsref_wopen(dsref_writer *w, const char *path, const char *stage, const char *cols, int prec) +{ + char buf[1024], *tok, *save = NULL; + memset(w, 0, sizeof(*w)); + w->prec = prec > 0 ? prec : 9; + snprintf(buf, sizeof(buf), "%s", cols); + for (tok = strtok_r(buf, " \t", &save); tok; tok = strtok_r(NULL, " \t", &save)) { + char *colon = strrchr(tok, ':'); + if (w->ncol == DSREF_MAX_COLS || !colon || !parse_type(colon + 1, &w->type[w->ncol])) { + fprintf(stderr, "%s: bad column spec '%s'\n", path, tok); + return 0; + } + w->ncol++; + } + w->f = fopen(path, "w"); + if (!w->f) { + fprintf(stderr, "%s: cannot create: %s\n", path, strerror(errno)); + return 0; + } + fprintf(w->f, "# xombe-dstar-ref 1\n# stage=%s\n# prec=%d\n# src=xombe\n%s\n", stage, w->prec, cols); + return 1; +} + +static int wcol(dsref_writer *w, dsref_type t) +{ + if (w->failed || !w->f) + return 0; + if (w->cur >= w->ncol || w->type[w->cur] != t) { + fprintf(stderr, "dsref writer: value %d is not of type %s\n", w->cur, dsref_type_name(t)); + w->failed = 1; + return 0; + } + if (w->cur++) + fputc(' ', w->f); + return 1; +} + +static void put_f(dsref_writer *w, double v) +{ + if (v == 0.0) + fputs("0", w->f); + else if (isnan(v)) + fputs("nan", w->f); + else + fprintf(w->f, "%.*g", w->prec, v); +} + +void dsref_wi(dsref_writer *w, long v) +{ + if (wcol(w, DSREF_INT)) + fprintf(w->f, "%ld", v); +} + +void dsref_wf(dsref_writer *w, double v) +{ + if (wcol(w, DSREF_FLOAT)) + put_f(w, v); +} + +void dsref_ws(dsref_writer *w, const char *s) +{ + if (wcol(w, DSREF_STR)) + fputs(*s ? s : "-", w->f); +} + +void dsref_wx(dsref_writer *w, const uint8_t *bytes, int n) +{ + int k; + if (!wcol(w, DSREF_HEX)) + return; + if (!n) + fputc('-', w->f); + for (k = 0; k < n; k++) + fprintf(w->f, "%02x", bytes[k]); +} + +void dsref_wb(dsref_writer *w, const uint8_t *bits, int n) +{ + int k; + if (!wcol(w, DSREF_BITS)) + return; + if (!n) + fputc('-', w->f); + for (k = 0; k < n; k++) + fputc(bits[k] ? '1' : '0', w->f); +} + +void dsref_wiv(dsref_writer *w, const long *v, int n) +{ + int k; + if (!wcol(w, DSREF_IVEC)) + return; + fprintf(w->f, "%d", n); + for (k = 0; k < n; k++) + fprintf(w->f, " %ld", v[k]); +} + +void dsref_wiv_int(dsref_writer *w, const int *v, int n) +{ + int k; + if (!wcol(w, DSREF_IVEC)) + return; + fprintf(w->f, "%d", n); + for (k = 0; k < n; k++) + fprintf(w->f, " %d", v[k]); +} + +void dsref_wfv(dsref_writer *w, const double *v, int n) +{ + int k; + if (!wcol(w, DSREF_FVEC)) + return; + fprintf(w->f, "%d", n); + for (k = 0; k < n; k++) { + fputc(' ', w->f); + put_f(w, v[k]); + } +} + +void dsref_wfv_float(dsref_writer *w, const float *v, int n) +{ + int k; + if (!wcol(w, DSREF_FVEC)) + return; + fprintf(w->f, "%d", n); + for (k = 0; k < n; k++) { + fputc(' ', w->f); + put_f(w, v[k]); + } +} + +void dsref_wend(dsref_writer *w) +{ + if (!w->f || w->failed) + return; + if (w->cur != w->ncol) { + fprintf(stderr, "dsref writer: record has %d values, %d columns\n", w->cur, w->ncol); + w->failed = 1; + return; + } + fputc('\n', w->f); + w->cur = 0; +} + +int dsref_wclose(dsref_writer *w) +{ + int ok = w->f && !w->failed && w->cur == 0; + if (w->f) { + if (ferror(w->f) || fclose(w->f)) + ok = 0; + } + w->f = NULL; + return ok; +} diff --git a/xombe/test/dstar_ref.h b/xombe/test/dstar_ref.h new file mode 100644 index 0000000..fe769b0 --- /dev/null +++ b/xombe/test/dstar_ref.h @@ -0,0 +1,104 @@ +#ifndef XOMBE_TEST_DSTAR_REF_H +#define XOMBE_TEST_DSTAR_REF_H + +/* reader and writer for the D-STAR reference records, the writer for stage dumps test/dstar_cmp.py compares + + a record file is text, gzip-compressed if the path ends in .gz (read through gzip -dc): + # xombe-dstar-ref 1 meta lines start with '#', "# key=value" lines are kept + # stage=fec + n:i in:x ea:i ... a:f* column line, name:type, types i f s x b i* f* + 0 9e8d32... 0 ... 3 0.5 1 2 one record per line, whitespace separated + i integer, f float (nan allowed), s token, x hex bytes, b string of 0/1, '-' is an empty s/x/b + i* and f*: a count followed by that many values */ + +#include +#include + +#define DSREF_MAX_COLS 64 +#define DSREF_NAME_LEN 32 +#define DSREF_MAX_META 16 + +typedef enum { DSREF_INT, DSREF_FLOAT, DSREF_STR, DSREF_HEX, DSREF_BITS, DSREF_IVEC, DSREF_FVEC } dsref_type; + +typedef struct { + char name[DSREF_NAME_LEN]; + dsref_type type; + /* the current record's value */ + long i; + double f; + int len; /* vector or token length, byte or bit count, 1 for i and f */ + const char *s; /* s, x, and b: the token ("" for '-') */ + long *iv; + double *fv; + uint8_t *bytes; /* x: decoded bytes, b: one 0/1 per bit */ + size_t cap; +} dsref_column; + +typedef struct { + const char *path; + FILE *f; + long pid; + char *line; + size_t line_cap; + long lineno; + long nrec; + int failed; + int ncol; + dsref_column col[DSREF_MAX_COLS]; + int nmeta; + char meta_key[DSREF_MAX_META][DSREF_NAME_LEN]; + char meta_val[DSREF_MAX_META][128]; +} dsref; + +/* opens path and reads the meta and column lines, returns 0 (reported) on failure */ +int dsref_open(dsref *r, const char *path); +/* reads the next record: 1, 0 at the end, -1 on a malformed record (reported) */ +int dsref_next(dsref *r); +/* returns 1 if the file was opened and read without error */ +int dsref_close(dsref *r); +/* column index of name, or -1 */ +int dsref_col(const dsref *r, const char *name); +/* column index of name with the given type, a missing column or another type is reported and fails the file (-1) */ +int dsref_need(dsref *r, const char *name, dsref_type type); +/* "# key=value" meta value, or NULL */ +const char *dsref_meta(const dsref *r, const char *key); + +static inline long dsref_i(const dsref *r, int c) { return r->col[c].i; } +static inline double dsref_f(const dsref *r, int c) { return r->col[c].f; } +static inline int dsref_len(const dsref *r, int c) { return r->col[c].len; } +static inline const char *dsref_s(const dsref *r, int c) { return r->col[c].s; } +static inline const long *dsref_iv(const dsref *r, int c) { return r->col[c].iv; } +static inline const double *dsref_fv(const dsref *r, int c) { return r->col[c].fv; } +static inline const uint8_t *dsref_bytes(const dsref *r, int c) { return r->col[c].bytes; } + +const char *dsref_type_name(dsref_type t); + +/* whole binary files, PCM (int16 little endian) and 9-byte frame streams + return malloc'd data (free() it) and the count, or NULL (reported) */ +int16_t *dsref_read_pcm(const char *path, long *nsamples); +uint8_t *dsref_read_frames(const char *path, int frame_bytes, long *nframes); + +typedef struct { + FILE *f; + int ncol, cur, prec; + dsref_type type[DSREF_MAX_COLS]; + int failed; +} dsref_writer; + +/* writes the meta and column lines, prec = significant digits of floats (9 if 0) */ +int dsref_wopen(dsref_writer *w, const char *path, const char *stage, const char *cols, int prec); +void dsref_wi(dsref_writer *w, long v); +void dsref_wf(dsref_writer *w, double v); +void dsref_ws(dsref_writer *w, const char *s); +void dsref_wx(dsref_writer *w, const uint8_t *bytes, int n); +void dsref_wb(dsref_writer *w, const uint8_t *bits, int n); +void dsref_wiv(dsref_writer *w, const long *v, int n); +void dsref_wiv_int(dsref_writer *w, const int *v, int n); +void dsref_wfv(dsref_writer *w, const double *v, int n); +void dsref_wfv_float(dsref_writer *w, const float *v, int n); +/* ends the record, a wrong number of values or a type mismatch fails the writer */ +void dsref_wend(dsref_writer *w); +/* returns 1 if every record was written correctly */ +int dsref_wclose(dsref_writer *w); + +#endif diff --git a/xombe/test/q15ops_arm.sh b/xombe/test/q15ops_arm.sh new file mode 100644 index 0000000..a9702e8 --- /dev/null +++ b/xombe/test/q15ops_arm.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# q15ops_arm.sh CC QEMU SRC OUT: test_q15ops built for a Cortex-M33 (DSP extension) and run under qemu-arm +# with semihosting, checking q15ops.h's intrinsics as the host run checks the fallback +set -e +"$1" -mcpu=cortex-m33 -mthumb -O2 -std=c99 -Wall -Wextra -Werror --specs=rdimon.specs \ + -Wl,-Ttext-segment=0x100000 "$3/test/test_q15ops.c" -o "$4/test_q15ops_m33.elf" -lm +"$2" -cpu cortex-m33 "$4/test_q15ops_m33.elf" diff --git a/xombe/test/ref.h b/xombe/test/ref.h new file mode 100644 index 0000000..4f67100 --- /dev/null +++ b/xombe/test/ref.h @@ -0,0 +1,66 @@ +#ifndef XOMBE_TEST_REF_H +#define XOMBE_TEST_REF_H + +/* double-precision references for the generated tables (scripts/gen_dsp_tables.py) and the tests */ + +#include +#include "../src/internal.h" +#include "../src/dsp/biquad.h" + +static inline double ref_hamming(int i, int n) +{ + return 0.54 - 0.46 * cos(2.0 * XOMBE_PI * i / (n - 1)); +} + +/* solves a*x = b (n x n, row-major) in place by Gaussian elimination with partial pivoting, x replaces b + returns 0 if a is singular */ +static inline int ref_solve(double *a, double *b, int n) +{ + int i, j, k; + for (i = 0; i < n; i++) { + int piv = i; + for (j = i + 1; j < n; j++) + if (fabs(a[j * n + i]) > fabs(a[piv * n + i])) + piv = j; + if (fabs(a[piv * n + i]) < 1e-12) + return 0; + for (k = 0; k < n; k++) { + double t = a[i * n + k]; + a[i * n + k] = a[piv * n + k]; + a[piv * n + k] = t; + } + { + double t = b[i]; + b[i] = b[piv]; + b[piv] = t; + } + for (j = i + 1; j < n; j++) { + double m = a[j * n + i] / a[i * n + i]; + for (k = i; k < n; k++) + a[j * n + k] -= m * a[i * n + k]; + b[j] -= m * b[i]; + } + } + for (i = n - 1; i >= 0; i--) { + for (k = i + 1; k < n; k++) + b[i] -= a[i * n + k] * b[k]; + b[i] /= a[i * n + i]; + } + return 1; +} + +/* codec high-pass power gain at f_hz, dB */ +static inline double ref_hpf_gain_db(double f_hz) +{ + double w = 2.0 * XOMBE_PI * f_hz / XOMBE_FS; + double cr = cos(w), ci = -sin(w), c2r = cos(2 * w), c2i = -sin(2 * w); + double zr = 1.0 - cr, zi = -ci; + double nr = zr * zr - zi * zi, ni = 2.0 * zr * zi, n3r = nr * zr - ni * zi, n3i = nr * zi + ni * zr; + double d1r = 1.0 - HPF_POLE1 * cr, d1i = -HPF_POLE1 * ci; + double d2r = 1.0 - HPF_A1 * cr + HPF_A2 * c2r, d2i = -HPF_A1 * ci + HPF_A2 * c2i; + double num = n3r * n3r + n3i * n3i; + double den = (d1r * d1r + d1i * d1i) * (d2r * d2r + d2i * d2i); + return 10.0 * log10(num / den); +} + +#endif diff --git a/xombe/test/sizes.c b/xombe/test/sizes.c new file mode 100644 index 0000000..fe643a6 --- /dev/null +++ b/xombe/test/sizes.c @@ -0,0 +1,115 @@ +#include +#include +#include "xombe.h" + +/* prints this build's row of the size table (scripts/size_table.sh) and checks every *_size() <= its *_SIZE. + usage: sizes [--header] */ + +static int failures; + +static void check(size_t got, size_t max, const char *what) +{ + if (got > max) { + failures++; + fprintf(stderr, "FAIL %s: %zu > %zu\n", what, got, max); + } +} + +#if XOMBE_HAVE_DSTAR +/* state and workspace bytes xombe_xc_init_shared writes for one input codec (it zeroes both in full): the last + byte off its fill, over two fills */ +static void shared_bytes(enum xombe_codec from, size_t *state, size_t *ws) +{ + static unsigned char mem[2][XOMBE_XC_SIZE]; /* larger than any shared state */ + static unsigned char qws[2][XOMBE_QWS_SIZE]; + static const unsigned char pat[2] = {0xA5, 0x5A}; + size_t s[2], w[2]; + int i; + for (i = 0; i < 2; i++) { + memset(mem[i], pat[i], sizeof(mem[i])); + memset(qws[i], pat[i], sizeof(qws[i])); + xombe_xc_init_shared(mem[i], from, qws[i]); + } + for (i = 0; i < 2; i++) { + size_t k = sizeof(mem[i]); + while (k > 0 && mem[i][k - 1] == pat[i]) + k--; + s[i] = k; + k = sizeof(qws[i]); + while (k > 0 && qws[i][k - 1] == pat[i]) + k--; + w[i] = k; + } + *state = s[0] > s[1] ? s[0] : s[1]; + *ws = w[0] > w[1] ? w[0] : w[1]; +} +#endif + +int main(int argc, char **argv) +{ + char row[1024]; + size_t n = 0; + if (argc > 1 && !strcmp(argv[1], "--header")) { + printf("| kernels | D-STAR | enc | enc delay DMR / D-STAR / both | dec | xc | xc shared DMR / D-STAR | QWS |\n"); + printf("|---|---|---|---|---|---|---|---|\n"); + return 0; + } + n += (size_t)snprintf(row + n, sizeof(row) - n, "| %s | %s |", XOMBE_KERNELS_Q15 ? "q15" : "float", + XOMBE_HAVE_DSTAR ? "on" : "off"); +#if XOMBE_HAVE_ENCODER + { + static xombe_enc_mem mem; + static const unsigned outs[3] = {XOMBE_ENC_DMR, XOMBE_ENC_DSTAR, XOMBE_ENC_DMR | XOMBE_ENC_DSTAR}; + xombe_enc_cfg cfg; + int i; + check(xombe_enc_size(), XOMBE_ENC_SIZE, "xombe_enc_size"); + n += (size_t)snprintf(row + n, sizeof(row) - n, " %zu |", xombe_enc_size()); + for (i = 0; i < 3; i++) { + xombe_enc *e; + xombe_enc_cfg_default(&cfg); + cfg.outputs = outs[i]; + e = xombe_enc_init(&mem, &cfg); + if (e) + n += (size_t)snprintf(row + n, sizeof(row) - n, "%s%d", i ? " / " : " ", xombe_enc_delay(e)); + else + n += (size_t)snprintf(row + n, sizeof(row) - n, "%s-", i ? " / " : " "); + if (!e && !(outs[i] & XOMBE_ENC_DSTAR)) { + failures++; + fprintf(stderr, "FAIL encoder init, outputs %u\n", outs[i]); + } + } + n += (size_t)snprintf(row + n, sizeof(row) - n, " |"); + } +#else + n += (size_t)snprintf(row + n, sizeof(row) - n, " - | - |"); +#endif + check(xombe_dec_size(), XOMBE_DEC_SIZE, "xombe_dec_size"); + n += (size_t)snprintf(row + n, sizeof(row) - n, " %zu |", xombe_dec_size()); +#if XOMBE_HAVE_DSTAR + { + size_t st, ws, qws; + check(xombe_xc_size(), XOMBE_XC_SIZE, "xombe_xc_size"); + shared_bytes(XOMBE_DMR, &st, &ws); + check(st, XOMBE_XC_SHARED_SIZE, "xc shared state from DMR"); + check(ws, XOMBE_QWS_SIZE, "xc workspace from DMR"); + qws = ws; + n += (size_t)snprintf(row + n, sizeof(row) - n, " %zu | %zu", xombe_xc_size(), st); +#if XOMBE_HAVE_ENCODER + shared_bytes(XOMBE_DSTAR, &st, &ws); + check(st, XOMBE_XC_SHARED_SIZE, "xc shared state from D-STAR"); + check(ws, XOMBE_QWS_SIZE, "xc workspace from D-STAR"); + qws = ws > qws ? ws : qws; + n += (size_t)snprintf(row + n, sizeof(row) - n, " / %zu |", st); +#else + n += (size_t)snprintf(row + n, sizeof(row) - n, " / - |"); +#endif + n += (size_t)snprintf(row + n, sizeof(row) - n, " %zu |", qws); + } +#else + n += (size_t)snprintf(row + n, sizeof(row) - n, " - | - | - |"); +#endif + puts(row); + if (failures) + fprintf(stderr, "sizes: %d failures\n", failures); + return failures != 0; +} diff --git a/xombe/test/snapcmp.py b/xombe/test/snapcmp.py new file mode 100755 index 0000000..af32587 --- /dev/null +++ b/xombe/test/snapcmp.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +"""usage: snapcmp.py [-v] A B, compares two test/snapshot.sh outputs, exit 0 when identical + +per output: frames changed for each bitstream (AMBE+2 .amb, air, D-STAR, dual, xc, xr) and samples changed with the +largest difference for each decoder output, then totals per output kind. -v also lists unchanged files""" +import os +import sys +from array import array + +AMB_HEADER = b".amb" +AMB_RECORD = 8 +AIR_RECORD = 9 # air frames, D-STAR frames, and rate-33 frames are all 72 bits + + +def kind(path): + """output kind and frame size (0: 16-bit PCM, None: compared as text) of a snapshot file""" + top, name = path.split("/", 1) + if name.endswith(".err"): + return "stderr", None + if top == "dec": + return "decoder", 0 + if top == "xc": + return ("xc", AIR_RECORD) if name.endswith(".dstar") else ("xr", AIR_RECORD) + for suffix, k, n in ((".dual.amb", "dual AMBE+2", AMB_RECORD), (".dual.dstar", "dual D-STAR", AIR_RECORD), + (".dsdtx.dstar", "D-STAR dtx", AIR_RECORD), (".dstar", "D-STAR", AIR_RECORD), + (".air", "AMBE+2 air", AIR_RECORD), (".amb", "AMBE+2", AMB_RECORD)): + if name.endswith(suffix): + return k, n + return "other", None + + +def frames(data, n): + if n == AMB_RECORD and data.startswith(AMB_HEADER): + data = data[len(AMB_HEADER):] + return [data[i:i + n] for i in range(0, len(data), n)] + + +def pcm(data): + a = array("h") + a.frombytes(data[:len(data) & ~1]) + if sys.byteorder != "little": + a.byteswap() + return a + + +def compare(a, b, n): + """(changed, total, detail) for one file pair""" + if n is None: + la, lb = a.decode(errors="replace").splitlines(), b.decode(errors="replace").splitlines() + changed = sum(x != y for x, y in zip(la, lb)) + abs(len(la) - len(lb)) + return changed, max(len(la), len(lb)), "lines" + if n == 0: + sa, sb = pcm(a), pcm(b) + diffs = [abs(x - y) for x, y in zip(sa, sb) if x != y] + extra = abs(len(sa) - len(sb)) + detail = "samples, max diff %d" % max(diffs) if diffs else "samples" + if extra: + detail += ", length %d vs %d" % (len(sa), len(sb)) + return len(diffs) + extra, max(len(sa), len(sb)), detail + fa, fb = frames(a, n), frames(b, n) + changed = sum(x != y for x, y in zip(fa, fb)) + abs(len(fa) - len(fb)) + detail = "frames" if len(fa) == len(fb) else "frames, length %d vs %d" % (len(fa), len(fb)) + return changed, max(len(fa), len(fb)), detail + + +def files(root): + out = set() + for d in ("dec", "enc", "xc"): + top = os.path.join(root, d) + if os.path.isdir(top): + out.update(d + "/" + f for f in os.listdir(top)) + return out + + +def read(path): + with open(path, "rb") as f: + return f.read() + + +def main(argv): + verbose = "-v" in argv + args = [a for a in argv if a != "-v"] + if len(args) != 2: + sys.exit(__doc__) + ra, rb = args + totals = {} + differ = 0 + for path in sorted(files(ra) | files(rb)): + k, n = kind(path) + pa, pb = os.path.join(ra, path), os.path.join(rb, path) + if not os.path.exists(pa) or not os.path.exists(pb): + print("%s: only in %s" % (path, ra if os.path.exists(pa) else rb)) + differ = 1 + continue + a, b = read(pa), read(pb) + t = totals.setdefault(k, [0, 0, 0, 0, 0]) # files, files changed, units changed, units, max diff + t[0] += 1 + if a == b: + if verbose: + print("%s: same" % path) + continue + changed, total, detail = compare(a, b, n) + t[1] += 1 + t[2] += changed + t[3] += total + if n == 0 and "max diff" in detail: + t[4] = max(t[4], int(detail.split("max diff ")[1].split(",")[0])) + print("%s: %d of %d %s" % (path, changed, total, detail)) + differ = 1 + sa, sb = read(os.path.join(ra, "status")), read(os.path.join(rb, "status")) + if sa != sb: + print("status differs") + differ = 1 + print("summary:") + for k in sorted(totals): + f, fc, uc, u, md = totals[k] + line = " %-12s %3d files, %3d changed" % (k, f, fc) + if fc: + unit = "lines" if kind_unit(k) is None else ("samples" if kind_unit(k) == 0 else "frames") + line += ", %d of %d %s in those" % (uc, u, unit) + if kind_unit(k) == 0: + line += ", max diff %d" % md + print(line) + print("identical" if not differ else "DIFFERENT") + return differ + + +def kind_unit(k): + return {"decoder": 0, "stderr": None, "other": None}.get(k, AIR_RECORD) + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/xombe/test/snapshot.sh b/xombe/test/snapshot.sh new file mode 100755 index 0000000..1c70643 --- /dev/null +++ b/xombe/test/snapshot.sh @@ -0,0 +1,106 @@ +#!/bin/sh +# bit-exactness snapshot of a xombe source tree, compare two with test/snapcmp.py +# +# usage: snapshot.sh [-q] [-j N] [-D CMAKE_DEF]... SRC OUT +# SRC xombe source tree (a worktree or an exported `git archive`) +# OUT output dir, removed first if it exists, the build goes to OUT.build (reused, reconfigured each run) +# -q build with -DXOMBE_KERNELS=q15 +# -j N build parallelism (default nproc) +# -D X extra cmake definition, e.g. -D XOMBE_DSTAR=OFF (repeatable) +# +# OUT holds one file per run, named / _>[.ext]: +# dec/ xombe-dec PCM for every .amb (default, --lost 3,10-12, --conformance-noise), .bits, .r33 (--air), .dstar +# (--dstar, and --lost 3,10-12), stream .jsonl.gz (--stream) +# enc/ xombe-enc for every .raw: .amb, --air, --dstar, --dual (amb + dstar), and --dstar-dtx on, each with +# default settings (def) and with --ns off --dtx off (quiet) +# xc/ xombe-xc forward on every .r33, --reverse on every .dstar +# status exit status of every run, a mode the build lacks shows as a nonzero status +# stderr of each run is kept as .err next to its output (it holds --decisions where used) +set -u + +kern= +jobs=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4) +defs= +while getopts qj:D: o; do + case $o in + q) kern=-DXOMBE_KERNELS=q15 ;; + j) jobs=$OPTARG ;; + D) defs="$defs -D$OPTARG" ;; + *) sed -n '4,9p' "$0"; exit 2 ;; + esac +done +shift $((OPTIND - 1)) +[ $# -eq 2 ] || { sed -n '4,9p' "$0"; exit 2; } +src=$(cd "$1" && pwd) || exit 2 +out=$2 +case $out in /*) ;; *) out=$(pwd)/$out ;; esac +bld=$out.build + +# shellcheck disable=SC2086 +cmake -S "$src" -B "$bld" -DCMAKE_BUILD_TYPE=Release -DXOMBE_BUILD_TOOLS=ON -DXOMBE_BUILD_TESTS=OFF $kern $defs \ + >"$bld.log" 2>&1 && + cmake --build "$bld" -j "$jobs" >>"$bld.log" 2>&1 || { echo "snapshot.sh: build failed, see $bld.log" >&2; exit 1; } + +tdir=$(dirname "$(find "$bld" -name xombe-dec -type f -perm -u+x | head -1)") +[ -x "$tdir/xombe-dec" ] || { echo "snapshot.sh: no xombe-dec in $bld" >&2; exit 1; } +DEC=$tdir/xombe-dec ENC=$tdir/xombe-enc XC=$tdir/xombe-xc + +rm -rf "$out" +mkdir -p "$out/dec" "$out/enc" "$out/xc" +st=$out/status +: >"$st" + +# run NAME CMD...: CMD with stderr to NAME.err, its status recorded +run() { + n=$1; shift + "$@" 2>"$n.err" + echo "$? ${n#"$out"/}" >>"$st" +} + +cd "$src" || exit 2 +key() { echo "$1" | sed 's|^vectors/||; s|/|_|g'; } + +for f in $(find vectors -name '*.amb' | sort); do + k=$out/dec/$(key "$f") + run "$k.raw" "$DEC" --decisions "$f" "$k.raw" + run "$k.lost.raw" "$DEC" --lost 3,10-12 "$f" "$k.lost.raw" + run "$k.conf.raw" "$DEC" --conformance-noise "$f" "$k.conf.raw" +done +for f in $(find vectors -name '*.bits' | sort); do + k=$out/dec/$(key "$f") + run "$k.raw" "$DEC" --bits --decisions "$f" "$k.raw" +done +for f in $(find vectors -name '*.r33' | sort); do + k=$out/dec/$(key "$f") + run "$k.raw" "$DEC" --air --decisions "$f" "$k.raw" + k=$out/xc/$(key "$f") + run "$k.dstar" "$XC" --decisions "$f" "$k.dstar" +done +for f in $(find vectors -name '*.dstar' | sort); do + k=$out/dec/$(key "$f") + run "$k.raw" "$DEC" --dstar --decisions "$f" "$k.raw" + run "$k.lost.raw" "$DEC" --dstar --lost 3,10-12 "$f" "$k.lost.raw" + k=$out/xc/$(key "$f") + run "$k.r33" "$XC" --reverse --decisions "$f" "$k.r33" +done +for f in $(find vectors -name '*.jsonl.gz' | sort); do + k=$out/dec/$(key "$f") + run "$k.raw" "$DEC" --stream "$f" "$k.raw" +done +for f in $(find vectors -name '*.raw' | sort); do + for set in def quiet; do + if [ $set = quiet ]; then o="--ns off --dtx off"; else o=; fi + k=$out/enc/$(key "$f").$set + # shellcheck disable=SC2086 + { + run "$k.amb" "$ENC" $o "$f" "$k.amb" + run "$k.air" "$ENC" $o --air "$f" "$k.air" + run "$k.dstar" "$ENC" $o --dstar "$f" "$k.dstar" + run "$k.dual.amb" "$ENC" $o --dual "$k.dual.dstar" "$f" "$k.dual.amb" + run "$k.dsdtx.dstar" "$ENC" $o --dstar --dstar-dtx on "$f" "$k.dsdtx.dstar" + } + done +done +n=$(wc -l <"$st") +bad=$(awk '$1 != 0' "$st" | wc -l) +echo "snapshot.sh: $n runs into $out ($bad nonzero exits, see status)" diff --git a/xombe/test/test_api.c b/xombe/test/test_api.c new file mode 100644 index 0000000..8c3e7bb --- /dev/null +++ b/xombe/test/test_api.c @@ -0,0 +1,786 @@ +#include +#include +#include +#include +#include "xombe.h" + +/* public API contracts: handles, sizes, argument checks, call order, and delays, public headers only. every + codec test runs for each codec built */ + +static int failures, checks; + +static void check(int ok, const char *what) +{ + checks++; + if (!ok) { + failures++; + fprintf(stderr, "FAIL %s\n", what); + } +} + +static const char *codec_name(enum xombe_codec c) +{ + return c == XOMBE_DSTAR ? "D-STAR" : "DMR"; +} + +static void checkc(int ok, enum xombe_codec c, const char *what) +{ + char msg[256]; + snprintf(msg, sizeof(msg), "%s: %s", codec_name(c), what); + check(ok, msg); +} + +static const enum xombe_codec codecs[] = { + XOMBE_DMR, +#if XOMBE_HAVE_DSTAR + XOMBE_DSTAR, +#endif +}; +#define NCODECS ((int)(sizeof(codecs) / sizeof(codecs[0]))) + +static const uint8_t dmr_silence_bits[XOMBE_BITS_BYTES] = {0xF8, 0x01, 0xA9, 0x9F, 0x8C, 0xE0, 0x80}; +static const uint8_t dstar_null_frame[XOMBE_FRAME_BYTES] = {0x9E, 0x8D, 0x32, 0x88, 0x26, 0x1A, 0x3F, 0x61, 0xE8}; +static const uint8_t dstar_null_bits[XOMBE_BITS_BYTES] = {0xF8, 0x54, 0xAA, 0x9D, 0xE8, 0x0A, 0x00}; +static const uint8_t fill[XOMBE_FRAME_BYTES] = {0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5}; + +/* each codec's silence frame (DMR silence, D-STAR null frame) and its voice bits */ +static uint8_t silence_frame[2][XOMBE_FRAME_BYTES]; +static const uint8_t *const silence_bits[2] = {dmr_silence_bits, dstar_null_bits}; + +static void setup_frames(void) +{ + uint8_t f[XOMBE_FRAME_BYTES]; + xombe_fec_encode(XOMBE_DMR, dmr_silence_bits, silence_frame[XOMBE_DMR]); + memcpy(silence_frame[XOMBE_DSTAR], dstar_null_frame, XOMBE_FRAME_BYTES); + memcpy(f, fill, sizeof(f)); + check(xombe_fec_encode(XOMBE_DSTAR, dstar_null_bits, f) == (XOMBE_HAVE_DSTAR ? 0 : -1) && + !memcmp(f, XOMBE_HAVE_DSTAR ? dstar_null_frame : fill, sizeof(f)), + "D-STAR null frame from its voice bits, refused without D-STAR"); +} + +/* pseudo-random frame n: every tenth the silence frame, every third a clean one from random voice bits */ +static void stream_frame(enum xombe_codec c, int n, uint8_t fr[XOMBE_FRAME_BYTES]) +{ + int i; + for (i = 0; i < XOMBE_FRAME_BYTES; i++) + fr[i] = (uint8_t)((n * 131 + i * 71 + (n * i) % 13) & 0xff); + if (n % 10 == 3) { + memcpy(fr, silence_frame[c], XOMBE_FRAME_BYTES); + } else if (n % 3 == 0) { + uint8_t bits[XOMBE_BITS_BYTES]; + for (i = 0; i < XOMBE_BITS_BYTES; i++) + bits[i] = (uint8_t)(n * 37 + i * 101); + bits[0] &= 0x7f; + bits[6] &= c == XOMBE_DMR ? 0x80 : 0x00; + xombe_fec_encode(c, bits, fr); + } +} + +static int popcount_bytes(const uint8_t *a, const uint8_t *b, int n) +{ + int i, k = 0; + for (i = 0; i < n; i++) { + unsigned v = (unsigned)(a[i] ^ b[i]); + while (v) { + k += v & 1; + v >>= 1; + } + } + return k; +} + +static void test_fec(enum xombe_codec c) +{ + xombe_fec f; + xombe_fec_stats st; + uint8_t bits[XOMBE_BITS_BYTES], back[XOMBE_BITS_BYTES], fr[XOMBE_FRAME_BYTES]; + int n, i, round = 1, flipped = 1, rate = 1; + checkc(xombe_fec_init(&f, c) == 0, c, "fec init"); + for (n = 0; n < 72; n++) { + int diff; + for (i = 0; i < XOMBE_BITS_BYTES; i++) + bits[i] = (uint8_t)(n * 53 + i * 29 + n * i); + bits[6] &= c == XOMBE_DMR ? 0x80 : 0x00; + checkc(xombe_fec_encode(c, bits, fr) == 0, c, "fec encode"); + round &= xombe_fec_decode(&f, fr, back, n % 2 ? NULL : &st) == 0 && !memcmp(bits, back, sizeof(bits)); + if (n % 2 == 0) + round &= st.eps0 == 0 && st.eps1 == 0 && st.eps_t == 0 && !st.bf && !st.hb; + fr[n / 8] ^= (uint8_t)(0x80 >> (n % 8)); + xombe_fec_decode(&f, fr, back, &st); + diff = popcount_bytes(bits, back, XOMBE_BITS_BYTES); + flipped &= diff <= 1 && st.eps_t <= 1 && (diff == 0 || st.eps_t == 0) && st.eps_t == st.eps0 + st.eps1; + rate &= st.eps_r > 0; + } + checkc(round, c, "fec round trip of clean frames, no corrections, NULL stats accepted"); + checkc(flipped, c, "any single flipped bit is corrected, or reaches the voice bits as one bit"); + checkc(rate, c, "the running error rate counts the corrections"); +} + +static void test_decoder(enum xombe_codec c) +{ + const uint8_t *silence = silence_frame[c]; + static xombe_dec_mem mem; + int16_t pcm[XOMBE_HALF_MAX]; + xombe_dec *d, *h; + void *heap; + + checkc(xombe_dec_init(NULL, c) == NULL, c, "decoder init rejects NULL"); + checkc(xombe_dec_size() <= XOMBE_DEC_SIZE, c, "decoder size within XOMBE_DEC_SIZE"); + d = xombe_dec_init(&mem, c); + checkc(d == (xombe_dec *)&mem, c, "decoder handle is the caller's memory"); + { + xombe_decision r; + xombe_dec_decision_get(d, &r); + checkc(r.mute_src == -1 && r.e0 == -1 && r.e1 == -1 && r.run == 0, c, "decision before the first frame"); + } + + checkc(xombe_dec_set_noise(d, (enum xombe_noise_mode)7, 1) == -1, c, "set_noise rejects an unknown mode"); + checkc(xombe_dec_set_noise(d, XOMBE_NOISE_PRODUCTION, 1) == 0, c, "set_noise accepts production"); + checkc(xombe_dec_set_noise(d, XOMBE_NOISE_CONFORMANCE, 0) == 0, c, "set_noise accepts conformance"); + { + static xombe_dec_mem m[3]; + xombe_dec *def = xombe_dec_init(&m[0], c), *prod = xombe_dec_init(&m[1], c); + xombe_dec *conf = xombe_dec_init(&m[2], c); + int16_t a[160], b[160], cc[160]; + int f, same_prod = 1, same_conf = 1; + xombe_dec_set_noise(prod, XOMBE_NOISE_PRODUCTION, 0); + xombe_dec_set_noise(conf, XOMBE_NOISE_CONFORMANCE, 0); + for (f = 0; f < 4; f++) { + xombe_dec_frame(def, silence, 0, a); + xombe_dec_frame(prod, silence, 0, b); + xombe_dec_frame(conf, silence, 0, cc); + same_prod &= !memcmp(a, b, sizeof(a)); + same_conf &= !memcmp(a, cc, sizeof(a)); + } + checkc(same_prod && !same_conf, c, "default noise source is production, seed 0"); + } + + d = xombe_dec_init(&mem, c); + checkc(xombe_dec_half(d, silence, 0, 1, 80, pcm) == -1, c, "second half before a first half is refused"); + checkc(xombe_dec_half(d, silence, 0, 0, 200, pcm) == XOMBE_HALF_MAX, c, "first half, length clamped up to 84"); + checkc(xombe_dec_half(d, silence, 0, 0, 80, pcm) == -1, c, "two first halves in a row are refused"); + checkc(xombe_dec_half(d, silence, 0, 1, 10, pcm) == XOMBE_HALF_MIN, c, "second half, length clamped to 76"); + checkc(xombe_dec_half(d, silence, 0, 1, 80, pcm) == -1, c, "two second halves in a row are refused"); + checkc(xombe_dec_half(d, silence, 0, 0, 80, pcm) == 80 && xombe_dec_half(d, NULL, 0, 1, 80, pcm) == 80, c, + "second half reads no frame"); + checkc(xombe_dec_half_bits(d, NULL, 0, 1, 80, pcm) == -1, c, "bits second half before a first half is refused"); + checkc(xombe_dec_half_bits(d, silence_bits[c], 0, 0, 80, pcm) == 80 && + xombe_dec_half_bits(d, NULL, 0, 1, 80, pcm) == 80, + c, "bits second half reads no bits"); + { + static xombe_dec_mem lone_mem, twin_mem; + xombe_dec *lone = xombe_dec_init(&lone_mem, c), *twin = xombe_dec_init(&twin_mem, c); + int16_t full[160], want[160]; + int i, zeros = 1; + xombe_dec_half(lone, silence, 0, 0, 80, pcm); + xombe_dec_half(twin, silence, 0, 0, 80, want); + xombe_dec_half(twin, NULL, 0, 1, 80, want + 80); + for (i = 0; i < 160; i++) + full[i] = 0x5555; + checkc(xombe_dec_frame(lone, silence, 0, full) == 0, c, "frame after an unpaired first half returns 0"); + for (i = 0; i < 80; i++) + zeros &= full[i] == 0; + checkc(zeros && !memcmp(full + 80, want + 80, 80 * sizeof(*full)), c, + "frame after an unpaired first half: zeros, then the pending second half"); + checkc(xombe_dec_frame(lone, silence, 0, full) == 1, c, "the next frame returns 1"); + xombe_dec_frame(twin, silence, 0, want); + checkc(!memcmp(full, want, sizeof(full)), c, "the next frame decodes normally"); + xombe_dec_half_bits(lone, silence_bits[c], 0, 0, 80, pcm); + checkc(xombe_dec_frame_bits(lone, silence_bits[c], 0, full) == 0, c, + "bits frame after an unpaired first half returns 0"); + } + { + xombe_decision r; + int16_t f[160]; + xombe_dec_frame(d, silence, 0, f); + xombe_dec_decision_get(d, &r); + checkc(r.cls == XOMBE_CLASS_SILENCE && r.conceal == XOMBE_CONCEAL_NONE && r.e0 == 0 && r.e1 == 0, c, + "decision of a silence frame"); + } + { + /* a lost frame plays as a bad frame, without reading bits. D-STAR's bad voice frames never mute, so its + run stays short of the mute */ + static xombe_dec_mem lm, bm; + xombe_dec *l = xombe_dec_init(&lm, c), *b = xombe_dec_init(&bm, c); + static const uint8_t zero[XOMBE_BITS_BYTES]; + int16_t pl[160], pb[160]; + int i, same = 1, erasure = 1, last_lost = c == XOMBE_DMR ? 6 : 3; + for (i = 0; i < 8; i++) { + xombe_decision r; + unsigned lost = i >= 2 && i <= last_lost; + xombe_dec_frame_bits(l, lost ? NULL : silence_bits[c], lost ? XOMBE_FLAG_LOST : 0, pl); + xombe_dec_frame_bits(b, lost ? zero : silence_bits[c], lost ? XOMBE_FLAG_BF : 0, pb); + same &= !memcmp(pl, pb, sizeof(pl)); + xombe_dec_decision_get(l, &r); + if (lost) + erasure &= r.cls == XOMBE_CLASS_ERASURE && r.conceal != XOMBE_CONCEAL_NONE && r.run == i - 1 && + r.e0 == -1 && r.e1 == -1 && !r.bf && !r.hb; + } + checkc(same, c, "XOMBE_FLAG_LOST plays as XOMBE_FLAG_BF"); + checkc(erasure, c, "decision of a lost frame: erasure, concealed, run counts it"); + } + + heap = malloc(xombe_dec_size()); + h = xombe_dec_init(heap, c); + if (h) { + int16_t a[160], b[160]; + int i; + d = xombe_dec_init(&mem, c); + for (i = 0; i < 20; i++) { + xombe_dec_frame(d, silence, 0, a); + xombe_dec_frame(h, silence, 0, b); + } + checkc(!memcmp(a, b, sizeof(a)), c, "malloc'd and static decoders agree"); + } + checkc(h != NULL, c, "decoder in malloc'd memory"); + free(heap); +} + +/* frame calls equal the caller's own FEC into the *_bits calls, and two half calls */ +static void test_decoder_bits(enum xombe_codec c) +{ + static xombe_dec_mem am, bm, hm; + xombe_dec *a = xombe_dec_init(&am, c), *b = xombe_dec_init(&bm, c), *h = xombe_dec_init(&hm, c); + xombe_fec fec; + int n, same = 1, halves = 1, decided = 1, seen = 0; + xombe_fec_init(&fec, c); + for (n = 0; n < 300; n++) { + uint8_t fr[XOMBE_FRAME_BYTES], bits[XOMBE_BITS_BYTES]; + int16_t pa[160], pb[160], ph[160]; + unsigned lost = n % 41 >= 7 && n % 41 < 11 ? XOMBE_FLAG_LOST : 0, flags = XOMBE_FLAG_LOST; + xombe_fec_stats st; + xombe_decision ra, rb; + stream_frame(c, n, fr); + same &= xombe_dec_frame(a, lost ? NULL : fr, lost, pa) == 1; + if (!lost) { + flags = xombe_fec_decode(&fec, fr, bits, &st); + xombe_dec_set_errors(b, st.eps_t, st.eps1); + } + same &= xombe_dec_frame_bits(b, lost ? NULL : bits, flags, pb) == 1; + halves &= xombe_dec_half(h, lost ? NULL : fr, lost, 0, 80, ph) == 80 && + xombe_dec_half(h, NULL, 0, 1, 80, ph + 80) == 80 && !memcmp(pa, ph, sizeof(pa)); + same &= !memcmp(pa, pb, sizeof(pa)); + xombe_dec_decision_get(a, &ra); + xombe_dec_decision_get(b, &rb); + decided &= ra.cls == rb.cls && ra.conceal == rb.conceal && ra.run == rb.run && ra.mute_src == rb.mute_src && + ra.bf == rb.bf && ra.hb == rb.hb && rb.e0 == -1 && rb.e1 == -1; + decided &= lost ? ra.e0 == -1 && ra.e1 == -1 && !ra.bf && !ra.hb + : ra.e0 == st.eps0 && ra.e1 == st.eps1 && ra.bf == st.bf && ra.hb == st.hb; + if (ra.conceal == XOMBE_CONCEAL_NONE) + seen |= 1 << ra.cls; + else + seen |= 1 << (4 + ra.conceal); + } + checkc(same, c, "xombe_dec_frame equals xombe_fec_decode, xombe_dec_set_errors, and xombe_dec_frame_bits"); + checkc(halves, c, "xombe_dec_frame equals two xombe_dec_half calls"); + checkc(decided, c, "frame decisions: the bits one with the Golay corrections"); + checkc((seen & 0x65) == 0x65, c, "the stream plays voice, silence, repeats, and mutes"); +} + +/* tone frames: same ID and level rules as forced tones, refused calls write nothing, decoded as tones */ +static void test_tone_frames(enum xombe_codec c) +{ + static const int bad[][2] = {{0, 90}, {4, 90}, {123, 90}, {127, 90}, {164, 90}, {-1, 90}, {255, 90}, + {5, -1}, {5, 128}, {129, 1000}}; + static const int good[][2] = {{5, 0}, {122, 127}, {128, 64}, {163, 1}}; + static xombe_dec_mem dm; + xombe_dec *d = xombe_dec_init(&dm, c); + uint8_t f[XOMBE_FRAME_BYTES]; + int16_t pcm[160]; + unsigned i; + int refused = 1, accepted = 1, knox = 1; + for (i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) { + memcpy(f, fill, sizeof(f)); + refused &= xombe_tone_frame(c, bad[i][0], bad[i][1], f) == -1 && !memcmp(f, fill, sizeof(f)); + } + for (i = 0; i < sizeof(good) / sizeof(good[0]); i++) { + xombe_decision r; + accepted &= xombe_tone_frame(c, good[i][0], good[i][1], f) == 0; + xombe_dec_frame(d, f, 0, pcm); + xombe_dec_decision_get(d, &r); + accepted &= r.cls == XOMBE_CLASS_TONE && r.conceal == XOMBE_CONCEAL_NONE && r.e0 == 0 && r.e1 == 0; + } + for (i = 144; i <= 159; i++) { + int r; + memcpy(f, fill, sizeof(f)); + r = xombe_tone_frame(c, (int)i, 90, f); + knox &= c == XOMBE_DMR ? r == 0 : r == -1 && !memcmp(f, fill, sizeof(f)); + } + checkc(refused, c, "xombe_tone_frame refuses IDs outside 5..122, 128..163 and levels outside 0..127"); + checkc(accepted, c, "xombe_tone_frame takes range ends, its frames decode as clean tones"); + checkc(knox, c, "Knox tone frames: DMR has them, D-STAR refuses them and writes nothing"); +} + +/* calls naming a codec the build lacks, or none at all */ +static void test_codecs(void) +{ + static xombe_dec_mem dm; + xombe_fec f, g; + uint8_t fr[XOMBE_FRAME_BYTES]; + memset(&f, 0x5A, sizeof(f)); + g = f; + check(xombe_dec_init(&dm, (enum xombe_codec)7) == NULL, "decoder init refuses an unknown codec"); + check(xombe_fec_init(&f, (enum xombe_codec)7) == -1 && !memcmp(&f, &g, sizeof(f)), + "fec init refuses an unknown codec, f unchanged"); + memcpy(fr, fill, sizeof(fr)); + check(xombe_fec_encode((enum xombe_codec)7, dmr_silence_bits, fr) == -1 && !memcmp(fr, fill, sizeof(fr)), + "fec encode refuses an unknown codec, writes nothing"); + check(xombe_tone_frame((enum xombe_codec)7, 128, 64, fr) == -1 && !memcmp(fr, fill, sizeof(fr)), + "tone frame refuses an unknown codec, writes nothing"); + check((xombe_dec_init(&dm, XOMBE_DSTAR) != NULL) == XOMBE_HAVE_DSTAR, "D-STAR decoder only in a D-STAR build"); + check((xombe_fec_init(&f, XOMBE_DSTAR) == 0) == XOMBE_HAVE_DSTAR, "D-STAR FEC only in a D-STAR build"); + check((xombe_tone_frame(XOMBE_DSTAR, 128, 64, fr) == 0) == XOMBE_HAVE_DSTAR, + "D-STAR tone frames only in a D-STAR build"); +#if XOMBE_HAVE_DSTAR + { + xombe_fec_stats st; + uint8_t bits[XOMBE_BITS_BYTES]; + xombe_fec_init(&f, XOMBE_DSTAR); + check(xombe_fec_decode(&f, dstar_null_frame, bits, &st) == 0 && !memcmp(bits, dstar_null_bits, 7), + "D-STAR null frame's voice bits"); + } +#endif +} + +#if XOMBE_HAVE_ENCODER +/* harmonic signal that comes and goes */ +static void test_signal(int n, int16_t pcm[160]) +{ + int i; + for (i = 0; i < 160; i++) { + float t = (float)(n * 160 + i), x = 0.0f; + int h; + if ((n / 20) % 2 == 0) + for (h = 1; h <= 8; h++) + x += 1500.0f / (float)h * sinf(0.0393f * (float)h * t + 0.3f * (float)h); + pcm[i] = (int16_t)(x + (float)((n * 160 + i) * 7919 % 61) - 30.0f); + } +} + +#if XOMBE_HAVE_DSTAR +#define ALL_OUTPUTS (XOMBE_ENC_DMR | XOMBE_ENC_DSTAR) +#else +#define ALL_OUTPUTS XOMBE_ENC_DMR +#endif + +static void test_encoder(void) +{ + static xombe_enc_mem mem; + xombe_enc_cfg cfg; + int16_t pcm[160]; + uint8_t f[XOMBE_FRAME_BYTES]; + int i, got = 0; + + check(xombe_enc_size() <= XOMBE_ENC_SIZE, "encoder size within XOMBE_ENC_SIZE"); + check(xombe_enc_init(NULL, NULL) == NULL, "encoder init rejects NULL"); + check(xombe_enc_init(&mem, NULL) != NULL, "encoder init with default settings"); + + xombe_enc_cfg_default(&cfg); + cfg.ns_strength_permille = -1; + check(xombe_enc_init(&mem, &cfg) == NULL, "ns_strength_permille below 0 is refused"); + cfg.ns_strength_permille = 1001; + check(xombe_enc_init(&mem, &cfg) == NULL, "ns_strength_permille above 1000 is refused"); + cfg.ns_strength_permille = 0; + check(xombe_enc_init(&mem, &cfg) != NULL, "ns_strength_permille 0 is accepted"); + cfg.ns_strength_permille = 1000; + check(xombe_enc_init(&mem, &cfg) != NULL, "ns_strength_permille 1000 is accepted"); + xombe_enc_cfg_default(&cfg); + cfg.voicing_scale_permille = 0; + check(xombe_enc_init(&mem, &cfg) == NULL, "voicing_scale_permille 0 is refused"); + cfg.voicing_scale_permille = -350; + check(xombe_enc_init(&mem, &cfg) == NULL, "voicing_scale_permille below 0 is refused"); + xombe_enc_cfg_default(&cfg); + cfg.dmr_dtx = 5; + cfg.dstar_dtx = 5; + check(xombe_enc_init(&mem, &cfg) != NULL, "nonzero dtx means on"); + + memset(pcm, 0, sizeof(pcm)); + xombe_enc_init(&mem, NULL); + for (i = 0; i < XOMBE_ENC_DELAY + 2; i++) + got += xombe_enc_frame((xombe_enc *)&mem, pcm, NULL, f, NULL); + check(got == 2, "encoder output starts after XOMBE_ENC_DELAY frames"); + + xombe_enc_cfg_default(&cfg); + cfg.outputs = 0x80u; + check(xombe_enc_init(&mem, &cfg) == NULL, "an unknown output is refused"); + cfg.outputs = 0; + check(xombe_enc_init(&mem, &cfg) != NULL, "outputs 0 means DMR"); + check(xombe_enc_delay((xombe_enc *)&mem) == XOMBE_ENC_DELAY, "DMR-only delay"); + cfg.outputs = XOMBE_ENC_DSTAR; + check((xombe_enc_init(&mem, &cfg) != NULL) == XOMBE_HAVE_DSTAR, "D-STAR output only in a D-STAR build"); + xombe_enc_cfg_default(&cfg); + check(cfg.outputs == XOMBE_ENC_DMR && cfg.dmr_dtx && !cfg.dstar_dtx && cfg.dmr_quant == XOMBE_ENC_QUANT_CLOSED, + "defaults: DMR output, DMR DTX on, D-STAR DTX off, closed loop"); + + { + /* pcm NULL is a frame of zeros, for both outputs and both forms */ + static xombe_enc_mem m2, m3, m4; + xombe_enc *a, *b, *c2, *d2; + uint8_t fa[2][XOMBE_FRAME_BYTES], fb[2][XOMBE_FRAME_BYTES], ba[2][XOMBE_BITS_BYTES]; + uint8_t bb[2][XOMBE_BITS_BYTES]; + int same = 1; + xombe_enc_cfg_default(&cfg); + cfg.outputs = ALL_OUTPUTS; + a = xombe_enc_init(&mem, &cfg); + b = xombe_enc_init(&m2, &cfg); + c2 = xombe_enc_init(&m3, &cfg); + d2 = xombe_enc_init(&m4, &cfg); + for (i = 0; i < 8; i++) { + int ra = xombe_enc_frame(a, NULL, NULL, fa[0], fa[1]), rb = xombe_enc_frame(b, pcm, NULL, fb[0], fb[1]); + int rc = xombe_enc_frame_bits(c2, NULL, NULL, ba[0], ba[1]); + int rd = xombe_enc_frame_bits(d2, pcm, NULL, bb[0], bb[1]); + same &= ra == rb && rc == rd && !memcmp(fa, fb, sizeof(fa)) && !memcmp(ba, bb, sizeof(ba)); + } + check(same, "pcm NULL encodes zeros"); + } +} + +/* an output the encoder does not produce gets its codec's silence frame, in either form */ +static void test_encoder_absent(void) +{ + static xombe_enc_mem mem; + int16_t pcm[160]; + uint8_t f[XOMBE_FRAME_BYTES], b[XOMBE_BITS_BYTES]; + int n, ok = 1; + xombe_enc_init(&mem, NULL); + for (n = 0; n < 10; n++) { + test_signal(n, pcm); + xombe_enc_frame((xombe_enc *)&mem, pcm, NULL, NULL, f); + xombe_enc_frame_bits((xombe_enc *)&mem, pcm, NULL, NULL, b); + ok &= !memcmp(f, dstar_null_frame, sizeof(f)) && !memcmp(b, dstar_null_bits, sizeof(b)); + } + check(ok, "a DMR-only encoder writes D-STAR null frames and their bits"); +#if XOMBE_HAVE_DSTAR + { + xombe_enc_cfg cfg; + xombe_enc_cfg_default(&cfg); + cfg.outputs = XOMBE_ENC_DSTAR; + xombe_enc_init(&mem, &cfg); + for (n = 0, ok = 1; n < 10; n++) { + test_signal(n, pcm); + xombe_enc_frame((xombe_enc *)&mem, pcm, NULL, f, NULL); + xombe_enc_frame_bits((xombe_enc *)&mem, pcm, NULL, b, NULL); + ok &= !memcmp(f, silence_frame[XOMBE_DMR], sizeof(f)) && !memcmp(b, dmr_silence_bits, sizeof(b)); + } + check(ok, "a D-STAR-only encoder writes DMR silence frames and their bits"); + } +#endif +} + +/* frames are the voice bits through the FEC, for both codecs, through the delay fill, tones, and voice */ +static void test_encoder_bits(void) +{ + static const xombe_enc_tone tones[] = {{128, 64}, {150, 90}, {40, 100}}; + static xombe_enc_mem ma, mb; + xombe_enc_cfg cfg; + xombe_enc *a, *b; + int16_t pcm[160]; + int n, k, same = 1; + xombe_enc_cfg_default(&cfg); + cfg.outputs = ALL_OUTPUTS; + a = xombe_enc_init(&ma, &cfg); + b = xombe_enc_init(&mb, &cfg); + for (n = 0; n < 100; n++) { + uint8_t f[2][XOMBE_FRAME_BYTES], bits[2][XOMBE_BITS_BYTES], g[XOMBE_FRAME_BYTES]; + const xombe_enc_tone *t = n % 17 == 5 ? &tones[(n / 17) % 3] : NULL; + test_signal(n, pcm); + same &= xombe_enc_frame(a, pcm, t, f[0], f[1]) == xombe_enc_frame_bits(b, pcm, t, bits[0], bits[1]); + for (k = 0; k < NCODECS; k++) { + xombe_fec_encode(codecs[k], bits[codecs[k]], g); + same &= !memcmp(g, f[codecs[k]], sizeof(g)); + } + } + check(same, "xombe_enc_frame equals xombe_fec_encode of xombe_enc_frame_bits, both codecs"); +} + +/* forced tone requests: ID and level ranges, refused calls write and consume nothing */ +static void test_encoder_tone(void) +{ + static const xombe_enc_tone bad[] = {{0, 90}, {4, 90}, {123, 90}, {127, 90}, {164, 90}, {-1, 90}, + {255, 90}, {5, -1}, {5, 128}, {129, 1000}}; + static const xombe_enc_tone good[] = {{5, 0}, {122, 127}, {128, 64}, {163, 1}, {144, 90}, {159, 90}}; + static xombe_enc_mem ma, mb; + xombe_enc_cfg cfg; + xombe_enc *a, *b; + int16_t pcm[160]; + uint8_t fa[2][XOMBE_FRAME_BYTES], fb[2][XOMBE_FRAME_BYTES], ba[2][XOMBE_BITS_BYTES]; + unsigned i, n; + int refused = 1, untouched = 1, same = 1, accepted = 1; + xombe_enc_cfg_default(&cfg); + cfg.outputs = ALL_OUTPUTS; + a = xombe_enc_init(&ma, &cfg); + b = xombe_enc_init(&mb, &cfg); + for (n = 0; n < 40; n++) { + for (i = 0; i < 160; i++) + pcm[i] = (int16_t)(3000.0f * sinf(0.05f * (float)(n * 160 + i)) + (float)((n * 160 + i) * 7919 % 61)); + if (n % 4 == 0) { + for (i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) { + memset(fa, 0xA5, sizeof(fa)); + memset(ba, 0xA5, sizeof(ba)); + refused &= xombe_enc_frame(a, pcm, &bad[i], fa[0], fa[1]) == -1 && + xombe_enc_frame_bits(a, pcm, &bad[i], ba[0], ba[1]) == -1; + untouched &= !memcmp(fa[0], fill, 9) && !memcmp(fa[1], fill, 9) && !memcmp(ba[0], fill, 7) && + !memcmp(ba[1], fill, 7); + } + } + same &= xombe_enc_frame(a, pcm, NULL, fa[0], fa[1]) == xombe_enc_frame(b, pcm, NULL, fb[0], fb[1]) && + !memcmp(fa, fb, sizeof(fa)); + } + check(refused, "xombe_enc_frame refuses IDs outside 5..122, 128..163 and levels outside 0..127"); + check(untouched, "a refused request writes nothing"); + check(same, "refused requests consume nothing"); + for (i = 0; i < sizeof(good) / sizeof(good[0]); i++) + accepted &= xombe_enc_frame(a, pcm, &good[i], fa[0], fa[1]) == 1; + check(accepted, "range ends and Knox IDs are accepted"); + check(xombe_enc_frame(a, pcm, &good[1], NULL, NULL) == 1 && + xombe_enc_frame_bits(a, pcm, &good[1], NULL, NULL) == 1, + "NULL outputs are accepted"); +} + +/* FNV-1a 32 of the DMR voice bits of 100 test_signal frames, open loop, per kernel backend */ +#if XOMBE_KERNELS_Q15 +#define OPEN_LOOP_HASH 0xb7487b6du +#else +#define OPEN_LOOP_HASH 0x99dd5352u +#endif + +static uint32_t fnv1a(uint32_t h, const uint8_t *p, size_t n) +{ + while (n--) + h = (h ^ *p++) * 16777619u; + return h; +} + +/* quantizer setting: range, open loop unchanged, D-STAR output independent of it */ +static void test_encoder_quant(void) +{ + static xombe_enc_mem m1, m2; + xombe_enc_cfg cfg; + xombe_enc *e1, *e2; + int16_t pcm[160]; + uint8_t a1[7], a2[7]; + uint32_t h = 2166136261u; + int n, differ = 0; + + xombe_enc_cfg_default(&cfg); + cfg.dmr_quant = 2; + check(xombe_enc_init(&m1, &cfg) == NULL, "an unknown quantizer is refused"); + cfg.dmr_quant = -1; + check(xombe_enc_init(&m1, &cfg) == NULL, "a negative quantizer is refused"); + cfg.dmr_quant = XOMBE_ENC_QUANT_OPEN; + e1 = xombe_enc_init(&m1, &cfg); + e2 = xombe_enc_init(&m2, NULL); + check(e1 && e2, "encoder init with each quantizer"); + if (!e1 || !e2) + return; + for (n = 0; n < 100; n++) { + test_signal(n, pcm); + if (xombe_enc_frame_bits(e1, pcm, NULL, a1, NULL) == 1) + h = fnv1a(h, a1, 7); + xombe_enc_frame_bits(e2, pcm, NULL, a2, NULL); + differ += memcmp(a1, a2, 7) != 0; + } + if (h != OPEN_LOOP_HASH) + fprintf(stderr, "open-loop hash 0x%08lx\n", (unsigned long)h); + check(h == OPEN_LOOP_HASH, "open-loop output unchanged"); + check(differ > 0, "closed-loop output differs from open loop"); +#if XOMBE_HAVE_DSTAR + { + uint8_t d1[XOMBE_FRAME_BYTES], d2[XOMBE_FRAME_BYTES], f1[XOMBE_FRAME_BYTES], f2[XOMBE_FRAME_BYTES]; + int same = 1; + cfg.outputs = XOMBE_ENC_DMR | XOMBE_ENC_DSTAR; + e1 = xombe_enc_init(&m1, &cfg); + cfg.dmr_quant = XOMBE_ENC_QUANT_CLOSED; + e2 = xombe_enc_init(&m2, &cfg); + for (n = 0, differ = 0; n < 100; n++) { + test_signal(n, pcm); + xombe_enc_frame(e1, pcm, NULL, f1, d1); + xombe_enc_frame(e2, pcm, NULL, f2, d2); + same &= !memcmp(d1, d2, sizeof(d1)); + differ += memcmp(f1, f2, sizeof(f1)) != 0; + } + check(same && differ > 0, "D-STAR output of a dual encoder independent of the quantizer"); + } +#endif +} + +#if XOMBE_HAVE_DSTAR +static void test_encoder_dstar(void) +{ + const uint8_t *silence = silence_frame[XOMBE_DMR]; + static xombe_enc_mem m1, m2, m3, m4; + static uint8_t a1[100][XOMBE_FRAME_BYTES]; + xombe_enc_cfg cfg; + xombe_enc *e1, *e2, *e3, *e4; + int16_t pcm[160]; + uint8_t a2[XOMBE_FRAME_BYTES], a3[XOMBE_FRAME_BYTES], d2[XOMBE_FRAME_BYTES], d3[XOMBE_FRAME_BYTES]; + uint8_t d4[XOMBE_FRAME_BYTES]; + int n, same = 1, nulls = 0, dtx_nulls = 0, silent = 1, r1 = 0, r2 = 0, r3 = 0; + int lag = XOMBE_ENC_DSTAR_DELAY - XOMBE_ENC_DELAY; + + xombe_enc_cfg_default(&cfg); + e1 = xombe_enc_init(&m1, &cfg); + cfg.outputs = XOMBE_ENC_DMR | XOMBE_ENC_DSTAR; + e2 = xombe_enc_init(&m2, &cfg); + cfg.outputs = XOMBE_ENC_DSTAR; + e3 = xombe_enc_init(&m3, &cfg); + cfg.dstar_dtx = 1; + e4 = xombe_enc_init(&m4, &cfg); + check(e1 && e2 && e3 && e4, "encoder init with each output set"); + if (!e1 || !e2 || !e3 || !e4) + return; + check(xombe_enc_delay(e1) == XOMBE_ENC_DELAY && xombe_enc_delay(e2) == XOMBE_ENC_DSTAR_DELAY && + xombe_enc_delay(e3) == XOMBE_ENC_DSTAR_DELAY && lag > 0, + "the D-STAR output adds look-ahead to both outputs"); + for (n = 0; n < 100; n++) { + test_signal(n, pcm); + r1 += xombe_enc_frame(e1, pcm, NULL, a1[n], NULL); + r2 += xombe_enc_frame(e2, pcm, NULL, a2, d2); + r3 += xombe_enc_frame(e3, pcm, NULL, a3, d3); + same &= !memcmp(n >= lag ? a1[n - lag] : silence, a2, XOMBE_FRAME_BYTES); + silent &= !memcmp(a3, silence, XOMBE_FRAME_BYTES); + if (n >= XOMBE_ENC_DSTAR_DELAY) + nulls += !memcmp(d2, dstar_null_frame, sizeof(d2)) + !memcmp(d3, dstar_null_frame, sizeof(d3)); + if (xombe_enc_frame(e4, pcm, NULL, NULL, d4)) + dtx_nulls += !memcmp(d4, dstar_null_frame, sizeof(d4)); + } + check(r1 == 100 - XOMBE_ENC_DELAY && r2 == 100 - XOMBE_ENC_DSTAR_DELAY && r3 == r2, + "both outputs share XOMBE_ENC_DSTAR_DELAY"); + check(same, "with D-STAR, the DMR output is the DMR-only one, delayed"); + check(silent, "an encoder without DMR writes DMR silence frames"); + check(nulls == 0, "with D-STAR DTX off, every D-STAR frame is a voice frame"); + check(dtx_nulls > 0, "with D-STAR DTX on, inactive frames are null frames"); +} +#endif +#endif + +#if XOMBE_HAVE_DSTAR +/* transcoder from codec c: init, lost frames, clean output, two instances agree, and the decision of the input is + the source decoder's */ +static void test_xc(enum xombe_codec c) +{ + enum xombe_codec to = c == XOMBE_DMR ? XOMBE_DSTAR : XOMBE_DMR; + static xombe_xc_mem x1, x2; + static xombe_dec_mem dm; + xombe_xc *x, *y; + xombe_xc_decision d; + xombe_dec *dd; + xombe_fec fs; + uint8_t fr[XOMBE_FRAME_BYTES], o1[XOMBE_FRAME_BYTES], o2[XOMBE_FRAME_BYTES], bits[XOMBE_BITS_BYTES]; + int16_t pcm[160]; + int n, agree = 1, clean = 1, decided = 1, lost_ok = 1, outs = 1; + x = xombe_xc_init(&x1, c); + if (c == XOMBE_DSTAR && !XOMBE_HAVE_ENCODER) { + checkc(x == NULL, c, "transcoder from D-STAR needs the encoder"); + return; + } + y = xombe_xc_init(&x2, c); + dd = xombe_dec_init(&dm, c); + checkc(x == (xombe_xc *)&x1 && y != NULL, c, "transcoder handle is the caller's memory"); + checkc(xombe_xc_size() <= XOMBE_XC_SIZE, c, "transcoder size within XOMBE_XC_SIZE"); + checkc(xombe_xc_init(NULL, c) == NULL, c, "transcoder init rejects NULL"); + xombe_xc_decision_get(x, &d); + checkc(d.in.e0 == -1 && d.in.e1 == -1 && d.in.mute_src == -1, c, "transcoder decision before the first frame"); + checkc(xombe_xc_frame(x, silence_frame[c], 0, o1) == 1 && xombe_xc_frame(y, silence_frame[c], 0, o2) == 1, c, + "transcoder takes a silence frame"); + xombe_dec_frame(dd, silence_frame[c], 0, pcm); + xombe_xc_decision_get(x, &d); + checkc(d.in.cls == XOMBE_CLASS_SILENCE && d.out == (c == XOMBE_DMR ? XOMBE_XC_OUT_VOICE : XOMBE_XC_OUT_SILENCE), + c, "a silence frame transcodes as a D-STAR all-unvoiced voice frame or a DMR silence frame"); + xombe_fec_init(&fs, to); + for (n = 0; n < 300; n++) { + unsigned flags = n % 37 == 5 ? XOMBE_FLAG_LOST : 0; + xombe_fec_stats st; + xombe_decision r; + stream_frame(c, n, fr); + agree &= xombe_xc_frame(x, flags ? NULL : fr, flags, o1) == 1; + agree &= xombe_xc_frame(y, fr, flags, o2) == 1 && !memcmp(o1, o2, sizeof(o1)); + xombe_fec_decode(&fs, o1, bits, &st); + clean &= st.eps0 == 0 && st.eps1 == 0; + xombe_xc_decision_get(x, &d); + if (flags) + lost_ok &= d.in.cls == XOMBE_CLASS_ERASURE && d.in.conceal != XOMBE_CONCEAL_NONE && d.in.e0 == -1 && + !d.in.bf && !d.in.hb; + xombe_dec_frame(dd, fr, flags, pcm); + xombe_dec_decision_get(dd, &r); + decided &= d.in.cls == r.cls && d.in.conceal == r.conceal && d.in.run == r.run && + d.in.mute_src == r.mute_src && d.in.e0 == r.e0 && d.in.e1 == r.e1 && d.in.bf == r.bf && + d.in.hb == r.hb; + if (c == XOMBE_DMR) + outs &= d.out == XOMBE_XC_OUT_VOICE || d.out == XOMBE_XC_OUT_TONE || d.out == XOMBE_XC_OUT_KNOX || + d.out == XOMBE_XC_OUT_RESEND; + else + outs &= d.out == XOMBE_XC_OUT_VOICE || d.out == XOMBE_XC_OUT_PULSE || d.out == XOMBE_XC_OUT_TONE || + d.out == XOMBE_XC_OUT_SILENCE; + } + checkc(agree, c, "two transcoders agree, a lost frame's input is not read"); + checkc(clean, c, "transcoder output frames are clean codewords of the other codec"); + checkc(lost_ok, c, "decision of a lost frame: erasure, concealed, no error counts"); + checkc(decided, c, "the transcoder's input decision is the source decoder's"); + checkc(outs, c, "output classes are those of its direction"); + checkc(xombe_xc_init_shared(NULL, c, &x2) == NULL && xombe_xc_init_shared(&x2, c, NULL) == NULL, c, + "shared init rejects NULL memory or workspace"); +} + +static void test_xc_codecs(void) +{ + static xombe_xc_mem m; + check(xombe_xc_init(&m, (enum xombe_codec)7) == NULL, "transcoder init refuses an unknown codec"); +#if XOMBE_HAVE_ENCODER + { + /* two transcoders on one workspace, interleaved, equal two with their own */ + static xombe_xc_mem c1, r1; + static xombe_qws_mem ws; + static xombe_xc_shared_mem c2, r2; + xombe_xc *ca = xombe_xc_init(&c1, XOMBE_DMR), *ra = xombe_xc_init(&r1, XOMBE_DSTAR), *cb, *rb; + uint8_t fr[XOMBE_FRAME_BYTES], o1[XOMBE_FRAME_BYTES], o2[XOMBE_FRAME_BYTES], q1[XOMBE_FRAME_BYTES]; + uint8_t q2[XOMBE_FRAME_BYTES]; + int n, same = 1; + cb = xombe_xc_init_shared(&c2, XOMBE_DMR, &ws); + rb = xombe_xc_init_shared(&r2, XOMBE_DSTAR, &ws); + check(cb != NULL && rb != NULL, "shared init in XOMBE_XC_SHARED_SIZE"); + for (n = 0; cb && rb && n < 200; n++) { + stream_frame(XOMBE_DMR, n, fr); + xombe_xc_frame(ca, fr, 0, o1); + xombe_xc_frame(cb, fr, 0, o2); + xombe_xc_frame(ra, o1, 0, q1); + xombe_xc_frame(rb, o2, 0, q2); + same &= !memcmp(o1, o2, sizeof(o1)) && !memcmp(q1, q2, sizeof(q1)); + } + check(same, "transcoders sharing a workspace equal transcoders with their own"); + } +#endif +} +#endif + +int main(void) +{ + int k; + check(xombe_version() == XOMBE_VERSION, "library version matches the header"); + setup_frames(); + test_codecs(); + for (k = 0; k < NCODECS; k++) { + test_fec(codecs[k]); + test_decoder(codecs[k]); + test_decoder_bits(codecs[k]); + test_tone_frames(codecs[k]); +#if XOMBE_HAVE_DSTAR + test_xc(codecs[k]); +#endif + } +#if XOMBE_HAVE_DSTAR + test_xc_codecs(); +#endif +#if XOMBE_HAVE_ENCODER + test_encoder(); + test_encoder_absent(); + test_encoder_bits(); + test_encoder_tone(); + test_encoder_quant(); +#if XOMBE_HAVE_DSTAR + test_encoder_dstar(); +#endif +#endif + printf("API: %d/%d checks passed\n", checks - failures, checks); + return failures ? 1 : 0; +} diff --git a/xombe/test/test_dstar_refs.c b/xombe/test/test_dstar_refs.c new file mode 100644 index 0000000..9f7b98d --- /dev/null +++ b/xombe/test/test_dstar_refs.c @@ -0,0 +1,223 @@ +/* checks a D-STAR reference set is complete and well formed: every file in MANIFEST + exists with its size, every record file parses, and the per-clip files agree on the frame counts + tests the harness and the references, not the codec + + test_dstar_refs DIR */ +#include +#include +#include +#include "dstar_ref.h" + +#define MAX_FILES 512 + +static char names[MAX_FILES][128]; +static int nfiles; +static int failures; + +static void bad(const char *what, const char *name) +{ + fprintf(stderr, "FAIL %s: %s\n", name, what); + failures++; +} + +static int has(const char *name) +{ + int k; + for (k = 0; k < nfiles; k++) + if (!strcmp(names[k], name)) + return 1; + return 0; +} + +static int ends(const char *s, const char *suffix) +{ + size_t n = strlen(s), m = strlen(suffix); + return n >= m && !strcmp(s + n - m, suffix); +} + +static long file_size(const char *dir, const char *name) +{ + char path[1024]; + FILE *f; + long n; + if (snprintf(path, sizeof(path), "%s/%s", dir, name) >= (int)sizeof(path)) + return -1; + f = fopen(path, "rb"); + if (!f) + return -1; + fseek(f, 0, SEEK_END); + n = ftell(f); + fclose(f); + return n; +} + +/* parses every record, returns the record count, or -1 */ +static long records(const char *dir, const char *name) +{ + char path[1024]; + dsref r; + long n = 0; + int st; + if (snprintf(path, sizeof(path), "%s/%s", dir, name) >= (int)sizeof(path) || !dsref_open(&r, path)) + return -1; + if (!dsref_meta(&r, "stage")) + fprintf(stderr, "%s: no stage meta line\n", path), r.failed = 1; + while ((st = dsref_next(&r)) > 0) + n++; + if (!dsref_close(&r) || st < 0) + return -1; + return n; +} + +static long count_of(const char *dir, const char *clip, const char *suffix, long unit) +{ + char name[160]; + long n; + if (snprintf(name, sizeof(name), "%s%s", clip, suffix) >= (int)sizeof(name) || !has(name)) + return -2; + if (ends(name, ".txt.gz")) + return records(dir, name); + n = file_size(dir, name); + if (n < 0 || n % unit) { + bad("size is not a multiple of the unit", name); + return -1; + } + return n / unit; +} + +static void expect(const char *dir, const char *clip, const char *suffix, long unit, long want) +{ + long n = count_of(dir, clip, suffix, unit); + if (n == -2) + return; + if (n != want) { + char msg[96], name[160]; + if (snprintf(name, sizeof(name), "%s%s", clip, suffix) >= (int)sizeof(name)) + name[0] = 0; + snprintf(msg, sizeof(msg), "%ld units, expected %ld", n, want); + bad(msg, name); + } +} + +/* writes a record of every type with the C writer and reads it back */ +static void selftest(void) +{ + const char *path = "dstar_ref_selftest.txt"; + static const uint8_t bytes[3] = {0x9e, 0x8d, 0xff}, bits[5] = {1, 0, 1, 1, 0}; + static const double fv[3] = {-15.0, 0.125, 1e-7}; + static const long iv[2] = {-3, 123456}; + dsref_writer w; + dsref r; + int ok = dsref_wopen(&w, path, "selftest", "n:i x:f s:s h:x b:b iv:i* fv:f* e:f*", 0); + dsref_wi(&w, 7); + dsref_wf(&w, 0.1); + dsref_ws(&w, "voice"); + dsref_wx(&w, bytes, 3); + dsref_wb(&w, bits, 5); + dsref_wiv(&w, iv, 2); + dsref_wfv(&w, fv, 3); + dsref_wfv(&w, fv, 0); + dsref_wend(&w); + ok = dsref_wclose(&w) && ok; + if (ok && dsref_open(&r, path)) { + int cn = dsref_need(&r, "n", DSREF_INT), cx = dsref_need(&r, "x", DSREF_FLOAT); + int cs = dsref_need(&r, "s", DSREF_STR), ch = dsref_need(&r, "h", DSREF_HEX); + int cb = dsref_need(&r, "b", DSREF_BITS), ci = dsref_need(&r, "iv", DSREF_IVEC); + int cf = dsref_need(&r, "fv", DSREF_FVEC), ce = dsref_need(&r, "e", DSREF_FVEC); + ok = cn >= 0 && cx >= 0 && cs >= 0 && ch >= 0 && cb >= 0 && ci >= 0 && cf >= 0 && ce >= 0 && + dsref_next(&r) == 1 && dsref_i(&r, cn) == 7 && dsref_f(&r, cx) == 0.1 && + !strcmp(dsref_s(&r, cs), "voice") && dsref_len(&r, ch) == 3 && !memcmp(dsref_bytes(&r, ch), bytes, 3) && + dsref_len(&r, cb) == 5 && !memcmp(dsref_bytes(&r, cb), bits, 5) && dsref_len(&r, ci) == 2 && + dsref_iv(&r, ci)[1] == 123456 && dsref_len(&r, cf) == 3 && dsref_fv(&r, cf)[0] == -15.0 && + dsref_fv(&r, cf)[2] == 1e-7 && dsref_len(&r, ce) == 0 && dsref_next(&r) == 0 && + !strcmp(dsref_meta(&r, "stage"), "selftest"); + ok = dsref_close(&r) && ok; + } else { + ok = 0; + } + if (!ok) + bad("writer/reader round trip", path); + remove(path); +} + +int main(int argc, char **argv) +{ + const char *dir; + char path[1024], line[512]; + FILE *mf; + int k, nrecfiles = 0, nclips = 0; + if (argc != 2) { + fprintf(stderr, "usage: test_dstar_refs DIR\n"); + return 2; + } + dir = argv[1]; + selftest(); + if (snprintf(path, sizeof(path), "%s/MANIFEST", dir) >= (int)sizeof(path)) + return 2; + mf = fopen(path, "r"); + if (!mf) { + fprintf(stderr, "%s: cannot open\n", path); + return 1; + } + while (fgets(line, sizeof(line), mf)) { + char sha[80], name[128]; + long size; + if (line[0] == '#') + continue; + if (sscanf(line, "%79s %ld %127s", sha, &size, name) != 3 || nfiles == MAX_FILES) { + bad("malformed MANIFEST line", line); + continue; + } + snprintf(names[nfiles++], sizeof(names[0]), "%s", name); + if (file_size(dir, name) != size) + bad("missing or size differs from MANIFEST", name); + if (ends(name, ".txt.gz")) { + nrecfiles++; + if (records(dir, name) <= 0) + bad("unreadable or empty record file", name); + } + } + fclose(mf); + + /* per-clip consistency, keyed by the stream files */ + for (k = 0; k < nfiles; k++) { + char clip[128]; + size_t n = strlen(names[k]); + if (ends(names[k], ".dstar") && !ends(names[k], ".xc.dstar")) { + long nf; + memcpy(clip, names[k], n - 6); + clip[n - 6] = 0; + nf = count_of(dir, clip, ".dstar", 9); + if (nf <= 0) { + bad("empty D-Star stream", names[k]); + continue; + } + nclips++; + expect(dir, clip, ".fec.txt.gz", 1, nf); + expect(dir, clip, ".deq.txt.gz", 1, nf); + expect(dir, clip, ".dec.txt.gz", 1, nf); + expect(dir, clip, ".half.txt.gz", 1, 2 * nf); + expect(dir, clip, ".dec.raw", 2 * 160, nf); + expect(dir, clip, ".xrev.txt.gz", 1, nf); + expect(dir, clip, ".xrev.r33", 9, nf); + expect(dir, clip, ".enc.txt.gz", 1, nf); + if (has(strcat(strcpy(path, clip), ".in.raw"))) { + long ns = file_size(dir, path) / 2; + if ((ns + 159) / 160 != nf) + bad("encoder frame count is not ceil(samples / 160)", path); + } + } else if (ends(names[k], ".r33") && !ends(names[k], ".xrev.r33")) { + long nf; + memcpy(clip, names[k], n - 4); + clip[n - 4] = 0; + nf = count_of(dir, clip, ".r33", 9); + nclips++; + expect(dir, clip, ".xc.txt.gz", 1, nf); + expect(dir, clip, ".xc.dstar", 9, nf); + } + } + printf("%d files, %d record files, %d streams checked, %d failures\n", nfiles, nrecfiles, nclips, failures); + if (!nrecfiles || !nclips) + return 1; + return failures ? 1 : 0; +} diff --git a/xombe/test/test_dstar_tables.c b/xombe/test/test_dstar_tables.c new file mode 100644 index 0000000..ca3785c --- /dev/null +++ b/xombe/test/test_dstar_tables.c @@ -0,0 +1,144 @@ +#include +#include +#include +#include "../src/dstar/dstar_internal.h" +#include "dstar_ref.h" + +/* generated D-STAR tables (scripts/gen_dstar_tables.py) against the model's tables_dstar record (vectors/dstar): + every float within a float rounding of the double, the masks, VUV0, and LMPRBL exact, the pitch grid against + its closed form, and the table sets' shapes */ + +static int failures, checks; + +static void check(int ok, const char *what, long i) +{ + checks++; + if (!ok) { + failures++; + fprintf(stderr, "FAIL %s (item %ld)\n", what, i); + } +} + +static int close_to(float t, double v) +{ + return fabs((double)t - v) <= 6e-8 * (fabs(v) > 1.0 ? fabs(v) : 1.0); +} + +static void floats(const char *what, long row, const float *t, int n, const double *v, int nv) +{ + int i; + check(n == nv, what, row); + for (i = 0; i < n && i < nv; i++) + check(close_to(t[i], v[i]), what, row * 100 + i); +} + +static void bytes(const char *what, long row, const unsigned char *t, int n, const double *v, int nv) +{ + int i; + check(n == nv, what, row); + for (i = 0; i < n && i < nv; i++) + check((double)t[i] == v[i], what, row * 1000 + i); +} + +int main(int argc, char **argv) +{ + static const char *const hoc_name[4] = {"HOC1", "HOC2", "HOC3", "HOC4"}; + static const char *const ok_hoc_name[4] = {"ok_HOC1", "ok_HOC2", "ok_HOC3", "ok_HOC4"}; + const xombe_amp_tables *ts = &xombe__amp_dstar; + double p0 = 0, p1 = 0; + int seen[32], st, k, c_tab, c_row, c_v; + char path[1024]; + dsref r; + if (argc != 2) { + fprintf(stderr, "usage: test_dstar_tables VECTORS/dstar\n"); + return 2; + } + snprintf(path, sizeof(path), "%s/tables_dstar.txt.gz", argv[1]); + if (!dsref_open(&r, path)) + return 1; + c_tab = dsref_need(&r, "tab", DSREF_STR); + c_row = dsref_need(&r, "row", DSREF_INT); + c_v = dsref_need(&r, "v", DSREF_FVEC); + memset(seen, 0, sizeof(seen)); + while (c_v >= 0 && (st = dsref_next(&r)) > 0) { + const char *t = dsref_s(&r, c_tab); + long row = dsref_i(&r, c_row); + const double *v = dsref_fv(&r, c_v); + int n = dsref_len(&r, c_v); + if (!strcmp(t, "p0")) + p0 = v[0], seen[0]++; + else if (!strcmp(t, "p1")) + p1 = v[0], seen[1]++; + else if (!strcmp(t, "rho")) + check(close_to(XOMBE_DS_RHO, v[0]) && ts->rho == XOMBE_DS_RHO, "rho", 0), seen[2]++; + else if (!strcmp(t, "grho")) + check(close_to(XOMBE_DS_GRHO, v[0]) && ts->grho == XOMBE_DS_GRHO, "grho", 0), seen[3]++; + else if (!strcmp(t, "DG") && row < 64) + floats("DG", row, &xombe__ds_dg[row], 1, v, n), seen[4]++; + else if (!strcmp(t, "PRBA24") && row < 512) + floats("PRBA24", row, xombe__ds_prba24[row], 3, v, n), seen[5]++; + else if (!strcmp(t, "PRBA58") && row < 128) + floats("PRBA58", row, xombe__ds_prba58[row], 4, v, n), seen[6]++; + else if (!strcmp(t, "VUV0") && row < 16) + bytes("VUV0", row, xombe__ds_vuv[row], 8, v, n), seen[7]++; + else if (!strcmp(t, "LMPRBL") && row < 57) + bytes("LMPRBL", row, ts->blk[row], 4, v, n), seen[8]++; + else if (!strcmp(t, "ok_DG")) + bytes("ok_DG", row, ts->ok_dg, ts->n_dg, v, n), seen[9]++; + else if (!strcmp(t, "ok_PRBA24")) + bytes("ok_PRBA24", row, ts->ok_prba24, ts->n_prba24, v, n), seen[10]++; + else if (!strcmp(t, "ok_PRBA58")) + bytes("ok_PRBA58", row, ts->ok_prba58, ts->n_prba58, v, n), seen[11]++; + else { + for (k = 0; k < 4; k++) { + if (!strcmp(t, hoc_name[k]) && row < ts->n_hoc[k]) { + floats(hoc_name[k], row, ts->hoc[k] + 4 * row, 4, v, n), seen[12 + k]++; + break; + } + if (!strcmp(t, ok_hoc_name[k])) { + bytes(ok_hoc_name[k], row, ts->ok_hoc[k], ts->n_hoc[k], v, n), seen[16 + k]++; + break; + } + } + check(k < 4, t, row); + } + } + if (!dsref_close(&r)) + failures++; + { + static const int want[20] = {1, 1, 1, 1, 64, 512, 128, 16, 57, 1, 1, 1, 16, 16, 16, 8, 1, 1, 1, 1}; + for (k = 0; k < 20; k++) + check(seen[k] == want[k], "row count", k); + } + check(close_to(XOMBE_DS_P0, p0) && close_to(XOMBE_DS_P1, p1), "p0 p1", 0); + for (k = 0; k < XOMBE_DS_B0_COUNT; k++) { + double f0 = pow(2.0, p0 + p1 * (k + 0.5)); + int L = (int)floor(0.4627 / f0); + L = L < 9 ? 9 : L > XOMBE_LMAX ? XOMBE_LMAX : L; + check(close_to(xombe__ds_w0[k], f0), "W0", k); + check(xombe__ds_lt[k] == L, "LTAB", k); + } + check(ts->n_dg == 64 && ts->n_prba24 == 512 && ts->n_prba58 == 128, "table set sizes", 0); + check(xombe__ds_tone_id[0] == 129 && xombe__ds_tone_id[16] == 160 && xombe__ds_tone_id[37] == 5 && + xombe__ds_tone_id[154] == 122 && xombe__ds_tone_id[20] == XOMBE_DS_TONE_NONE && + xombe__ds_tone_id[155] == XOMBE_DS_TONE_NONE, "tone map", 0); + { /* the silence frame decodes cleanly to b0 124 and re-encodes to itself */ + static const uint8_t nf[9] = XOMBE_DS_NULL_FRAME; + xombe_ds_frame f; + uint8_t o[9]; + xombe__ds_fec_decode(nf, &f); + check(f.ea == 0 && f.eb == 0 && f.b[0] == XOMBE_DS_B0_SILENCE && f.cls == XOMBE_DS_NULL, "null frame", 0); + check(xombe__ds_encode_fields(f.b, o) == 0 && !memcmp(o, nf, 9), "null frame encode", 0); + } + { /* out-of-range fields are clamped to their widths and still written */ + int lo[9] = {-1, -1, -1, -1, -1, -1, -1, -1, -1}, hi[9] = {999, 99, 99, 999, 999, 99, 99, 99, 99}; + int zero[9] = {0}, top[9] = {127, 15, 63, 511, 127, 15, 15, 15, 7}; + uint8_t o[9], want[9]; + xombe__ds_encode_fields(zero, want); + check(xombe__ds_encode_fields(lo, o) == -1 && !memcmp(o, want, 9), "fields clamped up to 0", 0); + xombe__ds_encode_fields(top, want); + check(xombe__ds_encode_fields(hi, o) == -1 && !memcmp(o, want, 9), "fields clamped down to their widths", 0); + } + printf("%d checks, %d failures\n", checks, failures); + return failures ? 1 : 0; +} diff --git a/xombe/test/test_enc_tone.c b/xombe/test/test_enc_tone.c new file mode 100644 index 0000000..e202342 --- /dev/null +++ b/xombe/test/test_enc_tone.c @@ -0,0 +1,570 @@ +#include +#include +#include +#include +#include "tone_fit.h" +#if XOMBE_HAVE_DSTAR +#include "../src/dstar/dstar_enc.h" +#endif + +/* forced tones (xombe_enc_frame): position, decoded tone, unchanged analysis + state, no leak into later frames, and the D-STAR mirror */ + +#define MAXF 4000 +#define RUN 30 /* forced frames in a row for the decode measurements */ +#define FIT_AT 12 + +static int failures, checks; + +static void check(int ok, const char *what) +{ + checks++; + if (!ok) { + failures++; + printf("FAIL: %s\n", what); + } +} + +static int16_t *load_raw(const char *dir, const char *name, int *frames) +{ + char path[4096]; + FILE *f; + long size; + int16_t *x; + snprintf(path, sizeof(path), "%s/%s", dir, name); + f = fopen(path, "rb"); + if (!f) { + perror(path); + exit(2); + } + fseek(f, 0, SEEK_END); + size = ftell(f); + fseek(f, 0, SEEK_SET); + x = malloc((size_t)size + 2); + *frames = (int)(fread(x, sizeof(int16_t), (size_t)size / 2, f) / 160); + fclose(f); + if (*frames > MAXF) + *frames = MAXF; + return x; +} + +/* per input frame: requested tone (id 0: none) and the outputs that belong to it */ +typedef struct { + int frames; + xombe_enc_tone req[MAXF]; + uint8_t a2[MAXF][7]; + uint8_t ds[MAXF][9]; +} run; + +static xombe_enc_mem mem_a, mem_b; + +/* xombe_enc_frame with DMR voice bits and a D-STAR frame (ds NULL: none) */ +static int enc_frame(xombe_enc *e, const int16_t *pcm, const xombe_enc_tone *t, uint8_t a2[7], uint8_t *ds) +{ + uint8_t dsb[7]; + int got = xombe_enc_frame_bits(e, pcm, t, a2, ds ? dsb : NULL); + if (ds) + xombe_fec_encode(XOMBE_DSTAR, dsb, ds); + return got; +} + +/* encodes r->frames of x with r->req, flushing so every input frame has its output */ +static void encode(const xombe_enc_cfg *cfg, const int16_t *x, run *r) +{ + static const int16_t zeros[160]; + xombe_enc *e = xombe_enc_init(&mem_a, cfg); + int dual = (cfg->outputs & ~XOMBE_ENC_DMR) != 0, delay = xombe_enc_delay(e), c; + memset(r->a2, 0, sizeof(r->a2)); + memset(r->ds, 0, sizeof(r->ds)); + for (c = 0; c < r->frames + delay; c++) { + const int16_t *pcm = c < r->frames ? x + 160 * c : zeros; + const xombe_enc_tone *t = c < r->frames && r->req[c].id ? &r->req[c] : NULL; + uint8_t a[7], d[9] = {0}; + int got; + got = enc_frame(e, pcm, t, a, dual ? d : NULL); + if (got == 1) { + memcpy(r->a2[c - delay], a, 7); + memcpy(r->ds[c - delay], d, 9); + } + } +} + +static void tone_bytes(int id, int ad, uint8_t bytes[7]) +{ + uint8_t d[49]; + xombe__tone_frame_bits(id, ad, d); + xombe__pack49(d, bytes); +} + +static int is_tone(const uint8_t bytes[7]) +{ + uint8_t d[49]; + xombe__unpack49(bytes, d); + return xombe__frame_class(d) == XOMBE_CLASS_TONE; +} + +#if XOMBE_HAVE_DSTAR +static int ds_code(int id) +{ + int T; + for (T = 0; T < 256; T++) + if (xombe__ds_tone_id[T] == id) + return T; + return -1; +} + +static int ds_is_tone(const uint8_t f[9]) +{ + xombe_ds_frame fr; + xombe__ds_fec_decode(f, &fr); + return fr.cls == XOMBE_DS_TONE; +} +#endif + +static xombe_enc_cfg cfg_of(unsigned outputs, int tones) +{ + xombe_enc_cfg c; + xombe_enc_cfg_default(&c); + c.outputs = outputs; + c.tones = tones; + return c; +} + +static void label(char what[160], unsigned outputs, int tones, const char *s) +{ + const char *o = outputs == XOMBE_ENC_DMR ? "AMBE+2" : outputs == XOMBE_ENC_DSTAR ? "D-STAR" : "dual"; + snprintf(what, 160, "%s, tones %s: %s", o, tones ? "on" : "off", s); +} + +/* forced frames land at their own input's output, in both outputs, and nothing else turns into a tone */ +static void test_position(const int16_t *x, int frames, unsigned outputs, int tones) +{ + static run plain, forced; + static const int at[][3] = {{40, 20, 90}, {41, 129, 70}, {77, 150, 100}, {120, 5, 0}, + {121, 122, 127}, {122, 163, 3}, {200, 144, 60}, {201, 160, 110}}; + xombe_enc_cfg cfg = cfg_of(outputs, tones); + int i, n = (int)(sizeof(at) / sizeof(at[0])), first = at[0][0], pos_ok = 1, before_ok = 1, leak = 0; + int plain_tones = 0; + char what[160]; + memset(&plain, 0, sizeof(plain)); + plain.frames = frames; + encode(&cfg, x, &plain); + forced = plain; + for (i = 0; i < n; i++) { + forced.req[at[i][0]].id = at[i][1]; + forced.req[at[i][0]].ad = at[i][2]; + } + encode(&cfg, x, &forced); + for (i = 0; i < frames; i++) { + plain_tones += is_tone(plain.a2[i]); + if (forced.req[i].id) { + uint8_t want[7]; + tone_bytes(forced.req[i].id, forced.req[i].ad, want); + if (outputs & XOMBE_ENC_DMR) + pos_ok &= !memcmp(forced.a2[i], want, 7); +#if XOMBE_HAVE_DSTAR + if (outputs & XOMBE_ENC_DSTAR) { + int T = ds_code(forced.req[i].id); + int ad = forced.req[i].ad; + xombe_ds_frame fr; + xombe__ds_fec_decode(forced.ds[i], &fr); + if (T >= 0) + pos_ok &= fr.cls == XOMBE_DS_TONE && fr.tid == forced.req[i].id && fr.AD == (ad < 8 ? 8 : ad); + else + pos_ok &= fr.cls == XOMBE_DS_VOICE; + } +#endif + } else { + leak += is_tone(forced.a2[i]); +#if XOMBE_HAVE_DSTAR + if (outputs & XOMBE_ENC_DSTAR) + leak += ds_is_tone(forced.ds[i]); +#endif + } + if (i < first) + before_ok &= !memcmp(plain.a2[i], forced.a2[i], 7) && !memcmp(plain.ds[i], forced.ds[i], 9); + } + label(what, outputs, tones, "speech input without detected tones"); + check(plain_tones == 0, what); + label(what, outputs, tones, "each forced tone is its input frame's output"); + check(pos_ok, what); + label(what, outputs, tones, "frames before the first request are unchanged"); + check(before_ok, what); + label(what, outputs, tones, "no tone frame without a request"); + check(leak == 0, what); +} + +/* a forced tone inside a detected tone run changes nothing but its own frame: tone frames leave the AMBE+2 + predictor at class tone and the D-STAR mirror alone, so the rest of the stream is bit-identical unless the + request leaked into the detector's confirmation and hold */ +static void test_in_tone_run(const int16_t *x, int frames, unsigned outputs) +{ + static run plain, forced; + xombe_enc_cfg cfg = cfg_of(outputs, 1); + int i, len = 0, placed = 0, same = 1, j; + memset(&plain, 0, sizeof(plain)); + plain.frames = frames; + encode(&cfg, x, &plain); + forced = plain; + for (i = 0; i < frames && placed < 6; i++) { + int both = is_tone(plain.a2[i]); +#if XOMBE_HAVE_DSTAR + if (outputs & XOMBE_ENC_DSTAR) + both &= ds_is_tone(plain.ds[i]); +#endif + len = both ? len + 1 : 0; + if (len == 5) { + /* last frame of a natural run's first five, also the frame after its end when the run is short */ + forced.req[i - 2].id = 130 + placed; + forced.req[i - 2].ad = 80; + placed++; + } + } + check(placed >= 3, "tone input has detected tone runs"); + encode(&cfg, x, &forced); + for (i = 0; i < frames; i++) { + if (forced.req[i].id) + continue; + same &= !memcmp(plain.a2[i], forced.a2[i], 7); + for (j = 0; j < 9; j++) + same &= plain.ds[i][j] == forced.ds[i][j]; + } + check(same, outputs & XOMBE_ENC_DSTAR ? "dual: a forced tone in a tone run leaves every other frame unchanged" + : "AMBE+2: a forced tone in a tone run leaves every other frame unchanged"); +} + +#define SAME_FIELD(a, b, f) (!memcmp(&(a)->f, &(b)->f, sizeof((a)->f))) + +/* VAD, hangover, noise and comfort-noise tracking, and the tone detector's state */ +static int same_analysis(const struct xombe_enc *a, const struct xombe_enc *b) +{ + size_t lo = offsetof(struct xombe_enc, vad_nl), hi = offsetof(struct xombe_enc, tone_spec); + int same = !memcmp((const char *)a + lo, (const char *)b + lo, hi - lo) && a->tone_prev_id == b->tone_prev_id && + a->tone_confirmed == b->tone_confirmed && a->tone_hold_used == b->tone_hold_used && + a->tone_last_id == b->tone_last_id && a->tone_last_ad == b->tone_last_ad && a->p_prev == b->p_prev; +#if XOMBE_HAVE_DSTAR + if (a->cfg.outputs & XOMBE_ENC_DSTAR) { + const xombe_ds_enc *da = XOMBE_DS_ENC(a), *db = XOMBE_DS_ENC(b); + same &= SAME_FIELD(da, db, ns_mem) && SAME_FIELD(&da->tones, &db->tones, detected) && + SAME_FIELD(&da->tones, &db->tones, run) && SAME_FIELD(&da->tones, &db->tones, confirmed) && + SAME_FIELD(&da->tones, &db->tones, held) && da->tones.hold_left == db->tones.hold_left && + SAME_FIELD(&da->tones, &db->tones, level_db); + } +#endif + return same; +} + +/* lockstep with an unforced encoder: up to and including the call that emits the forced frame, the analysis + state is the same, a request changes only the output and the prediction memory */ +static void test_state(const int16_t *x, unsigned outputs, int tones, int dtx, int start) +{ + char what[160]; + xombe_enc_cfg cfg = cfg_of(outputs, tones); + xombe_enc *a, *b; + xombe_enc_tone t = {150, 90}; + int c, same = 1, delay; + cfg.dmr_dtx = dtx; + a = xombe_enc_init(&mem_a, &cfg); + b = xombe_enc_init(&mem_b, &cfg); + delay = xombe_enc_delay(a); + for (c = 0; c <= start + delay + 3; c++) { + const xombe_enc_tone *r = c >= start && c < start + 4 ? &t : NULL; + uint8_t a2[9], ds[9]; + xombe_enc_frame(a, x + 160 * c, r, a2, ds); + xombe_enc_frame(b, x + 160 * c, NULL, a2, ds); + same &= same_analysis(a, b); + } + label(what, outputs, tones, "a request leaves VAD, noise, comfort-noise, and tone detector state as without it"); + check(same, what); +} + +static void fit(const double *x, int id, double *freq, double *amp, int *nf) +{ + float lo, hi; + *nf = xombe__tone_freqs(id, &lo, &hi); + freq[0] = lo; + freq[1] = hi; + search_freqs(x, freq, *nf, *nf == 1 ? 0.005 : 0.05); + sinusoid_fit(x, FIT_LEN, freq, *nf, amp); +} + +/* frequency and level errors of a fitted tone, the T5 limits */ +static int tone_ok(int id, int ad, const double *freq, const double *amp, int nf, double *worst_df, double *worst_dl) +{ + float lo, hi; + double nominal[2]; + int c, ok = 1; + xombe__tone_freqs(id, &lo, &hi); + nominal[0] = lo; + nominal[1] = hi; + for (c = 0; c < nf; c++) { + double df = nf == 1 ? fabs(freq[c] - nominal[c]) : fabs(freq[c] - nominal[c]) / nominal[c]; + double dl = 20.0 * log10(amp[c] / 32768.0 + 1e-30) - expected_db(ad, freq[c]); + ok &= nf == 1 ? df <= 0.1 : df <= (id >= 160 ? 0.04 : 0.01); + ok &= fabs(dl) <= 0.5; + if (nf == 2 && df > *worst_df) + *worst_df = df; + if (fabs(dl) > fabs(*worst_dl)) + *worst_dl = dl; + } + return ok; +} + +/* RUN forced frames in speech, decoded through xombe_dec (and xombe_dsd), measured FIT_AT frames into the run */ +static void test_decode(const int16_t *x, int frames, unsigned outputs) +{ + static run r; + static double y[MAXF * 160]; + static const int ids[] = {5, 20, 64, 122, 128, 129, 143, 144, 150, 156, 159, 160, 161, 163}; + static const int ads[] = {40, 90, 115}; + const int start = 60; + xombe_enc_cfg cfg = cfg_of(outputs, 1); + double wdf = 0.0, wdl = 0.0; + int ii, ai, i, ok = 1, cases = 0; +#if XOMBE_HAVE_DSTAR + double wdf_ds = 0.0, wdl_ds = 0.0, knox_df = 0.0, knox_res = 0.0; + int ok_ds = 1, knox_voice = 1; +#endif + for (ii = 0; ii < (int)(sizeof(ids) / sizeof(ids[0])); ii++) { + for (ai = 0; ai < 3; ai++) { + int id = ids[ii], ad = ads[ai], nf; + double freq[2], amp[2]; + xombe_dec dec; + memset(&r, 0, sizeof(r)); + r.frames = start + RUN + 1 < frames ? start + RUN + 1 : frames; + for (i = start; i < start + RUN; i++) { + r.req[i].id = id; + r.req[i].ad = ad; + } + encode(&cfg, x, &r); + xombe_dec_set_noise(xombe_dec_init(&dec, XOMBE_DMR), XOMBE_NOISE_CONFORMANCE, 0); + for (i = 0; i < start + RUN; i++) { + int16_t pcm[160]; + int k; + xombe_dec_frame_bits(&dec, r.a2[i], 0, pcm); + for (k = 0; k < 160; k++) + y[i * 160 + k] = pcm[k]; + } + fit(y + (start + FIT_AT) * 160, id, freq, amp, &nf); + if (!tone_ok(id, ad, freq, amp, nf, &wdf, &wdl)) { + ok = 0; + printf(" AMBE+2 id %d AD %d: %.2f/%.2f Hz\n", id, ad, freq[0], freq[1]); + } + cases++; +#if XOMBE_HAVE_DSTAR + if (outputs & XOMBE_ENC_DSTAR) { + static xombe_dec_mem dm; + xombe_dec *dsd = xombe_dec_init(&dm, XOMBE_DSTAR); + int voice = 1; + xombe_dec_set_noise(dsd, XOMBE_NOISE_CONFORMANCE, 0); + for (i = 0; i < start + RUN; i++) { + int16_t pcm[160]; + xombe_decision dc; + int k; + xombe_dec_frame(dsd, r.ds[i], 0, pcm); + xombe_dec_decision_get(dsd, &dc); + if (i >= start) + voice &= dc.cls == XOMBE_CLASS_VOICE; + for (k = 0; k < 160; k++) + y[i * 160 + k] = pcm[k]; + } + if (ds_code(id) < 0) { + /* Knox: voice frames with the two tones on the nearest D-STAR harmonics */ + const double *seg = y + (start + FIT_AT) * 160; + double e = 0.0, res, df = 0.0; + float lo, hi; + int c2; + xombe__tone_freqs(id, &lo, &hi); + fit(seg, id, freq, amp, &nf); + for (i = 0; i < FIT_LEN; i++) + e += seg[i] * seg[i]; + res = sinusoid_fit(seg, FIT_LEN, freq, nf, amp) / e; + for (c2 = 0; c2 < 2; c2++) { + double d = fabs(freq[c2] - (c2 ? hi : lo)) / (c2 ? hi : lo); + df = d > df ? d : df; + } + knox_df = df > knox_df ? df : knox_df; + knox_res = res > knox_res ? res : knox_res; + if (!voice || df > 0.03 || res > 0.6) { + knox_voice = 0; + printf(" D-STAR Knox id %d AD %d: voice %d, frequency error %.2f%%, residual %.2f\n", id, ad, + voice, 100.0 * df, res); + } + } else { + fit(y + (start + FIT_AT) * 160, id, freq, amp, &nf); + if (!tone_ok(id, ad, freq, amp, nf, &wdf_ds, &wdl_ds)) { + ok_ds = 0; + printf(" D-STAR id %d AD %d: %.2f/%.2f Hz, %.1f/%.1f\n", id, ad, freq[0], freq[1], + 20.0 * log10(amp[0] / 32768.0), expected_db(ad, freq[0])); + } + } + } +#endif + } + } + printf("forced tones (%s): %d cases, AMBE+2 worst dual frequency error %.2f%%, worst level error %+.3f dB\n", + outputs & XOMBE_ENC_DSTAR ? "dual" : "AMBE+2", cases, 100.0 * wdf, wdl); + check(ok, "forced tones decode at their frequency and level (T5 limits)"); +#if XOMBE_HAVE_DSTAR + if (outputs & XOMBE_ENC_DSTAR) { + printf("forced tones, D-STAR: worst dual frequency error %.2f%%, worst level error %+.3f dB\n", 100.0 * wdf_ds, + wdl_ds); + check(ok_ds, "forced D-STAR tones decode at their frequency and level (T5 limits)"); + printf("forced Knox tones, D-STAR: worst frequency error %.2f%%, worst residual %.2f of the energy\n", + 100.0 * knox_df, knox_res); + check(knox_voice, "forced Knox tones are D-STAR voice frames carrying the tone"); + } +#endif +} + +/* the packers' frames are the forced encoder's, for every ID at levels 0..127 in steps of 7 and 127, and decode + as tone frames of that ID and level */ +static void test_packers(const int16_t *x, int frames, unsigned outputs) +{ + static run r; + static int16_t loop[MAXF * 160]; + xombe_enc_cfg cfg = cfg_of(outputs, 1); + int id, ad, i, n = 0, same = 1, decoded = 1; + memset(&r, 0, sizeof(r)); + for (i = 0; i < MAXF; i++) + memcpy(loop + 160 * i, x + 160 * (i % frames), sizeof(int16_t) * 160); + for (id = 5; id <= 163; id++) + for (ad = 0; ad <= 127 + 6; ad += 7) + if (xombe__tone_id_accepted(id) && n < MAXF) { + r.req[n].id = id; + r.req[n].ad = ad > 127 ? 127 : ad; + n++; + } + r.frames = n; + encode(&cfg, loop, &r); + for (i = 0; i < n; i++) { + static xombe_dec dec; + uint8_t a2[7], f[9], d[9], d49[49]; + int16_t pcm[160]; + xombe_decision dc; + xombe_fec fec; + int ok = xombe_tone_frame(XOMBE_DMR, r.req[i].id, r.req[i].ad, f) == 0, pid, pad; + xombe_fec_init(&fec, XOMBE_DMR); + xombe_fec_decode(&fec, f, a2, NULL); + if (outputs & XOMBE_ENC_DMR) + same &= ok && !memcmp(a2, r.a2[i], 7); + xombe_dec_set_noise(xombe_dec_init(&dec, XOMBE_DMR), XOMBE_NOISE_CONFORMANCE, 0); + xombe_dec_frame(&dec, f, 0, pcm); + xombe_dec_decision_get(&dec, &dc); + xombe__unpack49(a2, d49); + decoded &= dc.cls == XOMBE_CLASS_TONE && xombe__tone_frame_parse(d49, &pid, &pad) && pid == r.req[i].id && + pad == r.req[i].ad; +#if XOMBE_HAVE_DSTAR + if (outputs & XOMBE_ENC_DSTAR) { + int T = ds_code(r.req[i].id); + ok = xombe_tone_frame(XOMBE_DSTAR, r.req[i].id, r.req[i].ad, d); + same &= T >= 0 ? ok == 0 && !memcmp(d, r.ds[i], 9) : ok == -1; + if (T >= 0) { + static xombe_dec_mem dm; + xombe_dec *dsd = xombe_dec_init(&dm, XOMBE_DSTAR); + xombe_decision dd; + xombe_ds_frame fr; + xombe_dec_set_noise(dsd, XOMBE_NOISE_CONFORMANCE, 0); + xombe_dec_frame(dsd, d, 0, pcm); + xombe_dec_decision_get(dsd, &dd); + xombe__ds_fec_decode(d, &fr); + decoded &= dd.cls == XOMBE_CLASS_TONE && fr.tid == r.req[i].id && + fr.AD == (r.req[i].ad < 8 ? 8 : r.req[i].ad); + } + } +#else + (void)d; +#endif + } + check(n < MAXF, "every ID in the packer sweep"); + check(same, outputs & XOMBE_ENC_DSTAR ? "packers equal the forced dual encoder's frames" + : "xombe_tone_frame equals the forced DMR encoder's frames"); + check(decoded, "packer frames decode as tone frames of their ID and level"); +} + +#if XOMBE_HAVE_DSTAR +/* the D-STAR encoder's mirror equals the decoder's, replayed from the emitted frames, after every frame, with + forced tones in speech */ +static void test_ds_mirror(const int16_t *x, int frames) +{ + static run r; + xombe_enc_cfg cfg = cfg_of(XOMBE_ENC_DMR | XOMBE_ENC_DSTAR, 1); + xombe_enc *e = xombe_enc_init(&mem_a, &cfg); + xombe_ds_mirror dm; + int c, bad = 0, n = 0, knox = 0, tone = 0, knox_bad = 0, delay = xombe_enc_delay(e); + uint32_t s = 12345u; + xombe__ds_mirror_init(&dm); + memset(&r, 0, sizeof(r)); + for (c = 30; c < frames; c += 7 + (int)(s % 23)) { + int k, len = 1 + (int)((s >> 8) % 3), id = (int)((s >> 12) % 154) + 5; + if (id > 122) + id += 5; + for (k = 0; k < len && c + k < frames; k++) { + r.req[c + k].id = id; + r.req[c + k].ad = (int)((s >> 16) % 128); + } + knox += id >= 144 && id <= 159; + tone += id < 144 || id > 159; + s = s * 1664525u + 1013904223u; + } + for (c = 0; c < frames; c++) { + static xombe_ds_enc before; + uint8_t a2[7], ds[9], want[9]; + const xombe_enc_tone *t = c >= delay ? &r.req[c - delay] : NULL; + int is_knox = t && t->id >= 144 && t->id <= 159; + if (is_knox) { + /* the encoder's own Knox frame at the requested level */ + int k = 0, b[9]; + before = *XOMBE_DS_ENC(e); + while (before.tones.knox[k].id != t->id) + k++; + xombe__ds_knox_amps(&before, k, (float)t->ad, b); + xombe__ds_encode_fields(b, want); + } + if (enc_frame(e, x + 160 * c, r.req[c].id ? &r.req[c] : NULL, a2, ds) == 1) { + const xombe_ds_mirror *m = &XOMBE_DS_ENC(e)->mirror; + xombe_ds_frame fr; + xombe_ds_params p; + xombe__ds_fec_decode(ds, &fr); + xombe__ds_params_from_frame(&dm, &fr, &p); + bad += m->L != dm.L || m->G != dm.G || memcmp(m->a, dm.a, sizeof(m->a)); + knox_bad += is_knox && memcmp(ds, want, 9); + n++; + } + } + printf("D-STAR mirror with %d forced tone and %d Knox requests: %d/%d frames equal\n", tone, knox, n - bad, n); + check(knox > 0 && tone > 0, "mirror test forces both kinds"); + check(bad == 0, "the D-STAR mirror stays equal to the decoder's across forced tones"); + check(knox_bad == 0, "a forced Knox tone is the D-STAR encoder's Knox voice frame"); +} +#endif + +int main(int argc, char **argv) +{ + const char *vec = argc > 1 ? argv[1] : "vectors"; + int fs, ft; + int16_t *speech = load_raw(vec, "e3/es1_orig.raw", &fs), *tones = load_raw(vec, "e7/tones.raw", &ft); + test_position(speech, fs, XOMBE_ENC_DMR, 1); + test_position(speech, fs, XOMBE_ENC_DMR, 0); + test_in_tone_run(tones, ft, XOMBE_ENC_DMR); + test_state(speech, XOMBE_ENC_DMR, 1, 1, 50); + test_state(tones, XOMBE_ENC_DMR, 1, 1, 50); + test_state(speech, XOMBE_ENC_DMR, 0, 0, 80); + test_decode(speech, fs, XOMBE_ENC_DMR); + test_packers(speech, fs, XOMBE_ENC_DMR); +#if XOMBE_HAVE_DSTAR + test_position(speech, fs, XOMBE_ENC_DMR | XOMBE_ENC_DSTAR, 1); + test_position(speech, fs, XOMBE_ENC_DMR | XOMBE_ENC_DSTAR, 0); + test_position(speech, fs, XOMBE_ENC_DSTAR, 1); + test_in_tone_run(tones, ft, XOMBE_ENC_DMR | XOMBE_ENC_DSTAR); + test_state(speech, XOMBE_ENC_DMR | XOMBE_ENC_DSTAR, 1, 1, 50); + test_state(tones, XOMBE_ENC_DMR | XOMBE_ENC_DSTAR, 1, 0, 50); + test_decode(speech, fs, XOMBE_ENC_DMR | XOMBE_ENC_DSTAR); + test_ds_mirror(speech, fs); + test_packers(speech, fs, XOMBE_ENC_DMR | XOMBE_ENC_DSTAR); +#endif + free(speech); + free(tones); + printf("forced tones: %d/%d checks passed\n", checks - failures, checks); + return failures ? 1 : 0; +} diff --git a/xombe/test/test_fec.c b/xombe/test/test_fec.c new file mode 100644 index 0000000..4dbbca8 --- /dev/null +++ b/xombe/test/test_fec.c @@ -0,0 +1,321 @@ +#include +#include +#include +#include +#include "../src/internal.h" + +static int failures, checks; + +static void check(int ok, const char *what, int index) +{ + checks++; + if (!ok) { + failures++; + if (failures <= 20) + fprintf(stderr, "FAIL %s (item %d)\n", what, index); + } +} + +static int hex_bytes(const char *s, uint8_t *out, int n) +{ + int i; + for (i = 0; i < n; i++) { + unsigned v; + if (sscanf(s + 2 * i, "%2x", &v) != 1) + return 0; + out[i] = (uint8_t)v; + } + return 1; +} + +static FILE *open_vec(const char *dir, const char *name) +{ + char path[4096]; + FILE *f; + snprintf(path, sizeof(path), "%s/%s", dir, name); + f = fopen(path, "r"); + if (!f) { + perror(path); + exit(2); + } + return f; +} + +static void test_encode_vectors(const char *dir) +{ + char line[512], h49[64], h72[64]; + FILE *f = open_vec(dir, "fec_encode_vectors.txt"); + int n = 0; + while (fgets(line, sizeof(line), f)) { + uint8_t b[7], air[9], mine[9], back[7]; + xombe_fec fec; + xombe_fec_stats st; + unsigned flags; + if (line[0] == '#' || sscanf(line, "%63s %63s", h49, h72) != 2) + continue; + hex_bytes(h49, b, 7); + hex_bytes(h72, air, 9); + xombe_fec_encode(XOMBE_DMR, b, mine); + check(!memcmp(mine, air, 9), "encode vector", n); + xombe_fec_init(&fec, XOMBE_DMR); + flags = xombe_fec_decode(&fec, air, back, &st); + check(!memcmp(back, b, 7) && st.eps0 == 0 && st.eps1 == 0 && flags == 0, "decode vector", n); + n++; + } + fclose(f); + check(n == 80, "80 encode vectors", n); + printf("fec_encode_vectors: %d pairs\n", n); +} + +static void test_air_map(const char *dir) +{ + char line[512], cw[16], label[32]; + FILE *f = open_vec(dir, "air72_map.txt"); + static const int offset[4] = {0, 24, 47, 58}; + static const int data_base[4] = {0, 12, 24, 35}; + static const int data_len[4] = {12, 12, 11, 14}; + uint8_t w[72], a[72]; + int n = 0, i; + for (i = 0; i < 72; i++) + w[i] = (uint8_t)i; + xombe__interleave(w, a); + while (fgets(line, sizeof(line), f)) { + int air_bit, k, bit; + char *p; + if (line[0] == '#') + continue; + if (sscanf(line, "%d %15s", &air_bit, cw) != 2) + continue; + p = strchr(line, '['); + if (!p || sscanf(p + 1, "%d] %31s", &bit, label) != 2) + continue; + k = cw[1] - '0'; + check(a[air_bit] == offset[k] + bit, "air map position", air_bit); + if (bit < data_len[k]) { + char want[16]; + snprintf(want, sizeof(want), "d%d", data_base[k] + bit); + check(!strcmp(label, want), "air map data index", air_bit); + } else { + check(!strcmp(label, "parity"), "air map parity", air_bit); + } + n++; + } + fclose(f); + check(n == 72, "72 air map entries", n); + printf("air72_map: %d entries\n", n); +} + +static uint32_t rng_state = 12345u; +static uint32_t rnd(void) +{ + rng_state = rng_state * 1103515245u + 12345u; + return rng_state >> 8; +} + +static void flip_codeword_bit(uint8_t air[9], int w_index) +{ + uint8_t w[72], a[72]; + int i; + for (i = 0; i < 72; i++) + w[i] = (uint8_t)(i == w_index); + xombe__interleave(w, a); + for (i = 0; i < 72; i++) + if (a[i]) + air[i >> 3] ^= (uint8_t)(0x80 >> (i & 7)); +} + +static void test_injection(void) +{ + int trial, e0, e1, n = 0; + for (trial = 0; trial < 400; trial++) { + for (e0 = 0; e0 <= 3; e0++) { + for (e1 = 0; e1 <= 3; e1++) { + uint8_t b[7], air[9], back[7]; + int used[24] = {0}, used1[23] = {0}, i; + xombe_fec fec; + xombe_fec_stats st; + for (i = 0; i < 7; i++) + b[i] = (uint8_t)rnd(); + b[6] &= 0x80; + xombe_fec_encode(XOMBE_DMR, b, air); + for (i = 0; i < e0;) { + int pos = (int)(rnd() % 24); + if (used[pos]) + continue; + used[pos] = 1; + flip_codeword_bit(air, pos); + i++; + } + for (i = 0; i < e1;) { + int pos = (int)(rnd() % 23); + if (used1[pos]) + continue; + used1[pos] = 1; + flip_codeword_bit(air, 24 + pos); + i++; + } + xombe_fec_init(&fec, XOMBE_DMR); + xombe_fec_decode(&fec, air, back, &st); + check(!memcmp(back, b, 7), "corrected data", trial); + check(st.eps0 == e0 && st.eps1 == e1, "error counts", trial); + check(st.bf == (e0 >= 2 && e0 + e1 >= 6), "bad-frame flag", trial); + n++; + } + } + { + uint8_t b[7], air[9], back[7]; + int i; + xombe_fec fec; + xombe_fec_stats st; + for (i = 0; i < 7; i++) + b[i] = (uint8_t)rnd(); + b[6] &= 0x80; + xombe_fec_encode(XOMBE_DMR, b, air); + flip_codeword_bit(air, 23); + xombe_fec_init(&fec, XOMBE_DMR); + xombe_fec_decode(&fec, air, back, &st); + check(!memcmp(back, b, 7) && st.eps0 == 1 && st.eps1 == 0, "parity-only error", trial); + n++; + } + } + printf("error injection: %d frames\n", n); +} + +static void test_c0x4(const char *dir) +{ + char line[512], s49[64], a72[64], o49[64]; + FILE *f = open_vec(dir, "fec_decode_c0x4.txt"); + int n = 0; + while (fgets(line, sizeof(line), f)) { + uint8_t air[9], want[7], got[7]; + int e0, e1, bf; + xombe_fec fec; + xombe_fec_stats st; + if (line[0] == '#' || sscanf(line, "%63s %63s %63s %d %d %d", s49, a72, o49, &e0, &e1, &bf) != 6) + continue; + hex_bytes(a72, air, 9); + hex_bytes(o49, want, 7); + xombe_fec_init(&fec, XOMBE_DMR); + xombe_fec_decode(&fec, air, got, &st); + check(!memcmp(got, want, 7), "c0x4 output bits", n); + check(st.eps0 == e0 && st.eps1 == e1 && st.bf == bf, "c0x4 counts and BF", n); + n++; + } + fclose(f); + check(n == 200, "200 c0x4 frames", n); + printf("fec_decode_c0x4: %d frames\n", n); +} + +static void test_hb_onset(const char *dir) +{ + char line[512], a72[64], o49[64]; + FILE *f = open_vec(dir, "fec_hb_onset.txt"); + int n = 0, cur_seq = -1; + xombe_fec fec; + xombe_fec_init(&fec, XOMBE_DMR); + while (fgets(line, sizeof(line), f)) { + uint8_t air[9], want[7], got[7]; + int seq, fr, e0, e1, bf, hb; + xombe_fec_stats st; + if (line[0] == '#' || + sscanf(line, "%d %d %63s %63s %d %d %d %d", &seq, &fr, a72, o49, &e0, &e1, &bf, &hb) != 8) + continue; + if (seq != cur_seq) { + xombe_fec_init(&fec, XOMBE_DMR); + cur_seq = seq; + } + hex_bytes(a72, air, 9); + hex_bytes(o49, want, 7); + xombe_fec_decode(&fec, air, got, &st); + check(!memcmp(got, want, 7), "hb_onset output bits", n); + check(st.eps0 == e0 && st.eps1 == e1 && st.bf == bf && st.hb == hb, "hb_onset flags", n); + n++; + } + fclose(f); + printf("fec_hb_onset: %d frames\n", n); +} + +static void test_fields(void) +{ + uint8_t d[49]; + int b[9], c, i, f; + for (c = 0; c < 64; c++) { + memset(d, 0, sizeof(d)); + xombe__put_bits(d, 0, 6, c); + i = xombe__frame_class(d); + check(i == (c < 60 ? XOMBE_CLASS_VOICE : c < 62 ? XOMBE_CLASS_ERASURE + : c == 62 ? XOMBE_CLASS_SILENCE : XOMBE_CLASS_TONE), "frame class", c); + } + for (f = 0; f < 9; f++) { + static const int lsb[9] = {39, 35, 36, 43, 42, 44, 45, 46, 48}; + static const int msb[9] = {0, 4, 8, 12, 20, 24, 28, 31, 34}; + static const int width[9] = {7, 5, 5, 9, 7, 5, 4, 4, 3}; + memset(b, 0, sizeof(b)); + b[f] = 1; + memset(d, 0, sizeof(d)); + xombe__put_fields(b, d); + check(d[lsb[f]] == 1, "field LSB position", f); + b[f] = 1 << (width[f] - 1); + memset(d, 0, sizeof(d)); + xombe__put_fields(b, d); + check(d[msb[f]] == 1, "field MSB position", f); + } + for (i = 0; i < 2000; i++) { + int back[9]; + uint8_t packed[7], again[49]; + for (c = 0; c < 49; c++) + d[c] = (uint8_t)(rnd() & 1); + xombe__get_fields(d, b); + memset(again, 0, sizeof(again)); + xombe__put_fields(b, again); + check(!memcmp(again, d, 49), "field round trip", i); + xombe__pack49(d, packed); + xombe__unpack49(packed, again); + check(!memcmp(again, d, 49), "pack round trip", i); + xombe__get_fields(again, back); + check(!memcmp(back, b, sizeof(b)), "field values", i); + } + printf("class and field map: ok\n"); +} + +/* Q24 running error rate against 0.95*eps_r + 0.05*eps_t/47 in double, over runs of error counts hovering + around the HB threshold (eps_t = 4 or 5 in steady state gives eps_r 0.085 or 0.106) */ +static void test_eps_r(void) +{ + xombe_fec f; + double r = 0.0, worst = 0.0; + int i, hb_diff = 0; + xombe_fec_init(&f, XOMBE_DMR); + for (i = 0; i < 200000; i++) { + xombe_fec_stats st; + int burst = (i / 1000) % 3; + memset(&st, 0, sizeof(st)); + st.eps0 = (int)(rnd() % (burst == 0 ? 3u : burst == 1 ? 5u : 8u)); + st.eps1 = (int)(rnd() % 4u); + if (st.eps0 > 4) + st.eps0 = 4; + xombe__fec_stats_update(&f, &st); + r = 0.95 * r + 0.05 * st.eps_t / 47.0; + if (fabs(st.eps_r / 16777216.0 - r) > worst) + worst = fabs(st.eps_r / 16777216.0 - r); + if (st.hb != (r > 0.096) && fabs(r - 0.096) > 1e-6) + hb_diff++; + } + check(worst < 1e-6, "eps_r within 1e-6 of the double recursion", 0); + check(hb_diff == 0, "HB as in the double recursion away from the threshold", hb_diff); + printf("eps_r: worst %.2g against double\n", worst); +} + +int main(int argc, char **argv) +{ + const char *dir = argc > 1 ? argv[1] : "vectors/fec"; + test_encode_vectors(dir); + test_air_map(dir); + test_injection(); + test_c0x4(dir); + test_hb_onset(dir); + test_fields(); + test_eps_r(); + printf("T1: %d/%d checks passed\n", checks - failures, checks); + return failures ? 1 : 0; +} diff --git a/xombe/test/test_kern_cq.c b/xombe/test/test_kern_cq.c new file mode 100644 index 0000000..a278bf3 --- /dev/null +++ b/xombe/test/test_kern_cq.c @@ -0,0 +1,109 @@ +/* closed-loop quantizer (src/common/cquant.c): the pruned pair search against the exhaustive one on random + shaped targets for both table sets, and with the q15 kernels the codebook images against the codebooks */ +#include +#include +#include +#include "../src/common/cquant.h" +#include "../src/dstar/dstar_internal.h" +#include "../src/tables/dsp_tables.h" + +#define CASES 300 + +static unsigned rng = 12345u; + +static float urand(void) /* [0, 1) */ +{ + rng = rng * 1664525u + 1013904223u; + return (float)(rng >> 8) / 16777216.0f; +} + +static int irand(int n) +{ + return (int)(urand() * (float)n) % n; +} + +static xombe_cq_ws ws; + +/* random fields' shape plus noise, quantized with and without pruning, uncapped */ +static int brute_cases(const xombe_amp_tables *ts, const char *name) +{ + int c, bad = 0; + for (c = 0; c < CASES; c++) { + float t[XOMBE_LMAX + 1], target[XOMBE_LMAX + 1], base[XOMBE_LMAX + 1], w[XOMBE_LMAX + 1], G; + float noise = 0.05f + 0.6f * urand(); + int b[9] = {0}, L = 9 + irand(48), l, k, pass; + xombe_cq_result res[2]; + b[3] = irand(ts->n_prba24); + b[4] = irand(ts->n_prba58); + for (k = 0; k < 4; k++) + b[5 + k] = irand(ts->n_hoc[k]); + xombe__spectral_shape_ts(ts, b, L, t); + G = 2.0f * urand() - 1.0f; + target[0] = base[0] = 0.0f; + for (l = 1; l <= L; l++) { + target[l] = t[l] + 3.0f * G + noise * (2.0f * urand() - 1.0f); + base[l] = -xombe__half_log2[L]; + } + xombe__cq_amp_weights(target, L, XOMBE_CQ_QWEIGHT, XOMBE_CQ_WEIGHT_FLOOR, w); + for (pass = 0; pass < 2; pass++) { + memset(&ws, 0, sizeof(ws)); + ws.brute = pass; + xombe__cq_prepare(&ws, ts, L, c & 1 ? w : NULL); + xombe__cq_closed(&ws, target, target, base, 0.0f, XOMBE_CQ_N_PAIRS, XOMBE_CQ_N_GAIN, XOMBE_CQ_ITERS, + &res[pass]); + } + for (k = 2; k < 9 && res[0].b[k] == res[1].b[k]; k++) + ; + if (k < 9 && bad++ < 5) + fprintf(stderr, "%s case %d (L %d): pruned b%d %d, exhaustive %d\n", name, c, L, k, res[0].b[k], + res[1].b[k]); + } + printf("kern_cq: %s %d/%d cases pruned = exhaustive\n", name, CASES - bad, CASES); + return bad; +} + +#if XOMBE_KERNELS_Q15 +/* every image entry within 1/2 unit of its exact value and within its column's maximum */ +static int image_check(const xombe_amp_tables *ts, const xombe_cq_q15_tab *qt, const char *name) +{ + static const int p24[6][2] = {{0, 0}, {1, 1}, {2, 2}, {0, 1}, {0, 2}, {1, 2}}; + static const int p58[10][2] = {{0, 0}, {1, 1}, {2, 2}, {3, 3}, {0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}}; + int i, k, bad = 0; + for (i = 0; i < ts->n_prba24; i++) { + const float *x = ts->prba24[i]; + for (k = 0; k < 9; k++) { + uint32_t v = qt->r24[i][k / 2]; + int q = (int16_t)(k & 1 ? v >> 16 : v & 0xffff), t = k < 6 ? qt->tm24 : qt->tx24; + double e = k < 6 ? (p24[k][0] == p24[k][1] ? 1.0 : 2.0) * x[p24[k][0]] * x[p24[k][1]] : x[k - 6]; + double m = k < 6 ? qt->m24[k] : qt->x24[k - 6]; + bad += fabs(q - ldexp(e, t)) > 0.5 || fabs(ldexp(q, -t)) > m; + } + } + for (i = 0; i < ts->n_prba58; i++) { + const float *x = ts->prba58[i]; + for (k = 0; k < 14; k++) { + uint32_t v = qt->r58[i][k / 2]; + int q = (int16_t)(k & 1 ? v >> 16 : v & 0xffff), t = k < 10 ? qt->tm58 : qt->tx58; + double e = k < 10 ? (p58[k][0] == p58[k][1] ? 1.0 : 2.0) * x[p58[k][0]] * x[p58[k][1]] : x[k - 10]; + double m = k < 10 ? qt->m58[k] : qt->x58[k - 10]; + bad += fabs(q - ldexp(e, t)) > 0.5 || fabs(ldexp(q, -t)) > m; + } + } + printf("kern_cq: %s images %s\n", name, bad ? "WRONG, rerun scripts/gen_cq_tables.py" : "match the codebooks"); + return bad; +} +#endif + +int main(int argc, char **argv) +{ + int bad = 0; + (void)argc; + (void)argv; +#if XOMBE_KERNELS_Q15 + bad += image_check(&xombe__amp_ambe2, &xombe__cq_q15_ambe2, "AMBE+2"); + bad += image_check(&xombe__amp_dstar, &xombe__cq_q15_dstar, "D-STAR"); +#endif + bad += brute_cases(&xombe__amp_ambe2, "AMBE+2"); + bad += brute_cases(&xombe__amp_dstar, "D-STAR"); + return bad != 0; +} diff --git a/xombe/test/test_kern_dec.c b/xombe/test/test_kern_dec.c new file mode 100644 index 0000000..911231f --- /dev/null +++ b/xombe/test/test_kern_dec.c @@ -0,0 +1,162 @@ +/* decoder kernels (src/dec/dkernels.h) and src/dsp/fmath.h against float, argv[1] the vectors directory */ +#include +#include +#include +#include "../src/internal.h" +#include "../src/dec/dkernels.h" +#include "../src/dsp/fmath.h" + +#if XOMBE_KERNELS_Q15 +/* the float kernels as the reference, renamed */ +#define xombe__dk_wavetable ref_wavetable +#define xombe__dk_add_grain ref_add_grain +#define xombe__dk_unvoiced ref_unvoiced +void ref_wavetable(const xombe_set *s, const float *M, const uint8_t *vh, float tab[XOMBE_WT_SIZE]); +void ref_add_grain(float *buf, int N, float P, float fhat, float period, const float *tab); +void ref_unvoiced(const int16_t *seg, int N, const xombe_set *cur, const float *M, const uint8_t *vh, + float avg_f0, float y[XOMBE_UV_FFT]); +#include "../src/dec/dkern_float.c" +#undef xombe__dk_wavetable +#undef xombe__dk_add_grain +#undef xombe__dk_unvoiced +#endif + +/* fmath.h against libm: exact in float builds, in q15 builds exp2 within EXP2_TOL relative, log2 and sincos + within LOG2_TOL (absolute, relative above 1) and SINCOS_TOL absolute, sincos over |x| <= 520 (wavetable + phases reach about 360) */ +#define EXP2_TOL 2e-7 +#define LOG2_TOL 1.5e-7 +#define SINCOS_TOL 2e-7 + +static double rel_err(double v, double ref) +{ + return fabs(v - ref) / fabs(ref); +} + +static double log_err(double v, double ref) +{ + return fabs(v - ref) / fmax(1.0, fabs(ref)); +} + +static int test_fmath(void) +{ + double e_exp = 0.0, e_log = 0.0, e_sc = 0.0, d; + int i, fails = 0; + for (i = -1300000; i <= 1300000; i++) { + float x = (float)i * 9e-5f, y = exp2f((float)i * 9.6e-5f), z = (float)(i + 1300001) * 1e-6f, s, c; + xombe__sincosf(4.4f * x, &s, &c); + d = fmax(fabs(s - sin(4.4f * x)), fabs(c - cos(4.4f * x))); + e_sc = fmax(e_sc, d); + e_exp = fmax(e_exp, rel_err(xombe__exp2f(x), exp2(x))); + e_log = fmax(e_log, fmax(log_err(xombe__log2f(y), log2(y)), log_err(xombe__log2f(z), log2(z)))); + if (!XOMBE_KERNELS_Q15) { + xombe__sincosf(x, &s, &c); + if (xombe__exp2f(x) != exp2f(x) || s != sinf(x) || c != cosf(x) || xombe__log2f(y) != log2f(y)) + fails++; + } + } + /* libm's results at the edges */ + if (xombe__exp2f(-200.0f) != exp2f(-200.0f) || !isinf(xombe__exp2f(200.0f)) || isinf(xombe__exp2f(127.9f)) || + !isinf(xombe__log2f(0.0f)) || xombe__log2f(1e-40f) != log2f(1e-40f)) + fails++; + if (XOMBE_KERNELS_Q15 && (e_exp > EXP2_TOL || e_log > LOG2_TOL || e_sc > SINCOS_TOL)) + fails++; + printf("kern_dec: fmath max error exp2 %.2e (relative), log2 %.2e, sincos %.2e: %s\n", e_exp, e_log, e_sc, + fails ? "FAIL" : "ok"); + return fails; +} + +#if XOMBE_KERNELS_Q15 +/* q15 kernels against float on random sets, SNR limits in dB over each output: the wavetable differs only by + fmath.h, the unvoiced transforms carry the Q15 FFT's 60-70 dB, down to ~52 dB when a few strong unvoiced + bands hold nearly all the power, the block exponent then set by bins the error spreads over all */ +#define WT_SNR 100.0 +#define GRAIN_SNR 95.0 +#define UV_SNR 50.0 +#define CN_SNR 55.0 +#define SETS 400 + +static uint32_t rng = 1; + +static float urand(void) +{ + rng = rng * 1664525u + 1013904223u; + return (float)(rng >> 8) * (1.0f / 16777216.0f); +} + +static void snr_add(const float *a, const float *b, int n, double *worst) +{ + double e = 0.0, p = 0.0, r; + int i; + for (i = 0; i < n; i++) { + e += (double)(a[i] - b[i]) * (a[i] - b[i]); + p += (double)b[i] * b[i]; + } + r = e > 0.0 ? 10.0 * log10(p / e) : 200.0; + if (p > 0.0 && r < *worst) + *worst = r; +} + +/* f0 80..400 Hz, log2 amplitudes falling about 0.1 per harmonic plus up to 6 of noise, random phases and + voicing, every class but tone */ +static void random_set(xombe_set *s, float *M, uint8_t *vh) +{ + int l; + memset(s, 0, sizeof(*s)); + s->f0 = XOMBE_HZ(80.0f + 320.0f * urand()); + s->L = xombe__L_from_f0(s->f0); + s->cls = urand() < 0.2f ? XOMBE_CLASS_SILENCE : XOMBE_CLASS_VOICE; + for (l = 0; l <= XOMBE_LMAX; l++) { + M[l] = l ? exp2f(12.0f - 0.1f * (float)l - 6.0f * urand()) : 0.0f; + vh[l] = (uint8_t)(urand() < 0.5f); + s->phi[l] = 400.0f * (urand() - 0.5f); + } +} + +static int test_kernels(void) +{ + double wt = 200.0, uv = 200.0, cn = 200.0, gr = 200.0; + int i, n, fails; + for (i = 0; i < SETS; i++) { + xombe_set s; + float M[XOMBE_LMAX + 1], a[XOMBE_UV_FFT], b[XOMBE_UV_FFT]; + int16_t seg[2 * XOMBE_HALF_MAX]; + uint8_t vh[XOMBE_LMAX + 1]; + int N = XOMBE_HALF_MIN + (int)(urand() * (XOMBE_HALF_MAX - XOMBE_HALF_MIN + 1)); + random_set(&s, M, vh); + xombe__dk_wavetable(&s, M, vh, a); + ref_wavetable(&s, M, vh, b); + snr_add(a, b, XOMBE_WT_SIZE, &wt); + { + float ga[XOMBE_HALF_MAX + XOMBE_TAIL], gb[XOMBE_HALF_MAX + XOMBE_TAIL], fh = s.f0 * (0.9f + 0.2f * urand()); + float P = 1.5f * (float)N * urand() - 0.5f * (float)N; + memset(ga, 0, sizeof(ga)); + memset(gb, 0, sizeof(gb)); + xombe__dk_add_grain(ga, N, P, fh, 1.0f / s.f0, b); + ref_add_grain(gb, N, P, fh, 1.0f / s.f0, b); + snr_add(ga, gb, N + XOMBE_TAIL, &gr); + } + for (n = 0; n < 2 * N; n++) + seg[n] = (int16_t)(urand() * 65535.0f - 32768.0f); + xombe__dk_unvoiced(seg, N, &s, M, vh, XOMBE_HZ(100.0f), a); + ref_unvoiced(seg, N, &s, M, vh, XOMBE_HZ(100.0f), b); + snr_add(a, b, 2 * N, s.cls == XOMBE_CLASS_SILENCE ? &cn : &uv); + } + fails = (wt < WT_SNR) + (gr < GRAIN_SNR) + (uv < UV_SNR) + (cn < CN_SNR); + printf("kern_dec: worst SNR vs float over %d sets, wavetable %.1f dB, grain %.1f dB, unvoiced %.1f dB, comfort " + "noise %.1f dB: %s\n", SETS, wt, gr, uv, cn, fails ? "FAIL" : "ok"); + return fails; +} +#endif + +int main(int argc, char **argv) +{ + int fails = 0; + (void)argc; + (void)argv; + fails += test_fmath(); +#if XOMBE_KERNELS_Q15 + fails += test_kernels(); +#endif + return fails != 0; +} diff --git a/xombe/test/test_kern_spec.c b/xombe/test/test_kern_spec.c new file mode 100644 index 0000000..0123376 --- /dev/null +++ b/xombe/test/test_kern_spec.c @@ -0,0 +1,219 @@ +/* analysis spectrum kernels (src/enc/kernels.h) against a double-precision DFT, argv[1] the vectors directory */ +#include +#include +#include +#include +#include "../src/internal.h" +#include "../src/enc/kernels.h" +#include "../src/tables/dsp_tables.h" + +#define PI 3.14159265358979323846 +#define HMAX (XOMBE_MAX_WINDOW / 2) + +/* worst bin amplitude error relative to the peak bin, and least SNR over all bins. q15: the block-floating-point + FFT sets both (61 dB, 0.0032 on these frames with a float split), prepared bins against their range's peak */ +#if XOMBE_KERNELS_Q15 +#define AMP_TOL 5e-3 +#define SNR_MIN 58.0 +#define LF_TOL 0.05 +#else +#define AMP_TOL 1e-5 +#define SNR_MIN 100.0 +#endif + +static int fails; +static double worst_snr = 1e9, worst_amp, sum_snr; +#if XOMBE_KERNELS_Q15 +static double worst_lf; +#endif +static int nsnr; + +static double urand(uint32_t *s) +{ + *s = *s * 1664525u + 1013904223u; + return (double)(*s >> 8) / 8388608.0 - 1.0; +} + +static void fail(const char *what, const char *msg, double v) +{ + if (fails++ < 10) + printf("%s: %s %g\n", what, msg, v); +} + +#if XOMBE_KERNELS_Q15 +/* block layout, then lf_prepare on the whole band and on a high band: prepared peak at least 16384, exact prefix + sums, and bins / g against the reference relative to the range's peak */ +static void check_q15(const char *what, const xombe_spec *S, const double *rr, const double *ri) +{ + static xombe_enc e; + const int16_t *re = S->v, *im = re + XOMBE_LF_IM; + int k, j, big = 0, kmax = XOMBE_SPEC_BINS - 2; + if (im[0] != 0 || im[XOMBE_SPEC_BINS - 1] != 0) + fail(what, "imaginary DC or Nyquist", 0); + for (k = 0; k < XOMBE_SPEC_BINS; k++) { + if (abs(re[k]) > big) + big = abs(re[k]); + if (abs(im[k]) > big) + big = abs(im[k]); + } + if (big < 32735 || big > 32767) + fail(what, "largest component", big); + for (j = 0; j < 2; j++) { + xombe_lf_spec sp; + uint64_t acc = 0; + double lpeak = 0.0, lf = 0.0; + const int16_t *pr, *pi; + int kmin = j ? 300 : 1, top = 0; + xombe__kern_lf_prepare(&e, S, kmin, kmax, &sp); + if (sp.g == 0.0f || (sp.S != S && sp.S != &e.kq.spec)) { + fail(what, "prepared g 0 or a foreign spectrum, from kmin", kmin); + continue; + } + pr = sp.S->v; + pi = pr + XOMBE_LF_IM; + if (e.kq.ep[kmin] != 0) + fail(what, "prefix sum start", (double)e.kq.ep[kmin]); + for (k = kmin; k <= kmax; k++) { + acc += (uint64_t)((int32_t)pr[k] * pr[k]) + (uint64_t)((int32_t)pi[k] * pi[k]); + if (e.kq.ep[k + 1] != acc) + fail(what, "prefix sum at", k); + if (abs(pr[k]) > top) + top = abs(pr[k]); + if (abs(pi[k]) > top) + top = abs(pi[k]); + if (hypot(rr[k], ri[k]) > lpeak) + lpeak = hypot(rr[k], ri[k]); + } + if (top < 16384) + fail(what, "prepared peak", top); + for (k = kmin; k <= kmax; k++) { + double d = hypot(pr[k] / sp.g - rr[k], pi[k] / sp.g - ri[k]) / lpeak; + if (d > lf) + lf = d; + } + if (lf > worst_lf) + worst_lf = lf; + if (lf > LF_TOL) + fail(what, "prepared bins off, of the range peak, by", lf); + } +} +#endif + +static void check_frame(const char *what, const float *centre, const float *w, int n, double sum_w2) +{ + static double rr[XOMBE_SPEC_BINS], ri[XOMBE_SPEC_BINS]; + static float P[XOMBE_SPEC_BINS]; + static xombe_spec S; + double peak = 0.0, sig = 0.0, err = 0.0, amp = 0.0, scale = 1.0 / (XOMBE_FFT * sum_w2), snr; + int half = (n - 1) / 2, j, k; + for (k = 0; k < XOMBE_SPEC_BINS; k++) { + double xr = 0.0, xi = 0.0; + for (j = -half; j <= half; j++) { + double a = -2.0 * PI * (double)(((j + XOMBE_FFT) * k) % XOMBE_FFT) / XOMBE_FFT; + double v = (double)centre[j] * w[half + j]; + xr += v * cos(a); + xi += v * sin(a); + } + rr[k] = xr; + ri[k] = xi; + if (hypot(xr, xi) > peak) + peak = hypot(xr, xi); + } + xombe__kern_spectrum(centre, w, n, &S); + xombe__kern_bin_power(&S, (float)sum_w2, P); + if (peak == 0.0) { + for (k = 0; k < XOMBE_SPEC_BINS; k++) + if (P[k] != 0.0f) + fail(what, "power of a zero frame at bin", k); + return; + } + for (k = 0; k < XOMBE_SPEC_BINS; k++) { + double d = sqrt(P[k] / scale) - hypot(rr[k], ri[k]); + sig += rr[k] * rr[k] + ri[k] * ri[k]; + err += d * d; + if (fabs(d) / peak > amp) + amp = fabs(d) / peak; + } + snr = err > 0.0 ? 10.0 * log10(sig / err) : 999.0; + if (amp > worst_amp) + worst_amp = amp; + sum_snr += snr; + nsnr++; + if (snr < worst_snr) + worst_snr = snr; + if (amp > AMP_TOL) + fail(what, "bin amplitude error, of the peak", amp); + if (snr < SNR_MIN) + fail(what, "SNR dB", snr); +#if XOMBE_KERNELS_Q15 + check_q15(what, &S, rr, ri); +#endif +} + +int main(int argc, char **argv) +{ + static float buf[2 * HMAX + 1], wl[XOMBE_MAX_WINDOW]; + static int16_t pcm[100000]; + float *centre = buf + HMAX; + const float *ws[2]; + int ns[2] = {XOMBE_BASE_WINDOW, XOMBE_MAX_WINDOW}, i, j, k, frames = 0, len = 0; + double s2[2] = {0.0, 0.0}; + uint32_t seed = 1; + char path[1024], what[64]; + FILE *f; + for (j = 0; j < XOMBE_MAX_WINDOW; j++) + wl[j] = (float)(0.54 - 0.46 * cos(2.0 * PI * j / (XOMBE_MAX_WINDOW - 1))); + ws[0] = xombe__base_win; + ws[1] = wl; + for (i = 0; i < 2; i++) + for (j = 0; j < ns[i]; j++) + s2[i] += (double)ws[i][j] * ws[i][j]; + snprintf(path, sizeof path, "%s/e3/es1_orig.raw", argc > 1 ? argv[1] : "vectors"); + f = fopen(path, "rb"); + if (f) { + len = (int)fread(pcm, sizeof(pcm[0]), sizeof(pcm) / sizeof(pcm[0]), f); + fclose(f); + } else { + fail(path, "can't read", 0); + } + /* speech every 37 ms through es1 (16-bit little-endian), both windows */ + for (k = HMAX; k + HMAX < len; k += 296) { + for (i = 0; i < 2; i++) { + int h = (ns[i] - 1) / 2; + for (j = -h; j <= h; j++) { + const uint8_t *b = (const uint8_t *)&pcm[k + j]; + centre[j] = (float)(int16_t)(b[0] | b[1] << 8); + } + snprintf(what, sizeof what, "es1 at %d, window %d", k, ns[i]); + check_frame(what, centre, ws[i], ns[i], s2[i]); + frames++; + } + } + /* harmonics with a falling envelope and noise 70 dB down, loud and quiet, an impulse, and silence */ + for (i = 0; i < 3; i++) { + double f0 = 0.0125 + 0.02 * i; + int l; + for (j = -HMAX; j <= HMAX; j++) { + double v = 3e-4 * urand(&seed); + for (l = 1; l * f0 < 0.5; l++) + v += cos(2.0 * PI * l * f0 * j + l) / l; + centre[j] = (float)(v * (i == 2 ? 1e-6 : 3000.0)); + } + snprintf(what, sizeof what, "harmonics f0 %.4f", f0); + check_frame(what, centre, wl, XOMBE_MAX_WINDOW, s2[1]); + frames++; + } + memset(buf, 0, sizeof buf); + centre[0] = 1000.0f; + check_frame("impulse", centre, wl, XOMBE_MAX_WINDOW, s2[1]); + centre[0] = 0.0f; + check_frame("silence", centre, wl, XOMBE_MAX_WINDOW, s2[1]); + frames += 2; + printf("kern_spec: %d frames, SNR mean %.2f dB least %.1f dB, worst bin amplitude error %.2g of peak", frames, + sum_snr / nsnr, worst_snr, worst_amp); +#if XOMBE_KERNELS_Q15 + printf(", prepared bins %.2g of the range peak", worst_lf); +#endif + printf(", %d failures\n", fails); + return fails != 0; +} diff --git a/xombe/test/test_kern_tone.c b/xombe/test/test_kern_tone.c new file mode 100644 index 0000000..7d507a5 --- /dev/null +++ b/xombe/test/test_kern_tone.c @@ -0,0 +1,168 @@ +/* tone detector kernels against float, argv[1] the vectors directory: q15 bin powers against a double DFT, gate + shares, sincos_turn, and the tone twiddles */ +#include "../src/enc/tone_detect.c" /* its spectrum and trig are static */ +#include +#include + +#if XOMBE_KERNELS_Q15 +static int failures, checks; + +static void check(int ok, const char *what) +{ + checks++; + if (!ok) { + failures++; + printf("FAIL: %s\n", what); + } +} + +#define PEAK_TOL 2.5e-3 /* largest bin power error, relative to the peak bin (amplitude error near -64 dB) */ +#define SHARE_TOL 3e-4 /* gate share error, against DUAL_GATE_SHARE 0.7 */ + +static struct xombe_enc enc; +static double worst_bin, worst_share; + +/* bin powers of x under win, double DFT */ +static void ref_power(const float *x, int len, const float *win, double *pw) +{ + int k, n; + for (k = 0; k <= XOMBE_TONE_FFT / 2; k++) { + double re = 0.0, im = 0.0; + for (n = 0; n < len; n++) { + double v = (double)x[n] * win[n], a = 2.0 * XOMBE_PI * k * n / XOMBE_TONE_FFT; + re += v * cos(a); + im -= v * sin(a); + } + pw[k] = re * re + im * im; + } +} + +/* q15 powers of one segment against ref_power, scaled by their ratio of sums, and the gate share of each + AMBE+2 dual against the reference share */ +static void one_segment(const int16_t *seg, int len, const float *win, const char *what) +{ + xombe_tone_seg sg; + double ref[XOMBE_TONE_FFT / 2 + 1], peak = 0.0, num = 0.0, den = 0.0, sc, err = 0.0, rtot = 0.0, serr = 0.0; + double qtot; + int k, id; + char msg[160]; + sg.energy = prepare(&enc, seg, len, win, sg.x, sg.pw); + if (sg.energy == 0.0f) + return; + ref_power(sg.x, len, win, ref); + for (k = 0; k <= XOMBE_TONE_FFT / 2; k++) { + peak = ref[k] > peak ? ref[k] : peak; + num += (double)sg.pw[k]; + den += ref[k]; + } + sc = num / den; + for (k = 0; k <= XOMBE_TONE_FFT / 2; k++) { + double d = fabs((double)sg.pw[k] - sc * ref[k]) / (sc * peak); + err = d > err ? d : err; + } + worst_bin = err > worst_bin ? err : worst_bin; + snprintf(msg, sizeof(msg), "%s, %d samples: bin power error %.2e of peak", what, len, err); + check(err <= PEAK_TOL, msg); + for (k = (int)ceilf(GATE_LO_HZ / BIN_HZ); k <= (int)floorf(GATE_HI_HZ / BIN_HZ); k++) + rtot += ref[k]; + qtot = (double)band_total(sg.pw); + for (id = XOMBE_TONE_DUAL_FIRST; id < XOMBE_TONE_DUAL_FIRST + XOMBE_TONE_DUALS; id++) { + float nominal[2]; + int r0lo, r0hi, r1lo, r1hi; + double near = 0.0, qnear = 0.0; + xombe__tone_freqs(id, &nominal[0], &nominal[1]); + gate_run(nominal[0], &r0lo, &r0hi); + gate_run(nominal[1], &r1lo, &r1hi); + for (k = 0; k <= XOMBE_TONE_FFT / 2; k++) + if ((k >= r0lo && k <= r0hi) || (k >= r1lo && k <= r1hi)) { + near += ref[k]; + qnear += (double)sg.pw[k]; + } + if (rtot > 0.0 && qtot > 0.0) { + double d = fabs(qnear / qtot - near / rtot); + serr = d > serr ? d : serr; + } + } + worst_share = serr > worst_share ? serr : worst_share; + snprintf(msg, sizeof(msg), "%s, %d samples: gate share error %.2e", what, len, serr); + check(serr <= SHARE_TOL, msg); +} + +static void spectra(const char *vec) +{ + static int16_t seg[XOMBE_TONE_SEG]; + static const double hz[] = {300.0, 697.0, 1209.0, 1633.0, 2000.0, 3000.0, 3800.0}; + static const double dbfs[] = {-3.0, -20.0, -45.0}; + char path[4096], what[64]; + unsigned lcg = 1u; + int i, j, n, segs = 0; + FILE *f; + for (i = 0; i < (int)(sizeof(hz) / sizeof(hz[0])); i++) + for (j = 0; j < 3; j++) { + double a = 32768.0 * pow(10.0, dbfs[j] / 20.0) / 1.5; + for (n = 0; n < XOMBE_TONE_SEG; n++) { + lcg = lcg * 1664525u + 1013904223u; + seg[n] = (int16_t)floor(a * cos(2.0 * XOMBE_PI * hz[i] * n / XOMBE_FS + 0.3) + + 0.5 * a * cos(2.0 * XOMBE_PI * 1.37 * hz[i] * n / XOMBE_FS) + + (double)(lcg >> 28) - 7.5 + 0.5); + } + snprintf(what, sizeof(what), "%.0f Hz %.0f dBFS", hz[i], dbfs[j]); + one_segment(seg, XOMBE_TONE_SEG, xombe__tone_win, what); + one_segment(seg, 160, xombe__tone_win + 40, what); /* shorter segment, any window */ + } + snprintf(path, sizeof(path), "%s/e3/es1_orig.raw", vec); + f = fopen(path, "rb"); + if (!f) { + perror(path); + exit(2); + } + while (segs < 120 && fread(seg, sizeof(int16_t), XOMBE_TONE_SEG, f) == XOMBE_TONE_SEG) { + snprintf(what, sizeof(what), "es1 segment %d", segs++); + one_segment(seg, XOMBE_TONE_SEG, xombe__tone_win, what); + } + fclose(f); + printf("kern_tone: worst bin power error %.2e of peak, gate share error %.2e\n", worst_bin, worst_share); +} + +static void trig(void) +{ + double worst = 0.0; + int i; + for (i = -400000; i <= 400000; i++) { + float t = (float)i * 3.0e-4f, s, c; /* to 120 turns, as far as (2*len - 1)*w/2 reaches */ + double ds = sin(2.0 * XOMBE_PI * (double)t), dc = cos(2.0 * XOMBE_PI * (double)t), e; + sincos_turn(t, &s, &c); + e = fmax(fabs(s - ds), fabs(c - dc)); + worst = e > worst ? e : worst; + } + printf("kern_tone: sincos_turn worst error %.2e\n", worst); + check(worst < 3e-7, "sincos_turn within 3e-7"); +} + +static void twiddles(void) +{ + int j, ok = 1; + for (j = 0; j < XOMBE_TONE_FFT / 4; j++) + ok &= xombe__tone_tw_q15[j] == xombe__fft_tw_q15[2 * j]; + check(ok, "xombe__tone_tw_q15 is every second xombe__fft_tw_q15"); +} +#endif + +int main(int argc, char **argv) +{ + if (argc < 2) { + fprintf(stderr, "usage: test_kern_tone VEC\n"); + return 2; + } +#if XOMBE_KERNELS_Q15 + twiddles(); + trig(); + spectra(argv[1]); + printf("kern_tone: %d/%d checks passed\n", checks - failures, checks); + return failures != 0; +#else + (void)argv; + printf("kern_tone: float build, no checks\n"); + return 0; +#endif +} diff --git a/xombe/test/test_mirror.c b/xombe/test/test_mirror.c new file mode 100644 index 0000000..d330767 --- /dev/null +++ b/xombe/test/test_mirror.c @@ -0,0 +1,627 @@ +#include +#include +#include +#include +#include "../src/internal.h" +#include "../src/tables/tables.h" + +#define FS 8000 + +static long e1_frames, e1_bad, mirror_frames, mirror_bad, e7_fail; +static const xombe_enc_tone *forced; /* per input frame, id 0: none, NULL: no requests */ +static long forced_frames; +static double mirror_max_err; +static uint32_t rng = 20261019u; + +static uint32_t rnd(void) +{ + rng = rng * 1664525u + 1013904223u; + return rng >> 8; +} + +static double urand(void) +{ + return (rnd() & 0xFFFFFF) / 16777216.0; +} + +static int16_t *load_raw(const char *dir, const char *name, long *n) +{ + char path[4096]; + FILE *f; + long size; + int16_t *x; + snprintf(path, sizeof(path), "%s/%s", dir, name); + f = fopen(path, "rb"); + if (!f) { + perror(path); + exit(2); + } + fseek(f, 0, SEEK_END); + size = ftell(f); + fseek(f, 0, SEEK_SET); + x = malloc((size_t)size + 2); + *n = (long)fread(x, sizeof(int16_t), (size_t)size / 2, f); + fclose(f); + return x; +} + +static int e1_frame_ok(const uint8_t d[49]) +{ + int c = xombe__get_bits(d, 0, 6), b[9], i; + if (c == 60 || c == 61) + return 0; + if (c == 63) { + int id = xombe__get_bits(d, 12, 8); + for (i = 1; i < 4; i++) + if (xombe__get_bits(d, 12 + 8 * i, 8) != id) + return 0; + return xombe__tone_id_accepted(id) && !d[45] && !d[46] && !d[47] && !d[48]; + } + xombe__get_fields(d, b); + if (c == 62) + return b[0] == XOMBE_SILENCE_B0 && b[1] == XOMBE_SILENCE_B1; + return b[0] <= 119 && (b[1] < 18 || b[1] > 31); +} + +static int same_pred(const xombe_pred *a, const xombe_pred *b) +{ + int l; + if (a->cls != b->cls || a->L != b->L || a->f0 != b->f0 || a->gamma != b->gamma || memcmp(a->v2, b->v2, 8)) + return 0; + for (l = 0; l <= XOMBE_LMAX; l++) + if (a->a[l] != b->a[l]) + return 0; + return 1; +} + +/* E2(a): decoder's dequantized f0, L, and amplitudes equal the encoder's reconstruction, the dequantization of + the emitted fields from the encoder's predictor before the frame. the encoder keeps that reconstruction as its + predictor after a voice frame, so the two predictors must also agree */ +static int mirror_ok(const xombe_pred *before, const xombe_enc *enc, const xombe_dec *dec, const uint8_t d[49], + int cls) +{ + const xombe_set *p2 = &dec->c.p2; + xombe_params rec; + int b[9], l; + if (enc->pi.cls != cls || !same_pred(&enc->pi, &dec->c.pi)) + return 0; + if (cls == XOMBE_CLASS_TONE) + return 1; + xombe__get_fields(d, b); + xombe__dequant(b, before, cls == XOMBE_CLASS_SILENCE, &rec); + if (p2->L != rec.L || p2->f0 != rec.f0) + return 0; + for (l = 1; l <= p2->L; l++) { + double err = fabs((double)p2->a[l] - rec.a[l]); + if (err > mirror_max_err) + mirror_max_err = err; + if (err > 1e-6) + return 0; + } + return 1; +} + +typedef struct { + long frames; + int16_t *pcm; + int *cls; + int *b0; + int *voiced_bands; + int state_finite; /* encoder and decoder state free of NaN and infinity after the run */ +} encode_result; + +static int all_finite(const float *v, int n) +{ + int i; + for (i = 0; i < n; i++) + if (!isfinite(v[i])) + return 0; + return 1; +} + +static int pred_finite(const xombe_pred *p) +{ + return isfinite(p->f0) && isfinite(p->gamma) && all_finite(p->a, XOMBE_LMAX + 1); +} + +static int state_finite(const xombe_enc *e, const xombe_dec *d) +{ + return pred_finite(&e->pi) && pred_finite(&d->c.pi) && isfinite(d->c.lambda) && isfinite(d->c.avg_f0) && + isfinite(d->hpf.y1) && isfinite(d->hpf.y2) && isfinite(e->hpf.y1) && isfinite(e->hpf.y2) && + isfinite(d->pitch_phase) && isfinite(d->epoch) && all_finite(d->tail, XOMBE_TAIL) && + all_finite(d->uv_overlap, XOMBE_TAIL) && isfinite(e->ns_floor) && + all_finite(e->ns_noise, XOMBE_NS_BINS) && all_finite(e->cn_power, XOMBE_SPEC_BINS) && + all_finite(e->vad_nl, 8) && isfinite(e->p_prev); +} + +static void e7_check(int ok, const char *what) +{ + if (!ok) { + e7_fail++; + printf("E7 FAIL: %s\n", what); + } +} + +static void run_case(const char *name, const int16_t *x, long n, const xombe_enc_cfg *cfg, encode_result *res) +{ + static xombe_enc enc; + static xombe_dec dec; + long frames = n / 160, f, out = 0, bad = 0; + xombe_enc_init(&enc, cfg); + xombe_dec_set_noise(xombe_dec_init(&dec, XOMBE_DMR), XOMBE_NOISE_CONFORMANCE, 0); + if (res) { + res->frames = frames; + res->pcm = malloc(sizeof(int16_t) * 160 * (size_t)(frames + 1)); + res->cls = malloc(sizeof(int) * (size_t)(frames + 1)); + res->b0 = malloc(sizeof(int) * (size_t)(frames + 1)); + res->voiced_bands = malloc(sizeof(int) * (size_t)(frames + 1)); + } + for (f = 0; out < frames; f++) { + uint8_t bits[7], d[49]; + int16_t pcm[160]; + xombe_pred before = enc.pi; + const xombe_enc_tone *t = forced && f < frames && forced[f].id ? &forced[f] : NULL; + int got = xombe_enc_frame_bits(&enc, f < frames ? x + 160 * f : NULL, t, bits, NULL); + forced_frames += t != NULL; + int cls, b[9]; + if (!got) + continue; + xombe__unpack49(bits, d); + e1_frames++; + if (!e1_frame_ok(d)) { + bad++; + e1_bad++; + } + xombe_dec_frame_bits(&dec, bits, 0, pcm); + cls = xombe__frame_class(d); + mirror_bad += !mirror_ok(&before, &enc, &dec, d, cls); + mirror_frames++; + if (res) { + xombe__get_fields(d, b); + memcpy(res->pcm + 160 * out, pcm, sizeof(pcm)); + res->cls[out] = cls; + res->b0[out] = b[0]; + res->voiced_bands[out] = cls == XOMBE_CLASS_VOICE ? xombe__count_voiced(xombe__vuv[b[1]]) : 0; + } + out++; + } + if (bad) + printf(" %s: %ld E1 violations\n", name, bad); + if (res) + res->state_finite = state_finite(&enc, &dec); +} + +static void free_result(encode_result *r) +{ + free(r->pcm); + free(r->cls); + free(r->b0); + free(r->voiced_bands); +} + +static void test_files(const char *vec) +{ + static const char *const files[] = { + "e3/es1_orig.raw", "e3/es2_orig.raw", "e3/es3_orig.raw", "e3/sn10_orig.raw", "e3/ttsf_orig.raw", + "e3/ttsc_orig.raw", "e3/ttsl_orig.raw", "e5/low5.raw", "e5/hp5.raw", "e5/es1_lead0.5s.raw", + "e7/glide.raw", "e7/mix.raw", "e7/saw150.raw", "e7/tones.raw"}; + xombe_enc_cfg cfg[4]; + unsigned i, v; + for (v = 0; v < 4; v++) + xombe_enc_cfg_default(&cfg[v]); + cfg[1].dmr_dtx = 0; + cfg[2].ns = 0; + cfg[2].tones = 0; + cfg[3].voicing_scale_permille = 600; + for (i = 0; i < sizeof(files) / sizeof(files[0]); i++) { + long n; + int16_t *x = load_raw(vec, files[i], &n); + for (v = 0; v < 4; v++) + if (v == 0 || i % 3 == v - 1) + run_case(files[i], x, n, &cfg[v], NULL); + free(x); + } +} + +static uint32_t lcg(uint32_t *s) +{ + *s = *s * 1664525u + 1013904223u; + return *s >> 8; +} + +/* E2 across forced tones: bursts of one to three tone frames at random IDs and levels in speech and noise */ +static void test_forced(const char *vec) +{ + static const char *const files[] = {"e3/es1_orig.raw", "e3/sn10_orig.raw", "e3/ttsl_orig.raw", "e5/low5.raw"}; + xombe_enc_cfg cfg; + uint32_t r = 7u; + unsigned i; + for (i = 0; i < sizeof(files) / sizeof(files[0]); i++) { + long n, f, frames; + int16_t *x = load_raw(vec, files[i], &n); + xombe_enc_tone *req; + frames = n / 160; + req = calloc((size_t)frames + 1, sizeof(*req)); + for (f = 20; f < frames; f += 5 + (long)(lcg(&r) % 30)) { + int k, len = 1 + (int)(lcg(&r) % 3), id = 5 + (int)(lcg(&r) % 154); + if (id > 122) + id += 5; + for (k = 0; k < len && f + k < frames; k++) { + req[f + k].id = id; + req[f + k].ad = (int)(lcg(&r) % 128); + } + } + forced = req; + xombe_enc_cfg_default(&cfg); + cfg.tones = (int)(i & 1); + cfg.dmr_dtx = i != 2; + run_case(files[i], x, n, &cfg, NULL); + forced = NULL; + free(req); + free(x); + } +} + +static void random_frame(int b[9], int silence) +{ + b[0] = silence ? XOMBE_SILENCE_B0 : (int)(rnd() % 120); + b[1] = silence ? XOMBE_SILENCE_B1 : (int)(rnd() % 18); + b[2] = (int)(rnd() % 32); + b[3] = (int)(rnd() % 512); + b[4] = (int)(rnd() % 128); + b[5] = (int)(rnd() % 32); + b[6] = (int)(rnd() % 16); + b[7] = (int)(rnd() % 16); + b[8] = (int)(rnd() % 8); +} + +static int same_recon(const xombe_params *a, const xombe_params *b) +{ + int l; + if (a->L != b->L || fabsf(a->gamma - b->gamma) > 1e-6f) + return 0; + for (l = 1; l <= a->L; l++) + if (fabsf(a->a[l] - b->a[l]) > 1e-5f) + return 0; + return 1; +} + +static int clamp_hit(const xombe_params *p) +{ + int l; + if (p->gamma >= XOMBE_GAIN_MAX) + return 1; + for (l = 1; l <= p->L; l++) + if (p->a[l] <= XOMBE_AMP_MIN || p->a[l] >= XOMBE_AMP_MAX) + return 1; + return 0; +} + +static long idem_frames, idem_exact, idem_equivalent, idem_clamped, idem_bad; + +static void test_idempotence(int count) +{ + xombe_pred pi; + int i; + xombe__pred_init(&pi); + for (i = 0; i < count; i++) { + int b[9], q[9], silence = (rnd() % 5) == 0, k, same = 1; + xombe_params p, back; + uint8_t v2[8]; + random_frame(b, silence); + xombe__dequant(b, &pi, silence, &p); + memcpy(q, b, sizeof(q)); + xombe__quantize(&pi, silence, p.L, p.a, q); + for (k = 2; k < 9; k++) + same &= q[k] == b[k]; + idem_frames++; + if (same) { + idem_exact++; + } else { + xombe__dequant(q, &pi, silence, &back); + if (same_recon(&p, &back)) + idem_equivalent++; + else if (clamp_hit(&p)) + idem_clamped++; + else { + idem_bad++; + if (idem_bad <= 10) + printf(" idempotence: frame %d b=%d,%d,%d,%d,%d,%d,%d got %d,%d,%d,%d,%d,%d,%d\n", i, b[2], b[3], + b[4], b[5], b[6], b[7], b[8], q[2], q[3], q[4], q[5], q[6], q[7], q[8]); + } + } + if (silence) { + xombe__pred_store_other(&pi, XOMBE_CLASS_SILENCE); + } else { + xombe__v2_from_b1(b[1], v2); + xombe__pred_store_voice(&pi, &p, v2); + } + } +} + +static double level_dbfs(const int16_t *x, long n) +{ + double s = 0.0; + long i; + for (i = 0; i < n; i++) + s += (double)x[i] * x[i]; + return s > 0.0 ? 10.0 * log10(s / n / (32768.0 * 32768.0)) : -200.0; +} + +static int16_t clip16(double v) +{ + return (int16_t)(v > 32767.0 ? 32767 : v < -32768.0 ? -32768 : floor(v + 0.5)); +} + +static void am_sweep(int16_t *x, long n, long lead, double f_start, double f_end, double *f_at) +{ + double phase = 0.0; + long i; + for (i = 0; i < n; i++) { + double t = (double)(i - lead) / FS, dur = (double)(n - lead) / FS, f, v = 0.0, env; + int k; + if (i < lead) { + x[i] = 0; + if (f_at) + f_at[i] = 0.0; + continue; + } + f = f_start * pow(f_end / f_start, t / dur); + if (f_at) + f_at[i] = f; + phase += 2.0 * XOMBE_PI * f / FS; + for (k = 1; k * f < 3900.0; k++) + v += cos(k * phase); + env = 1.0 + 0.5 * sin(2.0 * XOMBE_PI * 3.5 * t); + x[i] = clip16(600.0 * env * v / sqrt((double)(3900.0 / f))); + } +} + +static void sweep_report(const char *name, double f_start, double f_end, int16_t *x, long n) +{ + double *f_at = malloc(sizeof(double) * (size_t)n); + encode_result r; + xombe_enc_cfg cfg; + long f, in_range = 0, good = 0, octave_low = 0; + am_sweep(x, n, FS / 2, f_start, f_end, f_at); + xombe_enc_cfg_default(&cfg); + run_case(name, x, n, &cfg, &r); + for (f = 0; f < r.frames; f++) { + double truth = f_at[160 * f + 120 < n ? 160 * f + 120 : n - 1], coded; + if (truth < 66.0 || truth > 398.0 || r.cls[f] != XOMBE_CLASS_VOICE) + continue; + in_range++; + coded = xombe__w0[r.b0[f]] * FS; + if (fabs(coded - truth) <= 0.05 * truth) + good++; + else if (fabs(coded - truth / 2.0) <= 0.05 * truth / 2.0) + octave_low++; + } + printf("E7 %s (informative): coded pitch within 5%% on %ld of %ld voice frames in 66..398 Hz (%ld an octave " + "low)\n", name, good, in_range, octave_low); + free_result(&r); + free(f_at); +} + +/* decoded over input power in dB on the pause frames of x from frame from on, frames whose clean source and two + neighbours on each side are below 20 dB (16-bit units), which also absorbs the decoder's delay + pcm[i] is aligned with x[i] */ +static double pause_suppression(const int16_t *x, const int16_t *clean, const int16_t *pcm, long n, long from) +{ + long nfr = n / 160, i, j, k; + double pin = 0.0, pout = 0.0; + for (i = from; i < nfr - 2; i++) { + int quiet = 1; + for (j = i - 2; j <= i + 2 && quiet; j++) { + double e = 0.0; + for (k = 0; k < 160; k++) + e += (double)clean[160 * j + k] * clean[160 * j + k]; + quiet = 10.0 * log10(e / 160.0 + 1e-3) < 20.0; + } + if (!quiet) + continue; + for (k = 160 * i; k < 160 * (i + 1); k++) { + pin += (double)x[k] * x[k]; + pout += (double)pcm[k] * pcm[k]; + } + } + return 10.0 * log10((pout + 1e-9) / (pin + 1e-9)); +} + +/* VAD recovery (inputs as E5's vad_* from tools/e5.py --vad-gen) + three triggers push the noise levels under the background of sn10 (es1 + white noise, 10 dB SNR, 0.5 s + noise lead-in): 120 zero samples prepended, digital-silence gaps in two pauses (0 from 0.16 s, constant +1 + from 3.68 s, 8 frames each), and the noise raised 8 dB from 2.0 s + from 7.5 s on, pause frames must be suppressed at most 3 dB less than in the unmodified clip, i.e. the noise + levels have recovered (with the digital-silence guard, vad_gap never locks) */ +static void test_vad_recovery(const char *vec, const char *inputs) +{ + long n, nc, i, m; + int16_t *sn = load_raw(inputs, "sn10.d0.raw", &n), *clean = load_raw(vec, "e5/es1_lead0.5s.raw", &nc); + int16_t *x = malloc(sizeof(int16_t) * (size_t)(n + 120)), *cl = calloc((size_t)(n + 120), sizeof(int16_t)); + const char *names[4] = {"sn10", "vad_on", "vad_gap", "vad_step"}; + const long from = 375; + double ref = 0.0, g = pow(10.0, 8.0 / 20.0); + int t; + encode_result r; + xombe_enc_cfg cfg; + xombe_enc_cfg_default(&cfg); + if (nc < n) + n = nc; + for (t = 0; t < 4; t++) { + const int16_t *in = x; + long off = t == 1 ? 120 : 0; + double sup; + memset(x, 0, sizeof(int16_t) * (size_t)(n + 120)); + for (i = 0; i < n; i++) { + cl[off + i] = clean[i]; + x[off + i] = t == 3 && i >= 2 * FS ? clip16(clean[i] + g * (sn[i] - clean[i])) : sn[i]; + } + if (t == 2) { + for (i = 8 * 160; i < 16 * 160; i++) + x[i] = 0; + for (i = 184 * 160; i < 192 * 160; i++) + x[i] = 1; + } + run_case(names[t], in, n + off, &cfg, &r); + m = 160 * r.frames - off; + sup = pause_suppression(x + off, cl + off, r.pcm + off, m < n ? m : n, from); + if (t == 0) { + ref = sup; + printf("E7 VAD recovery: sn10 pause frames from 7.5 s decoded at %+.1f dB\n", sup); + } else { + printf("E7 VAD recovery: %s %+.1f dB (%+.1f vs sn10, limit +3)\n", names[t], sup, sup - ref); + e7_check(sup - ref <= 3.0, "noise level not recovered after a VAD trigger"); + } + free_result(&r); + } + free(sn); + free(clean); + free(x); + free(cl); +} + +/* E7 robustness, mandatory: + digital silence decodes to -85 dBFS or less + clipped full-scale speech, sweeps, and stationary inputs keep E1/E2 (checked on every frame by run_case) + a stationary tone is absorbed (tone frames, or comfort noise after about 3 s without the tone detector) + ten minutes of mixed abuse leave the state finite and the codec quiet again on digital silence + informative: the sweeps' pitch accuracy */ +static void test_e7(const char *vec, const char *inputs, double stress_seconds) +{ + const long lead = FS / 2, lead_frames = lead / 160; + long n = 10 * FS, i, es1_n; + int16_t *x = calloc((size_t)(30 * FS), sizeof(int16_t)), *es1 = load_raw(vec, "e3/es1_orig.raw", &es1_n); + encode_result r; + xombe_enc_cfg cfg; + double lvl; + long tone_frames = 0, other_frames = 0, absorbed_at = -1; + xombe_enc_cfg_default(&cfg); + + run_case("digital silence", x, n, &cfg, &r); + lvl = level_dbfs(r.pcm, 160 * r.frames); + printf("E7 digital silence: decoded %.1f dBFS (limit -85)\n", lvl); + e7_check(lvl <= -85.0, "digital silence above -85 dBFS"); + free_result(&r); + + for (i = 0; i < es1_n; i++) + x[i] = clip16(16.0 * es1[i]); + run_case("clipped full-scale speech", x, es1_n, &cfg, &r); + printf("E7 clipped full-scale speech: decoded %.1f dBFS, %ld frames\n", level_dbfs(r.pcm, 160 * r.frames), + r.frames); + free_result(&r); + + sweep_report("rising AM comb sweep 50->500 Hz", 50.0, 500.0, x, 20 * FS); + sweep_report("falling AM comb sweep 500->50 Hz", 500.0, 50.0, x, 20 * FS); + + /* tone detector on: every frame from two frames after the onset is a tone frame */ + memset(x, 0, sizeof(int16_t) * 30 * FS); + for (i = lead; i < 8 * FS; i++) + x[i] = clip16(8000.0 * sin(2.0 * XOMBE_PI * 1000.0 * i / FS)); + run_case("stationary 1 kHz tone", x, 8 * FS, &cfg, &r); + for (i = lead_frames + 2; i < r.frames; i++) { + tone_frames += r.cls[i] == XOMBE_CLASS_TONE; + other_frames += r.cls[i] != XOMBE_CLASS_TONE; + } + printf("E7 stationary 1 kHz tone (7.5 s): %ld tone frames, %ld others after onset + 2 frames\n", tone_frames, + other_frames); + e7_check(other_frames == 0, "stationary tone not coded as tone frames throughout"); + free_result(&r); + + /* tone detector off: the steady comb becomes background (comfort noise) about 3 s after its onset, at the + latest 4 s after it, and stays background */ + cfg.tones = 0; + am_sweep(x, 8 * FS, lead, 150.0, 150.0, NULL); + for (i = lead; i < 8 * FS; i++) + x[i] = clip16(x[i] / (1.0 + 0.5 * sin(2.0 * XOMBE_PI * 3.5 * (double)(i - lead) / FS))); + run_case("stationary 150 Hz comb", x, 8 * FS, &cfg, &r); + for (i = r.frames - 1; i >= lead_frames && r.cls[i] == XOMBE_CLASS_SILENCE; i--) + absorbed_at = i; + printf("E7 stationary 150 Hz comb, tone detector off: background from %.2f s after onset\n", + absorbed_at < 0 ? -1.0 : (absorbed_at - lead_frames) * 0.02); + e7_check(absorbed_at >= 0 && absorbed_at - lead_frames <= 4 * 50, "steady comb not absorbed within 4 s"); + free_result(&r); + free(x); + + test_vad_recovery(vec, inputs); + + if (stress_seconds > 0.0) { + long total = (long)(stress_seconds * FS), pos = 0, bad_samples = 0, quiet_start = -1, quiet_len = 0; + int16_t *s = malloc(sizeof(int16_t) * (size_t)total); + int seg = 0; + xombe_enc_cfg_default(&cfg); + while (pos < total) { + long len = (long)(2 + rnd() % 9) * FS, k; + int kind = seg++ % 6; + if (pos + len > total) + len = total - pos; + for (k = 0; k < len; k++) { + double v; + switch (kind) { + case 0: v = es1[k % es1_n]; break; + case 1: v = 3000.0 * (urand() - 0.5); break; + case 2: v = 16.0 * es1[k % es1_n]; break; + case 3: v = 9000.0 * sin(2.0 * XOMBE_PI * (300.0 + 2700.0 * k / len) * k / FS); break; + case 4: v = 0.0; break; + default: v = es1[k % es1_n] + 2000.0 * (urand() - 0.5); break; + } + s[pos + k] = clip16(v); + } + if (kind == 4 && len >= 2 * FS) { + quiet_start = pos; + quiet_len = len; + } + pos += len; + } + run_case("stress", s, total, &cfg, &r); + for (i = 0; i < 160 * r.frames; i++) + bad_samples += r.pcm[i] == 32767 || r.pcm[i] == -32768; + printf("E7 stress: %.0f s, %ld frames, %ld saturated output samples (informative), state %s\n", + stress_seconds, r.frames, bad_samples, r.state_finite ? "finite" : "NOT FINITE"); + e7_check(r.state_finite, "encoder or decoder state not finite after the stress run"); + if (quiet_start >= 0) { + /* last digital-silence stretch, from 1 s into it to its end */ + long a = (quiet_start + FS) / 160, b = (quiet_start + quiet_len) / 160; + lvl = level_dbfs(r.pcm + 160 * a, 160 * (b - a)); + printf("E7 stress: last digital silence (%.1f s) decodes to %.1f dBFS (limit -85)\n", + (b - a) * 0.02, lvl); + e7_check(lvl <= -85.0, "digital silence after the stress run above -85 dBFS"); + } + free_result(&r); + free(s); + } + free(es1); + printf("E7: %s\n", e7_fail ? "FAIL" : "PASS"); +} + +int main(int argc, char **argv) +{ + const char *vec = argc > 1 ? argv[1] : "vectors", *inputs = NULL; + int i, e7 = 0; + double stress = 0.0; + for (i = 2; i < argc; i++) { + if (!strcmp(argv[i], "--e7")) + e7 = 1; + else if (!strcmp(argv[i], "--stress") && i + 1 < argc) + stress = atof(argv[++i]); + else if (!strcmp(argv[i], "--inputs") && i + 1 < argc) + inputs = argv[++i]; + } + if (e7 && !inputs) { + fprintf(stderr, "test_mirror: --e7 needs --inputs DIR, the dithered E3 inputs (scripts/gen_inputs.py)\n"); + return 2; + } + test_files(vec); + test_forced(vec); + test_idempotence(5000); + if (e7) + test_e7(vec, inputs, stress); + printf("E1: %ld/%ld frames valid\n", e1_frames - e1_bad, e1_frames); + printf("E2 mirror: %ld/%ld frames equal (max |error| %.3g log2)\n", mirror_frames - mirror_bad, mirror_frames, + mirror_max_err); + printf("E2 forced tones: %ld requests among the frames above\n", forced_frames); + printf("E2 idempotence: %ld frames, %ld identical, %ld equivalent (unused HOC field), %ld clamped, %ld mismatches\n", + idem_frames, idem_exact, idem_equivalent, idem_clamped, idem_bad); + printf("E1/E2: %s\n", e1_bad || mirror_bad || idem_bad ? "FAIL" : "PASS"); + return e1_bad || mirror_bad || idem_bad || e7_fail ? 1 : 0; +} diff --git a/xombe/test/test_q15ops.c b/xombe/test/test_q15ops.c new file mode 100644 index 0000000..d6dd070 --- /dev/null +++ b/xombe/test/test_q15ops.c @@ -0,0 +1,221 @@ +/* src/dsp/q15ops.h operations against 64-bit reference arithmetic on edge values and a pseudo-random sweep, + checks the C fallback on a host and the intrinsics on an Arm target with the DSP extension */ +#include +#include +#include +#include "../src/dsp/fft_q15.h" + +static int fails; + +static void check(const char *what, int64_t got, int64_t want, uint32_t a, uint32_t b) +{ + if (got != want && fails++ < 10) + printf("%s(%08lx, %08lx): %lld, want %lld\n", what, (unsigned long)a, (unsigned long)b, (long long)got, + (long long)want); +} + +static int64_t lo(uint32_t a) +{ + return (int64_t)(a & 0xffffu) - (a & 0x8000u ? 65536 : 0); +} + +static int64_t hi(uint32_t a) +{ + return lo(a >> 16); +} + +static int64_t wrap32(int64_t v) +{ + v %= 4294967296LL; + if (v < 0) + v += 4294967296LL; + return v >= 2147483648LL ? v - 4294967296LL : v; +} + +static int ref_clz64(uint64_t x) +{ + int n = 64; + while (x) { + n--; + x >>= 1; + } + return n; +} + +static int64_t sat16(int64_t v) +{ + return v > 32767 ? 32767 : v < -32768 ? -32768 : v; +} + +static int64_t floor_half(int64_t v) +{ + return (int64_t)floor((double)v / 2.0); +} + +static int64_t floor_div32(int64_t v) +{ + return v >= 0 ? v / 4294967296LL : -((-v + 4294967295LL) / 4294967296LL); +} + +static int64_t pair(int64_t l, int64_t h) +{ + return (int64_t)(((uint32_t)l & 0xffffu) | ((uint32_t)h & 0xffffu) << 16); +} + +static uint32_t ref_rbit(uint32_t x) +{ + uint32_t r = 0; + int i; + for (i = 0; i < 32; i++) + r |= (x >> i & 1u) << (31 - i); + return r; +} + +/* FFT against a double-precision DFT of its quantized input: SNR in dB of the 512-point transform of 1024 real + samples, packed as xombe__kern_spectrum packs them */ +#define FM 512 +#define PI 3.14159265358979323846 +static double fft_snr(const double *in) +{ + static uint32_t tw[FM / 2], x[FM]; + static double zr[FM], zi[FM]; + double peak = 0.0, g, sig = 0.0, err = 0.0; + int k, n, s; + for (k = 0; k < FM / 2; k++) { + double c = floor(cos(2.0 * PI * k / FM) * 32768.0 + 0.5); + double si = floor(-sin(2.0 * PI * k / FM) * 32768.0 + 0.5); + tw[k] = (uint32_t)pair(c > 32767 ? 32767 : (int64_t)c, si > 32767 ? 32767 : (int64_t)si); + } + for (n = 0; n < 2 * FM; n++) + if (fabs(in[n]) > peak) + peak = fabs(in[n]); + g = XOMBE_CFFT_Q15_PEAK / peak; + for (n = 0; n < FM; n++) { + zr[n] = floor(in[2 * n] * g + 0.5); + zi[n] = floor(in[2 * n + 1] * g + 0.5); + x[q15_rbit((uint32_t)n) >> 23] = (uint32_t)pair((int64_t)zr[n], (int64_t)zi[n]); + } + s = xombe__cfft_q15(x, FM, tw, XOMBE_CFFT_Q15_PEAK); + for (k = 0; k < FM; k++) { + double xr = 0.0, xi = 0.0, er, ei; + for (n = 0; n < FM; n++) { + double a = -2.0 * PI * (double)((k * n) % FM) / FM, c = cos(a), si = sin(a); + xr += zr[n] * c - zi[n] * si; + xi += zr[n] * si + zi[n] * c; + } + er = ldexp((double)lo(x[k]), s) - xr; + ei = ldexp((double)hi(x[k]), s) - xi; + sig += xr * xr + xi * xi; + err += er * er + ei * ei; + } + return 10.0 * log10(sig / err); +} + +static double urand(uint32_t *s) +{ + *s = *s * 1664525u + 1013904223u; + return (double)(*s >> 8) / 8388608.0 - 1.0; +} + +/* noise, and voiced-like frames: harmonics of f0 with a falling envelope under the 199-point Hamming window, + centred on sample 0 as xombe__kern_spectrum centres it, with noise 60 dB down */ +static void fft_tests(void) +{ + static double in[2 * FM]; + static const double f0s[] = {0.0125, 0.03, 0.06}; /* cycles/sample, 100, 240, 480 Hz */ + uint32_t s = 7; + double snr, worst = 1e9; + int n, i, l; + for (n = 0; n < 2 * FM; n++) + in[n] = urand(&s); + snr = fft_snr(in); + printf("fft_q15 noise: %.1f dB\n", snr); + if (snr < 62.0) + fails++; + for (i = 0; i < 3; i++) { + memset(in, 0, sizeof in); + for (n = -99; n <= 99; n++) { + double v = 0.0, w = 0.54 + 0.46 * cos(PI * n / 99.0); + for (l = 1; l * f0s[i] < 0.5; l++) + v += cos(2.0 * PI * l * f0s[i] * n + l) / (double)l; + in[(n + 2 * FM) % (2 * FM)] = w * (v + 1e-3 * urand(&s)); + } + snr = fft_snr(in); + if (snr < worst) + worst = snr; + printf("fft_q15 harmonic f0 %.4f: %.1f dB\n", f0s[i], snr); + } + if (worst < 57.0) + fails++; +} + +static void one(uint32_t a, uint32_t b, uint32_t c, uint64_t d) +{ + int64_t dot = lo(a) * lo(b) + hi(a) * hi(b); + int32_t acc = (int32_t)wrap32((int64_t)c); + int64_t acc64 = (int64_t)(d >> 1) - (int64_t)(d >> 2); /* keeps the sum within int64 */ + uint32_t pk = (a & 0xffffu) | ((b << 2) & 0xffff0000u); + check("smuad", q15_smuad(a, b), wrap32(dot), a, b); + check("smlad", q15_smlad(a, b, acc), wrap32(acc + dot), a, b); + check("smlald", q15_smlald(a, b, acc64), acc64 + dot, a, b); + check("pack_lsl2", q15_pack_lsl2(a, b), pk, a, b); + check("smlsd", q15_smlsd(a, b, acc), wrap32(acc + lo(a) * lo(b) - hi(a) * hi(b)), a, b); + check("smladx", q15_smladx(a, b, acc), wrap32(acc + lo(a) * hi(b) + hi(a) * lo(b)), a, b); + check("qadd16", q15_qadd16(a, b), pair(sat16(lo(a) + lo(b)), sat16(hi(a) + hi(b))), a, b); + check("qsub16", q15_qsub16(a, b), pair(sat16(lo(a) - lo(b)), sat16(hi(a) - hi(b))), a, b); + check("shadd16", q15_shadd16(a, b), pair(floor_half(lo(a) + lo(b)), floor_half(hi(a) + hi(b))), a, b); + check("shsub16", q15_shsub16(a, b), pair(floor_half(lo(a) - lo(b)), floor_half(hi(a) - hi(b))), a, b); + check("qsax", q15_qsax(a, b), pair(sat16(lo(a) + hi(b)), sat16(hi(a) - lo(b))), a, b); + check("qasx", q15_qasx(a, b), pair(sat16(lo(a) - hi(b)), sat16(hi(a) + lo(b))), a, b); + check("shsax", q15_shsax(a, b), pair(floor_half(lo(a) + hi(b)), floor_half(hi(a) - lo(b))), a, b); + check("shasx", q15_shasx(a, b), pair(floor_half(lo(a) - hi(b)), floor_half(hi(a) + lo(b))), a, b); + check("pack_lsl1", q15_pack_lsl1(a, b), (a & 0xffffu) | ((b << 1) & 0xffff0000u), a, b); + check("rbit", q15_rbit(a), ref_rbit(a), a, 0); + check("smmulr", q15_smmulr((int32_t)a, (int32_t)b), + floor_div32((int64_t)(int32_t)a * (int32_t)b + 0x80000000LL), a, b); + check("umax16", q15_umax16(a, b), + ((a >> 16) > (b >> 16) ? a >> 16 : b >> 16) << 16 | (((a & 0xffffu) > (b & 0xffffu) ? a : b) & 0xffffu), + a, b); + check("clz64", q15_clz64(d), ref_clz64(d), (uint32_t)(d >> 32), (uint32_t)d); + check("clz64", q15_clz64(d >> (a & 63)), ref_clz64(d >> (a & 63)), a, (uint32_t)d); +} + +int main(void) +{ + static const uint32_t edge[] = {0, 1, 0x7fff, 0x8000, 0xffff, 0x7fff7fff, 0x80008000, 0x80007fff, + 0x7fff8000, 0xffffffff, 0x00010000, 0x12345678}; + uint32_t s = 1; + int i, j; + for (i = 0; i < (int)(sizeof edge / sizeof edge[0]); i++) + for (j = 0; j < (int)(sizeof edge / sizeof edge[0]); j++) { + one(edge[i], edge[j], 0x7fffffff, 0); + one(edge[i], edge[j], 0x80000000u, ~0ull); + } + for (i = 0; i < 200000; i++) { + uint32_t a, b, c; + uint64_t d; + s = s * 1664525u + 1013904223u; + a = s; + s = s * 1664525u + 1013904223u; + b = s; + s = s * 1664525u + 1013904223u; + c = s; + s = s * 1664525u + 1013904223u; + d = (uint64_t)c << 32 | s; + one(a, b, c, d); + } + { + const int16_t v[3] = {-2, 3, 5}; + uint32_t p = q15_ld2(v + 1); + check("ld2", lo(p) * 100 + hi(p), 305, p, 0); + } + fft_tests(); + printf("q15ops (%s): %s\n", +#if defined(__ARM_FEATURE_DSP) + "DSP extension", +#else + "C fallback", +#endif + fails ? "FAIL" : "ok"); + return fails != 0; +} diff --git a/xombe/test/test_stream.c b/xombe/test/test_stream.c new file mode 100644 index 0000000..5beee09 --- /dev/null +++ b/xombe/test/test_stream.c @@ -0,0 +1,296 @@ +#include +#include +#include +#include +#include "xombe.h" +#include "../tools/io.h" + +#define MAX_CALLS 20000 +#define LEVEL_FLOOR_DB (-80.0) + +enum { CAT_VOICE, CAT_SILENCE, CAT_TONE, CAT_REPEAT, CAT_MUTE, NCAT }; +static const char *const cat_names[NCAT] = {"voice", "silence", "tone", "repeat", "mute"}; +static const double lim_median[NCAT] = {0.5, 0.5, 0.25, 0.75, 0.25}; +static const double lim_p90[NCAT] = {7.0, 4.0, 1.0, 7.0, 1.0}; +static const double lim_share[NCAT] = {0.25, 0.12, 0.03, 0.25, 0.08}; + +typedef struct { + enum xombe_class cls; + enum xombe_conceal conceal; + int run; + long mute_src; + int tone_id, tone_ad; +} frame_info; + +static double deltas[NCAT][MAX_CALLS]; +static int ndeltas[NCAT]; +static double snr_mute[MAX_CALLS], snr_cn[MAX_CALLS]; +static int nsnr_mute, nsnr_cn; +static int steady_fail, steady_mute_n, steady_tone_n; +static double steady_mute_max, steady_tone_max; +static long frames_total, decision_fail; + +static enum xombe_class parse_class(const char *p) +{ + if (!strncmp(p, "\"voice\"", 7)) + return XOMBE_CLASS_VOICE; + if (!strncmp(p, "\"erasure\"", 9)) + return XOMBE_CLASS_ERASURE; + if (!strncmp(p, "\"silence\"", 9)) + return XOMBE_CLASS_SILENCE; + return XOMBE_CLASS_TONE; +} + +static enum xombe_conceal parse_conceal(const char *p) +{ + if (!strncmp(p, "\"none\"", 6)) + return XOMBE_CONCEAL_NONE; + if (!strncmp(p, "\"repeat\"", 8)) + return XOMBE_CONCEAL_REPEAT; + return XOMBE_CONCEAL_MUTE; +} + +static double level_db(const int16_t *x, int n) +{ + double s = 0.0; + int i; + for (i = 0; i < n; i++) + s += (double)x[i] * x[i]; + if (s <= 0.0) + return -1e9; + return 10.0 * log10(s / n) - 20.0 * log10(32768.0); +} + +static int cmp_double(const void *a, const void *b) +{ + double x = *(const double *)a, y = *(const double *)b; + return x < y ? -1 : x > y; +} + +static double percentile(double *v, int n, double q) +{ + double pos; + int i; + if (n == 0) + return 0.0; + qsort(v, (size_t)n, sizeof(double), cmp_double); + pos = q * (n - 1); + i = (int)floor(pos); + if (i >= n - 1) + return v[n - 1]; + return v[i] + (pos - i) * (v[i + 1] - v[i]); +} + +static int expect_field(const stream_reader *r, const char *e, const char *key, const char **out) +{ + *out = e ? stream_key(e, key) : NULL; + if (*out) + return 1; + fprintf(stderr, "%s:%ld: missing \"expect\".\"%s\"\n", r->path, r->lineno, key); + return 0; +} + +static int run_file(const char *path, int verbose) +{ + stream_reader r; + stream_half h; + int have_prev = 0, ev, ok = 1; + long frame = -1; + frame_info cur, prev; + xombe_dec_mem mem; + xombe_dec *dec; + memset(&cur, 0, sizeof(cur)); + memset(&prev, 0, sizeof(prev)); + if (!stream_open(&r, path)) + return 1; + dec = xombe_dec_init(&mem, XOMBE_DMR); + xombe_dec_set_noise(dec, XOMBE_NOISE_CONFORMANCE, 0); + while (ok && (ev = stream_next(&r, &h)) != STREAM_END) { + if (ev == STREAM_ERROR) { + ok = 0; + break; + } + if (ev == STREAM_SET) { + xombe_dec_set_errors(dec, r.eps_t, r.eps_1); + continue; + } + if (ev == STREAM_INIT) { + dec = xombe_dec_init(&mem, XOMBE_DMR); + xombe_dec_set_noise(dec, XOMBE_NOISE_CONFORMANCE, 0); + frame = -1; + have_prev = 0; + continue; + } + { + const uint8_t *d = h.d; + int16_t pcm[XOMBE_HALF_MAX], ref[XOMBE_HALF_MAX]; + int i, n, nref = 0; + const char *q; + double ld, lr, dl, num = 0.0, den = 0.0; + int cat; + n = xombe_dec_half_bits(dec, h.bits, h.flags, h.second_half, h.nsamples, pcm); + if (n < 0) { + fprintf(stderr, "%s:%ld: half-frame call out of order\n", path, r.lineno); + ok = 0; + break; + } + if (!h.second_half) { + xombe_decision got; + const char *e = stream_key(h.line, "expect"), *cls, *conceal; + long run; + frame++; + frames_total++; + if (have_prev || frame > 0) + prev = cur; + have_prev = frame > 0; + memset(&cur, 0, sizeof(cur)); + if (!expect_field(&r, e, "class", &cls) || !expect_field(&r, e, "conceal", &conceal) || + !stream_int(&r, e, "run", &run)) { + ok = 0; + break; + } + cur.cls = parse_class(cls); + cur.conceal = parse_conceal(conceal); + cur.run = (int)run; + cur.mute_src = -2; + if ((q = stream_key(e, "mute_src"))) + cur.mute_src = *q == '"' ? -1 : atol(q); + for (i = 0; i < 8; i++) + cur.tone_id = (cur.tone_id << 1) | d[12 + i]; + for (i = 0; i < 6; i++) + cur.tone_ad = (cur.tone_ad << 1) | d[6 + i]; + cur.tone_ad = (cur.tone_ad << 1) | d[44]; + xombe_dec_decision_get(dec, &got); + if (got.cls != cur.cls || got.conceal != cur.conceal || got.run != cur.run || + (cur.conceal == XOMBE_CONCEAL_MUTE && got.mute_src != cur.mute_src)) { + decision_fail++; + if (verbose && decision_fail <= 20) + fprintf(stderr, "%s frame %ld: expect %d/%d/%d/%ld got %d/%d/%d/%lld\n", path, frame, + cur.cls, cur.conceal, cur.run, cur.mute_src, got.cls, got.conceal, got.run, + (long long)got.mute_src); + } + } + q = stream_key(h.line, "pcm"); + if (q && (q = strchr(q, '['))) { + q++; + while (nref < XOMBE_HALF_MAX && *q && *q != ']') { + char *endp; + ref[nref++] = (int16_t)strtol(q, &endp, 10); + if (endp == q) + break; + q = endp; + while (*q == ',' || *q == ' ') + q++; + } + } + if (nref != n) { + fprintf(stderr, "%s frame %ld: length %d, reference %d\n", path, frame, n, nref); + decision_fail++; + continue; + } + ld = level_db(pcm, n); + lr = level_db(ref, n); + dl = (ld > LEVEL_FLOOR_DB ? ld : LEVEL_FLOOR_DB) - (lr > LEVEL_FLOOR_DB ? lr : LEVEL_FLOOR_DB); + if (cur.conceal == XOMBE_CONCEAL_MUTE) + cat = CAT_MUTE; + else if (cur.conceal == XOMBE_CONCEAL_REPEAT) + cat = CAT_REPEAT; + else + cat = cur.cls == XOMBE_CLASS_SILENCE ? CAT_SILENCE : cur.cls == XOMBE_CLASS_TONE ? CAT_TONE + : CAT_VOICE; + deltas[cat][ndeltas[cat]++] = dl; + for (i = 0; i < n; i++) { + num += (double)ref[i] * ref[i]; + den += ((double)ref[i] - pcm[i]) * ((double)ref[i] - pcm[i]); + } + if (have_prev) { + int steady_mute = cur.conceal == XOMBE_CONCEAL_MUTE && prev.conceal == XOMBE_CONCEAL_MUTE && + prev.mute_src == cur.mute_src; + int steady_tone = cur.conceal == XOMBE_CONCEAL_NONE && cur.cls == XOMBE_CLASS_TONE && + prev.conceal == XOMBE_CONCEAL_NONE && prev.cls == XOMBE_CLASS_TONE && + prev.tone_id == cur.tone_id && prev.tone_ad == cur.tone_ad && + ((cur.tone_id >= 5 && cur.tone_id <= 122) || + (cur.tone_id >= 128 && cur.tone_id <= 143)); + int steady_cn = cur.conceal == XOMBE_CONCEAL_NONE && cur.cls == XOMBE_CLASS_SILENCE && + (prev.conceal == XOMBE_CONCEAL_MUTE || + (prev.conceal == XOMBE_CONCEAL_NONE && prev.cls == XOMBE_CLASS_SILENCE)); + if (steady_mute) { + steady_mute_n++; + if (fabs(dl) > steady_mute_max) + steady_mute_max = fabs(dl); + if (fabs(dl) > 2.0) + steady_fail++; + if (lr >= LEVEL_FLOOR_DB && nsnr_mute < MAX_CALLS) + snr_mute[nsnr_mute++] = 10.0 * log10(num / (den > 0 ? den : 1e-9)); + } + if (steady_tone) { + steady_tone_n++; + if (fabs(dl) > steady_tone_max) + steady_tone_max = fabs(dl); + if (fabs(dl) > 1.0) + steady_fail++; + } + if (steady_cn && nsnr_cn < MAX_CALLS && num > 0) + snr_cn[nsnr_cn++] = 10.0 * log10(num / (den > 0 ? den : 1e-9)); + } + } + } + if (!stream_close(&r)) + ok = 0; + return ok ? 0 : 1; +} + +int main(int argc, char **argv) +{ + int i, metrics = 0, fail = 0; + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--metrics")) { + metrics = 1; + continue; + } + if (run_file(argv[i], 1)) + return 2; + } + printf("T4(a) decisions: %ld/%ld frames match\n", frames_total - decision_fail, frames_total); + if (decision_fail) + fail = 1; + if (metrics) { + int c; + double m; + printf("T4(b) level, pooled |median| P90 |dL| share>3dB (limits)\n"); + for (c = 0; c < NCAT; c++) { + double absd[MAX_CALLS], med, p90, share; + int k, over = 0, ok; + for (k = 0; k < ndeltas[c]; k++) { + absd[k] = fabs(deltas[c][k]); + over += absd[k] > 3.0; + } + med = fabs(percentile(deltas[c], ndeltas[c], 0.5)); + p90 = percentile(absd, ndeltas[c], 0.9); + share = ndeltas[c] ? (double)over / ndeltas[c] : 0.0; + ok = med <= lim_median[c] && p90 <= lim_p90[c] && share <= lim_share[c]; + printf(" %-8s n=%5d %6.3f %8.3f %8.1f%% (%.2f / %.1f / %.0f%%) %s\n", cat_names[c], ndeltas[c], + med, p90, 100.0 * share, lim_median[c], lim_p90[c], 100.0 * lim_share[c], ok ? "ok" : "FAIL"); + if (!ok) + fail = 1; + } + printf("T4(c) steady state: mute calls %d (max |dL| %.2f dB, limit 2.0), tone calls %d (max %.2f dB, limit 1.0)" + ", %d violations %s\n", + steady_mute_n, steady_mute_max, steady_tone_n, steady_tone_max, steady_fail, + steady_fail ? "FAIL" : "ok"); + if (steady_fail) + fail = 1; + m = percentile(snr_mute, nsnr_mute, 0.5); + printf("T4(d) noise sync: steady mute median SNR %.1f dB over %d calls (>= 15) %s\n", m, nsnr_mute, + m >= 15.0 ? "ok" : "FAIL"); + if (m < 15.0) + fail = 1; + m = percentile(snr_cn, nsnr_cn, 0.5); + printf("T4(d) noise sync: steady comfort noise median SNR %.1f dB over %d calls (>= 12) %s\n", m, nsnr_cn, + m >= 12.0 ? "ok" : "FAIL"); + if (m < 12.0) + fail = 1; + } + printf("T4%s: %s\n", metrics ? "" : "(a)", fail ? "FAIL" : "PASS"); + return fail; +} diff --git a/xombe/test/test_tables.c b/xombe/test/test_tables.c new file mode 100644 index 0000000..368c321 --- /dev/null +++ b/xombe/test/test_tables.c @@ -0,0 +1,140 @@ +#include +#include +#include "../src/internal.h" +#include "../src/tables/tables.h" +#include "../src/tables/dsp_tables.h" +#include "ref.h" + +/* generated tables (scripts/gen_dsp_tables.py) against their closed forms, spectral blocks against the kernel + table's range, and the harmonic interpolation's end rules */ + +static int failures, checks; + +static void check(int ok, const char *what, int i) +{ + checks++; + if (!ok) { + failures++; + fprintf(stderr, "FAIL %s (item %d)\n", what, i); + } +} + +static int rounds_to(float t, double v) +{ + return fabs((double)t - v) <= 6e-8 * (fabs(v) > 1.0 ? fabs(v) : 1.0); +} + +int main(void) +{ + int J, m, i, L, k, N, n; + float a[XOMBE_LMAX + 1]; + + for (m = 0; m < 8; m++) + for (i = 0; i < 8; i++) + check(rounds_to(xombe__dct8[m][i], cos(XOMBE_PI * m * (i + 0.5) / 8.0)), "dct8", 8 * m + i); + for (J = 1; J <= XOMBE_DCT_BLK_J_MAX; J++) { + const float *kern = xombe__dct_blk + xombe__dct_blk_off[J]; + check(xombe__dct_blk_off[J] + XOMBE_DCT_BLK_ROWS * J <= XOMBE_DCT_BLK_SIZE, "dct_blk extent", J); + for (m = 0; m < XOMBE_DCT_BLK_ROWS; m++) + for (i = 0; i < J; i++) + check(rounds_to(kern[m * J + i], cos(XOMBE_PI * m * (i + 0.5) / J)), "dct_blk", 100 * J + 10 * m + i); + } + for (L = 9; L <= XOMBE_LMAX; L++) { + int sum = 0; + for (k = 0; k < 4; k++) { + check(xombe__blk[L][k] >= 1 && xombe__blk[L][k] <= XOMBE_DCT_BLK_J_MAX, "block length in kernel range", + 4 * L + k); + sum += xombe__blk[L][k]; + } + check(sum == L, "blocks cover L", L); + check(rounds_to(xombe__half_log2[L], 0.5 * log2((double)L)), "half_log2", L); + } + for (i = 0; i < XOMBE_GRAIN_RAMP; i++) { + check(rounds_to(xombe__ramp_cos[i], cos(XOMBE_PI * i / XOMBE_GRAIN_RAMP)), "ramp_cos", i); + check(rounds_to(xombe__ramp_sin[i], sin(XOMBE_PI * i / XOMBE_GRAIN_RAMP)), "ramp_sin", i); + } + for (n = 0; n <= XOMBE_HALF_MAX; n++) + check(rounds_to(xombe__sqrt_n[n], sqrt((double)n)), "sqrt_n", n); + for (N = XOMBE_HALF_MIN; N <= XOMBE_HALF_MAX; N++) + check(rounds_to(xombe__rsqrt_half[N - XOMBE_HALF_MIN], 1.0 / sqrt((double)N)), "rsqrt_half", N); + for (i = 0; i < XOMBE_B0_COUNT - 1; i++) { + check(rounds_to(xombe__w0_mid[i], sqrt((double)xombe__w0[i] * xombe__w0[i + 1])), "w0_mid", i); + check(xombe__w0_mid[i] < xombe__w0[i] && xombe__w0_mid[i] > xombe__w0[i + 1], "w0_mid between", i); + } + + for (k = 0; k < XOMBE_TW_N / 2; k++) { + double ang = -2.0 * XOMBE_PI * k / XOMBE_TW_N; + check(rounds_to(xombe__fft_tw[k].re, cos(ang)) && rounds_to(xombe__fft_tw[k].im, sin(ang)), "fft_tw", k); + } + +#if XOMBE_HAVE_ENCODER + { + /* init-time tables against their closed forms */ + double s = 0.0, s2 = 0.0, s4 = 0.0, h[2 * XOMBE_PITCH_LPF_HALF + 1]; + float lo, hi; + int j; + for (i = 0; i < XOMBE_BASE_WINDOW; i++) + check(rounds_to(xombe__base_win[i], ref_hamming(i, XOMBE_BASE_WINDOW)), "base_win", i); + for (j = -XOMBE_PITCH_LPF_HALF; j <= XOMBE_PITCH_LPF_HALF; j++) { + double x = 0.25 * j, sinc = j == 0 ? 1.0 : sin(XOMBE_PI * x) / (XOMBE_PI * x); + h[j + XOMBE_PITCH_LPF_HALF] = 0.25 * sinc * (0.54 + 0.46 * cos(XOMBE_PI * j / XOMBE_PITCH_LPF_HALF)); + s += h[j + XOMBE_PITCH_LPF_HALF]; + } + for (j = 0; j < 2 * XOMBE_PITCH_LPF_HALF + 1; j++) + check(rounds_to(xombe__pitch_lpf[j], h[j] / s), "pitch_lpf", j); + for (j = 0; j < XOMBE_PITCH_WIN; j++) + s2 += ref_hamming(j, XOMBE_PITCH_WIN) * ref_hamming(j, XOMBE_PITCH_WIN); + for (j = 0; j < XOMBE_PITCH_WIN; j++) { + double w2 = ref_hamming(j, XOMBE_PITCH_WIN) * ref_hamming(j, XOMBE_PITCH_WIN) / s2; + check(rounds_to(xombe__pitch_w2[j], w2), "pitch_w2", j); + s4 += w2 * w2; + } + check(fabs(xombe__pitch_sum_w4 - s4) <= 6e-8 * s4, "pitch_sum_w4", 0); + for (i = 0; i < XOMBE_TONE_SEG; i++) + check(rounds_to(xombe__tone_win[i], 0.5 - 0.5 * cos(2.0 * XOMBE_PI * i / (XOMBE_TONE_SEG - 1))), + "tone_win", i); + for (i = 0; i < XOMBE_TONE_IDS; i++) { /* filter gain at each tone component, float within 2.2e-5 dB */ + if (!xombe__tone_freqs(i, &lo, &hi)) + continue; + check(fabs(xombe__tone_hpf_gain_db(lo) - ref_hpf_gain_db(lo)) <= 1e-4, "tone_hpf_gain_db", i); + check(fabs(xombe__tone_hpf_gain_db(hi) - ref_hpf_gain_db(hi)) <= 1e-4, "tone_hpf_gain_db", i); + } + } + /* window transform table reaches the widest harmonic fit: half the spacing at the highest pitch, widened + by the voicing metric's 2% jitter, plus the interpolation's next point */ + check(0.5 * XOMBE_FFT * xombe__w0[0] * 1.02 * XOMBE_WTAB_OVERSAMPLE + 1.0 < XOMBE_WTAB_LEN - 1, + "window transform covers the harmonic fits", XOMBE_WTAB_LEN); + /* every analysis window, its energy, and its tabulated transform against double sums of the window */ + for (n = XOMBE_BASE_WINDOW; n <= XOMBE_MAX_WINDOW; n += 2) { + static float w[XOMBE_MAX_WINDOW]; + double s2 = 0.0, w0 = 0.0, worst = 0.0; + int h = (n - 1) / 2, q, j; + xombe__hamming(w, n); + for (i = 0; i < n; i++) { + check(fabs(w[i] - ref_hamming(i, n)) <= 1.2e-7, "hamming", 1000 * n + i); + s2 += ref_hamming(i, n) * ref_hamming(i, n); + w0 += ref_hamming(i, n); + } + check(fabs(xombe__hamming_sum2(n) - s2) <= 2e-7 * s2, "hamming_sum2", n); /* three roundings */ + for (q = 0; q < XOMBE_WTAB_LEN; q++) { + double nu = 2.0 * XOMBE_PI * q / ((double)XOMBE_WTAB_OVERSAMPLE * XOMBE_FFT), v = 0.0; + for (j = -h; j <= h; j++) + v += ref_hamming(j + h, n) * cos(nu * j); + v = fabs(xombe__hamming_dtft(n, q, (long)XOMBE_WTAB_OVERSAMPLE * XOMBE_FFT) - v); + if (v > worst) + worst = v; + } + check(worst <= 1e-6 * w0, "hamming_dtft", n); + } +#endif + + for (i = 0; i <= XOMBE_LMAX; i++) + a[i] = (float)i; + check(xombe__harmonic_lerp(a, 0, 0.7f) == 1.0f, "lerp holds a[1] below harmonic 1", 0); + check(xombe__harmonic_lerp(a, -3, 0.0f) == 1.0f, "lerp holds a[1] for negative positions", -3); + check(xombe__harmonic_lerp(a, XOMBE_LMAX, 0.5f) == (float)XOMBE_LMAX, "lerp holds a[LMAX] above", XOMBE_LMAX); + check(fabsf(xombe__harmonic_lerp(a, 10, 0.25f) - 10.25f) < 1e-5f, "lerp interior", 10); + + printf("tables: %d/%d checks pass\n", checks - failures, checks); + return failures ? 1 : 0; +} diff --git a/xombe/test/test_tones.c b/xombe/test/test_tones.c new file mode 100644 index 0000000..b8a8c23 --- /dev/null +++ b/xombe/test/test_tones.c @@ -0,0 +1,152 @@ +#include +#include +#include +#include +#include "../src/internal.h" +#include "tone_fit.h" + +#define FRAMES 30 +#define FIT_START (12 * 160) + +static void tone_bits(int id, int ad, uint8_t bytes[7]) +{ + uint8_t d[49]; + xombe__tone_frame_bits(id, ad, d); + xombe__pack49(d, bytes); +} + +static void decode_tone(const uint8_t bytes[7], double *x) +{ + xombe_dec dec; + int16_t pcm[160]; + int f, i; + xombe_dec_set_noise(xombe_dec_init(&dec, XOMBE_DMR), XOMBE_NOISE_CONFORMANCE, 0); + for (f = 0; f < FRAMES; f++) { + xombe_dec_frame_bits(&dec, bytes, 0, pcm); + for (i = 0; i < 160; i++) + x[f * 160 + i] = pcm[i]; + } +} + +static void compare_reference_table(const char *dir) +{ + static double x[FRAMES * 160]; + char path[4096], line[512], bits[64], kind[32]; + double max_df = 0.0, max_dl = 0.0; + int rows = 0; + FILE *f; + snprintf(path, sizeof(path), "%s/tone_table.tsv", dir); + f = fopen(path, "r"); + if (!f) { + perror(path); + return; + } + while (fgets(line, sizeof(line), f)) { + double f1, f2 = 0.0, level, freq[2], amp[2]; + uint8_t d[49], bytes[7]; + int idx, i, nf, c; + if (line[0] == '#') + continue; + nf = sscanf(line, "%d %31s %63s %lf %lf %lf", &idx, kind, bits, &f1, &f2, &level); + if (nf == 5) { + level = f2; + nf = 1; + } else if (nf == 6) { + nf = 2; + } else { + continue; + } + for (i = 0; i < 49; i++) + d[i] = (uint8_t)(bits[i] == '1'); + xombe__pack49(d, bytes); + decode_tone(bytes, x); + freq[0] = f1; + freq[1] = f2; + search_freqs(x + FIT_START, freq, nf, 0.01); + sinusoid_fit(x + FIT_START, FIT_LEN, freq, nf, amp); + for (c = 0; c < nf; c++) { + double df = fabs(freq[c] - (c ? f2 : f1)), dl = fabs(20.0 * log10(amp[c] / 32768.0) - level); + if (df > max_df) + max_df = df; + if (dl > max_dl) + max_dl = dl; + } + rows++; + } + fclose(f); + printf("reference tone table (informative): %d frames, max |frequency difference| %.2f Hz, " + "max |peak level difference| %.2f dB\n", rows, max_df, max_dl); +} + +int main(int argc, char **argv) +{ + static double x[FRAMES * 160]; + int id, fail = 0, cases = 0; + double worst_f_single = 0.0, worst_f_dtmf = 0.0, worst_f_knox = 0.0, worst_f_progress = 0.0; + double worst_l_single = 0.0, worst_l_dual = 0.0; + for (id = 5; id <= 163; id++) { + float flo, fhi; + int kind = xombe__tone_id_accepted(id) ? xombe__tone_freqs(id, &flo, &fhi) : 0, ad; + double freq[2], nominal[2], amp[2]; + int nf; + uint8_t bytes[7]; + if (!kind) + continue; + nf = kind; + nominal[0] = flo; + nominal[1] = fhi; + tone_bits(id, 90, bytes); + decode_tone(bytes, x); + freq[0] = nominal[0]; + freq[1] = nominal[1]; + search_freqs(x + FIT_START, freq, nf, kind == 1 ? 0.005 : 0.05); + if (kind == 1) { + double err = fabs(freq[0] - nominal[0]); + if (err > worst_f_single) + worst_f_single = err; + if (err > 0.1) { + fail++; + printf("FAIL id %d: %.3f Hz, nominal %.3f\n", id, freq[0], nominal[0]); + } + } else { + double tol = id >= 160 ? 0.04 : 0.01; + int c; + for (c = 0; c < 2; c++) { + double rel = fabs(freq[c] - nominal[c]) / nominal[c]; + double *worst = id >= 160 ? &worst_f_progress : id >= 144 ? &worst_f_knox : &worst_f_dtmf; + if (rel > *worst) + *worst = rel; + if (rel > tol) { + fail++; + printf("FAIL id %d component %d: %.2f Hz, nominal %.0f\n", id, c, freq[c], nominal[c]); + } + } + } + for (ad = 30; ad <= (kind == 1 ? 120 : 115); ad++) { + int c; + tone_bits(id, ad, bytes); + decode_tone(bytes, x); + sinusoid_fit(x + FIT_START, FIT_LEN, freq, nf, amp); + for (c = 0; c < nf; c++) { + double err = 20.0 * log10(amp[c] / 32768.0 + 1e-30) - expected_db(ad, freq[c]); + double *worst = kind == 1 ? &worst_l_single : &worst_l_dual; + if (fabs(err) > fabs(*worst)) + *worst = err; + if (fabs(err) > 0.5) { + fail++; + printf("FAIL id %d AD %d component %d: level error %+.2f dB\n", id, ad, c, err); + } + } + cases++; + } + } + printf("T5: %d tone frames; worst single-tone frequency error %.4f Hz (limit 0.1)\n", cases, worst_f_single); + printf("T5: worst frequency error DTMF %.2f%% (limit 1%%), Knox %.2f%% (limit 1%%), call progress %.2f%% " + "(limit 4%%)\n", + 100.0 * worst_f_dtmf, 100.0 * worst_f_knox, 100.0 * worst_f_progress); + printf("T5: worst level error single %+.3f dB, dual %+.3f dB (limit 0.5)\n", worst_l_single, worst_l_dual); + if (argc > 1) + compare_reference_table(argv[1]); + printf("T5: %s\n", fail ? "FAIL" : "PASS"); + return fail ? 1 : 0; +} diff --git a/xombe/test/tone_cmp.c b/xombe/test/tone_cmp.c new file mode 100644 index 0000000..c9e5c15 --- /dev/null +++ b/xombe/test/tone_cmp.c @@ -0,0 +1,490 @@ +/* AMBE+2 tone detector, reference vs merged (xombe__tone_detect over the generic search), on every segment position the + encoder reads: decoded tone frames (T5), synthetic E6 cases, the tone vectors, and speech and other non-tone + vectors. --full takes every AD in T5 (default every 6th), --list prints each disagreement, --time the slowest + segment of each detector. exits 1 on a regression (see verdict) */ +#include "../src/enc/tone_detect.c" /* its fit helpers are static */ +#include +#include +#include +#include "ref.h" + +#define MAXFILES 64 +#define T5_FRAMES 8 +#define T5_FIRST 3 /* decoded frames before the first segment */ + +/* reference: AMBE+2 detector before the merge into xombe__tone_search, per-ID filter gain as tabulated then */ +static float ref_hpf_db[XOMBE_TONE_IDS]; + +#define DUAL_REFINE_SPAN 0.025f +#define DUAL_TRIALS 24 /* 2 passes x 2 components x 3 steps x 2 signs */ + +/* the reference's float front end and correlation, as the float build has them */ +static void ref_correlate(const float *x, int len, float hz, component *c) +{ + float w = 2.0f * XOMBE_PI_F * hz / XOMBE_FS, hc = cosf(0.5f * w), hs = sinf(0.5f * w); + float cw = hc * hc - hs * hs, s = 0.0f, d = 0.0f, prev; + int n = len - 1; + if (cw >= 0.0f) { + float l = -4.0f * hs * hs; + for (; n > 0; n -= 2) { + d += x[n] + l * s; + s += d; + d += x[n - 1] + l * s; + s += d; + } + if (n == 0) { + d += x[0] + l * s; + s += d; + } + prev = s - d; + } else { + float l = 4.0f * hc * hc; + for (; n > 0; n -= 2) { + d = x[n] + l * s - d; + s = d - s; + d = x[n - 1] + l * s - d; + s = d - s; + } + if (n == 0) { + d = x[0] + l * s - d; + s = d - s; + } + prev = d - s; + } + c->hz = hz; + c->rc = s - cw * prev; + c->rs = 2.0f * hs * hc * prev; + c->h[0] = hc; + c->h[1] = hs; + c->m[0] = cosf((float)(2 * len - 1) * 0.5f * w); + c->m[1] = sinf((float)(2 * len - 1) * 0.5f * w); +} + +static void ref_fit_component(const float *x, int len, float hz, component *c) +{ + ref_correlate(x, len, hz, c); + gram(c, c, len, c->g); +} + +static float ref_prepare(xombe_enc *e, const int16_t *seg, float *x, float pw[XOMBE_TONE_FFT / 2 + 1]) +{ + static const float min_amp = 32768.0f * 0.0031622777f; + xombe_cpx *X = e->tone_spec; + float mean, energy = 0.0f; + long sum = 0; + int n, k; + for (n = 0; n < XOMBE_TONE_SEG; n++) + sum += seg[n]; + mean = (float)sum / XOMBE_TONE_SEG; + for (n = 0; n < XOMBE_TONE_SEG; n++) { + x[n] = (float)seg[n] - mean; + energy += x[n] * x[n]; + } + if (energy / XOMBE_TONE_SEG < 0.5f * min_amp * min_amp) + return 0.0f; + memset(e->tone_spec, 0, sizeof(e->tone_spec)); + for (n = 0; n < XOMBE_TONE_SEG; n++) { + float v = x[n] * xombe__tone_win[n]; + if (n & 1) + X[n >> 1].im = v; + else + X[n >> 1].re = v; + } + xombe__rfft_packed(X, XOMBE_TONE_FFT, xombe__fft_tw, XOMBE_TW_N); + for (k = 0; k <= XOMBE_TONE_FFT / 2; k++) + pw[k] = X[k].re * X[k].re + X[k].im * X[k].im; + return energy; +} + +static float ref_band_total(const float *pw) +{ + float total = 0.0f; + int k; + for (k = (int)ceilf(GATE_LO_HZ / BIN_HZ); k <= (int)floorf(GATE_HI_HZ / BIN_HZ); k++) + total += pw[k]; + return total; +} + +static int ref_gate_pass(const float *pw, const float nominal[2], float total) +{ + float near = 0.0f; + int k, r0lo, r0hi, r1lo, r1hi; + gate_run(nominal[0], &r0lo, &r0hi); + gate_run(nominal[1], &r1lo, &r1hi); + for (k = 0; k <= XOMBE_TONE_FFT / 2; k++) + if ((k >= r0lo && k <= r0hi) || (k >= r1lo && k <= r1hi)) + near += pw[k]; + return !(near < DUAL_GATE_SHARE * total); +} + +/* returns 1 if seen[n] repeats an earlier pair, already rejected since none beats the current best */ +static int visited(const float seen[][2], int n) +{ + int i; + for (i = 0; i < n; i++) + if (seen[i][0] == seen[n][0] && seen[i][1] == seen[n][1]) + return 1; + return 0; +} + +static int ref_detect(xombe_enc *e, const int16_t *seg, int *id, int *ad) +{ + float x[XOMBE_TONE_SEG], energy, total, best_dual = -1.0f, e1, amp1[2] = {0.0f, 0.0f}; + component single; + float pw[XOMBE_TONE_FFT / 2 + 1]; + int k, peak = 2, single_id = -1, dual_id = -1, dual_ad = 0, cand; + energy = ref_prepare(e, seg, x, pw); + if (energy == 0.0f) + return 0; + for (k = 3; k < XOMBE_TONE_FFT / 2; k++) + if (pw[k] > pw[peak]) + peak = k; + { + float a = 0.5f * logf(pw[peak - 1] + 1e-30f), b = 0.5f * logf(pw[peak] + 1e-30f); + float c = 0.5f * logf(pw[peak + 1] + 1e-30f), den = a - 2.0f * b + c; + float delta = den != 0.0f ? 0.5f * (a - c) / den : 0.0f; + ref_fit_component(x, XOMBE_TONE_SEG, ((float)peak + delta) * BIN_HZ, &single); + } + e1 = fit(energy, &single, 1, XOMBE_TONE_SEG, amp1); + cand = (int)floorf(single.hz / SINGLE_ID_HZ + 0.5f); + if (e1 >= EXPLAINED_MIN && cand >= 5 && cand <= 122) + single_id = cand; + total = ref_band_total(pw); + for (cand = 128; cand <= 163; cand++) { + float lo, hi, nominal[2], amp[2], ex; + component comp[2]; + float seen[DUAL_TRIALS + 1][2]; + int pass, c, s, nseen; + if (xombe__tone_freqs(cand, &lo, &hi) != 2) + continue; + nominal[0] = lo; + nominal[1] = hi; + if (!ref_gate_pass(pw, nominal, total)) + continue; + ref_fit_component(x, XOMBE_TONE_SEG, nominal[0], &comp[0]); + ref_fit_component(x, XOMBE_TONE_SEG, nominal[1], &comp[1]); + ex = fit(energy, comp, 2, XOMBE_TONE_SEG, amp); + seen[0][0] = comp[0].hz; + seen[0][1] = comp[1].hz; + nseen = 1; + for (pass = 0; pass < 2; pass++) + for (c = 0; c < 2; c++) + for (s = 0; s < 3; s++) { + static const float steps[3] = {0.01f, 0.005f, 0.0025f}; + int sign; + for (sign = -1; sign <= 1; sign += 2) { + component keep = comp[c]; + float hz = keep.hz + (float)sign * steps[s] * nominal[c], trial_amp[2] = {0.0f, 0.0f}, te; + if (fabsf(hz - nominal[c]) > DUAL_REFINE_SPAN * nominal[c] * (1.0f + 1e-6f)) + continue; + seen[nseen][c] = hz; + seen[nseen][1 - c] = comp[1 - c].hz; + if (visited(seen, nseen)) + continue; + nseen++; + ref_fit_component(x, XOMBE_TONE_SEG, hz, &comp[c]); + te = fit(energy, comp, 2, XOMBE_TONE_SEG, trial_amp); + if (te > ex) { + ex = te; + amp[0] = trial_amp[0]; + amp[1] = trial_amp[1]; + } else { + comp[c] = keep; + } + } + } + if (ex >= EXPLAINED_MIN && fabsf(20.0f * log10f((amp[0] + 1e-30f) / (amp[1] + 1e-30f))) <= DUAL_TWIST_DB && + ex > best_dual) { + best_dual = ex; + dual_id = cand; + dual_ad = ad_from_level(0.5f * (peak_db(amp[0]) + peak_db(amp[1])) - ref_hpf_db[cand]); + } + } + if (dual_id >= 0 && (single_id < 0 || best_dual > e1 + DUAL_PREFERENCE)) { + *id = dual_id; + *ad = dual_ad; + return 1; + } + if (single_id >= 0) { + *id = single_id; + *ad = ad_from_level(peak_db(amp1[0]) - ref_hpf_db[single_id]); + return 1; + } + return 0; +} + +/* the detector under test */ +static int new_detect(xombe_enc *e, const int16_t *seg, int *id, int *ad) +{ + return xombe__tone_detect(e, seg, id, ad); +} + +typedef struct { + const char *name; + long segs, det[2], id_diff, ad_diff, max_dad, only[2], frames[2], truth, miss[2], wrong[2], ad_off[2]; +} stats; + +static struct xombe_enc enc_ref, enc_new; +static int list, timing; +static double slow_t[2]; +static char slow_at[2][128]; + +static double now(void) +{ + return (double)clock() / CLOCKS_PER_SEC; +} + +static void reset_decide(void) +{ + enc_ref.tone_prev_id = enc_new.tone_prev_id = -1; + enc_ref.tone_confirmed = enc_new.tone_confirmed = 0; + enc_ref.tone_hold_used = enc_new.tone_hold_used = 0; + enc_ref.tone_last_id = enc_new.tone_last_id = 0; + enc_ref.tone_last_ad = enc_new.tone_last_ad = 0; +} + +/* both detectors on one segment, true_id > 0 names the tone it holds (0: no tone, -1: unknown) */ +static void one(stats *s, const int16_t *seg, int true_id, int true_ad, const char *where, long pos) +{ + struct xombe_enc *es[2] = {&enc_ref, &enc_new}; + int det[2], id[2] = {-1, -1}, ad[2] = {0, 0}, k; + for (k = 0; k < 2; k++) { + double t0 = timing ? now() : 0.0; + det[k] = (k ? new_detect : ref_detect)(es[k], seg, &id[k], &ad[k]); + if (timing) { + double t = now() - t0; + if (t > slow_t[k]) { + slow_t[k] = t; + snprintf(slow_at[k], sizeof(slow_at[k]), "%s @%ld", where, pos); + } + } + if (!det[k]) + id[k] = -1; + s->det[k] += det[k]; + { + int tid, tad; + s->frames[k] += xombe__tone_decide(es[k], det[k], id[k], ad[k], &tid, &tad); + } + if (true_id > 0) { + if (!det[k]) + s->miss[k]++; + else if (id[k] != true_id) + s->wrong[k]++; + else if (true_ad >= 0 && ad[k] != true_ad) + s->ad_off[k]++; + } + } + s->segs++; + s->truth += true_id > 0; + if (det[0] != det[1]) { + s->only[det[1]]++; + } else if (det[0] && id[0] != id[1]) { + s->id_diff++; + } else if (det[0] && ad[0] != ad[1]) { + int d = abs(ad[0] - ad[1]); + s->ad_diff++; + s->max_dad = d > s->max_dad ? d : s->max_dad; + } else { + return; + } + if (list) + printf(" %s @%ld: ref %d/%d new %d/%d (true %d/%d)\n", where, pos, id[0], ad[0], id[1], ad[1], true_id, + true_ad); +} + +static void report(const stats *s) +{ + printf("%-8s %7ld segs det %6ld %6ld tone frames %6ld %6ld ref-only %4ld new-only %4ld ID diff %4ld " + "AD diff %4ld (max %ld)", + s->name, s->segs, s->det[0], s->det[1], s->frames[0], s->frames[1], s->only[0], s->only[1], s->id_diff, + s->ad_diff, s->max_dad); + if (s->truth) + printf("\n%-8s %7ld true missed %4ld %4ld wrong ID %4ld %4ld AD off %4ld %4ld", "", s->truth, s->miss[0], + s->miss[1], s->wrong[0], s->wrong[1], s->ad_off[0], s->ad_off[1]); + printf("\n"); +} + +static int16_t *load(const char *path, long *n) +{ + FILE *f = fopen(path, "rb"); + long size; + int16_t *x; + if (!f) { + perror(path); + exit(2); + } + fseek(f, 0, SEEK_END); + size = ftell(f); + fseek(f, 0, SEEK_SET); + *n = size / 2; + x = calloc((size_t)*n + XOMBE_TONE_SEG, sizeof(int16_t)); /* zero tail, as the encoder flushes */ + if (fread(x, sizeof(int16_t), (size_t)*n, f) != (size_t)*n) + exit(2); + fclose(f); + return x; +} + +/* every segment at 160k of x[0..n), zeros past the end; tone true_id over [on, off) */ +static void run_signal(stats *s, const int16_t *x, long n, const char *name, int true_id, int true_ad, long on, + long off) +{ + long p; + reset_decide(); + for (p = 0; p < n; p += XOMBE_FRAME) { + int t = true_id > 0 && p >= on && p + XOMBE_TONE_SEG <= off ? true_id : true_id > 0 ? -1 : true_id; + one(s, x + p, t, true_ad, name, p); + } +} + +static void run_file(stats *s, const char *path, int tone) +{ + long n; + int16_t *x = load(path, &n); + run_signal(s, x, n, path, tone ? -1 : 0, 0, 0, 0); + free(x); +} + +static void run_t5(stats *s, int ad_step) +{ + static int16_t x[T5_FRAMES * XOMBE_FRAME]; + int id, ad, f; + for (id = 5; id <= 163; id++) { + float lo, hi; + if (!xombe__tone_id_accepted(id) || !xombe__tone_freqs(id, &lo, &hi)) + continue; + for (ad = 30; ad <= 120; ad += ad_step) { + xombe_dec dec; + uint8_t d[49], bytes[7]; + char where[32]; + xombe__tone_frame_bits(id, ad, d); + xombe__pack49(d, bytes); + xombe_dec_set_noise(xombe_dec_init(&dec, XOMBE_DMR), XOMBE_NOISE_CONFORMANCE, 0); + for (f = 0; f < T5_FRAMES; f++) + xombe_dec_frame_bits(&dec, bytes, 0, x + f * XOMBE_FRAME); + snprintf(where, sizeof(where), "T5 id %d ad %d", id, ad); + reset_decide(); + for (f = T5_FIRST; (f + 1) * XOMBE_FRAME + XOMBE_TONE_SEG - XOMBE_FRAME <= T5_FRAMES * XOMBE_FRAME; f++) + one(s, x + f * XOMBE_FRAME, id, ad, where, f * XOMBE_FRAME); + } + } +} + +/* tools/e6.py gen: DTMF at -16 dBFS, Knox and call progress at -20, single tones at 300, 1000, 2000, and 3000 Hz + from -6 to -46 dBFS, each 0.4 s between 0.5 s and 0.3 s of silence, phases from a fixed LCG */ +static void run_e6(stats *s) +{ + static int16_t x[8000 + 1600 + XOMBE_TONE_SEG]; + static const int singles[4] = {300, 1000, 2000, 3000}; + unsigned lcg = 20261019u; + int c, n, len = 3200, on = 4000, total = on + len + 2400; + for (c = 0; c < 36 + 20; c++) { + double f[2], lev, ph[2]; + int id, nf, i; + char where[32]; + float lo, hi; + if (c < 36) { + id = 128 + c; + xombe__tone_freqs(id, &lo, &hi); + f[0] = lo; + f[1] = hi; + nf = 2; + lev = id < 144 ? -16.0 : -20.0; + } else { + f[0] = singles[(c - 36) / 5]; + lev = -6.0 - 10.0 * ((c - 36) % 5); + id = (int)floor(f[0] / 31.25 + 0.5); + nf = 1; + } + for (i = 0; i < nf; i++) { + lcg = lcg * 1664525u + 1013904223u; + ph[i] = 2.0 * XOMBE_PI * (lcg >> 8) / 16777216.0; + } + memset(x, 0, sizeof(x)); + for (n = 0; n < len; n++) { + double v = 0.0; + for (i = 0; i < nf; i++) + v += 32768.0 * pow(10.0, lev / 20.0) * cos(2.0 * XOMBE_PI * f[i] / XOMBE_FS * n + ph[i]); + v = floor(v + 0.5); + x[on + n] = (int16_t)(v > 32767 ? 32767 : v < -32768 ? -32768 : v); + } + snprintf(where, sizeof(where), "E6 id %d %.0f dBFS", id, lev); + run_signal(s, x, total, where, id, -1, on, on + len); + } +} + +int main(int argc, char **argv) +{ + static const char *tone_vec[] = {"e7/tones.raw", "dstar/tn.in.raw", "dstar/kx.in.raw", "dstar/tn.dec.raw", + "dstar/kx.dec.raw"}; + static const char *speech_vec[] = { + "e3/es1_orig.raw", "e3/es2_orig.raw", "e3/es3_orig.raw", "e3/sn10_orig.raw", + "e3/ttsc_orig.raw", "e3/ttsf_orig.raw", "e3/ttsl_orig.raw", + "perceptual/es2_orig.raw", "perceptual/es3_orig.raw", "perceptual/es4_orig.raw", + "perceptual/es1_nsdtx_off_ref.raw", "perceptual/es1_nsdtx_on_ref.raw", "perceptual/es2_ref.raw", + "perceptual/es3_ref.raw", "perceptual/es4_ref.raw", "e5/es1_lead0.5s.raw", "e5/hp5.raw", "e5/low5.raw", + "e7/glide.raw", "e7/mix.raw", "e7/saw150.raw", "dstar/sp.in.raw", "dstar/nz.in.raw", "dstar/sp.dec.raw", + "dstar/sper.dec.raw", "dstar/nz.dec.raw"}; + const char *extra_tone[MAXFILES], *extra_speech[MAXFILES]; + stats t5, e6, tv, sp; + char path[4096]; + int i, full = 0, ntone = 0, nspeech = 0, bad = 0; + if (argc < 2) { + fprintf(stderr, "usage: tone_cmp VEC [--full] [--list] [--time] [--tones FILE]... [--speech FILE]...\n"); + return 2; + } + for (i = 2; i < argc; i++) { + if (!strcmp(argv[i], "--full")) + full = 1; + else if (!strcmp(argv[i], "--list")) + list = 1; + else if (!strcmp(argv[i], "--time")) + timing = 1; + else if (!strcmp(argv[i], "--tones") && i + 1 < argc && ntone < MAXFILES) + extra_tone[ntone++] = argv[++i]; + else if (!strcmp(argv[i], "--speech") && i + 1 < argc && nspeech < MAXFILES) + extra_speech[nspeech++] = argv[++i]; + else + return 2; + } + memset(&t5, 0, sizeof(t5)); + memset(&e6, 0, sizeof(e6)); + memset(&tv, 0, sizeof(tv)); + memset(&sp, 0, sizeof(sp)); + t5.name = "T5"; + e6.name = "E6"; + tv.name = "tones"; + sp.name = "speech"; + for (i = 0; i < XOMBE_TONE_IDS; i++) { + float lo, hi; + ref_hpf_db[i] = xombe__tone_freqs(i, &lo, &hi) ? (float)(0.5 * (ref_hpf_gain_db(lo) + ref_hpf_gain_db(hi))) + : 0.0f; + } + run_t5(&t5, full ? 1 : 6); + run_e6(&e6); + for (i = 0; i < (int)(sizeof(tone_vec) / sizeof(tone_vec[0])); i++) { + snprintf(path, sizeof(path), "%s/%s", argv[1], tone_vec[i]); + run_file(&tv, path, 1); + } + for (i = 0; i < ntone; i++) + run_file(&tv, extra_tone[i], 1); + for (i = 0; i < (int)(sizeof(speech_vec) / sizeof(speech_vec[0])); i++) { + snprintf(path, sizeof(path), "%s/%s", argv[1], speech_vec[i]); + run_file(&sp, path, 0); + } + for (i = 0; i < nspeech; i++) + run_file(&sp, extra_speech[i], 0); + printf("columns: reference, new\n"); + report(&t5); + report(&e6); + report(&tv); + report(&sp); + if (timing) + printf("slowest: reference %.1f us (%s), new %.1f us (%s)\n", 1e6 * slow_t[0], slow_at[0], 1e6 * slow_t[1], + slow_at[1]); + /* verdict: no new speech detections, and no T5 or E6 tone the reference finds that the new one misses */ + bad |= sp.only[1] != 0 || sp.frames[1] > sp.frames[0]; + bad |= t5.miss[1] + t5.wrong[1] > t5.miss[0] + t5.wrong[0]; + bad |= e6.miss[1] + e6.wrong[1] > e6.miss[0] + e6.wrong[0]; + printf("tone_cmp: %s\n", bad ? "FAIL" : "PASS"); + return bad; +} diff --git a/xombe/test/tone_fit.h b/xombe/test/tone_fit.h new file mode 100644 index 0000000..fdba0b9 --- /dev/null +++ b/xombe/test/tone_fit.h @@ -0,0 +1,85 @@ +#ifndef XOMBE_TEST_TONE_FIT_H +#define XOMBE_TEST_TONE_FIT_H + +/* least-squares sinusoid fits of decoded tones, FIT_LEN samples */ + +#include +#include +#include "ref.h" + +#define FIT_LEN 1600 + +static inline double sinusoid_fit(const double *x, int n, const double *freq, int nf, double *amp) +{ + double basis[4][FIT_LEN], g[16], r[4], energy = 0.0, explained = 0.0; + int c, i, j, m = 2 * nf; + for (c = 0; c < nf; c++) { + double w = 2.0 * XOMBE_PI * freq[c] / 8000.0, cr = cos(w), ci = sin(w), pr = 1.0, pi = 0.0; + for (i = 0; i < n; i++) { + double t; + basis[2 * c][i] = pr; + basis[2 * c + 1][i] = pi; + t = pr * cr - pi * ci; + pi = pr * ci + pi * cr; + pr = t; + } + } + for (i = 0; i < m; i++) { + r[i] = 0.0; + for (j = 0; j < m; j++) { + double s = 0.0; + int k; + for (k = 0; k < n; k++) + s += basis[i][k] * basis[j][k]; + g[i * m + j] = s; + } + for (j = 0; j < n; j++) + r[i] += basis[i][j] * x[j]; + } + { + double rr[4]; + memcpy(rr, r, sizeof(rr)); + if (!ref_solve(g, r, m)) + return 1e300; + for (i = 0; i < m; i++) + explained += r[i] * rr[i]; + } + for (i = 0; i < n; i++) + energy += x[i] * x[i]; + for (c = 0; c < nf; c++) + amp[c] = hypot(r[2 * c], r[2 * c + 1]); + return energy - explained; +} + +static inline void search_freqs(const double *x, double *freq, int nf, double span) +{ + int c, round; + double amp[2]; + for (round = 0; round < 2; round++) { + for (c = 0; c < nf; c++) { + double centre = freq[c], step = centre * span / 100.0, best = freq[c], bestr = 1e300; + int pass, k; + for (pass = 0; pass < 4; pass++) { + for (k = -100; k <= 100; k++) { + double r; + freq[c] = centre + k * step; + r = sinusoid_fit(x, FIT_LEN, freq, nf, amp); + if (r < bestr) { + bestr = r; + best = freq[c]; + } + } + centre = best; + step /= 50.0; + } + freq[c] = best; + } + } +} + +static inline double expected_db(int ad, double f) +{ + return 20.0 * log10(2.0 * exp2(xombe__tone_log2_amp(ad)) / 32768.0) + ref_hpf_gain_db(f); +} + +#endif diff --git a/xombe/test/tools.sh b/xombe/test/tools.sh new file mode 100644 index 0000000..5810ef7 --- /dev/null +++ b/xombe/test/tools.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# tools.sh BUILD VECTORS: command-line contracts of xombe-enc, xombe-dec, and xombe-xc +B=$1; V=$2; T=$B/tools_out; mkdir -p "$T"; fails=0 +expect() { # expect STATUS DESC CMD... + want=$1; what=$2; shift 2 + "$@" > "$T/out.txt" 2> "$T/err.txt"; got=$? + if [ "$got" -ne "$want" ]; then echo "FAIL $what: exit $got, want $want"; cat "$T/err.txt"; fails=$((fails + 1)); fi +} +have() { [ -x "$B/$1" ]; } +partial() { # partial WHO: the last command reported the partial final frame + grep -q "error: partial final frame" "$T/err.txt" || { echo "FAIL $1 partial frame message"; fails=$((fails + 1)); } +} +for t in xombe-enc xombe-dec xombe-xc; do + have $t || continue + expect 0 "$t --help" "$B/$t" --help + grep -q "usage: $t" "$T/out.txt" || { echo "FAIL $t --help text"; fails=$((fails + 1)); } + expect 2 "$t unknown option" "$B/$t" --nope a b + expect 2 "$t missing paths" "$B/$t" +done +head -c 1001 "$V/dstar/sp.in.raw" > "$T/odd.raw" +head -c 100 "$V/dstar/sp.dstar" > "$T/odd.dstar" +if have xombe-enc; then + expect 0 "enc partial final frame" "$B/xombe-enc" "$T/odd.raw" "$T/odd.amb" + grep -q "partial final frame" "$T/err.txt" || { echo "FAIL enc partial frame warning"; fails=$((fails + 1)); } + expect 2 "enc bad on/off" "$B/xombe-enc" --ns maybe "$T/odd.raw" "$T/x" + expect 2 "enc bad number" "$B/xombe-enc" --vscale 0 "$T/odd.raw" "$T/x" + expect 2 "enc bad quantizer" "$B/xombe-enc" --quant maybe "$T/odd.raw" "$T/x" + expect 0 "enc open quantizer" "$B/xombe-enc" --quant open "$T/odd.raw" "$T/x" + if "$B/xombe-enc" --help | grep -q "^ --dstar .*not in this build"; then + expect 2 "enc --dstar without D-STAR" "$B/xombe-enc" --dstar "$T/odd.raw" "$T/x" + else + expect 2 "enc --dstar with --air" "$B/xombe-enc" --dstar --air "$T/odd.raw" "$T/x" + expect 0 "enc --dual" "$B/xombe-enc" --dual "$T/dual.dstar" "$T/odd.raw" "$T/dual.amb" + [ "$(wc -c < "$T/dual.dstar")" -eq 27 ] || { echo "FAIL enc --dual frame count"; fails=$((fails + 1)); } + fi +fi +if have xombe-dec; then + expect 2 "dec two input formats" "$B/xombe-dec" --bits --air "$T/odd.dstar" "$T/x" + expect 2 "dec bad --lost" "$B/xombe-dec" --lost 3-1 "$T/odd.dstar" "$T/x" + head -c 15 "$V/e3/es1.ref.d0.amb" > "$T/odd.amb" + expect 1 "dec truncated .amb frame" "$B/xombe-dec" "$T/odd.amb" "$T/x" + partial "dec" + if "$B/xombe-dec" --help | grep -q "^ --dstar .*not in this build"; then + expect 2 "dec --dstar without D-STAR" "$B/xombe-dec" --dstar "$T/odd.dstar" "$T/x" + else + expect 1 "dec truncated D-STAR frame" "$B/xombe-dec" --dstar "$T/odd.dstar" "$T/x" + partial "dec --dstar" + expect 0 "dec --lost" "$B/xombe-dec" --dstar --decisions --lost 2,5-6 "$V/dstar/sp.dstar" "$T/x" + [ "$(grep -c " erasure " "$T/err.txt")" -eq 3 ] || { echo "FAIL dec --lost decisions"; fails=$((fails + 1)); } + fi +fi +if have xombe-xc; then + expect 1 "xc truncated frame" "$B/xombe-xc" "$T/odd.dstar" "$T/x" + partial "xc" + expect 0 "xc --lost" "$B/xombe-xc" --decisions --lost 1 "$V/dstar/sp.r33" "$T/x" + [ "$(grep -c " erasure " "$T/err.txt")" -eq 1 ] || { echo "FAIL xc --lost decisions"; fails=$((fails + 1)); } + if "$B/xombe-xc" --help | grep -q "^ --reverse .*not in this build"; then + expect 2 "xc --reverse without the encoder" "$B/xombe-xc" --reverse "$V/dstar/sp.dstar" "$T/x" + else + expect 0 "xc --reverse --lost" "$B/xombe-xc" --reverse --decisions --lost 0 "$V/dstar/sp.dstar" "$T/x" + [ "$(grep -c " erasure " "$T/err.txt")" -eq 1 ] || { echo "FAIL xc --reverse --lost"; fails=$((fails + 1)); } + expect 0 "xc --reverse --amb" "$B/xombe-xc" --reverse --amb "$V/dstar/sper.dstar" "$T/rt.amb" + expect 0 "xc --amb" "$B/xombe-xc" --amb "$T/rt.amb" "$T/rt_amb.dstar" + "$B/xombe-xc" --reverse "$V/dstar/sper.dstar" "$T/rt.r33" && "$B/xombe-xc" "$T/rt.r33" "$T/rt_r33.dstar" + cmp -s "$T/rt_amb.dstar" "$T/rt_r33.dstar" || { echo "FAIL xc --amb round trip differs from r33"; fails=$((fails + 1)); } + fi + expect 1 "xc --amb on a non-.amb file" "$B/xombe-xc" --amb "$V/dstar/sp.r33" "$T/x" +fi +[ $fails -eq 0 ] && echo "tools: ok" +exit $fails diff --git a/xombe/test/trace_cmp.py b/xombe/test/trace_cmp.py new file mode 100644 index 0000000..cf4661c --- /dev/null +++ b/xombe/test/trace_cmp.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +"""compares two stage dumps from test/trace_dump (or another implementation writing the same records) and +reports, per stage, how far the second is from the first + +absolute differences: log-amplitude stages (DEQUANT, SMOOTH, SET, TARGET), VAD decision and metric (VAD), +and phases (PHASE, wrapped) +log2 ratios: linear amplitudes (ENHANCED, SHAPED), ignoring harmonics below --floor in the reference +SNR over the whole dump: SYNTH +records match by frame, half, and stage, a record whose length or f0 differs is a structural mismatch +exits 1 if any limit given on the command line is exceeded or any record is unmatched""" +import argparse +import math +import struct +import sys + +STAGES = ['DEQUANT', 'SMOOTH', 'SET', 'ENHANCED', 'PHASE', 'SHAPED', 'SYNTH', 'TARGET', 'VAD'] +LOG_STAGES = {'DEQUANT', 'SMOOTH', 'SET', 'TARGET', 'VAD'} +LIN_STAGES = {'ENHANCED', 'SHAPED'} + + +def read(path): + recs = {} + with open(path, 'rb') as f: + data = f.read() + pos = 0 + while pos < len(data): + if pos + 12 > len(data): + sys.exit('%s: truncated record header at byte %d' % (path, pos)) + frame, half, stage, n, f0 = struct.unpack_from(' len(data): + sys.exit('%s: truncated record at byte %d' % (path, pos)) + v = struct.unpack_from('<%df' % n, data, pos) + pos += 4 * n + key = (frame, half, stage) + # a stage may fire more than once per half, keep them in order + recs.setdefault(key, []).append((f0, v)) + return recs + + +def main(): + ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + ap.add_argument('ref') + ap.add_argument('test') + ap.add_argument('--floor', type=float, default=1e-3, help='linear amplitude below which ENHANCED/SHAPED ' + 'harmonics are not compared (default 1e-3, far below one output LSB)') + ap.add_argument('--max-log', type=float, help='limit on the log2 stages and linear-stage log2 ratios') + ap.add_argument('--max-phase', type=float, help='limit on PHASE differences, radians') + ap.add_argument('--min-snr', type=float, help='limit on SYNTH SNR, dB') + args = ap.parse_args() + + a, b = read(args.ref), read(args.test) + stats = {s: {'n': 0, 'max': 0.0, 'where': None, 'sig': 0.0, 'err': 0.0, 'struct': 0} for s in STAGES} + unmatched = len(set(a) ^ set(b)) + for key in sorted(set(a) & set(b)): + name = STAGES[key[2]] if key[2] < len(STAGES) else 'stage%d' % key[2] + st = stats.setdefault(name, {'n': 0, 'max': 0.0, 'where': None, 'sig': 0.0, 'err': 0.0, 'struct': 0}) + for (f0a, va), (f0b, vb) in zip(a[key], b[key]): + st['n'] += 1 + if len(va) != len(vb) or abs(f0a - f0b) > 1e-6 * max(abs(f0a), 1e-3): + st['struct'] += 1 + continue + for i, (x, y) in enumerate(zip(va, vb)): + if name in LOG_STAGES: + d = abs(x - y) + elif name == 'PHASE': + d = abs(math.remainder(x - y, 2.0 * math.pi)) + elif name in LIN_STAGES: + if x < args.floor: + continue + d = abs(math.log2(max(y, 1e-30) / x)) + else: + st['sig'] += x * x + st['err'] += (x - y) * (x - y) + d = abs(x - y) + if d > st['max']: + st['max'], st['where'] = d, (key[0], key[1], i) + + bad = unmatched > 0 + print('%-9s %8s %6s %12s %s' % ('stage', 'records', 'struct', 'max diff', 'worst (frame, half, index)')) + for name, st in stats.items(): + if not st['n']: + continue + line = '%-9s %8d %6d %12.3g %s' % (name, st['n'], st['struct'], st['max'], st['where']) + if name == 'SYNTH': + snr = 10 * math.log10(st['sig'] / st['err']) if st['err'] > 0 else float('inf') + line += ' SNR %.1f dB' % snr + if args.min_snr is not None and snr < args.min_snr: + bad = True + elif name == 'PHASE': + if args.max_phase is not None and st['max'] > args.max_phase: + bad = True + elif args.max_log is not None and st['max'] > args.max_log: + bad = True + bad |= st['struct'] > 0 + print(line) + if unmatched: + print('%d records present in only one dump' % unmatched) + sys.exit(1 if bad else 0) + + +if __name__ == '__main__': + main() diff --git a/xombe/test/trace_dump.c b/xombe/test/trace_dump.c new file mode 100644 index 0000000..d38ff35 --- /dev/null +++ b/xombe/test/trace_dump.c @@ -0,0 +1,138 @@ +/* dumps the codec's stage taps (src/state.h) for one input, for test/trace_cmp.py to compare two builds or + against another implementation, decoder stages in two 80-sample halves per frame, encoder stages in the default + configuration + OUT.trace: little-endian records, u32 frame, u8 half, u8 stage (enum xombe_stage), u16 n, f32 f0, n x f32 + encoder records carry the frame they belong to (the call that returned its bits, less XOMBE_ENC_DELAY) + and half 0 */ +#include +#include +#include +#include "../src/internal.h" +#include "../tools/io.h" + +typedef struct { + FILE *f; + const char *path; + uint32_t frame; + uint8_t half; + int failed; +} dump; + +static void put_u32(uint8_t *p, uint32_t v) +{ + p[0] = (uint8_t)v; + p[1] = (uint8_t)(v >> 8); + p[2] = (uint8_t)(v >> 16); + p[3] = (uint8_t)(v >> 24); +} + +static void put_f32(uint8_t *p, float x) +{ + uint32_t v; + memcpy(&v, &x, sizeof(v)); + put_u32(p, v); +} + +static void tap(void *ctx, enum xombe_stage stage, float f0, const float *v, int n) +{ + dump *t = ctx; + uint8_t head[12], buf[4 * (XOMBE_HALF_MAX + XOMBE_LMAX)]; + int i; + if (t->failed || n < 0 || n > (int)(sizeof(buf) / 4)) + return; + put_u32(head, t->frame); + head[4] = t->half; + head[5] = (uint8_t)stage; + head[6] = (uint8_t)n; + head[7] = (uint8_t)(n >> 8); + put_f32(head + 8, f0); + for (i = 0; i < n; i++) + put_f32(buf + 4 * i, v[i]); + if (!io_write(t->f, head, sizeof(head), t->path) || !io_write(t->f, buf, 4 * (size_t)n, t->path)) + t->failed = 1; +} + +static int run_dec(FILE *in, const char *in_path, dump *t) +{ + static xombe_dec_mem mem; + xombe_dec *d = xombe_dec_init(&mem, XOMBE_DMR); + uint8_t rec[IO_AMB_RECORD], bits[7]; + char head[sizeof(IO_AMB_HEADER) - 1]; + int16_t pcm[XOMBE_HALF_MAX]; + size_t got; + xombe_dec_set_noise(d, XOMBE_NOISE_CONFORMANCE, 0); + if (fread(head, 1, sizeof(head), in) != sizeof(head) || memcmp(head, IO_AMB_HEADER, sizeof(head)) != 0) { + fprintf(stderr, "%s: not an .amb file\n", in_path); + return 0; + } + xombe__dec_set_tap(d, tap, t); + while ((got = fread(rec, 1, sizeof(rec), in)) == sizeof(rec)) { + io_amb_to_bytes(rec, bits); + t->half = 0; + xombe_dec_half_bits(d, bits, 0, 0, 80, pcm); + t->half = 1; + xombe_dec_half_bits(d, bits, 0, 1, 80, pcm); + t->frame++; + } + if (got) { + fprintf(stderr, "%s: truncated frame\n", in_path); + return 0; + } + return 1; +} + +#if XOMBE_HAVE_ENCODER +static int run_enc(FILE *in, dump *t) +{ + static xombe_enc_mem mem; + xombe_enc *e = xombe_enc_init(&mem, NULL); + int16_t pcm[XOMBE_FRAME]; + uint8_t bits[7]; + uint32_t call = 0; + int i; + xombe__enc_set_tap(e, tap, t); + t->half = 0; + for (;; call++) { + t->frame = call - XOMBE_ENC_DELAY; + if (io_read_pcm(in, pcm, XOMBE_FRAME) != XOMBE_FRAME) + break; + xombe_enc_frame_bits(e, pcm, NULL, bits, NULL); + } + for (i = 0; i < XOMBE_ENC_DELAY; i++, call++) { + t->frame = call - XOMBE_ENC_DELAY; + xombe_enc_frame_bits(e, NULL, NULL, bits, NULL); + } + return 1; +} +#endif + +int main(int argc, char **argv) +{ + dump t; + FILE *in; + int ok; + if (argc != 4 || (strcmp(argv[1], "dec") != 0 && strcmp(argv[1], "enc") != 0)) { + fprintf(stderr, "usage: trace_dump dec IN.amb OUT.trace | trace_dump enc IN.raw OUT.trace\n"); + return 2; + } +#if !XOMBE_HAVE_ENCODER + if (strcmp(argv[1], "enc") == 0) { + fprintf(stderr, "trace_dump: built without the encoder\n"); + return 2; + } +#endif + memset(&t, 0, sizeof(t)); + if (!(in = io_open(argv[2], "rb"))) + return 1; + t.path = argv[3]; + if (!(t.f = io_open(argv[3], "wb"))) + return 1; +#if XOMBE_HAVE_ENCODER + ok = strcmp(argv[1], "dec") == 0 ? run_dec(in, argv[2], &t) : run_enc(in, &t); +#else + ok = run_dec(in, argv[2], &t); +#endif + fclose(in); + ok &= io_close(t.f, argv[3]) && !t.failed; + return ok ? 0 : 1; +} diff --git a/xombe/tools/common.py b/xombe/tools/common.py new file mode 100644 index 0000000..47c85d0 --- /dev/null +++ b/xombe/tools/common.py @@ -0,0 +1,136 @@ +"""paths, clip lists, file formats, and helpers shared by the scoring and checking scripts + +import before numpy, it pins BLAS/OpenMP threads (unless the environment sets them) for the scripts' own pools +""" +import os +for _v in ('OMP_NUM_THREADS', 'OPENBLAS_NUM_THREADS', 'MKL_NUM_THREADS'): + os.environ.setdefault(_v, '1') +import hashlib +import math +import shlex +import shutil +import subprocess +import tempfile +import uuid +from concurrent.futures import ThreadPoolExecutor + +HERE = os.path.dirname(os.path.abspath(__file__)) +ROOT = os.path.dirname(HERE) +VEC = os.path.join(ROOT, 'vectors') +E3V = os.path.join(VEC, 'e3') +E5V = os.path.join(VEC, 'e5') +E7V = os.path.join(VEC, 'e7') +BUILD = os.environ.get('XOMBE_BUILD', os.path.join(ROOT, 'build')) +E3IN = os.path.join(BUILD, 'e3in') # dithered E3 inputs, written by scripts/gen_inputs.py +FS = 8000 +MAX_JOBS = 4 +DEFAULT_DEC = shlex.quote(os.path.join(BUILD, 'xombe-dec')) + ' --conformance-noise {inp} {out}' + +# E3 clips and the level dithers of their five inputs in dB, input k is round(10^(g/20)*x) +CLIPS = ['es1', 'es2', 'es3', 'sn10', 'ttsf', 'ttsc', 'ttsl'] +DITHER_DB = [0.0, +0.025, -0.025, +0.05, -0.05] + +# dual-tone IDs -> (high, low) Hz (DTMF, Knox 144..159, call progress 160..163), single tones are IDs 5..122 at +# 31.25 Hz x ID, must match src/common/tone_table.c +DUAL = {128: (1336, 941), 129: (1209, 697), 130: (1336, 697), 131: (1477, 697), 132: (1209, 770), + 133: (1336, 770), 134: (1477, 770), 135: (1209, 852), 136: (1336, 852), 137: (1477, 852), + 138: (1633, 697), 139: (1633, 770), 140: (1633, 852), 141: (1633, 941), 142: (1209, 941), + 143: (1477, 941), 144: (1162, 820), 145: (1052, 606), 146: (1162, 606), 147: (1297, 606), + 148: (1052, 672), 149: (1162, 672), 150: (1297, 672), 151: (1052, 743), 152: (1162, 743), + 153: (1297, 743), 154: (1430, 606), 155: (1430, 672), 156: (1430, 743), 157: (1430, 820), + 158: (1052, 820), 159: (1297, 820), 160: (440, 350), 161: (480, 440), 162: (620, 480), 163: (490, 350)} +TONE_IDS = set(range(5, 123)) | set(DUAL) + + +def read_amb(path): + """frames of an .amb file as lists of 49 bits d0..d48""" + data = open(path, 'rb').read() + if data[:4] != b'.amb': + raise ValueError('%s: missing .amb header' % path) + if (len(data) - 4) % 8: + raise ValueError('%s: length is not 4 + 8*n bytes' % path) + frames = [] + for off in range(4, len(data), 8): + fr = data[off:off + 8] + frames.append([(fr[1 + i // 8] >> (7 - i % 8)) & 1 for i in range(48)] + [fr[7] & 1]) + return frames + + +def val(d, idx): + """bits of d at positions idx, MSB first, as an integer""" + v = 0 + for i in idx: + v = (v << 1) | d[i] + return v + + +def frame_class(d): + c = val(d, range(6)) + return 'voice' if c < 60 else 'erasure' if c < 62 else 'silence' if c == 62 else 'tone' + + +def read_raw(path): + import numpy as np + return np.fromfile(path, '= c).astype(float)) + win = cs - np.concatenate([np.zeros(hang + 1), cs[:-(hang + 1)]]) + n_act = int(np.sum(win > 0)) + A.append(10 * math.log10(sq / n_act) if n_act else -200.0) + C.append(20 * math.log10(c)) + d = np.array(A) - np.array(C) - 15.9 + for j in range(1, 16): + if d[j - 1] >= 0 > d[j]: + t = d[j - 1] / (d[j - 1] - d[j]) + return float(A[j - 1] + t * (A[j] - A[j - 1]) - 20 * math.log10(32768)) + return float(A[0] - 20 * math.log10(32768)) diff --git a/xombe/tools/dstar_conf.py b/xombe/tools/dstar_conf.py new file mode 100644 index 0000000..612345d --- /dev/null +++ b/xombe/tools/dstar_conf.py @@ -0,0 +1,322 @@ +#!/usr/bin/env python3 +"""D-STAR conformance checks (make conformance-dstar) on in-repo data + +usage: dstar_conf.py refs BUILD [--json OUT] stage comparisons against vectors/dstar (ctest dstar_*) + dstar_conf.py speech BUILD OUTDIR [--json] encode/decode and both transcoders on vectors/, scored + dstar_conf.py tones BUILD OUTDIR [--json] D-STAR tone frames on the E6 tone inputs, and transcoded +speech and tones read the dithered E3 inputs from --inputs DIR (scripts/gen_inputs.py, default BUILD/e3in) +""" +import os +import sys +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from common import CLIPS, E5V, FS, MAX_JOBS, read_raw +import argparse +import json +import re +import subprocess +from concurrent.futures import ProcessPoolExecutor + +# speech: per path, the mean over the clips and the worst clip. limits are the measured values (the lower of +# float and q15) less 0.05 on mean PESQ and ViSQOL, 0.10 on the worst clip, 0.01 STOI, and 0.10 dB LSD. the scores +# against the input are low for every path (AMBE+2 itself: PESQ 2.45), */src rows score a transcoded decode +# against the source codec's own decode +SPEECH_LIMITS = { + # path: (mean PESQ, worst PESQ, mean ViSQOL, worst ViSQOL, mean STOI, mean LSD max) + 'ambe2': None, # reference row + 'dstar': (2.39, 1.72, 3.14, 1.18, 0.81, 7.71), + 'dual': (2.38, 1.70, 3.13, 1.14, 0.81, 7.71), + 'a2ds': (2.25, 1.69, 2.80, 1.24, 0.74, 8.29), + 'dsa2': (2.21, 1.64, 2.88, 1.07, 0.77, 8.10), + 'a2ds/src': (4.14, 3.82, 3.87, 3.23, 0.95, 2.74), + 'dsa2/src': (3.99, 3.68, 4.04, 3.86, 0.94, 3.13), +} +# tones: frames from onset to the first tone frame and the level limit as E6. tones without a D-STAR code play as +# voice frames, their level limits are the measured worst case (float and q15) plus about 1 dB +TONE_ONSET, TONE_LEVEL_DB = 2, 1.0 # measured onset+0, 0.6 dB +VOICE_LEVEL_DB = 7.0 # measured 6.2 (knox_158) +XC_KNOX_LEVEL_DB = 10.5 # measured 9.7 (knox_146) +KNOX = range(144, 160) + + +def run(cmd, **kw): + r = subprocess.run(cmd, capture_output=True, text=True, **kw) + if r.returncode: + sys.exit('failed (%d): %s\n%s' % (r.returncode, ' '.join(cmd), r.stderr)) + return r + + +def refs(build): + """runs ctest's dstar_ tests verbosely and collects each comparison's agreement""" + r = subprocess.run(['ctest', '-V', '-R', '^dstar_', '-j', str(os.cpu_count() or 4)], cwd=build, + capture_output=True, text=True) + out = {} + col = re.compile(r'^(\d+): (\S+)\s+\S+\s+(\d+)/(\d+)\s+([\d.]+)%') + pcm = re.compile(r'^(\d+): .* (\d+) samples, max diff (\d+) LSB, rms diff ([\d.]+) LSB, ([\d.]+)% within (\d+) ' + r'LSB, SNR ([-\d.inf]+) dB') + names, res = {}, {} + for line in r.stdout.splitlines(): + m = re.match(r'^\s*\d+/\d+ Test\s+#(\d+): (\S+) \.+\s*(\*{3})?(\w+)', line) + if m: + names[m.group(1)] = m.group(2) + res[m.group(1)] = m.group(4) == 'Passed' + continue + m = col.match(line) + if m: + t = out.setdefault(m.group(1), {'cols': {}}) + t['cols'][m.group(2)] = (int(m.group(3)), int(m.group(4))) + continue + m = pcm.match(line) + if m: + out.setdefault(m.group(1), {})['pcm'] = dict(samples=int(m.group(2)), max=int(m.group(3)), + rms=float(m.group(4)), within=float(m.group(5)), + lsb=int(m.group(6)), snr=m.group(7)) + rows = [] + for k in sorted(names, key=lambda k: names[k]): + n = names[k] + t = out.get(k, {}) + row = dict(test=n, passed=res[k]) + if t.get('cols'): + cols = t['cols'] + worst = min(cols, key=lambda c: cols[c][0] / max(1, cols[c][1])) + row['records'] = max(v[1] for v in cols.values()) + row['worst'] = (worst, 100.0 * cols[worst][0] / max(1, cols[worst][1])) + bc = [c for c in ('out', 'enc', 'd49', 'b') if c in cols] + if bc: + row['bytes'] = (bc[0], 100.0 * cols[bc[0]][0] / max(1, cols[bc[0]][1])) + row['bytes_n'] = cols[bc[0]] + if t.get('pcm'): + row['pcm'] = t['pcm'] + rows.append(row) + print('%-34s %7s %-24s %-18s %s' % ('test', 'records', 'lowest column', 'frames/bytes', '')) + for w in rows: + if 'pcm' in w: + p = w['pcm'] + desc = '%d samples, rms %.2f LSB, %.2f%% within %d LSB, SNR %s dB' % (p['samples'], p['rms'], + p['within'], p['lsb'], p['snr']) + print('%-34s %7s %-43s %s' % (w['test'], '', desc, 'ok' if w['passed'] else 'FAIL')) + elif 'records' in w: + print('%-34s %7d %-10s %8.3f%% %-18s %s' % ( + w['test'], w['records'], w['worst'][0], w['worst'][1], + '%s %.3f%%' % w['bytes'] if 'bytes' in w else '-', 'ok' if w['passed'] else 'FAIL')) + else: + print('%-34s %7s %-43s %s' % (w['test'], '', 'exact file comparison', 'ok' if w['passed'] else 'FAIL')) + npass = sum(w['passed'] for w in rows) + agree = sum(w['bytes_n'][0] for w in rows if 'bytes_n' in w and 'selfcheck' not in w['test']) + total = sum(w['bytes_n'][1] for w in rows if 'bytes_n' in w and 'selfcheck' not in w['test']) + print('frames or records with equal output bytes/fields over the stage tests: %d/%d (%.3f%%)' + % (agree, total, 100.0 * agree / max(1, total))) + print('D-STAR refs: %d/%d tests pass' % (npass, len(rows))) + ok = r.returncode == 0 and npass == len(rows) and rows + return bool(ok), rows + + +def tool(build, name): + return os.path.join(build, name) + + +def make_paths(build, raw, od): + """encodes, transcodes, and decodes one clip on every path, returns {path: (decoded, source-codec decoded)}""" + b = os.path.splitext(os.path.basename(raw))[0] + p = lambda ext: os.path.join(od, b + ext) + E, D, X = tool(build, 'xombe-enc'), tool(build, 'xombe-dec'), tool(build, 'xombe-xc') + run([E, '--air', raw, p('.r33')]) + run([D, '--conformance-noise', '--air', p('.r33'), p('.a2.raw')]) + run([E, '--dstar', raw, p('.dstar')]) + run([D, '--conformance-noise', '--dstar', p('.dstar'), p('.ds.raw')]) + run([E, '--dual', p('.dual.dstar'), raw, p('.dual.amb')]) + run([D, '--conformance-noise', '--dstar', p('.dual.dstar'), p('.dual.raw')]) + run([X, p('.r33'), p('.a2ds.dstar')]) + run([D, '--conformance-noise', '--dstar', p('.a2ds.dstar'), p('.a2ds.raw')]) + run([X, '--reverse', p('.dstar'), p('.dsa2.r33')]) + run([D, '--conformance-noise', '--air', p('.dsa2.r33'), p('.dsa2.raw')]) + return {'ambe2': p('.a2.raw'), 'dstar': p('.ds.raw'), 'dual': p('.dual.raw'), 'a2ds': p('.a2ds.raw'), + 'dsa2': p('.dsa2.raw')}, {'a2ds': p('.a2.raw'), 'dsa2': p('.ds.raw')} + + +def score_one(args): + ref, deg = args + import score as S + r, d, lag = S.align(read_raw(ref), read_raw(deg)) + o = S.score(r, d) + o['lag'] = lag + return o + + +def speech(build, od, clips): + os.makedirs(od, exist_ok=True) + jobs, keys = [], [] + for raw in clips: + dec, src = make_paths(build, raw, od) + for k, f in dec.items(): + jobs.append((raw, f)) + keys.append((os.path.basename(raw), k)) + for k, f in src.items(): + jobs.append((f, dec[k])) + keys.append((os.path.basename(raw), k + '/src')) + with ProcessPoolExecutor(MAX_JOBS) as ex: + res = list(ex.map(score_one, jobs)) + table = {} + for (clip, k), o in zip(keys, res): + table.setdefault(k, {})[clip] = o + ok = True + summary = {} + print('%-10s %6s %6s %7s %7s %6s %6s %s' % ('path', 'PESQ', 'min', 'ViSQOL', 'min', 'STOI', 'LSD', '')) + for k in ['ambe2', 'dstar', 'dual', 'a2ds', 'dsa2', 'a2ds/src', 'dsa2/src']: + rows = list(table[k].values()) + if any(r.get('visqol_speech') is None for r in rows): + print('%-10s ViSQOL failed' % k) + ok = False + continue + mp = sum(r['pesq_nb'] for r in rows) / len(rows) + np_ = min(r['pesq_nb'] for r in rows) + mv = sum(r['visqol_speech'] for r in rows) / len(rows) + nv = min(r['visqol_speech'] for r in rows) + ms = sum(r['stoi'] for r in rows) / len(rows) + ml = sum(r['lsd_db'] for r in rows) / len(rows) + lim = SPEECH_LIMITS.get(k) + good = lim is None or (mp >= lim[0] and np_ >= lim[1] and mv >= lim[2] and nv >= lim[3] and ms >= lim[4] + and ml <= lim[5]) + ok &= good + summary[k] = dict(pesq=mp, pesq_min=np_, visqol=mv, visqol_min=nv, stoi=ms, lsd=ml) + print('%-10s %6.3f %6.3f %7.3f %7.3f %6.3f %6.3f %s' % ( + k, mp, np_, mv, nv, ms, ml, 'informative' if lim is None else 'ok' if good else 'FAIL')) + print('paths: ambe2 AMBE+2 encode/decode, dstar D-STAR only, dual the D-STAR output of the dual encoder,') + print(' a2ds AMBE+2 -> xombe-xc -> D-STAR decode, dsa2 D-STAR -> xombe-xc --reverse -> AMBE+2 decode,') + print(' */src the transcoded decode against the source codec\'s decode') + print('%d clips, scored against the encoder input (*/src: the source decode); limits (mean PESQ, worst PESQ, ' + 'mean ViSQOL, worst ViSQOL, mean STOI, mean LSD):' % len(clips)) + for k, lim in SPEECH_LIMITS.items(): + if lim: + print(' %-8s >= %.2f, >= %.2f, >= %.2f, >= %.2f, >= %.2f, <= %.2f' % ((k,) + lim)) + return ok, dict(summary=summary, clips=table) + + +def tone_ids(build, dstar): + out = run([tool(build, 'dstar_dump_fec'), '--ids', dstar]).stdout.split('\n') + return [int(l.split()[2]) if l.split()[1] == 'tone' else None for l in out if l.strip()] + + +def ds163_case(od): + """D-STAR detects tone 163 as 340 + 550 Hz and plays AMBE+2's 350 + 490 Hz""" + import numpy as np + n = np.arange(int(0.4 * FS)) + A = 32768 * 10 ** (-20 / 20) + rng = np.random.default_rng(20261024) + tone = sum(A * np.cos(2 * np.pi * f / FS * n + rng.uniform(0, 2 * np.pi)) for f in (550.0, 340.0)) + x = np.concatenate([np.zeros(FS // 2), tone, np.zeros(int(0.3 * FS))]) + np.clip(np.round(x), -32768, 32767).astype(' 119: + bad.append('voice b0 = %d > 119' % b0) + if 18 <= b1 <= 31: + bad.append('voice b1 = %d (pulse code)' % b1) + return 'voice', b0, b1, bad + + +def check_fec(path): + def load(p): + m = {} + for line in open(p): + line = line.split('#')[0].split() + if len(line) >= 2: + m[line[0].upper()] = line[1].upper() + return m + ref, cand = load(FEC_REF), load(path) + miss = [k for k in ref if k not in cand] + wrong = [k for k in ref if k in cand and cand[k] != ref[k]] + return len(ref), miss, wrong + + +def main(): + ap = argparse.ArgumentParser(description='E1 bitstream validity') + ap.add_argument('files', nargs='*') + ap.add_argument('--input', help='raw input: also check one frame per 160 samples') + ap.add_argument('--fec', help='candidate FEC pairs in the fec_encode_vectors.txt format') + ap.add_argument('--frames', action='store_true') + ap.add_argument('--quiet', action='store_true') + a = ap.parse_args() + ok = True + for f in a.files: + frames = read_amb(f) + counts, nbad, tones = {}, 0, {} + for n, d in enumerate(frames): + cls, _, x, bad = check_frame(d) + counts[cls] = counts.get(cls, 0) + 1 + if cls == 'tone': + tones[x] = tones.get(x, 0) + 1 + if bad: + nbad += 1 + if not a.quiet and (nbad <= 20 or a.frames): + print(' %s frame %d: %s' % (os.path.basename(f), n, '; '.join(bad))) + line = '%s: %d frames (%s)' % (f, len(frames), ', '.join('%s %d' % kv for kv in sorted(counts.items()))) + if tones: + line += '; tone IDs ' + ', '.join('%d×%d' % kv for kv in sorted(tones.items())) + if a.input: + want = os.path.getsize(a.input) // 320 + if len(frames) != want: + line += '; FRAME COUNT %d != %d' % (len(frames), want) + nbad += 1 + print(line + ('; E1 PASS' if not nbad else '; E1 FAIL (%d frames)' % nbad)) + ok &= not nbad + if a.fec: + n, miss, wrong = check_fec(a.fec) + good = not miss and not wrong + print('FEC: %d reference pairs, %d missing, %d wrong; %s' % (n, len(miss), len(wrong), 'PASS' if good else 'FAIL')) + ok &= good + return 0 if ok else 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/xombe/tools/e3.py b/xombe/tools/e3.py new file mode 100755 index 0000000..b98f254 --- /dev/null +++ b/xombe/tools/e3.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 +import os +import sys +import argparse +import hashlib +import json +import shlex +import subprocess +import warnings +from concurrent.futures import ProcessPoolExecutor + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, HERE) +from common import BUILD, CLIPS, DEFAULT_DEC, DITHER_DB as DB, E3V, MAX_JOBS, decoder_id + +LIM_CLIP, LIM_MEAN, LIM_VQ = -0.30, -0.08, -0.20 + + +def sha(*parts): + h = hashlib.sha256() + for p in parts: + h.update(p if isinstance(p, bytes) else str(p).encode()) + h.update(b'\0') + return h.hexdigest()[:24] + + +def score_pair(orig, deg, visqol): + import score as S + from pesq import pesq + r, d, lag = S.align(S.load(orig), S.load(deg)) + o = {'pesq_nb': float(pesq(S.FS, r / 32768, d / 32768, 'nb')), 'lag': lag} + if visqol: + from scipy.signal import resample_poly + from visqol import VisqolApi + api = VisqolApi() + api.create(mode='speech') + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + o['visqol_speech'] = float(api.measure_from_arrays(resample_poly(r, 2, 1), resample_poly(d, 2, 1), + 16000).moslqo) + return o + + +def job(args): + amb, orig, visqol, dec_cmd, dec_id, cache = args + key = sha(dec_id, open(amb, 'rb').read(), open(orig, 'rb').read(), visqol) + cf = os.path.join(cache, key + '.json') + if os.path.exists(cf): + return json.load(open(cf)) + raw = os.path.join(cache, key + '.raw') + if not os.path.exists(raw): + tmp = raw + '.%d.tmp' % os.getpid() + subprocess.run(dec_cmd.format(inp=shlex.quote(amb), out=shlex.quote(tmp)), shell=True, check=True, + capture_output=True) + os.replace(tmp, raw) + o = score_pair(orig, raw, visqol) + tmp = cf + '.%d.tmp' % os.getpid() + json.dump(o, open(tmp, 'w')) + os.replace(tmp, cf) + return o + + +def main(): + ap = argparse.ArgumentParser(description='E3 five-dither perceptual comparison against the reference encoder') + ap.add_argument('cand_dir') + ap.add_argument('--clips', default=','.join(CLIPS)) + ap.add_argument('--jobs', type=int, default=MAX_JOBS) + ap.add_argument('--json') + ap.add_argument('--cand-pattern', default='{clip}.d{k}.amb') + ap.add_argument('--decoder', default=DEFAULT_DEC) + ap.add_argument('--vectors', default=E3V) + ap.add_argument('--cache', default=os.path.join(BUILD, 'e3cache')) + ap.add_argument('--quiet', action='store_true') + a = ap.parse_args() + a.jobs = max(1, min(a.jobs, MAX_JOBS)) + clips = [c for c in a.clips.split(',') if c] + os.makedirs(a.cache, exist_ok=True) + dec_id = decoder_id(a.decoder) + tasks = [] + for c in clips: + orig = os.path.join(a.vectors, c + '_orig.raw') + for k in range(len(DB)): + ref = os.path.join(a.vectors, '%s.ref.d%d.amb' % (c, k)) + cand = os.path.join(a.cand_dir, a.cand_pattern.format(clip=c, k=k)) + for p in (orig, ref, cand): + if not os.path.exists(p): + sys.exit('missing: ' + p) + for who, amb in (('ref', ref), ('cand', cand)): + tasks.append(((c, k, who), (os.path.abspath(amb), orig, k == 0, a.decoder, dec_id, a.cache))) + res = {} + with ProcessPoolExecutor(a.jobs) as ex: + for (tag, _), o in zip(tasks, ex.map(job, [t[1] for t in tasks])): + res[tag] = o + if not a.quiet: + print(' %-5s d%d %-4s PESQ %.3f%s' % (tag[0], tag[1], tag[2], o['pesq_nb'], + (' ViSQOL %.3f' % o['visqol_speech']) if 'visqol_speech' in o else ''), + file=sys.stderr, flush=True) + out = {'decoder': a.decoder, 'dithers_db': DB, 'clips': {}} + print('E3: PESQ-NB vs undithered original, decoder = %s' % a.decoder) + print('dither k: ' + ' '.join('%+7.3f' % g for g in DB) + ' (dB)') + print('%-5s %-4s ' % ('clip', 'enc') + ' '.join(' d%d ' % k for k in range(len(DB))) + + ' mean ΔPESQ ViSQOL ΔViSQOL') + dps, dvs, fails = [], [], [] + for c in clips: + row = {} + for who in ('ref', 'cand'): + p = [res[(c, k, who)]['pesq_nb'] for k in range(len(DB))] + row[who] = {'pesq': p, 'pesq_mean': sum(p) / len(p), 'visqol': res[(c, 0, who)]['visqol_speech']} + dp = row['cand']['pesq_mean'] - row['ref']['pesq_mean'] + dv = row['cand']['visqol'] - row['ref']['visqol'] + row['d_pesq'], row['d_visqol'] = dp, dv + row['d_pesq_per_dither'] = [x - y for x, y in zip(row['cand']['pesq'], row['ref']['pesq'])] + dps.append(dp) + dvs.append(dv) + ok = dp >= LIM_CLIP + if not ok: + fails.append('%s ΔPESQ %.3f < %.2f' % (c, dp, LIM_CLIP)) + for who in ('ref', 'cand'): + r = row[who] + print('%-5s %-4s ' % (c if who == 'ref' else '', who) + ' '.join('%7.3f' % x for x in r['pesq']) + + ' %7.3f' % r['pesq_mean'] + (' %+.3f%s' % (dp, '' if ok else '!') if who == 'cand' else ' ') + + ' %7.3f' % r['visqol'] + (' %+.3f' % dv if who == 'cand' else '')) + print('%-5s %-4s ' % ('', 'Δ') + ' '.join('%+7.3f' % x for x in row['d_pesq_per_dither'])) + out['clips'][c] = row + mp, mv = sum(dps) / len(dps), sum(dvs) / len(dvs) + if mp < LIM_MEAN: + fails.append('mean ΔPESQ %.3f < %.2f' % (mp, LIM_MEAN)) + if mv < LIM_VQ: + fails.append('mean ΔViSQOL %.3f < %.2f' % (mv, LIM_VQ)) + rm = sum(out['clips'][c]['ref']['pesq_mean'] for c in clips) / len(clips) + cm = sum(out['clips'][c]['cand']['pesq_mean'] for c in clips) / len(clips) + print('mean over %d clips: ref %.3f cand %.3f ΔPESQ %+.3f ΔViSQOL %+.3f' % (len(clips), rm, cm, mp, mv)) + print('thresholds: per clip ΔPESQ >= %.2f, mean ΔPESQ >= %.2f, mean ΔViSQOL >= %.2f' % (LIM_CLIP, LIM_MEAN, LIM_VQ)) + full = set(clips) == set(CLIPS) + print('E3%s: ' % ('' if full else ' (informative, partial clip set)') + + ('PASS' if not fails else 'FAIL (' + '; '.join(fails) + ')')) + out.update(mean_d_pesq=mp, mean_d_visqol=mv, pass_=not fails and full, fails=fails) + if a.json: + json.dump(out, open(a.json, 'w'), indent=1) + return 0 if not fails else 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/xombe/tools/e4.py b/xombe/tools/e4.py new file mode 100755 index 0000000..8dfdf03 --- /dev/null +++ b/xombe/tools/e4.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +import os +import sys +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from common import CLIPS, DEFAULT_DEC, E3V, MAX_JOBS, decode_many, p56, read_raw +import argparse +import json + +LIM_E4 = 1.5 + + +def main(): + ap = argparse.ArgumentParser(description='E4 active speech level (ITU-T P.56 method B), g = 0 inputs') + ap.add_argument('cand_dir') + ap.add_argument('--clips', default=','.join(CLIPS)) + ap.add_argument('--cand-pattern', default='{clip}.d0.amb') + ap.add_argument('--decoder', default=DEFAULT_DEC) + ap.add_argument('--vectors', default=E3V) + ap.add_argument('--cache') + ap.add_argument('--jobs', type=int, default=MAX_JOBS) + ap.add_argument('--json') + a = ap.parse_args() + clips = [c for c in a.clips.split(',') if c] + pairs = [] + for c in clips: + cand = os.path.join(a.cand_dir, a.cand_pattern.format(clip=c, k=0)) + ref = os.path.join(a.vectors, c + '.ref.d0.amb') + for p in (cand, ref, os.path.join(a.vectors, c + '_orig.raw')): + if not os.path.exists(p): + sys.exit('missing: ' + p) + pairs.append((c, cand, ref)) + pcm = decode_many([p for _, c_, r_ in pairs for p in (c_, r_)], a.decoder, a.cache, a.jobs) + print('E4: active speech level, decoder = %s' % a.decoder) + print('%-6s %9s %9s %9s %7s' % ('clip', 'cand', 'ref', 'orig', 'diff')) + out, fails = {}, [] + for c, cand, ref in pairs: + lc, lr = p56(pcm[cand]), p56(pcm[ref]) + lo = p56(read_raw(os.path.join(a.vectors, c + '_orig.raw'))) + ok = abs(lc - lr) <= LIM_E4 + if not ok: + fails.append('%s %+.2f dB' % (c, lc - lr)) + out[c] = dict(cand=lc, ref=lr, orig=lo, diff=lc - lr, ok=ok) + print('%-6s %9.2f %9.2f %9.2f %+7.2f %s' % (c, lc, lr, lo, lc - lr, '' if ok else 'FAIL')) + print('levels in dBov; limit |cand - ref| <= %.1f dB' % LIM_E4) + print('E4: ' + ('PASS' if not fails else 'FAIL (' + '; '.join(fails) + ')')) + if a.json: + json.dump(dict(clips=out, pass_=not fails, fails=fails), open(a.json, 'w'), indent=1) + return 0 if not fails else 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/xombe/tools/e5.py b/xombe/tools/e5.py new file mode 100755 index 0000000..585199c --- /dev/null +++ b/xombe/tools/e5.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +import os +import sys +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from common import (DEFAULT_DEC, E3IN, E3V, E5V, FS, MAX_JOBS, decode_many, frame_class, p56, read_amb, + read_raw) +import argparse +import json +import math +import numpy as np + +CLEAN_CLIPS = ['es1', 'es2', 'es3', 'ttsf', 'ttsc', 'ttsl'] +LIM_CLIP = -0.30 +LIM_CN_LEVEL, LIM_CN_SHAPE, CN_RANGE = 3.0, 4.0, 30.0 +CLIP_MARGIN, CLIP_SKIP = 15.0, 3 + + +def classes(amb): + return [frame_class(d) for d in read_amb(amb)] + + +def cn_stats(pcm, cls, min_run=5, trim=2): + from scipy.signal import welch + first_v = cls.index('voice') if 'voice' in cls else len(cls) + segs, i = [], first_v + while i < len(cls): + if cls[i] != 'silence': + i += 1 + continue + j = i + while j < len(cls) and cls[j] == 'silence': + j += 1 + if j - i >= min_run: + segs.append(pcm[160 * (i + trim):160 * (j - trim)]) + i = j + segs = [s for s in segs if len(s)] + if not segs: + return None + x = np.concatenate(segs) + f, P = welch(x, FS, nperseg=256) + bands = np.array([10 * math.log10(np.sum(P[(f >= 500 * b) & (f < 500 * (b + 1))]) + 1e-12) for b in range(8)]) + return dict(frames=len(x) // 160, level=10 * math.log10(np.mean(x * x) + 1e-12), bands=bands) + + +def pesq_vs(orig, deg): + import score as S + from pesq import pesq + r, d, _ = S.align(orig, deg) + return float(pesq(FS, r / 32768, d / 32768, 'nb')) + + +def clipped_frames(x, cls, tol=1): + al = p56(x) + n = min(len(cls), len(x) // 160) + fr = x[:n * 160].reshape(-1, 160) + loud = 10 * np.log10(np.mean(fr ** 2, 1) + 1e-9) - 20 * math.log10(32768) > al - CLIP_MARGIN + return al, [i for i in range(CLIP_SKIP, n) if cls[i] == 'silence' and loud[max(0, i - tol):i + tol + 1].all()] + + +def main(): + ap = argparse.ArgumentParser(description='E5 noise clips, comfort noise and clipped speech') + ap.add_argument('e3_cand') + ap.add_argument('--e5-cand', help='encodes of vectors/e5/low5.raw and hp5.raw') + ap.add_argument('--cand-pattern', default='{clip}.d0.amb') + ap.add_argument('--e5-pattern', default='{name}.amb') + ap.add_argument('--inputs', default=E3IN, help='dithered E3 inputs from scripts/gen_inputs.py') + ap.add_argument('--ref-mode', action='store_true') + ap.add_argument('--decoder', default=DEFAULT_DEC) + ap.add_argument('--cache') + ap.add_argument('--jobs', type=int, default=MAX_JOBS) + ap.add_argument('--json') + a = ap.parse_args() + if a.ref_mode: + a.e3_cand, a.cand_pattern, a.e5_cand, a.e5_pattern = E3V, '{clip}.ref.d0.amb', E5V, '{name}.ref.amb' + noise = [('sn10', os.path.join(a.e3_cand, a.cand_pattern.format(clip='sn10', k=0)), + os.path.join(E3V, 'sn10.ref.d0.amb'), os.path.join(E3V, 'sn10_orig.raw'))] + if a.e5_cand: + for nm in ('low5', 'hp5'): + noise.append((nm, os.path.join(a.e5_cand, a.e5_pattern.format(name=nm)), + os.path.join(E5V, nm + '.ref.amb'), os.path.join(E5V, nm + '.raw'))) + for _, c, r, o in noise: + for p in (c, r, o): + if not os.path.exists(p): + sys.exit('missing: ' + p) + pcm = decode_many([p for _, c, r, _ in noise for p in (c, r)], a.decoder, a.cache, a.jobs) + clean = read_raw(os.path.join(E5V, 'es1_lead0.5s.raw')) + out, fails = {'noise': {}, 'clipped': {}}, [] + print('E5: decoder = %s, g = 0 input' % a.decoder) + print('%-5s %22s %22s %9s %9s %9s %s' % ('clip', 'PESQ noisy c/r/Δ', 'PESQ clean c/r/Δ', 'CN frames', + 'CN level', 'shape', 'band diffs counted (dB)')) + for nm, c, r, o in noise: + noisy = read_raw(o) + pn = (pesq_vs(noisy, pcm[c]), pesq_vs(noisy, pcm[r])) + pc = (pesq_vs(clean, pcm[c]), pesq_vs(clean, pcm[r])) + res = dict(pesq_noisy=[pn[0], pn[1], pn[0] - pn[1]], pesq_clean=[pc[0], pc[1], pc[0] - pc[1]]) + if pn[0] - pn[1] < LIM_CLIP: + fails.append('%s ΔPESQ vs noisy %.3f' % (nm, pn[0] - pn[1])) + cm, cr = cn_stats(pcm[c], classes(c)), cn_stats(pcm[r], classes(r)) + cn_txt = 'no comfort noise in %s' % ('candidate' if cr else 'reference') if not (cm and cr) else '' + if cm and cr: + keep = cr['bands'] >= cr['bands'].max() - CN_RANGE + dl = cm['level'] - cr['level'] + shape = (cm['bands'] - cr['bands']) - dl + sm = float(np.max(np.abs(shape[keep]))) + res.update(cn_frames=[cm['frames'], cr['frames']], cn_level_diff=dl, band_shape=shape.tolist(), + bands_counted=keep.tolist(), shape_dev_max=sm) + if abs(dl) > LIM_CN_LEVEL: + fails.append('%s comfort-noise level %+.2f dB' % (nm, dl)) + if sm > LIM_CN_SHAPE: + fails.append('%s comfort-noise shape %.2f dB' % (nm, sm)) + cn_txt = '%4d/%-4d %+9.2f %9.2f %s' % (cm['frames'], cr['frames'], dl, sm, + ' '.join(('%+.1f' % v) if k else ' .' for v, k in zip(shape, keep))) + elif cr and not cm: + fails.append('%s: candidate sends no comfort noise' % nm) + out['noise'][nm] = res + print('%-5s %6.3f/%5.3f/%+6.3f %6.3f/%5.3f/%+6.3f %s' % (nm, pn[0], pn[1], pn[0] - pn[1], pc[0], pc[1], + pc[0] - pc[1], cn_txt)) + print(' limits: ΔPESQ vs noisy >= %.2f; CN level within ±%.0f dB; shape within ±%.0f dB over bands within' + ' %.0f dB of the reference\'s strongest' % (LIM_CLIP, LIM_CN_LEVEL, LIM_CN_SHAPE, CN_RANGE)) + print('Clipped speech: silence frames n >= %d with input frames n-1..n+1 within %.0f dB of the active level' + % (CLIP_SKIP, CLIP_MARGIN)) + tot_c = tot_r = 0 + for c in CLEAN_CLIPS: + amb = os.path.join(a.e3_cand, a.cand_pattern.format(clip=c, k=0)) + if not os.path.exists(amb): + sys.exit('missing: ' + amb) + cls, cls_r = classes(amb), classes(os.path.join(E3V, c + '.ref.d0.amb')) + x = read_raw(os.path.join(a.inputs, c + '.d0.raw')) + al, bad = clipped_frames(x, cls) + _, bad_r = clipped_frames(x, cls_r) + tot_c += len(bad) + tot_r += len(bad_r) + out['clipped'][c] = dict(cand=bad, ref=bad_r) + print(' %-5s active %6.1f dBov silence frames %3d clipped: cand %d %s ref %d' % + (c, al, cls.count('silence'), len(bad), bad[:10] if bad else '', len(bad_r))) + print(' total clipped: cand %d, ref %d (limit: cand <= ref)' % (tot_c, tot_r)) + if tot_c > tot_r: + fails.append('clipped speech frames %d > reference %d' % (tot_c, tot_r)) + print('E5: ' + ('PASS' if not fails else 'FAIL (' + '; '.join(fails) + ')') + + ('' if a.e5_cand else ' [low5/hp5 not checked]')) + if a.json: + json.dump(dict(out, pass_=not fails, fails=fails), open(a.json, 'w'), indent=1) + return 0 if not fails else 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/xombe/tools/e6.py b/xombe/tools/e6.py new file mode 100755 index 0000000..072c179 --- /dev/null +++ b/xombe/tools/e6.py @@ -0,0 +1,177 @@ +#!/usr/bin/env python3 +import os +import sys +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from common import (DEFAULT_DEC, DUAL, E7V, FS, MAX_JOBS, decode_many, frame_class, read_amb, + read_raw, val) +import argparse +import glob +import json +import math +import numpy as np + +DTMF_NAMES = '0123456789ABCD*#' +LIM_LEVEL, LIM_ONSET, SEARCH = 1.0, 2, 0.05 +PKG_CASE = dict(name='tones', file=os.path.join(E7V, 'tones.raw'), segments=[ + dict(start=2400, length=4800, id=32, freqs=[1000.0]), + dict(start=9600, length=4800, id=133, freqs=[1336.0, 770.0]), + dict(start=16800, length=4800, id=161, freqs=[480.0, 440.0])]) + + +def gen(outdir): + os.makedirs(outdir, exist_ok=True) + cases = [] + specs = [('dtmf_%s' % ('star' if ch == '*' else 'hash' if ch == '#' else ch), 128 + i, DUAL[128 + i], -16.0) + for i, ch in enumerate(DTMF_NAMES)] + specs += [('knox_%d' % t, t, DUAL[t], -20.0) for t in range(144, 160)] + specs += [('cp_%d' % t, t, DUAL[t], -20.0) for t in (160, 161, 162, 163)] + specs += [('tone_%d_%d' % (f, -lev), int(round(f / 31.25)), (float(f),), float(lev)) + for f in (300, 1000, 2000, 3000) for lev in (-6, -16, -26, -36, -46)] + rng = np.random.default_rng(20261019) + for name, tid, freqs, lev in specs: + n = np.arange(int(0.4 * FS)) + A = 32768 * 10 ** (lev / 20) + tone = sum(A * np.cos(2 * np.pi * f / FS * n + rng.uniform(0, 2 * np.pi)) for f in freqs) + x = np.concatenate([np.zeros(FS // 2), tone, np.zeros(int(0.3 * FS))]) + x = np.clip(np.round(x), -32768, 32767).astype(' 0.25 * env.max())[0] + st = on[0] + 800 + if on[-1] - st <= 960: + return None + return lo + st, min(1600, on[-1] - st - 160) + + +def tone_ids(amb): + return [val(d, range(12, 20)) if frame_class(d) == 'tone' else None for d in read_amb(amb)] + + +def check(cases, cand_dir, pattern, dec, cache, jobs): + ambs = [os.path.join(cand_dir, pattern.format(name=c['name'])) for c in cases] + for p in ambs: + if not os.path.exists(p): + sys.exit('missing: ' + p) + pcm = decode_many(ambs, dec, cache, jobs) + n_ok = n_all = 0 + rows = [] + for c, amb in zip(cases, ambs): + x = read_raw(c['file']) + ids = tone_ids(amb) + y = pcm[amb] + for s in c['segments']: + n_all += 1 + on_f = s['start'] // 160 + end_f = min(len(ids), (s['start'] + s['length']) // 160 + 10) + first = next((i for i in range(on_f, end_f) if ids[i] == s['id']), None) + other = sorted({i for i in ids[on_f:end_f] if i is not None and i != s['id']}) + ok_id = first is not None and first - on_f <= LIM_ONSET and not other + si = steady(x, s['start'] - 160, s['start'] + s['length'] + 160) + so = steady(y, s['start'] - 160, min(len(y), s['start'] + s['length'] + 2400)) + if si and so: + lin, _ = fit_levels(x[si[0]:si[0] + si[1]], s['freqs']) + lout, fo = fit_levels(y[so[0]:so[0] + so[1]], s['freqs']) + err = [o - i for o, i in zip(lout, lin)] + else: + lin, lout, err, fo = [None], [None], [None], [] + ok_lev = None not in err and all(abs(e) <= LIM_LEVEL for e in err) + ok = ok_id and ok_lev + n_ok += ok + rows.append(dict(case=c['name'], id=s['id'], first=None if first is None else first - on_f, + other_ids=other, level_in=lin, level_out=lout, err=err, f_out=fo, ok=ok)) + print('%-14s ID %3d first tone frame %s other IDs %-8s level in %s err %s %s' % ( + c['name'], s['id'], 'none' if first is None else 'onset+%d' % (first - on_f), other or '-', + ' '.join('%6.2f' % v if v is not None else ' n/a' for v in lin), + ' '.join('%+5.2f' % v if v is not None else ' n/a' for v in err), 'ok' if ok else 'FAIL')) + print('E6 tone cases: %d/%d pass (ID within %d frames of onset, no other IDs, level within ±%.1f dB)' + % (n_ok, n_all, LIM_ONSET, LIM_LEVEL)) + return n_ok == n_all, rows + + +def speech(paths, exclude=('tones',)): + files = [] + for p in paths: + files += sorted(glob.glob(os.path.join(p, '*.amb'))) if os.path.isdir(p) else [p] + files = [f for f in files if not any(os.path.basename(f).startswith(x) for x in exclude if x)] + bad = {} + for f in files: + n = sum(1 for i in tone_ids(f) if i is not None) + if n: + bad[f] = n + for f, n in bad.items(): + print(' %s: %d tone frames' % (f, n)) + print('E6 speech check: %d files, %s' % (len(files), 'no tone frames: PASS' if not bad else + '%d with tone frames: FAIL' % len(bad))) + return not bad, bad + + +def main(): + ap = argparse.ArgumentParser(description='E6 tone frames') + sub = ap.add_subparsers(dest='cmd', required=True) + g = sub.add_parser('gen') + g.add_argument('outdir') + c = sub.add_parser('check') + c.add_argument('cases', help="cases.json from 'gen', or 'pkg' for vectors/e7/tones.raw") + c.add_argument('cand_dir', help="candidate directory ('ref' with 'pkg': the reference bitstream)") + c.add_argument('--pattern', default='{name}.amb') + c.add_argument('--decoder', default=DEFAULT_DEC) + c.add_argument('--cache') + c.add_argument('--jobs', type=int, default=MAX_JOBS) + c.add_argument('--json') + s = sub.add_parser('speech') + s.add_argument('paths', nargs='+') + s.add_argument('--exclude', default='tones') + a = ap.parse_args() + if a.cmd == 'gen': + gen(a.outdir) + return 0 + if a.cmd == 'speech': + return 0 if speech(a.paths, a.exclude.split(','))[0] else 1 + if a.cases == 'pkg': + cases = [PKG_CASE] + if a.cand_dir == 'ref': + a.cand_dir, a.pattern = E7V, '{name}.ref.amb' + else: + cases = json.load(open(a.cases)) + base = os.path.dirname(os.path.abspath(a.cases)) + for cs in cases: + cs['file'] = os.path.join(base, cs['file']) + ok, rows = check(cases, a.cand_dir, a.pattern, a.decoder, a.cache, a.jobs) + if a.json: + json.dump(dict(cases=rows, pass_=ok), open(a.json, 'w'), indent=1) + print('E6 (tone cases): ' + ('PASS' if ok else 'FAIL')) + return 0 if ok else 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/xombe/tools/io.c b/xombe/tools/io.c new file mode 100644 index 0000000..e2c28ce --- /dev/null +++ b/xombe/tools/io.c @@ -0,0 +1,392 @@ +#define _POSIX_C_SOURCE 200809L +#include "io.h" +#include +#include +#include +#ifndef _WIN32 +#include +#include +#include +#endif + +#define LINE_MAX_LEN (1 << 14) + +const char *io_prog = "xombe"; + +void io_fail(const char *msg, const char *arg) +{ + fprintf(stderr, "%s: %s%s\n", io_prog, arg ? arg : "", msg); + exit(2); +} + +const char *io_class_name(int cls) +{ + static const char *const names[] = {"voice", "erasure", "silence", "tone"}; + return cls >= 0 && cls < 4 ? names[cls] : "?"; +} + +const char *io_conceal_name(int conceal) +{ + static const char *const names[] = {"none", "repeat", "mute"}; + return conceal >= 0 && conceal < 3 ? names[conceal] : "?"; +} + +void io_print_decision(long n, const xombe_decision *d, const char *out) +{ + fprintf(stderr, "%ld %s %s %d ", n, io_class_name(d->cls), io_conceal_name(d->conceal), d->run); + if (d->conceal != XOMBE_CONCEAL_MUTE) + fputc('-', stderr); + else if (d->mute_src < 0) + fputs("init", stderr); + else + fprintf(stderr, "%lld", (long long)d->mute_src); + fprintf(stderr, " %d %d %d %d", d->e0, d->e1, d->bf, d->hb); + if (out) + fprintf(stderr, " %s", out); + fputc('\n', stderr); +} + +void io_pack_bits(const uint8_t d[49], uint8_t bytes[XOMBE_BITS_BYTES]) +{ + int i; + memset(bytes, 0, XOMBE_BITS_BYTES); + for (i = 0; i < 49; i++) + if (d[i]) + bytes[i >> 3] |= (uint8_t)(0x80 >> (i & 7)); +} + +void io_unpack_bits(const uint8_t bytes[XOMBE_BITS_BYTES], uint8_t d[49]) +{ + int i; + for (i = 0; i < 49; i++) + d[i] = (uint8_t)((bytes[i >> 3] >> (7 - (i & 7))) & 1); +} + +void io_amb_from_bytes(const uint8_t bytes[XOMBE_BITS_BYTES], uint8_t rec[IO_AMB_RECORD]) +{ + rec[0] = 0; + memcpy(rec + 1, bytes, 6); + rec[7] = (uint8_t)(bytes[6] >> 7); +} + +void io_amb_to_bytes(const uint8_t rec[IO_AMB_RECORD], uint8_t bytes[XOMBE_BITS_BYTES]) +{ + memcpy(bytes, rec + 1, 6); + bytes[6] = (uint8_t)((rec[7] & 1) << 7); +} + +FILE *io_open(const char *path, const char *mode) +{ + FILE *f; + if (!strcmp(path, "-")) + return mode[0] == 'r' ? stdin : stdout; + f = fopen(path, mode); + if (!f) + fprintf(stderr, "%s: %s\n", path, strerror(errno)); + return f; +} + +int io_close(FILE *f, const char *path) +{ + int bad = ferror(f); + if (f == stdin || f == stdout) + bad |= fflush(f); + else + bad |= fclose(f); + if (bad) + fprintf(stderr, "%s: I/O error\n", path); + return !bad; +} + +int io_write(FILE *f, const void *p, size_t n, const char *path) +{ + if (fwrite(p, 1, n, f) == n) + return 1; + fprintf(stderr, "%s: write failed: %s\n", path, strerror(errno)); + return 0; +} + +int io_read_record(FILE *f, void *rec, size_t n, const char *path) +{ + size_t got = fread(rec, 1, n, f); + if (got == n) + return 1; + if (got && !ferror(f)) { + fprintf(stderr, "%s: error: partial final frame\n", path); + return -1; + } + return 0; +} + +size_t io_read_pcm(FILE *f, int16_t *pcm, size_t n) +{ + uint8_t b[2 * 256]; + size_t done = 0; + while (done < n) { + size_t want = n - done < 256 ? n - done : 256, got = fread(b, 2, want, f), i; + for (i = 0; i < got; i++) + pcm[done + i] = (int16_t)(uint16_t)(b[2 * i] | (b[2 * i + 1] << 8)); + done += got; + if (got < want) + break; + } + return done; +} + +int io_write_pcm(FILE *f, const int16_t *pcm, size_t n, const char *path) +{ + uint8_t b[2 * 256]; + while (n) { + size_t k = n < 256 ? n : 256, i; + for (i = 0; i < k; i++) { + uint16_t u = (uint16_t)pcm[i]; + b[2 * i] = (uint8_t)(u & 0xFF); + b[2 * i + 1] = (uint8_t)(u >> 8); + } + if (!io_write(f, b, 2 * k, path)) + return 0; + pcm += k; + n -= k; + } + return 1; +} + +int io_parse_float(const char *s, float lo, float hi, float *out) +{ + char *end; + double v; + errno = 0; + v = strtod(s, &end); + if (end == s || *end || errno || !(v >= lo && v <= hi)) + return 0; + *out = (float)v; + return 1; +} + +int io_frames_parse(const char *s, io_frames *out) +{ + const char *p = s; + int n = 1; + for (; *p; p++) + n += *p == ','; + out->n = 0; + out->r = malloc((size_t)n * sizeof(*out->r)); + if (!out->r) + return 0; + for (p = s;;) { + char *end; + long a, b; + errno = 0; + a = strtol(p, &end, 10); + if (end == p || a < 0 || errno) + break; + b = a; + if (*end == '-') { + p = end + 1; + b = strtol(p, &end, 10); + if (end == p || b < a || errno) + break; + } + out->r[out->n][0] = a; + out->r[out->n][1] = b; + out->n++; + if (!*end) + return 1; + if (*end != ',') + break; + p = end + 1; + } + free(out->r); + out->r = NULL; + out->n = 0; + return 0; +} + +int io_frames_has(const io_frames *f, long i) +{ + int k; + for (k = 0; k < f->n; k++) + if (i >= f->r[k][0] && i <= f->r[k][1]) + return 1; + return 0; +} + +#ifndef _WIN32 +static FILE *open_gzip(const char *path, long *pid_out) +{ + int fd[2]; + pid_t pid; + FILE *f; + if (pipe(fd)) + return NULL; + pid = fork(); + if (pid < 0) { + close(fd[0]); + close(fd[1]); + return NULL; + } + if (pid == 0) { + dup2(fd[1], STDOUT_FILENO); + close(fd[0]); + close(fd[1]); + execlp("gzip", "gzip", "-dc", "--", path, (char *)NULL); + _exit(127); + } + close(fd[1]); + f = fdopen(fd[0], "r"); + if (!f) { + close(fd[0]); + waitpid(pid, NULL, 0); + return NULL; + } + *pid_out = (long)pid; + return f; +} +#endif + +int stream_open(stream_reader *r, const char *path) +{ + size_t n = strlen(path); + memset(r, 0, sizeof(*r)); + r->path = path; + r->pid = -1; + r->line = malloc(LINE_MAX_LEN); + if (!r->line) + return 0; + if (n > 3 && !strcmp(path + n - 3, ".gz")) { +#ifdef _WIN32 + fprintf(stderr, "%s: .gz streams are unsupported on Windows\n", path); +#else + r->f = open_gzip(path, &r->pid); + if (!r->f) + fprintf(stderr, "%s: cannot run gzip: %s\n", path, strerror(errno)); +#endif + } else { + r->f = io_open(path, "r"); + } + if (!r->f) { + free(r->line); + r->line = NULL; + return 0; + } + return 1; +} + +int stream_close(stream_reader *r) +{ + int ok = 1; + if (r->f) { + ok = !ferror(r->f); + if (r->f != stdin) + fclose(r->f); + } +#ifndef _WIN32 + if (r->pid >= 0) { + int status = 0; + if (waitpid((pid_t)r->pid, &status, 0) < 0 || !WIFEXITED(status) || WEXITSTATUS(status)) { + fprintf(stderr, "%s: gzip failed\n", r->path); + ok = 0; + } + } +#endif + free(r->line); + r->line = NULL; + r->f = NULL; + return ok; +} + +const char *stream_key(const char *s, const char *key) +{ + char pat[64]; + const char *p; + snprintf(pat, sizeof(pat), "\"%s\":", key); + p = strstr(s, pat); + return p ? p + strlen(pat) : NULL; +} + +int stream_int(const stream_reader *r, const char *s, const char *key, long *out) +{ + const char *p = stream_key(s, key); + char *end; + if (p) { + errno = 0; + *out = strtol(p, &end, 10); + if (end != p && !errno && (*end == ',' || *end == '}' || *end == ' ')) + return 1; + } + fprintf(stderr, "%s:%ld: %s \"%s\"\n", r->path, r->lineno, p ? "malformed" : "missing", key); + return 0; +} + +static int parse_bits(const stream_reader *r, const char *p, stream_half *h) +{ + int i; + p += strspn(p, " "); + if (*p++ != '"') + goto bad; + for (i = 0; i < 49; i++) { + if (p[i] != '0' && p[i] != '1') + goto bad; + h->d[i] = (uint8_t)(p[i] == '1'); + } + if (p[49] != '"') + goto bad; + io_pack_bits(h->d, h->bits); + return 1; +bad: + fprintf(stderr, "%s:%ld: \"bits\" is not a string of 49 binary digits\n", r->path, r->lineno); + return 0; +} + +int stream_next(stream_reader *r, stream_half *h) +{ + const char *p; + long v; + for (;;) { + size_t n; + if (!fgets(r->line, LINE_MAX_LEN, r->f)) + return ferror(r->f) ? STREAM_ERROR : STREAM_END; + r->lineno++; + n = strlen(r->line); + if (n == LINE_MAX_LEN - 1 && r->line[n - 1] != '\n') { + fprintf(stderr, "%s:%ld: line too long\n", r->path, r->lineno); + return STREAM_ERROR; + } + if (r->line[strspn(r->line, " \t\r\n")]) + break; + } + if ((p = stream_key(r->line, "set"))) { + p += strspn(p, " "); + if (!stream_int(r, r->line, "value", &v)) + return STREAM_ERROR; + if (!strncmp(p, "\"eps_T\"", 7)) + r->eps_t = (int)v; + else if (!strncmp(p, "\"eps_1\"", 7)) + r->eps_1 = (int)v; + else if (!strncmp(p, "\"status_flags\"", 14)) + r->status_flags = (unsigned)v; + else { + fprintf(stderr, "%s:%ld: unknown \"set\" key\n", r->path, r->lineno); + return STREAM_ERROR; + } + return STREAM_SET; + } + if (stream_key(r->line, "init")) { + r->eps_t = r->eps_1 = 0; + r->status_flags = 0; + return STREAM_INIT; + } + if ((p = stream_key(r->line, "bits"))) { + long second, ns, flags; + if (!parse_bits(r, p, h) || !stream_int(r, r->line, "second_half", &second) || + !stream_int(r, r->line, "nsamples", &ns) || !stream_int(r, r->line, "flags", &flags)) + return STREAM_ERROR; + h->second_half = second != 0; + h->nsamples = (int)ns; + h->flags = (unsigned)flags | r->status_flags; + h->line = r->line; + return STREAM_HALF; + } + fprintf(stderr, "%s:%ld: unrecognised line\n", r->path, r->lineno); + return STREAM_ERROR; +} diff --git a/xombe/tools/io.h b/xombe/tools/io.h new file mode 100644 index 0000000..271610d --- /dev/null +++ b/xombe/tools/io.h @@ -0,0 +1,93 @@ +#ifndef XOMBE_TOOLS_IO_H +#define XOMBE_TOOLS_IO_H + +/* file formats, checked I/O, and messages shared by the tools and test_stream */ + +#include +#include +#include "xombe.h" + +enum io_format { + IO_AMB, /* ".amb" header, then 8 bytes per frame: a zero byte, d0..d47 MSB-first, d48 in the LSB */ + IO_BITS, /* 49 bytes per frame, one bit per byte */ + IO_AIR /* 9 bytes per frame, the 72-bit frame */ +}; + +#define IO_AMB_HEADER ".amb" +#define IO_AMB_RECORD 8 +#define IO_BITS_RECORD 49 +#define IO_AIR_RECORD XOMBE_FRAME_BYTES + +/* bytes: d0..d48 MSB-first, d48 in the MSB of bytes[6] (the library's voice bits) */ +void io_pack_bits(const uint8_t d[49], uint8_t bytes[XOMBE_BITS_BYTES]); +void io_unpack_bits(const uint8_t bytes[XOMBE_BITS_BYTES], uint8_t d[49]); +void io_amb_from_bytes(const uint8_t bytes[XOMBE_BITS_BYTES], uint8_t rec[IO_AMB_RECORD]); +void io_amb_to_bytes(const uint8_t rec[IO_AMB_RECORD], uint8_t bytes[XOMBE_BITS_BYTES]); + +/* tool name for messages, each tool sets it first */ +extern const char *io_prog; +/* usage error: prints "io_prog: " (arg may be NULL) and exits 2 */ +void io_fail(const char *msg, const char *arg); +/* names of enum xombe_class and enum xombe_conceal values, "?" out of range */ +const char *io_class_name(int cls); +const char *io_conceal_name(int conceal); +/* --decisions line on stderr: "n class conceal run mute e0 e1 bf hb[ out]", mute the mute set's source frame, + init, or - without a mute */ +void io_print_decision(long n, const xombe_decision *d, const char *out); + +/* "-" selects stdin or stdout, both report failures on stderr with the path and return NULL or 0 */ +FILE *io_open(const char *path, const char *mode); +int io_close(FILE *f, const char *path); +int io_write(FILE *f, const void *p, size_t n, const char *path); +/* reads an n-byte record, returns 1, or 0 at the end of the input or on a read error (check ferror), or -1 for a + partial final record, reported as an error */ +int io_read_record(FILE *f, void *rec, size_t n, const char *path); +/* raw audio, signed 16-bit little-endian samples whatever the host byte order + io_read_pcm returns the number of whole samples read */ +size_t io_read_pcm(FILE *f, int16_t *pcm, size_t n); +int io_write_pcm(FILE *f, const int16_t *pcm, size_t n, const char *path); +/* parses a whole string as a number in [lo, hi], returns 0 if it is not one */ +int io_parse_float(const char *s, float lo, float hi, float *out); + +/* frame index set from "a,b-c,...", for --lost, io_frames_parse returns 0 for a malformed list */ +typedef struct { + long (*r)[2]; + int n; +} io_frames; +int io_frames_parse(const char *s, io_frames *out); +int io_frames_has(const io_frames *f, long i); + +/* JSONL decoder streams, one {"init":...}, {"set":KEY,"value":N}, or half-frame object per line */ +enum stream_event { STREAM_END, STREAM_HALF, STREAM_SET, STREAM_INIT, STREAM_ERROR }; + +typedef struct { + FILE *f; + long pid; + const char *path; + long lineno; + char *line; + /* latest "set" values, an "init" line resets them */ + int eps_t, eps_1; + unsigned status_flags; +} stream_reader; + +typedef struct { + uint8_t bits[XOMBE_BITS_BYTES]; + uint8_t d[49]; + unsigned flags; /* the line's flags OR the latest status_flags */ + int second_half; + int nsamples; + const char *line; /* whole line, for further keys, valid until the next stream_next */ +} stream_half; + +/* a path ending in .gz is decompressed with gzip (run directly, without a shell) */ +int stream_open(stream_reader *r, const char *path); +int stream_next(stream_reader *r, stream_half *h); +/* returns 0 when the input was read without error */ +int stream_close(stream_reader *r); +/* text after "key": in s, or NULL */ +const char *stream_key(const char *s, const char *key); +/* reads the integer after "key": in s, reports a missing or malformed value and returns 0 */ +int stream_int(const stream_reader *r, const char *s, const char *key, long *out); + +#endif diff --git a/xombe/tools/score.py b/xombe/tools/score.py new file mode 100755 index 0000000..80191b6 --- /dev/null +++ b/xombe/tools/score.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +import os, sys, json, warnings +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from common import FS, read_raw as load +import numpy as np +from scipy.signal import resample_poly, stft + +def align(r, d, maxlag=800): + n = min(len(r), len(d)) + c = np.correlate(d[:n], r[:n], 'full')[n - 1 - maxlag:n + maxlag] + lag = int(np.argmax(np.abs(c))) - maxlag + if lag > 0: d = d[lag:] + elif lag < 0: d = np.concatenate([np.zeros(-lag), d]) + n = min(len(r), len(d)) + return r[:n], d[:n], lag + +def lsd(r, d): + _, _, R = stft(r, FS, nperseg=256, noverlap=192) + _, _, D = stft(d, FS, nperseg=256, noverlap=192) + pr, pd = np.abs(R) ** 2, np.abs(D) ** 2 + act = 10 * np.log10(pr.sum(0) + 1e-9) > 10 * np.log10(pr.sum(0).max() + 1e-9) - 40 + band = (np.arange(pr.shape[0]) * FS / 256 >= 100) & (np.arange(pr.shape[0]) * FS / 256 <= 3800) + floor = pr.max() * 1e-6 + x = 10 * np.log10(pr[band][:, act] + floor) - 10 * np.log10(pd[band][:, act] + floor) + return float(np.mean(np.sqrt(np.mean(x ** 2, 0)))) + +def segsnr(r, d, n=160): + k = len(r) // n + s = [] + for i in range(k): + a, b = r[i * n:(i + 1) * n], d[i * n:(i + 1) * n] + e = np.sum(a ** 2) + if e < 1e-3 * n * 32768 ** 2 * 1e-6: continue + s.append(np.clip(10 * np.log10(e / (np.sum((a - b) ** 2) + 1e-9)), -10, 35)) + return float(np.mean(s)) if s else float('nan') + +def score(r, d): + out = {} + from pesq import pesq + out['pesq_nb'] = float(pesq(FS, r / 32768, d / 32768, 'nb')) + from pystoi import stoi + out['stoi'] = float(stoi(r, d, FS, extended=False)) + try: + from visqol import VisqolApi + api = VisqolApi(); api.create(mode='speech') + r16, d16 = resample_poly(r, 2, 1), resample_poly(d, 2, 1) + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + out['visqol_speech'] = float(api.measure_from_arrays(r16, d16, 16000).moslqo) + except Exception as e: + out['visqol_speech'] = None + out['visqol_error'] = str(e) + out['lsd_db'] = lsd(r, d) + out['segsnr_db'] = segsnr(r, d) + return out + +if __name__ == '__main__': + a = [x for x in sys.argv[1:] if not x.startswith('--')] + r, d = load(a[0]), load(a[1]) + lag = 0 + if '--no-align' not in sys.argv: r, d, lag = align(r, d) + o = score(r, d); o['lag'] = lag; o['seconds'] = len(r) / FS + print(json.dumps(o) if '--json' in sys.argv else '\n'.join(f'{k:14s} {v}' for k, v in o.items())) + if 'visqol_error' in o: + print('ViSQOL failed: ' + o['visqol_error'], file=sys.stderr) + sys.exit(1) diff --git a/xombe/tools/xombe-dec.c b/xombe/tools/xombe-dec.c new file mode 100644 index 0000000..f5285b9 --- /dev/null +++ b/xombe/tools/xombe-dec.c @@ -0,0 +1,208 @@ +#include +#include +#include +#include "io.h" +#include "xombe.h" + +#if XOMBE_HAVE_DSTAR +#define NO_DSTAR "" +#else +#define NO_DSTAR " (not in this build)" +#endif + +static void usage(FILE *f, int status) +{ + fprintf(f, + "usage: xombe-dec [options] IN OUT.raw\n" + " OUT.raw: 8 kHz s16le mono, 160 samples per frame. '-' is stdin or stdout\n" + "input formats (modes):\n" + " (default) AMBE+2 .amb file\n" + " --bits AMBE+2, 49 bytes per frame, one bit per byte\n" + " --air AMBE+2 72-bit air frames, 9 bytes, FEC applied\n" + " --dstar D-STAR (AMBE 2400) frames, 9 bytes as received, FEC applied" NO_DSTAR "\n" + " --stream AMBE+2 JSONL stream IN.jsonl[.gz], one half call per line\n" + "options:\n" + " --lost LIST frames lost, e.g. 3,10-12 (XOMBE_FLAG_LOST)\n" + " --conformance-noise\n" + " noise source that reproduces the test vectors (default: production source)\n" + " --decisions per-frame decisions to stderr: 'n class conceal run mute e0 e1 bf hb', mute: the\n" + " muted set's source frame, init, or -. e0 e1: Golay corrections, -1 if lost or\n" + " post-FEC (.amb, --bits)\n" + " --help this text\n" + " a truncated final frame is an error\n"); + exit(status); +} + +static void print_decision(const xombe_dec *d, long frame) +{ + xombe_decision r; + xombe_dec_decision_get(d, &r); + io_print_decision(frame, &r, NULL); +} + +static int read_frame(FILE *in, const char *path, enum io_format fmt, uint8_t bits[XOMBE_BITS_BYTES], uint8_t air[IO_AIR_RECORD]) +{ + uint8_t buf[IO_BITS_RECORD]; + size_t want = fmt == IO_AMB ? IO_AMB_RECORD : fmt == IO_BITS ? IO_BITS_RECORD : IO_AIR_RECORD; + int i, got = io_read_record(in, fmt == IO_AIR ? air : buf, want, path); + if (got != 1) + return got; + if (fmt == IO_AMB) { + io_amb_to_bytes(buf, bits); + } else if (fmt == IO_BITS) { + for (i = 0; i < IO_BITS_RECORD; i++) + buf[i] &= 1; + io_pack_bits(buf, bits); + } + return 1; +} + +static int run_stream(const char *path, const char *out_path, int conformance, int show) +{ + stream_reader r; + stream_half h; + FILE *out; + long frame = -1; + xombe_dec_mem mem; + xombe_dec *dec; + int ev, ok = 1; + if (!stream_open(&r, path)) + return 1; + out = io_open(out_path, "wb"); + if (!out) { + stream_close(&r); + return 1; + } + dec = xombe_dec_init(&mem, XOMBE_DMR); + if (conformance) + xombe_dec_set_noise(dec, XOMBE_NOISE_CONFORMANCE, 0); + while (ok && (ev = stream_next(&r, &h)) != STREAM_END) { + if (ev == STREAM_ERROR) { + ok = 0; + } else if (ev == STREAM_SET) { + xombe_dec_set_errors(dec, r.eps_t, r.eps_1); + } else if (ev == STREAM_INIT) { + dec = xombe_dec_init(&mem, XOMBE_DMR); + if (conformance) + xombe_dec_set_noise(dec, XOMBE_NOISE_CONFORMANCE, 0); + frame = -1; + } else { + int16_t pcm[XOMBE_HALF_MAX]; + int ns = xombe_dec_half_bits(dec, h.bits, h.flags, h.second_half, h.nsamples, pcm); + if (ns < 0) { + fprintf(stderr, "%s:%ld: half-frame call out of order\n", path, r.lineno); + ok = 0; + break; + } + ok = io_write_pcm(out, pcm, (size_t)ns, out_path); + if (!h.second_half) { + frame++; + if (show) + print_decision(dec, frame); + } + } + } + ok &= stream_close(&r); + ok &= io_close(out, out_path); + return ok ? 0 : 1; +} + +int main(int argc, char **argv) +{ + enum io_format fmt = IO_AMB; + int conformance = 0, show = 0, stream = 0, dstar = 0, np = 0, nfmt = 0, i, ok = 1, got; + io_frames lost = {NULL, 0}; + const char *paths[2]; + FILE *in, *out; + xombe_dec_mem mem; + xombe_dec *dec; + long frame = 0; + io_prog = "xombe-dec"; + for (i = 1; i < argc; i++) { + const char *a = argv[i]; + if (!strcmp(a, "--help")) + usage(stdout, 0); + else if (!strcmp(a, "--bits")) { + fmt = IO_BITS; + nfmt++; + } else if (!strcmp(a, "--air")) { + fmt = IO_AIR; + nfmt++; + } else if (!strcmp(a, "--dstar")) { + if (!XOMBE_HAVE_DSTAR) + io_fail(": not in this build (XOMBE_DSTAR=OFF)", a); + dstar = 1; + fmt = IO_AIR; + nfmt++; + } else if (!strcmp(a, "--stream")) { + stream = 1; + nfmt++; + } else if (!strcmp(a, "--lost") && i + 1 < argc) { + if (!io_frames_parse(argv[++i], &lost)) + io_fail(": not a frame list (e.g. 3,10-12)", argv[i]); + } else if (!strcmp(a, "--conformance-noise")) + conformance = 1; + else if (!strcmp(a, "--decisions")) + show = 1; + else if (a[0] == '-' && a[1]) + usage(stderr, 2); + else if (np < 2) + paths[np++] = a; + else + usage(stderr, 2); + } + if (np != 2) + usage(stderr, 2); + if (nfmt > 1) + io_fail("--bits, --air, --dstar and --stream are exclusive", NULL); + if (stream) { + if (lost.n) + io_fail("--lost does not apply to --stream", NULL); + return run_stream(paths[0], paths[1], conformance, show); + } + in = io_open(paths[0], "rb"); + if (!in) + return 1; + if (fmt == IO_AMB) { + char hdr[4]; + if (fread(hdr, 1, 4, in) != 4 || memcmp(hdr, IO_AMB_HEADER, 4)) { + fprintf(stderr, "%s: not an .amb file\n", paths[0]); + return 1; + } + } + out = io_open(paths[1], "wb"); + if (!out) + return 1; + dec = xombe_dec_init(&mem, dstar ? XOMBE_DSTAR : XOMBE_DMR); + if (conformance) + xombe_dec_set_noise(dec, XOMBE_NOISE_CONFORMANCE, 0); + for (;;) { + uint8_t bits[XOMBE_BITS_BYTES], air[IO_AIR_RECORD]; + int16_t pcm[160]; + unsigned flags = io_frames_has(&lost, frame) ? XOMBE_FLAG_LOST : 0; + if ((got = read_frame(in, paths[0], fmt, bits, air)) != 1) { + ok = got == 0; + break; + } + if (fmt == IO_AIR) + xombe_dec_frame(dec, air, flags, pcm); + else + xombe_dec_frame_bits(dec, bits, flags, pcm); + if (show) + print_decision(dec, frame); + if (!io_write_pcm(out, pcm, 160, paths[1])) { + ok = 0; + break; + } + frame++; + } + if (ferror(in)) { + fprintf(stderr, "%s: read error\n", paths[0]); + ok = 0; + } + if (in != stdin) + fclose(in); + ok &= io_close(out, paths[1]); + free(lost.r); + return ok ? 0 : 1; +} diff --git a/xombe/tools/xombe-enc.c b/xombe/tools/xombe-enc.c new file mode 100644 index 0000000..89be9e9 --- /dev/null +++ b/xombe/tools/xombe-enc.c @@ -0,0 +1,210 @@ +#include +#include +#include +#include "io.h" +#include "xombe.h" + +#if XOMBE_HAVE_DSTAR +#define NO_DSTAR "" +#else +#define NO_DSTAR " (not in this build)" +#endif + +static void usage(FILE *f, int status) +{ + fprintf(f, + "usage: xombe-enc [options] IN.raw OUT\n" + " IN.raw: 8 kHz s16le mono, a partial final frame is dropped. '-' is stdin or stdout\n" + "modes:\n" + " (default) AMBE+2: OUT is .amb, or .bits with --bits, or air frames with --air\n" + " --dstar D-STAR only: OUT is 9-byte D-STAR frames (.dstar)" NO_DSTAR "\n" + " --dual DSTAR_OUT both: AMBE+2 to OUT, D-STAR frames to DSTAR_OUT" NO_DSTAR "\n" + "AMBE+2 output format:\n" + " --bits 49 bytes per frame, one bit per byte\n" + " --air 72-bit air frames, 9 bytes, FEC applied\n" + "options:\n" + " --ns on|off noise suppression (default on)\n" + " --ns-strength S suppression strength, 0..1 (default 0.5)\n" + " --dtx on|off AMBE+2 silence frames for background (default on)\n" + " --tones on|off tone detection (default on)\n" + " --vscale S voicing decision scale, 0.001..1000000 (default 0.35)\n" + " --dstar-dtx on|off D-STAR null frames for background (default off)" NO_DSTAR "\n" + " --quant closed|open AMBE+2 amplitude quantizer, open is faster (default closed)\n" + " --help this text\n" + " --ns-strength and --vscale round S to thousandths. delay: 3 frames, 4 with D-STAR, flushed at the end\n"); + exit(status); +} + +static int on_off(const char *s) +{ + if (!strcmp(s, "on")) + return 1; + if (!strcmp(s, "off")) + return 0; + io_fail(": expected on or off", s); + return 0; +} + +static int quantizer(const char *s) +{ + if (!strcmp(s, "closed")) + return XOMBE_ENC_QUANT_CLOSED; + if (!strcmp(s, "open")) + return XOMBE_ENC_QUANT_OPEN; + io_fail(": expected closed or open", s); + return 0; +} + +static float number(const char *s, float lo, float hi) +{ + float v; + if (!io_parse_float(s, lo, hi, &v)) { + fprintf(stderr, "%s: '%s' is not a number in %.7g..%.7g\n", io_prog, s, lo, hi); + exit(2); + } + return v; +} + +/* the library takes the scales in thousandths */ +static int permille(const char *s, float lo, float hi) +{ + return (int)(number(s, lo, hi) * 1000.0f + 0.5f); +} + +static int write_frame(FILE *out, enum io_format fmt, const uint8_t bits[XOMBE_BITS_BYTES], const char *path) +{ + uint8_t buf[IO_BITS_RECORD]; + if (fmt == IO_AMB) { + io_amb_from_bytes(bits, buf); + return io_write(out, buf, IO_AMB_RECORD, path); + } + if (fmt == IO_AIR) { + xombe_fec_encode(XOMBE_DMR, bits, buf); + return io_write(out, buf, IO_AIR_RECORD, path); + } + io_unpack_bits(bits, buf); + return io_write(out, buf, IO_BITS_RECORD, path); +} + +static int write_dstar(FILE *out, const uint8_t bits[XOMBE_BITS_BYTES], const char *path) +{ + uint8_t fr[XOMBE_FRAME_BYTES]; + xombe_fec_encode(XOMBE_DSTAR, bits, fr); + return io_write(out, fr, sizeof(fr), path); +} + +enum mode { MODE_AMBE2, MODE_DSTAR, MODE_DUAL }; + +/* one frame through the encoder, pcm NULL flushes, returns 1 if it wrote a frame. the DMR output goes to out in + fmt, the D-STAR output to out (--dstar) or dout (--dual) */ +static int encode_frame(xombe_enc *enc, enum mode mode, const int16_t *pcm, FILE *out, enum io_format fmt, + const char *path, FILE *dout, const char *dpath, int *ok) +{ + uint8_t dmr[XOMBE_BITS_BYTES], dstar[XOMBE_BITS_BYTES]; + if (xombe_enc_frame_bits(enc, pcm, NULL, mode != MODE_DSTAR ? dmr : NULL, mode != MODE_AMBE2 ? dstar : NULL) != 1) + return 0; + if (mode == MODE_DSTAR) + *ok = write_dstar(out, dstar, path); + else + *ok = write_frame(out, fmt, dmr, path) && (mode != MODE_DUAL || write_dstar(dout, dstar, dpath)); + return 1; +} + +int main(int argc, char **argv) +{ + xombe_enc_cfg cfg; + static xombe_enc_mem mem; + xombe_enc *enc; + const char *paths[2], *dpath = NULL; + enum io_format fmt = IO_AMB; + enum mode mode = MODE_AMBE2; + int np = 0, i, ok = 1, have_fmt = 0; + long frames = 0, written = 0; + FILE *in, *out, *dout = NULL; + io_prog = "xombe-enc"; + xombe_enc_cfg_default(&cfg); + for (i = 1; i < argc; i++) { + const char *a = argv[i]; + int more = i + 1 < argc; + if (!strcmp(a, "--help")) + usage(stdout, 0); + else if (!strcmp(a, "--air")) { + fmt = IO_AIR; + have_fmt = 1; + } else if (!strcmp(a, "--bits")) { + fmt = IO_BITS; + have_fmt = 1; + } else if (!strcmp(a, "--ns") && more) + cfg.ns = on_off(argv[++i]); + else if (!strcmp(a, "--ns-strength") && more) + cfg.ns_strength_permille = permille(argv[++i], 0.0f, 1.0f); + else if (!strcmp(a, "--dtx") && more) + cfg.dmr_dtx = on_off(argv[++i]); + else if (!strcmp(a, "--tones") && more) + cfg.tones = on_off(argv[++i]); + else if (!strcmp(a, "--quant") && more) + cfg.dmr_quant = quantizer(argv[++i]); + else if (!strcmp(a, "--vscale") && more) + cfg.voicing_scale_permille = permille(argv[++i], 0.001f, 1e6f); + else if (!strcmp(a, "--dstar") || (!strcmp(a, "--dual") && more) || (!strcmp(a, "--dstar-dtx") && more)) { + if (!XOMBE_HAVE_DSTAR) + io_fail(": not in this build (XOMBE_DSTAR=OFF)", a); + if (!strcmp(a, "--dstar")) + mode = MODE_DSTAR; + else if (!strcmp(a, "--dual")) { + mode = MODE_DUAL; + dpath = argv[++i]; + } else + cfg.dstar_dtx = on_off(argv[++i]); + } else if (a[0] == '-' && a[1]) + usage(stderr, 2); + else if (np < 2) + paths[np++] = a; + else + usage(stderr, 2); + } + if (np != 2) + usage(stderr, 2); + if (mode == MODE_DSTAR && have_fmt) + io_fail("--bits and --air select the AMBE+2 output's format, --dstar has none", NULL); + cfg.outputs = mode == MODE_AMBE2 ? XOMBE_ENC_DMR + : mode == MODE_DSTAR ? XOMBE_ENC_DSTAR + : XOMBE_ENC_DMR | XOMBE_ENC_DSTAR; + enc = xombe_enc_init(&mem, &cfg); + if (!enc) + io_fail("invalid encoder settings", NULL); + in = io_open(paths[0], "rb"); + if (!in) + return 1; + out = io_open(paths[1], "wb"); + if (!out) + return 1; + if (dpath && !(dout = io_open(dpath, "wb"))) + return 1; + if (fmt == IO_AMB && mode != MODE_DSTAR) + ok = io_write(out, IO_AMB_HEADER, 4, paths[1]); + while (ok) { + int16_t pcm[160]; + size_t got = io_read_pcm(in, pcm, 160); + if (got != 160) { + /* as the reference encoder's frame count */ + if (got) + fprintf(stderr, "%s: partial final frame of %zu samples dropped\n", paths[0], got); + break; + } + frames++; + written += encode_frame(enc, mode, pcm, out, fmt, paths[1], dout, dpath, &ok); + } + if (ferror(in)) { + fprintf(stderr, "%s: read error\n", paths[0]); + ok = 0; + } + while (ok && written < frames) + written += encode_frame(enc, mode, NULL, out, fmt, paths[1], dout, dpath, &ok); + if (in != stdin) + fclose(in); + ok &= io_close(out, paths[1]); + if (dout) + ok &= io_close(dout, dpath); + return ok ? 0 : 1; +} diff --git a/xombe/tools/xombe-xc.c b/xombe/tools/xombe-xc.c new file mode 100644 index 0000000..bc00ec9 --- /dev/null +++ b/xombe/tools/xombe-xc.c @@ -0,0 +1,131 @@ +#include +#include +#include +#include "io.h" +#include "xombe.h" + +/* DMR rate-33 frames -> D-STAR frames, or back with --reverse (xombe_xc_frame) + --amb: the DMR side is .amb, through the FEC (exact on clean frames) */ + +#if XOMBE_HAVE_ENCODER +#define NO_REVERSE "" +#else +#define NO_REVERSE " (not in this build)" +#endif + +static void usage(FILE *f, int status) +{ + fprintf(f, + "usage: xombe-xc [options] IN.r33 OUT.dstar\n" + " xombe-xc --reverse [options] IN.dstar OUT.r33\n" + "modes:\n" + " (default) DMR rate 33 -> D-STAR\n" + " --reverse D-STAR -> DMR rate 33" NO_REVERSE "\n" + " r33: DMR rate-33 frames, 9 bytes (xombe-enc --air, xombe-dec --air)\n" + " dstar: D-STAR frames, 9 bytes (xombe-enc --dstar, xombe-dec --dstar). '-' is stdin or stdout\n" + "DMR format:\n" + " --amb .amb in place of r33, either direction (xombe-enc, xombe-dec)\n" + "options:\n" + " --lost LIST frames lost, e.g. 3,10-12 (XOMBE_FLAG_LOST)\n" + " --decisions per-frame decisions to stderr: 'n class conceal run mute e0 e1 bf hb out', as\n" + " xombe-dec's of the input, then the output kind\n" + " --help this text\n" + " no delay: one output frame per input frame. a truncated final frame is an error\n"); + exit(status); +} + +int main(int argc, char **argv) +{ + static const char *const outk[] = {"voice", "pulse", "tone", "knox", "silence", "resend"}; + static xombe_xc_mem mem; + const char *paths[2]; + xombe_xc *x = NULL; + io_frames lost = {NULL, 0}; + FILE *in, *out; + long n = 0; + xombe_fec fec; + int i, np = 0, show = 0, rev = 0, amb = 0, ok = 1, got; + io_prog = "xombe-xc"; + for (i = 1; i < argc; i++) { + const char *a = argv[i]; + if (!strcmp(a, "--help")) + usage(stdout, 0); + else if (!strcmp(a, "--decisions")) + show = 1; + else if (!strcmp(a, "--amb")) + amb = 1; + else if (!strcmp(a, "--reverse")) { + if (!XOMBE_HAVE_ENCODER) + io_fail(": not in this build (XOMBE_ENCODER=OFF)", a); + rev = 1; + } else if (!strcmp(a, "--lost") && i + 1 < argc) { + if (!io_frames_parse(argv[++i], &lost)) + io_fail(": not a frame list (e.g. 3,10-12)", argv[i]); + } else if (np < 2 && (a[0] != '-' || !a[1])) + paths[np++] = a; + else + usage(stderr, 2); + } + if (np != 2) + usage(stderr, 2); + if (!(in = io_open(paths[0], "rb"))) + return 1; + if (amb && !rev) { + char hdr[4]; + if (fread(hdr, 1, 4, in) != 4 || memcmp(hdr, IO_AMB_HEADER, 4)) { + fprintf(stderr, "%s: not an .amb file\n", paths[0]); + if (in != stdin) + fclose(in); + return 1; + } + } + if (!(out = io_open(paths[1], "wb"))) { + if (in != stdin) + fclose(in); + return 1; + } + if (amb && rev && !io_write(out, IO_AMB_HEADER, 4, paths[1])) + ok = 0; + xombe_fec_init(&fec, XOMBE_DMR); + x = xombe_xc_init(&mem, rev ? XOMBE_DSTAR : XOMBE_DMR); + while (ok) { + uint8_t fr[XOMBE_FRAME_BYTES], ds[XOMBE_FRAME_BYTES], bits[XOMBE_BITS_BYTES], rec[IO_AMB_RECORD]; + unsigned flags = io_frames_has(&lost, n) ? XOMBE_FLAG_LOST : 0; + if (amb && !rev) { + if ((got = io_read_record(in, rec, IO_AMB_RECORD, paths[0])) == 1) { + io_amb_to_bytes(rec, bits); + xombe_fec_encode(XOMBE_DMR, bits, fr); + } + } else + got = io_read_record(in, fr, XOMBE_FRAME_BYTES, paths[0]); + if (got != 1) { + ok = got == 0; + break; + } + xombe_xc_frame(x, fr, flags, ds); + if (show) { + xombe_xc_decision d; + xombe_xc_decision_get(x, &d); + io_print_decision(n, &d.in, outk[d.out]); + } + if (amb && rev) { + xombe_fec_stats st; + xombe_fec_decode(&fec, ds, bits, &st); + io_amb_from_bytes(bits, rec); + ok = io_write(out, rec, IO_AMB_RECORD, paths[1]); + } else + ok = io_write(out, ds, XOMBE_FRAME_BYTES, paths[1]); + if (!ok) + break; + n++; + } + if (ferror(in)) { + fprintf(stderr, "%s: read error\n", paths[0]); + ok = 0; + } + if (in != stdin) + fclose(in); + ok &= io_close(out, paths[1]); + free(lost.r); + return ok ? 0 : 1; +} diff --git a/xombe/vectors/dstar/MANIFEST b/xombe/vectors/dstar/MANIFEST new file mode 100644 index 0000000..8715897 --- /dev/null +++ b/xombe/vectors/dstar/MANIFEST @@ -0,0 +1,69 @@ +# xombe-dstar-ref 1; sha256 bytes name +0d2b07774d4055258eae0d2a32550b4c7e36236fbdfccd82c7c9693d48d1e36d 10113 fec_enc.txt.gz +d8221e02b7359f4fb0aa449031b5d22e682dc4dce73de21e0ad8e4df0c9617ca 14400 kx.dec.raw +40e767b12e089de7d8f3c1be840e09f0e9f85c61e93fcde454bd4fc4ada570ec 8588 kx.dec.txt.gz +fe53d22916d388c08fe1d0dacc31dec7f16fc29ef985f0d4538a986da4eaf0f0 20174 kx.deq.txt.gz +51d025c1f0a7a413eb3bd0e14320da674f3450396448903ac18670df285aef52 405 kx.dstar +48494eae417719faa2555b3a020abb1ca63ec5f450df643c36c415fd165b8674 8511 kx.enc.txt.gz +e1de5050d2aa9bdabe4cf5d38b0b825b8bed4c710e3e2d87a8cdb9d3bebef731 2513 kx.fec.txt.gz +cdcc3b37cd5bd1be895c467545db2cea163eae250d8dddaa6e4d1cf872e70da5 28492 kx.half.txt.gz +729f4d9843c6cfff0501120141b705a5f8140595f3069b4d711861a345e26ccd 14400 kx.in.raw +ae18099deecc82b8fdcb37875078f5c1d2de6318ed1a6871f0fe50f9870f4f92 405 kx.r33 +768921362362917d149be857abe44c49966d6f9c77208321d97d83d220c3724f 405 kx.xc.dstar +3f3cd52b8b83ae07062b3ab14caecc66ae0a8635748641bd107240ac088f5ace 6492 kx.xc.txt.gz +c046aaea60a24e3c43159c5d7201fca073e36c65ee10262c08d480242f38aefe 405 kx.xrev.r33 +375724ab377c8cca8da5cccdfd871ee669feb173241d8fead5f18981d28539db 19208 kx.xrev.txt.gz +66f9dff886a4c89df6c7cdaf00b25a37bc69d71bdb71391955020d9c298efaf4 16000 nz.dec.raw +14a4099c7f78bf22dc254b5471a2d16c35691b689749893ba674b19e9568da37 9151 nz.dec.txt.gz +44d108a5f47889164b59013b9b7f63f9458c882a5eae3633d3a4ad63bac19872 23345 nz.deq.txt.gz +58bd1a7f42599ba043477111f9b832d7b75148cc883c68b4fe7d0a154821a34f 450 nz.dstar +b69845feac9a81f0b12b1a8caf03f39ea2c723a129e1677ae0234d409dfca700 24829 nz.enc.txt.gz +27f83eea17dc1f071cb3abf19e5428ba8f176bc9bf055484e0cd2b32411316a6 3475 nz.fec.txt.gz +25dd62e7f760a147f18c1ce56945180a63f4915c9397af6f86accf55863367a4 29452 nz.half.txt.gz +52583dbeb3b4c8514d2b6a7303664db51e548075052e43a740453101a4327a1e 16000 nz.in.raw +93948909e5647630a0557f4cf3e689c9a161a1b54cfc6ee853ab0c604e4c191e 25053 quant_ambe2.txt.gz +941a6156cec8e3528cc87f3647055c6afa3031b38a188eacb71a7570c4abbcf8 47526 quant_closed.txt.gz +c1d3ce93d634eb00d15483f3a8d4128f4c15fdb998e23c61f09d1ccdc33432d5 20163 quant_dstar.txt.gz +0cbf88e5fa460d972025858dfcadd8da3fe543dbec24166ebaebb848f8fe5c23 19200 sp.dec.raw +9791eb82f8058f368b45143fdace9ea43dca65558e958248755c57ab64e45bfe 10158 sp.dec.txt.gz +64ed7f172b9e72f100b03f8b4629d33b3bcdbb29a330820e2ab958b87fe96e94 24573 sp.deq.txt.gz +c91c61f4d71d4f59a035992dfbaaeca95d40600b8dd8e689bce3a5266ee4dc80 540 sp.dstar +bf4623d06938f77469260898fe19840086339a051cc8a84ac1d2b0afafb6f4dc 28055 sp.enc.txt.gz +d59b215400756bcb16937372436f247a78a9e31cb1af2c8da59737e31159a9cc 4140 sp.fec.txt.gz +02fe2026f889a1d60cd481ae974009e1618974f4959b2b92396957307c7f617f 32779 sp.half.txt.gz +363ba5e1ca70d5661202816ba845111f3fd33facf6c1736236dd4b08ecb29a24 19200 sp.in.raw +b35fa20ea656d855cbfae405389201ad23f3687525b1562b95f0ef1db645dfb5 540 sp.r33 +bec829a7e545d01f82d3eef094c52eb0704be439a3d93b79369c0f0dc2ebd0e7 540 sp.xc.dstar +15116f696360fc6214ce48ab59aeff2b0cdb8e90e14fe8f583180f94f69af7ce 21249 sp.xc.txt.gz +553c8acf0f103a1ae88b6b8444540333470b32a0f849a3cd8e7968e5354d42d3 540 sp.xrev.r33 +1fbf8a7b2740edf44a276dc44958d95b9036c751ef93021b91d58ccb46d2d0fd 23456 sp.xrev.txt.gz +49864527ceb4904191258b6baab1a4d6165af47302e12300e5b24a34b5f2db12 19200 sper.dec.raw +5a04e4c8e50baa2aa14142f97ef7024e0ded8face65ab4c952e02c168a7f8c11 8600 sper.dec.txt.gz +433457ddc7394e4ab04f0d650aeeca9ac03dcae5f2a435b6857619558a543dd4 21442 sper.deq.txt.gz +4aa0a5079a06ef4a3d870a7b31a6c345d4371464b7b8a03197b09e8477b60a58 540 sper.dstar +69449ab8151caa2f4f143902a053f6ef9a64a625ff1661f57ec5d413bfab3cd5 4398 sper.fec.txt.gz +ab2604080e32d413545f10c65bb8d204b08bf2adcc056824903060fff38303a0 21776 sper.half.txt.gz +478b08f4bd9de5c0d097b60b6179cb1a5a17fdc6aefaebe649826235db5803ae 502 sper.plan +4cb58311eab2dc0e7f497b02ddc827115bc325a537b62605a3a7e5402cff0d42 540 sper.r33 +2dd02e3d9e49dd6428b1e655c7afbf2f742aa1e6f84857051f6238461e9fb3fb 540 sper.xc.dstar +1bf337da737269491d4e31e06844f51f519e575a90f5d74b20826028011f13a8 20663 sper.xc.txt.gz +626ed34422408e316843d82b8385a1835f4874dd7219c493502d284b8228be08 540 sper.xrev.r33 +f739da8a4c6d34be958cfa74e94299b52b719e84413eb2b0b9315fccb12c1d51 16702 sper.xrev.txt.gz +f922e0ca2869cb40e37283728b3da59f027a5cde96a7e9d8160f3c5196701734 11948 tables_ambe2.txt.gz +2949e4abd2ad4bd18c138132f4069797f2017a365006f82403923be28fb71ea6 25819 tables_dstar.txt.gz +b4f4c6987c93b1e43fe67a4bf1bb793fed4b76c377b54ae77ce2be172133237d 25600 tn.dec.raw +7fa7a3ddae1c549c8faec8a48e301dec1c11f5fc92bbcbceadffa6813940abee 2103 tn.dec.txt.gz +71b6da46e2e662e5472b2c8de11d560a09d2f1cc2ff16ea45ef71bc4d561b7b0 3959 tn.deq.txt.gz +c6aa30c8e8ba18d9ffba315fd1a44e724644d60ead6731e9ccf06ad3280be155 720 tn.dstar +d0412e6931759ef7fbc535893db2e2354bebea926ce681d1c2f6412671f010ce 4860 tn.enc.txt.gz +084c8f8e42473d73886dd05684454e1cdbb23a5a9f0017fca9ef24578acf479a 1512 tn.fec.txt.gz +c9653d4a4bdb96f5e2b5bda94eb04b9392e416a554ee257a5818acd91a7bb9ce 6200 tn.half.txt.gz +aec0728bf7c6444c3b99e40277506df9d68e7ce4d3c46adfcc7b54aefdd047d9 25600 tn.in.raw +e70ca2210b8a9a7a85888072c7ec949cd11a1f98983305b17fc6c08e35573804 720 tn.r33 +e184c8ee65c1c83c83696ec215474173fd16fed3972b0f37d7adf1dd21eec4b1 720 tn.xc.dstar +0cd61f3ede31e458e9bac6b874f90b89e5db9c462021683268cb55e9f6ba39d4 5233 tn.xc.txt.gz +ec9132e1d395bbf384b01874edd8cbdd6371b5c6e1fdc1c5657624766d036103 720 tn.xrev.r33 +065d982e113f47ff9c4d5ce12838d407a50a2e5532da11e9cae32c62e5cb16a9 9382 tn.xrev.txt.gz +fab9fbc4ea8eafeef85658b0ae67373b4966703285016a00372f7a5575ccf2c8 648 tx.r33 +3098edaba1737d19e22df2c1c96ff3e808189e8cb94e4584f70b983dd7ffcbc8 648 tx.xc.dstar +cf7e065cc9ce1d585d793ea83af522f00a2357a59eda6c7b7dbe98670b6b67a4 8216 tx.xc.txt.gz diff --git a/xombe/vectors/dstar/fec_enc.txt.gz b/xombe/vectors/dstar/fec_enc.txt.gz new file mode 100644 index 0000000..874c464 Binary files /dev/null and b/xombe/vectors/dstar/fec_enc.txt.gz differ diff --git a/xombe/vectors/dstar/kx.dec.raw b/xombe/vectors/dstar/kx.dec.raw new file mode 100644 index 0000000..529aca9 Binary files /dev/null and b/xombe/vectors/dstar/kx.dec.raw differ diff --git a/xombe/vectors/dstar/kx.dec.txt.gz b/xombe/vectors/dstar/kx.dec.txt.gz new file mode 100644 index 0000000..5bd25dd Binary files /dev/null and b/xombe/vectors/dstar/kx.dec.txt.gz differ diff --git a/xombe/vectors/dstar/kx.deq.txt.gz b/xombe/vectors/dstar/kx.deq.txt.gz new file mode 100644 index 0000000..b681a4e Binary files /dev/null and b/xombe/vectors/dstar/kx.deq.txt.gz differ diff --git a/xombe/vectors/dstar/kx.dstar b/xombe/vectors/dstar/kx.dstar new file mode 100644 index 0000000..5b17be8 --- /dev/null +++ b/xombe/vectors/dstar/kx.dstar @@ -0,0 +1,2 @@ +Ÿ¤áŒD&ùŸ ñÁŒD·½›&ù€„D湟¤áŒD&ù ŽQ\ÿêýgEÏpù„‰¾ÿoËý�°ù®Øs§­~‚è"%ÉÐ5¸èé’÷g�«ÇwÀ"·ë'¶‘?,–I'³ˆ�+!ñWxJ7c +Qþš-ï3héÍ^ûŒ¨0ÕT‘­Ý÷Ío¹‘ò­½ñÝ­¹±ò鹜ûíì½�ã­­ÝñÕ­¹‘c©Œ›ãÌýà ±¬YåôýíµŒÛåÜ>ì#põ¸›ëÜüéq±Œšåļèaµ¬Ûãü>å!õ¬Yåôýo!µ¸…8óÁªð"£� 4ÙõavDÚÙýžjrW–?ÀO>ã¶þ"2óø Ô¡bWx \ No newline at end of file diff --git a/xombe/vectors/dstar/kx.enc.txt.gz b/xombe/vectors/dstar/kx.enc.txt.gz new file mode 100644 index 0000000..e12f2b1 Binary files /dev/null and b/xombe/vectors/dstar/kx.enc.txt.gz differ diff --git a/xombe/vectors/dstar/kx.fec.txt.gz b/xombe/vectors/dstar/kx.fec.txt.gz new file mode 100644 index 0000000..21604ee Binary files /dev/null and b/xombe/vectors/dstar/kx.fec.txt.gz differ diff --git a/xombe/vectors/dstar/kx.half.txt.gz b/xombe/vectors/dstar/kx.half.txt.gz new file mode 100644 index 0000000..6fe84c7 Binary files /dev/null and b/xombe/vectors/dstar/kx.half.txt.gz differ diff --git a/xombe/vectors/dstar/kx.in.raw b/xombe/vectors/dstar/kx.in.raw new file mode 100644 index 0000000..0ac7228 Binary files /dev/null and b/xombe/vectors/dstar/kx.in.raw differ diff --git a/xombe/vectors/dstar/kx.r33 b/xombe/vectors/dstar/kx.r33 new file mode 100644 index 0000000..8f8a5db Binary files /dev/null and b/xombe/vectors/dstar/kx.r33 differ diff --git a/xombe/vectors/dstar/kx.xc.dstar b/xombe/vectors/dstar/kx.xc.dstar new file mode 100644 index 0000000..257b90f Binary files /dev/null and b/xombe/vectors/dstar/kx.xc.dstar differ diff --git a/xombe/vectors/dstar/kx.xc.txt.gz b/xombe/vectors/dstar/kx.xc.txt.gz new file mode 100644 index 0000000..492ab54 Binary files /dev/null and b/xombe/vectors/dstar/kx.xc.txt.gz differ diff --git a/xombe/vectors/dstar/kx.xrev.r33 b/xombe/vectors/dstar/kx.xrev.r33 new file mode 100644 index 0000000..3584952 Binary files /dev/null and b/xombe/vectors/dstar/kx.xrev.r33 differ diff --git a/xombe/vectors/dstar/kx.xrev.txt.gz b/xombe/vectors/dstar/kx.xrev.txt.gz new file mode 100644 index 0000000..e3bcdb5 Binary files /dev/null and b/xombe/vectors/dstar/kx.xrev.txt.gz differ diff --git a/xombe/vectors/dstar/nz.dec.raw b/xombe/vectors/dstar/nz.dec.raw new file mode 100644 index 0000000..817060b Binary files /dev/null and b/xombe/vectors/dstar/nz.dec.raw differ diff --git a/xombe/vectors/dstar/nz.dec.txt.gz b/xombe/vectors/dstar/nz.dec.txt.gz new file mode 100644 index 0000000..9168d47 Binary files /dev/null and b/xombe/vectors/dstar/nz.dec.txt.gz differ diff --git a/xombe/vectors/dstar/nz.deq.txt.gz b/xombe/vectors/dstar/nz.deq.txt.gz new file mode 100644 index 0000000..c10a4a5 Binary files /dev/null and b/xombe/vectors/dstar/nz.deq.txt.gz differ diff --git a/xombe/vectors/dstar/nz.dstar b/xombe/vectors/dstar/nz.dstar new file mode 100644 index 0000000..cfc63cb Binary files /dev/null and b/xombe/vectors/dstar/nz.dstar differ diff --git a/xombe/vectors/dstar/nz.enc.txt.gz b/xombe/vectors/dstar/nz.enc.txt.gz new file mode 100644 index 0000000..2d59f50 Binary files /dev/null and b/xombe/vectors/dstar/nz.enc.txt.gz differ diff --git a/xombe/vectors/dstar/nz.fec.txt.gz b/xombe/vectors/dstar/nz.fec.txt.gz new file mode 100644 index 0000000..4addbc6 Binary files /dev/null and b/xombe/vectors/dstar/nz.fec.txt.gz differ diff --git a/xombe/vectors/dstar/nz.half.txt.gz b/xombe/vectors/dstar/nz.half.txt.gz new file mode 100644 index 0000000..5653778 Binary files /dev/null and b/xombe/vectors/dstar/nz.half.txt.gz differ diff --git a/xombe/vectors/dstar/nz.in.raw b/xombe/vectors/dstar/nz.in.raw new file mode 100644 index 0000000..b7d866e Binary files /dev/null and b/xombe/vectors/dstar/nz.in.raw differ diff --git a/xombe/vectors/dstar/quant_ambe2.txt.gz b/xombe/vectors/dstar/quant_ambe2.txt.gz new file mode 100644 index 0000000..8aa4677 Binary files /dev/null and b/xombe/vectors/dstar/quant_ambe2.txt.gz differ diff --git a/xombe/vectors/dstar/quant_closed.txt.gz b/xombe/vectors/dstar/quant_closed.txt.gz new file mode 100644 index 0000000..1ddd45c Binary files /dev/null and b/xombe/vectors/dstar/quant_closed.txt.gz differ diff --git a/xombe/vectors/dstar/quant_dstar.txt.gz b/xombe/vectors/dstar/quant_dstar.txt.gz new file mode 100644 index 0000000..d7e6de3 Binary files /dev/null and b/xombe/vectors/dstar/quant_dstar.txt.gz differ diff --git a/xombe/vectors/dstar/sp.dec.raw b/xombe/vectors/dstar/sp.dec.raw new file mode 100644 index 0000000..c976618 Binary files /dev/null and b/xombe/vectors/dstar/sp.dec.raw differ diff --git a/xombe/vectors/dstar/sp.dec.txt.gz b/xombe/vectors/dstar/sp.dec.txt.gz new file mode 100644 index 0000000..313b40e Binary files /dev/null and b/xombe/vectors/dstar/sp.dec.txt.gz differ diff --git a/xombe/vectors/dstar/sp.deq.txt.gz b/xombe/vectors/dstar/sp.deq.txt.gz new file mode 100644 index 0000000..9078c4c Binary files /dev/null and b/xombe/vectors/dstar/sp.deq.txt.gz differ diff --git a/xombe/vectors/dstar/sp.dstar b/xombe/vectors/dstar/sp.dstar new file mode 100644 index 0000000..84309c1 --- /dev/null +++ b/xombe/vectors/dstar/sp.dstar @@ -0,0 +1,2 @@ +Žª² ´ÂŸ»‚ûó€�·¿³Þ²˜sO™,03²°[G vÚÒ¶W‹é ç_T˺N3b૆kƒlåö£œ"c…IâÍO«G’ÖæÊ�Y -aplW¯ø‚XüÕâöÇŒ . +þXø7ÜÀx…Îå¿ïøyؼ‹«*Ë1ŒeÀZUï _‡~”XµŠÛÖ×RÐû‡Üm«Ì%Ü€_Fÿ{r�ßð}ÁÖYnvBæÜ[sm}êl‚*ÍÞ¸|> ¤NÍ%2+…޾ÍåŒ)„‘ÒØ€¨mUEV¡�昹´tŠtkÄîÒò&Â~ Ý.4È�ÜLãÙç8™á‚Òæ„©›.A>ª¸ï”ŸxC‡ý¼î�ÙdI L–Ùf­8ØŠÿö´f©üß¿ª¨û£ÝÛG†Ûîí9Kٻƈ®íû‰”mdÍì~Lñ¸å,˜Ê]ë|:—ýH�‰þaH Åx†ˆùa»žv“ç¡ÿ/þŠ^÷Âùœÿ�ÛM@Û�:a>¶²ÎÊ‹�M0ø6÷Kêë0šØ‡$¦öø7à4âÓ™¬s¶¢¿Ÿ÷ÉŠ®’}ÌÔÚìa‹¬>è7¼mt¾åzN ̸i^ª¼ÝÎÜÛi-ì˜ O‰qõl¿�ófœaä<çó¼w…=°XKŒØ§Ìï«/póŒLšˆ¬ƒ•´p $Š¥!‚EŽ8ålõÚÓ‰´2-XÑ_‹ \ No newline at end of file diff --git a/xombe/vectors/dstar/sp.enc.txt.gz b/xombe/vectors/dstar/sp.enc.txt.gz new file mode 100644 index 0000000..3ea39fb Binary files /dev/null and b/xombe/vectors/dstar/sp.enc.txt.gz differ diff --git a/xombe/vectors/dstar/sp.fec.txt.gz b/xombe/vectors/dstar/sp.fec.txt.gz new file mode 100644 index 0000000..69e3dbd Binary files /dev/null and b/xombe/vectors/dstar/sp.fec.txt.gz differ diff --git a/xombe/vectors/dstar/sp.half.txt.gz b/xombe/vectors/dstar/sp.half.txt.gz new file mode 100644 index 0000000..36c5d94 Binary files /dev/null and b/xombe/vectors/dstar/sp.half.txt.gz differ diff --git a/xombe/vectors/dstar/sp.in.raw b/xombe/vectors/dstar/sp.in.raw new file mode 100644 index 0000000..7cf4a46 Binary files /dev/null and b/xombe/vectors/dstar/sp.in.raw differ diff --git a/xombe/vectors/dstar/sp.r33 b/xombe/vectors/dstar/sp.r33 new file mode 100644 index 0000000..6f088b4 Binary files /dev/null and b/xombe/vectors/dstar/sp.r33 differ diff --git a/xombe/vectors/dstar/sp.xc.dstar b/xombe/vectors/dstar/sp.xc.dstar new file mode 100644 index 0000000..f614db6 --- /dev/null +++ b/xombe/vectors/dstar/sp.xc.dstar @@ -0,0 +1,5 @@ +¶ûçf»ù~ø›²ÕåI +S¶Ïº6Õ7ÍÃ/4có·]'½‹K˜ãrYDÈqR"!‡VS™£MôðлÓ=àî[ÙäÀöŒAdØN £ØÖ§ŽÏYCg:h0ºâ§¹ÍLý‘榰¸éIMŸ·ø˜ÁªçïÀÌ#�Ù�ßjŸ:™{ØZE®L–F¾ÀàUäÍš²!fż×ÍLòBGFù\SíO3B‡ÊÔ=Ù§ŠsGÀsm]#pÃîÕþýt� ´—F�b¼C•’(™é"Œ)„“!ÒŒ6ó6 ]G[‰ð²Ý­>ˆ$ÆÑÛÑ,PFð•¹aÍ‚›^ßÍÑæ8™â„ò„Ùüç%ž[¹ü»±8mvß“k=¶�øem� ‚Yb˜þÉ¿¿,"g�í:Çž¸êýøGÉÝÏiöü³³ÌOÆãZ£cØ\m «èY:á™e ©BòÚµ=ë\[–ÝØ…©½a\ +ÛÁÂÄßaTú +U÷û½Xÿ/î�zô‘õ‹�5«¡9å6–÷ÖŠ�Œ[ñ„W¿Ì²ðë0ÝÄU$¦wÑ·Eß¶`öWº¨RwŽ¿žUûÉßë§*ØjVú¼xaEš¾=Lg¬=ití¡ZŸÅìÙuvlð¹ÔvÌÚo7<ªœ� [aÔ\î 0r¨q•´ +ØÅ¬Xñ¥|½*i�œÚáÜì©/ ·¹[Ï�žŸ?ôèäaˆÒ‡L&ÓÔ10pÄ%“;ûÅm«sˆâ \ No newline at end of file diff --git a/xombe/vectors/dstar/sp.xc.txt.gz b/xombe/vectors/dstar/sp.xc.txt.gz new file mode 100644 index 0000000..5da265c Binary files /dev/null and b/xombe/vectors/dstar/sp.xc.txt.gz differ diff --git a/xombe/vectors/dstar/sp.xrev.r33 b/xombe/vectors/dstar/sp.xrev.r33 new file mode 100644 index 0000000..00bb086 Binary files /dev/null and b/xombe/vectors/dstar/sp.xrev.r33 differ diff --git a/xombe/vectors/dstar/sp.xrev.txt.gz b/xombe/vectors/dstar/sp.xrev.txt.gz new file mode 100644 index 0000000..2a87911 Binary files /dev/null and b/xombe/vectors/dstar/sp.xrev.txt.gz differ diff --git a/xombe/vectors/dstar/sper.dec.raw b/xombe/vectors/dstar/sper.dec.raw new file mode 100644 index 0000000..50198d2 Binary files /dev/null and b/xombe/vectors/dstar/sper.dec.raw differ diff --git a/xombe/vectors/dstar/sper.dec.txt.gz b/xombe/vectors/dstar/sper.dec.txt.gz new file mode 100644 index 0000000..2b14287 Binary files /dev/null and b/xombe/vectors/dstar/sper.dec.txt.gz differ diff --git a/xombe/vectors/dstar/sper.deq.txt.gz b/xombe/vectors/dstar/sper.deq.txt.gz new file mode 100644 index 0000000..ec09adc Binary files /dev/null and b/xombe/vectors/dstar/sper.deq.txt.gz differ diff --git a/xombe/vectors/dstar/sper.dstar b/xombe/vectors/dstar/sper.dstar new file mode 100644 index 0000000..4d7edfd Binary files /dev/null and b/xombe/vectors/dstar/sper.dstar differ diff --git a/xombe/vectors/dstar/sper.fec.txt.gz b/xombe/vectors/dstar/sper.fec.txt.gz new file mode 100644 index 0000000..67aafcf Binary files /dev/null and b/xombe/vectors/dstar/sper.fec.txt.gz differ diff --git a/xombe/vectors/dstar/sper.half.txt.gz b/xombe/vectors/dstar/sper.half.txt.gz new file mode 100644 index 0000000..e35dceb Binary files /dev/null and b/xombe/vectors/dstar/sper.half.txt.gz differ diff --git a/xombe/vectors/dstar/sper.plan b/xombe/vectors/dstar/sper.plan new file mode 100644 index 0000000..9b34972 --- /dev/null +++ b/xombe/vectors/dstar/sper.plan @@ -0,0 +1,41 @@ +# frames of sper.dstar changed from sp.dstar: n what (errAEC = bit errors in codewords A, B, C) +12 special +13 special +14 special +15 special +19 err100 +20 err012 +21 err210 +22 err301 +23 err400 +24 err030 +25 err041 +26 err333 +27 err520 +28 err111 +29 err220 +30 special +31 special +37 err442 +38 err340 +39 err431 +40 err553 +41 err442 +42 err340 +43 err431 +44 err553 +45 err442 +46 err340 +47 err431 +48 err553 +49 err442 +50 err340 +51 err431 +52 err553 +53 err442 +54 err340 +55 err431 +56 err553 +57 err442 +58 err340 +59 err431 diff --git a/xombe/vectors/dstar/sper.r33 b/xombe/vectors/dstar/sper.r33 new file mode 100644 index 0000000..2756b05 Binary files /dev/null and b/xombe/vectors/dstar/sper.r33 differ diff --git a/xombe/vectors/dstar/sper.xc.dstar b/xombe/vectors/dstar/sper.xc.dstar new file mode 100644 index 0000000..f9d9380 --- /dev/null +++ b/xombe/vectors/dstar/sper.xc.dstar @@ -0,0 +1,3 @@ +¶ûçf»ù~ø›²ÕåI +S¶Ïº6Õ7ÍÃ/4có·]'½‹K˜ãrYDÈqR"!‡VS™£MôðлÓ=àî[ÙäÀöŒAdØN £ØÖ§ŽÏYCg:h0ºâ§¹ÍLý‘榰¸éIMŸ·ø˜ÁªçïÀÌ#�Ù�ßjŸ:™{ØZE®L–F¾ÀàUäÍš²!fż×ÍLòBGFù\SíO3B‡ÊÔ=Ù§ŠsGÀsm]#pÃîÝßùdœ ¤�b¾K¥Ò8ÛõCŒ9…›1!–�uÍþªMU{Õrõ,zˆub�á¸I] QíÈöñ]m‹ÜÕ±&*¹ç«ºNÙüç-žØ¹Ü»µÛivÞ×Sÿôñ½e-_U•Ïü¬¾Ë·þ©"™ÙøßÏøöø³ýÝ:Ýߪòìqwí^cW\f×§Ð\i‹äØtˆ\o|Žåbî„ݘã,›†êΓ¹½äD{×ř€ÙeËZvñ«ÈÛÏïÄwƼáÞûGŒ“UЗ¡xá6Öóö +ˬÙçŪÍéˆë0_Äu$¦wµðM߯dÕ�ÍñK–¨4¤‰Øï×èÊyPª¼xaEŠü=Låìºm$½ÿI™VÌ™eާ¨-ˆü›k èˆLF¨[aÔ|î 0r€[aÔ_­Á·ŒXàü=¡b?Ü_cŒ^õ<5¯¹ÙÏ�Ÿ—7U¬ð ŒÒ„@6“%G4p…5“@%Æ*xÈ»O{ d¤ºC4™r<´¤Ï6ùˆñW÷Ä«5õV.ð2´¿÷ÿv­ý0ô¿»ñ5ûäs¨¿9Úå30à¯ûõ5yè72 jÿïjg_¼ÙÐïÿ/3.°Õ~“ëŽè?jg­­^Q”šýcøÍÙÅÿõb´È¹ÝÙ„¸±qðŒG• ©¤p¨Œ[É�ê©�q¬œ˜C¥Š¥€`윘C¥Š¥€`윘C¥Š¥€`ìÓ8Ý.[y% ÜÏØÅ%û˜ºòñ³»Ëdßþ–…¤øm M¿öø˜Íš¥§Äœ!ˆƒî<ÏYIW \ No newline at end of file diff --git a/xombe/vectors/dstar/tx.xc.txt.gz b/xombe/vectors/dstar/tx.xc.txt.gz new file mode 100644 index 0000000..7d34ab3 Binary files /dev/null and b/xombe/vectors/dstar/tx.xc.txt.gz differ diff --git a/xombe/vectors/e3/SHA256SUMS b/xombe/vectors/e3/SHA256SUMS new file mode 100644 index 0000000..b5bd354 --- /dev/null +++ b/xombe/vectors/e3/SHA256SUMS @@ -0,0 +1,35 @@ +b4be3094f9c95d699c7b4b922609eb1d63ee45cb445df758f798d928c804b535 es1.d0.raw +0bc585cca3183241bc4183c6d4481f4f97865174771deb1ecaa47ee957d5e27e es1.d1.raw +111178baded36b9d3e0eb2de04585c415b738220b5c846d21fe9afc926b0284b es1.d2.raw +d5cfbad1cef13583e29ec860730a6f835736f4c2bbb91052e7af291de4d91207 es1.d3.raw +ddb3f23e97629f26e9edf22f198ae30299ff9d13bd64425406f17951aa6c4147 es1.d4.raw +30e2be4c392c06994f0ee4232ccd9e7bbb00afe9237903559efb3c5d627aa0a3 es2.d0.raw +41cc28b91f16088632a9120cc6818de941c63b5aeb4a245eba8807b424513ef6 es2.d1.raw +ce986e30605296ae5696980c50522d0bb2b06d12bffc50f62d2b3c388262a379 es2.d2.raw +5066a58894ee163ae41c8b6001b8359c2ec868ade78f1b55042d53cf7881b63a es2.d3.raw +d42be8b35d6a6b49b9ecbdcd1da411a03d3fe23f2a473a839765f527a43922f5 es2.d4.raw +0a3b5602bf59a82147ed052aa6b53d87d48722ff5d4e2531e3badc76a106f889 es3.d0.raw +34b4d014add7dab50e9947eea89cafb52af8535e444a393a8134cf09be56432e es3.d1.raw +0f66de98104c825593f0d06213168d1069fde47d12961fa29a7064a1bb600a6f es3.d2.raw +c700a6e29d4864e07e2c7996a2435326f11fc7d0fd64197a2f001ecca75c8584 es3.d3.raw +093045ed7c24f36e3bf6ebf1609bddb403f0eeb4b32e5b044d3cf2d865589ad1 es3.d4.raw +4f25853171a6cc1c00fa7c0b760ae794b89750994c6ef5a2b6189a8ae6293a60 sn10.d0.raw +51947abffd136cd337f5f46ca364cc52d944c759cf888fa938d55196a9ac6330 sn10.d1.raw +9d116439a0be2a27f0d47c44a43c1308103661c72005345632c4c39a469e5bfe sn10.d2.raw +39c12d22cd5f79c65cd451cfa4be77f15d49f7fa3ee35535bb4963daa976bf4c sn10.d3.raw +f073a42d0db03b29b5239c6c730a66f723a35ad549baa6449279ac111a641003 sn10.d4.raw +ad7000cfbf5356888b993365bba85de0838f9b897f6f87837b6e82e5deadb4aa ttsf.d0.raw +13b1cf966bda497e0316448672b2cadaf67dd015a89de8af03b2c655cc3e6ffd ttsf.d1.raw +bbb7f77afabdb4c5ad149a03df4150d6fcebeff9f1afd58ae13448fc32b5e880 ttsf.d2.raw +98fba7943129aecbceda8eee6b79ecfa5c8b9d5ed8d2013e2c8cc4baa1f3f4ba ttsf.d3.raw +aa165069d094e7e4f659e9cc85fadfd71a8821b96797256a399c71c360f6291e ttsf.d4.raw +f8872e3da2b448fae0c3b7e01ced0ca0b422fe78d96972e7c43dd835c880e36f ttsc.d0.raw +0ac20da75c864d68f51aae13230d183d134bfc3797e76c973d428b128f1616b6 ttsc.d1.raw +42c18d15405067f905e7ae8be7999c542d13202e57d9b2a16f4dd1e00e2abd40 ttsc.d2.raw +23eade0901ed647c56cf77ce192c590f5ec7e57f0afffb7abfc1f84e859204ae ttsc.d3.raw +31083ca6cbe825ad01dd79b245f26bdca81f49910d1ec46a127f76aded5df9f3 ttsc.d4.raw +1b19588474fa3b719b351d1d38de85a7a9d197005eeaefda446455176f29c362 ttsl.d0.raw +fbbe97731107c1914f3eb2bae56fb836aa42ba83b3e313d304470140e79457f9 ttsl.d1.raw +3ce4e6fb6d3c8c25c4175323d04c8e8b51f1ebbec29373881c946171b967c38c ttsl.d2.raw +9d7cab9e1e436d5ee213ece0563afbd9bca2e6e34cbf1904fd2ee6a67d56d5d1 ttsl.d3.raw +fe9168f9be5f7516d91ea8b83326f1ad8100f63f21e2d24a143458fedb842d0a ttsl.d4.raw diff --git a/xombe/vectors/e3/es1.ref.d0.amb b/xombe/vectors/e3/es1.ref.d0.amb new file mode 100644 index 0000000..53516da Binary files /dev/null and b/xombe/vectors/e3/es1.ref.d0.amb differ diff --git a/xombe/vectors/e3/es1.ref.d1.amb b/xombe/vectors/e3/es1.ref.d1.amb new file mode 100644 index 0000000..402d382 Binary files /dev/null and b/xombe/vectors/e3/es1.ref.d1.amb differ diff --git a/xombe/vectors/e3/es1.ref.d2.amb b/xombe/vectors/e3/es1.ref.d2.amb new file mode 100644 index 0000000..01a01e2 Binary files /dev/null and b/xombe/vectors/e3/es1.ref.d2.amb differ diff --git a/xombe/vectors/e3/es1.ref.d3.amb b/xombe/vectors/e3/es1.ref.d3.amb new file mode 100644 index 0000000..55f53c3 Binary files /dev/null and b/xombe/vectors/e3/es1.ref.d3.amb differ diff --git a/xombe/vectors/e3/es1.ref.d4.amb b/xombe/vectors/e3/es1.ref.d4.amb new file mode 100644 index 0000000..ed61d8b Binary files /dev/null and b/xombe/vectors/e3/es1.ref.d4.amb differ diff --git a/xombe/vectors/e3/es1_orig.raw b/xombe/vectors/e3/es1_orig.raw new file mode 100644 index 0000000..6691595 Binary files /dev/null and b/xombe/vectors/e3/es1_orig.raw differ diff --git a/xombe/vectors/e3/es2.ref.d0.amb b/xombe/vectors/e3/es2.ref.d0.amb new file mode 100644 index 0000000..7d6d825 Binary files /dev/null and b/xombe/vectors/e3/es2.ref.d0.amb differ diff --git a/xombe/vectors/e3/es2.ref.d1.amb b/xombe/vectors/e3/es2.ref.d1.amb new file mode 100644 index 0000000..10a2b47 Binary files /dev/null and b/xombe/vectors/e3/es2.ref.d1.amb differ diff --git a/xombe/vectors/e3/es2.ref.d2.amb b/xombe/vectors/e3/es2.ref.d2.amb new file mode 100644 index 0000000..0636338 Binary files /dev/null and b/xombe/vectors/e3/es2.ref.d2.amb differ diff --git a/xombe/vectors/e3/es2.ref.d3.amb b/xombe/vectors/e3/es2.ref.d3.amb new file mode 100644 index 0000000..7b09eae Binary files /dev/null and b/xombe/vectors/e3/es2.ref.d3.amb differ diff --git a/xombe/vectors/e3/es2.ref.d4.amb b/xombe/vectors/e3/es2.ref.d4.amb new file mode 100644 index 0000000..4324484 Binary files /dev/null and b/xombe/vectors/e3/es2.ref.d4.amb differ diff --git a/xombe/vectors/e3/es2_orig.raw b/xombe/vectors/e3/es2_orig.raw new file mode 100644 index 0000000..dddaf74 Binary files /dev/null and b/xombe/vectors/e3/es2_orig.raw differ diff --git a/xombe/vectors/e3/es3.ref.d0.amb b/xombe/vectors/e3/es3.ref.d0.amb new file mode 100644 index 0000000..79052e7 Binary files /dev/null and b/xombe/vectors/e3/es3.ref.d0.amb differ diff --git a/xombe/vectors/e3/es3.ref.d1.amb b/xombe/vectors/e3/es3.ref.d1.amb new file mode 100644 index 0000000..0b9a952 Binary files /dev/null and b/xombe/vectors/e3/es3.ref.d1.amb differ diff --git a/xombe/vectors/e3/es3.ref.d2.amb b/xombe/vectors/e3/es3.ref.d2.amb new file mode 100644 index 0000000..d5611cc Binary files /dev/null and b/xombe/vectors/e3/es3.ref.d2.amb differ diff --git a/xombe/vectors/e3/es3.ref.d3.amb b/xombe/vectors/e3/es3.ref.d3.amb new file mode 100644 index 0000000..14c11f4 Binary files /dev/null and b/xombe/vectors/e3/es3.ref.d3.amb differ diff --git a/xombe/vectors/e3/es3.ref.d4.amb b/xombe/vectors/e3/es3.ref.d4.amb new file mode 100644 index 0000000..41d21f0 Binary files /dev/null and b/xombe/vectors/e3/es3.ref.d4.amb differ diff --git a/xombe/vectors/e3/es3_orig.raw b/xombe/vectors/e3/es3_orig.raw new file mode 100644 index 0000000..f218a9d Binary files /dev/null and b/xombe/vectors/e3/es3_orig.raw differ diff --git a/xombe/vectors/e3/sn10.ref.d0.amb b/xombe/vectors/e3/sn10.ref.d0.amb new file mode 100644 index 0000000..cfc0fcf Binary files /dev/null and b/xombe/vectors/e3/sn10.ref.d0.amb differ diff --git a/xombe/vectors/e3/sn10.ref.d1.amb b/xombe/vectors/e3/sn10.ref.d1.amb new file mode 100644 index 0000000..94db895 Binary files /dev/null and b/xombe/vectors/e3/sn10.ref.d1.amb differ diff --git a/xombe/vectors/e3/sn10.ref.d2.amb b/xombe/vectors/e3/sn10.ref.d2.amb new file mode 100644 index 0000000..4a7ef14 Binary files /dev/null and b/xombe/vectors/e3/sn10.ref.d2.amb differ diff --git a/xombe/vectors/e3/sn10.ref.d3.amb b/xombe/vectors/e3/sn10.ref.d3.amb new file mode 100644 index 0000000..3e2d09e Binary files /dev/null and b/xombe/vectors/e3/sn10.ref.d3.amb differ diff --git a/xombe/vectors/e3/sn10.ref.d4.amb b/xombe/vectors/e3/sn10.ref.d4.amb new file mode 100644 index 0000000..0e214ef Binary files /dev/null and b/xombe/vectors/e3/sn10.ref.d4.amb differ diff --git a/xombe/vectors/e3/sn10_orig.raw b/xombe/vectors/e3/sn10_orig.raw new file mode 100644 index 0000000..cee4296 Binary files /dev/null and b/xombe/vectors/e3/sn10_orig.raw differ diff --git a/xombe/vectors/e3/ttsc.ref.d0.amb b/xombe/vectors/e3/ttsc.ref.d0.amb new file mode 100644 index 0000000..54d5937 Binary files /dev/null and b/xombe/vectors/e3/ttsc.ref.d0.amb differ diff --git a/xombe/vectors/e3/ttsc.ref.d1.amb b/xombe/vectors/e3/ttsc.ref.d1.amb new file mode 100644 index 0000000..91db24e Binary files /dev/null and b/xombe/vectors/e3/ttsc.ref.d1.amb differ diff --git a/xombe/vectors/e3/ttsc.ref.d2.amb b/xombe/vectors/e3/ttsc.ref.d2.amb new file mode 100644 index 0000000..fdc0cf2 Binary files /dev/null and b/xombe/vectors/e3/ttsc.ref.d2.amb differ diff --git a/xombe/vectors/e3/ttsc.ref.d3.amb b/xombe/vectors/e3/ttsc.ref.d3.amb new file mode 100644 index 0000000..e847290 Binary files /dev/null and b/xombe/vectors/e3/ttsc.ref.d3.amb differ diff --git a/xombe/vectors/e3/ttsc.ref.d4.amb b/xombe/vectors/e3/ttsc.ref.d4.amb new file mode 100644 index 0000000..6eecf7a Binary files /dev/null and b/xombe/vectors/e3/ttsc.ref.d4.amb differ diff --git a/xombe/vectors/e3/ttsc_orig.raw b/xombe/vectors/e3/ttsc_orig.raw new file mode 100644 index 0000000..49de708 Binary files /dev/null and b/xombe/vectors/e3/ttsc_orig.raw differ diff --git a/xombe/vectors/e3/ttsf.ref.d0.amb b/xombe/vectors/e3/ttsf.ref.d0.amb new file mode 100644 index 0000000..63c8c99 Binary files /dev/null and b/xombe/vectors/e3/ttsf.ref.d0.amb differ diff --git a/xombe/vectors/e3/ttsf.ref.d1.amb b/xombe/vectors/e3/ttsf.ref.d1.amb new file mode 100644 index 0000000..1a0bd25 Binary files /dev/null and b/xombe/vectors/e3/ttsf.ref.d1.amb differ diff --git a/xombe/vectors/e3/ttsf.ref.d2.amb b/xombe/vectors/e3/ttsf.ref.d2.amb new file mode 100644 index 0000000..25d2f82 Binary files /dev/null and b/xombe/vectors/e3/ttsf.ref.d2.amb differ diff --git a/xombe/vectors/e3/ttsf.ref.d3.amb b/xombe/vectors/e3/ttsf.ref.d3.amb new file mode 100644 index 0000000..ac5afcc Binary files /dev/null and b/xombe/vectors/e3/ttsf.ref.d3.amb differ diff --git a/xombe/vectors/e3/ttsf.ref.d4.amb b/xombe/vectors/e3/ttsf.ref.d4.amb new file mode 100644 index 0000000..1f5fb04 Binary files /dev/null and b/xombe/vectors/e3/ttsf.ref.d4.amb differ diff --git a/xombe/vectors/e3/ttsf_orig.raw b/xombe/vectors/e3/ttsf_orig.raw new file mode 100644 index 0000000..95d4021 Binary files /dev/null and b/xombe/vectors/e3/ttsf_orig.raw differ diff --git a/xombe/vectors/e3/ttsl.ref.d0.amb b/xombe/vectors/e3/ttsl.ref.d0.amb new file mode 100644 index 0000000..913e29b Binary files /dev/null and b/xombe/vectors/e3/ttsl.ref.d0.amb differ diff --git a/xombe/vectors/e3/ttsl.ref.d1.amb b/xombe/vectors/e3/ttsl.ref.d1.amb new file mode 100644 index 0000000..793bd46 Binary files /dev/null and b/xombe/vectors/e3/ttsl.ref.d1.amb differ diff --git a/xombe/vectors/e3/ttsl.ref.d2.amb b/xombe/vectors/e3/ttsl.ref.d2.amb new file mode 100644 index 0000000..2187d33 Binary files /dev/null and b/xombe/vectors/e3/ttsl.ref.d2.amb differ diff --git a/xombe/vectors/e3/ttsl.ref.d3.amb b/xombe/vectors/e3/ttsl.ref.d3.amb new file mode 100644 index 0000000..32e907b Binary files /dev/null and b/xombe/vectors/e3/ttsl.ref.d3.amb differ diff --git a/xombe/vectors/e3/ttsl.ref.d4.amb b/xombe/vectors/e3/ttsl.ref.d4.amb new file mode 100644 index 0000000..0f0503e Binary files /dev/null and b/xombe/vectors/e3/ttsl.ref.d4.amb differ diff --git a/xombe/vectors/e3/ttsl_orig.raw b/xombe/vectors/e3/ttsl_orig.raw new file mode 100644 index 0000000..6f290ca Binary files /dev/null and b/xombe/vectors/e3/ttsl_orig.raw differ diff --git a/xombe/vectors/e5/es1_lead0.5s.raw b/xombe/vectors/e5/es1_lead0.5s.raw new file mode 100644 index 0000000..5468173 Binary files /dev/null and b/xombe/vectors/e5/es1_lead0.5s.raw differ diff --git a/xombe/vectors/e5/hp5.raw b/xombe/vectors/e5/hp5.raw new file mode 100644 index 0000000..b545a5c Binary files /dev/null and b/xombe/vectors/e5/hp5.raw differ diff --git a/xombe/vectors/e5/hp5.ref.amb b/xombe/vectors/e5/hp5.ref.amb new file mode 100644 index 0000000..40f02a2 Binary files /dev/null and b/xombe/vectors/e5/hp5.ref.amb differ diff --git a/xombe/vectors/e5/low5.raw b/xombe/vectors/e5/low5.raw new file mode 100644 index 0000000..05a0d4e Binary files /dev/null and b/xombe/vectors/e5/low5.raw differ diff --git a/xombe/vectors/e5/low5.ref.amb b/xombe/vectors/e5/low5.ref.amb new file mode 100644 index 0000000..de16b47 Binary files /dev/null and b/xombe/vectors/e5/low5.ref.amb differ diff --git a/xombe/vectors/e7/glide.raw b/xombe/vectors/e7/glide.raw new file mode 100644 index 0000000..df0f47a Binary files /dev/null and b/xombe/vectors/e7/glide.raw differ diff --git a/xombe/vectors/e7/glide.ref.amb b/xombe/vectors/e7/glide.ref.amb new file mode 100644 index 0000000..74d0415 Binary files /dev/null and b/xombe/vectors/e7/glide.ref.amb differ diff --git a/xombe/vectors/e7/mix.raw b/xombe/vectors/e7/mix.raw new file mode 100644 index 0000000..346ba13 Binary files /dev/null and b/xombe/vectors/e7/mix.raw differ diff --git a/xombe/vectors/e7/mix.ref.amb b/xombe/vectors/e7/mix.ref.amb new file mode 100644 index 0000000..9411931 Binary files /dev/null and b/xombe/vectors/e7/mix.ref.amb differ diff --git a/xombe/vectors/e7/saw150.raw b/xombe/vectors/e7/saw150.raw new file mode 100644 index 0000000..ef57788 Binary files /dev/null and b/xombe/vectors/e7/saw150.raw differ diff --git a/xombe/vectors/e7/saw150.ref.amb b/xombe/vectors/e7/saw150.ref.amb new file mode 100644 index 0000000..7649897 Binary files /dev/null and b/xombe/vectors/e7/saw150.ref.amb differ diff --git a/xombe/vectors/e7/tones.raw b/xombe/vectors/e7/tones.raw new file mode 100644 index 0000000..e66737e Binary files /dev/null and b/xombe/vectors/e7/tones.raw differ diff --git a/xombe/vectors/e7/tones.ref.amb b/xombe/vectors/e7/tones.ref.amb new file mode 100644 index 0000000..e9f178e Binary files /dev/null and b/xombe/vectors/e7/tones.ref.amb differ diff --git a/xombe/vectors/fec/air72_map.txt b/xombe/vectors/fec/air72_map.txt new file mode 100644 index 0000000..6edaea2 --- /dev/null +++ b/xombe/vectors/fec/air72_map.txt @@ -0,0 +1,73 @@ +# air bit (0 = first transmitted, MSB of byte 0 in the 9-byte packing) -> codeword, bit (0 = codeword MSB), 49-bit index if data bit (C1 data bits are PN-scrambled on air) + 0 C0[ 0] d0 + 1 C0[18] parity + 2 C1[12] parity + 3 C2[ 7] d31 + 4 C0[ 1] d1 + 5 C0[19] parity + 6 C1[13] parity + 7 C2[ 8] d32 + 8 C0[ 2] d2 + 9 C0[20] parity +10 C1[14] parity +11 C2[ 9] d33 +12 C0[ 3] d3 +13 C0[21] parity +14 C1[15] parity +15 C2[10] d34 +16 C0[ 4] d4 +17 C0[22] parity +18 C1[16] parity +19 C3[ 0] d35 +20 C0[ 5] d5 +21 C0[23] parity +22 C1[17] parity +23 C3[ 1] d36 +24 C0[ 6] d6 +25 C1[ 0] d12 +26 C1[18] parity +27 C3[ 2] d37 +28 C0[ 7] d7 +29 C1[ 1] d13 +30 C1[19] parity +31 C3[ 3] d38 +32 C0[ 8] d8 +33 C1[ 2] d14 +34 C1[20] parity +35 C3[ 4] d39 +36 C0[ 9] d9 +37 C1[ 3] d15 +38 C1[21] parity +39 C3[ 5] d40 +40 C0[10] d10 +41 C1[ 4] d16 +42 C1[22] parity +43 C3[ 6] d41 +44 C0[11] d11 +45 C1[ 5] d17 +46 C2[ 0] d24 +47 C3[ 7] d42 +48 C0[12] parity +49 C1[ 6] d18 +50 C2[ 1] d25 +51 C3[ 8] d43 +52 C0[13] parity +53 C1[ 7] d19 +54 C2[ 2] d26 +55 C3[ 9] d44 +56 C0[14] parity +57 C1[ 8] d20 +58 C2[ 3] d27 +59 C3[10] d45 +60 C0[15] parity +61 C1[ 9] d21 +62 C2[ 4] d28 +63 C3[11] d46 +64 C0[16] parity +65 C1[10] d22 +66 C2[ 5] d29 +67 C3[12] d47 +68 C0[17] parity +69 C1[11] d23 +70 C2[ 6] d30 +71 C3[13] d48 diff --git a/xombe/vectors/fec/fec_decode_c0x4.txt b/xombe/vectors/fec/fec_decode_c0x4.txt new file mode 100644 index 0000000..0972605 --- /dev/null +++ b/xombe/vectors/fec/fec_decode_c0x4.txt @@ -0,0 +1,203 @@ +# Reference FEC decoder, 4 bit errors in C0 (random positions), fresh decoder state per line. +# Columns: sent49 air72_received out49 eps0 eps1 BF. 49-bit fields as in fec_encode_vectors.txt; +# out49 is the decoder's 49-bit output (spec 2.3, eps0 = 4 case); sent49 is the frame before errors. +9D3CD3657F3100 F43DFF7B34EDFE8C30 9D3CD3657F3100 4 0 1 +3556B759EA2700 175541096829603718 0153EE59EA2700 4 3 1 +14C833EAB03000 616F3AE6C6433A0E0E 96A4C3EAB03000 4 3 1 +45EDBF8979C380 7C75FD6ABDB24C8391 45EDBF8979C380 4 0 1 +C5A73C748E7300 8B42695D42B9F66578 C51F02748E7300 4 3 1 +80A4D33253D780 C87C5627D1949635D7 54A44C3253D780 4 3 1 +15A54DD976EE00 F47B5859C79BAD7780 9FB72ED976EE00 4 3 1 +2D00A28318F300 10C4BB466157DC015E 2C8E758318F300 4 3 1 +0D3BF6E2729A80 E6519C4F0FEEBB498F 99FAE5E2729A80 4 3 1 +7495FB968E5580 ED8AEF75A0DA1CF07F ECB035968E5580 4 3 1 +56120BD81F4700 CC4A199B347E24BF54 971404D81F4700 4 3 1 +A8EA5519751C80 F4D3B0F6F6E499B641 AABA6319751C80 4 3 1 +A0E86956BF4400 C5A57317D894ECBCA6 A2E25156BF4400 4 3 1 +247C6955FE7400 53F37F312E9DBCB8A4 64777955FE7400 4 3 1 +8453EC91348E00 DC0B1850496E01FD8C 50582491348E00 4 3 1 +21CD0BA5A4CE80 1D47605E6D1AC3D929 C15190A5A4CE80 4 3 1 +F2987BC9A87800 D9AB63C4E0F7354E8C F2AD50C9A87800 4 3 1 +99757AB9E06B00 F71DC2EE4897032B14 1368CBB9E06B00 4 3 1 +865DDE83302C80 94673A84AA470D140B 865DDE83302C80 4 0 1 +641E9AE615C200 2A8010165516AA0166 641E9AE615C200 4 0 1 +F2824B94F08A00 2BDB3C80812685EDA4 360D9794F08A00 4 3 1 +E21348D689A600 A78241E4112FA4B566 821F1DD689A600 4 3 1 +EFF46BAE404000 0CD4EC8AE8B2C6466A 6729C8AE404000 4 3 1 +58DBC9FBF4DC00 7B7FD0748B5EB7BA0A 58DBC9FBF4DC00 4 0 1 +66C364AF88FE00 3D842BEAEB579B9F6A 37D590AF88FE00 4 3 1 +0539D7E915D680 30421C1071FA7EDF45 023D96E915D680 4 3 1 +7CB865FCC42080 499CEE5AA42BAAE6E1 7D9962FCC42080 4 3 1 +CD6552ECCCF080 8BF0EFF66FB33A46E9 EE7FDDECCCF080 4 3 1 +27AF990408C980 E4A049AECDD0418CF5 27AF990408C980 4 0 1 +DC6D01F2AC4900 8F2B8F5204D267281A DC6D01F2AC4900 4 0 1 +9A68B51A038C80 C66CC68D1DC4453E8F 9BEDF21A038C80 4 2 1 +B5A3F451270180 D6CD0EDFB2C46CA091 B2A04D51270180 4 3 1 +E117D25F539180 D8D2148B5300B8A6B7 E117D25F539180 4 0 1 +9BCD36DE838100 E12A86E3B562A0A63A 9BCD36DE838100 4 0 1 +5BD668AB115B00 180EFEA0D87A934B5A 1E558EAB115B00 4 3 1 +635FA914C86F80 6B94C5E6487D8DF1F5 EA40CC14C86F80 4 3 1 +E05213E51F4800 98E0B3537E3EEBC82C 785495E51F4800 4 3 1 +7C55C859909980 1FE8382E25687526D9 7506F259909980 4 3 1 +A7CE9A7F08E080 F4E20F0C8915EA2623 B5E1627F08E080 4 3 1 +9863D4264FBB00 E63C813771E1D7CDFE D83B88264FBB00 4 3 1 +B016C1EDF02000 B1B35A2424AF6A466C 2532BCEDF02000 4 3 1 +98F68E093FFF80 9629FD737DBD99D3D5 9C7681093FFF80 4 3 1 +1818FCF179F980 98159564371BBB2011 C19D82F179F980 4 3 1 +4751D280D9FF00 491413A63B7B5D515C 405C5480D9FF00 4 3 1 +DCCB08D58FC800 93688977BB1E692CAC 9EF683D58FC800 4 3 1 +E0E87D3C405E80 88926444CC98D3FFAD E0FED03C405E80 4 3 1 +0AF65E98C7BC00 25F286D7D9AB11BA8C 3AB2B198C7BC00 4 3 1 +0199114E987400 E1427168CE393CD266 A1C7CF4E987400 4 3 1 +909B8B03FB2300 D3DF3127922904899A 38134603FB2300 4 3 1 +EA1C5DA60EB380 8EECC1D723239A45BF F206C7A60EB380 4 3 1 +D9F86C6080AC00 ADAAC66E67ADE79CC8 F9362A6080AC00 4 2 1 +1C1DB9167AF780 065B114303791C7D73 D0115E167AF780 4 3 1 +283B986C180980 6AA6D562A4E8E74E31 78B1E46C180980 4 3 1 +8DAF89B9818880 D542E60C95A68B6A81 8AA45AB9818880 4 3 1 +CB84870F2C5280 9C43875AC4541447AB CB84870F2C5280 4 0 1 +4CB0865EDDFF00 6B52DF90B99D797FBE 4AFEA15EDDFF00 4 3 1 +64F89D45A28380 19A76A4329E0208171 660F0B45A28380 4 3 1 +4F6A0A7B5D2700 5CB29F9E1EE1A6B71E 6E68A07B5D2700 4 3 1 +10778D2D887100 712A612CCCDD9A06FC 01FE592D887100 4 3 1 +63CF8BC6438600 08D402A99B666CD9E6 E3C074C6438600 4 0 1 +A9E5D456E50A00 83F1C01AFA40296DEE A9E5D456E50A00 4 0 1 +CA82A2FAC90000 AD766182F48226A28A CA82A2FAC90000 4 0 1 +B453E7E9C00200 959CAC026A0EA2CB48 B453E7E9C00200 4 0 1 +081A96FA98A580 4F0491A0632BA2BE13 081A96FA98A580 4 0 1 +EE15FF90A67800 69A3C6B1027BDD6C0C 625A0390A67800 4 3 1 +2892B896C01F80 27FEC444E44E55F5B7 B8978A96C01F80 4 3 1 +482863EBD0AE00 1DD0D406A3872F53CA 68BE01EBD0AE00 4 3 1 +3FE6B1A4A82500 8FE3E3AECC878E583C EBEB9DA4A82500 4 2 1 +6D6516AB31F300 B6C7FCA87B975ACBDE 6D6516AB31F300 4 0 1 +A6DDDEB1592880 F4B01D02B24F0BE80D A0916EB1592880 4 3 1 +69B089C8FCE880 EFD3BD7E8BBF6D4A8D EDD73FC8FCE880 4 3 1 +288DB73E4EB780 049CA139A105527B77 1186573E4EB780 4 3 1 +8B49F60A692F80 C611A16C1C494557D7 C97A180A692F80 4 2 1 +9DF86ACC5B4900 E498D52B9E9A65063C 39B06ACC5B4900 4 2 1 +3C030E6FD78B80 D55CD47335442F83F7 9983286FD78B80 4 3 1 +25A889E7712300 32F5FA84B2C32E4D7A 2E6EDFE7712300 4 2 1 +64650551A8A000 710569026DC168AC48 64650551A8A000 4 0 1 +943D4B3C1CE280 82EA3F760D9D4EA3E1 B4D9203C1CE280 4 3 1 +7FEC4A3AB88500 A9A99D88E140C2FE5E BF097E3AB88500 4 3 1 +761A60DC966300 0DC0B899C41FAC2F78 AF9A05DC966300 4 3 1 +35E9EADD7C2500 12359F18EEA3A4327C 0F6418DD7C2500 4 3 1 +487FE4A3ED5B00 5B91E574349E5B4592 6D3092A3ED5B00 4 3 1 +BB12A906588800 C698F1CA296CC508E6 BB715D06588800 4 3 1 +BB1B0C617CE680 F4D9D1BA0595A695C1 FA2769617CE680 4 3 1 +83ECD17B37B580 742150FD1BA17E3ED7 136BBD7B37B580 4 3 1 +5B9A4CBF7BAB00 5E7DD3E9972343A7BE 5B0792BF7BAB00 4 3 1 +7B193AC9B71280 3D6F12F9566A300341 421DA2C9B71280 4 3 1 +BCBE538752AA80 F6DCBC25E7AB490127 BEB67B8752AA80 4 3 1 +33FD2C343A0E00 448B716388AC033DEC B8FF01343A0E00 4 3 1 +EAAD5A11CA0900 7B7287A38EA04D6498 4AFFF611CA0900 4 3 1 +5D90C11B9D9F80 3F8CD918D3A0913F93 3DE7B31B9D9F80 4 3 1 +A831FBAA003F80 A482C24E208B539393 EB3888AA003F80 4 3 1 +C0F1CF61E8A000 9B55434A0F69AA44C8 C9531161E8A000 4 3 1 +FBF3E112DF8080 ED9ED3BDFF0CC0A80B 7990D612DF8080 4 3 1 +18F36956EF1580 E173C1199EAC34B8FF ABF2A856EF1580 4 2 1 +78E535E8DD9580 2B9AFB5C9BC6725E5D 7DFF88E8DD9580 4 3 1 +E5F72733ACD180 BDE70BDAC3B01A2C1B CFA05233ACD180 4 3 1 +74371CA2E02D00 299B6EC624AF039C96 6639F8A2E02D00 4 3 1 +4628CC32806880 4D000EA060FD036443 56111A32806880 4 3 1 +59D5BC75DA8000 B37AB16B890CEEAC24 BDF5D575DA8000 4 3 1 +1F357501B00E80 796B988846E8091585 DE378901B00E80 4 2 1 +7E666143FC4900 BB9939D66AD0A508DA D6EBE643FC4900 4 3 1 +E78D641902C800 9CE22C8DE954412ECC E6D6041902C800 4 3 1 +50C2053C35B500 0E2B7050BF0512B2F0 52CA263C35B500 4 3 1 +C922F642313600 A005140A78E574DD8A 91768C42313600 4 3 1 +AF3FC3B909C300 D688A78815FA826B58 BB6DB1B909C300 4 3 1 +DA5A30E15EAF00 1C1895B76B23EF9198 5EC25AE15EAF00 4 3 1 +FFEA8FBC35C900 CCC9B8DAF5F20FAE34 7DAE9ABC35C900 4 3 1 +27237C7F45DE00 7ADC2C7C5790FFF72A F503A67F45DE00 4 1 1 +74FF107D5E1380 5E7A5BD30CAC722FB9 5679B97D5E1380 4 3 1 +D7B2D768BE3A80 AF4D7BFFACE1F70FC5 97E61368BE3A80 4 3 1 +9716DAFD857900 374E2CBA7493B7EA30 35251CFD857900 4 3 1 +3509419ECEB680 C3B8615BC3075CF36F B19E979ECEB680 4 2 1 +8FD1832888B980 E102A3ACC549D70215 9290532888B980 4 2 1 +D700C006A37600 AB634E4B70591C59AA C115A406A37600 4 3 1 +1F250001A7CD00 71218C3951940958DC 052D9101A7CD00 4 3 1 +F497EA04250B80 C02D6A329C2CC58D35 96D0E404250B80 4 3 1 +FF7C4BC20F5780 CAAAADB7781A309557 FE559AC20F5780 4 2 1 +1600BFC2FC4000 033B339604F6A80CCE 12AC77C2FC4000 4 3 1 +E086BD4F3D1D80 D0A1317CD06CB112B3 A11FC04F3D1D80 4 3 1 +77BC662B1B1900 1AAA7DCFD8CC9F02DE 5FFB052B1B1900 4 2 1 +80E25C59F97B80 F553F926FA9571E395 0CACA659F97B80 4 3 1 +A6287894D01400 CFD45E420482587C6C C461FB94D01400 4 2 1 +BEF7672EC68A00 C998ECBDAD880347E6 EFE2792EC68A00 4 3 1 +364D47EDD53900 17F65E341A63734EF4 2501B1EDD53900 4 3 1 +8DBB6E72D14400 A3D2BA0AB0B8AE7842 BDF8BA72D14400 4 1 1 +77F37C10792800 0C9B39AEDE0D05E804 5DD78810792800 4 2 1 +CA322D2EACCF00 AB45A3D4A734CF9736 E2892F2EACCF00 4 2 1 +92772AACB12000 E14FD2A21EEBCE8260 AB74DFACB12000 4 3 1 +8F07A3B8661180 C4D58AFB20461EEE5D AB097AB8661180 4 3 1 +2EE395F402B080 22A08CE5AB673668ED 2FCA76F402B080 4 3 1 +03A5A990669A80 A4B140FB4382D12D4D AB24AA90669A80 4 3 1 +F58D1328845E80 E9EA6A7C2E54571741 B5569828845E80 4 3 1 +F2136DE786CC80 5F8A22D3435A6F5CA3 760B19E786CC80 4 3 1 +E32C0A5A81D900 C7E022AA17B0352E92 A7458D5A81D900 4 3 1 +B189FEB7627800 D2F9206B4A93D3A426 716206B7627800 4 3 1 +DB83B4C9423780 BAFAA06DEA4738935D F8CD98C9423780 4 3 1 +D5687A0C1CD300 CECC977A2DB01443B4 F944600C1CD300 4 2 1 +6A0F21C3B1E000 5B0FB2A6373BEC400E 5A12E4C3B1E000 4 3 1 +46640CC9F1D880 1D7778E453B2FDCE89 47327BC9F1D880 4 3 1 +B1F2B93F6FDA80 B2BF433B9BB81B2FAB B3FAC03F6FDA80 4 3 1 +8DCC131B8B5C80 9B28CB695E545DF607 DF04AE1B8B5C80 4 3 1 +D0D4C8EC3AD700 8C2111A7CD5E729B3C C2DABDEC3AD700 4 3 1 +DCFCA1CA8ECD00 ED048B13899E295252 DCFCA1CA8ECD00 4 0 1 +F4F07749F97000 B9F9DD60BCDDF44688 FCB76849F97000 4 3 1 +0F7A68833B5080 3861F5873ADE504083 42562E833B5080 4 3 1 +936E0EAFFED200 95397FBD49F6D64BEE 936E0EAFFED200 4 0 1 +0ED69ED6AB4B80 012529819E5A6D6977 06CC38D6AB4B80 4 3 1 +17B802FF7D5780 3E9F59D8F6DEF2FBF3 77B95BFF7D5780 4 3 1 +62E9D3373EB880 582317F3AF25132C2F 40C42E373EB880 4 3 1 +22E32BF724E180 52C942D2C9D7EE68BB 36EAD9F724E180 4 3 1 +65A421E526A580 9EA7285B8107269079 65A421E526A580 4 0 1 +AD2254E775D600 909DDE3C3952FA9D22 B5CC9DE775D600 4 3 1 +909D66A5BBFC80 F16F7303D9DFD7D4AD 93F0E2A5BBFC80 4 1 1 +6F14F5F6A69100 8F85AEBD2B4AB6A83A EE5365F6A69100 4 3 1 +0D23D30A8AC400 2FE0CD09619408124E 0D23D30A8AC400 4 0 1 +3B529F65046000 36A8A0BA84356A40E8 7B895265046000 4 3 1 +5EADAFF7381680 5C4BDDE40AA2FEF9EB 5A78E0F7381680 4 3 1 +BF01AE7AB9C800 A52B9B8E7114A7EE46 97129D7AB9C800 4 3 1 +5C329710E75480 4D1BA45194BCD8F445 1ABD3510E75480 4 3 1 +77A9664D84FE80 3B8E0AFA619571D369 FF230F4D84FE80 4 3 1 +52C86378012000 0E2220C2DC09262644 52C86378012000 4 0 1 +CE604D011BDB00 3A6A9FE11BF411C91C 5F2F71011BDB00 4 3 1 +234E874B848D80 1DAE04DAA9646D121B 73CACD4B848D80 4 3 1 +E1B6A2C4A62F80 8D8B425BC2CB619DB9 71BF3BC4A62F80 4 3 1 +E1D8C15976DB00 5E75741DAF5CFD6FDC 43E5C65976DB00 4 3 1 +D1AC53A78D5C00 3F8C271EF692D3D42A 3BAAE1A78D5C00 4 2 1 +D2CFFEBEB8AE00 E90F7188E7274F3F2E F780ACBEB8AE00 4 2 1 +1427B9C032B500 2409184183E7B0DC50 1427B9C032B500 4 0 1 +E1FFB877995F80 BBA431A6BCF87379BF E1FFB877995F80 4 0 1 +9A7A140AFFE380 A79795937DDD000FD7 9A7A140AFFE380 4 0 1 +5147381889A380 274C67223961406319 904B1A1889A380 4 2 1 +4E1A168169FA00 1457CB88517B190908 0D172A8169FA00 4 3 1 +2530903C139E00 02E27C03770C93336C 241D633C139E00 4 3 1 +6522A427D30A00 BD945E69308CCB41A2 A5344427D30A00 4 3 1 +56CFAB893ADF80 3A0DF983893E995FD1 5EF71B893ADF80 4 3 1 +06F10AC3CB2580 373223C5BA8FE0DC5B 52BABBC3CB2580 4 2 1 +FBF5F233961B80 D9ECF0992E8C57295F F97E1933961B80 4 2 1 +D1F409F6A7A380 AD6DA6B9BBAF266573 5AFA5AF6A7A380 4 3 1 +EC90A909C21100 D3D0C821A424DCC61C AEA3CA09C21100 4 3 1 +BF76403F18AC00 B0887B6A61EDCF3666 9521F63F18AC00 4 3 1 +B24363337B1C00 F4B357C3520CDB34CA 839BA8337B1C00 4 3 1 +C39F33B60B2280 AAA025E7D06B06E1AF E29B59B60B2280 4 3 1 +29397616EDD480 2993A35037F8DC30E3 6A332D16EDD480 4 2 1 +943E861131C200 32E53E46D3D84CEDC4 2494E81131C200 4 3 1 +B4AA3DA8286780 80E96B44A6F3CED395 B5A39CA8286780 4 3 1 +72031B7D4C6900 F87843966031636638 D402A77D4C6900 4 2 1 +F3C2D57EB2CA00 CBE95CEF49102727AE C7441F7EB2CA00 4 3 1 +F95873D2421300 26BAC40FEA0234211E 19CF7DD2421300 4 3 1 +31014D3B41F780 56FE6428573DD23F9F 1199C93B41F780 4 3 1 +88450E8D7C0880 B453F1B86E424D0E25 8F4AED8D7C0880 4 3 1 +ADCE6E79C59D80 D7D2A8B05F20B37A5D 2E458879C59D80 4 3 1 +51320D297E6B00 5C5B153BAE9903C750 71D58F297E6B00 4 3 1 +C9BD9EB3A23480 FB03A80D808FDE700F CF8333B3A23480 4 2 1 +34BAB397673600 34374813DE83D43D2E 056A9A97673600 4 3 1 +982D20E8889180 E30E63E241E2760A51 982D20E8889180 4 0 1 +E60D932F2C7500 D62549B60635DA9676 862E9A2F2C7500 4 3 1 +E0DBB0AF678B80 B4F72077BB8EC707BF A07188AF678B80 4 3 1 +55DDC701AD2500 394B0F7C982D8CD4DC 59D1B601AD2500 4 3 1 +9676901D583300 D43C7D4EA8AD94EBBC 9DB5651D583300 4 3 1 diff --git a/xombe/vectors/fec/fec_encode_vectors.txt b/xombe/vectors/fec/fec_encode_vectors.txt new file mode 100644 index 0000000..f119f54 --- /dev/null +++ b/xombe/vectors/fec/fec_encode_vectors.txt @@ -0,0 +1,81 @@ +# 49-bit frame (d0..d48, MSB-first 7-byte hex, d48 in the MSB of the last byte) -> 72-bit air frame (9-byte hex, first transmitted bit = MSB of byte 0). Reference encoder pairs. +FC10000FFFFF00 FDD9F9537779191776 +F801A99F8CE080 B9E881526173002A6B +80000000000000 C426246264448C004C +40000000000000 6C4046026264088440 +20000000000000 42E02266624088CC08 +10000000000000 442C2002402408C8C0 +08000000000000 2640C2604420008C8C +04000000000000 04602C620220CC0CC4 +02000000000000 224626C4202008C4C8 +01000000000000 6024666E6064408C48 +00800000000000 22046042A2208C488C +00400000000000 262646044A2080C0C4 +00200000000000 466640206480800C00 +00100000000000 42606622266884448C +00080000000000 000000660020404400 +00040000000000 202002222200404400 +00020000000000 002200246220404400 +00010000000000 202222260420404400 +00008000000000 222220062240404400 +00004000000000 000222062224404400 +00002000000000 202020042020004400 +00001000000000 222200240000444400 +00000800000000 000220040000400400 +00000400000000 022022060000404000 +00000200000000 020202262000404440 +00000100000000 020020242200404404 +00000080000000 220002040222404400 +00000040000000 220002040220604400 +00000020000000 220002040220424400 +00000010000000 220002040220406400 +00000008000000 220002040220404600 +00000004000000 220002040220404420 +00000002000000 220002040220404402 +00000001000000 320002040220404400 +00000000800000 230002040220404400 +00000000400000 221002040220404400 +00000000200000 220102040220404400 +00000000100000 220012040220404400 +00000000080000 220003040220404400 +00000000040000 220002140220404400 +00000000020000 220002050220404400 +00000000010000 220002041220404400 +00000000008000 220002040320404400 +00000000004000 220002040230404400 +00000000002000 220002040221404400 +00000000001000 220002040220504400 +00000000000800 220002040220414400 +00000000000400 220002040220405400 +00000000000200 220002040220404500 +00000000000100 220002040220404410 +00000000000080 220002040220404401 +2F2D90A69A5B80 65C4FDED62D2DF0DF3 +ADA7581F4B7D80 90B0AD4FD4F1D5F6FF +042A62FCF54400 61157C3074B62E72E4 +D3A26C252BB880 DA4B21AD9781DB40E5 +6B807EA54A3B00 789487CFC0231781B8 +44243F23F35C80 3F5718255290179487 +2AB5A050F20D00 61F79287C6CC6DB058 +1317DB48F13380 473F348C764DF4C39D +713D2678A2ED00 0DAF260B03FDAB3658 +6D224F7284F980 29E08C5C45D1BB685B +FB2EAF558F7500 BDCE81B952B5BC38BC +A87199DBA74580 B3A5A63558BAA0FED7 +1E2380F0B8EF00 032F99E661936BB154 +07A1330515F080 12405CBAB5B1D804E9 +B5411A2D6ADA80 929B0B6D2D741347AD +3CA763FC77E180 429DFE35B3B766A63D +7F10920B975980 5B8CBCBD1238DD4A9F +6C9FE95E1FF680 4EC4BF13B77D30B363 +1BFEE015132D00 3028B2EBDAA949F878 +2F49ECD9A53F80 1587C8DC3C67F9B355 +7493C40723CC80 1CAB6C43D35849942B +23519AB7A06F00 57E540886C1F8335F2 +AB079CC57F2080 F2F797FF70032C482D +E23DFC4CA8DE80 EFC541C467D831D725 +D8C38B49090600 DC288540D864E45B08 +90F3B766FE2100 833F1513AEADEE4C3E +6070ACBAAE4200 2F8107134CBA06A706 +9468FC2B0C6500 F42A0F526CF50A1ADA +8CBF5D70756600 E015BC72F2FDEEB140 diff --git a/xombe/vectors/fec/fec_hb_onset.txt b/xombe/vectors/fec/fec_hb_onset.txt new file mode 100644 index 0000000..c1e4362 --- /dev/null +++ b/xombe/vectors/fec/fec_hb_onset.txt @@ -0,0 +1,363 @@ +# Reference FEC decoder, HB onset. Each sequence starts from a fresh decoder (epsR = 0); frame 1 is the first. +# Columns: seq frame air72_received out49 eps0 eps1 BF HB. Sequences: constant injected (C0, C1) errors per +# frame; sequence 3 continues with error-free frames. out49 equals the sent frame on every line. +0 1 0566A3B3763589D224 088C130C8F6C00 2 2 0 0 +0 2 75F99CDC6418333482 3E193073F45C00 2 2 0 0 +0 3 A9B85812597C631C4D 745F9A60D5CC80 2 2 0 0 +0 4 8673F897318C06B705 9E378A38778680 2 2 0 0 +0 5 12A5B67E75C9BAD541 29374B6135B680 2 2 0 0 +0 6 4B84005A0B00C7C247 61078F2A848880 2 2 0 0 +0 7 B9444B95D54CF649B2 C29C93678F9300 2 2 0 0 +0 8 F30175CAB9E3DFA2C9 E3ED11B9B9B880 2 2 0 0 +0 9 B550A484E4379FDA38 CA08B1ADC07D00 2 2 0 0 +0 10 F2E9D4E0E29475A9D0 B8A3A551305B00 2 2 0 0 +0 11 BFC1CAB114F9AB9CF7 EF3B9967A76D80 2 2 0 0 +0 12 D6C1619C95F17B5D99 B3A891612DFF80 2 2 0 0 +0 13 3DFA90C077C6AEAF12 7AAF2BFBD18300 2 2 0 0 +0 14 F0675BC8FF7CA4D8BA 87D7A44739C500 2 2 0 0 +0 15 2C3BCE69C4B1FE2C2E 5DA86976627000 2 2 0 0 +0 16 84BA68A488631366A0 B6EB46BC403800 2 2 0 0 +0 17 F930DDC2F84E1C34DF CADACC93D91580 2 2 0 0 +0 18 B0569809F793F55BD9 0DA604C953FF80 2 2 0 0 +0 19 36C1EFF34B42874189 2D46ADA12E8A80 2 2 0 0 +0 20 102AA241B9D6103E8E 88E6FD9B03D400 2 2 0 0 +0 21 278837BC12C6CB7FFA 3722C1BE9D0F00 2 2 0 0 +0 22 B3388758CC2370FD4D B9C57ED1CC3680 2 2 0 0 +0 23 ED45E56CFA6E9D706D C9F40394A91C80 2 2 0 0 +0 24 6EACE926C78C399A2A ECB3BE4E089C00 2 2 0 0 +0 25 E27BDC1B09B314E376 9C6D6A9E76F300 2 2 0 0 +0 26 CA4DED566592B09382 DC2BBCCA2CD600 2 2 0 0 +0 27 E1635C05576C0F7DF7 C45A9C36B38F80 2 2 0 0 +0 28 D925CAA6593E445F7B C6520C8FA1C780 2 2 0 0 +0 29 02C48C91E82BFF9826 2E1641E6063C00 2 2 0 0 +0 30 455AB5342621D4A6BB 184E8F1EDC3180 2 2 0 0 +0 31 2461DE676C43D4229B 2D41959A323180 2 2 0 0 +0 32 2079446F5DB98B44D8 197BCB2063E900 2 2 0 0 +0 33 2C980C60C6F00582E6 7EA13D0E404800 2 2 0 0 +0 34 C15F5AF1931FA1056B 96177CC6F7EA80 2 2 0 0 +0 35 CF5EFB2F519CDE8E6E 5D3F6D2EDBD000 2 2 0 0 +0 36 B935D0B110629DE932 CE8D3A97F71B00 2 2 0 0 +0 37 F96A2F4D48F23A04F1 D56FF5E58A5180 2 2 0 0 +0 38 1569F3C0266BB5A03D 1A1454D5B83980 2 2 0 0 +0 39 C2E2CD4B99CB8FA2B8 8DDA4BBC0BA900 2 2 0 0 +0 40 D4F312DB219FCD25F3 AB33249776EB80 2 2 0 0 +0 41 3910C1F9BFFB024A20 49FDA5ADCFE000 2 2 0 0 +0 42 A5A82027552EDC226E B014D99E839000 2 2 0 0 +0 43 2BB293CD04D07715A8 692A6964DA5E00 2 2 0 0 +0 44 36CE6311F8CDF3BF95 307D80790F3F80 2 2 0 0 +0 45 523B9C03DD48850A00 3CD03009738800 2 2 0 0 +0 46 EA6DD52AA4388BD195 DB9C9F20384F80 2 2 0 0 +0 47 D198EC277E0D9D9E34 AC5BFF0DC33D00 2 2 0 0 +0 48 80B3740201D3A98402 A022F9C270E800 2 2 0 0 +0 49 C9632D5A7E3443BCA9 C5C72034AD4C80 2 2 0 0 +0 50 935D465B66F0E98850 916FEF41E64900 2 2 0 0 +0 51 3F1F14C579EDBD39BD 52438055F3BF80 2 2 0 0 +0 52 9AB6375F9D0E5770E6 E1F76AB75F9C00 2 2 0 0 +0 53 DE06558F260A8B58E5 4115C9A51A0C80 2 2 0 0 +0 54 920C0866DCE1F469B0 14633955013300 2 2 0 0 +0 55 86F7C26FC7FCF22F4D ABBA967862D280 2 2 0 0 +0 56 C949CF93B7021D4BB7 DA868E8EAF9B80 2 2 0 0 +0 57 F4487059ED4BF37D25 93C854F516BE80 2 2 0 0 +0 58 B4466D8E111E2EA0EE 979D4FF709C000 2 2 0 0 +0 59 7A06102C8E6EC1E40F 41D89193100880 2 2 0 0 +0 60 12810BEA5B0C7FF544 265AC071299E00 2 2 0 0 +0 61 FBD75963A82BBDDBA7 E4C676CFFA3E80 2 2 0 0 +0 62 4143BB7CFE157A8ECC 09C0EF68BD7000 2 2 0 0 +0 63 5E04E4C4E1EB35132F 6AB8FDCF00BE80 2 2 0 0 +0 64 4AF55D6EF43CF0A66B 6586125E795080 2 2 0 0 +0 65 3F8EEABE86CB316BEF 7FA5EEDF843A80 2 2 0 0 +0 66 F17E2F6B94CE959F63 95BCE98FCB1E80 2 2 0 0 +0 67 4484559E91F787D5C9 21A993A01DEE80 2 2 0 0 +0 68 0A34E9F9FC6F0040C9 6F5821804F2080 2 2 0 0 +0 69 E6ED387045597C7A4E B03F035A34F400 2 2 0 0 +0 70 5331465367D4FFF8FF 0226E377E6DD80 2 2 0 0 +0 71 EEEAFB901B53CE409A 7E4D65A21DE100 2 2 0 0 +0 72 98E4462009244A15E7 E069B827008680 2 2 0 0 +0 73 E8ABBE8D434284B622 F7032E9E328400 2 2 0 0 +0 74 B69BAEC7E2C1F9DDDA BAEC6243623F00 2 2 0 0 +0 75 0531D8467593286132 0D2E98D6F1E300 2 2 0 0 +0 76 33A2716E7F015A29EC 294E763599B200 2 2 0 0 +0 77 B7022B5F37A27FCBBD 0522A2ED8F9B80 2 2 0 0 +0 78 AA6BB55EF140653AD1 D98BEC583D8D80 2 2 0 0 +0 79 8148A7023EE5AC7C03 D86A7C52892480 2 2 0 0 +0 80 0EDD499AB7F90DA63D 73B73B1C6DE980 2 2 0 0 +1 1 4C54DCB2948268C5DE 66AFB7C2550300 2 3 0 0 +1 2 18E0D1CC1CC89EA7C7 6B62F73B191280 2 3 0 0 +1 3 891ED1C7104425E064 DA1E6B54DB0800 2 3 0 0 +1 4 C675598BDEEB482E3F 97F9B89E7B2180 2 3 0 0 +1 5 0E70BF10BB20E230D5 5CC891705D8580 2 3 0 0 +1 6 CCB4BB8801194F2437 EF1F6D3658E980 2 3 0 0 +1 7 6BC85D8C7B318D247C 774E2B1499E900 2 3 0 0 +1 8 B4096CAE383DDD4713 935F120B217B80 2 3 0 0 +1 9 9A9A263B3DF1571948 51679E2147FE00 2 3 0 0 +1 10 62F12F977CE9604FF9 2634BF4C6F2380 2 3 0 0 +1 11 69FF81737BDBCAFB65 1874BFBCEFE680 2 3 0 0 +1 12 2E9BBD0EA70E2161CF 3D9C80D2788A80 2 3 0 0 +1 13 1DADEBE2619F01F101 7D30F491A8EE80 2 3 0 0 +1 14 7D42598846EA967797 463D28BB981780 2 3 0 0 +1 15 CEEB1EB3C1CAE4D794 D6B60DC8368700 2 3 0 0 +1 16 991B3CA660896F52A6 DE32086FF02C00 2 3 0 0 +1 17 B9AC45F95BB3C8E102 F32DBD938FE200 2 3 0 0 +1 18 C15BB72D66CEECF8E0 9938EDD4FA0400 2 3 0 0 +1 19 53EECFE43989DA2C03 7E714E3389B080 2 3 0 0 +1 20 7ABBAA65C2B80F3713 7CF6A33B624F80 2 3 0 0 +1 21 A587AF6EAEAB6AADB1 8DF84DF4A82380 2 3 0 0 +1 22 C105821F2EEFBD97D4 89512DC8A63F00 2 3 0 0 +1 23 07658E98644BFA510E 1F054DE2A43600 2 3 0 0 +1 24 178DCD410369BE3956 3D184F73AAB700 2 3 0 0 +1 25 F66145A0B9FB4E92D1 82BA6BA929E580 2 3 0 0 +1 26 FC3D75AAB5156D7AB5 D3814D5D79ED80 2 3 0 0 +1 27 12758D22166A6A59DD 0D14A1E1690780 2 3 0 0 +1 28 E7AD0E94FC762F3735 B2C55EFCA54F80 2 3 0 0 +1 29 61B8F432BF63B1869C 28CF4FC8D5B900 2 3 0 0 +1 30 5E855AD23B0A74B7A6 6455AEDF359600 2 3 0 0 +1 31 731A3BF1C0EC1F7752 07BD703BDE1F00 2 3 0 0 +1 32 CAEB9A8495EA4C2A45 FFBBB798318080 2 3 0 0 +1 33 8E3D4671C749C2595D D09E0C2066A780 2 3 0 0 +1 34 28937B8E2D8EB4D219 677387C8789580 2 3 0 0 +1 35 2583F759EC448979E7 23CAE316BE0E80 2 3 0 0 +1 36 A4A937FBB1CA186B10 B3B0E6983F9300 2 3 0 0 +1 37 0C24D26DA5AF8A7A24 69AD20BC12A400 2 3 0 0 +1 38 0F2A85D9EBD88BA265 7BF8FD3C8EC880 2 3 0 0 +1 39 0EEE065F48243CFD52 714B0652061700 2 3 0 0 +1 40 81A53F847FAC0F5571 A23D8224B98F80 2 3 0 0 +1 41 2DA88A4AE8A51C4190 7DC93B00803300 2 3 0 0 +1 42 5998894A893DB72FCD 79D73E79C8FA80 2 3 0 0 +1 43 3DEFF3CDA1B01FBE5B 73BAB83BBADD80 2 3 0 0 +1 44 BE351D7CB93D233DC1 C591DD717DEE80 2 3 0 0 +1 45 D5928957D8D361D154 ACE223C1CF6F00 2 3 0 0 +1 46 253BCA7B98CD5F0DCE 1D782822E73A00 2 3 0 1 +1 47 7E88A2F8E468D84CF1 7B956905041180 2 3 0 1 +1 48 3DED5F5A2EA921E96A 7571AB57BC2A00 2 3 0 1 +1 49 1EA15F977370810C2E 6007D9073FC800 2 3 0 1 +1 50 FD86F2DE48F8E56734 EB7B955D944B00 2 3 0 1 +1 51 D8840B25640853312C E41917350A1E00 2 3 0 1 +1 52 DFE169A600BA048714 E2367489A84300 2 3 0 1 +1 53 F6038BC1F4D6152A90 0E2098992B5900 2 3 0 1 +1 54 2A38437E0D7A9E7B7E 51DD8DBE4CD700 2 3 0 1 +1 55 64FF92FA9A70F734EF 3BC04676755C80 2 3 0 1 +1 56 45071793613B0B57E1 0258AAACBEEE80 2 3 0 1 +1 57 1DAEDA8001F47F76A0 EE22877D90DC00 2 3 0 1 +1 58 CD7728631FE66D10DF C46037C2E38D80 2 3 0 1 +1 59 A2B8AD453BFFF6282E BC632AF64BF000 2 3 0 1 +1 60 2E4CDE65AB21A087B4 5CC4974C12A300 2 3 0 1 +2 1 DEAE79B1E1A3C78872 F6AC28A71EA900 3 2 0 0 +2 2 70227C5155F4843DA9 04AA301517C680 3 2 0 0 +2 3 0C29DAE5098FFA38E9 5A7CB8F432B480 3 2 0 0 +2 4 3B0BF422B33B559DDC 18933C81B1FF00 3 2 0 0 +2 5 CFA8B7D0EFED332142 FAF5BF729CBA00 3 2 0 0 +2 6 F29812B8853AC06275 929A499D54C180 3 2 0 0 +2 7 4FCFE20A9A48E31BAF 79FBEF6EA10E80 3 2 0 0 +2 8 3C8DD30196D0E39B68 78E86A6D3B4E00 3 2 0 0 +2 9 81FA7495A76180D98E B7C59C02D6A600 3 2 0 0 +2 10 4073C5A1125FB19A82 2A3ECCCA6B7C00 3 2 0 0 +2 11 BBFBBAB9F39EF4C45A DFB2D1C3F7D100 3 2 0 0 +2 12 C58A1BDEA7F602FF0B 36ABD8BA9CC680 3 2 0 0 +2 13 B387E173AC5D2AC802 A8C9E563AE6000 3 2 0 0 +2 14 4798DC92A964E4341B 1ECC4352D48580 3 2 0 0 +2 15 D3BD0C2F820B0E5425 A584CBA5E22480 3 2 0 0 +2 16 30CB9E57644B623151 BC1F10F1362780 3 2 0 0 +2 17 65925DDA79A53355F5 27603564DDBF80 3 2 0 0 +2 18 7AEE0D466B8A5AD552 467185A3089700 3 2 0 0 +2 19 F069CBCB279F7F32C7 953B9AFB2AFC80 3 2 0 0 +2 20 6BBF297DB9F9A8F8BD 67FEB054EFE580 3 2 0 0 +2 21 0DC6CD1834C1B5C819 4D0653408D3980 3 2 0 0 +2 22 9C67EDB3D8F1CC6EE2 CEE4AD1F2F6000 3 2 0 0 +2 23 B9AA56DA11D77759B5 B30C0DE595FF80 3 2 0 0 +2 24 90C1269DCAC45F6DDB A7ED8D33261B80 3 2 0 0 +2 25 8FCEB67899D1DDE184 FBECB31095FA00 3 2 0 0 +2 26 13C8D396F530B48D80 3ACD59419DD200 3 2 0 0 +2 27 EDD6F5808AA51DB487 EAFACB12D83C80 3 2 0 0 +2 28 5C40BFE45EB411A18F 4A37E613195A80 3 2 0 0 +2 29 008638A3AE91C180CB 26A3F102126880 3 2 0 0 +2 30 61D5BFF347CEC82582 2E75AA92FE8200 3 2 0 0 +2 31 EDBF968B0788A88BF8 D830354CF28300 3 2 0 0 +2 32 DFB48620766E42A5D1 C01E02B1C10380 3 2 0 0 +2 33 6B2F0250045A363274 501FBEFCA45500 3 2 0 0 +2 34 581F97A4EF2C0CB1C4 5A5CAC11788600 3 2 0 0 +2 35 B1D2972DF49A11F875 81BB4B95DB5D80 3 2 0 0 +2 36 BBD5578CE3524429B9 FB99C995F8C380 3 2 0 0 +2 37 D98BC706FD47E7BBDF 28C231FBA9AF80 3 2 0 0 +2 38 FC9ED3EFD501A34B7F FB88CE6F5BAB80 3 2 0 0 +2 39 BDBB8096C2EBD470D9 FBB2EA91E43580 3 2 0 0 +2 40 5204CD8172E5C4D339 0E6BB20D0B2780 3 2 0 0 +2 41 16BF021D0A123587DF 39492ECB665B80 3 2 0 0 +2 42 2E083ED96ACE3728EE 56720EF6161800 3 2 0 0 +2 43 13B8B6E54773084EEC 3A09D38DD2E000 3 2 0 0 +2 44 D2393A6E8F6C66EA7F B7D95A7F708180 3 2 0 0 +2 45 7D5F75D3634C0F6BB2 5256083FFE8B00 3 2 0 0 +2 46 D8AA83C6AFEA7134CE B2FDF2D3089C00 3 2 0 1 +2 47 2E49C5BA05194E31CD 7F3236302CE680 3 2 0 1 +2 48 7A839C4798F0E065C2 64EC4353334200 3 2 0 1 +2 49 B9BC8C6B063018EDC7 FA0A0C13C25280 3 2 0 1 +2 50 1027B5E473567A61DD 0206EDF139D380 3 2 0 1 +2 51 5A76EB6E7F5C308637 4511574F49D180 3 2 0 1 +2 52 A96BE3840A9274AD20 1A66CBD4A85200 3 2 0 1 +2 53 EF790452F8BED35B17 D1FE3EAAE55F80 3 2 0 1 +2 54 66D2EC9FD67DFB1934 2FD1D664477F00 3 2 0 1 +2 55 FEF73E0A89C302BA73 F5C252BF70A580 3 2 0 1 +2 56 DC896CACA800A3FE0F D7D7037B200C80 3 2 0 1 +2 57 0B688BBFA6BDC45012 DFB513028E6500 3 2 0 1 +2 58 B9A2ADF8BC921FD560 EE6B75A58D5E00 3 2 0 1 +2 59 980FE415D96272915A D8EAFDE3279700 3 2 0 1 +2 60 4309641D78A0404133 11A74906A70380 3 2 0 1 +3 1 8316A8EAAEE7FD26CB 85E831DAC03880 3 3 1 0 +3 2 2028260E86B6F78D6A 31AEF1E6005A00 3 3 1 0 +3 3 534B45AA41E18AA506 930DD333A8A200 3 3 1 0 +3 4 FEF9B60ADB669C212C 7DD7A895719200 3 3 1 0 +3 5 4D19F0536303EE3EC9 D003E0F8F6A480 3 3 1 0 +3 6 010BE848DC7D62FF81 11CD8378A16680 3 3 1 0 +3 7 E3B852417CFBF252AA A977F4EED37400 3 3 1 0 +3 8 AC5043ECBFD707B224 80E9C4BC49EC00 3 3 1 0 +3 9 75020AB1A35FEF4CC8 06FDBEE186E800 3 3 1 0 +3 10 6DECA44C6A5BD6D1B5 3955B5A4807780 3 3 1 0 +3 11 D3CD629AFFF5930F7A B3E6892FA5FB00 3 3 1 0 +3 12 73BCE9A0193E32367F 3E5CF1FFC9D580 3 3 1 0 +3 13 628C1188F125A5A542 33C5AA5219AA00 3 3 1 0 +3 14 22F121C67E62C6AE22 226A82BE690000 3 3 1 0 +3 15 27EF6609D319832DA4 289A4434A3EA00 3 3 1 0 +3 16 727A59758BDAE03816 34E4B8D35EC500 3 3 1 0 +3 17 DD1ADD681935B8BC06 D95F9C53D9F400 3 3 1 0 +3 18 440335896E9AE8057D 13E31BC43A4380 3 3 1 0 +3 19 1A3FFA69499F64D9B0 457E32C572E700 3 3 1 0 +3 20 1BD4E4708B6AE94D73 68F9E7C7C48B80 3 3 1 0 +3 21 9CAEA2435EA7953F99 F075F299033F80 3 3 1 0 +3 22 AAAE08A35B73C61176 F04AFEA603E700 3 3 1 0 +3 23 53BB18C75981B648BA A6604F67F3B100 3 3 1 0 +3 24 F7DB8563039F090334 B875718DEAEB00 3 3 1 0 +3 25 23BA7F4BD58FF1124A 2538B5CADBBC00 3 3 1 0 +3 26 5E1F245277AC04FEA1 5138171D658480 3 3 1 0 +3 27 89977FB03886AF6F04 D665D4F8FD0A00 3 3 1 0 +3 28 327DC73DC80CD58971 09D94B056E1B80 3 3 1 1 +3 29 D5670DDA3FD30C8F2E 8762C68FADE200 3 3 1 1 +3 30 56BA504417D600D322 382D2F8F51C600 3 3 1 1 +3 31 117315955A8AAC623B 02F56DDFFF0180 3 3 1 1 +3 32 786AB9493DDAD47A7C 5CFA879D1BD500 3 3 1 1 +3 33 FBE46A593E94738FA9 E52C576D875A80 3 3 1 1 +3 34 6A9896A0B9D93C1BC9 7AB1964851F680 3 3 1 1 +3 35 1425E5E9F271BBE311 438923792B7B80 3 3 1 1 +3 36 55C2A5E2DD2D05600E 3AD6971389A800 3 3 1 1 +3 37 639C654AAD2366F36C 33CE8FFCC8A600 3 3 1 1 +3 38 891526AE8F124B24F8 43CCECB4E0C900 3 3 1 1 +3 39 135884718E649C5384 08CC1309C61600 3 3 1 1 +3 40 BD16636475A37DB5E3 C0ABCED7C9BE80 3 3 1 1 +3 41 F54365687DC3F86280 816183D9A9B000 0 0 0 1 +3 42 91A0BAB4D5CD2D9B91 AEB1C64995AF80 0 0 0 1 +3 43 601558C922BEB44DCF 073B4EC2725280 0 0 0 0 +3 44 0A9FEBF68995C47651 7EE073186CE580 0 0 0 0 +3 45 E2283EE9F0B99CBCFF 97B60016137580 0 0 0 0 +3 46 DC0A8B83EAAE07ABC9 DEFA90B90A0A80 0 0 0 0 +3 47 3DD0146CA45DEA8B50 61993569D06300 0 0 0 0 +3 48 A54C8E78A7A521F177 9DA7E85684AF80 0 0 0 0 +3 49 52F0E8883768F8614A 2F173353419200 0 0 0 0 +3 50 E47420E7CFCF9F3022 82F359B642BC00 0 0 0 0 +3 51 3DFCC873C93ECAEC05 7CD6FCB1C6C080 0 0 0 0 +3 52 D17485013EDA6A30BA 88759CF7CB4500 0 0 0 0 +3 53 D3E9B6C50917B68A74 BA4F5CEDB2F100 0 0 0 0 +3 54 07EA5D85D6AE8C9EB3 36B7FA8E9B0580 0 0 0 0 +3 55 45651C862BF7E175AF 066EA2D6B0EE80 0 0 0 0 +3 56 8796F001BE051B8BF2 A8C17F2ED33B00 0 0 0 0 +3 57 4C7F6C3558C2F9EB92 5466EDDA671B00 0 0 0 0 +3 58 B8617A6FF94CA5FE54 C5D40A59338D00 0 0 0 0 +3 59 AB6CFAB0EA7DE7F58D DEDD1170946E80 0 0 0 0 +3 60 04C2C6725BA69CDE10 286A8E88059500 0 0 0 0 +3 61 EB9E227ECB741BC784 F1C02428C4DA00 0 0 0 0 +3 62 BC34AFD606CA36EB74 CE37D8FD4C1300 0 0 0 0 +3 63 CC908D8E37E46EFADF EF2A787A498580 0 0 0 0 +3 64 E5EF0A6E206B45A5F6 B511F796A02B00 0 0 0 0 +3 65 3DDB008A00FAC1F4C5 73307791E04C80 0 0 0 0 +3 66 07A17A1BAFBE3B9F30 25FA6BECB6DF00 0 0 0 0 +3 67 456BDBA37060DEDC36 1E029226BB1500 0 0 0 0 +3 68 17657E52D52650434B 048D228BB59280 0 0 0 0 +3 69 B9FE072EF7A13C2A23 F1A6C55FC9B080 0 0 0 0 +3 70 BCDB0824D0A9159C53 F4BDA703613D80 0 0 0 0 +3 71 D51AC0013BB6E2CB82 986503EBC3C200 0 0 0 0 +3 72 98CA50A461DF2A1BE5 F23A2CED10E680 0 0 0 0 +3 73 B5A43E338C02916ABE A4CD269F961900 0 0 0 0 +3 74 BF6023FB3B29D92AB0 C35FA31D8FB900 0 0 0 0 +3 75 54BFFA551BB06B5D07 3C6D096377CE80 0 0 0 0 +3 76 9EDAD18AF0F1222271 FBA0637D596180 0 0 0 0 +3 77 8205BCF130C68F19FD 8E2C65A4370F80 0 0 0 0 +3 78 C165F4567675BAC9D0 880B3060B57300 0 0 0 0 +3 79 C3C7AA0F40E98AD8DF AD35EA22A22580 0 0 0 0 +3 80 55CBBCC5225FC774B7 3E1A89B7B26D80 0 0 0 0 +4 1 72C00DA20683082DB9 26335795082380 1 3 0 0 +4 2 C9D70F4FF8C22CF26B EDE05FDEEB0480 1 3 0 0 +4 3 7A7D6F815507C86C3A 460A4D976BA100 1 3 0 0 +4 4 009C224898B65F39E8 31ED95B4415E00 1 3 0 0 +4 5 A6BDB653C48E6AD931 38B1FCE4760780 1 3 0 0 +4 6 75BA9BB842DE37F1DA 3F3B22F3DC5F00 1 3 0 0 +4 7 A4ADDDFCF4DE31BC3C BFB105D43D5D00 1 3 0 0 +4 8 6E8F0808AEB3A9A258 75ED11D8206900 1 3 0 0 +4 9 55E7F6644207E6E26C 2A01E1FDB02000 1 3 0 0 +4 10 4D2405512CC009D0AD 416E7A048E0C80 1 3 0 0 +4 11 541199AE072238943F 0B0995C7789580 1 3 0 0 +4 12 F63128B2C127165229 86C0F4AD64B480 1 3 0 0 +4 13 156244695A7F25ED03 015F92D3836A80 1 3 0 0 +4 14 0166AF17F8190F802F 1CD639268F6880 1 3 0 0 +4 15 D4C72606C63A0412EE A292C78F204400 1 3 0 0 +4 16 CC8760B99B05AF8E06 E3D2456A27A800 1 3 0 0 +4 17 776AA9405398B1B88F 143DC75389DC80 1 3 0 0 +4 18 628F310D4C43034A07 314ABBAA3A2880 1 3 0 0 +4 19 649E76B7B05430DBE8 3282A64C575600 1 3 0 0 +4 20 D23E4A6273F59FAA25 942A183D41F880 1 3 0 0 +4 21 7E308547F2B69D836F 68A5E28F4B5A80 1 3 0 0 +4 22 85286DB5F241C81E73 9680CE0E8F2580 1 3 0 0 +4 23 AC8C41E42EB70E88DE F26AEBA2086100 1 3 0 0 +4 24 0ACE9D662CE293BF56 7C6ED4BA181F00 1 3 0 0 +4 25 ED675AB9112A3979FF E712BED6B79F80 1 3 0 0 +4 26 B7D4EECF2588056103 AF157F13C28A80 1 3 0 0 +4 27 25AB785CE68403B08F 35AFBE32B40C80 1 3 0 0 +4 28 CED26C6FBE89EAE172 E4F0CA76432300 1 3 0 0 +4 29 5B7046EEC829D00241 43DAA009C03080 1 3 0 0 +4 30 3F573ABC06DBFF8CAC 473DD3E5F47800 1 3 0 0 +4 31 7FBDE53EC42DB01A5A 7996BC4BEC3500 1 3 0 0 +4 32 39BBC5CBAB99CDF174 7BF3C615EAEF00 1 3 0 0 +4 33 8B6F6B77974BCD6B19 D4968D98AFAB80 1 3 0 0 +4 34 C08CEA77A6B7D40CE4 ACA47884067000 1 3 0 0 +4 35 24ACD278397323D0DF 3945B2E215ED80 1 3 0 0 +4 36 8C4309D74E7BA0824B C676D6CA2E6080 1 3 0 0 +4 37 7696DA7DA2C24BC1A6 2DAB91A7560A00 1 3 0 0 +4 38 F80F7968ECA686EFF2 D7E4CBBF380300 1 3 0 0 +4 39 64587081F7DE891A3E 12B9F28E53CD00 1 3 0 0 +4 40 9B36492977B6EE6CC3 C52473F3CBC080 1 3 0 0 +4 41 A7D8CC33275C434ADA B416532AC6C900 1 3 0 0 +4 42 DAE06744A0B7DF09A6 60A49EA7087A00 1 3 0 0 +4 43 ABD05B10A3D0A6F697 E6A1FA7ADCC580 1 3 0 0 +4 44 00F4A73884A3F1BC37 29A721D64C3D80 1 3 0 0 +4 45 9E60F1185DEEC32D2D C965C9B51D8A80 1 3 0 0 +4 46 1D9651E1DB050F1B5C 66C6F529DBAF00 1 3 0 0 +4 47 AD24551B7EA3060046 C129E4A29F2000 1 3 0 0 +4 48 DB150B0823ED0C5808 C5335001E8A400 1 3 0 0 +4 49 8C1B499215818CC980 D62881006DA200 1 3 0 0 +4 50 64930C6AD79ED3A635 35BD0BBC61D980 1 3 0 0 +4 51 58261A44D64B6DC64B 448E9CCB112880 1 3 0 0 +4 52 29434C222BA4C06481 4466E710A08080 1 3 0 0 +4 53 C979B348FBC3249C0D D9EC10C0F9A480 1 3 0 0 +4 54 2A890EC9208989DE43 7736860A222C80 1 3 0 0 +4 55 A010A28877F31F5B12 CB23B9AA41FF00 1 3 0 0 +4 56 9811B1330D687E11C4 E85104617E9600 1 3 0 0 +4 57 1615B1582FA867FC06 09678E737C8C00 1 3 0 0 +4 58 004ACAEF3C673C8DDF 1F4BFEC2033380 1 3 0 0 +4 59 AAC5EC925724BAD7AF EF09706E259680 1 3 0 0 +4 60 2D7182CB32A898514A 4BBAAE02E31600 1 3 0 0 +4 61 BB9191268E2A2F24B7 E855A2F7F80980 1 3 0 0 +4 62 6F40409F446BD1D70E 4317468A863E00 1 3 0 0 +4 63 1CF7DDC45450465CDE 6E019623794500 1 3 0 0 +4 64 FC88B7748A31F32D4F D8C550731C7A80 1 3 0 0 +4 65 E505CAE88E1FB11711 8FDF74C8A07F80 1 3 0 0 +4 66 9FD4039B4740116480 E30BAF11CE9800 1 3 0 0 +4 67 FE83824963CDFC382C E9146D5522B400 1 3 0 0 +4 68 13318E947A9B284D14 0C727CC1E56300 1 3 0 0 +4 69 2FBE274B47E9AA286D 71364374CAA080 1 3 0 0 +4 70 4A8148EA483B978204 677E5EA8207800 1 3 0 0 +4 71 C9805B31CAD8739B95 E0F649689E5F80 1 3 0 0 +4 72 EFFE38204B544C3FD3 F443511AD0C780 1 3 0 0 +4 73 985554584028388E06 C315134B741000 1 3 0 0 +4 74 8C9E6E82AD87BA97F4 F6CA74EC40B700 1 3 0 0 +4 75 55274E8CE1024D5B88 07820289A08E00 1 3 0 0 +4 76 63BE405312A6624AA8 302184ECC70000 1 3 0 0 +4 77 5E53E77FC01E669880 499166E16E4400 1 3 0 0 +4 78 E1FA806F7F7E582539 B95BD794C3D380 1 3 0 0 +4 79 13C45ABEB1895BF4A6 273ED43795BC00 1 3 0 0 +4 80 C2DF1004B52BDB85CA 909ABDA271BA00 1 3 0 0 diff --git a/xombe/vectors/perceptual/es1_nsdtx_off.amb b/xombe/vectors/perceptual/es1_nsdtx_off.amb new file mode 100644 index 0000000..adb267d Binary files /dev/null and b/xombe/vectors/perceptual/es1_nsdtx_off.amb differ diff --git a/xombe/vectors/perceptual/es1_nsdtx_off_ref.raw b/xombe/vectors/perceptual/es1_nsdtx_off_ref.raw new file mode 100644 index 0000000..98766c8 Binary files /dev/null and b/xombe/vectors/perceptual/es1_nsdtx_off_ref.raw differ diff --git a/xombe/vectors/perceptual/es1_nsdtx_on.amb b/xombe/vectors/perceptual/es1_nsdtx_on.amb new file mode 100644 index 0000000..53516da Binary files /dev/null and b/xombe/vectors/perceptual/es1_nsdtx_on.amb differ diff --git a/xombe/vectors/perceptual/es1_nsdtx_on_ref.raw b/xombe/vectors/perceptual/es1_nsdtx_on_ref.raw new file mode 100644 index 0000000..bedf4a5 Binary files /dev/null and b/xombe/vectors/perceptual/es1_nsdtx_on_ref.raw differ diff --git a/xombe/vectors/perceptual/es2.amb b/xombe/vectors/perceptual/es2.amb new file mode 100644 index 0000000..c3b76b0 Binary files /dev/null and b/xombe/vectors/perceptual/es2.amb differ diff --git a/xombe/vectors/perceptual/es2_orig.raw b/xombe/vectors/perceptual/es2_orig.raw new file mode 100644 index 0000000..afb5aeb Binary files /dev/null and b/xombe/vectors/perceptual/es2_orig.raw differ diff --git a/xombe/vectors/perceptual/es2_ref.raw b/xombe/vectors/perceptual/es2_ref.raw new file mode 100644 index 0000000..5e4d707 Binary files /dev/null and b/xombe/vectors/perceptual/es2_ref.raw differ diff --git a/xombe/vectors/perceptual/es3.amb b/xombe/vectors/perceptual/es3.amb new file mode 100644 index 0000000..017a8ee Binary files /dev/null and b/xombe/vectors/perceptual/es3.amb differ diff --git a/xombe/vectors/perceptual/es3_orig.raw b/xombe/vectors/perceptual/es3_orig.raw new file mode 100644 index 0000000..c13f319 Binary files /dev/null and b/xombe/vectors/perceptual/es3_orig.raw differ diff --git a/xombe/vectors/perceptual/es3_ref.raw b/xombe/vectors/perceptual/es3_ref.raw new file mode 100644 index 0000000..998c0eb Binary files /dev/null and b/xombe/vectors/perceptual/es3_ref.raw differ diff --git a/xombe/vectors/perceptual/es4.amb b/xombe/vectors/perceptual/es4.amb new file mode 100644 index 0000000..25fcbe5 Binary files /dev/null and b/xombe/vectors/perceptual/es4.amb differ diff --git a/xombe/vectors/perceptual/es4_orig.raw b/xombe/vectors/perceptual/es4_orig.raw new file mode 100644 index 0000000..0bcd634 Binary files /dev/null and b/xombe/vectors/perceptual/es4_orig.raw differ diff --git a/xombe/vectors/perceptual/es4_ref.raw b/xombe/vectors/perceptual/es4_ref.raw new file mode 100644 index 0000000..15513da Binary files /dev/null and b/xombe/vectors/perceptual/es4_ref.raw differ diff --git a/xombe/vectors/stream/mixed_stream_0.jsonl.gz b/xombe/vectors/stream/mixed_stream_0.jsonl.gz new file mode 100644 index 0000000..fbdae46 Binary files /dev/null and b/xombe/vectors/stream/mixed_stream_0.jsonl.gz differ diff --git a/xombe/vectors/stream/mixed_stream_1.jsonl.gz b/xombe/vectors/stream/mixed_stream_1.jsonl.gz new file mode 100644 index 0000000..0b5b81c Binary files /dev/null and b/xombe/vectors/stream/mixed_stream_1.jsonl.gz differ diff --git a/xombe/vectors/stream/mixed_stream_2.jsonl.gz b/xombe/vectors/stream/mixed_stream_2.jsonl.gz new file mode 100644 index 0000000..52dd7ce Binary files /dev/null and b/xombe/vectors/stream/mixed_stream_2.jsonl.gz differ diff --git a/xombe/vectors/stream/mixed_stream_3.jsonl.gz b/xombe/vectors/stream/mixed_stream_3.jsonl.gz new file mode 100644 index 0000000..ef538fc Binary files /dev/null and b/xombe/vectors/stream/mixed_stream_3.jsonl.gz differ diff --git a/xombe/vectors/tones/tone_table.tsv b/xombe/vectors/tones/tone_table.tsv new file mode 100644 index 0000000..dd6f2a2 --- /dev/null +++ b/xombe/vectors/tones/tone_table.tsv @@ -0,0 +1,138 @@ +# idx class frame49(encoder, 0 dB, AD per encoder) f1_meas f2_meas peak_dBFS_each +5 single 1111111111010000010100000101000001010000010110000 156.2 -2.4 +6 single 1111111111010000011000000110000001100000011010000 187.5 -2.4 +7 single 1111111111010000011100000111000001110000011110000 218.7 -2.4 +8 single 1111111111010000100000001000000010000000100010000 250.0 -2.4 +9 single 1111111111010000100100001001000010010000100110000 281.2 -2.4 +10 single 1111111111010000101000001010000010100000101010000 312.5 -2.4 +11 single 1111111111010000101100001011000010110000101110000 343.8 -2.4 +12 single 1111111111010000110000001100000011000000110010000 375.0 -2.4 +13 single 1111111111010000110100001101000011010000110110000 406.3 -2.4 +14 single 1111111111010000111000001110000011100000111010000 437.5 -2.4 +15 single 1111111111010000111100001111000011110000111110000 468.8 -2.4 +16 single 1111111111010001000000010000000100000001000010000 500.0 -2.4 +17 single 1111111111010001000100010001000100010001000110000 531.3 -2.4 +18 single 1111111111010001001000010010000100100001001010000 562.5 -2.4 +19 single 1111111111010001001100010011000100110001001110000 593.8 -2.4 +20 single 1111111111010001010000010100000101000001010010000 625.0 -2.4 +21 single 1111111111010001010100010101000101010001010110000 656.3 -2.4 +22 single 1111111111010001011000010110000101100001011010000 687.5 -2.4 +23 single 1111111111010001011100010111000101110001011110000 718.8 -2.4 +24 single 1111111111010001100000011000000110000001100010000 750.0 -2.4 +25 single 1111111111010001100100011001000110010001100110000 781.3 -2.4 +26 single 1111111111010001101000011010000110100001101010000 812.5 -2.4 +27 single 1111111111010001101100011011000110110001101110000 843.8 -2.4 +28 single 1111111111010001110000011100000111000001110010000 875.0 -2.4 +29 single 1111111111010001110100011101000111010001110110000 906.2 -2.4 +30 single 1111111111010001111000011110000111100001111010000 937.5 -2.4 +31 single 1111111111010001111100011111000111110001111110000 968.7 -2.4 +32 single 1111111111010010000000100000001000000010000010000 1000.0 -2.4 +33 single 1111111111010010000100100001001000010010000110000 1031.3 -2.4 +34 single 1111111111010010001000100010001000100010001010000 1062.5 -2.4 +35 single 1111111111010010001100100011001000110010001110000 1093.7 -2.4 +36 single 1111111111010010010000100100001001000010010010000 1125.0 -2.4 +37 single 1111111111010010010100100101001001010010010110000 1156.2 -2.4 +38 single 1111111111010010011000100110001001100010011010000 1187.5 -2.4 +39 single 1111111111010010011100100111001001110010011110000 1218.7 -2.4 +40 single 1111111111010010100000101000001010000010100010000 1250.0 -2.4 +41 single 1111111111010010100100101001001010010010100110000 1281.3 -2.4 +42 single 1111111111010010101000101010001010100010101010000 1312.5 -2.4 +43 single 1111111111010010101100101011001010110010101110000 1343.8 -2.4 +44 single 1111111111010010110000101100001011000010110010000 1375.0 -2.4 +45 single 1111111111010010110100101101001011010010110110000 1406.2 -2.4 +46 single 1111111111010010111000101110001011100010111010000 1437.5 -2.4 +47 single 1111111111010010111100101111001011110010111110000 1468.7 -2.4 +48 single 1111111111010011000000110000001100000011000010000 1500.0 -2.4 +49 single 1111111111010011000100110001001100010011000110000 1531.2 -2.4 +50 single 1111111111010011001000110010001100100011001010000 1562.5 -2.4 +51 single 1111111111010011001100110011001100110011001110000 1593.8 -2.4 +52 single 1111111111010011010000110100001101000011010010000 1625.0 -2.4 +53 single 1111111111010011010100110101001101010011010110000 1656.2 -2.4 +54 single 1111111111010011011000110110001101100011011010000 1687.5 -2.4 +55 single 1111111111010011011100110111001101110011011110000 1718.8 -2.4 +56 single 1111111111010011100000111000001110000011100010000 1750.0 -2.4 +57 single 1111111111010011100100111001001110010011100110000 1781.2 -2.4 +58 single 1111111111010011101000111010001110100011101010000 1812.4 -2.4 +59 single 1111111111010011101100111011001110110011101110000 1843.7 -2.4 +60 single 1111111111010011110000111100001111000011110010000 1875.0 -2.4 +61 single 1111111111010011110100111101001111010011110110000 1906.2 -2.4 +62 single 1111111111010011111000111110001111100011111010000 1937.5 -2.4 +63 single 1111111111010011111100111111001111110011111110000 1968.7 -2.4 +64 single 1111111111010100000001000000010000000100000010000 2000.0 -2.4 +65 single 1111111111010100000101000001010000010100000110000 2031.2 -2.4 +66 single 1111111111010100001001000010010000100100001010000 2062.5 -2.4 +67 single 1111111111010100001101000011010000110100001110000 2093.7 -2.4 +68 single 1111111111010100010001000100010001000100010010000 2124.9 -2.4 +69 single 1111111111010100010101000101010001010100010110000 2156.3 -2.4 +70 single 1111111111010100011001000110010001100100011010000 2187.5 -2.4 +71 single 1111111111010100011101000111010001110100011110000 2218.7 -2.4 +72 single 1111111111010100100001001000010010000100100010000 2250.0 -2.4 +73 single 1111111111010100100101001001010010010100100110000 2281.2 -2.4 +74 single 1111111111010100101001001010010010100100101010000 2312.4 -2.4 +75 single 1111111111010100101101001011010010110100101110000 2343.8 -2.4 +76 single 1111111111010100110001001100010011000100110010000 2375.0 -2.4 +77 single 1111111111010100110101001101010011010100110110000 2406.3 -2.4 +78 single 1111111111010100111001001110010011100100111010000 2437.4 -2.4 +79 single 1111111111010100111101001111010011110100111110000 2468.7 -2.4 +80 single 1111111111010101000001010000010100000101000010000 2499.9 -2.4 +81 single 1111111111010101000101010001010100010101000110000 2531.2 -2.4 +82 single 1111111111010101001001010010010100100101001010000 2562.4 -2.4 +83 single 1111111111010101001101010011010100110101001110000 2593.7 -2.4 +84 single 1111111111010101010001010100010101000101010010000 2625.0 -2.4 +85 single 1111111111010101010101010101010101010101010110000 2656.2 -2.4 +86 single 1111111111010101011001010110010101100101011010000 2687.5 -2.4 +87 single 1111111111010101011101010111010101110101011110000 2718.7 -2.4 +88 single 1111111111010101100001011000010110000101100010000 2750.0 -2.4 +89 single 1111111111010101100101011001010110010101100110000 2781.2 -2.4 +90 single 1111111111010101101001011010010110100101101010000 2812.5 -2.4 +91 single 1111111111010101101101011011010110110101101110000 2843.8 -2.4 +92 single 1111111111010101110001011100010111000101110010000 2875.0 -2.4 +93 single 1111111111010101110101011101010111010101110110000 2906.2 -2.4 +94 single 1111111111010101111001011110010111100101111010000 2937.5 -2.4 +95 single 1111111111010101111101011111010111110101111110000 2968.8 -2.4 +96 single 1111111111010110000001100000011000000110000010000 3000.0 -2.4 +97 single 1111111111010110000101100001011000010110000110000 3031.3 -2.4 +98 single 1111111111010110001001100010011000100110001010000 3062.5 -2.4 +99 single 1111111111010110001101100011011000110110001110000 3093.8 -2.4 +100 single 1111111111010110010001100100011001000110010010000 3125.0 -2.4 +101 single 1111111111010110010101100101011001010110010110000 3156.3 -2.4 +102 single 1111111111010110011001100110011001100110011010000 3187.5 -2.4 +103 single 1111111111010110011101100111011001110110011110000 3218.7 -2.4 +104 single 1111111111010110100001101000011010000110100010000 3249.9 -2.4 +105 single 1111111111010110100101101001011010010110100110000 3281.2 -2.4 +106 single 1111111111010110101001101010011010100110101010000 3312.4 -2.4 +107 single 1111111111010110101101101011011010110110101110000 3343.7 -2.4 +108 single 1111111111010110110001101100011011000110110010000 3375.0 -2.4 +109 single 1111111111010110110101101101011011010110110110000 3406.2 -2.4 +110 single 1111111111010110111001101110011011100110111010000 3437.5 -2.4 +111 single 1111111111010110111101101111011011110110111110000 3468.7 -2.4 +112 single 1111111111010111000001110000011100000111000010000 3500.0 -2.4 +113 single 1111111111010111000101110001011100010111000110000 3531.1 -2.4 +114 single 1111111111010111001001110010011100100111001010000 3562.4 -2.4 +115 single 1111111111010111001101110011011100110111001110000 3593.6 -2.4 +116 single 1111111111010111010001110100011101000111010010000 3624.9 -2.4 +117 single 1111111111010111010101110101011101010111010110000 3656.2 -2.4 +118 single 1111111111010111011001110110011101100111011010000 3687.4 -2.4 +119 single 1111111111010111011101110111011101110111011110000 3718.7 -2.4 +120 single 1111111111010111100001111000011110000111100010000 3750.0 -2.4 +121 single 1111111111010111100101111001011110010111100110000 3781.1 -2.4 +122 single 1111111111010111101001111010011110100111101010000 3812.4 -2.4 +128 DTMF 1111111110011000000010000000100000001000000000000 942.1 1334.6 -8.8 +129 DTMF 1111111110011000000110000001100000011000000100000 693.9 1214.3 -8.8 +130 DTMF 1111111110011000001010000010100000101000001000000 700.1 1330.1 -8.8 +131 DTMF 1111111110011000001110000011100000111000001100000 696.0 1479.1 -8.8 +132 DTMF 1111111110011000010010000100100001001000010000000 769.7 1209.5 -8.8 +133 DTMF 1111111110011000010110000101100001011000010100000 766.7 1341.8 -8.8 +134 DTMF 1111111110011000011010000110100001101000011000000 771.9 1473.7 -8.8 +135 DTMF 1111111110011000011110000111100001111000011100000 852.7 1208.0 -8.8 +136 DTMF 1111111110011000100010001000100010001000100000000 851.1 1337.4 -8.8 +137 DTMF 1111111110011000100110001001100010011000100100000 848.0 1484.0 -8.8 +138 DTMF 1111111110011000101010001010100010101000101000000 698.5 1629.7 -8.8 +139 DTMF 1111111110011000101110001011100010111000101100000 769.2 1634.5 -8.8 +140 DTMF 1111111110011000110010001100100011001000110000000 852.0 1633.0 -8.8 +141 DTMF 1111111110011000110110001101100011011000110100000 937.0 1639.8 -8.8 +142 DTMF 1111111110011000111010001110100011101000111000000 940.7 1209.5 -8.8 +143 DTMF 1111111110011000111110001111100011111000111100000 940.5 1477.9 -8.8 +160 callprog 1111111110011010000010100000101000001010000000000 351.1 438.9 -8.8 +161 callprog 1111111110011010000110100001101000011010000100000 425.0 495.8 -8.8 +162 callprog 1111111110011010001010100010101000101010001000000 488.0 610.0 -8.8 diff --git a/xombe/xombe.pc.in b/xombe/xombe.pc.in new file mode 100644 index 0000000..56499c6 --- /dev/null +++ b/xombe/xombe.pc.in @@ -0,0 +1,10 @@ +prefix=@XOMBE_PC_PREFIX@ +libdir=@XOMBE_PC_LIBDIR@ +includedir=@XOMBE_PC_INCLUDEDIR@ + +Name: xombe +Description: DMR (AMBE+2 half rate) and D-STAR (AMBE 2400) vocoder, channel FEC, and transcoders +Version: @PROJECT_VERSION@ +Libs: -L${libdir} -lxombe@XOMBE_PC_LIBS@ +Libs.private: @XOMBE_PC_LIBS_PRIVATE@ +Cflags: -I${includedir}@XOMBE_PC_CFLAGS@