Skip to content

audio: ultrasound: add hostless ultrasonic Doppler gesture & presence sensing - #11576

Draft
lgirdwood wants to merge 5 commits into
thesofproject:mainfrom
lgirdwood:topic/ultrasound-gesture
Draft

lgirdwood wants to merge 5 commits into
thesofproject:mainfrom
lgirdwood:topic/ultrasound-gesture

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements DSP-autonomous ultrasonic Doppler gesture and presence sensing on IPC4 platforms (tested on Wildcat Lake / ACE 3.0 with Realtek RT722 SoundWire speaker + 4-ch Intel PDM DMIC), supporting both Approach A (hostless TX/RX with zero host audio DMA) and Approach B (click-free duty-cycled TX bursting with in-DSP presence auto-boost and D0i3/S0ix low-power operation).

Commits

  1. ipc4: notification: add generic module notification helper and presence state
    • Adds send_module_notif_msg() for LLEXT modules to emit SOF_IPC4_NOTIFY_MODULE_NOTIFICATION messages (SOF_IPC4_NOTIFY_MODULE_EVENTID_GESTURE_MAGIC_VAL = 0x6E570000).
    • Increases NOTIFICATION_POOL_MAX_PAYLOAD_SIZE from 40 to 80 bytes.
    • Exports atomic ultrasound_set_presence() / ultrasound_get_presence() from base firmware for lockless RX→TX duty-cycle auto-boost coordination across separate LLEXTs.
  2. audio: ultrasound: add hostless ultrasonic TX/RX Doppler gesture modules
    • ultrasound_tx (standalone 0-in/1-out source or 1-in/1-out additive): phase-continuous 20 kHz carrier (-18 dBFS default) with click-free Approach B low-power duty cycling (96 ms ON / 154 ms OFF, 250 ms period, 10 ms linear fade-in/out ramps) and automatic switch to 100% continuous TX while presence is active.
    • ultrasound_rx (1-in/0-out terminal sink or 1-in/1-out passthrough): 24-bit Q23 complex mixer, 2nd-order CIC decimation to 1 kHz baseband, DC carrier blocker, 64-pt Hann FFT with parabolic sub-bin interpolation, per-sideband local in-band noise floor estimation (canceling CIC droop and PDM DMIC rolloff tilt), 3-hop Doppler continuity filtering, and IPC4 event emission (PRESENCE_DETECTED, PUSH, PULL, TAP, SWIPE_RIGHT, SWIPE_LEFT, PRESENCE_LOST).
    • Adds app/ultrasound.conf overlay and PTL/WCL rimage manifest entries.
  3. topology2: intel: add hostless RT722 + 4-ch DMIC ultrasonic sensing topology
    • Adds virtual hostless-aif widget (priv.size == 0), ultrasound_tx / ultrasound_rx widgets & pipelines, sdw-ultrasound.conf, and sof-ptl-rt722-4ch-ultrasound target (Pipelines 160/161, PCMs 40/41, D0i3-compatible).
    • Updates tools/topology/validator to recognize hostless virtual aif_in/aif_out widgets matching kernel sof_widget_ready().

Hardware Verification (WCL RVP2 / Realtek RT722 + 4-ch Intel PDM DMIC)

  • Zero host DMA: probe_points_available verified zero host-copier in DSP; AudioDSP PCI IRQ delta was 7 IRQs over 4 s (mtrace flushes only).
  • Ambient DMIC immunity: 12.5 s quiet live 4-ch Intel PDM DMIC run produced 0 false positives (nf=[607, 491]).
  • TX carrier & media coexistence (SOF probes at alh-copier.Playback-SmartAmp.0): 20,000.0 Hz at -7.31 dBFS (audible band < -124 dBFS); coexisted cleanly with mid-stream aplay -D hw:0,2 playback and arecord -D hw:0,10 capture with zero dropout.
  • Approach B duty cycling & auto-boost (SOF probes at ultrasound_tx.160.1): Verified exact 250.0 ms pulsed TX (10 ms smooth ramps, audible edge ≤ -75 dBFS) → automatic 100% continuous TX on PRESENCE_DETECTED → return to 250.0 ms pulsed TX on PRESENCE_LOST, with 7/7 gesture/presence events detected with sub-Hz Doppler precision.
  • D0i3 & S0ix: Verified automatic D0I3 entry (~5 s idle) and rtcwake -m freeze -s 4 (s2idle) retention in D0I3 without pipeline teardown or FW reload.
  • Builds verified: WCL with and without app/ultrasound.conf, plus topology2_dev_sof-ptl-rt722-4ch-ultrasound (0 validator errors).

Companion Linux Kernel PR

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

Unprivileged access to kernel-only notification state can fault, IPC3 builds fail, and RX bypass and TX envelope defects can stall capture or distort output.

7 open issues
What changed in this PR

Adds DSP-autonomous ultrasonic gesture and presence sensing to SOF IPC4, alongside hostless stream support in companion Linux PR #6074.

Changes:

  • Adds ultrasonic TX/RX modules with Doppler detection, duty cycling, and presence-driven continuous transmission.
  • Introduces event/configuration interfaces, IPC4 notifications, and firmware packaging.
  • Adds an RT722/4-channel DMIC hostless topology and validator support for virtual audio interfaces.
File Description
uuid-registry.txt Registers TX and RX module UUIDs.
tools/​topology/​validator/​tplgparse/​kernel_engine.py Recognizes hostless virtual widgets.
tools/​topology/​validator/​checks/​ipc4.py Exempts hostless widgets from module-format checks.
tools/​topology/​topology2/​platform/​intel/​sdw-ultrasound.conf Connects ultrasonic pipelines to speaker and DMIC backends.
tools/​topology/​topology2/​include/​pipelines/​cavs/​ultrasound-tx-playback.conf Defines the hostless TX pipeline.
tools/​topology/​topology2/​include/​pipelines/​cavs/​ultrasound-rx-capture.conf Defines the hostless RX pipeline.
tools/​topology/​topology2/​include/​components/​ultrasound_tx.conf Defines the TX widget and controls.
tools/​topology/​topology2/​include/​components/​ultrasound_rx.conf Defines the RX widget and controls.
tools/​topology/​topology2/​include/​components/​hostless-aif.conf Defines virtual hostless audio-interface widgets.
tools/​topology/​topology2/​development/​tplg-targets.cmake Registers the PTL/WCL ultrasound topology target.
tools/​topology/​topology2/​cavs-sdw.conf Adds optional ultrasound topology integration.
tools/​rimage/​config/​wcl.toml.h Includes ultrasound modules in WCL manifests.
tools/​rimage/​config/​ptl.toml.h Includes ultrasound modules in PTL manifests.
src/​kernel/​ipc/​notification_pool.c Enlarges notification payload capacity.
src/​kernel/​ipc/​ipc4/​notification.c Adds module notifications and shared presence state.
src/​include/​user/​ultrasound.h Defines event payloads, configuration, and controls.
src/​include/​ipc4/​notification.h Declares notification and presence APIs.
src/​include/​ipc4/​header.h Defines the ultrasound event-ID prefix.
src/​audio/​ultrasound/​ultrasound_tx.toml Defines TX module manifest metadata.
src/​audio/​ultrasound/​ultrasound_tx.h Defines TX defaults and runtime state.
src/​audio/​ultrasound/​ultrasound_tx.c Implements carrier generation, ramps, and duty cycling.
src/​audio/​ultrasound/​ultrasound_rx.toml Defines RX module manifest metadata.
src/​audio/​ultrasound/​ultrasound_rx.h Defines detector defaults and runtime state.
src/​audio/​ultrasound/​ultrasound_rx.c Implements Doppler analysis and gesture/presence events.
src/​audio/​ultrasound/​ultrasound_dsp.h Provides fixed-point signal-processing primitives.
src/​audio/​ultrasound/​llext_tx/​llext.toml.h Defines the loadable TX manifest.
src/​audio/​ultrasound/​llext_tx/​CMakeLists.txt Builds TX as a loadable extension.
src/​audio/​ultrasound/​llext_rx/​llext.toml.h Defines the loadable RX manifest.
src/​audio/​ultrasound/​llext_rx/​CMakeLists.txt Builds RX as a loadable extension.
src/​audio/​ultrasound/​Kconfig Adds TX and RX component options.
src/​audio/​ultrasound/​CMakeLists.txt Selects built-in or loadable module builds.
src/​audio/​Kconfig Includes ultrasound configuration options.
src/​audio/​CMakeLists.txt Integrates ultrasound into audio builds.
app/​ultrasound.conf Enables both modules as loadable extensions.

Review effort: Balanced

Comment thread src/audio/Kconfig Outdated
DAI DMA operation and issues with low-latency scheduling.

rsource "bt_codec/Kconfig"
rsource "ultrasound/Kconfig"

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 5dd7937: gated COMP_ULTRASOUND_TX and COMP_ULTRASOUND_RX on depends on COMP_MODULE_ADAPTER && IPC_MAJOR_4 and removed the default y / default m if LIBRARY_DEFAULT_MODULAR lines so the components are opt-in via app/ultrasound.conf. Also fixed the 64-bit host/testbench size_t buffer size types and added missing sys_comp_module_ultrasound_{tx,rx}_interface_init() prototypes.

Comment thread src/audio/ultrasound/ultrasound_rx.c Resolved
Comment thread src/audio/ultrasound/ultrasound_tx.c Resolved
Comment thread src/kernel/ipc/ipc4/notification.c Resolved
Comment thread src/kernel/ipc/ipc4/notification.c Resolved
Comment thread src/audio/ultrasound/ultrasound_rx.c Resolved
Comment thread src/audio/ultrasound/ultrasound_tx.c Resolved
…ce state

Add send_module_notif_msg() for sending IPC4 module notifications
(SOF_IPC4_NOTIFY_MODULE_NOTIFICATION) from loadable LLEXT processing
modules, define SOF_IPC4_NOTIFY_MODULE_EVENTID_GESTURE_MAGIC_VAL
(0x6E57 << 16), and increase NOTIFICATION_POOL_MAX_PAYLOAD_SIZE from 40
to 80 bytes to accommodate struct sof_ipc4_notify_module_data payloads.

Also expose atomic ultrasound_set_presence() / ultrasound_get_presence()
helpers from base firmware so separate ultrasound_rx and ultrasound_tx
LLEXT modules can coordinate duty-cycle auto-boost without cross-LLEXT
symbol dependencies.

Expose send_module_notif_msg(), ultrasound_set_presence(), and
ultrasound_get_presence() as validated Zephyr __syscalls (with payload
bounds and K_SYSCALL_MEMORY_READ checks in z_vrfy_send_module_notif_msg,
plus EXPORT_SYMBOL(z_impl_*) for kernel-mode LLEXT callers) so unprivileged
userspace LL threads (CONFIG_SOF_USERSPACE_LL=y) can invoke them safely.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Comment thread src/audio/ultrasound/ultrasound_rx.c Outdated
Comment on lines +543 to +546
c->int1_i += mix_i;
c->int2_i += c->int1_i;
c->int1_q += mix_q;
c->int2_q += c->int1_q;

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 9d13448: switched all 2nd-order CIC integrator and comb state fields in struct us_rx_channel (int1_/int2_/comb1_/comb2_) to uint64_t modular arithmetic, casting only the final bounded 2nd-order comb output (int64_t)c2_* back to signed before dividing by d2.

Comment on lines +321 to +323
if widget.type_name in ("aif_in", "aif_out") and not data:
kw.hostless = True
return kw

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 96502c2: excluded routes touching hostless virtual widgets in kernel_routes() (and skipped hostless widgets in G005/F004) while preserving pcm_paths() traversal. Verified tplg_validate.py emits 0 errors and 0 W007 warnings on sof-ptl-rt722-4ch-ultrasound.tplg, and added test_hostless_virtual_aif_widgets_and_routes() (173/173 test_rules.py tests pass).

Comment on lines +365 to +375
} else {
cd->presence_consec = 0;
if (cd->present && (now_ms - cd->last_activity_ms) >= cd->cfg.presence_timeout_ms) {
cd->present = false;
#if CONFIG_IPC_MAJOR_4
ultrasound_set_presence(false);
#endif
ultrasound_rx_emit_event(mod, cd, SOF_US_EVT_PRESENCE_LOST,
0, 0, cd->cfg.carrier_hz[0]);
}
}

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 9d13448: tracked coherent_activity separately (set only when presence_consec >= 2 refreshes last_activity_ms) and evaluate presence timeout whenever cd->present && !coherent_activity so alternating non-coherent Doppler candidates cannot pin presence or TX boost indefinitely.

Comment thread src/audio/ultrasound/ultrasound_tx.c Outdated

/* Approach B: click-free duty-cycled bursting with auto-boost on presence */
if (desired > 0 && cd->duty_period_samples > 0) {
bool boosted = cd->cfg.auto_boost_on_presence && ultrasound_get_presence();

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 9d13448: cached presence_boost via ultrasound_get_presence() once per audio block in ultrasound_tx_process() (1 kHz instead of 48 kHz under CONFIG_SOF_USERSPACE_LL=y) and read cd->presence_boost inside ultrasound_tx_step_env(). Verified Approach B PULSED -> CONTINUOUS transition within 0.6 ms of PRESENCE_DETECTED on Ladybird.

@lgirdwood lgirdwood left a comment

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.

This is IPC4 only so no need for ifdefs. There is also duplication of many maths functions, we should use existing maths lib if possible.

Comment thread src/audio/ultrasound/ultrasound_dsp.h Outdated
}

/* In-place 64-point radix-2 forward complex FFT (unscaled, int32_t safe up to |x|<=2^22) */
static inline void us_fft64(int32_t *re, int32_t *im)

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.

we already have an xtensa fft in the maths lib, we should reuse that if possible.

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 757a48c and 9d13448: removed the custom FFT, sine LUT, Hann window table, integer sqrt, log2, and saturation helpers from ultrasound_dsp.h / ultrasound_tx.c and switched to SOF's math and format libraries:

  • Exported mod_fft_plan_new(), mod_fft_plan_free(), fft_execute_32() (generic + HiFi3), win_hann_16b(), and base2_logarithm() in 757a48c for LLEXT callers.
  • Reused fft_execute_32() (with norm_int32() Q1.31 block scaling and 8-byte aligned buffers), win_hann_16b(), sofm_lut_sin_fixed_16b(), sofm_sqrt_int32(), base2_logarithm(), SPEED_OF_SOUND, and <sof/audio/format.h> sat_int16()/sat_int24()/sat_int32()/sign_extend_s24() in 9d13448, selecting the required CONFIG_MATH_* symbols in src/audio/ultrasound/Kconfig.
  • Verified on Ladybird (WCL, CONFIG_SOF_USERSPACE_LL=y): all 7/7 synthetic Doppler events pass with zero unresolved LLEXT symbols and zero memory faults.

Comment thread src/audio/ultrasound/ultrasound_rx.c Outdated
memset(&cd->pending_push, 0, sizeof(cd->pending_push));
memset(&cd->pending_pull, 0, sizeof(cd->pending_pull));

#if CONFIG_IPC_MAJOR_4

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.

this will be IPC4 only.

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 9d13448: removed all #if CONFIG_IPC_MAJOR_4 guards from ultrasound_rx.c and ultrasound_tx.c since both modules depend on IPC_MAJOR_4 in Kconfig, and moved rsource "ultrasound/Kconfig" into the alphabetical Audio components section of src/audio/Kconfig.

for w in ctx.tplg.widgets:
kw = ctx.kw(w)
if kw.error or w.type_name not in AUDIO_FMT_TYPES or ctx.pipeline_widget(w) is None:
if kw.error or kw.hostless or w.type_name not in AUDIO_FMT_TYPES or \

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.

validator changes need to be a separate patch.

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: split the tools/topology/validator/ changes out of the topology2 commit into their own standalone commit 96502c2 ("topology: validator: support hostless virtual aif_in/aif_out widgets"), including hostless route filtering in kernel_routes() and a dedicated unit test in tests/test_rules.py.

Export mod_fft_plan_new(), mod_fft_plan_free(), fft_execute_32() (both
generic and HiFi3 implementations), win_hann_16b(), and base2_logarithm()
via EXPORT_SYMBOL() so relocatable LLEXT processing modules can reuse
SOF's math library without duplicating FFT, window, or log code.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add two IPC4-only standalone relocatable LLEXT processing modules for
DSP-autonomous ultrasonic Doppler gesture and presence sensing:

- ultrasound_tx (0-in/1-out standalone or 1-in/1-out additive/replace):
  synthesizes a phase-continuous 20 kHz carrier (-18 dBFS default) using
  SOF's LUT sine (sofm_lut_sin_fixed_16b) and format saturation helpers,
  with optional low-power duty-cycled bursting (96 ms ON / 154 ms OFF,
  250 ms period, 10 ms linear fade-in/out ramps) that caches
  ultrasound_get_presence() once per audio block to automatically boost
  to 100% continuous TX while user presence is active.
- ultrasound_rx (1-in/0-out terminal sink or 1-in/1-out passthrough):
  performs 24-bit Q23 quadrature down-conversion, modular uint64_t
  2nd-order CIC decimation to 1 kHz complex baseband, DC carrier
  blocking, 64-pt Hann-windowed FFT via SOF's math library
  (win_hann_16b, mod_fft_plan_new, fft_execute_32, norm_int32,
  sofm_sqrt_int32, base2_logarithm) with parabolic sub-bin interpolation,
  per-sideband local in-band noise floor estimation, 3-hop Doppler
  frequency continuity filtering, and emits PRESENCE_DETECTED, PUSH,
  PULL, TAP, SWIPE_RIGHT, SWIPE_LEFT, and PRESENCE_LOST via IPC4 module
  notifications.

Gate both Kconfig options on COMP_MODULE_ADAPTER && IPC_MAJOR_4, select
their required SOF math library dependencies (opt-in via
app/ultrasound.conf), and provide rimage manifest entries for PTL/WCL.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Mirror kernel sof_widget_ready() and sof_route_setup() handling for
hostless virtual aif_in / aif_out widgets that have zero private token
data (priv.size == 0):

- Mark empty-priv aif_in/aif_out widgets as hostless in widget_ready().
- Skip firmware module format/UUID/pipeline/copier-output checks (G005,
  W002, W003, F004) for hostless virtual widgets.
- Exclude routes touching hostless virtual widgets from kernel_routes()
  (eliminating spurious W007 zero-pin warnings on DAPM-only routes to
  0-input source / 0-output sink modules) while keeping pcm_paths()
  traversal intact.
- Add unit test covering hostless TX/RX virtual widgets and routes.

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

Add virtual hostless-aif widget (zero private token data), ultrasound_tx
and ultrasound_rx widget/pipeline definitions, and the sdw-ultrasound.conf
integration wired into cavs-sdw.conf (ADD_ULTRASOUND) and
sof-ptl-rt722-4ch-ultrasound:

- Pipeline 160 (PCM 40: "Ultrasound TX", D0i3-compatible):
  ultrasound_tx.160.1 -> mixin.160.1 -> mixout.21.1 (RT722 Speaker BE),
  coexisting cleanly with normal media playback on PCM 2.
- Pipeline 161 (PCM 41: "Ultrasound RX", D0i3-compatible):
  module-copier.101.2 (Intel 4-ch PDM DMIC BE) -> ultrasound_rx.161.1,
  coexisting cleanly with normal DMIC capture on PCM 10.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/ultrasound-gesture branch from 6219c7b to 17b4832 Compare December 3, 2026 21:47
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