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) \
17 ({ \
18 __typeof__(a) _a = (a); \
19 __typeof__(b) _b = (b); \
20 _a < _b ? _a : _b; \
21 })
22 #endif
23
tp_diff(struct timespec * tp2,struct timespec * tp1)24 static double tp_diff(struct timespec *tp2, struct timespec *tp1)
25 {
26 return (tp2->tv_sec - tp1->tv_sec) +
27 (tp2->tv_nsec - tp1->tv_nsec) * 1e-9;
28 }
29
30 /* Processes a buffer of data chunk by chunk using the filter */
process(struct dcblock * dcblock,float * data,int count)31 static void process(struct dcblock *dcblock, float *data, int count)
32 {
33 int start;
34 for (start = 0; start < count; start += 128)
35 dcblock_process(dcblock, data + start, min(128, count - start));
36 }
37
38 /* Runs the filters on an input file */
test_file(const char * input_filename,const char * output_filename)39 static void test_file(const char *input_filename, const char *output_filename)
40 {
41 size_t frames;
42 struct timespec tp1, tp2;
43 struct dcblock *dcblockl;
44 struct dcblock *dcblockr;
45
46 float *data = read_raw(input_filename, &frames);
47
48 dcblockl = dcblock_new(0.995, 48000);
49 dcblockr = dcblock_new(0.995, 48000);
50 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp1);
51 process(dcblockl, data, frames);
52 process(dcblockr, data + frames, frames);
53 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp2);
54 printf("processing takes %g seconds for %zu samples\n",
55 tp_diff(&tp2, &tp1), frames);
56 dcblock_free(dcblockl);
57 dcblock_free(dcblockr);
58
59 write_raw(output_filename, data, frames);
60 free(data);
61 }
62
main(int argc,char ** argv)63 int main(int argc, char **argv)
64 {
65 dsp_enable_flush_denormal_to_zero();
66 if (dsp_util_has_denormal())
67 printf("denormal still supported?\n");
68 else
69 printf("denormal disabled\n");
70 dsp_util_clear_fp_exceptions();
71
72 if (argc == 3)
73 test_file(argv[1], argv[2]);
74 else
75 printf("Usage: dcblock_test input.raw output.raw\n");
76
77 dsp_util_print_fp_exceptions();
78 return 0;
79 }
80