• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <time.h>
9 
10 #include "dsp_test_util.h"
11 #include "dsp_util.h"
12 #include "dcblock.h"
13 #include "raw.h"
14 
15 #ifndef min
16 #define min(a, b) ({ __typeof__(a) _a = (a);	\
17 			__typeof__(b) _b = (b);	\
18 			_a < _b ? _a : _b; })
19 #endif
20 
tp_diff(struct timespec * tp2,struct timespec * tp1)21 static double tp_diff(struct timespec *tp2, struct timespec *tp1)
22 {
23 	return (tp2->tv_sec - tp1->tv_sec)
24 		+ (tp2->tv_nsec - tp1->tv_nsec) * 1e-9;
25 }
26 
27 /* Processes a buffer of data chunk by chunk using the filter */
process(struct dcblock * dcblock,float * data,int count)28 static void process(struct dcblock *dcblock, float *data, int count)
29 {
30 	int start;
31 	for (start = 0; start < count; start += 128)
32 		dcblock_process(dcblock,
33                                 data + start,
34                                 min(128, count - start));
35 }
36 
37 /* Runs the filters on an input file */
test_file(const char * input_filename,const char * output_filename)38 static void test_file(const char *input_filename, const char *output_filename)
39 {
40 	size_t frames;
41 	struct timespec tp1, tp2;
42 	struct dcblock *dcblockl;
43 	struct dcblock *dcblockr;
44 
45 	float *data = read_raw(input_filename, &frames);
46 
47 	dcblockl = dcblock_new(0.995);
48 	dcblockr = dcblock_new(0.995);
49 	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1);
50 	process(dcblockl, data, frames);
51 	process(dcblockr, data+frames, frames);
52 	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2);
53 	printf("processing takes %g seconds for %zu samples\n",
54 	       tp_diff(&tp2, &tp1), frames);
55 	dcblock_free(dcblockl);
56 	dcblock_free(dcblockr);
57 
58 	write_raw(output_filename, data, frames);
59 	free(data);
60 }
61 
main(int argc,char ** argv)62 int main(int argc, char **argv)
63 {
64 	dsp_enable_flush_denormal_to_zero();
65 	if (dsp_util_has_denormal())
66 		printf("denormal still supported?\n");
67 	else
68 		printf("denormal disabled\n");
69 	dsp_util_clear_fp_exceptions();
70 
71 	if (argc == 3)
72 		test_file(argv[1], argv[2]);
73 	else
74 		printf("Usage: dcblock_test input.raw output.raw\n");
75 
76 	dsp_util_print_fp_exceptions();
77 	return 0;
78 }
79