2023-05-17 20:22:21 +08:00
|
|
|
function example_drc()
|
2020-09-22 18:21:24 +08:00
|
|
|
|
2023-05-17 20:22:21 +08:00
|
|
|
addpath ../common
|
2020-11-04 14:48:21 +08:00
|
|
|
|
|
|
|
% The parameters of the DRC compressor
|
|
|
|
% enabled: 1 to enable the compressor, 0 to disable it
|
|
|
|
params.enabled = 0;
|
|
|
|
% threshold: The value above which the compression starts, in dB
|
|
|
|
params.threshold = -24;
|
|
|
|
% knee: The value above which the knee region starts, in dB
|
|
|
|
params.knee = 30;
|
|
|
|
% ratio: The input/output dB ratio after the knee region
|
|
|
|
params.ratio = 12;
|
|
|
|
% attack: The time to reduce the gain by 10dB, in seconds
|
|
|
|
params.attack = 0.003;
|
|
|
|
% release: The time to increase the gain by 10dB, in seconds
|
|
|
|
params.release = 0.25;
|
|
|
|
% pre_delay: The lookahead time for the compressor, in seconds
|
|
|
|
params.pre_delay = 0.006;
|
|
|
|
% release_zone[4]: The adaptive release curve parameters
|
|
|
|
params.release_zone = [0.09 0.16 0.42 0.98];
|
|
|
|
% release_spacing: The value of spacing per frame while releasing, in dB
|
|
|
|
params.release_spacing = 5;
|
|
|
|
% post_gain: The static boost value in output, in dB
|
|
|
|
params.post_gain = 0;
|
|
|
|
|
2023-05-17 20:22:21 +08:00
|
|
|
% Export
|
|
|
|
drc_coefs_and_config_export(params, 'passthrough');
|
|
|
|
|
|
|
|
% Export enabled
|
|
|
|
params.enabled = 1;
|
|
|
|
drc_coefs_and_config_export(params, 'enabled');
|
|
|
|
|
2023-11-11 01:03:03 +08:00
|
|
|
% Export experimental configuration for a small speaker
|
|
|
|
params.enabled = 1;
|
|
|
|
params.threshold = -25;
|
|
|
|
params.knee = 15;
|
|
|
|
params.ratio = 10;
|
|
|
|
params.post_gain = 3;
|
|
|
|
drc_coefs_and_config_export(params, 'generic_notebook_speaker');
|
|
|
|
|
2023-05-17 20:22:21 +08:00
|
|
|
rmpath ../common
|
|
|
|
|
|
|
|
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
|
|
|
|
% Use those files with sof-ctl to update the component's configuration
|
2023-08-25 18:40:04 +08:00
|
|
|
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
|
2023-05-17 20:22:21 +08:00
|
|
|
|
|
|
|
endian = "little";
|
|
|
|
sample_rate = 48000;
|
|
|
|
|
2020-11-04 14:48:21 +08:00
|
|
|
% Generate coefficients for DRC with the given parameters
|
|
|
|
coefs = drc_gen_coefs(params, sample_rate);
|
2020-09-22 18:21:24 +08:00
|
|
|
|
|
|
|
% Convert coefficients to sof_drc_config struct
|
2020-11-04 14:48:21 +08:00
|
|
|
config = drc_generate_config(coefs);
|
2020-09-22 18:21:24 +08:00
|
|
|
|
|
|
|
% Convert struct to binary blob
|
|
|
|
blob8 = drc_build_blob(config, endian);
|
2023-05-17 20:22:21 +08:00
|
|
|
blob8_ipc4 = drc_build_blob(config, endian, 4);
|
2020-09-22 18:21:24 +08:00
|
|
|
|
|
|
|
% Generate output files
|
2023-12-19 01:10:15 +08:00
|
|
|
my_name = mfilename();
|
|
|
|
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);
|
2023-08-25 18:40:04 +08:00
|
|
|
blob_write(blob3_fn, blob8);
|
|
|
|
alsactl_write(alsa3_fn, blob8);
|
|
|
|
blob_write(blob4_fn, blob8_ipc4);
|
|
|
|
alsactl_write(alsa4_fn, blob8_ipc4);
|
2020-09-22 18:21:24 +08:00
|
|
|
|
2020-11-04 14:48:21 +08:00
|
|
|
% Plot x-y response in dB
|
|
|
|
drc_plot_db_curve(coefs);
|
|
|
|
|
2023-05-17 20:22:21 +08:00
|
|
|
end
|