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