1function test = thdnf_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% SPDX-License-Identifier: BSD-3-Clause
30% Copyright(c) 2016 Intel Corporation. All rights reserved.
31% Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
32
33%% Reference: AES17 6.3.2 THD+N ratio vs frequency
34%  http://www.aes.org/publications/standards/
35
36if nargin < 1
37        fprintf('Warning, using default parameters!\n');
38        test.fs = 48e3; test.f_start=20; test.f_end=20e3; test.bits_in=32; test.ch=1; test.nch=1;
39end
40
41if test.ch == 0
42        test.ch = 1+round(rand(1,1)*(test.nch-1)); % Test random channel 1..Nch
43end
44
45for ch = test.ch
46    fprintf('Using parameters Fstart=%.0f Hz, Fend=%.0f Hz, Fs=%.1f Hz, bits_in=%d, ch=%d, Nch=%d\n', ...
47        test.f_start, test.f_end, test.fs/1e3, test.bits_in, ch, test.nch );
48end
49
50id = floor(rand(1,1) * 1e6);
51test.fn_in = sprintf('thdnf_test_in_%d.%s', id, test.fmt);
52test.fn_out = sprintf('thdnf_test_out_%d.%s', id, test.fmt);
53noct = ceil(log(test.f_end/test.f_start)/log(2)); % Max 1 octave steps
54test.f = logspace(log10(test.f_start),log10(test.f_end), noct+1);
55
56%% Tone sweep parameters
57test.is = 20e-3; % Ignore signal from tone start
58test.ie = 20e-3; % Ignore signal from tone end
59test.tr = 10e-3; % Gain ramp time for tones
60test.sm = 3; % Seek start marker from 3s from start
61test.em = 3; % Seek end marker from 3s from end
62test.mt = 0.1; % Error if marker positions delta is greater than 0.1s
63test.a_db = [-1 -20]; % -1 and -20 dBFS levels
64test.a = 10.^(test.a_db/20);
65test.tl = 4; % 3 seconds tone
66test.nst = 2; % Wait 1 seconds for frequency specific notch output to settle
67
68%% Mix the input file for test and write output
69test = mix_sweep(test);
70
71end
72