diff --git a/tools/tune/drc/drc_build_blob.m b/src/audio/drc/tune/sof_drc_build_blob.m similarity index 97% rename from tools/tune/drc/drc_build_blob.m rename to src/audio/drc/tune/sof_drc_build_blob.m index 6873d81dcec4..48ef29b31a65 100644 --- a/tools/tune/drc/drc_build_blob.m +++ b/src/audio/drc/tune/sof_drc_build_blob.m @@ -1,4 +1,4 @@ -function blob8 = drc_build_blob(blob_struct, endian, ipc_ver) +function blob8 = sof_drc_build_blob(blob_struct, endian, ipc_ver) if nargin < 2 endian = 'little' diff --git a/tools/tune/drc/drc_gen_coefs.m b/src/audio/drc/tune/sof_drc_gen_coefs.m similarity index 98% rename from tools/tune/drc/drc_gen_coefs.m rename to src/audio/drc/tune/sof_drc_gen_coefs.m index 28479934732e..9cfa8b7019e2 100644 --- a/tools/tune/drc/drc_gen_coefs.m +++ b/src/audio/drc/tune/sof_drc_gen_coefs.m @@ -1,4 +1,4 @@ -function coefs = drc_gen_coefs(params, sample_rate) +function coefs = sof_drc_gen_coefs(params, sample_rate) if exist('OCTAVE_VERSION', 'builtin') pkg load control; diff --git a/tools/tune/drc/drc_generate_config.m b/src/audio/drc/tune/sof_drc_generate_config.m similarity index 95% rename from tools/tune/drc/drc_generate_config.m rename to src/audio/drc/tune/sof_drc_generate_config.m index b4b3a0a506f7..083f3257157a 100644 --- a/tools/tune/drc/drc_generate_config.m +++ b/src/audio/drc/tune/sof_drc_generate_config.m @@ -1,6 +1,4 @@ -function config = drc_generate_config(coefs); - -addpath ./../eq +function config = sof_drc_generate_config(coefs); config.enabled = coefs.enabled; config.db_threshold = eq_coef_quant(coefs.db_threshold, 32, 24); % Q8.24 @@ -28,5 +26,4 @@ % Print out config config -rmpath ./../eq end diff --git a/src/audio/drc/tune/sof_drc_paths.m b/src/audio/drc/tune/sof_drc_paths.m new file mode 100644 index 000000000000..b1071bcf2b0e --- /dev/null +++ b/src/audio/drc/tune/sof_drc_paths.m @@ -0,0 +1,24 @@ +function sof_drc_paths(enable) + +% sof_drc_paths(enable) +% enable - set to 1 to enable needed search path +% set to 0 to disable the search paths +% + +% SPDX-License-Identifier: BSD-3-Clause +% +% Copyright (c) 2024, Intel Corporation. All rights reserved. + + common = '../../../../tools/tune/common'; + % After #9187 use this + %eq = '../../eq_iir/tune'; + % and remove this + eq = '../../../../tools/tune/eq'; + if enable + addpath(common); + addpath(eq); + else + rmpath(common); + rmpath(eq); + end +end diff --git a/tools/tune/drc/drc_plot_db_curve.m b/src/audio/drc/tune/sof_drc_plot_db_curve.m similarity index 97% rename from tools/tune/drc/drc_plot_db_curve.m rename to src/audio/drc/tune/sof_drc_plot_db_curve.m index e8d479fa1f1f..e44f5d4a102d 100644 --- a/tools/tune/drc/drc_plot_db_curve.m +++ b/src/audio/drc/tune/sof_drc_plot_db_curve.m @@ -1,4 +1,4 @@ -function drc_plot_db_curve(coefs) +function sof_drc_plot_db_curve(coefs) if exist('OCTAVE_VERSION', 'builtin') pkg load control; diff --git a/tools/tune/drc/example_drc.m b/src/audio/drc/tune/sof_example_drc.m similarity index 71% rename from tools/tune/drc/example_drc.m rename to src/audio/drc/tune/sof_example_drc.m index 3bb0898ec74d..865d816dd7f8 100644 --- a/tools/tune/drc/example_drc.m +++ b/src/audio/drc/tune/sof_example_drc.m @@ -1,6 +1,6 @@ -function example_drc() +function sof_example_drc() -addpath ../common +sof_drc_paths(1); % The parameters of the DRC compressor % enabled: 1 to enable the compressor, 0 to disable it @@ -47,33 +47,36 @@ function example_drc() params.post_gain = 0; drc_coefs_and_config_export(params, 'dmic_default'); -rmpath ../common +sof_drc_paths(0); end function drc_coefs_and_config_export(params, id) % Set the parameters here -tplg1_fn = sprintf("../../topology/topology1/m4/drc_coef_%s.m4", id); % Control Bytes File -tplg2_fn = sprintf("../../topology/topology2/include/components/drc/%s.conf", id); % Control Bytes File +sof_tools = '../../../../tools'; +sof_tplg = fullfile(sof_tools, 'topology'); +sof_ctl = fullfile(sof_tools, 'ctl'); +tplg1_fn = sprintf("%s/topology1/m4/drc_coef_%s.m4", sof_tplg, id); % Control Bytes File +tplg2_fn = sprintf("%s/topology2/include/components/drc/%s.conf", sof_tplg, id); % Control Bytes File % Use those files with sof-ctl to update the component's configuration -blob3_fn = sprintf("../../ctl/ipc3/drc_coef_%s.blob", id); % Blob binary file -alsa3_fn = sprintf("../../ctl/ipc3/drc_coef_%s.txt", id); % ALSA CSV format file -blob4_fn = sprintf("../../ctl/ipc4/drc/%s.blob", id); % Blob binary file -alsa4_fn = sprintf("../../ctl/ipc4/drc/%s.txt", id); % ALSA CSV format file +blob3_fn = sprintf("%s/ipc3/drc_coef_%s.blob", sof_ctl, id); % Blob binary file +alsa3_fn = sprintf("%s/ipc3/drc_coef_%s.txt", sof_ctl, id); % ALSA CSV format file +blob4_fn = sprintf("%s/ipc4/drc/%s.blob", sof_ctl, id); % Blob binary file +alsa4_fn = sprintf("%s/ipc4/drc/%s.txt", sof_ctl, id); % ALSA CSV format file endian = "little"; sample_rate = 48000; % Generate coefficients for DRC with the given parameters -coefs = drc_gen_coefs(params, sample_rate); +coefs = sof_drc_gen_coefs(params, sample_rate); % Convert coefficients to sof_drc_config struct -config = drc_generate_config(coefs); +config = sof_drc_generate_config(coefs); % Convert struct to binary blob -blob8 = drc_build_blob(config, endian); -blob8_ipc4 = drc_build_blob(config, endian, 4); +blob8 = sof_drc_build_blob(config, endian); +blob8_ipc4 = sof_drc_build_blob(config, endian, 4); % Generate output files my_name = mfilename(); @@ -87,6 +90,6 @@ function drc_coefs_and_config_export(params, id) alsactl_write(alsa4_fn, blob8_ipc4); % Plot x-y response in dB -drc_plot_db_curve(coefs); +sof_drc_plot_db_curve(coefs); end diff --git a/tools/tune/common/alsactl_write.m b/tools/tune/common/alsactl_write.m index fc4b1badaf34..92fa67c3844f 100644 --- a/tools/tune/common/alsactl_write.m +++ b/tools/tune/common/alsactl_write.m @@ -3,6 +3,10 @@ function alsactl_write(fn, blob8) %% Write blob check_create_dir(fn); fh = fopen(fn, 'w'); +if fh < 0 + fprintf(1, 'Error: Could not open file %s\n', fn); + error("Failed."); +end %% Pad blob length to multiple of four bytes n_orig = length(blob8); diff --git a/tools/tune/common/blob_write.m b/tools/tune/common/blob_write.m index 8b87af9ddf6f..e13bea505bba 100644 --- a/tools/tune/common/blob_write.m +++ b/tools/tune/common/blob_write.m @@ -4,6 +4,11 @@ function blob_write(fn, blob8) %% Write blob check_create_dir(fn); fh = fopen(fn, 'wb'); +if fh < 0 + fprintf(1, 'Error: Could not open file %s\n', fn); + error("Failed."); +end + fwrite(fh, blob8, 'uint8'); fclose(fh); diff --git a/tools/tune/common/sof_ucm_blob_write.m b/tools/tune/common/sof_ucm_blob_write.m index 0a6c4da4454a..2a60b0021861 100644 --- a/tools/tune/common/sof_ucm_blob_write.m +++ b/tools/tune/common/sof_ucm_blob_write.m @@ -25,6 +25,11 @@ function sof_ucm_blob_write(fn, blob8) %% Write blob check_create_dir(fn); fh = fopen(fn, 'wb'); +if fh < 0 + fprintf(1, 'Error: Could not open file %s\n', fn); + error("Failed."); +end + fwrite(fh, ublob8, 'uint8'); fclose(fh); diff --git a/tools/tune/common/tplg2_write.m b/tools/tune/common/tplg2_write.m index 1bb28b05e5c6..cff82f79f1ca 100644 --- a/tools/tune/common/tplg2_write.m +++ b/tools/tune/common/tplg2_write.m @@ -24,6 +24,10 @@ function tplg2_write(fn, blob8, component, comment, howto) %% Write blob fh = fopen(fn, 'w'); +if fh < 0 + fprintf(1, 'Error: Could not open file %s\n', fn); + error("Failed."); +end nl = 8; fprintf(fh, '# %s %s\n', comment, date()); if ~isempty(howto) diff --git a/tools/tune/common/tplg_write.m b/tools/tune/common/tplg_write.m index 15692cfab295..2834af82a919 100644 --- a/tools/tune/common/tplg_write.m +++ b/tools/tune/common/tplg_write.m @@ -15,6 +15,10 @@ function tplg_write(fn, blob8, name, comment, howto) %% Write blob fh = fopen(fn, 'w'); +if fh < 0 + fprintf(1, 'Error: Could not open file %s\n', fn); + error("Failed."); +end nl = 8; fprintf(fh, '# %s %s\n', comment, date()); if ~isempty(howto)