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