Skip to content

Commit

Permalink
Audio: TDFB: Tune: Make setup blobs build quicker
Browse files Browse the repository at this point in the history
This change makes automatic blobs build quick enough to be
included to a batch build task. It speeds up the blobs create
from about one hour to about one minute.

The first preferred numerical computing tool is changed from
Matlab to Octave to enable build in typical build servers.

In bf_defaults.m the "do_plots" is changed to zero to skip creating
various plots. The create of various simulation data files for
the beamformer (used by tools/test/audio/tdfb_test.m) is disabled
with add of "create_simulation_data" set to false.

For beamformer development work, it is easy to switch the options
back on.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
  • Loading branch information
singalsu committed Dec 20, 2024
1 parent 3c4184b commit 6eae20d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 65 deletions.
3 changes: 2 additions & 1 deletion src/audio/tdfb/tune/sof_bf_defaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
bf.fir_length = 64; % 64 tap FIR filters
bf.kaiser_beta = 10; % Beta for kaiser window method FIR design
bf.mu_db = -40; % dB of diagonal loading to noise covariance matrix
bf.do_plots = 1;
bf.do_plots = 0;
bf.plot_box = 0.20; % Show 20cm wide plot cube for array geometry
bf.array_angle = [0 0 0]; % Array rotation angles for xyz
bf.tplg_fn = '';
Expand All @@ -29,6 +29,7 @@
bf.data_path = './data';
bf.endian = 'little';
bf.fn = 1;
bf.create_simulation_data = false;
bf.sinerot_a = 10^(-20/20);
bf.sinerot_f = 2e3;
bf.sinerot_t = 1.0;
Expand Down
119 changes: 60 additions & 59 deletions src/audio/tdfb/tune/sof_bf_design.m
Original file line number Diff line number Diff line change
Expand Up @@ -374,73 +374,74 @@
end

%% Create data for simulation 1s per angle
if bf.create_simulation_data
if isempty(bf.sinerot_fn)
fprintf(1, 'No file for 360 degree sine source rotate specified\n');
else
rotate_sound_source(bf, bf.sinerot_fn, 'sine');
end

if isempty(bf.sinerot_fn)
fprintf(1, 'No file for 360 degree sine source rotate specified\n');
else
rotate_sound_source(bf, bf.sinerot_fn, 'sine');
end

if isempty(bf.noiserot_fn)
fprintf(1, 'No file for 360 degree random noise source rotate specified\n');
else
rotate_sound_source(bf, bf.noiserot_fn, 'noise');
end
if isempty(bf.noiserot_fn)
fprintf(1, 'No file for 360 degree random noise source rotate specified\n');
else
rotate_sound_source(bf, bf.noiserot_fn, 'noise');
end


if isempty(bf.diffuse_fn)
fprintf(1, 'No file for diffuse noise field specified\n');
else
fprintf(1, 'Creating diffuse noise field...\n');
fsi = 384e3; % Target interpolated rate
p = round(fsi / bf.fs); % Interpolation factor
fsi = p * bf.fs; % Recalculate high rate
ti = 1/fsi; % period at higher rate
t_add = 10.0/bf.c; % Additional signal time for max 20m propagation
t0 = bf.diffuse_t + t_add; % Total sine length per angle
n0 = floor(bf.fs * t0);
nt = floor(bf.fs * bf.diffuse_t); % Number samples output per angle
nti = p * nt; % Number samples output per angle at high rate
el = 0;
for az_deg = -160:20:180 % Azimuth plane only noise with sources
az = az_deg * pi/180;
[nx, ny, nz] = source_xyz(bf.steer_r, az, el);
dt = delay_from_source(bf, nx, ny, nz);
dn = round(dt / ti);
ns = rand(n0, 1) + rand(n0, 1) - 1;
nsi = interp(ns, p);
nmi = zeros(nti, bf.mic_n);
for j = 1:bf.mic_n
nmi(:,j) = nmi(:,j) + nsi(end-dn(j)-nti+1:end-dn(j));
if isempty(bf.diffuse_fn)
fprintf(1, 'No file for diffuse noise field specified\n');
else
fprintf(1, 'Creating diffuse noise field...\n');
fsi = 384e3; % Target interpolated rate
p = round(fsi / bf.fs); % Interpolation factor
fsi = p * bf.fs; % Recalculate high rate
ti = 1/fsi; % period at higher rate
t_add = 10.0/bf.c; % Additional signal time for max 20m propagation
t0 = bf.diffuse_t + t_add; % Total sine length per angle
n0 = floor(bf.fs * t0);
nt = floor(bf.fs * bf.diffuse_t); % Number samples output per angle
nti = p * nt; % Number samples output per angle at high rate
el = 0;
for az_deg = -160:20:180 % Azimuth plane only noise with sources
az = az_deg * pi/180;
[nx, ny, nz] = source_xyz(bf.steer_r, az, el);
dt = delay_from_source(bf, nx, ny, nz);
dn = round(dt / ti);
ns = rand(n0, 1) + rand(n0, 1) - 1;
nsi = interp(ns, p);
nmi = zeros(nti, bf.mic_n);
for j = 1:bf.mic_n
nmi(:,j) = nmi(:,j) + nsi(end-dn(j)-nti+1:end-dn(j));
end
end
nm = nmi(1:p:end, :);
nlev = level_dbfs(nm(:,1));
nm = nm * 10^((bf.diffuse_lev - nlev)/20);
myaudiowrite(bf.diffuse_fn, nm, bf.fs);
end
nm = nmi(1:p:end, :);
nlev = level_dbfs(nm(:,1));
nm = nm * 10^((bf.diffuse_lev - nlev)/20);
myaudiowrite(bf.diffuse_fn, nm, bf.fs);
end

if isempty(bf.random_fn)
fprintf(1, 'No file for random noise specified\n');
else
fprintf(1, 'Creating random noise ...\n');
nt = bf.fs * bf.random_t;
rn = rand(nt, bf.num_filters) + rand(nt, bf.num_filters) - 1;
if isempty(bf.random_fn)
fprintf(1, 'No file for random noise specified\n');
else
fprintf(1, 'Creating random noise ...\n');
nt = bf.fs * bf.random_t;
rn = rand(nt, bf.num_filters) + rand(nt, bf.num_filters) - 1;

nlev = level_dbfs(rn(:,1));
rn = rn * 10^((bf.random_lev - nlev)/20);
myaudiowrite(bf.random_fn, rn, bf.fs);
end
nlev = level_dbfs(rn(:,1));
rn = rn * 10^((bf.random_lev - nlev)/20);
myaudiowrite(bf.random_fn, rn, bf.fs);
end

if isempty(bf.mat_fn)
fprintf(1, 'No file for beam pattern simulation data specified.\n');
else
fprintf(1, 'Saving design to %s\n', bf.mat_fn);
bf_copy = bf;
bf.fh = []; % Don't save the large figures, this avoids a warning print too
mkdir_check(bf.data_path);
save(bf.mat_fn, 'bf');
bf = bf_copy;
if isempty(bf.mat_fn)
fprintf(1, 'No file for beam pattern simulation data specified.\n');
else
fprintf(1, 'Saving design to %s\n', bf.mat_fn);
bf_copy = bf;
bf.fh = []; % Don't save the large figures, this avoids a warning print too
mkdir_check(bf.data_path);
save(bf.mat_fn, 'bf');
bf = bf_copy;
end
end

fprintf(1, 'Done.\n');
Expand Down
10 changes: 5 additions & 5 deletions src/audio/tdfb/tune/sof_example_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ OCTAVE_CMD=( octave --no-window-system )
MATLAB_CMD=( matlab -nodisplay -batch )

main () {
if command -v matlab &> /dev/null; then
echo "Using Matlab"
CMD=( "${MATLAB_CMD[@]}" )
EXT=
elif command -v octave &> /dev/null; then
if command -v octave &> /dev/null; then
echo "Using Octave"
CMD=( "${OCTAVE_CMD[@]}" )
EXT=".m"
elif command -v matlab &> /dev/null; then
echo "Using Matlab"
CMD=( "${MATLAB_CMD[@]}" )
EXT=
else
echo "Please install Matlab or Octave to run this script."
exit 1
Expand Down

0 comments on commit 6eae20d

Please sign in to comment.