From 01eaed435e67e466eb9c99a3c06063766afe4593 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 18 Oct 2024 12:39:39 +0300 Subject: [PATCH 1/5] Audio: Multiband-DRC: Tune: Update moved functions and add sof prefix This patch fixes paths to moved utilities from DRC, EQ, and crossover. The paths are changed and common utilities are prefixed with sof_. The same sof prefix add is done for Mltiband-DRC. There are no functional changes and changes to config blob data contents from this patch. Signed-off-by: Seppo Ingalsuo --- .../crossover/tune/sof_crossover_coef_quant.m | 8 ++-- .../crossover/tune/sof_crossover_paths.m | 4 +- src/audio/drc/tune/sof_drc_generate_config.m | 40 +++++++++---------- src/audio/drc/tune/sof_drc_paths.m | 5 +-- src/audio/drc/tune/sof_example_drc.m | 4 +- .../multiband_drc/tune/drc_gen_quant_coefs.m | 8 ---- ...oefs.m => sof_crossover_gen_quant_coefs.m} | 16 +++----- .../tune/sof_drc_gen_quant_coefs.m | 8 ++++ ...band_drc.m => sof_example_multiband_drc.m} | 32 +++++++-------- ...uant_coefs.m => sof_iir_gen_quant_coefs.m} | 6 +-- ..._blob.m => sof_multiband_drc_build_blob.m} | 8 ++-- ..._drc_paths.m => sof_multiband_drc_paths.m} | 16 +++----- 12 files changed, 70 insertions(+), 85 deletions(-) delete mode 100644 src/audio/multiband_drc/tune/drc_gen_quant_coefs.m rename src/audio/multiband_drc/tune/{crossover_gen_quant_coefs.m => sof_crossover_gen_quant_coefs.m} (76%) create mode 100644 src/audio/multiband_drc/tune/sof_drc_gen_quant_coefs.m rename src/audio/multiband_drc/tune/{example_multiband_drc.m => sof_example_multiband_drc.m} (86%) rename src/audio/multiband_drc/tune/{iir_gen_quant_coefs.m => sof_iir_gen_quant_coefs.m} (93%) rename src/audio/multiband_drc/tune/{multiband_drc_build_blob.m => sof_multiband_drc_build_blob.m} (94%) rename src/audio/multiband_drc/tune/{multiband_drc_paths.m => sof_multiband_drc_paths.m} (52%) diff --git a/src/audio/crossover/tune/sof_crossover_coef_quant.m b/src/audio/crossover/tune/sof_crossover_coef_quant.m index c2627b22eec6..b53a92c0885d 100644 --- a/src/audio/crossover/tune/sof_crossover_coef_quant.m +++ b/src/audio/crossover/tune/sof_crossover_coef_quant.m @@ -13,10 +13,10 @@ for i = 1:n lp = lowpass(i); hp = highpass(i); - lp_a = eq_coef_quant(-lp.a(3:-1:2), bits_iir, qf_iir); - lp_b = eq_coef_quant(lp.b(3:-1:1), bits_iir, qf_iir); - hp_a = eq_coef_quant(-hp.a(3:-1:2), bits_iir, qf_iir); - hp_b = eq_coef_quant(hp.b(3:-1:1), bits_iir, qf_iir); + lp_a = sof_eq_coef_quant(-lp.a(3:-1:2), bits_iir, qf_iir); + lp_b = sof_eq_coef_quant(lp.b(3:-1:1), bits_iir, qf_iir); + hp_a = sof_eq_coef_quant(-hp.a(3:-1:2), bits_iir, qf_iir); + hp_b = sof_eq_coef_quant(hp.b(3:-1:1), bits_iir, qf_iir); crossover_quant.lp_coef(i) = [lp_a lp_b 0 16384]; crossover_quant.hp_coef(i) = [hp_a hp_b 0 16384]; diff --git a/src/audio/crossover/tune/sof_crossover_paths.m b/src/audio/crossover/tune/sof_crossover_paths.m index 9b6f6892c54e..eba41c93768f 100644 --- a/src/audio/crossover/tune/sof_crossover_paths.m +++ b/src/audio/crossover/tune/sof_crossover_paths.m @@ -10,9 +10,7 @@ function sof_crossover_paths(enable) % Copyright (c) 2024, Intel Corporation. All rights reserved. common = '../../../../tools/tune/common'; - eq = '../../../../tools/tune/eq'; - # After #9187 merge use this: - # eq = '../../eq_iir/tune'; + eq = '../../eq_iir/tune'; if enable addpath(common); addpath(eq); diff --git a/src/audio/drc/tune/sof_drc_generate_config.m b/src/audio/drc/tune/sof_drc_generate_config.m index 083f3257157a..780b6cf51e09 100644 --- a/src/audio/drc/tune/sof_drc_generate_config.m +++ b/src/audio/drc/tune/sof_drc_generate_config.m @@ -1,27 +1,27 @@ function config = sof_drc_generate_config(coefs); config.enabled = coefs.enabled; -config.db_threshold = eq_coef_quant(coefs.db_threshold, 32, 24); % Q8.24 -config.db_knee = eq_coef_quant(coefs.db_knee, 32, 24); % Q8.24 -config.ratio = eq_coef_quant(coefs.ratio, 32, 24); % Q8.24 -config.pre_delay_time = eq_coef_quant(coefs.pre_delay_time, 32, 30); % Q2.30 -config.linear_threshold = eq_coef_quant(coefs.linear_threshold, 32, 30); % Q2.30 -config.slope = eq_coef_quant(coefs.slope, 32, 30); % Q2.30 -config.K = eq_coef_quant(coefs.K, 32, 20); % Q12.20 -config.knee_alpha = eq_coef_quant(coefs.knee_alpha, 32, 24); % Q8.24 -config.knee_beta = eq_coef_quant(coefs.knee_beta, 32, 24); % Q8.24 -config.knee_threshold = eq_coef_quant(coefs.knee_threshold, 32, 24); % Q8.24 -config.ratio_base = eq_coef_quant(coefs.ratio_base, 32, 30); % Q2.30 -config.master_linear_gain = eq_coef_quant(coefs.master_linear_gain, 32, 24); % Q8.24 -config.one_over_attack_frames = eq_coef_quant(coefs.one_over_attack_frames, 32, 30); % Q2.30 -config.sat_release_frames_inv_neg = eq_coef_quant(coefs.sat_release_frames_inv_neg, 32, 30); % Q2.30 -config.sat_release_rate_at_neg_two_db = eq_coef_quant(coefs.sat_release_rate_at_neg_two_db, 32, 30); % Q2.30 +config.db_threshold = sof_eq_coef_quant(coefs.db_threshold, 32, 24); % Q8.24 +config.db_knee = sof_eq_coef_quant(coefs.db_knee, 32, 24); % Q8.24 +config.ratio = sof_eq_coef_quant(coefs.ratio, 32, 24); % Q8.24 +config.pre_delay_time = sof_eq_coef_quant(coefs.pre_delay_time, 32, 30); % Q2.30 +config.linear_threshold = sof_eq_coef_quant(coefs.linear_threshold, 32, 30); % Q2.30 +config.slope = sof_eq_coef_quant(coefs.slope, 32, 30); % Q2.30 +config.K = sof_eq_coef_quant(coefs.K, 32, 20); % Q12.20 +config.knee_alpha = sof_eq_coef_quant(coefs.knee_alpha, 32, 24); % Q8.24 +config.knee_beta = sof_eq_coef_quant(coefs.knee_beta, 32, 24); % Q8.24 +config.knee_threshold = sof_eq_coef_quant(coefs.knee_threshold, 32, 24); % Q8.24 +config.ratio_base = sof_eq_coef_quant(coefs.ratio_base, 32, 30); % Q2.30 +config.master_linear_gain = sof_eq_coef_quant(coefs.master_linear_gain, 32, 24); % Q8.24 +config.one_over_attack_frames = sof_eq_coef_quant(coefs.one_over_attack_frames, 32, 30); % Q2.30 +config.sat_release_frames_inv_neg = sof_eq_coef_quant(coefs.sat_release_frames_inv_neg, 32, 30); % Q2.30 +config.sat_release_rate_at_neg_two_db = sof_eq_coef_quant(coefs.sat_release_rate_at_neg_two_db, 32, 30); % Q2.30 config.kSpacingDb = coefs.kSpacingDb; -config.kA = eq_coef_quant(coefs.kA, 32, 12); % Q20.12 -config.kB = eq_coef_quant(coefs.kB, 32, 12); % Q20.12 -config.kC = eq_coef_quant(coefs.kC, 32, 12); % Q20.12 -config.kD = eq_coef_quant(coefs.kD, 32, 12); % Q20.12 -config.kE = eq_coef_quant(coefs.kE, 32, 12); % Q20.12 +config.kA = sof_eq_coef_quant(coefs.kA, 32, 12); % Q20.12 +config.kB = sof_eq_coef_quant(coefs.kB, 32, 12); % Q20.12 +config.kC = sof_eq_coef_quant(coefs.kC, 32, 12); % Q20.12 +config.kD = sof_eq_coef_quant(coefs.kD, 32, 12); % Q20.12 +config.kE = sof_eq_coef_quant(coefs.kE, 32, 12); % Q20.12 % Print out config config diff --git a/src/audio/drc/tune/sof_drc_paths.m b/src/audio/drc/tune/sof_drc_paths.m index b1071bcf2b0e..8bed8c8410f5 100644 --- a/src/audio/drc/tune/sof_drc_paths.m +++ b/src/audio/drc/tune/sof_drc_paths.m @@ -10,10 +10,7 @@ function sof_drc_paths(enable) % 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'; + eq = '../../eq_iir/tune'; if enable addpath(common); addpath(eq); diff --git a/src/audio/drc/tune/sof_example_drc.m b/src/audio/drc/tune/sof_example_drc.m index 865d816dd7f8..896556e74f5b 100644 --- a/src/audio/drc/tune/sof_example_drc.m +++ b/src/audio/drc/tune/sof_example_drc.m @@ -1,6 +1,6 @@ function sof_example_drc() -sof_drc_paths(1); +sof_drc_paths(true); % The parameters of the DRC compressor % enabled: 1 to enable the compressor, 0 to disable it @@ -47,7 +47,7 @@ function sof_example_drc() params.post_gain = 0; drc_coefs_and_config_export(params, 'dmic_default'); -sof_drc_paths(0); +sof_drc_paths(false); end diff --git a/src/audio/multiband_drc/tune/drc_gen_quant_coefs.m b/src/audio/multiband_drc/tune/drc_gen_quant_coefs.m deleted file mode 100644 index fa39750214ad..000000000000 --- a/src/audio/multiband_drc/tune/drc_gen_quant_coefs.m +++ /dev/null @@ -1,8 +0,0 @@ -function drc_coefs = drc_gen_quant_coefs(num_bands, sample_rate, params); - -for i = 1:num_bands - coefs = drc_gen_coefs(params(i), sample_rate); - drc_coefs(i) = drc_generate_config(coefs); -end - -end diff --git a/src/audio/multiband_drc/tune/crossover_gen_quant_coefs.m b/src/audio/multiband_drc/tune/sof_crossover_gen_quant_coefs.m similarity index 76% rename from src/audio/multiband_drc/tune/crossover_gen_quant_coefs.m rename to src/audio/multiband_drc/tune/sof_crossover_gen_quant_coefs.m index 44f46f276ce8..df00c2de3df4 100644 --- a/src/audio/multiband_drc/tune/crossover_gen_quant_coefs.m +++ b/src/audio/multiband_drc/tune/sof_crossover_gen_quant_coefs.m @@ -1,13 +1,11 @@ -function crossover_coefs = crossover_gen_quant_coefs(num_bands, sample_rate, - fc_low, fc_med, fc_high); +function crossover_coefs = sof_crossover_gen_quant_coefs(num_bands, sample_rate, + fc_low, fc_med, fc_high); % De-normalize cutoff frequencies in respect to nyquist (half of sample rate) fc_low = fc_low * sample_rate / 2; fc_med = fc_med * sample_rate / 2; fc_high = fc_high * sample_rate / 2; -addpath ../crossover - filter_len = 3; crossover.lp = cell(1:filter_len); crossover.hp = cell(1:filter_len); @@ -19,15 +17,15 @@ crossover.hp = [flat_filter() flat_filter() flat_filter()]; elseif (num_bands == 2) % 2-way crossover - crossover = crossover_gen_coefs(sample_rate, fc_low); + crossover = sof_crossover_gen_coefs(sample_rate, fc_low); crossover.lp = [crossover.lp(1) flat_filter() flat_filter()]; crossover.hp = [crossover.hp(1) flat_filter() flat_filter()]; elseif (num_bands == 3) % 3-way crossover - crossover = crossover_gen_coefs(sample_rate, fc_low, fc_med); + crossover = sof_crossover_gen_coefs(sample_rate, fc_low, fc_med); else % (num_bands == 4) % 4-way crossover - crossover = crossover_gen_coefs(sample_rate, fc_low, fc_med, fc_high); + crossover = sof_crossover_gen_coefs(sample_rate, fc_low, fc_med, fc_high); end assert(length(crossover.lp) == filter_len && length(crossover.hp) == filter_len); @@ -39,9 +37,7 @@ end % Convert the [a,b] coefficients to values usable with SOF -crossover_bqs = crossover_coef_quant(crossover.lp, crossover.hp); - -rmpath ../crossover +crossover_bqs = sof_crossover_coef_quant(crossover.lp, crossover.hp); j = 1; k = 1; diff --git a/src/audio/multiband_drc/tune/sof_drc_gen_quant_coefs.m b/src/audio/multiband_drc/tune/sof_drc_gen_quant_coefs.m new file mode 100644 index 000000000000..681c34147568 --- /dev/null +++ b/src/audio/multiband_drc/tune/sof_drc_gen_quant_coefs.m @@ -0,0 +1,8 @@ +function drc_coefs = sof_drc_gen_quant_coefs(num_bands, sample_rate, params); + +for i = 1:num_bands + coefs = sof_drc_gen_coefs(params(i), sample_rate); + drc_coefs(i) = sof_drc_generate_config(coefs); +end + +end diff --git a/src/audio/multiband_drc/tune/example_multiband_drc.m b/src/audio/multiband_drc/tune/sof_example_multiband_drc.m similarity index 86% rename from src/audio/multiband_drc/tune/example_multiband_drc.m rename to src/audio/multiband_drc/tune/sof_example_multiband_drc.m index a5b7450b5bc7..81346aed93c3 100644 --- a/src/audio/multiband_drc/tune/example_multiband_drc.m +++ b/src/audio/multiband_drc/tune/sof_example_multiband_drc.m @@ -1,4 +1,4 @@ -function example_multiband_drc() +function sof_example_multiband_drc() prm.name = "default"; prm.sample_rate = 48000; @@ -19,7 +19,7 @@ function example_multiband_drc() function export_multiband_drc(prm) -multiband_drc_paths(true); +sof_multiband_drc_paths(true); % Set the parameters here sof_tools = '../../../../tools'; @@ -121,34 +121,34 @@ function export_multiband_drc(prm) % Generate Emphasis/Deemphasis IIR filter quantized coefs struct from parameters -[emp_coefs, deemp_coefs] = iir_gen_quant_coefs(iir_params); +[emp_coefs, deemp_coefs] = sof_iir_gen_quant_coefs(iir_params); % Generate Crossover quantized coefs struct from parameters -crossover_coefs = crossover_gen_quant_coefs(num_bands, sample_rate, ... - drc_params(2).band_lower_freq, ... - drc_params(3).band_lower_freq, ... - drc_params(4).band_lower_freq); +crossover_coefs = sof_crossover_gen_quant_coefs(num_bands, sample_rate, ... + drc_params(2).band_lower_freq, ... + drc_params(3).band_lower_freq, ... + drc_params(4).band_lower_freq); % Generate DRC quantized coefs struct from parameters -drc_coefs = drc_gen_quant_coefs(num_bands, sample_rate, drc_params); +drc_coefs = sof_drc_gen_quant_coefs(num_bands, sample_rate, drc_params); % Generate output files % Convert quantized coefs structs to binary blob -blob8 = multiband_drc_build_blob(num_bands, enable_emp_deemp, emp_coefs, ... - deemp_coefs, crossover_coefs, drc_coefs, ... - endian, 3); -blob8_ipc4 = multiband_drc_build_blob(num_bands, enable_emp_deemp, emp_coefs, ... - deemp_coefs, crossover_coefs, drc_coefs, ... - endian, 4); +blob8 = sof_multiband_drc_build_blob(num_bands, enable_emp_deemp, emp_coefs, ... + deemp_coefs, crossover_coefs, drc_coefs, ... + endian, 3); +blob8_ipc4 = sof_multiband_drc_build_blob(num_bands, enable_emp_deemp, emp_coefs, ... + deemp_coefs, crossover_coefs, drc_coefs, ... + endian, 4); tplg_write(tplg1_fn, blob8, "MULTIBAND_DRC"); -tplg2_write(tplg2_fn, blob8_ipc4, "multiband_drc_config", "Exported with script example_multiband_drc.m"); +tplg2_write(tplg2_fn, blob8_ipc4, "multiband_drc_config", "Exported with script sof_example_multiband_drc.m"); sof_ucm_blob_write(blob3_fn, blob8); alsactl_write(alsa3_fn, blob8); sof_ucm_blob_write(blob4_fn, blob8_ipc4); alsactl_write(alsa4_fn, blob8_ipc4); -multiband_drc_paths(false); +sof_multiband_drc_paths(false); end diff --git a/src/audio/multiband_drc/tune/iir_gen_quant_coefs.m b/src/audio/multiband_drc/tune/sof_iir_gen_quant_coefs.m similarity index 93% rename from src/audio/multiband_drc/tune/iir_gen_quant_coefs.m rename to src/audio/multiband_drc/tune/sof_iir_gen_quant_coefs.m index dafeb3cfe30b..fb78e4fc1ad0 100644 --- a/src/audio/multiband_drc/tune/iir_gen_quant_coefs.m +++ b/src/audio/multiband_drc/tune/sof_iir_gen_quant_coefs.m @@ -1,4 +1,4 @@ -function [emp_coefs, deemp_coefs] = iir_gen_quant_coefs(params) +function [emp_coefs, deemp_coefs] = sof_iir_gen_quant_coefs(params) stage_gain = params.stage_gain; stage_ratio = params.stage_ratio; @@ -79,8 +79,8 @@ quant_coefs = cell(1, 2); for i = 1:length(coefs) coef = cell2mat(coefs(i)); - quant_ab = eq_coef_quant(coef(1:5), bits_iir, qf_iir); - quant_gain = eq_coef_quant(coef(7), bits_gain, qf_gain); + quant_ab = sof_eq_coef_quant(coef(1:5), bits_iir, qf_iir); + quant_gain = sof_eq_coef_quant(coef(7), bits_gain, qf_gain); quant_coefs(i) = [quant_ab coef(6) quant_gain]; end diff --git a/src/audio/multiband_drc/tune/multiband_drc_build_blob.m b/src/audio/multiband_drc/tune/sof_multiband_drc_build_blob.m similarity index 94% rename from src/audio/multiband_drc/tune/multiband_drc_build_blob.m rename to src/audio/multiband_drc/tune/sof_multiband_drc_build_blob.m index 59e9edde6681..ab3fc063a8ec 100644 --- a/src/audio/multiband_drc/tune/multiband_drc_build_blob.m +++ b/src/audio/multiband_drc/tune/sof_multiband_drc_build_blob.m @@ -1,7 +1,7 @@ -function blob8 = multiband_drc_build_blob(num_bands, enable_emp_deemp, - emp_coefs, deemp_coefs, - crossover_coefs, drc_coefs, - endian, ipc_ver) +function blob8 = sof_multiband_drc_build_blob(num_bands, enable_emp_deemp, + emp_coefs, deemp_coefs, + crossover_coefs, drc_coefs, + endian, ipc_ver) if nargin < 7 endian = 'little' diff --git a/src/audio/multiband_drc/tune/multiband_drc_paths.m b/src/audio/multiband_drc/tune/sof_multiband_drc_paths.m similarity index 52% rename from src/audio/multiband_drc/tune/multiband_drc_paths.m rename to src/audio/multiband_drc/tune/sof_multiband_drc_paths.m index 2a5e4ae7595b..477aebc4c023 100644 --- a/src/audio/multiband_drc/tune/multiband_drc_paths.m +++ b/src/audio/multiband_drc/tune/sof_multiband_drc_paths.m @@ -1,6 +1,6 @@ -function multiband_drc_paths(enable) +function sof_multiband_drc_paths(enable) -% multiband_drc_paths(enable) +% sof_multiband_drc_paths(enable) % enable - set to true to enable needed search path % set to false to disable the search paths % @@ -10,15 +10,9 @@ function multiband_drc_paths(enable) % Copyright (c) 2024, Intel Corporation. All rights reserved. common = '../../../../tools/tune/common'; - crossover = '../../../../tools/tune/crossover'; - drc = '../../../../tools/tune/drc'; - eq = '../../../../tools/tune/eq'; - # After #9215 merge use this: - # crossover = '../../crossover/tune'; - # After #9188 merge use this: - # drc = '../../drc/tune'; - # After #9187 merge use this: - # eq = '../../eq_iir/tune'; + crossover = '../../crossover/tune'; + drc = '../../drc/tune'; + eq = '../../eq_iir/tune'; if enable addpath(common); addpath(crossover); From ad0f77ceb911a7d1c0fa9691e25231b36a19101f Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 18 Oct 2024 14:42:26 +0300 Subject: [PATCH 2/5] Audio: Multiband-DRC: Tune: Expose all band parameters to top This change allows to tune all bands parameters from script top level. It prepares for a better testable default blob for the component. The actual setup blobs data is not impacted by this same since the parameters are kept the same. Signed-off-by: Seppo Ingalsuo --- .../tune/sof_example_multiband_drc.m | 87 +++++++------------ 1 file changed, 31 insertions(+), 56 deletions(-) diff --git a/src/audio/multiband_drc/tune/sof_example_multiband_drc.m b/src/audio/multiband_drc/tune/sof_example_multiband_drc.m index 81346aed93c3..de50d9b92d45 100644 --- a/src/audio/multiband_drc/tune/sof_example_multiband_drc.m +++ b/src/audio/multiband_drc/tune/sof_example_multiband_drc.m @@ -1,11 +1,24 @@ function sof_example_multiband_drc() +rz1 = [0.09 0.16 0.42 0.98]; + prm.name = "default"; prm.sample_rate = 48000; prm.enable_emp_deemp = 1; +prm.stage_gain = 4.4; +prm.stage_ratio = 2; prm.num_bands = 3; -prm.enable_bands = [1 2 3 0]; -prm.band_lower_freq = [0 200 2000 10000]; +prm.enable_bands = [ 1 2 3 0 ]; +prm.band_lower_freq = [ 0 200 2000 10000 ]; +prm.threshold = [ -24 -24 -24 -24 ]; +prm.knee = [ 30 30 30 30 ]; +prm.ratio = [ 12 12 12 12 ]; +prm.attack = [ 0.003 0.003 0.003 0.003 ]; +prm.release = [ 0.2 0.2 0.2 0.2 ]; +prm.pre_delay = [ 0.006 0.006 0.006 0.006 ]; +prm.release_spacing = [ 5 5 5 5 ]; +prm.post_gain = [ 0 0 0 0 ]; +prm.release_zone = [ rz1' rz1' rz1' rz1']; export_multiband_drc(prm) prm.name = "passthrough"; @@ -44,10 +57,10 @@ function export_multiband_drc(prm) % The parameters of Emphasis IIR filter % stage_gain: The gain of each emphasis filter stage -iir_params.stage_gain = 4.4; +iir_params.stage_gain = prm.stage_gain; % stage_ratio: The frequency ratio for each emphasis filter stage to the % previous stage -iir_params.stage_ratio = 2; +iir_params.stage_ratio = prm.stage_ratio; % anchor: The frequency of the first emphasis filter, in normalized frequency % (in [0, 1], relative to half of the sample rate) iir_params.anchor = 15000 / nyquist; @@ -66,61 +79,23 @@ function export_multiband_drc(prm) % band_lower_freq: The lower frequency of the band, in normalized frequency % (in [0, 1], relative to half of the sample rate) -% Band 1 DRC parameter -drc_params(1).enabled = prm.enable_bands(1); -drc_params(1).threshold = -24; -drc_params(1).knee = 30; -drc_params(1).ratio = 12; -drc_params(1).attack = 0.003; -drc_params(1).release = 0.2; -drc_params(1).pre_delay = 0.006; -drc_params(1).release_zone = [0.09 0.16 0.42 0.98]; -drc_params(1).release_spacing = 5; -drc_params(1).post_gain = 0; -drc_params(1).band_lower_freq = prm.band_lower_freq(1) / nyquist; - -% Band 2 DRC parameter (only valid if num_bands > 1) -drc_params(2).enabled = prm.enable_bands(2); -drc_params(2).threshold = -24; -drc_params(2).knee = 30; -drc_params(2).ratio = 12; -drc_params(2).attack = 0.003; -drc_params(2).release = 0.2; -drc_params(2).pre_delay = 0.006; -drc_params(2).release_zone = [0.09 0.16 0.42 0.98]; -drc_params(2).release_spacing = 5; -drc_params(2).post_gain = 0; -drc_params(2).band_lower_freq = prm.band_lower_freq(2) / nyquist; - -% Band 3 DRC parameter (only valid if num_bands > 2) -drc_params(3).enabled = prm.enable_bands(3); -drc_params(3).threshold = -24; -drc_params(3).knee = 30; -drc_params(3).ratio = 12; -drc_params(3).attack = 0.003; -drc_params(3).release = 0.2; -drc_params(3).pre_delay = 0.006; -drc_params(3).release_zone = [0.09 0.16 0.42 0.98]; -drc_params(3).release_spacing = 5; -drc_params(3).post_gain = 0; -drc_params(3).band_lower_freq = prm.band_lower_freq(3) / nyquist; - -% Band 4 DRC parameter (only valid if num_bands > 3) -drc_params(4).enabled = prm.enable_bands(4); -drc_params(4).threshold = -24; -drc_params(4).knee = 30; -drc_params(4).ratio = 12; -drc_params(4).attack = 0.003; -drc_params(4).release = 0.2; -drc_params(4).pre_delay = 0.006; -drc_params(4).release_zone = [0.09 0.16 0.42 0.98]; -drc_params(4).release_spacing = 5; -drc_params(4).post_gain = 0; -drc_params(4).band_lower_freq = prm.band_lower_freq(4) / nyquist; +for i = 1:4 + % Band n DRC parameter, (only valid if num_bands >= i) + drc_params(i).enabled = prm.enable_bands(i); + drc_params(i).threshold = prm.threshold(i); + drc_params(i).knee = prm.knee(i); + drc_params(i).ratio = prm.ratio(i); + drc_params(i).attack = prm.attack(i); + drc_params(i).release = prm.release(i); + drc_params(i).pre_delay = prm.pre_delay(i); + drc_params(i).release_zone = prm.release_zone(:, i)'; + drc_params(i).release_spacing = prm.release_spacing(i); + drc_params(i).post_gain = prm.post_gain(i); + drc_params(i).band_lower_freq = prm.band_lower_freq(i) / nyquist; +end % Generate Emphasis/Deemphasis IIR filter quantized coefs struct from parameters - [emp_coefs, deemp_coefs] = sof_iir_gen_quant_coefs(iir_params); % Generate Crossover quantized coefs struct from parameters From a7ef93bb30cf6a12c73cbb7093bc9bd3db1347f8 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 18 Oct 2024 17:07:29 +0300 Subject: [PATCH 3/5] Audio: Multiband-DRC: Tune: Add plot of emphasis/de-emphasis response The plot is useful to see impact of emphasis/de-emphasis filter parameters. The patch adds two arguments to function sof_iir_gen_quant_coefs() for rate and enable to show in the plot when enabled and with a frequency scale in x-axis. Signed-off-by: Seppo Ingalsuo --- .../tune/sof_example_multiband_drc.m | 2 +- .../tune/sof_iir_gen_quant_coefs.m | 53 +++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/audio/multiband_drc/tune/sof_example_multiband_drc.m b/src/audio/multiband_drc/tune/sof_example_multiband_drc.m index de50d9b92d45..b3136bf11b8b 100644 --- a/src/audio/multiband_drc/tune/sof_example_multiband_drc.m +++ b/src/audio/multiband_drc/tune/sof_example_multiband_drc.m @@ -96,7 +96,7 @@ function export_multiband_drc(prm) % Generate Emphasis/Deemphasis IIR filter quantized coefs struct from parameters -[emp_coefs, deemp_coefs] = sof_iir_gen_quant_coefs(iir_params); +[emp_coefs, deemp_coefs] = sof_iir_gen_quant_coefs(iir_params, sample_rate, enable_emp_deemp); % Generate Crossover quantized coefs struct from parameters crossover_coefs = sof_crossover_gen_quant_coefs(num_bands, sample_rate, ... diff --git a/src/audio/multiband_drc/tune/sof_iir_gen_quant_coefs.m b/src/audio/multiband_drc/tune/sof_iir_gen_quant_coefs.m index fb78e4fc1ad0..946434e2172f 100644 --- a/src/audio/multiband_drc/tune/sof_iir_gen_quant_coefs.m +++ b/src/audio/multiband_drc/tune/sof_iir_gen_quant_coefs.m @@ -1,4 +1,4 @@ -function [emp_coefs, deemp_coefs] = sof_iir_gen_quant_coefs(params) +function [emp_coefs, deemp_coefs] = sof_iir_gen_quant_coefs(params, sample_rate, enable) stage_gain = params.stage_gain; stage_ratio = params.stage_ratio; @@ -19,9 +19,10 @@ % Adjust the stage gain (push gains to the last stage) of emphasis filter [emp(1), emp(2)] = stage_gain_adjust(emp(1), emp(2)); -% Print emp and deemp -%emp -%deemp +% Plot emp and deemp +if enable + plot_emp_deem(emp, deemp, sample_rate); +end % Convert the coefficients to values usable with SOF emp_coefs = iir_coef_quant(emp); @@ -111,3 +112,47 @@ end end + +function plot_emp_deem(emp, deemp, fs) + +f = logspace(log10(10), log10(fs/2), 100); + +[eb1, ea1] = get_biquad(cell2mat(emp(1))); +[eb2, ea2] = get_biquad(cell2mat(emp(2))); +eb = conv(eb1, eb2); +ea = conv(ea1, ea2); +he = freqz(eb, ea, f, fs); + +[db1, da1] = get_biquad(cell2mat(deemp(1))); +[db2, da2] = get_biquad(cell2mat(deemp(2))); +db = conv(db1, db2); +da = conv(da1, da2); +hd = freqz(db, da, f, fs); +hed = he .* hd; + +figure +subplot(3,1,1); +semilogx(f, 20*log10(he)); +grid on; +ylabel('Emp (dB)'); +title('Emphasis, de-emphasis responses'); +subplot(3,1,2); +semilogx(f, 20*log10(hd)); +grid on; +ylabel('De-emp (dB)'); +subplot(3,1,3); +semilogx(f, 20*log10(hed)); +grid on; +ylabel('Combined (dB)') +xlabel('Frequency (Hz)'); + +end + +function [b, a] = get_biquad(bq) + + a = [1 -bq(2:-1:1)]; + b = [bq(5:-1:3)]; + shift = bq(6); + gain = bq(7) * 2^(-shift); + b = b * gain; +end From 9c4b972b38bc96427f0fc8de5d652c0bfab0310a Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 18 Oct 2024 17:12:53 +0300 Subject: [PATCH 4/5] Audio: Multiband-DRC: Tune: Adjust default blob parameters This change helps the default blob to pass the coarse audio quality check that is done in scripts/host-testbench.sh. The knee and limiting region of each band is brought down from threshold -24 to -40 to avoid signal clipping. It helps to pass the -1 dBFS chirp in the test. The band edge frequencies are moved up for test purpose to better see the band edges. The emphasis of high frequencies is changed with parameter stage_gain to much less than 1 dB to keep the feature active in testing performance but not impacting much to processed audio. The emphasis filter with previous setting caused a lot of distortion and may need revisit in coefficients calculation or filter scaling. These parameters are not final. The better default parameters for e.g. a notebook speaker are for further study. Signed-off-by: Seppo Ingalsuo --- .../multiband_drc/tune/sof_example_multiband_drc.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/audio/multiband_drc/tune/sof_example_multiband_drc.m b/src/audio/multiband_drc/tune/sof_example_multiband_drc.m index b3136bf11b8b..2626c1600310 100644 --- a/src/audio/multiband_drc/tune/sof_example_multiband_drc.m +++ b/src/audio/multiband_drc/tune/sof_example_multiband_drc.m @@ -5,14 +5,14 @@ function sof_example_multiband_drc() prm.name = "default"; prm.sample_rate = 48000; prm.enable_emp_deemp = 1; -prm.stage_gain = 4.4; -prm.stage_ratio = 2; +prm.stage_gain = 0.01; +prm.stage_ratio = 2 prm.num_bands = 3; prm.enable_bands = [ 1 2 3 0 ]; -prm.band_lower_freq = [ 0 200 2000 10000 ]; -prm.threshold = [ -24 -24 -24 -24 ]; -prm.knee = [ 30 30 30 30 ]; -prm.ratio = [ 12 12 12 12 ]; +prm.band_lower_freq = [ 0 2000 8000 16000 ]; +prm.threshold = [ -30 -30 -30 -30 ]; +prm.knee = [ 20 20 20 20 ]; +prm.ratio = [ 10 10 10 10 ]; prm.attack = [ 0.003 0.003 0.003 0.003 ]; prm.release = [ 0.2 0.2 0.2 0.2 ]; prm.pre_delay = [ 0.006 0.006 0.006 0.006 ]; From 2f412f1d44c6a3ef94a769cececc012032feb682 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 18 Oct 2024 18:04:14 +0300 Subject: [PATCH 5/5] Tools: Topology2: Multiband-DRC: Replace default configuration blob New blob for testing that passes the scripts/host-testbench.sh audio quality test. Signed-off-by: Seppo Ingalsuo --- .../components/multiband_drc/default.conf | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/tools/topology/topology2/include/components/multiband_drc/default.conf b/tools/topology/topology2/include/components/multiband_drc/default.conf index e42467528301..5412f03a7cda 100644 --- a/tools/topology/topology2/include/components/multiband_drc/default.conf +++ b/tools/topology/topology2/include/components/multiband_drc/default.conf @@ -1,4 +1,4 @@ -# Exported with script example_multiband_drc.m 01-Sep-2023 +# Exported with script sof_example_multiband_drc.m 18-Oct-2024 Object.Base.data."multiband_drc_config" { bytes " 0x53,0x4f,0x46,0x34,0x00,0x00,0x00,0x00, @@ -10,27 +10,20 @@ Object.Base.data."multiband_drc_config" { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x7b,0x8e,0x88,0xfe, - 0x36,0x79,0x57,0x17,0x5f,0x19,0x6f,0x06, - 0xe8,0x79,0x67,0xd4,0x00,0x00,0x00,0x40, + 0x00,0x00,0x00,0x00,0x59,0xa5,0xa3,0xfc, + 0x0b,0xdc,0xf0,0x20,0x76,0xe4,0x5e,0x03, + 0x8d,0x98,0x04,0xdf,0x00,0x00,0x00,0x40, 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00, - 0x5f,0x6d,0x19,0xe7,0x39,0xc4,0xd4,0x50, - 0x0c,0x9b,0x09,0x24,0xad,0x76,0x82,0x9f, - 0x00,0x00,0x00,0x40,0xff,0xff,0xff,0xff, - 0x43,0x72,0x00,0x00,0xa1,0xe6,0x90,0xf9, - 0x18,0x86,0x98,0x2b,0xe3,0x32,0xef,0x00, - 0x4b,0xf7,0x20,0xf1,0x18,0x69,0xc6,0x28, + 0x88,0xf6,0x5c,0xe1,0x67,0xb2,0x3a,0x59, + 0xc3,0xd0,0xa8,0x1e,0x78,0x3b,0xbd,0xa6, + 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, + 0x2a,0x40,0x00,0x00,0x8a,0x1b,0xa1,0xfc, + 0x73,0x67,0xfb,0x20,0x87,0x92,0x5b,0x03, + 0x7a,0xcd,0x16,0xdf,0x02,0x1d,0xf1,0x3f, 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00, - 0xf4,0x64,0xf6,0xdb,0x53,0x89,0x7d,0x60, - 0x5c,0x14,0xf2,0x0a,0x84,0x0d,0x78,0xdc, - 0xda,0xef,0x21,0x1c,0x00,0x00,0x00,0x00, - 0x00,0x40,0x00,0x00,0x6f,0x82,0x53,0xc2, - 0x3e,0x77,0xa1,0x7d,0x95,0xc1,0x02,0x00, - 0x2a,0x83,0x05,0x00,0x95,0xc1,0x02,0x00, - 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00, - 0x6f,0x82,0x53,0xc2,0x3e,0x77,0xa1,0x7d, - 0x34,0x7d,0xd3,0x3e,0x99,0x05,0x59,0x82, - 0x34,0x7d,0xd3,0x3e,0x00,0x00,0x00,0x00, + 0x3d,0x2f,0x57,0xe1,0x88,0xc4,0x42,0x59, + 0xb9,0x0c,0x96,0x1e,0xdd,0x20,0xeb,0xa6, + 0xa6,0xde,0xe4,0x3f,0x00,0x00,0x00,0x00, 0x00,0x40,0x00,0x00,0x2d,0x3a,0xcd,0xd3, 0xc0,0xf5,0x82,0x68,0x05,0xf4,0xeb,0x00, 0x0a,0xe8,0xd7,0x01,0x05,0xf4,0xeb,0x00, @@ -38,42 +31,49 @@ Object.Base.data."multiband_drc_config" { 0x2d,0x3a,0xcd,0xd3,0xc0,0xf5,0x82,0x68, 0xe5,0x6e,0x2d,0x35,0x36,0x22,0xa5,0x95, 0xe5,0x6e,0x2d,0x35,0x00,0x00,0x00,0x00, - 0x00,0x40,0x00,0x00,0x2d,0x3a,0xcd,0xd3, - 0xc0,0xf5,0x82,0x68,0x05,0xf4,0xeb,0x00, - 0x0a,0xe8,0xd7,0x01,0x05,0xf4,0xeb,0x00, + 0x00,0x40,0x00,0x00,0xe7,0x26,0x9d,0xf0, + 0x8d,0x6c,0xb1,0x27,0x23,0x5b,0xec,0x09, + 0x46,0xb6,0xd8,0x13,0x23,0x5b,0xec,0x09, 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00, - 0x2d,0x3a,0xcd,0xd3,0xc0,0xf5,0x82,0x68, - 0xe5,0x6e,0x2d,0x35,0x36,0x22,0xa5,0x95, - 0xe5,0x6e,0x2d,0x35,0x00,0x00,0x00,0x00, + 0xe7,0x26,0x9d,0xf0,0x8d,0x6c,0xb1,0x27, + 0x6a,0x11,0xc5,0x1d,0x2d,0xdd,0x75,0xc4, + 0x6a,0x11,0xc5,0x1d,0x00,0x00,0x00,0x00, + 0x00,0x40,0x00,0x00,0xe7,0x26,0x9d,0xf0, + 0x8d,0x6c,0xb1,0x27,0x23,0x5b,0xec,0x09, + 0x46,0xb6,0xd8,0x13,0x23,0x5b,0xec,0x09, + 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00, + 0xe7,0x26,0x9d,0xf0,0x8d,0x6c,0xb1,0x27, + 0x6a,0x11,0xc5,0x1d,0x2d,0xdd,0x75,0xc4, + 0x6a,0x11,0xc5,0x1d,0x00,0x00,0x00,0x00, 0x00,0x40,0x00,0x00,0x01,0x00,0x00,0x00, - 0x00,0x00,0x00,0xe8,0x00,0x00,0x00,0x1e, - 0x00,0x00,0x00,0x0c,0xd3,0x4d,0x62,0x00, - 0xb1,0xc2,0x09,0x04,0x55,0x55,0x55,0x05, - 0x50,0xfa,0x1e,0x00,0x55,0x60,0x94,0x00, - 0x7e,0x98,0x6a,0xff,0x83,0xc9,0xfe,0x01, - 0x64,0x47,0x47,0x22,0x17,0x56,0x74,0x01, + 0x00,0x00,0x00,0xe2,0x00,0x00,0x00,0x14, + 0x00,0x00,0x00,0x0a,0xd3,0x4d,0x62,0x00, + 0x8a,0x1b,0x06,0x02,0x66,0x66,0x66,0x06, + 0x2f,0x97,0xba,0x00,0x18,0x0c,0x1e,0x00, + 0x20,0x42,0xe0,0xff,0x4e,0xf4,0x50,0x00, + 0x9a,0x9f,0x34,0x08,0x0b,0xfa,0x6d,0x03, 0x1c,0xc7,0x71,0x00,0x77,0x77,0x77,0xff, 0xd8,0x77,0x1f,0x00,0x05,0x00,0x00,0x00, 0x00,0x00,0x36,0x00,0xdf,0x97,0x03,0x00, 0xe7,0x3e,0x1e,0x00,0xdf,0x97,0x07,0x00, 0x5b,0x91,0x00,0x00,0x02,0x00,0x00,0x00, - 0x00,0x00,0x00,0xe8,0x00,0x00,0x00,0x1e, - 0x00,0x00,0x00,0x0c,0xd3,0x4d,0x62,0x00, - 0xb1,0xc2,0x09,0x04,0x55,0x55,0x55,0x05, - 0x50,0xfa,0x1e,0x00,0x55,0x60,0x94,0x00, - 0x7e,0x98,0x6a,0xff,0x83,0xc9,0xfe,0x01, - 0x64,0x47,0x47,0x22,0x17,0x56,0x74,0x01, + 0x00,0x00,0x00,0xe2,0x00,0x00,0x00,0x14, + 0x00,0x00,0x00,0x0a,0xd3,0x4d,0x62,0x00, + 0x8a,0x1b,0x06,0x02,0x66,0x66,0x66,0x06, + 0x2f,0x97,0xba,0x00,0x18,0x0c,0x1e,0x00, + 0x20,0x42,0xe0,0xff,0x4e,0xf4,0x50,0x00, + 0x9a,0x9f,0x34,0x08,0x0b,0xfa,0x6d,0x03, 0x1c,0xc7,0x71,0x00,0x77,0x77,0x77,0xff, 0xd8,0x77,0x1f,0x00,0x05,0x00,0x00,0x00, 0x00,0x00,0x36,0x00,0xdf,0x97,0x03,0x00, 0xe7,0x3e,0x1e,0x00,0xdf,0x97,0x07,0x00, 0x5b,0x91,0x00,0x00,0x03,0x00,0x00,0x00, - 0x00,0x00,0x00,0xe8,0x00,0x00,0x00,0x1e, - 0x00,0x00,0x00,0x0c,0xd3,0x4d,0x62,0x00, - 0xb1,0xc2,0x09,0x04,0x55,0x55,0x55,0x05, - 0x50,0xfa,0x1e,0x00,0x55,0x60,0x94,0x00, - 0x7e,0x98,0x6a,0xff,0x83,0xc9,0xfe,0x01, - 0x64,0x47,0x47,0x22,0x17,0x56,0x74,0x01, + 0x00,0x00,0x00,0xe2,0x00,0x00,0x00,0x14, + 0x00,0x00,0x00,0x0a,0xd3,0x4d,0x62,0x00, + 0x8a,0x1b,0x06,0x02,0x66,0x66,0x66,0x06, + 0x2f,0x97,0xba,0x00,0x18,0x0c,0x1e,0x00, + 0x20,0x42,0xe0,0xff,0x4e,0xf4,0x50,0x00, + 0x9a,0x9f,0x34,0x08,0x0b,0xfa,0x6d,0x03, 0x1c,0xc7,0x71,0x00,0x77,0x77,0x77,0xff, 0xd8,0x77,0x1f,0x00,0x05,0x00,0x00,0x00, 0x00,0x00,0x36,0x00,0xdf,0x97,0x03,0x00,