Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions scripts/llext_link_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,50 @@ def prune_xtensa_relocs(path):
print(f'llext_link_helper.py: dropped {dropped} of {total} relocations not needing '
'run-time processing')

def promote_defined_weak_syms(path):
# Zephyr llext_load/llext_link only index and relocate STB_GLOBAL and
# STB_LOCAL symbols, leaving STB_WEAK relocations (e.g. C++ templates
# and vtables) unpatched at 0. Promote defined STB_WEAK FUNC/OBJECT
# symbols to STB_GLOBAL so LLEXT resolves them against ext->sym_tab.
SYM_SIZE = 16
STB_GLOBAL = 1
STB_WEAK = 2
STT_OBJECT = 1
STT_FUNC = 2
SHN_UNDEF = 0
SHN_LORESERVE = 0xff00

with open(path, 'rb') as f:
elf = ELFFile(f)
if elf['e_type'] != 'ET_REL':
return
symtab = None
for section in elf.iter_sections():
if section['sh_type'] == 'SHT_SYMTAB' and section['sh_entsize'] == SYM_SIZE:
symtab = section
break
if symtab is None:
return
sh_offset = symtab['sh_offset']
raw = bytearray(symtab.data())

promoted = 0
for off in range(0, len(raw), SYM_SIZE):
st_info = raw[off + 12]
st_shndx, = struct.unpack_from('<H', raw, off + 14)
bind = st_info >> 4
stype = st_info & 0xf
if (bind == STB_WEAK and stype in (STT_OBJECT, STT_FUNC) and
SHN_UNDEF < st_shndx < SHN_LORESERVE):
raw[off + 12] = (STB_GLOBAL << 4) | stype
promoted += 1

if promoted:
with open(path, 'r+b') as f:
f.seek(sh_offset)
f.write(raw)
print(f'llext_link_helper.py: promoted {promoted} defined STB_WEAK symbols to STB_GLOBAL')

def main():
global args

Expand Down Expand Up @@ -380,6 +424,7 @@ def main():

if '-r' in params:
prune_xtensa_relocs(f'{args.file}.tmp')
promote_defined_weak_syms(f'{args.file}.tmp')

copy_command = [args.copy]

Expand Down
3 changes: 3 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ endif()
if(CONFIG_COMP_VOLUME)
add_subdirectory(volume)
endif()
if(CONFIG_COMP_RESONANCE_AUDIO)
add_subdirectory(resonance_audio)
endif()
if(CONFIG_COMP_WEBRTC_VAD)
add_subdirectory(webrtc_vad)
endif()
Expand Down
1 change: 1 addition & 0 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ rsource "multiband_drc/Kconfig"
rsource "mux/Kconfig"
rsource "nxp/Kconfig"
rsource "phase_vocoder/Kconfig"
rsource "resonance_audio/Kconfig"
rsource "rtnr/Kconfig"
rsource "selector/Kconfig"
rsource "smart_amp/Kconfig"
Expand Down
17 changes: 17 additions & 0 deletions src/audio/resonance_audio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: BSD-3-Clause

if(CONFIG_COMP_RESONANCE_AUDIO STREQUAL "m" AND DEFINED CONFIG_LLEXT)
add_subdirectory(llext ${PROJECT_BINARY_DIR}/resonance_audio_llext)
add_dependencies(app resonance_audio)
else()
add_local_sources(sof resonance_audio.c)
if(CONFIG_COMP_RESONANCE_AUDIO_STUB)
add_local_sources(sof resonance_audio-stub.c)
else()
include(${CMAKE_CURRENT_LIST_DIR}/resonance_audio.cmake)
add_local_sources(sof resonance_audio-real.c resonance_shims.c)
add_dependencies(modules_sof resonance_audio_ext)
target_link_libraries(modules_sof PUBLIC
"${RESONANCE_AUDIO_INSTALL_DIR}/lib/libresonance_audio_dsp.a")
endif()
endif()
33 changes: 33 additions & 0 deletions src/audio/resonance_audio/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: BSD-3-Clause

config COMP_RESONANCE_AUDIO
tristate "Google Resonance Audio spatializer (virtual surround & FOA)"
help
Select to include the Google Resonance Audio spatializer module.
Renders Mono, Stereo, 5.1, 7.1, and 1st-order Ambisonics (AmbiX)
into 2-channel binaural stereo using SADIE HRTF measurements, with
ALSA kcontrol support for head-tracking orientation and speaker mode.

Source is fetched via west (resonance-audio + eigen + pffft).
For CI builds without external sources, select COMP_RESONANCE_AUDIO_STUB.

if COMP_RESONANCE_AUDIO

config COMP_RESONANCE_AUDIO_STUB
bool "Resonance Audio stub backend (dependency-free stereo downmix)"
default y if COMP_STUBS
help
Build the resonance_audio module with a dependency-free stereo
downmix stub backend. Useful for CI validation of the SOF module
adapter, LLEXT packaging, and topology wiring without C++ Resonance
Audio sources.

config RESONANCE_AUDIO_ROOM_REVERB
bool "Enable shoebox room reflections & spectral reverb by default"
default n
help
Enables Resonance Audio room early reflections and spectral reverb
by default on pipeline prepare(). Can also be toggled at runtime via
ALSA switch/bytes kcontrol.

endif # COMP_RESONANCE_AUDIO
26 changes: 26 additions & 0 deletions src/audio/resonance_audio/llext/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2026 Intel Corporation.
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_COMP_RESONANCE_AUDIO_STUB)
sof_llext_build("resonance_audio"
SOURCES ../resonance_audio.c
../resonance_audio-stub.c
LIB openmodules
)
else()
include(${CMAKE_CURRENT_LIST_DIR}/../resonance_audio.cmake)

sof_llext_build("resonance_audio"
SOURCES ../resonance_audio.c
../resonance_audio-real.c
../resonance_shims.c
INCLUDES "${CMAKE_CURRENT_LIST_DIR}/.."
CFLAGS -DLLEXT_MODULE -DLL_EXTENSION_BUILD
LIBS_PATH "${RESONANCE_AUDIO_INSTALL_DIR}/lib"
LIBS resonance_audio_dsp
LIB openmodules
)

add_dependencies(resonance_audio_llext_lib resonance_audio_ext)
add_dependencies(resonance_audio resonance_audio_ext)
endif()
6 changes: 6 additions & 0 deletions src/audio/resonance_audio/llext/llext.toml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <tools/rimage/config/platform.toml>
#define LOAD_TYPE "2"
#include "../resonance_audio.toml"

[module]
count = __COUNTER__
Loading
Loading