Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6edcabf777 | ||
|
|
787984afe5 | ||
|
|
836d68c354 | ||
|
|
abce8465f8 | ||
|
|
3f0d5e87fe | ||
|
|
0bb82e4115 | ||
|
|
a2760286b0 | ||
|
|
58e3403642 | ||
|
|
20f2e77664 | ||
|
|
29f4f83c29 | ||
|
|
fd842db26f | ||
|
|
34a722f56a | ||
|
|
6674cb5386 | ||
|
|
188a066642 | ||
|
|
8e688d496e | ||
|
|
075ef60afa | ||
|
|
1227fd6bbb | ||
|
|
2a79db4868 | ||
|
|
c8d2b09357 | ||
|
|
7cd5c660e4 | ||
|
|
55f14667d2 | ||
|
|
89d45e14d3 | ||
|
|
d2d6ac0e6f | ||
|
|
7b83358eb5 | ||
|
|
7eb2fa3b61 |
No files matched your search
+44
-22
@@ -1,9 +1,9 @@
|
||||
|
||||
name: ci
|
||||
|
||||
# Builds and tests every push and pull request, packages the CLI as a workflow
|
||||
# artifact, and -- when a tag is pushed -- turns those packages into a GitHub
|
||||
# release. One file keeps the release job inside the same run as the build, so it
|
||||
# collects that run's artifacts instead of rebuilding them.
|
||||
# Build and test on every push and pull request.
|
||||
# Upload unpacked files as Actions artifacts.
|
||||
# Create ZIP archives only when publishing a release.
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -25,6 +25,7 @@ jobs:
|
||||
label: macos
|
||||
- os: windows-latest
|
||||
label: windows
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -47,49 +48,70 @@ jobs:
|
||||
- name: Test
|
||||
run: ctest --test-dir build --output-on-failure -C Release
|
||||
|
||||
# The CLI and its runtime assets sit at the archive root with the libraries
|
||||
# in lib/ below, so the download can be unpacked and run as it is.
|
||||
- name: Stage
|
||||
run: cmake --install build --config Release --prefix stage
|
||||
|
||||
# Place executables at the package root and libraries in lib/.
|
||||
- name: Package
|
||||
shell: bash
|
||||
run: |
|
||||
folder="joc_cli_${{ matrix.label }}"
|
||||
mkdir -p "package/$folder/lib"
|
||||
cp -r stage/bin/. "package/$folder/"
|
||||
cp -r stage/lib/. "package/$folder/lib/"
|
||||
|
||||
- name: Archive
|
||||
run: cmake -E tar cf "joc_cli_${{ matrix.label }}.zip" --format=zip "package/joc_cli_${{ matrix.label }}"
|
||||
mkdir -p package/lib
|
||||
cp -r stage/bin/. package/
|
||||
cp -r stage/lib/. package/lib/
|
||||
|
||||
# GitHub automatically creates the artifact ZIP.
|
||||
# Upload files directly to avoid nested ZIP archives.
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: joc_cli_${{ matrix.label }}
|
||||
path: joc_cli_${{ matrix.label }}.zip
|
||||
path: package/
|
||||
if-no-files-found: error
|
||||
|
||||
release:
|
||||
# A pushed tag is what makes a release; branch and PR builds only leave
|
||||
# artifacts. The archives come from the build job of this same run.
|
||||
# Only tagged builds create releases.
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Collect the packaged archives
|
||||
# Keep each platform's files in a separate directory.
|
||||
- name: Collect build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: joc_cli_*
|
||||
path: dist
|
||||
merge-multiple: true
|
||||
merge-multiple: false
|
||||
|
||||
- name: List what will be published
|
||||
run: ls -l dist
|
||||
# Create flat ZIP archives from the artifact contents.
|
||||
# Restore executable permissions on Unix platforms.
|
||||
- name: Create release archives
|
||||
shell: bash
|
||||
run: |
|
||||
for platform in linux macos windows; do
|
||||
dir="dist/joc_cli_${platform}"
|
||||
|
||||
# The archives are attached to the tag's release, whether it already exists
|
||||
# (created in the web interface) or has to be created here.
|
||||
if [ ! -d "$dir" ]; then
|
||||
echo "Missing artifact: joc_cli_${platform}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$platform" != "windows" ]; then
|
||||
chmod +x "$dir/joc_cli"
|
||||
fi
|
||||
|
||||
(
|
||||
cd "$dir"
|
||||
cmake -E tar cf "../joc_cli_${platform}.zip" --format=zip -- *
|
||||
)
|
||||
done
|
||||
|
||||
- name: List release archives
|
||||
run: ls -lh dist/*.zip
|
||||
|
||||
# Publish the archives directly to GitHub Releases.
|
||||
- name: Publish
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
+48
-21
@@ -81,19 +81,24 @@ if(MSVC AND CMAKE_GENERATOR MATCHES "Ninja" AND NOT CMAKE_CL_SHOWINCLUDES_PREFIX
|
||||
"messages in the language CMake probes for.")
|
||||
endif()
|
||||
|
||||
# Verbatim copies of the upstream native library; see THIRD_PARTY_NOTICES.md.
|
||||
# These files are never edited: they are the validated DSP kernels.
|
||||
# Sources copied verbatim from the upstream native library; see
|
||||
# THIRD_PARTY_NOTICES.md. binaural_renderer.cpp is still an unmodified copy and
|
||||
# is never edited; the unchanged reused headers include/eac3joc_core.h and
|
||||
# src/joc_bitstream/joc_huffman_tables.h belong to the same set. The JOC core,
|
||||
# the speaker renderer and the remaining tables started as copies and are
|
||||
# maintained in-tree now, so they are listed as internal sources below.
|
||||
set(JOC_REUSED_SOURCES
|
||||
src/joc_core/eac3joc_core.cpp
|
||||
src/speaker/speaker_renderer.cpp
|
||||
src/binaural/binaural_renderer.cpp
|
||||
)
|
||||
|
||||
set(JOC_INTERNAL_SOURCES
|
||||
src/adm/adm_metadata.cpp
|
||||
src/adm/adm_tracks.cpp
|
||||
src/binaural/binaural_runtime.cpp
|
||||
src/binaural/sofa_binaural_renderer.cpp
|
||||
src/binaural/jochrtf_runtime.cpp
|
||||
src/binaural/jochrtf_renderer.cpp
|
||||
src/binaural/multichannel_layout.cpp
|
||||
src/binaural/pcm_resampler.cpp
|
||||
src/virtual_speaker/virtual_speaker.cpp
|
||||
src/eac3_transport/eac3_reader.cpp
|
||||
src/emdf/emdf_parser.cpp
|
||||
src/foundation/bit_reader.cpp
|
||||
@@ -104,25 +109,31 @@ set(JOC_INTERNAL_SOURCES
|
||||
src/foundation/status.cpp
|
||||
src/hrtf/jochrtf.cpp
|
||||
src/hrtf/public_filterbank.cpp
|
||||
src/hrtf/rosella_bank.cpp
|
||||
src/hrtf/rosella_filterbank.cpp
|
||||
src/hrtf/rosella_model.cpp
|
||||
src/hrtf/rosella_renderer.cpp
|
||||
src/hrtf/kernel_tables.cpp
|
||||
src/hrtf/sofa.cpp
|
||||
src/hrtf/sofa_cache.cpp
|
||||
src/hrtf/sofa_field.cpp
|
||||
src/io/adm_writer.cpp
|
||||
src/io/hdf5.cpp
|
||||
src/io/inflate.cpp
|
||||
src/io/npy.cpp
|
||||
src/io/npy_writer.cpp
|
||||
src/io/wav_pcm.cpp
|
||||
src/io/process.cpp
|
||||
src/io/wav_writer.cpp
|
||||
src/io/zip_reader.cpp
|
||||
src/joc_bitstream/bed_layout_map.cpp
|
||||
src/joc_bitstream/joc_parser.cpp
|
||||
src/joc_core/eac3joc_core.cpp
|
||||
src/joc_core/objects16.cpp
|
||||
src/oamd/oamd_math.cpp
|
||||
src/oamd/oamd_params.cpp
|
||||
src/oamd/oamd_parser.cpp
|
||||
src/speaker/speaker_renderer.cpp
|
||||
src/speaker/speaker_layout_lookup.cpp
|
||||
src/speaker/speaker_step.cpp
|
||||
src/speaker/speaker_trim.cpp
|
||||
src/stream/stream.cpp
|
||||
src/task/task.cpp
|
||||
src/telemetry/event_bus.cpp
|
||||
@@ -235,6 +246,23 @@ if(JOC_BUILD_TESTS OR JOC_BUILD_DEVTOOLS)
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||
)
|
||||
target_link_libraries(joc_core_impl PUBLIC Threads::Threads)
|
||||
# The same sources back both the shared library and this static archive. In
|
||||
# the archive the C entry points are plain definitions: EJOC_STATIC stops the
|
||||
# kernel sources that carry their own EJOC_BUILD_DLL define from marking them
|
||||
# as dllexports, which would collide with the DLL import library in a link
|
||||
# that uses both libraries (the tests do).
|
||||
target_compile_definitions(joc_core_impl PUBLIC EJOC_STATIC)
|
||||
endif()
|
||||
|
||||
if(JOC_BUILD_TESTS OR JOC_BUILD_DEVTOOLS)
|
||||
add_executable(joc_multichannel src/cli/joc_multichannel.cpp)
|
||||
target_link_libraries(joc_multichannel PRIVATE joc_core_impl)
|
||||
target_include_directories(joc_multichannel PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
set_target_properties(joc_multichannel PROPERTIES
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
if(WIN32)
|
||||
target_link_libraries(joc_multichannel PRIVATE shell32)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(joc_core SHARED
|
||||
@@ -286,6 +314,14 @@ if(JOC_BUILD_TESTS)
|
||||
target_link_libraries(joc_tests PRIVATE joc_core_impl joc_core)
|
||||
target_include_directories(joc_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
add_test(NAME core COMMAND joc_tests)
|
||||
add_executable(joc_rosella_filterbank_tests tests/test_rosella_filterbank.cpp)
|
||||
target_link_libraries(joc_rosella_filterbank_tests PRIVATE joc_core_impl)
|
||||
target_include_directories(joc_rosella_filterbank_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
add_test(NAME rosella_filterbank COMMAND joc_rosella_filterbank_tests)
|
||||
add_executable(joc_oamd_metadata_tests tests/test_oamd_metadata.cpp)
|
||||
target_link_libraries(joc_oamd_metadata_tests PRIVATE joc_core_impl)
|
||||
target_include_directories(joc_oamd_metadata_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
add_test(NAME oamd_metadata COMMAND joc_oamd_metadata_tests)
|
||||
# The public headers must stay valid C and C++: these targets exist to prove it.
|
||||
add_library(joc_headers_c OBJECT tests/test_headers.c)
|
||||
target_include_directories(joc_headers_c PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
@@ -297,20 +333,10 @@ if(JOC_BUILD_DEVTOOLS)
|
||||
add_executable(joc_dump devtools/joc_dump/main.cpp)
|
||||
target_link_libraries(joc_dump PRIVATE joc_core joc_core_impl)
|
||||
target_include_directories(joc_dump PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
# SOFA reader probe: the C++ side of devtools/checks/check_sofa.py.
|
||||
add_executable(joc_sofa_field_probe devtools/sofa_field_probe/main.cpp)
|
||||
add_executable(joc_dictionary_probe devtools/sofa_field_probe/dictionary_main.cpp)
|
||||
target_link_libraries(joc_dictionary_probe PRIVATE joc_core_impl)
|
||||
target_include_directories(joc_dictionary_probe PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
target_link_libraries(joc_sofa_field_probe PRIVATE joc_core_impl)
|
||||
target_include_directories(joc_sofa_field_probe PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
# Rosella model probe: the C++ side of devtools/checks/check_rosella.py.
|
||||
add_executable(joc_rosella_probe devtools/rosella_probe/main.cpp)
|
||||
target_link_libraries(joc_rosella_probe PRIVATE joc_core_impl)
|
||||
target_include_directories(joc_rosella_probe PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
add_executable(joc_sofa_probe devtools/sofa_probe/main.cpp)
|
||||
target_link_libraries(joc_sofa_probe PRIVATE joc_core_impl)
|
||||
target_include_directories(joc_sofa_probe PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||
# Probe for the streaming surface: the acceptance harness and the usage
|
||||
# example for joc_stream.h. Not shipped: a player integrates the library.
|
||||
add_executable(joc_stream_probe devtools/joc_stream/main.cpp)
|
||||
@@ -322,10 +348,10 @@ if(JOC_BUILD_TESTS OR JOC_BUILD_DEVTOOLS)
|
||||
list(APPEND JOC_MSVC_TARGETS joc_core_impl)
|
||||
endif()
|
||||
if(JOC_BUILD_TESTS)
|
||||
list(APPEND JOC_MSVC_TARGETS joc_tests joc_headers_c joc_headers_cpp)
|
||||
list(APPEND JOC_MSVC_TARGETS joc_tests joc_rosella_filterbank_tests
|
||||
joc_oamd_metadata_tests joc_headers_c joc_headers_cpp)
|
||||
endif()
|
||||
if(JOC_BUILD_DEVTOOLS)
|
||||
list(APPEND JOC_MSVC_TARGETS joc_rosella_probe joc_dump joc_stream_probe joc_sofa_probe joc_sofa_field_probe joc_dictionary_probe)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
@@ -364,6 +390,7 @@ target_sources(joc_core PRIVATE
|
||||
include/eac3joc_core.h
|
||||
src/joc_bitstream/joc_huffman_tables.h
|
||||
src/joc_core/qmf_tables.h
|
||||
src/oamd/oamd_parser.h
|
||||
src/speaker/speaker_layouts.h
|
||||
)
|
||||
|
||||
|
||||
+150
-21
@@ -30,7 +30,7 @@ The heaviest binaural loops are **runtime-dispatched**: one binary carries sever
|
||||
ISA variants and picks the widest one at startup from CPUID/XGETBV, with the output
|
||||
byte-identical either way (see [SIMD dispatch](docs/simd.en.md)). `JOC_ENABLE_AVX2` /
|
||||
`JOC_ENABLE_AVX512` (both ON by default) only decide whether those units are linked
|
||||
in: carrying the AVX2 unit buys 12.4% on the SOFA binaural kernel and 1.8% on
|
||||
in: carrying the AVX2 unit buys 12.4% on the .jochrtf binaural kernel and 1.8% on
|
||||
Rosella, while a CPU without AVX2 still runs the baseline (SSE2) path. To produce a
|
||||
baseline-only binary:
|
||||
|
||||
@@ -77,11 +77,13 @@ joc_cli input.m4a -o out/adm.wav # explicit output
|
||||
joc_cli input.m4a --speaker-layout 5.1 # -> output/<name>.5.1.wav
|
||||
joc_cli input.m4a --speaker-layout 7.1.4 --speaker-output out/714.wav --speaker-format int24
|
||||
|
||||
# Binaural (HRTF defaults to <exe>/HRTF/binaural.sofa, then <exe>/HRTF/binaural.personalized_headphone)
|
||||
# Binaural (defaults to <exe>/HRTF/binaural.personalized_headphone)
|
||||
joc_cli input.m4a --binaural
|
||||
joc_cli input.m4a --binaural --sofa-hrtf HRTF/other.sofa # another SOFA
|
||||
joc_cli input.m4a --binaural --compiled-hrtf-cache HRTF/subject.jochrtf # offline compiled field
|
||||
joc_cli input.m4a --binaural --compiled-hrtf-cache HRTF/subject.jochrtf --jochrtf-room off
|
||||
joc_cli input.m4a --binaural --personalized-headphone # Rosella personalisation
|
||||
# -> output/<name>.binaural.wav
|
||||
joc_cli input.m4a --binaural --personalized-headphone --rosella-filterbank 2 # captured bank
|
||||
|
||||
# Other common switches
|
||||
joc_cli input.m4a --duration 30 --gain-db -3 --trajectory-mode dense64
|
||||
@@ -95,12 +97,70 @@ pass `continue`, `float32` or `abort`). `--duration` is in **seconds**, and
|
||||
`--binaural-tail-threshold` (1e-8, the binaural tail trim) keep the reference
|
||||
defaults. A run always writes `<output>.report.json` (`--report-json` overrides it).
|
||||
|
||||
**Differences from the reference:** `--sofa-hrtf`, `--personalized-headphone`,
|
||||
`--backend python` and the metadata sidecars (`--metadata-dir`, `--metadata-cache`,
|
||||
`--metadata-backend sidecar`) are unavailable in this build and fail immediately
|
||||
with an explanation instead of being ignored. This build adds `--bed` (pre-decoded
|
||||
`--rosella-filterbank 1|2` picks the filterbank of the Rosella `.personalized_headphone`
|
||||
path: `1` (default) is the public 13-tap / 6-slot bank, `2` is the captured 11-tap /
|
||||
3-slot bank. Their latencies are 961 and 448 samples, and each keeps its own
|
||||
coefficients, history and flush capacity. The option only applies to the Rosella
|
||||
model; the `.jochrtf` path rejects it. See
|
||||
[Rosella filterbank](docs/rosella_filterbank.en.md).
|
||||
|
||||
**Differences from the reference:** `--backend python` and the metadata sidecars
|
||||
(`--metadata-dir`, `--metadata-cache`, `--metadata-backend sidecar`) are unavailable
|
||||
in this build and fail immediately with an explanation instead of being ignored.
|
||||
This build adds `--bed` (pre-decoded
|
||||
6-channel float32 PCM, which skips ffmpeg decoding), `--kernels`, `--work-dir`,
|
||||
`--report-json`, `--dry-run` and `--quiet`.
|
||||
`--report-json`, `--dry-run`, `--quiet` and `--rosella-filterbank`.
|
||||
|
||||
## Speaker layouts and channel order
|
||||
|
||||
`--speaker-layout` accepts the twelve layouts below, and the PCM/WAV channel order is the order in
|
||||
the table:
|
||||
|
||||
| Layout | Channel order |
|
||||
|---|---|
|
||||
| 2.0 | L, R |
|
||||
| 3.1 | L, R, C, LFE |
|
||||
| 4.0 | L, R, Lrs, Rrs |
|
||||
| 5.1 | L, R, C, LFE, Ls, Rs |
|
||||
| 6.0 | L, R, Ls, Rs, Lrs, Rrs |
|
||||
| 7.1 | L, R, C, LFE, Ls, Rs, Lrs, Rrs |
|
||||
| 5.1.2 | L, R, C, LFE, Ls, Rs, Ltm, Rtm |
|
||||
| 5.1.4 | L, R, C, LFE, Ls, Rs, Ltf, Rtf, Ltr, Rtr |
|
||||
| 7.1.2 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Ltm, Rtm |
|
||||
| 7.1.4 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Ltf, Rtf, Ltr, Rtr |
|
||||
| 9.1.4 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Lw, Rw, Ltf, Rtf, Ltr, Rtr |
|
||||
| 9.1.6 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Lw, Rw, Ltf, Rtf, Ltm, Rtm, Ltr, Rtr |
|
||||
|
||||
`4.0` is the quad layout this project adds (the traditional `FL FR BL BR`, here `L R Lrs Rrs`); it is
|
||||
not part of the Dolby layout set. Every other layout and channel order follows the Dolby
|
||||
specifications.
|
||||
|
||||
Multichannel WAV files use `WAVE_FORMAT_EXTENSIBLE` with `dwChannelMask = 0`: the file declares no
|
||||
Windows speaker positions, and the PCM channel order is exactly the table above, never rearranged
|
||||
into mask-bit order. Players, ASIO, DAWs and other devices have to map the channel numbers
|
||||
themselves; this project guarantees the content and numbering of each PCM channel, not that a
|
||||
downstream player recognises Dolby speaker positions on its own.
|
||||
|
||||
`--speaker-layout` accepts only the twelve names in the table; anything else fails as an unknown
|
||||
layout.
|
||||
|
||||
Speaker rendering reads warp, trim and front/back balance from the OAMD metadata; the CLI has no
|
||||
warp override. Warp 0/1 render directly; warp 2/3 render to a 7.1.x intermediate layout first,
|
||||
then fold back to 5.1.x with PLIIx or Standard (Lo/Ro) coefficients, and calibration always
|
||||
follows the final target layout. Source trajectories and binaural rendering do not pre-apply
|
||||
these controls; see [mathematics §12](docs/math.en.md) for the parameters and evaluation order.
|
||||
|
||||
Speaker rendering also applies the OAMD object attributes: per-block gain/inactive,
|
||||
zone/elevation, size/snap/divergence, the priority size budget, element 5 position
|
||||
refinement, ISF basis matrices, and bed distribution. ADM export and the binaural
|
||||
paths still place point objects and do not apply these speaker target coefficients.
|
||||
|
||||
Object position updates are scheduled from the complete `frame_state`: speaker and
|
||||
binaural rendering both accept multiple position blocks and programmes with more than
|
||||
16 objects and schedule every block at its own time and ramp. The binaural audio input
|
||||
is still one LFE plus fifteen object sources; the extra position tracks are followed
|
||||
but not panned. ADM export keeps the 15-track single-block position view and rejects
|
||||
anything larger as an unsupported variant.
|
||||
|
||||
## Library integration
|
||||
|
||||
@@ -144,18 +204,49 @@ tests/ unit tests (CTest, self-contained, no external data)
|
||||
docs/ mathematics, the binaural rendering flow and SIMD dispatch
|
||||
```
|
||||
|
||||
Eight files under `src/` are byte-identical copies of the upstream JustOneCacophony
|
||||
native library and are never edited (see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)).
|
||||
The QMF and binaural tables and the JOC Huffman tables under `src/` are written from
|
||||
publicly documented standards; [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) records
|
||||
their sources.
|
||||
|
||||
The ISF compressed base coefficients and layout descriptors are obtained from
|
||||
lookup tables stored in the generated header (`src/oamd/isf_tables.h`), which is
|
||||
compiled into the binary with the code, so nothing reads a data file at run
|
||||
time. Gain, size, priority, position, divergence, delta and refinement values are
|
||||
computed in code, while the size kernel is generated from the speaker layout
|
||||
region geometry and bed routing is derived from those layouts.
|
||||
|
||||
## Mathematical implementation
|
||||
|
||||
The main documented stages are:
|
||||
|
||||
- dense JOC differential reconstruction and dequantization;
|
||||
- parameter-band mapping to 64 QMF subbands;
|
||||
- cross-frame parameter interpolation (hard cut when no previous state exists, zero-matrix publishing after an object disappears);
|
||||
- the frame-level JOC state machine (normal, hold, hard cut, core passthrough);
|
||||
- analysis/inverse QMF, surround delay, and FIR state;
|
||||
- the 1217-sample LFE delay with its sample-wise clipgain ramp;
|
||||
- OAMD Q15 coordinate conversion;
|
||||
- equal-power panning over target-layout regions;
|
||||
- OAMD metadata application (per-block gain and inactive, zone/elevation, size kernel, snap, divergence, position refinement, priority size budget, ISF matrices, bed distribution);
|
||||
- layout-dependent position compensation and sample-wise gain ramps;
|
||||
- float32 and PCM24 output quantization;
|
||||
- Rosella and compiled `.jochrtf` binaural rendering, with exactly-once delay/phase and special LFE.
|
||||
|
||||
See the [mathematical notes](docs/math.en.md) for the equations used by the decoding
|
||||
and rendering process.
|
||||
|
||||
## Compatibility note
|
||||
|
||||
### How `joc_clipgain` is applied
|
||||
|
||||
`joc_clipgain` is folded into the **analysis-side scalar**: `scalar = 1/16 x g` (`g = 1 + (y/32)·2^(x-4)`,
|
||||
from the 8-bit field `x:3 | y:5`). The x16 at the output cancels the 1/16, so the net effect is a multiply
|
||||
by `g` and the clamp therefore sits **after** the gain (`clamp(16·IQMF·g_interp)`). The scalar is kept in
|
||||
two per-frame slots: the first 256 samples of a frame ramp linearly from the previous value, the rest stays
|
||||
constant, and the first frame after a reset takes the new value directly. For `g = 1` the interpolation is the identity and `clamp(x)·1 == clamp(x·1)`.
|
||||
`joc_clipgain` is folded into the **analysis-side scalar**: `scalar = 1/16 x g`, with
|
||||
`g = 2^(x-4)·(1 + y/32)` from the 8-bit field `x:3 | y:5`; the range is 0.0625..15.75. The x16 at the
|
||||
output cancels the 1/16, so the net effect is a multiply by `g` and the clamp therefore sits **after**
|
||||
the gain (`clamp(16·IQMF·g_interp)`). The scalar is kept in two per-frame slots: the first 256 samples
|
||||
of a frame ramp linearly from the previous value, the rest stays constant, and the first frame after a
|
||||
reset takes the new value directly. For `g = 1` the interpolation is the identity and
|
||||
`clamp(x)·1 == clamp(x·1)`. LFE bypasses the analysis but applies the same full `g` as a sample-wise
|
||||
ramp before its 1217-sample delay.
|
||||
|
||||
`object_delay_samples` defaults to **1473**, preserving the behaviour of the existing
|
||||
implementation; it is a configurable field and changing it changes the OAMD/ADM time
|
||||
@@ -180,9 +271,11 @@ ffmpeg gets `-ac 6` only for the $N=5$ configurations; $N=7$ keeps the decoder's
|
||||
a non-zero $joc\_ext\_config\_idx$ is an unmapped variant, and a declared object count above 15 is
|
||||
clamped to 15 and recorded as a diagnostic - those change the DSP input, so a mismatch is refused.
|
||||
The extra pair's **identity** never reaches the DSP (section 10.1): when the dependent-substream
|
||||
`chanmap` disagrees with $k$, or an OAMD standard bed mask does, the mismatch is recorded as a
|
||||
diagnostic and the frame still renders, with the bed mapping following the channel codes the
|
||||
`chanmap` declares. When one audio frame holds several EMDF containers carrying ID11/ID14, they
|
||||
`chanmap` disagrees with $k$, the mismatch is recorded as a diagnostic and the frame still
|
||||
renders, with the bed mapping following the channel codes the `chanmap` declares. The bed
|
||||
layout the OAMD declares may hold more channels than the core substream codes (a 9.1.6 bed
|
||||
with a 5.1 core, for example): only a core channel missing from that layout counts as a
|
||||
mismatch. When one audio frame holds several EMDF containers carrying ID11/ID14, they
|
||||
are scored by the association rule of section 8.2 and its Table 56: a container whose OAMD and JOC
|
||||
payloads share a group id and whose ID14 parses completely wins, then one whose ID14 merely parses;
|
||||
only a unique best score is used and the others are recorded as a diagnostic
|
||||
@@ -190,9 +283,45 @@ only a unique best score is used and the others are recorded as a diagnostic
|
||||
$k\in\{2,4\}\to8/9$) is recorded, but bed channels are not output channels under the current
|
||||
contract.
|
||||
|
||||
An audio frame with no JOC EMDF at all (for example when the encoder wrote none for the first
|
||||
frame) emits silent object channels while the QMF analysis and synthesis state keep advancing,
|
||||
and it is counted separately in the statistics.
|
||||
### Frame status and the JOC decode state machine
|
||||
|
||||
Every frame carries a status; a non-zero status is reported as a diagnostic. A non-zero status
|
||||
makes the frame invalid for rendering, so the renderer holds the previous matrices or passes the
|
||||
core PCM through instead of decoding that frame's matrix: 2 unsupported downmix configuration,
|
||||
3 object count clamped to 15, 4 unknown parameter-band index, 5 invalid `offset_ts`, 6 trailing
|
||||
data after byte padding, and 7 an ID14 payload that ends inside `joc_data`. A file task refuses a
|
||||
`joc_dmx_config_idx` outside 0..4 earlier, in the metadata scan, as an unsupported variant.
|
||||
Status 3 still yields the clamped object list for diagnostics, status 2 and 4 stop the parse at
|
||||
the failing header field, and status 7 keeps the complete header, clipgain, sequence counter and
|
||||
object parameters, with only the object matrices missing.
|
||||
|
||||
Status 7 is classified only when the EMDF container itself is complete: a container length past
|
||||
the syncframe, or a payload too short for the 12-bit `joc_header`, stays a transport error, and
|
||||
the file task and stream API additionally require the container's ID11 payload to parse. A
|
||||
complete container whose payload ends inside `joc_data` takes the invalid-frame path (the
|
||||
previous matrices are held), so decoding continues instead of stopping; the stream statistics
|
||||
count those frames in `truncated_joc_frames`, and `joc_check_id14_padding` still reports
|
||||
`JOC_ERR_BITSTREAM_TRUNCATED` for them.
|
||||
|
||||
Rendering then runs a per-frame state machine: normal, hold, hard cut, and core passthrough. An
|
||||
unusable-JOC frame that arrives during normal rendering enters hold, where the previous frame-end
|
||||
matrices keep being published; six consecutive unusable frames move the internal hold state on but
|
||||
stay in hold, and a valid frame resynchronises the sequence number. A sequence number of 0 after
|
||||
the renderer left its initial state, a sequence mismatch, or a change of the declared core channel
|
||||
count is a hard cut: every object matrix is zeroed and each object's previous state becomes
|
||||
the zero matrix, while a core channel count change also clears the LFE delay ring but keeps
|
||||
the clipgain ramp state. Before the first valid frame the renderer passes the core PCM
|
||||
through.
|
||||
|
||||
A frame with no JOC EMDF at all (for example when the encoder wrote none for the first frame)
|
||||
always takes the passthrough path: the eight core planes L, R, C, LFE, Ls, Rs, (Lrs, Rrs) are
|
||||
written to output slots 0..7 by identity, each delayed by 1217 samples, slots 8..15 stay zero,
|
||||
and the 8-plane history keeps advancing. Those frames are counted separately in the statistics,
|
||||
and E-AC-3 input without JOC metadata (ID11 + ID14) is outside the supported scope. A frame whose
|
||||
ID14 payload ended inside `joc_data` is not one of these: it takes the hold path above and is
|
||||
counted separately in the stream statistics (`truncated_joc_frames`). While hold or
|
||||
passthrough runs without fresh parameters, the analysis scalar and the LFE ramp keep the
|
||||
currently held clipgain.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ Windows(MSVC / VS 2022,静态 CRT)、Linux 与 macOS 由 `.github/workflow
|
||||
|
||||
最重的双耳循环由**运行时派发**:同一份二进制里装多套 ISA 代码,启动时按 CPUID/XGETBV 选最宽
|
||||
的一套,输出逐字节不变(见 [SIMD 与运行时派发](docs/simd.md))。`JOC_ENABLE_AVX2` /
|
||||
`JOC_ENABLE_AVX512`(默认都 ON)只决定是否把这些单元编进二进制:带上 AVX2 单元让 SOFA 双耳
|
||||
`JOC_ENABLE_AVX512`(默认都 ON)只决定是否把这些单元编进二进制:带上 AVX2 单元让 `.jochrtf` 双耳
|
||||
内核快 12.4%、Rosella 快 1.8%,而没有 AVX2 的 CPU 仍走基线(SSE2)路径。要产出只带基线 ISA
|
||||
的二进制:
|
||||
|
||||
@@ -67,11 +67,13 @@ joc_cli input.m4a -o out/adm.wav # 指定输出
|
||||
joc_cli input.m4a --speaker-layout 5.1 # -> output/<名称>.5.1.wav
|
||||
joc_cli input.m4a --speaker-layout 7.1.4 --speaker-output out/714.wav --speaker-format int24
|
||||
|
||||
# 双耳(HRTF 默认取 <exe>/HRTF/binaural.sofa,其次 <exe>/HRTF/binaural.personalized_headphone)
|
||||
# 双耳(默认取 <exe>/HRTF/binaural.personalized_headphone)
|
||||
joc_cli input.m4a --binaural
|
||||
joc_cli input.m4a --binaural --sofa-hrtf HRTF/other.sofa # 换一个 SOFA
|
||||
joc_cli input.m4a --binaural --personalized-headphone # Rosella 个性化模型
|
||||
joc_cli input.m4a --binaural --compiled-hrtf-cache HRTF/subject.jochrtf # 离线编译的 .jochrtf
|
||||
joc_cli input.m4a --binaural --compiled-hrtf-cache HRTF/subject.jochrtf --jochrtf-room off
|
||||
# -> output/<名称>.binaural.wav
|
||||
joc_cli input.m4a --binaural --personalized-headphone --rosella-filterbank 2 # 新版 Rosella 滤波器组
|
||||
|
||||
# 其它常用开关
|
||||
joc_cli input.m4a --duration 30 --gain-db -3 --trajectory-mode dense64
|
||||
@@ -84,11 +86,57 @@ joc_cli input.eac3 --metadata-only --print-metadata summary # 只解析并打
|
||||
`--binaural-tail-threshold`(默认 1e-8,双耳尾音裁切阈值)等默认值与上游一致。命令总是写出
|
||||
`<输出>.report.json`(`--report-json` 可改路径)。
|
||||
|
||||
**与上游参数的差异**:`--sofa-hrtf`、`--personalized-headphone`、`--backend python` 以及
|
||||
metadata sidecar(`--metadata-dir`/`--metadata-cache`/`--metadata-backend sidecar`)在本构建中
|
||||
不可用,给出时立刻报错并说明原因,而不是静默忽略。本构建额外提供 `--bed`(已解码的 6 通道
|
||||
float32 PCM,给出后不调用 ffmpeg 解码)、`--kernels`(滤波器组表路径)、`--work-dir`、
|
||||
`--report-json`、`--dry-run`、`--quiet`。
|
||||
`--rosella-filterbank 1|2` 选择 Rosella 个性化模型使用的滤波器组:`1`(默认)是 13 taps /
|
||||
6 slots 的公开滤波器组,`2` 是 11 taps / 3 slots 的捕获版。两者延迟分别为 961 / 448 samples,
|
||||
系数、历史缓冲与 flush 容量各自独立;该选项只作用于 `.personalized_headphone`,
|
||||
`.jochrtf` 路径给出时直接报错。详见 [Rosella 滤波器组](docs/rosella_filterbank.en.md)。
|
||||
|
||||
**与上游参数的差异**:`--backend python` 与 metadata sidecar(`--metadata-dir`/
|
||||
`--metadata-cache`/`--metadata-backend sidecar`)在本构建中不可用,给出时立刻报错并说明原因,
|
||||
而不是静默忽略。本构建额外提供 `--bed`(已解码的 6 通道 float32 PCM,给出后不调用 ffmpeg
|
||||
解码)、`--kernels`(滤波器组表路径)、`--work-dir`、`--report-json`、`--dry-run`、
|
||||
`--quiet`、`--rosella-filterbank`。
|
||||
|
||||
## 扬声器布局与声道顺序
|
||||
|
||||
`--speaker-layout` 只接受下表 12 个布局,PCM/WAV 的声道顺序就是表里的顺序:
|
||||
|
||||
| 布局 | 声道顺序 |
|
||||
|---|---|
|
||||
| 2.0 | L, R |
|
||||
| 3.1 | L, R, C, LFE |
|
||||
| 4.0 | L, R, Lrs, Rrs |
|
||||
| 5.1 | L, R, C, LFE, Ls, Rs |
|
||||
| 6.0 | L, R, Ls, Rs, Lrs, Rrs |
|
||||
| 7.1 | L, R, C, LFE, Ls, Rs, Lrs, Rrs |
|
||||
| 5.1.2 | L, R, C, LFE, Ls, Rs, Ltm, Rtm |
|
||||
| 5.1.4 | L, R, C, LFE, Ls, Rs, Ltf, Rtf, Ltr, Rtr |
|
||||
| 7.1.2 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Ltm, Rtm |
|
||||
| 7.1.4 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Ltf, Rtf, Ltr, Rtr |
|
||||
| 9.1.4 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Lw, Rw, Ltf, Rtf, Ltr, Rtr |
|
||||
| 9.1.6 | L, R, C, LFE, Ls, Rs, Lrs, Rrs, Lw, Rw, Ltf, Rtf, Ltm, Rtm, Ltr, Rtr |
|
||||
|
||||
`4.0` 是本项目补充的 Quad 布局(传统 Quad 的 `FL FR BL BR`),声道为 `L R Lrs Rrs`,不在杜比
|
||||
文档的布局列表里;除它以外的布局及声道顺序均依据杜比相关规范定义。
|
||||
|
||||
多声道 WAV 使用 `WAVE_FORMAT_EXTENSIBLE`,`dwChannelMask = 0`:文件不声明 Windows 扬声器位置,
|
||||
PCM 声道顺序严格按上表,不按掩码位序重排。播放器、ASIO、DAW 或其他设备需要按声道编号自行完成
|
||||
输出映射;本项目保证各 PCM 声道的内容和编号符合上表,不保证下游播放器自动识别杜比扬声器位置。
|
||||
|
||||
`--speaker-layout` 只接受上表 12 个名字;其它名字按未知布局报错。
|
||||
|
||||
扬声器渲染从 OAMD 元数据读取 warp、trim 和 front/back balance;命令行不提供 warp 覆盖。
|
||||
warp 0/1 直接渲染;warp 2/3 先渲染到 7.1.x 中间布局,再按 PLIIx 或 Standard(Lo/Ro)
|
||||
折回 5.1.x,校准参数始终按最终目标布局选择。原始对象轨迹与双耳渲染不预处理这些控制,
|
||||
参数与求值顺序见[数学说明 §12](docs/math.md)。
|
||||
|
||||
扬声器渲染还会应用 OAMD 的对象属性:每块增益/inactive、zone/elevation、size/snap/divergence、
|
||||
priority 尺寸预算、element 5 位置细化、ISF 基矩阵和 bed distribute。ADM 导出与双耳路径仍按点
|
||||
对象放置,不应用这些扬声器目标系数。
|
||||
|
||||
对象位置的调度按完整 `frame_state` 进行:扬声器与双耳渲染都接受多 position block 和超过 16
|
||||
个对象的节目,按各块的时间与 ramp 逐个调度;双耳渲染的音频输入仍是 1 LFE + 15 对象,多出的
|
||||
位置轨道只跟踪不参与声像。ADM 导出仍使用 15 轨、单 block 的对象位置视图,超出时按变体报错。
|
||||
|
||||
## 库集成
|
||||
|
||||
@@ -125,17 +173,41 @@ tests/ 单元测试(CTest,自足,不需要外部素材)
|
||||
docs/ 数学说明、双耳渲染流程与 SIMD 派发
|
||||
```
|
||||
|
||||
`src/` 下 8 个文件是 JustOneCacophony 原生库的逐字节副本,永不修改(见
|
||||
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md))。
|
||||
`src/` 下的 QMF/双耳表与 JOC Huffman 表按公开标准实现;来源记录见
|
||||
[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
|
||||
|
||||
ISF 压缩基系数与布局描述以查表方式提供:表数据写在生成头文件 `src/oamd/isf_tables.h` 中,
|
||||
与代码一起编译进二进制,运行时不读取数据文件。gain、size、priority、位置、divergence
|
||||
与差分/细化值都在代码中计算,size 核由扬声器布局的 region 几何生成,bed 路由由布局表推导。
|
||||
|
||||
## 数学实现
|
||||
|
||||
主要文档化阶段:
|
||||
|
||||
- dense JOC 差分还原与去量化;
|
||||
- 参数带到 64 个 QMF 子带的映射;
|
||||
- 跨帧参数插值(无上一帧时硬切,对象消失后按零矩阵发布);
|
||||
- 帧级 JOC 状态机(正常 / 保持 / 硬切 / 核心直通);
|
||||
- analysis / inverse QMF、环绕声道延迟与 FIR 状态;
|
||||
- LFE 1217-sample 延迟与逐点 clipgain 斜坡;
|
||||
- OAMD Q15 坐标转换;
|
||||
- 基于目标布局 region 的等功率声像;
|
||||
- OAMD 元数据应用(每块增益与 inactive、zone/elevation、size 核、snap、divergence、位置细化、priority 尺寸预算、ISF 矩阵、bed 分配);
|
||||
- 布局位置补偿与逐样本增益斜坡;
|
||||
- float32 与 PCM24 输出量化;
|
||||
- Rosella 与编译好的 `.jochrtf` 双耳渲染,含 exactly-once delay/phase 与 special LFE。
|
||||
|
||||
解码与渲染所用的公式见[数学说明](docs/math.md)。
|
||||
|
||||
## 兼容性说明
|
||||
|
||||
### `joc_clipgain` 的施加方式
|
||||
|
||||
`joc_clipgain` 在**分析端**并入分析标量:`标量 = 1/16 × g`(`g = 1 + (y/32)·2^(x−4)`,8 bit 字段
|
||||
`x:3 | y:5`)。出口的 ×16 抵消 1/16,净效果是 `×g`,因此 clamp 处在增益**之后**
|
||||
`joc_clipgain` 在**分析端**并入分析标量:`标量 = 1/16 × g`(`g = 2^(x−4)·(1 + y/32)`,8 bit 字段
|
||||
`x:3 | y:5`,值域 0.0625..15.75)。出口的 ×16 抵消 1/16,净效果是 `×g`,因此 clamp 处在增益**之后**
|
||||
(`clamp(16·IQMF·g_interp)`)。标量按帧保存在两个槽里:本帧前 256 个采样从上一帧值线性过渡、之后为
|
||||
常数,复位后的第一帧直接取新值。`g = 1` 时插值恒等,且 `clamp(x)·1 == clamp(x·1)`。
|
||||
常数,复位后的第一帧直接取新值。`g = 1` 时插值恒等,且 `clamp(x)·1 == clamp(x·1)`。LFE 走独立
|
||||
通路,但使用同一个完整 `g` 的逐点斜坡,并乘在 1217-sample 延迟之前。
|
||||
|
||||
`object_delay_samples` 默认 **1473**,与既有实现的行为保持一致;它是可配置字段,改动它会
|
||||
改变 OAMD/ADM 时间对齐。上游调查认为该值应为 0,本项目为保持逐字节等价暂不改默认值。
|
||||
@@ -156,14 +228,39 @@ ffmpeg 侧只在 $N=5$ 档位传 `-ac 6`;$N=7$ 档位不传 `-ac`,保留解
|
||||
**跨层一致性校验**(§11.2):子流声明的全频段通道数必须等于 $N$,$joc\_ext\_config\_idx$ 非零
|
||||
时报未映射变体,对象数超过 15 时截断到 15 并记入 diagnostics——这几项会改变 DSP 输入,不一致就
|
||||
拒绝。额外那一对的**身份**只进元数据、不进 DSP(§10.1):依赖子流 `chanmap` 与 $k$ 不一致、或
|
||||
OAMD 标准 bed 掩码与 $k$ 不一致时,只记 diagnostics 并照常解码,床映射按 `chanmap` 的通道码走。
|
||||
OAMD 声明的 bed 布局可以比核心子流实际编码的声道多(例如 9.1.6 bed 只编 5.1 核心),只有核心
|
||||
声道在 bed 布局里找不到位置才记 diagnostics 并照常解码,床映射按 `chanmap` 的通道码走。
|
||||
同一音频帧里出现多个含 ID11/ID14 的 EMDF 容器时,按规格 §8.2 + Table 56 的关联规则打分:
|
||||
OAMD 与 JOC 载荷 groupid 相同且 ID14 能完整解析的优先,其次只看 ID14 能否解析;唯一最高分才用,
|
||||
其余记入 diagnostics(`emdf/extra_container_ignored`)。额外那一对在 10 槽 ADM 骨架上的落位
|
||||
($k=1\to6/7$、$k\in\{2,4\}\to8/9$)会被记录,但床通道按现行契约不作为输出通道。
|
||||
|
||||
音频帧内完全没有 JOC EMDF 时(例如编码器没写首帧元数据),该帧的对象通道静音,
|
||||
QMF 分析与合成状态照常推进,并在统计里单独计数。
|
||||
### 帧状态与 JOC 解码状态机
|
||||
|
||||
每个帧都带一个状态,非零状态按诊断报告。非零状态使该帧不能用于渲染,渲染器因此保持上一帧矩阵或输出
|
||||
核心 PCM 直通,而不还原该帧的矩阵:2 不支持的下混配置,3 对象数截断到 15,4 未知参数带索引,
|
||||
5 非法 `offset_ts`,6 字节对齐后存在尾随数据,7 ID14 载荷在 `joc_data` 内提前结束。文件任务对
|
||||
`joc_dmx_config_idx` 超出 0..4 的输入更早在元数据扫描阶段按不支持变体拒绝。状态 3 仍给出截断后的
|
||||
对象列表(供诊断),状态 2、4 在出错的头字段处停止解析,状态 7 则保留完整的头、clipgain、序号和
|
||||
对象参数,只缺对象矩阵。
|
||||
|
||||
状态 7 只在 EMDF 容器本身完整时才分类:容器长度越界、或载荷短到连 12 bit 的 `joc_header` 都放
|
||||
不下仍是传输错误,文件任务与流接口还要求同一容器里的 ID11 载荷能解析。容器完整而载荷在
|
||||
`joc_data` 中提前结束的帧按无效帧处理(保持上一帧矩阵),文件任务和流接口因此继续解码而不中断,
|
||||
流接口统计里的 `truncated_joc_frames` 记录这类帧,`joc_check_id14_padding` 对它们仍报
|
||||
`JOC_ERR_BITSTREAM_TRUNCATED`。
|
||||
|
||||
渲染随后按帧级状态机运行:正常、保持、硬切、核心直通。正常渲染期间出现 JOC 参数不可用的帧时
|
||||
进入保持,继续发布上一帧末的矩阵;连续六个不可用帧只把内部保持状态推进一档、仍保持;出现有效
|
||||
帧后重新对齐序号。渲染器离开初始状态后序号回到 0、序号不匹配、或声明的核心声道数变化都
|
||||
触发硬切:所有对象矩阵清零、每个对象的 previous 状态置零,核心声道数变化还清空 LFE 延迟环
|
||||
但保留 clipgain 斜坡状态。首个有效帧之前,渲染器输出核心 PCM 直通。
|
||||
|
||||
音频帧内完全没有 JOC EMDF 时(例如编码器没写首帧元数据),该帧一律走直通路径:8 路核心平面
|
||||
L、R、C、LFE、Ls、Rs、(Lrs, Rrs) 按 identity 写入输出槽 0..7,每路延迟 1217 采样,槽 8..15
|
||||
保持零,8 平面历史照常推进。这类帧在统计里单独计数;不含 JOC 元数据(ID11 + ID14)的 E-AC-3
|
||||
输入不在支持范围。ID14 载荷在 `joc_data` 内提前结束的帧不属于这一类:它走上面的保持路径,
|
||||
在流接口统计里单独计数(`truncated_joc_frames`)。保持或直通期间没有新参数时,分析标量与 LFE 斜坡沿用当前保持的 clipgain。
|
||||
|
||||
## 许可
|
||||
|
||||
|
||||
+27
-61
@@ -2,24 +2,19 @@
|
||||
|
||||
[中文](binaural.md) · [Back to README](../README.en.md)
|
||||
|
||||
JustOneCacophony's binaural backend supports three HRTF sources:
|
||||
`SimpleFreeFieldHRIR` SOFA, the Rosella `.personalized_headphone` model exported
|
||||
by Dolby's official personalization scan (its JSON parsing is implemented by
|
||||
this project and invokes no Dolby software), and the `.jochrtf` cache compiled
|
||||
from SOFA. SOFA is compiled into an in-memory directional field when the model
|
||||
is loaded. A `.jochrtf` file is only a disposable, reproducible JOC compiled
|
||||
HRTF cache; it is neither an interchange format nor a prerequisite for using
|
||||
SOFA.
|
||||
JustOneCacophony's binaural backend supports two HRTF sources: the Rosella
|
||||
`.personalized_headphone` model exported by Dolby's official personalization scan
|
||||
(its JSON parsing is implemented by this project and invokes no Dolby software),
|
||||
and an offline compiled `.jochrtf` directional-field cache. A `.jochrtf` file is
|
||||
a disposable, reproducible JOC compiled HRTF cache, not an interchange format.
|
||||
|
||||
```text
|
||||
SOFA FIR
|
||||
-> CanonicalHrtf
|
||||
-> 48 kHz / one radius shell / delay-phase policy
|
||||
-> 64-QMF / 77-hybrid projection
|
||||
-> fifth-order ACN/N3D real-SH field
|
||||
-> per-object direct + early reflections
|
||||
-> shared unitary-FDN late room
|
||||
-> float64 stereo
|
||||
.jochrtf
|
||||
-> 77-band directional field + delay model
|
||||
-> 64-QMF / 77-hybrid analysis
|
||||
-> per-object direct + optional early reflections
|
||||
-> optional shared unitary-FDN late room
|
||||
-> stereo float64
|
||||
```
|
||||
|
||||
## Inputs
|
||||
@@ -31,7 +26,7 @@ performs no parsing or conversion of measurement data formats.
|
||||
```powershell
|
||||
joc_cli input.m4a --binaural `
|
||||
--compiled-hrtf-cache path\to\subject.jochrtf `
|
||||
--kernels data\rosella_kernels.npz `
|
||||
--kernels path\to\rosella_kernels.npz `
|
||||
--binaural-mode mid --binaural-tail-seconds 5.0
|
||||
```
|
||||
|
||||
@@ -61,41 +56,6 @@ input E-AC-3 JOC bitstream:
|
||||
entries unchanged; the default is `mid`, and `off` explicitly disables the
|
||||
binaural metadata hint.
|
||||
|
||||
## Canonical SOFA contract
|
||||
|
||||
The strict importer currently accepts:
|
||||
|
||||
- `Conventions=SOFA`;
|
||||
- `SOFAConventions=SimpleFreeFieldHRIR`, version `0.4`, `1.0`, or `1.1`;
|
||||
- `DataType=FIR` and `Data.IR[M,2,N]`;
|
||||
- one positive finite `Data.SamplingRate` in hertz/Hz;
|
||||
- spherical or Cartesian `SourcePosition`;
|
||||
- singleton or per-measurement `ListenerPosition/View/Up`;
|
||||
- two receivers whose listener-local lateral geometry uniquely identifies L/R;
|
||||
- one zero-offset emitter;
|
||||
- causal `Data.Delay[I,2]` or `[M,2]`;
|
||||
- an explicitly free-field/anechoic `RoomType`.
|
||||
|
||||
Receiver order comes from geometry, never from the receiver array index. SOFA
|
||||
listener coordinates are $+X$ front,
|
||||
$+Y$ left,
|
||||
$+Z$ up; ADM coordinates are
|
||||
$+X$ right,
|
||||
$+Y$ front,
|
||||
$+Z$ up:
|
||||
|
||||
$$\bigl(x_{\mathrm{SOFA}},\ y_{\mathrm{SOFA}},\ z_{\mathrm{SOFA}}\bigr) = \bigl(y_{\mathrm{ADM}},\ -x_{\mathrm{ADM}},\ z_{\mathrm{ADM}}\bigr)$$
|
||||
|
||||
`CanonicalHrtf` keeps `Data.IR` and `Data.Delay` separate. Only a time-domain
|
||||
baseline calls `materialized_measurement()` to apply delay once; the runtime SH
|
||||
path never materializes and then restores the delay. Non-48-kHz HRIRs are
|
||||
normalized with float64 `scipy.signal.resample_poly`, and delay samples scale by
|
||||
the same ratio.
|
||||
|
||||
GeneralFIR, BRIR, TF, multiple emitters, ambiguous receivers, and non-free-field
|
||||
data require convention-specific adapters. They cannot enter the core importer
|
||||
through a reshape.
|
||||
|
||||
## Exactly-once delay and phase
|
||||
|
||||
The compiler recognizes three mutually exclusive representations:
|
||||
@@ -112,7 +72,7 @@ No path may add a second ear delay or phase-group delay.
|
||||
|
||||
## Public filterbank and directional field
|
||||
|
||||
The runtime is fixed at:
|
||||
The `.jochrtf` runtime is fixed at:
|
||||
|
||||
- 48 kHz;
|
||||
- a 64-sample QMF hop;
|
||||
@@ -121,14 +81,22 @@ The runtime is fixed at:
|
||||
- fifth order, 36 terms, ACN/N3D real spherical harmonics;
|
||||
- float64 PCM, delay, SH, and room state; complex128 band transfers and spectra.
|
||||
|
||||
The `.personalized_headphone` path selects its bank rather than fixing it. The
|
||||
default is the shared public bank described here (961 samples of latency); bank
|
||||
2 is the captured Rosella bank (448 samples). Both keep their own coefficients,
|
||||
history and high-band delay, and the runtime skips the selected bank's latency
|
||||
and sizes the flush with it. See [Rosella filterbank](rosella_filterbank.en.md)
|
||||
for the parameters, the CLI switch and the validation results. The SOFA and
|
||||
`.jochrtf` banks described here are unchanged and never use the selector.
|
||||
|
||||
Real and imaginary unit gains for every hybrid band pass through the same
|
||||
analysis/synthesis chain to form a 154-real-parameter impulse dictionary. The
|
||||
compiler does not sample 77 FFT bins. Defaults are `1e-3` projection ridge and
|
||||
`1e-5` SH ridge. Coincident directions are merged before a spherical-Voronoi
|
||||
weighted ridge fit.
|
||||
|
||||
The fixed resource is `data/rosella_kernels.npz`, which implements publicly
|
||||
standardized filter banks, computable from the following formulas.
|
||||
The fixed tables implement publicly standardized filter banks, compile into the
|
||||
sources, and are computable from the following formulas.
|
||||
|
||||
The hybrid analysis kernels are defined in [3GPP TS 26.405 / ETSI TS 126 405](https://www.etsi.org/deliver/etsi_ts/126400_126499/126405/06.00.00_60/ts_126405v060000p.pdf),
|
||||
Section 5.2.2 (Table 1 $Q=8$/
|
||||
@@ -157,11 +125,9 @@ $8+4+4$ child partition):
|
||||
|
||||
$$Y_p = \sum_{q\in C_p}\Bigl(\mathrm{Re}X_q + j\,s_q\,\mathrm{Im}X_q\Bigr),\qquad s_q\in\{\pm1\}$$
|
||||
|
||||
The loader verifies the archive and every array by SHA-256; the table version,
|
||||
all array hashes, and the 77 reference band-center values are part of the cache
|
||||
key. Public availability of a standard does not by itself grant permission to
|
||||
practice related patent claims. See
|
||||
[`data/README.en.md`](../data/README.en.md) and
|
||||
The tables are fixed at compile time, so no external archive is loaded and
|
||||
nothing enters a cache key at run time. Public availability of a standard does
|
||||
not by itself grant permission to practice related patent claims. See
|
||||
[`THIRD_PARTY_NOTICES.md`](../THIRD_PARTY_NOTICES.md) for the sources and the
|
||||
rights boundary.
|
||||
|
||||
@@ -224,7 +190,7 @@ Dolby.
|
||||
|
||||
The binaural renderer is implemented inside this library: the filterbank, the SH
|
||||
directional-field evaluation, the per-object early/direct histories and the shared
|
||||
FDN all run in `joc_core` (the `ejoc_sofa_binaural_*` kernel), consuming a compiled
|
||||
FDN all run in `joc_core` (the `ejoc_jochrtf_*` kernel), consuming a compiled
|
||||
directional field and 512-sample metadata updates.
|
||||
|
||||
## Technical references and rights boundary
|
||||
|
||||
+35
-55
@@ -2,33 +2,32 @@
|
||||
|
||||
[English](binaural.en.md) · [返回 README](../README.md)
|
||||
|
||||
JustOneCacophony 的双耳后端支持三种 HRTF 来源:`SimpleFreeFieldHRIR` SOFA、
|
||||
杜比官方软件个性化扫描导出的 Rosella `.personalized_headphone`(JSON 解析由本项目
|
||||
自行实现,不调用杜比软件),以及从 SOFA 编译出的 `.jochrtf` 缓存。SOFA 在模型加载
|
||||
时编译成内存方向场;`.jochrtf` 只是可删除、可重建的 JOC compiled HRTF cache,
|
||||
不是交换格式,也不是使用 SOFA 的前置步骤。
|
||||
JustOneCacophony 的双耳后端支持两种 HRTF 来源:杜比官方软件个性化扫描导出的
|
||||
Rosella `.personalized_headphone`(JSON 解析由本项目自行实现,不调用杜比软件),以及
|
||||
离线编译好的 `.jochrtf` 方向场缓存。`.jochrtf` 是可删除、可重建的 JOC compiled HRTF
|
||||
cache,不是交换格式。
|
||||
|
||||
```text
|
||||
SOFA FIR
|
||||
-> CanonicalHrtf
|
||||
-> 48 kHz / 单 radius shell / delay-phase policy
|
||||
-> 64-QMF / 77-hybrid projection
|
||||
-> 五阶 ACN/N3D 实球谐场
|
||||
-> 逐对象 direct + early reflections
|
||||
-> shared unitary-FDN late room
|
||||
.jochrtf
|
||||
-> 77 带方向场 + 延迟模型
|
||||
-> 64-QMF / 77-hybrid analysis
|
||||
-> 逐对象 direct + 可选 early reflections
|
||||
-> 可选 shared unitary-FDN late room
|
||||
-> stereo float64
|
||||
```
|
||||
|
||||
## 输入接口
|
||||
|
||||
双耳后端消费一个已编译的方向场(JOC compiled HRTF cache,`.jochrtf`)与共享滤波器组表;
|
||||
两者都是只读输入,本库不做任何测量数据格式的解析或转换:
|
||||
双耳后端消费两种输入:已编译的方向场(JOC compiled HRTF cache,`.jochrtf`)配共享滤波器组表,
|
||||
或者是 Rosella `.personalized_headphone` 模型。两者都是只读输入,本库不做测量数据格式的解析:
|
||||
|
||||
```powershell
|
||||
joc_cli input.m4a --binaural `
|
||||
--compiled-hrtf-cache path\to\subject.jochrtf `
|
||||
--kernels data\rosella_kernels.npz `
|
||||
--kernels path\to\rosella_kernels.npz `
|
||||
--jochrtf-room on `
|
||||
--binaural-mode mid --binaural-tail-seconds 5.0
|
||||
joc_cli input.m4a --binaural --personalized-headphone HRTF\binaural.personalized_headphone
|
||||
```
|
||||
|
||||
库接口使用同一组字段:文件任务用 `joc_task_config`,流式用 `joc_stream_config`,
|
||||
@@ -51,39 +50,6 @@ joc_cli input.m4a --binaural `
|
||||
`off=0/near=1/far=2/mid=3`,前 10 个 bed 保持不变,默认 `mid`;`off` 用于显式
|
||||
关闭双耳元数据提示。
|
||||
|
||||
## Canonical SOFA 契约
|
||||
|
||||
当前 strict importer 接受:
|
||||
|
||||
- `Conventions=SOFA`;
|
||||
- `SOFAConventions=SimpleFreeFieldHRIR`,version `0.4`、`1.0` 或 `1.1`;
|
||||
- `DataType=FIR`,`Data.IR[M,2,N]`;
|
||||
- 单一正有限 `Data.SamplingRate`,单位为 hertz/Hz;
|
||||
- spherical 或 Cartesian `SourcePosition`;
|
||||
- 单值或 per-measurement 的 `ListenerPosition/View/Up`;
|
||||
- 两个能由 listener-local lateral 坐标唯一识别左右的 receiver;
|
||||
- 单一且零偏移的 emitter;
|
||||
- causal `Data.Delay[I,2]` 或 `[M,2]`;
|
||||
- 明确的 free-field/anechoic `RoomType`。
|
||||
|
||||
receiver 左右顺序由几何决定,不能假定 `Data.IR` 的 receiver index。SOFA listener
|
||||
坐标为 $+X$ front、
|
||||
$+Y$ left、
|
||||
$+Z$ up;ADM 坐标为
|
||||
$+X$ right、
|
||||
$+Y$ front、
|
||||
$+Z$ up,转换为:
|
||||
|
||||
$$\bigl(x_{\mathrm{SOFA}},\ y_{\mathrm{SOFA}},\ z_{\mathrm{SOFA}}\bigr) = \bigl(y_{\mathrm{ADM}},\ -x_{\mathrm{ADM}},\ z_{\mathrm{ADM}}\bigr)$$
|
||||
|
||||
`CanonicalHrtf` 将 `Data.IR` 与 `Data.Delay` 分开保存。只有时域 baseline 才调用
|
||||
`materialized_measurement()` 将 delay 应用一次;运行时 SH 路径不先 materialize。
|
||||
非 48 kHz HRIR 使用 float64 `scipy.signal.resample_poly` 规范化,delay samples 按
|
||||
相同比例缩放。
|
||||
|
||||
GeneralFIR、BRIR、TF、多 emitter、多义 receiver 或非 free-field 数据需要单独的
|
||||
convention adapter,不能只通过 reshape 进入核心 importer。
|
||||
|
||||
## Delay/phase:exactly once
|
||||
|
||||
编译器只允许三种互斥语义:
|
||||
@@ -112,7 +78,7 @@ convention adapter,不能只通过 reshape 进入核心 importer。
|
||||
ridge 为 `1e-3`,SH ridge 为 `1e-5`。同方向 measurement 先合并,再用球面 Voronoi
|
||||
面积权重做 ridge fit。
|
||||
|
||||
固定表位于 `data/rosella_kernels.npz`,实现公开标准化的滤波器组,各表可由如下
|
||||
固定表按公开标准化的滤波器组实现并编译进源码,各表可由如下
|
||||
公式计算。
|
||||
|
||||
hybrid 分析核定义于 [3GPP TS 26.405 / ETSI TS 126 405](https://www.etsi.org/deliver/etsi_ts/126400_126499/126405/06.00.00_60/ts_126405v060000p.pdf)
|
||||
@@ -140,9 +106,8 @@ $8+4+4$ 子带划分):
|
||||
|
||||
$$Y_p = \sum_{q\in C_p}\Bigl(\mathrm{Re}X_q + j\,s_q\,\mathrm{Im}X_q\Bigr),\qquad s_q\in\{\pm1\}$$
|
||||
|
||||
loader 校验 archive 和每个数组的 SHA-256;table version、所有数组 hash 与
|
||||
77 个 band-center 参考值都属于 cache key。标准可公开获取不等于获准实施相关
|
||||
专利;更多来源信息见 [`data/README.md`](../data/README.md) 与
|
||||
固定表在编译期确定,运行时不加载外部 archive,也不参与缓存键。标准可公开
|
||||
获取不等于获准实施相关专利;来源与权利边界见
|
||||
[`THIRD_PARTY_NOTICES.md`](../THIRD_PARTY_NOTICES.md)。
|
||||
|
||||
## `.jochrtf`
|
||||
@@ -166,8 +131,7 @@ loader 使用 `allow_pickle=False`,并在构造对象前检查 ZIP 成员集
|
||||
dtype、端序、连续布局、有限值、delay bounds、band centers、payload hash 和 cache
|
||||
key。writer 使用同目录临时文件、`fsync`、进程持有的 OS 文件锁和原子
|
||||
`os.replace`;对应的隐藏 `.lock` sidecar 可保留,但不代表仍有 writer 持锁。
|
||||
旧版本、损坏或配置不匹配的 cache 不能命中;从 SOFA 启动时会重建,显式 cache
|
||||
入口则直接报错。
|
||||
旧版本、损坏或配置不匹配的 cache 不会命中,而是直接报错。
|
||||
|
||||
删除磁盘 cache 后,从同一 SOFA 和同一编译配置得到的场与渲染结果不得改变。
|
||||
|
||||
@@ -177,6 +141,22 @@ key。writer 使用同目录临时文件、`fsync`、进程持有的 OS 文件
|
||||
私有 cache,不随程序或构建产物发布。`source_sha256` 只用于内容一致性校验,不是许可
|
||||
或来源证明。
|
||||
|
||||
## Rosella 个性化模型
|
||||
|
||||
`.personalized_headphone` 走独立的 Rosella 渲染器,滤波器组可以二选一,
|
||||
由 `--rosella-filterbank 1|2`(库接口为 `joc_task_config::rosella_filterbank` /
|
||||
`joc_stream_config::rosella_filterbank`,`0` 表示默认)选择:
|
||||
|
||||
| 取值 | 滤波器组 | 低频 hybrid | 高频 slot delay | 延迟 |
|
||||
| --- | --- | --- | --- | ---: |
|
||||
| `1`(默认) | `PublicFilterbank`(与 Rosella 路径共用) | 13 taps | 6 slots | 961 samples |
|
||||
| `2` | `RosellaFilterbank`(从参考渲染器捕获) | 11 taps | 3 slots | 448 samples |
|
||||
|
||||
两套实现通过同一组四个有状态 half-step 调用,因此切换时系数、高频 delay、历史缓冲
|
||||
布局、起始延迟跳过量和 flush 容量一起改变,分析与合成两级互不共享状态。其它取值直接
|
||||
报错;非 Rosella 输入给出该选项也报错,不会静默忽略。详见
|
||||
[Rosella filterbank](rosella_filterbank.en.md)。
|
||||
|
||||
## JOC 对象与房间
|
||||
|
||||
生产适配器继续使用现有 JOC 调度:
|
||||
@@ -193,7 +173,7 @@ unitary FDN、LFE 120–180 Hz cosine-squared 低通及 room calibration 都是
|
||||
项目定义行为,不是 SOFA 或 Dolby 公布常数。
|
||||
|
||||
双耳渲染在本库内实现:filterbank、SH 方向场求值、逐对象 early/direct 历史与共享 FDN
|
||||
全部执行于 `joc_core`(`ejoc_sofa_binaural_*` 内核),对外只消费编译好的方向场与
|
||||
全部执行于 `joc_core`(`ejoc_jochrtf_*` 内核),对外只消费编译好的方向场与
|
||||
512-sample 粒度的元数据更新。
|
||||
|
||||
## 技术引用与权利边界
|
||||
|
||||
+294
-18
@@ -147,10 +147,17 @@ If the clipgain field consists of integer $x$ and mantissa $y$, then
|
||||
|
||||
$$
|
||||
G_{\mathrm{clip}}=
|
||||
1+\frac{y}{32}2^{x-4}.
|
||||
2^{x-4}\left(1+\frac{y}{32}\right).
|
||||
$$
|
||||
|
||||
It is applied to object PCM after inverse QMF and does not apply to LFE.
|
||||
Its range is $[0.0625,15.75]$; at $x=4$ it reduces to $1+y/32$. It is folded into the analysis-side
|
||||
scalar $S=\frac{1}{16}G_{\mathrm{clip}}$, which multiplies every core-bed sample before the QMF
|
||||
analysis; the $\times16$ after the object inverse QMF cancels the $1/16$, so the net effect is a multiply
|
||||
by $G_{\mathrm{clip}}$ and the $[-1,1]$ clamp sits **after** the gain. The scalar keeps two per-frame
|
||||
slots: the first 256 samples of a frame ramp linearly from the previous frame's value to this frame's
|
||||
value and the rest stays constant, and the first frame after a reset takes the new value directly. LFE
|
||||
uses a separate path but applies the same full $G_{\mathrm{clip}}$ as a sample-wise ramp before its
|
||||
1217-sample delay; see section 8.
|
||||
|
||||
## 3. Parameter-band expansion and time interpolation
|
||||
|
||||
@@ -185,7 +192,13 @@ Thus $p(b)=k$ if and only if $b\in\mathcal B_k$. Other parameter-band counts use
|
||||
|
||||
### 3.2 One-data-point interpolation
|
||||
|
||||
Let $P_{o,c,b}$ be the previous frame-end value and $D_{o,c,p(b)}$ the current target. For slot $t=0\ldots23$:
|
||||
Let $P_{o,c,b}$ be the previous frame-end value and $D_{o,c,p(b)}$ the current target. When the object
|
||||
has no previous state yet (the first frame of the stream, or the object's first appearance), a single
|
||||
data point keeps all 24 slots at $D_{o,c,p(b)}$ (hard cut, no fade-in from zero); with two data points,
|
||||
the first 12 slots stay at $D_0$ and the last 12 slots still interpolate from $D_0$ to $D_1$ using the
|
||||
second segment of section 3.3 (with $P$ set to $D_0$).
|
||||
|
||||
With a previous state, for slot $t=0\ldots23$:
|
||||
|
||||
$$
|
||||
\alpha_t=\frac{t+1}{24},
|
||||
@@ -203,11 +216,31 @@ $$
|
||||
M_{o,c,b,23}=D_{o,c,p(b)}.
|
||||
$$
|
||||
|
||||
This value then becomes the previous state for the next frame.
|
||||
This value then becomes the previous state for the next frame. Once an object's present flag goes from 1
|
||||
to 0, it keeps being published with an all-zero matrix and its previous state is updated to zero until it
|
||||
becomes present again.
|
||||
|
||||
### 3.3 Multiple data points
|
||||
|
||||
When a frame contains two data points, `offset_ts` gives the segment boundary. Each segment uses the same linear relation between the previous and next targets; step mode switches targets at the designated slot.
|
||||
`offset_ts` gives the first slot at which each data point becomes active, using the raw 5-bit value
|
||||
(legal range $0\ldots23$); the values of one object must be strictly increasing. In the default mode
|
||||
(`slope_idx=0`), two data points $D_0$ and $D_1$ interpolate as
|
||||
|
||||
$$
|
||||
M_{o,c,b,t}=
|
||||
\begin{cases}
|
||||
(1-\alpha_t)P_{o,c,b}+\alpha_tD_{0}, & t=0\ldots10,\ \alpha_t=\dfrac{t+1}{12},\\[1mm]
|
||||
D_{0}, & t=11,\\[1mm]
|
||||
(1-\beta_t)D_{0}+\beta_tD_{1}, & t=12\ldots23,\ \beta_t=\dfrac{t-11}{12}.
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
When no previous state exists, the same formulas apply with $P_{o,c,b}$ set to $D_0$.
|
||||
|
||||
Step mode (`slope_idx=1`) switches targets directly at the designated slots: for $t<o_0$ it keeps the
|
||||
previous frame-end value $P_{o,c,b}$ (or $D_0$ when no previous state exists), for $o_0\le t<o_1$ it
|
||||
uses $D_0$, and for $t\ge o_1$ it uses $D_1$; with a single data point it keeps $P$ for $t<o_0$ and uses
|
||||
$D_0$ from $o_0$ on.
|
||||
|
||||
## 4. Analysis QMF for core PCM
|
||||
|
||||
@@ -238,8 +271,9 @@ $$
|
||||
\qquad c\in\{L,R,C\}.
|
||||
$$
|
||||
|
||||
For Ls and Rs the ten-slot delay, the $-j$ rotation for $b>0$ and the band-0 21-tap
|
||||
complex FIR are all gated by the **same switch** $\sigma(k)=1\iff k\in\{3,4\}$:
|
||||
Ls and Rs take the same delay inside the surround path, whose delay line advances
|
||||
regardless; the $-j$ rotation for $b>0$ and the band-0 21-tap complex FIR are gated by
|
||||
the **same switch** $\sigma(k)=1\iff k\in\{3,4\}$:
|
||||
|
||||
$$
|
||||
\widehat X_{c,b,t}=
|
||||
@@ -251,9 +285,9 @@ X_{c,b,t-10}, & \text{otherwise}.
|
||||
$$
|
||||
|
||||
For $N=7$ the sixth and seventh core channels (Lb/Rb or Tfl/Tfr) behave like the front
|
||||
channels and only take the ten-slot delay: channel identity affects metadata and the ADM
|
||||
placement, not the DSP. These delays and filter histories are decoder state and cannot be
|
||||
reset independently for every frame.
|
||||
channels and only take the ten-slot delay: channel identity affects metadata and rendering,
|
||||
not the DSP. These delays and filter histories are decoder state and cannot be reset
|
||||
independently for every frame.
|
||||
|
||||
## 6. Object matrix
|
||||
|
||||
@@ -331,15 +365,21 @@ where $r=0\ldots63$. Synthesis state must advance continuously by slot.
|
||||
|
||||
## 8. LFE path
|
||||
|
||||
LFE bypasses the object matrix and inverse QMF and uses a 1217-sample delay. After the input and output scale factors cancel:
|
||||
LFE bypasses the object matrix and inverse QMF. The core LFE samples are first multiplied by the
|
||||
sample-wise gain ramp $G[n]$ (the same full $G_{\mathrm{clip}}$ as section 2.4: for $n<256$,
|
||||
$G[n]=G_{\mathrm{old}}+n(G_{\mathrm{new}}-G_{\mathrm{old}})/256$; for $n\ge256$, $G[n]=G_{\mathrm{new}}$;
|
||||
on the first frame or after a reset, $G_{\mathrm{old}}=G_{\mathrm{new}}$). The scaled samples then
|
||||
enter the 1217-sample delay, and the read-out is only clamped, with no further gain:
|
||||
|
||||
$$
|
||||
y_{\mathrm{LFE}}[n]=
|
||||
\mathrm{clip}\left(
|
||||
x_{\mathrm{LFE,core}}[n-1217],-1,1
|
||||
x_{\mathrm{LFE,core}}[n-1217]\cdot G[n-1217],-1,1
|
||||
\right).
|
||||
$$
|
||||
|
||||
Here $G[k]$ uses the frame-local position of input sample $k$, i.e. $k\bmod1536$.
|
||||
|
||||
## 9. OAMD coordinates
|
||||
|
||||
The lateral and longitudinal grids use $N=62$; the height grid uses $N=15$. The quantizer is
|
||||
@@ -352,7 +392,7 @@ q_N(k)=
|
||||
\right).
|
||||
$$
|
||||
|
||||
OAR coordinates are
|
||||
The normalized room coordinates are
|
||||
|
||||
$$
|
||||
u=\frac{q_1}{32768},
|
||||
@@ -439,14 +479,17 @@ $$
|
||||
\mathbf h(u)\odot\mathbf v(v).
|
||||
$$
|
||||
|
||||
For 5.1-family layouts with one horizontal surround pair rather than separate side and rear pairs, the longitudinal coordinate is
|
||||
For layouts with one horizontal surround pair rather than separate side and rear pairs (the 5.1
|
||||
family, and 4.0, which carries one rear pair only), the longitudinal coordinate is
|
||||
|
||||
$$
|
||||
v_{\mathrm{floor}}=
|
||||
\mathrm{clamp}(2v,0,1).
|
||||
$$
|
||||
|
||||
Other layouts use $v_{\mathrm{floor}}=v$.
|
||||
Warp 0 and other layouts use $v_{\mathrm{floor}}=v$. The height layer is not scaled.
|
||||
An absent warp indication uses 0; no CLI override is provided. Modes 2/3 use
|
||||
the intermediate layout and folding matrix in §12.5. Balance follows this scaling.
|
||||
|
||||
### 10.3 Height layer
|
||||
|
||||
@@ -467,6 +510,9 @@ $$
|
||||
|
||||
## 11. Layout-dependent position compensation
|
||||
|
||||
This is the per-object gain for automatic trim. Disabled trim uses unity;
|
||||
explicit trim uses §12.2 instead, without multiplying automatic compensation again.
|
||||
|
||||
Let $N_h$ be the number of relevant height speakers and $N_f$ the number of relevant additional horizontal speakers:
|
||||
|
||||
$$
|
||||
@@ -512,7 +558,188 @@ G_{\mathrm{pos}}
|
||||
\mathbf G_{\mathrm{point}}.
|
||||
$$
|
||||
|
||||
## 12. OAMD time alignment and gain ramps
|
||||
## 12. OAMD trim and front-back balance
|
||||
|
||||
### 12.1 Configuration selection
|
||||
|
||||
The OAMD trim element splits a programme's calibration data into nine
|
||||
configurations, chosen by the target layout's additional horizontal speaker
|
||||
count $N_f$ and height speaker count $N_h$:
|
||||
|
||||
$$
|
||||
\kappa_f(N)=
|
||||
\begin{cases}
|
||||
0, & N=0,\\
|
||||
1, & N\in\{2,3\},\\
|
||||
2, & \text{otherwise},
|
||||
\end{cases}
|
||||
\qquad
|
||||
\kappa_h(N)=
|
||||
\begin{cases}
|
||||
0, & N=0,\\
|
||||
1, & N=2,\\
|
||||
2, & \text{otherwise}.
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
$$
|
||||
c_{\mathrm{trim}}=\kappa_f(N_f)+3\,\kappa_h(N_h).
|
||||
$$
|
||||
|
||||
The nine configurations enumerate "no / some / many additional horizontal
|
||||
speakers by no / some / many height speakers".
|
||||
|
||||
Trim and front-back balance apply to seven layouts only: 2.0, 3.1, 4.0, 5.1,
|
||||
5.1.2, 5.1.4 and 7.1. Wider layouts (7.1.2, 7.1.4, 9.1.4, 9.1.6) are left
|
||||
untrimmed, with $g_t=1$ and $b=0$.
|
||||
|
||||
Warp, trim and balance controls are read from OAMD metadata:
|
||||
|
||||
| Parameter | Value or unit | Behavior |
|
||||
|---|---|---|
|
||||
| `warp_mode` | 0 / 1 / 2 / 3 | Direct rendering / floor Y scaling / PLIIx folding / Standard (Lo/Ro) folding |
|
||||
| `global_trim_mode` | 0 / 1 / 2 | Automatic / disabled / per-layout configuration; reserved value 3 is rejected |
|
||||
| $T_s$, $T_h$ | dB | Explicit surround and height trim, with positive values treated as zero |
|
||||
| $T_c$ | dB | Signed explicit centre trim |
|
||||
| $b_{\mathrm{lis}}$, $b_{\mathrm{tb}}$ | $[-1,1]$, step $1/16$ | Listener-plane and overhead front-back balance |
|
||||
| Per-object trim bypass | Boolean | Disables the object's balance and trim gain while retaining warp |
|
||||
|
||||
With global mode 2, the selected configuration's default or disabled flag
|
||||
chooses automatic or disabled trim. A missing configuration uses automatic;
|
||||
otherwise its explicit parameters apply. Automatic uses §11, disabled uses
|
||||
unity, and explicit uses §12.2. These modes are mutually exclusive.
|
||||
|
||||
Without an initial trim element, warp is 0 and trim is automatic. A later
|
||||
payload without that element retains the previous controls; a new element
|
||||
updates them at the corresponding metadata event boundary. The CLI has no
|
||||
warp override.
|
||||
|
||||
### 12.2 Per-object levels
|
||||
|
||||
Centre, surround and height levels parameterize a position-dependent object
|
||||
gain; they are not fixed gains applied to the output channels after mixing.
|
||||
For original Y after balance $y_t$ and $z=\max(w,0)$:
|
||||
|
||||
$$
|
||||
a_s=\mathrm{clamp}(2y_t,0,1)(1-z),\quad a_h=z,
|
||||
$$
|
||||
|
||||
$$
|
||||
a_c=1-\mathrm{clamp}\bigl(10\max(|z|-0.05,y_t-0.05,|u-0.5|-0.05),0,1\bigr).
|
||||
$$
|
||||
|
||||
Explicit trim uses
|
||||
|
||||
$$
|
||||
D=a_s\min(T_s,0)+a_h\min(T_h,0)+a_cT_c,\qquad g_t=10^{D/20}.
|
||||
$$
|
||||
|
||||
The scalar multiplies the object's whole panning vector before accumulation.
|
||||
Automatic trim uses §11; disabled trim or per-object bypass uses unity. LFE
|
||||
passes through. Gain evaluation, panning interpolation and object accumulation
|
||||
use float64.
|
||||
|
||||
### 12.3 Front-back balance
|
||||
|
||||
Each configuration also carries two front-back balance values:
|
||||
$b_{\mathrm{lis}}$ for the listener plane and $b_{\mathrm{tb}}$ for the overhead
|
||||
layer. Both are quantised to a $1/16$ grid and are non-zero only in an explicit
|
||||
configuration.
|
||||
|
||||
Writing $n=\mathrm{round}(16\,|b|)$ and $s=n/18$, the single-layer map is
|
||||
|
||||
$$
|
||||
B_b(y)=
|
||||
\begin{cases}
|
||||
y, & y\le 0.05\ \text{or}\ y\ge 0.95,\\[2pt]
|
||||
(1+s)y-0.05s, & 0.05<y<0.5,\ b>0,\\[2pt]
|
||||
(1-s)(y-0.5)+0.5+0.45s, & 0.5\le y<0.95,\ b>0,\\[2pt]
|
||||
(1-s)y+0.05s, & 0.05<y<0.5,\ b<0,\\[2pt]
|
||||
(1+s)(y-0.5)+0.5-0.45s, & 0.5\le y<0.95,\ b<0.
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
It maps $[0.05,0.95]$ monotonically onto itself: the two walls stay fixed, the
|
||||
two halves meet at $y=0.5$, and their slopes are $1+s$ and $1-s$. The 5 percent
|
||||
wall bands and the case $b=0$ pass through unchanged, so the map never leaves
|
||||
the interval and needs no extra clamp.
|
||||
|
||||
The height $w$ blends the two layers:
|
||||
|
||||
$$
|
||||
y'=(1-w)\,B_{b_{\mathrm{lis}}}(y)+w\,B_{b_{\mathrm{tb}}}(y).
|
||||
$$
|
||||
|
||||
The front-back axis $y$ is oriented as in §9, with $0$ at the front wall and
|
||||
$1$ at the back wall; $x$ and $z$ are unchanged.
|
||||
|
||||
### 12.4 Where it is applied
|
||||
|
||||
Let $B_z(y)$ denote the balance map of §12.3 and $W(y)$ the warp map of §10.2.
|
||||
Direct point rendering in warp modes 0/1 keeps three coordinates:
|
||||
|
||||
$$
|
||||
y_f=B_z(W(y)),\qquad y_h=B_z(y),\qquad y_t=B_z(y).
|
||||
$$
|
||||
|
||||
Floor and height panning use $y_f,y_h$; trim evaluation uses $y_t$. The final gain is
|
||||
|
||||
$$
|
||||
g_{o,c}=G_{\mathrm{object}}\,g_t(u,y_t,z)\,P_c(u,y_f,y_h,z).
|
||||
$$
|
||||
|
||||
Warp precedes balance, followed by trim/pan gain composition, but not every
|
||||
stage shares a warped Y. Balance requires explicit trim without object bypass;
|
||||
warp remains independent of trim state and bypass. Source positions are kept
|
||||
unchanged for ADM and binaural.
|
||||
|
||||
Floor coordinates pass through warp and then balance before floor panning.
|
||||
Height and trim coordinates pass through balance alone. The trim scalar
|
||||
multiplies the object's entire panning vector before accumulation into output
|
||||
channels. LFE passes through.
|
||||
|
||||
### 12.5 Surround folding in warp modes 2/3
|
||||
|
||||
For a 5.1, 5.1.2 or 5.1.4 target, warp modes 2/3 first render objects to the
|
||||
corresponding 7.1, 7.1.2 or 7.1.4 intermediate layout, then fold the rear
|
||||
surrounds into the target surround pair. The 4.0 layout also adds a rear pair
|
||||
without adding centre or LFE. Other existing layouts render directly.
|
||||
|
||||
The intermediate layout changes speaker geometry and panning only. The trim
|
||||
configuration, both balance layers and the maximum automatic position
|
||||
compensation remain those of the final target. For example, 5.1.2 uses
|
||||
configuration 4 and a maximum compensation of $-2.25$ dB even when its
|
||||
intermediate layout is 7.1.2. With separate side and rear pairs in the
|
||||
intermediate layout, floor Y is not doubled. Balance and per-object trim
|
||||
are evaluated during intermediate rendering.
|
||||
|
||||
For intermediate outputs $L_s,R_s,L_{rs},R_{rs}$ and target surrounds
|
||||
$L'_s,R'_s$:
|
||||
|
||||
$$
|
||||
L'_s=L_s+aL_{rs}+bR_{rs},\qquad
|
||||
R'_s=R_s+bL_{rs}+aR_{rs}.
|
||||
$$
|
||||
|
||||
| Mode | $a$ | $b$ |
|
||||
|---|---|---|
|
||||
| 2: PLIIx | $\sqrt{3}/2$ | $1/2$ |
|
||||
| 3: Standard (Lo/Ro) | $1$ | $0$ |
|
||||
|
||||
Both matrices add linear amplitudes without normalizing energy after the
|
||||
fold. Shared front, height and LFE channels pass through to their matching
|
||||
positions. The folded object gain vector enters the target-gain update and
|
||||
ramp in §13 before object audio is accumulated.
|
||||
|
||||
The complete order is: select calibration for the target layout → apply
|
||||
balance and trim while panning in the intermediate layout → fold horizontal
|
||||
surrounds → update gain ramps and mix. Per-object bypass disables balance
|
||||
and trim while retaining layout selection and folding. These modes are
|
||||
generic speaker-rendering controls; the publicly defined E-AC-3 JOC warp
|
||||
values remain 0/1. Source trajectories, ADM and binaural do not bake in the
|
||||
folded result.
|
||||
|
||||
## 13. OAMD time alignment and gain ramps
|
||||
|
||||
The coded position of an OAMD update is
|
||||
|
||||
@@ -568,7 +795,7 @@ $$
|
||||
|
||||
If no new metadata update intervenes, this is equivalent to a sample-wise linear ramp of total length $KB$.
|
||||
|
||||
## 13. Final speaker mix
|
||||
## 14. Final speaker mix
|
||||
|
||||
For target output channel $c$:
|
||||
|
||||
@@ -600,9 +827,58 @@ y_{24}[n]=
|
||||
\right).
|
||||
$$
|
||||
|
||||
## 14. Scope of the formulas
|
||||
## 15. Scope of the formulas
|
||||
|
||||
- The JOC matrix section covers both the dense MTX and the sparse IDX/VEC differential syntax.
|
||||
- The speaker-panning section describes ordinary point objects; extent, spread, divergence, and similar modes require additional models.
|
||||
- Multiple OAMD position blocks must be scheduled in time order.
|
||||
- A limiter is separate post-processing and is not included in the mixing equations above.
|
||||
- Trim and front-back balance affect speaker rendering only; binaural rendering does not read them.
|
||||
|
||||
## 16. OAMD metadata application (speaker path)
|
||||
|
||||
When mapping object PCM to the target layout, speaker rendering applies the OAMD
|
||||
object attributes in addition to the geometric panning:
|
||||
|
||||
- per-block integer gain `Qg` (unity 4096) and `inactive`; the gain is applied to
|
||||
the target coefficients once, and the LFE uses its owning metadata object's
|
||||
gain/active state;
|
||||
- full basic/render status 0/1/2/3 block expansion, same-object previous-block
|
||||
inheritance, and local mask updates;
|
||||
- `zone_constraints_idx` region selection mapped through `[0,1,2,3,4,5,6,0]`;
|
||||
`enable_elevation=0` forces z=0 before position compensation and size spread;
|
||||
- `object_size_idx` 5-bit sizes, the `size_curve` piecewise mapping, and the size
|
||||
kernel; the kernel is generated at runtime from region geometry with
|
||||
equal-power grouped panning, the S448 weight and a power sum (20/20/8
|
||||
virtual points, 20 size nodes, 35/4 position nodes; boundary rows
|
||||
X(0), X(1), Y(0), Y(1), Z(1));
|
||||
- `snap` first-argmax speaker snapping, `divergence` left/right point-source
|
||||
combination, and element 5 high-precision position refinement;
|
||||
- `default_priority`/`priority_bits` choose which size objects keep their size
|
||||
when the size budget is limited;
|
||||
- `isf_idx` basis matrices (signed coefficients, no per-column normalization)
|
||||
with the per-basis compensation;
|
||||
- `b_bed_chan_distribute` label candidates, weight normalization, missing-channel
|
||||
fallback, and the direct/distribute compensation.
|
||||
|
||||
The ISF path orders the N ISF object audio essences into the column vector t
|
||||
according to the M.U.L.Z order of `isf_config`, selects the input configuration
|
||||
by `isf_idx` and the matrix M for the target output layout, and evaluates
|
||||
y = M·t: each ISF channel is distributed over the speakers by the corresponding
|
||||
matrix row, LFE bypasses the matrix, and each basis carries its own
|
||||
compensation. The matrix coefficients and layout descriptors are obtained from
|
||||
lookup tables stored in the compiled-in `src/oamd/isf_tables.h`; nothing reads a
|
||||
data file at run time.
|
||||
|
||||
Gain, size, priority, position, divergence, delta and refinement values are
|
||||
computed in code (`src/oamd/oamd_parser.*`) from formulas or fixed constants; the
|
||||
size kernel (`src/oamd/oamd_math.*`) is generated at runtime from region geometry
|
||||
with grouped equal-power panning, the S448 weight and a power sum. Bed labels,
|
||||
routing and reference positions are derived from the speaker layout tables
|
||||
(`src/speaker/speaker_layouts.h`) by
|
||||
`src/joc_bitstream/bed_layout_map.{h,cpp}`.
|
||||
ADM export and the binaural paths still use object positions only and do not apply
|
||||
these speaker target coefficients. The binaural path schedules positions from the
|
||||
complete `frame_state`: multiple position blocks and programmes with more than 16
|
||||
objects are scheduled block by block at their own time and ramp, and its position
|
||||
track list is not limited to 16; ADM export keeps the 15-track single-block view.
|
||||
+248
-16
@@ -147,10 +147,15 @@ $$
|
||||
|
||||
$$
|
||||
G_{\mathrm{clip}}=
|
||||
1+\frac{y}{32}2^{x-4}.
|
||||
2^{x-4}\left(1+\frac{y}{32}\right).
|
||||
$$
|
||||
|
||||
它在对象 inverse QMF 之后作用于对象 PCM,不作用于 LFE。
|
||||
值域为 $[0.0625,15.75]$;$x=4$ 时化为 $1+y/32$。它并入分析端标量
|
||||
$S=\frac{1}{16}G_{\mathrm{clip}}$,乘在核心 bed 的每个采样上(QMF 分析之前);
|
||||
对象 inverse QMF 之后的 $\times16$ 抵消 $1/16$,净效果是乘 $G_{\mathrm{clip}}$,因此钳位 $[-1,1]$
|
||||
处在增益**之后**。标量按帧保留两个槽,本帧前 256 个采样从上一帧值线性过渡到本帧值、之后为常数,
|
||||
复位后的第一帧直接取新值。LFE 走独立通路,但使用同一个完整 $G_{\mathrm{clip}}$ 的逐点斜坡:
|
||||
斜坡在进入 1217-sample 延迟之前乘到 LFE 采样上,见 §8。
|
||||
|
||||
## 3. 参数带展开与时间插值
|
||||
|
||||
@@ -185,7 +190,12 @@ $$
|
||||
|
||||
### 3.2 单数据点插值
|
||||
|
||||
令上一帧末值为 $P_{o,c,b}$,当前目标值为 $D_{o,c,p(b)}$。对时槽 $t=0\ldots23$:
|
||||
令上一帧末值为 $P_{o,c,b}$,当前目标值为 $D_{o,c,p(b)}$。对象没有 previous 状态时
|
||||
(整条流第一帧或对象首次出现):单数据点情形 24 个时槽恒为 $D_{o,c,p(b)}$(硬切,
|
||||
不从零淡入);双数据点情形前 12 个时槽为 $D_0$,后 12 个时槽按 §3.3 的第二段公式
|
||||
从 $D_0$ 插值到 $D_1$(把该节的 $P$ 取为 $D_0$)。
|
||||
|
||||
有 previous 状态时,对时槽 $t=0\ldots23$:
|
||||
|
||||
$$
|
||||
\alpha_t=\frac{t+1}{24},
|
||||
@@ -203,11 +213,28 @@ $$
|
||||
M_{o,c,b,23}=D_{o,c,p(b)}.
|
||||
$$
|
||||
|
||||
该值随后成为下一帧的 previous 状态。
|
||||
该值随后成为下一帧的 previous 状态。对象 present 由 1 变 0 后,从该帧起继续按全零矩阵发布,
|
||||
并把 previous 更新为零矩阵,直到它重新 present=1。
|
||||
|
||||
### 3.3 多数据点
|
||||
|
||||
当一帧含两个数据点时,`offset_ts` 给出分段边界。每一段在上一目标和下一目标之间使用相同的线性关系;阶跃模式则在指定时槽直接切换目标。
|
||||
`offset_ts` 给出各数据点开始生效的时隙序号,取原始 5 bit 值(合法范围 $0\ldots23$);
|
||||
同一对象的数据点必须严格递增。默认模式(`slope_idx=0`)下,两个数据点 $D_0,D_1$ 的插值为
|
||||
|
||||
$$
|
||||
M_{o,c,b,t}=
|
||||
\begin{cases}
|
||||
(1-\alpha_t)P_{o,c,b}+\alpha_tD_{0}, & t=0\ldots10,\ \alpha_t=\dfrac{t+1}{12},\\[1mm]
|
||||
D_{0}, & t=11,\\[1mm]
|
||||
(1-\beta_t)D_{0}+\beta_tD_{1}, & t=12\ldots23,\ \beta_t=\dfrac{t-11}{12}.
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
没有 previous 状态时同样使用上面的公式,只是把 $P_{o,c,b}$ 取为 $D_0$。
|
||||
|
||||
阶跃模式(`slope_idx=1`)在指定时槽直接切换目标:$t<o_0$ 保持上一帧末值 $P_{o,c,b}$
|
||||
(没有 previous 时取 $D_0$),$o_0\le t<o_1$ 取 $D_0$,$t\ge o_1$ 取 $D_1$;
|
||||
单数据点时 $t<o_0$ 保持 $P$、$t\ge o_0$ 取 $D_0$。
|
||||
|
||||
## 4. 核心 PCM 的 analysis QMF
|
||||
|
||||
@@ -239,8 +266,8 @@ $$
|
||||
\qquad c\in\{L,R,C\}.
|
||||
$$
|
||||
|
||||
Ls、Rs 的 10 时槽延迟、$b>0$ 的 $-j$ 旋转与 band-0 的 21-tap 复 FIR 由**同一个开关**
|
||||
$\sigma(k)=1\iff k\in\{3,4\}$ 门控:
|
||||
Ls、Rs 的 10 时槽延迟在环绕通路内完成,延迟线照常推进;$b>0$ 的 $-j$ 旋转与 band-0 的
|
||||
21-tap 复 FIR 由**同一个开关** $\sigma(k)=1\iff k\in\{3,4\}$ 门控:
|
||||
|
||||
$$
|
||||
\widehat X_{c,b,t}=
|
||||
@@ -252,7 +279,7 @@ X_{c,b,t-10}, & \text{其他情况}.
|
||||
$$
|
||||
|
||||
$N=7$ 时第 6、7 个核心声道(Lb/Rb 或 Tfl/Tfr)与前级相同,只做 10 时槽延迟:
|
||||
通道身份只影响元数据与 ADM 落位,不进入 DSP。这些延迟和滤波历史属于解码状态,
|
||||
通道身份只影响元数据与渲染,不进入 DSP。这些延迟和滤波历史属于解码状态,
|
||||
不能按帧独立清零。
|
||||
|
||||
## 6. 对象矩阵
|
||||
@@ -331,15 +358,20 @@ $$
|
||||
|
||||
## 8. LFE 路径
|
||||
|
||||
LFE 不经过对象矩阵或 inverse QMF,而是使用 1217-sample 延迟。输入与输出端的比例因子抵消后:
|
||||
LFE 不经过对象矩阵或 inverse QMF。核心 LFE 先乘逐点增益斜坡 $G[n]$(与 §2.4 同一个完整
|
||||
$G_{\mathrm{clip}}$:$n<256$ 时 $G[n]=G_{\mathrm{old}}+n(G_{\mathrm{new}}-G_{\mathrm{old}})/256$,
|
||||
$n\ge256$ 时 $G[n]=G_{\mathrm{new}}$,首帧或复位后 $G_{\mathrm{old}}=G_{\mathrm{new}}$),
|
||||
再进入 1217-sample 延迟;读出后只做钳位,不再乘任何增益:
|
||||
|
||||
$$
|
||||
y_{\mathrm{LFE}}[n]=
|
||||
\mathrm{clip}\left(
|
||||
x_{\mathrm{LFE,core}}[n-1217],-1,1
|
||||
x_{\mathrm{LFE,core}}[n-1217]\cdot G[n-1217],-1,1
|
||||
\right).
|
||||
$$
|
||||
|
||||
其中 $G[k]$ 取输入采样 $k$ 所在帧内的位置,即 $k\bmod1536$。
|
||||
|
||||
## 9. OAMD 坐标
|
||||
|
||||
横向和纵向网格使用 $N=62$,高度网格使用 $N=15$。量化函数为
|
||||
@@ -352,7 +384,7 @@ q_N(k)=
|
||||
\right).
|
||||
$$
|
||||
|
||||
OAR 坐标为
|
||||
归一化房间坐标为
|
||||
|
||||
$$
|
||||
u=\frac{q_1}{32768},
|
||||
@@ -439,14 +471,17 @@ $$
|
||||
\mathbf h(u)\odot\mathbf v(v).
|
||||
$$
|
||||
|
||||
对于只有一对水平环绕、没有独立 side/rear 两对的 5.1 系列布局,纵向坐标使用
|
||||
对于只有一对水平环绕、没有独立 side/rear 两对的布局(5.1 系列,以及 4.0 这类
|
||||
只有一对后置声道的布局),纵向坐标使用
|
||||
|
||||
$$
|
||||
v_{\mathrm{floor}}=
|
||||
\mathrm{clamp}(2v,0,1).
|
||||
$$
|
||||
|
||||
其他布局使用 $v_{\mathrm{floor}}=v$。
|
||||
`warp_mode=0` 或其他布局使用 $v_{\mathrm{floor}}=v$。高度层不做该缩放。
|
||||
未携带 warp 元数据时采用 0;命令行不提供覆盖选项。warp 2/3 使用 §12.5 的中间布局与折叠矩阵。
|
||||
有 front/back balance 时,先求这里的分支坐标,再应用 §12.3 的 balance。
|
||||
|
||||
### 10.3 高度层
|
||||
|
||||
@@ -467,6 +502,9 @@ $$
|
||||
|
||||
## 11. 布局位置补偿
|
||||
|
||||
本节是 trim 为 automatic 时的逐对象增益。disabled 取 1;explicit 改用 §12.2,
|
||||
不能把 automatic 增益与 explicit trim 再乘一遍。
|
||||
|
||||
令 $N_h$ 为相关高度扬声器数,$N_f$ 为相关附加水平扬声器数:
|
||||
|
||||
$$
|
||||
@@ -512,7 +550,165 @@ G_{\mathrm{pos}}
|
||||
\mathbf G_{\mathrm{point}}.
|
||||
$$
|
||||
|
||||
## 12. OAMD 时间对齐与增益斜坡
|
||||
## 12. OAMD trim 与前后平衡
|
||||
|
||||
### 12.1 配置选择
|
||||
|
||||
OAMD trim element 把节目的校准数据分成九个配置,由目标布局的附加水平扬声器数
|
||||
$N_f$ 与高度扬声器数 $N_h$ 选定:
|
||||
|
||||
$$
|
||||
\kappa_f(N)=
|
||||
\begin{cases}
|
||||
0, & N=0,\\
|
||||
1, & N\in\{2,3\},\\
|
||||
2, & \text{其他},
|
||||
\end{cases}
|
||||
\qquad
|
||||
\kappa_h(N)=
|
||||
\begin{cases}
|
||||
0, & N=0,\\
|
||||
1, & N=2,\\
|
||||
2, & \text{其他}.
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
$$
|
||||
c_{\mathrm{trim}}=\kappa_f(N_f)+3\,\kappa_h(N_h).
|
||||
$$
|
||||
|
||||
九个配置依次为“no / some / many 附加水平 × no / some / many 高度”。
|
||||
|
||||
trim 与前后平衡只在七种布局下施加:2.0、3.1、4.0、5.1、5.1.2、5.1.4、7.1。
|
||||
更宽的布局(7.1.2、7.1.4、9.1.4、9.1.6)取 $g_t=1$、$b=0$。
|
||||
|
||||
warp、trim 和 balance 均从 OAMD 元数据读取。各参数的取值与作用为:
|
||||
|
||||
| 参数 | 取值或单位 | 行为 |
|
||||
|---|---|---|
|
||||
| `warp_mode` | 0 / 1 / 2 / 3 | 直接渲染 / 地面 Y 缩放 / PLIIx 折叠 / Standard(Lo/Ro)折叠 |
|
||||
| `global_trim_mode` | 0 / 1 / 2 | automatic / disabled / 按目标布局配置选择;3 为保留值,明确报错 |
|
||||
| $T_s$、$T_h$ | dB | 显式 surround、height trim 参数,正值按 0 处理 |
|
||||
| $T_c$ | dB | 显式 centre trim 参数,保留符号 |
|
||||
| $b_{\mathrm{lis}}$、$b_{\mathrm{tb}}$ | $[-1,1]$,步长 $1/16$ | 听音平面、顶部的前后 balance |
|
||||
| 逐对象 trim bypass | 布尔值 | 关闭该对象的 balance 和 trim 增益,保留 warp |
|
||||
|
||||
全局模式为 2 时,所选配置的 default 或 disabled 标志分别采用 automatic 或 disabled;
|
||||
缺失配置采用 automatic,其他配置使用其显式参数。automatic 使用 §11 的位置补偿,
|
||||
disabled 使用单位增益,explicit 使用 §12.2,三种模式互斥。
|
||||
|
||||
初始没有 trim element 时采用 `warp_mode=0`、automatic trim。后续 payload 不含该
|
||||
element 时保持上一组控制;出现新 element 时,在对应元数据事件边界更新。命令行不提供
|
||||
warp 覆盖选项。
|
||||
|
||||
### 12.2 逐对象电平
|
||||
|
||||
centre、surround、height 是位置相关 trim 函数的参数,不是混音后各输出声道的固定增益。
|
||||
令 $y_t$ 为原始 Y 经 balance 后的坐标,$z=\max(w,0)$:
|
||||
|
||||
$$
|
||||
a_s=\mathrm{clamp}(2y_t,0,1)(1-z),\qquad a_h=z,
|
||||
$$
|
||||
|
||||
$$
|
||||
a_c=1-\mathrm{clamp}\bigl(10\max(|z|-0.05,\ y_t-0.05,\ |u-0.5|-0.05),0,1\bigr).
|
||||
$$
|
||||
|
||||
explicit 状态下,surround/height 参数上限为 0 dB,centre 保留有符号电平:
|
||||
|
||||
$$
|
||||
D=a_s\min(T_s,0)+a_h\min(T_h,0)+a_cT_c,\qquad g_t=10^{D/20}.
|
||||
$$
|
||||
|
||||
同一个 $g_t$ 乘该对象的整条声像增益向量,然后才累加不同对象。automatic 使用 §11;
|
||||
disabled 或逐对象 trim bypass 取 $g_t=1$。LFE 仍直接通过。
|
||||
增益求值、声像插值和对象累加均使用 float64。
|
||||
|
||||
### 12.3 前后平衡
|
||||
|
||||
每个配置还携带两个前后平衡量:$b_{\mathrm{lis}}$ 作用于听音平面,
|
||||
$b_{\mathrm{tb}}$ 作用于顶部。二者按 $1/16$ 网格量化,只在显式配置下非零。
|
||||
|
||||
记 $n=\mathrm{round}(16\,|b|)$、$s=n/18$,单层映射为
|
||||
|
||||
$$
|
||||
B_b(y)=
|
||||
\begin{cases}
|
||||
y, & y\le 0.05\ \text{或}\ y\ge 0.95,\\[2pt]
|
||||
(1+s)y-0.05s, & 0.05<y<0.5,\ b>0,\\[2pt]
|
||||
(1-s)(y-0.5)+0.5+0.45s, & 0.5\le y<0.95,\ b>0,\\[2pt]
|
||||
(1-s)y+0.05s, & 0.05<y<0.5,\ b<0,\\[2pt]
|
||||
(1+s)(y-0.5)+0.5-0.45s, & 0.5\le y<0.95,\ b<0.
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
它把 $[0.05,0.95]$ 单调映到自身:两端不动,$y=0.5$ 处两段取值相同,斜率分别为
|
||||
$1+s$ 与 $1-s$。首尾各 $5\%$ 的墙区以及 $b=0$ 的情形都原样通过,因此映射不会
|
||||
越界,也无需额外钳位。
|
||||
|
||||
高度 $w$ 把两层混合起来:
|
||||
|
||||
$$
|
||||
y'=(1-w)\,B_{b_{\mathrm{lis}}}(y)+w\,B_{b_{\mathrm{tb}}}(y).
|
||||
$$
|
||||
|
||||
前后轴 $y$ 的取向见 §9,$0$ 为前、$1$ 为后;$x$ 与 $z$ 不变。
|
||||
|
||||
### 12.4 施加位置
|
||||
|
||||
记 §12.3 的高度混合 balance 映射为 $B_z(y)$,§10.2 的 warp 映射为 $W(y)$。
|
||||
warp 0/1 直接渲染点对象时,分支顺序为
|
||||
|
||||
$$
|
||||
y_f=B_z(W(y)),\qquad y_h=B_z(y),\qquad y_t=B_z(y).
|
||||
$$
|
||||
|
||||
地面和高度声像分别使用 $y_f,y_h$,trim 函数使用 $y_t$。最后组合
|
||||
|
||||
$$
|
||||
g_{o,c}=G_{\mathrm{object}}\,g_t(u,y_t,z)\,P_c(u,y_f,y_h,z).
|
||||
$$
|
||||
|
||||
因此可概括为 warp → balance → trim 与声像增益合成,但不能让所有阶段共用一个
|
||||
已经 warp 的 Y。balance 仅在 explicit 且未逐对象 bypass 时启用;warp 不受 trim
|
||||
状态或 trim bypass 控制。源坐标保持原值,ADM 与 binaural 不预处理此变换。
|
||||
|
||||
地面坐标依次经过 warp、balance,再用于地面声像;顶部坐标和 trim 求值坐标只经过
|
||||
balance。trim 标量乘到该对象的整条声像增益向量后,再累加到输出声道。LFE 直接通过。
|
||||
|
||||
### 12.5 warp 2/3 的环绕折叠
|
||||
|
||||
目标为 5.1、5.1.2 或 5.1.4 时,warp 2/3 先把对象渲染到对应的 7.1、7.1.2 或
|
||||
7.1.4 中间布局,再将后环绕折叠到目标的环绕对。4.0 同样先增加一对后环绕,
|
||||
中间布局不增加 centre 或 LFE。其他现有布局直接渲染。
|
||||
|
||||
中间布局只改变扬声器几何与声像分配。Trim 配置、两层 Balance 和 Auto Trim 的
|
||||
最大位置补偿仍按最终目标布局选择。例如,5.1.2 使用配置 4,最大位置补偿为
|
||||
$-2.25$ dB,即使其中间布局是 7.1.2,也继续使用这些参数。中间布局已有独立
|
||||
side/rear 两对,地面 Y 不再乘 2;Balance 和逐对象 Trim 在中间渲染时求值。
|
||||
|
||||
设中间布局输出为 $L_s,R_s,L_{rs},R_{rs}$,最终目标的环绕输出为 $L'_s,R'_s$:
|
||||
|
||||
$$
|
||||
L'_s=L_s+aL_{rs}+bR_{rs},\qquad
|
||||
R'_s=R_s+bL_{rs}+aR_{rs}.
|
||||
$$
|
||||
|
||||
| 模式 | $a$ | $b$ |
|
||||
|---|---|---|
|
||||
| 2:PLIIx | $\sqrt{3}/2$ | $1/2$ |
|
||||
| 3:Standard(Lo/Ro) | $1$ | $0$ |
|
||||
|
||||
两种矩阵都按线性幅度相加,不做折叠后的能量归一化。共同的前方、高度和 LFE
|
||||
声道按对应位置直接通过。折叠后的对象增益向量进入 §13 的目标增益更新与斜坡,
|
||||
然后累加对象音频。
|
||||
|
||||
完整顺序为:按目标布局选择校准参数 → 在中间布局应用 Balance、Trim 并计算声像
|
||||
增益 → 折叠水平环绕 → 更新增益斜坡与混音。逐对象 bypass 关闭 Balance 和 Trim,
|
||||
但仍保留 warp 2/3 的布局选择与折叠。上述模式属于通用扬声器渲染控制;E-AC-3 JOC
|
||||
公开定义的 warp 值仍为 0/1,源对象轨迹、ADM 和 binaural 不预处理折叠结果。
|
||||
|
||||
## 13. OAMD 时间对齐与增益斜坡
|
||||
|
||||
OAMD 更新的编码位置为
|
||||
|
||||
@@ -568,7 +764,7 @@ $$
|
||||
|
||||
如果中途没有新的 metadata 更新,该过程等价于总长度 $KB$ 的逐样本线性斜坡。
|
||||
|
||||
## 13. 最终扬声器混音
|
||||
## 14. 最终扬声器混音
|
||||
|
||||
对目标输出声道 $c$:
|
||||
|
||||
@@ -600,9 +796,45 @@ y_{24}[n]=
|
||||
\right).
|
||||
$$
|
||||
|
||||
## 14. 公式适用范围
|
||||
## 15. 公式适用范围
|
||||
|
||||
- JOC 矩阵部分同时描述 dense MTX 与 sparse IDX/VEC 两条差分语法。
|
||||
- 扬声器声像部分描述普通点对象;extent、spread、divergence 等模式需要额外模型。
|
||||
- 多个 OAMD position block 必须按其时间顺序调度。
|
||||
- limiter 属于独立后处理,不包含在上述混音公式中。
|
||||
- trim 与前后平衡只作用于扬声器渲染;双耳渲染不读取它们。
|
||||
|
||||
## 16. OAMD 元数据应用(扬声器路径)
|
||||
|
||||
扬声器渲染把对象 PCM 映射到目标布局时,除几何声像外还应用 OAMD 的对象属性:
|
||||
|
||||
- 每块整数增益 `Qg`(单位增益 4096)与 `inactive`;增益在生成目标系数时乘一次,
|
||||
LFE 使用所属元数据对象的增益/活动状态;
|
||||
- basic/render 状态 0/1/2/3 的完整块展开、同对象前一块继承与局部 mask 更新;
|
||||
- `zone_constraints_idx` 选择区域,映射为 `[0,1,2,3,4,5,6,0]`;`enable_elevation=0`
|
||||
在位置补偿和尺寸扩散前令 z=0;
|
||||
- `object_size_idx` 的 5 bit 尺寸、`size_curve` 分段线性映射与尺寸扩散核;
|
||||
尺寸核按分组等功率声像、S448 权重和幂和,在运行时用区域几何生成:
|
||||
20/20/8 个虚拟点、20 个尺寸节点、35/4 个位置节点,边界表为
|
||||
X(0)、X(1)、Y(0)、Y(1)、Z(1);
|
||||
- `snap` 的首个最大系数扬声器吸附、`divergence` 的左右两点合成、
|
||||
element 5 的高精度位置补充;
|
||||
- `default_priority`/`priority_bits` 在 size 数量预算不足时决定保留尺寸的对象;
|
||||
- `isf_idx` 的 ISF 基矩阵(可含负系数,不做逐列归一化)与逐 basis 补偿;
|
||||
- `b_bed_chan_distribute` 的 bed 标签候选筛选、权重归一化、缺失声道 fallback 和
|
||||
直达/distribute 的补偿。
|
||||
|
||||
ISF 路径把 N 路 ISF object audio essences 按 `isf_config` 的 M.U.L.Z 顺序组成
|
||||
列向量 t,按 `isf_idx` 选输入配置、按目标输出布局选矩阵 M,再计算 y = M·t:
|
||||
每个 ISF 声道按矩阵对应的一行分配到目标扬声器,LFE 不参与矩阵、直接旁路,
|
||||
每个 basis 另有补偿。矩阵系数与布局描述通过查表获得,表数据写在编译进源码的
|
||||
`src/oamd/isf_tables.h` 中,运行时不读取数据文件。
|
||||
|
||||
gain、size、priority、位置、divergence 与差分/细化值由 `src/oamd/oamd_parser.*`
|
||||
按公式或固定常量计算,size 扩散核由 `src/oamd/oamd_math.*` 从区域几何生成
|
||||
(分组等功率声像 + S448 权重 + 幂和)。bed 标签、路由和参考位置由
|
||||
`src/joc_bitstream/bed_layout_map.*` 从 `src/speaker/speaker_layouts.h` 的布局表
|
||||
推导。
|
||||
ADM 导出与双耳路径仍只使用对象位置,不应用这些扬声器目标系数。双耳路径按完整
|
||||
`frame_state` 调度位置:多 position block 与超过 16 个对象的节目都按各块的时间与 ramp
|
||||
逐个调度,双耳位置轨道数不限于 16;ADM 导出保持 15 轨单 block 视图。
|
||||
@@ -0,0 +1,100 @@
|
||||
# Rosella filterbank
|
||||
|
||||
The Rosella renderer runs one of two 64-band QMF / 77-band hybrid filterbanks.
|
||||
The shared public bank is the default; the captured Rosella bank reproduces the
|
||||
reference headphone renderer. The SOFA compiler and renderer always use
|
||||
`PublicFilterbank`.
|
||||
|
||||
## Which bank runs
|
||||
|
||||
`--rosella-filterbank 1|2` selects the bank for the `.personalized_headphone`
|
||||
path; `joc_task_config::rosella_filterbank` and
|
||||
`joc_stream_config::rosella_filterbank` carry the same value, with `0` meaning
|
||||
the default.
|
||||
|
||||
| Value | Bank | Low-band hybrid | High-band delay | Latency |
|
||||
| --- | --- | --- | --- | ---: |
|
||||
| `1` (default) | `PublicFilterbank` | 13 taps | 6 slots | 961 samples |
|
||||
| `2` | `RosellaFilterbank` | 11 taps | 3 slots | 448 samples |
|
||||
|
||||
Both banks are driven through the same four stateful half-steps, so the choice
|
||||
switches the coefficients, the high-band delay, the history layout, the startup
|
||||
skip and the flush capacity together; the analysis and synthesis banks never
|
||||
share state. Any other value is rejected, and the option is an error when the
|
||||
binaural input is not a Rosella model: the SOFA and `.jochrtf` paths do not use
|
||||
it and must not silently ignore it.
|
||||
|
||||
## Why the banks differ
|
||||
|
||||
The reference headphone renderer selects its analysis and synthesis callbacks
|
||||
during preparation, after initialization. Capturing only the initial callbacks
|
||||
identified the wrong filterbank variant.
|
||||
|
||||
Runtime buffer captures identified these parameters:
|
||||
|
||||
| Parameter | Rosella bank | Public bank |
|
||||
| --- | --- | --- |
|
||||
| QMF prototype | 640 asymmetric coefficients | Separate prototype |
|
||||
| Low-band hybrid filter | 11 taps | 13 taps |
|
||||
| High-band hybrid delay | 3 slots | 6 slots |
|
||||
| Analysis/synthesis latency | 448 samples | 961 samples |
|
||||
|
||||
The wrong variant produced a frequency-dependent room-tail error. With the
|
||||
captured room send as input, the existing room recursion already matched the
|
||||
reference. The fix changes the filterbank, not the room coefficients, direct
|
||||
HRTF calculation, phase mapping, or output EQ.
|
||||
|
||||
## Implementation
|
||||
|
||||
`RosellaFilterbank` keeps separate analysis, hybrid, and synthesis histories for
|
||||
each channel. QMF data uses `[slot, channel, 64]` order. Hybrid data uses
|
||||
`[slot, channel, 77]` order. The half-step methods preserve state between calls.
|
||||
|
||||
`rosella_filterbank_tables.h` stores the captured float32 prototype, rotation,
|
||||
and hybrid coefficients as hexadecimal literals. Processing uses double
|
||||
precision. The tables do not contain the personalized HRTF or room tuning.
|
||||
|
||||
The runtime removes the selected bank's startup samples and uses the same
|
||||
latency when it calculates flush capacity. Its rendered buffer is resized to the
|
||||
current block length, including a short final block.
|
||||
|
||||
## Validation
|
||||
|
||||
Run the self-contained tests:
|
||||
|
||||
```sh
|
||||
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build --parallel
|
||||
ctest --test-dir build --output-on-failure
|
||||
```
|
||||
|
||||
`rosella_filterbank` checks deterministic analysis, hybrid, folding, and synthesis
|
||||
vectors from an independent NumPy implementation. It also checks empty and
|
||||
unequal chunks, reset, channel isolation, and impulse latency. A second group
|
||||
checks the bank selector: each kind reproduces exactly what its own class
|
||||
computes, the two produce different hybrid data, chunking and reset are
|
||||
invariant for both, and each reports its own latency (961 or 448 samples). The
|
||||
tests need no reference binary, audio fixture, or personalized headphone file.
|
||||
|
||||
Before integration with the upstream bed-layout changes, four captured-input
|
||||
tests gave the following room PCM residuals. No gain fitting was used for this
|
||||
table. Residual is `10 * log10(sum(abs(reference - candidate)^2) /
|
||||
sum(abs(reference)^2))`.
|
||||
|
||||
| Input | Room PCM residual |
|
||||
| --- | ---: |
|
||||
| Left-front click | -133.94 dB |
|
||||
| Left-front log sweep | -135.40 dB |
|
||||
| Left-front noise | -133.50 dB |
|
||||
| Right-front signal | -133.34 dB |
|
||||
|
||||
The old bank produced room residuals near -10 to -11 dB on these captures.
|
||||
A 30-second music replay using the reference decoder's object PCM reached
|
||||
correlation 0.9999999503 and a -70.02 dB residual after delay alignment and one
|
||||
global gain fit. A full-file render through this project's decoder reached
|
||||
correlation 0.99988816 after alignment and gain fitting.
|
||||
|
||||
These are separate experiments, not bit-exactness claims. A fixed gain
|
||||
difference of approximately 1.0004885 remains in the captured chain. The patch
|
||||
does not compensate for that difference. Decoder differences and the remaining
|
||||
music residual are outside this fix.
|
||||
+144
-24
@@ -3,19 +3,22 @@
|
||||
#include <stdint.h>
|
||||
|
||||
/* EJOC_STATIC: this branch exists for building the sources directly into an application, where nothing is imported or exported. */
|
||||
#if defined(_WIN32)
|
||||
#define EJOC_CALL __cdecl
|
||||
#else
|
||||
#define EJOC_CALL
|
||||
#endif
|
||||
|
||||
#if defined(EJOC_STATIC)
|
||||
#define EJOC_API
|
||||
#define EJOC_CALL __cdecl
|
||||
#elif defined(_WIN32)
|
||||
#if defined(EJOC_BUILD_DLL)
|
||||
#define EJOC_API __declspec(dllexport)
|
||||
#else
|
||||
#define EJOC_API __declspec(dllimport)
|
||||
#endif
|
||||
#define EJOC_CALL __cdecl
|
||||
#else
|
||||
#define EJOC_API __attribute__((visibility("default")))
|
||||
#define EJOC_CALL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -23,18 +26,21 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
EJOC_ABI_VERSION = 2,
|
||||
EJOC_ABI_VERSION = 4,
|
||||
EJOC_FRAME_SAMPLES = 1536,
|
||||
EJOC_TIMESLOTS = 24,
|
||||
EJOC_SUBBANDS = 64,
|
||||
EJOC_CORE_CHANNELS = 5, /* downmix configurations 0 and 3 */
|
||||
EJOC_MAX_CORE_CHANNELS = 7, /* downmix configurations 1, 2 and 4 */
|
||||
EJOC_OUTPUT_CHANNELS = 16,
|
||||
EJOC_CORE_OUT_CHANNELS = 8, /* passthrough order: L,R,C,LFE,Ls,Rs,(Lrs,Rrs) */
|
||||
EJOC_LFE_SLOT = 3, /* LFE slot of the passthrough order */
|
||||
EJOC_MAX_OBJECTS = 15,
|
||||
EJOC_MAX_DPOINTS = 2,
|
||||
EJOC_MAX_PARAMETER_BANDS = 23,
|
||||
EJOC_SPEAKER_BLOCK_SAMPLES = 32,
|
||||
EJOC_SPEAKER_COORDINATES = 3,
|
||||
EJOC_SPEAKER_CONTROLS_VERSION = 1,
|
||||
EJOC_BINAURAL_BLOCK_SAMPLES = 512,
|
||||
EJOC_BINAURAL_INPUT_CHANNELS = 16,
|
||||
EJOC_BINAURAL_OUTPUT_CHANNELS = 2,
|
||||
@@ -42,6 +48,21 @@ enum {
|
||||
EJOC_BINAURAL_HYBRID_BANDS = 77
|
||||
};
|
||||
|
||||
/* Per-frame status of ejoc_renderer_render_frame(). A status outside 0..6 is
|
||||
* the renderer's own no-metadata marker; the parse-status values match
|
||||
* joc_frame_params.status (JOC_FRAME_STATUS_* in joc_core.h). Any non-zero
|
||||
* status makes the frame invalid for matrix rendering: the renderer holds the
|
||||
* previous matrices or passes the core PCM through instead of decoding it. */
|
||||
enum {
|
||||
EJOC_FRAME_STATUS_OK = 0,
|
||||
EJOC_FRAME_STATUS_UNSUPPORTED_DMX = 2,
|
||||
EJOC_FRAME_STATUS_OBJECTS_CLAMPED = 3,
|
||||
EJOC_FRAME_STATUS_BAD_PARAMETER_BAND = 4,
|
||||
EJOC_FRAME_STATUS_BAD_OFFSET_TS = 5,
|
||||
EJOC_FRAME_STATUS_TRAILING_DATA = 6,
|
||||
EJOC_FRAME_STATUS_NO_METADATA = 8
|
||||
};
|
||||
|
||||
typedef void* ejoc_renderer_handle;
|
||||
typedef void* ejoc_speaker_renderer_handle;
|
||||
typedef void* ejoc_binaural_renderer_handle;
|
||||
@@ -102,6 +123,63 @@ EJOC_API int EJOC_CALL ejoc_renderer_process(
|
||||
float output_scale,
|
||||
float* output16_planar);
|
||||
|
||||
/*
|
||||
Frame-level entry point: one E-AC-3 audio frame per call, with the seq state
|
||||
machine and the per-object previous-matrix state kept inside the renderer. This
|
||||
is what produces the 16-channel object result for the ADM, speaker and binaural
|
||||
backends; ejoc_renderer_process() stays as a single-frame kernel for A/B tests.
|
||||
|
||||
Fixed array layouts, identical to ejoc_renderer_process():
|
||||
bed_planar [core_channel_count][1536] (JOC lane order L,R,C,Ls,Rs,(pair))
|
||||
lfe [1536] or NULL (zeros; the LFE delay ring still advances)
|
||||
n_bands, n_dpoints, slope_idx [15]
|
||||
offset_ts [15][2] (raw 5-bit JOC offsets, 0..23)
|
||||
dq [15][2][7][23]
|
||||
output16 [16][1536] (ch0 = LFE, ch1..15 = objects)
|
||||
|
||||
frame_status is a JOC_FRAME_STATUS_* / EJOC_FRAME_STATUS_* value. has_metadata
|
||||
is 0 for an audio frame without a JOC EMDF container (frame_status must then be
|
||||
EJOC_FRAME_STATUS_NO_METADATA); such a frame always passes the 8 core planes
|
||||
through to output slots 0..7, delayed by 1217 samples, with slots 8..15 zero.
|
||||
declared_core_channels is the JOC header's n_channels (0 when unknown); a declared
|
||||
change against the previous frame's actual count turns the frame into a hard cut
|
||||
with the LFE ring cleared. phase_shift is sigma(k) = (k in {3,4}) for the frame's
|
||||
downmix configuration; phase_shift_valid = 0 keeps the previous switch (an
|
||||
unsupported downmix configuration has no usable one). clipgain is the frame's
|
||||
joc_clipgain when frame_status == 0. seq is the 10-bit JOC sequence counter.
|
||||
When has_metadata is 0 the object descriptors are ignored.
|
||||
|
||||
Slot 0 of output16 is the LFE, slots 1..15 are the 15 objects; each frame's
|
||||
values are float32(clamped PCM) * output_scale, exactly like the reference.
|
||||
*/
|
||||
typedef struct ejoc_frame_input {
|
||||
uint32_t struct_size;
|
||||
uint32_t struct_version;
|
||||
const float* bed_planar;
|
||||
const float* lfe;
|
||||
uint32_t core_channel_count;
|
||||
uint32_t declared_core_channels;
|
||||
uint32_t phase_shift;
|
||||
uint32_t phase_shift_valid;
|
||||
uint32_t frame_status;
|
||||
uint32_t seq;
|
||||
uint32_t has_metadata;
|
||||
uint32_t object_mask;
|
||||
const uint8_t* n_bands;
|
||||
const uint8_t* n_dpoints;
|
||||
const uint8_t* slope_idx;
|
||||
const uint8_t* offset_ts;
|
||||
const double* dq;
|
||||
double clipgain;
|
||||
float output_scale;
|
||||
float* output16_planar;
|
||||
} ejoc_frame_input;
|
||||
|
||||
enum { EJOC_FRAME_INPUT_VERSION = 1 };
|
||||
|
||||
EJOC_API int EJOC_CALL ejoc_renderer_render_frame(ejoc_renderer_handle handle,
|
||||
const ejoc_frame_input* input);
|
||||
|
||||
/*
|
||||
High-precision object-to-speaker renderer.
|
||||
|
||||
@@ -123,6 +201,47 @@ metadata_offsets must be nondecreasing and <= sample_count. sample_count must
|
||||
be a multiple of EJOC_SPEAKER_BLOCK_SAMPLES. State and unfinished ramps are
|
||||
preserved across calls.
|
||||
*/
|
||||
|
||||
/*
|
||||
Per-object speaker controls taken from OAMD metadata: warp mode, trim mode,
|
||||
the three trim levels and the two front-back balances. trim_bypass is indexed
|
||||
by object slot (1..15); slot 0 carries the LFE and is unused.
|
||||
|
||||
warp_mode 0 leaves the floor Y coordinate unchanged; mode 1 maps it through
|
||||
clamp(2Y, 0, 1). Modes 2 and 3 render the 5.1-family and 4.0 layouts through an
|
||||
expanded surround layout (7.1-family, or a rear pair added to 4.0 without a
|
||||
centre or LFE) and fold the rear pair into the target surround pair: mode 2
|
||||
uses the PLIIx coefficients (sqrt(3)/2 and 1/2), mode 3 the Standard (Lo/Ro)
|
||||
coefficients (1 and 0). Layouts without a single surround pair render directly.
|
||||
|
||||
trim_mode selects where the gain comes from: automatic applies the layout
|
||||
position compensation, disabled applies no trim, and explicit applies the
|
||||
position-dependent trim from centre_db / surround_db / height_db. A bypassed
|
||||
object keeps its warp but loses the balance and the trim gain.
|
||||
|
||||
Controls may change between calls; each call's metadata events use the
|
||||
controls passed with that call. A null pointer means warp 0, no trim and no
|
||||
balance.
|
||||
*/
|
||||
typedef enum ejoc_speaker_trim_mode {
|
||||
EJOC_SPEAKER_TRIM_AUTOMATIC = 0,
|
||||
EJOC_SPEAKER_TRIM_DISABLED = 1,
|
||||
EJOC_SPEAKER_TRIM_EXPLICIT = 2
|
||||
} ejoc_speaker_trim_mode;
|
||||
|
||||
typedef struct ejoc_speaker_controls {
|
||||
uint32_t struct_size;
|
||||
uint32_t struct_version;
|
||||
uint32_t warp_mode;
|
||||
uint32_t trim_mode; /* ejoc_speaker_trim_mode */
|
||||
double centre_db;
|
||||
double surround_db; /* positive values are treated as zero */
|
||||
double height_db; /* positive values are treated as zero */
|
||||
double listener_balance; /* [-1, 1] */
|
||||
double overhead_balance; /* [-1, 1] */
|
||||
uint8_t trim_bypass[EJOC_MAX_OBJECTS + 1]; /* per object slot, slot 0 unused */
|
||||
} ejoc_speaker_controls;
|
||||
|
||||
EJOC_API uint32_t EJOC_CALL ejoc_speaker_layout_channel_count(uint32_t speaker_bitfield);
|
||||
EJOC_API ejoc_speaker_renderer_handle EJOC_CALL ejoc_speaker_renderer_create(uint32_t speaker_bitfield);
|
||||
EJOC_API void EJOC_CALL ejoc_speaker_renderer_destroy(ejoc_speaker_renderer_handle handle);
|
||||
@@ -139,6 +258,7 @@ EJOC_API int EJOC_CALL ejoc_speaker_renderer_process(
|
||||
const uint8_t* region_indices,
|
||||
const uint8_t* height_enabled,
|
||||
const double* object_gains,
|
||||
const ejoc_speaker_controls* controls,
|
||||
double* output_interleaved);
|
||||
|
||||
EJOC_API ejoc_binaural_renderer_handle EJOC_CALL ejoc_binaural_renderer_create(void);
|
||||
@@ -188,19 +308,19 @@ per-object whole-QMF-slot delay histories, six first-order image-source early
|
||||
reflections, the shared unitary-FDN late room, the 120-180 Hz LFE low-pass and
|
||||
the 961-sample latency compensation. The caller configures the filterbank
|
||||
tables, the compiled HRTF field and the room constants once, then per 512-sample
|
||||
block updates every source with ejoc_sofa_binaural_set_source() and calls
|
||||
ejoc_sofa_binaural_process(). Process returns the number of trimmed stereo
|
||||
block updates every source with ejoc_jochrtf_set_source() and calls
|
||||
ejoc_jochrtf_process(). Process returns the number of trimmed stereo
|
||||
samples written; the first 961 processed samples across calls are discarded.
|
||||
*/
|
||||
typedef void* ejoc_sofa_binaural_handle;
|
||||
typedef void* ejoc_jochrtf_handle;
|
||||
|
||||
EJOC_API ejoc_sofa_binaural_handle EJOC_CALL ejoc_sofa_binaural_create(void);
|
||||
EJOC_API void EJOC_CALL ejoc_sofa_binaural_destroy(ejoc_sofa_binaural_handle handle);
|
||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_reset(ejoc_sofa_binaural_handle handle);
|
||||
EJOC_API const char* EJOC_CALL ejoc_sofa_binaural_last_error(
|
||||
ejoc_sofa_binaural_handle handle);
|
||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_kernels(
|
||||
ejoc_sofa_binaural_handle handle,
|
||||
EJOC_API ejoc_jochrtf_handle EJOC_CALL ejoc_jochrtf_create(void);
|
||||
EJOC_API void EJOC_CALL ejoc_jochrtf_destroy(ejoc_jochrtf_handle handle);
|
||||
EJOC_API int EJOC_CALL ejoc_jochrtf_reset(ejoc_jochrtf_handle handle);
|
||||
EJOC_API const char* EJOC_CALL ejoc_jochrtf_last_error(
|
||||
ejoc_jochrtf_handle handle);
|
||||
EJOC_API int EJOC_CALL ejoc_jochrtf_configure_kernels(
|
||||
ejoc_jochrtf_handle handle,
|
||||
const double* qmf_analysis,
|
||||
const double* hybrid_low,
|
||||
const int16_t* hybrid_indices,
|
||||
@@ -208,15 +328,15 @@ EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_kernels(
|
||||
uint32_t hybrid_count,
|
||||
const double* qmf_basis,
|
||||
const double* qmf_taps);
|
||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_field(
|
||||
ejoc_sofa_binaural_handle handle,
|
||||
EJOC_API int EJOC_CALL ejoc_jochrtf_configure_field(
|
||||
ejoc_jochrtf_handle handle,
|
||||
const double* coefficients,
|
||||
const double* delay_coefficients,
|
||||
const double* delay_bounds,
|
||||
const double* band_centers,
|
||||
double measurement_radius_m);
|
||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_room(
|
||||
ejoc_sofa_binaural_handle handle,
|
||||
EJOC_API int EJOC_CALL ejoc_jochrtf_configure_room(
|
||||
ejoc_jochrtf_handle handle,
|
||||
const double* room_dims,
|
||||
const double* listener_pos,
|
||||
const double* wall_gains,
|
||||
@@ -229,8 +349,8 @@ EJOC_API int EJOC_CALL ejoc_sofa_binaural_configure_room(
|
||||
const double* allpass_gains,
|
||||
uint32_t enable_early_reflections,
|
||||
uint32_t enable_late_room);
|
||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_set_source(
|
||||
ejoc_sofa_binaural_handle handle,
|
||||
EJOC_API int EJOC_CALL ejoc_jochrtf_set_source(
|
||||
ejoc_jochrtf_handle handle,
|
||||
uint32_t source,
|
||||
const double* position_adm,
|
||||
uint32_t profile,
|
||||
@@ -238,14 +358,14 @@ EJOC_API int EJOC_CALL ejoc_sofa_binaural_set_source(
|
||||
uint32_t enabled,
|
||||
uint32_t special_lfe,
|
||||
uint32_t fade);
|
||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_process(
|
||||
ejoc_sofa_binaural_handle handle,
|
||||
EJOC_API int EJOC_CALL ejoc_jochrtf_process(
|
||||
ejoc_jochrtf_handle handle,
|
||||
const double* input16_interleaved,
|
||||
uint32_t sample_count,
|
||||
double output_gain,
|
||||
double* output_stereo_interleaved);
|
||||
EJOC_API int EJOC_CALL ejoc_sofa_binaural_finish(
|
||||
ejoc_sofa_binaural_handle handle,
|
||||
EJOC_API int EJOC_CALL ejoc_jochrtf_finish(
|
||||
ejoc_jochrtf_handle handle,
|
||||
uint32_t flush_samples,
|
||||
double* output_stereo_interleaved,
|
||||
uint32_t capacity);
|
||||
|
||||
+60
-32
@@ -36,27 +36,30 @@
|
||||
|
||||
#include "joc_version.h"
|
||||
|
||||
#define JOC_ABI_VERSION 5u
|
||||
#define JOC_FRAME_PARAMS_VERSION 1u
|
||||
#define JOC_EMDF_INFO_VERSION 1u
|
||||
#define JOC_TASK_CONFIG_VERSION 3u
|
||||
#define JOC_ABI_VERSION 6u
|
||||
#define JOC_FRAME_PARAMS_VERSION 2u
|
||||
#define JOC_EMDF_INFO_VERSION 2u
|
||||
#define JOC_TASK_CONFIG_VERSION 4u
|
||||
#define JOC_TASK_RESULT_VERSION 2u
|
||||
#define JOC_EVENT_VERSION 1u
|
||||
|
||||
/* JOC_STATIC: this branch exists for building the sources directly into an application, where nothing is imported or exported. */
|
||||
#if defined(_WIN32)
|
||||
#define JOC_CALL __cdecl
|
||||
#else
|
||||
#define JOC_CALL
|
||||
#endif
|
||||
|
||||
#if defined(JOC_STATIC)
|
||||
#define JOC_API
|
||||
#define JOC_CALL __cdecl
|
||||
#elif defined(_WIN32)
|
||||
#if defined(JOC_BUILD_DLL)
|
||||
#define JOC_API __declspec(dllexport)
|
||||
#else
|
||||
#define JOC_API __declspec(dllimport)
|
||||
#endif
|
||||
#define JOC_CALL __cdecl
|
||||
#else
|
||||
#define JOC_API __attribute__((visibility("default")))
|
||||
#define JOC_CALL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -82,7 +85,7 @@ enum {
|
||||
JOC_BINAURAL_QMF_BANDS = 64,
|
||||
JOC_BINAURAL_HYBRID_BANDS = 77,
|
||||
JOC_QMF_HOP_SAMPLES = 64,
|
||||
JOC_BINAURAL_LATENCY_SAMPLES = 961,
|
||||
JOC_BINAURAL_LATENCY_SAMPLES = 961, /* SOFA/.jochrtf and Rosella bank 1 */
|
||||
JOC_LFE_DELAY_SAMPLES = 1217
|
||||
};
|
||||
|
||||
@@ -152,8 +155,7 @@ JOC_API const char* JOC_CALL joc_last_error_detail(void);
|
||||
typedef struct joc_emdf_payload_info {
|
||||
uint8_t id;
|
||||
uint8_t reserved[3];
|
||||
uint16_t sample_offset; /* EMDF outer smpoffst, 11 bits */
|
||||
uint16_t reserved2;
|
||||
uint32_t sample_offset; /* EMDF outer smpoffst: variable_bits(11) */
|
||||
uint32_t bit_offset;
|
||||
uint32_t size; /* payload bytes */
|
||||
} joc_emdf_payload_info;
|
||||
@@ -170,7 +172,8 @@ typedef struct joc_emdf_info {
|
||||
|
||||
/* Per-object ID14/JOC descriptor plus its dequantized matrix.
|
||||
* dq[dp][ch][pb] is zero filled outside [0,n_dpoints) x [0,n_channels) x
|
||||
* [0,n_bands). Absent objects are entirely zero. */
|
||||
* [0,n_bands). Absent objects are entirely zero. offset_ts holds the raw
|
||||
* 5-bit JOC offsets (legal range 0..23, strictly increasing per object). */
|
||||
typedef struct joc_object_params {
|
||||
uint8_t present;
|
||||
uint8_t num_bands_idx;
|
||||
@@ -185,6 +188,26 @@ typedef struct joc_object_params {
|
||||
double dq[JOC_MAX_DPOINTS][JOC_MAX_CORE_CHANNELS][JOC_MAX_PARAMETER_BANDS];
|
||||
} joc_object_params;
|
||||
|
||||
/* Per-frame JOC parse status (joc_frame_params.status). A non-zero status makes
|
||||
* the frame invalid for rendering: the renderer holds the previous matrices or
|
||||
* passes the core PCM through instead of decoding the matrix. Statuses 3 and 7
|
||||
* still carry the complete header and object list for diagnostics; statuses 2
|
||||
* and 4 stop the parse after the failing header field, and 7 stops inside
|
||||
* joc_data, so only the per-object matrices are missing there. */
|
||||
enum {
|
||||
JOC_FRAME_STATUS_OK = 0,
|
||||
JOC_FRAME_STATUS_UNSUPPORTED_DMX = 2, /* joc_dmx_config_idx outside 0..4 */
|
||||
JOC_FRAME_STATUS_OBJECTS_CLAMPED = 3, /* declared object count above 15 */
|
||||
JOC_FRAME_STATUS_BAD_PARAMETER_BAND = 4, /* unknown num_bands index */
|
||||
JOC_FRAME_STATUS_BAD_OFFSET_TS = 5, /* offset_ts outside 0..23 or not */
|
||||
/* strictly increasing */
|
||||
JOC_FRAME_STATUS_TRAILING_DATA = 6, /* bytes after joc_data alignment */
|
||||
/* The ID14 payload ends before its joc_data is complete. The header,
|
||||
* clipgain, sequence counter and object parameters are intact, so the frame
|
||||
* stays classified and is concealed by holding the previous matrices. */
|
||||
JOC_FRAME_STATUS_TRUNCATED = 7
|
||||
};
|
||||
|
||||
typedef struct joc_frame_params {
|
||||
uint32_t struct_size;
|
||||
uint32_t struct_version;
|
||||
@@ -196,21 +219,29 @@ typedef struct joc_frame_params {
|
||||
uint8_t clipgain_x_bits;
|
||||
uint8_t clipgain_y_bits;
|
||||
uint8_t objects_clamped; /* num_objects_bits+1 exceeded 15 */
|
||||
uint32_t seq_count; /* 10-bit JOC sequence counter, parsed only */
|
||||
uint32_t seq_count; /* 10-bit JOC sequence counter */
|
||||
uint32_t present_mask; /* bit i == object i present */
|
||||
uint8_t status; /* JOC_FRAME_STATUS_* */
|
||||
uint8_t reserved[3];
|
||||
uint32_t data_end_bits; /* bit position just after joc_data */
|
||||
uint32_t trailing_bits; /* bits left after joc_data (padding/ext) */
|
||||
uint8_t tail_bytes[8]; /* first up to 8 trailing bytes, for A/B */
|
||||
double clipgain; /* 1 + (y/32) * 2^(x-4), bit-exact */
|
||||
double clipgain; /* 2^(x-4) * (1 + y/32), bit-exact */
|
||||
joc_object_params objects[JOC_MAX_OBJECTS];
|
||||
} joc_frame_params;
|
||||
|
||||
/* Parse an EMDF ID14 (JOC) payload. */
|
||||
/* Parse an EMDF ID14 (JOC) payload. A payload that ends inside joc_data is a
|
||||
* damaged frame rather than a transport error: the call succeeds, the header and
|
||||
* object parameters are filled in, and out_params->status is
|
||||
* JOC_FRAME_STATUS_TRUNCATED. A payload too short for the 12-bit joc_header is
|
||||
* unclassifiable and stays JOC_ERR_BITSTREAM_TRUNCATED. */
|
||||
JOC_API joc_error JOC_CALL joc_parse_id14(const uint8_t* payload, size_t payload_size,
|
||||
joc_frame_params* out_params);
|
||||
|
||||
/* Locate the contiguous JOC EMDF container inside one E-AC-3 syncframe and
|
||||
* parse its ID14 payload. out_emdf may be NULL. */
|
||||
* parse its ID14 payload. out_emdf may be NULL. A damaged ID14 payload is
|
||||
* reported through out_params->status like joc_parse_id14(); an incomplete
|
||||
* container stays a transport error. */
|
||||
JOC_API joc_error JOC_CALL joc_parse_eac3_frame(const uint8_t* frame, size_t frame_size,
|
||||
joc_frame_params* out_params,
|
||||
joc_emdf_info* out_emdf);
|
||||
@@ -231,7 +262,8 @@ JOC_API joc_error JOC_CALL joc_eac3_frame_bytes(const uint8_t* data, size_t size
|
||||
|
||||
/* Strict trailing-bit check for the JOC payload (A/B robustness corpus).
|
||||
* Returns JOC_ERR_BITSTREAM_PADDING when more than 7 bits are left over or the
|
||||
* leftover bits are not zero. */
|
||||
* leftover bits are not zero, and JOC_ERR_BITSTREAM_TRUNCATED when the payload
|
||||
* ends inside joc_data. */
|
||||
JOC_API joc_error JOC_CALL joc_check_id14_padding(const uint8_t* payload, size_t payload_size,
|
||||
uint32_t* out_trailing_bits);
|
||||
|
||||
@@ -358,13 +390,14 @@ typedef enum joc_clip_action {
|
||||
JOC_CLIP_ABORT = 3 /* fail the task */
|
||||
} joc_clip_action;
|
||||
|
||||
/* Compiled-HRTF cache policy for a SOFA input; the .jochrtf itself is an
|
||||
* internal artifact of the compile step. */
|
||||
typedef enum joc_hrtf_cache_policy {
|
||||
JOC_HRTF_CACHE_NONE = 0, /* compile and discard */
|
||||
JOC_HRTF_CACHE_MEMORY = 1, /* compile and keep in this process (default) */
|
||||
JOC_HRTF_CACHE_DISK = 2 /* compile, reuse and write <cache_dir>/<name>.jochrtf */
|
||||
} joc_hrtf_cache_policy;
|
||||
/* Which 64-QMF / 77-hybrid filterbank the Rosella .personalized_headphone path
|
||||
* renders through. The two banks differ in coefficients, hybrid tap count,
|
||||
* high-band slot delay and total latency, so they are not interchangeable; the
|
||||
* SOFA and .jochrtf paths always use JOC_ROSELLA_FILTERBANK_PUBLIC. */
|
||||
typedef enum joc_rosella_filterbank {
|
||||
JOC_ROSELLA_FILTERBANK_PUBLIC = 1, /* 13-tap hybrid, 6-slot delay, 961 samples */
|
||||
JOC_ROSELLA_FILTERBANK_CAPTURED = 2 /* 11-tap hybrid, 3-slot delay, 448 samples */
|
||||
} joc_rosella_filterbank;
|
||||
|
||||
enum { JOC_TASK_F_SKIP_SHA256 = 1u, JOC_TASK_F_KEEP_INTERMEDIATE = 2u,
|
||||
JOC_TASK_F_QUIET = 4u, JOC_TASK_F_METADATA_ONLY = 8u };
|
||||
@@ -415,16 +448,11 @@ typedef struct joc_task_config {
|
||||
|
||||
joc_cancel_token* cancel; /* optional */
|
||||
|
||||
/* Binaural HRTF input (config version 2): when hrtf_sofa_path is set the
|
||||
* library compiles it with hrtf_cache_policy / hrtf_cache_dir / hrtf_radius_m
|
||||
* and hrtf_path is unused. hrtf_path stays the advanced override that reads
|
||||
* a .jochrtf directly. */
|
||||
const char* hrtf_sofa_path; /* SOFA SimpleFreeFieldHRIR input */
|
||||
/* Binaural input (config version 2): a compiled .jochrtf field (hrtf_path)
|
||||
* or a Rosella .personalized_headphone model. */
|
||||
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
|
||||
const char* hrtf_cache_dir; /* disk policy directory */
|
||||
uint32_t hrtf_cache_policy; /* joc_hrtf_cache_policy */
|
||||
uint32_t reserved0;
|
||||
double hrtf_radius_m; /* SOFA measurement-radius shell */
|
||||
uint32_t rosella_filterbank; /* joc_rosella_filterbank; 0 = PUBLIC */
|
||||
uint32_t jochrtf_room; /* non-zero enables the project room */
|
||||
} joc_task_config;
|
||||
|
||||
typedef enum joc_task_status {
|
||||
|
||||
+14
-13
@@ -40,7 +40,8 @@ typedef struct joc_stream joc_stream;
|
||||
typedef enum joc_stream_input {
|
||||
JOC_STREAM_IN_EAC3 = 0, /* bare E-AC-3 syncframes (the metadata stream) */
|
||||
JOC_STREAM_IN_PCM_OBJECTS16 = 1, /* objects16 frames, planar [16][1536] each */
|
||||
JOC_STREAM_IN_CORE_PCM = 3 /* the 5.1 core PCM of the pushed E-AC-3 frames */
|
||||
JOC_STREAM_IN_CORE_PCM = 3, /* the 5.1 core PCM of the pushed E-AC-3 frames */
|
||||
JOC_STREAM_IN_PCM_LAYOUT = 4 /* interleaved 48k f32, mapped by pcm_layout */
|
||||
} joc_stream_input;
|
||||
|
||||
typedef enum joc_stream_output {
|
||||
@@ -63,17 +64,13 @@ typedef struct joc_stream_config {
|
||||
uint32_t object_delay_samples; /* default 1473 */
|
||||
double gain_db; /* default 0 */
|
||||
uint32_t native_threads;
|
||||
uint32_t reserved;
|
||||
/* Binaural HRTF input, the same three shapes joc_task_config accepts: when
|
||||
* hrtf_sofa_path is set the library compiles it with hrtf_cache_policy /
|
||||
* hrtf_cache_dir / hrtf_radius_m and hrtf_path is unused; when
|
||||
* personalized_headphone_path is set the Rosella runtime renders instead.
|
||||
* hrtf_path stays the fallback/advanced input that reads a .jochrtf directly. */
|
||||
const char* hrtf_sofa_path; /* SOFA SimpleFreeFieldHRIR input */
|
||||
uint32_t rosella_filterbank; /* joc_rosella_filterbank; Rosella input, 0 = PUBLIC */
|
||||
/* Binaural input, the same shapes joc_task_config accepts: a compiled
|
||||
* .jochrtf field (hrtf_path) or a Rosella .personalized_headphone model. */
|
||||
const char* personalized_headphone_path; /* Rosella .personalized_headphone input */
|
||||
const char* hrtf_cache_dir; /* disk cache directory for SOFA compilation */
|
||||
uint32_t hrtf_cache_policy; /* joc_hrtf_cache_policy: 0 none, 1 memory, 2 disk */
|
||||
double hrtf_radius_m; /* SOFA measurement-radius shell, default 1.0 */
|
||||
uint32_t jochrtf_room; /* non-zero enables the project room */
|
||||
/* PCM_LAYOUT input: "2.0", "5.1", "7.1", or NULL/"" to infer by channels. */
|
||||
const char* pcm_layout;
|
||||
} joc_stream_config;
|
||||
|
||||
typedef struct joc_stream_buffer {
|
||||
@@ -103,8 +100,9 @@ typedef struct joc_stream_status_info {
|
||||
uint64_t oamd_payloads;
|
||||
uint64_t oamd_transitions;
|
||||
/* Metadata the renderer had to work around, per audio frame: no JOC payload at
|
||||
* all, a declared object count clamped to 15, and a syncframe carrying a second
|
||||
* EMDF container that is not this frame's JOC metadata. */
|
||||
* all, an ID14 payload that ends inside joc_data (that frame holds the previous
|
||||
* matrices), a declared object count clamped to 15, and a syncframe carrying a
|
||||
* second EMDF container that is not this frame's JOC metadata. */
|
||||
uint64_t missing_joc_frames;
|
||||
uint64_t objects_clamped_frames;
|
||||
uint64_t extra_container_frames;
|
||||
@@ -114,6 +112,9 @@ typedef struct joc_stream_status_info {
|
||||
uint64_t bed_mask_mismatch_frames;
|
||||
uint32_t output_channels;
|
||||
uint32_t ended; /* 1 after flush() */
|
||||
/* Appended field: joc_stream_status() accepts the size that ends at `ended`
|
||||
* as well, so a caller built against the previous header keeps working. */
|
||||
uint64_t truncated_joc_frames;
|
||||
} joc_stream_status_info;
|
||||
|
||||
JOC_API joc_error JOC_CALL joc_stream_create(const joc_stream_config* config, joc_stream** out);
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#ifndef JOC_VERSION_H
|
||||
#define JOC_VERSION_H
|
||||
|
||||
#define JOC_VERSION_MAJOR 0
|
||||
#define JOC_VERSION_MINOR 1
|
||||
#define JOC_VERSION_PATCH 0
|
||||
#define JOC_VERSION_STRING "1.0.0"
|
||||
#define JOC_VERSION_MAJOR 1
|
||||
#define JOC_VERSION_MINOR 3
|
||||
#define JOC_VERSION_PATCH 3
|
||||
#define JOC_VERSION_STRING "1.3.3"
|
||||
|
||||
#endif /* JOC_VERSION_H */
|
||||
+119
-4
@@ -54,6 +54,67 @@ std::uint8_t checksum(const std::string& segment) {
|
||||
return static_cast<std::uint8_t>((~sum + 1) & 0xFF);
|
||||
}
|
||||
|
||||
// OAMD trim element warp mode as the dbmd, DAMF and AXML warp field carry it:
|
||||
// 0 normal, 1 warping, 2 downmix_pl2x, 3 downmix_loro.
|
||||
std::uint32_t trim_warp_mode(const oamd::OamdTrim* trim) {
|
||||
if (trim == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return std::min<std::uint32_t>(trim->warp_mode, 3u);
|
||||
}
|
||||
|
||||
// Trim records carry the balance as a sign bit plus a 7-bit magnitude on a
|
||||
// 1/127 grid.
|
||||
std::uint8_t balance_byte(double value) {
|
||||
const long long magnitude =
|
||||
std::min<long long>(pynum::py_round(std::fabs(value) * 127.0), 127);
|
||||
return static_cast<std::uint8_t>(static_cast<unsigned>(magnitude) |
|
||||
(value < 0.0 ? 0x80u : 0x00u));
|
||||
}
|
||||
|
||||
void append_trim_records(const oamd::OamdTrim& trim, std::string* out) {
|
||||
out->append("<DolbyTrimModeSetup>");
|
||||
for (int index = 0; index < oamd::kTrimConfigs; ++index) {
|
||||
const oamd::TrimConfig& record = trim.configs[index];
|
||||
if (record.kind == oamd::TrimConfigKind::kAbsent) {
|
||||
continue;
|
||||
}
|
||||
out->append("<records><type>");
|
||||
out->append(std::to_string(index));
|
||||
out->append("</type>");
|
||||
if (record.kind == oamd::TrimConfigKind::kDefault) {
|
||||
out->append("</records>");
|
||||
continue;
|
||||
}
|
||||
const bool explicit_record = record.kind == oamd::TrimConfigKind::kExplicit;
|
||||
const double centre = explicit_record ? record.centre : 0.0;
|
||||
const double surround = explicit_record ? record.surround : 0.0;
|
||||
const double height = explicit_record ? record.height : 0.0;
|
||||
const double overhead = explicit_record ? record.balance_overhead : 0.0;
|
||||
const double listener = explicit_record ? record.balance_listener : 0.0;
|
||||
out->append("<centerTrim>" + pynum::format_fixed(centre, 6) + "</centerTrim>");
|
||||
out->append("<surroundTrim>" + pynum::format_fixed(surround, 6) + "</surroundTrim>");
|
||||
out->append("<heightTrim>" + pynum::format_fixed(height, 6) + "</heightTrim>");
|
||||
out->append("<balanceOverhead>" + pynum::format_fixed(overhead, 6) +
|
||||
"</balanceOverhead>");
|
||||
out->append("<balanceListener>" + pynum::format_fixed(listener, 6) +
|
||||
"</balanceListener>");
|
||||
out->append("</records>");
|
||||
}
|
||||
out->append("</DolbyTrimModeSetup>");
|
||||
}
|
||||
|
||||
void append_atmos_master_block(const oamd::OamdTrim& trim, std::string* out) {
|
||||
const std::string warp = std::to_string(trim_warp_mode(&trim));
|
||||
out->append("<DolbyAtmosMasterFile><DolbyMasterContentInfo><render_warp_mode>");
|
||||
out->append(warp);
|
||||
out->append("</render_warp_mode></DolbyMasterContentInfo>");
|
||||
append_trim_records(trim, out);
|
||||
out->append("<DolbyWarpMode>");
|
||||
out->append(warp);
|
||||
out->append("</DolbyWarpMode></DolbyAtmosMasterFile>");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string ts(double seconds) {
|
||||
@@ -102,7 +163,8 @@ std::string build_chna() {
|
||||
return out;
|
||||
}
|
||||
|
||||
Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* out) {
|
||||
Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* out,
|
||||
const oamd::OamdTrim* trim) {
|
||||
if (out == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOutput, "null output");
|
||||
}
|
||||
@@ -125,8 +187,8 @@ Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* ou
|
||||
out->push_back(static_cast<char>(checksum(segment7)));
|
||||
|
||||
std::string segment9(248, '\0');
|
||||
const std::string creator = "Created with EAC3JOC";
|
||||
const std::string renderer = "EAC3JOC Python Renderer";
|
||||
const std::string creator = "JustOneCacophony";
|
||||
const std::string renderer = "JustOneCacophony";
|
||||
std::memcpy(&segment9[0], creator.data(), creator.size());
|
||||
std::memcpy(&segment9[32], renderer.data(), renderer.size());
|
||||
segment9[96] = 2;
|
||||
@@ -136,6 +198,10 @@ Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* ou
|
||||
segment9[106] = 0x01;
|
||||
segment9[111] = 0x22;
|
||||
segment9[112] = static_cast<char>(0xFF);
|
||||
// at[152]: the low three bits are the warp code, the other bits belong to
|
||||
// the template's packed fields.
|
||||
segment9[152] = static_cast<char>(
|
||||
(static_cast<unsigned char>(segment9[152]) & 0xF8u) | trim_warp_mode(trim));
|
||||
out->push_back(9);
|
||||
put_u16(out, 248);
|
||||
out->append(segment9);
|
||||
@@ -151,6 +217,37 @@ Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* ou
|
||||
for (std::size_t i = 5u + 262u; i < segment10.size(); ++i) {
|
||||
segment10[i] = static_cast<char>(0x84);
|
||||
}
|
||||
// Nine 15-byte configuration trims start at byte 7; the first byte of each
|
||||
// carries the auto-trim flag in bit 0 (1 = automatic, 0 = manual). A
|
||||
// configuration without an explicit record stays automatic, so a freshly
|
||||
// rendered master opens with automatic trims in the renderer.
|
||||
for (std::size_t layout = 0; layout < static_cast<std::size_t>(oamd::kTrimConfigs);
|
||||
++layout) {
|
||||
const std::size_t base = 7u + 15u * layout;
|
||||
const oamd::TrimConfig* record =
|
||||
trim != nullptr ? &trim->configs[layout] : nullptr;
|
||||
const bool manual = record != nullptr &&
|
||||
(record->kind == oamd::TrimConfigKind::kExplicit ||
|
||||
record->kind == oamd::TrimConfigKind::kDisabled);
|
||||
if (!manual) {
|
||||
segment10[base] =
|
||||
static_cast<char>(static_cast<unsigned char>(segment10[base]) | 0x01u);
|
||||
continue;
|
||||
}
|
||||
segment10[base] = static_cast<char>(static_cast<unsigned char>(segment10[base]) & 0xFEu);
|
||||
const bool explicit_record = record->kind == oamd::TrimConfigKind::kExplicit;
|
||||
const double levels[3] = {explicit_record ? record->centre : 0.0,
|
||||
explicit_record ? record->surround : 0.0,
|
||||
explicit_record ? record->height : 0.0};
|
||||
for (std::size_t index = 0; index < 3; ++index) {
|
||||
const float stored = static_cast<float>(levels[index]);
|
||||
std::memcpy(&segment10[base + 1u + 4u * index], &stored, sizeof(stored));
|
||||
}
|
||||
const double overhead = explicit_record ? record->balance_overhead : 0.0;
|
||||
const double listener = explicit_record ? record->balance_listener : 0.0;
|
||||
segment10[base + 13u] = static_cast<char>(balance_byte(overhead));
|
||||
segment10[base + 14u] = static_cast<char>(balance_byte(listener));
|
||||
}
|
||||
const std::size_t object_modes = 4u + 2u + 1u + 9u * 15u + object_count;
|
||||
for (std::uint32_t i = 10; i < std::min<std::uint32_t>(object_count, 10u + kObjectCount); ++i) {
|
||||
const std::size_t index = object_modes + i;
|
||||
@@ -168,7 +265,8 @@ Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* ou
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
std::string build_axml(const std::vector<Track>& tracks, double duration_sec, std::uint32_t rate) {
|
||||
std::string build_axml(const std::vector<Track>& tracks, double duration_sec, std::uint32_t rate,
|
||||
const oamd::OamdTrim* trim) {
|
||||
const double scale = static_cast<double>(rate);
|
||||
std::string out;
|
||||
out.reserve(64u * 1024u);
|
||||
@@ -265,6 +363,20 @@ std::string build_axml(const std::vector<Track>& tracks, double duration_sec, st
|
||||
out += "<position coordinate=\"Z\">" + pynum::format_fixed(block.z, 10) +
|
||||
"</position>";
|
||||
}
|
||||
const ObjectMetadata& meta = block.meta;
|
||||
if (meta.size[0] > 0.0 || meta.size[1] > 0.0 || meta.size[2] > 0.0) {
|
||||
out += "<width>" + pynum::format_fixed(meta.size[0], 6) + "</width>";
|
||||
out += "<height>" + pynum::format_fixed(meta.size[2], 6) + "</height>";
|
||||
out += "<depth>" + pynum::format_fixed(meta.size[1], 6) + "</depth>";
|
||||
}
|
||||
if (std::fabs(meta.gain - 1.0) > 1e-9) {
|
||||
out += "<gain gainUnit=\"linear\">" + pynum::format_fixed(meta.gain, 6) +
|
||||
"</gain>";
|
||||
}
|
||||
if (meta.divergence > 0.0) {
|
||||
out += "<objectDivergence positionRange=\"" +
|
||||
pynum::format_fixed(meta.divergence, 6) + "\"/>";
|
||||
}
|
||||
out += "<jumpPosition interpolationLength=\"" +
|
||||
pynum::format_fixed(static_cast<double>(block.interpolation_samples) / scale,
|
||||
5) +
|
||||
@@ -325,6 +437,9 @@ std::string build_axml(const std::vector<Track>& tracks, double duration_sec, st
|
||||
"_01</audioTrackFormatIDRef>";
|
||||
out += "</audioStreamFormat>";
|
||||
}
|
||||
if (trim != nullptr) {
|
||||
append_atmos_master_block(*trim, &out);
|
||||
}
|
||||
out += "</audioFormatExtended></format></coreMetadata>";
|
||||
out += "</ebuCoreMain>";
|
||||
return out;
|
||||
|
||||
+19
-2
@@ -7,12 +7,22 @@
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/status.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
|
||||
namespace joc::adm {
|
||||
|
||||
inline constexpr int kObjectCount = 15;
|
||||
inline constexpr std::uint32_t kTrackCount = 25;
|
||||
|
||||
// Per-block OAMD render metadata the ADM audioBlockFormat can express.
|
||||
struct ObjectMetadata {
|
||||
double gain = 1.0;
|
||||
// OAMD order: width, depth, height (relative units 0..1).
|
||||
double size[3] = {0.0, 0.0, 0.0};
|
||||
double divergence = 0.0;
|
||||
bool snap = false;
|
||||
};
|
||||
|
||||
struct Keyframe {
|
||||
std::int64_t rtime_samples = 0;
|
||||
double x = 0.0;
|
||||
@@ -20,6 +30,7 @@ struct Keyframe {
|
||||
double z = 0.0;
|
||||
std::int64_t duration_samples = 0;
|
||||
std::int64_t interpolation_samples = 0;
|
||||
ObjectMetadata meta;
|
||||
};
|
||||
|
||||
struct Track {
|
||||
@@ -34,10 +45,16 @@ enum class BinauralMode : std::uint32_t { Off = 0, Near = 1, Far = 2, Mid = 3, U
|
||||
|
||||
bool binaural_mode_from_name(const char* name, BinauralMode* out);
|
||||
|
||||
std::string build_axml(const std::vector<Track>& tracks, double duration_sec, std::uint32_t rate);
|
||||
// ``trim`` is the OAMD trim element of the programme; when it is present the
|
||||
// AXML carries the Dolby master-file block (content info, trim records, warp
|
||||
// mode) and the dbmd chunk carries the per-configuration records and the warp
|
||||
// code.
|
||||
std::string build_axml(const std::vector<Track>& tracks, double duration_sec, std::uint32_t rate,
|
||||
const oamd::OamdTrim* trim = nullptr);
|
||||
|
||||
std::string build_chna();
|
||||
|
||||
Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* out);
|
||||
Status build_dbmd(std::uint32_t object_count, BinauralMode mode, std::string* out,
|
||||
const oamd::OamdTrim* trim = nullptr);
|
||||
|
||||
} // namespace joc::adm
|
||||
+103
-44
@@ -4,6 +4,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include "foundation/geometry.h"
|
||||
#include "foundation/metadata_timing.h"
|
||||
|
||||
namespace joc::adm {
|
||||
|
||||
@@ -15,15 +16,22 @@ struct Point {
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
std::int64_t interpolation_samples = 0;
|
||||
ObjectMetadata meta;
|
||||
};
|
||||
|
||||
bool same_meta(const ObjectMetadata& left, const ObjectMetadata& right) {
|
||||
return left.gain == right.gain && left.size[0] == right.size[0] &&
|
||||
left.size[1] == right.size[1] && left.size[2] == right.size[2] &&
|
||||
left.divergence == right.divergence && left.snap == right.snap;
|
||||
}
|
||||
|
||||
// otherwise (the reference drops silently).
|
||||
void append_point(std::vector<Point>* points, std::int64_t sample, double x, double y, double z,
|
||||
std::int64_t interpolation_samples) {
|
||||
std::int64_t interpolation_samples, const ObjectMetadata& meta) {
|
||||
if (!points->empty() && sample == points->back().sample) {
|
||||
points->back() = Point{sample, x, y, z, interpolation_samples};
|
||||
points->back() = Point{sample, x, y, z, interpolation_samples, meta};
|
||||
} else if (points->empty() || sample > points->back().sample) {
|
||||
points->push_back(Point{sample, x, y, z, interpolation_samples});
|
||||
points->push_back(Point{sample, x, y, z, interpolation_samples, meta});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +59,7 @@ void points_to_blocks(const std::vector<Point>& points, std::int64_t total_sampl
|
||||
keyframe.z = point.z;
|
||||
keyframe.duration_samples = duration;
|
||||
keyframe.interpolation_samples = std::min(point.interpolation_samples, duration);
|
||||
keyframe.meta = point.meta;
|
||||
out->push_back(keyframe);
|
||||
}
|
||||
}
|
||||
@@ -66,7 +75,7 @@ Status non_monotonic(const char* name, const char* message, int object_index, st
|
||||
} // namespace
|
||||
|
||||
Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
|
||||
std::int64_t update_quantum_samples, std::int64_t object_delay_samples,
|
||||
std::int64_t update_block_samples, std::int64_t object_delay_samples,
|
||||
int object_index, std::vector<Keyframe>* out) {
|
||||
out->clear();
|
||||
const double scale = static_cast<double>(rate);
|
||||
@@ -84,22 +93,22 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
|
||||
std::vector<Point> points;
|
||||
double current[3] = {events[0].x, events[0].y, events[0].z};
|
||||
append_point(&points, 0, current[0], current[1], current[2], 0);
|
||||
ObjectMetadata current_meta = events[0].meta;
|
||||
append_point(&points, 0, current[0], current[1], current[2], 0, current_meta);
|
||||
|
||||
for (std::size_t index = 1; index < events.size(); ++index) {
|
||||
const OamdEvent& event = events[index];
|
||||
const std::int64_t event_start = event.sample + object_delay_samples;
|
||||
const std::int64_t event_start = timing::align_metadata_sample(
|
||||
event.sample + object_delay_samples, update_block_samples);
|
||||
if (event_start >= total_samples) {
|
||||
break;
|
||||
}
|
||||
const std::int64_t effective_ramp =
|
||||
std::max<std::int64_t>(0, event.ramp_samples - update_quantum_samples);
|
||||
const std::int64_t block_start =
|
||||
event_start + (effective_ramp != 0 ? update_quantum_samples : 0);
|
||||
const std::int64_t ramp = std::max<std::int64_t>(0, event.ramp_samples);
|
||||
const std::int64_t block_start = event_start;
|
||||
if (block_start >= total_samples) {
|
||||
break;
|
||||
}
|
||||
const std::int64_t ramp_end = block_start + effective_ramp;
|
||||
const std::int64_t ramp_end = block_start + ramp;
|
||||
|
||||
if (block_start < points.back().sample) {
|
||||
return non_monotonic("non_monotonic_compact_position_updates",
|
||||
@@ -107,11 +116,8 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
block_start, points.back().sample);
|
||||
}
|
||||
if (index + 1 < events.size()) {
|
||||
const std::int64_t next_event_start = events[index + 1].sample + object_delay_samples;
|
||||
const std::int64_t next_effective =
|
||||
std::max<std::int64_t>(0, events[index + 1].ramp_samples - update_quantum_samples);
|
||||
const std::int64_t next_block_start =
|
||||
next_event_start + (next_effective != 0 ? update_quantum_samples : 0);
|
||||
const std::int64_t next_block_start = timing::align_metadata_sample(
|
||||
events[index + 1].sample + object_delay_samples, update_block_samples);
|
||||
if (next_block_start < ramp_end) {
|
||||
return non_monotonic("overlapping_compact_position_ramps",
|
||||
"a new position update arrived before the previous compact "
|
||||
@@ -121,11 +127,10 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
}
|
||||
|
||||
double target[3] = {event.x, event.y, event.z};
|
||||
std::int64_t interpolation = effective_ramp;
|
||||
std::int64_t interpolation = ramp;
|
||||
const std::int64_t available = total_samples - block_start;
|
||||
if (effective_ramp > available) {
|
||||
const double amount =
|
||||
static_cast<double>(available) / static_cast<double>(effective_ramp);
|
||||
if (ramp > available) {
|
||||
const double amount = static_cast<double>(available) / static_cast<double>(ramp);
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
@@ -135,10 +140,12 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
target[2] = z;
|
||||
interpolation = available;
|
||||
}
|
||||
append_point(&points, block_start, target[0], target[1], target[2], interpolation);
|
||||
append_point(&points, block_start, target[0], target[1], target[2], interpolation,
|
||||
event.meta);
|
||||
current[0] = event.x;
|
||||
current[1] = event.y;
|
||||
current[2] = event.z;
|
||||
current_meta = event.meta;
|
||||
}
|
||||
|
||||
points_to_blocks(points, total_samples, out);
|
||||
@@ -147,7 +154,7 @@ Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
}
|
||||
|
||||
Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
|
||||
std::int64_t update_quantum_samples, std::int64_t object_delay_samples,
|
||||
std::int64_t update_block_samples, std::int64_t object_delay_samples,
|
||||
int object_index, std::vector<Keyframe>* out) {
|
||||
out->clear();
|
||||
(void)rate;
|
||||
@@ -160,11 +167,13 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
|
||||
std::vector<Point> points;
|
||||
double current[3] = {events[0].x, events[0].y, events[0].z};
|
||||
append_point(&points, 0, current[0], current[1], current[2], 0);
|
||||
ObjectMetadata current_meta = events[0].meta;
|
||||
append_point(&points, 0, current[0], current[1], current[2], 0, current_meta);
|
||||
|
||||
for (std::size_t index = 1; index < events.size(); ++index) {
|
||||
const OamdEvent& event = events[index];
|
||||
const std::int64_t start = event.sample + object_delay_samples;
|
||||
const std::int64_t start =
|
||||
timing::align_metadata_sample(event.sample + object_delay_samples, update_block_samples);
|
||||
if (start >= total_samples) {
|
||||
break;
|
||||
}
|
||||
@@ -174,22 +183,22 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
points.back().sample);
|
||||
}
|
||||
if (start > points.back().sample) {
|
||||
append_point(&points, start, current[0], current[1], current[2], 0);
|
||||
append_point(&points, start, current[0], current[1], current[2], 0, current_meta);
|
||||
}
|
||||
const std::int64_t effective_ramp =
|
||||
std::max<std::int64_t>(0, event.ramp_samples - update_quantum_samples);
|
||||
if (effective_ramp == 0) {
|
||||
append_point(&points, start, event.x, event.y, event.z, 0);
|
||||
const std::int64_t ramp = std::max<std::int64_t>(0, event.ramp_samples);
|
||||
if (ramp == 0) {
|
||||
append_point(&points, start, event.x, event.y, event.z, 0, event.meta);
|
||||
current[0] = event.x;
|
||||
current[1] = event.y;
|
||||
current[2] = event.z;
|
||||
current_meta = event.meta;
|
||||
continue;
|
||||
}
|
||||
const std::int64_t steps =
|
||||
(effective_ramp + update_quantum_samples - 1) / update_quantum_samples;
|
||||
const std::int64_t end = start + steps * update_quantum_samples;
|
||||
const std::int64_t steps = (ramp + update_block_samples - 1) / update_block_samples;
|
||||
const std::int64_t end = start + steps * update_block_samples;
|
||||
if (index + 1 < events.size()) {
|
||||
const std::int64_t next_start = events[index + 1].sample + object_delay_samples;
|
||||
const std::int64_t next_start = timing::align_metadata_sample(
|
||||
events[index + 1].sample + object_delay_samples, update_block_samples);
|
||||
if (next_start < end) {
|
||||
return non_monotonic("overlapping_position_ramps",
|
||||
"a new position update arrived before the previous ramp "
|
||||
@@ -197,12 +206,12 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
object_index, start, end);
|
||||
}
|
||||
}
|
||||
std::int64_t future = effective_ramp;
|
||||
std::int64_t future = ramp;
|
||||
std::int64_t elapsed = 0;
|
||||
double position[3] = {current[0], current[1], current[2]};
|
||||
while (future > 0) {
|
||||
const double amount =
|
||||
std::min(static_cast<double>(update_quantum_samples) / static_cast<double>(future),
|
||||
std::min(static_cast<double>(update_block_samples) / static_cast<double>(future),
|
||||
1.0);
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
@@ -212,18 +221,19 @@ Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_s
|
||||
position[0] = x;
|
||||
position[1] = y;
|
||||
position[2] = z;
|
||||
elapsed += update_quantum_samples;
|
||||
elapsed += update_block_samples;
|
||||
const std::int64_t sample = start + elapsed;
|
||||
if (sample >= total_samples) {
|
||||
break;
|
||||
}
|
||||
append_point(&points, sample, position[0], position[1], position[2],
|
||||
update_quantum_samples);
|
||||
future -= update_quantum_samples;
|
||||
update_block_samples, event.meta);
|
||||
future -= update_block_samples;
|
||||
}
|
||||
current[0] = event.x;
|
||||
current[1] = event.y;
|
||||
current[2] = event.z;
|
||||
current_meta = event.meta;
|
||||
}
|
||||
|
||||
points_to_blocks(points, total_samples, out);
|
||||
@@ -240,18 +250,55 @@ void TrajectoryBuilder::submit_frame(std::int64_t frame_index, const oamd::OamdU
|
||||
ramp_samples = static_cast<std::int64_t>(update->ramp_duration_samples);
|
||||
}
|
||||
for (int object = 1; object <= kObjectCount; ++object) {
|
||||
if (fixed_[object - 1]) {
|
||||
continue; // 固定 bed 声道:位置由布局给出,不跟 OAMD 更新
|
||||
}
|
||||
const int slot = object - 1;
|
||||
// OAMD block 0 对动态对象显式携带 gain/size/snap;divergence 只在扩展
|
||||
// 元素里出现,缺失时按 0 处理,与 speaker 渲染器的逐 payload 语义一致。
|
||||
if (update != nullptr && update->has_frame_state &&
|
||||
static_cast<std::size_t>(object) < update->frame_state.objects.size()) {
|
||||
const oamd::ObjectElementState& element =
|
||||
update->frame_state.objects[static_cast<std::size_t>(object)];
|
||||
if (!element.blocks.empty() && element.kind == oamd::ObjectKind::kDynamic) {
|
||||
const oamd::ObjectRenderState& render = element.blocks[0].render;
|
||||
ObjectMetadata& meta = meta_[slot];
|
||||
if (render.not_active) {
|
||||
meta.gain = 0.0;
|
||||
} else {
|
||||
meta.gain = static_cast<double>(render.gain_q) / 4096.0;
|
||||
if (render.size_mode == 1u || render.size_mode == 2u) {
|
||||
for (int axis = 0; axis < 3; ++axis) {
|
||||
meta.size[axis] = std::min(
|
||||
std::max(static_cast<double>(render.size_q[axis]) / 32767.0, 0.0),
|
||||
1.0);
|
||||
}
|
||||
} else {
|
||||
meta.size[0] = 0.0;
|
||||
meta.size[1] = 0.0;
|
||||
meta.size[2] = 0.0;
|
||||
}
|
||||
meta.divergence = static_cast<double>(render.divergence_q) / 32767.0;
|
||||
meta.snap = render.snap;
|
||||
}
|
||||
}
|
||||
}
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
geometry::q_to_adm_xyz(state_.q(object, 0), state_.q(object, 1), state_.q(object, 2), &x,
|
||||
&y, &z);
|
||||
const int slot = object - 1;
|
||||
if (!has_previous_[slot] || previous_[slot][0] != x || previous_[slot][1] != y ||
|
||||
previous_[slot][2] != z) {
|
||||
events_[slot].push_back(OamdEvent{event_sample, x, y, z, ramp_samples});
|
||||
const ObjectMetadata& meta = meta_[slot];
|
||||
const bool position_changed =
|
||||
!has_previous_[slot] || previous_[slot][0] != x || previous_[slot][1] != y ||
|
||||
previous_[slot][2] != z;
|
||||
const bool meta_changed = !has_previous_[slot] || !same_meta(previous_meta_[slot], meta);
|
||||
if (position_changed || meta_changed) {
|
||||
events_[slot].push_back(OamdEvent{event_sample, x, y, z, ramp_samples, meta});
|
||||
previous_[slot][0] = x;
|
||||
previous_[slot][1] = y;
|
||||
previous_[slot][2] = z;
|
||||
previous_meta_[slot] = meta;
|
||||
has_previous_[slot] = true;
|
||||
}
|
||||
}
|
||||
@@ -264,11 +311,23 @@ Status TrajectoryBuilder::build(std::int64_t total_samples, TrajectoryMode mode,
|
||||
for (int object = 1; object <= kObjectCount; ++object) {
|
||||
Track track;
|
||||
track.name = "JOC_Object_" + std::to_string(object);
|
||||
if (fixed_[object - 1]) {
|
||||
Keyframe block;
|
||||
block.rtime_samples = 0;
|
||||
block.x = fixed_xyz_[object - 1][0];
|
||||
block.y = fixed_xyz_[object - 1][1];
|
||||
block.z = fixed_xyz_[object - 1][2];
|
||||
block.duration_samples = total_samples;
|
||||
block.interpolation_samples = 0;
|
||||
track.blocks.push_back(block);
|
||||
out->push_back(std::move(track));
|
||||
continue;
|
||||
}
|
||||
const Status status =
|
||||
(mode == TrajectoryMode::Compact)
|
||||
? expand_compact(events_[object - 1], total_samples, rate_, quantum_,
|
||||
? expand_compact(events_[object - 1], total_samples, rate_, block_,
|
||||
object_delay_, object, &track.blocks)
|
||||
: expand_dense64(events_[object - 1], total_samples, rate_, quantum_,
|
||||
: expand_dense64(events_[object - 1], total_samples, rate_, block_,
|
||||
object_delay_, object, &track.blocks);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
|
||||
+24
-5
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "adm/adm_metadata.h"
|
||||
#include "foundation/metadata_timing.h"
|
||||
#include "foundation/status.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
|
||||
@@ -18,6 +19,7 @@ struct OamdEvent {
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
std::int64_t ramp_samples = 0;
|
||||
ObjectMetadata meta;
|
||||
};
|
||||
|
||||
enum class TrajectoryMode { Compact, Dense64 };
|
||||
@@ -26,36 +28,53 @@ enum class TrajectoryMode { Compact, Dense64 };
|
||||
// runs, and records one event per object whenever its coordinates change.
|
||||
class TrajectoryBuilder {
|
||||
public:
|
||||
TrajectoryBuilder(std::uint32_t rate = 48000, std::int64_t update_quantum_samples = 64,
|
||||
TrajectoryBuilder(std::uint32_t rate = 48000,
|
||||
std::int64_t update_block_samples = timing::kMetadataBlockSamples,
|
||||
std::int64_t object_delay_samples = 1473)
|
||||
: rate_(rate),
|
||||
quantum_(update_quantum_samples),
|
||||
block_(update_block_samples),
|
||||
object_delay_(object_delay_samples) {}
|
||||
|
||||
void submit_frame(std::int64_t frame_index, const oamd::OamdUpdate* update, std::int64_t outer_offset);
|
||||
|
||||
Status build(std::int64_t total_samples, TrajectoryMode mode, std::vector<Track>* out) const;
|
||||
|
||||
// bed 声道是固定通道:OAMD 不给位置,整片静止在声明的 bed 方位。
|
||||
void set_fixed_position(int object_index, double x, double y, double z) {
|
||||
if (object_index < 1 || object_index > kObjectCount) {
|
||||
return;
|
||||
}
|
||||
const int slot = object_index - 1;
|
||||
fixed_[slot] = true;
|
||||
fixed_xyz_[slot][0] = x;
|
||||
fixed_xyz_[slot][1] = y;
|
||||
fixed_xyz_[slot][2] = z;
|
||||
}
|
||||
|
||||
const std::vector<OamdEvent>& events(int object_index) const { return events_[object_index]; }
|
||||
std::uint32_t rate() const { return rate_; }
|
||||
std::int64_t object_delay_samples() const { return object_delay_; }
|
||||
|
||||
private:
|
||||
std::uint32_t rate_;
|
||||
std::int64_t quantum_;
|
||||
std::int64_t block_;
|
||||
std::int64_t object_delay_;
|
||||
oamd::OamdState state_;
|
||||
std::vector<OamdEvent> events_[kObjectCount];
|
||||
bool has_previous_[kObjectCount] = {};
|
||||
double previous_[kObjectCount][3] = {};
|
||||
ObjectMetadata meta_[kObjectCount];
|
||||
ObjectMetadata previous_meta_[kObjectCount];
|
||||
bool fixed_[kObjectCount] = {};
|
||||
double fixed_xyz_[kObjectCount][3] = {};
|
||||
};
|
||||
|
||||
Status expand_compact(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
|
||||
std::int64_t update_quantum_samples, std::int64_t object_delay_samples,
|
||||
std::int64_t update_block_samples, std::int64_t object_delay_samples,
|
||||
int object_index, std::vector<Keyframe>* out);
|
||||
|
||||
Status expand_dense64(const std::vector<OamdEvent>& events, std::int64_t total_samples, std::uint32_t rate,
|
||||
std::int64_t update_quantum_samples, std::int64_t object_delay_samples,
|
||||
std::int64_t update_block_samples, std::int64_t object_delay_samples,
|
||||
int object_index, std::vector<Keyframe>* out);
|
||||
|
||||
} // namespace joc::adm
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
@@ -36,16 +37,16 @@ joc::stream::Config to_config(const joc_stream_config& config) {
|
||||
}
|
||||
out.gain_db = config.gain_db;
|
||||
out.native_threads = config.native_threads;
|
||||
// The binaural HRTF inputs of joc_task_config, copied with the same defaults:
|
||||
// the policy is taken verbatim (0 is "none", a real choice, not "unset") and
|
||||
// the radius keeps its documented default of 1.0 when the field is not set.
|
||||
if (config.hrtf_sofa_path != nullptr) { out.hrtf_sofa_path = config.hrtf_sofa_path; }
|
||||
if (config.personalized_headphone_path != nullptr) {
|
||||
out.personalized_headphone_path = config.personalized_headphone_path;
|
||||
}
|
||||
if (config.hrtf_cache_dir != nullptr) { out.hrtf_cache_dir = config.hrtf_cache_dir; }
|
||||
out.hrtf_cache_policy = config.hrtf_cache_policy;
|
||||
if (config.hrtf_radius_m > 0.0) { out.hrtf_radius_m = config.hrtf_radius_m; }
|
||||
// 0 is the documented "off" spelling for the room switch.
|
||||
out.jochrtf_room = config.jochrtf_room;
|
||||
// 0 is "unset" here as well: the Rosella path defaults to the public bank.
|
||||
if (config.rosella_filterbank != 0u) {
|
||||
out.rosella_filterbank = config.rosella_filterbank;
|
||||
}
|
||||
if (config.pcm_layout != nullptr) { out.pcm_layout = config.pcm_layout; }
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -95,6 +96,19 @@ joc_error JOC_CALL joc_stream_push(joc_stream* stream, const joc_stream_buffer*
|
||||
}
|
||||
return pushed;
|
||||
}
|
||||
if (input->kind == JOC_STREAM_IN_PCM_LAYOUT) {
|
||||
if (input->sample_rate != 0u && input->sample_rate != 48000u) {
|
||||
return joc::Status::fail(JOC_ERR_INVALID_ARGUMENT, joc::stage::kRender,
|
||||
"PCM layout input must be 48 kHz");
|
||||
}
|
||||
std::size_t consumed = 0;
|
||||
const joc::Status pushed = stream->instance.push_pcm_layout(
|
||||
input->pcm, input->sample_count, input->channels, &consumed);
|
||||
if (consumed_samples != nullptr) {
|
||||
*consumed_samples = static_cast<std::uint32_t>(consumed);
|
||||
}
|
||||
return pushed;
|
||||
}
|
||||
std::size_t consumed = 0;
|
||||
const std::uint32_t channels = input->channels != 0u ? input->channels : 6u;
|
||||
const joc::Status pushed =
|
||||
@@ -141,8 +155,13 @@ joc_error JOC_CALL joc_stream_reset(joc_stream* stream) {
|
||||
}
|
||||
|
||||
joc_error JOC_CALL joc_stream_status(const joc_stream* stream, joc_stream_status_info* out) {
|
||||
// The info struct only grows by appending fields, so a caller built against
|
||||
// the previous size still gets every field it knows about.
|
||||
constexpr uint32_t kSizeBeforeTruncatedFrames = static_cast<uint32_t>(
|
||||
offsetof(joc_stream_status_info, truncated_joc_frames));
|
||||
if (stream == nullptr || out == nullptr ||
|
||||
out->struct_size != sizeof(joc_stream_status_info)) {
|
||||
(out->struct_size != sizeof(joc_stream_status_info) &&
|
||||
out->struct_size != kSizeBeforeTruncatedFrames)) {
|
||||
return JOC_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
const joc::stream::Info& info = stream->instance.info();
|
||||
@@ -161,6 +180,9 @@ joc_error JOC_CALL joc_stream_status(const joc_stream* stream, joc_stream_status
|
||||
out->bed_mask_mismatch_frames = info.bed_mask_mismatch_frames;
|
||||
out->output_channels = info.output_channels;
|
||||
out->ended = info.ended;
|
||||
if (out->struct_size > kSizeBeforeTruncatedFrames) {
|
||||
out->truncated_joc_frames = info.truncated_joc_frames;
|
||||
}
|
||||
return JOC_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Derived from the upstream native/src/sofa_binaural_renderer.cpp (JustOneCacophony
|
||||
// @ 6bc2c2885666bb151bb66af93472199af9a99b81, sha256 81b485e4c71907672ab308ddc38228
|
||||
// 4acf29161cee93d7906785a4cce58941c7) and a drop-in replacement for it: the same
|
||||
// ejoc_sofa_binaural_* C ABI. The changes are table hoisting, result memoisation,
|
||||
// ejoc_jochrtf_* C ABI. The changes are table hoisting, result memoisation,
|
||||
// input validation and a dispatched SIMD cascade -- no arithmetic is reordered,
|
||||
// reassociated or contracted, so the output is bit-identical to the upstream
|
||||
// implementation (verified: identical FNV-1a over the exact output bit patterns at
|
||||
@@ -1378,7 +1378,7 @@ using ejoc::sofa_binaural::Renderer;
|
||||
|
||||
extern "C" {
|
||||
|
||||
ejoc_sofa_binaural_handle EJOC_CALL ejoc_sofa_binaural_create(void) {
|
||||
ejoc_jochrtf_handle EJOC_CALL ejoc_jochrtf_create(void) {
|
||||
try {
|
||||
return new (std::nothrow) Renderer();
|
||||
} catch (...) {
|
||||
@@ -1386,21 +1386,21 @@ ejoc_sofa_binaural_handle EJOC_CALL ejoc_sofa_binaural_create(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void EJOC_CALL ejoc_sofa_binaural_destroy(ejoc_sofa_binaural_handle handle) {
|
||||
void EJOC_CALL ejoc_jochrtf_destroy(ejoc_jochrtf_handle handle) {
|
||||
delete static_cast<Renderer*>(handle);
|
||||
}
|
||||
|
||||
int EJOC_CALL ejoc_sofa_binaural_reset(ejoc_sofa_binaural_handle handle) {
|
||||
int EJOC_CALL ejoc_jochrtf_reset(ejoc_jochrtf_handle handle) {
|
||||
return handle ? static_cast<Renderer*>(handle)->reset() : -1;
|
||||
}
|
||||
|
||||
const char* EJOC_CALL ejoc_sofa_binaural_last_error(
|
||||
ejoc_sofa_binaural_handle handle) {
|
||||
const char* EJOC_CALL ejoc_jochrtf_last_error(
|
||||
ejoc_jochrtf_handle handle) {
|
||||
return handle ? static_cast<Renderer*>(handle)->error() : "null handle";
|
||||
}
|
||||
|
||||
int EJOC_CALL ejoc_sofa_binaural_configure_kernels(
|
||||
ejoc_sofa_binaural_handle handle, const double* qmf_analysis,
|
||||
int EJOC_CALL ejoc_jochrtf_configure_kernels(
|
||||
ejoc_jochrtf_handle handle, const double* qmf_analysis,
|
||||
const double* hybrid_low, const int16_t* hybrid_indices,
|
||||
const double* hybrid_values, uint32_t hybrid_count, const double* qmf_basis,
|
||||
const double* qmf_taps) {
|
||||
@@ -1409,8 +1409,8 @@ int EJOC_CALL ejoc_sofa_binaural_configure_kernels(
|
||||
qmf_basis, qmf_taps) : -1;
|
||||
}
|
||||
|
||||
int EJOC_CALL ejoc_sofa_binaural_configure_field(
|
||||
ejoc_sofa_binaural_handle handle, const double* coefficients,
|
||||
int EJOC_CALL ejoc_jochrtf_configure_field(
|
||||
ejoc_jochrtf_handle handle, const double* coefficients,
|
||||
const double* delay_coefficients, const double* delay_bounds,
|
||||
const double* band_centers, double measurement_radius_m) {
|
||||
return handle ? static_cast<Renderer*>(handle)->configure_field(
|
||||
@@ -1418,8 +1418,8 @@ int EJOC_CALL ejoc_sofa_binaural_configure_field(
|
||||
measurement_radius_m) : -1;
|
||||
}
|
||||
|
||||
int EJOC_CALL ejoc_sofa_binaural_configure_room(
|
||||
ejoc_sofa_binaural_handle handle, const double* room_dims,
|
||||
int EJOC_CALL ejoc_jochrtf_configure_room(
|
||||
ejoc_jochrtf_handle handle, const double* room_dims,
|
||||
const double* listener_pos, const double* wall_gains, double speed_of_sound,
|
||||
const uint32_t* fdn_delays, const double* fdn_feedback, double damping,
|
||||
double fdn_output_gain, const uint32_t* allpass_delays,
|
||||
@@ -1430,24 +1430,24 @@ int EJOC_CALL ejoc_sofa_binaural_configure_room(
|
||||
enable_early, enable_late) : -1;
|
||||
}
|
||||
|
||||
int EJOC_CALL ejoc_sofa_binaural_set_source(
|
||||
ejoc_sofa_binaural_handle handle, uint32_t source, const double* position_adm,
|
||||
int EJOC_CALL ejoc_jochrtf_set_source(
|
||||
ejoc_jochrtf_handle handle, uint32_t source, const double* position_adm,
|
||||
uint32_t profile, double gain, uint32_t enabled, uint32_t special_lfe,
|
||||
uint32_t fade) {
|
||||
return handle ? static_cast<Renderer*>(handle)->set_source(
|
||||
source, position_adm, profile, gain, enabled, special_lfe, fade) : -1;
|
||||
}
|
||||
|
||||
int EJOC_CALL ejoc_sofa_binaural_process(
|
||||
ejoc_sofa_binaural_handle handle, const double* input16_interleaved,
|
||||
int EJOC_CALL ejoc_jochrtf_process(
|
||||
ejoc_jochrtf_handle handle, const double* input16_interleaved,
|
||||
uint32_t sample_count, double output_gain, double* output_stereo_interleaved) {
|
||||
return handle ? static_cast<Renderer*>(handle)->process(
|
||||
input16_interleaved, sample_count, output_gain, output_stereo_interleaved)
|
||||
: -1;
|
||||
}
|
||||
|
||||
int EJOC_CALL ejoc_sofa_binaural_finish(
|
||||
ejoc_sofa_binaural_handle handle, uint32_t flush_samples,
|
||||
int EJOC_CALL ejoc_jochrtf_finish(
|
||||
ejoc_jochrtf_handle handle, uint32_t flush_samples,
|
||||
double* output_stereo_interleaved, uint32_t capacity) {
|
||||
return handle ? static_cast<Renderer*>(handle)->finish(
|
||||
flush_samples, output_stereo_interleaved, capacity) : -1;
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "binaural/binaural_runtime.h"
|
||||
#include "binaural/jochrtf_runtime.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -29,14 +29,14 @@ bool profile_from_name(const char* name, Profile* out) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SofaBinauralRuntime::~SofaBinauralRuntime() {
|
||||
JochrtfRuntime::~JochrtfRuntime() {
|
||||
if (handle_ != nullptr) {
|
||||
ejoc_sofa_binaural_destroy(handle_);
|
||||
ejoc_jochrtf_destroy(handle_);
|
||||
handle_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Status SofaBinauralRuntime::open(const hrtf::Field& field, const hrtf::Kernels& kernels,
|
||||
Status JochrtfRuntime::open(const hrtf::Field& field, const hrtf::Kernels& kernels,
|
||||
Profile profile, const RoomConstants& room) {
|
||||
if (handle_ != nullptr) {
|
||||
return Status::fail(JOC_ERR_STATE, stage::kRender, "binaural runtime already open");
|
||||
@@ -47,36 +47,36 @@ Status SofaBinauralRuntime::open(const hrtf::Field& field, const hrtf::Kernels&
|
||||
return Status::fail(JOC_ERR_HRTF_FORMAT, stage::kRender,
|
||||
"compiled HRTF field has unexpected array sizes");
|
||||
}
|
||||
handle_ = ejoc_sofa_binaural_create();
|
||||
handle_ = ejoc_jochrtf_create();
|
||||
if (handle_ == nullptr) {
|
||||
return Status::fail(JOC_ERR_OUT_OF_MEMORY, stage::kRender,
|
||||
"ejoc_sofa_binaural_create failed");
|
||||
"ejoc_jochrtf_create failed");
|
||||
}
|
||||
profile_ = profile;
|
||||
|
||||
if (ejoc_sofa_binaural_configure_kernels(
|
||||
if (ejoc_jochrtf_configure_kernels(
|
||||
handle_, kernels.qmf_analysis.data(), kernels.hybrid_low.data(),
|
||||
kernels.hybrid_indices.data(), kernels.hybrid_values.data(), kernels.hybrid_count,
|
||||
kernels.qmf_basis.data(), kernels.qmf_taps.data()) != 0) {
|
||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
||||
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||
return Status::fail(JOC_ERR_HRTF_FORMAT, stage::kRender,
|
||||
std::string("configure_kernels failed: ") +
|
||||
(message != nullptr ? message : "unknown"));
|
||||
}
|
||||
if (ejoc_sofa_binaural_configure_field(handle_, field.coefficients.data(),
|
||||
if (ejoc_jochrtf_configure_field(handle_, field.coefficients.data(),
|
||||
field.delay_coefficients.data(),
|
||||
field.delay_bounds.data(), field.band_centers_hz.data(),
|
||||
field.measurement_radius_m) != 0) {
|
||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
||||
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||
return Status::fail(JOC_ERR_HRTF_FORMAT, stage::kRender,
|
||||
std::string("configure_field failed: ") +
|
||||
(message != nullptr ? message : "unknown"));
|
||||
}
|
||||
if (ejoc_sofa_binaural_configure_room(
|
||||
if (ejoc_jochrtf_configure_room(
|
||||
handle_, room.dims, room.listener, room.walls, room.speed_of_sound, room.fdn_delays,
|
||||
room.fdn_feedback, room.damping, room.fdn_output_gain, room.allpass_delays,
|
||||
room.allpass_gains, room.enable_early_reflections, room.enable_late_room) != 0) {
|
||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
||||
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||
std::string("configure_room failed: ") +
|
||||
(message != nullptr ? message : "unknown"));
|
||||
@@ -95,10 +95,11 @@ Status SofaBinauralRuntime::open(const hrtf::Field& field, const hrtf::Kernels&
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status SofaBinauralRuntime::process_block() {
|
||||
Status JochrtfRuntime::process_block() {
|
||||
double positions[timeline::kTimelineObjects][3] = {};
|
||||
const Status queried = timeline_.positions_at(static_cast<std::int64_t>(processed_samples_),
|
||||
positions);
|
||||
&positions[0][0],
|
||||
timeline::kTimelineObjects);
|
||||
if (!queried.ok()) {
|
||||
return queried;
|
||||
}
|
||||
@@ -106,28 +107,28 @@ Status SofaBinauralRuntime::process_block() {
|
||||
// backend default (fade enabled) applies - the per-object path crossfade is
|
||||
// part of the reference behaviour, not an optional extra.
|
||||
constexpr std::uint32_t kFade = 1u;
|
||||
if (ejoc_sofa_binaural_set_source(handle_, 0u, kLfePosition,
|
||||
if (ejoc_jochrtf_set_source(handle_, 0u, kLfePosition,
|
||||
static_cast<std::uint32_t>(profile_), 1.0, 1u, 1u,
|
||||
kFade) != 0) {
|
||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
||||
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||
std::string("set_source(LFE) failed: ") +
|
||||
(message != nullptr ? message : "unknown"));
|
||||
}
|
||||
for (std::uint32_t source = 0; source < timeline::kTimelineObjects; ++source) {
|
||||
if (ejoc_sofa_binaural_set_source(handle_, source + 1u, positions[source],
|
||||
if (ejoc_jochrtf_set_source(handle_, source + 1u, positions[source],
|
||||
static_cast<std::uint32_t>(profile_), 1.0, 1u, 0u,
|
||||
kFade) != 0) {
|
||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
||||
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||
std::string("set_source(object ") + std::to_string(source + 1u) +
|
||||
") failed: " + (message != nullptr ? message : "unknown"));
|
||||
}
|
||||
}
|
||||
const int trimmed = ejoc_sofa_binaural_process(handle_, staging_.data(), kBlockSamples, 1.0,
|
||||
const int trimmed = ejoc_jochrtf_process(handle_, staging_.data(), kBlockSamples, 1.0,
|
||||
block_output_.data());
|
||||
if (trimmed < 0) {
|
||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
||||
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||
std::string("sofa process failed: ") +
|
||||
(message != nullptr ? message : "unknown"));
|
||||
@@ -142,7 +143,7 @@ Status SofaBinauralRuntime::process_block() {
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status SofaBinauralRuntime::submit_frame(const float* objects16_planar,
|
||||
Status JochrtfRuntime::submit_frame(const float* objects16_planar,
|
||||
const oamd::OamdUpdate* update, std::int64_t frame_index,
|
||||
std::int64_t outer_sample_offset,
|
||||
std::int64_t object_delay_samples) {
|
||||
@@ -186,7 +187,7 @@ Status SofaBinauralRuntime::submit_frame(const float* objects16_planar,
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
std::uint32_t SofaBinauralRuntime::finish_capacity(double tail_seconds) const {
|
||||
std::uint32_t JochrtfRuntime::finish_capacity(double tail_seconds) const {
|
||||
std::int64_t requested = tail_samples_;
|
||||
if (tail_seconds >= 0.0) {
|
||||
requested = static_cast<std::int64_t>(std::ceil(tail_seconds * 48000.0 - 1e-9));
|
||||
@@ -198,14 +199,14 @@ std::uint32_t SofaBinauralRuntime::finish_capacity(double tail_seconds) const {
|
||||
return static_cast<std::uint32_t>(drain);
|
||||
}
|
||||
|
||||
Status SofaBinauralRuntime::reset() {
|
||||
Status JochrtfRuntime::reset() {
|
||||
if (handle_ == nullptr) {
|
||||
return Status::fail(JOC_ERR_STATE, stage::kRender, "binaural runtime is not open");
|
||||
}
|
||||
if (ejoc_sofa_binaural_reset(handle_) != 0) {
|
||||
if (ejoc_jochrtf_reset(handle_) != 0) {
|
||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender, "sofa reset failed");
|
||||
}
|
||||
timeline_ = timeline::OamdPositionTimeline();
|
||||
timeline_.reset();
|
||||
output_.clear();
|
||||
staged_ = 0;
|
||||
input_samples_ = 0;
|
||||
@@ -214,7 +215,7 @@ Status SofaBinauralRuntime::reset() {
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status SofaBinauralRuntime::finish(std::uint32_t flush_samples, std::vector<double>* out) {
|
||||
Status JochrtfRuntime::finish(std::uint32_t flush_samples, std::vector<double>* out) {
|
||||
if (handle_ == nullptr) {
|
||||
return Status::fail(JOC_ERR_STATE, stage::kRender, "binaural runtime is not open");
|
||||
}
|
||||
@@ -230,9 +231,9 @@ Status SofaBinauralRuntime::finish(std::uint32_t flush_samples, std::vector<doub
|
||||
std::uint32_t remaining = flush_samples;
|
||||
while (remaining > 0) {
|
||||
const std::uint32_t request = std::min<std::uint32_t>(remaining, kBlockSamples);
|
||||
const int produced = ejoc_sofa_binaural_finish(handle_, request, chunk.data(), request);
|
||||
const int produced = ejoc_jochrtf_finish(handle_, request, chunk.data(), request);
|
||||
if (produced < 0) {
|
||||
const char* message = ejoc_sofa_binaural_last_error(handle_);
|
||||
const char* message = ejoc_jochrtf_last_error(handle_);
|
||||
return Status::fail(JOC_ERR_RENDER_FAILED, stage::kRender,
|
||||
std::string("sofa finish failed: ") +
|
||||
(message != nullptr ? message : "unknown"));
|
||||
@@ -38,13 +38,13 @@ enum class Profile : std::uint32_t { Near = 0, Mid = 1, Far = 2 };
|
||||
|
||||
bool profile_from_name(const char* name, Profile* out);
|
||||
|
||||
class SofaBinauralRuntime {
|
||||
class JochrtfRuntime {
|
||||
public:
|
||||
SofaBinauralRuntime() = default;
|
||||
~SofaBinauralRuntime();
|
||||
JochrtfRuntime() = default;
|
||||
~JochrtfRuntime();
|
||||
|
||||
SofaBinauralRuntime(const SofaBinauralRuntime&) = delete;
|
||||
SofaBinauralRuntime& operator=(const SofaBinauralRuntime&) = delete;
|
||||
JochrtfRuntime(const JochrtfRuntime&) = delete;
|
||||
JochrtfRuntime& operator=(const JochrtfRuntime&) = delete;
|
||||
|
||||
Status open(const hrtf::Field& field, const hrtf::Kernels& kernels, Profile profile,
|
||||
const RoomConstants& room = RoomConstants{});
|
||||
@@ -72,13 +72,18 @@ public:
|
||||
std::size_t staged_samples() const { return staged_; }
|
||||
const timeline::OamdPositionTimeline& timeline() const { return timeline_; }
|
||||
|
||||
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
|
||||
void set_fixed_position(int object_index, const double position[3]) {
|
||||
timeline_.set_fixed_position(object_index, position);
|
||||
}
|
||||
|
||||
// finish_output_capacity as the reference computes it (plan 21.4).
|
||||
std::uint32_t finish_capacity(double tail_seconds) const;
|
||||
|
||||
private:
|
||||
Status process_block();
|
||||
|
||||
ejoc_sofa_binaural_handle handle_ = nullptr;
|
||||
ejoc_jochrtf_handle handle_ = nullptr;
|
||||
Profile profile_ = Profile::Mid;
|
||||
timeline::OamdPositionTimeline timeline_;
|
||||
std::vector<double> staging_;
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "binaural/multichannel_layout.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace joc::multichannel {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr ChannelSpec kStereo[] = {
|
||||
{"L", false, {-1.0, 1.0, 0.0}},
|
||||
{"R", false, {1.0, 1.0, 0.0}},
|
||||
};
|
||||
|
||||
constexpr ChannelSpec kSurround51[] = {
|
||||
{"L", false, {-1.0, 1.0, 0.0}},
|
||||
{"R", false, {1.0, 1.0, 0.0}},
|
||||
{"C", false, {0.0, 1.0, 0.0}},
|
||||
{"LFE", true, {0.0, 1.0, 0.0}},
|
||||
{"BL", false, {-1.0, -1.0, 0.0}},
|
||||
{"BR", false, {1.0, -1.0, 0.0}},
|
||||
};
|
||||
|
||||
constexpr ChannelSpec kSurround71[] = {
|
||||
{"L", false, {-1.0, 1.0, 0.0}},
|
||||
{"R", false, {1.0, 1.0, 0.0}},
|
||||
{"C", false, {0.0, 1.0, 0.0}},
|
||||
{"LFE", true, {0.0, 1.0, 0.0}},
|
||||
{"BL", false, {-1.0, -1.0, 0.0}},
|
||||
{"BR", false, {1.0, -1.0, 0.0}},
|
||||
{"SL", false, {-1.0, 0.0, 0.0}},
|
||||
{"SR", false, {1.0, 0.0, 0.0}},
|
||||
};
|
||||
|
||||
constexpr Layout kLayouts[] = {
|
||||
{"2.0", 2, kStereo},
|
||||
{"5.1", 6, kSurround51},
|
||||
{"7.1", 8, kSurround71},
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
const Layout* find_layout(const std::string& name) {
|
||||
for (const Layout& layout : kLayouts) {
|
||||
if (name == layout.name) {
|
||||
return &layout;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Layout* detect_layout(int channels) {
|
||||
for (const Layout& layout : kLayouts) {
|
||||
if (layout.channels == channels) {
|
||||
return &layout;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Status object_positions(const Layout& layout, double positions[15][3]) {
|
||||
if (positions == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kFoundation,
|
||||
"object position output is null");
|
||||
}
|
||||
std::memset(positions, 0, sizeof(double) * 15 * 3);
|
||||
int slot = 0;
|
||||
for (int channel = 0; channel < layout.channels; ++channel) {
|
||||
const ChannelSpec& spec = layout.specs[channel];
|
||||
if (spec.lfe) {
|
||||
continue;
|
||||
}
|
||||
if (slot >= 15) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kFoundation,
|
||||
"layout needs more than 15 object channels");
|
||||
}
|
||||
for (int axis = 0; axis < 3; ++axis) {
|
||||
positions[slot][axis] = spec.position[axis];
|
||||
}
|
||||
++slot;
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status pcm_to_objects16(const float* interleaved, std::size_t frames, const Layout& layout,
|
||||
float* objects16_planar) {
|
||||
if (interleaved == nullptr || objects16_planar == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kFoundation,
|
||||
"multichannel PCM buffers are null");
|
||||
}
|
||||
std::memset(objects16_planar, 0, sizeof(float) * frames * 16u);
|
||||
int slot = 0;
|
||||
for (int channel = 0; channel < layout.channels; ++channel) {
|
||||
const ChannelSpec& spec = layout.specs[channel];
|
||||
const int destination = spec.lfe ? 0 : 1 + slot;
|
||||
for (std::size_t frame = 0; frame < frames; ++frame) {
|
||||
objects16_planar[static_cast<std::size_t>(destination) * frames + frame] =
|
||||
interleaved[frame * static_cast<std::size_t>(layout.channels) + channel];
|
||||
}
|
||||
if (!spec.lfe) {
|
||||
++slot;
|
||||
}
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
} // namespace joc::multichannel
|
||||
@@ -0,0 +1,39 @@
|
||||
// Channel order and fixed ADM directions for the multichannel binaural path.
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "foundation/status.h"
|
||||
|
||||
namespace joc::multichannel {
|
||||
|
||||
struct ChannelSpec {
|
||||
const char* label;
|
||||
bool lfe;
|
||||
double position[3];
|
||||
};
|
||||
|
||||
struct Layout {
|
||||
const char* name;
|
||||
int channels;
|
||||
const ChannelSpec* specs;
|
||||
};
|
||||
|
||||
// WAV channel order follows the ffmpeg definitions:
|
||||
// 2.0 = FL FR
|
||||
// 5.1 = FL FR FC LFE BL BR
|
||||
// 7.1 = FL FR FC LFE BL BR SL SR
|
||||
// BL/BR are the rear pair, SL/SR the side pair.
|
||||
const Layout* find_layout(const std::string& name);
|
||||
const Layout* detect_layout(int channels);
|
||||
|
||||
Status object_positions(const Layout& layout, double positions[15][3]);
|
||||
|
||||
// Maps interleaved layout PCM to the JOC source layout: channel 0 is LFE,
|
||||
// channels 1..15 are objects. Unused object channels stay silent.
|
||||
Status pcm_to_objects16(const float* interleaved, std::size_t frames, const Layout& layout,
|
||||
float* objects16_planar);
|
||||
|
||||
} // namespace joc::multichannel
|
||||
@@ -0,0 +1,101 @@
|
||||
#include "binaural/pcm_resampler.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace joc::multichannel {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr double kPi = 3.14159265358979323846264338327950288;
|
||||
constexpr int kHalfTaps = 32;
|
||||
|
||||
double bessel_i0(double value) {
|
||||
double sum = 1.0;
|
||||
double term = 1.0;
|
||||
const double half = value * 0.5;
|
||||
for (int k = 1; k < 32; ++k) {
|
||||
term *= (half / k) * (half / k);
|
||||
sum += term;
|
||||
if (term < sum * 1.0e-12) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
double kaiser_window(double x) {
|
||||
constexpr double kBeta = 8.6;
|
||||
const double ratio = std::max(0.0, 1.0 - (x / kHalfTaps) * (x / kHalfTaps));
|
||||
return bessel_i0(kBeta * std::sqrt(ratio)) / bessel_i0(kBeta);
|
||||
}
|
||||
|
||||
double sinc(double x) {
|
||||
if (std::fabs(x) < 1.0e-12) {
|
||||
return 1.0;
|
||||
}
|
||||
return std::sin(kPi * x) / (kPi * x);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Status resample_interleaved(const float* input, std::size_t frames, int channels,
|
||||
std::uint32_t source_rate, std::uint32_t target_rate,
|
||||
std::vector<float>* output) {
|
||||
if (output == nullptr || channels <= 0 || frames == 0) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kFoundation,
|
||||
"resampler needs samples, channels and an output vector");
|
||||
}
|
||||
if (source_rate == 0 || target_rate == 0) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kFoundation,
|
||||
"resampler sample rates must be positive");
|
||||
}
|
||||
if (source_rate == target_rate) {
|
||||
output->assign(input, input + frames * static_cast<std::size_t>(channels));
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
const double step = static_cast<double>(source_rate) / static_cast<double>(target_rate);
|
||||
const double cutoff = (target_rate < source_rate)
|
||||
? static_cast<double>(target_rate) / source_rate
|
||||
: 1.0;
|
||||
const std::size_t output_frames = static_cast<std::size_t>(std::llround(
|
||||
static_cast<double>(frames) * target_rate / source_rate));
|
||||
output->assign(output_frames * static_cast<std::size_t>(channels), 0.0f);
|
||||
|
||||
for (std::size_t out_frame = 0; out_frame < output_frames; ++out_frame) {
|
||||
const double position = static_cast<double>(out_frame) * step;
|
||||
const std::int64_t base = static_cast<std::int64_t>(std::floor(position));
|
||||
const double fraction = position - static_cast<double>(base);
|
||||
double weights[2 * kHalfTaps + 1];
|
||||
double weight_sum = 0.0;
|
||||
for (int tap = -kHalfTaps + 1; tap <= kHalfTaps; ++tap) {
|
||||
const double distance = tap - fraction;
|
||||
const double weight = cutoff * sinc(cutoff * distance) * kaiser_window(distance);
|
||||
weights[tap + kHalfTaps] = weight;
|
||||
weight_sum += weight;
|
||||
}
|
||||
if (std::fabs(weight_sum) < 1.0e-12) {
|
||||
continue;
|
||||
}
|
||||
for (int channel = 0; channel < channels; ++channel) {
|
||||
double sum = 0.0;
|
||||
for (int tap = -kHalfTaps + 1; tap <= kHalfTaps; ++tap) {
|
||||
const std::int64_t index = base + tap;
|
||||
if (index < 0 || index >= static_cast<std::int64_t>(frames)) {
|
||||
continue;
|
||||
}
|
||||
sum += static_cast<double>(
|
||||
input[static_cast<std::size_t>(index) *
|
||||
static_cast<std::size_t>(channels) +
|
||||
channel]) *
|
||||
weights[tap + kHalfTaps];
|
||||
}
|
||||
output->at(out_frame * static_cast<std::size_t>(channels) + channel) =
|
||||
static_cast<float>(sum / weight_sum);
|
||||
}
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
} // namespace joc::multichannel
|
||||
@@ -0,0 +1,18 @@
|
||||
// Rational sample-rate conversion for the multichannel binaural frontend.
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/status.h"
|
||||
|
||||
namespace joc::multichannel {
|
||||
|
||||
// Resamples interleaved PCM with a windowed-sinc low-pass. The binaural
|
||||
// runtime is native 48 kHz, so any other input rate passes through this first.
|
||||
Status resample_interleaved(const float* input, std::size_t frames, int channels,
|
||||
std::uint32_t source_rate, std::uint32_t target_rate,
|
||||
std::vector<float>* output);
|
||||
|
||||
} // namespace joc::multichannel
|
||||
+43
-97
@@ -4,7 +4,7 @@
|
||||
// choices and defaults, and the same default output naming under output/.
|
||||
//
|
||||
// Options that exist only because this build has no Python side or no Rosella
|
||||
// import chain (--backend python, --sofa-hrtf, --personalized-headphone,
|
||||
// import chain (--backend python, --personalized-headphone,
|
||||
// metadata sidecars) fail with an explicit message instead of being ignored.
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -40,13 +40,12 @@ struct Options {
|
||||
std::string clip_action = "ask";
|
||||
int speaker_metadata_offset = 1473;
|
||||
std::string binaural_mode = "mid";
|
||||
std::string sofa_hrtf;
|
||||
std::string compiled_hrtf_cache;
|
||||
std::string jochrtf_room = "on";
|
||||
std::string personalized_headphone;
|
||||
bool personalized_headphone_used = false;
|
||||
std::string hrtf_cache_policy;
|
||||
std::string hrtf_cache_dir;
|
||||
double hrtf_radius_m = 1.0;
|
||||
int rosella_filterbank = 1;
|
||||
bool rosella_filterbank_set = false;
|
||||
double binaural_tail_seconds = 5.0;
|
||||
double binaural_tail_threshold = 1.0e-8;
|
||||
int binaural_chunk_frames = 64;
|
||||
@@ -84,7 +83,7 @@ struct Options {
|
||||
};
|
||||
|
||||
const char* kLayoutChoices =
|
||||
"2.0 3.0 3.1 4.0 5.0 5.1 5.1.2 5.1.4 6.1 7.0 7.1 7.1.2 7.1.4 9.1.4 9.1.6 22.2";
|
||||
"2.0 3.1 4.0 5.1 7.1 5.1.2 5.1.4 7.1.2 7.1.4 9.1.4 9.1.6 6.0";
|
||||
|
||||
void print_usage() {
|
||||
std::printf(
|
||||
@@ -98,7 +97,7 @@ void print_usage() {
|
||||
" input 输入 .m4a/.eac3/.ec3\n"
|
||||
"\n"
|
||||
"模式(默认输出 ADM BWF):\n"
|
||||
" --speaker-layout L 直接扬声器渲染布局,例如 2.0、5.1、7.1.2\n"
|
||||
" --speaker-layout L 直接扬声器渲染布局,例如 2.0、5.1、6.0、7.1.2\n"
|
||||
" 可选值: %s\n"
|
||||
" --binaural 直接双耳渲染;不生成临时 ADM BWF\n"
|
||||
"\n"
|
||||
@@ -115,13 +114,12 @@ void print_usage() {
|
||||
" --speaker-metadata-offset N 扬声器渲染 metadata 相对帧偏移,默认 1473 samples\n"
|
||||
" --binaural-mode M 双耳渲染模式 off|near|mid|far,默认 mid;\n"
|
||||
" off 仅用于 ADM BWF(关闭 DBMD 双耳提示)\n"
|
||||
" --sofa-hrtf PATH SOFA SimpleFreeFieldHRIR 输入;.jochrtf 由本工具内部编译\n"
|
||||
" --personalized-headphone [PATH] Rosella 个性化模型,默认 "
|
||||
"HRTF/binaural.personalized_headphone\n"
|
||||
" --compiled-hrtf-cache PATH 直接读取 .jochrtf(高级用法,跳过 SOFA 编译)\n"
|
||||
" --hrtf-cache-policy P SOFA 编译缓存策略 none|memory|disk,默认 memory\n"
|
||||
" --hrtf-cache-dir DIR disk cache 目录,默认 <exe>/output/hrtf-cache\n"
|
||||
" --hrtf-radius-m R 选择最近的 SOFA measurement-radius shell,默认 1.0 m\n"
|
||||
" --rosella-filterbank N Rosella 模型滤波器组:1=13 taps/6 slots(默认),\n"
|
||||
" 2=11 taps/3 slots;仅作用于个性化模型\n"
|
||||
" --compiled-hrtf-cache PATH 读取离线编译好的 .jochrtf\n"
|
||||
" --jochrtf-room on|off .jochrtf 的项目房间,默认 on;off 只输出直达声\n"
|
||||
" --binaural-tail-seconds S 双耳 room/filterbank flush 上限,默认 5 秒\n"
|
||||
" --binaural-tail-threshold T 双耳尾声裁切阈值,默认 1e-8;主体至少保留原时长\n"
|
||||
" --binaural-chunk-frames N 双耳内部批处理帧数,默认 64(本构建按 512 块渲染,\n"
|
||||
@@ -227,8 +225,8 @@ void parse_args(const std::vector<std::string>& arguments, Options* options) {
|
||||
to_int(require_value(arguments, &index), "--speaker-metadata-offset"));
|
||||
}
|
||||
else if (arg == "--binaural-mode") { options->binaural_mode = require_value(arguments, &index); }
|
||||
else if (arg == "--sofa-hrtf") { options->sofa_hrtf = require_value(arguments, &index); }
|
||||
else if (arg == "--compiled-hrtf-cache") { options->compiled_hrtf_cache = require_value(arguments, &index); }
|
||||
else if (arg == "--jochrtf-room") { options->jochrtf_room = require_value(arguments, &index); }
|
||||
else if (arg == "--personalized-headphone") {
|
||||
options->personalized_headphone_used = true;
|
||||
// nargs="?": the path is optional, so the next token may be the input.
|
||||
@@ -238,9 +236,11 @@ void parse_args(const std::vector<std::string>& arguments, Options* options) {
|
||||
options->personalized_headphone = require_value(arguments, &index);
|
||||
}
|
||||
}
|
||||
else if (arg == "--hrtf-cache-policy") { options->hrtf_cache_policy = require_value(arguments, &index); }
|
||||
else if (arg == "--hrtf-cache-dir") { options->hrtf_cache_dir = require_value(arguments, &index); }
|
||||
else if (arg == "--hrtf-radius-m") { options->hrtf_radius_m = to_double(require_value(arguments, &index), "--hrtf-radius-m"); }
|
||||
else if (arg == "--rosella-filterbank") {
|
||||
options->rosella_filterbank = static_cast<int>(
|
||||
to_int(require_value(arguments, &index), "--rosella-filterbank"));
|
||||
options->rosella_filterbank_set = true;
|
||||
}
|
||||
else if (arg == "--binaural-tail-seconds") { options->binaural_tail_seconds = to_double(require_value(arguments, &index), "--binaural-tail-seconds"); }
|
||||
else if (arg == "--binaural-tail-threshold") { options->binaural_tail_threshold = to_double(require_value(arguments, &index), "--binaural-tail-threshold"); }
|
||||
else if (arg == "--binaural-chunk-frames") { options->binaural_chunk_frames = static_cast<int>(to_int(require_value(arguments, &index), "--binaural-chunk-frames")); }
|
||||
@@ -336,16 +336,12 @@ std::string find_kernels(const Options& options, const std::string& argv0) {
|
||||
return options.kernels;
|
||||
}
|
||||
|
||||
// Mirrors the reference binaural HRTF resolution (main.py:89-160): the SOFA file
|
||||
// is the user-facing input and the .jochrtf is only its compiled cache. Paths
|
||||
// are anchored at the executable directory, as the reference anchors them at the
|
||||
// project directory.
|
||||
// The binaural input is either an explicitly compiled .jochrtf field or a Rosella
|
||||
// .personalized_headphone model. Paths are anchored at the executable directory,
|
||||
// as the reference anchors them at the project directory.
|
||||
struct HrtfInput {
|
||||
std::string sofa_path; // compile this
|
||||
std::string compiled_path; // or read this .jochrtf directly
|
||||
std::string cache_dir; // disk policy directory
|
||||
std::string compiled_path; // read this .jochrtf
|
||||
std::string personalized_path; // Rosella .personalized_headphone
|
||||
bool disk = false;
|
||||
};
|
||||
|
||||
std::string resolve_compiled_hrtf(const Options& options, const std::string& project_directory) {
|
||||
@@ -353,9 +349,7 @@ std::string resolve_compiled_hrtf(const Options& options, const std::string& pro
|
||||
return options.compiled_hrtf_cache;
|
||||
}
|
||||
const std::string directory_utf8 =
|
||||
options.hrtf_cache_dir.empty()
|
||||
? fs_utf8::from_path(fs_utf8::to_path(project_directory) / "output" / "hrtf-cache")
|
||||
: options.hrtf_cache_dir;
|
||||
fs_utf8::from_path(fs_utf8::to_path(project_directory) / "output" / "hrtf-cache");
|
||||
if (!fs_utf8::is_directory(directory_utf8)) {
|
||||
return std::string();
|
||||
}
|
||||
@@ -369,34 +363,18 @@ std::string resolve_compiled_hrtf(const Options& options, const std::string& pro
|
||||
std::sort(candidates.begin(), candidates.end());
|
||||
if (candidates.size() > 1u) {
|
||||
fail(directory_utf8 +
|
||||
" 下有多个 .jochrtf 缓存,无法自动选择;请用 --sofa-hrtf PATH 或 "
|
||||
"--compiled-hrtf-cache PATH 显式指定");
|
||||
" 下有多个 .jochrtf 缓存,无法自动选择;请用 --compiled-hrtf-cache PATH 显式指定");
|
||||
}
|
||||
return candidates.empty() ? std::string() : fs_utf8::from_path(candidates.front());
|
||||
}
|
||||
|
||||
HrtfInput resolve_hrtf_input(const Options& options, const std::string& project_directory) {
|
||||
HrtfInput input;
|
||||
const std::string default_sofa =
|
||||
fs_utf8::from_path(fs_utf8::to_path(project_directory) / "HRTF" / "binaural.sofa");
|
||||
const std::string default_private = fs_utf8::from_path(
|
||||
fs_utf8::to_path(project_directory) / "HRTF" / "binaural.personalized_headphone");
|
||||
const std::string default_cache_dir =
|
||||
fs_utf8::from_path(fs_utf8::to_path(project_directory) / "output" / "hrtf-cache");
|
||||
|
||||
if (!options.compiled_hrtf_cache.empty() && !options.hrtf_cache_policy.empty()) {
|
||||
fail("显式 .jochrtf 输入不能再指定 --hrtf-cache-policy");
|
||||
}
|
||||
if (!options.compiled_hrtf_cache.empty() && options.hrtf_radius_m != 1.0) {
|
||||
fail("显式 .jochrtf 输入不能再选择 SOFA radius shell");
|
||||
}
|
||||
if (options.personalized_headphone_used &&
|
||||
(!options.hrtf_cache_policy.empty() || !options.hrtf_cache_dir.empty() ||
|
||||
options.hrtf_radius_m != 1.0)) {
|
||||
fail("Rosella 模型输入不能使用 --hrtf-cache-policy/--hrtf-cache-dir/--hrtf-radius-m");
|
||||
}
|
||||
|
||||
std::string sofa = options.sofa_hrtf;
|
||||
std::string compiled = options.compiled_hrtf_cache;
|
||||
std::string personalized =
|
||||
options.personalized_headphone_used ? options.personalized_headphone : std::string();
|
||||
@@ -404,18 +382,13 @@ HrtfInput resolve_hrtf_input(const Options& options, const std::string& project_
|
||||
// "--personalized-headphone" without a path means the project default.
|
||||
personalized = default_private;
|
||||
}
|
||||
if (sofa.empty() && compiled.empty() && personalized.empty()) {
|
||||
// The reference order: the SOFA file, then the unique compiled cache, then the
|
||||
// personalized model.
|
||||
if (fs_utf8::exists(default_sofa)) {
|
||||
sofa = default_sofa;
|
||||
} else {
|
||||
if (compiled.empty() && personalized.empty()) {
|
||||
// The compiled cache, then the personalized model.
|
||||
compiled = resolve_compiled_hrtf(options, project_directory);
|
||||
if (compiled.empty() && fs_utf8::exists(default_private)) {
|
||||
personalized = default_private;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!personalized.empty()) {
|
||||
if (!fs_utf8::exists(personalized)) {
|
||||
fail("双耳模型不存在: " + personalized);
|
||||
@@ -423,37 +396,14 @@ HrtfInput resolve_hrtf_input(const Options& options, const std::string& project_
|
||||
input.personalized_path = personalized;
|
||||
return input;
|
||||
}
|
||||
if (sofa.empty() && compiled.empty()) {
|
||||
if (!options.hrtf_cache_policy.empty() || !options.hrtf_cache_dir.empty() ||
|
||||
options.hrtf_radius_m != 1.0) {
|
||||
fail("HRTF cache/radius 选项需要 --sofa-hrtf");
|
||||
if (compiled.empty()) {
|
||||
fail("--binaural 未找到 HRTF 输入:默认 " + default_private + " 与 " + default_cache_dir +
|
||||
" 下的 .jochrtf 都不存在,请用 --personalized-headphone PATH 或 "
|
||||
"--compiled-hrtf-cache PATH 指定");
|
||||
}
|
||||
fail("--binaural 未找到 HRTF 输入:默认 " + default_sofa + "、" + default_private +
|
||||
" 或 " + default_cache_dir +
|
||||
" 下的 .jochrtf 都不存在,请用 --sofa-hrtf PATH、--personalized-headphone PATH "
|
||||
"或 --compiled-hrtf-cache PATH 指定");
|
||||
}
|
||||
if (sofa.empty() && (!options.hrtf_cache_policy.empty() || !options.hrtf_cache_dir.empty() ||
|
||||
options.hrtf_radius_m != 1.0)) {
|
||||
fail("HRTF cache/radius 选项需要 --sofa-hrtf");
|
||||
}
|
||||
if (sofa.empty()) {
|
||||
input.compiled_path = compiled;
|
||||
return input;
|
||||
}
|
||||
const std::string effective_policy =
|
||||
options.hrtf_cache_policy.empty() ? "memory" : options.hrtf_cache_policy;
|
||||
if (!options.hrtf_cache_dir.empty() && effective_policy != "disk") {
|
||||
fail("--hrtf-cache-dir 需要 SOFA 与 disk cache policy 一起使用");
|
||||
}
|
||||
input.sofa_path = sofa;
|
||||
input.disk = effective_policy == "disk";
|
||||
input.cache_dir = options.hrtf_cache_dir.empty() ? default_cache_dir : options.hrtf_cache_dir;
|
||||
if (!fs_utf8::exists(input.sofa_path)) {
|
||||
fail("SOFA HRTF 不存在: " + input.sofa_path);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
std::uint32_t binaural_mode_value(const std::string& name) {
|
||||
if (name == "off") { return JOC_BINAURAL_OFF; }
|
||||
@@ -558,9 +508,9 @@ int main(int argc, char** argv) {
|
||||
check_choice(options.backend, "--backend", {"auto", "native", "python"});
|
||||
check_choice(options.print_metadata, "--print-metadata", {"none", "summary", "frames"});
|
||||
check_choice(options.metadata_backend, "--metadata-backend", {"auto", "emdf", "sidecar"});
|
||||
if (!options.hrtf_cache_policy.empty()) {
|
||||
check_choice(options.hrtf_cache_policy, "--hrtf-cache-policy",
|
||||
{"none", "memory", "disk"});
|
||||
if (options.rosella_filterbank != 1 && options.rosella_filterbank != 2) {
|
||||
fail("--rosella-filterbank: invalid choice: " +
|
||||
std::to_string(options.rosella_filterbank) + " (choose from 1, 2)");
|
||||
}
|
||||
|
||||
const bool speaker_mode = !options.speaker_layout.empty();
|
||||
@@ -589,13 +539,16 @@ int main(int argc, char** argv) {
|
||||
if (options.speaker_metadata_offset < 0) {
|
||||
fail("speaker-metadata-offset 不能为负数");
|
||||
}
|
||||
check_choice(options.jochrtf_room, "--jochrtf-room", {"on", "off"});
|
||||
const bool hrtf_options_used =
|
||||
!options.sofa_hrtf.empty() || !options.compiled_hrtf_cache.empty() ||
|
||||
options.personalized_headphone_used || !options.hrtf_cache_policy.empty() ||
|
||||
!options.hrtf_cache_dir.empty() || options.hrtf_radius_m != 1.0;
|
||||
!options.compiled_hrtf_cache.empty() || options.personalized_headphone_used ||
|
||||
options.jochrtf_room != "on";
|
||||
if (hrtf_options_used && !binaural_mode) {
|
||||
fail("SOFA/HRTF 选项仅与 --binaural 一起使用");
|
||||
}
|
||||
if (options.rosella_filterbank_set && !binaural_mode) {
|
||||
fail("--rosella-filterbank 仅与 --binaural 一起使用");
|
||||
}
|
||||
if (!std::isfinite(options.binaural_tail_seconds) ||
|
||||
options.binaural_tail_seconds < 0.0) {
|
||||
fail("binaural-tail-seconds 必须是非负有限值");
|
||||
@@ -607,9 +560,6 @@ int main(int argc, char** argv) {
|
||||
if (options.binaural_chunk_frames <= 0) {
|
||||
fail("binaural-chunk-frames 必须大于 0");
|
||||
}
|
||||
if (!std::isfinite(options.hrtf_radius_m) || options.hrtf_radius_m <= 0.0) {
|
||||
fail("hrtf-radius-m 必须是正有限值");
|
||||
}
|
||||
if (options.duration_set && options.duration <= 0.0) {
|
||||
fail("duration 必须大于 0");
|
||||
}
|
||||
@@ -670,6 +620,7 @@ int main(int argc, char** argv) {
|
||||
config.speaker_metadata_offset = static_cast<std::uint32_t>(options.speaker_metadata_offset);
|
||||
config.binaural_mode = binaural_mode_value(options.binaural_mode);
|
||||
config.adm_binaural_mode = binaural_mode_value(options.binaural_mode);
|
||||
config.rosella_filterbank = static_cast<std::uint32_t>(options.rosella_filterbank);
|
||||
config.binaural_tail_seconds = options.binaural_tail_seconds;
|
||||
config.binaural_tail_threshold = options.binaural_tail_threshold;
|
||||
config.binaural_chunk_frames = static_cast<std::uint32_t>(options.binaural_chunk_frames);
|
||||
@@ -697,33 +648,28 @@ int main(int argc, char** argv) {
|
||||
if (options.quiet) { config.flags |= JOC_TASK_F_QUIET; }
|
||||
|
||||
std::string hrtf_path;
|
||||
std::string hrtf_sofa_path;
|
||||
std::string hrtf_cache_dir;
|
||||
std::string personalized_path;
|
||||
std::string kernels_path;
|
||||
if (binaural_mode) {
|
||||
try {
|
||||
const HrtfInput input = resolve_hrtf_input(options, project_directory);
|
||||
hrtf_path = input.compiled_path;
|
||||
hrtf_sofa_path = input.sofa_path;
|
||||
hrtf_cache_dir = input.cache_dir;
|
||||
personalized_path = input.personalized_path;
|
||||
kernels_path = find_kernels(options, arguments.empty() ? std::string()
|
||||
: arguments.front());
|
||||
if (options.rosella_filterbank_set && personalized_path.empty()) {
|
||||
fail("--rosella-filterbank 只作用于 Rosella .personalized_headphone 输入;"
|
||||
"当前 .jochrtf 路径不使用该滤波器组");
|
||||
}
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "joc_cli: error: %s\n", error.what());
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
config.hrtf_path = hrtf_path.empty() ? nullptr : hrtf_path.c_str();
|
||||
config.hrtf_sofa_path = hrtf_sofa_path.empty() ? nullptr : hrtf_sofa_path.c_str();
|
||||
config.hrtf_cache_dir = hrtf_cache_dir.empty() ? nullptr : hrtf_cache_dir.c_str();
|
||||
config.personalized_headphone_path =
|
||||
personalized_path.empty() ? nullptr : personalized_path.c_str();
|
||||
config.hrtf_cache_policy = options.hrtf_cache_policy == "disk" ? JOC_HRTF_CACHE_DISK
|
||||
: options.hrtf_cache_policy == "none" ? JOC_HRTF_CACHE_NONE
|
||||
: JOC_HRTF_CACHE_MEMORY;
|
||||
config.hrtf_radius_m = options.hrtf_radius_m;
|
||||
config.jochrtf_room = options.jochrtf_room == "off" ? 0u : 1u;
|
||||
config.kernels_path = kernels_path.empty() ? nullptr : kernels_path.c_str();
|
||||
|
||||
joc_validation_issue issues[32];
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
// Multichannel PCM WAV -> binaural WAV frontend.
|
||||
//
|
||||
// Ordinary 2.0/5.1/7.1 PCM has no OAMD. Each non-LFE channel is assigned a
|
||||
// fixed ADM direction, the LFE channel goes to source 0, and the resulting
|
||||
// sixteen JOC sources feed the Rosella binaural runtime. The runtime is
|
||||
// native 48 kHz; other input rates are resampled on the way in and the stereo
|
||||
// result is resampled to the requested output rate on the way out.
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "binaural/multichannel_layout.h"
|
||||
#include "binaural/pcm_resampler.h"
|
||||
#include "foundation/status.h"
|
||||
#include "hrtf/rosella_model.h"
|
||||
#include "hrtf/rosella_renderer.h"
|
||||
#include "io/wav_pcm.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr std::uint32_t kFrameSamples = 1536;
|
||||
constexpr std::uint32_t kSourceChannels = 16;
|
||||
constexpr std::uint32_t kTargetRate = 48000;
|
||||
|
||||
void usage() {
|
||||
std::printf(
|
||||
"usage: joc_multichannel INPUT.wav -o OUTPUT.wav [options]\n"
|
||||
" --layout auto|2.0|5.1|7.1 WAV channel layout (auto by channel count)\n"
|
||||
" --model PATH Rosella .personalized_headphone model\n"
|
||||
" --mode near|mid|far Rosella binaural profile (default mid)\n"
|
||||
" --filterbank 1|2 Rosella filterbank (default 1)\n"
|
||||
" --tail-seconds SECONDS room tail (default 2.0)\n"
|
||||
" --output-rate 48000|input|N output rate (default 48000; non-48k adds\n"
|
||||
" a second resampling pass)\n"
|
||||
" --list-layouts\n"
|
||||
"\n"
|
||||
"Prefer a 48 kHz float32 WAV; let ffmpeg/libsoxr do the one conversion:\n"
|
||||
" ffmpeg -i INPUT -af \"aresample=resampler=soxr:precision=28:osr=48000\" "
|
||||
"-c:a pcm_f32le OUT.wav\n"
|
||||
"44.1/88.2/176.4 or 48/96/192 kHz accepted; non-48k is converted once in.\n");
|
||||
}
|
||||
|
||||
std::int16_t q_for_position(double value) {
|
||||
if (value <= -0.999) {
|
||||
return 0;
|
||||
}
|
||||
if (value >= 0.999) {
|
||||
return 32767;
|
||||
}
|
||||
return 16384;
|
||||
}
|
||||
|
||||
void fill_initial_update(const joc::multichannel::Layout& layout, joc::oamd::OamdUpdate* update) {
|
||||
update->has_frame_state = true;
|
||||
update->object_count = kSourceChannels;
|
||||
update->frame_state.object_count = kSourceChannels;
|
||||
update->frame_state.block_count = 1;
|
||||
update->frame_state.blocks.resize(1);
|
||||
update->frame_state.objects.resize(kSourceChannels);
|
||||
double positions[15][3];
|
||||
const joc::Status status = joc::multichannel::object_positions(layout, positions);
|
||||
if (!status.ok()) {
|
||||
return;
|
||||
}
|
||||
for (int object = 0; object < static_cast<int>(kSourceChannels); ++object) {
|
||||
joc::oamd::ObjectElementState& element = update->frame_state.objects[object];
|
||||
element.kind = object == 0 ? joc::oamd::ObjectKind::kBed
|
||||
: joc::oamd::ObjectKind::kDynamic;
|
||||
element.blocks.resize(1);
|
||||
joc::oamd::ObjectRenderState& render = element.blocks[0].render;
|
||||
render.not_active = false;
|
||||
render.gain_q = 4096;
|
||||
render.priority_q = 32767;
|
||||
render.enable_elevation = true;
|
||||
double x = 0.0;
|
||||
double y = 1.0;
|
||||
double z = 0.0;
|
||||
if (object > 0) {
|
||||
x = positions[object - 1][0];
|
||||
y = positions[object - 1][1];
|
||||
z = positions[object - 1][2];
|
||||
}
|
||||
render.qx = q_for_position(x);
|
||||
render.qy = q_for_position(-y);
|
||||
render.qz = static_cast<std::int32_t>(std::llround(z * 32767.0));
|
||||
}
|
||||
}
|
||||
|
||||
std::string model_default() {
|
||||
return "HRTF/binaural.personalized_headphone";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string input;
|
||||
std::string output;
|
||||
std::string layout_name = "auto";
|
||||
std::string model_path = model_default();
|
||||
std::string mode = "mid";
|
||||
int filterbank = 1;
|
||||
double tail_seconds = 2.0;
|
||||
std::string output_rate = "48000";
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
const std::string arg = argv[i];
|
||||
const auto next = [&](const char* option) -> std::string {
|
||||
if (i + 1 >= argc) {
|
||||
std::fprintf(stderr, "missing value for %s\n", option);
|
||||
std::exit(2);
|
||||
}
|
||||
return argv[++i];
|
||||
};
|
||||
if (arg == "--layout") {
|
||||
layout_name = next("--layout");
|
||||
} else if (arg == "--model") {
|
||||
model_path = next("--model");
|
||||
} else if (arg == "--mode") {
|
||||
mode = next("--mode");
|
||||
} else if (arg == "--filterbank") {
|
||||
filterbank = std::stoi(next("--filterbank"));
|
||||
} else if (arg == "--tail-seconds") {
|
||||
tail_seconds = std::stod(next("--tail-seconds"));
|
||||
} else if (arg == "--output-rate") {
|
||||
output_rate = next("--output-rate");
|
||||
} else if (arg == "--list-layouts") {
|
||||
std::printf("2.0: 2 channels\n5.1: 6 channels\n7.1: 8 channels\n");
|
||||
return 0;
|
||||
} else if (arg == "-o" || arg == "--output") {
|
||||
output = next("-o");
|
||||
} else if (arg == "-h" || arg == "--help") {
|
||||
usage();
|
||||
return 0;
|
||||
} else if (!arg.empty() && arg[0] == '-') {
|
||||
std::fprintf(stderr, "unknown option: %s\n", arg.c_str());
|
||||
return 2;
|
||||
} else if (input.empty()) {
|
||||
input = arg;
|
||||
} else {
|
||||
std::fprintf(stderr, "unexpected argument: %s\n", arg.c_str());
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if (input.empty()) {
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
if (output.empty()) {
|
||||
output = input + ".binaural.wav";
|
||||
}
|
||||
|
||||
joc::io::WavAudio wav;
|
||||
joc::Status status = joc::io::read_wav_file(input, &wav);
|
||||
if (!status.ok()) {
|
||||
std::fprintf(stderr, "read: %s\n", status.message().c_str());
|
||||
return 1;
|
||||
}
|
||||
const joc::multichannel::Layout* layout =
|
||||
(layout_name == "auto") ? joc::multichannel::detect_layout(wav.channels)
|
||||
: joc::multichannel::find_layout(layout_name);
|
||||
if (layout == nullptr) {
|
||||
std::fprintf(stderr, "unsupported layout: %s (%u channels)\n", layout_name.c_str(),
|
||||
static_cast<unsigned>(wav.channels));
|
||||
return 2;
|
||||
}
|
||||
if (wav.channels != layout->channels) {
|
||||
std::fprintf(stderr, "layout %s expects %d channels, WAV has %u\n", layout->name,
|
||||
layout->channels, static_cast<unsigned>(wav.channels));
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::vector<float> pcm48;
|
||||
if (wav.sample_rate == kTargetRate) {
|
||||
pcm48 = wav.samples;
|
||||
} else {
|
||||
std::fprintf(
|
||||
stderr,
|
||||
"warning: input is %u Hz and was converted once to 48000 Hz; prefer "
|
||||
"ffmpeg/libsoxr to produce 48 kHz float32 first:\n"
|
||||
" ffmpeg -i INPUT -af \"aresample=resampler=soxr:precision=28:osr=48000\" "
|
||||
"-c:a pcm_f32le OUT.wav\n",
|
||||
static_cast<unsigned>(wav.sample_rate));
|
||||
status = joc::multichannel::resample_interleaved(
|
||||
wav.samples.data(), wav.samples.size() / wav.channels, wav.channels,
|
||||
wav.sample_rate, kTargetRate, &pcm48);
|
||||
if (!status.ok()) {
|
||||
std::fprintf(stderr, "resample: %s\n", status.message().c_str());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
const std::size_t frames = pcm48.size() / wav.channels;
|
||||
|
||||
joc::hrtf::RosellaModel model;
|
||||
status = joc::hrtf::load_personalized_headphone(model_path, &model);
|
||||
if (!status.ok()) {
|
||||
std::fprintf(stderr, "model: %s\n", status.message().c_str());
|
||||
return 1;
|
||||
}
|
||||
joc::hrtf::RosellaRenderOptions options;
|
||||
options.profile = (mode == "near") ? joc::hrtf::RosellaProfile::Near
|
||||
: (mode == "far") ? joc::hrtf::RosellaProfile::Far
|
||||
: joc::hrtf::RosellaProfile::Mid;
|
||||
options.bank = (filterbank == 2) ? joc::hrtf::RosellaBankKind::Captured
|
||||
: joc::hrtf::RosellaBankKind::Public;
|
||||
options.tail_seconds = tail_seconds;
|
||||
joc::hrtf::RosellaRuntime runtime;
|
||||
status = runtime.open(model, options);
|
||||
if (!status.ok()) {
|
||||
std::fprintf(stderr, "open: %s\n", status.message().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
joc::oamd::OamdUpdate initial{};
|
||||
fill_initial_update(*layout, &initial);
|
||||
std::vector<float> objects16(kSourceChannels * kFrameSamples, 0.0f);
|
||||
std::vector<double> rendered;
|
||||
for (std::size_t start = 0, frame = 0; start < frames; start += kFrameSamples, ++frame) {
|
||||
const std::size_t count = std::min<std::size_t>(kFrameSamples, frames - start);
|
||||
std::fill(objects16.begin(), objects16.end(), 0.0f);
|
||||
for (int channel = 0; channel < layout->channels; ++channel) {
|
||||
const joc::multichannel::ChannelSpec& spec = layout->specs[channel];
|
||||
int destination = 0;
|
||||
if (!spec.lfe) {
|
||||
destination = 1;
|
||||
for (int previous = 0; previous < channel; ++previous) {
|
||||
if (!layout->specs[previous].lfe) {
|
||||
++destination;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (std::size_t sample = 0; sample < count; ++sample) {
|
||||
objects16[static_cast<std::size_t>(destination) * kFrameSamples + sample] =
|
||||
pcm48[(start + sample) * layout->channels + channel];
|
||||
}
|
||||
}
|
||||
status = runtime.submit_frame(objects16.data(), frame == 0 ? &initial : nullptr,
|
||||
static_cast<std::int64_t>(frame), 0, 0);
|
||||
if (!status.ok()) {
|
||||
std::fprintf(stderr, "render: %s\n", status.message().c_str());
|
||||
return 1;
|
||||
}
|
||||
std::vector<double> chunk;
|
||||
runtime.take_output(&chunk);
|
||||
rendered.insert(rendered.end(), chunk.begin(), chunk.end());
|
||||
}
|
||||
std::vector<double> tail;
|
||||
status = runtime.finish(runtime.finish_capacity(tail_seconds), &tail);
|
||||
if (!status.ok()) {
|
||||
std::fprintf(stderr, "finish: %s\n", status.message().c_str());
|
||||
return 1;
|
||||
}
|
||||
rendered.insert(rendered.end(), tail.begin(), tail.end());
|
||||
|
||||
std::vector<float> stereo(rendered.size());
|
||||
for (std::size_t index = 0; index < rendered.size(); ++index) {
|
||||
stereo[index] = static_cast<float>(rendered[index]);
|
||||
}
|
||||
std::uint32_t target_rate = wav.sample_rate;
|
||||
if (output_rate == "48k" || output_rate == "48000") {
|
||||
target_rate = kTargetRate;
|
||||
} else if (output_rate != "input") {
|
||||
target_rate = static_cast<std::uint32_t>(std::stoul(output_rate));
|
||||
}
|
||||
if (target_rate != kTargetRate) {
|
||||
std::fprintf(stderr,
|
||||
"warning: non-48k output adds a second resampling pass; the "
|
||||
"native binaural output rate is 48000 Hz\n");
|
||||
std::vector<float> converted;
|
||||
status = joc::multichannel::resample_interleaved(
|
||||
stereo.data(), stereo.size() / 2, 2, kTargetRate, target_rate, &converted);
|
||||
if (!status.ok()) {
|
||||
std::fprintf(stderr, "output resample: %s\n", status.message().c_str());
|
||||
return 1;
|
||||
}
|
||||
stereo.swap(converted);
|
||||
}
|
||||
status = joc::io::write_wav_float32(output, target_rate, 2, stereo.data(),
|
||||
stereo.size() / 2);
|
||||
if (!status.ok()) {
|
||||
std::fprintf(stderr, "write: %s\n", status.message().c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("input: %s (%u ch, %u Hz, %zu frames)\n", input.c_str(),
|
||||
static_cast<unsigned>(wav.channels), static_cast<unsigned>(wav.sample_rate),
|
||||
frames);
|
||||
std::printf("layout: %s\n", layout->name);
|
||||
std::printf("output: %s (%u Hz, %zu frames)\n", output.c_str(),
|
||||
static_cast<unsigned>(target_rate), stereo.size() / 2);
|
||||
return 0;
|
||||
}
|
||||
@@ -102,9 +102,15 @@ Status parse_at(const std::uint8_t* data, std::size_t size, std::size_t start_bi
|
||||
}
|
||||
|
||||
const std::uint32_t has_sample_offset = reader.read(1);
|
||||
std::uint16_t sample_offset = 0;
|
||||
std::uint32_t sample_offset = 0;
|
||||
if (has_sample_offset != 0u) {
|
||||
sample_offset = static_cast<std::uint16_t>(reader.read(12) >> 1);
|
||||
std::uint32_t value = 0;
|
||||
if (!bits::variable_bits(reader, 11, 8, &value)) {
|
||||
return reader.error() == JOC_ERR_BITSTREAM_TRUNCATED
|
||||
? truncated_fail(reader)
|
||||
: syntax_fail(reader.error_message());
|
||||
}
|
||||
sample_offset = value;
|
||||
}
|
||||
if (reader.read(1) != 0u) {
|
||||
std::uint32_t ignored = 0;
|
||||
|
||||
@@ -17,7 +17,7 @@ inline constexpr std::size_t kMaxPayloads = JOC_MAX_EMDF_PAYLOADS;
|
||||
|
||||
struct Payload {
|
||||
std::uint8_t id = 0;
|
||||
std::uint16_t sample_offset = 0;
|
||||
std::uint32_t sample_offset = 0; // EMDF outer smpoffst: variable_bits(11)
|
||||
std::size_t bit_offset = 0; // MSB-first bit position of the payload bytes
|
||||
std::size_t size = 0; // payload byte count
|
||||
// Payload configuration data (ETSI TS 102 366 H.2.2.3). Spec section 8.2 and
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Port of src/oamd_tracks.py align_metadata_sample: an OAMD position update is
|
||||
// scheduled on the renderer's processing-block grid, the same 32-sample grid the
|
||||
// speaker control blocks use. It lives in foundation because both the ADM track
|
||||
// builder and the object position timeline need it, and the timeline must not
|
||||
// depend on output.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace joc::timing {
|
||||
|
||||
inline constexpr std::int64_t kMetadataBlockSamples = 32;
|
||||
|
||||
// Nearest block boundary, ties towards the earlier block; the negative branch
|
||||
// floors like the reference's Python `//`.
|
||||
inline std::int64_t align_metadata_sample(std::int64_t sample,
|
||||
std::int64_t block_samples = kMetadataBlockSamples) {
|
||||
const std::int64_t numerator = sample + block_samples / 2 - 1;
|
||||
const std::int64_t quotient =
|
||||
numerator >= 0 ? numerator / block_samples
|
||||
: -((-numerator + block_samples - 1) / block_samples);
|
||||
return block_samples * quotient;
|
||||
}
|
||||
|
||||
} // namespace joc::timing
|
||||
@@ -7,10 +7,6 @@
|
||||
|
||||
#include "hrtf/jochrtf.h"
|
||||
|
||||
// Public 64-QMF / 77-hybrid filterbank, shared by the SOFA field compiler and the
|
||||
// Rosella renderer (upstream public_filterbank.py and rosella_filterbank.py are
|
||||
// the same bank). Everything is float64/complex128, as the reference computes it,
|
||||
// and the stateful half-steps are exposed because Rosella drives them directly.
|
||||
namespace joc::hrtf {
|
||||
|
||||
inline constexpr int kQmfBands = 64;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
#include "hrtf/rosella_bank.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "hrtf/rosella_filterbank.h"
|
||||
|
||||
namespace joc::hrtf {
|
||||
namespace {
|
||||
|
||||
// The shared public bank. It is also what the SOFA field compiler runs, and it
|
||||
// is the bank the Rosella renderer used before the Rosella-specific one was
|
||||
// captured.
|
||||
class PublicBank final : public RosellaBank {
|
||||
public:
|
||||
explicit PublicBank(std::size_t channels) : bank_(builtin_kernels(), channels) {}
|
||||
|
||||
void reset() override { bank_.reset(); }
|
||||
|
||||
void analyze_qmf(const std::vector<double>& hops, std::size_t slots,
|
||||
std::vector<Complex>* qmf) override {
|
||||
bank_.analyze_qmf(hops, slots, qmf);
|
||||
}
|
||||
|
||||
void analyze_hybrid(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<Complex>* hybrid) override {
|
||||
bank_.analyze_hybrid(qmf, slots, hybrid);
|
||||
}
|
||||
|
||||
void synthesize_hybrid(const std::vector<Complex>& hybrid, std::size_t slots,
|
||||
std::vector<Complex>* qmf) override {
|
||||
bank_.synthesize_hybrid(hybrid, slots, qmf);
|
||||
}
|
||||
|
||||
void synthesize_qmf(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<double>* hops) override {
|
||||
bank_.synthesize_qmf(qmf, slots, hops);
|
||||
}
|
||||
|
||||
private:
|
||||
PublicFilterbank bank_;
|
||||
};
|
||||
|
||||
// The bank captured from the Rosella headphone renderer.
|
||||
class CapturedBank final : public RosellaBank {
|
||||
public:
|
||||
explicit CapturedBank(std::size_t channels) : bank_(channels) {}
|
||||
|
||||
void reset() override { bank_.reset(); }
|
||||
|
||||
void analyze_qmf(const std::vector<double>& hops, std::size_t slots,
|
||||
std::vector<Complex>* qmf) override {
|
||||
bank_.analyze_qmf(hops, slots, qmf);
|
||||
}
|
||||
|
||||
void analyze_hybrid(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<Complex>* hybrid) override {
|
||||
bank_.analyze_hybrid(qmf, slots, hybrid);
|
||||
}
|
||||
|
||||
void synthesize_hybrid(const std::vector<Complex>& hybrid, std::size_t slots,
|
||||
std::vector<Complex>* qmf) override {
|
||||
bank_.synthesize_hybrid(hybrid, slots, qmf);
|
||||
}
|
||||
|
||||
void synthesize_qmf(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<double>* hops) override {
|
||||
bank_.synthesize_qmf(qmf, slots, hops);
|
||||
}
|
||||
|
||||
private:
|
||||
RosellaFilterbank bank_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::uint32_t rosella_bank_latency(RosellaBankKind kind) {
|
||||
return kind == RosellaBankKind::Captured
|
||||
? static_cast<std::uint32_t>(RosellaFilterbank::kLatencySamples)
|
||||
: static_cast<std::uint32_t>(kLatencySamples);
|
||||
}
|
||||
|
||||
std::unique_ptr<RosellaBank> RosellaBank::create(RosellaBankKind kind, std::size_t channels) {
|
||||
if (kind == RosellaBankKind::Captured) {
|
||||
return std::make_unique<CapturedBank>(channels);
|
||||
}
|
||||
return std::make_unique<PublicBank>(channels);
|
||||
}
|
||||
|
||||
} // namespace joc::hrtf
|
||||
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "hrtf/public_filterbank.h"
|
||||
|
||||
namespace joc::hrtf {
|
||||
|
||||
// Which 64-QMF / 77-hybrid bank the Rosella renderer runs. The two are not
|
||||
// interchangeable: the QMF prototype, the hybrid tap count, the high-band slot
|
||||
// delay and the analysis/synthesis latency all differ, so each bank keeps its own
|
||||
// tables and its own state.
|
||||
enum class RosellaBankKind : std::int32_t {
|
||||
Public = 1, // shared bank: 13-tap hybrid, 6-slot delay, 961 samples
|
||||
Captured = 2, // Rosella bank: 11-tap hybrid, 3-slot delay, 448 samples
|
||||
};
|
||||
|
||||
// Analysis/synthesis latency of `kind` at 48 kHz, in samples.
|
||||
std::uint32_t rosella_bank_latency(RosellaBankKind kind);
|
||||
|
||||
// The four stateful half-steps of either bank, in the order the reference runs
|
||||
// them. Hops and QMF data are [slots, channels, 64], hybrid data is
|
||||
// [slots, channels, 77]. State is per instance, so the analysis bank of a
|
||||
// runtime and its synthesis bank never share buffers.
|
||||
class RosellaBank {
|
||||
public:
|
||||
// `kind` must name one of the enumerators; anything else selects Public.
|
||||
static std::unique_ptr<RosellaBank> create(RosellaBankKind kind, std::size_t channels);
|
||||
|
||||
RosellaBank() = default;
|
||||
RosellaBank(const RosellaBank&) = delete;
|
||||
RosellaBank& operator=(const RosellaBank&) = delete;
|
||||
virtual ~RosellaBank() = default;
|
||||
|
||||
virtual void reset() = 0;
|
||||
|
||||
virtual void analyze_qmf(const std::vector<double>& hops, std::size_t slots,
|
||||
std::vector<Complex>* qmf) = 0;
|
||||
virtual void analyze_hybrid(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<Complex>* hybrid) = 0;
|
||||
virtual void synthesize_hybrid(const std::vector<Complex>& hybrid, std::size_t slots,
|
||||
std::vector<Complex>* qmf) = 0;
|
||||
virtual void synthesize_qmf(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<double>* hops) = 0;
|
||||
};
|
||||
|
||||
} // namespace joc::hrtf
|
||||
@@ -0,0 +1,173 @@
|
||||
#include "hrtf/rosella_filterbank.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include "foundation/fft.h"
|
||||
#include "hrtf/rosella_filterbank_tables.h"
|
||||
|
||||
namespace joc::hrtf {
|
||||
namespace {
|
||||
|
||||
constexpr std::size_t kBands = 64;
|
||||
constexpr std::size_t kQmfTaps = 10;
|
||||
constexpr std::size_t kHybridTaps = 11;
|
||||
constexpr std::size_t kHybridDelay = 3;
|
||||
constexpr std::array<std::size_t, 16> kHybridOrder = {0, 7, 1, 6, 2, 9, 3, 4,
|
||||
10, 5, 11, 15, 8, 12, 13, 14};
|
||||
|
||||
const dsp::FftPlan& qmf_plan() {
|
||||
static const dsp::FftPlan plan(kBands, false);
|
||||
return plan;
|
||||
}
|
||||
|
||||
const dsp::FftPlan& hybrid_plan(std::size_t bands) {
|
||||
static const dsp::FftPlan eight(8, false);
|
||||
static const dsp::FftPlan four(4, false);
|
||||
return bands == 8 ? eight : four;
|
||||
}
|
||||
|
||||
double tap_sign(std::size_t tap) { return (tap / 2) % 2 == 0 ? 1.0 : -1.0; }
|
||||
|
||||
}
|
||||
|
||||
RosellaFilterbank::RosellaFilterbank(std::size_t channels)
|
||||
: channels_(channels), analysis_history_(kQmfTaps * channels * kBands),
|
||||
hybrid_history_(kHybridTaps * channels * kBands),
|
||||
synthesis_history_(kQmfTaps * channels * kBands), spectrum_(kBands), hybrid_eight_(8),
|
||||
hybrid_four_(4) {}
|
||||
|
||||
void RosellaFilterbank::reset() {
|
||||
analysis_position_ = 0;
|
||||
hybrid_position_ = 0;
|
||||
synthesis_position_ = 0;
|
||||
std::fill(analysis_history_.begin(), analysis_history_.end(), 0.0);
|
||||
std::fill(hybrid_history_.begin(), hybrid_history_.end(), Complex{});
|
||||
std::fill(synthesis_history_.begin(), synthesis_history_.end(), Complex{});
|
||||
}
|
||||
|
||||
void RosellaFilterbank::analyze_qmf(const std::vector<double>& hops, std::size_t slots,
|
||||
std::vector<Complex>* qmf) {
|
||||
const std::size_t stride = channels_ * kBands;
|
||||
qmf->resize(slots * stride);
|
||||
for (std::size_t slot = 0; slot < slots; ++slot) {
|
||||
std::copy_n(hops.data() + slot * stride, stride,
|
||||
analysis_history_.data() + analysis_position_ * stride);
|
||||
for (std::size_t channel = 0; channel < channels_; ++channel) {
|
||||
for (std::size_t band = 0; band < kBands; ++band) {
|
||||
double even = 0.0;
|
||||
double odd = 0.0;
|
||||
for (std::size_t tap = 0; tap < kQmfTaps; ++tap) {
|
||||
const std::size_t history_slot = (analysis_position_ + tap + 1) % kQmfTaps;
|
||||
const double value =
|
||||
analysis_history_[history_slot * stride + channel * kBands + band];
|
||||
const double contribution =
|
||||
value * 0.5 * rosella_filterbank_tables::kPrototype[band * kQmfTaps + tap] *
|
||||
tap_sign(tap);
|
||||
(tap % 2 == 0 ? even : odd) += contribution;
|
||||
}
|
||||
spectrum_[band] = Complex(odd, even) * rosella_filterbank_tables::kRotation[band];
|
||||
}
|
||||
dsp::fft_radix2(&spectrum_, qmf_plan());
|
||||
Complex* destination = qmf->data() + slot * stride + channel * kBands;
|
||||
for (std::size_t band = 0; band < kBands / 2; ++band) {
|
||||
destination[2 * band] = spectrum_[band] / 64.0;
|
||||
destination[2 * band + 1] = std::conj(spectrum_[63 - band]) / 64.0;
|
||||
}
|
||||
}
|
||||
analysis_position_ = (analysis_position_ + 1) % kQmfTaps;
|
||||
}
|
||||
}
|
||||
|
||||
void RosellaFilterbank::analyze_hybrid(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<Complex>* hybrid) {
|
||||
const std::size_t stride = channels_ * kBands;
|
||||
hybrid->resize(slots * channels_ * kHybridBandCount);
|
||||
for (std::size_t slot = 0; slot < slots; ++slot) {
|
||||
std::copy_n(qmf.data() + slot * stride, stride,
|
||||
hybrid_history_.data() + hybrid_position_ * stride);
|
||||
for (std::size_t channel = 0; channel < channels_; ++channel) {
|
||||
std::array<Complex, 16> low{};
|
||||
for (std::size_t band = 0; band < 3; ++band) {
|
||||
std::vector<Complex>& spectrum = band == 0 ? hybrid_eight_ : hybrid_four_;
|
||||
std::fill(spectrum.begin(), spectrum.end(), Complex{});
|
||||
for (std::size_t tap = 0; tap < kHybridTaps; ++tap) {
|
||||
const std::size_t history_slot = (hybrid_position_ + tap + 1) % kHybridTaps;
|
||||
const std::size_t bin =
|
||||
(tap + kHybridDelay + 1 + 2 * spectrum.size() - kHybridTaps) %
|
||||
spectrum.size();
|
||||
spectrum[bin] +=
|
||||
hybrid_history_[history_slot * stride + channel * kBands + band] *
|
||||
rosella_filterbank_tables::kHybrid[(band == 0 ? 0 : kHybridTaps) + tap];
|
||||
}
|
||||
dsp::fft_radix2(&spectrum, hybrid_plan(spectrum.size()));
|
||||
std::copy(spectrum.begin(), spectrum.end(),
|
||||
low.begin() + (band == 0 ? 0 : 4 + band * 4));
|
||||
}
|
||||
Complex* destination = hybrid->data() + (slot * channels_ + channel) * kHybridBandCount;
|
||||
for (std::size_t band = 0; band < low.size(); ++band) {
|
||||
destination[band] = low[kHybridOrder[band]];
|
||||
}
|
||||
destination[1] = std::conj(destination[1]);
|
||||
destination[3] = std::conj(destination[3]);
|
||||
const std::size_t delayed =
|
||||
(hybrid_position_ + kHybridTaps - kHybridDelay) % kHybridTaps;
|
||||
std::copy_n(hybrid_history_.data() + delayed * stride + channel * kBands + 3,
|
||||
kBands - 3, destination + 16);
|
||||
}
|
||||
hybrid_position_ = (hybrid_position_ + 1) % kHybridTaps;
|
||||
}
|
||||
}
|
||||
|
||||
void RosellaFilterbank::synthesize_hybrid(const std::vector<Complex>& hybrid, std::size_t slots,
|
||||
std::vector<Complex>* qmf) {
|
||||
qmf->resize(slots * channels_ * kBands);
|
||||
for (std::size_t row = 0; row < slots * channels_; ++row) {
|
||||
const Complex* source = hybrid.data() + row * kHybridBandCount;
|
||||
Complex* destination = qmf->data() + row * kBands;
|
||||
destination[0] = source[0] + source[2] + source[4] + source[6] + source[7] + source[9] +
|
||||
std::conj(source[3]) + std::conj(source[1]);
|
||||
destination[1] = source[12] + source[5] + source[8] + source[10];
|
||||
destination[2] = source[13] + source[14] + source[15] + source[11];
|
||||
std::copy_n(source + 16, kBands - 3, destination + 3);
|
||||
}
|
||||
}
|
||||
|
||||
void RosellaFilterbank::synthesize_qmf(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<double>* hops) {
|
||||
const std::size_t stride = channels_ * kBands;
|
||||
hops->resize(slots * stride);
|
||||
for (std::size_t slot = 0; slot < slots; ++slot) {
|
||||
for (std::size_t channel = 0; channel < channels_; ++channel) {
|
||||
const Complex* source = qmf.data() + slot * stride + channel * kBands;
|
||||
for (std::size_t band = 0; band < kBands / 2; ++band) {
|
||||
spectrum_[band] = std::conj(source[2 * band]);
|
||||
spectrum_[32 + band] = source[63 - 2 * band];
|
||||
}
|
||||
dsp::fft_radix2(&spectrum_, qmf_plan());
|
||||
Complex* current =
|
||||
synthesis_history_.data() + synthesis_position_ * stride + channel * kBands;
|
||||
for (std::size_t band = 0; band < kBands; ++band) {
|
||||
current[band] = spectrum_[band] * rosella_filterbank_tables::kRotation[band];
|
||||
}
|
||||
for (std::size_t band = 0; band < kBands; ++band) {
|
||||
double value = 0.0;
|
||||
for (std::size_t lag = 0; lag < kQmfTaps; ++lag) {
|
||||
const std::size_t history_slot =
|
||||
(synthesis_position_ + kQmfTaps - lag) % kQmfTaps;
|
||||
const Complex sample =
|
||||
synthesis_history_[history_slot * stride + channel * kBands + band];
|
||||
const double component = lag % 2 == 0 ? sample.real() : sample.imag();
|
||||
value +=
|
||||
component *
|
||||
rosella_filterbank_tables::kPrototype[(63 - band) * kQmfTaps + 9 - lag] *
|
||||
tap_sign(lag) * 2.0;
|
||||
}
|
||||
(*hops)[slot * stride + channel * kBands + band] = value;
|
||||
}
|
||||
}
|
||||
synthesis_position_ = (synthesis_position_ + 1) % kQmfTaps;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#include "hrtf/public_filterbank.h"
|
||||
|
||||
namespace joc::hrtf {
|
||||
|
||||
class RosellaFilterbank {
|
||||
public:
|
||||
static constexpr int kLatencySamples = 448;
|
||||
|
||||
explicit RosellaFilterbank(std::size_t channels);
|
||||
|
||||
void reset();
|
||||
void analyze_qmf(const std::vector<double>& hops, std::size_t slots, std::vector<Complex>* qmf);
|
||||
void analyze_hybrid(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<Complex>* hybrid);
|
||||
void synthesize_hybrid(const std::vector<Complex>& hybrid, std::size_t slots,
|
||||
std::vector<Complex>* qmf);
|
||||
void synthesize_qmf(const std::vector<Complex>& qmf, std::size_t slots,
|
||||
std::vector<double>* hops);
|
||||
|
||||
private:
|
||||
std::size_t channels_;
|
||||
std::size_t analysis_position_ = 0;
|
||||
std::size_t hybrid_position_ = 0;
|
||||
std::size_t synthesis_position_ = 0;
|
||||
std::vector<double> analysis_history_;
|
||||
std::vector<Complex> hybrid_history_;
|
||||
std::vector<Complex> synthesis_history_;
|
||||
std::vector<Complex> spectrum_;
|
||||
std::vector<Complex> hybrid_eight_;
|
||||
std::vector<Complex> hybrid_four_;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <complex>
|
||||
|
||||
namespace joc::hrtf::rosella_filterbank_tables {
|
||||
|
||||
inline constexpr std::array<double, 640> kPrototype = {
|
||||
0x1.89b0a40000000p-14f, -0x1.9405b80000000p-11f, 0x1.caf19e0000000p-11f,
|
||||
0x1.b88a900000000p-8f, 0x1.a3899a0000000p-8f, -0x1.fa22860000000p-4f,
|
||||
0x1.5a540e0000000p-4f, 0x1.c420360000000p-1f, 0x1.1fb7200000000p-1f,
|
||||
-0x1.eb519a0000000p-12f, 0x1.fe69400000000p-14f, -0x1.aebea80000000p-11f,
|
||||
0x1.0b0c7c0000000p-10f, 0x1.baec6c0000000p-8f, 0x1.7fc1900000000p-8f,
|
||||
-0x1.0209c80000000p-3f, 0x1.88474c0000000p-4f, 0x1.c7781c0000000p-1f,
|
||||
0x1.1929680000000p-1f, -0x1.6f0b9e0000000p-9f, 0x1.0c4e040000000p-13f,
|
||||
-0x1.cabdf80000000p-11f, 0x1.3039ee0000000p-10f, 0x1.bd5e600000000p-8f,
|
||||
0x1.590ba60000000p-8f, -0x1.06dd700000000p-3f, 0x1.b728e40000000p-4f,
|
||||
0x1.ca9d100000000p-1f, 0x1.1298c60000000p-1f, -0x1.430d400000000p-8f,
|
||||
0x1.09af720000000p-13f, -0x1.e7140c0000000p-11f, 0x1.553e000000000p-10f,
|
||||
0x1.bfe6ee0000000p-8f, 0x1.2f581e0000000p-8f, -0x1.0b89600000000p-3f,
|
||||
0x1.e6f2b20000000p-4f, 0x1.cd8f8e0000000p-1f, 0x1.0c066e0000000p-1f,
|
||||
-0x1.c5fd4e0000000p-8f, 0x1.01e0d60000000p-13f, -0x1.01e8060000000p-10f,
|
||||
0x1.7a2d9e0000000p-10f, 0x1.c2890c0000000p-8f, 0x1.028f2c0000000p-8f,
|
||||
-0x1.100a6e0000000p-3f, 0x1.0bcf280000000p-3f, 0x1.d04eb00000000p-1f,
|
||||
0x1.0573b40000000p-1f, -0x1.1fe42e0000000p-7f, 0x1.e4c9900000000p-14f,
|
||||
-0x1.1083480000000p-10f, 0x1.9ef9b00000000p-10f, 0x1.c548880000000p-8f,
|
||||
0x1.a536b40000000p-9f, -0x1.145d660000000p-3f, 0x1.2492a60000000p-3f,
|
||||
0x1.d2d9d00000000p-1f, 0x1.fdc3f40000000p-2f, -0x1.584fbc0000000p-7f,
|
||||
0x1.bbe1f00000000p-14f, -0x1.1f4cc40000000p-10f, 0x1.c3a28c0000000p-10f,
|
||||
0x1.c828fe0000000p-8f, 0x1.3ed0ae0000000p-9f, -0x1.187f1e0000000p-3f,
|
||||
0x1.3dc0340000000p-3f, 0x1.d530800000000p-1f, 0x1.f0a4d80000000p-2f,
|
||||
-0x1.8c9d380000000p-7f, 0x1.8b83740000000p-14f, -0x1.2e42340000000p-10f,
|
||||
0x1.e827840000000p-10f, 0x1.cb2f1a0000000p-8f, 0x1.a38bba0000000p-10f,
|
||||
-0x1.1c6c620000000p-3f, 0x1.5754320000000p-3f, 0x1.d7522c0000000p-1f,
|
||||
0x1.e38cc40000000p-2f, -0x1.bccca00000000p-7f, 0x1.51b3dc0000000p-14f,
|
||||
-0x1.3d59c40000000p-10f, 0x1.0642740000000p-9f, 0x1.ce5f720000000p-8f,
|
||||
0x1.77c5740000000p-11f, -0x1.2021ea0000000p-3f, 0x1.714ae20000000p-3f,
|
||||
0x1.d93e620000000p-1f, 0x1.d67e3e0000000p-2f, -0x1.e902340000000p-7f,
|
||||
0x1.1135380000000p-14f, -0x1.4c72680000000p-10f, 0x1.184f0e0000000p-9f,
|
||||
0x1.d1bcf80000000p-8f, -0x1.cd43660000000p-13f, -0x1.239c8a0000000p-3f,
|
||||
0x1.8ba0220000000p-3f, 0x1.daf4c80000000p-1f, 0x1.c97bac0000000p-2f,
|
||||
-0x1.08b5360000000p-6f, 0x1.9380400000000p-15f, -0x1.5b82640000000p-10f,
|
||||
0x1.2a36bc0000000p-9f, 0x1.d54b040000000p-8f, -0x1.3d508c0000000p-10f,
|
||||
-0x1.26d9020000000p-3f, 0x1.a64ff60000000p-3f, 0x1.dc75060000000p-1f,
|
||||
0x1.bc87920000000p-2f, -0x1.1b117c0000000p-6f, 0x1.ef2dd20000000p-16f,
|
||||
-0x1.6a7bb60000000p-10f, 0x1.3bf6ea0000000p-9f, 0x1.d90d680000000p-8f,
|
||||
-0x1.27adc40000000p-9f, -0x1.29d4040000000p-3f, 0x1.c156200000000p-3f,
|
||||
0x1.ddbed80000000p-1f, 0x1.afa4460000000p-2f, -0x1.2ba7240000000p-6f,
|
||||
0x1.4b90ac0000000p-17f, -0x1.7946720000000p-10f, 0x1.4d8e5a0000000p-9f,
|
||||
0x1.dd07fe0000000p-8f, -0x1.b800720000000p-9f, -0x1.2c8a500000000p-3f,
|
||||
0x1.dcae220000000p-3f, 0x1.ded2060000000p-1f, 0x1.a2d44a0000000p-2f,
|
||||
-0x1.3a80720000000p-6f, -0x1.700b940000000p-17f, -0x1.87d4460000000p-10f,
|
||||
0x1.5ef8ce0000000p-9f, 0x1.e13c820000000p-8f, -0x1.27dccc0000000p-8f,
|
||||
-0x1.2ef8a80000000p-3f, 0x1.f853940000000p-3f, 0x1.dfae620000000p-1f,
|
||||
0x1.9619e20000000p-2f, -0x1.47ad4c0000000p-6f, -0x1.1120780000000p-15f,
|
||||
-0x1.960c8c0000000p-10f, 0x1.7033800000000p-9f, 0x1.e5adfa0000000p-8f,
|
||||
-0x1.7778760000000p-8f, -0x1.311bc00000000p-3f, 0x1.0a20dc0000000p-2f,
|
||||
0x1.e053dc0000000p-1f, 0x1.8977600000000p-2f, -0x1.533fe20000000p-6f,
|
||||
-0x1.ca9a980000000p-15f, -0x1.a3dfa80000000p-10f, 0x1.813d240000000p-9f,
|
||||
0x1.ea5d320000000p-8f, -0x1.cade8a0000000p-8f, -0x1.32f0680000000p-3f,
|
||||
0x1.1839ec0000000p-2f, 0x1.e0c25e0000000p-1f, 0x1.7cef0e0000000p-2f,
|
||||
-0x1.5d41a40000000p-6f, -0x1.45160a0000000p-14f, -0x1.b13e1c0000000p-10f,
|
||||
0x1.9211160000000p-9f, 0x1.ef4d0a0000000p-8f, -0x1.110bcc0000000p-7f,
|
||||
-0x1.3473540000000p-3f, 0x1.2672860000000p-2f, 0x1.e0f9ee0000000p-1f,
|
||||
0x1.7083220000000p-2f, -0x1.65bf6a0000000p-6f, -0x1.a5d63c0000000p-14f,
|
||||
-0x1.be0c7c0000000p-10f, 0x1.a2ad420000000p-9f, 0x1.f47de80000000p-8f,
|
||||
-0x1.3e95720000000p-7f, -0x1.35a15c0000000p-3f, 0x1.34c8260000000p-2f,
|
||||
0x1.e0faa00000000p-1f, 0x1.6435c80000000p-2f, -0x1.6cc7d80000000p-6f,
|
||||
-0x1.0363300000000p-13f, -0x1.ca38de0000000p-10f, 0x1.b30fc40000000p-9f,
|
||||
0x1.f9f0320000000p-8f, -0x1.6e0f4e0000000p-7f, -0x1.3677520000000p-3f,
|
||||
0x1.43383c0000000p-2f, 0x1.e0c4920000000p-1f, 0x1.58091e0000000p-2f,
|
||||
-0x1.7268700000000p-6f, -0x1.33a4780000000p-13f, -0x1.d5b2c20000000p-10f,
|
||||
0x1.c336cc0000000p-9f, 0x1.ffa3600000000p-8f, -0x1.9f7bd20000000p-7f,
|
||||
-0x1.36f2140000000p-3f, 0x1.51c02e0000000p-2f, 0x1.e057f20000000p-1f,
|
||||
0x1.4bff340000000p-2f, -0x1.76ae0c0000000p-6f, -0x1.63044a0000000p-13f,
|
||||
-0x1.e062560000000p-10f, 0x1.d321240000000p-9f, 0x1.02cb720000000p-7f,
|
||||
-0x1.d2dcc20000000p-7f, -0x1.370e8a0000000p-3f, 0x1.605d580000000p-2f,
|
||||
0x1.dfb5020000000p-1f, 0x1.401a140000000p-2f, -0x1.79a3480000000p-6f,
|
||||
-0x1.91dea40000000p-13f, -0x1.ea3a6c0000000p-10f, 0x1.e2cc1c0000000p-9f,
|
||||
0x1.05e49c0000000p-7f, -0x1.04190e0000000p-6f, -0x1.36c9a00000000p-3f,
|
||||
0x1.6f0cfe0000000p-2f, 0x1.dedc080000000p-1f, 0x1.345b9e0000000p-2f,
|
||||
-0x1.7b56a00000000p-6f, -0x1.bfa7220000000p-13f, -0x1.f327920000000p-10f,
|
||||
0x1.f234380000000p-9f, 0x1.091c860000000p-7f, -0x1.1fbe040000000p-6f,
|
||||
-0x1.36205c0000000p-3f, 0x1.7dcc500000000p-2f, 0x1.ddcd600000000p-1f,
|
||||
0x1.28c5be0000000p-2f, -0x1.7bd6c00000000p-6f, -0x1.ebbcb00000000p-13f,
|
||||
-0x1.fb17ea0000000p-10f, 0x1.00ad9a0000000p-8f, 0x1.0c71000000000p-7f,
|
||||
-0x1.3c5cfa0000000p-6f, -0x1.350fba0000000p-3f, 0x1.8c989a0000000p-2f,
|
||||
0x1.dc89760000000p-1f, 0x1.1d5a3e0000000p-2f, -0x1.7b2ea80000000p-6f,
|
||||
-0x1.0afed40000000p-12f, -0x1.00fdf80000000p-9f, 0x1.081ef40000000p-8f,
|
||||
0x1.0fe0aa0000000p-7f, -0x1.59f4a60000000p-6f, -0x1.3394de0000000p-3f,
|
||||
0x1.9b6efe0000000p-2f, 0x1.db10b80000000p-1f, 0x1.121ad80000000p-2f,
|
||||
-0x1.796b8c0000000p-6f, -0x1.1f023c0000000p-12f, -0x1.03dff00000000p-9f,
|
||||
0x1.0f6d1a0000000p-8f, 0x1.1368de0000000p-7f, -0x1.7883900000000p-6f,
|
||||
-0x1.31acee0000000p-3f, 0x1.aa4c940000000p-2f, 0x1.d963ae0000000p-1f,
|
||||
0x1.07092e0000000p-2f, -0x1.769b420000000p-6f, -0x1.31d35c0000000p-12f,
|
||||
-0x1.062c000000000p-9f, 0x1.1697660000000p-8f, 0x1.1706fa0000000p-7f,
|
||||
-0x1.9807dc0000000p-6f, -0x1.2f55300000000p-3f, 0x1.b92e760000000p-2f,
|
||||
0x1.d782e20000000p-1f, 0x1.f84daa0000000p-3f, -0x1.72cc440000000p-6f,
|
||||
-0x1.435c0e0000000p-12f, -0x1.07dcd20000000p-9f, 0x1.1d9da20000000p-8f,
|
||||
0x1.1ab8380000000p-7f, -0x1.b87f060000000p-6f, -0x1.2c8af40000000p-3f,
|
||||
0x1.c811b40000000p-2f, 0x1.d56ef40000000p-1f, 0x1.e2ea940000000p-3f,
|
||||
-0x1.6e0bd80000000p-6f, -0x1.5382940000000p-12f, -0x1.08eac40000000p-9f,
|
||||
0x1.247f400000000p-8f, 0x1.1e79ce0000000p-7f, -0x1.d9e6460000000p-6f,
|
||||
-0x1.294b8c0000000p-3f, 0x1.d6f34e0000000p-2f, 0x1.d3288c0000000p-1f,
|
||||
0x1.cdebe00000000p-3f, -0x1.6865f20000000p-6f, -0x1.624b420000000p-12f,
|
||||
-0x1.0952b80000000p-9f, 0x1.2b3bdc0000000p-8f, 0x1.2247060000000p-7f,
|
||||
-0x1.fc3a1a0000000p-6f, -0x1.2594900000000p-3f, 0x1.e5d0500000000p-2f,
|
||||
0x1.d0b05e0000000p-1f, 0x1.b9542e0000000p-3f, -0x1.61ea740000000p-6f,
|
||||
-0x1.6f8fc20000000p-12f, -0x1.090d6a0000000p-9f, 0x1.31d25e0000000p-8f,
|
||||
0x1.261bfc0000000p-7f, -0x1.0fbb460000000p-5f, -0x1.21637c0000000p-3f,
|
||||
0x1.f4a5aa0000000p-2f, 0x1.ce072e0000000p-1f, 0x1.a525de0000000p-3f,
|
||||
-0x1.5aa7b40000000p-6f, -0x1.7b53da0000000p-12f, -0x1.0819600000000p-9f,
|
||||
0x1.3842c00000000p-8f, 0x1.29f3580000000p-7f, -0x1.21cbac0000000p-5f,
|
||||
-0x1.1cb60a0000000p-3f, 0x1.01b82e0000000p-1f, 0x1.cb2dca0000000p-1f,
|
||||
0x1.9163520000000p-3f, -0x1.52aada0000000p-6f, -0x1.85a5dc0000000p-12f,
|
||||
-0x1.0671aa0000000p-9f, 0x1.3e8b260000000p-8f, 0x1.2dc77c0000000p-7f,
|
||||
-0x1.344b9e0000000p-5f, -0x1.1789fc0000000p-3f, 0x1.0916a80000000p-1f,
|
||||
0x1.c824fc0000000p-1f, 0x1.7e0e860000000p-3f, -0x1.4a023a0000000p-6f,
|
||||
-0x1.8e754e0000000p-12f, -0x1.0411fc0000000p-9f, 0x1.44aa780000000p-8f,
|
||||
0x1.3192620000000p-7f, -0x1.4738520000000p-5f, -0x1.11dd300000000p-3f,
|
||||
0x1.106cbc0000000p-1f, 0x1.c4edac0000000p-1f, 0x1.6b29640000000p-3f,
|
||||
-0x1.40bbf00000000p-6f, -0x1.95db9a0000000p-12f, -0x1.00fbba0000000p-9f,
|
||||
0x1.4aa1d60000000p-8f, 0x1.354e160000000p-7f, -0x1.5a8eb80000000p-5f,
|
||||
-0x1.0bad980000000p-3f, 0x1.17b8dc0000000p-1f, 0x1.c188c20000000p-1f,
|
||||
0x1.58b59e0000000p-3f, -0x1.36e7a40000000p-6f, -0x1.9be6720000000p-12f,
|
||||
-0x1.fa5a8a0000000p-10f, 0x1.506fe80000000p-8f, 0x1.38f3740000000p-7f,
|
||||
-0x1.6e4b4c0000000p-5f, -0x1.04f9500000000p-3f, 0x1.1ef9820000000p-1f,
|
||||
0x1.bdf7340000000p-1f, 0x1.46b4b40000000p-3f, -0x1.2c935c0000000p-6f,
|
||||
-0x1.a0ae100000000p-12f, -0x1.f14b760000000p-10f, 0x1.5614b40000000p-8f,
|
||||
0x1.3c7bfe0000000p-7f, -0x1.826b260000000p-5f, -0x1.fb7d1c0000000p-4f,
|
||||
0x1.262d200000000p-1f, 0x1.ba3a080000000p-1f, 0x1.3527ea0000000p-3f,
|
||||
-0x1.21cb9e0000000p-6f, -0x1.a45ab20000000p-12f, -0x1.e6cbec0000000p-10f,
|
||||
0x1.5b8f3c0000000p-8f, 0x1.3fdefe0000000p-7f, -0x1.96ea060000000p-5f,
|
||||
-0x1.ebf76a0000000p-4f, 0x1.2d52300000000p-1f, 0x1.b652420000000p-1f,
|
||||
0x1.24103e0000000p-3f, -0x1.16a0ec0000000p-6f, -0x1.a6fa860000000p-12f,
|
||||
-0x1.dadcf00000000p-10f, 0x1.60df2e0000000p-8f, 0x1.4315740000000p-7f,
|
||||
-0x1.abc3c80000000p-5f, -0x1.db5e1e0000000p-4f, 0x1.3467220000000p-1f,
|
||||
0x1.b240fa0000000p-1f, 0x1.136ebc0000000p-3f, -0x1.0b217a0000000p-6f,
|
||||
-0x1.a8bb460000000p-12f, -0x1.cd821e0000000p-10f, 0x1.6605500000000p-8f,
|
||||
0x1.4617c60000000p-7f, -0x1.c0f3f60000000p-5f, -0x1.c9aeee0000000p-4f,
|
||||
0x1.3b6a700000000p-1f, 0x1.ae07440000000p-1f, 0x1.03441c0000000p-3f,
|
||||
-0x1.feb4ba0000000p-7f, -0x1.a9e0be0000000p-12f, -0x1.bebef20000000p-10f,
|
||||
0x1.6b004c0000000p-8f, 0x1.48dc4a0000000p-7f, -0x1.d675c20000000p-5f,
|
||||
-0x1.b6e6ae0000000p-4f, 0x1.425a960000000p-1f, 0x1.a9a64c0000000p-1f,
|
||||
0x1.e7217e0000000p-4f, -0x1.e6b55c0000000p-7f, -0x1.aa85020000000p-12f,
|
||||
-0x1.ae9b460000000p-10f, 0x1.6fd00c0000000p-8f, 0x1.4b59340000000p-7f,
|
||||
-0x1.ec43c80000000p-5f, -0x1.a303a20000000p-4f, 0x1.49360c0000000p-1f,
|
||||
0x1.a51f340000000p-1f, 0x1.c8a9d20000000p-4f, -0x1.ce5e0a0000000p-7f,
|
||||
-0x1.aade480000000p-12f, -0x1.9d1b940000000p-10f, 0x1.7474cc0000000p-8f,
|
||||
0x1.4d85040000000p-7f, -0x1.012c820000000p-4f, -0x1.8e03600000000p-4f,
|
||||
0x1.4ffb520000000p-1f, 0x1.a073360000000p-1f, 0x1.ab21ee0000000p-4f,
|
||||
-0x1.b5ce920000000p-7f, -0x1.ab1c980000000p-12f, -0x1.8a49160000000p-10f,
|
||||
0x1.78eec60000000p-8f, 0x1.4f55b00000000p-7f, -0x1.0c57ca0000000p-4f,
|
||||
-0x1.77e4720000000p-4f, 0x1.56a8e60000000p-1f, 0x1.9ba3820000000p-1f,
|
||||
0x1.8e894a0000000p-4f, -0x1.9d20fe0000000p-7f, -0x1.ab834e0000000p-12f,
|
||||
-0x1.762b260000000p-10f, 0x1.7d3dde0000000p-8f, 0x1.50c0480000000p-7f,
|
||||
-0x1.17a0ae0000000p-4f, -0x1.60a5560000000p-4f, 0x1.5d3d4e0000000p-1f,
|
||||
0x1.96b1680000000p-1f, 0x1.72df7c0000000p-4f, -0x1.846b160000000p-7f,
|
||||
-0x1.ac64680000000p-12f, -0x1.60cd740000000p-10f, 0x1.81625a0000000p-8f,
|
||||
0x1.51b9dc0000000p-7f, -0x1.2303ee0000000p-4f, -0x1.4845000000000p-4f,
|
||||
0x1.63b7140000000p-1f, 0x1.919e200000000p-1f, 0x1.5823340000000p-4f,
|
||||
-0x1.6bcd900000000p-7f, -0x1.adf08e0000000p-12f, -0x1.4a3ac20000000p-10f,
|
||||
0x1.855cfe0000000p-8f, 0x1.5237680000000p-7f, -0x1.2e7e4e0000000p-4f,
|
||||
-0x1.2ec2760000000p-4f, 0x1.6a14c00000000p-1f, 0x1.8c6afe0000000p-1f,
|
||||
0x1.3e53ba0000000p-4f, -0x1.53608c0000000p-7f, -0x1.b06dac0000000p-12f,
|
||||
-0x1.327bec0000000p-10f, 0x1.892e780000000p-8f, 0x1.522d9c0000000p-7f,
|
||||
-0x1.3a0c300000000p-4f, -0x1.141d6e0000000p-4f, 0x1.7054ee0000000p-1f,
|
||||
0x1.87194e0000000p-1f, 0x1.256f780000000p-4f, -0x1.3b3a720000000p-7f,
|
||||
-0x1.b4260a0000000p-12f, -0x1.199f100000000p-10f, 0x1.8cd8000000000p-8f,
|
||||
0x1.5190560000000p-7f, -0x1.45aa140000000p-4f, -0x1.f0ab120000000p-5f,
|
||||
0x1.7676320000000p-1f, 0x1.81aa700000000p-1f, 0x1.0d73ae0000000p-4f,
|
||||
-0x1.2378140000000p-7f, -0x1.b946980000000p-12f, -0x1.ff5dae0000000p-11f,
|
||||
0x1.905a600000000p-8f, 0x1.5053d20000000p-7f, -0x1.5154220000000p-4f,
|
||||
-0x1.b6d5d40000000p-5f, 0x1.7c772e0000000p-1f, 0x1.7c1fb80000000p-1f,
|
||||
0x1.ecbc3e0000000p-5f, -0x1.0c29f20000000p-7f, -0x1.c0151e0000000p-12f,
|
||||
-0x1.c96f140000000p-11f, 0x1.93b7460000000p-8f, 0x1.4e6c1e0000000p-7f,
|
||||
-0x1.5d064a0000000p-4f, -0x1.7abc7a0000000p-5f, 0x1.8256860000000p-1f,
|
||||
0x1.767a860000000p-1f, 0x1.c059b00000000p-5f, -0x1.eadf100000000p-8f,
|
||||
-0x1.c8cc9c0000000p-12f, -0x1.918eb80000000p-11f, 0x1.96effa0000000p-8f,
|
||||
0x1.4bcc520000000p-7f, -0x1.68bca00000000p-4f, -0x1.3c5fe80000000p-5f,
|
||||
0x1.8812e80000000p-1f, 0x1.70bc380000000p-1f, 0x1.95b8180000000p-5f,
|
||||
-0x1.bebb380000000p-8f, -0x1.d3ab2e0000000p-12f, -0x1.57d51e0000000p-11f,
|
||||
0x1.9a075e0000000p-8f, 0x1.4868760000000p-7f, -0x1.7472b40000000p-4f,
|
||||
-0x1.f785a60000000p-6f, 0x1.8dab0e0000000p-1f, 0x1.6ae6480000000p-1f,
|
||||
0x1.6cd0a40000000p-5f, -0x1.93fad20000000p-8f, -0x1.e0dd0e0000000p-12f,
|
||||
-0x1.1c6a140000000p-11f, 0x1.9cfe1a0000000p-8f, 0x1.44329c0000000p-7f,
|
||||
-0x1.80243a0000000p-4f, -0x1.71cfa40000000p-6f, 0x1.931db60000000p-1f,
|
||||
0x1.64fa0a0000000p-1f, 0x1.459afa0000000p-5f, -0x1.6ae5d80000000p-8f,
|
||||
-0x1.f0751e0000000p-12f, -0x1.bea86e0000000p-12f, 0x1.9fd7d60000000p-8f,
|
||||
0x1.3f20100000000p-7f, -0x1.8bcca00000000p-4f, -0x1.cf4aee0000000p-7f,
|
||||
0x1.9869a40000000p-1f, 0x1.5ef8f00000000p-1f, 0x1.2010120000000p-5f,
|
||||
-0x1.43917e0000000p-8f, -0x1.014d9e0000000p-11f, -0x1.41769a0000000p-12f,
|
||||
0x1.a2962a0000000p-8f, 0x1.39224a0000000p-7f, -0x1.9767380000000p-4f,
|
||||
-0x1.643b740000000p-8f, 0x1.9d8dac0000000p-1f, 0x1.58e4620000000p-1f,
|
||||
0x1.f8505c0000000p-6f, -0x1.1e15b40000000p-8f, -0x1.0bbd1e0000000p-11f,
|
||||
-0x1.82f5720000000p-13f, 0x1.a53c820000000p-8f, 0x1.322da40000000p-7f,
|
||||
-0x1.a2ef380000000p-4f, 0x1.cf4bf20000000p-9f, 0x1.a288b20000000p-1f,
|
||||
0x1.52bdd00000000p-1f, 0x1.b3a9200000000p-6f, -0x1.f55fc60000000p-9f,
|
||||
-0x1.1795420000000p-11f, -0x1.f78ba40000000p-15f, 0x1.a7cd100000000p-8f,
|
||||
0x1.2a34100000000p-7f, -0x1.ae5f920000000p-4f, 0x1.a272920000000p-7f,
|
||||
0x1.a7599a0000000p-1f, 0x1.4c86bc0000000p-1f, 0x1.72191a0000000p-6f,
|
||||
-0x1.b278bc0000000p-9f, -0x1.24d82e0000000p-11f, 0x1.176aba0000000p-14f,
|
||||
0x1.aa4b400000000p-8f, 0x1.21297e0000000p-7f, -0x1.b9b3340000000p-4f,
|
||||
0x1.6cd36a0000000p-6f, 0x1.abff500000000p-1f, 0x1.46406e0000000p-1f,
|
||||
0x1.3392320000000p-6f, -0x1.7413460000000p-9f, -0x1.3371980000000p-11f,
|
||||
0x1.9954380000000p-13f, 0x1.acba4a0000000p-8f, 0x1.1700e40000000p-7f,
|
||||
-0x1.c4e4ec0000000p-4f, 0x1.0655200000000p-5f, 0x1.b078e40000000p-1f,
|
||||
0x1.3fec680000000p-1f, 0x1.efd5a20000000p-7f, -0x1.3a3eea0000000p-9f,
|
||||
-0x1.43727a0000000p-11f, 0x1.5542700000000p-12f, 0x1.af1de80000000p-8f,
|
||||
0x1.0bacb40000000p-7f, -0x1.cfef6c0000000p-4f, 0x1.58574a0000000p-5f,
|
||||
0x1.b4c5620000000p-1f, 0x1.398c3c0000000p-1f, 0x1.7e1d1c0000000p-7f,
|
||||
-0x1.039df20000000p-9f, -0x1.54c2b80000000p-11f, 0x1.df54960000000p-12f,
|
||||
0x1.b17a740000000p-8f, 0x1.fe42040000000p-8f, -0x1.dacd4c0000000p-4f,
|
||||
0x1.ac68700000000p-5f, 0x1.b8e3f00000000p-1f, 0x1.33211a0000000p-1f,
|
||||
0x1.11a4f80000000p-7f, -0x1.a3b4ea0000000p-10f, -0x1.671b880000000p-11f,
|
||||
0x1.3568c80000000p-11f, 0x1.b3d4520000000p-8f, 0x1.e2a46e0000000p-8f,
|
||||
-0x1.e579200000000p-4f, 0x1.013ff60000000p-4f, 0x1.bcd3ee0000000p-1f,
|
||||
0x1.2cacd00000000p-1f, 0x1.53b1420000000p-8f, -0x1.42fb1c0000000p-10f,
|
||||
-0x1.7b9bba0000000p-11f, 0x1.7c27840000000p-11f, 0x1.b62ed40000000p-8f,
|
||||
0x1.c465e60000000p-8f, -0x1.efecf00000000p-4f, 0x1.2d4b160000000p-4f,
|
||||
0x1.c093960000000p-1f, 0x1.2631fe0000000p-1f, 0x1.21b5e00000000p-9f,
|
||||
-0x1.a0c52c0000000p-11f,
|
||||
};
|
||||
|
||||
inline constexpr std::array<std::complex<double>, 64> kRotation = {{
|
||||
{0x1.fff6220000000p-1f, -0x1.921d200000000p-7f},
|
||||
{0x1.ffa72e0000000p-1f, -0x1.2d86580000000p-5f},
|
||||
{0x1.ff09560000000p-1f, -0x1.f656e80000000p-5f},
|
||||
{0x1.fe1cb00000000p-1f, -0x1.5f6d000000000p-4f},
|
||||
{0x1.fce1600000000p-1f, -0x1.c3785c0000000p-4f},
|
||||
{0x1.fb57980000000p-1f, -0x1.139f0c0000000p-3f},
|
||||
{0x1.f97f920000000p-1f, -0x1.45576c0000000p-3f},
|
||||
{0x1.f7599a0000000p-1f, -0x1.76dd9e0000000p-3f},
|
||||
{0x1.f4e6040000000p-1f, -0x1.a82a020000000p-3f},
|
||||
{0x1.f225300000000p-1f, -0x1.d934fe0000000p-3f},
|
||||
{0x1.ef178a0000000p-1f, -0x1.04fb800000000p-2f},
|
||||
{0x1.ebbd8c0000000p-1f, -0x1.1d34440000000p-2f},
|
||||
{0x1.e817ba0000000p-1f, -0x1.35410c0000000p-2f},
|
||||
{0x1.e426a40000000p-1f, -0x1.4d1e240000000p-2f},
|
||||
{0x1.dfeae60000000p-1f, -0x1.64c7de0000000p-2f},
|
||||
{0x1.db65260000000p-1f, -0x1.7c3a940000000p-2f},
|
||||
{0x1.d696180000000p-1f, -0x1.9372a60000000p-2f},
|
||||
{0x1.d17e780000000p-1f, -0x1.aa6c820000000p-2f},
|
||||
{0x1.cc1f100000000p-1f, -0x1.c1249e0000000p-2f},
|
||||
{0x1.c678b40000000p-1f, -0x1.d797760000000p-2f},
|
||||
{0x1.c08c420000000p-1f, -0x1.edc1960000000p-2f},
|
||||
{0x1.ba5aa60000000p-1f, -0x1.01cfc80000000p-1f},
|
||||
{0x1.b3e4d40000000p-1f, -0x1.0c97040000000p-1f},
|
||||
{0x1.ad2bca0000000p-1f, -0x1.1734d60000000p-1f},
|
||||
{0x1.a630920000000p-1f, -0x1.21a79a0000000p-1f},
|
||||
{0x1.9ef43e0000000p-1f, -0x1.2bedb20000000p-1f},
|
||||
{0x1.9777f00000000p-1f, -0x1.36058c0000000p-1f},
|
||||
{0x1.8fbcca0000000p-1f, -0x1.3fed960000000p-1f},
|
||||
{0x1.87c4000000000p-1f, -0x1.49a44a0000000p-1f},
|
||||
{0x1.7f8ece0000000p-1f, -0x1.53282a0000000p-1f},
|
||||
{0x1.771e760000000p-1f, -0x1.5c77bc0000000p-1f},
|
||||
{0x1.6e74460000000p-1f, -0x1.6591920000000p-1f},
|
||||
{0x1.6591920000000p-1f, -0x1.6e74460000000p-1f},
|
||||
{0x1.5c77bc0000000p-1f, -0x1.771e760000000p-1f},
|
||||
{0x1.53282a0000000p-1f, -0x1.7f8ece0000000p-1f},
|
||||
{0x1.49a44a0000000p-1f, -0x1.87c4000000000p-1f},
|
||||
{0x1.3fed960000000p-1f, -0x1.8fbcca0000000p-1f},
|
||||
{0x1.36058c0000000p-1f, -0x1.9777f00000000p-1f},
|
||||
{0x1.2bedb20000000p-1f, -0x1.9ef43e0000000p-1f},
|
||||
{0x1.21a79a0000000p-1f, -0x1.a630920000000p-1f},
|
||||
{0x1.1734d60000000p-1f, -0x1.ad2bca0000000p-1f},
|
||||
{0x1.0c97040000000p-1f, -0x1.b3e4d40000000p-1f},
|
||||
{0x1.01cfc80000000p-1f, -0x1.ba5aa60000000p-1f},
|
||||
{0x1.edc1960000000p-2f, -0x1.c08c420000000p-1f},
|
||||
{0x1.d797760000000p-2f, -0x1.c678b40000000p-1f},
|
||||
{0x1.c1249e0000000p-2f, -0x1.cc1f100000000p-1f},
|
||||
{0x1.aa6c820000000p-2f, -0x1.d17e780000000p-1f},
|
||||
{0x1.9372a60000000p-2f, -0x1.d696180000000p-1f},
|
||||
{0x1.7c3a940000000p-2f, -0x1.db65260000000p-1f},
|
||||
{0x1.64c7de0000000p-2f, -0x1.dfeae60000000p-1f},
|
||||
{0x1.4d1e240000000p-2f, -0x1.e426a40000000p-1f},
|
||||
{0x1.35410c0000000p-2f, -0x1.e817ba0000000p-1f},
|
||||
{0x1.1d34440000000p-2f, -0x1.ebbd8c0000000p-1f},
|
||||
{0x1.04fb800000000p-2f, -0x1.ef178a0000000p-1f},
|
||||
{0x1.d934fe0000000p-3f, -0x1.f225300000000p-1f},
|
||||
{0x1.a82a020000000p-3f, -0x1.f4e6040000000p-1f},
|
||||
{0x1.76dd9e0000000p-3f, -0x1.f7599a0000000p-1f},
|
||||
{0x1.45576c0000000p-3f, -0x1.f97f920000000p-1f},
|
||||
{0x1.139f0c0000000p-3f, -0x1.fb57980000000p-1f},
|
||||
{0x1.c3785c0000000p-4f, -0x1.fce1600000000p-1f},
|
||||
{0x1.5f6d000000000p-4f, -0x1.fe1cb00000000p-1f},
|
||||
{0x1.f656e80000000p-5f, -0x1.ff09560000000p-1f},
|
||||
{0x1.2d86580000000p-5f, -0x1.ffa72e0000000p-1f},
|
||||
{0x1.921d200000000p-7f, -0x1.fff6220000000p-1f},
|
||||
}};
|
||||
|
||||
inline constexpr std::array<std::complex<double>, 22> kHybrid = {{
|
||||
{-0x1.3a7de80000000p-7f, 0x1.0488900000000p-8f},
|
||||
{-0x1.4f39c60000000p-6f, 0x1.4f39c60000000p-6f},
|
||||
{-0x1.4f65900000000p-6f, 0x1.94dc0e0000000p-5f},
|
||||
{0x0.0p+0f, 0x1.4382f00000000p-4f},
|
||||
{0x1.3844900000000p-5f, 0x1.78f0ca0000000p-4f},
|
||||
{0x1.459b100000000p-4f, 0x1.459b100000000p-4f},
|
||||
{0x1.c49e200000000p-4f, 0x1.76f5f60000000p-5f},
|
||||
{0x1.0000000000000p-3f, 0x0.0p+0f},
|
||||
{0x1.c426000000000p-4f, -0x1.7692720000000p-5f},
|
||||
{0x1.2d4d820000000p-5f, -0x1.2d4d820000000p-5f},
|
||||
{0x1.e4029a0000000p-6f, -0x1.2420400000000p-4f},
|
||||
{-0x1.1ce09c0000000p-7f, 0x1.1ce0900000000p-7f},
|
||||
{0x0.0p+0f, 0x1.b5bb180000000p-6f},
|
||||
{0x1.586f240000000p-6f, 0x1.586f2c0000000p-6f},
|
||||
{0x0.0p+0f, 0x0.0p+0f},
|
||||
{-0x1.9eb2460000000p-5f, 0x1.9eb2460000000p-5f},
|
||||
{0x0.0p+0f, 0x1.5019100000000p-3f},
|
||||
{0x1.515a8e0000000p-3f, 0x1.515a8e0000000p-3f},
|
||||
{0x1.0000000000000p-2f, 0x0.0p+0f},
|
||||
{0x1.515b660000000p-3f, -0x1.515b660000000p-3f},
|
||||
{0x0.0p+0f, -0x1.1f2f040000000p-3f},
|
||||
{-0x1.af372a0000000p-5f, -0x1.af372a0000000p-5f},
|
||||
}};
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/fft.h"
|
||||
#include "hrtf/public_filterbank.h"
|
||||
#include "hrtf/rosella_bank.h"
|
||||
|
||||
namespace joc::hrtf {
|
||||
|
||||
@@ -1003,8 +1003,8 @@ struct RosellaRuntime::Impl {
|
||||
std::vector<double> field_left;
|
||||
std::vector<double> field_right;
|
||||
Core core;
|
||||
std::unique_ptr<PublicFilterbank> analysis_bank;
|
||||
std::unique_ptr<PublicFilterbank> synthesis_bank;
|
||||
std::unique_ptr<RosellaBank> analysis_bank;
|
||||
std::unique_ptr<RosellaBank> synthesis_bank;
|
||||
timeline::OamdPositionTimeline timeline{timeline::kTimelineObjects};
|
||||
|
||||
std::vector<double> buffer; // [chunk_samples][16]
|
||||
@@ -1051,9 +1051,7 @@ struct RosellaRuntime::Impl {
|
||||
analysis_bank->analyze_qmf(hops_, slots, &qmf_);
|
||||
analysis_bank->analyze_hybrid(qmf_, slots, &hybrid_);
|
||||
|
||||
if (rendered_.size() < slots * 2u * kHybridBands) {
|
||||
rendered_.resize(slots * 2u * kHybridBands);
|
||||
}
|
||||
if (room_sends_buffer_.size() != slots * kHybridBands) {
|
||||
room_sends_buffer_.resize(slots * kHybridBands);
|
||||
}
|
||||
@@ -1122,7 +1120,8 @@ struct RosellaRuntime::Impl {
|
||||
// rosella_binaural_renderer._set_block_parameters.
|
||||
Status set_block_parameters(std::int64_t sample) {
|
||||
double positions[timeline::kTimelineObjects][3] = {};
|
||||
Status status = timeline.positions_at(sample, positions);
|
||||
Status status = timeline.positions_at(sample, &positions[0][0],
|
||||
timeline::kTimelineObjects);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
@@ -1141,10 +1140,12 @@ struct RosellaRuntime::Impl {
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
// The reference drops the first 961 samples of the raw stream (the filterbank's
|
||||
// latency) and returns everything after that.
|
||||
// The reference drops the first `latency` samples of the raw stream (the
|
||||
// filterbank's own delay) and returns everything after that; the latency is
|
||||
// the selected bank's, so the two banks start at different sample offsets.
|
||||
void append_output(const double* stereo, std::size_t count) {
|
||||
const std::int64_t remaining = static_cast<std::int64_t>(kLatencySamples) -
|
||||
const std::int64_t remaining =
|
||||
static_cast<std::int64_t>(rosella_bank_latency(options.bank)) -
|
||||
static_cast<std::int64_t>(raw_output_samples);
|
||||
const std::size_t skip = static_cast<std::size_t>(
|
||||
std::max<std::int64_t>(0, std::min<std::int64_t>(static_cast<std::int64_t>(count),
|
||||
@@ -1191,6 +1192,9 @@ Status RosellaRuntime::open(const RosellaModel& model, const RosellaRenderOption
|
||||
if (options.object_delay_samples < 0) {
|
||||
return render_fail(JOC_ERR_INVALID_ARGUMENT, "object_delay_samples must be non-negative");
|
||||
}
|
||||
if (options.bank != RosellaBankKind::Public && options.bank != RosellaBankKind::Captured) {
|
||||
return render_fail(JOC_ERR_INVALID_ARGUMENT, "unknown Rosella filterbank");
|
||||
}
|
||||
impl_->model = model;
|
||||
impl_->options = options;
|
||||
logical_field(impl_->model.field_left_padded, &impl_->field_left);
|
||||
@@ -1203,8 +1207,8 @@ Status RosellaRuntime::open(const RosellaModel& model, const RosellaRenderOption
|
||||
return status;
|
||||
}
|
||||
// The analysis bank runs sixteen sources, the synthesis bank two output ears.
|
||||
impl_->analysis_bank = std::make_unique<PublicFilterbank>(builtin_kernels(), kSourceChannels);
|
||||
impl_->synthesis_bank = std::make_unique<PublicFilterbank>(builtin_kernels(), kOutputChannels);
|
||||
impl_->analysis_bank = RosellaBank::create(options.bank, kSourceChannels);
|
||||
impl_->synthesis_bank = RosellaBank::create(options.bank, kOutputChannels);
|
||||
impl_->buffer.assign(impl_->chunk_samples() * kSourceChannels, 0.0);
|
||||
impl_->room_sends_buffer_.assign(
|
||||
(impl_->chunk_samples() / kQmfHop) * kHybridBands, Complex(0.0, 0.0));
|
||||
@@ -1309,7 +1313,8 @@ Status RosellaRuntime::finish(std::uint32_t flush_samples, std::vector<double>*
|
||||
}
|
||||
|
||||
std::uint32_t RosellaRuntime::finish_capacity(double tail_seconds) const {
|
||||
const double samples = tail_seconds * 48000.0 + static_cast<double>(kLatencySamples) +
|
||||
const double samples = tail_seconds * 48000.0 +
|
||||
static_cast<double>(rosella_bank_latency(impl_->options.bank)) +
|
||||
static_cast<double>(kBlockSamples);
|
||||
const double blocks = std::ceil(samples / static_cast<double>(kBlockSamples));
|
||||
return static_cast<std::uint32_t>(blocks) * kBlockSamples;
|
||||
@@ -1329,7 +1334,7 @@ Status RosellaRuntime::reset() {
|
||||
impl_->raw_output_samples = 0u;
|
||||
impl_->metadata_block_updates = 0u;
|
||||
impl_->finished = false;
|
||||
impl_->timeline = timeline::OamdPositionTimeline(timeline::kTimelineObjects);
|
||||
impl_->timeline.reset();
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
@@ -1339,7 +1344,7 @@ void RosellaRuntime::take_output(std::vector<double>* out) {
|
||||
if (out == nullptr) {
|
||||
return;
|
||||
}
|
||||
// Replace semantics, exactly like SofaBinauralRuntime::take_output: the caller's
|
||||
// Replace semantics, exactly like JochrtfRuntime::take_output: the caller's
|
||||
// previous contents are discarded, and the internal buffer is emptied afterwards
|
||||
// because the swap leaves it holding whatever the caller had.
|
||||
out->swap(impl_->output);
|
||||
@@ -1355,4 +1360,8 @@ std::uint64_t RosellaRuntime::metadata_block_updates() const {
|
||||
}
|
||||
const timeline::OamdPositionTimeline& RosellaRuntime::timeline() const { return impl_->timeline; }
|
||||
|
||||
void RosellaRuntime::set_fixed_position(int object_index, const double position[3]) {
|
||||
impl_->timeline.set_fixed_position(object_index, position);
|
||||
}
|
||||
|
||||
} // namespace joc::hrtf
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/status.h"
|
||||
#include "hrtf/rosella_bank.h"
|
||||
#include "hrtf/rosella_model.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
#include "timeline/position_timeline.h"
|
||||
@@ -21,6 +22,9 @@ enum class RosellaProfile : std::int32_t { Near = 1, Far = 2, Mid = 3 };
|
||||
|
||||
struct RosellaRenderOptions {
|
||||
RosellaProfile profile = RosellaProfile::Mid;
|
||||
// The analysis and synthesis banks both come from this one choice, so the
|
||||
// latency skip, the flush capacity and the state histories stay consistent.
|
||||
RosellaBankKind bank = RosellaBankKind::Public;
|
||||
std::int64_t object_delay_samples = 1473;
|
||||
double tail_seconds = 5.0;
|
||||
double output_gain = 1.0;
|
||||
@@ -56,6 +60,9 @@ public:
|
||||
std::uint64_t metadata_block_updates() const;
|
||||
const timeline::OamdPositionTimeline& timeline() const;
|
||||
|
||||
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
|
||||
void set_fixed_position(int object_index, const double position[3]);
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
|
||||
@@ -1,255 +0,0 @@
|
||||
#include "hrtf/sofa.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <utility>
|
||||
|
||||
#include "foundation/fs_utf8.h"
|
||||
#include "foundation/sha256.h"
|
||||
#include "io/hdf5.h"
|
||||
|
||||
namespace joc::hrtf {
|
||||
|
||||
namespace {
|
||||
|
||||
Status sofa_fail(joc_error code, const std::string& message) {
|
||||
return Status::fail(code, stage::kRender, message);
|
||||
}
|
||||
|
||||
std::string format_number(double value) {
|
||||
if (std::isfinite(value) && value == std::floor(value) && std::fabs(value) < 1.0e15) {
|
||||
return std::to_string(static_cast<long long>(value));
|
||||
}
|
||||
char buffer[32];
|
||||
std::snprintf(buffer, sizeof(buffer), "%.6g", value);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
// Every array is checked against the element count the convention prescribes, so
|
||||
// a file whose shape disagrees with its metadata is rejected instead of silently
|
||||
// producing a shifted impulse response.
|
||||
Status read_doubles(const io::Hdf5File& file, const std::string& path, std::uint64_t expected,
|
||||
std::vector<double>* out) {
|
||||
if (!file.has_dataset(path)) {
|
||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA file has no " + path + " dataset");
|
||||
}
|
||||
const Status status = file.read_dataset_double(path, out);
|
||||
if (!status.ok()) {
|
||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA dataset " + path + ": " + status.message());
|
||||
}
|
||||
if (out->size() != expected) {
|
||||
return sofa_fail(JOC_ERR_HRTF_FORMAT,
|
||||
"SOFA dataset " + path + " holds " + std::to_string(out->size()) +
|
||||
" values, expected " + std::to_string(expected));
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status read_text(const io::Hdf5File& file, const std::string& name, bool required,
|
||||
std::string* out) {
|
||||
io::Hdf5Attribute attribute;
|
||||
const Status status = file.attribute("", name, &attribute);
|
||||
if (!status.ok()) {
|
||||
if (required) {
|
||||
return sofa_fail(JOC_ERR_HRTF_FORMAT,
|
||||
"SOFA file has no root attribute " + name + ": " + status.message());
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
*out = attribute.text;
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
// SHA-256 of the whole file: the compiled-cache key is derived from it, so the
|
||||
// digest is taken over the exact bytes the parse consumed.
|
||||
std::string file_digest(const std::string& path) {
|
||||
std::ifstream stream = fs_utf8::open_input(path);
|
||||
if (!stream.good()) {
|
||||
return std::string();
|
||||
}
|
||||
crypto::Sha256 hash;
|
||||
std::vector<char> buffer(1u << 20);
|
||||
while (stream.good()) {
|
||||
stream.read(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
||||
const std::streamsize count = stream.gcount();
|
||||
if (count > 0) {
|
||||
hash.update(buffer.data(), static_cast<std::size_t>(count));
|
||||
}
|
||||
}
|
||||
return hash.finish_hex();
|
||||
}
|
||||
|
||||
// The coordinate declaration of one dataset, when the file carries it.
|
||||
void read_coordinates(const io::Hdf5File& file, const std::string& dataset,
|
||||
SofaCoordinate* out) {
|
||||
io::Hdf5Attribute attribute;
|
||||
if (file.attribute(dataset, "Type", &attribute).ok()) {
|
||||
out->type = attribute.text;
|
||||
}
|
||||
if (file.attribute(dataset, "Units", &attribute).ok()) {
|
||||
out->units = attribute.text;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string SofaHrir::summary() const {
|
||||
return "SOFA " + sofa_conventions + ", " + std::to_string(ir_count) + " IRs x " +
|
||||
std::to_string(ir_length) + " taps @ " + format_number(sample_rate) + " Hz";
|
||||
}
|
||||
|
||||
Status load_sofa(const std::string& path, SofaHrir* out) {
|
||||
if (out == nullptr) {
|
||||
return sofa_fail(JOC_ERR_INVALID_ARGUMENT, "null SOFA destination");
|
||||
}
|
||||
if (!fs_utf8::exists(path)) {
|
||||
return sofa_fail(JOC_ERR_HRTF_NOT_FOUND, "SOFA file not found: " + path);
|
||||
}
|
||||
io::Hdf5File file;
|
||||
Status status = file.open(path);
|
||||
if (!status.ok()) {
|
||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA file " + path + ": " + status.message());
|
||||
}
|
||||
|
||||
SofaHrir sofa;
|
||||
sofa.source_path = path;
|
||||
sofa.source_sha256 = file_digest(path);
|
||||
for (char& character : sofa.source_sha256) {
|
||||
character = static_cast<char>(std::toupper(static_cast<unsigned char>(character)));
|
||||
}
|
||||
status = read_text(file, "Conventions", true, &sofa.conventions);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = read_text(file, "SOFAConventions", true, &sofa.sofa_conventions);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
if (sofa.conventions != "SOFA" || sofa.sofa_conventions != "SimpleFreeFieldHRIR") {
|
||||
return sofa_fail(JOC_ERR_HRTF_UNSUPPORTED_CONVENTION,
|
||||
"SOFA conventions " + sofa.conventions + "/" + sofa.sofa_conventions +
|
||||
" are not SimpleFreeFieldHRIR");
|
||||
}
|
||||
status = read_text(file, "SOFAConventionsVersion", false, &sofa.convention_version);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = read_text(file, "Version", false, &sofa.version);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = read_text(file, "DataType", false, &sofa.data_type);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = read_text(file, "RoomType", false, &sofa.room_type);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = read_text(file, "Title", false, &sofa.title);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = read_text(file, "DatabaseName", false, &sofa.database_name);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = read_text(file, "ListenerShortName", false, &sofa.listener_short_name);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = read_text(file, "Comment", false, &sofa.comment);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
io::Hdf5DatasetInfo info;
|
||||
status = file.dataset_info("Data.IR", &info);
|
||||
if (!status.ok()) {
|
||||
return sofa_fail(JOC_ERR_HRTF_FORMAT,
|
||||
"SOFA file has no usable Data.IR dataset: " + status.message());
|
||||
}
|
||||
if (info.shape.size() != 3u || info.shape[1] != 2u || info.shape[0] == 0u ||
|
||||
info.shape[2] == 0u) {
|
||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA Data.IR is not shaped (M, 2, N)");
|
||||
}
|
||||
if (info.shape[0] > 0xFFFFFFFFull || info.shape[2] > 0xFFFFFFFFull) {
|
||||
return sofa_fail(JOC_ERR_HRTF_FORMAT, "SOFA Data.IR is larger than this reader accepts");
|
||||
}
|
||||
sofa.ir_count = static_cast<std::uint32_t>(info.shape[0]);
|
||||
sofa.ir_length = static_cast<std::uint32_t>(info.shape[2]);
|
||||
const std::uint64_t taps = static_cast<std::uint64_t>(sofa.ir_count) * 2u * sofa.ir_length;
|
||||
status = read_doubles(file, "Data.IR", taps, &sofa.ir);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
std::vector<double> scalar;
|
||||
status = read_doubles(file, "Data.SamplingRate", 1u, &scalar);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
sofa.sample_rate = scalar[0];
|
||||
io::Hdf5Attribute attribute;
|
||||
if (file.attribute("Data.SamplingRate", "Units", &attribute).ok()) {
|
||||
sofa.sampling_rate_units = attribute.text;
|
||||
}
|
||||
|
||||
// Data.Delay is optional in the wild; absent means "no delay was measured".
|
||||
if (file.has_dataset("Data.Delay")) {
|
||||
std::vector<double> delay;
|
||||
status = read_doubles(file, "Data.Delay", 2u, &delay);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
sofa.delay[0] = delay[0];
|
||||
sofa.delay[1] = delay[1];
|
||||
}
|
||||
|
||||
const std::uint64_t measurements = sofa.ir_count;
|
||||
status = read_doubles(file, "SourcePosition", measurements * 3u, &sofa.source_position);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
read_coordinates(file, "SourcePosition", &sofa.source_position_coordinates);
|
||||
|
||||
std::vector<double> vector;
|
||||
status = read_doubles(file, "ListenerPosition", 3u, &vector);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
std::copy(vector.begin(), vector.end(), sofa.listener_position);
|
||||
read_coordinates(file, "ListenerPosition", &sofa.listener_position_coordinates);
|
||||
status = read_doubles(file, "ListenerView", 3u, &vector);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
std::copy(vector.begin(), vector.end(), sofa.listener_view);
|
||||
read_coordinates(file, "ListenerView", &sofa.listener_view_coordinates);
|
||||
status = read_doubles(file, "ListenerUp", 3u, &vector);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
std::copy(vector.begin(), vector.end(), sofa.listener_up);
|
||||
read_coordinates(file, "ListenerUp", &sofa.listener_up_coordinates);
|
||||
status = read_doubles(file, "EmitterPosition", 3u, &vector);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
std::copy(vector.begin(), vector.end(), sofa.emitter_position);
|
||||
read_coordinates(file, "EmitterPosition", &sofa.emitter_position_coordinates);
|
||||
status = read_doubles(file, "ReceiverPosition", 6u, &vector);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
std::copy(vector.begin(), vector.end(), sofa.receiver_position);
|
||||
read_coordinates(file, "ReceiverPosition", &sofa.receiver_position_coordinates);
|
||||
|
||||
*out = std::move(sofa);
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
} // namespace joc::hrtf
|
||||
@@ -1,61 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/status.h"
|
||||
|
||||
namespace joc::hrtf {
|
||||
|
||||
// Coordinate declaration of one SOFA variable: Type ("spherical"/"cartesian") and
|
||||
// Units. Empty when the file does not declare them (ListenerUp inherits).
|
||||
struct SofaCoordinate {
|
||||
std::string type;
|
||||
std::string units;
|
||||
};
|
||||
|
||||
// SOFA SimpleFreeFieldHRIR as this project consumes it: the impulse responses,
|
||||
// the measurement geometry and the metadata needed to report what was loaded.
|
||||
// All angles are degrees, all distances metres, exactly as the file stores them.
|
||||
struct SofaHrir {
|
||||
double sample_rate = 0.0;
|
||||
std::uint32_t ir_count = 0; // M: number of measurements
|
||||
std::uint32_t ir_length = 0; // N: taps per impulse response
|
||||
std::vector<double> ir; // C order [M][2][N]
|
||||
double delay[2] = {0.0, 0.0};
|
||||
std::vector<double> source_position; // M*3
|
||||
double listener_position[3] = {0.0, 0.0, 0.0};
|
||||
double listener_view[3] = {1.0, 0.0, 0.0};
|
||||
double listener_up[3] = {0.0, 0.0, 1.0};
|
||||
double emitter_position[3] = {0.0, 0.0, 0.0};
|
||||
double receiver_position[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||
std::string conventions;
|
||||
std::string sofa_conventions;
|
||||
std::string convention_version;
|
||||
std::string version;
|
||||
std::string data_type;
|
||||
std::string room_type;
|
||||
std::string title;
|
||||
std::string database_name;
|
||||
std::string listener_short_name;
|
||||
std::string comment;
|
||||
std::string sampling_rate_units;
|
||||
SofaCoordinate source_position_coordinates;
|
||||
SofaCoordinate listener_position_coordinates;
|
||||
SofaCoordinate listener_view_coordinates;
|
||||
SofaCoordinate listener_up_coordinates;
|
||||
SofaCoordinate emitter_position_coordinates;
|
||||
SofaCoordinate receiver_position_coordinates;
|
||||
// Identity of the file itself, needed for the compiled-cache key.
|
||||
std::string source_path;
|
||||
std::string source_sha256;
|
||||
|
||||
// One line for reports and logs:
|
||||
// "SOFA SimpleFreeFieldHRIR, <M> IRs x <N> taps @ <rate> Hz".
|
||||
std::string summary() const;
|
||||
};
|
||||
|
||||
Status load_sofa(const std::string& path, SofaHrir* out);
|
||||
|
||||
} // namespace joc::hrtf
|
||||
@@ -1,237 +0,0 @@
|
||||
#include "hrtf/sofa_cache.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/fs_utf8.h"
|
||||
#include "hrtf/sofa.h"
|
||||
|
||||
namespace joc::hrtf {
|
||||
|
||||
namespace {
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// Small process-local cache: the reference keeps the last eight compiled fields.
|
||||
constexpr std::size_t kMemoryCacheEntries = 8;
|
||||
|
||||
struct MemoryEntry {
|
||||
std::string key;
|
||||
Field field;
|
||||
};
|
||||
|
||||
std::mutex& memory_mutex() {
|
||||
static std::mutex mutex;
|
||||
return mutex;
|
||||
}
|
||||
|
||||
std::list<MemoryEntry>& memory_cache() {
|
||||
static std::list<MemoryEntry> cache;
|
||||
return cache;
|
||||
}
|
||||
|
||||
bool memory_cache_get(const std::string& key, Field* out) {
|
||||
std::lock_guard<std::mutex> lock(memory_mutex());
|
||||
std::list<MemoryEntry>& cache = memory_cache();
|
||||
for (auto entry = cache.begin(); entry != cache.end(); ++entry) {
|
||||
if (entry->key == key) {
|
||||
*out = entry->field;
|
||||
cache.splice(cache.begin(), cache, entry);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void memory_cache_put(const std::string& key, const Field& field) {
|
||||
std::lock_guard<std::mutex> lock(memory_mutex());
|
||||
std::list<MemoryEntry>& cache = memory_cache();
|
||||
for (auto entry = cache.begin(); entry != cache.end(); ++entry) {
|
||||
if (entry->key == key) {
|
||||
entry->field = field;
|
||||
cache.splice(cache.begin(), cache, entry);
|
||||
return;
|
||||
}
|
||||
}
|
||||
cache.push_front(MemoryEntry{key, field});
|
||||
while (cache.size() > kMemoryCacheEntries) {
|
||||
cache.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
Status cache_fail(joc_error code, const std::string& message) {
|
||||
return Status::fail(code, stage::kRender, message);
|
||||
}
|
||||
|
||||
std::string upper(std::string text) {
|
||||
std::transform(text.begin(), text.end(), text.begin(), [](unsigned char value) {
|
||||
return static_cast<char>(std::toupper(value));
|
||||
});
|
||||
return text;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Status parse_cache_policy(const std::string& text, CachePolicy* out) {
|
||||
if (out == nullptr) {
|
||||
return cache_fail(JOC_ERR_INVALID_ARGUMENT, "null cache policy");
|
||||
}
|
||||
if (text == "none") {
|
||||
*out = CachePolicy::None;
|
||||
return Status::success();
|
||||
}
|
||||
if (text == "memory") {
|
||||
*out = CachePolicy::Memory;
|
||||
return Status::success();
|
||||
}
|
||||
if (text == "disk") {
|
||||
*out = CachePolicy::Disk;
|
||||
return Status::success();
|
||||
}
|
||||
return cache_fail(JOC_ERR_INVALID_CONFIG, "cache_policy must be none, memory, or disk");
|
||||
}
|
||||
|
||||
Status validate_jochrtf(const std::string& path, const std::string& source_sha256,
|
||||
const std::string& cache_key, Field* out) {
|
||||
Field field;
|
||||
const Status status = load_jochrtf(path, &field);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
if (!source_sha256.empty() && field.source_sha256 != upper(source_sha256)) {
|
||||
return cache_fail(JOC_ERR_HRTF_HASH, "compiled HRTF source hash mismatch");
|
||||
}
|
||||
if (!cache_key.empty() && field.cache_key != upper(cache_key)) {
|
||||
return cache_fail(JOC_ERR_HRTF_HASH, "compiled HRTF configuration hash mismatch");
|
||||
}
|
||||
if (out != nullptr) {
|
||||
*out = std::move(field);
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status save_jochrtf_atomic(const Field& field, const std::string& path) {
|
||||
if (path.empty()) {
|
||||
return cache_fail(JOC_ERR_INVALID_ARGUMENT, "empty compiled HRTF cache path");
|
||||
}
|
||||
const fs::path target = fs_utf8::to_path(path);
|
||||
std::error_code error;
|
||||
if (target.has_parent_path()) {
|
||||
fs::create_directories(target.parent_path(), error);
|
||||
if (error) {
|
||||
return cache_fail(JOC_ERR_OUTPUT_OPEN,
|
||||
"cannot create " + fs_utf8::from_path(target.parent_path()));
|
||||
}
|
||||
}
|
||||
const std::string temporary = path + ".tmp";
|
||||
Status status = write_jochrtf(field, temporary);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
// The rename is what makes a half-written cache impossible to observe.
|
||||
fs::rename(fs_utf8::to_path(temporary), target, error);
|
||||
if (error) {
|
||||
fs::remove(fs_utf8::to_path(temporary), error);
|
||||
return cache_fail(JOC_ERR_OUTPUT_WRITE, "cannot replace " + path);
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status load_or_compile_sofa_field(const SofaFieldRequest& request, Field* out,
|
||||
std::string* cache_path) {
|
||||
if (out == nullptr) {
|
||||
return cache_fail(JOC_ERR_INVALID_ARGUMENT, "null compiled HRTF destination");
|
||||
}
|
||||
if (request.sofa_path.empty()) {
|
||||
return cache_fail(JOC_ERR_INVALID_ARGUMENT, "no SOFA path for the compiled HRTF field");
|
||||
}
|
||||
if (request.policy == CachePolicy::Disk && request.cache_dir.empty()) {
|
||||
return cache_fail(JOC_ERR_INVALID_CONFIG, "the disk cache policy needs a cache directory");
|
||||
}
|
||||
SofaHrir sofa;
|
||||
Status status = load_sofa(request.sofa_path, &sofa);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
CanonicalHrtf canonical;
|
||||
status = canonicalize_sofa(sofa, &canonical);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
// The key depends on the shell that the radius selects, exactly as upstream.
|
||||
double actual_radius = request.options.shell_radius_m;
|
||||
(void)canonical_shell_indices(canonical, request.options.shell_radius_m, &actual_radius);
|
||||
const std::string key = compiled_hrtf_cache_key(
|
||||
canonical.source_sha256, canonical.sample_rate_hz, actual_radius, request.options.order,
|
||||
request.options.projection_ridge, request.options.sh_ridge);
|
||||
if (cache_path != nullptr) {
|
||||
cache_path->clear();
|
||||
}
|
||||
|
||||
std::string target;
|
||||
if (request.policy == CachePolicy::Disk) {
|
||||
target = request.cache_dir;
|
||||
if (!target.empty() && target.back() != '/' && target.back() != '\\') {
|
||||
target += "/";
|
||||
}
|
||||
target += cache_file_name(canonical.source_path.empty()
|
||||
? std::string()
|
||||
: canonical.source_path,
|
||||
key);
|
||||
if (fs_utf8::exists(target)) {
|
||||
Field cached_field;
|
||||
const Status cached =
|
||||
validate_jochrtf(target, canonical.source_sha256, key, &cached_field);
|
||||
if (cached.ok()) {
|
||||
memory_cache_put(key, cached_field);
|
||||
*out = std::move(cached_field);
|
||||
if (cache_path != nullptr) {
|
||||
*cache_path = target;
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
}
|
||||
}
|
||||
Field field;
|
||||
if (request.policy != CachePolicy::None && memory_cache_get(key, &field)) {
|
||||
// A memory hit still materialises the disk cache the caller asked for.
|
||||
if (request.policy == CachePolicy::Disk) {
|
||||
status = save_jochrtf_atomic(field, target);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
if (cache_path != nullptr) {
|
||||
*cache_path = target;
|
||||
}
|
||||
}
|
||||
*out = std::move(field);
|
||||
return Status::success();
|
||||
}
|
||||
status = compile_canonical_field(canonical, request.options, &field);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
if (field.cache_key != key) {
|
||||
return cache_fail(JOC_ERR_INTERNAL, "internal compiled HRTF cache-key mismatch");
|
||||
}
|
||||
if (request.policy == CachePolicy::Disk) {
|
||||
status = save_jochrtf_atomic(field, target);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
if (cache_path != nullptr) {
|
||||
*cache_path = target;
|
||||
}
|
||||
}
|
||||
if (request.policy != CachePolicy::None) {
|
||||
memory_cache_put(key, field);
|
||||
}
|
||||
*out = std::move(field);
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
} // namespace joc::hrtf
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "foundation/status.h"
|
||||
#include "hrtf/jochrtf.h"
|
||||
#include "hrtf/sofa_field.h"
|
||||
|
||||
// Compiled-field cache: the .jochrtf is an internal artifact, so the caller only
|
||||
// names the SOFA file and the policy. "memory" keeps the compiled field in this
|
||||
// process, "disk" additionally reuses (and writes) <cache_dir>/<name>.<key>.jochrtf.
|
||||
namespace joc::hrtf {
|
||||
|
||||
enum class CachePolicy { None, Memory, Disk };
|
||||
|
||||
struct SofaFieldRequest {
|
||||
std::string sofa_path;
|
||||
CompileOptions options;
|
||||
CachePolicy policy = CachePolicy::Memory;
|
||||
std::string cache_dir; // required for the disk policy
|
||||
};
|
||||
|
||||
// Parses "none"/"memory"/"disk"; anything else is rejected.
|
||||
Status parse_cache_policy(const std::string& text, CachePolicy* out);
|
||||
|
||||
// Returns the compiled field, reusing a valid cache when the policy allows it.
|
||||
// `cache_path` (optional) receives the cache file that was read or written.
|
||||
Status load_or_compile_sofa_field(const SofaFieldRequest& request, Field* out,
|
||||
std::string* cache_path);
|
||||
|
||||
// Writes the field to `path` through a temporary file and an atomic rename.
|
||||
Status save_jochrtf_atomic(const Field& field, const std::string& path);
|
||||
|
||||
// Verifies that a cache file belongs to `source_sha256` and `cache_key`.
|
||||
Status validate_jochrtf(const std::string& path, const std::string& source_sha256,
|
||||
const std::string& cache_key, Field* out);
|
||||
|
||||
} // namespace joc::hrtf
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,103 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/status.h"
|
||||
#include "hrtf/jochrtf.h"
|
||||
#include "hrtf/sofa.h"
|
||||
|
||||
// SOFA SimpleFreeFieldHRIR -> compiled directional field, ported from the
|
||||
// reference chain (sofa_canonical.py + sofa_hrtf_field.py + the public
|
||||
// filterbank): the measurement shell is selected, one delay representation is
|
||||
// separated, the FIRs are projected onto the 64-QMF/77-hybrid filterbank and the
|
||||
// result is fitted with fifth-order ACN/N3D real spherical harmonics.
|
||||
namespace joc::hrtf {
|
||||
|
||||
inline constexpr int kFieldOrder = 5;
|
||||
inline constexpr int kFieldTerms = 36;
|
||||
inline constexpr double kFieldSampleRateHz = 48000.0;
|
||||
inline constexpr double kDefaultShellRadiusM = 1.0;
|
||||
inline constexpr double kDefaultProjectionRidge = 1.0e-3;
|
||||
inline constexpr double kDefaultSphericalHarmonicRidge = 1.0e-5;
|
||||
inline constexpr const char* kCompilerVersion = "joc-sofa-compiler-v1";
|
||||
inline constexpr const char* kPhasePolicyVersion = "sofa-delay-exactly-once-v1";
|
||||
inline constexpr const char* kShConvention = "ACN/N3D real";
|
||||
inline constexpr const char* kFilterbankTableVersion = "joc-public-64qmf-77hybrid-v1";
|
||||
// SHA-256 of the standard filterbank archive the embedded tables came from. It
|
||||
// participates in the cache key, so it is part of the file-format contract.
|
||||
inline constexpr const char* kFilterbankArchiveSha256 =
|
||||
"C05BEF4D26E96ECBD4694E2572F05DA400255C777BA5047300B9D3B1F81081CD";
|
||||
|
||||
struct CompileOptions {
|
||||
double shell_radius_m = kDefaultShellRadiusM;
|
||||
int order = kFieldOrder;
|
||||
double projection_ridge = kDefaultProjectionRidge;
|
||||
double sh_ridge = kDefaultSphericalHarmonicRidge;
|
||||
};
|
||||
|
||||
// Canonical HRIR set: Data.IR and Data.Delay stay separate, the listener frame is
|
||||
// applied to the source positions and the ears are ordered left/right.
|
||||
struct CanonicalHrtf {
|
||||
std::string source_path;
|
||||
std::string source_sha256;
|
||||
std::string convention;
|
||||
std::string convention_version;
|
||||
std::string processing_label;
|
||||
double sample_rate_hz = 0.0;
|
||||
std::uint32_t measurements = 0;
|
||||
std::uint32_t taps = 0;
|
||||
int left_receiver_index = 0;
|
||||
int right_receiver_index = 1;
|
||||
std::vector<double> source_position_cartesian_m; // [M,3] listener-local
|
||||
std::vector<double> unit_directions; // [M,3]
|
||||
std::vector<double> measurement_radius_m; // [M]
|
||||
std::vector<double> hrir; // [M,2,N] canonical L/R
|
||||
std::vector<double> delay_samples; // [M,2], not applied
|
||||
};
|
||||
|
||||
// Port of load_simple_free_field_hrir(): strict SimpleFreeFieldHRIR import.
|
||||
Status canonicalize_sofa(const SofaHrir& sofa, CanonicalHrtf* out);
|
||||
|
||||
// Compiles the canonical set into the runtime field (port of SofaHrtfField.fit).
|
||||
Status compile_sofa_field(const SofaHrir& sofa, const CompileOptions& options, Field* out);
|
||||
|
||||
// The measurements on the shell nearest to radius_m; actual_radius_m receives the
|
||||
// mean radius of that shell (upstream CanonicalHrtf.shell_indices).
|
||||
std::vector<std::size_t> canonical_shell_indices(const CanonicalHrtf& canonical, double radius_m,
|
||||
double* actual_radius_m);
|
||||
|
||||
// Compiles an already canonicalized set (used by tests and the cache layer).
|
||||
Status compile_canonical_field(const CanonicalHrtf& canonical, const CompileOptions& options,
|
||||
Field* out);
|
||||
|
||||
// Configuration hash that names the cache file (upstream compiled_hrtf_cache_key).
|
||||
std::string compiled_hrtf_cache_key(const std::string& source_sha256, double sample_rate_hz,
|
||||
double shell_radius_m, int order, double projection_ridge,
|
||||
double sh_ridge);
|
||||
|
||||
// Payload hash over the four arrays (upstream _payload_sha256).
|
||||
std::string field_payload_sha256(const Field& field);
|
||||
|
||||
// "<stem>.<first 20 key digits>.jochrtf", the upstream cache file name.
|
||||
std::string cache_file_name(const std::string& display_name, const std::string& cache_key);
|
||||
|
||||
// Serializes the field as a .jochrtf cache the upstream loader also accepts.
|
||||
Status write_jochrtf(const Field& field, const std::string& path);
|
||||
|
||||
// The analysis/gain/synthesis dictionary the projection solves against (dev check).
|
||||
std::vector<double> hybrid_gain_synthesis_dictionary_for_check(std::size_t sample_count);
|
||||
|
||||
// Shell directions and their spherical Voronoi weights (dev check).
|
||||
void shell_directions_and_weights_for_check(const SofaHrir& sofa, double radius_m,
|
||||
std::vector<double>* directions,
|
||||
std::vector<double>* weights);
|
||||
|
||||
// PublicAnalysis77 on a unit impulse, interleaved complex (dev check).
|
||||
std::vector<double> analysis_impulse_for_check(std::size_t total_samples);
|
||||
|
||||
// The 77 hybrid-band centre frequencies at 48 kHz.
|
||||
const std::vector<double>& hybrid_band_center_frequencies_hz();
|
||||
|
||||
} // namespace joc::hrtf
|
||||
@@ -0,0 +1,207 @@
|
||||
#include "io/wav_pcm.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
|
||||
namespace joc::io {
|
||||
|
||||
namespace {
|
||||
|
||||
std::uint16_t read_u16(const std::uint8_t* data) {
|
||||
return static_cast<std::uint16_t>(data[0] | (data[1] << 8));
|
||||
}
|
||||
|
||||
std::uint32_t read_u32(const std::uint8_t* data) {
|
||||
return static_cast<std::uint32_t>(data[0]) |
|
||||
(static_cast<std::uint32_t>(data[1]) << 8) |
|
||||
(static_cast<std::uint32_t>(data[2]) << 16) |
|
||||
(static_cast<std::uint32_t>(data[3]) << 24);
|
||||
}
|
||||
|
||||
void write_u16(std::vector<std::uint8_t>* out, std::uint16_t value) {
|
||||
out->push_back(static_cast<std::uint8_t>(value & 0xFFu));
|
||||
out->push_back(static_cast<std::uint8_t>((value >> 8) & 0xFFu));
|
||||
}
|
||||
|
||||
void write_u32(std::vector<std::uint8_t>* out, std::uint32_t value) {
|
||||
out->push_back(static_cast<std::uint8_t>(value & 0xFFu));
|
||||
out->push_back(static_cast<std::uint8_t>((value >> 8) & 0xFFu));
|
||||
out->push_back(static_cast<std::uint8_t>((value >> 16) & 0xFFu));
|
||||
out->push_back(static_cast<std::uint8_t>((value >> 24) & 0xFFu));
|
||||
}
|
||||
|
||||
std::string fourcc(const std::uint8_t* data) {
|
||||
return std::string(reinterpret_cast<const char*>(data), 4);
|
||||
}
|
||||
|
||||
float sample_to_float(const std::uint8_t* data, std::uint16_t format, std::uint16_t bits) {
|
||||
if (format == 3u) {
|
||||
if (bits == 32u) {
|
||||
float value = 0.0f;
|
||||
std::memcpy(&value, data, sizeof(value));
|
||||
return value;
|
||||
}
|
||||
double value = 0.0;
|
||||
std::memcpy(&value, data, sizeof(value));
|
||||
return static_cast<float>(value);
|
||||
}
|
||||
if (bits == 16u) {
|
||||
const std::int16_t value = static_cast<std::int16_t>(read_u16(data));
|
||||
return static_cast<float>(value) / 32768.0f;
|
||||
}
|
||||
if (bits == 24u) {
|
||||
std::int32_t value = static_cast<std::int32_t>(data[0]) |
|
||||
(static_cast<std::int32_t>(data[1]) << 8) |
|
||||
(static_cast<std::int32_t>(data[2]) << 16);
|
||||
if ((value & 0x00800000) != 0) {
|
||||
value |= static_cast<std::int32_t>(0xFF000000u);
|
||||
}
|
||||
return static_cast<float>(value) / 8388608.0f;
|
||||
}
|
||||
if (bits == 32u) {
|
||||
const std::int32_t value = static_cast<std::int32_t>(read_u32(data));
|
||||
return static_cast<float>(static_cast<double>(value) / 2147483648.0);
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Status read_wav_file(const std::string& path, WavAudio* out) {
|
||||
if (out == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kFoundation,
|
||||
"WAV output pointer is null");
|
||||
}
|
||||
std::ifstream stream(path, std::ios::binary);
|
||||
if (!stream) {
|
||||
return Status::fail(JOC_ERR_IO, stage::kFoundation,
|
||||
"cannot open WAV file: " + path);
|
||||
}
|
||||
std::vector<std::uint8_t> bytes((std::istreambuf_iterator<char>(stream)),
|
||||
std::istreambuf_iterator<char>());
|
||||
if (bytes.size() < 12u || fourcc(bytes.data()) != "RIFF" ||
|
||||
fourcc(bytes.data() + 8) != "WAVE") {
|
||||
return Status::fail(JOC_ERR_INPUT_FORMAT, stage::kFoundation,
|
||||
"not a RIFF/WAVE file: " + path);
|
||||
}
|
||||
|
||||
std::uint16_t format = 0;
|
||||
std::uint16_t channels = 0;
|
||||
std::uint32_t sample_rate = 0;
|
||||
std::uint16_t block_align = 0;
|
||||
std::uint16_t bits = 0;
|
||||
bool have_format = false;
|
||||
std::size_t data_offset = 0;
|
||||
std::size_t data_size = 0;
|
||||
bool have_data = false;
|
||||
|
||||
std::size_t offset = 12;
|
||||
while (offset + 8u <= bytes.size()) {
|
||||
const std::string id = fourcc(bytes.data() + offset);
|
||||
const std::uint32_t size = read_u32(bytes.data() + offset + 4);
|
||||
const std::size_t payload = offset + 8u;
|
||||
if (payload + size > bytes.size()) {
|
||||
return Status::fail(JOC_ERR_INPUT_FORMAT, stage::kFoundation,
|
||||
"truncated WAV chunk: " + id);
|
||||
}
|
||||
if (id == "fmt " && size >= 16u) {
|
||||
format = read_u16(bytes.data() + payload);
|
||||
channels = read_u16(bytes.data() + payload + 2);
|
||||
sample_rate = read_u32(bytes.data() + payload + 4);
|
||||
block_align = read_u16(bytes.data() + payload + 12);
|
||||
bits = read_u16(bytes.data() + payload + 14);
|
||||
if (format == 0xFFFEu && size >= 40u) {
|
||||
// WAVEFORMATEXTENSIBLE: the sub-format GUID starts at +24.
|
||||
format = read_u16(bytes.data() + payload + 24);
|
||||
}
|
||||
have_format = true;
|
||||
} else if (id == "data") {
|
||||
data_offset = payload;
|
||||
data_size = size;
|
||||
have_data = true;
|
||||
}
|
||||
offset = payload + size + (size & 1u);
|
||||
}
|
||||
|
||||
if (!have_format || !have_data || channels == 0 || sample_rate == 0) {
|
||||
return Status::fail(JOC_ERR_INPUT_FORMAT, stage::kFoundation,
|
||||
"WAV file has no usable fmt/data chunk: " + path);
|
||||
}
|
||||
if (format != 1u && format != 3u) {
|
||||
return Status::fail(JOC_ERR_INPUT_FORMAT, stage::kFoundation,
|
||||
"unsupported WAV sample format");
|
||||
}
|
||||
const std::uint16_t bytes_per_sample = static_cast<std::uint16_t>(bits / 8u);
|
||||
if (bytes_per_sample == 0u) {
|
||||
return Status::fail(JOC_ERR_INPUT_FORMAT, stage::kFoundation,
|
||||
"unsupported WAV bit depth");
|
||||
}
|
||||
if (block_align == 0u) {
|
||||
block_align = static_cast<std::uint16_t>(channels * bytes_per_sample);
|
||||
}
|
||||
if (block_align < channels * bytes_per_sample) {
|
||||
return Status::fail(JOC_ERR_INPUT_FORMAT, stage::kFoundation,
|
||||
"invalid WAV block alignment");
|
||||
}
|
||||
const std::size_t frames = data_size / block_align;
|
||||
out->sample_rate = sample_rate;
|
||||
out->channels = channels;
|
||||
out->samples.resize(frames * channels);
|
||||
const std::uint8_t* source = bytes.data() + data_offset;
|
||||
for (std::size_t frame = 0; frame < frames; ++frame) {
|
||||
for (std::size_t channel = 0; channel < channels; ++channel) {
|
||||
out->samples[frame * channels + channel] = sample_to_float(
|
||||
source + frame * block_align + channel * bytes_per_sample, format, bits);
|
||||
}
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status write_wav_float32(const std::string& path, std::uint32_t sample_rate,
|
||||
std::uint16_t channels, const float* interleaved, std::size_t frames) {
|
||||
if (channels == 0u || sample_rate == 0u || interleaved == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOutput,
|
||||
"WAV writer needs channels, a sample rate and samples");
|
||||
}
|
||||
if (frames > (std::numeric_limits<std::uint32_t>::max() - 36u) /
|
||||
(channels * sizeof(float))) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOutput,
|
||||
"WAV output is too large for RIFF");
|
||||
}
|
||||
const std::uint32_t data_bytes =
|
||||
static_cast<std::uint32_t>(frames * channels * sizeof(float));
|
||||
std::vector<std::uint8_t> header;
|
||||
header.reserve(44);
|
||||
header.insert(header.end(), {'R', 'I', 'F', 'F'});
|
||||
write_u32(&header, 36u + data_bytes);
|
||||
header.insert(header.end(), {'W', 'A', 'V', 'E'});
|
||||
header.insert(header.end(), {'f', 'm', 't', ' '});
|
||||
write_u32(&header, 16u);
|
||||
write_u16(&header, 3u); // IEEE float
|
||||
write_u16(&header, channels);
|
||||
write_u32(&header, sample_rate);
|
||||
write_u32(&header, sample_rate * static_cast<std::uint32_t>(channels * sizeof(float)));
|
||||
write_u16(&header, static_cast<std::uint16_t>(channels * sizeof(float)));
|
||||
write_u16(&header, 32u);
|
||||
header.insert(header.end(), {'d', 'a', 't', 'a'});
|
||||
write_u32(&header, data_bytes);
|
||||
|
||||
std::ofstream stream(path, std::ios::binary);
|
||||
if (!stream) {
|
||||
return Status::fail(JOC_ERR_IO, stage::kOutput,
|
||||
"cannot open WAV output: " + path);
|
||||
}
|
||||
stream.write(reinterpret_cast<const char*>(header.data()),
|
||||
static_cast<std::streamsize>(header.size()));
|
||||
stream.write(reinterpret_cast<const char*>(interleaved),
|
||||
static_cast<std::streamsize>(data_bytes));
|
||||
if (!stream) {
|
||||
return Status::fail(JOC_ERR_IO, stage::kOutput,
|
||||
"cannot write WAV output: " + path);
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
} // namespace joc::io
|
||||
@@ -0,0 +1,25 @@
|
||||
// Minimal RIFF/WAVE reader and float32 writer for the multichannel binaural
|
||||
// frontend. It accepts the formats ffmpeg writes for PCM input: 16/24/32-bit
|
||||
// integer, 32/64-bit float, including WAVE_FORMAT_EXTENSIBLE.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/status.h"
|
||||
|
||||
namespace joc::io {
|
||||
|
||||
struct WavAudio {
|
||||
std::uint32_t sample_rate = 0;
|
||||
std::uint16_t channels = 0;
|
||||
std::vector<float> samples; // interleaved
|
||||
};
|
||||
|
||||
Status read_wav_file(const std::string& path, WavAudio* out);
|
||||
|
||||
Status write_wav_float32(const std::string& path, std::uint32_t sample_rate,
|
||||
std::uint16_t channels, const float* interleaved, std::size_t frames);
|
||||
|
||||
} // namespace joc::io
|
||||
@@ -0,0 +1,632 @@
|
||||
|
||||
#include "joc_bitstream/bed_layout_map.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
#include "speaker/speaker_layouts.h"
|
||||
|
||||
namespace joc::joc {
|
||||
namespace {
|
||||
|
||||
constexpr std::uint32_t bit(BedChannel channel) {
|
||||
return 1u << static_cast<unsigned>(channel);
|
||||
}
|
||||
|
||||
// Table 12 每个 bit 展开的声道(LSB 在前)。
|
||||
struct StandardBit {
|
||||
BedChannel first;
|
||||
BedChannel second; // kCount 表示单声道
|
||||
};
|
||||
|
||||
constexpr StandardBit kStandardBits[10] = {
|
||||
{BedChannel::kLeft, BedChannel::kRight},
|
||||
{BedChannel::kCenter, BedChannel::kCount},
|
||||
{BedChannel::kLfe, BedChannel::kCount},
|
||||
{BedChannel::kLeftSurround, BedChannel::kRightSurround},
|
||||
{BedChannel::kLeftRearSurround, BedChannel::kRightRearSurround},
|
||||
{BedChannel::kTopFrontLeft, BedChannel::kTopFrontRight},
|
||||
{BedChannel::kTopSideLeft, BedChannel::kTopSideRight},
|
||||
{BedChannel::kTopBackLeft, BedChannel::kTopBackRight},
|
||||
{BedChannel::kLeftWide, BedChannel::kRightWide},
|
||||
{BedChannel::kLfe2, BedChannel::kCount},
|
||||
};
|
||||
|
||||
// Table 13 的 17 bit 非标准掩码(LSB 在前)。
|
||||
constexpr BedChannel kNonStandardBits[17] = {
|
||||
BedChannel::kLfe2, BedChannel::kRightWide, BedChannel::kLeftWide,
|
||||
BedChannel::kTopBackRight, BedChannel::kTopBackLeft,
|
||||
BedChannel::kTopSideRight, BedChannel::kTopSideLeft,
|
||||
BedChannel::kTopFrontRight, BedChannel::kTopFrontLeft,
|
||||
BedChannel::kRightRearSurround, BedChannel::kLeftRearSurround,
|
||||
BedChannel::kRightSurround, BedChannel::kLeftSurround,
|
||||
BedChannel::kLfe, BedChannel::kCenter, BedChannel::kRight,
|
||||
BedChannel::kLeft,
|
||||
};
|
||||
|
||||
struct ChannelSpec {
|
||||
BedChannel channel;
|
||||
const char* short_name;
|
||||
const char* label;
|
||||
double xyz[3];
|
||||
};
|
||||
|
||||
constexpr ChannelSpec kChannels[] = {
|
||||
{BedChannel::kLeft, "L", "RC_L", {-1.0, 1.0, 0.0}},
|
||||
{BedChannel::kRight, "R", "RC_R", {1.0, 1.0, 0.0}},
|
||||
{BedChannel::kCenter, "C", "RC_C", {0.0, 1.0, 0.0}},
|
||||
{BedChannel::kLfe, "LFE", "RC_LFE", {0.0, 0.0, 0.0}},
|
||||
{BedChannel::kLeftSurround, "Ls", "RC_LS", {-1.0, 0.0, 0.0}},
|
||||
{BedChannel::kRightSurround, "Rs", "RC_RS", {1.0, 0.0, 0.0}},
|
||||
{BedChannel::kLeftRearSurround, "Lrs", "RC_LB", {-1.0, -1.0, 0.0}},
|
||||
{BedChannel::kRightRearSurround, "Rrs", "RC_RB", {1.0, -1.0, 0.0}},
|
||||
{BedChannel::kTopFrontLeft, "Ltf", "RC_TFL", {-0.5, 0.5, 1.0}},
|
||||
{BedChannel::kTopFrontRight, "Rtf", "RC_TFR", {0.5, 0.5, 1.0}},
|
||||
{BedChannel::kTopSideLeft, "Ltm", "RC_TSL", {-1.0, 0.0, 1.0}},
|
||||
{BedChannel::kTopSideRight, "Rtm", "RC_TSR", {1.0, 0.0, 1.0}},
|
||||
{BedChannel::kTopBackLeft, "Ltr", "RC_TBL", {-0.5, -0.5, 1.0}},
|
||||
{BedChannel::kTopBackRight, "Rtr", "RC_TBR", {0.5, -0.5, 1.0}},
|
||||
{BedChannel::kLeftWide, "Lw", "RC_LW", {-1.0, 0.5, 0.0}},
|
||||
{BedChannel::kRightWide, "Rw", "RC_RW", {1.0, 0.5, 0.0}},
|
||||
{BedChannel::kLfe2, "LFE2", "RC_LFE2", {0.0, 0.0, 0.0}},
|
||||
};
|
||||
|
||||
const ChannelSpec* spec_of(BedChannel channel) {
|
||||
for (const ChannelSpec& spec : kChannels) {
|
||||
if (spec.channel == channel) {
|
||||
return &spec;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 标准 bed 布局名,键是声明声道的集合。
|
||||
struct LayoutName {
|
||||
std::uint32_t mask;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
constexpr std::uint32_t mask_of() { return 0u; }
|
||||
|
||||
constexpr LayoutName kLayoutNames[] = {
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight), "2.0"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) | bit(BedChannel::kCenter), "3.0"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) | bit(BedChannel::kCenter) |
|
||||
bit(BedChannel::kLfe), "3.1"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround), "4.0"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter), "5.0"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe), "5.1"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround), "6.0"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround), "7.1"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
|
||||
bit(BedChannel::kLeftWide) | bit(BedChannel::kRightWide), "9.1"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight), "5.1.2"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
|
||||
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "5.1.4"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
|
||||
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight), "7.1.2"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
|
||||
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
|
||||
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "7.1.4"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
|
||||
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
|
||||
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight) |
|
||||
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "7.1.6"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
|
||||
bit(BedChannel::kLeftWide) | bit(BedChannel::kRightWide) |
|
||||
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight), "9.1.2"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
|
||||
bit(BedChannel::kLeftWide) | bit(BedChannel::kRightWide) |
|
||||
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
|
||||
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "9.1.4"},
|
||||
{bit(BedChannel::kLeft) | bit(BedChannel::kRight) |
|
||||
bit(BedChannel::kLeftSurround) | bit(BedChannel::kRightSurround) |
|
||||
bit(BedChannel::kCenter) | bit(BedChannel::kLfe) |
|
||||
bit(BedChannel::kLeftRearSurround) | bit(BedChannel::kRightRearSurround) |
|
||||
bit(BedChannel::kLeftWide) | bit(BedChannel::kRightWide) |
|
||||
bit(BedChannel::kTopFrontLeft) | bit(BedChannel::kTopFrontRight) |
|
||||
bit(BedChannel::kTopSideLeft) | bit(BedChannel::kTopSideRight) |
|
||||
bit(BedChannel::kTopBackLeft) | bit(BedChannel::kTopBackRight), "9.1.6"},
|
||||
};
|
||||
|
||||
const char* layout_name_for(std::uint32_t mask) {
|
||||
for (const LayoutName& entry : kLayoutNames) {
|
||||
if (entry.mask == mask) {
|
||||
return entry.name;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// 每个扬声器布局的标准声道名(按该布局的标准声道顺序排列)。
|
||||
struct LayoutChannels {
|
||||
std::uint32_t out_ch_config;
|
||||
std::uint32_t count;
|
||||
const char* names[16];
|
||||
};
|
||||
|
||||
constexpr LayoutChannels kLayoutChannels[] = {
|
||||
{0, 2, {"L", "R"}},
|
||||
{3, 4, {"L", "R", "C", "LFE"}},
|
||||
{255, 4, {"L", "R", "Lrs", "Rrs"}},
|
||||
{7, 6, {"L", "R", "C", "LFE", "Ls", "Rs"}},
|
||||
{11, 8, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs"}},
|
||||
{13, 8, {"L", "R", "C", "LFE", "Ls", "Rs", "Ltm", "Rtm"}},
|
||||
{14, 10, {"L", "R", "C", "LFE", "Ls", "Rs", "Ltf", "Rtf", "Ltr", "Rtr"}},
|
||||
{15, 10, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Ltm", "Rtm"}},
|
||||
{16, 12, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Ltf", "Rtf", "Ltr", "Rtr"}},
|
||||
{19, 14, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Lw", "Rw",
|
||||
"Ltf", "Rtf", "Ltr", "Rtr"}},
|
||||
{20, 16, {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs", "Lw", "Rw",
|
||||
"Ltf", "Rtf", "Ltm", "Rtm", "Ltr", "Rtr"}},
|
||||
};
|
||||
|
||||
const ejoc::speaker_tables::LayoutGeometry* geometry_for(std::uint32_t out_ch_config) {
|
||||
for (const ejoc::speaker_tables::LayoutGeometry& layout : ejoc::speaker_tables::kLayouts) {
|
||||
if (layout.out_ch_config == out_ch_config) {
|
||||
return &layout;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
BedLayout resolve_bed_layout(const std::vector<oamd::BedAssignment>& assignments,
|
||||
bool bed_only) {
|
||||
BedLayout layout;
|
||||
layout.bed_only = bed_only;
|
||||
std::uint32_t mask = 0;
|
||||
for (const oamd::BedAssignment& assignment : assignments) {
|
||||
if (assignment.lfe_only) {
|
||||
mask |= bit(BedChannel::kLfe);
|
||||
layout.complete = false;
|
||||
continue;
|
||||
}
|
||||
if (assignment.standard) {
|
||||
for (int index = 0; index < 10; ++index) {
|
||||
if (((assignment.mask >> index) & 1u) == 0u) {
|
||||
continue;
|
||||
}
|
||||
mask |= bit(kStandardBits[index].first);
|
||||
if (kStandardBits[index].second != BedChannel::kCount) {
|
||||
mask |= bit(kStandardBits[index].second);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (int index = 0; index < 17; ++index) {
|
||||
if (((assignment.mask >> index) & 1u) != 0u) {
|
||||
mask |= bit(kNonStandardBits[index]);
|
||||
}
|
||||
}
|
||||
layout.complete = false; // 非标准掩码的声道名不在本标准表里
|
||||
}
|
||||
if (mask == 0u) {
|
||||
return layout;
|
||||
}
|
||||
layout.present = true;
|
||||
layout.mask = mask;
|
||||
layout.name = layout_name_for(mask);
|
||||
for (const ChannelSpec& spec : kChannels) {
|
||||
const BedChannel channel = spec.channel;
|
||||
if ((mask & bit(channel)) == 0u) {
|
||||
continue;
|
||||
}
|
||||
if (channel == BedChannel::kLfe || channel == BedChannel::kLfe2) {
|
||||
continue;
|
||||
}
|
||||
layout.channels.push_back(channel);
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
const char* bed_channel_short_name(BedChannel channel) {
|
||||
const ChannelSpec* spec = spec_of(channel);
|
||||
return spec != nullptr ? spec->short_name : "";
|
||||
}
|
||||
|
||||
const char* bed_channel_label(BedChannel channel) {
|
||||
const ChannelSpec* spec = spec_of(channel);
|
||||
return spec != nullptr ? spec->label : "";
|
||||
}
|
||||
|
||||
bool bed_channel_adm_position(BedChannel channel, double xyz[3]) {
|
||||
const ChannelSpec* spec = spec_of(channel);
|
||||
if (spec == nullptr || xyz == nullptr) {
|
||||
return false;
|
||||
}
|
||||
std::memcpy(xyz, spec->xyz, sizeof(spec->xyz));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bed_channel_q15(BedChannel channel, std::uint16_t q15[3]) {
|
||||
double xyz[3] = {0.0, 0.0, 0.0};
|
||||
if (!bed_channel_adm_position(channel, xyz) || q15 == nullptr) {
|
||||
return false;
|
||||
}
|
||||
const double q1 = (xyz[0] + 1.0) * 0.5 * 32767.0;
|
||||
const double q2 = (1.0 - xyz[1]) * 0.5 * 32767.0;
|
||||
const double q3 = xyz[2] * 32767.0;
|
||||
q15[0] = static_cast<std::uint16_t>(q1 < 0.0 ? 0.0 : (q1 > 32767.0 ? 32767.0 : q1));
|
||||
q15[1] = static_cast<std::uint16_t>(q2 < 0.0 ? 0.0 : (q2 > 32767.0 ? 32767.0 : q2));
|
||||
q15[2] = static_cast<std::uint16_t>(q3 < 0.0 ? 0.0 : (q3 > 32767.0 ? 32767.0 : q3));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
|
||||
std::uint16_t q15[3]) {
|
||||
if (q15 == nullptr) {
|
||||
return false;
|
||||
}
|
||||
const char* name = bed_channel_short_name(channel);
|
||||
if (name == nullptr || name[0] == '\0' || std::strcmp(name, "LFE") == 0) {
|
||||
return false;
|
||||
}
|
||||
const LayoutChannels* table = nullptr;
|
||||
for (const LayoutChannels& entry : kLayoutChannels) {
|
||||
if (entry.out_ch_config == out_ch_config) {
|
||||
table = &entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const ejoc::speaker_tables::LayoutGeometry* geometry = geometry_for(out_ch_config);
|
||||
if (table == nullptr || geometry == nullptr) {
|
||||
return false;
|
||||
}
|
||||
int standard_index = -1;
|
||||
for (std::uint32_t index = 0; index < table->count; ++index) {
|
||||
if (std::strcmp(table->names[index], name) == 0) {
|
||||
standard_index = static_cast<int>(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (standard_index < 0) {
|
||||
return false;
|
||||
}
|
||||
const std::uint8_t internal = geometry->standard_from_internal[standard_index];
|
||||
const ejoc::speaker_tables::RegionGeometry& region = geometry->regions[0];
|
||||
for (std::uint32_t point = 0; point < region.point_count; ++point) {
|
||||
if (region.points[point].speaker_id != internal) {
|
||||
continue;
|
||||
}
|
||||
for (int axis = 0; axis < 3; ++axis) {
|
||||
q15[axis] = region.points[point].coordinate_q15[axis];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// ETSI TS 103 420 Table B.10: the fixed ADM position of every Table 12 bed
|
||||
// channel. bed_output_description() matches these points against the target
|
||||
// layout; the kChannels table above keeps the ADM/binaural path's coordinates.
|
||||
struct TableB10Position {
|
||||
BedChannel channel;
|
||||
double xyz[3];
|
||||
};
|
||||
|
||||
constexpr TableB10Position kTableB10[oamd::kBedLabelCount] = {
|
||||
{BedChannel::kLeft, {-1.0, 1.0, 0.0}},
|
||||
{BedChannel::kRight, {1.0, 1.0, 0.0}},
|
||||
{BedChannel::kCenter, {0.0, 1.0, 0.0}},
|
||||
{BedChannel::kLfe, {-1.0, 1.0, -1.0}},
|
||||
{BedChannel::kLeftSurround, {-1.0, 0.0, 0.0}},
|
||||
{BedChannel::kRightSurround, {1.0, 0.0, 0.0}},
|
||||
{BedChannel::kLeftRearSurround, {-1.0, -1.0, 0.0}},
|
||||
{BedChannel::kRightRearSurround, {1.0, -1.0, 0.0}},
|
||||
{BedChannel::kTopFrontLeft, {-1.0, 1.0, 1.0}},
|
||||
{BedChannel::kTopFrontRight, {1.0, 1.0, 1.0}},
|
||||
{BedChannel::kTopSideLeft, {-1.0, 0.0, 1.0}},
|
||||
{BedChannel::kTopSideRight, {1.0, 0.0, 1.0}},
|
||||
{BedChannel::kTopBackLeft, {-1.0, -1.0, 1.0}},
|
||||
{BedChannel::kTopBackRight, {1.0, -1.0, 1.0}},
|
||||
{BedChannel::kLeftWide, {-1.0, 21.0 / 31.0, 0.0}},
|
||||
{BedChannel::kRightWide, {1.0, 21.0 / 31.0, 0.0}},
|
||||
{BedChannel::kLfe2, {1.0, 1.0, -1.0}},
|
||||
};
|
||||
|
||||
// bed_layout.BED_REFERENCE_POSITIONS_Q15; index 3 is the non-spatial sentinel.
|
||||
constexpr std::int32_t kReferencePositions[kBedReferencePositionCount][3] = {
|
||||
{0, 0, 0}, {32767, 0, 0}, {16384, 0, 0}, {-1, -1, -1},
|
||||
{0, 16384, 0}, {32767, 16384, 0}, {0, 32767, 0}, {32767, 32767, 0},
|
||||
{16384, 32767, 0}, {5285, 0, 0}, {27483, 0, 0}, {0, 5285, 0},
|
||||
{32767, 5285, 0}, {7928, 0, 32767}, {24840, 0, 32767}, {7928, 7928, 32767},
|
||||
{24840, 7928, 32767}, {7928, 16384, 32767}, {24840, 16384, 32767},
|
||||
{7928, 24840, 32767}, {24840, 24840, 32767}, {7928, 32767, 32767},
|
||||
{24840, 32767, 32767}, {11099, 0, 0}, {21669, 0, 0}, {0, 11099, 0},
|
||||
{32767, 11099, 0}, {0, 21669, 0}, {32767, 21669, 0}, {0, 27483, 0},
|
||||
{32767, 27483, 0}, {5285, 32767, 0}, {27483, 32767, 0}, {11099, 32767, 0},
|
||||
{21669, 32767, 0}, {16384, 0, 32767}, {16384, 16384, 32767},
|
||||
{16384, 32767, 32767},
|
||||
};
|
||||
|
||||
// 自动 trim 的每个布局基准衰减,单位 dB。
|
||||
struct AttenuationEntry {
|
||||
const char* compact_name;
|
||||
double db;
|
||||
};
|
||||
|
||||
constexpr AttenuationEntry kAttenuation[] = {
|
||||
{"20", -4.5}, {"31", -4.5}, {"40", -3.0}, {"51", -3.0},
|
||||
{"60", -1.5}, {"71", -1.5}, {"512", -2.25}, {"514", -1.5},
|
||||
{"712", -0.75}, {"714", 0.0}, {"914", 0.0}, {"916", 0.0},
|
||||
};
|
||||
|
||||
constexpr int kMaxChannels = static_cast<int>(ejoc::speaker_tables::kMaxChannels);
|
||||
|
||||
void set_sentinel(std::int32_t coordinate[3]) {
|
||||
coordinate[0] = -1;
|
||||
coordinate[1] = -1;
|
||||
coordinate[2] = -1;
|
||||
}
|
||||
|
||||
bool is_sentinel(const std::int32_t coordinate[3]) {
|
||||
return coordinate[0] == -1 && coordinate[1] == -1 && coordinate[2] == -1;
|
||||
}
|
||||
|
||||
bool is_lfe_label(BedChannel channel) {
|
||||
return channel == BedChannel::kLfe || channel == BedChannel::kLfe2;
|
||||
}
|
||||
|
||||
const TableB10Position* table_b10(BedChannel channel) {
|
||||
for (const TableB10Position& entry : kTableB10) {
|
||||
if (entry.channel == channel) {
|
||||
return &entry;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ADM 笛卡尔坐标 -> 渲染器方位 (u 右, v 后, w 上)。
|
||||
void render_coordinates(const double xyz[3], double out[3]) {
|
||||
out[0] = (xyz[0] + 1.0) * 0.5;
|
||||
out[1] = (1.0 - xyz[1]) * 0.5;
|
||||
out[2] = xyz[2];
|
||||
}
|
||||
|
||||
// 渲染器方位的欧氏距离,比较的是归一化到 0..1 的坐标。
|
||||
double render_distance(const double left[3], const double right[3]) {
|
||||
const double du = left[0] - right[0];
|
||||
const double dv = left[1] - right[1];
|
||||
const double dw = left[2] - right[2];
|
||||
return std::sqrt(du * du + dv * dv + dw * dw);
|
||||
}
|
||||
|
||||
// Reference-position matching: the non-spatial sentinel resolves to index 3.
|
||||
int nearest_reference(const std::int32_t coordinate[3]) {
|
||||
if (is_sentinel(coordinate)) {
|
||||
return 3;
|
||||
}
|
||||
const double position[3] = {
|
||||
static_cast<double>(coordinate[0]) / 32768.0,
|
||||
static_cast<double>(coordinate[1]) / 32768.0,
|
||||
static_cast<double>(coordinate[2]) / 32768.0,
|
||||
};
|
||||
int best = 3;
|
||||
double best_distance = 0.0;
|
||||
bool have_best = false;
|
||||
for (int index = 0; index < kBedReferencePositionCount; ++index) {
|
||||
const std::int32_t* candidate = kReferencePositions[index];
|
||||
if (candidate[0] == -1 && candidate[1] == -1 && candidate[2] == -1) {
|
||||
continue;
|
||||
}
|
||||
const double point[3] = {
|
||||
static_cast<double>(candidate[0]) / 32768.0,
|
||||
static_cast<double>(candidate[1]) / 32768.0,
|
||||
static_cast<double>(candidate[2]) / 32768.0,
|
||||
};
|
||||
const double distance = render_distance(position, point);
|
||||
if (!have_best || distance < best_distance) {
|
||||
best = index;
|
||||
best_distance = distance;
|
||||
have_best = true;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// 目标布局里离 desired 最近、且在 0.05 容差内的输出声道;没有返回 -1。
|
||||
int nearest_channel(const double desired[3], const std::int32_t positions[][3],
|
||||
std::uint32_t channel_count) {
|
||||
int best = -1;
|
||||
double best_distance = 0.0;
|
||||
bool have_best = false;
|
||||
for (std::uint32_t index = 0; index < channel_count; ++index) {
|
||||
if (is_sentinel(positions[index])) {
|
||||
continue;
|
||||
}
|
||||
const double point[3] = {
|
||||
static_cast<double>(positions[index][0]) / 32768.0,
|
||||
static_cast<double>(positions[index][1]) / 32768.0,
|
||||
static_cast<double>(positions[index][2]) / 32768.0,
|
||||
};
|
||||
const double distance = render_distance(desired, point);
|
||||
if (!have_best || distance < best_distance) {
|
||||
best = static_cast<int>(index);
|
||||
best_distance = distance;
|
||||
have_best = true;
|
||||
}
|
||||
}
|
||||
if (have_best && best_distance <= 0.05) {
|
||||
return best;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 输出声道 index -> 该声道的 Q15 方位;LFE 与非空间声道给 sentinel。
|
||||
void channel_positions(const speaker::LayoutInfo& layout,
|
||||
std::int32_t positions[][3]) {
|
||||
for (int index = 0; index < kMaxChannels; ++index) {
|
||||
set_sentinel(positions[index]);
|
||||
}
|
||||
const auto* geometry = ejoc::speaker_tables::find_layout(layout.speaker_bitfield);
|
||||
if (geometry != nullptr) {
|
||||
bool known[kMaxChannels] = {};
|
||||
std::int32_t found[kMaxChannels][3];
|
||||
for (int index = 0; index < kMaxChannels; ++index) {
|
||||
set_sentinel(found[index]);
|
||||
}
|
||||
for (const auto& region : geometry->regions) {
|
||||
for (std::size_t point = 0; point < region.point_count; ++point) {
|
||||
const auto speaker = static_cast<int>(region.points[point].speaker_id);
|
||||
if (speaker < 0 || speaker >= kMaxChannels || known[speaker]) {
|
||||
continue;
|
||||
}
|
||||
for (int axis = 0; axis < 3; ++axis) {
|
||||
found[speaker][axis] =
|
||||
static_cast<std::int32_t>(region.points[point].coordinate_q15[axis]);
|
||||
}
|
||||
known[speaker] = true;
|
||||
}
|
||||
}
|
||||
const std::uint32_t count =
|
||||
layout.channel_count < static_cast<std::uint32_t>(kMaxChannels)
|
||||
? layout.channel_count
|
||||
: static_cast<std::uint32_t>(kMaxChannels);
|
||||
for (std::uint32_t index = 0; index < count; ++index) {
|
||||
const char* name = layout.channel_names != nullptr ? layout.channel_names[index]
|
||||
: nullptr;
|
||||
if (name != nullptr && std::strcmp(name, "LFE") == 0) {
|
||||
continue;
|
||||
}
|
||||
if (known[index]) {
|
||||
for (int axis = 0; axis < 3; ++axis) {
|
||||
positions[index][axis] = found[index][axis];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int channel_index(const speaker::LayoutInfo& layout, const char* name) {
|
||||
if (name == nullptr || layout.channel_names == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
for (std::uint32_t index = 0; index < layout.channel_count; ++index) {
|
||||
if (std::strcmp(layout.channel_names[index], name) == 0) {
|
||||
return static_cast<int>(index);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
double attenuation_db(const speaker::LayoutInfo& layout) {
|
||||
for (const AttenuationEntry& entry : kAttenuation) {
|
||||
if (std::strcmp(entry.compact_name, layout.compact_name) == 0) {
|
||||
return entry.db;
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const std::int32_t (*bed_reference_positions_q15())[3] {
|
||||
return kReferencePositions;
|
||||
}
|
||||
|
||||
BedOutputDescription bed_output_description(const speaker::LayoutInfo& layout) {
|
||||
BedOutputDescription description;
|
||||
std::int32_t positions[kMaxChannels][3];
|
||||
channel_positions(layout, positions);
|
||||
const std::uint32_t output_count =
|
||||
layout.channel_count < static_cast<std::uint32_t>(kMaxChannels)
|
||||
? layout.channel_count
|
||||
: static_cast<std::uint32_t>(kMaxChannels);
|
||||
description.output_labels.reserve(output_count);
|
||||
for (std::uint32_t index = 0; index < output_count; ++index) {
|
||||
description.output_labels.push_back(nearest_reference(positions[index]));
|
||||
}
|
||||
for (int label = 0; label < oamd::kBedLabelCount; ++label) {
|
||||
const BedChannel channel = static_cast<BedChannel>(label);
|
||||
const char* name = channel == BedChannel::kLfe2 ? nullptr
|
||||
: bed_channel_short_name(channel);
|
||||
int slot = -1;
|
||||
if (name != nullptr && name[0] != '\0') {
|
||||
slot = channel_index(layout, name);
|
||||
}
|
||||
if (slot < 0 && channel == BedChannel::kLfe2) {
|
||||
slot = channel_index(layout, "LFE");
|
||||
}
|
||||
const TableB10Position* position = table_b10(channel);
|
||||
double desired[3] = {0.0, 0.0, 0.0};
|
||||
if (position != nullptr) {
|
||||
render_coordinates(position->xyz, desired);
|
||||
}
|
||||
if (slot < 0 && position != nullptr) {
|
||||
slot = nearest_channel(desired, positions, output_count);
|
||||
}
|
||||
if (slot < 0) {
|
||||
description.label_to_slot[label] = is_lfe_label(channel) ? -1 : -2;
|
||||
} else {
|
||||
description.label_to_slot[label] = slot;
|
||||
}
|
||||
if (is_lfe_label(channel)) {
|
||||
description.direct_output_labels[label] = 3;
|
||||
} else {
|
||||
int best = 3;
|
||||
double best_distance = 0.0;
|
||||
bool have_best = false;
|
||||
for (int index = 0; index < kBedReferencePositionCount; ++index) {
|
||||
const std::int32_t* candidate = kReferencePositions[index];
|
||||
if (candidate[0] == -1 && candidate[1] == -1 && candidate[2] == -1) {
|
||||
continue;
|
||||
}
|
||||
const double point[3] = {
|
||||
static_cast<double>(candidate[0]) / 32768.0,
|
||||
static_cast<double>(candidate[1]) / 32768.0,
|
||||
static_cast<double>(candidate[2]) / 32768.0,
|
||||
};
|
||||
const double distance = render_distance(desired, point);
|
||||
if (!have_best || distance < best_distance) {
|
||||
best = index;
|
||||
best_distance = distance;
|
||||
have_best = true;
|
||||
}
|
||||
}
|
||||
description.direct_output_labels[label] = best;
|
||||
}
|
||||
}
|
||||
description.automatic_attenuation_db = attenuation_db(layout);
|
||||
return description;
|
||||
}
|
||||
|
||||
} // namespace joc::joc
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "oamd/oamd_parser.h"
|
||||
#include "speaker/speaker_layout_lookup.h"
|
||||
|
||||
namespace joc::joc {
|
||||
|
||||
// BedChannel lives in oamd/oamd_parser.h: the enum is the OAMD Table 12
|
||||
// label order and OAMD frame state carries it directly.
|
||||
|
||||
// 内容声明的 bed 布局。bed 对象在 OAMD 里没有位置字段,位置由这里的布局决定。
|
||||
struct BedLayout {
|
||||
bool present = false; // 有 bed_assignment() 声明
|
||||
bool bed_only = false; // program 只由 bed 组成(无 ISF、无动态对象)
|
||||
bool complete = true; // 所有声明声道都在本标准表里
|
||||
const char* name = ""; // "9.1.6" 等;未知集合为空串
|
||||
std::uint32_t mask = 0; // 声明声道的位集合(1 << BedChannel)
|
||||
std::vector<BedChannel> channels; // 去掉 LFE/LFE2,按 JOC 对象槽顺序
|
||||
};
|
||||
|
||||
// 声明里是否包含某个 bed 声道。
|
||||
inline bool bed_layout_has(const BedLayout& layout, BedChannel channel) {
|
||||
return (layout.mask & (1u << static_cast<unsigned>(channel))) != 0u;
|
||||
}
|
||||
|
||||
// 展开 bed_assignment() 声明;``bed_only`` 来自 program_assignment() 的
|
||||
// content_description。
|
||||
BedLayout resolve_bed_layout(const std::vector<oamd::BedAssignment>& assignments,
|
||||
bool bed_only);
|
||||
|
||||
// 扬声器布局里的短名("Lw")与 Table 12 的标签("RC_LW")。
|
||||
const char* bed_channel_short_name(BedChannel channel);
|
||||
const char* bed_channel_label(BedChannel channel);
|
||||
|
||||
// 固定方位:ADM 笛卡尔坐标(x 右、y 前、z 上)与渲染器使用的 Q15 方位。
|
||||
bool bed_channel_adm_position(BedChannel channel, double xyz[3]);
|
||||
bool bed_channel_q15(BedChannel channel, std::uint16_t q15[3]);
|
||||
|
||||
// 目标布局里同名扬声器的 Q15 方位:bed 声道直连到该扬声器,而不是参与声像。
|
||||
// 目标布局没有这个声道时返回 false。4.0 与 6.0 共用未分配的 out_ch_config
|
||||
// 0xFF,因此这里按 4.0 的声道集合解释 0xFF。
|
||||
bool layout_bed_anchor(std::uint32_t out_ch_config, BedChannel channel,
|
||||
std::uint16_t q15[3]);
|
||||
|
||||
// 参考位置网格 ``BED_REFERENCE_POSITIONS_Q15``:bed 标签与输出 slots 的最近邻
|
||||
// 匹配都用这一组固定 Q15 点。索引 3 是 (-1,-1,-1),表示 LFE 那样的非空间声源。
|
||||
inline constexpr int kBedReferencePositionCount = 38;
|
||||
const std::int32_t (*bed_reference_positions_q15())[3];
|
||||
|
||||
// 一个目标扬声器布局的 bed 路由描述(bed_layout.bed_output_description):
|
||||
// 按标准 bed 标签序(Table 12 的 17 个标签)给出目标 layout 的输出参考位置、
|
||||
// 每个标签的输出 slot 与直连参考位置,以及该布局的自动 trim 基准衰减。
|
||||
struct BedOutputDescription {
|
||||
std::vector<int> output_labels; // 每个输出声道最近邻的参考位置索引
|
||||
int label_to_slot[oamd::kBedLabelCount] = {}; // -2 不可达,-1 LFE 通路
|
||||
int direct_output_labels[oamd::kBedLabelCount] = {};
|
||||
double automatic_attenuation_db = 0.0;
|
||||
};
|
||||
|
||||
// 由布局名/几何派生 bed 路由描述;``layout.channel_names`` 必须按标准声道
|
||||
// 顺序给出 ``layout.channel_count`` 个名字。
|
||||
BedOutputDescription bed_output_description(const speaker::LayoutInfo& layout);
|
||||
|
||||
} // namespace joc::joc
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "joc_bitstream/joc_parser.h"
|
||||
|
||||
#include "joc_bitstream/bed_layout_map.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
@@ -180,6 +182,77 @@ std::int16_t num_bands_for_index(std::uint32_t num_bands_idx) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Reads the 12-bit joc_header at the start of the payload. Mirrors
|
||||
// parse_joc_header(): a downmix configuration outside 0..4 is a frame status,
|
||||
// not an exception, because a metadata scan records it as an unsupported
|
||||
// variant while the frame itself stays classified.
|
||||
Status parse_id14_header(const std::uint8_t* payload, std::size_t payload_size,
|
||||
joc_frame_params* out) {
|
||||
bits::BitReader reader(payload, payload_size);
|
||||
out->dmx_config_idx = static_cast<std::uint8_t>(reader.read(3));
|
||||
out->num_objects_bits = static_cast<std::uint8_t>(reader.read(6));
|
||||
out->ext_config_idx = static_cast<std::uint8_t>(reader.read(3));
|
||||
if (reader.failed()) {
|
||||
return truncated_fail(reader);
|
||||
}
|
||||
const std::int16_t n_channels = num_channels_for_config(out->dmx_config_idx);
|
||||
if (n_channels < 0) {
|
||||
// The core channel count decides how the object syntax expands, so an
|
||||
// unknown configuration stops the parse after the header fields.
|
||||
out->status = JOC_FRAME_STATUS_UNSUPPORTED_DMX;
|
||||
out->objects_clamped = 0u;
|
||||
out->n_objects = 0u;
|
||||
return Status::success();
|
||||
}
|
||||
out->n_channels = static_cast<std::uint8_t>(n_channels);
|
||||
const std::uint32_t declared = static_cast<std::uint32_t>(out->num_objects_bits) + 1u;
|
||||
out->objects_clamped = declared > JOC_MAX_OBJECTS ? 1u : 0u;
|
||||
out->n_objects = static_cast<std::uint8_t>(
|
||||
std::min<std::uint32_t>(declared, static_cast<std::uint32_t>(JOC_MAX_OBJECTS)));
|
||||
if (out->objects_clamped != 0u) {
|
||||
out->status = JOC_FRAME_STATUS_OBJECTS_CLAMPED;
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
// Records where joc_data ends and the first trailing bytes, like _tail_info().
|
||||
void tail_info(joc_frame_params* out, const bits::BitReader& reader, const std::uint8_t* payload,
|
||||
std::size_t payload_size) {
|
||||
out->data_end_bits = static_cast<std::uint32_t>(reader.position());
|
||||
out->trailing_bits = static_cast<std::uint32_t>(payload_size * 8u - reader.position());
|
||||
const std::size_t tail_offset = reader.position() / 8u;
|
||||
if (tail_offset < payload_size) {
|
||||
const std::size_t tail_bytes = std::min<std::size_t>(8u, payload_size - tail_offset);
|
||||
std::memcpy(out->tail_bytes, payload + tail_offset, tail_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
// A payload that runs out of bits after the joc_header is a damaged but
|
||||
// identifiable JOC frame: the header, clipgain, sequence counter and object
|
||||
// parameters are intact, so the frame keeps its identity and the renderer can
|
||||
// hold the previous matrices instead of stopping the stream. A payload that
|
||||
// ends before the header cannot be classified and stays a transport error; a
|
||||
// Huffman walk that leaves the tree is a syntax error, never a truncation.
|
||||
Status truncated_frame(const bits::BitReader& reader, joc_frame_params* out,
|
||||
const std::uint8_t* payload, std::size_t payload_size) {
|
||||
if (reader.error() != JOC_ERR_BITSTREAM_TRUNCATED) {
|
||||
return syntax_fail(reader.error_message());
|
||||
}
|
||||
out->status = JOC_FRAME_STATUS_TRUNCATED;
|
||||
out->present_mask = 0u;
|
||||
for (std::uint32_t obj = 0; obj < out->n_objects; ++obj) {
|
||||
if (out->objects[obj].present != 0u) {
|
||||
out->present_mask |= 1u << obj;
|
||||
}
|
||||
}
|
||||
tail_info(out, reader, payload, payload_size);
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_frame_params* out,
|
||||
FrameSymbols* symbols) {
|
||||
if (payload == nullptr || out == nullptr) {
|
||||
@@ -193,45 +266,53 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
FrameSymbols& capture = (symbols != nullptr) ? *symbols : local_symbols;
|
||||
std::memset(&capture, 0, sizeof(capture));
|
||||
|
||||
bits::BitReader reader(payload, payload_size);
|
||||
|
||||
out->dmx_config_idx = static_cast<std::uint8_t>(reader.read(3));
|
||||
out->num_objects_bits = static_cast<std::uint8_t>(reader.read(6));
|
||||
out->ext_config_idx = static_cast<std::uint8_t>(reader.read(3));
|
||||
|
||||
const std::uint32_t declared_objects = static_cast<std::uint32_t>(out->num_objects_bits) + 1u;
|
||||
const std::int16_t n_channels = num_channels_for_config(out->dmx_config_idx);
|
||||
if (n_channels < 0) {
|
||||
return syntax_fail("unknown JOC downmix configuration " +
|
||||
std::to_string(out->dmx_config_idx));
|
||||
const Status header = parse_id14_header(payload, payload_size, out);
|
||||
if (!header.ok()) {
|
||||
return header;
|
||||
}
|
||||
out->n_channels = static_cast<std::uint8_t>(n_channels);
|
||||
// A declared object count above 15 is clamped to 15: the frame is parsed for
|
||||
// 15 objects only, and the clamp is reported separately.
|
||||
out->objects_clamped = declared_objects > JOC_MAX_OBJECTS ? 1u : 0u;
|
||||
const std::uint32_t n_objects =
|
||||
std::min<std::uint32_t>(declared_objects, JOC_MAX_OBJECTS);
|
||||
out->n_objects = static_cast<std::uint8_t>(n_objects);
|
||||
|
||||
bits::BitReader reader(payload, payload_size);
|
||||
reader.skip(12);
|
||||
out->clipgain_x_bits = static_cast<std::uint8_t>(reader.read(3));
|
||||
out->clipgain_y_bits = static_cast<std::uint8_t>(reader.read(5));
|
||||
out->seq_count = reader.read(10);
|
||||
// clipgain = 1 + (y/32) * 2^(x-4); ldexp builds the power of two exactly
|
||||
// over the whole legal range.
|
||||
out->clipgain = 1.0 + static_cast<double>(out->clipgain_y_bits) / 32.0 *
|
||||
std::ldexp(1.0, static_cast<int>(out->clipgain_x_bits) - 4);
|
||||
if (reader.failed()) {
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
// clipgain = 2^(x-4) * (1 + y/32); ldexp builds the power of two exactly
|
||||
// over the whole legal range, so the result is bit-exact to the reference.
|
||||
out->clipgain = std::ldexp(1.0, static_cast<int>(out->clipgain_x_bits) - 4) *
|
||||
(1.0 + static_cast<double>(out->clipgain_y_bits) / 32.0);
|
||||
|
||||
if (out->status == JOC_FRAME_STATUS_UNSUPPORTED_DMX) {
|
||||
tail_info(out, reader, payload, payload_size);
|
||||
return Status::success();
|
||||
}
|
||||
const std::int16_t n_channels = num_channels_for_config(out->dmx_config_idx);
|
||||
const std::uint32_t n_objects = out->n_objects;
|
||||
|
||||
for (std::uint32_t obj = 0; obj < n_objects; ++obj) {
|
||||
joc_object_params& info = out->objects[obj];
|
||||
info.present = static_cast<std::uint8_t>(reader.read(1));
|
||||
if (reader.failed()) {
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
if (info.present == 0u) {
|
||||
continue;
|
||||
}
|
||||
info.num_bands_idx = static_cast<std::uint8_t>(reader.read(3));
|
||||
if (reader.failed()) {
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
const std::int16_t bands = num_bands_for_index(info.num_bands_idx);
|
||||
if (bands < 0) {
|
||||
return syntax_fail("unknown JOC num_bands index " +
|
||||
std::to_string(info.num_bands_idx));
|
||||
// The symbol count depends on the parameter-band count, so the rest
|
||||
// of the payload cannot be parsed.
|
||||
if (out->status == JOC_FRAME_STATUS_OK) {
|
||||
out->status = JOC_FRAME_STATUS_BAD_PARAMETER_BAND;
|
||||
}
|
||||
tail_info(out, reader, payload, payload_size);
|
||||
return Status::success();
|
||||
}
|
||||
info.n_bands = static_cast<std::uint8_t>(bands);
|
||||
info.sparse = static_cast<std::uint8_t>(reader.read(1));
|
||||
@@ -239,16 +320,42 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
info.slope_idx = static_cast<std::uint8_t>(reader.read(1));
|
||||
info.num_dpoints_bits = static_cast<std::uint8_t>(reader.read(1));
|
||||
info.n_dpoints = static_cast<std::uint8_t>(info.num_dpoints_bits + 1u);
|
||||
if (reader.failed()) {
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
if (info.slope_idx == 1u) {
|
||||
for (std::uint32_t dp = 0; dp < info.n_dpoints; ++dp) {
|
||||
info.offset_ts[dp] = static_cast<std::uint8_t>(reader.read(5) + 1u);
|
||||
}
|
||||
}
|
||||
info.offset_ts[dp] = static_cast<std::uint8_t>(reader.read(5));
|
||||
}
|
||||
if (reader.failed()) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
// offset_ts is the raw 5-bit slot index (legal range 0..23) and one
|
||||
// object's data points must be strictly increasing.
|
||||
bool invalid = false;
|
||||
for (std::uint32_t dp = 0; dp < info.n_dpoints; ++dp) {
|
||||
if (info.offset_ts[dp] >= JOC_TIMESLOTS) {
|
||||
invalid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!invalid && info.n_dpoints > 1u) {
|
||||
for (std::uint32_t dp = 1; dp < info.n_dpoints; ++dp) {
|
||||
if (info.offset_ts[dp] <= info.offset_ts[dp - 1u]) {
|
||||
invalid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (invalid && out->status == JOC_FRAME_STATUS_OK) {
|
||||
out->status = JOC_FRAME_STATUS_BAD_OFFSET_TS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// joc_data (Huffman): dense reads MTX per channel and band, sparse reads IDX
|
||||
// then VEC. A frame whose status is already non-zero dequantizes below but
|
||||
// is never rendered, so a misaligned parse cannot reach the DSP.
|
||||
for (std::uint32_t obj = 0; obj < n_objects; ++obj) {
|
||||
const joc_object_params& info = out->objects[obj];
|
||||
if (info.present == 0u) {
|
||||
@@ -265,13 +372,13 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
const Tree idx_tree = select_tree(info.quant_idx, SymbolKind::Idx, n_channels);
|
||||
const std::uint32_t first = reader.read(3);
|
||||
if (reader.failed()) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
symbol->idx[dp][0] = static_cast<std::uint8_t>(first);
|
||||
for (int pb = 1; pb < info.n_bands; ++pb) {
|
||||
std::int16_t value = 0;
|
||||
if (!huff_decode(idx_tree, reader, &value)) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
symbol->idx[dp][pb] = static_cast<std::uint8_t>(value);
|
||||
}
|
||||
@@ -279,7 +386,7 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
for (int pb = 0; pb < info.n_bands; ++pb) {
|
||||
std::int16_t value = 0;
|
||||
if (!huff_decode(vec_tree, reader, &value)) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
symbol->vec[dp][pb] = value;
|
||||
}
|
||||
@@ -289,7 +396,7 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
for (int pb = 0; pb < info.n_bands; ++pb) {
|
||||
std::int16_t value = 0;
|
||||
if (!huff_decode(mtx_tree, reader, &value)) {
|
||||
return truncated_fail(reader);
|
||||
return truncated_frame(reader, out, payload, payload_size);
|
||||
}
|
||||
symbol->mtx[dp][ch][pb] = value;
|
||||
}
|
||||
@@ -298,12 +405,16 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
}
|
||||
}
|
||||
|
||||
out->data_end_bits = static_cast<std::uint32_t>(reader.position());
|
||||
out->trailing_bits = static_cast<std::uint32_t>(payload_size * 8u - reader.position());
|
||||
const std::size_t tail_offset = reader.position() / 8u;
|
||||
if (tail_offset < payload_size) {
|
||||
const std::size_t tail_bytes = std::min<std::size_t>(8u, payload_size - tail_offset);
|
||||
std::memcpy(out->tail_bytes, payload + tail_offset, tail_bytes);
|
||||
tail_info(out, reader, payload, payload_size);
|
||||
if (out->status == JOC_FRAME_STATUS_OK && out->ext_config_idx == 0u) {
|
||||
// The tail pads with zero bits up to the next byte; a whole byte after
|
||||
// that alignment is unexpected data.
|
||||
const std::uint32_t pad =
|
||||
(8u - (static_cast<std::uint32_t>(reader.position()) % 8u)) % 8u;
|
||||
const std::uint32_t total_bits = static_cast<std::uint32_t>(payload_size * 8u);
|
||||
if (total_bits > static_cast<std::uint32_t>(reader.position()) + pad) {
|
||||
out->status = JOC_FRAME_STATUS_TRAILING_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::uint32_t obj = 0; obj < n_objects; ++obj) {
|
||||
@@ -311,8 +422,7 @@ Status parse_id14(const std::uint8_t* payload, std::size_t payload_size, joc_fra
|
||||
if (info.present == 0u) {
|
||||
continue;
|
||||
}
|
||||
std::uint32_t mask_bit = 1u << obj;
|
||||
out->present_mask |= mask_bit;
|
||||
out->present_mask |= 1u << obj;
|
||||
|
||||
const std::int64_t nquant = (info.quant_idx == 0u) ? 96 : 192;
|
||||
std::int64_t q[JOC_MAX_DPOINTS][JOC_MAX_CORE_CHANNELS][JOC_MAX_PARAMETER_BANDS] = {};
|
||||
@@ -370,7 +480,16 @@ int score_container_as_joc(const std::uint8_t* data, std::size_t size,
|
||||
if (emdf::extract_payload_bytes(data, size, *payload, &bytes).ok()) {
|
||||
joc_frame_params params;
|
||||
FrameSymbols symbols;
|
||||
parses = parse_id14(bytes.data(), bytes.size(), ¶ms, &symbols).ok();
|
||||
if (parse_id14(bytes.data(), bytes.size(), ¶ms, &symbols).ok()) {
|
||||
// The reference scores a payload by the frame status: an unsupported
|
||||
// downmix configuration (2), an unknown parameter-band count (4) or a
|
||||
// payload that ends inside joc_data (7) must not win the container
|
||||
// choice, because another candidate may carry the frame's complete
|
||||
// metadata.
|
||||
parses = params.status != JOC_FRAME_STATUS_UNSUPPORTED_DMX &&
|
||||
params.status != JOC_FRAME_STATUS_BAD_PARAMETER_BAND &&
|
||||
params.status != JOC_FRAME_STATUS_TRUNCATED;
|
||||
}
|
||||
}
|
||||
const bool associated = oamd->has_group_id != 0u && payload->has_group_id != 0u &&
|
||||
oamd->group_id == payload->group_id;
|
||||
@@ -404,7 +523,20 @@ Status parse_eac3_frame(const std::uint8_t* frame, std::size_t frame_size, joc_f
|
||||
if (!extract.ok()) {
|
||||
return extract;
|
||||
}
|
||||
return parse_id14(bytes.data(), bytes.size(), out, symbols);
|
||||
const Status parsed = parse_id14(bytes.data(), bytes.size(), out, symbols);
|
||||
if (!parsed.ok()) {
|
||||
return parsed;
|
||||
}
|
||||
// A metadata scan rejects an unsupported downmix configuration outright: the
|
||||
// core channel count decides how every later frame is expanded, so this is a
|
||||
// variant error rather than a per-frame status.
|
||||
if (out->status == JOC_FRAME_STATUS_UNSUPPORTED_DMX) {
|
||||
const std::string message =
|
||||
"downmix_config_unsupported: ID14 declares joc_dmx_config_idx=" +
|
||||
std::to_string(out->dmx_config_idx) + " (legal values are 0..4)";
|
||||
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kJoc, message);
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status check_id14_padding(const std::uint8_t* payload, std::size_t payload_size,
|
||||
@@ -415,6 +547,21 @@ Status check_id14_padding(const std::uint8_t* payload, std::size_t payload_size,
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
// The statuses that stop the parse early leave the payload without a
|
||||
// joc_data end position, so they keep reporting the failure they reported
|
||||
// before the frame-status split.
|
||||
if (params.status == JOC_FRAME_STATUS_UNSUPPORTED_DMX) {
|
||||
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kJoc,
|
||||
"downmix_config_unsupported: joc_dmx_config_idx outside 0..4");
|
||||
}
|
||||
if (params.status == JOC_FRAME_STATUS_BAD_PARAMETER_BAND) {
|
||||
return Status::fail(JOC_ERR_JOC_SYNTAX, stage::kJoc,
|
||||
"unknown JOC num_bands index stops the payload");
|
||||
}
|
||||
if (params.status == JOC_FRAME_STATUS_TRUNCATED) {
|
||||
return Status::fail(JOC_ERR_BITSTREAM_TRUNCATED, stage::kJoc,
|
||||
"the ID14 payload ends before its joc_data is complete");
|
||||
}
|
||||
if (out_trailing_bits != nullptr) {
|
||||
*out_trailing_bits = params.trailing_bits;
|
||||
}
|
||||
@@ -545,6 +692,26 @@ std::string position_name(Position position) {
|
||||
}
|
||||
}
|
||||
|
||||
// 核心声道位置 → bed 布局声道;返回 kCount 表示本标准表没有对应身份。
|
||||
BedChannel bed_channel_for_position(Position position) {
|
||||
switch (position) {
|
||||
case Position::kLeft: return BedChannel::kLeft;
|
||||
case Position::kRight: return BedChannel::kRight;
|
||||
case Position::kCenter: return BedChannel::kCenter;
|
||||
case Position::kLfe: return BedChannel::kLfe;
|
||||
case Position::kLfe2: return BedChannel::kLfe2;
|
||||
case Position::kLeftSurround: return BedChannel::kLeftSurround;
|
||||
case Position::kRightSurround: return BedChannel::kRightSurround;
|
||||
case Position::kLeftRearSurround: return BedChannel::kLeftRearSurround;
|
||||
case Position::kRightRearSurround: return BedChannel::kRightRearSurround;
|
||||
case Position::kVerticalHeightLeft: return BedChannel::kTopFrontLeft;
|
||||
case Position::kVerticalHeightRight: return BedChannel::kTopFrontRight;
|
||||
case Position::kTopSurroundLeft: return BedChannel::kTopSideLeft;
|
||||
case Position::kTopSurroundRight: return BedChannel::kTopSideRight;
|
||||
default: return BedChannel::kCount;
|
||||
}
|
||||
}
|
||||
|
||||
std::string position_list(const std::vector<Position>& positions) {
|
||||
std::string text = "[";
|
||||
for (std::size_t index = 0; index < positions.size(); ++index) {
|
||||
@@ -839,6 +1006,7 @@ Status check_cross_layer(const joc_frame_params& params, const eac3::Frame* core
|
||||
std::uint16_t chanmap,
|
||||
const std::vector<oamd::BedAssignment>* bed_assignments,
|
||||
std::string* error, CrossLayerNotes* notes) {
|
||||
(void)has_dependent;
|
||||
const std::uint8_t config_idx = params.dmx_config_idx;
|
||||
const int core_channels = params.n_channels;
|
||||
std::vector<Position> wanted;
|
||||
@@ -917,25 +1085,24 @@ Status check_cross_layer(const joc_frame_params& params, const eac3::Frame* core
|
||||
error);
|
||||
}
|
||||
|
||||
if (bed_assignments != nullptr) {
|
||||
static constexpr std::uint32_t kBedBitLeftRear = 1u << 4; // RC_LB/RC_RB
|
||||
static constexpr std::uint32_t kBedBitTopFront = 1u << 5; // RC_TFL/RC_TFR
|
||||
std::vector<Position> declared_pair;
|
||||
for (const oamd::BedAssignment& assignment : *bed_assignments) {
|
||||
if (!assignment.standard || assignment.mask == 0u) {
|
||||
if (bed_assignments != nullptr && !bed_assignments->empty()) {
|
||||
// OAMD 的 bed 掩码描述的是内容的 bed 布局,可以比核心子流实际编码的声道多
|
||||
// (例如 9.1.6 bed 只编 5.1 核心)。只有核心声道在 bed 布局里找不到位置才是
|
||||
// 真正的不一致;多出来的 bed 声道是布局的一部分。
|
||||
const BedLayout bed = resolve_bed_layout(*bed_assignments, true);
|
||||
if (bed.present && bed.complete) {
|
||||
bool covered = true;
|
||||
for (const Position position : core_positions) {
|
||||
const BedChannel channel = bed_channel_for_position(position);
|
||||
if (channel == BedChannel::kCount) {
|
||||
continue;
|
||||
}
|
||||
if ((assignment.mask & kBedBitLeftRear) != 0u) {
|
||||
push_unique(&declared_pair, Position::kLeftRearSurround);
|
||||
push_unique(&declared_pair, Position::kRightRearSurround);
|
||||
}
|
||||
if ((assignment.mask & kBedBitTopFront) != 0u) {
|
||||
push_unique(&declared_pair, Position::kVerticalHeightLeft);
|
||||
push_unique(&declared_pair, Position::kVerticalHeightRight);
|
||||
if (!bed_layout_has(bed, channel)) {
|
||||
covered = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!declared_pair.empty() && declared_pair != wanted) {
|
||||
if (notes != nullptr) {
|
||||
if (!covered && notes != nullptr) {
|
||||
notes->bed_mask_mismatch = true;
|
||||
}
|
||||
}
|
||||
|
||||
+564
-34
@@ -69,6 +69,19 @@ public:
|
||||
std::memset(synthesis_state_, 0, sizeof(synthesis_state_));
|
||||
std::memset(x_, 0, sizeof(x_));
|
||||
std::memset(z_, 0, sizeof(z_));
|
||||
// Frame-level state: per-object previous matrices and presence markers,
|
||||
// the seq state machine, the 8-plane passthrough history, the LFE ramp
|
||||
// start value and the previous actual core-channel count.
|
||||
std::memset(prev_matrix_, 0, sizeof(prev_matrix_));
|
||||
std::memset(prev_present_, 0, sizeof(prev_present_));
|
||||
std::memset(core_history_, 0, sizeof(core_history_));
|
||||
state_ = 0;
|
||||
expected_seq_ = 0;
|
||||
invalid_count_ = 0;
|
||||
last_frame_valid_ = false;
|
||||
n_channels_prev_ = -1;
|
||||
has_lfe_clipgain_ = false;
|
||||
lfe_clipgain_ = 0.0;
|
||||
// Sentinel: the first frame after reset takes the new scalar directly,
|
||||
// without an intra-frame transition.
|
||||
analysis_phase_ = -0.5f;
|
||||
@@ -174,13 +187,22 @@ public:
|
||||
}
|
||||
|
||||
std::memset(output16, 0, sizeof(float) * EJOC_OUTPUT_CHANNELS * EJOC_FRAME_SAMPLES);
|
||||
analysis(bed_planar, phase_new);
|
||||
render_lfe(lfe, output_scale, output16);
|
||||
// Analysis-side scalar = the structural 1/16 times this frame's clipgain.
|
||||
// clipgain enters the analysis at this stage and the x16 at the output
|
||||
// cancels the 1/16, so the net effect is a multiply by joc_clipgain.
|
||||
analysis(bed_planar, static_cast<float>(phase_new * clipgain));
|
||||
decode_lfe(lfe, clipgain, output16, output_scale);
|
||||
process_objects(object_mask, n_bands, n_dpoints, slope_idx, offset_ts,
|
||||
dq, clipgain, output_scale, output16);
|
||||
dq, output_scale, output16);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Frame-level entry point; the state machine and per-object history live
|
||||
// inside the renderer (see render_frame_impl()).
|
||||
int render_frame(const ejoc_frame_input& input) noexcept {
|
||||
return render_frame_impl(input);
|
||||
}
|
||||
|
||||
private:
|
||||
void initialize_tables() noexcept {
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
@@ -378,13 +400,12 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void analysis(const float* bed_planar, const float phase_new) noexcept {
|
||||
// Frames the analysis QMF of the core PCM with the given analysis-side
|
||||
// scalar (the structural 1/16 times joc_clipgain). The scalar ramps over the
|
||||
// frame's first 256 samples from the previous frame's value; the first frame
|
||||
// after a reset takes it directly.
|
||||
void analysis(const float* bed_planar, const float scalar) noexcept {
|
||||
job_bed_ = bed_planar;
|
||||
// Analysis-side scalar = the structural 1/16 times this frame's clipgain.
|
||||
// clipgain enters the analysis at this stage and the x16 at the output
|
||||
// cancels the 1/16, so the net effect is a multiply by joc_clipgain; the
|
||||
// previous frame's scalar is the ramp start.
|
||||
const float scalar = static_cast<float>(phase_new * job_clipgain_);
|
||||
job_phase_old_ = analysis_phase_;
|
||||
if (job_phase_old_ <= 0.0f && job_phase_old_ != 0.0f) {
|
||||
job_phase_old_ = scalar;
|
||||
@@ -509,11 +530,11 @@ private:
|
||||
}
|
||||
qmf5_step(state, rotated, pcm64);
|
||||
for (int sample = 0; sample < 64; ++sample) {
|
||||
// The clamp is on the ×16 object PCM; joc_clipgain already
|
||||
// entered the analysis, so only the user output gain remains, and
|
||||
// it is a float32 multiply like the reference.
|
||||
const double clipped = clamp_unit(16.0 * pcm64[sample]);
|
||||
// joc_clipgain already entered the analysis (see analysis()); what
|
||||
// remains here is the user output gain.
|
||||
const float value = static_cast<float>(clipped * output_scale);
|
||||
destination[timeslot * 64 + sample] = value;
|
||||
destination[timeslot * 64 + sample] = static_cast<float>(clipped) * output_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -533,8 +554,10 @@ private:
|
||||
const int item = job_objects_[index];
|
||||
if (job_kind_ == JobKind::Analysis) {
|
||||
analysis_channel(item);
|
||||
} else {
|
||||
} else if (job_kind_ == JobKind::Objects) {
|
||||
process_one_object(item);
|
||||
} else {
|
||||
process_one_object_frame(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -595,7 +618,6 @@ private:
|
||||
const uint8_t* slope_idx,
|
||||
const uint8_t* offset_ts,
|
||||
const double* dq,
|
||||
const double clipgain,
|
||||
const float output_scale,
|
||||
float* output16) noexcept {
|
||||
|
||||
@@ -615,31 +637,509 @@ private:
|
||||
job_slope_idx_ = slope_idx;
|
||||
job_offset_ts_ = offset_ts;
|
||||
job_dq_ = dq;
|
||||
job_clipgain_ = clipgain;
|
||||
job_output_scale_ = output_scale;
|
||||
job_output16_ = output16;
|
||||
|
||||
dispatch_jobs();
|
||||
}
|
||||
|
||||
void render_lfe(const float* lfe, const float output_scale, float* output16) noexcept {
|
||||
if (!lfe) {
|
||||
return;
|
||||
// Core LFE: the full joc_clipgain is applied as a sample-wise ramp before the
|
||||
// 1217-sample delay, and the read-out is only clamped. The ramp is
|
||||
// G_old + n*(G_new-G_old)/256 for n < 256 and G_new afterwards; the first
|
||||
// frame after a reset uses G_old = G_new.
|
||||
void decode_lfe(const float* lfe, const double clipgain, float* output16,
|
||||
const float output_scale) noexcept {
|
||||
const double new_gain = clipgain;
|
||||
const double old_gain = has_lfe_clipgain_ ? lfe_clipgain_ : new_gain;
|
||||
const bool ramped = old_gain != new_gain;
|
||||
const double step = (new_gain - old_gain) / 256.0;
|
||||
double ramp[256];
|
||||
for (int n = 0; n < 256; ++n) {
|
||||
ramp[n] = ramped ? old_gain + static_cast<double>(n) * step : new_gain;
|
||||
}
|
||||
has_lfe_clipgain_ = true;
|
||||
lfe_clipgain_ = new_gain;
|
||||
|
||||
float* channel0 = output16;
|
||||
for (int sample = 0; sample < kLfeDelay; ++sample) {
|
||||
channel0[sample] =
|
||||
static_cast<float>(clamp_unit(lfe_delay_[sample])) * output_scale;
|
||||
}
|
||||
for (int sample = kLfeDelay; sample < EJOC_FRAME_SAMPLES; ++sample) {
|
||||
const int input = sample - kLfeDelay;
|
||||
const double gain = input < 256 ? ramp[input] : new_gain;
|
||||
const double value = (lfe != nullptr) ? static_cast<double>(lfe[input]) : 0.0;
|
||||
channel0[sample] =
|
||||
static_cast<float>(clamp_unit(value * gain)) * output_scale;
|
||||
}
|
||||
for (int sample = 0; sample < kLfeDelay; ++sample) {
|
||||
const float value = static_cast<float>(clamp_unit(lfe_delay_[sample]));
|
||||
output16[sample] = static_cast<float>(value * output_scale);
|
||||
}
|
||||
for (int sample = kLfeDelay; sample < 1536; ++sample) {
|
||||
const float value = static_cast<float>(clamp_unit(static_cast<double>(lfe[sample - kLfeDelay])));
|
||||
output16[sample] = static_cast<float>(value * output_scale);
|
||||
}
|
||||
for (int sample = 0; sample < kLfeDelay; ++sample) {
|
||||
lfe_delay_[sample] = static_cast<double>(lfe[sample + (1536 - kLfeDelay)]);
|
||||
const int input = sample + (EJOC_FRAME_SAMPLES - kLfeDelay);
|
||||
const double gain = input < 256 ? ramp[input] : new_gain;
|
||||
const double value = (lfe != nullptr) ? static_cast<double>(lfe[input]) : 0.0;
|
||||
lfe_delay_[sample] = value * gain;
|
||||
}
|
||||
}
|
||||
|
||||
enum class JobKind : uint8_t { Analysis, Objects };
|
||||
enum class FrameMode : uint8_t { Normal, Hold, HardCut, Passthrough };
|
||||
|
||||
// ---- frame-level state machine ------------------------------------- //
|
||||
// The Renderer owns the seq state machine (normal / hold / hard cut /
|
||||
// passthrough), the per-object previous matrix and its presence marker, the
|
||||
// analysis/synthesis state, the LFE delay ring with its clipgain ramp, and
|
||||
// the 8-plane core history of the passthrough path, so one audio frame in
|
||||
// produces the complete 16-channel object frame.
|
||||
|
||||
float held_analysis_scalar() const noexcept {
|
||||
// Sentinel: a renderer that has not seen a JOC frame yet reports the
|
||||
// structural 1/16, i.e. clipgain 1.0.
|
||||
return (analysis_phase_ <= 0.0f && analysis_phase_ != 0.0f) ? 0.0625f
|
||||
: analysis_phase_;
|
||||
}
|
||||
|
||||
double held_clipgain() const noexcept {
|
||||
return static_cast<double>(held_analysis_scalar()) * 16.0;
|
||||
}
|
||||
|
||||
// The 10-bit JOC sequence counter wraps from 1023 back to 1.
|
||||
static uint32_t next_seq(const uint32_t value) noexcept {
|
||||
return value == 1023u ? 1u : value + 1u;
|
||||
}
|
||||
|
||||
// Drops the state of the core channels a smaller layout does not use.
|
||||
void clear_unused_channels(const uint32_t n_channels) noexcept {
|
||||
if (n_channels >= EJOC_MAX_CORE_CHANNELS) {
|
||||
return;
|
||||
}
|
||||
for (uint32_t channel = n_channels; channel < EJOC_MAX_CORE_CHANNELS; ++channel) {
|
||||
std::memset(analysis_fifo_[channel], 0, sizeof(analysis_fifo_[channel]));
|
||||
}
|
||||
for (int object = 0; object < EJOC_MAX_OBJECTS; ++object) {
|
||||
for (uint32_t channel = n_channels; channel < EJOC_MAX_CORE_CHANNELS; ++channel) {
|
||||
std::memset(prev_matrix_[object][channel], 0,
|
||||
sizeof(prev_matrix_[object][channel]));
|
||||
}
|
||||
}
|
||||
if (n_channels == 5u) {
|
||||
// A 5-channel frame does not drive the extra-pair delay lanes.
|
||||
std::memset(analysis_delay_[3], 0, sizeof(analysis_delay_[3]));
|
||||
std::memset(analysis_delay_[4], 0, sizeof(analysis_delay_[4]));
|
||||
}
|
||||
}
|
||||
|
||||
// A declared core-channel-count change (renderer status 9) clears the LFE
|
||||
// ring; the clipgain ramp state is kept, so the gain does not retune.
|
||||
void maybe_clear_lfe_ring(const uint32_t status) noexcept {
|
||||
if (status == 9u) {
|
||||
std::memset(lfe_delay_, 0, sizeof(lfe_delay_));
|
||||
}
|
||||
}
|
||||
|
||||
// Advances the seq state machine for this frame and reports the state the
|
||||
// renderer was in before the frame. status 8 (no metadata) neither advances
|
||||
// the expected counter nor compares the sequence.
|
||||
uint32_t advance_state(const uint32_t status, const uint32_t seq) noexcept {
|
||||
const uint32_t pre_state = state_;
|
||||
const bool valid = status == 0u || status == 9u;
|
||||
if (status == EJOC_FRAME_STATUS_NO_METADATA && pre_state != 0u) {
|
||||
state_ = 3;
|
||||
return pre_state;
|
||||
}
|
||||
expected_seq_ = next_seq(expected_seq_);
|
||||
if (valid && seq == 0u && pre_state != 0u) {
|
||||
// The programme restarted: hard cut and drop the object history.
|
||||
state_ = 4;
|
||||
return pre_state;
|
||||
}
|
||||
uint32_t state = state_;
|
||||
if (state == 0u) {
|
||||
if (valid) {
|
||||
state = 1u;
|
||||
expected_seq_ = seq;
|
||||
}
|
||||
} else if (state == 1u) {
|
||||
if (valid) {
|
||||
if (seq != expected_seq_) {
|
||||
state = 4u;
|
||||
}
|
||||
} else {
|
||||
state = 2u;
|
||||
invalid_count_ = 1u;
|
||||
}
|
||||
} else if (state == 2u) {
|
||||
if (valid) {
|
||||
state = 1u;
|
||||
expected_seq_ = seq;
|
||||
} else if (invalid_count_ == 5u) {
|
||||
state = 3u;
|
||||
} else {
|
||||
++invalid_count_;
|
||||
}
|
||||
} else if (state == 3u) {
|
||||
if (valid) {
|
||||
state = 1u;
|
||||
expected_seq_ = seq;
|
||||
} else {
|
||||
++invalid_count_;
|
||||
}
|
||||
} else {
|
||||
// state 4: the hard cut lasted one frame; a valid frame resyncs and
|
||||
// an invalid one starts the invalid-frame count.
|
||||
if (valid) {
|
||||
state = 1u;
|
||||
expected_seq_ = seq;
|
||||
} else {
|
||||
state = 2u;
|
||||
invalid_count_ = 1u;
|
||||
}
|
||||
}
|
||||
state_ = state;
|
||||
if (status == 9u) {
|
||||
state_ = 4u;
|
||||
}
|
||||
last_frame_valid_ = valid;
|
||||
return pre_state;
|
||||
}
|
||||
|
||||
// Compatibility note for frames without JOC metadata (status 8).
|
||||
//
|
||||
// The state machine used to map status 8 to Passthrough unconditionally,
|
||||
// including in the middle of a stream. That is only meaningful before the
|
||||
// first valid JOC frame: a plain E-AC-3 stream (or a stream whose first JOC
|
||||
// frame comes late) has no object state yet, so the core planes are all
|
||||
// there is and the delayed core PCM is the right output. In the middle of
|
||||
// a JOC stream a frame without metadata is a damaged frame, not "no
|
||||
// objects": the Passthrough output replaces the object render with the core
|
||||
// planes, and the object synthesis restarts from silence on the next frame.
|
||||
// Every such frame therefore produced a step at the frame boundary and a
|
||||
// second one when the metadata came back; encoders that are not careful
|
||||
// with the JOC EMDF container emit exactly those frames.
|
||||
//
|
||||
// After the change status 8 follows the state machine like the other
|
||||
// invalid statuses: state 0 (no valid frame rendered yet) stays Passthrough,
|
||||
// and state 3 (mid-stream) selects Hold, which reuses the previous object
|
||||
// matrices and keeps the bed and object rendering continuous.
|
||||
//
|
||||
// This is a compatibility choice, not a claim about the normative reading
|
||||
// of the specification: a frame without metadata can be argued to be the
|
||||
// Passthrough case. It exists so that non-standard streams stay click-free;
|
||||
// if the reference behaviour is preferred, re-add the unconditional
|
||||
// Passthrough branch here.
|
||||
FrameMode select_mode(const uint32_t status) const noexcept {
|
||||
if (status == EJOC_FRAME_STATUS_NO_METADATA) {
|
||||
// See the note above: only a stream that has not rendered a valid
|
||||
// frame yet has nothing to hold.
|
||||
return state_ == 0u ? FrameMode::Passthrough : FrameMode::Hold;
|
||||
}
|
||||
if (state_ == 4u) {
|
||||
return FrameMode::HardCut;
|
||||
}
|
||||
if (state_ == 2u || state_ == 3u) {
|
||||
return FrameMode::Hold;
|
||||
}
|
||||
if (state_ == 1u && status == 0u) {
|
||||
return FrameMode::Normal;
|
||||
}
|
||||
return FrameMode::Passthrough;
|
||||
}
|
||||
|
||||
// JOC input order 5/7 channels (without LFE) -> 8-plane core order
|
||||
// L,R,C,LFE,Ls,Rs,(Lrs,Rrs). Used by the passthrough path and its history.
|
||||
void build_core8(const float* bed_planar, const float* lfe,
|
||||
const uint32_t n_channels) noexcept {
|
||||
std::memset(core8_, 0, sizeof(core8_));
|
||||
for (uint32_t channel = 0; channel < 3u && channel < n_channels; ++channel) {
|
||||
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
|
||||
core8_[channel][sample] =
|
||||
static_cast<double>(bed_planar[channel * EJOC_FRAME_SAMPLES + sample]);
|
||||
}
|
||||
}
|
||||
if (lfe != nullptr) {
|
||||
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
|
||||
core8_[EJOC_LFE_SLOT][sample] = static_cast<double>(lfe[sample]);
|
||||
}
|
||||
}
|
||||
const uint32_t rest = n_channels > 3u ? n_channels - 3u : 0u;
|
||||
for (uint32_t index = 0; index < rest; ++index) {
|
||||
const uint32_t channel = 3u + index;
|
||||
for (int sample = 0; sample < EJOC_FRAME_SAMPLES; ++sample) {
|
||||
core8_[4u + index][sample] =
|
||||
static_cast<double>(bed_planar[channel * EJOC_FRAME_SAMPLES + sample]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Passthrough output: slots 0..7 take the previous frame's 8 core planes
|
||||
// delayed by 1217 samples plus this frame's leading 319 samples; slots 8..15
|
||||
// stay zero.
|
||||
void write_passthrough(float* output16, const float output_scale) const noexcept {
|
||||
for (int channel = 0; channel < EJOC_CORE_OUT_CHANNELS; ++channel) {
|
||||
float* destination = output16 + channel * EJOC_FRAME_SAMPLES;
|
||||
for (int sample = 0; sample < kLfeDelay; ++sample) {
|
||||
destination[sample] = static_cast<float>(
|
||||
core_history_[channel][EJOC_FRAME_SAMPLES - kLfeDelay + sample]) *
|
||||
output_scale;
|
||||
}
|
||||
for (int sample = kLfeDelay; sample < EJOC_FRAME_SAMPLES; ++sample) {
|
||||
destination[sample] =
|
||||
static_cast<float>(core8_[channel][sample - kLfeDelay]) * output_scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normal rendering: interpolate the per-object matrix from its previous
|
||||
// frame-end value (or hard cut when there is none) and publish objects that
|
||||
// disappeared as an all-zero matrix until they come back.
|
||||
void matrix_object_frame(const int object) noexcept {
|
||||
std::memset(z_[object], 0, sizeof(z_[object]));
|
||||
const int n_channels = static_cast<int>(core_channels_);
|
||||
const bool present = (job_object_mask_ & (1u << object)) != 0u;
|
||||
if (!present) {
|
||||
if (prev_present_[object]) {
|
||||
for (int channel = 0; channel < n_channels; ++channel) {
|
||||
std::memset(prev_matrix_[object][channel], 0,
|
||||
sizeof(prev_matrix_[object][channel]));
|
||||
}
|
||||
prev_present_[object] = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
const int bands = job_n_bands_[object];
|
||||
const int points = job_n_dpoints_[object];
|
||||
const int slope = job_slope_idx_[object];
|
||||
const uint8_t* pb_map = parameter_band_map(bands);
|
||||
const bool has_previous = prev_present_[object];
|
||||
for (int channel = 0; channel < n_channels; ++channel) {
|
||||
for (int subband = 0; subband < EJOC_SUBBANDS; ++subband) {
|
||||
const int parameter_band = pb_map[subband];
|
||||
const double target0 = job_dq_[dq_index(object, 0, channel, parameter_band)];
|
||||
const double target1 = points == 2
|
||||
? job_dq_[dq_index(object, 1, channel, parameter_band)]
|
||||
: target0;
|
||||
const double previous =
|
||||
has_previous ? prev_matrix_[object][channel][subband] : 0.0;
|
||||
double last = target0;
|
||||
for (int timeslot = 0; timeslot < EJOC_TIMESLOTS; ++timeslot) {
|
||||
double coefficient = 0.0;
|
||||
if (slope == 0) {
|
||||
if (!has_previous) {
|
||||
if (points == 1 || timeslot < EJOC_TIMESLOTS / 2) {
|
||||
// Hard cut: no fade-in from zero. With two data
|
||||
// points the second half still interpolates.
|
||||
coefficient = target0;
|
||||
} else {
|
||||
const double alpha =
|
||||
static_cast<double>(timeslot - (EJOC_TIMESLOTS / 2 - 1)) /
|
||||
static_cast<double>(EJOC_TIMESLOTS / 2);
|
||||
coefficient = target0 * (1.0 - alpha) + target1 * alpha;
|
||||
}
|
||||
} else if (points == 1) {
|
||||
const double alpha =
|
||||
static_cast<double>(timeslot + 1) /
|
||||
static_cast<double>(EJOC_TIMESLOTS);
|
||||
coefficient = previous * (1.0 - alpha) + target0 * alpha;
|
||||
} else if (timeslot < EJOC_TIMESLOTS / 2) {
|
||||
const double alpha = static_cast<double>(timeslot + 1) /
|
||||
(EJOC_TIMESLOTS / 2);
|
||||
coefficient = previous * (1.0 - alpha) + target0 * alpha;
|
||||
} else {
|
||||
const double alpha =
|
||||
static_cast<double>(timeslot - (EJOC_TIMESLOTS / 2 - 1)) /
|
||||
static_cast<double>(EJOC_TIMESLOTS / 2);
|
||||
coefficient = target0 * (1.0 - alpha) + target1 * alpha;
|
||||
}
|
||||
} else {
|
||||
// Step mode switches targets at the raw offset slots.
|
||||
const double base = has_previous ? previous : target0;
|
||||
coefficient = timeslot < job_offset_ts_[object * EJOC_MAX_DPOINTS]
|
||||
? base
|
||||
: target0;
|
||||
if (points == 2 &&
|
||||
timeslot >= job_offset_ts_[object * EJOC_MAX_DPOINTS + 1]) {
|
||||
coefficient = target1;
|
||||
}
|
||||
}
|
||||
z_[object][subband][timeslot].re +=
|
||||
x_[channel][subband][timeslot].re * coefficient;
|
||||
z_[object][subband][timeslot].im +=
|
||||
x_[channel][subband][timeslot].im * coefficient;
|
||||
last = coefficient;
|
||||
}
|
||||
prev_matrix_[object][channel][subband] = last;
|
||||
}
|
||||
}
|
||||
prev_present_[object] = true;
|
||||
}
|
||||
|
||||
// Hold rendering: all 24 slots reuse the previous frame-end matrix and the
|
||||
// previous state is not updated.
|
||||
void matrix_object_hold(const int object) noexcept {
|
||||
std::memset(z_[object], 0, sizeof(z_[object]));
|
||||
const int n_channels = static_cast<int>(core_channels_);
|
||||
for (int channel = 0; channel < n_channels; ++channel) {
|
||||
for (int subband = 0; subband < EJOC_SUBBANDS; ++subband) {
|
||||
const double previous = prev_matrix_[object][channel][subband];
|
||||
for (int timeslot = 0; timeslot < EJOC_TIMESLOTS; ++timeslot) {
|
||||
z_[object][subband][timeslot].re +=
|
||||
x_[channel][subband][timeslot].re * previous;
|
||||
z_[object][subband][timeslot].im +=
|
||||
x_[channel][subband][timeslot].im * previous;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void process_one_object_frame(const int object) noexcept {
|
||||
if (frame_mode_ == FrameMode::Normal) {
|
||||
matrix_object_frame(object);
|
||||
} else if (frame_mode_ == FrameMode::Hold) {
|
||||
matrix_object_hold(object);
|
||||
} else {
|
||||
// Hard cut and passthrough publish silence, but every object slot is
|
||||
// still synthesised so the synthesis state stays aligned.
|
||||
std::memset(z_[object], 0, sizeof(z_[object]));
|
||||
}
|
||||
synthesis_object(object, job_output_scale_, job_output16_);
|
||||
}
|
||||
|
||||
// One E-AC-3 audio frame: validates the description, advances the state
|
||||
// machine and dispatches one of the four rendering modes.
|
||||
int render_frame_impl(const ejoc_frame_input& input) noexcept {
|
||||
error_[0] = '\0';
|
||||
if (input.struct_size != sizeof(ejoc_frame_input) ||
|
||||
input.struct_version != EJOC_FRAME_INPUT_VERSION) {
|
||||
return fail("unsupported ejoc_frame_input struct version");
|
||||
}
|
||||
if (input.bed_planar == nullptr || input.output16_planar == nullptr) {
|
||||
return fail("null bed or output pointer passed to ejoc_renderer_render_frame");
|
||||
}
|
||||
const uint32_t n_channels = input.core_channel_count;
|
||||
if (n_channels != EJOC_CORE_CHANNELS && n_channels != EJOC_MAX_CORE_CHANNELS) {
|
||||
return fail("core_channel_count must be 5 or 7");
|
||||
}
|
||||
if (!std::isfinite(input.clipgain) || !std::isfinite(input.output_scale)) {
|
||||
return fail("clipgain and output_scale must be finite");
|
||||
}
|
||||
const bool has_metadata = input.has_metadata != 0u;
|
||||
uint32_t status = input.frame_status;
|
||||
if (!has_metadata) {
|
||||
if (status != EJOC_FRAME_STATUS_NO_METADATA) {
|
||||
return fail("a frame without JOC metadata must use frame_status 8");
|
||||
}
|
||||
} else if (status != 0u && (status < 2u || status > 7u)) {
|
||||
return fail("frame_status is not a JOC parse status");
|
||||
}
|
||||
if ((input.object_mask & ~((1u << EJOC_MAX_OBJECTS) - 1u)) != 0u) {
|
||||
return fail("object_mask contains an object index above 14");
|
||||
}
|
||||
if (has_metadata && status == 0u) {
|
||||
for (int object = 0; object < EJOC_MAX_OBJECTS; ++object) {
|
||||
if ((input.object_mask & (1u << object)) == 0u) {
|
||||
continue;
|
||||
}
|
||||
if (parameter_band_map(input.n_bands[object]) == nullptr) {
|
||||
return fail("unsupported parameter-band count");
|
||||
}
|
||||
if (input.n_dpoints[object] < 1u || input.n_dpoints[object] > 2u) {
|
||||
return fail("n_dpoints must be 1 or 2");
|
||||
}
|
||||
if (input.slope_idx[object] > 1u) {
|
||||
return fail("slope_idx must be 0 or 1");
|
||||
}
|
||||
if (input.slope_idx[object] == 1u) {
|
||||
const uint8_t* offsets =
|
||||
input.offset_ts + object * EJOC_MAX_DPOINTS;
|
||||
for (uint32_t point = 0; point < input.n_dpoints[object]; ++point) {
|
||||
if (offsets[point] >= EJOC_TIMESLOTS) {
|
||||
return fail("offset_ts leaves the 0..23 range");
|
||||
}
|
||||
if (point != 0u && offsets[point] <= offsets[point - 1u]) {
|
||||
return fail("offset_ts is not strictly increasing");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (n_channels_prev_ >= 0 && n_channels != static_cast<uint32_t>(n_channels_prev_)) {
|
||||
clear_unused_channels(n_channels);
|
||||
}
|
||||
// The parse status decides whether the frame's clipgain is usable; a
|
||||
// declared-channel-count change (status 9) is only the renderer's own
|
||||
// dispatch tag, so the new gain still applies to that frame.
|
||||
const uint32_t parse_status = status;
|
||||
// A declared core-channel-count change is the renderer's status 9: hard
|
||||
// cut with the LFE ring cleared, while the clipgain ramp state is kept.
|
||||
if (has_metadata && status == 0u && input.declared_core_channels != 0u &&
|
||||
n_channels_prev_ >= 0 &&
|
||||
input.declared_core_channels != static_cast<uint32_t>(n_channels_prev_)) {
|
||||
status = 9u;
|
||||
}
|
||||
advance_state(status, input.seq);
|
||||
maybe_clear_lfe_ring(status);
|
||||
const FrameMode mode = select_mode(status);
|
||||
if (input.phase_shift_valid != 0u) {
|
||||
phase_shift_enabled_ = input.phase_shift != 0u;
|
||||
}
|
||||
const bool valid_metadata =
|
||||
has_metadata && parse_status == 0u && input.declared_core_channels != 0u;
|
||||
double clipgain;
|
||||
float phase_new;
|
||||
if ((mode == FrameMode::Normal || mode == FrameMode::HardCut) && valid_metadata) {
|
||||
clipgain = input.clipgain;
|
||||
phase_new = static_cast<float>(0.0625 * clipgain);
|
||||
} else {
|
||||
// Held frames reuse the current clipgain; they do not retune it.
|
||||
clipgain = held_clipgain();
|
||||
phase_new = held_analysis_scalar();
|
||||
}
|
||||
|
||||
core_channels_ = n_channels;
|
||||
std::memset(input.output16_planar, 0,
|
||||
sizeof(float) * EJOC_OUTPUT_CHANNELS * EJOC_FRAME_SAMPLES);
|
||||
build_core8(input.bed_planar, input.lfe, n_channels);
|
||||
analysis(input.bed_planar, phase_new);
|
||||
|
||||
job_kind_ = JobKind::FrameObjects;
|
||||
frame_mode_ = mode;
|
||||
job_object_mask_ = mode == FrameMode::Normal ? input.object_mask : 0u;
|
||||
job_n_bands_ = input.n_bands;
|
||||
job_n_dpoints_ = input.n_dpoints;
|
||||
job_slope_idx_ = input.slope_idx;
|
||||
job_offset_ts_ = input.offset_ts;
|
||||
job_dq_ = input.dq;
|
||||
job_output_scale_ = input.output_scale;
|
||||
job_output16_ = input.output16_planar;
|
||||
job_count_ = EJOC_MAX_OBJECTS;
|
||||
for (int object = 0; object < EJOC_MAX_OBJECTS; ++object) {
|
||||
job_objects_[object] = object;
|
||||
}
|
||||
dispatch_jobs();
|
||||
|
||||
decode_lfe(input.lfe, clipgain, input.output16_planar, input.output_scale);
|
||||
if (mode == FrameMode::HardCut) {
|
||||
// All matrices are zero this frame; the presence markers stay set so
|
||||
// the next valid frame fades in from zero.
|
||||
std::memset(input.output16_planar, 0,
|
||||
sizeof(float) * EJOC_OUTPUT_CHANNELS * EJOC_FRAME_SAMPLES);
|
||||
for (int object = 0; object < EJOC_MAX_OBJECTS; ++object) {
|
||||
prev_present_[object] = true;
|
||||
for (int channel = 0; channel < EJOC_MAX_CORE_CHANNELS; ++channel) {
|
||||
std::memset(prev_matrix_[object][channel], 0,
|
||||
sizeof(prev_matrix_[object][channel]));
|
||||
}
|
||||
}
|
||||
} else if (mode == FrameMode::Passthrough) {
|
||||
write_passthrough(input.output16_planar, input.output_scale);
|
||||
}
|
||||
|
||||
// The 8-plane history is updated on every frame so a later passthrough
|
||||
// frame is continuous with the last core PCM.
|
||||
std::memcpy(core_history_, core8_, sizeof(core_history_));
|
||||
n_channels_prev_ = static_cast<int>(n_channels);
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum class JobKind : uint8_t { Analysis, Objects, FrameObjects };
|
||||
|
||||
std::vector<std::thread> workers_;
|
||||
std::unique_ptr<std::barrier<>> work_barrier_;
|
||||
@@ -657,9 +1157,10 @@ private:
|
||||
const uint8_t* job_slope_idx_ = nullptr;
|
||||
const uint8_t* job_offset_ts_ = nullptr;
|
||||
const double* job_dq_ = nullptr;
|
||||
double job_clipgain_ = 1.0;
|
||||
float job_output_scale_ = 1.0f;
|
||||
float* job_output16_ = nullptr;
|
||||
uint32_t job_object_mask_ = 0;
|
||||
FrameMode frame_mode_ = FrameMode::Normal;
|
||||
|
||||
uint32_t core_channels_ = EJOC_CORE_CHANNELS;
|
||||
alignas(64) double analysis_fifo_[EJOC_MAX_CORE_CHANNELS][9][64];
|
||||
@@ -671,11 +1172,29 @@ private:
|
||||
// sigma(k) switch; the caller sets it for downmix configurations 3 and 4.
|
||||
bool phase_shift_enabled_ = true;
|
||||
alignas(64) double lfe_delay_[kLfeDelay];
|
||||
// LFE gain ramp start; cleared by reset() and cleared/unset only there, so a
|
||||
// held frame keeps the last applied gain.
|
||||
double lfe_clipgain_ = 0.0;
|
||||
bool has_lfe_clipgain_ = false;
|
||||
alignas(64) double matrix_previous_[15][EJOC_MAX_CORE_CHANNELS][64];
|
||||
alignas(64) double synthesis_state_[15][640];
|
||||
alignas(64) Complex x_[EJOC_MAX_CORE_CHANNELS][64][24];
|
||||
alignas(64) Complex z_[15][64][24];
|
||||
|
||||
// Frame-level state: the seq state machine and the per-object interpolation
|
||||
// previous matrix (frame-end timeslot of the last published matrix).
|
||||
uint32_t state_ = 0;
|
||||
uint32_t expected_seq_ = 0;
|
||||
uint32_t invalid_count_ = 0;
|
||||
bool last_frame_valid_ = false;
|
||||
int n_channels_prev_ = -1;
|
||||
alignas(64) double prev_matrix_[EJOC_MAX_OBJECTS][EJOC_MAX_CORE_CHANNELS][64];
|
||||
bool prev_present_[EJOC_MAX_OBJECTS];
|
||||
// Passthrough history: the 8 core planes of the previous frame and of this
|
||||
// frame, in the order L,R,C,LFE,Ls,Rs,(Lrs,Rrs).
|
||||
alignas(64) double core_history_[EJOC_CORE_OUT_CHANNELS][EJOC_FRAME_SAMPLES];
|
||||
alignas(64) double core8_[EJOC_CORE_OUT_CHANNELS][EJOC_FRAME_SAMPLES];
|
||||
|
||||
uint8_t bit_reverse_[64];
|
||||
Complex fft_twiddle_[32];
|
||||
double rotation_sin_[64];
|
||||
@@ -693,13 +1212,13 @@ uint32_t EJOC_CALL ejoc_abi_version(void) {
|
||||
|
||||
const char* EJOC_CALL ejoc_build_info(void) {
|
||||
#if defined(_MSC_VER)
|
||||
return "eac3joc-core abi=1 compiler=MSVC fft=fixed64 speaker=double binaural=double crt=static-by-build";
|
||||
return "eac3joc-core abi=4 compiler=MSVC fft=fixed64 speaker=double binaural=double crt=static-by-build";
|
||||
#elif defined(__clang__)
|
||||
return "eac3joc-core abi=1 compiler=Clang fft=fixed64 speaker=double binaural=double";
|
||||
return "eac3joc-core abi=4 compiler=Clang fft=fixed64 speaker=double binaural=double";
|
||||
#elif defined(__GNUC__)
|
||||
return "eac3joc-core abi=1 compiler=GCC fft=fixed64 speaker=double binaural=double";
|
||||
return "eac3joc-core abi=4 compiler=GCC fft=fixed64 speaker=double binaural=double";
|
||||
#else
|
||||
return "eac3joc-core abi=1 compiler=unknown fft=fixed64 speaker=double binaural=double";
|
||||
return "eac3joc-core abi=4 compiler=unknown fft=fixed64 speaker=double binaural=double";
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -763,4 +1282,15 @@ int EJOC_CALL ejoc_renderer_process(
|
||||
slope_idx, offset_ts, dq, clipgain, phase_new, output_scale, output16_planar);
|
||||
}
|
||||
|
||||
int EJOC_CALL ejoc_renderer_render_frame(ejoc_renderer_handle handle,
|
||||
const ejoc_frame_input* input) {
|
||||
if (!handle) {
|
||||
return -1;
|
||||
}
|
||||
if (!input) {
|
||||
return -1;
|
||||
}
|
||||
return static_cast<ejoc::Renderer*>(handle)->render_frame(*input);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
+38
-14
@@ -6,16 +6,17 @@
|
||||
namespace joc::joc {
|
||||
|
||||
Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& params,
|
||||
const float* bed_planar, const float* lfe, float gain,
|
||||
const float* bed_planar, const float* lfe,
|
||||
std::uint32_t core_channel_count, bool has_metadata, float gain,
|
||||
std::vector<float>* out16, std::string* error) {
|
||||
if (handle == nullptr || bed_planar == nullptr || out16 == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kDsp, "null argument");
|
||||
}
|
||||
if (params.n_channels != JOC_CORE_CHANNELS &&
|
||||
params.n_channels != JOC_MAX_CORE_CHANNELS) {
|
||||
if (core_channel_count != JOC_CORE_CHANNELS &&
|
||||
core_channel_count != JOC_MAX_CORE_CHANNELS) {
|
||||
if (error != nullptr) {
|
||||
*error = "the reused JOC kernel requires 5 or 7 core channels, frame declares " +
|
||||
std::to_string(static_cast<unsigned>(params.n_channels));
|
||||
*error = "the reused JOC kernel requires 5 or 7 core channels, the frame has " +
|
||||
std::to_string(core_channel_count);
|
||||
}
|
||||
return Status::fail(JOC_ERR_JOC_UNSUPPORTED_VARIANT, stage::kDsp, *error);
|
||||
}
|
||||
@@ -39,7 +40,7 @@ Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& pa
|
||||
offset_ts[obj * JOC_MAX_DPOINTS + dp] = object.offset_ts[dp];
|
||||
}
|
||||
for (unsigned dp = 0; dp < object.n_dpoints; ++dp) {
|
||||
for (unsigned ch = 0; ch < params.n_channels; ++ch) {
|
||||
for (unsigned ch = 0; ch < core_channel_count; ++ch) {
|
||||
for (unsigned pb = 0; pb < object.n_bands; ++pb) {
|
||||
const std::size_t index =
|
||||
((static_cast<std::size_t>(obj) * JOC_MAX_DPOINTS + dp) *
|
||||
@@ -53,19 +54,42 @@ Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& pa
|
||||
}
|
||||
}
|
||||
|
||||
out16->assign(static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * JOC_FRAME_SAMPLES, 0.0f);
|
||||
ejoc_frame_input input{};
|
||||
input.struct_size = sizeof(input);
|
||||
input.struct_version = EJOC_FRAME_INPUT_VERSION;
|
||||
input.bed_planar = bed_planar;
|
||||
input.lfe = lfe;
|
||||
input.core_channel_count = core_channel_count;
|
||||
// A frame without metadata has no declared channel count; the renderer's
|
||||
// status-9 path is gated on has_metadata, so the value is not consulted.
|
||||
input.declared_core_channels =
|
||||
has_metadata ? static_cast<std::uint32_t>(params.n_channels) : 0u;
|
||||
// sigma(k) = (k in {3,4}) gates the Ls/Rs -j rotation and the band-0 21-tap
|
||||
// DC compensation together; other configurations keep the common processing.
|
||||
const std::uint32_t phase_shift =
|
||||
(params.dmx_config_idx == 3 || params.dmx_config_idx == 4) ? 1u : 0u;
|
||||
const int result = ejoc_renderer_process(
|
||||
handle, bed_planar, lfe, params.n_channels, phase_shift, params.present_mask, n_bands,
|
||||
n_dpoints, slope_idx, offset_ts, dq.data(), params.clipgain, 0.0625f, gain,
|
||||
out16->data());
|
||||
// An unsupported downmix configuration (status 2) has no usable switch, so
|
||||
// the renderer keeps the previous one.
|
||||
input.phase_shift =
|
||||
(params.dmx_config_idx == 3u || params.dmx_config_idx == 4u) ? 1u : 0u;
|
||||
input.phase_shift_valid = params.status == JOC_FRAME_STATUS_UNSUPPORTED_DMX ? 0u : 1u;
|
||||
input.frame_status = has_metadata ? params.status : EJOC_FRAME_STATUS_NO_METADATA;
|
||||
input.seq = params.seq_count;
|
||||
input.has_metadata = has_metadata ? 1u : 0u;
|
||||
input.object_mask = params.present_mask;
|
||||
input.n_bands = n_bands;
|
||||
input.n_dpoints = n_dpoints;
|
||||
input.slope_idx = slope_idx;
|
||||
input.offset_ts = offset_ts;
|
||||
input.dq = dq.data();
|
||||
input.clipgain = params.clipgain;
|
||||
input.output_scale = gain;
|
||||
out16->assign(static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * JOC_FRAME_SAMPLES, 0.0f);
|
||||
input.output16_planar = out16->data();
|
||||
|
||||
const int result = ejoc_renderer_render_frame(handle, &input);
|
||||
if (result != 0) {
|
||||
const char* detail = ejoc_renderer_last_error(handle);
|
||||
const std::string message =
|
||||
"ejoc_renderer_process failed (" + std::to_string(result) + "): " +
|
||||
"ejoc_renderer_render_frame failed (" + std::to_string(result) + "): " +
|
||||
(detail != nullptr ? detail : "unknown");
|
||||
if (error != nullptr) {
|
||||
*error = message;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -10,10 +11,20 @@
|
||||
|
||||
namespace joc::joc {
|
||||
|
||||
// [16][1536] planar float32. bed_planar is [params.n_channels][1536], where
|
||||
// n_channels comes from joc_dmx_config_idx (5 or 7).
|
||||
// Rebuilds the 16-channel object frame ([16][1536] planar float32) for one
|
||||
// audio frame through the renderer's frame-level state machine. bed_planar is
|
||||
// [core_channel_count][1536] in JOC lane order (L,R,C,Ls,Rs,(extra pair)), where
|
||||
// core_channel_count is the actual bed lane count (5 or 7) and lfe is the
|
||||
// separate core LFE plane (NULL = zeros; the LFE ring still advances).
|
||||
//
|
||||
// has_metadata is false for an audio frame without a JOC EMDF container: such a
|
||||
// frame always passes the 8 core planes through to output slots 0..7. For a
|
||||
// frame with metadata, params.status selects normal rendering or the invalid
|
||||
// frame path (hold / hard cut), and params.seq_count drives the state machine.
|
||||
// gain is the user output gain (not joc_clipgain).
|
||||
Status rebuild_objects16(ejoc_renderer_handle handle, const joc_frame_params& params,
|
||||
const float* bed_planar, const float* lfe, float gain,
|
||||
const float* bed_planar, const float* lfe,
|
||||
std::uint32_t core_channel_count, bool has_metadata, float gain,
|
||||
std::vector<float>* out16, std::string* error);
|
||||
|
||||
} // namespace joc::joc
|
||||
@@ -338,7 +338,7 @@ inline constexpr uint8_t kPbMap1[64] = {
|
||||
};
|
||||
|
||||
inline constexpr uint8_t kPbMap3[64] = {
|
||||
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
|
||||
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
@@ -346,8 +346,8 @@ inline constexpr uint8_t kPbMap3[64] = {
|
||||
|
||||
inline constexpr uint8_t kPbMap5[64] = {
|
||||
0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
};
|
||||
|
||||
@@ -359,8 +359,8 @@ inline constexpr uint8_t kPbMap7[64] = {
|
||||
};
|
||||
|
||||
inline constexpr uint8_t kPbMap9[64] = {
|
||||
0, 1, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
};
|
||||
@@ -373,9 +373,9 @@ inline constexpr uint8_t kPbMap12[64] = {
|
||||
};
|
||||
|
||||
inline constexpr uint8_t kPbMap15[64] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 10, 11, 11, 11,
|
||||
12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 10, 10, 11, 11,
|
||||
11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,101 @@
|
||||
// Port of src/oamd_math.py: float32 equations for the metadata application path.
|
||||
//
|
||||
// The routines implement the fixed float32 equations for the size tables, ISF
|
||||
// basis assembly, bed channel routing and the position-dependent compensation.
|
||||
// The size tables are generated from the region geometry with grouped equal-power
|
||||
// panning, an S448 weight and a power sum; every operation is evaluated in
|
||||
// float32 in a fixed order so the coefficients are reproducible.
|
||||
//
|
||||
// The caller passes the parameter mappings from oamd_params; this module does
|
||||
// not read files itself.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "oamd/oamd_params.h"
|
||||
#include "speaker/speaker_layout_lookup.h"
|
||||
#include "speaker/speaker_layouts.h"
|
||||
|
||||
namespace joc::oamd {
|
||||
|
||||
// The specified 2**x approximation used by the compensation kernels.
|
||||
float exp2_approx(float value);
|
||||
|
||||
// The specified x**power approximation; power is a float32.
|
||||
float pow_approx(float value, float power);
|
||||
|
||||
// Stable float32 normalisation with the tiny-norm floor.
|
||||
std::vector<float> norm(const std::vector<float>& vector);
|
||||
|
||||
// One boundary weight of the size kernel.
|
||||
float boundary(int axis, int edge, float position, float t);
|
||||
|
||||
// Maps a scalar size in [0, 1] to t on the size curve.
|
||||
float size_curve_value(double size);
|
||||
|
||||
// Size kernel response in region-speaker order (the region point order).
|
||||
std::vector<float> size_kernel(const ::ejoc::speaker_tables::RegionGeometry& region,
|
||||
const float position[3], float t, bool height);
|
||||
|
||||
// Size-kernel target vector in layout channel order.
|
||||
std::vector<float> size_targets(const MetadataParams& meta,
|
||||
const ::ejoc::speaker_tables::LayoutGeometry& layout,
|
||||
int region_index, const double position[3],
|
||||
double size, bool height);
|
||||
|
||||
// One assembled ISF basis matrix (row_count x layout output_count, row major).
|
||||
struct IsfBasis {
|
||||
int rows = 0;
|
||||
int columns = 0;
|
||||
std::vector<float> values;
|
||||
|
||||
float at(int row, int column) const {
|
||||
return values[static_cast<std::size_t>(row) * static_cast<std::size_t>(columns) +
|
||||
static_cast<std::size_t>(column)];
|
||||
}
|
||||
};
|
||||
|
||||
// Assembles one ISF basis matrix from the compressed base tables.
|
||||
IsfBasis assemble_isf(const MetadataParams& meta, const char* layout_key, int isf_idx);
|
||||
|
||||
// Returns the per-basis ISF compensation gain.
|
||||
float isf_compensation(const MetadataParams& meta, const char* layout_key, int isf_idx,
|
||||
int row, bool disabled);
|
||||
|
||||
// Per-label bed redistribution weight, in the reference-position index space
|
||||
// used by the layout descriptors.
|
||||
float bed_weight(int label, std::uint32_t mask, int target_label);
|
||||
|
||||
// The five height-candidate flags for one input bed label.
|
||||
std::array<int, 5> bed_candidates(int label, std::uint32_t mask,
|
||||
const std::vector<int>& output_labels);
|
||||
|
||||
// Route and weights for one input bed label. route == -1 means the returned
|
||||
// weights are the target; otherwise route is the reference position used to
|
||||
// synthesise a point source.
|
||||
struct BedDistribution {
|
||||
int route = -1;
|
||||
std::vector<float> weights;
|
||||
};
|
||||
|
||||
// Derives the bed routing of one input bed label from the target layout.
|
||||
BedDistribution bed_distribution(const ::joc::speaker::LayoutInfo& layout, int label,
|
||||
std::uint32_t mask, bool distribute);
|
||||
|
||||
// Returns the Q15 reference position used by the bed fallback path.
|
||||
void bed_reference_position(int index, int q15[3]);
|
||||
|
||||
// Returns the bed path compensation gain for one input bed label. ``mode`` is
|
||||
// the trim mode (0 automatic, 1 disabled, 2 explicit) and ``levels`` holds the
|
||||
// surround, height and centre levels in dB.
|
||||
float bed_compensation(const ::joc::speaker::LayoutInfo& layout, int label, int mode,
|
||||
bool bypass, const double levels[3]);
|
||||
|
||||
// Automatic attenuation of a target layout in dB.
|
||||
float bed_attenuation_db(const ::joc::speaker::LayoutInfo& layout);
|
||||
|
||||
} // namespace joc::oamd
|
||||
@@ -0,0 +1,108 @@
|
||||
#include "oamd/oamd_params.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "oamd/isf_tables.h"
|
||||
|
||||
namespace joc::oamd {
|
||||
|
||||
namespace {
|
||||
|
||||
namespace tables = isf_tables;
|
||||
|
||||
// Builds the renderer-facing view from the checked-in table header. There is no
|
||||
// file I/O and no runtime parsing: the numbers are compiled in as static data.
|
||||
MetadataParams build_params() {
|
||||
MetadataParams params;
|
||||
params.configs.reserve(tables::kConfigCount);
|
||||
for (const tables::Config& source : tables::kConfigs) {
|
||||
IsfConfig config;
|
||||
for (std::size_t index = 0; index < config.counts.size(); ++index) {
|
||||
config.counts[index] = source.counts[index];
|
||||
}
|
||||
const std::size_t rows = static_cast<std::size_t>(config.row_count());
|
||||
config.primary_row_map.assign(source.primary_row_map, source.primary_row_map + rows);
|
||||
config.secondary_row_map.assign(source.secondary_row_map,
|
||||
source.secondary_row_map + rows);
|
||||
const std::size_t coefficients = rows * static_cast<std::size_t>(tables::kMatrixColumns);
|
||||
config.matrix.assign(source.matrix, source.matrix + coefficients);
|
||||
params.configs.push_back(std::move(config));
|
||||
}
|
||||
|
||||
params.layouts.reserve(tables::kLayoutCount);
|
||||
for (const tables::Layout& source : tables::kLayouts) {
|
||||
IsfLayout layout;
|
||||
layout.output_count = source.output_count;
|
||||
for (std::size_t index = 0; index < layout.selectors.size(); ++index) {
|
||||
layout.selectors[index] = source.selectors[index];
|
||||
}
|
||||
layout.compensation_value = source.compensation_value;
|
||||
layout.output_ids.assign(source.output_ids,
|
||||
source.output_ids + tables::kOutputIdSlots);
|
||||
params.layouts.emplace(source.key, std::move(layout));
|
||||
}
|
||||
|
||||
const auto copy_groups = [](const tables::GroupRecord* records, int count,
|
||||
std::vector<IsfGroupRecord>* out) {
|
||||
out->reserve(static_cast<std::size_t>(count));
|
||||
for (int index = 0; index < count; ++index) {
|
||||
out->push_back(IsfGroupRecord{records[index].selector, records[index].begin,
|
||||
records[index].end});
|
||||
}
|
||||
};
|
||||
copy_groups(tables::kLayoutGroups.floor_a, tables::kLayoutGroups.floor_a_count,
|
||||
¶ms.layout_groups.floor_a);
|
||||
copy_groups(tables::kLayoutGroups.floor_b, tables::kLayoutGroups.floor_b_count,
|
||||
¶ms.layout_groups.floor_b);
|
||||
copy_groups(tables::kLayoutGroups.height, tables::kLayoutGroups.height_count,
|
||||
¶ms.layout_groups.height);
|
||||
copy_groups(tables::kLayoutGroups.additional, tables::kLayoutGroups.additional_count,
|
||||
¶ms.layout_groups.additional);
|
||||
|
||||
params.paired_columns.assign(tables::kPairedColumns,
|
||||
tables::kPairedColumns + tables::kPairedColumnCount);
|
||||
return params;
|
||||
}
|
||||
|
||||
const MetadataParams& loaded_params() {
|
||||
static const MetadataParams params = build_params();
|
||||
return params;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const std::vector<IsfGroupRecord>* IsfLayoutGroups::find(const char* name) const {
|
||||
if (name == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
const std::string key(name);
|
||||
if (key == "floor_a") {
|
||||
return &floor_a;
|
||||
}
|
||||
if (key == "floor_b") {
|
||||
return &floor_b;
|
||||
}
|
||||
if (key == "height") {
|
||||
return &height;
|
||||
}
|
||||
if (key == "additional") {
|
||||
return &additional;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const IsfLayout* MetadataParams::layout(const char* key) const {
|
||||
if (key == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
const auto found = layouts.find(key);
|
||||
return found != layouts.end() ? &found->second : nullptr;
|
||||
}
|
||||
|
||||
const MetadataParams* metadata_params() { return &loaded_params(); }
|
||||
|
||||
const char* metadata_params_error() { return ""; }
|
||||
|
||||
} // namespace joc::oamd
|
||||
@@ -0,0 +1,82 @@
|
||||
// Port of src/oamd_params.py: the static ISF lookup data of the metadata path.
|
||||
//
|
||||
// The numbers are compiled in as the generated header `oamd/isf_tables.h`:
|
||||
// ISF base coefficients and layout descriptors, applied as lookup tables.
|
||||
// The remaining values (gain, size, priority, position, delta and refinement
|
||||
// tables) are computed in code; the size tables are generated from the region
|
||||
// geometry at runtime, and bed routing is derived from the speaker layouts.
|
||||
// The arrays are adapted once per process into the structures below; nothing
|
||||
// reads a data file.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/status.h"
|
||||
|
||||
namespace joc::oamd {
|
||||
|
||||
// One ISF configuration: the compressed basis matrix and the two row maps
|
||||
// that expand it to the layout output channels.
|
||||
struct IsfConfig {
|
||||
// mid, upper, lower, zenith, row_count (the reference's counts tuple).
|
||||
std::array<int, 5> counts{};
|
||||
std::vector<int> primary_row_map;
|
||||
std::vector<int> secondary_row_map;
|
||||
// row_count * 73 float32 coefficients, row major.
|
||||
std::vector<float> matrix;
|
||||
|
||||
int row_count() const { return counts[4]; }
|
||||
};
|
||||
|
||||
// One layout descriptor: how many output channels the basis has,
|
||||
// the layout-group selectors and the automatic compensation value.
|
||||
struct IsfLayout {
|
||||
int output_count = 0;
|
||||
std::array<int, 4> selectors{}; // floor_a, floor_b, height, additional
|
||||
double compensation_value = 0.0;
|
||||
// ISF channel id of each matrix output column, padded with zeros to 37.
|
||||
std::vector<std::uint8_t> output_ids;
|
||||
};
|
||||
|
||||
// One record of a layout group: selector id and the half-open column range
|
||||
// [begin, end).
|
||||
struct IsfGroupRecord {
|
||||
int selector = 0;
|
||||
int begin = 0;
|
||||
int end = 0;
|
||||
};
|
||||
|
||||
// The four layout groups of the ISF tables.
|
||||
struct IsfLayoutGroups {
|
||||
std::vector<IsfGroupRecord> floor_a;
|
||||
std::vector<IsfGroupRecord> floor_b;
|
||||
std::vector<IsfGroupRecord> height;
|
||||
std::vector<IsfGroupRecord> additional;
|
||||
|
||||
const std::vector<IsfGroupRecord>* find(const char* name) const;
|
||||
};
|
||||
|
||||
// The ISF lookup data in the shape the metadata renderer consumes.
|
||||
struct MetadataParams {
|
||||
std::vector<IsfConfig> configs;
|
||||
std::unordered_map<std::string, IsfLayout> layouts;
|
||||
IsfLayoutGroups layout_groups;
|
||||
// One flag per matrix column: whether the column also contributes through
|
||||
// the secondary row map.
|
||||
std::vector<bool> paired_columns;
|
||||
|
||||
const IsfLayout* layout(const char* key) const;
|
||||
};
|
||||
|
||||
// Returns the process-wide tables. They are compiled in, so the pointer is
|
||||
// never null; ``metadata_params_error`` is kept for callers that log a load
|
||||
// failure and always returns an empty string.
|
||||
const MetadataParams* metadata_params();
|
||||
const char* metadata_params_error();
|
||||
|
||||
} // namespace joc::oamd
|
||||
+1158
-254
File diff suppressed because it is too large.
Load diff
+213
-4
@@ -9,6 +9,34 @@
|
||||
#include "foundation/status.h"
|
||||
#include "joc_core.h"
|
||||
|
||||
namespace joc::joc {
|
||||
|
||||
// OAMD Table 12 的标准 bed 声道。LSB 顺序与声明顺序一致:L/R、C、LFE、
|
||||
// Ls/Rs、Lrs/Rrs、TFL/TFR、TSL/TSR、TBL/TBR、LW/RW、LFE2。
|
||||
// The enum values are the reference's BED_LABEL_INDEX - 1.
|
||||
enum class BedChannel : std::uint8_t {
|
||||
kLeft = 0,
|
||||
kRight,
|
||||
kCenter,
|
||||
kLfe,
|
||||
kLeftSurround,
|
||||
kRightSurround,
|
||||
kLeftRearSurround,
|
||||
kRightRearSurround,
|
||||
kTopFrontLeft,
|
||||
kTopFrontRight,
|
||||
kTopSideLeft,
|
||||
kTopSideRight,
|
||||
kTopBackLeft,
|
||||
kTopBackRight,
|
||||
kLeftWide,
|
||||
kRightWide,
|
||||
kLfe2,
|
||||
kCount,
|
||||
};
|
||||
|
||||
} // namespace joc::joc
|
||||
|
||||
namespace joc::oamd {
|
||||
|
||||
inline constexpr int kMaxSlots = 16;
|
||||
@@ -17,6 +45,132 @@ inline constexpr int kAxes = 3;
|
||||
inline constexpr int kNQ12 = 62;
|
||||
inline constexpr int kNQ3 = 15;
|
||||
inline constexpr int kQ15Scale = 32768;
|
||||
// Largest ISF configuration of Table 11b (5.6.0.11). A frame cannot carry more
|
||||
// objects than this through any of the standard programmes, but the parser does
|
||||
// not reject a larger count: it only bounds the legacy 16-slot view.
|
||||
inline constexpr int kMaxObjects = 30;
|
||||
inline constexpr int kMaxBlocks = 8;
|
||||
inline constexpr std::uint32_t kTrimElementId = 2;
|
||||
inline constexpr std::uint32_t kObjectElementId = 1;
|
||||
inline constexpr std::uint32_t kExtendedElementId = 5;
|
||||
inline constexpr int kTrimConfigs = 9;
|
||||
inline constexpr int kBedLabelCount = 17;
|
||||
|
||||
// One of the nine per-configuration trim records of the OAMD trim element.
|
||||
// ``kAbsent`` means the configuration carries no data (the element only
|
||||
// carries explicit records when global_trim_mode is 2).
|
||||
enum class TrimConfigKind : std::uint8_t {
|
||||
kAbsent = 0,
|
||||
kDefault,
|
||||
kDisabled,
|
||||
kExplicit,
|
||||
};
|
||||
|
||||
struct TrimConfig {
|
||||
TrimConfigKind kind = TrimConfigKind::kAbsent;
|
||||
std::uint8_t presence = 0; // b_*_trim_present bits of an explicit record
|
||||
double centre = 0.0; // dB
|
||||
double surround = 0.0; // dB
|
||||
double height = 0.0; // dB
|
||||
double balance_overhead = 0.0; // bal3d_y_tb, [-1, 1]
|
||||
double balance_listener = 0.0; // bal3d_y_lis, [-1, 1]
|
||||
};
|
||||
|
||||
// Programme calibration carried by the OAMD trim element: warp mode, global
|
||||
// trim mode, the nine configuration records and the per-object bypass flags.
|
||||
struct OamdTrim {
|
||||
std::uint32_t warp_mode = 0;
|
||||
std::uint32_t global_trim_mode = 0;
|
||||
TrimConfig configs[kTrimConfigs];
|
||||
std::uint32_t object_count = 0;
|
||||
bool disable_per_object[kMaxSlots] = {};
|
||||
};
|
||||
|
||||
// OAMD object kind: the programme assigns objects to the bed, to an ISF
|
||||
// configuration, or to the dynamic (positional) set, in that order.
|
||||
enum class ObjectKind : std::uint8_t {
|
||||
kBed = 0,
|
||||
kIsf = 1,
|
||||
kDynamic = 2,
|
||||
};
|
||||
|
||||
// Render state of one object in one block (5.5.9 object_info_block).
|
||||
struct ObjectRenderState {
|
||||
bool not_active = false;
|
||||
std::int32_t gain_q = 0; // integer gain, unity = 4096
|
||||
std::int32_t priority_q = 0; // Q10 priority, 32767 = default
|
||||
std::int32_t qx = 0; // Q15 room position, 0..32767
|
||||
std::int32_t qy = 0; // Q15 room position, 0..32767
|
||||
std::int32_t qz = 0; // signed Q15 elevation
|
||||
std::uint8_t zone_idx = 0;
|
||||
bool enable_elevation = true;
|
||||
std::uint8_t size_mode = 0; // 0 none, 1 isotropic, 2 per-axis
|
||||
std::uint16_t size_q[3] = {0, 0, 0}; // Q15 size per axis
|
||||
bool snap = false;
|
||||
std::uint16_t divergence_q = 0; // Q15 divergence width
|
||||
};
|
||||
|
||||
struct ObjectBlockState {
|
||||
ObjectRenderState render;
|
||||
};
|
||||
|
||||
// One object of the frame: its kind and the state of every block.
|
||||
struct ObjectElementState {
|
||||
ObjectKind kind = ObjectKind::kDynamic;
|
||||
std::vector<ObjectBlockState> blocks;
|
||||
};
|
||||
|
||||
// Timing shared by every object of one block. ``block_offset_samples`` already
|
||||
// includes the element's sample_offset, like the reference block dictionary.
|
||||
struct BlockTiming {
|
||||
std::uint32_t block_offset_samples = 0;
|
||||
std::uint32_t ramp_duration_samples = 0;
|
||||
};
|
||||
|
||||
// Program assignment (5.5.3) as consumed by the speaker renderer.
|
||||
struct ProgramState {
|
||||
bool dynamic_object_only = false;
|
||||
bool lfe_present = false;
|
||||
bool b_bed_chan_distribute = false;
|
||||
// program_assignment() content_description flags.
|
||||
bool content_reserved = false;
|
||||
bool content_bed = false;
|
||||
bool content_isf = false;
|
||||
bool content_dynamic = false;
|
||||
std::uint32_t num_bed_objects = 0;
|
||||
std::uint32_t num_isf_objects = 0;
|
||||
std::int32_t num_dynamic_objects = -1; // -1 when the frame declares none
|
||||
std::uint32_t bed_mask = 0; // 17-bit non-standard bed mask
|
||||
std::int32_t isf_idx = -1; // -1 when the frame declares none
|
||||
// Declared bed labels in channel order, including LFE/LFE2. Index i is the
|
||||
// label of object i for i < num_bed_objects.
|
||||
std::vector<::joc::joc::BedChannel> bed_labels;
|
||||
};
|
||||
|
||||
// One element whose parsed content ended past its declared size. The reference
|
||||
// keeps parsing such elements and only records the difference.
|
||||
struct ElementSizeMismatch {
|
||||
std::uint32_t element_ordinal = 0;
|
||||
std::uint32_t element_id = 0;
|
||||
std::uint32_t declared_size_bytes = 0;
|
||||
std::uint32_t declared_end_bit = 0;
|
||||
std::uint32_t parsed_end_bit = 0;
|
||||
};
|
||||
|
||||
// Full frame state (frame_state() in the reference): per-object per-block
|
||||
// render state plus programme assignment, timing and trim.
|
||||
struct FrameState {
|
||||
std::uint32_t object_count = 0;
|
||||
std::uint32_t block_count = 0;
|
||||
std::uint32_t sample_offset = 0; // object_element sample offset
|
||||
std::uint32_t ramp_duration_samples = 0; // block 0
|
||||
std::vector<BlockTiming> blocks;
|
||||
std::vector<ObjectElementState> objects;
|
||||
ProgramState program;
|
||||
bool has_trim = false;
|
||||
OamdTrim trim;
|
||||
std::vector<ElementSizeMismatch> size_mismatch;
|
||||
};
|
||||
|
||||
// (the reference's None), i.e. hold the previous position.
|
||||
struct SlotUpdate {
|
||||
@@ -35,6 +189,21 @@ struct OamdUpdate {
|
||||
std::uint32_t num_bed_objects = 0;
|
||||
std::uint32_t num_isf_objects = 0;
|
||||
std::int32_t num_dynamic_objects = -1;
|
||||
// program_assignment() 的 content_description:bed / ISF / 动态对象三类内容。
|
||||
bool content_bed = false;
|
||||
bool content_isf = false;
|
||||
bool content_dynamic = false;
|
||||
// Trim element of this payload. The element describes the programme, so
|
||||
// ``has_trim`` only marks the payloads that carry it; a payload without it
|
||||
// keeps whatever controls the caller already holds.
|
||||
OamdTrim trim;
|
||||
bool has_trim = false;
|
||||
// Full per-object per-block state of this payload. ``has_frame_state`` is
|
||||
// true whenever the parser produced it; the speaker metadata path and the
|
||||
// binaural position timeline consume it, while the legacy slot fields above
|
||||
// stay authoritative for ADM export and the point-renderer path.
|
||||
bool has_frame_state = false;
|
||||
FrameState frame_state;
|
||||
};
|
||||
|
||||
class OamdState {
|
||||
@@ -62,6 +231,23 @@ public:
|
||||
|
||||
std::int16_t q(int slot, int axis) const { return q_[slot][axis]; }
|
||||
|
||||
// Resolves one frame-state position block for one object. The legacy
|
||||
// apply() entry above keeps the reference frame_update() view (16 slots,
|
||||
// block 0); the binaural position timeline uses this entry so a frame may
|
||||
// carry more objects and more blocks than that view can express. Callers
|
||||
// skip inactive and non-dynamic objects themselves, exactly like the
|
||||
// reference's frame_update() value construction.
|
||||
void apply_render_state(int object_index, const ObjectRenderState& render) {
|
||||
if (object_index < 0 || object_index >= kMaxObjects) {
|
||||
return;
|
||||
}
|
||||
q_[object_index][0] = static_cast<std::int16_t>(render.qx);
|
||||
q_[object_index][1] = static_cast<std::int16_t>(render.qy);
|
||||
const std::int32_t elevation = render.enable_elevation ? render.qz : 0;
|
||||
q_[object_index][2] =
|
||||
static_cast<std::int16_t>(elevation > 0 ? elevation : 0);
|
||||
}
|
||||
|
||||
// Objects 1..15 as q15 triples, the layout the speaker renderer consumes.
|
||||
void object_positions_q15(std::uint16_t out[kObjects][kAxes]) const {
|
||||
for (int object = 0; object < kObjects; ++object) {
|
||||
@@ -72,18 +258,18 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::int16_t q_[kMaxSlots][kAxes] = {};
|
||||
std::int16_t q_[kMaxObjects][kAxes] = {};
|
||||
};
|
||||
|
||||
// q_of(k, n) = min(32767, floor(32768 k / n + 0.5)), the reference's quantiser.
|
||||
int q_of(int k, int n);
|
||||
|
||||
Status parse_id11(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out);
|
||||
|
||||
struct BedAssignment {
|
||||
bool lfe_only = false;
|
||||
bool standard = false;
|
||||
std::uint32_t mask = 0;
|
||||
std::uint32_t mask = 0; // 10-bit standard or 17-bit non-standard mask
|
||||
// Declared channels in channel order; LFE is kept in place.
|
||||
std::vector<::joc::joc::BedChannel> channels;
|
||||
};
|
||||
|
||||
struct ParseTrace {
|
||||
@@ -97,6 +283,26 @@ struct ParseTrace {
|
||||
bool reserved_data_not_present = false;
|
||||
};
|
||||
|
||||
// Legacy single-frame view (frame_update() in the reference): the 16-slot
|
||||
// position update plus programme and trim. A payload carrying more than 16
|
||||
// objects or more than one position block is rejected, exactly like the
|
||||
// reference legacy entry point. The ADM export path keeps this view; the
|
||||
// speaker and binaural renderers use parse_id11_state().
|
||||
Status parse_id11(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out);
|
||||
|
||||
// Full frame_state() view: per-object per-block state, no 16-slot or
|
||||
// single-block restriction. The legacy fields are filled as well whenever the
|
||||
// frame fits them, so a caller can parse once and hand the same update to the
|
||||
// renderers and to the ADM export path where its shape allows it.
|
||||
Status parse_id11_state(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out);
|
||||
|
||||
// Parses only the trim element of a payload. ``out`` receives the first trim
|
||||
// element found; ``*present`` is false when the payload carries none. decode
|
||||
// paths that need the OAMD calibration but no object state can use this
|
||||
// without requiring an object element.
|
||||
Status parse_trim(const std::uint8_t* payload, std::size_t payload_size, OamdTrim* out,
|
||||
bool* present);
|
||||
|
||||
Status parse_id11_verbose(const std::uint8_t* payload, std::size_t payload_size, OamdUpdate* out,
|
||||
ParseTrace* trace);
|
||||
|
||||
@@ -105,4 +311,7 @@ Status parse_id11_verbose(const std::uint8_t* payload, std::size_t payload_size,
|
||||
Status parse_id11_bed_assignments(const std::uint8_t* payload, std::size_t payload_size,
|
||||
std::vector<BedAssignment>* out);
|
||||
|
||||
// 10-bit standard bed mask -> 17-bit non-standard bed mask (5.6.1.1.4).
|
||||
std::uint32_t standard_bed_mask(std::uint32_t bed_mask);
|
||||
|
||||
} // namespace joc::oamd
|
||||
@@ -8,28 +8,58 @@ namespace {
|
||||
|
||||
struct FrozenLayout {
|
||||
const char* name;
|
||||
const char* compact_name;
|
||||
std::uint32_t out_ch_config;
|
||||
std::uint32_t speaker_bitfield;
|
||||
std::uint32_t surround_channels;
|
||||
std::uint32_t height_channels;
|
||||
bool carries_trim;
|
||||
const char* const* channel_names;
|
||||
};
|
||||
|
||||
const char* const kChannels20[] = {"L", "R"};
|
||||
const char* const kChannels31[] = {"L", "R", "C", "LFE"};
|
||||
const char* const kChannels40[] = {"L", "R", "Lrs", "Rrs"};
|
||||
const char* const kChannels51[] = {"L", "R", "C", "LFE", "Ls", "Rs"};
|
||||
const char* const kChannels71[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs"};
|
||||
const char* const kChannels512[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Ltm", "Rtm"};
|
||||
const char* const kChannels514[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Ltf", "Rtf",
|
||||
"Ltr", "Rtr"};
|
||||
const char* const kChannels712[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
|
||||
"Ltm", "Rtm"};
|
||||
const char* const kChannels714[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
|
||||
"Ltf", "Rtf", "Ltr", "Rtr"};
|
||||
const char* const kChannels914[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
|
||||
"Lw", "Rw", "Ltf", "Rtf", "Ltr", "Rtr"};
|
||||
const char* const kChannels916[] = {"L", "R", "C", "LFE", "Ls", "Rs", "Lrs", "Rrs",
|
||||
"Lw", "Rw", "Ltf", "Rtf", "Ltm", "Rtm", "Ltr", "Rtr"};
|
||||
const char* const kChannels60[] = {"L", "R", "Ls", "Rs", "Lrs", "Rrs"};
|
||||
|
||||
constexpr FrozenLayout kLayouts[kLayoutCount] = {
|
||||
{"2.0", 0, 1},
|
||||
{"3.1", 3, 7},
|
||||
{"5.1", 7, 15},
|
||||
{"7.1", 11, 31},
|
||||
{"5.1.2", 13, 1039},
|
||||
{"5.1.4", 14, 2575},
|
||||
{"7.1.2", 15, 1055},
|
||||
{"7.1.4", 16, 2591},
|
||||
{"9.1.4", 19, 2719},
|
||||
{"9.1.6", 20, 3743},
|
||||
{"2.0", "20", 0, 1, 0, 0, true, kChannels20},
|
||||
{"3.1", "31", 3, 7, 0, 0, true, kChannels31},
|
||||
{"4.0", "40", 0xFF, 9, 2, 0, true, kChannels40},
|
||||
{"5.1", "51", 7, 15, 2, 0, true, kChannels51},
|
||||
{"7.1", "71", 11, 31, 4, 0, true, kChannels71},
|
||||
{"5.1.2", "512", 13, 1039, 2, 2, true, kChannels512},
|
||||
{"5.1.4", "514", 14, 2575, 2, 4, true, kChannels514},
|
||||
{"7.1.2", "712", 15, 1055, 4, 2, false, kChannels712},
|
||||
{"7.1.4", "714", 16, 2591, 4, 4, false, kChannels714},
|
||||
{"9.1.4", "914", 19, 2719, 4, 4, false, kChannels914},
|
||||
{"9.1.6", "916", 20, 3743, 4, 6, false, kChannels916},
|
||||
{"6.0", "60", 0xFF, 25, 4, 0, false, kChannels60},
|
||||
};
|
||||
|
||||
void fill(const FrozenLayout& source, LayoutInfo* out) {
|
||||
out->name = source.name;
|
||||
out->compact_name = source.compact_name;
|
||||
out->out_ch_config = source.out_ch_config;
|
||||
out->speaker_bitfield = source.speaker_bitfield;
|
||||
out->channel_count = ejoc_speaker_layout_channel_count(source.speaker_bitfield);
|
||||
out->channel_names = source.channel_names;
|
||||
out->surround_channels = source.surround_channels;
|
||||
out->height_channels = source.height_channels;
|
||||
out->carries_trim = source.carries_trim;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -8,19 +8,34 @@
|
||||
|
||||
namespace joc::speaker {
|
||||
|
||||
inline constexpr int kLayoutCount = 10;
|
||||
inline constexpr int kLayoutCount = 12;
|
||||
|
||||
struct LayoutInfo {
|
||||
const char* name = "";
|
||||
// The reference's compact layout key ("2.0" -> "20", ...), the key of the
|
||||
// automatic-attenuation and divide-by-default tables.
|
||||
const char* compact_name = "";
|
||||
std::uint32_t out_ch_config = 0;
|
||||
std::uint32_t speaker_bitfield = 0;
|
||||
std::uint32_t channel_count = 0;
|
||||
// Standard channel names in output order, ``channel_count`` entries.
|
||||
const char* const* channel_names = nullptr;
|
||||
// Ls/Rs/Lrs/Rrs and Ltf/Rtf/Ltr/Rtr/Ltm/Rtm, the labels the OAMD trim
|
||||
// configuration index counts.
|
||||
std::uint32_t surround_channels = 0;
|
||||
std::uint32_t height_channels = 0;
|
||||
// One of the seven layouts that carry OAMD trim and front-back balance
|
||||
// semantics; wider layouts leave the programme untrimmed.
|
||||
bool carries_trim = false;
|
||||
};
|
||||
|
||||
// All ten layouts in the reference's order (2.0, 3.1, 5.1, 7.1, 5.1.2, 5.1.4,
|
||||
// All twelve layouts in the reference's order (2.0, 3.1, 4.0, 5.1, 7.1, 5.1.2,
|
||||
// 5.1.4, 7.1.2, 7.1.4, 9.1.4, 9.1.6, 6.0).
|
||||
bool layout_at(int index, LayoutInfo* out);
|
||||
|
||||
// False when the name is unknown (case-sensitive, exactly as the reference CLI).
|
||||
// False when the name is unknown (case-sensitive, as the reference CLI). "4.0"
|
||||
// is the quad layout (L R Lrs Rrs); a stored value is normalized by the caller
|
||||
// before the name is looked up here.
|
||||
bool layout_by_name(const char* name, LayoutInfo* out);
|
||||
|
||||
bool layout_by_bitfield(std::uint32_t bitfield, LayoutInfo* out);
|
||||
|
||||
+112
-16
@@ -39,7 +39,7 @@ struct LayoutGeometry {
|
||||
std::array<RegionGeometry, 7> regions{};
|
||||
};
|
||||
|
||||
inline constexpr std::array<LayoutGeometry, 10> kLayouts{{
|
||||
inline constexpr std::array<LayoutGeometry, 12> kLayouts{{
|
||||
LayoutGeometry{
|
||||
0x1u, 0, 2,
|
||||
{{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
@@ -136,31 +136,79 @@ inline constexpr std::array<LayoutGeometry, 10> kLayouts{{
|
||||
}
|
||||
}}
|
||||
},
|
||||
LayoutGeometry{
|
||||
0x9u, 0xFFu, 4,
|
||||
{{0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
{{
|
||||
RegionGeometry{
|
||||
4, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 32767, 0}, 2}, SpeakerPoint{{32767, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
4, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 32767, 0}, 2}, SpeakerPoint{{32767, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
4, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 32767, 0}, 2}, SpeakerPoint{{32767, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
4, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 32767, 0}, 2}, SpeakerPoint{{32767, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
2, 1, 1, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
2, 1, 1, 0,
|
||||
{{SpeakerPoint{{0, 32767, 0}, 2}, SpeakerPoint{{32767, 32767, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
2, 1, 1, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
}
|
||||
}}
|
||||
},
|
||||
LayoutGeometry{
|
||||
0xFu, 7, 6,
|
||||
{{0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
{{
|
||||
RegionGeometry{
|
||||
5, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
5, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
5, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
3, 2, 2, 0,
|
||||
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{1, {0, 0, 0}}, AxisGroup{2, {1, 2, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
@@ -172,7 +220,7 @@ inline constexpr std::array<LayoutGeometry, 10> kLayouts{{
|
||||
},
|
||||
RegionGeometry{
|
||||
2, 1, 1, 0,
|
||||
{{SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
@@ -238,25 +286,25 @@ inline constexpr std::array<LayoutGeometry, 10> kLayouts{{
|
||||
{{
|
||||
RegionGeometry{
|
||||
7, 3, 2, 1,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
7, 3, 2, 1,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
7, 3, 2, 1,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
5, 3, 2, 1,
|
||||
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{1, {0, 0, 0}}, AxisGroup{2, {1, 2, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
@@ -268,7 +316,7 @@ inline constexpr std::array<LayoutGeometry, 10> kLayouts{{
|
||||
},
|
||||
RegionGeometry{
|
||||
4, 3, 1, 1,
|
||||
{{SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 16384, 32767}, 6}, SpeakerPoint{{24840, 16384, 32767}, 7}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
@@ -286,25 +334,25 @@ inline constexpr std::array<LayoutGeometry, 10> kLayouts{{
|
||||
{{
|
||||
RegionGeometry{
|
||||
9, 3, 2, 2,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{2, {7, 8, 0}}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
9, 3, 2, 2,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{2, {7, 8, 0}}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
9, 3, 2, 2,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{3, {0, 2, 1}}, AxisGroup{2, {3, 4, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{2, {7, 8, 0}}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
7, 3, 2, 2,
|
||||
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{16384, 0, 0}, 2}, SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{1, {0, 0, 0}}, AxisGroup{2, {1, 2, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {3, 4, 0}}, AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
@@ -316,7 +364,7 @@ inline constexpr std::array<LayoutGeometry, 10> kLayouts{{
|
||||
},
|
||||
RegionGeometry{
|
||||
6, 3, 1, 2,
|
||||
{{SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{SpeakerPoint{{0, 16384, 0}, 4}, SpeakerPoint{{32767, 16384, 0}, 5}, SpeakerPoint{{7928, 7928, 32767}, 6}, SpeakerPoint{{24840, 7928, 32767}, 7}, SpeakerPoint{{7928, 24840, 32767}, 8}, SpeakerPoint{{24840, 24840, 32767}, 9}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{2, {2, 3, 0}}, AxisGroup{2, {4, 5, 0}}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
@@ -519,7 +567,55 @@ inline constexpr std::array<LayoutGeometry, 10> kLayouts{{
|
||||
{{AxisGroup{2, {5, 6, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
}
|
||||
}}
|
||||
},
|
||||
LayoutGeometry{
|
||||
0x19u, 0xFFu, 6,
|
||||
{{0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
{{
|
||||
RegionGeometry{
|
||||
6, 2, 3, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 16384, 0}, 2}, SpeakerPoint{{32767, 16384, 0}, 3}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{2, {4, 5, 0}}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
4, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 16384, 0}, 2}, SpeakerPoint{{32767, 16384, 0}, 3}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
4, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
2, 2, 1, 0,
|
||||
{{SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
2, 1, 1, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
4, 2, 2, 0,
|
||||
{{SpeakerPoint{{0, 16384, 0}, 2}, SpeakerPoint{{32767, 16384, 0}, 3}, SpeakerPoint{{0, 32767, 0}, 4}, SpeakerPoint{{32767, 32767, 0}, 5}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{2, {2, 3, 0}}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
},
|
||||
RegionGeometry{
|
||||
2, 1, 1, 0,
|
||||
{{SpeakerPoint{{0, 0, 0}, 0}, SpeakerPoint{{32767, 0, 0}, 1}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}, SpeakerPoint{}}},
|
||||
{{AxisGroup{2, {0, 1, 0}}, AxisGroup{}, AxisGroup{}, AxisGroup{}}},
|
||||
{{AxisGroup{}, AxisGroup{}, AxisGroup{}, AxisGroup{}}}
|
||||
}
|
||||
}}
|
||||
},
|
||||
}};
|
||||
|
||||
inline constexpr const LayoutGeometry* find_layout(const std::uint32_t speaker_bitfield) noexcept {
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
// Port of the metadata application path of src/speaker_renderer.py HEAD.
|
||||
//
|
||||
// The metadata path consumes the full per-object per-block OAMD frame state and
|
||||
// schedules block targets frame by frame: object gain/inactive, zone/elevation,
|
||||
// snap, divergence, size kernel fusion, priority size budget, ISF basis rows and
|
||||
// bed channel distribution, with the same float64 gain ramps and block alignment
|
||||
// as the reference renderer.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "eac3joc_core.h"
|
||||
#include "foundation/status.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
#include "speaker/speaker_layout_lookup.h"
|
||||
#include "speaker/speaker_trim.h"
|
||||
|
||||
namespace joc::speaker {
|
||||
|
||||
// One metadata target matrix: object_count x layout channel_count in the
|
||||
// renderer's internal channel order, before the ramp/timing stage.
|
||||
struct MetadataTargets {
|
||||
std::uint32_t object_count = 0;
|
||||
std::uint32_t channel_count = 0;
|
||||
std::vector<double> values; // object major
|
||||
|
||||
double at(std::uint32_t object, std::uint32_t channel) const {
|
||||
return values[static_cast<std::size_t>(object) * channel_count + channel];
|
||||
}
|
||||
};
|
||||
|
||||
// Computes the metadata target matrix of one block of a parsed frame without
|
||||
// touching renderer state: the reference's _init_meta validation plus
|
||||
// _block_targets. ``trim`` carries the current programme trim (bypass flags),
|
||||
// ``controls`` the derived per-layout controls, ``size_budget`` the priority
|
||||
// budget (0 means unlimited, the production value).
|
||||
Status metadata_block_targets(const LayoutInfo& layout, const oamd::OamdUpdate& update,
|
||||
std::uint32_t block_index,
|
||||
const ejoc_speaker_controls& controls,
|
||||
const oamd::OamdTrim* trim, std::uint32_t size_budget,
|
||||
MetadataTargets* out);
|
||||
|
||||
// Stateful metadata-path renderer. It owns the object target ramps and the
|
||||
// cross-block pending schedule; the legacy point-renderer state stays in the
|
||||
// C ABI renderer, which is used for the blocks of a frame that precede the first
|
||||
// metadata targets (the reference renders those with its legacy block path).
|
||||
class MetaRenderer {
|
||||
public:
|
||||
MetaRenderer();
|
||||
~MetaRenderer();
|
||||
MetaRenderer(MetaRenderer&&) noexcept;
|
||||
MetaRenderer& operator=(MetaRenderer&&) noexcept;
|
||||
MetaRenderer(const MetaRenderer&) = delete;
|
||||
MetaRenderer& operator=(const MetaRenderer&) = delete;
|
||||
|
||||
// Binds the target layout. Must be called once before process_frame().
|
||||
Status configure(const LayoutInfo& layout);
|
||||
|
||||
// Drops the ramp, schedule and metadata state (the layout stays bound).
|
||||
Status reset();
|
||||
|
||||
bool configured() const;
|
||||
// True once a metadata frame has been accepted (the reference's _meta_mode).
|
||||
bool engaged() const;
|
||||
|
||||
const char* last_error() const;
|
||||
|
||||
Status process_frame(ejoc_speaker_renderer_handle legacy,
|
||||
const float* objects16_interleaved, std::uint32_t sample_count,
|
||||
const oamd::OamdUpdate* update, std::uint32_t metadata_offset,
|
||||
const ejoc_speaker_controls& controls, const oamd::OamdTrim* trim,
|
||||
std::uint32_t raw_trim_mode, std::uint32_t size_budget,
|
||||
double* output_interleaved);
|
||||
|
||||
// Computes the target matrix of one block of ``update`` into ``out`` using a
|
||||
// scratch context; unlike metadata_block_targets() this validates through
|
||||
// the renderer's own state-independent path.
|
||||
Status block_targets(const oamd::OamdUpdate& update, std::uint32_t block_index,
|
||||
const ejoc_speaker_controls& controls, const oamd::OamdTrim* trim,
|
||||
std::uint32_t size_budget, MetadataTargets* out) const;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace joc::speaker
|
||||
+1369
-15
File diff suppressed because it is too large.
Load diff
@@ -26,6 +26,61 @@ Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
|
||||
static_cast<std::size_t>(JOC_FRAME_SAMPLES) * context->layout.channel_count, 0.0);
|
||||
|
||||
context->last_had_payload = update != nullptr;
|
||||
if (!context->controls_ready) {
|
||||
const Status status =
|
||||
parameters_from_oamd(nullptr, context->layout, &context->controls);
|
||||
if (!status.ok()) {
|
||||
if (error != nullptr) {
|
||||
*error = status.message();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
context->controls_ready = true;
|
||||
}
|
||||
if (update != nullptr && update->has_trim) {
|
||||
const Status status =
|
||||
parameters_from_oamd(&update->trim, context->layout, &context->controls);
|
||||
if (!status.ok()) {
|
||||
if (error != nullptr) {
|
||||
*error = status.message();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
context->trim = update->trim;
|
||||
context->has_trim = true;
|
||||
context->raw_trim_mode = update->trim.global_trim_mode;
|
||||
}
|
||||
|
||||
const bool metadata_frame =
|
||||
update != nullptr && update->has_frame_state &&
|
||||
update->frame_state.object_count != 0u;
|
||||
if (metadata_frame || context->meta_engaged) {
|
||||
if (!context->meta_configured) {
|
||||
const Status configured = context->meta.configure(context->layout);
|
||||
if (!configured.ok()) {
|
||||
if (error != nullptr) {
|
||||
*error = configured.message();
|
||||
}
|
||||
return configured;
|
||||
}
|
||||
context->meta_configured = true;
|
||||
}
|
||||
const oamd::OamdTrim* trim = context->has_trim ? &context->trim : nullptr;
|
||||
const Status processed = context->meta.process_frame(
|
||||
context->handle, context->interleaved.data(), JOC_FRAME_SAMPLES,
|
||||
metadata_frame ? update : nullptr, context->metadata_offset,
|
||||
context->controls, trim, context->raw_trim_mode, 0u,
|
||||
context->output.data());
|
||||
if (!processed.ok()) {
|
||||
if (error != nullptr) {
|
||||
*error = processed.message();
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
context->meta_engaged = context->meta.engaged();
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
std::uint32_t ramp = 0;
|
||||
if (update != nullptr) {
|
||||
context->state.apply(*update);
|
||||
@@ -37,6 +92,14 @@ Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
|
||||
|
||||
std::uint16_t positions[oamd::kObjects][3] = {};
|
||||
context->state.object_positions_q15(positions);
|
||||
for (int object = 0; object < oamd::kObjects; ++object) {
|
||||
if (!context->bed_override[object]) {
|
||||
continue;
|
||||
}
|
||||
for (int axis = 0; axis < oamd::kAxes; ++axis) {
|
||||
positions[object][axis] = context->bed_positions[object][axis];
|
||||
}
|
||||
}
|
||||
// A frame without OAMD must not touch the gains at all (no event), otherwise a
|
||||
// pending ramp would snap - matching the reference exactly.
|
||||
const std::uint32_t event_count = context->last_had_payload ? 1u : 0u;
|
||||
@@ -45,7 +108,7 @@ Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
|
||||
context->handle, context->interleaved.data(), JOC_FRAME_SAMPLES, event_count,
|
||||
event_count != 0u ? &offset : nullptr, event_count != 0u ? &ramp : nullptr,
|
||||
event_count != 0u ? &positions[0][0] : nullptr, nullptr, nullptr, nullptr,
|
||||
context->output.data());
|
||||
&context->controls, context->output.data());
|
||||
if (result != 0) {
|
||||
const char* message = ejoc_speaker_renderer_last_error(context->handle);
|
||||
const std::string text =
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "foundation/status.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
#include "speaker/speaker_layout_lookup.h"
|
||||
#include "speaker/speaker_meta.h"
|
||||
#include "speaker/speaker_trim.h"
|
||||
|
||||
namespace joc::speaker {
|
||||
|
||||
@@ -23,6 +25,24 @@ struct SpeakerStep {
|
||||
std::uint32_t last_ramp_duration = 0;
|
||||
std::uint32_t last_object_count = 0;
|
||||
bool last_had_payload = false;
|
||||
// OAMD speaker controls. A payload carrying the trim element replaces
|
||||
// them; a payload without it keeps the previous set.
|
||||
ejoc_speaker_controls controls{};
|
||||
bool controls_ready = false;
|
||||
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。这里存
|
||||
// 对象槽 → Q15 方位;bed_override 为 false 的槽仍按 OAMD 坐标声像。
|
||||
std::uint16_t bed_positions[oamd::kObjects][oamd::kAxes] = {};
|
||||
bool bed_override[oamd::kObjects] = {};
|
||||
// Metadata path: a frame that carries the full per-object block state
|
||||
// switches the speaker output to the metadata renderer. The programme trim
|
||||
// element and its raw global mode stay here because the metadata path needs
|
||||
// the per-object bypass flags and the ISF compensation mode.
|
||||
MetaRenderer meta;
|
||||
bool meta_configured = false;
|
||||
bool meta_engaged = false;
|
||||
oamd::OamdTrim trim{};
|
||||
bool has_trim = false;
|
||||
std::uint32_t raw_trim_mode = 0;
|
||||
};
|
||||
|
||||
Status step(SpeakerStep* context, const std::vector<float>& objects16_planar,
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
#include "speaker/speaker_trim.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
#include "foundation/py_num.h"
|
||||
|
||||
namespace joc::speaker {
|
||||
|
||||
namespace {
|
||||
|
||||
int height_class(std::uint32_t count) {
|
||||
if (count == 0u) {
|
||||
return 0;
|
||||
}
|
||||
if (count == 2u) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
int floor_class(std::uint32_t count) {
|
||||
if (count == 0u) {
|
||||
return 0;
|
||||
}
|
||||
if (count == 2u || count == 3u) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int trim_config_index(const LayoutInfo& layout) {
|
||||
return floor_class(layout.surround_channels) + 3 * height_class(layout.height_channels);
|
||||
}
|
||||
|
||||
Status parameters_from_oamd(const oamd::OamdTrim* trim, const LayoutInfo& layout,
|
||||
ejoc_speaker_controls* out) {
|
||||
if (out == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"null speaker controls");
|
||||
}
|
||||
ejoc_speaker_controls controls{};
|
||||
controls.struct_size = sizeof(controls);
|
||||
controls.struct_version = EJOC_SPEAKER_CONTROLS_VERSION;
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_AUTOMATIC;
|
||||
if (trim != nullptr) {
|
||||
controls.warp_mode = trim->warp_mode;
|
||||
for (int slot = 0; slot < oamd::kMaxSlots; ++slot) {
|
||||
controls.trim_bypass[slot] = trim->disable_per_object[slot] ? 1u : 0u;
|
||||
}
|
||||
}
|
||||
if (controls.warp_mode > 3u) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"speaker: invalid warp mode " +
|
||||
std::to_string(controls.warp_mode));
|
||||
}
|
||||
if (!layout.carries_trim) {
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_DISABLED;
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
const std::uint32_t mode = trim != nullptr ? trim->global_trim_mode : 0u;
|
||||
if (mode == 1u) {
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_DISABLED;
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
if (mode > 2u) {
|
||||
return Status::fail(JOC_ERR_NOT_SUPPORTED, stage::kRender,
|
||||
"speaker: trim_mode_not_implemented: OAMD global trim mode " +
|
||||
std::to_string(mode) + " is reserved");
|
||||
}
|
||||
if (mode == 2u) {
|
||||
const oamd::TrimConfig& record = trim->configs[trim_config_index(layout)];
|
||||
if (record.kind == oamd::TrimConfigKind::kDefault ||
|
||||
record.kind == oamd::TrimConfigKind::kAbsent) {
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
if (record.kind == oamd::TrimConfigKind::kDisabled) {
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_DISABLED;
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
if (!std::isfinite(record.centre) || !std::isfinite(record.surround) ||
|
||||
!std::isfinite(record.height)) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"speaker: trim levels must be finite");
|
||||
}
|
||||
for (const double balance : {record.balance_listener, record.balance_overhead}) {
|
||||
if (!std::isfinite(balance) || balance < -1.0 || balance > 1.0) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"speaker: balance must be finite and in [-1,1]");
|
||||
}
|
||||
}
|
||||
// Surround and height are attenuation-only; the centre level keeps its
|
||||
// sign.
|
||||
controls.trim_mode = EJOC_SPEAKER_TRIM_EXPLICIT;
|
||||
controls.centre_db = record.centre;
|
||||
controls.surround_db = std::min(record.surround, 0.0);
|
||||
controls.height_db = std::min(record.height, 0.0);
|
||||
controls.listener_balance = record.balance_listener;
|
||||
controls.overhead_balance = record.balance_overhead;
|
||||
}
|
||||
*out = controls;
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
double front_back_balance(double position, double balance) {
|
||||
const long long steps =
|
||||
pynum::py_round(std::fabs(balance) * static_cast<double>(kBalanceSteps));
|
||||
if (steps == 0) {
|
||||
return position;
|
||||
}
|
||||
const double slope = static_cast<double>(steps) / 18.0;
|
||||
if (position <= kBalanceWall || position >= 1.0 - kBalanceWall) {
|
||||
return position;
|
||||
}
|
||||
if (position < 0.5) {
|
||||
return balance > 0.0 ? (1.0 + slope) * position - kBalanceWall * slope
|
||||
: (1.0 - slope) * position + kBalanceWall * slope;
|
||||
}
|
||||
return balance > 0.0
|
||||
? (1.0 - slope) * (position - 0.5) + 0.5 + 0.45 * slope
|
||||
: (1.0 + slope) * (position - 0.5) + 0.5 - 0.45 * slope;
|
||||
}
|
||||
|
||||
double apply_balance(double position, double height, double listener, double overhead) {
|
||||
if (listener == 0.0 && overhead == 0.0) {
|
||||
return position;
|
||||
}
|
||||
const double low = front_back_balance(position, listener);
|
||||
const double high = front_back_balance(position, overhead);
|
||||
return (1.0 - height) * low + height * high;
|
||||
}
|
||||
|
||||
double explicit_position_gain(const ejoc_speaker_controls& controls, double x, double y,
|
||||
double z) {
|
||||
const double surround = std::min(std::max(2.0 * y, 0.0), 1.0) * (1.0 - z);
|
||||
const double centre = 1.0 - std::min(
|
||||
std::max(10.0 * std::max(std::max(std::fabs(z) - kBalanceWall,
|
||||
y - kBalanceWall),
|
||||
std::fabs(x - 0.5) - kBalanceWall),
|
||||
0.0),
|
||||
1.0);
|
||||
const double db = surround * std::min(controls.surround_db, 0.0) +
|
||||
z * std::min(controls.height_db, 0.0) + centre * controls.centre_db;
|
||||
return std::pow(10.0, db / 20.0);
|
||||
}
|
||||
|
||||
} // namespace joc::speaker
|
||||
@@ -0,0 +1,50 @@
|
||||
// Port of src/trim_balance.py.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "eac3joc_core.h"
|
||||
#include "foundation/status.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
#include "speaker/speaker_layout_lookup.h"
|
||||
|
||||
namespace joc::speaker {
|
||||
|
||||
// Front-back balance keeps a 5 percent wall band at each end unmapped.
|
||||
inline constexpr double kBalanceWall = 0.05;
|
||||
// bal3d_y is coded on a 1/16 grid, so a balance is quantised to that grid.
|
||||
inline constexpr int kBalanceSteps = 16;
|
||||
|
||||
// Trim configuration a layout selects, from its surround and height counts:
|
||||
//
|
||||
// cfg = kappa_f(surrounds) + 3 * kappa_h(heights)
|
||||
// kappa_f: 0 -> 0, 2..3 -> 1, otherwise 2
|
||||
// kappa_h: 0 -> 0, 2 -> 1, otherwise 2
|
||||
int trim_config_index(const LayoutInfo& layout);
|
||||
|
||||
// Converts OAMD calibration to the speaker controls of one layout. Warp 0
|
||||
// renders directly, 1 scales the floor Y, and 2/3 render through an expanded
|
||||
// surround layout before folding; the reserved global trim mode is reported as
|
||||
// unsupported. A null trim selects warp 0 and automatic trim, or disabled trim
|
||||
// for a layout that carries no trim semantics.
|
||||
Status parameters_from_oamd(const oamd::OamdTrim* trim, const LayoutInfo& layout,
|
||||
ejoc_speaker_controls* out);
|
||||
|
||||
// Reparameterises a front-back coordinate in [0, 1] by ``balance``: 0 is the
|
||||
// front wall and 1 the back wall, and the two wall bands pass through
|
||||
// unchanged.
|
||||
double front_back_balance(double position, double balance);
|
||||
|
||||
// Blends the listener-plane and overhead balance by height: 0 at the listener
|
||||
// plane, 1 at the top layer.
|
||||
double apply_balance(double position, double height, double listener, double overhead);
|
||||
|
||||
// Position-dependent object trim at the balanced original Y. Surround fades
|
||||
// in with Y and out towards Z=1, height fades in with Z, and the centre trim is
|
||||
// local to the front-centre region. The scalar multiplies the object's whole
|
||||
// panning vector before accumulation.
|
||||
double explicit_position_gain(const ejoc_speaker_controls& controls, double x, double y,
|
||||
double z);
|
||||
|
||||
} // namespace joc::speaker
|
||||
+136
-29
@@ -6,9 +6,10 @@
|
||||
|
||||
#include "adm/adm_metadata.h"
|
||||
#include "foundation/status.h"
|
||||
#include "virtual_speaker/virtual_speaker.h"
|
||||
#include "hrtf/jochrtf.h"
|
||||
#include "hrtf/rosella_model.h"
|
||||
#include "hrtf/sofa_cache.h"
|
||||
#include "joc_bitstream/bed_layout_map.h"
|
||||
#include "joc_bitstream/joc_parser.h"
|
||||
#include "joc_core/objects16.h"
|
||||
|
||||
@@ -45,6 +46,7 @@ void Stream::reset_state() {
|
||||
bed_pending_.clear();
|
||||
bed_read_offset_ = 0;
|
||||
objects16_.clear();
|
||||
pcm_input_.reset();
|
||||
objects_pending_.clear();
|
||||
objects_read_offset_ = 0;
|
||||
output_.clear();
|
||||
@@ -59,6 +61,8 @@ void Stream::reset_state() {
|
||||
speaker_.state.reset();
|
||||
speaker_.output.clear();
|
||||
speaker_.last_had_payload = false;
|
||||
// Back to the initial controls; the next trim element replaces them.
|
||||
speaker_.controls_ready = false;
|
||||
}
|
||||
if (binaural_ready_) {
|
||||
binaural_.reset();
|
||||
@@ -75,7 +79,7 @@ Status Stream::create(const Config& config) {
|
||||
return Status::fail(JOC_ERR_STATE, stage::kRender, "stream already created");
|
||||
}
|
||||
config_ = config;
|
||||
if (config_.input > JOC_STREAM_IN_PCM_OBJECTS16 ||
|
||||
if (config_.input > JOC_STREAM_IN_PCM_LAYOUT ||
|
||||
config_.output > JOC_STREAM_OUT_BINAURAL) {
|
||||
return Status::fail(JOC_ERR_INVALID_CONFIG, stage::kRender, "unknown stream kind");
|
||||
}
|
||||
@@ -85,6 +89,20 @@ Status Stream::create(const Config& config) {
|
||||
"objects16 input with objects16 output would do nothing");
|
||||
}
|
||||
gain_ = static_cast<float>(std::pow(10.0, config_.gain_db / 20.0));
|
||||
if (config_.input == JOC_STREAM_IN_PCM_LAYOUT && !config_.pcm_layout.empty() &&
|
||||
config_.pcm_layout != "auto") {
|
||||
const virtual_speaker::Layout* layout =
|
||||
virtual_speaker::find_layout(config_.pcm_layout);
|
||||
if (layout == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_CONFIG, stage::kRender,
|
||||
"unknown PCM layout: " + config_.pcm_layout);
|
||||
}
|
||||
const Status configured =
|
||||
pcm_input_.configure(config_.pcm_layout, layout->channels, config_.gain_db);
|
||||
if (!configured.ok()) {
|
||||
return configured;
|
||||
}
|
||||
}
|
||||
|
||||
if (config_.input == JOC_STREAM_IN_EAC3) {
|
||||
rebuilder_ = ejoc_renderer_create();
|
||||
@@ -126,6 +144,9 @@ Status Stream::create(const Config& config) {
|
||||
}
|
||||
render_options.object_delay_samples = config_.object_delay_samples;
|
||||
render_options.tail_seconds = config_.tail_seconds;
|
||||
render_options.bank = config_.rosella_filterbank == JOC_ROSELLA_FILTERBANK_CAPTURED
|
||||
? hrtf::RosellaBankKind::Captured
|
||||
: hrtf::RosellaBankKind::Public;
|
||||
if (status.ok()) {
|
||||
status = rosella_.open(model, render_options);
|
||||
}
|
||||
@@ -139,26 +160,7 @@ Status Stream::create(const Config& config) {
|
||||
hrtf::Field field;
|
||||
hrtf::Kernels kernels;
|
||||
Status status = Status::success();
|
||||
if (!config_.hrtf_sofa_path.empty()) {
|
||||
// The .jochrtf is an internal cache: the SOFA is the user-facing input.
|
||||
hrtf::SofaFieldRequest request;
|
||||
request.sofa_path = config_.hrtf_sofa_path;
|
||||
request.options.shell_radius_m = config_.hrtf_radius_m;
|
||||
request.cache_dir = config_.hrtf_cache_dir;
|
||||
switch (config_.hrtf_cache_policy) {
|
||||
case JOC_HRTF_CACHE_NONE: request.policy = hrtf::CachePolicy::None; break;
|
||||
case JOC_HRTF_CACHE_DISK: request.policy = hrtf::CachePolicy::Disk; break;
|
||||
default: request.policy = hrtf::CachePolicy::Memory; break;
|
||||
}
|
||||
std::string cache_path;
|
||||
status = hrtf::load_or_compile_sofa_field(request, &field, &cache_path);
|
||||
if (!status.ok()) {
|
||||
return Status::fail(status.code(), stage::kRender,
|
||||
"binaural setup failed: " + status.message());
|
||||
}
|
||||
} else {
|
||||
status = hrtf::load_jochrtf(config_.hrtf_path, &field);
|
||||
}
|
||||
if (status.ok()) {
|
||||
status = config_.kernels_path.empty()
|
||||
? (kernels = hrtf::builtin_kernels(), Status::success())
|
||||
@@ -171,7 +173,10 @@ Status Stream::create(const Config& config) {
|
||||
profile = binaural::Profile::Far;
|
||||
}
|
||||
if (status.ok()) {
|
||||
status = binaural_.open(field, kernels, profile);
|
||||
binaural::RoomConstants room;
|
||||
room.enable_early_reflections = config_.jochrtf_room ? 1u : 0u;
|
||||
room.enable_late_room = room.enable_early_reflections;
|
||||
status = binaural_.open(field, kernels, profile, room);
|
||||
}
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
@@ -186,12 +191,57 @@ Status Stream::create(const Config& config) {
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
void Stream::apply_bed_positions(const FrameMetadata& entry) {
|
||||
if (bed_positions_ready_ || entry.bed_assignments.empty()) {
|
||||
return;
|
||||
}
|
||||
const bool bed_only = entry.has_update && entry.update.content_bed &&
|
||||
!entry.update.content_isf && !entry.update.content_dynamic;
|
||||
const ::joc::joc::BedLayout bed = ::joc::joc::resolve_bed_layout(entry.bed_assignments, bed_only);
|
||||
if (!bed.present) {
|
||||
return;
|
||||
}
|
||||
bed_positions_ready_ = true;
|
||||
if (!bed.bed_only) {
|
||||
return;
|
||||
}
|
||||
for (std::size_t slot = 0; slot < bed.channels.size() &&
|
||||
slot < static_cast<std::size_t>(oamd::kObjects);
|
||||
++slot) {
|
||||
const ::joc::joc::BedChannel channel = bed.channels[slot];
|
||||
double xyz[3] = {0.0, 0.0, 0.0};
|
||||
if (::joc::joc::bed_channel_adm_position(channel, xyz)) {
|
||||
if (binaural_ready_) {
|
||||
binaural_.set_fixed_position(static_cast<int>(slot) + 1, xyz);
|
||||
}
|
||||
if (rosella_ready_) {
|
||||
rosella_.set_fixed_position(static_cast<int>(slot) + 1, xyz);
|
||||
}
|
||||
}
|
||||
if (!speaker_enabled_) {
|
||||
continue;
|
||||
}
|
||||
std::uint16_t q15[3] = {0, 0, 0};
|
||||
if (!::joc::joc::layout_bed_anchor(speaker_.layout.out_ch_config, channel, q15) &&
|
||||
!::joc::joc::bed_channel_q15(channel, q15)) {
|
||||
continue;
|
||||
}
|
||||
speaker_.bed_override[slot] = true;
|
||||
for (int axis = 0; axis < oamd::kAxes; ++axis) {
|
||||
speaker_.bed_positions[slot][axis] = q15[axis];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Status Stream::flush_pending_frame() {
|
||||
if (pending_frame_.streams.empty()) {
|
||||
return Status::success();
|
||||
}
|
||||
FrameMetadata entry = pending_frame_;
|
||||
pending_frame_ = FrameMetadata();
|
||||
if (entry.has_joc) {
|
||||
apply_bed_positions(entry);
|
||||
}
|
||||
if (entry.has_joc) {
|
||||
std::string error;
|
||||
joc::CrossLayerNotes notes;
|
||||
@@ -212,6 +262,9 @@ Status Stream::flush_pending_frame() {
|
||||
if (entry.params.objects_clamped != 0u) {
|
||||
++info_.objects_clamped_frames;
|
||||
}
|
||||
if (entry.params.status == JOC_FRAME_STATUS_TRUNCATED) {
|
||||
++info_.truncated_joc_frames;
|
||||
}
|
||||
} else {
|
||||
// No JOC metadata for this audio frame: the object channels stay silent
|
||||
// while the kernel state still advances for the frame.
|
||||
@@ -309,7 +362,14 @@ Status Stream::push_eac3(const std::uint8_t* data, std::size_t size, std::size_t
|
||||
if (!extracted.ok()) {
|
||||
return extracted;
|
||||
}
|
||||
const Status oamd = oamd::parse_id11(bytes.data(), bytes.size(), &pending_frame_.update);
|
||||
// Speaker and binaural consume the full per-object block state; the
|
||||
// other stream paths keep the reference's legacy single-block view.
|
||||
const bool full_metadata_state = speaker_enabled_ || binaural_enabled_;
|
||||
const Status oamd =
|
||||
full_metadata_state ? oamd::parse_id11_state(bytes.data(), bytes.size(),
|
||||
&pending_frame_.update)
|
||||
: oamd::parse_id11(bytes.data(), bytes.size(),
|
||||
&pending_frame_.update);
|
||||
if (!oamd.ok()) {
|
||||
return oamd;
|
||||
}
|
||||
@@ -409,6 +469,47 @@ Status Stream::push_objects16(const float* planar16, std::size_t samples, std::s
|
||||
return process_objects16_frames(false);
|
||||
}
|
||||
|
||||
Status Stream::push_pcm_layout(const float* interleaved, std::size_t samples,
|
||||
std::uint32_t channels, std::size_t* consumed) {
|
||||
if (consumed != nullptr) {
|
||||
*consumed = 0;
|
||||
}
|
||||
if (interleaved == nullptr || samples == 0u) {
|
||||
return Status::success();
|
||||
}
|
||||
if (pcm_input_.layout() == nullptr) {
|
||||
const Status configured = pcm_input_.configure(config_.pcm_layout,
|
||||
static_cast<int>(channels),
|
||||
config_.gain_db);
|
||||
if (!configured.ok()) {
|
||||
return configured;
|
||||
}
|
||||
} else if (pcm_input_.channels() != static_cast<int>(channels)) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"PCM channel count changed mid-stream");
|
||||
}
|
||||
Status status = pcm_input_.append(interleaved, samples);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
std::size_t processed = 0;
|
||||
while (pcm_input_.frame_ready()) {
|
||||
status = pcm_input_.take_frame(&objects_frame_);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
status = push_objects16(objects_frame_.data(), kFrameSamples, nullptr);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
processed += kFrameSamples;
|
||||
}
|
||||
if (consumed != nullptr) {
|
||||
*consumed = processed;
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status Stream::process_objects16_frames(bool drain_all) {
|
||||
constexpr std::size_t kFrameValues =
|
||||
static_cast<std::size_t>(JOC_OUTPUT_CHANNELS) * kFrameSamples;
|
||||
@@ -502,8 +603,10 @@ Status Stream::process_ready_frames(bool drain_all) {
|
||||
compact_bed_pending();
|
||||
|
||||
std::string error;
|
||||
const Status rebuilt = joc::rebuild_objects16(rebuilder_, entry.params, bed5_.data(),
|
||||
lfe_.data(), gain_, &objects16_, &error);
|
||||
const Status rebuilt = joc::rebuild_objects16(
|
||||
rebuilder_, entry.params, bed5_.data(), lfe_.data(),
|
||||
static_cast<std::uint32_t>(core_channels), entry.has_joc, gain_, &objects16_,
|
||||
&error);
|
||||
if (!rebuilt.ok()) {
|
||||
return Status::fail(rebuilt.code(), stage::kDsp, error);
|
||||
}
|
||||
@@ -544,9 +647,11 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
|
||||
if (speaker_enabled_) {
|
||||
std::string error;
|
||||
const Status stepped =
|
||||
speaker::step(&speaker_, objects16, pending_metadata_.has_update
|
||||
speaker::step(&speaker_, objects16,
|
||||
pending_metadata_.has_update
|
||||
? &pending_metadata_.update
|
||||
: nullptr,
|
||||
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update()
|
||||
: nullptr),
|
||||
&error);
|
||||
if (!stepped.ok()) {
|
||||
return Status::fail(stepped.code(), stage::kRender, error);
|
||||
@@ -565,7 +670,8 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
|
||||
|
||||
const Status submitted =
|
||||
binaural_.submit_frame(objects16.data(),
|
||||
pending_metadata_.has_update ? &pending_metadata_.update : nullptr,
|
||||
pending_metadata_.has_update ? &pending_metadata_.update
|
||||
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update() : nullptr),
|
||||
static_cast<std::int64_t>(info_.frames_out),
|
||||
pending_metadata_.outer_offset,
|
||||
static_cast<std::int64_t>(config_.object_delay_samples));
|
||||
@@ -592,7 +698,8 @@ Status Stream::render_objects16(const std::vector<float>& objects16) {
|
||||
Status Stream::render_rosella_objects16(const std::vector<float>& objects16) {
|
||||
const Status submitted =
|
||||
rosella_.submit_frame(objects16.data(),
|
||||
pending_metadata_.has_update ? &pending_metadata_.update : nullptr,
|
||||
pending_metadata_.has_update ? &pending_metadata_.update
|
||||
: (pcm_input_.layout() != nullptr ? &pcm_input_.fixed_update() : nullptr),
|
||||
static_cast<std::int64_t>(info_.frames_out),
|
||||
pending_metadata_.outer_offset,
|
||||
static_cast<std::int64_t>(config_.object_delay_samples));
|
||||
|
||||
+21
-8
@@ -6,7 +6,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "binaural/binaural_runtime.h"
|
||||
#include "binaural/jochrtf_runtime.h"
|
||||
#include "eac3_transport/eac3_reader.h"
|
||||
#include "foundation/status.h"
|
||||
#include "hrtf/rosella_renderer.h"
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "joc_stream.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
#include "speaker/speaker_step.h"
|
||||
#include "virtual_speaker/virtual_speaker.h"
|
||||
|
||||
namespace joc::stream {
|
||||
|
||||
@@ -30,13 +31,13 @@ struct Config {
|
||||
std::uint32_t object_delay_samples = 1473;
|
||||
double gain_db = 0.0;
|
||||
std::uint32_t native_threads = 0;
|
||||
// The three HRTF shapes of joc_task_config, in its precedence order: a Rosella
|
||||
// model wins over a SOFA, and hrtf_path (.jochrtf) is the fallback.
|
||||
std::string hrtf_sofa_path;
|
||||
// Binaural inputs of joc_task_config: a Rosella model wins over hrtf_path
|
||||
// (.jochrtf).
|
||||
std::string personalized_headphone_path;
|
||||
std::string hrtf_cache_dir;
|
||||
std::uint32_t hrtf_cache_policy = JOC_HRTF_CACHE_MEMORY;
|
||||
double hrtf_radius_m = 1.0;
|
||||
std::uint32_t jochrtf_room = 1;
|
||||
std::string pcm_layout;
|
||||
// Filterbank of the Rosella path; the other binaural inputs ignore it.
|
||||
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
|
||||
};
|
||||
|
||||
struct Info {
|
||||
@@ -48,6 +49,9 @@ struct Info {
|
||||
std::uint64_t oamd_payloads = 0;
|
||||
std::uint64_t oamd_transitions = 0;
|
||||
std::uint64_t missing_joc_frames = 0;
|
||||
// Audio frames whose ID14 payload ended inside joc_data; they render as
|
||||
// invalid frames and hold the previous matrices.
|
||||
std::uint64_t truncated_joc_frames = 0;
|
||||
std::uint64_t objects_clamped_frames = 0;
|
||||
// Audio frames whose syncframe held more than one top-level JOC container and
|
||||
// were decoded from the single one that carries a complete joc() payload.
|
||||
@@ -97,6 +101,8 @@ public:
|
||||
Status push_bed(const float* interleaved, std::size_t samples, std::uint32_t channels,
|
||||
std::size_t* consumed);
|
||||
Status push_objects16(const float* planar16, std::size_t samples, std::size_t* consumed);
|
||||
Status push_pcm_layout(const float* interleaved, std::size_t samples, std::uint32_t channels,
|
||||
std::size_t* consumed);
|
||||
Status pull(float* destination, std::size_t capacity_samples, std::size_t* produced);
|
||||
Status flush();
|
||||
Status reset();
|
||||
@@ -128,6 +134,9 @@ private:
|
||||
return rosella_ready_ ? (rosella_pending_.size() - rosella_read_offset_) / 2u : 0u;
|
||||
}
|
||||
void reset_state();
|
||||
// 声明的 bed 布局只在首帧解析一次:bed 声道在 OAMD 里没有位置字段,方位由布局
|
||||
// 给出;流式路径和文件任务走同一套 SpeakerStep/双耳运行时,所以这里也要下发。
|
||||
void apply_bed_positions(const FrameMetadata& entry);
|
||||
// Drops the bed samples that have already been rendered, keeping the rest.
|
||||
void compact_bed_pending();
|
||||
// Closes the audio frame currently being assembled and queues it.
|
||||
@@ -155,6 +164,9 @@ private:
|
||||
std::size_t bed_read_offset_ = 0;
|
||||
std::vector<float> bed5_;
|
||||
std::vector<float> lfe_;
|
||||
virtual_speaker::Input pcm_input_;
|
||||
oamd::OamdUpdate fixed_update_{};
|
||||
bool has_fixed_update_ = false;
|
||||
std::vector<float> objects_pending_;
|
||||
std::size_t objects_read_offset_ = 0;
|
||||
std::vector<float> objects_frame_;
|
||||
@@ -165,7 +177,7 @@ private:
|
||||
|
||||
ejoc_renderer_handle rebuilder_ = nullptr;
|
||||
speaker::SpeakerStep speaker_;
|
||||
binaural::SofaBinauralRuntime binaural_;
|
||||
binaural::JochrtfRuntime binaural_;
|
||||
hrtf::RosellaRuntime rosella_;
|
||||
std::vector<double> rosella_pending_;
|
||||
std::size_t rosella_read_offset_ = 0;
|
||||
@@ -173,6 +185,7 @@ private:
|
||||
bool speaker_enabled_ = false;
|
||||
bool binaural_enabled_ = false;
|
||||
bool binaural_ready_ = false;
|
||||
bool bed_positions_ready_ = false;
|
||||
bool rosella_ready_ = false;
|
||||
float gain_ = 1.0f;
|
||||
};
|
||||
|
||||
+269
-70
@@ -28,19 +28,20 @@
|
||||
|
||||
#include "adm/adm_metadata.h"
|
||||
#include "adm/adm_tracks.h"
|
||||
#include "binaural/binaural_runtime.h"
|
||||
#include "binaural/jochrtf_runtime.h"
|
||||
#include "eac3_transport/eac3_reader.h"
|
||||
#include "emdf/emdf_parser.h"
|
||||
#include "foundation/mini_json.h"
|
||||
#include "foundation/sha256.h"
|
||||
#include "hrtf/jochrtf.h"
|
||||
#include "hrtf/rosella_bank.h"
|
||||
#include "hrtf/rosella_model.h"
|
||||
#include "hrtf/rosella_renderer.h"
|
||||
#include "hrtf/sofa_cache.h"
|
||||
#include "io/adm_writer.h"
|
||||
#include "io/process.h"
|
||||
#include "io/wav_writer.h"
|
||||
#include "joc_bitstream/joc_parser.h"
|
||||
#include "joc_bitstream/bed_layout_map.h"
|
||||
#include "joc_core/objects16.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
#include "speaker/speaker_step.h"
|
||||
@@ -92,11 +93,9 @@ struct Settings {
|
||||
std::string layout;
|
||||
std::string hrtf_path;
|
||||
std::string kernels_path;
|
||||
std::string hrtf_sofa_path;
|
||||
std::string personalized_headphone_path;
|
||||
std::string hrtf_cache_dir;
|
||||
std::uint32_t hrtf_cache_policy = JOC_HRTF_CACHE_MEMORY;
|
||||
double hrtf_radius_m = 1.0;
|
||||
std::uint32_t jochrtf_room = 1;
|
||||
std::uint32_t rosella_filterbank = JOC_ROSELLA_FILTERBANK_PUBLIC;
|
||||
std::uint32_t operation = JOC_OP_ADM_BWF;
|
||||
std::uint32_t output_format = JOC_FORMAT_FLOAT32;
|
||||
std::uint32_t adm_binaural_mode = JOC_BINAURAL_MID;
|
||||
@@ -141,13 +140,13 @@ Settings normalise(const joc_task_config& raw) {
|
||||
if (raw.output_path != nullptr) { cfg.output_path = raw.output_path; }
|
||||
if (raw.speaker_layout_name != nullptr) { cfg.layout = raw.speaker_layout_name; }
|
||||
if (raw.hrtf_path != nullptr) { cfg.hrtf_path = raw.hrtf_path; }
|
||||
if (raw.hrtf_sofa_path != nullptr) { cfg.hrtf_sofa_path = raw.hrtf_sofa_path; }
|
||||
if (raw.personalized_headphone_path != nullptr) {
|
||||
cfg.personalized_headphone_path = raw.personalized_headphone_path;
|
||||
}
|
||||
if (raw.hrtf_cache_dir != nullptr) { cfg.hrtf_cache_dir = raw.hrtf_cache_dir; }
|
||||
cfg.hrtf_cache_policy = raw.hrtf_cache_policy;
|
||||
cfg.hrtf_radius_m = raw.hrtf_radius_m;
|
||||
cfg.jochrtf_room = raw.jochrtf_room;
|
||||
// Kept verbatim so validate() can reject an out-of-range value; 0 is the
|
||||
// documented "unset" spelling of the public bank.
|
||||
cfg.rosella_filterbank = raw.rosella_filterbank;
|
||||
if (raw.kernels_path != nullptr) { cfg.kernels_path = raw.kernels_path; }
|
||||
cfg.operation = raw.operation;
|
||||
cfg.output_format = raw.output_format;
|
||||
@@ -314,6 +313,91 @@ int probe_config_idx(const std::string& path) {
|
||||
return config;
|
||||
}
|
||||
|
||||
// Reads the programme trim element from the leading audio frames, without
|
||||
// rendering them. The ADM master metadata carries it, and the reference scans
|
||||
// the first 64 audio frames for it.
|
||||
Status probe_atmos_trim(const std::string& path, std::uint64_t max_frames,
|
||||
oamd::OamdTrim* trim, bool* present) {
|
||||
*present = false;
|
||||
std::ifstream input = fs_utf8::open_input(path);
|
||||
if (!input) {
|
||||
return Status::success();
|
||||
}
|
||||
::joc::eac3::FrameReader reader;
|
||||
std::vector<char> chunk(1u << 16);
|
||||
std::vector<::joc::eac3::Frame> group;
|
||||
std::uint64_t frames = 0;
|
||||
auto scan_group = [&]() -> bool {
|
||||
for (const ::joc::eac3::Frame& frame : group) {
|
||||
bool has_joc = false;
|
||||
::joc::emdf::Container container;
|
||||
if (!::joc::emdf::find_joc_emdf_optional(
|
||||
frame.data, frame.size, &has_joc, &container,
|
||||
&::joc::joc::score_container_as_joc, nullptr)
|
||||
.ok() ||
|
||||
!has_joc) {
|
||||
continue;
|
||||
}
|
||||
const ::joc::emdf::Payload* payload = container.find(::joc::emdf::kIdOamd);
|
||||
if (payload == nullptr) {
|
||||
continue;
|
||||
}
|
||||
std::vector<std::uint8_t> bytes;
|
||||
if (!::joc::emdf::extract_payload_bytes(frame.data, frame.size, *payload, &bytes)
|
||||
.ok()) {
|
||||
continue;
|
||||
}
|
||||
oamd::OamdUpdate update;
|
||||
if (!oamd::parse_id11_state(bytes.data(), bytes.size(), &update).ok() ||
|
||||
!update.has_trim) {
|
||||
continue;
|
||||
}
|
||||
*trim = update.trim;
|
||||
*present = true;
|
||||
return true;
|
||||
}
|
||||
group.clear();
|
||||
return false;
|
||||
};
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
input.read(chunk.data(), static_cast<std::streamsize>(chunk.size()));
|
||||
const std::streamsize got = input.gcount();
|
||||
if (got > 0) {
|
||||
reader.push(reinterpret_cast<const std::uint8_t*>(chunk.data()),
|
||||
static_cast<std::size_t>(got));
|
||||
} else {
|
||||
reader.finish();
|
||||
done = true;
|
||||
}
|
||||
for (;;) {
|
||||
::joc::eac3::Frame frame;
|
||||
const ::joc::eac3::FrameReader::Next state = reader.next(&frame);
|
||||
if (state != ::joc::eac3::FrameReader::Next::Ok) {
|
||||
break;
|
||||
}
|
||||
bool repeats = false;
|
||||
for (const ::joc::eac3::Frame& prior : group) {
|
||||
if (prior.same_stream(frame)) {
|
||||
repeats = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (repeats) {
|
||||
++frames;
|
||||
if (scan_group() || frames >= max_frames) {
|
||||
return Status::success();
|
||||
}
|
||||
}
|
||||
group.push_back(frame);
|
||||
}
|
||||
}
|
||||
if (!group.empty()) {
|
||||
scan_group();
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
// Rendered PCM is spooled to a float32 file so the output format can be decided
|
||||
// once the peak is known, which is what makes --clip-action possible; the
|
||||
// reference CLI spools for the same reason.
|
||||
@@ -1068,36 +1152,17 @@ Status validate(const joc_task_config& raw, std::vector<joc_validation_issue>* i
|
||||
}
|
||||
}
|
||||
if (cfg.operation == JOC_OP_BINAURAL) {
|
||||
if (cfg.hrtf_path.empty() && cfg.hrtf_sofa_path.empty() &&
|
||||
cfg.personalized_headphone_path.empty()) {
|
||||
if (cfg.hrtf_path.empty() && cfg.personalized_headphone_path.empty()) {
|
||||
fail(JOC_ERR_INVALID_CONFIG, "hrtf_path",
|
||||
"a SOFA input, a Rosella model or a compiled HRTF (.jochrtf) is required for the "
|
||||
"a Rosella model or a compiled HRTF (.jochrtf) is required for the "
|
||||
"binaural operation");
|
||||
} else if (!cfg.personalized_headphone_path.empty() &&
|
||||
!fs_utf8::exists(cfg.personalized_headphone_path)) {
|
||||
fail(JOC_ERR_HRTF_NOT_FOUND, "personalized_headphone_path",
|
||||
"personalized headphone model not found: " + cfg.personalized_headphone_path);
|
||||
} else if (!cfg.hrtf_sofa_path.empty() && !fs_utf8::exists(cfg.hrtf_sofa_path)) {
|
||||
fail(JOC_ERR_HRTF_NOT_FOUND, "hrtf_sofa_path",
|
||||
"SOFA HRTF not found: " + cfg.hrtf_sofa_path);
|
||||
} else if (cfg.hrtf_sofa_path.empty() && cfg.personalized_headphone_path.empty() &&
|
||||
!fs_utf8::exists(cfg.hrtf_path)) {
|
||||
} else if (cfg.personalized_headphone_path.empty() && !fs_utf8::exists(cfg.hrtf_path)) {
|
||||
fail(JOC_ERR_HRTF_NOT_FOUND, "hrtf_path", "HRTF cache not found: " + cfg.hrtf_path);
|
||||
}
|
||||
if (!cfg.hrtf_sofa_path.empty()) {
|
||||
if (cfg.hrtf_cache_policy > JOC_HRTF_CACHE_DISK) {
|
||||
fail(JOC_ERR_INVALID_CONFIG, "hrtf_cache_policy",
|
||||
"hrtf_cache_policy must be none, memory or disk");
|
||||
}
|
||||
if (cfg.hrtf_cache_policy == JOC_HRTF_CACHE_DISK && cfg.hrtf_cache_dir.empty()) {
|
||||
fail(JOC_ERR_INVALID_CONFIG, "hrtf_cache_dir",
|
||||
"the disk cache policy needs a cache directory");
|
||||
}
|
||||
if (!std::isfinite(cfg.hrtf_radius_m) || cfg.hrtf_radius_m <= 0.0) {
|
||||
fail(JOC_ERR_INVALID_CONFIG, "hrtf_radius_m",
|
||||
"hrtf_radius_m must be positive and finite");
|
||||
}
|
||||
}
|
||||
// The filterbank tables are compiled in; a path is only a verification override.
|
||||
if (!cfg.kernels_path.empty() && !fs_utf8::exists(cfg.kernels_path)) {
|
||||
fail(JOC_ERR_HRTF_NOT_FOUND, "kernels_path",
|
||||
@@ -1107,6 +1172,14 @@ Status validate(const joc_task_config& raw, std::vector<joc_validation_issue>* i
|
||||
fail(JOC_ERR_INVALID_CONFIG, "binaural_mode",
|
||||
"binaural_mode off is only meaningful for ADM output");
|
||||
}
|
||||
if (cfg.rosella_filterbank > JOC_ROSELLA_FILTERBANK_CAPTURED) {
|
||||
fail(JOC_ERR_INVALID_CONFIG, "rosella_filterbank",
|
||||
"rosella_filterbank must be 1 (public) or 2 (captured)");
|
||||
} else if (cfg.rosella_filterbank == JOC_ROSELLA_FILTERBANK_CAPTURED &&
|
||||
cfg.personalized_headphone_path.empty()) {
|
||||
fail(JOC_ERR_INVALID_CONFIG, "rosella_filterbank",
|
||||
"rosella_filterbank 2 only applies to a Rosella .personalized_headphone input");
|
||||
}
|
||||
}
|
||||
if (cfg.operation == JOC_OP_ADM_BWF) {
|
||||
if (cfg.adm_binaural_mode > 4u) {
|
||||
@@ -1322,6 +1395,14 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
}
|
||||
|
||||
::joc::speaker::SpeakerStep speaker;
|
||||
bool bed_positions_ready = false;
|
||||
// The ADM master metadata carries the programme's trim element, scanned
|
||||
// from the leading frames before rendering starts.
|
||||
::joc::oamd::OamdTrim adm_trim;
|
||||
bool adm_trim_present = false;
|
||||
if (cfg.operation == JOC_OP_ADM_BWF) {
|
||||
probe_atmos_trim(eac3_path, 64, &adm_trim, &adm_trim_present);
|
||||
}
|
||||
const bool speaker_enabled = cfg.operation == JOC_OP_SPEAKER;
|
||||
if (speaker_enabled) {
|
||||
if (!::joc::speaker::layout_by_name(cfg.layout.c_str(), &speaker.layout)) {
|
||||
@@ -1334,12 +1415,32 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
return finalize_with_error(JOC_ERR_RENDER_FAILED, "render",
|
||||
"cannot create the speaker renderer");
|
||||
}
|
||||
// The reference seeds the initial controls from the leading frames, so
|
||||
// the first trim element is in effect before its own event arrives.
|
||||
::joc::oamd::OamdTrim initial_trim;
|
||||
bool has_initial_trim = false;
|
||||
probe_atmos_trim(eac3_path, 64, &initial_trim, &has_initial_trim);
|
||||
if (has_initial_trim) {
|
||||
const Status seeded = ::joc::speaker::parameters_from_oamd(
|
||||
&initial_trim, speaker.layout, &speaker.controls);
|
||||
if (!seeded.ok()) {
|
||||
ejoc_speaker_renderer_destroy(speaker.handle);
|
||||
speaker.handle = nullptr;
|
||||
return finalize_with_error(seeded.code(), "render", seeded.message());
|
||||
}
|
||||
speaker.controls_ready = true;
|
||||
// The metadata path needs the programme trim before its own event
|
||||
// arrives; the probe above read it from the leading frames.
|
||||
speaker.trim = initial_trim;
|
||||
speaker.has_trim = true;
|
||||
speaker.raw_trim_mode = initial_trim.global_trim_mode;
|
||||
}
|
||||
bus.emit(JOC_EV_RENDERER_INITIALIZED, JOC_STAGE_RENDER, JOC_LOG_INFO,
|
||||
fmt("speaker renderer: %s, %u channels", speaker.layout.name,
|
||||
speaker.layout.channel_count));
|
||||
}
|
||||
|
||||
::joc::binaural::SofaBinauralRuntime binaural;
|
||||
::joc::binaural::JochrtfRuntime binaural;
|
||||
::joc::hrtf::RosellaRuntime rosella;
|
||||
const bool binaural_enabled = cfg.operation == JOC_OP_BINAURAL;
|
||||
const bool rosella_enabled = !cfg.personalized_headphone_path.empty();
|
||||
@@ -1356,14 +1457,22 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
}
|
||||
render_options.object_delay_samples = cfg.object_delay_samples;
|
||||
render_options.tail_seconds = cfg.tail_seconds;
|
||||
render_options.bank =
|
||||
cfg.rosella_filterbank == JOC_ROSELLA_FILTERBANK_CAPTURED
|
||||
? ::joc::hrtf::RosellaBankKind::Captured
|
||||
: ::joc::hrtf::RosellaBankKind::Public;
|
||||
if (status.ok()) {
|
||||
status = rosella.open(model, render_options);
|
||||
}
|
||||
if (status.ok()) {
|
||||
bus.emit(JOC_EV_HRTF_LOADED, JOC_STAGE_RENDER, JOC_LOG_INFO, model.summary());
|
||||
bus.emit(JOC_EV_RENDERER_INITIALIZED, JOC_STAGE_RENDER, JOC_LOG_INFO,
|
||||
"Rosella binaural runtime ready (the first 961 samples are the "
|
||||
"filterbank latency)");
|
||||
fmt("Rosella binaural runtime ready (%s filterbank, the first %u "
|
||||
"samples are the filterbank latency)",
|
||||
render_options.bank == ::joc::hrtf::RosellaBankKind::Captured
|
||||
? "captured"
|
||||
: "public",
|
||||
::joc::hrtf::rosella_bank_latency(render_options.bank)));
|
||||
}
|
||||
if (!status.ok()) {
|
||||
return finalize_with_error(status.code(), "render",
|
||||
@@ -1375,31 +1484,11 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
::joc::hrtf::Kernels kernels;
|
||||
::joc::binaural::Profile profile = ::joc::binaural::Profile::Mid;
|
||||
Status status = Status::success();
|
||||
if (!cfg.hrtf_sofa_path.empty()) {
|
||||
// The .jochrtf is an internal cache: the SOFA is the user-facing input.
|
||||
::joc::hrtf::SofaFieldRequest request;
|
||||
request.sofa_path = cfg.hrtf_sofa_path;
|
||||
request.options.shell_radius_m = cfg.hrtf_radius_m;
|
||||
request.cache_dir = cfg.hrtf_cache_dir;
|
||||
switch (cfg.hrtf_cache_policy) {
|
||||
case JOC_HRTF_CACHE_NONE: request.policy = ::joc::hrtf::CachePolicy::None; break;
|
||||
case JOC_HRTF_CACHE_DISK: request.policy = ::joc::hrtf::CachePolicy::Disk; break;
|
||||
default: request.policy = ::joc::hrtf::CachePolicy::Memory; break;
|
||||
}
|
||||
std::string cache_path;
|
||||
status = ::joc::hrtf::load_or_compile_sofa_field(request, &field, &cache_path);
|
||||
if (status.ok()) {
|
||||
bus.emit(JOC_EV_HRTF_LOADED, JOC_STAGE_RENDER, JOC_LOG_INFO,
|
||||
"SOFA HRTF compiled: " + field.source_sha256.substr(0, 16) +
|
||||
(cache_path.empty() ? std::string() : " -> " + cache_path));
|
||||
}
|
||||
} else {
|
||||
status = ::joc::hrtf::load_jochrtf(cfg.hrtf_path, &field);
|
||||
if (status.ok()) {
|
||||
bus.emit(JOC_EV_HRTF_LOADED, JOC_STAGE_RENDER, JOC_LOG_INFO,
|
||||
"compiled HRTF: " + field.source_sha256.substr(0, 16));
|
||||
}
|
||||
}
|
||||
if (status.ok()) {
|
||||
status = cfg.kernels_path.empty()
|
||||
? (kernels = ::joc::hrtf::builtin_kernels(), Status::success())
|
||||
@@ -1411,7 +1500,10 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
profile = ::joc::binaural::Profile::Far;
|
||||
}
|
||||
if (status.ok()) {
|
||||
status = binaural.open(field, kernels, profile);
|
||||
::joc::binaural::RoomConstants room;
|
||||
room.enable_early_reflections = cfg.jochrtf_room ? 1u : 0u;
|
||||
room.enable_late_room = room.enable_early_reflections;
|
||||
status = binaural.open(field, kernels, profile, room);
|
||||
}
|
||||
if (!status.ok()) {
|
||||
return finalize_with_error(status.code(), "render",
|
||||
@@ -1423,7 +1515,8 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
}
|
||||
|
||||
::joc::io::AdmBwfWriter adm_writer;
|
||||
::joc::adm::TrajectoryBuilder trajectory(48000, 64, cfg.object_delay_samples);
|
||||
::joc::adm::TrajectoryBuilder trajectory(48000, ::joc::timing::kMetadataBlockSamples,
|
||||
cfg.object_delay_samples);
|
||||
const bool adm_enabled = cfg.operation == JOC_OP_ADM_BWF;
|
||||
if (adm_enabled) {
|
||||
const Status status = adm_writer.open(cfg.output_path);
|
||||
@@ -1501,7 +1594,11 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
// count was clamped to 15, and frames whose syncframe carried a second EMDF
|
||||
// container that is not this frame's JOC metadata.
|
||||
std::uint64_t missing_joc_frames = 0;
|
||||
std::uint64_t truncated_joc_frames = 0;
|
||||
std::uint64_t objects_clamped_frames = 0;
|
||||
std::uint64_t bad_parameter_band_frames = 0;
|
||||
std::uint64_t bad_offset_ts_frames = 0;
|
||||
std::uint64_t trailing_data_frames = 0;
|
||||
std::uint64_t extra_container_frames = 0;
|
||||
std::uint64_t chanmap_pair_mismatch_frames = 0;
|
||||
std::uint64_t bed_mask_mismatch_frames = 0;
|
||||
@@ -1572,6 +1669,22 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
if (params.objects_clamped != 0u) {
|
||||
++objects_clamped_frames;
|
||||
}
|
||||
switch (params.status) {
|
||||
case JOC_FRAME_STATUS_BAD_PARAMETER_BAND:
|
||||
++bad_parameter_band_frames;
|
||||
break;
|
||||
case JOC_FRAME_STATUS_BAD_OFFSET_TS:
|
||||
++bad_offset_ts_frames;
|
||||
break;
|
||||
case JOC_FRAME_STATUS_TRAILING_DATA:
|
||||
++trailing_data_frames;
|
||||
break;
|
||||
case JOC_FRAME_STATUS_TRUNCATED:
|
||||
++truncated_joc_frames;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
++missing_joc_frames;
|
||||
}
|
||||
@@ -1603,8 +1716,9 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
}
|
||||
std::string dsp_error;
|
||||
const Status rebuilt = ::joc::joc::rebuild_objects16(
|
||||
rebuilder, params, bed5.data(), lfe.data(), gain, &objects16,
|
||||
&dsp_error);
|
||||
rebuilder, params, bed5.data(), lfe.data(),
|
||||
static_cast<std::uint32_t>(resolved_core_channels), has_joc, gain,
|
||||
&objects16, &dsp_error);
|
||||
if (!rebuilt.ok()) {
|
||||
return Status::fail(rebuilt.code(), "joc", dsp_error);
|
||||
}
|
||||
@@ -1731,8 +1845,17 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
stream_done = true;
|
||||
break;
|
||||
}
|
||||
// The speaker, binaural and ADM paths consume the full per-object
|
||||
// block state (multi-block and every declared object); the legacy
|
||||
// stream/ADM single-block view only needs the slot fields.
|
||||
const bool full_metadata_state =
|
||||
speaker_enabled || binaural_enabled || adm_enabled;
|
||||
const Status oamd =
|
||||
::joc::oamd::parse_id11(bytes.data(), bytes.size(), &job.update);
|
||||
full_metadata_state
|
||||
? ::joc::oamd::parse_id11_state(bytes.data(), bytes.size(),
|
||||
&job.update)
|
||||
: ::joc::oamd::parse_id11(bytes.data(), bytes.size(),
|
||||
&job.update);
|
||||
if (!oamd.ok()) {
|
||||
failures.record(produced, StageRank::kJoc, oamd.code(), oamd.stage(),
|
||||
"frame " + std::to_string(produced) + ": " +
|
||||
@@ -1744,6 +1867,62 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
job.outer_offset = static_cast<std::int64_t>(payload->sample_offset);
|
||||
const Status bed_ok = ::joc::oamd::parse_id11_bed_assignments(
|
||||
bytes.data(), bytes.size(), &group_bed_assignments);
|
||||
if (bed_ok.ok() && !bed_positions_ready &&
|
||||
!group_bed_assignments.empty()) {
|
||||
const ::joc::joc::BedLayout bed_layout =
|
||||
::joc::joc::resolve_bed_layout(
|
||||
group_bed_assignments,
|
||||
job.update.content_bed && !job.update.content_isf &&
|
||||
!job.update.content_dynamic);
|
||||
if (bed_layout.present) {
|
||||
bed_positions_ready = true;
|
||||
bus.emit(JOC_EV_RENDERER_INITIALIZED, JOC_STAGE_RENDER,
|
||||
JOC_LOG_INFO,
|
||||
fmt("bed layout: %s (%u bed channels)",
|
||||
bed_layout.name[0] != '\0'
|
||||
? bed_layout.name : "custom",
|
||||
static_cast<unsigned>(
|
||||
bed_layout.channels.size())));
|
||||
if (bed_layout.bed_only) {
|
||||
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
|
||||
for (std::size_t slot = 0;
|
||||
slot < bed_layout.channels.size() &&
|
||||
slot < static_cast<std::size_t>(::joc::oamd::kObjects);
|
||||
++slot) {
|
||||
const ::joc::joc::BedChannel channel =
|
||||
bed_layout.channels[slot];
|
||||
double xyz[3] = {0.0, 0.0, 0.0};
|
||||
if (::joc::joc::bed_channel_adm_position(channel, xyz)) {
|
||||
trajectory.set_fixed_position(
|
||||
static_cast<int>(slot) + 1, xyz[0], xyz[1],
|
||||
xyz[2]);
|
||||
if (binaural_enabled) {
|
||||
binaural.set_fixed_position(
|
||||
static_cast<int>(slot) + 1, xyz);
|
||||
}
|
||||
if (rosella_enabled) {
|
||||
rosella.set_fixed_position(
|
||||
static_cast<int>(slot) + 1, xyz);
|
||||
}
|
||||
}
|
||||
if (!speaker_enabled) {
|
||||
continue;
|
||||
}
|
||||
// 目标布局有同名扬声器时直连该声道,否则按标准方位声像。
|
||||
std::uint16_t q15[3] = {0, 0, 0};
|
||||
if (!::joc::joc::layout_bed_anchor(
|
||||
speaker.layout.out_ch_config, channel, q15) &&
|
||||
!::joc::joc::bed_channel_q15(channel, q15)) {
|
||||
continue;
|
||||
}
|
||||
speaker.bed_override[slot] = true;
|
||||
for (int axis = 0; axis < ::joc::oamd::kAxes; ++axis) {
|
||||
speaker.bed_positions[slot][axis] = q15[axis];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bed_ok.ok()) {
|
||||
failures.record(produced, StageRank::kJoc, bed_ok.code(),
|
||||
bed_ok.stage(), bed_ok.message());
|
||||
@@ -2022,11 +2201,33 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
joiner.shutdown(false);
|
||||
if (missing_joc_frames != 0u) {
|
||||
bus.warning(std::to_string(missing_joc_frames) +
|
||||
" audio frame(s) carried no JOC payload; their object channels stay silent");
|
||||
" audio frame(s) carried no JOC payload; their core PCM was passed "
|
||||
"through (8 core planes, 1217-sample delay)");
|
||||
}
|
||||
if (objects_clamped_frames != 0u) {
|
||||
bus.warning(std::to_string(objects_clamped_frames) +
|
||||
" audio frame(s) declared more than 15 objects; the count was clamped to 15");
|
||||
" audio frame(s) declared more than 15 objects; the count was clamped "
|
||||
"to 15 and the frame took the invalid-frame path");
|
||||
}
|
||||
if (bad_parameter_band_frames != 0u) {
|
||||
bus.warning(std::to_string(bad_parameter_band_frames) +
|
||||
" audio frame(s) declared an unknown JOC parameter-band count; the "
|
||||
"frame took the invalid-frame path");
|
||||
}
|
||||
if (bad_offset_ts_frames != 0u) {
|
||||
bus.warning(std::to_string(bad_offset_ts_frames) +
|
||||
" audio frame(s) carried an invalid JOC offset_ts value; the frame "
|
||||
"took the invalid-frame path");
|
||||
}
|
||||
if (trailing_data_frames != 0u) {
|
||||
bus.warning(std::to_string(trailing_data_frames) +
|
||||
" audio frame(s) carried JOC data after the byte-alignment padding; "
|
||||
"the frame took the invalid-frame path");
|
||||
}
|
||||
if (truncated_joc_frames != 0u) {
|
||||
bus.warning(std::to_string(truncated_joc_frames) +
|
||||
" audio frame(s) carried a JOC payload that ends inside joc_data; "
|
||||
"the frame took the invalid-frame path and held the previous matrices");
|
||||
}
|
||||
if (extra_container_frames != 0u) {
|
||||
bus.warning(std::to_string(extra_container_frames) +
|
||||
@@ -2038,11 +2239,6 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
" audio frame(s): the chanmap declares a different extra pair than "
|
||||
"joc_dmx_config_idx; the bed mapping follows the chanmap");
|
||||
}
|
||||
if (bed_mask_mismatch_frames != 0u) {
|
||||
bus.warning(std::to_string(bed_mask_mismatch_frames) +
|
||||
" audio frame(s): the OAMD bed mask declares a different extra pair than "
|
||||
"joc_dmx_config_idx; the bed mask only affects metadata");
|
||||
}
|
||||
StageFailure recorded;
|
||||
if (failures.earliest(&recorded)) {
|
||||
return finalize_with_error(recorded.code, recorded.stage_text, recorded.message);
|
||||
@@ -2075,13 +2271,16 @@ Status run(const joc_task_config& raw, const joc_event_sink* sink, joc_task_resu
|
||||
} else {
|
||||
const double duration_sec =
|
||||
static_cast<double>(processed) * static_cast<std::int64_t>(JOC_FRAME_SAMPLES) / 48000.0;
|
||||
const std::string axml = ::joc::adm::build_axml(tracks, duration_sec, 48000);
|
||||
const std::string axml =
|
||||
::joc::adm::build_axml(tracks, duration_sec, 48000,
|
||||
adm_trim_present ? &adm_trim : nullptr);
|
||||
const std::string chna = ::joc::adm::build_chna();
|
||||
std::string dbmd;
|
||||
const ::joc::adm::BinauralMode mode =
|
||||
static_cast<::joc::adm::BinauralMode>(cfg.adm_binaural_mode);
|
||||
const Status dbmd_status =
|
||||
::joc::adm::build_dbmd(::joc::io::AdmBwfWriter::kChannels, mode, &dbmd);
|
||||
const Status dbmd_status = ::joc::adm::build_dbmd(
|
||||
::joc::io::AdmBwfWriter::kChannels, mode, &dbmd,
|
||||
adm_trim_present ? &adm_trim : nullptr);
|
||||
if (!dbmd_status.ok()) {
|
||||
failure = dbmd_status.message();
|
||||
} else {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "timeline/position_timeline.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "foundation/geometry.h"
|
||||
#include "foundation/metadata_timing.h"
|
||||
|
||||
namespace joc::timeline {
|
||||
|
||||
@@ -93,33 +95,100 @@ Status ObjectPositionTrack::position_at(std::int64_t sample, double out[3]) {
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
OamdPositionTimeline::OamdPositionTimeline(int object_count) : object_count_(object_count) {
|
||||
if (object_count != kTimelineObjects) {
|
||||
object_count_ = kTimelineObjects;
|
||||
OamdPositionTimeline::OamdPositionTimeline(int object_count)
|
||||
: object_count_(std::clamp(object_count, 1, oamd::kMaxObjects - 1)) {
|
||||
const std::size_t count = static_cast<std::size_t>(object_count_);
|
||||
tracks_.resize(count);
|
||||
previous_targets_.resize(count);
|
||||
has_previous_.assign(count, false);
|
||||
fixed_.assign(count, false);
|
||||
fixed_xyz_.resize(count);
|
||||
}
|
||||
|
||||
void OamdPositionTimeline::ensure_tracks(int count) {
|
||||
const int capped = std::clamp(count, 1, oamd::kMaxObjects - 1);
|
||||
if (capped <= object_count_) {
|
||||
return;
|
||||
}
|
||||
const std::size_t size = static_cast<std::size_t>(capped);
|
||||
object_count_ = capped;
|
||||
tracks_.resize(size);
|
||||
previous_targets_.resize(size);
|
||||
has_previous_.resize(size, false);
|
||||
fixed_.resize(size, false);
|
||||
fixed_xyz_.resize(size);
|
||||
}
|
||||
|
||||
void OamdPositionTimeline::set_fixed_position(int object_index, const double position[3]) {
|
||||
if (object_index < 1 || object_index > object_count_) {
|
||||
return;
|
||||
}
|
||||
const std::size_t index = static_cast<std::size_t>(object_index - 1);
|
||||
fixed_[index] = true;
|
||||
for (int axis = 0; axis < 3; ++axis) {
|
||||
fixed_xyz_[index][static_cast<std::size_t>(axis)] = position[axis];
|
||||
}
|
||||
}
|
||||
|
||||
Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
|
||||
std::int64_t frame_start_sample,
|
||||
std::int64_t outer_sample_offset,
|
||||
void OamdPositionTimeline::reset() {
|
||||
state_.reset();
|
||||
for (int index = 0; index < object_count_; ++index) {
|
||||
tracks_[static_cast<std::size_t>(index)] = ObjectPositionTrack();
|
||||
has_previous_[static_cast<std::size_t>(index)] = false;
|
||||
previous_targets_[static_cast<std::size_t>(index)] = {0.0, 0.0, 0.0};
|
||||
}
|
||||
initialized_ = false;
|
||||
payload_count_ = 0;
|
||||
transition_count_ = 0;
|
||||
last_coded_event_sample_ = -1;
|
||||
}
|
||||
|
||||
void OamdPositionTimeline::apply_block(const oamd::FrameState& state,
|
||||
std::uint32_t block_index) {
|
||||
// Track i reads OAMD object i + 1: object 0 is the LFE/bed slot the JOC
|
||||
// renderers do not position. Bed and ISF objects carry no position field,
|
||||
// and an inactive block keeps the previous position, exactly like the
|
||||
// reference frame_update() value construction.
|
||||
for (int track = 0; track < object_count_; ++track) {
|
||||
const int object_index = track + 1;
|
||||
if (object_index >= static_cast<int>(state.objects.size())) {
|
||||
break;
|
||||
}
|
||||
const oamd::ObjectElementState& element =
|
||||
state.objects[static_cast<std::size_t>(object_index)];
|
||||
if (block_index >= element.blocks.size()) {
|
||||
continue;
|
||||
}
|
||||
const oamd::ObjectRenderState& render =
|
||||
element.blocks[static_cast<std::size_t>(block_index)].render;
|
||||
if (render.not_active || element.kind != oamd::ObjectKind::kDynamic) {
|
||||
continue;
|
||||
}
|
||||
state_.apply_render_state(object_index, render);
|
||||
}
|
||||
}
|
||||
|
||||
void OamdPositionTimeline::targets(std::vector<std::array<double, 3>>* out) const {
|
||||
out->resize(static_cast<std::size_t>(object_count_));
|
||||
for (int index = 0; index < object_count_; ++index) {
|
||||
const std::size_t slot = static_cast<std::size_t>(index);
|
||||
if (fixed_[slot]) {
|
||||
(*out)[slot] = fixed_xyz_[slot];
|
||||
continue;
|
||||
}
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
double z = 0.0;
|
||||
geometry::q_to_adm_xyz(state_.q(index + 1, 0), state_.q(index + 1, 1),
|
||||
state_.q(index + 1, 2), &x, &y, &z);
|
||||
(*out)[slot] = {x, y, z};
|
||||
}
|
||||
}
|
||||
|
||||
Status OamdPositionTimeline::schedule(const std::vector<std::array<double, 3>>& targets,
|
||||
std::int64_t coded_event, std::int64_t ramp_samples,
|
||||
std::int64_t object_delay_samples,
|
||||
std::int64_t processed_sample) {
|
||||
if (frame_start_sample < 0 || outer_sample_offset < 0 || object_delay_samples < 0) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
|
||||
"OAMD frame, outer offset and object delay must be non-negative");
|
||||
}
|
||||
state_.apply(update);
|
||||
|
||||
double targets[kTimelineObjects][3] = {};
|
||||
for (int index = 0; index < kTimelineObjects; ++index) {
|
||||
geometry::q_to_adm_xyz(state_.q(index + 1, 0), state_.q(index + 1, 1),
|
||||
state_.q(index + 1, 2), &targets[index][0], &targets[index][1],
|
||||
&targets[index][2]);
|
||||
}
|
||||
|
||||
const std::int64_t coded_event =
|
||||
frame_start_sample + outer_sample_offset +
|
||||
static_cast<std::int64_t>(update.block_offset_samples);
|
||||
if (coded_event < last_coded_event_sample_) {
|
||||
return timeline_fail(JOC_ERR_OAMD_UNSUPPORTED_VARIANT,
|
||||
"non_monotonic_binaural_updates: event sample " +
|
||||
@@ -135,48 +204,105 @@ Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
|
||||
"sample " + std::to_string(processed_sample) +
|
||||
" had been processed, so sample 0 cannot be backfilled");
|
||||
}
|
||||
for (int index = 0; index < kTimelineObjects; ++index) {
|
||||
tracks_[index].set_initial(targets[index]);
|
||||
std::memcpy(previous_targets_[index], targets[index], sizeof(targets[index]));
|
||||
has_previous_[index] = true;
|
||||
for (int index = 0; index < object_count_; ++index) {
|
||||
const std::size_t slot = static_cast<std::size_t>(index);
|
||||
tracks_[slot].set_initial(targets[slot].data());
|
||||
previous_targets_[slot] = targets[slot];
|
||||
has_previous_[slot] = true;
|
||||
}
|
||||
initialized_ = true;
|
||||
++payload_count_;
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
const std::int64_t ramp_duration = static_cast<std::int64_t>(update.ramp_duration_samples);
|
||||
const std::int64_t effective_ramp =
|
||||
ramp_duration - kOamdUpdateQuantumSamples > 0 ? ramp_duration - kOamdUpdateQuantumSamples
|
||||
: 0;
|
||||
std::int64_t transition_start = coded_event + object_delay_samples;
|
||||
if (effective_ramp != 0) {
|
||||
transition_start += kOamdUpdateQuantumSamples;
|
||||
}
|
||||
for (int index = 0; index < kTimelineObjects; ++index) {
|
||||
const bool changed = !has_previous_[index] ||
|
||||
std::memcmp(previous_targets_[index], targets[index],
|
||||
sizeof(targets[index])) != 0;
|
||||
const std::int64_t effective_ramp = std::max<std::int64_t>(0, ramp_samples);
|
||||
const std::int64_t transition_start =
|
||||
timing::align_metadata_sample(coded_event + object_delay_samples);
|
||||
for (int index = 0; index < object_count_; ++index) {
|
||||
const std::size_t slot = static_cast<std::size_t>(index);
|
||||
const bool changed =
|
||||
!has_previous_[slot] ||
|
||||
std::memcmp(previous_targets_[slot].data(), targets[slot].data(),
|
||||
sizeof(targets[slot])) != 0;
|
||||
if (!changed) {
|
||||
continue;
|
||||
}
|
||||
const Status status = tracks_[index].append(transition_start, effective_ramp,
|
||||
targets[index], index + 1);
|
||||
const Status status =
|
||||
tracks_[slot].append(transition_start, effective_ramp, targets[slot].data(),
|
||||
index + 1);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
std::memcpy(previous_targets_[index], targets[index], sizeof(targets[index]));
|
||||
has_previous_[index] = true;
|
||||
previous_targets_[slot] = targets[slot];
|
||||
has_previous_[slot] = true;
|
||||
++transition_count_;
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status OamdPositionTimeline::submit_update(const oamd::OamdUpdate& update,
|
||||
std::int64_t frame_start_sample,
|
||||
std::int64_t outer_sample_offset,
|
||||
std::int64_t object_delay_samples,
|
||||
std::int64_t processed_sample) {
|
||||
if (frame_start_sample < 0 || outer_sample_offset < 0 || object_delay_samples < 0) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
|
||||
"OAMD frame, outer offset and object delay must be non-negative");
|
||||
}
|
||||
if (!update.has_frame_state) {
|
||||
state_.apply(update);
|
||||
targets(&targets_);
|
||||
const std::int64_t coded_event =
|
||||
frame_start_sample + outer_sample_offset +
|
||||
static_cast<std::int64_t>(update.block_offset_samples);
|
||||
const Status status =
|
||||
schedule(targets_, coded_event, update.ramp_duration_samples, object_delay_samples,
|
||||
processed_sample);
|
||||
if (status.ok()) {
|
||||
++payload_count_;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
const oamd::FrameState& state = update.frame_state;
|
||||
ensure_tracks(state.object_count > 0u ? static_cast<int>(state.object_count) - 1 : 0);
|
||||
const std::uint32_t block_count =
|
||||
state.blocks.empty() ? 1u : static_cast<std::uint32_t>(state.blocks.size());
|
||||
for (std::uint32_t block = 0; block < block_count; ++block) {
|
||||
apply_block(state, block);
|
||||
targets(&targets_);
|
||||
std::int64_t block_offset = 0;
|
||||
std::int64_t ramp_samples = 0;
|
||||
if (block < state.blocks.size()) {
|
||||
block_offset = static_cast<std::int64_t>(state.blocks[block].block_offset_samples);
|
||||
ramp_samples = static_cast<std::int64_t>(state.blocks[block].ramp_duration_samples);
|
||||
}
|
||||
const std::int64_t coded_event =
|
||||
frame_start_sample + outer_sample_offset + block_offset;
|
||||
const Status status = schedule(targets_, coded_event, ramp_samples,
|
||||
object_delay_samples, processed_sample);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
++payload_count_;
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status OamdPositionTimeline::positions_at(std::int64_t sample,
|
||||
double positions[kTimelineObjects][3]) {
|
||||
for (int index = 0; index < kTimelineObjects; ++index) {
|
||||
const Status status = tracks_[index].position_at(sample, positions[index]);
|
||||
Status OamdPositionTimeline::positions_at(std::int64_t sample, double* positions,
|
||||
int count) {
|
||||
if (positions == nullptr || count < 0) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
|
||||
"binaural positions need a non-negative count and a buffer");
|
||||
}
|
||||
if (count > object_count_) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kOamd,
|
||||
"binaural positions requested " + std::to_string(count) +
|
||||
" objects but the timeline tracks " +
|
||||
std::to_string(object_count_));
|
||||
}
|
||||
for (int index = 0; index < count; ++index) {
|
||||
const Status status = tracks_[static_cast<std::size_t>(index)].position_at(
|
||||
sample, positions + static_cast<std::size_t>(index) * 3u);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
@@ -10,7 +11,11 @@
|
||||
|
||||
namespace joc::timeline {
|
||||
|
||||
inline constexpr std::int64_t kOamdUpdateQuantumSamples = 64;
|
||||
// The JOC binaural renderers carry one LFE plus fifteen object sources, but the
|
||||
// timeline is not tied to that product: it keeps one track per declared OAMD
|
||||
// object (bounded only by oamd::kMaxObjects) and the renderer reads as many as
|
||||
// its source layout consumes. A binaural output with a different source count
|
||||
// (for example one fed by a TrueHD decode) can ask for more tracks.
|
||||
inline constexpr int kTimelineObjects = 15;
|
||||
|
||||
struct PositionTransition {
|
||||
@@ -43,26 +48,53 @@ class OamdPositionTimeline {
|
||||
public:
|
||||
explicit OamdPositionTimeline(int object_count = kTimelineObjects);
|
||||
|
||||
// Schedules one OAMD payload. A payload parsed by parse_id11_state() carries
|
||||
// the full frame state: every position block is applied at its own offset and
|
||||
// ramp, and the track list grows to cover every declared object. The legacy
|
||||
// single-block slot view is still accepted for direct callers.
|
||||
Status submit_update(const oamd::OamdUpdate& update, std::int64_t frame_start_sample,
|
||||
std::int64_t outer_sample_offset, std::int64_t object_delay_samples,
|
||||
std::int64_t processed_sample);
|
||||
|
||||
// positions[15][3]; queries must be monotonically increasing.
|
||||
Status positions_at(std::int64_t sample, double positions[kTimelineObjects][3]);
|
||||
// positions[count][3]; queries must be monotonically increasing.
|
||||
Status positions_at(std::int64_t sample, double* positions, int count);
|
||||
|
||||
// bed 声道是固定通道:OAMD 不给位置,方位由声明的 bed 布局给出。
|
||||
void set_fixed_position(int object_index, const double position[3]);
|
||||
|
||||
// Drops the OAMD state and every transition but keeps the fixed bed positions:
|
||||
// they describe the content, not the playback position.
|
||||
void reset();
|
||||
|
||||
int object_count() const { return object_count_; }
|
||||
std::uint64_t payload_count() const { return payload_count_; }
|
||||
std::uint64_t transition_count() const { return transition_count_; }
|
||||
bool initialized() const { return initialized_; }
|
||||
|
||||
const ObjectPositionTrack& track(int index) const { return tracks_[index]; }
|
||||
const ObjectPositionTrack& track(int index) const { return tracks_[static_cast<std::size_t>(index)]; }
|
||||
|
||||
private:
|
||||
// Grows the track list so every declared OAMD object has one (the JOC
|
||||
// renderers use the first kTimelineObjects).
|
||||
void ensure_tracks(int count);
|
||||
// OAMD position state after applying one frame-state block.
|
||||
void apply_block(const oamd::FrameState& state, std::uint32_t block_index);
|
||||
// Current ADM cartesian target of every track.
|
||||
void targets(std::vector<std::array<double, 3>>* out) const;
|
||||
// Initialises from the first update or appends the changed transitions.
|
||||
Status schedule(const std::vector<std::array<double, 3>>& targets,
|
||||
std::int64_t coded_event, std::int64_t ramp_samples,
|
||||
std::int64_t object_delay_samples, std::int64_t processed_sample);
|
||||
|
||||
int object_count_;
|
||||
oamd::OamdState state_;
|
||||
ObjectPositionTrack tracks_[kTimelineObjects];
|
||||
std::vector<ObjectPositionTrack> tracks_;
|
||||
bool initialized_ = false;
|
||||
double previous_targets_[kTimelineObjects][3] = {};
|
||||
bool has_previous_[kTimelineObjects] = {};
|
||||
std::vector<std::array<double, 3>> previous_targets_;
|
||||
std::vector<bool> has_previous_;
|
||||
std::vector<bool> fixed_;
|
||||
std::vector<std::array<double, 3>> fixed_xyz_;
|
||||
std::vector<std::array<double, 3>> targets_;
|
||||
std::uint64_t payload_count_ = 0;
|
||||
std::uint64_t transition_count_ = 0;
|
||||
std::int64_t last_coded_event_sample_ = -1;
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
#include "virtual_speaker/virtual_speaker.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
#include "joc_core.h"
|
||||
|
||||
namespace joc::virtual_speaker {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr std::size_t kFrameSamples = JOC_FRAME_SAMPLES;
|
||||
constexpr std::size_t kSourceChannels = JOC_OUTPUT_CHANNELS;
|
||||
|
||||
// WAV order follows the ffmpeg layouts: 5.1 = L R C LFE BL BR,
|
||||
// 7.1 = L R C LFE BL BR SL SR.
|
||||
constexpr Layout kLayouts[] = {
|
||||
{"2.0",
|
||||
2,
|
||||
{{false, -1.0, 1.0, 0.0},
|
||||
{false, 1.0, 1.0, 0.0}}},
|
||||
{"5.1",
|
||||
6,
|
||||
{{false, -1.0, 1.0, 0.0},
|
||||
{false, 1.0, 1.0, 0.0},
|
||||
{false, 0.0, 1.0, 0.0},
|
||||
{true, 0.0, 1.0, 0.0},
|
||||
{false, -1.0, -1.0, 0.0},
|
||||
{false, 1.0, -1.0, 0.0}}},
|
||||
{"7.1",
|
||||
8,
|
||||
{{false, -1.0, 1.0, 0.0},
|
||||
{false, 1.0, 1.0, 0.0},
|
||||
{false, 0.0, 1.0, 0.0},
|
||||
{true, 0.0, 1.0, 0.0},
|
||||
{false, -1.0, -1.0, 0.0},
|
||||
{false, 1.0, -1.0, 0.0},
|
||||
{false, -1.0, 0.0, 0.0},
|
||||
{false, 1.0, 0.0, 0.0}}},
|
||||
};
|
||||
|
||||
std::int16_t q_for_axis(double value) {
|
||||
if (value <= -0.999) {
|
||||
return 0;
|
||||
}
|
||||
if (value >= 0.999) {
|
||||
return 32767;
|
||||
}
|
||||
return 16384;
|
||||
}
|
||||
|
||||
void fill_fixed_positions(const Layout& layout, oamd::OamdUpdate* update) {
|
||||
update->object_count = static_cast<std::uint32_t>(kSourceChannels);
|
||||
update->block_offset_samples = 0;
|
||||
update->ramp_duration_samples = 0;
|
||||
int slot = 1;
|
||||
for (int channel = 0; channel < layout.channels; ++channel) {
|
||||
const ChannelSpec& spec = layout.channel_specs[channel];
|
||||
const int destination = spec.lfe ? 0 : slot++;
|
||||
update->slots[destination].q1 = q_for_axis(spec.x);
|
||||
update->slots[destination].q2 = q_for_axis(-spec.y);
|
||||
update->slots[destination].q3 = q_for_axis(spec.z);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const Layout* find_layout(const std::string& name) {
|
||||
for (const Layout& layout : kLayouts) {
|
||||
if (name == layout.name) {
|
||||
return &layout;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Layout* detect_layout(int channels) {
|
||||
for (const Layout& layout : kLayouts) {
|
||||
if (layout.channels == channels) {
|
||||
return &layout;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Status Input::configure(const std::string& layout_name, int channels, double gain_db) {
|
||||
const Layout* layout =
|
||||
(layout_name.empty() || layout_name == "auto")
|
||||
? detect_layout(channels)
|
||||
: find_layout(layout_name);
|
||||
if (layout == nullptr || layout->channels != channels) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"PCM layout does not match the channel count");
|
||||
}
|
||||
layout_ = layout;
|
||||
channels_ = channels;
|
||||
gain_ = static_cast<double>(std::pow(10.0, gain_db / 20.0));
|
||||
pending_.clear();
|
||||
read_offset_ = 0;
|
||||
fill_fixed_positions(*layout_, &fixed_update_);
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
void Input::reset() {
|
||||
pending_.clear();
|
||||
read_offset_ = 0;
|
||||
}
|
||||
|
||||
Status Input::append(const float* interleaved, std::size_t frames) {
|
||||
if (interleaved == nullptr || frames == 0u) {
|
||||
return Status::success();
|
||||
}
|
||||
if (layout_ == nullptr || channels_ <= 0) {
|
||||
return Status::fail(JOC_ERR_STATE, stage::kRender,
|
||||
"virtual speaker input is not configured");
|
||||
}
|
||||
pending_.insert(pending_.end(), interleaved,
|
||||
interleaved + frames * static_cast<std::size_t>(channels_));
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
bool Input::frame_ready() const {
|
||||
return layout_ != nullptr &&
|
||||
pending_.size() - read_offset_ >=
|
||||
kFrameSamples * static_cast<std::size_t>(channels_);
|
||||
}
|
||||
|
||||
Status Input::take_frame(std::vector<float>* objects16) {
|
||||
if (objects16 == nullptr) {
|
||||
return Status::fail(JOC_ERR_INVALID_ARGUMENT, stage::kRender,
|
||||
"objects16 output is null");
|
||||
}
|
||||
if (!frame_ready()) {
|
||||
return Status::fail(JOC_ERR_STATE, stage::kRender,
|
||||
"no complete PCM frame is buffered");
|
||||
}
|
||||
objects16->assign(kSourceChannels * kFrameSamples, 0.0f);
|
||||
const float* source = pending_.data() + read_offset_;
|
||||
int slot = 1;
|
||||
for (int channel = 0; channel < layout_->channels; ++channel) {
|
||||
const int destination = layout_->channel_specs[channel].lfe ? 0 : slot++;
|
||||
for (std::size_t sample = 0; sample < kFrameSamples; ++sample) {
|
||||
(*objects16)[static_cast<std::size_t>(destination) * kFrameSamples + sample] =
|
||||
source[sample * static_cast<std::size_t>(channels_) + channel] *
|
||||
static_cast<float>(gain_);
|
||||
}
|
||||
}
|
||||
read_offset_ += kFrameSamples * static_cast<std::size_t>(channels_);
|
||||
if (read_offset_ == pending_.size()) {
|
||||
pending_.clear();
|
||||
read_offset_ = 0;
|
||||
} else if (read_offset_ >= (1u << 20)) {
|
||||
pending_.erase(pending_.begin(),
|
||||
pending_.begin() + static_cast<std::ptrdiff_t>(read_offset_));
|
||||
read_offset_ = 0;
|
||||
}
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
} // namespace joc::virtual_speaker
|
||||
@@ -0,0 +1,57 @@
|
||||
// Virtual speaker input: ordinary multichannel PCM as fixed-direction JOC
|
||||
// objects. It owns only the layout mapping and the PCM-to-objects16 shape;
|
||||
// decoding, speaker rendering and binaural rendering stay in their own modules.
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "foundation/status.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
|
||||
namespace joc::virtual_speaker {
|
||||
|
||||
struct ChannelSpec {
|
||||
bool lfe;
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
};
|
||||
|
||||
struct Layout {
|
||||
const char* name;
|
||||
int channels;
|
||||
ChannelSpec channel_specs[8];
|
||||
};
|
||||
|
||||
const Layout* find_layout(const std::string& name);
|
||||
const Layout* detect_layout(int channels);
|
||||
|
||||
class Input {
|
||||
public:
|
||||
// gain_db is the module's master attenuation; it is applied to every
|
||||
// mapped channel once, before the objects16 frame leaves the module.
|
||||
Status configure(const std::string& layout_name, int channels, double gain_db = 0.0);
|
||||
void reset();
|
||||
|
||||
const oamd::OamdUpdate& fixed_update() const { return fixed_update_; }
|
||||
int channels() const { return channels_; }
|
||||
const Layout* layout() const { return layout_; }
|
||||
|
||||
// Appends interleaved frames; take_frame() emits whole 1536-frame blocks.
|
||||
Status append(const float* interleaved, std::size_t frames);
|
||||
bool frame_ready() const;
|
||||
Status take_frame(std::vector<float>* objects16);
|
||||
|
||||
private:
|
||||
const Layout* layout_ = nullptr;
|
||||
int channels_ = 0;
|
||||
double gain_ = 1.0;
|
||||
oamd::OamdUpdate fixed_update_{};
|
||||
std::vector<float> pending_;
|
||||
std::size_t read_offset_ = 0;
|
||||
};
|
||||
|
||||
} // namespace joc::virtual_speaker
|
||||
@@ -0,0 +1,149 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <complex>
|
||||
#include <cstddef>
|
||||
|
||||
namespace rosella_test_vectors {
|
||||
struct ComplexSample {
|
||||
std::size_t index;
|
||||
std::complex<double> value;
|
||||
};
|
||||
struct RealSample {
|
||||
std::size_t index;
|
||||
double value;
|
||||
};
|
||||
|
||||
inline const std::array<ComplexSample, 45> kAnalysis = {{
|
||||
{0, {7.775565228424679e-06, 7.906356926119044e-05}},
|
||||
{1, {0.00012425227206597824, -4.6868619154722554e-05}},
|
||||
{31, {-4.138787216985311e-05, 5.162831590295054e-05}},
|
||||
{63, {-3.295086025588919e-05, -1.278928940280279e-06}},
|
||||
{64, {-3.351389443094305e-05, -0.00022684860394147635}},
|
||||
{69, {5.8879855585687005e-05, -0.0002184987979386939}},
|
||||
{127, {0.00017914426737246358, 9.642064782431324e-05}},
|
||||
{131, {0.0007132287349731125, 0.005832527881460842}},
|
||||
{175, {-0.0007411187757106858, 0.0006807654251128285}},
|
||||
{242, {-0.00614632667390274, -0.0018421222212599044}},
|
||||
{257, {0.019850879270364816, -0.006693042832175101}},
|
||||
{293, {-0.012195686344065404, -0.05921478919952099}},
|
||||
{301, {-0.002478141082434576, -0.003954837666622094}},
|
||||
{326, {-0.0025580636031437235, 0.0011174056358154022}},
|
||||
{510, {-0.017663241703992184, 0.0035507173965086524}},
|
||||
{544, {-0.008784632095067399, -0.009135393193440677}},
|
||||
{574, {-0.0009629093082367752, 0.0013287365759095497}},
|
||||
{603, {-0.0005141177077425535, 0.013385273817837683}},
|
||||
{637, {0.011278058600388273, 0.005937452476230072}},
|
||||
{643, {-0.00696332728884343, -0.004978700787364526}},
|
||||
{729, {0.0050457117591332055, 0.0016826727046474407}},
|
||||
{775, {0.003469262666915679, -0.004257569406861563}},
|
||||
{790, {-0.026299750617793667, 0.00416375313051273}},
|
||||
{856, {-0.011484924452018283, -0.00982872323688277}},
|
||||
{922, {0.012688560629388848, -0.00728168396968646}},
|
||||
{1000, {0.0011519072188212057, 0.006119400449478027}},
|
||||
{1061, {0.020940840595677954, -0.06189070534623452}},
|
||||
{1207, {0.010885743908845955, -0.006471503744246215}},
|
||||
{1431, {-0.007917589523676893, -0.004370087901858095}},
|
||||
{1458, {-0.008628466739126659, -0.0049257923325374}},
|
||||
{1511, {-0.004288762266687254, -0.0037576188137696497}},
|
||||
{1883, {0.008904981656753283, 0.004748622951092901}},
|
||||
{1985, {-0.01717853841839118, 0.033529024231708275}},
|
||||
{2009, {-0.006341206558393465, -0.0074488295721425605}},
|
||||
{2092, {0.004890829038856598, -0.0021667714905464486}},
|
||||
{2158, {0.006867229461380485, -0.0007371346599858038}},
|
||||
{2334, {-0.008248554400186915, -0.008662518985429475}},
|
||||
{2341, {-0.050888945810442746, 0.04982127826658001}},
|
||||
{2357, {-0.005734420983740394, -0.00038765299755766716}},
|
||||
{2429, {0.005443893166595231, -0.004923640532580573}},
|
||||
{2634, {0.011669730754497142, 0.020050423296197745}},
|
||||
{2779, {0.00020074872192237295, -0.006839871400930875}},
|
||||
{2955, {0.015493214930132214, 0.0018690053738887411}},
|
||||
{3008, {-0.011124416898103392, 0.006642606867866255}},
|
||||
{3071, {0.01165356921865766, -0.0044997289743379885}},
|
||||
}};
|
||||
|
||||
inline const std::array<ComplexSample, 45> kHybrid = {{
|
||||
{0, {5.868502326194375e-06, 1.7811152741480289e-06}},
|
||||
{1, {-5.4090964786860795e-06, -2.8902191018360635e-06}},
|
||||
{31, {0.0, 0.0}},
|
||||
{63, {0.0, 0.0}},
|
||||
{64, {0.0, 0.0}},
|
||||
{83, {-1.5188745949094245e-05, 9.09168380003381e-06}},
|
||||
{127, {0.0, 0.0}},
|
||||
{158, {0.00022583760103915134, -0.0004918103466920481}},
|
||||
{211, {0.0, 0.0}},
|
||||
{291, {0.0, 0.0}},
|
||||
{309, {-0.00015653046815661031, -0.0007306572668268195}},
|
||||
{353, {0.0, 0.0}},
|
||||
{362, {0.0, 0.0}},
|
||||
{392, {0.0007376543189844669, 0.00037513740947532886}},
|
||||
{614, {8.188514820841106e-06, 0.00018887636186503467}},
|
||||
{655, {-0.0002652390760717492, -0.0003838899787227982}},
|
||||
{691, {-0.0006112716629595866, -0.0002847050760692751}},
|
||||
{726, {-0.018681684150467052, 0.0024137001732511764}},
|
||||
{766, {-0.0011129045309462016, -0.0020692542444214848}},
|
||||
{774, {0.0008947778929531689, 0.0023555612398049788}},
|
||||
{878, {0.15610973092082112, 0.027180902851271033}},
|
||||
{933, {-0.0009923870793706617, -0.0004164569559879513}},
|
||||
{950, {-0.010556238335200434, -0.001222834781836447}},
|
||||
{1030, {0.012704796696902542, 0.0067623566227308024}},
|
||||
{1109, {-0.15244884147047966, -0.10978580650105556}},
|
||||
{1204, {-0.003434582532641294, 0.013677101643146762}},
|
||||
{1277, {0.002232145931138603, -0.00245876551959133}},
|
||||
{1452, {0.0013877744513344833, 0.010560167634531287}},
|
||||
{1722, {-0.008778455102118702, -0.009435079990235172}},
|
||||
{1754, {0.0008815091566413778, -0.0035065893857165464}},
|
||||
{1818, {-0.016024996427009656, 0.0034474393638554944}},
|
||||
{2265, {-0.045198220401304445, -0.10361062266400728}},
|
||||
{2388, {0.0005725894600346051, 0.0015359513917156335}},
|
||||
{2418, {-0.0019316669156428739, 0.21602300351272932}},
|
||||
{2517, {0.00201767915456565, -0.0028188485607173333}},
|
||||
{2596, {-0.00038944457447919844, 0.0015101147811087895}},
|
||||
{2809, {-0.008143911805470605, 0.01292515077837547}},
|
||||
{2817, {-0.0027510729690434243, 0.006659055212161834}},
|
||||
{2836, {-9.369629609244992e-05, -0.0026304132267606292}},
|
||||
{2922, {0.019245886198162414, -0.009431432730065513}},
|
||||
{3169, {-0.010855219707682658, 0.013010869795091879}},
|
||||
{3343, {-0.04505161077995541, -0.11044313232127823}},
|
||||
{3555, {-0.003976142798898398, -0.007486276873628099}},
|
||||
{3619, {0.00010380687898299806, 0.001843237344836469}},
|
||||
{3695, {-0.007436310982457473, -0.013161158071572683}},
|
||||
}};
|
||||
|
||||
inline const std::array<ComplexSample, 45> kFold = {{
|
||||
{0, {-2.109375, -0.71875}}, {1, {0.046875, 0.0}}, {31, {-0.09375, 0.71875}},
|
||||
{63, {0.515625, -0.359375}}, {64, {-1.03125, -0.296875}}, {69, {-0.75, 0.46875}},
|
||||
{127, {0.453125, 0.125}}, {131, {0.234375, 0.546875}}, {175, {-0.703125, 0.390625}},
|
||||
{242, {0.03125, -0.03125}}, {257, {0.625, 0.171875}}, {293, {-0.328125, -0.671875}},
|
||||
{301, {0.21875, -0.5625}}, {326, {-0.734375, -0.421875}}, {510, {-0.1875, -0.203125}},
|
||||
{544, {-0.328125, 0.25}}, {574, {-0.25, 0.28125}}, {603, {-0.140625, -0.28125}},
|
||||
{637, {-0.578125, 0.5625}}, {643, {-0.265625, -0.125}}, {729, {0.78125, 0.28125}},
|
||||
{775, {0.671875, 0.140625}}, {790, {-0.078125, 0.15625}}, {856, {0.390625, -0.46875}},
|
||||
{922, {-0.71875, 0.421875}}, {1000, {-0.21875, 0.71875}}, {1061, {0.5, 0.59375}},
|
||||
{1207, {0.421875, 0.671875}}, {1431, {-0.4375, 0.65625}}, {1458, {0.421875, 0.078125}},
|
||||
{1511, {0.59375, -0.15625}}, {1883, {0.1875, 0.3125}}, {1985, {0.1875, -0.5625}},
|
||||
{2009, {-0.46875, -0.640625}}, {2092, {-0.21875, 0.671875}}, {2158, {0.25, 0.046875}},
|
||||
{2334, {0.546875, -0.234375}}, {2341, {-0.75, -0.328125}}, {2357, {0.34375, -0.109375}},
|
||||
{2429, {-0.75, 0.484375}}, {2634, {-0.34375, -0.359375}}, {2779, {-0.6875, -0.484375}},
|
||||
{2955, {-0.390625, 0.75}}, {3008, {-0.359375, -0.59375}}, {3071, {0.734375, -0.328125}},
|
||||
}};
|
||||
|
||||
inline const std::array<RealSample, 45> kSynthesis = {{
|
||||
{0, -0.001658459165691889}, {1, 0.010948236643244243}, {31, -0.10085266025508711},
|
||||
{63, -0.003503870976352294}, {64, 0.0034821124123800007}, {69, 0.0036009386713644993},
|
||||
{127, -0.004572690451391407}, {131, -0.0968983768626099}, {175, 3.956732506047194},
|
||||
{242, -0.02213695704158057}, {257, 5.161514411138107}, {293, -2.22783403263535},
|
||||
{301, 1.658025919090119}, {326, 0.7270199192910349}, {510, 10.646246826011666},
|
||||
{544, 4.02304233235568}, {574, -1.8869149188681806}, {603, -3.6776755660477827},
|
||||
{637, 7.303828443375595}, {643, -6.429907198877739}, {729, 0.5963645962389459},
|
||||
{775, 3.801043327575303}, {790, -31.546778942872983}, {856, -0.16830000749121746},
|
||||
{922, -2.2137404260494975}, {1000, 0.24234450303821295}, {1061, 0.13427657788640274},
|
||||
{1207, -7.446434384896017}, {1431, -5.137441688406155}, {1458, -6.380668393736482},
|
||||
{1511, -5.013969777723457}, {1883, -6.706452727886115}, {1985, 9.437019480312102},
|
||||
{2009, -7.787276846635089}, {2092, -1.285900598190846}, {2158, -9.98553088525826},
|
||||
{2334, 0.621609996592438}, {2341, 4.2410850082140366}, {2357, 0.7274497164538002},
|
||||
{2429, 4.407873764785114}, {2634, -5.023050721472806}, {2779, -0.7007366475135158},
|
||||
{2955, 4.26452198462612}, {3008, 4.390815174418314}, {3071, -13.869120688929403},
|
||||
}};
|
||||
|
||||
}
|
||||
+1898
-258
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,437 @@
|
||||
// State-only checks of the OAMD parser, ported from tests/oamd_metadata_test.py.
|
||||
// The speaker-renderer targets are covered by the speaker tests; this file keeps
|
||||
// the bitstream expansion, formula tables and programme parsing checks.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "oamd/oamd_params.h"
|
||||
#include "oamd/oamd_parser.h"
|
||||
|
||||
namespace {
|
||||
|
||||
int failures = 0;
|
||||
|
||||
void check(bool passed, const char* name) {
|
||||
if (!passed) {
|
||||
std::fprintf(stderr, "FAIL: %s\n", name);
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> from_hex(const char* text) {
|
||||
std::vector<std::uint8_t> bytes;
|
||||
const std::size_t length = std::strlen(text);
|
||||
for (std::size_t index = 0; index + 1 < length; index += 2) {
|
||||
const auto high = static_cast<unsigned>(text[index]);
|
||||
const auto low = static_cast<unsigned>(text[index + 1]);
|
||||
const auto digit = [](unsigned value) -> unsigned {
|
||||
if (value >= '0' && value <= '9') {
|
||||
return value - '0';
|
||||
}
|
||||
if (value >= 'a' && value <= 'f') {
|
||||
return value - 'a' + 10;
|
||||
}
|
||||
if (value >= 'A' && value <= 'F') {
|
||||
return value - 'A' + 10;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
bytes.push_back(static_cast<std::uint8_t>((digit(high) << 4) | digit(low)));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
joc::oamd::OamdUpdate parse_state(const char* hex) {
|
||||
const std::vector<std::uint8_t> payload = from_hex(hex);
|
||||
joc::oamd::OamdUpdate update;
|
||||
const joc::Status status =
|
||||
joc::oamd::parse_id11_state(payload.data(), payload.size(), &update);
|
||||
check(status.ok(), "parse_id11_state succeeds");
|
||||
if (!status.ok()) {
|
||||
std::fprintf(stderr, " %s: %s\n", hex, status.message().c_str());
|
||||
}
|
||||
return update;
|
||||
}
|
||||
|
||||
const joc::oamd::ObjectRenderState& block0(const joc::oamd::OamdUpdate& update,
|
||||
int object) {
|
||||
return update.frame_state.objects[static_cast<std::size_t>(object)]
|
||||
.blocks[0]
|
||||
.render;
|
||||
}
|
||||
|
||||
// Two object blocks in one object element: block 0 is a full update, block 1 is
|
||||
// an inactive block. Ported from test_multiblock_state_expansion.
|
||||
void test_multiblock_state_expansion() {
|
||||
const joc::oamd::OamdUpdate update = parse_state("0104600800450132831d6a00");
|
||||
check(update.has_frame_state, "frame state present");
|
||||
check(update.frame_state.object_count == 1, "one object");
|
||||
check(update.frame_state.block_count == 2, "two blocks");
|
||||
check(update.frame_state.objects.size() == 1, "one object state");
|
||||
check(update.frame_state.objects[0].blocks.size() == 2, "two object blocks");
|
||||
const joc::oamd::ObjectRenderState& first = block0(update, 0);
|
||||
check(first.gain_q == 23033, "block 0 gain_q");
|
||||
check(first.priority_q == 32767, "block 0 priority_q");
|
||||
check(first.qx == 6342 && first.qy == 21141 && first.qz == -13107, "block 0 position");
|
||||
check(first.zone_idx == 3 && first.enable_elevation, "block 0 zone/elevation");
|
||||
check(first.size_mode == 1, "block 0 size mode");
|
||||
check(first.snap, "block 0 snap");
|
||||
const joc::oamd::ObjectRenderState& second =
|
||||
update.frame_state.objects[0].blocks[1].render;
|
||||
// The second block is active but carries basic_status 0: no gain update.
|
||||
check(!second.not_active, "block 1 active");
|
||||
check(second.gain_q == 0 && second.priority_q == 0, "block 1 gain/priority");
|
||||
check(second.qx == 16384 && second.qy == 16384 && second.qz == 0,
|
||||
"block 1 default position");
|
||||
}
|
||||
|
||||
// Two objects with three blocks: the first object's block 1 is inactive, the
|
||||
// second is a full update. Ported from test_multiblock_gain_inheritance.
|
||||
void test_multiblock_gain_inheritance() {
|
||||
const joc::oamd::OamdUpdate update =
|
||||
parse_state("038474100040850146527514c0407c3e00");
|
||||
check(update.frame_state.objects.size() == 2, "two objects");
|
||||
check(update.frame_state.block_count == 3, "three blocks");
|
||||
const std::int32_t expected_gain[3] = {23033, 0, 2052};
|
||||
for (int block = 0; block < 3; ++block) {
|
||||
check(update.frame_state.objects[0].blocks[static_cast<std::size_t>(block)]
|
||||
.render.gain_q == expected_gain[block],
|
||||
"first object gain inheritance");
|
||||
check(update.frame_state.objects[1].blocks[static_cast<std::size_t>(block)]
|
||||
.render.gain_q == expected_gain[block],
|
||||
"second object gain inheritance");
|
||||
}
|
||||
check(update.frame_state.objects[0].blocks[1].render.not_active,
|
||||
"first object block 1 inactive");
|
||||
check(!update.frame_state.objects[1].blocks[1].render.not_active,
|
||||
"second object block 1 active");
|
||||
for (int block = 0; block < 3; ++block) {
|
||||
check(update.frame_state.objects[0].blocks[static_cast<std::size_t>(block)]
|
||||
.render.qx == 16384,
|
||||
"first object holds centre x");
|
||||
check(update.frame_state.objects[1].blocks[static_cast<std::size_t>(block)]
|
||||
.render.qx == 10570,
|
||||
"second object x");
|
||||
}
|
||||
}
|
||||
|
||||
// gain_idx 0/1/2: unity, mute and the 6-bit dB table.
|
||||
void test_gain_formula() {
|
||||
check(block0(parse_state("010458000501514C0400"), 0).gain_q == 23033, "gain bits 0");
|
||||
check(block0(parse_state("01045800057F514C0400"), 0).gain_q == 14, "gain bits 63");
|
||||
check(block0(parse_state("0104540004D4530100"), 0).gain_q == 0, "gain mute");
|
||||
}
|
||||
|
||||
// size_idx 1/2: isotropic and per-axis Q15 sizes.
|
||||
void test_size_formula() {
|
||||
const joc::oamd::OamdUpdate size16 = parse_state("01045800045453016000");
|
||||
check(block0(size16, 0).size_mode == 1, "size mode 1");
|
||||
check(block0(size16, 0).size_q[0] == 16913, "size value 16");
|
||||
check(block0(size16, 0).size_q[1] == 16913 && block0(size16, 0).size_q[2] == 16913,
|
||||
"isotropic size");
|
||||
const joc::oamd::OamdUpdate size31 = parse_state("01045800045453017E00");
|
||||
check(block0(size31, 0).size_q[0] == 32767, "size value 31");
|
||||
const joc::oamd::OamdUpdate size2 = parse_state("01045C00045453018AAA00");
|
||||
check(block0(size2, 0).size_mode == 2, "size mode 2");
|
||||
check(block0(size2, 0).size_q[0] == 5285 && block0(size2, 0).size_q[1] == 10570 &&
|
||||
block0(size2, 0).size_q[2] == 21141,
|
||||
"per-axis size");
|
||||
}
|
||||
|
||||
// Position quantisation, zone/snap, elevation flag and signed z.
|
||||
void test_position_formula() {
|
||||
const joc::oamd::OamdUpdate base = parse_state("010454000454530100");
|
||||
check(block0(base, 0).qx == 10570 && block0(base, 0).qy == 10570 &&
|
||||
block0(base, 0).qz == 17476,
|
||||
"coarse position");
|
||||
check(block0(base, 0).enable_elevation, "elevation enabled");
|
||||
check(block0(base, 0).zone_idx == 0, "zone 0");
|
||||
|
||||
const joc::oamd::OamdUpdate zone = parse_state("0104540004420A0B10");
|
||||
check(block0(zone, 0).qx == 1057 && block0(zone, 0).qy == 1057 && block0(zone, 0).qz == 0,
|
||||
"zone position");
|
||||
check(block0(zone, 0).zone_idx == 5, "zone index");
|
||||
check(block0(zone, 0).snap, "snap flag");
|
||||
|
||||
const joc::oamd::OamdUpdate height = parse_state("010454000454530000");
|
||||
check(!block0(height, 0).enable_elevation, "elevation disabled");
|
||||
|
||||
const joc::oamd::OamdUpdate negative = parse_state("010454000454510100");
|
||||
check(block0(negative, 0).qz == -17476, "signed elevation");
|
||||
}
|
||||
|
||||
// Extended object element position refinement.
|
||||
void test_refinement() {
|
||||
const joc::oamd::OamdUpdate update = parse_state("010854000454530100A23E00");
|
||||
check(block0(update, 0).qx == 10676, "refined x");
|
||||
check(block0(update, 0).qy == 10676, "refined y");
|
||||
check(block0(update, 0).qz == 17913, "refined z");
|
||||
}
|
||||
|
||||
// Extended object element divergence table.
|
||||
void test_divergence() {
|
||||
check(block0(parse_state("010854000454530100A27400"), 0).divergence_q == 11548,
|
||||
"divergence table value 32");
|
||||
check(block0(parse_state("010854000454530100A277E0"), 0).divergence_q == 16384,
|
||||
"divergence table value 63");
|
||||
}
|
||||
|
||||
// Programme assignment: bed labels, ISF index, masks and distribution flag.
|
||||
void test_program_assignment() {
|
||||
const joc::oamd::OamdUpdate lfe = parse_state("018448000440");
|
||||
check(lfe.frame_state.program.dynamic_object_only, "dynamic object only");
|
||||
check(lfe.frame_state.program.lfe_present, "lfe present");
|
||||
check(lfe.frame_state.program.num_bed_objects == 1, "one bed object");
|
||||
check(lfe.frame_state.program.bed_labels.size() == 1 &&
|
||||
lfe.frame_state.program.bed_labels[0] == joc::joc::BedChannel::kLfe,
|
||||
"lfe bed label");
|
||||
check(lfe.frame_state.program.bed_mask == 0x8u, "lfe bed mask");
|
||||
check(lfe.frame_state.objects[0].kind == joc::oamd::ObjectKind::kBed, "bed object kind");
|
||||
check(block0(lfe, 0).qx == 16384 && block0(lfe, 0).qy == 16384 && block0(lfe, 0).qz == 0,
|
||||
"bed object holds centre");
|
||||
|
||||
const joc::oamd::OamdUpdate isf = parse_state("062011400011084200");
|
||||
check(isf.frame_state.object_count == 4, "isf object count");
|
||||
check(isf.frame_state.program.isf_idx == 0, "isf index");
|
||||
check(isf.frame_state.program.num_isf_objects == 4, "isf object number");
|
||||
for (int index = 0; index < 4; ++index) {
|
||||
check(isf.frame_state.objects[static_cast<std::size_t>(index)].kind ==
|
||||
joc::oamd::ObjectKind::kIsf,
|
||||
"isf object kind");
|
||||
}
|
||||
|
||||
const joc::oamd::OamdUpdate standard = parse_state("021100422600022100");
|
||||
check(standard.frame_state.program.num_bed_objects == 2, "standard bed object number");
|
||||
check(standard.frame_state.program.bed_mask == 0x3u, "standard bed wide mask");
|
||||
check(standard.frame_state.program.bed_labels.size() == 2 &&
|
||||
standard.frame_state.program.bed_labels[0] == joc::joc::BedChannel::kLeft &&
|
||||
standard.frame_state.program.bed_labels[1] == joc::joc::BedChannel::kRight,
|
||||
"standard bed labels");
|
||||
|
||||
const joc::oamd::OamdUpdate nonstandard = parse_state("001000800448000440");
|
||||
check(nonstandard.frame_state.program.num_bed_objects == 1, "non-standard bed number");
|
||||
check(nonstandard.frame_state.program.bed_mask == 0x100u, "non-standard bed mask");
|
||||
check(nonstandard.frame_state.program.bed_labels.size() == 1 &&
|
||||
nonstandard.frame_state.program.bed_labels[0] ==
|
||||
joc::joc::BedChannel::kTopFrontLeft,
|
||||
"non-standard bed label");
|
||||
check(!nonstandard.frame_state.program.b_bed_chan_distribute, "distribution off");
|
||||
|
||||
const joc::oamd::OamdUpdate distributed = parse_state("001800800448000440");
|
||||
check(distributed.frame_state.program.b_bed_chan_distribute, "distribution on");
|
||||
}
|
||||
|
||||
// The parsed bed declaration keeps its expanded channels for the ADM check.
|
||||
void test_bed_assignments() {
|
||||
const std::vector<std::uint8_t> payload = from_hex("021100422600022100");
|
||||
std::vector<joc::oamd::BedAssignment> assignments;
|
||||
check(joc::oamd::parse_id11_bed_assignments(payload.data(), payload.size(),
|
||||
&assignments)
|
||||
.ok(),
|
||||
"bed assignment parse");
|
||||
check(assignments.size() == 1, "one assignment");
|
||||
check(assignments[0].standard && !assignments[0].lfe_only, "standard assignment");
|
||||
check(assignments[0].channels.size() == 2 &&
|
||||
assignments[0].channels[0] == joc::joc::BedChannel::kLeft &&
|
||||
assignments[0].channels[1] == joc::joc::BedChannel::kRight,
|
||||
"assignment channels");
|
||||
}
|
||||
|
||||
// Legacy frame_update() view: 16 slots from block 0, >16 objects and multi-block
|
||||
// frames stay rejected; the full state accepts both.
|
||||
void test_legacy_view() {
|
||||
const std::vector<std::uint8_t> base_payload = from_hex("010454000454530100");
|
||||
joc::oamd::OamdUpdate legacy;
|
||||
check(joc::oamd::parse_id11(base_payload.data(), base_payload.size(), &legacy).ok(),
|
||||
"legacy parse");
|
||||
check(legacy.has_frame_state, "legacy carries frame state");
|
||||
check(legacy.frame_state.block_count == 1, "legacy block count");
|
||||
check(legacy.frame_state.blocks[0].block_offset_samples == 0 &&
|
||||
legacy.frame_state.blocks[0].ramp_duration_samples == 0,
|
||||
"legacy block timing");
|
||||
check(legacy.slots[0].q1 == 10570 && legacy.slots[0].q2 == 10570 &&
|
||||
legacy.slots[0].q3 == 17476,
|
||||
"legacy slot position");
|
||||
check(legacy.slots[1].q1 == -1 && legacy.slots[1].q2 == -1 && legacy.slots[1].q3 == -1,
|
||||
"legacy unused slot hold");
|
||||
|
||||
// The legacy slot view never publishes a negative elevation.
|
||||
const std::vector<std::uint8_t> negative = from_hex("010454000454510100");
|
||||
check(joc::oamd::parse_id11(negative.data(), negative.size(), &legacy).ok(),
|
||||
"negative legacy parse");
|
||||
check(legacy.slots[0].q3 == 0, "legacy negative z clamps to side");
|
||||
|
||||
const std::vector<std::uint8_t> elevation_off = from_hex("010454000454530000");
|
||||
check(joc::oamd::parse_id11(elevation_off.data(), elevation_off.size(), &legacy).ok(),
|
||||
"elevation-off legacy parse");
|
||||
check(legacy.slots[0].q3 == 0, "legacy elevation flag zeroes z");
|
||||
|
||||
// Bed objects have no position field: the slot keeps the previous position.
|
||||
const std::vector<std::uint8_t> bed = from_hex("018448000440");
|
||||
check(joc::oamd::parse_id11(bed.data(), bed.size(), &legacy).ok(), "bed legacy parse");
|
||||
check(legacy.slots[0].q1 == -1 && legacy.slots[0].q2 == -1 && legacy.slots[0].q3 == -1,
|
||||
"legacy bed slot holds");
|
||||
|
||||
const std::vector<std::uint8_t> multiblock = from_hex("0104600800450132831d6a00");
|
||||
const joc::Status legacy_status =
|
||||
joc::oamd::parse_id11(multiblock.data(), multiblock.size(), &legacy);
|
||||
check(!legacy_status.ok() &&
|
||||
legacy_status.code() == JOC_ERR_OAMD_UNSUPPORTED_VARIANT,
|
||||
"legacy rejects multiple blocks");
|
||||
|
||||
const char* many_objects_hex =
|
||||
"21044E600022A29808054530100A8A60201514C0402A29808054530100A8A60201514C040"
|
||||
"2A29808054530100A8A60201514C0402A29808054530100A8A60201514C0402A2980800";
|
||||
const std::vector<std::uint8_t> many_objects = from_hex(many_objects_hex);
|
||||
const joc::Status many_legacy =
|
||||
joc::oamd::parse_id11(many_objects.data(), many_objects.size(), &legacy);
|
||||
check(!many_legacy.ok() && many_legacy.code() == JOC_ERR_OAMD_UNSUPPORTED_VARIANT,
|
||||
"legacy rejects more than 16 objects");
|
||||
joc::oamd::OamdUpdate many;
|
||||
check(joc::oamd::parse_id11_state(many_objects.data(), many_objects.size(), &many).ok(),
|
||||
"full state accepts more than 16 objects");
|
||||
check(many.frame_state.object_count == 17, "full state object count");
|
||||
check(many.frame_state.objects.size() == 17, "full state expands every object");
|
||||
}
|
||||
|
||||
// Optional position fields must be consumed exactly: distance, screen reference
|
||||
// and the priority mask.
|
||||
void test_optional_fields() {
|
||||
const joc::oamd::OamdUpdate distance = parse_state("0304680004545313880D45301000");
|
||||
check(distance.frame_state.object_count == 2, "distance payload object count");
|
||||
check(block0(distance, 0).qx == 10570, "distance payload keeps alignment");
|
||||
check(block0(distance, 1).gain_q == 0, "distance payload second object");
|
||||
|
||||
const joc::oamd::OamdUpdate infinity = parse_state("010454000454531880");
|
||||
check(block0(infinity, 0).qz == 17476, "infinite distance keeps alignment");
|
||||
|
||||
const joc::oamd::OamdUpdate screen = parse_state("01045800045453013600");
|
||||
check(block0(screen, 0).qx == 10570 && block0(screen, 0).snap == false,
|
||||
"screen reference keeps alignment");
|
||||
|
||||
const joc::oamd::OamdUpdate priority = parse_state("03046800043EA29808000A298080");
|
||||
check(block0(priority, 0).priority_q == 31744, "priority bits");
|
||||
check(block0(priority, 1).priority_q == 0, "priority zero");
|
||||
|
||||
const joc::oamd::OamdUpdate inactive = parse_state("010448000600");
|
||||
check(block0(inactive, 0).not_active, "inactive object");
|
||||
check(block0(inactive, 0).gain_q == 0 && block0(inactive, 0).priority_q == 0,
|
||||
"inactive gain/priority");
|
||||
check(block0(inactive, 0).qx == 16384 && block0(inactive, 0).qy == 16384 &&
|
||||
block0(inactive, 0).qz == 0,
|
||||
"inactive default position");
|
||||
}
|
||||
|
||||
// The compiled-in ISF tables must be complete: six configurations, twelve
|
||||
// layout descriptors, four layout groups, 73 paired column flags, and exact
|
||||
// matrix coefficients.
|
||||
void test_metadata_params() {
|
||||
const joc::oamd::MetadataParams* params = joc::oamd::metadata_params();
|
||||
check(params != nullptr, "metadata params");
|
||||
if (params == nullptr) {
|
||||
std::fprintf(stderr, " %s\n", joc::oamd::metadata_params_error());
|
||||
return;
|
||||
}
|
||||
check(params->configs.size() == 6, "six ISF configurations");
|
||||
check(params->layouts.size() == 12, "twelve ISF layout descriptors");
|
||||
check(!params->layout_groups.floor_a.empty() && !params->layout_groups.floor_b.empty() &&
|
||||
!params->layout_groups.height.empty() &&
|
||||
!params->layout_groups.additional.empty(),
|
||||
"four layout groups");
|
||||
check(!params->paired_columns.empty(), "paired column flags");
|
||||
for (const joc::oamd::IsfConfig& config : params->configs) {
|
||||
check(config.counts[4] == static_cast<int>(config.primary_row_map.size()),
|
||||
"isf row count");
|
||||
// Every configuration stores its basis with a 73-column row stride.
|
||||
check(config.matrix.size() ==
|
||||
static_cast<std::size_t>(config.counts[4]) * 73u,
|
||||
"isf matrix size");
|
||||
}
|
||||
const joc::oamd::IsfLayout* layout20 = params->layout("20");
|
||||
const joc::oamd::IsfLayout* layout916 = params->layout("916");
|
||||
check(layout20 != nullptr && layout20->output_count == 2 &&
|
||||
layout20->compensation_value == -4.5,
|
||||
"2.0 layout descriptor");
|
||||
check(layout916 != nullptr && layout916->output_count == 16 &&
|
||||
layout916->compensation_value == 0.0,
|
||||
"9.1.6 layout descriptor");
|
||||
check(params->layout("60") != nullptr && params->layout("60")->output_count == 6 &&
|
||||
params->layout("60")->compensation_value == -1.5,
|
||||
"6.0 layout descriptor");
|
||||
check(!params->layout("unknown"), "unknown layout descriptor");
|
||||
|
||||
// Exact table contents: the config counts and the first coefficients pin
|
||||
// the reference data, and the row/column structure follows from them.
|
||||
const joc::oamd::IsfConfig& first = params->configs[0];
|
||||
check(first.counts[0] == 3 && first.counts[1] == 1 && first.counts[2] == 0 &&
|
||||
first.counts[3] == 0 && first.counts[4] == 4,
|
||||
"first config counts");
|
||||
check(first.matrix.size() == 4u * 73u && first.matrix[0] == 0.806554496f &&
|
||||
first.matrix[1] == 0.55179733f && first.matrix[15] == -0.280463845f,
|
||||
"first config coefficients");
|
||||
check(first.primary_row_map.size() == 4 && first.primary_row_map[3] == 3 &&
|
||||
first.secondary_row_map.size() == 4 && first.secondary_row_map[3] == 3,
|
||||
"first config row maps");
|
||||
const joc::oamd::IsfConfig& last = params->configs[5];
|
||||
check(last.counts[0] == 15 && last.counts[1] == 9 && last.counts[2] == 5 &&
|
||||
last.counts[3] == 1 && last.counts[4] == 30 &&
|
||||
last.matrix.size() == 30u * 73u,
|
||||
"last config shape");
|
||||
|
||||
check(params->layout("20")->output_ids.size() == 37 &&
|
||||
params->layout("20")->output_ids[0] == 0 &&
|
||||
params->layout("20")->output_ids[1] == 1 &&
|
||||
params->layout("20")->output_ids[2] == 0,
|
||||
"layout output ids");
|
||||
check(params->layout_groups.floor_a.size() == 6 &&
|
||||
params->layout_groups.floor_b.size() == 7 &&
|
||||
params->layout_groups.height.size() == 6 &&
|
||||
params->layout_groups.additional.size() == 5,
|
||||
"layout group sizes");
|
||||
check(params->layout_groups.floor_a[1].selector == 1 &&
|
||||
params->layout_groups.floor_a[1].begin == 1 &&
|
||||
params->layout_groups.floor_a[1].end == 3,
|
||||
"layout group record");
|
||||
const std::size_t paired = static_cast<std::size_t>(
|
||||
std::count(params->paired_columns.begin(), params->paired_columns.end(), true));
|
||||
check(params->paired_columns.size() == 73 && paired == 67, "paired column flags");
|
||||
}
|
||||
|
||||
// q_of is the reference's Q15 quantiser.
|
||||
void test_q_of() {
|
||||
check(joc::oamd::q_of(0, 62) == 0, "q_of 0");
|
||||
check(joc::oamd::q_of(62, 62) == 32767, "q_of max");
|
||||
check(joc::oamd::q_of(31, 62) == 16384, "q_of centre");
|
||||
check(joc::oamd::q_of(15, 15) == 32767, "q_of z max");
|
||||
check(joc::oamd::q_of(20, 62) == 10570, "q_of 20/62");
|
||||
check(joc::oamd::q_of(8, 15) == 17476, "q_of 8/15");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
test_multiblock_state_expansion();
|
||||
test_multiblock_gain_inheritance();
|
||||
test_gain_formula();
|
||||
test_size_formula();
|
||||
test_position_formula();
|
||||
test_refinement();
|
||||
test_divergence();
|
||||
test_program_assignment();
|
||||
test_bed_assignments();
|
||||
test_legacy_view();
|
||||
test_optional_fields();
|
||||
test_metadata_params();
|
||||
test_q_of();
|
||||
if (failures != 0) {
|
||||
std::fprintf(stderr, "%d OAMD metadata check(s) failed\n", failures);
|
||||
return 1;
|
||||
}
|
||||
std::printf("OAMD metadata checks passed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "hrtf/public_filterbank.h"
|
||||
#include "hrtf/rosella_bank.h"
|
||||
#include "hrtf/rosella_filterbank.h"
|
||||
#include "rosella_filterbank_vectors.h"
|
||||
|
||||
namespace {
|
||||
|
||||
int failures = 0;
|
||||
|
||||
void check(bool passed, const char* name) {
|
||||
if (!passed) {
|
||||
std::fprintf(stderr, "FAIL: %s\n", name);
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
|
||||
using joc::hrtf::Complex;
|
||||
using joc::hrtf::PublicFilterbank;
|
||||
using joc::hrtf::RosellaBank;
|
||||
using joc::hrtf::RosellaBankKind;
|
||||
using joc::hrtf::RosellaFilterbank;
|
||||
|
||||
template <typename Value, typename Expected>
|
||||
void check_samples(const std::vector<Value>& actual, const Expected& expected, const char* name) {
|
||||
for (const auto& sample : expected) {
|
||||
check(std::abs(actual.at(sample.index) - sample.value) < 1e-10, name);
|
||||
}
|
||||
}
|
||||
|
||||
void test_reference_and_streaming() {
|
||||
constexpr std::size_t slots = 24;
|
||||
constexpr std::size_t channels = 2;
|
||||
std::vector<double> input(slots * channels * 64);
|
||||
for (std::size_t index = 0; index < input.size(); ++index) {
|
||||
input[index] = (static_cast<int>((index * 37 + 11) % 257) - 128) / 128.0;
|
||||
}
|
||||
RosellaFilterbank bank(channels);
|
||||
std::vector<Complex> qmf, hybrid, folded;
|
||||
std::vector<double> time;
|
||||
bank.analyze_qmf(input, slots, &qmf);
|
||||
bank.analyze_hybrid(qmf, slots, &hybrid);
|
||||
check_samples(qmf, rosella_test_vectors::kAnalysis, "analysis reference");
|
||||
check_samples(hybrid, rosella_test_vectors::kHybrid, "hybrid reference");
|
||||
|
||||
std::vector<Complex> synthetic(slots * channels * 77);
|
||||
for (std::size_t index = 0; index < synthetic.size(); ++index) {
|
||||
synthetic[index] = Complex((static_cast<int>((index * 17 + 3) % 101) - 50) / 64.0,
|
||||
(static_cast<int>((index * 13 + 7) % 97) - 48) / 64.0);
|
||||
}
|
||||
bank.synthesize_hybrid(synthetic, slots, &folded);
|
||||
bank.synthesize_qmf(folded, slots, &time);
|
||||
check_samples(folded, rosella_test_vectors::kFold, "fold reference");
|
||||
check_samples(time, rosella_test_vectors::kSynthesis, "synthesis reference");
|
||||
|
||||
for (int repeat = 0; repeat < 2; ++repeat) {
|
||||
bank.reset();
|
||||
std::vector<Complex> joined_qmf, joined_hybrid, joined_folded;
|
||||
std::vector<double> joined_time;
|
||||
std::size_t first = 0;
|
||||
for (const std::size_t count : {0u, 1u, 7u, 0u, 3u, 13u}) {
|
||||
std::vector<double> part_input(input.begin() + first * channels * 64,
|
||||
input.begin() + (first + count) * channels * 64);
|
||||
std::vector<Complex> part_synthetic(synthetic.begin() + first * channels * 77,
|
||||
synthetic.begin() +
|
||||
(first + count) * channels * 77);
|
||||
std::vector<Complex> part_qmf, part_hybrid, part_folded;
|
||||
std::vector<double> part_time;
|
||||
bank.analyze_qmf(part_input, count, &part_qmf);
|
||||
bank.analyze_hybrid(part_qmf, count, &part_hybrid);
|
||||
bank.synthesize_hybrid(part_synthetic, count, &part_folded);
|
||||
bank.synthesize_qmf(part_folded, count, &part_time);
|
||||
joined_qmf.insert(joined_qmf.end(), part_qmf.begin(), part_qmf.end());
|
||||
joined_hybrid.insert(joined_hybrid.end(), part_hybrid.begin(), part_hybrid.end());
|
||||
joined_folded.insert(joined_folded.end(), part_folded.begin(), part_folded.end());
|
||||
joined_time.insert(joined_time.end(), part_time.begin(), part_time.end());
|
||||
first += count;
|
||||
}
|
||||
check(joined_qmf == qmf, "analysis chunk/reset invariance");
|
||||
check(joined_hybrid == hybrid, "hybrid chunk/reset invariance");
|
||||
check(joined_folded == folded, "fold chunk/reset invariance");
|
||||
check(joined_time == time, "synthesis chunk/reset invariance");
|
||||
}
|
||||
|
||||
for (std::size_t channel = 0; channel < channels; ++channel) {
|
||||
RosellaFilterbank mono(1);
|
||||
std::vector<double> mono_input;
|
||||
for (std::size_t slot = 0; slot < slots; ++slot) {
|
||||
const auto first = input.begin() + (slot * channels + channel) * 64;
|
||||
mono_input.insert(mono_input.end(), first, first + 64);
|
||||
}
|
||||
std::vector<Complex> mono_qmf, mono_hybrid;
|
||||
mono.analyze_qmf(mono_input, slots, &mono_qmf);
|
||||
mono.analyze_hybrid(mono_qmf, slots, &mono_hybrid);
|
||||
for (std::size_t slot = 0; slot < slots; ++slot) {
|
||||
check(std::equal(mono_hybrid.begin() + slot * 77, mono_hybrid.begin() + (slot + 1) * 77,
|
||||
hybrid.begin() + (slot * channels + channel) * 77),
|
||||
"channel isolation");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_latency() {
|
||||
RosellaFilterbank bank(1);
|
||||
std::vector<double> impulse(64 * 64);
|
||||
impulse[0] = 1.0;
|
||||
std::vector<Complex> qmf, hybrid;
|
||||
std::vector<double> output;
|
||||
bank.analyze_qmf(impulse, 64, &qmf);
|
||||
bank.analyze_hybrid(qmf, 64, &hybrid);
|
||||
bank.synthesize_hybrid(hybrid, 64, &qmf);
|
||||
bank.synthesize_qmf(qmf, 64, &output);
|
||||
const auto peak = std::max_element(output.begin(), output.end(), [](double left, double right) {
|
||||
return std::abs(left) < std::abs(right);
|
||||
});
|
||||
check(peak - output.begin() == RosellaFilterbank::kLatencySamples, "roundtrip latency");
|
||||
check(std::abs(*peak - 0.999989847495873) < 1e-10, "roundtrip gain");
|
||||
}
|
||||
|
||||
// One pass of the four half-steps, split into the given slot counts; the
|
||||
// concatenation is what a single call with the total count produces.
|
||||
struct BankTrace {
|
||||
std::vector<Complex> qmf;
|
||||
std::vector<Complex> hybrid;
|
||||
std::vector<Complex> folded;
|
||||
std::vector<double> time;
|
||||
};
|
||||
|
||||
BankTrace run_bank(RosellaBank& bank, const std::vector<double>& hops,
|
||||
const std::vector<Complex>& synthetic, const std::vector<std::size_t>& chunks,
|
||||
std::size_t channels) {
|
||||
BankTrace trace;
|
||||
std::size_t first = 0;
|
||||
for (const std::size_t count : chunks) {
|
||||
const std::vector<double> part_hops(hops.begin() + first * channels * 64,
|
||||
hops.begin() + (first + count) * channels * 64);
|
||||
const std::vector<Complex> part_synthetic(
|
||||
synthetic.begin() + first * channels * 77,
|
||||
synthetic.begin() + (first + count) * channels * 77);
|
||||
std::vector<Complex> qmf, hybrid, folded;
|
||||
std::vector<double> time;
|
||||
bank.analyze_qmf(part_hops, count, &qmf);
|
||||
bank.analyze_hybrid(qmf, count, &hybrid);
|
||||
bank.synthesize_hybrid(part_synthetic, count, &folded);
|
||||
bank.synthesize_qmf(folded, count, &time);
|
||||
trace.qmf.insert(trace.qmf.end(), qmf.begin(), qmf.end());
|
||||
trace.hybrid.insert(trace.hybrid.end(), hybrid.begin(), hybrid.end());
|
||||
trace.folded.insert(trace.folded.end(), folded.begin(), folded.end());
|
||||
trace.time.insert(trace.time.end(), time.begin(), time.end());
|
||||
first += count;
|
||||
}
|
||||
return trace;
|
||||
}
|
||||
|
||||
bool same_trace(const BankTrace& left, const BankTrace& right) {
|
||||
return left.qmf == right.qmf && left.hybrid == right.hybrid &&
|
||||
left.folded == right.folded && left.time == right.time;
|
||||
}
|
||||
|
||||
void test_bank_selection() {
|
||||
constexpr std::size_t slots = 24;
|
||||
constexpr std::size_t channels = 2;
|
||||
std::vector<double> hops(slots * channels * 64);
|
||||
for (std::size_t index = 0; index < hops.size(); ++index) {
|
||||
hops[index] = (static_cast<int>((index * 37 + 11) % 257) - 128) / 128.0;
|
||||
}
|
||||
std::vector<Complex> synthetic(slots * channels * 77);
|
||||
for (std::size_t index = 0; index < synthetic.size(); ++index) {
|
||||
synthetic[index] = Complex((static_cast<int>((index * 17 + 3) % 101) - 50) / 64.0,
|
||||
(static_cast<int>((index * 13 + 7) % 97) - 48) / 64.0);
|
||||
}
|
||||
|
||||
// The selector is only a choice of implementation: each kind must reproduce
|
||||
// exactly what its own class computes, and the two banks must stay separate.
|
||||
std::vector<Complex> public_hybrid;
|
||||
std::vector<Complex> captured_hybrid;
|
||||
for (const RosellaBankKind kind : {RosellaBankKind::Public, RosellaBankKind::Captured}) {
|
||||
std::vector<Complex> direct_qmf, direct_hybrid;
|
||||
if (kind == RosellaBankKind::Public) {
|
||||
PublicFilterbank bank(joc::hrtf::builtin_kernels(), channels);
|
||||
bank.analyze_qmf(hops, slots, &direct_qmf);
|
||||
bank.analyze_hybrid(direct_qmf, slots, &direct_hybrid);
|
||||
} else {
|
||||
RosellaFilterbank bank(channels);
|
||||
bank.analyze_qmf(hops, slots, &direct_qmf);
|
||||
bank.analyze_hybrid(direct_qmf, slots, &direct_hybrid);
|
||||
}
|
||||
std::unique_ptr<RosellaBank> selected = RosellaBank::create(kind, channels);
|
||||
std::vector<Complex> selected_qmf, selected_hybrid;
|
||||
selected->analyze_qmf(hops, slots, &selected_qmf);
|
||||
selected->analyze_hybrid(selected_qmf, slots, &selected_hybrid);
|
||||
check(selected_qmf == direct_qmf, "selector analysis matches the bank");
|
||||
check(selected_hybrid == direct_hybrid, "selector hybrid matches the bank");
|
||||
if (kind == RosellaBankKind::Public) {
|
||||
public_hybrid = selected_hybrid;
|
||||
} else {
|
||||
captured_hybrid = selected_hybrid;
|
||||
}
|
||||
|
||||
BankTrace whole;
|
||||
{
|
||||
std::unique_ptr<RosellaBank> fresh = RosellaBank::create(kind, channels);
|
||||
whole = run_bank(*fresh, hops, synthetic, {slots}, channels);
|
||||
}
|
||||
check(whole.qmf == selected_qmf, "whole chunk analysis");
|
||||
check(whole.hybrid == selected_hybrid, "whole chunk hybrid");
|
||||
for (int repeat = 0; repeat < 2; ++repeat) {
|
||||
std::unique_ptr<RosellaBank> split = RosellaBank::create(kind, channels);
|
||||
const BankTrace parts =
|
||||
run_bank(*split, hops, synthetic, {0u, 5u, 0u, 7u, 12u}, channels);
|
||||
check(same_trace(whole, parts), "chunk/reset invariance");
|
||||
}
|
||||
}
|
||||
check(public_hybrid != captured_hybrid, "the two banks produce different hybrid data");
|
||||
}
|
||||
|
||||
// Distance from the impulse to the absolute peak of the analysis/synthesis
|
||||
// roundtrip, which is the latency the runtime skips at the head of the stream.
|
||||
std::size_t roundtrip_peak(RosellaBank& bank, std::size_t slots) {
|
||||
std::vector<double> impulse(slots * 64, 0.0);
|
||||
impulse[0] = 1.0;
|
||||
std::vector<Complex> qmf, hybrid;
|
||||
std::vector<double> output;
|
||||
bank.analyze_qmf(impulse, slots, &qmf);
|
||||
bank.analyze_hybrid(qmf, slots, &hybrid);
|
||||
bank.synthesize_hybrid(hybrid, slots, &qmf);
|
||||
bank.synthesize_qmf(qmf, slots, &output);
|
||||
const auto peak = std::max_element(output.begin(), output.end(), [](double left, double right) {
|
||||
return std::abs(left) < std::abs(right);
|
||||
});
|
||||
return static_cast<std::size_t>(peak - output.begin());
|
||||
}
|
||||
|
||||
void test_bank_latency_and_reset() {
|
||||
check(joc::hrtf::rosella_bank_latency(RosellaBankKind::Public) ==
|
||||
static_cast<std::uint32_t>(joc::hrtf::kLatencySamples),
|
||||
"public latency is the public filterbank latency");
|
||||
check(joc::hrtf::rosella_bank_latency(RosellaBankKind::Captured) ==
|
||||
static_cast<std::uint32_t>(RosellaFilterbank::kLatencySamples),
|
||||
"captured latency is the Rosella filterbank latency");
|
||||
check(joc::hrtf::rosella_bank_latency(RosellaBankKind::Public) == 961u,
|
||||
"public latency is 961 samples");
|
||||
check(joc::hrtf::rosella_bank_latency(RosellaBankKind::Captured) == 448u,
|
||||
"captured latency is 448 samples");
|
||||
for (const RosellaBankKind kind : {RosellaBankKind::Public, RosellaBankKind::Captured}) {
|
||||
std::unique_ptr<RosellaBank> bank = RosellaBank::create(kind, 1);
|
||||
const std::size_t first = roundtrip_peak(*bank, 64);
|
||||
check(first == joc::hrtf::rosella_bank_latency(kind), "bank roundtrip latency");
|
||||
bank->reset();
|
||||
check(roundtrip_peak(*bank, 64) == first, "bank reset restores the startup delay");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_reference_and_streaming();
|
||||
test_latency();
|
||||
test_bank_selection();
|
||||
test_bank_latency_and_reset();
|
||||
std::printf("Rosella filterbank: %d failures\n", failures);
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user