|
| 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