Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio: Multiband-DRC: Tune: Updates to setup tool after moving then to modules, blob updates to pass a quality check #9599

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/audio/crossover/tune/sof_crossover_coef_quant.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 1 addition & 3 deletions src/audio/crossover/tune/sof_crossover_paths.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 20 additions & 20 deletions src/audio/drc/tune/sof_drc_generate_config.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/audio/drc/tune/sof_drc_paths.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/audio/drc/tune/sof_example_drc.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 0 additions & 8 deletions src/audio/multiband_drc/tune/drc_gen_quant_coefs.m

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/audio/multiband_drc/tune/sof_drc_gen_quant_coefs.m
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
function example_multiband_drc()
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 = 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.enable_bands = [ 1 2 3 0 ];
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 ];
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";
Expand All @@ -19,7 +32,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';
Expand All @@ -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;
Expand All @@ -66,89 +79,51 @@ 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] = 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 = 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
Loading
Loading