Chris@69
|
1 /* Copyright (c) 2008-2011 Xiph.Org Foundation
|
Chris@69
|
2 Written by Jean-Marc Valin */
|
Chris@69
|
3 /*
|
Chris@69
|
4 Redistribution and use in source and binary forms, with or without
|
Chris@69
|
5 modification, are permitted provided that the following conditions
|
Chris@69
|
6 are met:
|
Chris@69
|
7
|
Chris@69
|
8 - Redistributions of source code must retain the above copyright
|
Chris@69
|
9 notice, this list of conditions and the following disclaimer.
|
Chris@69
|
10
|
Chris@69
|
11 - Redistributions in binary form must reproduce the above copyright
|
Chris@69
|
12 notice, this list of conditions and the following disclaimer in the
|
Chris@69
|
13 documentation and/or other materials provided with the distribution.
|
Chris@69
|
14
|
Chris@69
|
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
Chris@69
|
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
Chris@69
|
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
Chris@69
|
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
Chris@69
|
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
Chris@69
|
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
Chris@69
|
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
Chris@69
|
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
Chris@69
|
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
Chris@69
|
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
Chris@69
|
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Chris@69
|
26 */
|
Chris@69
|
27
|
Chris@69
|
28 #ifdef HAVE_CONFIG_H
|
Chris@69
|
29 #include "config.h"
|
Chris@69
|
30 #endif
|
Chris@69
|
31
|
Chris@69
|
32 #ifndef CUSTOM_MODES
|
Chris@69
|
33 #define CUSTOM_MODES
|
Chris@69
|
34 #endif
|
Chris@69
|
35
|
Chris@69
|
36 #include <stdio.h>
|
Chris@69
|
37 #include <stdlib.h>
|
Chris@69
|
38 #include "vq.h"
|
Chris@69
|
39 #include "bands.h"
|
Chris@69
|
40 #include "stack_alloc.h"
|
Chris@69
|
41 #include <math.h>
|
Chris@69
|
42
|
Chris@69
|
43
|
Chris@69
|
44 #define MAX_SIZE 100
|
Chris@69
|
45
|
Chris@69
|
46 int ret=0;
|
Chris@69
|
47 void test_rotation(int N, int K)
|
Chris@69
|
48 {
|
Chris@69
|
49 int i;
|
Chris@69
|
50 double err = 0, ener = 0, snr, snr0;
|
Chris@69
|
51 opus_val16 x0[MAX_SIZE];
|
Chris@69
|
52 opus_val16 x1[MAX_SIZE];
|
Chris@69
|
53 for (i=0;i<N;i++)
|
Chris@69
|
54 x1[i] = x0[i] = rand()%32767-16384;
|
Chris@69
|
55 exp_rotation(x1, N, 1, 1, K, SPREAD_NORMAL);
|
Chris@69
|
56 for (i=0;i<N;i++)
|
Chris@69
|
57 {
|
Chris@69
|
58 err += (x0[i]-(double)x1[i])*(x0[i]-(double)x1[i]);
|
Chris@69
|
59 ener += x0[i]*(double)x0[i];
|
Chris@69
|
60 }
|
Chris@69
|
61 snr0 = 20*log10(ener/err);
|
Chris@69
|
62 err = ener = 0;
|
Chris@69
|
63 exp_rotation(x1, N, -1, 1, K, SPREAD_NORMAL);
|
Chris@69
|
64 for (i=0;i<N;i++)
|
Chris@69
|
65 {
|
Chris@69
|
66 err += (x0[i]-(double)x1[i])*(x0[i]-(double)x1[i]);
|
Chris@69
|
67 ener += x0[i]*(double)x0[i];
|
Chris@69
|
68 }
|
Chris@69
|
69 snr = 20*log10(ener/err);
|
Chris@69
|
70 printf ("SNR for size %d (%d pulses) is %f (was %f without inverse)\n", N, K, snr, snr0);
|
Chris@69
|
71 if (snr < 60 || snr0 > 20)
|
Chris@69
|
72 {
|
Chris@69
|
73 fprintf(stderr, "FAIL!\n");
|
Chris@69
|
74 ret = 1;
|
Chris@69
|
75 }
|
Chris@69
|
76 }
|
Chris@69
|
77
|
Chris@69
|
78 int main(void)
|
Chris@69
|
79 {
|
Chris@69
|
80 ALLOC_STACK;
|
Chris@69
|
81 test_rotation(15, 3);
|
Chris@69
|
82 test_rotation(23, 5);
|
Chris@69
|
83 test_rotation(50, 3);
|
Chris@69
|
84 test_rotation(80, 1);
|
Chris@69
|
85 return ret;
|
Chris@69
|
86 }
|