-
Notifications
You must be signed in to change notification settings - Fork 349
Audio: Level multiplier: Add new component #10176
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
Merged
lgirdwood
merged 5 commits into
thesofproject:main
from
singalsu:add_level_multiply_comp
Sep 10, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7dee064
Audio: Level multiplier: Add new component
singalsu 99637fa
Audio: Level Multiplier: Add blobs generate script
singalsu 7aea06f
Audio: Level Multiplier: Add HiFi3/HiFi4 processing version
singalsu af635da
Audio: Level Multiplier: Add HiFi5 processing
singalsu 36bd4b2
Tools: Topology: Add test topology for Level Multiplier
singalsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| if(CONFIG_COMP_LEVEL_MULTIPLIER STREQUAL "m") | ||
| add_subdirectory(llext ${PROJECT_BINARY_DIR}/level_multiplier_llext) | ||
| add_dependencies(app level_multiplier) | ||
| else() | ||
| add_local_sources(sof level_multiplier.c) | ||
| add_local_sources(sof level_multiplier-generic.c) | ||
| add_local_sources(sof level_multiplier-hifi3.c) | ||
| add_local_sources(sof level_multiplier-hifi5.c) | ||
|
|
||
| if(CONFIG_IPC_MAJOR_4) | ||
| add_local_sources(sof level_multiplier-ipc4.c) | ||
| endif() | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| config COMP_LEVEL_MULTIPLIER | ||
| tristate "Level multiplier component" | ||
| default y | ||
| help | ||
| Select for Level multiplier component. This component | ||
| applies a fixed gain to audio. The amount of gain | ||
| is configured in the bytes control that is typically | ||
| set in boot time from topology. It can e.g. increase | ||
| capture sensitivity of voice applications by 20 dB | ||
| compared to media capture. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| // Copyright(c) 2025 Intel Corporation. | ||
|
|
||
| #include <sof/audio/module_adapter/module/generic.h> | ||
| #include <sof/audio/component.h> | ||
| #include <sof/audio/sink_api.h> | ||
| #include <sof/audio/sink_source_utils.h> | ||
| #include <sof/audio/source_api.h> | ||
| #include <stdint.h> | ||
| #include "level_multiplier.h" | ||
|
|
||
| #define LEVEL_MULTIPLIER_S16_SHIFT Q_SHIFT_BITS_32(15, LEVEL_MULTIPLIER_QXY_Y, 15) | ||
| #define LEVEL_MULTIPLIER_S24_SHIFT Q_SHIFT_BITS_64(23, LEVEL_MULTIPLIER_QXY_Y, 23) | ||
| #define LEVEL_MULTIPLIER_S32_SHIFT Q_SHIFT_BITS_64(31, LEVEL_MULTIPLIER_QXY_Y, 31) | ||
|
|
||
| #if SOF_USE_HIFI(NONE, VOLUME) | ||
|
|
||
| #if CONFIG_FORMAT_S16LE | ||
| /** | ||
| * level_multiplier_s16() - Process S16_LE format. | ||
| * @mod: Pointer to module data. | ||
| * @source: Source for PCM samples data. | ||
| * @sink: Sink for PCM samples data. | ||
| * @frames: Number of audio data frames to process. | ||
| * | ||
| * This is the processing function for 16-bit signed integer PCM formats. The | ||
| * audio samples are copied from source to sink with gain defined in cd->gain. | ||
| * | ||
| * Return: Value zero for success, otherwise an error code. | ||
| */ | ||
| static int level_multiplier_s16(const struct processing_module *mod, | ||
| struct sof_source *source, | ||
| struct sof_sink *sink, | ||
| uint32_t frames) | ||
| { | ||
| struct level_multiplier_comp_data *cd = module_get_private_data(mod); | ||
| const int32_t gain = cd->gain; | ||
| int16_t const *x, *x_start, *x_end; | ||
| int16_t *y, *y_start, *y_end; | ||
| int x_size, y_size; | ||
| int source_samples_without_wrap; | ||
| int samples_without_wrap; | ||
| int remaining_samples = frames * cd->channels; | ||
| int bytes = frames * cd->frame_bytes; | ||
| int ret; | ||
| int i; | ||
|
|
||
| ret = source_get_data_s16(source, bytes, &x, &x_start, &x_size); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| /* Similarly get pointer to sink data in circular buffer, buffer start and size. */ | ||
| ret = sink_get_buffer_s16(sink, bytes, &y, &y_start, &y_size); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| /* Set helper pointers to buffer end for wrap check. Then loop until all | ||
| * samples are processed. | ||
| */ | ||
| x_end = x_start + x_size; | ||
| y_end = y_start + y_size; | ||
| while (remaining_samples) { | ||
| /* Find out samples to process before first wrap or end of data. */ | ||
| source_samples_without_wrap = x_end - x; | ||
| samples_without_wrap = y_end - y; | ||
| samples_without_wrap = MIN(samples_without_wrap, source_samples_without_wrap); | ||
| samples_without_wrap = MIN(samples_without_wrap, remaining_samples); | ||
| for (i = 0; i < samples_without_wrap; i++) { | ||
| *y = q_multsr_sat_32x32_16(*x, gain, LEVEL_MULTIPLIER_S16_SHIFT); | ||
| x++; | ||
| y++; | ||
| } | ||
|
|
||
| /* One of the buffers needs a wrap (or end of data), so check for wrap */ | ||
| x = (x >= x_end) ? x - x_size : x; | ||
| y = (y >= y_end) ? y - y_size : y; | ||
|
|
||
| remaining_samples -= samples_without_wrap; | ||
| } | ||
|
|
||
| /* Update the source and sink for bytes consumed and produced. Return success. */ | ||
| source_release_data(source, bytes); | ||
| sink_commit_buffer(sink, bytes); | ||
| return 0; | ||
| } | ||
| #endif /* CONFIG_FORMAT_S16LE */ | ||
|
|
||
| #if CONFIG_FORMAT_S24LE | ||
| /** | ||
| * level_multiplier_s24() - Process S24_4LE format. | ||
| * @mod: Pointer to module data. | ||
| * @source: Source for PCM samples data. | ||
| * @sink: Sink for PCM samples data. | ||
| * @frames: Number of audio data frames to process. | ||
| * | ||
| * This is the processing function for 24-bit signed integer PCM formats. The | ||
| * audio samples are copied from source to sink with gain defined in cd->gain. | ||
| * | ||
| * Return: Value zero for success, otherwise an error code. | ||
| */ | ||
| static int level_multiplier_s24(const struct processing_module *mod, | ||
| struct sof_source *source, | ||
| struct sof_sink *sink, | ||
| uint32_t frames) | ||
| { | ||
| struct level_multiplier_comp_data *cd = module_get_private_data(mod); | ||
| const int32_t gain = cd->gain; | ||
| int32_t const *x, *x_start, *x_end; | ||
| int32_t *y, *y_start, *y_end; | ||
| int x_size, y_size; | ||
| int source_samples_without_wrap; | ||
| int samples_without_wrap; | ||
| int remaining_samples = frames * cd->channels; | ||
| int bytes = frames * cd->frame_bytes; | ||
| int ret; | ||
| int i; | ||
|
|
||
| ret = source_get_data_s32(source, bytes, &x, &x_start, &x_size); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| /* Similarly get pointer to sink data in circular buffer, buffer start and size. */ | ||
| ret = sink_get_buffer_s32(sink, bytes, &y, &y_start, &y_size); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| /* Set helper pointers to buffer end for wrap check. Then loop until all | ||
| * samples are processed. | ||
| */ | ||
| x_end = x_start + x_size; | ||
| y_end = y_start + y_size; | ||
| while (remaining_samples) { | ||
| /* Find out samples to process before first wrap or end of data. */ | ||
| source_samples_without_wrap = x_end - x; | ||
| samples_without_wrap = y_end - y; | ||
| samples_without_wrap = MIN(samples_without_wrap, source_samples_without_wrap); | ||
| samples_without_wrap = MIN(samples_without_wrap, remaining_samples); | ||
| for (i = 0; i < samples_without_wrap; i++) { | ||
| *y = q_multsr_sat_32x32_24(sign_extend_s24(*x), gain, | ||
| LEVEL_MULTIPLIER_S24_SHIFT); | ||
| x++; | ||
| y++; | ||
| } | ||
|
|
||
| /* One of the buffers needs a wrap (or end of data), so check for wrap */ | ||
| x = (x >= x_end) ? x - x_size : x; | ||
| y = (y >= y_end) ? y - y_size : y; | ||
|
|
||
| remaining_samples -= samples_without_wrap; | ||
| } | ||
|
|
||
| /* Update the source and sink for bytes consumed and produced. Return success. */ | ||
| source_release_data(source, bytes); | ||
| sink_commit_buffer(sink, bytes); | ||
| return 0; | ||
| } | ||
| #endif /* CONFIG_FORMAT_S24LE */ | ||
|
|
||
| #if CONFIG_FORMAT_S32LE | ||
| /** | ||
| * level_multiplier_s32() - Process S32_LE format. | ||
| * @mod: Pointer to module data. | ||
| * @source: Source for PCM samples data. | ||
| * @sink: Sink for PCM samples data. | ||
| * @frames: Number of audio data frames to process. | ||
| * | ||
| * This is the processing function for 32-bit signed integer PCM formats. The | ||
| * audio samples are copied from source to sink with gain defined in cd->gain. | ||
| * | ||
| * Return: Value zero for success, otherwise an error code. | ||
| */ | ||
| static int level_multiplier_s32(const struct processing_module *mod, | ||
| struct sof_source *source, | ||
| struct sof_sink *sink, | ||
| uint32_t frames) | ||
| { | ||
| struct level_multiplier_comp_data *cd = module_get_private_data(mod); | ||
| const int32_t gain = cd->gain; | ||
| int32_t const *x, *x_start, *x_end; | ||
| int32_t *y, *y_start, *y_end; | ||
| int x_size, y_size; | ||
| int source_samples_without_wrap; | ||
| int samples_without_wrap; | ||
| int remaining_samples = frames * cd->channels; | ||
| int bytes = frames * cd->frame_bytes; | ||
| int ret; | ||
| int i; | ||
|
|
||
| ret = source_get_data_s32(source, bytes, &x, &x_start, &x_size); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| /* Similarly get pointer to sink data in circular buffer, buffer start and size. */ | ||
| ret = sink_get_buffer_s32(sink, bytes, &y, &y_start, &y_size); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| /* Set helper pointers to buffer end for wrap check. Then loop until all | ||
| * samples are processed. | ||
| */ | ||
| x_end = x_start + x_size; | ||
| y_end = y_start + y_size; | ||
| while (remaining_samples) { | ||
| /* Find out samples to process before first wrap or end of data. */ | ||
| source_samples_without_wrap = x_end - x; | ||
| samples_without_wrap = y_end - y; | ||
| samples_without_wrap = MIN(samples_without_wrap, source_samples_without_wrap); | ||
| samples_without_wrap = MIN(samples_without_wrap, remaining_samples); | ||
| for (i = 0; i < samples_without_wrap; i++) { | ||
| *y = q_multsr_sat_32x32(*x, gain, LEVEL_MULTIPLIER_S32_SHIFT); | ||
| x++; | ||
| y++; | ||
| } | ||
|
|
||
| /* One of the buffers needs a wrap (or end of data), so check for wrap */ | ||
| x = (x >= x_end) ? x - x_size : x; | ||
| y = (y >= y_end) ? y - y_size : y; | ||
|
|
||
| remaining_samples -= samples_without_wrap; | ||
| } | ||
|
|
||
| /* Update the source and sink for bytes consumed and produced. Return success. */ | ||
| source_release_data(source, bytes); | ||
| sink_commit_buffer(sink, bytes); | ||
| return 0; | ||
| } | ||
| #endif /* CONFIG_FORMAT_S32LE */ | ||
|
|
||
| /* This struct array defines the used processing functions for | ||
| * the PCM formats | ||
| */ | ||
| const struct level_multiplier_proc_fnmap level_multiplier_proc_fnmap[] = { | ||
| #if CONFIG_FORMAT_S16LE | ||
| { SOF_IPC_FRAME_S16_LE, level_multiplier_s16 }, | ||
| #endif | ||
| #if CONFIG_FORMAT_S24LE | ||
| { SOF_IPC_FRAME_S24_4LE, level_multiplier_s24 }, | ||
| #endif | ||
| #if CONFIG_FORMAT_S32LE | ||
| { SOF_IPC_FRAME_S32_LE, level_multiplier_s32 }, | ||
| #endif | ||
| }; | ||
|
|
||
| /** | ||
| * level_multiplier_find_proc_func() - Find suitable processing function. | ||
| * @src_fmt: Enum value for PCM format. | ||
| * | ||
| * This function finds the suitable processing function to use for | ||
| * the used PCM format. If not found, return NULL. | ||
| * | ||
| * Return: Pointer to processing function for the requested PCM format. | ||
| */ | ||
| level_multiplier_func level_multiplier_find_proc_func(enum sof_ipc_frame src_fmt) | ||
| { | ||
| int i; | ||
|
|
||
| /* Find suitable processing function from map */ | ||
| for (i = 0; i < ARRAY_SIZE(level_multiplier_proc_fnmap); i++) | ||
| if (src_fmt == level_multiplier_proc_fnmap[i].frame_fmt) | ||
| return level_multiplier_proc_fnmap[i].level_multiplier_proc_func; | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| #endif /* SOF_USE_HIFI(NONE, VOLUME) */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw - mix of tabs/spaces ? Not a blocker.