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