• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h"
41 #include "bands.h"
42 #include "stack_alloc.h"
43 #include <math.h>
44 
45 
46 #define MAX_SIZE 100
47 
48 int ret=0;
test_rotation(int N,int K)49 void test_rotation(int N, int K)
50 {
51    int i;
52    double err = 0, ener = 0, snr, snr0;
53    opus_val16 x0[MAX_SIZE];
54    opus_val16 x1[MAX_SIZE];
55    for (i=0;i<N;i++)
56       x1[i] = x0[i] = rand()%32767-16384;
57    exp_rotation(x1, N, 1, 1, K, SPREAD_NORMAL);
58    for (i=0;i<N;i++)
59    {
60       err += (x0[i]-(double)x1[i])*(x0[i]-(double)x1[i]);
61       ener += x0[i]*(double)x0[i];
62    }
63    snr0 = 20*log10(ener/err);
64    err = ener = 0;
65    exp_rotation(x1, N, -1, 1, K, SPREAD_NORMAL);
66    for (i=0;i<N;i++)
67    {
68       err += (x0[i]-(double)x1[i])*(x0[i]-(double)x1[i]);
69       ener += x0[i]*(double)x0[i];
70    }
71    snr = 20*log10(ener/err);
72    printf ("SNR for size %d (%d pulses) is %f (was %f without inverse)\n", N, K, snr, snr0);
73    if (snr < 60 || snr0 > 20)
74    {
75       fprintf(stderr, "FAIL!\n");
76       ret = 1;
77    }
78 }
79 
main(void)80 int main(void)
81 {
82    ALLOC_STACK;
83    test_rotation(15, 3);
84    test_rotation(23, 5);
85    test_rotation(50, 3);
86    test_rotation(80, 1);
87    return ret;
88 }
89