• 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 <assert.h>
9 #include <time.h>
10 #include <memory.h>
11 
12 #include "crossover.h"
13 #include "dsp_test_util.h"
14 #include "dsp_util.h"
15 #include "raw.h"
16 
17 #ifndef min
18 #define min(a, b)                                                              \
19 	({                                                                     \
20 		__typeof__(a) _a = (a);                                        \
21 		__typeof__(b) _b = (b);                                        \
22 		_a < _b ? _a : _b;                                             \
23 	})
24 #endif
25 
tp_diff(struct timespec * tp2,struct timespec * tp1)26 static double tp_diff(struct timespec *tp2, struct timespec *tp1)
27 {
28 	return (tp2->tv_sec - tp1->tv_sec) +
29 	       (tp2->tv_nsec - tp1->tv_nsec) * 1e-9;
30 }
31 
process(struct crossover * xo,int count,float * data0,float * data1,float * data2)32 void process(struct crossover *xo, int count, float *data0, float *data1,
33 	     float *data2)
34 {
35 	int start;
36 	for (start = 0; start < count; start += 2048)
37 		crossover_process(xo, min(2048, count - start), data0 + start,
38 				  data1 + start, data2 + start);
39 }
40 
main(int argc,char ** argv)41 int main(int argc, char **argv)
42 {
43 	size_t frames;
44 	float *data0, *data1, *data2;
45 	double NQ = 44100 / 2;
46 	struct timespec tp1, tp2;
47 	struct crossover xo;
48 
49 	if (argc != 3 && argc != 6) {
50 		printf("Usage: crossover_test input.raw output.raw "
51 		       "[low.raw mid.raw high.raw]\n");
52 		return 1;
53 	}
54 
55 	dsp_enable_flush_denormal_to_zero();
56 	dsp_util_clear_fp_exceptions();
57 
58 	data0 = read_raw(argv[1], &frames);
59 	data1 = (float *)malloc(sizeof(float) * frames * 2);
60 	data2 = (float *)malloc(sizeof(float) * frames * 2);
61 
62 	crossover_init(&xo, 400 / NQ, 4000 / NQ);
63 	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1);
64 	process(&xo, frames, data0, data1, data2);
65 	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2);
66 	printf("processing takes %g seconds for %zu samples\n",
67 	       tp_diff(&tp2, &tp1), frames);
68 
69 	crossover_init(&xo, 400 / NQ, 4000 / NQ);
70 	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1);
71 	process(&xo, frames, data0 + frames, data1 + frames, data2 + frames);
72 	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2);
73 	printf("processing takes %g seconds for %zu samples\n",
74 	       tp_diff(&tp2, &tp1), frames);
75 
76 	if (argc == 6) {
77 		write_raw(argv[3], data0, frames);
78 		write_raw(argv[4], data1, frames);
79 		write_raw(argv[5], data2, frames);
80 	}
81 
82 	int i;
83 	for (i = 0; i < frames * 2; i++)
84 		data0[i] += data1[i] + data2[i];
85 	write_raw(argv[2], data0, frames);
86 
87 	free(data0);
88 	free(data1);
89 	free(data2);
90 
91 	dsp_util_print_fp_exceptions();
92 	return 0;
93 }
94