• 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 "crossover2.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 crossover2 * xo2,int count,float * data0L,float * data0R,float * data1L,float * data1R,float * data2L,float * data2R)32 void process(struct crossover2 *xo2, int count, float *data0L, float *data0R,
33 	     float *data1L, float *data1R, float *data2L, float *data2R)
34 {
35 	int start;
36 	for (start = 0; start < count; start += 2048)
37 		crossover2_process(xo2, min(2048, count - start),
38 				   data0L + start, data0R + start,
39 				   data1L + start, data1R + start,
40 				   data2L + start, data2R + start);
41 }
42 
main(int argc,char ** argv)43 int main(int argc, char **argv)
44 {
45 	size_t frames;
46 	float *data0, *data1, *data2;
47 	double NQ = 44100 / 2;
48 	struct timespec tp1, tp2;
49 	struct crossover2 xo2;
50 
51 	if (argc != 3 && argc != 6) {
52 		printf("Usage: crossover2_test input.raw output.raw "
53 		       "[low.raw mid.raw high.raw]\n");
54 		return 1;
55 	}
56 
57 	dsp_enable_flush_denormal_to_zero();
58 	dsp_util_clear_fp_exceptions();
59 
60 	data0 = read_raw(argv[1], &frames);
61 	data1 = (float *)malloc(sizeof(float) * frames * 2);
62 	data2 = (float *)malloc(sizeof(float) * frames * 2);
63 
64 	crossover2_init(&xo2, 400 / NQ, 4000 / NQ);
65 	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1);
66 	process(&xo2, frames, data0, data0 + frames, data1, data1 + frames,
67 		data2, data2 + frames);
68 	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2);
69 	printf("processing takes %g seconds for %zu samples\n",
70 	       tp_diff(&tp2, &tp1), frames * 2);
71 
72 	if (argc == 6) {
73 		write_raw(argv[3], data0, frames);
74 		write_raw(argv[4], data1, frames);
75 		write_raw(argv[5], data2, frames);
76 	}
77 
78 	int i;
79 	for (i = 0; i < frames * 2; i++)
80 		data0[i] += data1[i] + data2[i];
81 	write_raw(argv[2], data0, frames);
82 
83 	free(data0);
84 	free(data1);
85 	free(data2);
86 
87 	dsp_util_print_fp_exceptions();
88 	return 0;
89 }
90