Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: tests/test_opus_encode.c

Issue 107243004: Updating Opus to release 1.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/opus
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/test_opus_decode.c ('k') | tests/test_opus_padding.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2011-2013 Xiph.Org Foundation 1 /* Copyright (c) 2011-2013 Xiph.Org Foundation
2 Written by Gregory Maxwell */ 2 Written by Gregory Maxwell */
3 /* 3 /*
4 Redistribution and use in source and binary forms, with or without 4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions 5 modification, are permitted provided that the following conditions
6 are met: 6 are met:
7 7
8 - Redistributions of source code must retain the above copyright 8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer. 9 notice, this list of conditions and the following disclaimer.
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 #if 0 86 #if 0
87 static int save_ctr = 0; 87 static int save_ctr = 0;
88 static void int_to_char(opus_uint32 i, unsigned char ch[4]) 88 static void int_to_char(opus_uint32 i, unsigned char ch[4])
89 { 89 {
90 ch[0] = i>>24; 90 ch[0] = i>>24;
91 ch[1] = (i>>16)&0xFF; 91 ch[1] = (i>>16)&0xFF;
92 ch[2] = (i>>8)&0xFF; 92 ch[2] = (i>>8)&0xFF;
93 ch[3] = i&0xFF; 93 ch[3] = i&0xFF;
94 } 94 }
95 95
96 static inline void save_packet(unsigned char* p, int len, opus_uint32 rng) 96 static OPUS_INLINE void save_packet(unsigned char* p, int len, opus_uint32 rng)
97 { 97 {
98 FILE *fout; 98 FILE *fout;
99 unsigned char int_field[4]; 99 unsigned char int_field[4];
100 char name[256]; 100 char name[256];
101 snprintf(name,255,"test_opus_encode.%llu.%d.bit",(unsigned long long)iseed,sa ve_ctr); 101 snprintf(name,255,"test_opus_encode.%llu.%d.bit",(unsigned long long)iseed,sa ve_ctr);
102 fprintf(stdout,"writing %d byte packet to %s\n",len,name); 102 fprintf(stdout,"writing %d byte packet to %s\n",len,name);
103 fout=fopen(name, "wb+"); 103 fout=fopen(name, "wb+");
104 if(fout==NULL)test_failed(); 104 if(fout==NULL)test_failed();
105 int_to_char(len, int_field); 105 int_to_char(len, int_field);
106 fwrite(int_field, 1, 4, fout); 106 fwrite(int_field, 1, 4, fout);
(...skipping 16 matching lines...) Expand all
123 OpusEncoder *enc; 123 OpusEncoder *enc;
124 OpusMSEncoder *MSenc; 124 OpusMSEncoder *MSenc;
125 OpusDecoder *dec; 125 OpusDecoder *dec;
126 OpusMSDecoder *MSdec; 126 OpusMSDecoder *MSdec;
127 OpusMSDecoder *MSdec_err; 127 OpusMSDecoder *MSdec_err;
128 OpusDecoder *dec_err[10]; 128 OpusDecoder *dec_err[10];
129 short *inbuf; 129 short *inbuf;
130 short *outbuf; 130 short *outbuf;
131 short *out2buf; 131 short *out2buf;
132 opus_int32 bitrate_bps; 132 opus_int32 bitrate_bps;
133 unsigned char packet[MAX_PACKET]; 133 unsigned char packet[MAX_PACKET+257];
134 opus_uint32 enc_final_range; 134 opus_uint32 enc_final_range;
135 opus_uint32 dec_final_range; 135 opus_uint32 dec_final_range;
136 int fswitch; 136 int fswitch;
137 int fsize; 137 int fsize;
138 int count; 138 int count;
139 139
140 /*FIXME: encoder api tests, fs!=48k, mono, VBR*/ 140 /*FIXME: encoder api tests, fs!=48k, mono, VBR*/
141 141
142 fprintf(stdout," Encode+Decode tests.\n"); 142 fprintf(stdout," Encode+Decode tests.\n");
143 143
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 { 240 {
241 int rate; 241 int rate;
242 int modes[13]={0,0,0,1,1,1,1,2,2,2,2,2,2}; 242 int modes[13]={0,0,0,1,1,1,1,2,2,2,2,2,2};
243 int rates[13]={6000,12000,48000,16000,32000,48000,64000,512000,13000,24 000,48000,64000,96000}; 243 int rates[13]={6000,12000,48000,16000,32000,48000,64000,512000,13000,24 000,48000,64000,96000};
244 int frame[13]={960*2,960,480,960,960,960,480,960*3,960*3,960,480,240,12 0}; 244 int frame[13]={960*2,960,480,960,960,960,480,960*3,960*3,960,480,240,12 0};
245 rate=rates[j]+fast_rand()%rates[j]; 245 rate=rates[j]+fast_rand()%rates[j];
246 count=i=0; 246 count=i=0;
247 do { 247 do {
248 int bw,len,out_samples,frame_size; 248 int bw,len,out_samples,frame_size;
249 frame_size=frame[j]; 249 frame_size=frame[j];
250 if(fast_rand()%100==0)opus_encoder_ctl(enc, OPUS_RESET_STATE); 250 if((fast_rand()&255)==0)
251 {
252 if(opus_encoder_ctl(enc, OPUS_RESET_STATE)!=OPUS_OK)test_failed() ;
253 if(opus_decoder_ctl(dec, OPUS_RESET_STATE)!=OPUS_OK)test_failed() ;
254 if((fast_rand()&1)!=0)
255 {
256 if(opus_decoder_ctl(dec_err[fast_rand()&1], OPUS_RESET_STATE)! =OPUS_OK)test_failed();
257 }
258 }
259 if((fast_rand()&127)==0)
260 {
261 if(opus_decoder_ctl(dec_err[fast_rand()&1], OPUS_RESET_STATE)!=OP US_OK)test_failed();
262 }
251 if(fast_rand()%10==0){ 263 if(fast_rand()%10==0){
252 int complex=fast_rand()%11; 264 int complex=fast_rand()%11;
253 if(opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complex))!=OPUS_OK)t est_failed(); 265 if(opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complex))!=OPUS_OK)t est_failed();
254 } 266 }
255 if(fast_rand()%50==0)opus_decoder_ctl(dec, OPUS_RESET_STATE); 267 if(fast_rand()%50==0)opus_decoder_ctl(dec, OPUS_RESET_STATE);
256 if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(rc==0))!=OPUS_OK)test_f ailed(); 268 if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(rc==0))!=OPUS_OK)test_f ailed();
257 if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(MODE_SILK_ONLY+modes[j] ))!=OPUS_OK)test_failed(); 269 if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(MODE_SILK_ONLY+modes[j] ))!=OPUS_OK)test_failed();
258 if(opus_encoder_ctl(enc, OPUS_SET_DTX(fast_rand()&1))!=OPUS_OK)test_ failed(); 270 if(opus_encoder_ctl(enc, OPUS_SET_DTX(fast_rand()&1))!=OPUS_OK)test_ failed();
259 if(opus_encoder_ctl(enc, OPUS_SET_BITRATE(rate))!=OPUS_OK)test_faile d(); 271 if(opus_encoder_ctl(enc, OPUS_SET_BITRATE(rate))!=OPUS_OK)test_faile d();
260 if(opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS((rates[j]>=64000?2: 1)))!=OPUS_OK)test_failed(); 272 if(opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS((rates[j]>=64000?2: 1)))!=OPUS_OK)test_failed();
261 if(opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY((count>>2)%11))!=OPUS_O K)test_failed(); 273 if(opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY((count>>2)%11))!=OPUS_O K)test_failed();
262 if(opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC((fast_rand()&15)& (fast_rand()%15)))!=OPUS_OK)test_failed(); 274 if(opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC((fast_rand()&15)& (fast_rand()%15)))!=OPUS_OK)test_failed();
263 bw=modes[j]==0?OPUS_BANDWIDTH_NARROWBAND+(fast_rand()%3): 275 bw=modes[j]==0?OPUS_BANDWIDTH_NARROWBAND+(fast_rand()%3):
264 modes[j]==1?OPUS_BANDWIDTH_SUPERWIDEBAND+(fast_rand()&1): 276 modes[j]==1?OPUS_BANDWIDTH_SUPERWIDEBAND+(fast_rand()&1):
265 OPUS_BANDWIDTH_NARROWBAND+(fast_rand()%5); 277 OPUS_BANDWIDTH_NARROWBAND+(fast_rand()%5);
266 if(modes[j]==2&&bw==OPUS_BANDWIDTH_MEDIUMBAND)bw+=3; 278 if(modes[j]==2&&bw==OPUS_BANDWIDTH_MEDIUMBAND)bw+=3;
267 if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bw))!=OPUS_OK)test_faile d(); 279 if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bw))!=OPUS_OK)test_faile d();
268 len = opus_encode(enc, &inbuf[i<<1], frame_size, packet, MAX_PACKET) ; 280 len = opus_encode(enc, &inbuf[i<<1], frame_size, packet, MAX_PACKET) ;
269 if(len<0 || len>MAX_PACKET)test_failed(); 281 if(len<0 || len>MAX_PACKET)test_failed();
270 if(opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OP US_OK)test_failed(); 282 if(opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OP US_OK)test_failed();
283 if((fast_rand()&3)==0)
284 {
285 if(opus_packet_pad(packet,len,len+1)!=OPUS_OK)test_failed();
286 len++;
287 }
288 if((fast_rand()&7)==0)
289 {
290 if(opus_packet_pad(packet,len,len+256)!=OPUS_OK)test_failed();
291 len+=256;
292 }
293 if((fast_rand()&3)==0)
294 {
295 len=opus_packet_unpad(packet,len);
296 if(len<1)test_failed();
297 }
271 out_samples = opus_decode(dec, packet, len, &outbuf[i<<1], MAX_FRAME _SAMP, 0); 298 out_samples = opus_decode(dec, packet, len, &outbuf[i<<1], MAX_FRAME _SAMP, 0);
272 if(out_samples!=frame_size)test_failed(); 299 if(out_samples!=frame_size)test_failed();
273 if(opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OP US_OK)test_failed(); 300 if(opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OP US_OK)test_failed();
274 if(enc_final_range!=dec_final_range)test_failed(); 301 if(enc_final_range!=dec_final_range)test_failed();
275 /*LBRR decode*/ 302 /*LBRR decode*/
276 out_samples = opus_decode(dec_err[0], packet, len, out2buf, frame_si ze, (fast_rand()&3)!=0); 303 out_samples = opus_decode(dec_err[0], packet, len, out2buf, frame_si ze, (fast_rand()&3)!=0);
277 if(out_samples!=frame_size)test_failed(); 304 if(out_samples!=frame_size)test_failed();
278 out_samples = opus_decode(dec_err[1], packet, (fast_rand()&3)==0?0:l en, out2buf, MAX_FRAME_SAMP, (fast_rand()&7)!=0); 305 out_samples = opus_decode(dec_err[1], packet, (fast_rand()&3)==0?0:l en, out2buf, MAX_FRAME_SAMP, (fast_rand()&7)!=0);
279 if(out_samples<120)test_failed(); 306 if(out_samples<120)test_failed();
280 i+=frame_size; 307 i+=frame_size;
(...skipping 20 matching lines...) Expand all
301 int modes[16]={0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2}; 328 int modes[16]={0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2};
302 int rates[16]={4000,12000,32000,8000,16000,32000,48000,88000,4000,12000 ,32000,8000,16000,32000,48000,88000}; 329 int rates[16]={4000,12000,32000,8000,16000,32000,48000,88000,4000,12000 ,32000,8000,16000,32000,48000,88000};
303 int frame[16]={160*1,160,80,160,160,80,40,20,160*1,160,80,160,160,80,40 ,20}; 330 int frame[16]={160*1,160,80,160,160,80,40,20,160*1,160,80,160,160,80,40 ,20};
304 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_INBAND_FEC(rc==0&&j==1) )!=OPUS_OK)test_failed(); 331 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_INBAND_FEC(rc==0&&j==1) )!=OPUS_OK)test_failed();
305 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_FORCE_MODE(MODE_SILK_ON LY+modes[j]))!=OPUS_OK)test_failed(); 332 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_FORCE_MODE(MODE_SILK_ON LY+modes[j]))!=OPUS_OK)test_failed();
306 rate=rates[j]+fast_rand()%rates[j]; 333 rate=rates[j]+fast_rand()%rates[j];
307 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_DTX(fast_rand()&1))!=OP US_OK)test_failed(); 334 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_DTX(fast_rand()&1))!=OP US_OK)test_failed();
308 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_BITRATE(rate))!=OPUS_OK )test_failed(); 335 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_BITRATE(rate))!=OPUS_OK )test_failed();
309 count=i=0; 336 count=i=0;
310 do { 337 do {
311 int len,out_samples,frame_size,loss; 338 int pred,len,out_samples,frame_size,loss;
339 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_PREDICTION_DISABLED( &pred))!=OPUS_OK)test_failed();
340 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PREDICTION_DISABLED( (int)(fast_rand()&15)<(pred?11:4)))!=OPUS_OK)test_failed();
312 frame_size=frame[j]; 341 frame_size=frame[j];
313 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_COMPLEXITY((count>>2 )%11))!=OPUS_OK)test_failed(); 342 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_COMPLEXITY((count>>2 )%11))!=OPUS_OK)test_failed();
314 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PACKET_LOSS_PERC((fa st_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed(); 343 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PACKET_LOSS_PERC((fa st_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed();
344 if((fast_rand()&255)==0)
345 {
346 if(opus_multistream_encoder_ctl(MSenc, OPUS_RESET_STATE)!=OPUS_OK )test_failed();
347 if(opus_multistream_decoder_ctl(MSdec, OPUS_RESET_STATE)!=OPUS_OK )test_failed();
348 if((fast_rand()&3)!=0)
349 {
350 if(opus_multistream_decoder_ctl(MSdec_err, OPUS_RESET_STATE)!= OPUS_OK)test_failed();
351 }
352 }
353 if((fast_rand()&255)==0)
354 {
355 if(opus_multistream_decoder_ctl(MSdec_err, OPUS_RESET_STATE)!=OPU S_OK)test_failed();
356 }
315 len = opus_multistream_encode(MSenc, &inbuf[i<<1], frame_size, packe t, MAX_PACKET); 357 len = opus_multistream_encode(MSenc, &inbuf[i<<1], frame_size, packe t, MAX_PACKET);
316 if(len<0 || len>MAX_PACKET)test_failed(); 358 if(len<0 || len>MAX_PACKET)test_failed();
317 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_FINAL_RANGE(&enc_fin al_range))!=OPUS_OK)test_failed(); 359 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_FINAL_RANGE(&enc_fin al_range))!=OPUS_OK)test_failed();
360 if((fast_rand()&3)==0)
361 {
362 if(opus_multistream_packet_pad(packet,len,len+1,2)!=OPUS_OK)test_ failed();
363 len++;
364 }
365 if((fast_rand()&7)==0)
366 {
367 if(opus_multistream_packet_pad(packet,len,len+256,2)!=OPUS_OK)tes t_failed();
368 len+=256;
369 }
370 if((fast_rand()&3)==0)
371 {
372 len=opus_multistream_packet_unpad(packet,len,2);
373 if(len<1)test_failed();
374 }
318 out_samples = opus_multistream_decode(MSdec, packet, len, out2buf, M AX_FRAME_SAMP, 0); 375 out_samples = opus_multistream_decode(MSdec, packet, len, out2buf, M AX_FRAME_SAMP, 0);
319 if(out_samples!=frame_size*6)test_failed(); 376 if(out_samples!=frame_size*6)test_failed();
320 if(opus_multistream_decoder_ctl(MSdec, OPUS_GET_FINAL_RANGE(&dec_fin al_range))!=OPUS_OK)test_failed(); 377 if(opus_multistream_decoder_ctl(MSdec, OPUS_GET_FINAL_RANGE(&dec_fin al_range))!=OPUS_OK)test_failed();
321 if(enc_final_range!=dec_final_range)test_failed(); 378 if(enc_final_range!=dec_final_range)test_failed();
322 /*LBRR decode*/ 379 /*LBRR decode*/
323 loss=(fast_rand()&63)==0; 380 loss=(fast_rand()&63)==0;
324 out_samples = opus_multistream_decode(MSdec_err, packet, loss?0:len, out2buf, frame_size*6, (fast_rand()&3)!=0); 381 out_samples = opus_multistream_decode(MSdec_err, packet, loss?0:len, out2buf, frame_size*6, (fast_rand()&3)!=0);
325 if(out_samples!=(frame_size*6))test_failed(); 382 if(out_samples!=(frame_size*6))test_failed();
326 i+=frame_size; 383 i+=frame_size;
327 count++; 384 count++;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 fsize=(fsize+1)%36; 447 fsize=(fsize+1)%36;
391 new_size=fsizes[db62[fsize]]; 448 new_size=fsizes[db62[fsize]];
392 if(new_size==960||new_size==480)fswitch=2880/new_size*(fast_rand()%19+1) ; 449 if(new_size==960||new_size==480)fswitch=2880/new_size*(fast_rand()%19+1) ;
393 else fswitch=(fast_rand()%(2880/new_size))+1; 450 else fswitch=(fast_rand()%(2880/new_size))+1;
394 } 451 }
395 bitrate_bps=((fast_rand()%508000+4000)+bitrate_bps)>>1; 452 bitrate_bps=((fast_rand()%508000+4000)+bitrate_bps)>>1;
396 i+=frame_size; 453 i+=frame_size;
397 }while(i<SAMPLES*4); 454 }while(i<SAMPLES*4);
398 fprintf(stdout," All framesize pairs switching encode, %d frames OK.\n",co unt); 455 fprintf(stdout," All framesize pairs switching encode, %d frames OK.\n",co unt);
399 456
457 if(opus_encoder_ctl(enc, OPUS_RESET_STATE)!=OPUS_OK)test_failed();
400 opus_encoder_destroy(enc); 458 opus_encoder_destroy(enc);
459 if(opus_multistream_encoder_ctl(MSenc, OPUS_RESET_STATE)!=OPUS_OK)test_failed ();
401 opus_multistream_encoder_destroy(MSenc); 460 opus_multistream_encoder_destroy(MSenc);
461 if(opus_decoder_ctl(dec, OPUS_RESET_STATE)!=OPUS_OK)test_failed();
402 opus_decoder_destroy(dec); 462 opus_decoder_destroy(dec);
463 if(opus_multistream_decoder_ctl(MSdec, OPUS_RESET_STATE)!=OPUS_OK)test_failed ();
403 opus_multistream_decoder_destroy(MSdec); 464 opus_multistream_decoder_destroy(MSdec);
404 opus_multistream_decoder_destroy(MSdec_err); 465 opus_multistream_decoder_destroy(MSdec_err);
405 for(i=0;i<10;i++)opus_decoder_destroy(dec_err[i]); 466 for(i=0;i<10;i++)opus_decoder_destroy(dec_err[i]);
406 free(inbuf); 467 free(inbuf);
407 free(outbuf); 468 free(outbuf);
408 free(out2buf); 469 free(out2buf);
409 return 0; 470 return 0;
410 } 471 }
411 472
412 int main(int _argc, char **_argv) 473 int main(int _argc, char **_argv)
(...skipping 26 matching lines...) Expand all
439 500
440 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data 501 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data
441 into the decoders. This is helpful because garbage data 502 into the decoders. This is helpful because garbage data
442 may cause the decoders to clip, which angers CLANG IOC.*/ 503 may cause the decoders to clip, which angers CLANG IOC.*/
443 run_test1(getenv("TEST_OPUS_NOFUZZ")!=NULL); 504 run_test1(getenv("TEST_OPUS_NOFUZZ")!=NULL);
444 505
445 fprintf(stderr,"Tests completed successfully.\n"); 506 fprintf(stderr,"Tests completed successfully.\n");
446 507
447 return 0; 508 return 0;
448 } 509 }
OLDNEW
« no previous file with comments | « tests/test_opus_decode.c ('k') | tests/test_opus_padding.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698