Skip to content

Commit fd996bd

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 68a023a commit fd996bd

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
% Export configuration blobs for Level Multiplier
2+
3+
% SPDX-License-Identifier: BSD-3-Clause
4+
%
5+
% Copyright (c) 2025, Intel Corporation.
6+
7+
function sof_level_multiplier_blobs()
8+
9+
% Set the parameters here
10+
sof_tools = '../../../../tools';
11+
sof_tplg = fullfile(sof_tools, 'topology/topology2');
12+
sof_tplg_level_multiplier = fullfile(sof_tplg, 'include/components/level_multiplier');
13+
sof_ctl_level_multiplier = fullfile(sof_tools, 'ctl/ipc4/level_multiplier');
14+
15+
sof_level_multiplier_paths(true);
16+
17+
for param = -40:10:40
18+
gain_value = sof_level_multiplier_db2lin(param);
19+
blob8 = sof_level_multiplier_build_blob(gain_value);
20+
tplg2_fn = sprintf("%s/gain_%d_db.conf", sof_tplg_level_multiplier, param);
21+
sof_tplg2_write(tplg2_fn, blob8, "level_multiplier_config", ...
22+
"Exported with script sof_level_multiplier_blobs.m" , ...
23+
"cd tools/tune/level_multiplier; octave sof_level_multiplier_blobs.m");
24+
ctl_fn = sprintf("%s/gain_%d_db.txt", sof_ctl_level_multiplier, param);
25+
sof_alsactl_write(ctl_fn, blob8);
26+
end
27+
28+
sof_level_multiplier_paths(false);
29+
end
30+
31+
function lin_value = sof_level_multiplier_db2lin(db)
32+
scale = 2^23;
33+
lin_value = int32(10^(db/20) * scale);
34+
end
35+
36+
function sof_level_multiplier_paths(enable)
37+
38+
common = '../../../../tools/tune/common';
39+
if enable
40+
addpath(common);
41+
else
42+
rmpath(common);
43+
end
44+
end
45+
46+
function blob8 = sof_level_multiplier_build_blob(param_values)
47+
48+
blob_type = 0;
49+
blob_param_id = 1;
50+
data_length = length(param_values);
51+
data_size = 4 * data_length;
52+
ipc_ver = 4;
53+
[abi_bytes, abi_size] = sof_get_abi(data_size, ipc_ver, blob_type, blob_param_id);
54+
blob_size = data_size + abi_size;
55+
blob8 = uint8(zeros(1, blob_size));
56+
blob8(1:abi_size) = abi_bytes;
57+
j = abi_size + 1;
58+
for i = 1:data_length
59+
blob8(j:j+3) = word2byte(param_values(i));
60+
j=j+4;
61+
end
62+
end
63+
64+
function bytes = word2byte(word)
65+
sh = [0 -8 -16 -24];
66+
bytes = uint8(zeros(1,4));
67+
bytes(1) = bitand(bitshift(word, sh(1)), 255);
68+
bytes(2) = bitand(bitshift(word, sh(2)), 255);
69+
bytes(3) = bitand(bitshift(word, sh(3)), 255);
70+
bytes(4) = bitand(bitshift(word, sh(4)), 255);
71+
end

0 commit comments

Comments
 (0)