1% ref_auditory - Generate C header files for auditory library unit tests
2
3% SPDX-License-Identifier: BSD-3-Clause
4%
5% Copyright(c) 2022 Intel Corporation. All rights reserved.
6
7function ref_dct()
8
9	path(path(), '../../../m');
10	opt.describe = export_get_git_describe();
11
12	%% Test 1,
13	opt.test_n = 1;
14	opt.num_in = 23;
15	opt.num_out = 13;
16	opt.type = 'DCT_II';
17	opt.ortho = 'true';
18	opt.bits = 16;
19	get_ref_dct_matrix(opt);
20
21	%% Test 2,
22	opt.test_n = 2;
23	opt.num_in = 42;
24	opt.num_out = 42;
25	opt.type = 'DCT_II';
26	opt.ortho = 'true';
27	opt.bits = 16;
28	get_ref_dct_matrix(opt);
29
30end
31
32function get_ref_dct_matrix(opt)
33
34	header_fn = sprintf('ref_dct_matrix_%d_test%d.h', opt.bits, opt.test_n);
35
36	% TODO: type and ortho parameters are not supported
37	dct_matrix = mfcc_get_dct_matrix(opt.num_out, opt.num_in, 2);
38
39	switch opt.bits
40		case 16
41			qdm = export_quant_qxy(dct_matrix, 16, 15, false); % Q1.15
42		case 32
43			qdm = export_quant_qxy(dct_matrix, 32, 31, false); % Q1.31
44		otherwise
45			error('Illegal bits value');
46	end
47
48	define_prefix = sprintf('DCT_MATRIX_%d_TEST%d_', opt.bits, opt.test_n);
49	vector_prefix = sprintf('dct_matrix_%d_test%d_', opt.bits, opt.test_n);
50
51	fh = export_headerfile_open(header_fn);
52	comment = sprintf('Created %s with script ref_matrix.m %s', ...
53			  datestr(now, 0), opt.describe);
54	export_comment(fh, comment);
55	export_ndefine(fh, [define_prefix 'NUM_IN'], opt.num_in);
56	export_ndefine(fh, [define_prefix 'NUM_OUT'], opt.num_out);
57	export_sdefine(fh, [define_prefix 'TYPE'], opt.type);
58	export_sdefine(fh, [define_prefix 'ORTHO'], opt.ortho);
59	export_vector(fh, opt.bits, [vector_prefix 'matrix'], mat_to_vec(qdm));
60	fclose(fh);
61	fprintf(1, 'Exported %s.\n', header_fn);
62
63end
64
65function v = mat_to_vec(m)
66	v = reshape(transpose(m), prod(size(m)), 1);
67end
68