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 <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
Seppo Ingalsuo 2024-04-22 11:36:49 +03:00 committed by Liam Girdwood
parent 48499455c8
commit 25e105026d
9 changed files with 84 additions and 17 deletions

View File

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

View File

@ -88,7 +88,7 @@ mkdir_check(tpath2);
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

View File

@ -58,13 +58,13 @@ blob8_ipc4 = dcblock_build_blob(R_coeffs, endian, 4);
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

View File

@ -73,9 +73,9 @@ drc_note = sprintf("Exported with script %s.m", my_name);
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

View File

@ -16,6 +16,8 @@ fn.tpath1 = '../../topology/topology1/m4';
fn.tpath2 = '../../topology/topology2/include/components/eqfir';
fn.priv = 'DEF_EQFIR_PRIV';
addpath ../common
%% -------------------
%% Example 1: Loudness
%% -------------------
@ -133,6 +135,8 @@ eq_pack_export(bm, fn, comment);
%% 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 @@ end
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);

View File

@ -14,6 +14,8 @@ tpath = '../../topology/topology1/m4';
cpath = '../../ctl';
priv = 'DEF_EQIIR_PRIV';
addpath ../common
%% --------------------------------------------------
%% Example: Band-split 2ch to 4ch low and high bands
%% --------------------------------------------------
@ -47,6 +49,7 @@ eq_pack_export(bm, blob_fn, alsa_fn, tplg_fn, priv, comment)
%% 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)

View File

@ -16,6 +16,8 @@ fn.tpath1 = '../../topology/topology1/m4';
fn.tpath2 = '../../topology/topology2/include/components/eqiir';
fn.priv = 'DEF_EQIIR_PRIV';
addpath ../common
%% -------------------
%% Example 1: Loudness
%% -------------------
@ -225,6 +227,8 @@ eq_pack_export(bm, fn, comment)
%% Done.
%% ------------------------------------
rmpath ../common
end
%% -------------------
@ -349,8 +353,8 @@ end
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 @@ end
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);

View File

@ -35,6 +35,8 @@ iir.bin = 'eq_iir_spk.bin';
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 @@ if eq.enable_fir
[ 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 @@ if eq.enable_iir
[ 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

View File

@ -140,9 +140,9 @@ blob8_ipc4 = multiband_drc_build_blob(num_bands, enable_emp_deemp, emp_coefs, ..
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