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
5 changes: 5 additions & 0 deletions app/ultrasound.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONFIG_COMP_ULTRASOUND_TX=m
CONFIG_COMP_ULTRASOUND_RX=m

# Ensure enough kernel heap for authenticating external LLEXTs alongside LL userspace
CONFIG_SOF_ZEPHYR_HEAP_SIZE=0x80000
4 changes: 4 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,7 @@ endif()
if(CONFIG_COMP_BT_CODEC)
add_subdirectory(bt_codec)
endif()

if(CONFIG_COMP_ULTRASOUND_TX OR CONFIG_COMP_ULTRASOUND_RX)
add_subdirectory(ultrasound)
endif()
1 change: 1 addition & 0 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ rsource "tdfb/Kconfig"
rsource "template/Kconfig"
rsource "tensorflow/Kconfig"
rsource "tone/Kconfig"
rsource "ultrasound/Kconfig"
rsource "up_down_mixer/Kconfig"
rsource "volume/Kconfig"
rsource "webrtc_vad/Kconfig"
Expand Down
15 changes: 15 additions & 0 deletions src/audio/ultrasound/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: BSD-3-Clause

if(CONFIG_COMP_ULTRASOUND_TX STREQUAL "m" AND DEFINED CONFIG_LLEXT)
add_subdirectory(llext_tx ${PROJECT_BINARY_DIR}/ultrasound_tx_llext)
add_dependencies(app ultrasound_tx)
elseif(CONFIG_COMP_ULTRASOUND_TX)
add_local_sources(sof ultrasound_tx.c)
endif()

if(CONFIG_COMP_ULTRASOUND_RX STREQUAL "m" AND DEFINED CONFIG_LLEXT)
add_subdirectory(llext_rx ${PROJECT_BINARY_DIR}/ultrasound_rx_llext)
add_dependencies(app ultrasound_rx)
elseif(CONFIG_COMP_ULTRASOUND_RX)
add_local_sources(sof ultrasound_rx.c)
endif()
28 changes: 28 additions & 0 deletions src/audio/ultrasound/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: BSD-3-Clause

config COMP_ULTRASOUND_TX
tristate "Ultrasonic carrier generator (TX) component"
depends on COMP_MODULE_ADAPTER && IPC_MAJOR_4
select MATH_LUT_SINE_FIXED
help
Select for ultrasonic carrier generator component. Injects an inaudible
ultrasonic tone (>= 19 kHz) with smooth ramping onto an audio stream
for acoustic gesture and presence sensing, and supports hostless
generator mode with low-power duty cycling.

config COMP_ULTRASOUND_RX
tristate "Ultrasonic Doppler gesture and presence detector (RX) component"
depends on COMP_MODULE_ADAPTER && IPC_MAJOR_4
select BINARY_LOGARITHM_FIXED
select MATH_32BIT_FFT
select MATH_DECIBELS
select MATH_FFT
select MATH_LUT_SINE_FIXED
select MATH_WINDOW
select NUMBERS_NORM
select SQRT_FIXED
help
Select for ultrasonic Doppler gesture and presence detector component.
Demodulates ultrasonic carrier sidebands, classifies push/pull/tap/swipe
gestures and user presence, and emits IPC4 module notifications to the
host client driver.
6 changes: 6 additions & 0 deletions src/audio/ultrasound/llext_rx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2026 Intel Corporation.
# SPDX-License-Identifier: Apache-2.0

sof_llext_build("ultrasound_rx"
SOURCES ../ultrasound_rx.c
)
6 changes: 6 additions & 0 deletions src/audio/ultrasound/llext_rx/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 "../ultrasound_rx.toml"

[module]
count = __COUNTER__
6 changes: 6 additions & 0 deletions src/audio/ultrasound/llext_tx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2026 Intel Corporation.
# SPDX-License-Identifier: Apache-2.0

sof_llext_build("ultrasound_tx"
SOURCES ../ultrasound_tx.c
)
6 changes: 6 additions & 0 deletions src/audio/ultrasound/llext_tx/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 "../ultrasound_tx.toml"

[module]
count = __COUNTER__
100 changes: 100 additions & 0 deletions src/audio/ultrasound/ultrasound_dsp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2026 Intel Corporation.
*
* Fixed-point DSP helpers for SOF ultrasonic gesture/presence sensing,
* built on SOF's math library (LUT trig, sqrt, norm, base-2 log).
*/

#ifndef __SOF_AUDIO_ULTRASOUND_DSP_H__
#define __SOF_AUDIO_ULTRASOUND_DSP_H__

#include <stdint.h>
#include <sof/audio/format.h>
#include <sof/math/log.h>
#include <sof/math/lut_trig.h>
#include <sof/math/numbers.h>
#include <sof/math/sqrt.h>
#include <sof/math/trig.h>

#define US_FFT_SIZE 64
#define US_FFT_LOG2 6
#define US_BASEBAND_RATE_HZ 1000

/* 20 * log10(2) in Q16.16: round(6.0205999133 * 65536) */
#define US_20_LOG10_2_Q16 394566LL

/* Q1.15 sine from 32-bit phase [0, 2*pi) via SOF quarter-wave LUT (Q4.28 rad) */
static inline int32_t us_sin_q15(uint32_t phase)
{
int32_t w_q28 = (int32_t)(((uint64_t)phase * PI_MUL2_Q4_28) >> 32);

return sofm_lut_sin_fixed_16b(w_q28);
}

static inline int32_t us_cos_q15(uint32_t phase)
{
return us_sin_q15(phase + 0x40000000U);
}

static inline uint32_t us_phase_inc(uint32_t freq_hz, uint32_t sample_rate)
{
if (!sample_rate)
return 0;

return (uint32_t)((((uint64_t)freq_hz << 32) + (sample_rate >> 1)) / sample_rate);
}

/* Complex magnitude sqrt(re^2 + im^2) using SOF norm_int32() and sofm_sqrt_int32() */
static inline uint32_t us_mag_u32(int32_t re, int32_t im)
{
uint32_t are = (re < 0) ? (uint32_t)(-(int64_t)re) : (uint32_t)re;
uint32_t aim = (im < 0) ? (uint32_t)(-(int64_t)im) : (uint32_t)im;
uint32_t peak = (are >= aim) ? are : aim;
int32_t nr, ni, arg;
uint32_t m_q30;
int shift;

if (!peak)
return 0;

/* Scale (re, im) so max(|nr|, |ni|) is in [2^29, 2^30], keeping arg in [2^26, 2^29] */
if (peak >= 0x40000000U) {
shift = -1;
nr = re >> 1;
ni = im >> 1;
} else {
shift = norm_int32((int32_t)peak) - 1;
nr = (int32_t)((uint32_t)re << shift);
ni = (int32_t)((uint32_t)im << shift);
}

/* (nr^2 + ni^2) / 2^32 in Q2.30 -> sofm_sqrt_int32() returns sqrt(nr^2 + ni^2) / 2 */
arg = (int32_t)(((int64_t)nr * nr + (int64_t)ni * ni) >> 32);
m_q30 = (uint32_t)sofm_sqrt_int32(arg);

if (shift > 1)
return (m_q30 + (1U << (shift - 2))) >> (shift - 1);
if (shift == 1)
return m_q30;
return m_q30 << (1 - shift);
}

/* 20 * log10(peak / noise_floor) in Q24.8 dB using SOF base2_logarithm() (Q16.16) */
static inline uint32_t us_snr_db_q8(uint32_t peak, uint32_t noise_floor)
{
int32_t diff_q16;

if (noise_floor < 1)
noise_floor = 1;
if (peak <= noise_floor)
return 0;

diff_q16 = base2_logarithm(peak) - base2_logarithm(noise_floor);
if (diff_q16 <= 0)
return 0;

return (uint32_t)(((int64_t)diff_q16 * US_20_LOG10_2_Q16 + (1LL << 23)) >> 24);
}

#endif /* __SOF_AUDIO_ULTRASOUND_DSP_H__ */
Loading
Loading