Skip to content
This repository was archived by the owner on Jan 17, 2019. It is now read-only.

Commit 1abae16

Browse files
committed
SOFT: Add various utility scripts for audio component tests
This patch provides the non-standard based utilities to help to execute the tests. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent a852b53 commit 1abae16

13 files changed

Lines changed: 918 additions & 0 deletions
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
function test = chirp_test_analyze(test)
2+
3+
%%
4+
% Copyright (c) 2017, Intel Corporation
5+
% All rights reserved.
6+
%
7+
% Redistribution and use in source and binary forms, with or without
8+
% modification, are permitted provided that the following conditions are met:
9+
% * Redistributions of source code must retain the above copyright
10+
% notice, this list of conditions and the following disclaimer.
11+
% * Redistributions in binary form must reproduce the above copyright
12+
% notice, this list of conditions and the following disclaimer in the
13+
% documentation and/or other materials provided with the distribution.
14+
% * Neither the name of the Intel Corporation nor the
15+
% names of its contributors may be used to endorse or promote products
16+
% derived from this software without specific prior written permission.
17+
%
18+
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22+
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
% POSSIBILITY OF SUCH DAMAGE.
29+
%
30+
% Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
31+
%
32+
33+
%% Load output file
34+
[x, nx] = load_test_output(test);
35+
if nx < 1
36+
test.fail = -1; % No data
37+
return;
38+
end
39+
40+
%% Find sync
41+
[d, nt, nt_use, nt_skip] = find_test_signal(x, test);
42+
43+
%% Trim sample
44+
i1 = d+nt_skip;
45+
i2 = i1+nt_use-1;
46+
z = x(i1:i2, :);
47+
y = z(:,test.ch);
48+
s = sum(z,2);
49+
50+
%% Quick check length, RMS, offset, and channels sum
51+
sz = size(z);
52+
tz = sz(1)/test.fs;
53+
et = abs(test.cl-tz)/test.cl;
54+
rms_db = 10*log10(mean(z.^2)) + 20*log10(sqrt(2));
55+
offs_db = 20*log10(abs(mean(z)));
56+
sum_max_db = 20*log10(max(abs(s)));
57+
% Check for proper ratio of out/in samples, minimum level, maximum offset
58+
% and maximum of sum of channels. The input is such that the channels should
59+
% sum to zero. A phase difference in channels would cause non-zero output
60+
% for channels sum. Dithered input causes a small non-zero sum value.
61+
62+
if et > 0.05
63+
fail = 1;
64+
fprintf('Failed output chirp length, err=%f, t=%f.\n', et, tz);
65+
else if (min(rms_db) < -3) && (test.fs2 + 1 > test.fs1)
66+
fail = 1;
67+
fprintf('Failed output chirp level.\n');
68+
else if max(offs_db) > -40
69+
fail = 1;
70+
fprintf('Failed output chirp DC offset.\n');
71+
else if (sum_max_db > -100) && (mod(test.nch, 2) == 0)
72+
fail = 1;
73+
fprintf('Failed output chirp channels phase.\n');
74+
else
75+
fail = 0;
76+
end
77+
end
78+
end
79+
end
80+
81+
test.fh = figure('visible', test.visible);
82+
ns = 1024;
83+
no = round(0.9*ns);
84+
specgram(y(:,1), ns, test.fs, kaiser(ns,27), no);
85+
colormap('jet');
86+
caxis([-150 0]);
87+
colorbar('EastOutside');
88+
89+
test.fail = fail;
90+
91+
end

test/test_utils/chirp_test_input.m

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
function test = chirp_test_input(test)
2+
3+
%% t = dr_test_input(t)
4+
%
5+
% Create tone data file for playback & record on real device or
6+
% for algorithm simulation.
7+
%
8+
% Input parameters
9+
% t.fs - sample rate
10+
% t.bits_in - signal word length
11+
% t.ch - mix test signal to channel ch
12+
% t.nch - total number of channels in data
13+
%
14+
% Output parameters
15+
% t.fn_in - created input file name
16+
% t.fn_out - proposed output file name for captured output
17+
% t.f - test signal frequency
18+
% t.tl - tone length in seconds
19+
% t.ts - tone start time
20+
% t.tr - tone gain ramp length in seconds
21+
% t.ti - ignore time from tone start and end, must be ti > tr
22+
% t.a - tone amplitude (lin)
23+
% t.a_db - tone amplitude (dB)
24+
% t.mark_t - length of marker tone in seconds
25+
% t.mark_a - amplitude max of marker tone (lin)
26+
% t.mark_a_db - amplitude max of marker tone (dB)
27+
%
28+
29+
%%
30+
% Copyright (c) 2016, Intel Corporation
31+
% All rights reserved.
32+
%
33+
% Redistribution and use in source and binary forms, with or without
34+
% modification, are permitted provided that the following conditions are met:
35+
% * Redistributions of source code must retain the above copyright
36+
% notice, this list of conditions and the following disclaimer.
37+
% * Redistributions in binary form must reproduce the above copyright
38+
% notice, this list of conditions and the following disclaimer in the
39+
% documentation and/or other materials provided with the distribution.
40+
% * Neither the name of the Intel Corporation nor the
41+
% names of its contributors may be used to endorse or promote products
42+
% derived from this software without specific prior written permission.
43+
%
44+
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45+
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46+
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47+
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
48+
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49+
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50+
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51+
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52+
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53+
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54+
% POSSIBILITY OF SUCH DAMAGE.
55+
%
56+
% Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
57+
%
58+
59+
if nargin < 1
60+
fprintf('Warning, using default parameters!\n');
61+
test.fs = 48e3; test.bits=32; test.ch=1; test.nch=1;
62+
end
63+
64+
if test.ch == 0
65+
test.ch = 1:test.nch; % Test all channels 1..Nch
66+
end
67+
68+
fprintf('Using parameters Fs=%.1f, bits_in=%d', test.fs/1e3, test.bits_in);
69+
fprintf(', ch=%d', test.ch );
70+
fprintf(', Nch=%d\n', test.nch );
71+
72+
test.fn_in = sprintf('chirp_test_in.%s', test.fmt);
73+
test.fn_out = sprintf('chirp_test_out.%s', test.fmt);
74+
75+
76+
%% Chirp parameters
77+
test.a_db = -0.1; % Near full scale
78+
test.a = 10^(test.a_db/20);
79+
test.f_min = 20;
80+
test.f_max = test.fs/2;
81+
test.cl = 2.0;
82+
83+
84+
%% Parameters to find signal between markers
85+
test.nf = 1;
86+
test.na = 1;
87+
test.sm = 3; % Seek start marker from 3s from start
88+
test.em = 3; % Seek end marker from 3s from end
89+
test.mt = 0.3; % Error if marker positions delta is greater than 0.3s
90+
test.is = 0; % Ignore signal from tone start
91+
test.ie = 0; % Ignore signal from tone end
92+
93+
%% Mix the input file for test and write output
94+
test = mix_chirp(test);
95+
96+
end

test/test_utils/delete_check.m

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
%%
2+
% Copyright (c) 2017, Intel Corporation
3+
% All rights reserved.
4+
%
5+
% Redistribution and use in source and binary forms, with or without
6+
% modification, are permitted provided that the following conditions are met:
7+
% * Redistributions of source code must retain the above copyright
8+
% notice, this list of conditions and the following disclaimer.
9+
% * Redistributions in binary form must reproduce the above copyright
10+
% notice, this list of conditions and the following disclaimer in the
11+
% documentation and/or other materials provided with the distribution.
12+
% * Neither the name of the Intel Corporation nor the
13+
% names of its contributors may be used to endorse or promote products
14+
% derived from this software without specific prior written permission.
15+
%
16+
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
% POSSIBILITY OF SUCH DAMAGE.
27+
%
28+
% Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
29+
%
30+
31+
function delete_check(really, f)
32+
if really && exist(f) == 2
33+
delete(f);
34+
end
35+
end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
%% xq = dither_and_quantize(x, bits)
2+
%
3+
% Input
4+
% x - input signal
5+
% bits - number of bits
6+
%
7+
% Output
8+
% (int32) xq - scaled, dithered and quantized signal
9+
%
10+
11+
%%
12+
% Copyright (c) 2016, Intel Corporation
13+
% All rights reserved.
14+
%
15+
% Redistribution and use in source and binary forms, with or without
16+
% modification, are permitted provided that the following conditions are met:
17+
% * Redistributions of source code must retain the above copyright
18+
% notice, this list of conditions and the following disclaimer.
19+
% * Redistributions in binary form must reproduce the above copyright
20+
% notice, this list of conditions and the following disclaimer in the
21+
% documentation and/or other materials provided with the distribution.
22+
% * Neither the name of the Intel Corporation nor the
23+
% names of its contributors may be used to endorse or promote products
24+
% derived from this software without specific prior written permission.
25+
%
26+
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27+
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29+
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30+
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31+
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32+
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33+
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34+
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35+
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36+
% POSSIBILITY OF SUCH DAMAGE.
37+
%
38+
% Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
39+
%
40+
41+
function xq = dither_and_quantize(x, bits)
42+
43+
if (bits > 32) || (bits < 1)
44+
error('This function supports max 32 bits quantization!');
45+
end
46+
47+
scale = 2^(bits-1);
48+
smax = scale-1;
49+
smin = -scale;
50+
sx = size(x);
51+
nx = sx(1);
52+
nch = sx(2);
53+
54+
xq = int32(floor( scale*x + randn(nx,nch) - randn(nx,nch) -0.5)); % TPDF dither
55+
%xq = int32(round( scale*x )); % Omit dither
56+
idx = find(xq > smax);
57+
xq(idx) = smax;
58+
idx = find(xq < smin);
59+
xq(idx) = smin;
60+
61+
end

test/test_utils/find_test_signal.m

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
function [d, nt, nt_use, nt_skip] = find_test_signal(x, test)
2+
3+
%%
4+
% Copyright (c) 2017, Intel Corporation
5+
% All rights reserved.
6+
%
7+
% Redistribution and use in source and binary forms, with or without
8+
% modification, are permitted provided that the following conditions are met:
9+
% * Redistributions of source code must retain the above copyright
10+
% notice, this list of conditions and the following disclaimer.
11+
% * Redistributions in binary form must reproduce the above copyright
12+
% notice, this list of conditions and the following disclaimer in the
13+
% documentation and/or other materials provided with the distribution.
14+
% * Neither the name of the Intel Corporation nor the
15+
% names of its contributors may be used to endorse or promote products
16+
% derived from this software without specific prior written permission.
17+
%
18+
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22+
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
% POSSIBILITY OF SUCH DAMAGE.
29+
%
30+
% Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
31+
%
32+
33+
%% Find start marker
34+
fprintf('Finding test start marker...\n');
35+
s = sync_chirp(test.fs, 'up');
36+
nx = length(x);
37+
n_half = round(nx/2);
38+
n = min(round(test.fs*test.sm), n_half);
39+
y = x(1:n);
40+
[r, lags] = xcorr(y, s);
41+
[r_max, idx] = max(r);
42+
d_start = lags(idx);
43+
44+
%% Find end marker
45+
fprintf('Finding test end marker...\n');
46+
s = sync_chirp(test.fs, 'down');
47+
n = min(round(test.fs*test.em),n_half);
48+
y = x(end-n+1:end);
49+
[r, lags] = xcorr(y, s);
50+
[r_max, idx] = max(r);
51+
d_end = nx-n+lags(idx);
52+
53+
%% Check correct length of signal
54+
len = d_end-d_start;
55+
len_s = len/test.fs;
56+
ref_s = test.mark_t+test.nf*test.na*test.tl;
57+
if abs(len_s-ref_s) > test.mt
58+
len_s
59+
ref_s
60+
error('Start and end markers were not found. Test play or capture quality may be poor');
61+
end
62+
63+
%% Delay to first tone, length of tone in samples
64+
d = d_start + round(test.mark_t*test.fs);
65+
if (d < 0)
66+
error('Invalid negative delay seen. Test play or capture quality may be poor');
67+
end
68+
nt = round(test.tl*test.fs);
69+
nt_use = nt -round(test.is*test.fs) -round(test.ie*test.fs);
70+
if nt_use < 0
71+
error('Test signal length parameters must be wrong!');
72+
end
73+
nt_skip = round(test.is*test.fs);
74+
75+
end

0 commit comments

Comments
 (0)