Skip to content

Commit 1989a26

Browse files
committed
Audio: Sound Dose: Add new component
This patch adds a new SOF component Sound Dose. The purpose is to calculate for audio playback MEL values (momentary sound exposure level) to provide to user space the data to compute the sound dose CSD as defined in EN 50332-3. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com> Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent b109287 commit 1989a26

28 files changed

+1443
-2
lines changed

app/boards/intel_adsp/Kconfig.defconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ config PCM_CONVERTER_FORMAT_U8
6161

6262
config PIPELINE_2_0
6363
default y
64+
65+
config COMP_SOUND_DOSE
66+
default y

src/arch/host/configs/library_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CONFIG_COMP_MULTIBAND_DRC=y
1515
CONFIG_COMP_MUX=y
1616
CONFIG_COMP_RTNR=y
1717
CONFIG_COMP_SEL=y
18+
CONFIG_COMP_SOUND_DOSE=y
1819
CONFIG_COMP_SRC=y
1920
CONFIG_COMP_SRC_IPC4_FULL_MATRIX=y
2021
CONFIG_COMP_STUBS=y

src/audio/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ if(NOT CONFIG_COMP_MODULE_SHARED_LIBRARY_BUILD)
8080
if(CONFIG_COMP_SMART_AMP)
8181
add_subdirectory(smart_amp)
8282
endif()
83+
if(CONFIG_COMP_SOUND_DOSE)
84+
add_subdirectory(sound_dose)
85+
endif()
8386
if(CONFIG_COMP_SRC)
8487
add_subdirectory(src)
8588
endif()

src/audio/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ rsource "nxp/Kconfig"
149149
rsource "rtnr/Kconfig"
150150
rsource "selector/Kconfig"
151151
rsource "smart_amp/Kconfig"
152+
rsource "sound_dose/Kconfig"
152153
rsource "src/Kconfig"
153154
rsource "tdfb/Kconfig"
154155
rsource "template/Kconfig"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
3+
if(CONFIG_COMP_SOUND_DOSE STREQUAL "m")
4+
add_subdirectory(llext ${PROJECT_BINARY_DIR}/sound_dose_llext)
5+
add_dependencies(app sound_dose)
6+
else()
7+
add_local_sources(sof sound_dose.c)
8+
add_local_sources(sof sound_dose-generic.c)
9+
add_local_sources(sof sound_dose-ipc4.c)
10+
endif()

src/audio/sound_dose/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
3+
config COMP_SOUND_DOSE
4+
tristate "Sound Dose module"
5+
default m if LIBRARY_DEFAULT_MODULAR
6+
depends on COMP_MODULE_ADAPTER
7+
depends on IPC_MAJOR_4
8+
select MATH_IIR
9+
select MATH_IIR_DF1
10+
select MATH_EXP
11+
help
12+
Select this for Sound Dose SOF module. The purpose is
13+
to calculate for audio playback MEL values (momentary
14+
sound exposure level) to provide to user space the data
15+
to compute the sound dose CSD as defined in EN 50332-3.

src/audio/sound_dose/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Sound Dose
2+
3+
The purpose of this component is to calculate with DSP offload the
4+
headphone audio playback MEL values (momentary sound exposure level).
5+
The calculated MEL values are notified to user space to be available
6+
every one second. The user space should respond to notification with
7+
bytes control get to get the data. The MEL values are used to
8+
calculate the CSD value (cumulative sound dose). Low enough CSD value
9+
ensures the music listening is safe the user's hearing.
10+
11+
The calculation of MEL values and CSD values is defined in EN 50332-3
12+
stadard. The implementation in the Android OS is described in
13+
https://source.android.com/docs/core/audio/sound-dose .
14+
15+
The SOF Sound Dose component should be placed in topology as last
16+
component before playback dai-copier.
17+
18+
Currently it can be tested with next test topologies:
19+
- sof-hda-benchmark-sound_dose32.tplg
20+
- sof-mtl-sdw-benchmark-sound_dose32-sdw0.tplg
21+
- sof-mtl-sdw-benchmark-sound_dose32-simplejack.tplg
22+
23+
E.g. in the sdw topologies the controls for setting it up can be
24+
seen with command:
25+
26+
$ amixer -c0 controls | grep "Jack Out Sound Dose"
27+
numid=33,iface=MIXER,name='Jack Out Sound Dose data bytes'
28+
numid=32,iface=MIXER,name='Jack Out Sound Dose gain bytes'
29+
numid=30,iface=MIXER,name='Jack Out Sound Dose setup bytes'
30+
numid=31,iface=MIXER,name='Jack Out Sound Dose volume bytes'
31+
32+
The above topologies program the setup bytes for acoustical
33+
sensitivity of acoustical 100 dBSPL for 0 dBFS digital level.
34+
The gain is set to 0 dB and volume to 0 dB.
35+
36+
To test the basics copy a compatible test topology over the
37+
normal topology file. Or alternative use module options
38+
tplg_filename and tplg_path for module snd_sof.
39+
40+
Get kcontrol_events from https://github.com/ujfalusi/kcontrol_events
41+
and build and install it.
42+
43+
Start playback of some music or test signal. Note that there is no SOF
44+
volume control component in the test topology, so it plays out at max
45+
volume.
46+
47+
Start in other console kcontrol_events. The control 'Jack Out Sound
48+
Dose data bytes' should get updates every one second. The structures
49+
are defined in src/include/user/audio_feature.h and
50+
src/include/user/sound_dose.h.
51+
52+
The next steps require build of blobs for sof-ctl. The blobs can be
53+
rebuilt with command
54+
55+
cd src/audio/sound_dose/tune; octave --quiet --no-window-system sof_sound_dose_blobs.m
56+
57+
To simulate effect of initial sensitivity setup, try command
58+
59+
sof-ctl -c name='Jack Out Sound Dose setup bytes' -s <path>/sound_dose/setup_sens_0db.txt
60+
sof-ctl -c name='Jack Out Sound Dose setup bytes' -s <path>/sound_dose/setup_sens_100db.txt
61+
62+
To simulate adjusting codec volume control down 10 dB and up again 10 dB
63+
64+
sof-ctl -c name='Jack Out Sound Dose volume bytes' -s ctl4/sound_dose/setup_vol_-10db.txt
65+
sof-ctl -c name='Jack Out Sound Dose volume bytes' -s ctl4/sound_dose/setup_vol_0db.txt
66+
67+
To force user's listening level 10 dB down after observing too large dose per the MSD value
68+
69+
sof-ctl -c name='Jack Out Sound Dose gain bytes' -s ctl4/sound_dose/setup_gain_-10db.txt
70+
71+
To restore user's listening level to non-attenuated
72+
73+
sof-ctl -c name='Jack Out Sound Dose gain bytes' -s ctl4/sound_dose/setup_gain_0db.txt
74+
75+
The above commands have impact to data shown by kcontrol_events.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 Intel Corporation.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
sof_llext_build("sound_dose"
5+
SOURCES ../sound_dose.c
6+
../sound_dose-generic.c
7+
../sound_dose-ipc4.c
8+
LIB openmodules
9+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <tools/rimage/config/platform.toml>
2+
#define LOAD_TYPE "2"
3+
#include "../sound_dose.toml"
4+
5+
[module]
6+
count = __COUNTER__

0 commit comments

Comments
 (0)