Skip to content

audio: resonance_audio: add Google Resonance Audio spatializer module - #11568

Draft
lgirdwood wants to merge 8 commits into
thesofproject:mainfrom
lgirdwood:topic/resonance-audio-module
Draft

lgirdwood wants to merge 8 commits into
thesofproject:mainfrom
lgirdwood:topic/resonance-audio-module

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Add the Google Resonance Audio binaural spatializer DSP module to SOF (Phase 1 kcontrols + Phase 2 DMA pose metadata over ALSA compress mmap):

  • West manifest (west.yml): add upstream resonance-audio, eigen, and pffft projects under modules/audio/resonance-audio.
  • LLEXT helper (scripts/llext_link_helper.py): promote defined STB_WEAK STT_FUNC/STT_OBJECT symbols to STB_GLOBAL in ET_REL objects so Zephyr LLEXT resolves C++ templates and vtables.
  • UUID & rimage (uuid-registry.txt, tools/rimage/config/{ptl,wcl}.toml.h): register resonance_audio (12f51e05-61d9-4a96-939eca72c615d89b) and RESAUD module manifest entries.
  • DSP module (src/audio/resonance_audio/):
    • Supports Mono, Stereo, 5.1, 7.1, and 1st-order Ambisonics (AmbiX) inputs rendered to 2-channel binaural stereo using SADIE HRTFs.
    • Dual-pin IPC4 processing: Pin 0 carries PCM audio and non-blocking Pin 1 receives 128-byte FNV-1a checksummed DMA spatial pose metadata frames (magic = 0x4E534552) over ALSA compress mmap with circular buffer wrap resync.
    • Phase 1 ALSA kcontrols (pose, speaker_mode, room) remain active when Pin 1 is closed.
    • Emits .sof_codec_info descriptors (SND_AUDIOCODEC_PCM, SND_AUDIOCODEC_BESPOKE) via <sof/audio/codec_info.h>.
    • Includes a dependency-free COMP_RESONANCE_AUDIO_STUB backend and LLEXT build support.
  • Unit tests (test/ztest/unit/audio/resonance_audio/): native Zephyr ztest suite covering speaker modes, Phase 1 kcontrol head rotation, and Phase 2 Pin 1 DMA metadata frames.

Related Draft PRs

Verification

  • Native Zephyr ztest (resonance_audio_suite): 5/5 passed (west build -b native_sim -d build-ztest-resonance sof/test/ztest/unit/audio/resonance_audio).
  • WCL LLEXT firmware build (xtensa-build-zephyr.py -z -p wcl): succeeded and verified .sof_codec_info section in resonance_audio.llext.
  • WCL built-in stub build (CONFIG_COMP_RESONANCE_AUDIO=y, CONFIG_COMP_RESONANCE_AUDIO_STUB=y): succeeded.
  • Hardware-verified on Wildcat Lake RVP (RT722 SoundWire) with 200 Hz and 1 kHz compress mmap pose streams alongside 4ch S32_LE and 6ch S16_LE playback.

Add upstream remotes and west projects for resonance-audio, eigen, and pffft under modules/audio/resonance-audio so the Google Resonance Audio spatializer can be built as a Zephyr/SOF LLEXT or built-in module.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…LOBAL

Zephyr llext_load/llext_link only index and relocate STB_GLOBAL and STB_LOCAL symbols, leaving defined STB_WEAK symbols (such as C++ templates and vtables) unpatched at 0. Promote defined STB_WEAK STT_OBJECT and STT_FUNC symbols to STB_GLOBAL in ET_REL objects so LLEXT resolves them properly.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Register UUID 12f51e05-61d9-4a96-939eca72c615d89b for the resonance_audio spatializer module.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Include resonance_audio.toml in the PTL and WCL rimage manifests when CONFIG_COMP_RESONANCE_AUDIO or LLEXT_FORCE_ALL_MODULAR is enabled.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add the Google Resonance Audio binaural spatializer module supporting Mono, Stereo, 5.1, 7.1, and 1st-order Ambisonics (AmbiX) inputs rendered to 2-channel binaural output using SADIE HRTFs.

Includes:
- IPC4 dual-pin processing: Pin 0 for PCM audio and non-blocking Pin 1 for low-latency DMA spatial pose metadata frames over ALSA compress mmap
- Phase 1 ALSA kcontrol (bytes/switch/enum) pose, room, and speaker-mode configuration alongside Phase 2 DMA pose frame updates (128-byte FNV-1a checksummed frames with circular buffer wrap resync)
- .sof_codec_info descriptor registration for SND_AUDIOCODEC_PCM and SND_AUDIOCODEC_BESPOKE compress pose streams
- Dependency-free stub backend (COMP_RESONANCE_AUDIO_STUB) and LLEXT packaging for ACE/PTL/WCL

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add native Zephyr ztest unit tests covering Resonance Audio parameter validation, speaker-mode/HRTF configuration, Phase 1 kcontrol pose updates, and Phase 2 DMA pose frame checksum/wrap/playback verification.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Enabling room reverb fails to build because the standalone compiler lacks the configuration macro, while concurrent instances can misattribute allocations and free memory still used by another instance.

5 open issues
What changed in this PR

Adds Google Resonance Audio as a SOF spatializer module, rendering multichannel and first-order Ambisonics input to binaural stereo. It provides the DSP-side support for the related topology and Linux compress-mmap work.

Changes:

  • Adds real and stub backends, ALSA controls, and an optional DMA pose-metadata input.
  • Integrates dependencies, firmware manifests, and loadable-module support.
  • Adds native Zephyr tests for rendering, controls, and metadata processing.
File Description
west.yml Pins Resonance Audio, Eigen, and PFFFT dependencies.
uuid-registry.txt Registers the spatializer UUID.
tools/​rimage/​config/​wcl.toml.h Includes RESAUD in WCL manifests.
tools/​rimage/​config/​ptl.toml.h Includes RESAUD in PTL manifests.
test/​ztest/​unit/​audio/​resonance_audio/​testcase.yaml Registers the native simulation test suite.
test/​ztest/​unit/​audio/​resonance_audio/​resonance_audio_ztest.c Tests rendering, controls, bypass, and DMA metadata.
test/​ztest/​unit/​audio/​resonance_audio/​resonance_audio_test_alloc.c Supplies host allocation helpers for tests.
test/​ztest/​unit/​audio/​resonance_audio/​prj.conf Configures tests with the real backend.
test/​ztest/​unit/​audio/​resonance_audio/​CMakeLists.txt Builds the native test application and dependencies.
src/​audio/​resonance_audio/​resonance_wrapper.h Defines the C interface to the C++ renderer.
src/​audio/​resonance_audio/​resonance_wrapper.cpp Implements spatial rendering and runtime controls.
src/​audio/​resonance_audio/​resonance_shims.cpp Provides minimal C++ runtime support.
src/​audio/​resonance_audio/​resonance_shims.c Provides allocation, libc, and math shims.
src/​audio/​resonance_audio/​resonance_preinc.h Redirects library allocations through SOF shims.
src/​audio/​resonance_audio/​resonance_hrtf_assets.cc Embeds and loads first-order SADIE HRTF data.
src/​audio/​resonance_audio/​resonance_audio.toml Defines module identity, pins, and resource metadata.
src/​audio/​resonance_audio/​resonance_audio.h Defines controls, pose packets, and backend state.
src/​audio/​resonance_audio/​resonance_audio.cmake Cross-builds the renderer’s static library.
src/​audio/​resonance_audio/​resonance_audio.c Implements PCM processing, controls, and metadata framing.
src/​audio/​resonance_audio/​resonance_audio-stub.c Adds a dependency-free stereo downmix backend.
src/​audio/​resonance_audio/​resonance_audio-real.c Connects the module lifecycle to the renderer.
src/​audio/​resonance_audio/​overrides/​graph/​reverb_node.h Stubs reverb when compiled out.
src/​audio/​resonance_audio/​overrides/​graph/​reflections_node.h Stubs reflections when compiled out.
src/​audio/​resonance_audio/​overrides/​config/​global_config.h Limits rendering to first-order Ambisonics.
src/​audio/​resonance_audio/​overrides/​base/​logging.h Replaces heavyweight upstream logging.
src/​audio/​resonance_audio/​overrides/​base/​constants_and_types.h Caps internal audio buffer sizes.
src/​audio/​resonance_audio/​overrides/​ambisonics/​ambisonic_lookup_table.cc Optimizes encoder lookup-table generation.
src/​audio/​resonance_audio/​llext/​llext.toml.h Defines the loadable-module manifest.
src/​audio/​resonance_audio/​llext/​CMakeLists.txt Packages real or stub loadable modules.
src/​audio/​resonance_audio/​Kconfig Exposes module, stub, and room-effects options.
src/​audio/​resonance_audio/​CMakeLists.txt Selects built-in or loadable-module builds.
src/​audio/​Kconfig Includes the spatializer configuration.
src/​audio/​CMakeLists.txt Adds the spatializer build directory.
scripts/​llext_link_helper.py Promotes defined weak symbols for LLEXT resolution.

Review effort: Balanced

Comment on lines +175 to +187
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/resonance-audio-build.sh.tmp"
"#!/bin/sh
set -e
INST=\"${RESONANCE_AUDIO_INSTALL_DIR}\"
OBJ=\"${CMAKE_CURRENT_BINARY_DIR}/resonance-audio-obj\"

rm -rf \"\$OBJ\" \"\$INST/lib/libresonance_audio_dsp.a\"
mkdir -p \"\$OBJ\" \"\$INST/lib\" \"\$INST/include\"

COMMON_FLAGS=\"-O3 ${_res_arch_flags} ${_res_clang_fp_flags} ${_res_sysroot_inc} -DNDEBUG -D_GNU_SOURCE -DM_PI=3.14159265358979323846 -DPFFFT_SIMD_DISABLE -DDISABLE_SIMD -DEIGEN_MPL2_ONLY -DEIGEN_NO_DEBUG -DEIGEN_DONT_VECTORIZE\"
INCS=\"-I${_res_mod_dir}/overrides -I${_res_mod_dir} -I${SOF_RESONANCE_AUDIO_SRC_DIR} -I${_res_ra_dir} -I${_res_eigen_dir} -I${_res_pffft_dir}\"
CFLAGS=\"\$COMMON_FLAGS \$INCS -Dmalloc=res_shim_malloc -Dcalloc=res_shim_calloc -Drealloc=res_shim_realloc -Dfree=res_shim_free -Wno-unused-function -Wno-double-promotion\"
CXXFLAGS=\"-std=c++17 -fno-exceptions -fno-rtti -fno-threadsafe-statics -include ${_res_mod_dir}/resonance_preinc.h \$COMMON_FLAGS ${_res_cxx_sys_inc} \$INCS -Wno-unused-function -Wno-double-promotion -Wno-deprecated-declarations -Wno-sign-compare\"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f5b4c39: resonance_audio.cmake now passes -DCONFIG_RESONANCE_AUDIO_ROOM_REVERB=1 to external C++ CXXFLAGS when CONFIG_RESONANCE_AUDIO_ROOM_REVERB=y, and resonance_shims.c exposes its trig/PRNG math shims for built-in firmware builds as well (keeping minimal-libc sqrt/sqrtf guarded). Verified cleanly with a full CONFIG_COMP_RESONANCE_AUDIO=y + CONFIG_RESONANCE_AUDIO_ROOM_REVERB=y PTL build.

void *res_shim_malloc(size_t size)
{
struct res_alloc_hdr *hdr;
struct processing_module *mod = active_res_mod;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f5b4c39: serialized built-in backend operations (resonance_audio_backend_enter() / resonance_audio_backend_exit()) using k_mutex / APP_SYSUSER_BSS sys_mutex (matching module/generic.c), and updated res_shim_realloc() to allocate against hdr->owner rather than the global pointer. Added test_multi_instance_isolation in 50833f4.

}

cd->sample_rate = in_rate;
cd->in_channels = in_ch;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f5b4c39: added resonance_setup_in_chmap() to validate IPC4 ch_map on Pin 0 and build per-channel permutation in_perm[] so semantic layouts such as up_down_mixer 5.1 (0xFF743210, L,C,R,LS,RS,LFE) are reordered to Resonance order (L,R,C,LFE,LS,RS) and incomplete/invalid maps return -EINVAL, while leaving 4ch FOA AmbiX channel interpretation untouched. Added test_up_down_mixer_51_chmap_and_invalid_chmap in 50833f4.

Comment on lines +378 to +379
if (cfg.input_mode <= 4)
cd->mode_override = cfg.input_mode;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f5b4c39: resonance_apply_pose_cfg() now accepts RESONANCE_INPUT_MODE_AUTO (0xff) as well as 0..4, restoring channel-based mode selection on the next prepare/reset. Added test_pose_input_mode_auto_reset in 50833f4.

if (n <= 0)
return 0;

n = MIN(n, RESONANCE_FIFO_FRAMES - cd->buffered_in_frames);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f5b4c39: resonance_process() now bounds accepted frames n by both input FIFO capacity and available output FIFO block headroom ((RESONANCE_FIFO_FRAMES - buffered_out_frames) / block_frames * block_frames + block_frames - 1 - buffered_in_frames), preventing partial drainage / silent gap insertion. Added test_large_batch_512_frames_no_gap in 50833f4.

…d FIFO

Address code review findings for the Google Resonance Audio module:
- resonance_audio.cmake: pass -DCONFIG_RESONANCE_AUDIO_ROOM_REVERB=1 to the external C++ compiler when enabled
- resonance_shims.c: provide trig/PRNG math shims for built-in firmware builds (avoiding double definitions with minimal libc sqrt/sqrtf), allocate realloc() buffers against hdr->owner, and serialize built-in backend allocation context using k_mutex/sys_mutex
- resonance_audio.{h,c}: accept documented input_mode=0xff (auto), validate and reorder speaker-mode PCM channels per IPC4 ch_map while keeping AmbiX identity untouched, and bound process() batch size by both input and output FIFO headroom

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Suppress Clang -W#warnings on upstream pffft/simd_utils.cc in host/llvm ztest builds and add unit tests covering input_mode=0xff auto reset, up_down_mixer 5.1 semantic ch_map reordering, invalid ch_map rejection, 512-frame batch continuity, and multi-instance isolation.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood

Copy link
Copy Markdown
Member Author

Addressed all Copilot code review comments (commits f5b4c3933 and 50833f42d) and fixed the CI host/llvm ztest build error (-Wno-#warnings on upstream pffft/simd_utils.cc):

  • Passed -DCONFIG_RESONANCE_AUDIO_ROOM_REVERB=1 to external C++ compilation and exposed math/PRNG shims for built-in firmware builds; verified full PTL CONFIG_COMP_RESONANCE_AUDIO=y + CONFIG_RESONANCE_AUDIO_ROOM_REVERB=y build.
  • Serialized built-in backend alloc context (k_mutex/sys_mutex) and pinned res_shim_realloc() to hdr->owner.
  • Added IPC4 ch_map validation & speaker-order remapping (preserving AmbiX identity), RESONANCE_INPUT_MODE_AUTO (0xff) support, and combined input/output FIFO batch limiting.
  • Re-tested native Zephyr ztest (resonance_audio_suite: 9/9 passed under both host/gcc and host/llvm Clang 18 with -Werror).
  • Rebuilt community-signed PTL LLEXT firmware (sof-ptl.ri + sof-ptl-openmodules.ri) and verified live playback (2ch S16_LE & 2ch S32_LE), input_mode=0xff auto reset, TLV pose updates, switch toggles, and ACE 3.0 DSP mtrace logs on Damsel Fly (UP Xtreme PTL, ALC888-VD).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants