Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/dc_restore_tests.c @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 15:50:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * dc_restore_tests.c - Tests for the dc_restore functions. | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2001 Steve Underwood | |
9 * | |
10 * All rights reserved. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License version 2, as | |
14 * published by the Free Software Foundation. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 * $Id: dc_restore_tests.c,v 1.24 2008/11/30 12:38:27 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \page dc_restore_tests_page DC restoration tests | |
29 \section dc_restore_tests_page_sec_1 What does it do? | |
30 */ | |
31 | |
32 #if defined(HAVE_CONFIG_H) | |
33 #include "config.h" | |
34 #endif | |
35 | |
36 #include <stdlib.h> | |
37 #include <stdio.h> | |
38 #include <memory.h> | |
39 #include <time.h> | |
40 | |
41 //#if defined(WITH_SPANDSP_INTERNALS) | |
42 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES | |
43 //#endif | |
44 | |
45 #include "spandsp.h" | |
46 | |
47 int main (int argc, char *argv[]) | |
48 { | |
49 awgn_state_t noise_source; | |
50 dc_restore_state_t dc_state; | |
51 int i; | |
52 int idum = 1234567; | |
53 int16_t dirty; | |
54 int16_t clean; | |
55 int estimate; | |
56 int min; | |
57 int max; | |
58 int dc_offset; | |
59 | |
60 dc_offset = 5000; | |
61 awgn_init_dbm0(&noise_source, idum, -10.0); | |
62 dc_restore_init(&dc_state); | |
63 for (i = 0; i < 100000; i++) | |
64 { | |
65 dirty = awgn(&noise_source) + dc_offset; | |
66 clean = dc_restore(&dc_state, dirty); | |
67 if ((i % 1000) == 0) | |
68 { | |
69 printf("Sample %6d: %d (expect %d)\n", | |
70 i, | |
71 dc_restore_estimate(&dc_state), | |
72 dc_offset); | |
73 } | |
74 } | |
75 /* We should have settled by now. Look at the variation we get */ | |
76 min = 99999; | |
77 max = -99999; | |
78 for (i = 0; i < 100000; i++) | |
79 { | |
80 dirty = awgn(&noise_source) + dc_offset; | |
81 clean = dc_restore(&dc_state, dirty); | |
82 estimate = dc_restore_estimate(&dc_state); | |
83 if (estimate < min) | |
84 min = estimate; | |
85 if (estimate > max) | |
86 max = estimate; | |
87 } | |
88 printf("Spread of DC estimate for an offset of %d was %d to %d\n", dc_offset, min, max); | |
89 if (min < dc_offset - 50 || max > dc_offset + 50) | |
90 { | |
91 printf("Test failed.\n"); | |
92 exit(2); | |
93 } | |
94 printf("Test passed.\n"); | |
95 return 0; | |
96 } | |
97 /*- End of function --------------------------------------------------------*/ | |
98 /*- End of file ------------------------------------------------------------*/ |