diff options
Diffstat (limited to 'lib/rbcodec/codecs/libopus/celt/tests')
8 files changed, 1445 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libopus/celt/tests/test_unit_cwrs32.c b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_cwrs32.c new file mode 100644 index 0000000000..36dd8af5f5 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_cwrs32.c | |||
@@ -0,0 +1,161 @@ | |||
1 | /* Copyright (c) 2008-2011 Xiph.Org Foundation, Mozilla Corporation, | ||
2 | Gregory Maxwell | ||
3 | Written by Jean-Marc Valin, Gregory Maxwell, and Timothy B. Terriberry */ | ||
4 | /* | ||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions | ||
7 | are met: | ||
8 | |||
9 | - Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | - Redistributions in binary form must reproduce the above copyright | ||
13 | notice, this list of conditions and the following disclaimer in the | ||
14 | documentation and/or other materials provided with the distribution. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
17 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | ||
20 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | */ | ||
28 | |||
29 | #ifdef HAVE_CONFIG_H | ||
30 | #include "config.h" | ||
31 | #endif | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <string.h> | ||
35 | |||
36 | #ifndef CUSTOM_MODES | ||
37 | #define CUSTOM_MODES | ||
38 | #else | ||
39 | #define TEST_CUSTOM_MODES | ||
40 | #endif | ||
41 | |||
42 | #define CELT_C | ||
43 | #include "stack_alloc.h" | ||
44 | #include "entenc.c" | ||
45 | #include "entdec.c" | ||
46 | #include "entcode.c" | ||
47 | #include "cwrs.c" | ||
48 | #include "mathops.c" | ||
49 | #include "rate.h" | ||
50 | |||
51 | #define NMAX (240) | ||
52 | #define KMAX (128) | ||
53 | |||
54 | #ifdef TEST_CUSTOM_MODES | ||
55 | |||
56 | #define NDIMS (44) | ||
57 | static const int pn[NDIMS]={ | ||
58 | 2, 3, 4, 5, 6, 7, 8, 9, 10, | ||
59 | 11, 12, 13, 14, 15, 16, 18, 20, 22, | ||
60 | 24, 26, 28, 30, 32, 36, 40, 44, 48, | ||
61 | 52, 56, 60, 64, 72, 80, 88, 96, 104, | ||
62 | 112, 120, 128, 144, 160, 176, 192, 208 | ||
63 | }; | ||
64 | static const int pkmax[NDIMS]={ | ||
65 | 128, 128, 128, 128, 88, 52, 36, 26, 22, | ||
66 | 18, 16, 15, 13, 12, 12, 11, 10, 9, | ||
67 | 9, 8, 8, 7, 7, 7, 7, 6, 6, | ||
68 | 6, 6, 6, 5, 5, 5, 5, 5, 5, | ||
69 | 4, 4, 4, 4, 4, 4, 4, 4 | ||
70 | }; | ||
71 | |||
72 | #else /* TEST_CUSTOM_MODES */ | ||
73 | |||
74 | #define NDIMS (22) | ||
75 | static const int pn[NDIMS]={ | ||
76 | 2, 3, 4, 6, 8, 9, 11, 12, 16, | ||
77 | 18, 22, 24, 32, 36, 44, 48, 64, 72, | ||
78 | 88, 96, 144, 176 | ||
79 | }; | ||
80 | static const int pkmax[NDIMS]={ | ||
81 | 128, 128, 128, 88, 36, 26, 18, 16, 12, | ||
82 | 11, 9, 9, 7, 7, 6, 6, 5, 5, | ||
83 | 5, 5, 4, 4 | ||
84 | }; | ||
85 | |||
86 | #endif | ||
87 | |||
88 | int main(void){ | ||
89 | int t; | ||
90 | int n; | ||
91 | ALLOC_STACK; | ||
92 | for(t=0;t<NDIMS;t++){ | ||
93 | int pseudo; | ||
94 | n=pn[t]; | ||
95 | for(pseudo=1;pseudo<41;pseudo++) | ||
96 | { | ||
97 | int k; | ||
98 | #if defined(SMALL_FOOTPRINT) | ||
99 | opus_uint32 uu[KMAX+2U]; | ||
100 | #endif | ||
101 | opus_uint32 inc; | ||
102 | opus_uint32 nc; | ||
103 | opus_uint32 i; | ||
104 | k=get_pulses(pseudo); | ||
105 | if (k>pkmax[t])break; | ||
106 | printf("Testing CWRS with N=%i, K=%i...\n",n,k); | ||
107 | #if defined(SMALL_FOOTPRINT) | ||
108 | nc=ncwrs_urow(n,k,uu); | ||
109 | #else | ||
110 | nc=CELT_PVQ_V(n,k); | ||
111 | #endif | ||
112 | inc=nc/20000; | ||
113 | if(inc<1)inc=1; | ||
114 | for(i=0;i<nc;i+=inc){ | ||
115 | #if defined(SMALL_FOOTPRINT) | ||
116 | opus_uint32 u[KMAX+2U]; | ||
117 | #endif | ||
118 | int y[NMAX]; | ||
119 | int sy; | ||
120 | opus_uint32 v; | ||
121 | opus_uint32 ii; | ||
122 | int j; | ||
123 | #if defined(SMALL_FOOTPRINT) | ||
124 | memcpy(u,uu,(k+2U)*sizeof(*u)); | ||
125 | cwrsi(n,k,i,y,u); | ||
126 | #else | ||
127 | cwrsi(n,k,i,y); | ||
128 | #endif | ||
129 | sy=0; | ||
130 | for(j=0;j<n;j++)sy+=abs(y[j]); | ||
131 | if(sy!=k){ | ||
132 | fprintf(stderr,"N=%d Pulse count mismatch in cwrsi (%d!=%d).\n", | ||
133 | n,sy,k); | ||
134 | return 99; | ||
135 | } | ||
136 | /*printf("%6u of %u:",i,nc); | ||
137 | for(j=0;j<n;j++)printf(" %+3i",y[j]); | ||
138 | printf(" ->");*/ | ||
139 | #if defined(SMALL_FOOTPRINT) | ||
140 | ii=icwrs(n,k,&v,y,u); | ||
141 | #else | ||
142 | ii=icwrs(n,y); | ||
143 | v=CELT_PVQ_V(n,k); | ||
144 | #endif | ||
145 | if(ii!=i){ | ||
146 | fprintf(stderr,"Combination-index mismatch (%lu!=%lu).\n", | ||
147 | (long)ii,(long)i); | ||
148 | return 1; | ||
149 | } | ||
150 | if(v!=nc){ | ||
151 | fprintf(stderr,"Combination count mismatch (%lu!=%lu).\n", | ||
152 | (long)v,(long)nc); | ||
153 | return 2; | ||
154 | } | ||
155 | /*printf(" %6u\n",i);*/ | ||
156 | } | ||
157 | /*printf("\n");*/ | ||
158 | } | ||
159 | } | ||
160 | return 0; | ||
161 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/celt/tests/test_unit_dft.c b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_dft.c new file mode 100644 index 0000000000..70f8f4937b --- /dev/null +++ b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_dft.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /* Copyright (c) 2008 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 | #include <stdio.h> | ||
33 | |||
34 | #include "stack_alloc.h" | ||
35 | #include "kiss_fft.h" | ||
36 | #include "mathops.h" | ||
37 | #include "modes.h" | ||
38 | |||
39 | #ifndef M_PI | ||
40 | #define M_PI 3.141592653 | ||
41 | #endif | ||
42 | |||
43 | int ret = 0; | ||
44 | |||
45 | void check(kiss_fft_cpx * in,kiss_fft_cpx * out,int nfft,int isinverse) | ||
46 | { | ||
47 | int bin,k; | ||
48 | double errpow=0,sigpow=0, snr; | ||
49 | |||
50 | for (bin=0;bin<nfft;++bin) { | ||
51 | double ansr = 0; | ||
52 | double ansi = 0; | ||
53 | double difr; | ||
54 | double difi; | ||
55 | |||
56 | for (k=0;k<nfft;++k) { | ||
57 | double phase = -2*M_PI*bin*k/nfft; | ||
58 | double re = cos(phase); | ||
59 | double im = sin(phase); | ||
60 | if (isinverse) | ||
61 | im = -im; | ||
62 | |||
63 | if (!isinverse) | ||
64 | { | ||
65 | re /= nfft; | ||
66 | im /= nfft; | ||
67 | } | ||
68 | |||
69 | ansr += in[k].r * re - in[k].i * im; | ||
70 | ansi += in[k].r * im + in[k].i * re; | ||
71 | } | ||
72 | /*printf ("%d %d ", (int)ansr, (int)ansi);*/ | ||
73 | difr = ansr - out[bin].r; | ||
74 | difi = ansi - out[bin].i; | ||
75 | errpow += difr*difr + difi*difi; | ||
76 | sigpow += ansr*ansr+ansi*ansi; | ||
77 | } | ||
78 | snr = 10*log10(sigpow/errpow); | ||
79 | printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr ); | ||
80 | if (snr<60) { | ||
81 | printf( "** poor snr: %f ** \n", snr); | ||
82 | ret = 1; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void test1d(int nfft,int isinverse,int arch) | ||
87 | { | ||
88 | size_t buflen = sizeof(kiss_fft_cpx)*nfft; | ||
89 | kiss_fft_cpx *in; | ||
90 | kiss_fft_cpx *out; | ||
91 | int k; | ||
92 | #ifdef CUSTOM_MODES | ||
93 | kiss_fft_state *cfg = opus_fft_alloc(nfft,0,0,arch); | ||
94 | #else | ||
95 | int id; | ||
96 | const kiss_fft_state *cfg; | ||
97 | CELTMode *mode = opus_custom_mode_create(48000, 960, NULL); | ||
98 | if (nfft == 480) id = 0; | ||
99 | else if (nfft == 240) id = 1; | ||
100 | else if (nfft == 120) id = 2; | ||
101 | else if (nfft == 60) id = 3; | ||
102 | else return; | ||
103 | cfg = mode->mdct.kfft[id]; | ||
104 | #endif | ||
105 | |||
106 | in = (kiss_fft_cpx*)malloc(buflen); | ||
107 | out = (kiss_fft_cpx*)malloc(buflen); | ||
108 | |||
109 | for (k=0;k<nfft;++k) { | ||
110 | in[k].r = (rand() % 32767) - 16384; | ||
111 | in[k].i = (rand() % 32767) - 16384; | ||
112 | } | ||
113 | |||
114 | for (k=0;k<nfft;++k) { | ||
115 | in[k].r *= 32768; | ||
116 | in[k].i *= 32768; | ||
117 | } | ||
118 | |||
119 | if (isinverse) | ||
120 | { | ||
121 | for (k=0;k<nfft;++k) { | ||
122 | in[k].r /= nfft; | ||
123 | in[k].i /= nfft; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | /*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/ | ||
128 | |||
129 | if (isinverse) | ||
130 | opus_ifft(cfg,in,out, arch); | ||
131 | else | ||
132 | opus_fft(cfg,in,out, arch); | ||
133 | |||
134 | /*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/ | ||
135 | |||
136 | check(in,out,nfft,isinverse); | ||
137 | |||
138 | free(in); | ||
139 | free(out); | ||
140 | #ifdef CUSTOM_MODES | ||
141 | opus_fft_free(cfg, arch); | ||
142 | #endif | ||
143 | } | ||
144 | |||
145 | int main(int argc,char ** argv) | ||
146 | { | ||
147 | ALLOC_STACK; | ||
148 | int arch = opus_select_arch(); | ||
149 | |||
150 | if (argc>1) { | ||
151 | int k; | ||
152 | for (k=1;k<argc;++k) { | ||
153 | test1d(atoi(argv[k]),0,arch); | ||
154 | test1d(atoi(argv[k]),1,arch); | ||
155 | } | ||
156 | }else{ | ||
157 | test1d(32,0,arch); | ||
158 | test1d(32,1,arch); | ||
159 | test1d(128,0,arch); | ||
160 | test1d(128,1,arch); | ||
161 | test1d(256,0,arch); | ||
162 | test1d(256,1,arch); | ||
163 | #ifndef RADIX_TWO_ONLY | ||
164 | test1d(36,0,arch); | ||
165 | test1d(36,1,arch); | ||
166 | test1d(50,0,arch); | ||
167 | test1d(50,1,arch); | ||
168 | test1d(60,0,arch); | ||
169 | test1d(60,1,arch); | ||
170 | test1d(120,0,arch); | ||
171 | test1d(120,1,arch); | ||
172 | test1d(240,0,arch); | ||
173 | test1d(240,1,arch); | ||
174 | test1d(480,0,arch); | ||
175 | test1d(480,1,arch); | ||
176 | #endif | ||
177 | } | ||
178 | return ret; | ||
179 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/celt/tests/test_unit_entropy.c b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_entropy.c new file mode 100644 index 0000000000..7f674529df --- /dev/null +++ b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_entropy.c | |||
@@ -0,0 +1,383 @@ | |||
1 | /* Copyright (c) 2007-2011 Xiph.Org Foundation, Mozilla Corporation, | ||
2 | Gregory Maxwell | ||
3 | Written by Jean-Marc Valin, Gregory Maxwell, and Timothy B. Terriberry */ | ||
4 | /* | ||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions | ||
7 | are met: | ||
8 | |||
9 | - Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | - Redistributions in binary form must reproduce the above copyright | ||
13 | notice, this list of conditions and the following disclaimer in the | ||
14 | documentation and/or other materials provided with the distribution. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
17 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | ||
20 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | */ | ||
28 | |||
29 | #ifdef HAVE_CONFIG_H | ||
30 | #include "config.h" | ||
31 | #endif | ||
32 | |||
33 | #include <stdlib.h> | ||
34 | #include <stdio.h> | ||
35 | #include <math.h> | ||
36 | #include <time.h> | ||
37 | #define CELT_C | ||
38 | #include "entcode.h" | ||
39 | #include "entenc.h" | ||
40 | #include "entdec.h" | ||
41 | #include <string.h> | ||
42 | |||
43 | #include "entenc.c" | ||
44 | #include "entdec.c" | ||
45 | #include "entcode.c" | ||
46 | |||
47 | #ifndef M_LOG2E | ||
48 | # define M_LOG2E 1.4426950408889634074 | ||
49 | #endif | ||
50 | #define DATA_SIZE 10000000 | ||
51 | #define DATA_SIZE2 10000 | ||
52 | |||
53 | int main(int _argc,char **_argv){ | ||
54 | ec_enc enc; | ||
55 | ec_dec dec; | ||
56 | long nbits; | ||
57 | long nbits2; | ||
58 | double entropy; | ||
59 | int ft; | ||
60 | int ftb; | ||
61 | int sz; | ||
62 | int i; | ||
63 | int ret; | ||
64 | unsigned int sym; | ||
65 | unsigned int seed; | ||
66 | unsigned char *ptr; | ||
67 | const char *env_seed; | ||
68 | ret=0; | ||
69 | entropy=0; | ||
70 | if (_argc > 2) { | ||
71 | fprintf(stderr, "Usage: %s [<seed>]\n", _argv[0]); | ||
72 | return 1; | ||
73 | } | ||
74 | env_seed = getenv("SEED"); | ||
75 | if (_argc > 1) | ||
76 | seed = atoi(_argv[1]); | ||
77 | else if (env_seed) | ||
78 | seed = atoi(env_seed); | ||
79 | else | ||
80 | seed = time(NULL); | ||
81 | /*Testing encoding of raw bit values.*/ | ||
82 | ptr = (unsigned char *)malloc(DATA_SIZE); | ||
83 | ec_enc_init(&enc,ptr, DATA_SIZE); | ||
84 | for(ft=2;ft<1024;ft++){ | ||
85 | for(i=0;i<ft;i++){ | ||
86 | entropy+=log(ft)*M_LOG2E; | ||
87 | ec_enc_uint(&enc,i,ft); | ||
88 | } | ||
89 | } | ||
90 | /*Testing encoding of raw bit values.*/ | ||
91 | for(ftb=1;ftb<16;ftb++){ | ||
92 | for(i=0;i<(1<<ftb);i++){ | ||
93 | entropy+=ftb; | ||
94 | nbits=ec_tell(&enc); | ||
95 | ec_enc_bits(&enc,i,ftb); | ||
96 | nbits2=ec_tell(&enc); | ||
97 | if(nbits2-nbits!=ftb){ | ||
98 | fprintf(stderr,"Used %li bits to encode %i bits directly.\n", | ||
99 | nbits2-nbits,ftb); | ||
100 | ret=-1; | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | nbits=ec_tell_frac(&enc); | ||
105 | ec_enc_done(&enc); | ||
106 | fprintf(stderr, | ||
107 | "Encoded %0.2lf bits of entropy to %0.2lf bits (%0.3lf%% wasted).\n", | ||
108 | entropy,ldexp(nbits,-3),100*(nbits-ldexp(entropy,3))/nbits); | ||
109 | fprintf(stderr,"Packed to %li bytes.\n",(long)ec_range_bytes(&enc)); | ||
110 | ec_dec_init(&dec,ptr,DATA_SIZE); | ||
111 | for(ft=2;ft<1024;ft++){ | ||
112 | for(i=0;i<ft;i++){ | ||
113 | sym=ec_dec_uint(&dec,ft); | ||
114 | if(sym!=(unsigned)i){ | ||
115 | fprintf(stderr,"Decoded %i instead of %i with ft of %i.\n",sym,i,ft); | ||
116 | ret=-1; | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | for(ftb=1;ftb<16;ftb++){ | ||
121 | for(i=0;i<(1<<ftb);i++){ | ||
122 | sym=ec_dec_bits(&dec,ftb); | ||
123 | if(sym!=(unsigned)i){ | ||
124 | fprintf(stderr,"Decoded %i instead of %i with ftb of %i.\n",sym,i,ftb); | ||
125 | ret=-1; | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | nbits2=ec_tell_frac(&dec); | ||
130 | if(nbits!=nbits2){ | ||
131 | fprintf(stderr, | ||
132 | "Reported number of bits used was %0.2lf, should be %0.2lf.\n", | ||
133 | ldexp(nbits2,-3),ldexp(nbits,-3)); | ||
134 | ret=-1; | ||
135 | } | ||
136 | /*Testing an encoder bust prefers range coder data over raw bits. | ||
137 | This isn't a general guarantee, will only work for data that is buffered in | ||
138 | the encoder state and not yet stored in the user buffer, and should never | ||
139 | get used in practice. | ||
140 | It's mostly here for code coverage completeness.*/ | ||
141 | /*Start with a 16-bit buffer.*/ | ||
142 | ec_enc_init(&enc,ptr,2); | ||
143 | /*Write 7 raw bits.*/ | ||
144 | ec_enc_bits(&enc,0x55,7); | ||
145 | /*Write 12.3 bits of range coder data.*/ | ||
146 | ec_enc_uint(&enc,1,2); | ||
147 | ec_enc_uint(&enc,1,3); | ||
148 | ec_enc_uint(&enc,1,4); | ||
149 | ec_enc_uint(&enc,1,5); | ||
150 | ec_enc_uint(&enc,2,6); | ||
151 | ec_enc_uint(&enc,6,7); | ||
152 | ec_enc_done(&enc); | ||
153 | ec_dec_init(&dec,ptr,2); | ||
154 | if(!enc.error | ||
155 | /*The raw bits should have been overwritten by the range coder data.*/ | ||
156 | ||ec_dec_bits(&dec,7)!=0x05 | ||
157 | /*And all the range coder data should have been encoded correctly.*/ | ||
158 | ||ec_dec_uint(&dec,2)!=1 | ||
159 | ||ec_dec_uint(&dec,3)!=1 | ||
160 | ||ec_dec_uint(&dec,4)!=1 | ||
161 | ||ec_dec_uint(&dec,5)!=1 | ||
162 | ||ec_dec_uint(&dec,6)!=2 | ||
163 | ||ec_dec_uint(&dec,7)!=6){ | ||
164 | fprintf(stderr,"Encoder bust overwrote range coder data with raw bits.\n"); | ||
165 | ret=-1; | ||
166 | } | ||
167 | srand(seed); | ||
168 | fprintf(stderr,"Testing random streams... Random seed: %u (%.4X)\n", seed, rand() % 65536); | ||
169 | for(i=0;i<409600;i++){ | ||
170 | unsigned *data; | ||
171 | unsigned *tell; | ||
172 | unsigned tell_bits; | ||
173 | int j; | ||
174 | int zeros; | ||
175 | ft=rand()/((RAND_MAX>>(rand()%11U))+1U)+10; | ||
176 | sz=rand()/((RAND_MAX>>(rand()%9U))+1U); | ||
177 | data=(unsigned *)malloc(sz*sizeof(*data)); | ||
178 | tell=(unsigned *)malloc((sz+1)*sizeof(*tell)); | ||
179 | ec_enc_init(&enc,ptr,DATA_SIZE2); | ||
180 | zeros = rand()%13==0; | ||
181 | tell[0]=ec_tell_frac(&enc); | ||
182 | for(j=0;j<sz;j++){ | ||
183 | if (zeros) | ||
184 | data[j]=0; | ||
185 | else | ||
186 | data[j]=rand()%ft; | ||
187 | ec_enc_uint(&enc,data[j],ft); | ||
188 | tell[j+1]=ec_tell_frac(&enc); | ||
189 | } | ||
190 | if (rand()%2==0) | ||
191 | while(ec_tell(&enc)%8 != 0) | ||
192 | ec_enc_uint(&enc, rand()%2, 2); | ||
193 | tell_bits = ec_tell(&enc); | ||
194 | ec_enc_done(&enc); | ||
195 | if(tell_bits!=(unsigned)ec_tell(&enc)){ | ||
196 | fprintf(stderr,"ec_tell() changed after ec_enc_done(): %i instead of %i (Random seed: %u)\n", | ||
197 | ec_tell(&enc),tell_bits,seed); | ||
198 | ret=-1; | ||
199 | } | ||
200 | if ((tell_bits+7)/8 < ec_range_bytes(&enc)) | ||
201 | { | ||
202 | fprintf (stderr, "ec_tell() lied, there's %i bytes instead of %d (Random seed: %u)\n", | ||
203 | ec_range_bytes(&enc), (tell_bits+7)/8,seed); | ||
204 | ret=-1; | ||
205 | } | ||
206 | ec_dec_init(&dec,ptr,DATA_SIZE2); | ||
207 | if(ec_tell_frac(&dec)!=tell[0]){ | ||
208 | fprintf(stderr, | ||
209 | "Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n", | ||
210 | 0,ec_tell_frac(&dec),tell[0],seed); | ||
211 | } | ||
212 | for(j=0;j<sz;j++){ | ||
213 | sym=ec_dec_uint(&dec,ft); | ||
214 | if(sym!=data[j]){ | ||
215 | fprintf(stderr, | ||
216 | "Decoded %i instead of %i with ft of %i at position %i of %i (Random seed: %u).\n", | ||
217 | sym,data[j],ft,j,sz,seed); | ||
218 | ret=-1; | ||
219 | } | ||
220 | if(ec_tell_frac(&dec)!=tell[j+1]){ | ||
221 | fprintf(stderr, | ||
222 | "Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n", | ||
223 | j+1,ec_tell_frac(&dec),tell[j+1],seed); | ||
224 | } | ||
225 | } | ||
226 | free(tell); | ||
227 | free(data); | ||
228 | } | ||
229 | /*Test compatibility between multiple different encode/decode routines.*/ | ||
230 | for(i=0;i<409600;i++){ | ||
231 | unsigned *logp1; | ||
232 | unsigned *data; | ||
233 | unsigned *tell; | ||
234 | unsigned *enc_method; | ||
235 | int j; | ||
236 | sz=rand()/((RAND_MAX>>(rand()%9U))+1U); | ||
237 | logp1=(unsigned *)malloc(sz*sizeof(*logp1)); | ||
238 | data=(unsigned *)malloc(sz*sizeof(*data)); | ||
239 | tell=(unsigned *)malloc((sz+1)*sizeof(*tell)); | ||
240 | enc_method=(unsigned *)malloc(sz*sizeof(*enc_method)); | ||
241 | ec_enc_init(&enc,ptr,DATA_SIZE2); | ||
242 | tell[0]=ec_tell_frac(&enc); | ||
243 | for(j=0;j<sz;j++){ | ||
244 | data[j]=rand()/((RAND_MAX>>1)+1); | ||
245 | logp1[j]=(rand()%15)+1; | ||
246 | enc_method[j]=rand()/((RAND_MAX>>2)+1); | ||
247 | switch(enc_method[j]){ | ||
248 | case 0:{ | ||
249 | ec_encode(&enc,data[j]?(1<<logp1[j])-1:0, | ||
250 | (1<<logp1[j])-(data[j]?0:1),1<<logp1[j]); | ||
251 | }break; | ||
252 | case 1:{ | ||
253 | ec_encode_bin(&enc,data[j]?(1<<logp1[j])-1:0, | ||
254 | (1<<logp1[j])-(data[j]?0:1),logp1[j]); | ||
255 | }break; | ||
256 | case 2:{ | ||
257 | ec_enc_bit_logp(&enc,data[j],logp1[j]); | ||
258 | }break; | ||
259 | case 3:{ | ||
260 | unsigned char icdf[2]; | ||
261 | icdf[0]=1; | ||
262 | icdf[1]=0; | ||
263 | ec_enc_icdf(&enc,data[j],icdf,logp1[j]); | ||
264 | }break; | ||
265 | } | ||
266 | tell[j+1]=ec_tell_frac(&enc); | ||
267 | } | ||
268 | ec_enc_done(&enc); | ||
269 | if((ec_tell(&enc)+7U)/8U<ec_range_bytes(&enc)){ | ||
270 | fprintf(stderr,"tell() lied, there's %i bytes instead of %d (Random seed: %u)\n", | ||
271 | ec_range_bytes(&enc),(ec_tell(&enc)+7)/8,seed); | ||
272 | ret=-1; | ||
273 | } | ||
274 | ec_dec_init(&dec,ptr,DATA_SIZE2); | ||
275 | if(ec_tell_frac(&dec)!=tell[0]){ | ||
276 | fprintf(stderr, | ||
277 | "Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n", | ||
278 | 0,ec_tell_frac(&dec),tell[0],seed); | ||
279 | } | ||
280 | for(j=0;j<sz;j++){ | ||
281 | int fs; | ||
282 | int dec_method; | ||
283 | dec_method=rand()/((RAND_MAX>>2)+1); | ||
284 | switch(dec_method){ | ||
285 | case 0:{ | ||
286 | fs=ec_decode(&dec,1<<logp1[j]); | ||
287 | sym=fs>=(1<<logp1[j])-1; | ||
288 | ec_dec_update(&dec,sym?(1<<logp1[j])-1:0, | ||
289 | (1<<logp1[j])-(sym?0:1),1<<logp1[j]); | ||
290 | }break; | ||
291 | case 1:{ | ||
292 | fs=ec_decode_bin(&dec,logp1[j]); | ||
293 | sym=fs>=(1<<logp1[j])-1; | ||
294 | ec_dec_update(&dec,sym?(1<<logp1[j])-1:0, | ||
295 | (1<<logp1[j])-(sym?0:1),1<<logp1[j]); | ||
296 | }break; | ||
297 | case 2:{ | ||
298 | sym=ec_dec_bit_logp(&dec,logp1[j]); | ||
299 | }break; | ||
300 | case 3:{ | ||
301 | unsigned char icdf[2]; | ||
302 | icdf[0]=1; | ||
303 | icdf[1]=0; | ||
304 | sym=ec_dec_icdf(&dec,icdf,logp1[j]); | ||
305 | }break; | ||
306 | } | ||
307 | if(sym!=data[j]){ | ||
308 | fprintf(stderr, | ||
309 | "Decoded %i instead of %i with logp1 of %i at position %i of %i (Random seed: %u).\n", | ||
310 | sym,data[j],logp1[j],j,sz,seed); | ||
311 | fprintf(stderr,"Encoding method: %i, decoding method: %i\n", | ||
312 | enc_method[j],dec_method); | ||
313 | ret=-1; | ||
314 | } | ||
315 | if(ec_tell_frac(&dec)!=tell[j+1]){ | ||
316 | fprintf(stderr, | ||
317 | "Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n", | ||
318 | j+1,ec_tell_frac(&dec),tell[j+1],seed); | ||
319 | } | ||
320 | } | ||
321 | free(enc_method); | ||
322 | free(tell); | ||
323 | free(data); | ||
324 | free(logp1); | ||
325 | } | ||
326 | ec_enc_init(&enc,ptr,DATA_SIZE2); | ||
327 | ec_enc_bit_logp(&enc,0,1); | ||
328 | ec_enc_bit_logp(&enc,0,1); | ||
329 | ec_enc_bit_logp(&enc,0,1); | ||
330 | ec_enc_bit_logp(&enc,0,1); | ||
331 | ec_enc_bit_logp(&enc,0,2); | ||
332 | ec_enc_patch_initial_bits(&enc,3,2); | ||
333 | if(enc.error){ | ||
334 | fprintf(stderr,"patch_initial_bits failed"); | ||
335 | ret=-1; | ||
336 | } | ||
337 | ec_enc_patch_initial_bits(&enc,0,5); | ||
338 | if(!enc.error){ | ||
339 | fprintf(stderr,"patch_initial_bits didn't fail when it should have"); | ||
340 | ret=-1; | ||
341 | } | ||
342 | ec_enc_done(&enc); | ||
343 | if(ec_range_bytes(&enc)!=1||ptr[0]!=192){ | ||
344 | fprintf(stderr,"Got %d when expecting 192 for patch_initial_bits",ptr[0]); | ||
345 | ret=-1; | ||
346 | } | ||
347 | ec_enc_init(&enc,ptr,DATA_SIZE2); | ||
348 | ec_enc_bit_logp(&enc,0,1); | ||
349 | ec_enc_bit_logp(&enc,0,1); | ||
350 | ec_enc_bit_logp(&enc,1,6); | ||
351 | ec_enc_bit_logp(&enc,0,2); | ||
352 | ec_enc_patch_initial_bits(&enc,0,2); | ||
353 | if(enc.error){ | ||
354 | fprintf(stderr,"patch_initial_bits failed"); | ||
355 | ret=-1; | ||
356 | } | ||
357 | ec_enc_done(&enc); | ||
358 | if(ec_range_bytes(&enc)!=2||ptr[0]!=63){ | ||
359 | fprintf(stderr,"Got %d when expecting 63 for patch_initial_bits",ptr[0]); | ||
360 | ret=-1; | ||
361 | } | ||
362 | ec_enc_init(&enc,ptr,2); | ||
363 | ec_enc_bit_logp(&enc,0,2); | ||
364 | for(i=0;i<48;i++){ | ||
365 | ec_enc_bits(&enc,0,1); | ||
366 | } | ||
367 | ec_enc_done(&enc); | ||
368 | if(!enc.error){ | ||
369 | fprintf(stderr,"Raw bits overfill didn't fail when it should have"); | ||
370 | ret=-1; | ||
371 | } | ||
372 | ec_enc_init(&enc,ptr,2); | ||
373 | for(i=0;i<17;i++){ | ||
374 | ec_enc_bits(&enc,0,1); | ||
375 | } | ||
376 | ec_enc_done(&enc); | ||
377 | if(!enc.error){ | ||
378 | fprintf(stderr,"17 raw bits encoded in two bytes"); | ||
379 | ret=-1; | ||
380 | } | ||
381 | free(ptr); | ||
382 | return ret; | ||
383 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/celt/tests/test_unit_laplace.c b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_laplace.c new file mode 100644 index 0000000000..727bf012ef --- /dev/null +++ b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_laplace.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /* Copyright (c) 2008-2011 Xiph.Org Foundation, Mozilla Corporation | ||
2 | Written by Jean-Marc Valin and Timothy B. Terriberry */ | ||
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 | #include <stdio.h> | ||
33 | #include <stdlib.h> | ||
34 | #define CELT_C | ||
35 | #include "laplace.h" | ||
36 | #include "stack_alloc.h" | ||
37 | |||
38 | #include "entenc.c" | ||
39 | #include "entdec.c" | ||
40 | #include "entcode.c" | ||
41 | #include "laplace.c" | ||
42 | |||
43 | #define DATA_SIZE 40000 | ||
44 | |||
45 | int ec_laplace_get_start_freq(int decay) | ||
46 | { | ||
47 | opus_uint32 ft = 32768 - LAPLACE_MINP*(2*LAPLACE_NMIN+1); | ||
48 | int fs = (ft*(16384-decay))/(16384+decay); | ||
49 | return fs+LAPLACE_MINP; | ||
50 | } | ||
51 | |||
52 | int main(void) | ||
53 | { | ||
54 | int i; | ||
55 | int ret = 0; | ||
56 | ec_enc enc; | ||
57 | ec_dec dec; | ||
58 | unsigned char *ptr; | ||
59 | int val[10000], decay[10000]; | ||
60 | ALLOC_STACK; | ||
61 | ptr = (unsigned char *)malloc(DATA_SIZE); | ||
62 | ec_enc_init(&enc,ptr,DATA_SIZE); | ||
63 | |||
64 | val[0] = 3; decay[0] = 6000; | ||
65 | val[1] = 0; decay[1] = 5800; | ||
66 | val[2] = -1; decay[2] = 5600; | ||
67 | for (i=3;i<10000;i++) | ||
68 | { | ||
69 | val[i] = rand()%15-7; | ||
70 | decay[i] = rand()%11000+5000; | ||
71 | } | ||
72 | for (i=0;i<10000;i++) | ||
73 | ec_laplace_encode(&enc, &val[i], | ||
74 | ec_laplace_get_start_freq(decay[i]), decay[i]); | ||
75 | |||
76 | ec_enc_done(&enc); | ||
77 | |||
78 | ec_dec_init(&dec,ec_get_buffer(&enc),ec_range_bytes(&enc)); | ||
79 | |||
80 | for (i=0;i<10000;i++) | ||
81 | { | ||
82 | int d = ec_laplace_decode(&dec, | ||
83 | ec_laplace_get_start_freq(decay[i]), decay[i]); | ||
84 | if (d != val[i]) | ||
85 | { | ||
86 | fprintf (stderr, "Got %d instead of %d\n", d, val[i]); | ||
87 | ret = 1; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | free(ptr); | ||
92 | return ret; | ||
93 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/celt/tests/test_unit_mathops.c b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_mathops.c new file mode 100644 index 0000000000..874e9adf0f --- /dev/null +++ b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_mathops.c | |||
@@ -0,0 +1,266 @@ | |||
1 | /* Copyright (c) 2008-2011 Xiph.Org Foundation, Mozilla Corporation, | ||
2 | Gregory Maxwell | ||
3 | Written by Jean-Marc Valin, Gregory Maxwell, and Timothy B. Terriberry */ | ||
4 | /* | ||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions | ||
7 | are met: | ||
8 | |||
9 | - Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | - Redistributions in binary form must reproduce the above copyright | ||
13 | notice, this list of conditions and the following disclaimer in the | ||
14 | documentation and/or other materials provided with the distribution. | ||
15 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
17 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | ||
20 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | */ | ||
28 | |||
29 | #ifdef HAVE_CONFIG_H | ||
30 | #include "config.h" | ||
31 | #endif | ||
32 | |||
33 | #ifndef CUSTOM_MODES | ||
34 | #define CUSTOM_MODES | ||
35 | #endif | ||
36 | |||
37 | #include <stdio.h> | ||
38 | #include <math.h> | ||
39 | #include "mathops.h" | ||
40 | #include "bands.h" | ||
41 | |||
42 | #ifdef FIXED_POINT | ||
43 | #define WORD "%d" | ||
44 | #else | ||
45 | #define WORD "%f" | ||
46 | #endif | ||
47 | |||
48 | int ret = 0; | ||
49 | |||
50 | void testdiv(void) | ||
51 | { | ||
52 | opus_int32 i; | ||
53 | for (i=1;i<=327670;i++) | ||
54 | { | ||
55 | double prod; | ||
56 | opus_val32 val; | ||
57 | val = celt_rcp(i); | ||
58 | #ifdef FIXED_POINT | ||
59 | prod = (1./32768./65526.)*val*i; | ||
60 | #else | ||
61 | prod = val*i; | ||
62 | #endif | ||
63 | if (fabs(prod-1) > .00025) | ||
64 | { | ||
65 | fprintf (stderr, "div failed: 1/%d="WORD" (product = %f)\n", i, val, prod); | ||
66 | ret = 1; | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | void testsqrt(void) | ||
72 | { | ||
73 | opus_int32 i; | ||
74 | for (i=1;i<=1000000000;i++) | ||
75 | { | ||
76 | double ratio; | ||
77 | opus_val16 val; | ||
78 | val = celt_sqrt(i); | ||
79 | ratio = val/sqrt(i); | ||
80 | if (fabs(ratio - 1) > .0005 && fabs(val-sqrt(i)) > 2) | ||
81 | { | ||
82 | fprintf (stderr, "sqrt failed: sqrt(%d)="WORD" (ratio = %f)\n", i, val, ratio); | ||
83 | ret = 1; | ||
84 | } | ||
85 | i+= i>>10; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | void testbitexactcos(void) | ||
90 | { | ||
91 | int i; | ||
92 | opus_int32 min_d,max_d,last,chk; | ||
93 | chk=max_d=0; | ||
94 | last=min_d=32767; | ||
95 | for(i=64;i<=16320;i++) | ||
96 | { | ||
97 | opus_int32 d; | ||
98 | opus_int32 q=bitexact_cos(i); | ||
99 | chk ^= q*i; | ||
100 | d = last - q; | ||
101 | if (d>max_d)max_d=d; | ||
102 | if (d<min_d)min_d=d; | ||
103 | last = q; | ||
104 | } | ||
105 | if ((chk!=89408644)||(max_d!=5)||(min_d!=0)||(bitexact_cos(64)!=32767)|| | ||
106 | (bitexact_cos(16320)!=200)||(bitexact_cos(8192)!=23171)) | ||
107 | { | ||
108 | fprintf (stderr, "bitexact_cos failed\n"); | ||
109 | ret = 1; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | void testbitexactlog2tan(void) | ||
114 | { | ||
115 | int i,fail; | ||
116 | opus_int32 min_d,max_d,last,chk; | ||
117 | fail=chk=max_d=0; | ||
118 | last=min_d=15059; | ||
119 | for(i=64;i<8193;i++) | ||
120 | { | ||
121 | opus_int32 d; | ||
122 | opus_int32 mid=bitexact_cos(i); | ||
123 | opus_int32 side=bitexact_cos(16384-i); | ||
124 | opus_int32 q=bitexact_log2tan(mid,side); | ||
125 | chk ^= q*i; | ||
126 | d = last - q; | ||
127 | if (q!=-1*bitexact_log2tan(side,mid)) | ||
128 | fail = 1; | ||
129 | if (d>max_d)max_d=d; | ||
130 | if (d<min_d)min_d=d; | ||
131 | last = q; | ||
132 | } | ||
133 | if ((chk!=15821257)||(max_d!=61)||(min_d!=-2)||fail|| | ||
134 | (bitexact_log2tan(32767,200)!=15059)||(bitexact_log2tan(30274,12540)!=2611)|| | ||
135 | (bitexact_log2tan(23171,23171)!=0)) | ||
136 | { | ||
137 | fprintf (stderr, "bitexact_log2tan failed\n"); | ||
138 | ret = 1; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | #ifndef FIXED_POINT | ||
143 | void testlog2(void) | ||
144 | { | ||
145 | float x; | ||
146 | for (x=0.001;x<1677700.0;x+=(x/8.0)) | ||
147 | { | ||
148 | float error = fabs((1.442695040888963387*log(x))-celt_log2(x)); | ||
149 | if (error>0.0009) | ||
150 | { | ||
151 | fprintf (stderr, "celt_log2 failed: fabs((1.442695040888963387*log(x))-celt_log2(x))>0.001 (x = %f, error = %f)\n", x,error); | ||
152 | ret = 1; | ||
153 | } | ||
154 | } | ||
155 | } | ||
156 | |||
157 | void testexp2(void) | ||
158 | { | ||
159 | float x; | ||
160 | for (x=-11.0;x<24.0;x+=0.0007) | ||
161 | { | ||
162 | float error = fabs(x-(1.442695040888963387*log(celt_exp2(x)))); | ||
163 | if (error>0.0002) | ||
164 | { | ||
165 | fprintf (stderr, "celt_exp2 failed: fabs(x-(1.442695040888963387*log(celt_exp2(x))))>0.0005 (x = %f, error = %f)\n", x,error); | ||
166 | ret = 1; | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | |||
171 | void testexp2log2(void) | ||
172 | { | ||
173 | float x; | ||
174 | for (x=-11.0;x<24.0;x+=0.0007) | ||
175 | { | ||
176 | float error = fabs(x-(celt_log2(celt_exp2(x)))); | ||
177 | if (error>0.001) | ||
178 | { | ||
179 | fprintf (stderr, "celt_log2/celt_exp2 failed: fabs(x-(celt_log2(celt_exp2(x))))>0.001 (x = %f, error = %f)\n", x,error); | ||
180 | ret = 1; | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | #else | ||
185 | void testlog2(void) | ||
186 | { | ||
187 | opus_val32 x; | ||
188 | for (x=8;x<1073741824;x+=(x>>3)) | ||
189 | { | ||
190 | float error = fabs((1.442695040888963387*log(x/16384.0))-celt_log2(x)/1024.0); | ||
191 | if (error>0.003) | ||
192 | { | ||
193 | fprintf (stderr, "celt_log2 failed: x = %ld, error = %f\n", (long)x,error); | ||
194 | ret = 1; | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | |||
199 | void testexp2(void) | ||
200 | { | ||
201 | opus_val16 x; | ||
202 | for (x=-32768;x<15360;x++) | ||
203 | { | ||
204 | float error1 = fabs(x/1024.0-(1.442695040888963387*log(celt_exp2(x)/65536.0))); | ||
205 | float error2 = fabs(exp(0.6931471805599453094*x/1024.0)-celt_exp2(x)/65536.0); | ||
206 | if (error1>0.0002&&error2>0.00004) | ||
207 | { | ||
208 | fprintf (stderr, "celt_exp2 failed: x = "WORD", error1 = %f, error2 = %f\n", x,error1,error2); | ||
209 | ret = 1; | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | void testexp2log2(void) | ||
215 | { | ||
216 | opus_val32 x; | ||
217 | for (x=8;x<65536;x+=(x>>3)) | ||
218 | { | ||
219 | float error = fabs(x-0.25*celt_exp2(celt_log2(x)))/16384; | ||
220 | if (error>0.004) | ||
221 | { | ||
222 | fprintf (stderr, "celt_log2/celt_exp2 failed: fabs(x-(celt_exp2(celt_log2(x))))>0.001 (x = %ld, error = %f)\n", (long)x,error); | ||
223 | ret = 1; | ||
224 | } | ||
225 | } | ||
226 | } | ||
227 | |||
228 | void testilog2(void) | ||
229 | { | ||
230 | opus_val32 x; | ||
231 | for (x=1;x<=268435455;x+=127) | ||
232 | { | ||
233 | opus_val32 lg; | ||
234 | opus_val32 y; | ||
235 | |||
236 | lg = celt_ilog2(x); | ||
237 | if (lg<0 || lg>=31) | ||
238 | { | ||
239 | printf("celt_ilog2 failed: 0<=celt_ilog2(x)<31 (x = %d, celt_ilog2(x) = %d)\n",x,lg); | ||
240 | ret = 1; | ||
241 | } | ||
242 | y = 1<<lg; | ||
243 | |||
244 | if (x<y || (x>>1)>=y) | ||
245 | { | ||
246 | printf("celt_ilog2 failed: 2**celt_ilog2(x)<=x<2**(celt_ilog2(x)+1) (x = %d, 2**celt_ilog2(x) = %d)\n",x,y); | ||
247 | ret = 1; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | #endif | ||
252 | |||
253 | int main(void) | ||
254 | { | ||
255 | testbitexactcos(); | ||
256 | testbitexactlog2tan(); | ||
257 | testdiv(); | ||
258 | testsqrt(); | ||
259 | testlog2(); | ||
260 | testexp2(); | ||
261 | testexp2log2(); | ||
262 | #ifdef FIXED_POINT | ||
263 | testilog2(); | ||
264 | #endif | ||
265 | return ret; | ||
266 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/celt/tests/test_unit_mdct.c b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_mdct.c new file mode 100644 index 0000000000..4a563ccfe3 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_mdct.c | |||
@@ -0,0 +1,227 @@ | |||
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 | #include <stdio.h> | ||
33 | |||
34 | #include "mdct.h" | ||
35 | #include "stack_alloc.h" | ||
36 | #include "kiss_fft.h" | ||
37 | #include "mdct.h" | ||
38 | #include "modes.h" | ||
39 | |||
40 | #ifndef M_PI | ||
41 | #define M_PI 3.141592653 | ||
42 | #endif | ||
43 | |||
44 | int ret = 0; | ||
45 | void check(kiss_fft_scalar * in,kiss_fft_scalar * out,int nfft,int isinverse) | ||
46 | { | ||
47 | int bin,k; | ||
48 | double errpow=0,sigpow=0; | ||
49 | double snr; | ||
50 | for (bin=0;bin<nfft/2;++bin) { | ||
51 | double ansr = 0; | ||
52 | double difr; | ||
53 | |||
54 | for (k=0;k<nfft;++k) { | ||
55 | double phase = 2*M_PI*(k+.5+.25*nfft)*(bin+.5)/nfft; | ||
56 | double re = cos(phase); | ||
57 | |||
58 | re /= nfft/4; | ||
59 | |||
60 | ansr += in[k] * re; | ||
61 | } | ||
62 | /*printf ("%f %f\n", ansr, out[bin]);*/ | ||
63 | difr = ansr - out[bin]; | ||
64 | errpow += difr*difr; | ||
65 | sigpow += ansr*ansr; | ||
66 | } | ||
67 | snr = 10*log10(sigpow/errpow); | ||
68 | printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr ); | ||
69 | if (snr<60) { | ||
70 | printf( "** poor snr: %f **\n", snr); | ||
71 | ret = 1; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | void check_inv(kiss_fft_scalar * in,kiss_fft_scalar * out,int nfft,int isinverse) | ||
76 | { | ||
77 | int bin,k; | ||
78 | double errpow=0,sigpow=0; | ||
79 | double snr; | ||
80 | for (bin=0;bin<nfft;++bin) { | ||
81 | double ansr = 0; | ||
82 | double difr; | ||
83 | |||
84 | for (k=0;k<nfft/2;++k) { | ||
85 | double phase = 2*M_PI*(bin+.5+.25*nfft)*(k+.5)/nfft; | ||
86 | double re = cos(phase); | ||
87 | |||
88 | /*re *= 2;*/ | ||
89 | |||
90 | ansr += in[k] * re; | ||
91 | } | ||
92 | /*printf ("%f %f\n", ansr, out[bin]);*/ | ||
93 | difr = ansr - out[bin]; | ||
94 | errpow += difr*difr; | ||
95 | sigpow += ansr*ansr; | ||
96 | } | ||
97 | snr = 10*log10(sigpow/errpow); | ||
98 | printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr ); | ||
99 | if (snr<60) { | ||
100 | printf( "** poor snr: %f **\n", snr); | ||
101 | ret = 1; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | |||
106 | void test1d(int nfft,int isinverse,int arch) | ||
107 | { | ||
108 | size_t buflen = sizeof(kiss_fft_scalar)*nfft; | ||
109 | kiss_fft_scalar *in; | ||
110 | kiss_fft_scalar *in_copy; | ||
111 | kiss_fft_scalar *out; | ||
112 | opus_val16 *window; | ||
113 | int k; | ||
114 | |||
115 | #ifdef CUSTOM_MODES | ||
116 | int shift = 0; | ||
117 | const mdct_lookup *cfg; | ||
118 | mdct_lookup _cfg; | ||
119 | clt_mdct_init(&_cfg, nfft, 0, arch); | ||
120 | cfg = &_cfg; | ||
121 | #else | ||
122 | int shift; | ||
123 | const mdct_lookup *cfg; | ||
124 | CELTMode *mode = opus_custom_mode_create(48000, 960, NULL); | ||
125 | if (nfft == 1920) shift = 0; | ||
126 | else if (nfft == 960) shift = 1; | ||
127 | else if (nfft == 480) shift = 2; | ||
128 | else if (nfft == 240) shift = 3; | ||
129 | else return; | ||
130 | cfg = &mode->mdct; | ||
131 | #endif | ||
132 | |||
133 | in = (kiss_fft_scalar*)malloc(buflen); | ||
134 | in_copy = (kiss_fft_scalar*)malloc(buflen); | ||
135 | out = (kiss_fft_scalar*)malloc(buflen); | ||
136 | window = (opus_val16*)malloc(sizeof(opus_val16)*nfft/2); | ||
137 | |||
138 | for (k=0;k<nfft;++k) { | ||
139 | in[k] = (rand() % 32768) - 16384; | ||
140 | } | ||
141 | |||
142 | for (k=0;k<nfft/2;++k) { | ||
143 | window[k] = Q15ONE; | ||
144 | } | ||
145 | for (k=0;k<nfft;++k) { | ||
146 | in[k] *= 32768; | ||
147 | } | ||
148 | |||
149 | if (isinverse) | ||
150 | { | ||
151 | for (k=0;k<nfft;++k) { | ||
152 | in[k] /= nfft; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | for (k=0;k<nfft;++k) | ||
157 | in_copy[k] = in[k]; | ||
158 | /*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/ | ||
159 | |||
160 | if (isinverse) | ||
161 | { | ||
162 | for (k=0;k<nfft;++k) | ||
163 | out[k] = 0; | ||
164 | clt_mdct_backward(cfg,in,out, window, nfft/2, shift, 1, arch); | ||
165 | /* apply TDAC because clt_mdct_backward() no longer does that */ | ||
166 | for (k=0;k<nfft/4;++k) | ||
167 | out[nfft-k-1] = out[nfft/2+k]; | ||
168 | check_inv(in,out,nfft,isinverse); | ||
169 | } else { | ||
170 | clt_mdct_forward(cfg,in,out,window, nfft/2, shift, 1, arch); | ||
171 | check(in_copy,out,nfft,isinverse); | ||
172 | } | ||
173 | /*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/ | ||
174 | |||
175 | |||
176 | free(in); | ||
177 | free(in_copy); | ||
178 | free(out); | ||
179 | free(window); | ||
180 | #ifdef CUSTOM_MODES | ||
181 | clt_mdct_clear(&_cfg, arch); | ||
182 | #endif | ||
183 | } | ||
184 | |||
185 | int main(int argc,char ** argv) | ||
186 | { | ||
187 | ALLOC_STACK; | ||
188 | int arch = opus_select_arch(); | ||
189 | |||
190 | if (argc>1) { | ||
191 | int k; | ||
192 | for (k=1;k<argc;++k) { | ||
193 | test1d(atoi(argv[k]),0,arch); | ||
194 | test1d(atoi(argv[k]),1,arch); | ||
195 | } | ||
196 | }else{ | ||
197 | test1d(32,0,arch); | ||
198 | test1d(32,1,arch); | ||
199 | test1d(256,0,arch); | ||
200 | test1d(256,1,arch); | ||
201 | test1d(512,0,arch); | ||
202 | test1d(512,1,arch); | ||
203 | test1d(1024,0,arch); | ||
204 | test1d(1024,1,arch); | ||
205 | test1d(2048,0,arch); | ||
206 | test1d(2048,1,arch); | ||
207 | #ifndef RADIX_TWO_ONLY | ||
208 | test1d(36,0,arch); | ||
209 | test1d(36,1,arch); | ||
210 | test1d(40,0,arch); | ||
211 | test1d(40,1,arch); | ||
212 | test1d(60,0,arch); | ||
213 | test1d(60,1,arch); | ||
214 | test1d(120,0,arch); | ||
215 | test1d(120,1,arch); | ||
216 | test1d(240,0,arch); | ||
217 | test1d(240,1,arch); | ||
218 | test1d(480,0,arch); | ||
219 | test1d(480,1,arch); | ||
220 | test1d(960,0,arch); | ||
221 | test1d(960,1,arch); | ||
222 | test1d(1920,0,arch); | ||
223 | test1d(1920,1,arch); | ||
224 | #endif | ||
225 | } | ||
226 | return ret; | ||
227 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/celt/tests/test_unit_rotation.c b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_rotation.c new file mode 100644 index 0000000000..8a31b3f2b1 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_rotation.c | |||
@@ -0,0 +1,86 @@ | |||
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; | ||
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 | |||
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 | } | ||
diff --git a/lib/rbcodec/codecs/libopus/celt/tests/test_unit_types.c b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_types.c new file mode 100644 index 0000000000..67a0fb8ed3 --- /dev/null +++ b/lib/rbcodec/codecs/libopus/celt/tests/test_unit_types.c | |||
@@ -0,0 +1,50 @@ | |||
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 | #include "opus_types.h" | ||
33 | #include <stdio.h> | ||
34 | |||
35 | int main(void) | ||
36 | { | ||
37 | opus_int16 i = 1; | ||
38 | i <<= 14; | ||
39 | if (i>>14 != 1) | ||
40 | { | ||
41 | fprintf(stderr, "opus_int16 isn't 16 bits\n"); | ||
42 | return 1; | ||
43 | } | ||
44 | if (sizeof(opus_int16)*2 != sizeof(opus_int32)) | ||
45 | { | ||
46 | fprintf(stderr, "16*2 != 32\n"); | ||
47 | return 1; | ||
48 | } | ||
49 | return 0; | ||
50 | } | ||