From e67ce01dc24c829e0dad38a6778236e264cb44c8 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 22 Apr 2024 11:36:49 +0300 Subject: [PATCH 1/6] Tools: Tune: Use common/sof_ucm_blob_write.m for binary blob export The sof_ucm_blob_write.m is an updated copy of blob_write that exports binary blobs with header that is suitable for ALSA UCM's cset-tlv command. The UCM requires binary files so the default binary export is changed for every component setup script to this format. The ASCII decimal numbers .txt format export remains suitable for sof-ctl tool. Signed-off-by: Seppo Ingalsuo --- tools/tune/common/sof_ucm_blob_write.m | 52 +++++++++++++++++++ tools/tune/crossover/example_crossover.m | 2 +- tools/tune/dcblock/example_dcblock.m | 4 +- tools/tune/drc/example_drc.m | 4 +- tools/tune/eq/example_fir_eq.m | 8 ++- tools/tune/eq/example_iir_bandsplit.m | 5 +- tools/tune/eq/example_iir_eq.m | 10 ++-- tools/tune/eq/example_spk_eq.m | 12 +++-- .../multiband_drc/example_multiband_drc.m | 4 +- 9 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 tools/tune/common/sof_ucm_blob_write.m diff --git a/tools/tune/common/sof_ucm_blob_write.m b/tools/tune/common/sof_ucm_blob_write.m new file mode 100644 index 000000000000..0a6c4da4454a --- /dev/null +++ b/tools/tune/common/sof_ucm_blob_write.m @@ -0,0 +1,52 @@ +function sof_ucm_blob_write(fn, blob8) + +% Export blob to UCM2 cset-tlv binary format +% +% sof_ucm_blob_write(fn, blob) +% +% Input parameters +% fn - Filename for the blob +% blob - Vector of data with uint8 type +% + +% SPDX-License-Identifier: BSD-3-Clause +% +% Copyright (c) 2024, Intel Corporation. All rights reserved. + +% Export for UCM cset-tlv with additional 8 bytes header +SOF_CTRL_CMD_BINARY = 3; +nh = 8; +nb = length(blob8); +ublob8 = zeros(nb + nh, 1, 'uint8'); +ublob8(1:4) = w32b(SOF_CTRL_CMD_BINARY); +ublob8(5:8) = w32b(nb); +ublob8(9:end) = blob8; + +%% Write blob +check_create_dir(fn); +fh = fopen(fn, 'wb'); +fwrite(fh, ublob8, 'uint8'); +fclose(fh); + +%% Print as 8 bit hex +nb = length(ublob8); +nl = ceil(nb/16); +for i = 1:nl + m = min(16, nb-(i-1)*16); + for j = 1:m + fprintf(1, "%02x ", ublob8((i-1)*16 + j)); + end + fprintf(1, "\n"); +end + +fprintf(1, "\n"); +end + +function bytes = w32b(word) +sh = [0 -8 -16 -24]; +bytes = uint8(zeros(1,4)); +bytes(1) = bitand(bitshift(word, sh(1)), 255); +bytes(2) = bitand(bitshift(word, sh(2)), 255); +bytes(3) = bitand(bitshift(word, sh(3)), 255); +bytes(4) = bitand(bitshift(word, sh(4)), 255); +end diff --git a/tools/tune/crossover/example_crossover.m b/tools/tune/crossover/example_crossover.m index 6bdf596abc45..7b93b0edf5da 100644 --- a/tools/tune/crossover/example_crossover.m +++ b/tools/tune/crossover/example_crossover.m @@ -88,7 +88,7 @@ function export_crossover(cr) mkdir_check(ctlpath); tplg_write(tplg1_fn, blob8, "CROSSOVER"); tplg2_write(tplg2_fn, blob8_ipc4, "crossover_config", 'Exported Control Bytes'); -blob_write(blob_fn, blob8); +sof_ucm_blob_write(blob_fn, blob8); alsactl_write(alsa_fn, blob8); % Plot Magnitude and Phase Response of each sink diff --git a/tools/tune/dcblock/example_dcblock.m b/tools/tune/dcblock/example_dcblock.m index 6ffa179e5485..5e1d022c8e61 100644 --- a/tools/tune/dcblock/example_dcblock.m +++ b/tools/tune/dcblock/example_dcblock.m @@ -58,13 +58,13 @@ function dcblock_blob_calculate(prm) tplg_write(tplg1_fn, blob8, "DCBLOCK", ... "Exported with script example_dcblock.m", ... "cd tools/tune/dcblock; octave example_dcblock.m"); -blob_write(blob3_fn, blob8); +sof_ucm_blob_write(blob3_fn, blob8); alsactl_write(alsa3_fn, blob8); tplg2_write(tplg2_fn, blob8_ipc4, "dcblock_config", ... "Exported with script example_dcblock.m" , ... "cd tools/tune/dcblock; octave example_dcblock.m"); -blob_write(blob4_fn, blob8_ipc4); +sof_ucm_blob_write(blob4_fn, blob8_ipc4); alsactl_write(alsa4_fn, blob8_ipc4); % Plot Filter's Transfer Function and Step Response diff --git a/tools/tune/drc/example_drc.m b/tools/tune/drc/example_drc.m index 4ebae19c0be4..2a21fe1d9c3a 100644 --- a/tools/tune/drc/example_drc.m +++ b/tools/tune/drc/example_drc.m @@ -73,9 +73,9 @@ function drc_coefs_and_config_export(params, id) drc_howto = sprintf("cd tools/tune/drc; octave --no-window-system %s.m", my_name); tplg_write(tplg1_fn, blob8, "DRC", drc_note, drc_howto); tplg2_write(tplg2_fn, blob8_ipc4, "drc_config", drc_note, drc_howto); -blob_write(blob3_fn, blob8); +sof_ucm_blob_write(blob3_fn, blob8); alsactl_write(alsa3_fn, blob8); -blob_write(blob4_fn, blob8_ipc4); +sof_ucm_blob_write(blob4_fn, blob8_ipc4); alsactl_write(alsa4_fn, blob8_ipc4); % Plot x-y response in dB diff --git a/tools/tune/eq/example_fir_eq.m b/tools/tune/eq/example_fir_eq.m index 3131b88992ac..be942cd37e7e 100644 --- a/tools/tune/eq/example_fir_eq.m +++ b/tools/tune/eq/example_fir_eq.m @@ -16,6 +16,8 @@ function example_fir_eq() fn.tpath2 = '../../topology/topology2/include/components/eqfir'; fn.priv = 'DEF_EQFIR_PRIV'; +addpath ../common + %% ------------------- %% Example 1: Loudness %% ------------------- @@ -133,6 +135,8 @@ function example_fir_eq() %% Done. %% -------------------------- +rmpath ../common + end %% ------------------- @@ -221,7 +225,7 @@ function eq_pack_export(bm, fn, note) bp = eq_fir_blob_pack(bm, 3); % IPC3 if ~isempty(fn.bin) - eq_blob_write(fullfile(fn.cpath3, fn.bin), bp); + sof_ucm_blob_write(fullfile(fn.cpath3, fn.bin), bp); end if ~isempty(fn.txt) eq_alsactl_write(fullfile(fn.cpath3, fn.txt), bp); @@ -232,7 +236,7 @@ function eq_pack_export(bm, fn, note) bp = eq_fir_blob_pack(bm, 4); % IPC4 if ~isempty(fn.bin) - eq_blob_write(fullfile(fn.cpath4, fn.bin), bp); + sof_ucm_blob_write(fullfile(fn.cpath4, fn.bin), bp); end if ~isempty(fn.txt) eq_alsactl_write(fullfile(fn.cpath4, fn.txt), bp); diff --git a/tools/tune/eq/example_iir_bandsplit.m b/tools/tune/eq/example_iir_bandsplit.m index 37e6bcd60336..fdef97ffe7df 100644 --- a/tools/tune/eq/example_iir_bandsplit.m +++ b/tools/tune/eq/example_iir_bandsplit.m @@ -14,6 +14,8 @@ function example_iir_bandsplit() cpath = '../../ctl'; priv = 'DEF_EQIIR_PRIV'; +addpath ../common + %% -------------------------------------------------- %% Example: Band-split 2ch to 4ch low and high bands %% -------------------------------------------------- @@ -47,6 +49,7 @@ function example_iir_bandsplit() %% Done. %% ------------------------------------ +rmpath ../common end %% ------------------- @@ -126,7 +129,7 @@ function eq_pack_export(bm, bin_fn, ascii_fn, tplg_fn, priv, note) bp = eq_iir_blob_pack(bm); if ~isempty(bin_fn) - eq_blob_write(bin_fn, bp); + sof_ucm_blob_write(bin_fn, bp); end if ~isempty(ascii_fn) diff --git a/tools/tune/eq/example_iir_eq.m b/tools/tune/eq/example_iir_eq.m index 990ebcb7d317..b47aa7405ef5 100644 --- a/tools/tune/eq/example_iir_eq.m +++ b/tools/tune/eq/example_iir_eq.m @@ -16,6 +16,8 @@ function example_iir_eq() fn.tpath2 = '../../topology/topology2/include/components/eqiir'; fn.priv = 'DEF_EQIIR_PRIV'; +addpath ../common + %% ------------------- %% Example 1: Loudness %% ------------------- @@ -225,6 +227,8 @@ function example_iir_eq() %% Done. %% ------------------------------------ +rmpath ../common + end %% ------------------- @@ -349,8 +353,8 @@ function example_iir_eq() function eq_pack_export(bm, fn, note) bp = eq_iir_blob_pack(bm, 3); % IPC3 -if ~isempty(fn. bin) - eq_blob_write(fullfile(fn.cpath3, fn.bin), bp); +if ~isempty(fn.bin) + sof_ucm_blob_write(fullfile(fn.cpath3, fn.bin), bp); end if ~isempty(fn.txt) eq_alsactl_write(fullfile(fn.cpath3, fn.txt), bp); @@ -361,7 +365,7 @@ function eq_pack_export(bm, fn, note) bp = eq_iir_blob_pack(bm, 4); % IPC4 if ~isempty(fn.bin) - eq_blob_write(fullfile(fn.cpath4, fn.bin), bp); + sof_ucm_blob_write(fullfile(fn.cpath4, fn.bin), bp); end if ~isempty(fn.txt) eq_alsactl_write(fullfile(fn.cpath4, fn.txt), bp); diff --git a/tools/tune/eq/example_spk_eq.m b/tools/tune/eq/example_spk_eq.m index 80c4d1fac5c7..92c7c5d2f75c 100644 --- a/tools/tune/eq/example_spk_eq.m +++ b/tools/tune/eq/example_spk_eq.m @@ -35,6 +35,8 @@ function example_spk_eq() iir.tplg1 = 'eq_iir_coef_spk.m4'; iir.tplg2 = 'example_speaker.conf'; +addpath ../common + %% Get defaults for equalizer design eq = eq_defaults(); @@ -133,11 +135,11 @@ function example_spk_eq() [ bq_fir ]); bp_fir = eq_fir_blob_pack(bm_fir, 3); % IPC3 eq_alsactl_write(fullfile(fn.cpath3, fir.txt), bp_fir); - eq_blob_write(fullfile(fn.cpath3, fir.bin), bp_fir); + sof_ucm_blob_write(fullfile(fn.cpath3, fir.bin), bp_fir); eq_tplg_write(fullfile(fn.tpath1, fir.tplg1), bp_fir, fir.priv, fir.comment); bp_fir = eq_fir_blob_pack(bm_fir, 4); % IPC4 eq_alsactl_write(fullfile(fn.cpath4, fir.txt), bp_fir); - eq_blob_write(fullfile(fn.cpath4, fir.bin), bp_fir); + sof_ucm_blob_write(fullfile(fn.cpath4, fir.bin), bp_fir); eq_tplg2_write(fullfile(fir.tpath2, fir.tplg2), bp_fir, 'eq_fir', fir.comment); end @@ -150,12 +152,14 @@ function example_spk_eq() [ bq_iir ]); bp_iir = eq_iir_blob_pack(bm_iir, 3); % IPC3 eq_alsactl_write(fullfile(fn.cpath3, iir.txt), bp_iir); - eq_blob_write(fullfile(fn.cpath3, iir.bin), bp_iir); + sof_ucm_blob_write(fullfile(fn.cpath3, iir.bin), bp_iir); eq_tplg_write(fullfile(fn.tpath1, iir.tplg1), bp_iir, iir.priv, iir.comment); bp_iir = eq_iir_blob_pack(bm_iir, 4); % IPC4 eq_alsactl_write(fullfile(fn.cpath4, iir.txt), bp_iir); - eq_blob_write(fullfile(fn.cpath4, iir.bin), bp_iir); + sof_ucm_blob_write(fullfile(fn.cpath4, iir.bin), bp_iir); eq_tplg2_write(fullfile(iir.tpath2, iir.tplg2), bp_iir, 'eq_iir', iir.comment); end +rmpath ../common + end diff --git a/tools/tune/multiband_drc/example_multiband_drc.m b/tools/tune/multiband_drc/example_multiband_drc.m index 486e79dd88b2..e5ab9880888a 100644 --- a/tools/tune/multiband_drc/example_multiband_drc.m +++ b/tools/tune/multiband_drc/example_multiband_drc.m @@ -140,9 +140,9 @@ function export_multiband_drc(prm) tplg_write(tplg1_fn, blob8, "MULTIBAND_DRC"); tplg2_write(tplg2_fn, blob8_ipc4, "multiband_drc_config", "Exported with script example_multiband_drc.m"); -blob_write(blob3_fn, blob8); +sof_ucm_blob_write(blob3_fn, blob8); alsactl_write(alsa3_fn, blob8); -blob_write(blob4_fn, blob8_ipc4); +sof_ucm_blob_write(blob4_fn, blob8_ipc4); alsactl_write(alsa4_fn, blob8_ipc4); rmpath ../common From 616765bc0bef108edea8b1d0daa383ca7912bd04 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 22 Apr 2024 17:03:57 +0300 Subject: [PATCH 2/6] Tools: Tune: EQ: Create highpass blobs and add 100 Hz version There were no bytes control binary blobs for highpass filters. This patch adds export of them and adds a 100 Hz filter option. Signed-off-by: Seppo Ingalsuo --- tools/tune/eq/example_iir_eq.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tune/eq/example_iir_eq.m b/tools/tune/eq/example_iir_eq.m index b47aa7405ef5..4df71fdadfa6 100644 --- a/tools/tune/eq/example_iir_eq.m +++ b/tools/tune/eq/example_iir_eq.m @@ -161,9 +161,8 @@ function example_iir_eq() %% Example 6: 20/30/40/50 Hz high-pass %% ------------------------------------ -fn.bin = ''; % Don't create fs_list = [16e3 48e3]; -fc_list = [20 30 40 50]; +fc_list = [20 30 40 50 100]; g_list = [0 20]; for i = 1:length(fs_list) for j = 1:length(fc_list); @@ -179,6 +178,7 @@ function example_iir_eq() fc, g, fsk); comment = sprintf('%d Hz second order high-pass, gain %d dB, created with example_iir_eq.m', ... fc, g); + fn.bin = sprintf('eq_iir_highpass_%dhz_%ddb_%dkhz.bin', fc, g, fsk); %% Design IIR high-pass eq_hp = hp_iir_eq(fs, fc, g); From 8b698a4fefd385572609d505d703c81ed19aa7fa Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 22 Apr 2024 11:39:14 +0300 Subject: [PATCH 3/6] Tools: Tune: EQ: The function eq_blob_write.m is deleted The replacement is sof_ucm_blob_write.m. Signed-off-by: Seppo Ingalsuo --- tools/tune/eq/eq_blob_write.m | 49 ----------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 tools/tune/eq/eq_blob_write.m diff --git a/tools/tune/eq/eq_blob_write.m b/tools/tune/eq/eq_blob_write.m deleted file mode 100644 index 95f83854ba22..000000000000 --- a/tools/tune/eq/eq_blob_write.m +++ /dev/null @@ -1,49 +0,0 @@ -function eq_blob_write(fn, blob8) - -%% -% Copyright (c) 2016, Intel Corporation -% All rights reserved. -% -% Redistribution and use in source and binary forms, with or without -% modification, are permitted provided that the following conditions are met: -% * Redistributions of source code must retain the above copyright -% notice, this list of conditions and the following disclaimer. -% * Redistributions in binary form must reproduce the above copyright -% notice, this list of conditions and the following disclaimer in the -% documentation and/or other materials provided with the distribution. -% * Neither the name of the Intel Corporation nor the -% names of its contributors may be used to endorse or promote products -% derived from this software without specific prior written permission. -% -% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -% POSSIBILITY OF SUCH DAMAGE. -% -% Author: Seppo Ingalsuo -% - -%% Write blob -fh = fopen(fn, 'wb'); -fwrite(fh, blob8, 'uint8'); -fclose(fh); - -%% Print as 8 bit hex -nb = length(blob8); -nl = ceil(nb/16); -for i = 1:nl - m = min(16, nb-(i-1)*16); - for j = 1:m - fprintf(1, "%02x ", blob8((i-1)*16 + j)); - end - fprintf(1, "\n"); -end - -end From 44ba7477f14c1c978359c3fea1b9b99b33b958f8 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 22 Apr 2024 16:58:29 +0300 Subject: [PATCH 4/6] Tools: Tune: EQ: Rename configuration blobs to use .blob We have both .bin and .blob file name suffixes in use for similar byte controls initialize files. The scripts those generate files with .bin are changed to .blob. Signed-off-by: Seppo Ingalsuo --- tools/tune/eq/example_fir_eq.m | 8 ++++---- tools/tune/eq/example_iir_bandsplit.m | 2 +- tools/tune/eq/example_iir_eq.m | 14 +++++++------- tools/tune/eq/example_spk_eq.m | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/tune/eq/example_fir_eq.m b/tools/tune/eq/example_fir_eq.m index be942cd37e7e..07a8a7e997f9 100644 --- a/tools/tune/eq/example_fir_eq.m +++ b/tools/tune/eq/example_fir_eq.m @@ -21,7 +21,7 @@ function example_fir_eq() %% ------------------- %% Example 1: Loudness %% ------------------- -fn.bin = 'eq_fir_loudness.bin'; +fn.bin = 'eq_fir_loudness.blob'; fn.txt = 'eq_fir_loudness.txt'; fn.tplg1 = 'eq_fir_coef_loudness.m4'; fn.tplg2 = 'loudness.conf'; @@ -52,7 +52,7 @@ function example_fir_eq() %% ------------------- %% Example 2: Mid boost %% ------------------- -fn.bin = 'eq_fir_mid.bin'; +fn.bin = 'eq_fir_mid.blob'; fn.txt = 'eq_fir_mid.txt'; fn.tplg1 = 'eq_fir_coef_mid.m4'; fn.tplg2 = 'midboost.conf'; @@ -79,7 +79,7 @@ function example_fir_eq() %% ------------------- %% Example 3: Flat EQ %% ------------------- -fn.bin = 'eq_fir_flat.bin'; +fn.bin = 'eq_fir_flat.blob'; fn.txt = 'eq_fir_flat.txt'; fn.tplg1 = 'eq_fir_coef_flat.m4'; fn.tplg2 = 'flat.conf'; @@ -106,7 +106,7 @@ function example_fir_eq() %% -------------------------- %% Example 4: Pass-through EQ %% -------------------------- -fn.bin = 'eq_fir_pass.bin'; +fn.bin = 'eq_fir_pass.blob'; fn.txt = 'eq_fir_pass.txt'; fn.tplg1 = 'eq_fir_coef_pass.m4'; fn.tplg2 = 'passthrough.conf'; diff --git a/tools/tune/eq/example_iir_bandsplit.m b/tools/tune/eq/example_iir_bandsplit.m index fdef97ffe7df..a4e9b02e838a 100644 --- a/tools/tune/eq/example_iir_bandsplit.m +++ b/tools/tune/eq/example_iir_bandsplit.m @@ -19,7 +19,7 @@ function example_iir_bandsplit() %% -------------------------------------------------- %% Example: Band-split 2ch to 4ch low and high bands %% -------------------------------------------------- -blob_fn = fullfile(cpath, 'eq_iir_bandsplit.bin'); +blob_fn = fullfile(cpath, 'eq_iir_bandsplit.blob'); alsa_fn = fullfile(cpath, 'eq_iir_bandsplit.txt'); tplg_fn = fullfile(tpath, 'eq_iir_bandsplit.m4'); comment = 'Bandsplit, created with example_iir_bandsplit.m'; diff --git a/tools/tune/eq/example_iir_eq.m b/tools/tune/eq/example_iir_eq.m index 4df71fdadfa6..f924f1c65e4a 100644 --- a/tools/tune/eq/example_iir_eq.m +++ b/tools/tune/eq/example_iir_eq.m @@ -21,7 +21,7 @@ function example_iir_eq() %% ------------------- %% Example 1: Loudness %% ------------------- -fn.bin = 'eq_iir_loudness.bin'; +fn.bin = 'eq_iir_loudness.blob'; fn.txt = 'eq_iir_loudness.txt'; fn.tplg1 = 'eq_iir_coef_loudness.m4'; fn.tplg2 = 'loudness.conf'; @@ -52,7 +52,7 @@ function example_iir_eq() %% ------------------------------------ %% Example 2: Bass boost %% ------------------------------------ -fn.bin = 'eq_iir_bassboost.bin'; +fn.bin = 'eq_iir_bassboost.blob'; fn.txt = 'eq_iir_bassboost.txt'; fn.tplg1 = 'eq_iir_coef_bassboost.m4'; fn.tplg2 = 'bassboost.conf'; @@ -79,7 +79,7 @@ function example_iir_eq() %% ------------------------------------ %% Example 3: Band-pass %% ------------------------------------ -fn.bin = 'eq_iir_bandpass.bin'; +fn.bin = 'eq_iir_bandpass.blob'; fn.txt = 'eq_iir_bandpass.txt'; fn.tplg1 = 'eq_iir_coef_bandpass.m4'; fn.tplg2 = 'bandpass.conf'; @@ -106,7 +106,7 @@ function example_iir_eq() %% ------------------- %% Example 4: Flat IIR %% ------------------- -fn.bin = 'eq_iir_flat.bin'; +fn.bin = 'eq_iir_flat.blob'; fn.txt = 'eq_iir_flat.txt'; fn.tplg1 = 'eq_iir_coef_flat.m4'; fn.tplg2 = 'flat.conf'; @@ -133,7 +133,7 @@ function example_iir_eq() %% --------------------------- %% Example 5: Pass-through IIR %% --------------------------- -fn.bin = 'eq_iir_pass.bin'; +fn.bin = 'eq_iir_pass.blob'; fn.txt = 'eq_iir_pass.txt'; fn.tplg1 = 'eq_iir_coef_pass.m4'; fn.tplg2 = 'passthrough.conf'; @@ -178,7 +178,7 @@ function example_iir_eq() fc, g, fsk); comment = sprintf('%d Hz second order high-pass, gain %d dB, created with example_iir_eq.m', ... fc, g); - fn.bin = sprintf('eq_iir_highpass_%dhz_%ddb_%dkhz.bin', fc, g, fsk); + fn.bin = sprintf('eq_iir_highpass_%dhz_%ddb_%dkhz.blob', fc, g, fsk); %% Design IIR high-pass eq_hp = hp_iir_eq(fs, fc, g); @@ -205,7 +205,7 @@ function example_iir_eq() %% Example 7: Merge previous desigs to single blob for use as presets %% ------------------------------------------------------------------ -fn.bin = 'eq_iir_bundle.bin'; +fn.bin = 'eq_iir_bundle.blob'; fn.txt = 'eq_iir_bundle.txt'; fn.tplg1 = 'eq_iir_bundle.m4'; fn.tplg2 = 'bundle.conf'; diff --git a/tools/tune/eq/example_spk_eq.m b/tools/tune/eq/example_spk_eq.m index 92c7c5d2f75c..23c99dda36c0 100644 --- a/tools/tune/eq/example_spk_eq.m +++ b/tools/tune/eq/example_spk_eq.m @@ -27,11 +27,11 @@ function example_spk_eq() %% File names fir.txt = 'eq_fir_spk.txt'; -fir.bin = 'eq_fir_spk.bin'; +fir.bin = 'eq_fir_spk.blob'; fir.tplg1 = 'eq_fir_coef_spk.m4'; fir.tplg2 = 'example_speaker.conf'; iir.txt = 'eq_iir_spk.txt'; -iir.bin = 'eq_iir_spk.bin'; +iir.bin = 'eq_iir_spk.blob'; iir.tplg1 = 'eq_iir_coef_spk.m4'; iir.tplg2 = 'example_speaker.conf'; From 9ece79cc79a08fa99ea0559624d6191f1868e0da Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 22 Apr 2024 17:33:15 +0300 Subject: [PATCH 5/6] Tools: Tune: EQ: Cleanup produced blob files structure To remove clutter from upper level this patch changes generated files naming from e.g. "ipc4/eq_fir_loudness.blob" to "ipc4/eq_fir/loudness.blob". It helps to find the blob files from directory that has same name as the target component. Signed-off-by: Seppo Ingalsuo --- tools/tune/eq/example_fir_eq.m | 20 ++++++++-------- tools/tune/eq/example_iir_bandsplit.m | 7 +++--- tools/tune/eq/example_iir_eq.m | 33 +++++++++++++-------------- tools/tune/eq/example_spk_eq.m | 30 ++++++++++++------------ 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/tools/tune/eq/example_fir_eq.m b/tools/tune/eq/example_fir_eq.m index 07a8a7e997f9..8ff092db2379 100644 --- a/tools/tune/eq/example_fir_eq.m +++ b/tools/tune/eq/example_fir_eq.m @@ -10,8 +10,8 @@ function example_fir_eq() %% Common definitions fs = 48e3; -fn.cpath3 = '../../ctl/ipc3'; -fn.cpath4 = '../../ctl/ipc4'; +fn.cpath3 = '../../ctl/ipc3/eq_fir'; +fn.cpath4 = '../../ctl/ipc4/eq_fir'; fn.tpath1 = '../../topology/topology1/m4'; fn.tpath2 = '../../topology/topology2/include/components/eqfir'; fn.priv = 'DEF_EQFIR_PRIV'; @@ -21,8 +21,8 @@ function example_fir_eq() %% ------------------- %% Example 1: Loudness %% ------------------- -fn.bin = 'eq_fir_loudness.blob'; -fn.txt = 'eq_fir_loudness.txt'; +fn.bin = 'loudness.blob'; +fn.txt = 'loudness.txt'; fn.tplg1 = 'eq_fir_coef_loudness.m4'; fn.tplg2 = 'loudness.conf'; comment = 'Loudness effect, created with example_fir_eq.m'; @@ -52,8 +52,8 @@ function example_fir_eq() %% ------------------- %% Example 2: Mid boost %% ------------------- -fn.bin = 'eq_fir_mid.blob'; -fn.txt = 'eq_fir_mid.txt'; +fn.bin = 'mid.blob'; +fn.txt = 'mid.txt'; fn.tplg1 = 'eq_fir_coef_mid.m4'; fn.tplg2 = 'midboost.conf'; comment = 'Mid boost, created with example_fir_eq.m'; @@ -79,8 +79,8 @@ function example_fir_eq() %% ------------------- %% Example 3: Flat EQ %% ------------------- -fn.bin = 'eq_fir_flat.blob'; -fn.txt = 'eq_fir_flat.txt'; +fn.bin = 'flat.blob'; +fn.txt = 'flat.txt'; fn.tplg1 = 'eq_fir_coef_flat.m4'; fn.tplg2 = 'flat.conf'; comment = 'Flat response, created with example_fir_eq.m'; @@ -106,8 +106,8 @@ function example_fir_eq() %% -------------------------- %% Example 4: Pass-through EQ %% -------------------------- -fn.bin = 'eq_fir_pass.blob'; -fn.txt = 'eq_fir_pass.txt'; +fn.bin = 'pass.blob'; +fn.txt = 'pass.txt'; fn.tplg1 = 'eq_fir_coef_pass.m4'; fn.tplg2 = 'passthrough.conf'; comment = 'Pass-through response, created with example_fir_eq.m'; diff --git a/tools/tune/eq/example_iir_bandsplit.m b/tools/tune/eq/example_iir_bandsplit.m index a4e9b02e838a..86fec4486c4c 100644 --- a/tools/tune/eq/example_iir_bandsplit.m +++ b/tools/tune/eq/example_iir_bandsplit.m @@ -11,7 +11,7 @@ function example_iir_bandsplit() %% Common definitions fs = 48e3; tpath = '../../topology/topology1/m4'; -cpath = '../../ctl'; +cpath = '../../ctl/ipc3/eq_iir'; priv = 'DEF_EQIIR_PRIV'; addpath ../common @@ -19,8 +19,8 @@ function example_iir_bandsplit() %% -------------------------------------------------- %% Example: Band-split 2ch to 4ch low and high bands %% -------------------------------------------------- -blob_fn = fullfile(cpath, 'eq_iir_bandsplit.blob'); -alsa_fn = fullfile(cpath, 'eq_iir_bandsplit.txt'); +blob_fn = fullfile(cpath, 'bandsplit.blob'); +alsa_fn = fullfile(cpath, 'bandsplit.txt'); tplg_fn = fullfile(tpath, 'eq_iir_bandsplit.m4'); comment = 'Bandsplit, created with example_iir_bandsplit.m'; @@ -44,7 +44,6 @@ function example_iir_bandsplit() %% Pack and write file eq_pack_export(bm, blob_fn, alsa_fn, tplg_fn, priv, comment) - %% ------------------------------------ %% Done. %% ------------------------------------ diff --git a/tools/tune/eq/example_iir_eq.m b/tools/tune/eq/example_iir_eq.m index f924f1c65e4a..ac2a43b146ab 100644 --- a/tools/tune/eq/example_iir_eq.m +++ b/tools/tune/eq/example_iir_eq.m @@ -10,8 +10,8 @@ function example_iir_eq() %% Common definitions fs = 48e3; -fn.cpath3 = '../../ctl/ipc3'; -fn.cpath4 = '../../ctl/ipc4'; +fn.cpath3 = '../../ctl/ipc3/eq_iir'; +fn.cpath4 = '../../ctl/ipc4/eq_iir'; fn.tpath1 = '../../topology/topology1/m4'; fn.tpath2 = '../../topology/topology2/include/components/eqiir'; fn.priv = 'DEF_EQIIR_PRIV'; @@ -21,8 +21,8 @@ function example_iir_eq() %% ------------------- %% Example 1: Loudness %% ------------------- -fn.bin = 'eq_iir_loudness.blob'; -fn.txt = 'eq_iir_loudness.txt'; +fn.bin = 'loudness.blob'; +fn.txt = 'loudness.txt'; fn.tplg1 = 'eq_iir_coef_loudness.m4'; fn.tplg2 = 'loudness.conf'; comment = 'Loudness effect, created with example_iir_eq.m'; @@ -52,8 +52,8 @@ function example_iir_eq() %% ------------------------------------ %% Example 2: Bass boost %% ------------------------------------ -fn.bin = 'eq_iir_bassboost.blob'; -fn.txt = 'eq_iir_bassboost.txt'; +fn.bin = 'bassboost.blob'; +fn.txt = 'bassboost.txt'; fn.tplg1 = 'eq_iir_coef_bassboost.m4'; fn.tplg2 = 'bassboost.conf'; comment = 'Bass boost, created with example_iir_eq.m'; @@ -79,8 +79,8 @@ function example_iir_eq() %% ------------------------------------ %% Example 3: Band-pass %% ------------------------------------ -fn.bin = 'eq_iir_bandpass.blob'; -fn.txt = 'eq_iir_bandpass.txt'; +fn.bin = 'bandpass.blob'; +fn.txt = 'bandpass.txt'; fn.tplg1 = 'eq_iir_coef_bandpass.m4'; fn.tplg2 = 'bandpass.conf'; comment = 'Band-pass, created with example_iir_eq.m'; @@ -106,8 +106,8 @@ function example_iir_eq() %% ------------------- %% Example 4: Flat IIR %% ------------------- -fn.bin = 'eq_iir_flat.blob'; -fn.txt = 'eq_iir_flat.txt'; +fn.bin = 'flat.blob'; +fn.txt = 'flat.txt'; fn.tplg1 = 'eq_iir_coef_flat.m4'; fn.tplg2 = 'flat.conf'; comment = 'Flat response, created with example_iir_eq.m'; @@ -133,8 +133,8 @@ function example_iir_eq() %% --------------------------- %% Example 5: Pass-through IIR %% --------------------------- -fn.bin = 'eq_iir_pass.blob'; -fn.txt = 'eq_iir_pass.txt'; +fn.bin = 'pass.blob'; +fn.txt = 'pass.txt'; fn.tplg1 = 'eq_iir_coef_pass.m4'; fn.tplg2 = 'passthrough.conf'; comment = 'Pass-through, created with example_iir_eq.m'; @@ -174,11 +174,10 @@ function example_iir_eq() fn.tplg1 = sprintf('eq_iir_coef_highpass_%dhz_%ddb_%dkhz.m4', ... fc, g, fsk); fn.tplg2 = sprintf('highpass_%dhz_%ddb_%dkhz.conf', fc, g, fsk); - fn.txt = sprintf('eq_iir_highpass_%dhz_%ddb_%dkhz.txt', ... - fc, g, fsk); + fn.txt = sprintf('highpass_%dhz_%ddb_%dkhz.txt', fc, g, fsk); comment = sprintf('%d Hz second order high-pass, gain %d dB, created with example_iir_eq.m', ... fc, g); - fn.bin = sprintf('eq_iir_highpass_%dhz_%ddb_%dkhz.blob', fc, g, fsk); + fn.bin = sprintf('highpass_%dhz_%ddb_%dkhz.blob', fc, g, fsk); %% Design IIR high-pass eq_hp = hp_iir_eq(fs, fc, g); @@ -205,8 +204,8 @@ function example_iir_eq() %% Example 7: Merge previous desigs to single blob for use as presets %% ------------------------------------------------------------------ -fn.bin = 'eq_iir_bundle.blob'; -fn.txt = 'eq_iir_bundle.txt'; +fn.bin = 'bundle.blob'; +fn.txt = 'bundle.txt'; fn.tplg1 = 'eq_iir_bundle.m4'; fn.tplg2 = 'bundle.conf'; comment = 'Bundle of responses flat/loud/bass/band/high, created with example_iir_eq.m'; diff --git a/tools/tune/eq/example_spk_eq.m b/tools/tune/eq/example_spk_eq.m index 23c99dda36c0..291d880afecd 100644 --- a/tools/tune/eq/example_spk_eq.m +++ b/tools/tune/eq/example_spk_eq.m @@ -15,8 +15,10 @@ function example_spk_eq() %% Defaults fs = 48e3; -fn.cpath3 = '../../ctl/ipc3'; -fn.cpath4 = '../../ctl/ipc4'; +iir.cpath3 = '../../ctl/ipc3/eq_iir'; +iir.cpath4 = '../../ctl/ipc4/eq_iir'; +fir.cpath3 = '../../ctl/ipc3/eq_fir'; +fir.cpath4 = '../../ctl/ipc4/eq_fir'; fn.tpath1 = '../../topology/topology1/m4'; fir.tpath2 = '../../topology/topology2/include/components/eqfir'; iir.tpath2 = '../../topology/topology2/include/components/eqiir'; @@ -26,12 +28,12 @@ function example_spk_eq() fir.comment = 'Speaker FIR+IIR EQ created with example_spk_eq.m'; %% File names -fir.txt = 'eq_fir_spk.txt'; -fir.bin = 'eq_fir_spk.blob'; +fir.txt = 'spk.txt'; +fir.bin = 'spk.blob'; fir.tplg1 = 'eq_fir_coef_spk.m4'; fir.tplg2 = 'example_speaker.conf'; -iir.txt = 'eq_iir_spk.txt'; -iir.bin = 'eq_iir_spk.blob'; +iir.txt = 'spk.txt'; +iir.bin = 'spk.blob'; iir.tplg1 = 'eq_iir_coef_spk.m4'; iir.tplg2 = 'example_speaker.conf'; @@ -134,12 +136,12 @@ function example_spk_eq() assign_response, ... [ bq_fir ]); bp_fir = eq_fir_blob_pack(bm_fir, 3); % IPC3 - eq_alsactl_write(fullfile(fn.cpath3, fir.txt), bp_fir); - sof_ucm_blob_write(fullfile(fn.cpath3, fir.bin), bp_fir); + eq_alsactl_write(fullfile(fir.cpath3, fir.txt), bp_fir); + sof_ucm_blob_write(fullfile(fir.cpath3, fir.bin), bp_fir); eq_tplg_write(fullfile(fn.tpath1, fir.tplg1), bp_fir, fir.priv, fir.comment); bp_fir = eq_fir_blob_pack(bm_fir, 4); % IPC4 - eq_alsactl_write(fullfile(fn.cpath4, fir.txt), bp_fir); - sof_ucm_blob_write(fullfile(fn.cpath4, fir.bin), bp_fir); + eq_alsactl_write(fullfile(fir.cpath4, fir.txt), bp_fir); + sof_ucm_blob_write(fullfile(fir.cpath4, fir.bin), bp_fir); eq_tplg2_write(fullfile(fir.tpath2, fir.tplg2), bp_fir, 'eq_fir', fir.comment); end @@ -151,12 +153,12 @@ function example_spk_eq() assign_response, ... [ bq_iir ]); bp_iir = eq_iir_blob_pack(bm_iir, 3); % IPC3 - eq_alsactl_write(fullfile(fn.cpath3, iir.txt), bp_iir); - sof_ucm_blob_write(fullfile(fn.cpath3, iir.bin), bp_iir); + eq_alsactl_write(fullfile(iir.cpath3, iir.txt), bp_iir); + sof_ucm_blob_write(fullfile(iir.cpath3, iir.bin), bp_iir); eq_tplg_write(fullfile(fn.tpath1, iir.tplg1), bp_iir, iir.priv, iir.comment); bp_iir = eq_iir_blob_pack(bm_iir, 4); % IPC4 - eq_alsactl_write(fullfile(fn.cpath4, iir.txt), bp_iir); - sof_ucm_blob_write(fullfile(fn.cpath4, iir.bin), bp_iir); + eq_alsactl_write(fullfile(iir.cpath4, iir.txt), bp_iir); + sof_ucm_blob_write(fullfile(iir.cpath4, iir.bin), bp_iir); eq_tplg2_write(fullfile(iir.tpath2, iir.tplg2), bp_iir, 'eq_iir', iir.comment); end From 6908a5b63bfaf5a6bada4d50a06cf7c3ebc21b2b Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 22 Apr 2024 18:06:14 +0300 Subject: [PATCH 6/6] Tools: Tune: Crossover: Cleanup blob files paths This patch moves blobs for crossover component into sub-directory "crossover" to clean up clutter from ctl/ipc3 and ipc4 level. The patch also adds export of blobs for IPC4 mode that was missing. Signed-off-by: Seppo Ingalsuo --- tools/tune/crossover/example_crossover.m | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/tune/crossover/example_crossover.m b/tools/tune/crossover/example_crossover.m index 7b93b0edf5da..b33250af489f 100644 --- a/tools/tune/crossover/example_crossover.m +++ b/tools/tune/crossover/example_crossover.m @@ -39,7 +39,8 @@ function export_crossover(cr) endian = "little"; tpath1 = '../../topology/topology1/m4/crossover'; tpath2 = '../../topology/topology2/include/components/crossover'; -ctlpath = '../../ctl/ipc3'; +ctlpath3 = '../../ctl/ipc3/crossover'; +ctlpath4 = '../../ctl/ipc4/crossover'; str_way = sprintf('%dway', cr.num_sinks); str_freq = get_str_freq(cr); @@ -49,8 +50,10 @@ function export_crossover(cr) tplg1_fn = sprintf('%s/coef_%s_%s_%s.m4', tpath1, str_way, str_freq, str_pid); % Control Bytes File tplg2_fn = sprintf('%s/coef_%s_%s_%s.conf', tpath2, str_way, str_freq, str_pid); % Use those files with sof-ctl to update the component's configuration -blob_fn = sprintf('%s/crossover_coef_%dway.blob', ctlpath, cr.num_sinks); % Blob binary file -alsa_fn = sprintf('%s/crossover_coef_%dway.txt', ctlpath, cr.num_sinks); % ALSA CSV format file +blob3_fn = sprintf('%s/coef_%dway.blob', ctlpath3, cr.num_sinks); % Blob binary file +alsa3_fn = sprintf('%s/coef_%dway.txt', ctlpath3, cr.num_sinks); % ALSA CSV format file +blob4_fn = sprintf('%s/coef_%dway.blob', ctlpath4, cr.num_sinks); % Blob binary file +alsa4_fn = sprintf('%s/coef_%dway.txt', ctlpath4, cr.num_sinks); % ALSA CSV format file % This array is an example on how to assign a buffer from pipeline 1 to output 0, % buffer from pipeline 2 to output 1, etc... @@ -85,11 +88,14 @@ function export_crossover(cr) mkdir_check(tpath1); mkdir_check(tpath2); -mkdir_check(ctlpath); +mkdir_check(ctlpath3); +mkdir_check(ctlpath4); tplg_write(tplg1_fn, blob8, "CROSSOVER"); tplg2_write(tplg2_fn, blob8_ipc4, "crossover_config", 'Exported Control Bytes'); -sof_ucm_blob_write(blob_fn, blob8); -alsactl_write(alsa_fn, blob8); +sof_ucm_blob_write(blob3_fn, blob8); +sof_ucm_blob_write(blob4_fn, blob8_ipc4); +alsactl_write(alsa3_fn, blob8); +alsactl_write(alsa4_fn, blob8_ipc4); % Plot Magnitude and Phase Response of each sink crossover_plot_freq(crossover.lp, crossover.hp, cr.fs, cr.num_sinks);