Skip to content
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
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,5 +26,4 @@
% Print out config
config

rmpath ./../eq
end
24 changes: 24 additions & 0 deletions src/audio/drc/tune/sof_drc_paths.m
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for the moment (short term), but in the long term we need a script that sets the Matlab/Octave environment and paths up (we have a source script for Zephyr today- so something similar). See https://docs.octave.org/v4.2.1/Startup-Files.html as these mechanism can be used

Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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
4 changes: 4 additions & 0 deletions tools/tune/common/alsactl_write.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions tools/tune/common/blob_write.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions tools/tune/common/sof_ucm_blob_write.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions tools/tune/common/tplg2_write.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tools/tune/common/tplg_write.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down