From 6eae20d35bed94176b6f5ea44f0aa090de79c064 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 20 Dec 2024 11:37:59 +0200 Subject: [PATCH 1/2] Audio: TDFB: Tune: Make setup blobs build quicker 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 --- src/audio/tdfb/tune/sof_bf_defaults.m | 3 +- src/audio/tdfb/tune/sof_bf_design.m | 119 +++++++++++++------------ src/audio/tdfb/tune/sof_example_all.sh | 10 +-- 3 files changed, 67 insertions(+), 65 deletions(-) diff --git a/src/audio/tdfb/tune/sof_bf_defaults.m b/src/audio/tdfb/tune/sof_bf_defaults.m index 6e530c52d065..cf8e8838ed32 100644 --- a/src/audio/tdfb/tune/sof_bf_defaults.m +++ b/src/audio/tdfb/tune/sof_bf_defaults.m @@ -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 = ''; @@ -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; diff --git a/src/audio/tdfb/tune/sof_bf_design.m b/src/audio/tdfb/tune/sof_bf_design.m index 010e48b2c94d..5121ebe6630f 100644 --- a/src/audio/tdfb/tune/sof_bf_design.m +++ b/src/audio/tdfb/tune/sof_bf_design.m @@ -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'); diff --git a/src/audio/tdfb/tune/sof_example_all.sh b/src/audio/tdfb/tune/sof_example_all.sh index 2a7b45b3833c..2a263f3438f5 100755 --- a/src/audio/tdfb/tune/sof_example_all.sh +++ b/src/audio/tdfb/tune/sof_example_all.sh @@ -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 From d23216e1dc47052e8b06036fd6b387c60a3165ec Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 20 Dec 2024 12:23:18 +0200 Subject: [PATCH 2/2] Scripts: Add script to rebuild all configuration blobs for processing This patch adds script sof-rebuild-processing-comp-blobs.sh. It rebuilds all the blobs for topology embedding, for sof-ctl, and for ucm2 cset-tlv. Signed-off-by: Seppo Ingalsuo --- scripts/sof-rebuild-processing-comp-blobs.sh | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 scripts/sof-rebuild-processing-comp-blobs.sh diff --git a/scripts/sof-rebuild-processing-comp-blobs.sh b/scripts/sof-rebuild-processing-comp-blobs.sh new file mode 100755 index 000000000000..26410c811259 --- /dev/null +++ b/scripts/sof-rebuild-processing-comp-blobs.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Intel Corporation. + +set -e + +if [ -z "${SOF_WORKSPACE}" ]; then + echo "Error: environment variable SOF_WORKSPACE need to be set to top level sof directory" + exit 1 +fi + +if ! command -v octave &> /dev/null; then + echo "Error: this scrip needs GNU Octave, see https://octave.org/" + exit 1 +fi + +OCTAVE="octave --quiet --no-window-system" +cd "$SOF_WORKSPACE"/sof/src/audio/aria/tune; $OCTAVE sof_aria_blobs.m +cd "$SOF_WORKSPACE"/sof/src/audio/crossover/tune; $OCTAVE sof_example_crossover.m +cd "$SOF_WORKSPACE"/sof/src/audio/dcblock/tune; $OCTAVE sof_example_dcblock.m +cd "$SOF_WORKSPACE"/sof/src/audio/drc/tune; $OCTAVE sof_example_drc.m +cd "$SOF_WORKSPACE"/sof/src/audio/eq_iir/tune; $OCTAVE sof_example_iir_eq.m +cd "$SOF_WORKSPACE"/sof/src/audio/eq_iir/tune; $OCTAVE sof_example_fir_eq.m +cd "$SOF_WORKSPACE"/sof/src/audio/eq_iir/tune; $OCTAVE sof_example_iir_bandsplit.m +cd "$SOF_WORKSPACE"/sof/src/audio/eq_iir/tune; $OCTAVE sof_example_spk_eq.m +cd "$SOF_WORKSPACE"/sof/src/audio/multiband_drc/tune; $OCTAVE sof_example_multiband_drc.m +cd "$SOF_WORKSPACE"/sof/src/audio/tdfb/tune; ./sof_example_all.sh +cd "$SOF_WORKSPACE"/sof/tools/tune/mfcc; $OCTAVE setup_mfcc.m