Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OpenVino noise suppression model in the SOF plugin #8847

Merged
merged 10 commits into from
Feb 16, 2024
3 changes: 2 additions & 1 deletion posix/include/rtos/panic.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
void dump_panicinfo(void *addr, struct sof_ipc_panic_info *panic_info);
void panic_dump(uint32_t p, struct sof_ipc_panic_info *panic_info,
uintptr_t *data) SOF_NORETURN;
void __panic(uint32_t p, char *filename, uint32_t linenum) SOF_NORETURN;
void __panic(uint32_t p, const char *filename, uint32_t linenum) SOF_NORETURN;

/** panic dump filename and linenumber of the call
*
* \param x panic code defined in ipc/trace.h
*/

#define sof_panic(x) __panic((x), (RELATIVE_FILE), (__LINE__))

/* runtime assertion */
Expand Down
2 changes: 1 addition & 1 deletion src/debug/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void panic_dump(uint32_t p, struct sof_ipc_panic_info *panic_info,
;
}

void __panic(uint32_t panic_code, char *filename, uint32_t linenum)
void __panic(uint32_t panic_code, const char *filename, uint32_t linenum)
{
struct sof_ipc_panic_info panicinfo = { .linenum = linenum };
const unsigned int length_max = sizeof(panicinfo.filename);
Expand Down
6 changes: 3 additions & 3 deletions src/include/sof/audio/audio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ static inline int audio_stream_set_params(struct audio_stream *buffer,
if (!params)
return -EINVAL;

buffer->runtime_stream_params.frame_fmt = params->frame_fmt;
buffer->runtime_stream_params.frame_fmt = (enum sof_ipc_frame)params->frame_fmt;
Copy link
Member

Choose a reason for hiding this comment

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

Good catch by G++, these should be fixed at source though, but sadly I dont think all C compilers allow this

diff --git a/src/include/ipc/stream.h b/src/include/ipc/stream.h
index c397f34a1..6466b2cbc 100644
--- a/src/include/ipc/stream.h
+++ b/src/include/ipc/stream.h
@@ -75,7 +75,7 @@ struct sof_ipc_stream_params {
        struct sof_ipc_hdr hdr;
        struct sof_ipc_host_buffer buffer;
        uint32_t direction;     /**< enum sof_ipc_stream_direction */
-       uint32_t frame_fmt;     /**< enum sof_ipc_frame */
+       enum sof_ipc_frame frame_fmt:32;        /**< enum sof_ipc_frame */
        uint32_t buffer_fmt;    /**< enum sof_ipc_buffer_format */
        uint32_t rate;
        uint16_t stream_tag;

buffer->runtime_stream_params.rate = params->rate;
buffer->runtime_stream_params.channels = params->channels;

Expand Down Expand Up @@ -990,8 +990,8 @@ static inline void audio_stream_fmt_conversion(enum ipc4_bit_depth depth,
* IPC4_DEPTH_24BIT (24) <---> SOF_IPC_FRAME_S24_4LE (1)
* IPC4_DEPTH_32BIT (32) <---> SOF_IPC_FRAME_S32_LE (2)
*/
*frame_fmt = (depth >> 3) - 2;
*valid_fmt = (valid >> 3) - 2;
*frame_fmt = (enum sof_ipc_frame)((depth >> 3) - 2);
*valid_fmt = (enum sof_ipc_frame)((valid >> 3) - 2);

#ifdef CONFIG_FORMAT_U8
if (depth == 8)
Expand Down
2 changes: 2 additions & 0 deletions src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,8 @@ static const struct ipc4_module_uuid uuid_map[] = {
.d = { 0x8d, 0x3f, 0xf9, 0x2c, 0xd5, 0xc4, 0x3c, 0x09 }}}, /* mixin */
{0x3, {.a = 0x3c56505a, .b = 0x24d7, .c = 0x418f,
.d = { 0xbd, 0xdc, 0xc1, 0xf5, 0xa3, 0xac, 0x2a, 0xe0 }}}, /* mixout */
{0x95, {.a = 0x7ae671a7, .b = 0x4617, .c = 0x4a09,
.d = { 0xbf, 0x6d, 0x9d, 0x29, 0xc9, 0x98, 0xdb, 0xc1 }}}, /* noise suppresion */
{0x96, {.a = 0xe2b6031c, .b = 0x47e8, .c = 0x11ed,
.d = { 0x07, 0xa9, 0x7f, 0x80, 0x1b, 0x6e, 0xfa, 0x6c }}}, /* host SHM write */
{0x98, {.a = 0xdabe8814, .b = 0x47e8, .c = 0x11ed,
Expand Down
2 changes: 1 addition & 1 deletion src/platform/library/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <rtos/panic.h>
#include <stdlib.h>

void __panic(uint32_t p, char *filename, uint32_t linenum)
void __panic(uint32_t p, const char *filename, uint32_t linenum)
{
abort();
}
2 changes: 1 addition & 1 deletion test/cmocka/src/common_mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int WEAK rstrlen(const char *s)
return strlen(s);
}

void WEAK __panic(uint32_t p, char *filename, uint32_t linenum)
void WEAK __panic(uint32_t p, const char *filename, uint32_t linenum)
{
fail_msg("panic: %s:%d (code 0x%x)\n", filename, linenum, p);
exit(EXIT_FAILURE);
Expand Down
2 changes: 1 addition & 1 deletion tools/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cmake_minimum_required(VERSION 3.13)

project(SOF_PLUGIN C)
project(SOF_PLUGIN C CXX)

include(../../scripts/cmake/misc.cmake)
include(CheckCCompilerFlag)
Expand Down
27 changes: 26 additions & 1 deletion tools/plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cmake --build build-plugin/
then (use default ALSA prefix atm)

```
sudo make install <ALSA prefix>
sudo cmake --install build-plugin/

Make sure to set the LD_LIBRARY_PATH to include directory where the SOF modules are installed
Ex: "~/work/sof/sof/build_plugin/sof_ep/install/lib:~/work/sof/sof/build_plugin/modules/"
Expand Down Expand Up @@ -76,6 +76,31 @@ Mixer settings can be adjusted for bdw-nocodec by (Not functional yet)
alsamixer -Dsof:tgl-nocodec:1
```

# Instructions for testing OpenVino noise suppression model with the SOF plugin:
1. Fetch the model from the Open Model zoo repository ex: noise-suppression-poconetlike-0001.xml

https://docs.openvino.ai/archive/2023.0/omz_demos.html#build-the-demo-applications-on-linux

2. Source OpenVino environment and get OpenCV
https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit-download.html

3. Worth building and running the demo noise suppression application in the open model zoo
repository to make sure OpenVino and OpenCV are configured properly.

4. Set environment variable NOISE_SUPPRESSION_MODEL_NAME to point to the model file
```
export NOISE_SUPPRESSION_MODEL_NAME="~/open_model_zoo/demos/noise_suppression_demo/cpp/intel/noise-suppression-poconetlike-0001/FP16/noise-suppression-poconetlike-0001.xml"

```
5. Enable noise suppression by setting NOISE_SUPPRESSION=true in the tplg-targets for the sof-plugin topology

6. Start capture using the following command. This uses the 16K capture from the DMIC from
PCM hw device 0,7. Currently, only 16K capture is supported but in the future this will be expanded
to work with 48K capture.
```
arecord -Dsof:plugin:1:0:7:16k2c16b -f dat -r 16000 --period-size=2048 file_ns_16k.wa
```

#TODO Items (and T-shirt size) for single pipeline E2E audio
* IPC4 support in tplg parser (M)
* IPC4 support in plugin (pipe/ipc4.c) (M)
Expand Down
10 changes: 10 additions & 0 deletions tools/plugin/alsaconf/50-sof.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ pcm.sof {
buffer_frames 192
}

config.16k2c16b {
rate 16000
channels 2
format S16_LE
period_time 0
period_frames 2048 # based on the period size needed for Noise suppression module
buffer_time 0
buffer_frames 8192
}

config.48k8c16b {
rate 48000
channels 8
Expand Down
2 changes: 2 additions & 0 deletions tools/plugin/alsaplug/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ static int plug_pcm_hw_free(snd_pcm_ioplug_t *io)
sem_close(pcm->ready[pipe_info->instance_id].sem);
sem_close(pcm->done[pipe_info->instance_id].sem);
}

return 0;
}

static const snd_pcm_ioplug_callback_t sof_playback_callback = {
Expand Down
63 changes: 33 additions & 30 deletions tools/plugin/alsaplug/tplg.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,31 +292,27 @@ static int plug_new_process(snd_sof_plug_t *plug)
{
struct tplg_context *ctx = &plug->tplg;
struct tplg_comp_info *comp_info = ctx->current_comp_info;
struct sof_ipc_comp_process *process;
struct ipc4_base_module_cfg basecfg;
struct snd_soc_tplg_ctl_hdr *tplg_ctl;
int ret;

process = calloc(MAX_TPLG_OBJECT_SIZE, 1);
if (!process)
ret = tplg_parse_widget_audio_formats(ctx);
if (ret < 0)
return ret;

/* only base config supported for now. extn support will be added later */
comp_info->ipc_size = sizeof(struct ipc4_base_module_cfg);
comp_info->ipc_payload = calloc(comp_info->ipc_size, 1);
if (!comp_info->ipc_payload)
return -ENOMEM;

comp_info->ipc_payload = process;
/* FIXME: move this to when the widget is actually set up */
comp_info->instance_id = plug->instance_ids[SND_SOC_TPLG_DAPM_EFFECT]++;
comp_info->module_id = 0x95;

tplg_ctl = calloc(ctx->hdr->payload_size, 1);
if (!tplg_ctl) {
free(process);
return -ENOMEM;
}
plug_setup_widget_ipc_msg(comp_info);

ret = tplg_new_process(ctx, process, MAX_TPLG_OBJECT_SIZE,
tplg_ctl, ctx->hdr->payload_size);
if (ret < 0) {
SNDERR("error: failed to create PGA\n");
goto out;
}
out:
free(tplg_ctl);
return ret;
return 0;
}

static int plug_new_pipeline(snd_sof_plug_t *plug)
Expand Down Expand Up @@ -699,13 +695,10 @@ static int plug_match_audio_format(snd_sof_plug_t *plug, struct tplg_comp_info *
(fmt->audio_fmt.fmt_cfg & MASK(15, 8)) >> 8;
base_cfg->audio_fmt.s_type =
(fmt->audio_fmt.fmt_cfg & MASK(23, 16)) >> 16;
base_cfg->ibs = fmt->buffer_size;

/*
* FIXME: is this correct? Choose ALSA period size for obs so that the buffer sizes
* will set accodingly. Need to get channel count and format from output format
*/
base_cfg->obs = plug->period_size * 2 * 2;
/* Choose ALSA period size for ibs/obs so that the buffer sizes will be set accordingly */
base_cfg->ibs = plug->period_size * 2;
base_cfg->obs = plug->period_size * 2;

return 0;
}
Expand Down Expand Up @@ -1022,7 +1015,7 @@ static int plug_prepare_widgets_capture(snd_sof_plug_t *plug, struct tplg_pcm_in
struct list_item *item;
int ret;

/* for playback */
/* for capture */
list_for_item(item, &plug->route_list) {
struct tplg_route_info *route_info = container_of(item, struct tplg_route_info,
item);
Expand All @@ -1045,8 +1038,8 @@ static int plug_prepare_widgets_capture(snd_sof_plug_t *plug, struct tplg_pcm_in
/* and then continue up the path */
if (route_info->source->type != SND_SOC_TPLG_DAPM_DAI_IN &&
route_info->source->type != SND_SOC_TPLG_DAPM_DAI_OUT) {
ret = plug_prepare_widgets(plug, pcm_info, starting_comp_info,
route_info->source);
ret = plug_prepare_widgets_capture(plug, pcm_info, starting_comp_info,
route_info->source);
if (ret < 0)
return ret;
}
Expand Down Expand Up @@ -1199,7 +1192,8 @@ static int plug_set_up_widgets_capture(snd_sof_plug_t *plug,
/* and then continue down the path */
if (route_info->source->type != SND_SOC_TPLG_DAPM_DAI_IN &&
route_info->source->type != SND_SOC_TPLG_DAPM_DAI_OUT) {
ret = plug_set_up_widgets(plug, starting_comp_info, route_info->source);
ret = plug_set_up_widgets_capture(plug, starting_comp_info,
route_info->source);
if (ret < 0)
return ret;
}
Expand Down Expand Up @@ -1389,7 +1383,8 @@ static int plug_free_widgets_capture(snd_sof_plug_t *plug,
/* and then continue down the path */
if (route_info->sink->type != SND_SOC_TPLG_DAPM_DAI_IN &&
route_info->sink->type != SND_SOC_TPLG_DAPM_DAI_OUT) {
ret = plug_free_widgets(plug, starting_comp_info, route_info->source);
ret = plug_free_widgets_capture(plug, starting_comp_info,
route_info->source);
if (ret < 0)
return ret;
}
Expand All @@ -1409,7 +1404,10 @@ int plug_free_pipelines(snd_sof_plug_t *plug, struct tplg_pipeline_list *pipelin
pcm_info = container_of(item, struct tplg_pcm_info, item);

if (pcm_info->id == plug->pcm_id) {
host = pcm_info->playback_host; /* FIXME */
if (dir)
host = pcm_info->capture_host;
else
host = pcm_info->playback_host;
break;
}
}
Expand All @@ -1420,6 +1418,11 @@ int plug_free_pipelines(snd_sof_plug_t *plug, struct tplg_pipeline_list *pipelin
}

if (dir) {
ret = plug_free_widgets_capture(plug, host, host);
if (ret < 0) {
SNDERR("failed to free widgets for capture PCM %d\n", plug->pcm_id);
return ret;
}
} else {
ret = plug_free_widgets(plug, host, host);
if (ret < 0) {
Expand Down
2 changes: 2 additions & 0 deletions tools/plugin/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ set_target_properties(sof_mod_alsa
INSTALL_RPATH "${sof_install_directory}/alsa-lib"
INSTALL_RPATH_USE_LINK_PATH TRUE
)

add_subdirectory(ov_noise_suppression)
42 changes: 42 additions & 0 deletions tools/plugin/modules/ov_noise_suppression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: BSD-3-Clause

# Noise suppression module
find_package(OpenVINO COMPONENTS Runtime)

if(OpenVINO_FOUND)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if(OpenVINO_FOUND)
if(OpenVINO_FOUND)

Can you move the find_package() and if() to the parent CMakeLists.txt? This avoids the entire file being guarded.

add_library(sof_ns_interface STATIC noise_suppression_interface.cpp)
target_link_libraries(sof_ns_interface PRIVATE -Wl,--export-dynamic)
target_link_libraries(sof_ns_interface PRIVATE openvino::runtime)
target_compile_options(sof_ns_interface PRIVATE -fPIC)
target_include_directories(sof_ns_interface PRIVATE ${sof_source_directory}/src/include)
target_include_directories(sof_ns_interface PRIVATE ${sof_source_directory}/posix/include)
target_include_directories(sof_ns_interface PRIVATE ${sof_source_directory}/src/arch/host/include)
target_include_directories(sof_ns_interface PRIVATE ${sof_source_directory}/src/platform/posix/include)
set_target_properties(sof_ns_interface PROPERTIES LINKER_LANGUAGE CXX)
sof_append_relative_path_definitions(sof_ns_interface)
install(TARGETS sof_ns_interface DESTINATION /usr/lib/x86_64-linux-gnu/alsa-lib)

add_library(sof_ns MODULE noise_suppression.c)
target_link_libraries(sof_ns PRIVATE sof_ns_interface)
target_link_libraries(sof_ns PRIVATE -Wl,--export-dynamic)
sof_append_relative_path_definitions(sof_ns)
target_compile_options(sof_ns PRIVATE -DPIC -g -O3 -Wl,-EL -Wall -Werror -DCONFIG_LIBRARY -imacros${config_h})
install(TARGETS sof_ns DESTINATION /usr/lib/x86_64-linux-gnu/alsa-lib)

target_include_directories(sof_ns PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_SOURCE_DIR}/../pipe
${sof_source_directory}/src/audio)


target_link_options(sof_ns PRIVATE -Wl,--export-dynamic)
target_include_directories(sof_ns PRIVATE ${sof_install_directory}/include)
target_include_directories(sof_ns PRIVATE ${parser_install_dir}/include)

set_target_properties(sof_ns
PROPERTIES
INSTALL_RPATH "${sof_install_directory}/alsa-lib"
INSTALL_RPATH_USE_LINK_PATH TRUE
)
endif()
Loading
Loading