cannam@154
|
1 /* Copyright (c) 2011-2013 Xiph.Org Foundation
|
cannam@154
|
2 Written by Gregory Maxwell */
|
cannam@154
|
3 /*
|
cannam@154
|
4 Redistribution and use in source and binary forms, with or without
|
cannam@154
|
5 modification, are permitted provided that the following conditions
|
cannam@154
|
6 are met:
|
cannam@154
|
7
|
cannam@154
|
8 - Redistributions of source code must retain the above copyright
|
cannam@154
|
9 notice, this list of conditions and the following disclaimer.
|
cannam@154
|
10
|
cannam@154
|
11 - Redistributions in binary form must reproduce the above copyright
|
cannam@154
|
12 notice, this list of conditions and the following disclaimer in the
|
cannam@154
|
13 documentation and/or other materials provided with the distribution.
|
cannam@154
|
14
|
cannam@154
|
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
cannam@154
|
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
cannam@154
|
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
cannam@154
|
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
cannam@154
|
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
cannam@154
|
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
cannam@154
|
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
cannam@154
|
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
cannam@154
|
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
cannam@154
|
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
cannam@154
|
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
cannam@154
|
26 */
|
cannam@154
|
27
|
cannam@154
|
28 #ifdef HAVE_CONFIG_H
|
cannam@154
|
29 #include "config.h"
|
cannam@154
|
30 #endif
|
cannam@154
|
31
|
cannam@154
|
32 #include <stdio.h>
|
cannam@154
|
33 #include <stdlib.h>
|
cannam@154
|
34 #include <limits.h>
|
cannam@154
|
35 #include <stdint.h>
|
cannam@154
|
36 #include <math.h>
|
cannam@154
|
37 #include <string.h>
|
cannam@154
|
38 #include <time.h>
|
cannam@154
|
39 #if (!defined WIN32 && !defined _WIN32) || defined(__MINGW32__)
|
cannam@154
|
40 #include <unistd.h>
|
cannam@154
|
41 #else
|
cannam@154
|
42 #include <process.h>
|
cannam@154
|
43 #define getpid _getpid
|
cannam@154
|
44 #endif
|
cannam@154
|
45 #include "opus.h"
|
cannam@154
|
46 #include "test_opus_common.h"
|
cannam@154
|
47
|
cannam@154
|
48 #define MAX_PACKET (1500)
|
cannam@154
|
49 #define MAX_FRAME_SAMP (5760)
|
cannam@154
|
50
|
cannam@154
|
51 int test_decoder_code0(int no_fuzz)
|
cannam@154
|
52 {
|
cannam@154
|
53 static const opus_int32 fsv[5]={48000,24000,16000,12000,8000};
|
cannam@154
|
54 int err,skip,plen;
|
cannam@154
|
55 int out_samples,fec;
|
cannam@154
|
56 int t;
|
cannam@154
|
57 opus_int32 i;
|
cannam@154
|
58 OpusDecoder *dec[5*2];
|
cannam@154
|
59 opus_int32 decsize;
|
cannam@154
|
60 OpusDecoder *decbak;
|
cannam@154
|
61 opus_uint32 dec_final_range1,dec_final_range2,dec_final_acc;
|
cannam@154
|
62 unsigned char *packet;
|
cannam@154
|
63 unsigned char modes[4096];
|
cannam@154
|
64 short *outbuf_int;
|
cannam@154
|
65 short *outbuf;
|
cannam@154
|
66
|
cannam@154
|
67 dec_final_range1=dec_final_range2=2;
|
cannam@154
|
68
|
cannam@154
|
69 packet=malloc(sizeof(unsigned char)*MAX_PACKET);
|
cannam@154
|
70 if(packet==NULL)test_failed();
|
cannam@154
|
71
|
cannam@154
|
72 outbuf_int=malloc(sizeof(short)*(MAX_FRAME_SAMP+16)*2);
|
cannam@154
|
73 for(i=0;i<(MAX_FRAME_SAMP+16)*2;i++)outbuf_int[i]=32749;
|
cannam@154
|
74 outbuf=&outbuf_int[8*2];
|
cannam@154
|
75
|
cannam@154
|
76 fprintf(stdout," Starting %d decoders...\n",5*2);
|
cannam@154
|
77 for(t=0;t<5*2;t++)
|
cannam@154
|
78 {
|
cannam@154
|
79 int fs=fsv[t>>1];
|
cannam@154
|
80 int c=(t&1)+1;
|
cannam@154
|
81 err=OPUS_INTERNAL_ERROR;
|
cannam@154
|
82 dec[t] = opus_decoder_create(fs, c, &err);
|
cannam@154
|
83 if(err!=OPUS_OK || dec[t]==NULL)test_failed();
|
cannam@154
|
84 fprintf(stdout," opus_decoder_create(%5d,%d) OK. Copy ",fs,c);
|
cannam@154
|
85 {
|
cannam@154
|
86 OpusDecoder *dec2;
|
cannam@154
|
87 /*The opus state structures contain no pointers and can be freely copied*/
|
cannam@154
|
88 dec2=(OpusDecoder *)malloc(opus_decoder_get_size(c));
|
cannam@154
|
89 if(dec2==NULL)test_failed();
|
cannam@154
|
90 memcpy(dec2,dec[t],opus_decoder_get_size(c));
|
cannam@154
|
91 memset(dec[t],255,opus_decoder_get_size(c));
|
cannam@154
|
92 opus_decoder_destroy(dec[t]);
|
cannam@154
|
93 printf("OK.\n");
|
cannam@154
|
94 dec[t]=dec2;
|
cannam@154
|
95 }
|
cannam@154
|
96 }
|
cannam@154
|
97
|
cannam@154
|
98 decsize=opus_decoder_get_size(1);
|
cannam@154
|
99 decbak=(OpusDecoder *)malloc(decsize);
|
cannam@154
|
100 if(decbak==NULL)test_failed();
|
cannam@154
|
101
|
cannam@154
|
102 for(t=0;t<5*2;t++)
|
cannam@154
|
103 {
|
cannam@154
|
104 int factor=48000/fsv[t>>1];
|
cannam@154
|
105 for(fec=0;fec<2;fec++)
|
cannam@154
|
106 {
|
cannam@154
|
107 opus_int32 dur;
|
cannam@154
|
108 /*Test PLC on a fresh decoder*/
|
cannam@154
|
109 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor, fec);
|
cannam@154
|
110 if(out_samples!=120/factor)test_failed();
|
cannam@154
|
111 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_OK)test_failed();
|
cannam@154
|
112 if(dur!=120/factor)test_failed();
|
cannam@154
|
113
|
cannam@154
|
114 /*Test on a size which isn't a multiple of 2.5ms*/
|
cannam@154
|
115 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor+2, fec);
|
cannam@154
|
116 if(out_samples!=OPUS_BAD_ARG)test_failed();
|
cannam@154
|
117
|
cannam@154
|
118 /*Test null pointer input*/
|
cannam@154
|
119 out_samples = opus_decode(dec[t], 0, -1, outbuf, 120/factor, fec);
|
cannam@154
|
120 if(out_samples!=120/factor)test_failed();
|
cannam@154
|
121 out_samples = opus_decode(dec[t], 0, 1, outbuf, 120/factor, fec);
|
cannam@154
|
122 if(out_samples!=120/factor)test_failed();
|
cannam@154
|
123 out_samples = opus_decode(dec[t], 0, 10, outbuf, 120/factor, fec);
|
cannam@154
|
124 if(out_samples!=120/factor)test_failed();
|
cannam@154
|
125 out_samples = opus_decode(dec[t], 0, fast_rand(), outbuf, 120/factor, fec);
|
cannam@154
|
126 if(out_samples!=120/factor)test_failed();
|
cannam@154
|
127 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_OK)test_failed();
|
cannam@154
|
128 if(dur!=120/factor)test_failed();
|
cannam@154
|
129
|
cannam@154
|
130 /*Zero lengths*/
|
cannam@154
|
131 out_samples = opus_decode(dec[t], packet, 0, outbuf, 120/factor, fec);
|
cannam@154
|
132 if(out_samples!=120/factor)test_failed();
|
cannam@154
|
133
|
cannam@154
|
134 /*Zero buffer*/
|
cannam@154
|
135 outbuf[0]=32749;
|
cannam@154
|
136 out_samples = opus_decode(dec[t], packet, 0, outbuf, 0, fec);
|
cannam@154
|
137 if(out_samples>0)test_failed();
|
cannam@154
|
138 #if !defined(OPUS_BUILD) && (OPUS_GNUC_PREREQ(4, 6) || (defined(__clang_major__) && __clang_major__ >= 3))
|
cannam@154
|
139 #pragma GCC diagnostic push
|
cannam@154
|
140 #pragma GCC diagnostic ignored "-Wnonnull"
|
cannam@154
|
141 #endif
|
cannam@154
|
142 out_samples = opus_decode(dec[t], packet, 0, 0, 0, fec);
|
cannam@154
|
143 #if !defined(OPUS_BUILD) && (OPUS_GNUC_PREREQ(4, 6) || (defined(__clang_major__) && __clang_major__ >= 3))
|
cannam@154
|
144 #pragma GCC diagnostic pop
|
cannam@154
|
145 #endif
|
cannam@154
|
146 if(out_samples>0)test_failed();
|
cannam@154
|
147 if(outbuf[0]!=32749)test_failed();
|
cannam@154
|
148
|
cannam@154
|
149 /*Invalid lengths*/
|
cannam@154
|
150 out_samples = opus_decode(dec[t], packet, -1, outbuf, MAX_FRAME_SAMP, fec);
|
cannam@154
|
151 if(out_samples>=0)test_failed();
|
cannam@154
|
152 out_samples = opus_decode(dec[t], packet, INT_MIN, outbuf, MAX_FRAME_SAMP, fec);
|
cannam@154
|
153 if(out_samples>=0)test_failed();
|
cannam@154
|
154 out_samples = opus_decode(dec[t], packet, -1, outbuf, -1, fec);
|
cannam@154
|
155 if(out_samples>=0)test_failed();
|
cannam@154
|
156
|
cannam@154
|
157 /*Crazy FEC values*/
|
cannam@154
|
158 out_samples = opus_decode(dec[t], packet, 1, outbuf, MAX_FRAME_SAMP, fec?-1:2);
|
cannam@154
|
159 if(out_samples>=0)test_failed();
|
cannam@154
|
160
|
cannam@154
|
161 /*Reset the decoder*/
|
cannam@154
|
162 if(opus_decoder_ctl(dec[t], OPUS_RESET_STATE)!=OPUS_OK)test_failed();
|
cannam@154
|
163 }
|
cannam@154
|
164 }
|
cannam@154
|
165 fprintf(stdout," dec[all] initial frame PLC OK.\n");
|
cannam@154
|
166
|
cannam@154
|
167 /*Count code 0 tests*/
|
cannam@154
|
168 for(i=0;i<64;i++)
|
cannam@154
|
169 {
|
cannam@154
|
170 opus_int32 dur;
|
cannam@154
|
171 int j,expected[5*2];
|
cannam@154
|
172 packet[0]=i<<2;
|
cannam@154
|
173 packet[1]=255;
|
cannam@154
|
174 packet[2]=255;
|
cannam@154
|
175 err=opus_packet_get_nb_channels(packet);
|
cannam@154
|
176 if(err!=(i&1)+1)test_failed();
|
cannam@154
|
177
|
cannam@154
|
178 for(t=0;t<5*2;t++){
|
cannam@154
|
179 expected[t]=opus_decoder_get_nb_samples(dec[t],packet,1);
|
cannam@154
|
180 if(expected[t]>2880)test_failed();
|
cannam@154
|
181 }
|
cannam@154
|
182
|
cannam@154
|
183 for(j=0;j<256;j++)
|
cannam@154
|
184 {
|
cannam@154
|
185 packet[1]=j;
|
cannam@154
|
186 for(t=0;t<5*2;t++)
|
cannam@154
|
187 {
|
cannam@154
|
188 out_samples = opus_decode(dec[t], packet, 3, outbuf, MAX_FRAME_SAMP, 0);
|
cannam@154
|
189 if(out_samples!=expected[t])test_failed();
|
cannam@154
|
190 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_OK)test_failed();
|
cannam@154
|
191 if(dur!=out_samples)test_failed();
|
cannam@154
|
192 opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1));
|
cannam@154
|
193 if(t==0)dec_final_range2=dec_final_range1;
|
cannam@154
|
194 else if(dec_final_range1!=dec_final_range2)test_failed();
|
cannam@154
|
195 }
|
cannam@154
|
196 }
|
cannam@154
|
197
|
cannam@154
|
198 for(t=0;t<5*2;t++){
|
cannam@154
|
199 int factor=48000/fsv[t>>1];
|
cannam@154
|
200 /* The PLC is run for 6 frames in order to get better PLC coverage. */
|
cannam@154
|
201 for(j=0;j<6;j++)
|
cannam@154
|
202 {
|
cannam@154
|
203 out_samples = opus_decode(dec[t], 0, 0, outbuf, expected[t], 0);
|
cannam@154
|
204 if(out_samples!=expected[t])test_failed();
|
cannam@154
|
205 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_OK)test_failed();
|
cannam@154
|
206 if(dur!=out_samples)test_failed();
|
cannam@154
|
207 }
|
cannam@154
|
208 /* Run the PLC once at 2.5ms, as a simulation of someone trying to
|
cannam@154
|
209 do small drift corrections. */
|
cannam@154
|
210 if(expected[t]!=120/factor)
|
cannam@154
|
211 {
|
cannam@154
|
212 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor, 0);
|
cannam@154
|
213 if(out_samples!=120/factor)test_failed();
|
cannam@154
|
214 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_OK)test_failed();
|
cannam@154
|
215 if(dur!=out_samples)test_failed();
|
cannam@154
|
216 }
|
cannam@154
|
217 out_samples = opus_decode(dec[t], packet, 2, outbuf, expected[t]-1, 0);
|
cannam@154
|
218 if(out_samples>0)test_failed();
|
cannam@154
|
219 }
|
cannam@154
|
220 }
|
cannam@154
|
221 fprintf(stdout," dec[all] all 2-byte prefix for length 3 and PLC, all modes (64) OK.\n");
|
cannam@154
|
222
|
cannam@154
|
223 if(no_fuzz)
|
cannam@154
|
224 {
|
cannam@154
|
225 fprintf(stdout," Skipping many tests which fuzz the decoder as requested.\n");
|
cannam@154
|
226 free(decbak);
|
cannam@154
|
227 for(t=0;t<5*2;t++)opus_decoder_destroy(dec[t]);
|
cannam@154
|
228 printf(" Decoders stopped.\n");
|
cannam@154
|
229
|
cannam@154
|
230 err=0;
|
cannam@154
|
231 for(i=0;i<8*2;i++)err|=outbuf_int[i]!=32749;
|
cannam@154
|
232 for(i=MAX_FRAME_SAMP*2;i<(MAX_FRAME_SAMP+8)*2;i++)err|=outbuf[i]!=32749;
|
cannam@154
|
233 if(err)test_failed();
|
cannam@154
|
234
|
cannam@154
|
235 free(outbuf_int);
|
cannam@154
|
236 free(packet);
|
cannam@154
|
237 return 0;
|
cannam@154
|
238 }
|
cannam@154
|
239
|
cannam@154
|
240 {
|
cannam@154
|
241 /*We only test a subset of the modes here simply because the longer
|
cannam@154
|
242 durations end up taking a long time.*/
|
cannam@154
|
243 static const int cmodes[4]={16,20,24,28};
|
cannam@154
|
244 static const opus_uint32 cres[4]={116290185,2172123586u,2172123586u,2172123586u};
|
cannam@154
|
245 static const opus_uint32 lres[3]={3285687739u,1481572662,694350475};
|
cannam@154
|
246 static const int lmodes[3]={0,4,8};
|
cannam@154
|
247 int mode=fast_rand()%4;
|
cannam@154
|
248
|
cannam@154
|
249 packet[0]=cmodes[mode]<<3;
|
cannam@154
|
250 dec_final_acc=0;
|
cannam@154
|
251 t=fast_rand()%10;
|
cannam@154
|
252
|
cannam@154
|
253 for(i=0;i<65536;i++)
|
cannam@154
|
254 {
|
cannam@154
|
255 int factor=48000/fsv[t>>1];
|
cannam@154
|
256 packet[1]=i>>8;
|
cannam@154
|
257 packet[2]=i&255;
|
cannam@154
|
258 packet[3]=255;
|
cannam@154
|
259 out_samples = opus_decode(dec[t], packet, 4, outbuf, MAX_FRAME_SAMP, 0);
|
cannam@154
|
260 if(out_samples!=120/factor)test_failed();
|
cannam@154
|
261 opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1));
|
cannam@154
|
262 dec_final_acc+=dec_final_range1;
|
cannam@154
|
263 }
|
cannam@154
|
264 if(dec_final_acc!=cres[mode])test_failed();
|
cannam@154
|
265 fprintf(stdout," dec[%3d] all 3-byte prefix for length 4, mode %2d OK.\n",t,cmodes[mode]);
|
cannam@154
|
266
|
cannam@154
|
267 mode=fast_rand()%3;
|
cannam@154
|
268 packet[0]=lmodes[mode]<<3;
|
cannam@154
|
269 dec_final_acc=0;
|
cannam@154
|
270 t=fast_rand()%10;
|
cannam@154
|
271 for(i=0;i<65536;i++)
|
cannam@154
|
272 {
|
cannam@154
|
273 int factor=48000/fsv[t>>1];
|
cannam@154
|
274 packet[1]=i>>8;
|
cannam@154
|
275 packet[2]=i&255;
|
cannam@154
|
276 packet[3]=255;
|
cannam@154
|
277 out_samples = opus_decode(dec[t], packet, 4, outbuf, MAX_FRAME_SAMP, 0);
|
cannam@154
|
278 if(out_samples!=480/factor)test_failed();
|
cannam@154
|
279 opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1));
|
cannam@154
|
280 dec_final_acc+=dec_final_range1;
|
cannam@154
|
281 }
|
cannam@154
|
282 if(dec_final_acc!=lres[mode])test_failed();
|
cannam@154
|
283 fprintf(stdout," dec[%3d] all 3-byte prefix for length 4, mode %2d OK.\n",t,lmodes[mode]);
|
cannam@154
|
284 }
|
cannam@154
|
285
|
cannam@154
|
286 skip=fast_rand()%7;
|
cannam@154
|
287 for(i=0;i<64;i++)
|
cannam@154
|
288 {
|
cannam@154
|
289 int j,expected[5*2];
|
cannam@154
|
290 packet[0]=i<<2;
|
cannam@154
|
291 for(t=0;t<5*2;t++)expected[t]=opus_decoder_get_nb_samples(dec[t],packet,1);
|
cannam@154
|
292 for(j=2+skip;j<1275;j+=4)
|
cannam@154
|
293 {
|
cannam@154
|
294 int jj;
|
cannam@154
|
295 for(jj=0;jj<j;jj++)packet[jj+1]=fast_rand()&255;
|
cannam@154
|
296 for(t=0;t<5*2;t++)
|
cannam@154
|
297 {
|
cannam@154
|
298 out_samples = opus_decode(dec[t], packet, j+1, outbuf, MAX_FRAME_SAMP, 0);
|
cannam@154
|
299 if(out_samples!=expected[t])test_failed();
|
cannam@154
|
300 opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1));
|
cannam@154
|
301 if(t==0)dec_final_range2=dec_final_range1;
|
cannam@154
|
302 else if(dec_final_range1!=dec_final_range2)test_failed();
|
cannam@154
|
303 }
|
cannam@154
|
304 }
|
cannam@154
|
305 }
|
cannam@154
|
306 fprintf(stdout," dec[all] random packets, all modes (64), every 8th size from from %d bytes to maximum OK.\n",2+skip);
|
cannam@154
|
307
|
cannam@154
|
308 debruijn2(64,modes);
|
cannam@154
|
309 plen=(fast_rand()%18+3)*8+skip+3;
|
cannam@154
|
310 for(i=0;i<4096;i++)
|
cannam@154
|
311 {
|
cannam@154
|
312 int j,expected[5*2];
|
cannam@154
|
313 packet[0]=modes[i]<<2;
|
cannam@154
|
314 for(t=0;t<5*2;t++)expected[t]=opus_decoder_get_nb_samples(dec[t],packet,plen);
|
cannam@154
|
315 for(j=0;j<plen;j++)packet[j+1]=(fast_rand()|fast_rand())&255;
|
cannam@154
|
316 memcpy(decbak,dec[0],decsize);
|
cannam@154
|
317 if(opus_decode(decbak, packet, plen+1, outbuf, expected[0], 1)!=expected[0])test_failed();
|
cannam@154
|
318 memcpy(decbak,dec[0],decsize);
|
cannam@154
|
319 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 1)<20)test_failed();
|
cannam@154
|
320 memcpy(decbak,dec[0],decsize);
|
cannam@154
|
321 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 0)<20)test_failed();
|
cannam@154
|
322 for(t=0;t<5*2;t++)
|
cannam@154
|
323 {
|
cannam@154
|
324 opus_int32 dur;
|
cannam@154
|
325 out_samples = opus_decode(dec[t], packet, plen+1, outbuf, MAX_FRAME_SAMP, 0);
|
cannam@154
|
326 if(out_samples!=expected[t])test_failed();
|
cannam@154
|
327 if(t==0)dec_final_range2=dec_final_range1;
|
cannam@154
|
328 else if(dec_final_range1!=dec_final_range2)test_failed();
|
cannam@154
|
329 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_OK)test_failed();
|
cannam@154
|
330 if(dur!=out_samples)test_failed();
|
cannam@154
|
331 }
|
cannam@154
|
332 }
|
cannam@154
|
333 fprintf(stdout," dec[all] random packets, all mode pairs (4096), %d bytes/frame OK.\n",plen+1);
|
cannam@154
|
334
|
cannam@154
|
335 plen=(fast_rand()%18+3)*8+skip+3;
|
cannam@154
|
336 t=rand()&3;
|
cannam@154
|
337 for(i=0;i<4096;i++)
|
cannam@154
|
338 {
|
cannam@154
|
339 int count,j,expected;
|
cannam@154
|
340 packet[0]=modes[i]<<2;
|
cannam@154
|
341 expected=opus_decoder_get_nb_samples(dec[t],packet,plen);
|
cannam@154
|
342 for(count=0;count<10;count++)
|
cannam@154
|
343 {
|
cannam@154
|
344 for(j=0;j<plen;j++)packet[j+1]=(fast_rand()|fast_rand())&255;
|
cannam@154
|
345 out_samples = opus_decode(dec[t], packet, plen+1, outbuf, MAX_FRAME_SAMP, 0);
|
cannam@154
|
346 if(out_samples!=expected)test_failed();
|
cannam@154
|
347 }
|
cannam@154
|
348 }
|
cannam@154
|
349 fprintf(stdout," dec[%3d] random packets, all mode pairs (4096)*10, %d bytes/frame OK.\n",t,plen+1);
|
cannam@154
|
350
|
cannam@154
|
351 {
|
cannam@154
|
352 int tmodes[1]={25<<2};
|
cannam@154
|
353 opus_uint32 tseeds[1]={140441};
|
cannam@154
|
354 int tlen[1]={157};
|
cannam@154
|
355 opus_int32 tret[1]={480};
|
cannam@154
|
356 t=fast_rand()&1;
|
cannam@154
|
357 for(i=0;i<1;i++)
|
cannam@154
|
358 {
|
cannam@154
|
359 int j;
|
cannam@154
|
360 packet[0]=tmodes[i];
|
cannam@154
|
361 Rw=Rz=tseeds[i];
|
cannam@154
|
362 for(j=1;j<tlen[i];j++)packet[j]=fast_rand()&255;
|
cannam@154
|
363 out_samples=opus_decode(dec[t], packet, tlen[i], outbuf, MAX_FRAME_SAMP, 0);
|
cannam@154
|
364 if(out_samples!=tret[i])test_failed();
|
cannam@154
|
365 }
|
cannam@154
|
366 fprintf(stdout," dec[%3d] pre-selected random packets OK.\n",t);
|
cannam@154
|
367 }
|
cannam@154
|
368
|
cannam@154
|
369 free(decbak);
|
cannam@154
|
370 for(t=0;t<5*2;t++)opus_decoder_destroy(dec[t]);
|
cannam@154
|
371 printf(" Decoders stopped.\n");
|
cannam@154
|
372
|
cannam@154
|
373 err=0;
|
cannam@154
|
374 for(i=0;i<8*2;i++)err|=outbuf_int[i]!=32749;
|
cannam@154
|
375 for(i=MAX_FRAME_SAMP*2;i<(MAX_FRAME_SAMP+8)*2;i++)err|=outbuf[i]!=32749;
|
cannam@154
|
376 if(err)test_failed();
|
cannam@154
|
377
|
cannam@154
|
378 free(outbuf_int);
|
cannam@154
|
379 free(packet);
|
cannam@154
|
380 return 0;
|
cannam@154
|
381 }
|
cannam@154
|
382
|
cannam@154
|
383 #ifndef DISABLE_FLOAT_API
|
cannam@154
|
384 void test_soft_clip(void)
|
cannam@154
|
385 {
|
cannam@154
|
386 int i,j;
|
cannam@154
|
387 float x[1024];
|
cannam@154
|
388 float s[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
cannam@154
|
389 fprintf(stdout," Testing opus_pcm_soft_clip... ");
|
cannam@154
|
390 for(i=0;i<1024;i++)
|
cannam@154
|
391 {
|
cannam@154
|
392 for (j=0;j<1024;j++)
|
cannam@154
|
393 {
|
cannam@154
|
394 x[j]=(j&255)*(1/32.f)-4.f;
|
cannam@154
|
395 }
|
cannam@154
|
396 opus_pcm_soft_clip(&x[i],1024-i,1,s);
|
cannam@154
|
397 for (j=i;j<1024;j++)
|
cannam@154
|
398 {
|
cannam@154
|
399 if(x[j]>1.f)test_failed();
|
cannam@154
|
400 if(x[j]<-1.f)test_failed();
|
cannam@154
|
401 }
|
cannam@154
|
402 }
|
cannam@154
|
403 for(i=1;i<9;i++)
|
cannam@154
|
404 {
|
cannam@154
|
405 for (j=0;j<1024;j++)
|
cannam@154
|
406 {
|
cannam@154
|
407 x[j]=(j&255)*(1/32.f)-4.f;
|
cannam@154
|
408 }
|
cannam@154
|
409 opus_pcm_soft_clip(x,1024/i,i,s);
|
cannam@154
|
410 for (j=0;j<(1024/i)*i;j++)
|
cannam@154
|
411 {
|
cannam@154
|
412 if(x[j]>1.f)test_failed();
|
cannam@154
|
413 if(x[j]<-1.f)test_failed();
|
cannam@154
|
414 }
|
cannam@154
|
415 }
|
cannam@154
|
416 opus_pcm_soft_clip(x,0,1,s);
|
cannam@154
|
417 opus_pcm_soft_clip(x,1,0,s);
|
cannam@154
|
418 opus_pcm_soft_clip(x,1,1,0);
|
cannam@154
|
419 opus_pcm_soft_clip(x,1,-1,s);
|
cannam@154
|
420 opus_pcm_soft_clip(x,-1,1,s);
|
cannam@154
|
421 opus_pcm_soft_clip(0,1,1,s);
|
cannam@154
|
422 printf("OK.\n");
|
cannam@154
|
423 }
|
cannam@154
|
424 #endif
|
cannam@154
|
425
|
cannam@154
|
426 int main(int _argc, char **_argv)
|
cannam@154
|
427 {
|
cannam@154
|
428 const char * oversion;
|
cannam@154
|
429 const char * env_seed;
|
cannam@154
|
430 int env_used;
|
cannam@154
|
431
|
cannam@154
|
432 if(_argc>2)
|
cannam@154
|
433 {
|
cannam@154
|
434 fprintf(stderr,"Usage: %s [<seed>]\n",_argv[0]);
|
cannam@154
|
435 return 1;
|
cannam@154
|
436 }
|
cannam@154
|
437
|
cannam@154
|
438 env_used=0;
|
cannam@154
|
439 env_seed=getenv("SEED");
|
cannam@154
|
440 if(_argc>1)iseed=atoi(_argv[1]);
|
cannam@154
|
441 else if(env_seed)
|
cannam@154
|
442 {
|
cannam@154
|
443 iseed=atoi(env_seed);
|
cannam@154
|
444 env_used=1;
|
cannam@154
|
445 }
|
cannam@154
|
446 else iseed=(opus_uint32)time(NULL)^(((opus_uint32)getpid()&65535)<<16);
|
cannam@154
|
447 Rw=Rz=iseed;
|
cannam@154
|
448
|
cannam@154
|
449 oversion=opus_get_version_string();
|
cannam@154
|
450 if(!oversion)test_failed();
|
cannam@154
|
451 fprintf(stderr,"Testing %s decoder. Random seed: %u (%.4X)\n", oversion, iseed, fast_rand() % 65535);
|
cannam@154
|
452 if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).\n", env_seed);
|
cannam@154
|
453
|
cannam@154
|
454 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data
|
cannam@154
|
455 into the decoders. This is helpful because garbage data
|
cannam@154
|
456 may cause the decoders to clip, which angers CLANG IOC.*/
|
cannam@154
|
457 test_decoder_code0(getenv("TEST_OPUS_NOFUZZ")!=NULL);
|
cannam@154
|
458 #ifndef DISABLE_FLOAT_API
|
cannam@154
|
459 test_soft_clip();
|
cannam@154
|
460 #endif
|
cannam@154
|
461
|
cannam@154
|
462 return 0;
|
cannam@154
|
463 }
|