Skip to content

Commit 99637fa

Browse files
committed
Audio: Level Multiplier: Add blobs generate script
This patch adds script sof_level_multiplier_blobs.m It exports blobs for -40 to +40 dB gain configuration. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 7dee064 commit 99637fa

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

scripts/sof-rebuild-processing-comp-blobs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ cd "$SOF_WORKSPACE"/sof/src/audio/multiband_drc/tune; $OCTAVE sof_example_multib
4141
cd "$SOF_WORKSPACE"/sof/src/audio/tdfb/tune; ./sof_example_all.sh
4242
cd "$SOF_WORKSPACE"/sof/src/audio/selector/tune; $OCTAVE ./sof_selector_blobs.m
4343
cd "$SOF_WORKSPACE"/sof/tools/tune/mfcc; $OCTAVE setup_mfcc.m
44+
cd "$SOF_WORKSPACE"/sof/src/audio/level_multiplier/tune; $OCTAVE sof_level_multiplier_blobs.m
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
% Export configuration blobs for Level Multiplier
2+
%
3+
% This script creates configuration blobs for the Level Multiplier
4+
% component to apply gains -40, -30, -20, -10, 0, 10, 20, 30, 40 dB.
5+
% Run the script interactively from Octave shell with just command:
6+
%
7+
% sof_level_multiplier_blobs
8+
%
9+
% There are no arguments for the function. Or from SOF level directory
10+
% with command:
11+
%
12+
% cd src/audio/level_multiplier/tune; octave sof_level_multiplier_blobs.m
13+
%
14+
15+
% SPDX-License-Identifier: BSD-3-Clause
16+
%
17+
% Copyright (c) 2025, Intel Corporation.
18+
19+
function sof_level_multiplier_blobs()
20+
21+
% Set the parameters here
22+
sof_tools = '../../../../tools';
23+
sof_tplg = fullfile(sof_tools, 'topology/topology2');
24+
sof_tplg_level_multiplier = fullfile(sof_tplg, 'include/components/level_multiplier');
25+
sof_ctl_level_multiplier = fullfile(sof_tools, 'ctl/ipc4/level_multiplier');
26+
27+
sof_level_multiplier_paths(true);
28+
29+
for param = -40:10:40
30+
gain_value = sof_level_multiplier_db2lin(param);
31+
blob8 = sof_level_multiplier_build_blob(gain_value);
32+
tplg2_fn = sprintf("%s/gain_%d_db.conf", sof_tplg_level_multiplier, param);
33+
sof_tplg2_write(tplg2_fn, blob8, "level_multiplier_config", ...
34+
"Exported with script sof_level_multiplier_blobs.m" , ...
35+
"cd tools/tune/level_multiplier; octave sof_level_multiplier_blobs.m");
36+
ctl_fn = sprintf("%s/gain_%d_db.txt", sof_ctl_level_multiplier, param);
37+
sof_alsactl_write(ctl_fn, blob8);
38+
end
39+
40+
sof_level_multiplier_paths(false);
41+
end
42+
43+
function lin_value = sof_level_multiplier_db2lin(db)
44+
scale = 2^23;
45+
lin_value = int32(10^(db/20) * scale);
46+
end
47+
48+
function sof_level_multiplier_paths(enable)
49+
50+
common = '../../../../tools/tune/common';
51+
if enable
52+
addpath(common);
53+
else
54+
rmpath(common);
55+
end
56+
end
57+
58+
function blob8 = sof_level_multiplier_build_blob(param_values)
59+
60+
blob_type = 0;
61+
blob_param_id = 1;
62+
data_length = length(param_values);
63+
data_size = 4 * data_length;
64+
ipc_ver = 4;
65+
[abi_bytes, abi_size] = sof_get_abi(data_size, ipc_ver, blob_type, blob_param_id);
66+
blob_size = data_size + abi_size;
67+
blob8 = uint8(zeros(1, blob_size));
68+
blob8(1:abi_size) = abi_bytes;
69+
j = abi_size + 1;
70+
for i = 1:data_length
71+
blob8(j:j+3) = word2byte(param_values(i));
72+
j=j+4;
73+
end
74+
end
75+
76+
function bytes = word2byte(word)
77+
sh = [0 -8 -16 -24];
78+
bytes = uint8(zeros(1,4));
79+
bytes(1) = bitand(bitshift(word, sh(1)), 255);
80+
bytes(2) = bitand(bitshift(word, sh(2)), 255);
81+
bytes(3) = bitand(bitshift(word, sh(3)), 255);
82+
bytes(4) = bitand(bitshift(word, sh(4)), 255);
83+
end

0 commit comments

Comments
 (0)