Tools: Tune: MFCC: Fix channels handling in audio feature plotter

In test topologies the MFCC data can be packed to 1, 2, or 4
channels stream. This change fixes the shown time scale for
audio features 3D plot.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
Seppo Ingalsuo 2024-08-20 18:59:14 +03:00 committed by Liam Girdwood
parent 5c84e5bbd4
commit b1c996b21b
1 changed files with 11 additions and 9 deletions

View File

@ -1,8 +1,9 @@
% [ceps, t, n] = decode_ceps(fn, num_ceps) % [ceps, t, n] = decode_ceps(fn, num_ceps, num_channels)
% %
% Input % Input
% fn - File with MFCC data in .raw or .wav format % fn - File with MFCC data in .raw or .wav format
% num_ceps - number of cepstral coefficients per frame % num_ceps - number of cepstral coefficients per frame
% num_channels - needed for .raw format, omit for .wav
% %
% Outputs % Outputs
% ceps - cepstral coefficients % ceps - cepstral coefficients
@ -12,10 +13,10 @@
% SPDX-License-Identifier: BSD-3-Clause % SPDX-License-Identifier: BSD-3-Clause
% Copyright(c) 2022 Intel Corporation. All rights reserved. % Copyright(c) 2022 Intel Corporation. All rights reserved.
function [ceps, t, n] = decode_ceps(fn, num_ceps, channels) function [ceps, t, n] = decode_ceps(fn, num_ceps, num_channels)
if nargin < 3 if nargin < 3
channels = 1; num_channels = 1;
end end
% MFCC stream % MFCC stream
@ -24,7 +25,7 @@ qformat = 7;
magic = [25443 28006]; % ASCII 'mfcc' as int16 magic = [25443 28006]; % ASCII 'mfcc' as int16
% Load output data % Load output data
data = get_file(fn); [data, num_channels] = get_file(fn, num_channels);
idx1 = find(data == magic(1)); idx1 = find(data == magic(1));
idx = []; idx = [];
@ -40,7 +41,7 @@ end
period_ceps = idx(2)-idx(1); period_ceps = idx(2)-idx(1);
num_frames = length(idx); num_frames = length(idx);
t_ceps = period_ceps / channels / fs; t_ceps = period_ceps / num_channels / fs;
t = (0:num_frames -1) * t_ceps; t = (0:num_frames -1) * t_ceps;
n = 1:num_ceps; n = 1:num_ceps;
@ -62,7 +63,7 @@ ylabel('Cepstral coef #');
end end
function data = get_file(fn) function [data, num_channels] = get_file(fn, num_channels)
[~, ~, ext] = fileparts(fn); [~, ~, ext] = fileparts(fn);
@ -78,10 +79,11 @@ switch lower(ext)
error('Only 16-bit wav file format is supported'); error('Only 16-bit wav file format is supported');
end end
s = size(tmp); s = size(tmp);
if s(2) > 1 num_channels = s(2);
if num_channels > 1
data = int16(zeros(prod(s), 1)); data = int16(zeros(prod(s), 1));
for i = 1:s(2) for i = 1:num_channels
data(i:s(2):end) = tmp(:, i); data(i:num_channels:end) = tmp(:, i);
end end
end end
otherwise otherwise