Skip to content

Commit

Permalink
Audio: TDFB: Tune: Move beamformer setup scripts to module directory
Browse files Browse the repository at this point in the history
The change is done to consolidate the files belonging to the
module. The files are moved from directory tools/tune/tdfb
into src/audio/tdfb/tune. There are no functional changes but
the impacts of naming the scripts with sof prefix and move of
directory locations is fixed. A new script sof_bf_paths is
added to make add and remove needed paths more convenient.

Signed-off-by: Seppo Ingalsuo <[email protected]>
  • Loading branch information
singalsu authored and lgirdwood committed Oct 16, 2024
1 parent cb7358e commit 166453b
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% bf = bf_array_circ(bf)
% bf = sof_bf_array_circ(bf)
%
% Inputs
% bf.mic_n ... number of microphones
Expand All @@ -15,7 +15,7 @@
%
% Author: Seppo Ingalsuo <[email protected]>

function bf = bf_array_circ(bf)
function bf = sof_bf_array_circ(bf)

bf.mic_angle = (0:bf.mic_n-1)*360/bf.mic_n; % Mic 1 at 0 deg
idx = find(bf.mic_angle > 180); % wrap > 180 deg to -180 .. 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% bf = bf_array_line(bf)
% bf = sof_bf_array_line(bf)
%
% Inputs
% bf.mic_n ... number of microphones
Expand All @@ -15,7 +15,7 @@
%
% Author: Seppo Ingalsuo <[email protected]>

function bf = bf_array_line(bf)
function bf = sof_bf_array_line(bf)

bf.mic_y = linspace(0, -(bf.mic_n-1) * bf.mic_d, bf.mic_n) ...
+ (bf.mic_n-1) * bf.mic_d / 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% bf = bf_array_lshape(bf)
% bf = sof_bf_array_lshape(bf)
%
% Inputs
% bf.mic_nxy ... vector of two with number of microphones along x and y
Expand All @@ -15,7 +15,7 @@
%
% Author: Seppo Ingalsuo <[email protected]>

function bf = bf_array_lshape(bf)
function bf = sof_bf_array_lshape(bf)

bf.mic_x = [];
bf.mic_y = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% bf = bf_array_rect(bf)
% bf = sof_bf_array_rect(bf)
%
% Inputs
% bf.mic_nxy ... vector of two with number of microphones along x and y
Expand All @@ -15,7 +15,7 @@
%
% Author: Seppo Ingalsuo <[email protected]>

function bf = bf_array_rect(bf)
function bf = sof_bf_array_rect(bf)

bf.mic_x = [];
bf.mic_y = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% bf = bf_array_rot(bf)
% bf = sof_bf_array_rot(bf)
%
% Inputs
% bf.array_angle ... three element vector for x, y, z rotation [degrees]
Expand All @@ -17,7 +17,7 @@
%
% Author: Seppo Ingalsuo <[email protected]>

function bf = bf_array_rot(bf)
function bf = sof_bf_array_rot(bf)

% Equations reference
% https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% bf = bf_array_xyz(bf)
% bf = sof_bf_array_xyz(bf)
%
% Inputs
% bf.mic_x ... x coordinates [m]
Expand All @@ -17,7 +17,7 @@
%
% Author: Seppo Ingalsuo <[email protected]>

function bf = bf_array_xyz(bf)
function bf = sof_bf_array_xyz(bf)

bf.mic_n = length(bf.mic_x);
bf.mic_x = bf.mic_x - mean(bf.mic_x);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function blob8 = bf_blob_pack(bf, ipc_version)
function blob8 = sof_bf_blob_pack(bf, ipc_version)

%% Pack TDFB struct to bytes
%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function bf = bf_defaults()
function bf = sof_bf_defaults()

% Recording array general setup
bf.taylorwin_sidelobe = -30;
Expand All @@ -19,10 +19,11 @@
bf.array_angle = [0 0 0]; % Array rotation angles for xyz
bf.tplg_fn = '';
bf.sofctl_fn = '';
bf.tplg1_path = '../../topology/topology1/m4/tdfb';
bf.tplg2_path = '../../topology/topology2/include/components/tdfb';
bf.sofctl3_path = '../../ctl/ipc3/tdfb';
bf.sofctl4_path = '../../ctl/ipc4/tdfb';
sof_tools = '../../../../tools';
bf.tplg1_path = fullfile(sof_tools, 'topology/topology1/m4/tdfb');
bf.tplg2_path = fullfile(sof_tools, 'topology/topology2/include/components/tdfb');
bf.sofctl3_path = fullfile(sof_tools, 'ctl/ipc3/tdfb');
bf.sofctl4_path = fullfile(sof_tools, 'ctl/ipc4/tdfb');
bf.data_path = './data';
bf.endian = 'little';
bf.fn = 1;
Expand Down
21 changes: 10 additions & 11 deletions tools/tune/tdfb/bf_design.m → src/audio/tdfb/tune/sof_bf_design.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% bf = bf_design(bf)
% bf = sof_bf_design(bf)
%
% This script calculates beamformer filters with superdirective design
% criteria.
Expand All @@ -9,10 +9,9 @@
%
% Author: Seppo Ingalsuo <[email protected]>

function bf = bf_design(bf)
function bf = sof_bf_design(bf)

addpath('../../test/audio/test_utils');
addpath('../../test/audio/std_utils');
sof_bf_paths(true);
mkdir_check('plots');
mkdir_check('data');

Expand All @@ -30,15 +29,15 @@

switch lower(bf.array)
case 'line'
bf = bf_array_line(bf);
bf = sof_bf_array_line(bf);
case 'circular'
bf = bf_array_circ(bf);
bf = sof_bf_array_circ(bf);
case 'rectangle'
bf = bf_array_rect(bf);
bf = sof_bf_array_rect(bf);
case 'lshape'
bf = bf_array_lshape(bf);
bf = sof_bf_array_lshape(bf);
case 'xyz'
bf = bf_array_xyz(bf);
bf = sof_bf_array_xyz(bf);
otherwise
error('Invalid array type')
end
Expand All @@ -51,7 +50,7 @@
end
end

bf = bf_array_rot(bf);
bf = sof_bf_array_rot(bf);

% The design function handles only single (az, el) value, so need to
% loop every steer angle.
Expand Down Expand Up @@ -88,11 +87,11 @@
bf.mat_fn = all_mat_fn;
bf.w = w_all;

sof_bf_paths(false);
end

function bf = bf_one_design(bf)


%% Defaults
j = complex(0,-1);
fs = bf.fs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% bf_export(bf)
% sof_bf_export(bf)
%
% Inputs
% bf.sofctl3_fn .... filename of ascii text format blob
Expand All @@ -13,12 +13,10 @@
%
% Author: Seppo Ingalsuo <[email protected]>

function bf = bf_export(bf)
function bf = sof_bf_export(bf)

% Use functionc from common, test utils
addpath('../common');
addpath('../eq');
addpath('../../test/audio/test_utils');
% Use functions from common, test utils
sof_bf_paths(true);

%% Add needed default controls if missing

Expand Down Expand Up @@ -60,24 +58,24 @@
for j=1:bf.num_angles
for i=1:bf.num_filters
coefs = squeeze(bf.w(:,i,j));
bq = eq_fir_blob_quant(coefs, 16, 0);
bq = sof_eq_fir_blob_quant(coefs, 16, 0);
filters = [filters bq ];
end
end

%% Add beam-off preset
if bf.beam_off_defined
b_pass = [1];
bq = eq_fir_blob_quant(b_pass, 16, 0);
bq = sof_eq_fir_blob_quant(b_pass, 16, 0);
for i=1:bf.num_filters
filters = [filters bq ];
end
end

%% Build blob
bf.all_filters = filters;
bp3 = bf_blob_pack(bf, 3);
bp4 = bf_blob_pack(bf, 4);
bp3 = sof_bf_blob_pack(bf, 3);
bp4 = sof_bf_blob_pack(bf, 4);

%% Export
if isempty(bf.sofctl3_fn)
Expand Down Expand Up @@ -118,8 +116,6 @@
tplg2_write(bf.tplg2_fn, bp4, "tdfb_config", export_note, bf.export_howto);
end

rmpath('../../test/audio/test_utils');
rmpath('../eq');
rmpath('../common');
sof_bf_paths(false);

end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% bf = bf_filenames_helper(bf, id)
% bf = sof_bf_filenames_helper(bf, id)
%
% Automatically defines output files names based on array geometry
% and steer angle.
Expand All @@ -9,7 +9,7 @@
%
% Author: Seppo Ingalsuo <[email protected]>

function bf = bf_filenames_helper(bf, id)
function bf = sof_bf_filenames_helper(bf, id)

switch lower(bf.array)
case {'rectangle' 'lshape'}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
% bfm = bf_merge(bf1, bf2)
% bfm = sof_bf_merge(bf1, bf2)

% SPDX-License-Identifier: BSD-3-Clause
%
% Copyright (c) 2020, Intel Corporation. All rights reserved.
%
% Author: Seppo Ingalsuo <[email protected]>

function bfm = bf_merge(bf1, bf2)
function bfm = sof_bf_merge(bf1, bf2)

if nargin > 2
error('Current implementation can merge only two beams configuration');
Expand Down
29 changes: 29 additions & 0 deletions src/audio/tdfb/tune/sof_bf_paths.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function sof_bf_paths(enable)

% sof_bf_paths(enable)
% enable - set to true to enable needed search path
% set to false to disable the search paths
%

% SPDX-License-Identifier: BSD-3-Clause
%
% Copyright (c) 2024, Intel Corporation.

sof_tools = '../../../../tools';
sof_modules = '../..';
common = fullfile(sof_tools, 'tune/common');
eq = fullfile(sof_modules, 'eq_iir/tune');
test_utils = fullfile(sof_tools, 'test/audio/test_utils');
std_utils = fullfile(sof_tools, 'test/audio/std_utils');
if enable
addpath(common);
addpath(eq);
addpath(test_utils);
addpath(std_utils);
else
rmpath(common);
rmpath(eq);
rmpath(test_utils);
rmpath(std_utils);
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

set -e

CONFIG_LIST=( example_pass_config example_line_array
example_line_0mm36mm146mm182mm example_circular_array example_two_beams )
CONFIG_LIST=( sof_example_pass_config sof_example_line_array
sof_example_line_0mm36mm146mm182mm sof_example_circular_array sof_example_two_beams )
OCTAVE_CMD=( octave --no-window-system )
MATLAB_CMD=( matlab -nodisplay -batch )

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function example_circular_array()
function sof_example_circular_array()

% example_circular_array()
%
Expand Down Expand Up @@ -27,7 +27,7 @@ function example_circular_array()
function circular_one_beam(fs, r, n, fir_length, az);

% Get defaults
bf = bf_defaults();
bf = sof_bf_defaults();
bf.input_channel_select = 0:(n-1); % Input all n channels to filters
bf.output_channel_mix_beam_off = zeros(1, n); % For some stereo symmetry
bf.output_channel_mix_beam_off(2) = 1; % Mic2 to channel 2^0
Expand All @@ -47,9 +47,9 @@ function example_circular_array()
bf.fir_length = fir_length;

% Design
bf = bf_filenames_helper(bf);
bf = bf_design(bf);
bf.export_note = 'Created with script example_circular_array.m';
bf.export_howto = 'cd tools/tune/tdfb; octave --no-window-system example_circular_array.m';
bf_export(bf);
bf = sof_bf_filenames_helper(bf);
bf = sof_bf_design(bf);
bf.export_note = 'Created with script sof_example_circular_array.m';
bf.export_howto = 'cd tools/tune/tdfb; octave --no-window-system sof_example_circular_array.m';
sof_bf_export(bf);
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function example_line_0mm36mm146mm182mm()
function sof_example_line_0mm36mm146mm182mm()

% Creates beamformer for device with device with microphones
% at 0, 36, 146, 182mm locations
Expand All @@ -23,7 +23,7 @@ function line_xyz(fs, fir_length, az)

% Get defaults
close all;
bf = bf_defaults();
bf = sof_bf_defaults();
bf.fs = fs;
bf.beta = 5;

Expand All @@ -50,12 +50,12 @@ function line_xyz(fs, fir_length, az)

%bf.sofctl_fn = fullfile(bf.sofctl_path, sofctl_fn);
%bf.tplg_fn = fullfile(bf.tplg_path, tplg_fn);
bf = bf_filenames_helper(bf, 'line4_0mm36mm146mm182mm');
bf = bf_design(bf);
bf = sof_bf_filenames_helper(bf, 'line4_0mm36mm146mm182mm');
bf = sof_bf_design(bf);

% Export files for topology and sof-ctl
bf.export_note = 'Created with script example_line_0mm36mm146mm182mm.m';
bf.export_howto = 'cd tools/tune/tdfb; octave --no-window-system example_line_0mm36mm146mm182mm.m';
bf_export(bf);
sof_bf_export(bf);

end
Loading

0 comments on commit 166453b

Please sign in to comment.