Skip to content

Commit

Permalink
Audio: EQIIR: Tune: Prefix top level functions with sof_
Browse files Browse the repository at this point in the history
Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
  • Loading branch information
singalsu committed Aug 28, 2024
1 parent 4bd3334 commit 817974f
Show file tree
Hide file tree
Showing 36 changed files with 231 additions and 217 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
%
% Copyright (c) 2021, Intel Corporation. All rights reserved.

function cmocka_data_eq_fir()
function sof_cmocka_data_eq_fir()

% Output files and paths
chirp_fn = '../../../test/cmocka/include/cmocka_chirp_2ch.h';
ref_fn = '../../../test/cmocka/src/audio/eq_fir/cmocka_fir_ref.h';
coef_fn = '../../../test/cmocka/src/audio/eq_fir/cmocka_fir_coef_2ch.h';
sof_cmocka = '../../../../test/cmocka';

chirp_fn = fullfile(sof_cmocka, 'include/cmocka_chirp_2ch.h');
ref_fn = fullfile(sof_cmocka, 'src/audio/eq_fir/cmocka_fir_ref.h');
coef_fn = fullfile(sof_cmocka, 'src/audio/eq_fir/cmocka_fir_coef_2ch.h');

% Input data
fs = 48e3;
t = 100e-3;
scale = 2^31;
[x, yi] = get_chirp(fs, t);
export_c_int32t(chirp_fn, 'chirp_2ch', 'CHIRP_2CH_LENGTH',yi)
sof_export_c_int32t(chirp_fn, 'chirp_2ch', 'CHIRP_2CH_LENGTH',yi)

% Compute a test EQ
eq = test_response(coef_fn, 'fir_coef_2ch', fs);
Expand All @@ -28,7 +30,7 @@ function cmocka_data_eq_fir()
ref(:,1) = filter(eq.b_fir, 1, x(:,1));
ref(:,2) = filter(eq.b_fir, 1, x(:,2));
refi = scale_saturate(ref, scale);
export_c_int32t(ref_fn, 'fir_ref_2ch', 'FIR_REF_2CH_LENGTH', refi)
sof_export_c_int32t(ref_fn, 'fir_ref_2ch', 'FIR_REF_2CH_LENGTH', refi)

figure;
plot(yi/scale)
Expand Down Expand Up @@ -82,23 +84,24 @@ function cmocka_data_eq_fir()
function eq = test_response(fn, vn, fs)

%% Get EQ
blob_fn = '../../ctl/eq_fir_loudness.txt';
eq = eq_blob_plot(blob_fn, 'fir', fs, [], 0);
sof_ctl = '../../../../tools/ctl';
blob_fn = fullfile(sof_ctl, 'ipc3/eq_fir_loudness.txt');
eq = sof_eq_blob_plot(blob_fn, 'fir', fs, [], 0);

%% Quantize and pack filter coefficients plus shifts etc.
bq = eq_fir_blob_quant(eq.b_fir);
bq = sof_eq_fir_blob_quant(eq.b_fir);

%% Build blob
channels_in_config = 2; % Setup max 2 channels EQ
assign_response = [0 0]; % Same response for L and R
num_responses = 1; % One response
bm = eq_fir_blob_merge(channels_in_config, ...
bm = sof_eq_fir_blob_merge(channels_in_config, ...
num_responses, ...
assign_response, ...
bq);

%% Pack and write file
bp = eq_fir_blob_pack(bm);
export_c_eq_uint32t(fn, bp, vn, 0);
bp = sof_eq_fir_blob_pack(bm);
sof_export_c_eq_uint32t(fn, bp, vn, 0);

end
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
%
% Copyright (c) 2021, Intel Corporation. All rights reserved.

function cmocka_data_eq_iir()
function sof_cmocka_data_eq_iir()

% Output files and paths
chirp_fn = '../../../test/cmocka/include/cmocka_chirp_2ch.h';
ref_fn = '../../../test/cmocka/src/audio/eq_iir/cmocka_chirp_iir_ref_2ch.h';
coef_fn = '../../../test/cmocka/src/audio/eq_iir/cmocka_iir_coef_2ch.h';
sof_cmocka = '../../../../test/cmocka';
chirp_fn = fullfile(sof_cmocka, 'include/cmocka_chirp_2ch.h');
ref_fn = fullfile(sof_cmocka, 'src/audio/eq_iir/cmocka_chirp_iir_ref_2ch.h');
coef_fn = fullfile(sof_cmocka, 'src/audio/eq_iir/cmocka_iir_coef_2ch.h');

% Input data
fs = 48e3;
t = 100e-3;
scale = 2^31;
[x, yi] = get_chirp(fs, t);
export_c_int32t(chirp_fn, 'chirp_2ch', 'CHIRP_2CH_LENGTH',yi)
sof_export_c_int32t(chirp_fn, 'chirp_2ch', 'CHIRP_2CH_LENGTH',yi)

% Compute a test EQ
eq = test_response(coef_fn, 'iir_coef_2ch', fs);
Expand All @@ -30,7 +31,7 @@ function cmocka_data_eq_iir()
ref(:,2) = filter(b, a, x(:,2));
[b, a] = zp2tf(eq.p_z, eq.p_p, eq.p_k);
refi = scale_saturate(ref, scale);
export_c_int32t(ref_fn, 'chirp_iir_ref_2ch', 'CHIRP_IIR_REF_2CH_LENGTH', refi)
sof_export_c_int32t(ref_fn, 'chirp_iir_ref_2ch', 'CHIRP_IIR_REF_2CH_LENGTH', refi)

figure;
plot(yi/scale)
Expand Down Expand Up @@ -84,7 +85,7 @@ function cmocka_data_eq_iir()
function eq = test_response(fn, vn, fs)

%% Get defaults for equalizer design
eq = eq_defaults();
eq = sof_eq_defaults();
eq.fs = fs;
eq.enable_iir = 1;
eq.iir_norm_type = 'peak';
Expand All @@ -99,25 +100,25 @@ function cmocka_data_eq_iir()
];

%% Design EQ
eq = eq_compute(eq);
eq = sof_eq_compute(eq);

%% Plot
eq_plot(eq);
sof_eq_plot(eq);

%% Quantize and pack filter coefficients plus shifts etc.
bq = eq_iir_blob_quant(eq.p_z, eq.p_p, eq.p_k);
bq = sof_eq_iir_blob_quant(eq.p_z, eq.p_p, eq.p_k);

%% Build blob
channels_in_config = 2; % Setup max 2 channels EQ
assign_response = [0 0]; % Same response for L and R
num_responses = 1; % One response
bm = eq_iir_blob_merge(channels_in_config, ...
bm = sof_eq_iir_blob_merge(channels_in_config, ...
num_responses, ...
assign_response, ...
bq);

%% Pack and write file
bp = eq_iir_blob_pack(bm);
export_c_eq_uint32t(fn, bp, vn, 0);
bp = sof_eq_iir_blob_pack(bm);
sof_export_c_eq_uint32t(fn, bp, vn, 0);

end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [am, offs, p] = eq_align(f, m, f_align, m_align)
function [am, offs, p] = sof_eq_align(f, m, f_align, m_align)

%% [am, offs, p] = eq_align(f, m, f_align, m_align)
%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function eq_alsactl_write(fn, blob8)
function sof_eq_alsactl_write(fn, blob8)

%%
% Copyright (c) 2016, Intel Corporation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function eq = eq_blob_plot(blobfn, eqtype, fs, f, doplot)
function eq = sof_eq_blob_plot(blobfn, eqtype, fs, f, doplot)

% eq = eq_blob_plot(blobfn, eqtype, fs, f, doplot)
% eq = sof_eq_blob_plot(blobfn, eqtype, fs, f, doplot)
%
% Plot frequency response of IIR or FIR EQ coefficients blob
%
Expand All @@ -20,9 +20,9 @@
% eq.a - IIR denominator coefficients
%
% Examples
% eq_blob_plot('../../topology/topology1/m4/eq_iir_coef_loudness.m4', 'iir');
% eq_blob_plot('../../ctl/eq_fir_mid.bin', 'fir');
% eq_blob_plot('../../ctl/eq_iir_bassboost.txt', 'iir');
% sof_eq_blob_plot('../../topology/topology1/m4/eq_iir_coef_loudness.m4', 'iir');
% sof_eq_blob_plot('../../ctl/eq_fir_mid.bin', 'fir');
% sof_eq_blob_plot('../../ctl/eq_iir_bassboost.txt', 'iir');

% SPDX-License-Identifier: BSD-3-Clause
%
Expand Down Expand Up @@ -62,7 +62,7 @@
end

%% Read blob as 32 bit integers
blob = eq_blob_read(blobfn);
blob = sof_eq_blob_read(blobfn);

%% Group delay with grpdelay() is not working in Octave
do_group_delay = ~exist('OCTAVE_VERSION', 'builtin');
Expand All @@ -72,10 +72,10 @@
eq.gd = [];
switch lower(eqtype)
case 'fir'
hd = eq_fir_blob_decode(blob);
hd = sof_eq_fir_blob_decode(blob);
eq.m = zeros(length(eq.f), hd.channels_in_config);
for i = 1:hd.channels_in_config
decoded_eq = eq_fir_blob_decode(blob, hd.assign_response(i));
decoded_eq = sof_eq_fir_blob_decode(blob, hd.assign_response(i));
eq.b_fir = decoded_eq.b;
eq.b = 1;
eq.a = 1;
Expand All @@ -88,10 +88,10 @@
end

case 'iir'
hd = eq_iir_blob_decode(blob);
hd = sof_eq_iir_blob_decode(blob);
eq.m = zeros(length(eq.f), hd.channels_in_config);
for i = 1:hd.channels_in_config
decoded_eq = eq_iir_blob_decode(blob, hd.assign_response(i));
decoded_eq = sof_eq_iir_blob_decode(blob, hd.assign_response(i));
eq.b = decoded_eq.b;
eq.a = decoded_eq.a;
h = freqz(eq.b, eq.a, eq.f, fs);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function blob = eq_blob_read(blobfn, fntype)
function blob = sof_eq_blob_read(blobfn, fntype)

% SPDX-License-Identifier: BSD-3-Clause
%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function qc = eq_coef_quant(c, bits, qf)
function qc = sof_eq_coef_quant(c, bits, qf)

%%
% Copyright (c) 2016, Intel Corporation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function eq = eq_compute( eq )
function eq = sof_eq_compute( eq )

%%
% Copyright (c) 2016, Intel Corporation
Expand Down Expand Up @@ -42,20 +42,20 @@
%% Define target (e.g. speaker) response as parametric filter. This could also
% be numerical data interpolated to the grid.
if length(eq.parametric_target_response) > 0
[eq.t_z, eq.t_p, eq.t_k] = eq_define_parametric_eq( ...
[eq.t_z, eq.t_p, eq.t_k] = sof_eq_define_parametric_eq( ...
eq.parametric_target_response, eq.fs);
eq.t_db = eq_compute_response(eq.t_z, eq.t_p, eq.t_k, eq.f, eq.fs);
eq.t_db = sof_eq_compute_response(eq.t_z, eq.t_p, eq.t_k, eq.f, eq.fs);
end

if isempty(eq.t_db)
fprintf('Warning: No target response is defined.\n');
end

%% Align responses at some frequency and dB
[eq.m_db_s, offs] = eq_align(eq.f, eq.m_db_s, eq.f_align, eq.db_align);
[eq.m_db_s, offs] = sof_eq_align(eq.f, eq.m_db_s, eq.f_align, eq.db_align);
eq.raw_m_db = eq.raw_m_db + offs;
eq.m_db = eq.m_db + offs;
eq.t_db = eq_align(eq.f, eq.t_db, eq.f_align, eq.db_align);
eq.t_db = sof_eq_align(eq.f, eq.t_db, eq.f_align, eq.db_align);

%% Error to equalize = target - raw response, apply 1/N octave smoothing to
% soften the EQ shape
Expand All @@ -64,14 +64,14 @@

%% Parametric IIR EQ definition
if eq.enable_iir
[eq.p_z, eq.p_p, eq.p_k] = eq_define_parametric_eq(eq.peq, eq.fs);
[eq.p_z, eq.p_p, eq.p_k] = sof_eq_define_parametric_eq(eq.peq, eq.fs);
if max(length(eq.p_z), length(eq.p_p)) > 2*eq.iir_biquads_max
error('Maximum number of IIR biquads is exceeded');
end
else
[eq.p_z, eq.p_p, eq.p_k] = tf2zp(1, 1);
end
[eq.iir_eq_db, eq.iir_eq_ph, eq.iir_eq_gd] = eq_compute_response(eq.p_z, ...
[eq.iir_eq_db, eq.iir_eq_ph, eq.iir_eq_gd] = sof_eq_compute_response(eq.p_z, ...
eq.p_p, eq.p_k, eq.f, eq.fs);


Expand Down Expand Up @@ -101,10 +101,10 @@
end

%% Update all responses
eq = eq_compute_tot_response(eq);
eq = sof_eq_compute_tot_response(eq);

%% Normalize
eq = eq_norm(eq);
eq = sof_eq_norm(eq);

end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [m, ph, gd] = eq_compute_response(z, p, k, f, fs)
function [m, ph, gd] = sof_eq_compute_response(z, p, k, f, fs)

%%
% Copyright (c) 2016, Intel Corporation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function eq = eq_compute_tot_response(eq)
function eq = sof_eq_compute_tot_response(eq)

%%
% Copyright (c) 2016, Intel Corporation
Expand Down Expand Up @@ -31,8 +31,8 @@
%

% FIR response and combined IIR+FIR EQ
[eq.iir_eq_db, eq.iir_eq_ph, eq.iir_eq_gd] = eq_compute_response(eq.p_z, eq.p_p, eq.p_k, eq.f, eq.fs);
[eq.fir_eq_db, eq.fir_eq_ph, eq.fir_eq_gd] = eq_compute_response(eq.b_fir, eq.f, eq.fs);
[eq.iir_eq_db, eq.iir_eq_ph, eq.iir_eq_gd] = sof_eq_compute_response(eq.p_z, eq.p_p, eq.p_k, eq.f, eq.fs);
[eq.fir_eq_db, eq.fir_eq_ph, eq.fir_eq_gd] = sof_eq_compute_response(eq.b_fir, eq.f, eq.fs);
eq.tot_eq_db = eq.iir_eq_db + eq.fir_eq_db;
eq.tot_eq_gd = eq.iir_eq_gd + eq.fir_eq_gd;

Expand All @@ -42,7 +42,7 @@
eq.gd_eqd = eq.gd_s' + eq.tot_eq_gd;

% Align
[eq.m_eqd_s, adjust, p] = eq_align(eq.f, eq.m_eqd_s, eq.f_align, eq.db_align);
[eq.m_eqd_s, adjust, p] = sof_eq_align(eq.f, eq.m_eqd_s, eq.f_align, eq.db_align);
eq.m_eqd = eq.m_eqd + adjust;
eq.m_eq_loss = eq.tot_eq_db(p);
eq.m_eqd_abs = eq.m_db_abs+eq.m_eq_loss;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function p = eq_defaults
function p = sof_eq_defaults

%%
% Copyright (c) 2016, Intel Corporation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [z, p, k] = eq_define_parametric_eq(peq, fs)
function [z, p, k] = sof_eq_define_parametric_eq(peq, fs)

%%
% Copyright (c) 2016, Intel Corporation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function status = eq_deploy_to_dut(target, temp_file)
function status = sof_eq_deploy_to_dut(target, temp_file)
% deploy eq over ssh to a given dut with sof-eqctl
% the end target is expected to be some sort of unix system with sof-eqctl
% already installed. The system should also have ssh keys installed to prevent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function eq = eq_fir_blob_decode(blob, resp_n)
function eq = sof_eq_fir_blob_decode(blob, resp_n)

%% Decode a FIR EQ binary blob
%
Expand Down Expand Up @@ -35,7 +35,7 @@
end

%% Get ABI information
[abi_bytes, nbytes_abi] = eq_get_abi(0);
[abi_bytes, nbytes_abi] = sof_eq_get_abi(0);

%% Defaults
eq.b = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function bs = eq_fir_blob_merge(channels_in_config, ...
function bs = sof_eq_fir_blob_merge(channels_in_config, ...
number_of_responses_defined, assign_response, all_coefficients);

%% Merge equalizer definition into a struct used by successive blob making
% functions.
%
% bs = eq_fir_blob_merge(channels_in_config, number_of_responses_defined, ...
% bs = sof_eq_fir_blob_merge(channels_in_config, number_of_responses_defined, ...
% assign_response, all_coefficients);
%

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function blob8 = eq_fir_blob_pack(bs, ipc_ver, endian)
function blob8 = sof_eq_fir_blob_pack(bs, ipc_ver, endian)

%% Pack equalizer struct to bytes
%
% blob8 = eq_fir_blob_pack(bs, ipc_ver, endian)
% blob8 = sof_eq_fir_blob_pack(bs, ipc_ver, endian)
% bs - blob struct
% ipc_ver - optional, use 3 or 4. Default is 3.
% endian - optional, use 'little' or 'big'. Defaults to little.
Expand Down Expand Up @@ -89,7 +89,7 @@
nbytes_data = nb16 * 2;

%% Get ABI information
[abi_bytes, nbytes_abi] = eq_get_abi(nbytes_data, ipc_ver);
[abi_bytes, nbytes_abi] = sof_eq_get_abi(nbytes_data, ipc_ver);

%% Initialize uint8 array with correct size
nbytes = nbytes_abi + nbytes_data;
Expand Down
Loading

0 comments on commit 817974f

Please sign in to comment.