| OLD | NEW |
| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 decsize=opus_decoder_get_size(1); | 98 decsize=opus_decoder_get_size(1); |
| 99 decbak=(OpusDecoder *)malloc(decsize); | 99 decbak=(OpusDecoder *)malloc(decsize); |
| 100 if(decbak==NULL)test_failed(); | 100 if(decbak==NULL)test_failed(); |
| 101 | 101 |
| 102 for(t=0;t<5*2;t++) | 102 for(t=0;t<5*2;t++) |
| 103 { | 103 { |
| 104 int factor=48000/fsv[t>>1]; | 104 int factor=48000/fsv[t>>1]; |
| 105 for(fec=0;fec<2;fec++) | 105 for(fec=0;fec<2;fec++) |
| 106 { | 106 { |
| 107 int dur; | 107 opus_int32 dur; |
| 108 /*Test PLC on a fresh decoder*/ | 108 /*Test PLC on a fresh decoder*/ |
| 109 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor, fec); | 109 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor, fec); |
| 110 if(out_samples!=120/factor)test_failed(); | 110 if(out_samples!=120/factor)test_failed(); |
| 111 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_
OK)test_failed(); | 111 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_
OK)test_failed(); |
| 112 if(dur!=120/factor)test_failed(); | 112 if(dur!=120/factor)test_failed(); |
| 113 | 113 |
| 114 /*Test on a size which isn't a multiple of 2.5ms*/ | 114 /*Test on a size which isn't a multiple of 2.5ms*/ |
| 115 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor+2, fec); | 115 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor+2, fec); |
| 116 if(out_samples!=OPUS_BAD_ARG)test_failed(); | 116 if(out_samples!=OPUS_BAD_ARG)test_failed(); |
| 117 | 117 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 128 if(dur!=120/factor)test_failed(); | 128 if(dur!=120/factor)test_failed(); |
| 129 | 129 |
| 130 /*Zero lengths*/ | 130 /*Zero lengths*/ |
| 131 out_samples = opus_decode(dec[t], packet, 0, outbuf, 120/factor, fec); | 131 out_samples = opus_decode(dec[t], packet, 0, outbuf, 120/factor, fec); |
| 132 if(out_samples!=120/factor)test_failed(); | 132 if(out_samples!=120/factor)test_failed(); |
| 133 | 133 |
| 134 /*Zero buffer*/ | 134 /*Zero buffer*/ |
| 135 outbuf[0]=32749; | 135 outbuf[0]=32749; |
| 136 out_samples = opus_decode(dec[t], packet, 0, outbuf, 0, fec); | 136 out_samples = opus_decode(dec[t], packet, 0, outbuf, 0, fec); |
| 137 if(out_samples>0)test_failed(); | 137 if(out_samples>0)test_failed(); |
| 138 #if !defined(OPUS_BUILD) && (OPUS_GNUC_PREREQ(4, 6) || (defined(__clang_major__)
&& __clang_major__ >= 3)) |
| 139 #pragma GCC diagnostic push |
| 140 #pragma GCC diagnostic ignored "-Wnonnull" |
| 141 #endif |
| 138 out_samples = opus_decode(dec[t], packet, 0, 0, 0, fec); | 142 out_samples = opus_decode(dec[t], packet, 0, 0, 0, fec); |
| 143 #if !defined(OPUS_BUILD) && (OPUS_GNUC_PREREQ(4, 6) || (defined(__clang_major__)
&& __clang_major__ >= 3)) |
| 144 #pragma GCC diagnostic pop |
| 145 #endif |
| 139 if(out_samples>0)test_failed(); | 146 if(out_samples>0)test_failed(); |
| 140 if(outbuf[0]!=32749)test_failed(); | 147 if(outbuf[0]!=32749)test_failed(); |
| 141 | 148 |
| 142 /*Invalid lengths*/ | 149 /*Invalid lengths*/ |
| 143 out_samples = opus_decode(dec[t], packet, -1, outbuf, MAX_FRAME_SAMP, f
ec); | 150 out_samples = opus_decode(dec[t], packet, -1, outbuf, MAX_FRAME_SAMP, f
ec); |
| 144 if(out_samples>=0)test_failed(); | 151 if(out_samples>=0)test_failed(); |
| 145 out_samples = opus_decode(dec[t], packet, INT_MIN, outbuf, MAX_FRAME_SA
MP, fec); | 152 out_samples = opus_decode(dec[t], packet, INT_MIN, outbuf, MAX_FRAME_SA
MP, fec); |
| 146 if(out_samples>=0)test_failed(); | 153 if(out_samples>=0)test_failed(); |
| 147 out_samples = opus_decode(dec[t], packet, -1, outbuf, -1, fec); | 154 out_samples = opus_decode(dec[t], packet, -1, outbuf, -1, fec); |
| 148 if(out_samples>=0)test_failed(); | 155 if(out_samples>=0)test_failed(); |
| 149 | 156 |
| 150 /*Crazy FEC values*/ | 157 /*Crazy FEC values*/ |
| 151 out_samples = opus_decode(dec[t], packet, 1, outbuf, MAX_FRAME_SAMP, fe
c?-1:2); | 158 out_samples = opus_decode(dec[t], packet, 1, outbuf, MAX_FRAME_SAMP, fe
c?-1:2); |
| 152 if(out_samples>=0)test_failed(); | 159 if(out_samples>=0)test_failed(); |
| 153 | 160 |
| 154 /*Reset the decoder*/ | 161 /*Reset the decoder*/ |
| 155 if(opus_decoder_ctl(dec[t], OPUS_RESET_STATE)!=OPUS_OK)test_failed(); | 162 if(opus_decoder_ctl(dec[t], OPUS_RESET_STATE)!=OPUS_OK)test_failed(); |
| 156 } | 163 } |
| 157 } | 164 } |
| 158 fprintf(stdout," dec[all] initial frame PLC OK.\n"); | 165 fprintf(stdout," dec[all] initial frame PLC OK.\n"); |
| 159 | 166 |
| 160 /*Count code 0 tests*/ | 167 /*Count code 0 tests*/ |
| 161 for(i=0;i<64;i++) | 168 for(i=0;i<64;i++) |
| 162 { | 169 { |
| 163 int dur; | 170 opus_int32 dur; |
| 164 int j,expected[5*2]; | 171 int j,expected[5*2]; |
| 165 packet[0]=i<<2; | 172 packet[0]=i<<2; |
| 166 packet[1]=255; | 173 packet[1]=255; |
| 167 packet[2]=255; | 174 packet[2]=255; |
| 168 err=opus_packet_get_nb_channels(packet); | 175 err=opus_packet_get_nb_channels(packet); |
| 169 if(err!=(i&1)+1)test_failed(); | 176 if(err!=(i&1)+1)test_failed(); |
| 170 | 177 |
| 171 for(t=0;t<5*2;t++){ | 178 for(t=0;t<5*2;t++){ |
| 172 expected[t]=opus_decoder_get_nb_samples(dec[t],packet,1); | 179 expected[t]=opus_decoder_get_nb_samples(dec[t],packet,1); |
| 173 if(expected[t]>2880)test_failed(); | 180 if(expected[t]>2880)test_failed(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 for(t=0;t<5*2;t++)expected[t]=opus_decoder_get_nb_samples(dec[t],packet,pl
en); | 314 for(t=0;t<5*2;t++)expected[t]=opus_decoder_get_nb_samples(dec[t],packet,pl
en); |
| 308 for(j=0;j<plen;j++)packet[j+1]=(fast_rand()|fast_rand())&255; | 315 for(j=0;j<plen;j++)packet[j+1]=(fast_rand()|fast_rand())&255; |
| 309 memcpy(decbak,dec[0],decsize); | 316 memcpy(decbak,dec[0],decsize); |
| 310 if(opus_decode(decbak, packet, plen+1, outbuf, expected[0], 1)!=expected[0
])test_failed(); | 317 if(opus_decode(decbak, packet, plen+1, outbuf, expected[0], 1)!=expected[0
])test_failed(); |
| 311 memcpy(decbak,dec[0],decsize); | 318 memcpy(decbak,dec[0],decsize); |
| 312 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 1)<20)test_failed(); | 319 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 1)<20)test_failed(); |
| 313 memcpy(decbak,dec[0],decsize); | 320 memcpy(decbak,dec[0],decsize); |
| 314 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 0)<20)test_failed(); | 321 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 0)<20)test_failed(); |
| 315 for(t=0;t<5*2;t++) | 322 for(t=0;t<5*2;t++) |
| 316 { | 323 { |
| 317 int dur; | 324 opus_int32 dur; |
| 318 out_samples = opus_decode(dec[t], packet, plen+1, outbuf, MAX_FRAME_SAM
P, 0); | 325 out_samples = opus_decode(dec[t], packet, plen+1, outbuf, MAX_FRAME_SAM
P, 0); |
| 319 if(out_samples!=expected[t])test_failed(); | 326 if(out_samples!=expected[t])test_failed(); |
| 320 if(t==0)dec_final_range2=dec_final_range1; | 327 if(t==0)dec_final_range2=dec_final_range1; |
| 321 else if(dec_final_range1!=dec_final_range2)test_failed(); | 328 else if(dec_final_range1!=dec_final_range2)test_failed(); |
| 322 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_
OK)test_failed(); | 329 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_
OK)test_failed(); |
| 323 if(dur!=out_samples)test_failed(); | 330 if(dur!=out_samples)test_failed(); |
| 324 } | 331 } |
| 325 } | 332 } |
| 326 fprintf(stdout," dec[all] random packets, all mode pairs (4096), %d bytes/fr
ame OK.\n",plen+1); | 333 fprintf(stdout," dec[all] random packets, all mode pairs (4096), %d bytes/fr
ame OK.\n",plen+1); |
| 327 | 334 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 void test_soft_clip(void) | 384 void test_soft_clip(void) |
| 378 { | 385 { |
| 379 int i,j; | 386 int i,j; |
| 380 float x[1024]; | 387 float x[1024]; |
| 381 float s[8] = {0, 0, 0, 0, 0, 0, 0, 0}; | 388 float s[8] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 382 fprintf(stdout," Testing opus_pcm_soft_clip... "); | 389 fprintf(stdout," Testing opus_pcm_soft_clip... "); |
| 383 for(i=0;i<1024;i++) | 390 for(i=0;i<1024;i++) |
| 384 { | 391 { |
| 385 for (j=0;j<1024;j++) | 392 for (j=0;j<1024;j++) |
| 386 { | 393 { |
| 387 x[j]=(i&255)*(1/32.f)-4.f; | 394 x[j]=(j&255)*(1/32.f)-4.f; |
| 388 } | 395 } |
| 389 opus_pcm_soft_clip(&x[i],1024-i,1,s); | 396 opus_pcm_soft_clip(&x[i],1024-i,1,s); |
| 390 for (j=i;j<1024;j++) | 397 for (j=i;j<1024;j++) |
| 391 { | 398 { |
| 392 if(x[i]>1.f)test_failed(); | 399 if(x[j]>1.f)test_failed(); |
| 393 if(x[i]<-1.f)test_failed(); | 400 if(x[j]<-1.f)test_failed(); |
| 394 } | 401 } |
| 395 } | 402 } |
| 396 for(i=1;i<9;i++) | 403 for(i=1;i<9;i++) |
| 397 { | 404 { |
| 398 for (j=0;j<1024;j++) | 405 for (j=0;j<1024;j++) |
| 399 { | 406 { |
| 400 x[j]=(i&255)*(1/32.f)-4.f; | 407 x[j]=(j&255)*(1/32.f)-4.f; |
| 401 } | 408 } |
| 402 opus_pcm_soft_clip(x,1024/i,i,s); | 409 opus_pcm_soft_clip(x,1024/i,i,s); |
| 403 for (j=0;j<(1024/i)*i;j++) | 410 for (j=0;j<(1024/i)*i;j++) |
| 404 { | 411 { |
| 405 if(x[i]>1.f)test_failed(); | 412 if(x[j]>1.f)test_failed(); |
| 406 if(x[i]<-1.f)test_failed(); | 413 if(x[j]<-1.f)test_failed(); |
| 407 } | 414 } |
| 408 } | 415 } |
| 409 opus_pcm_soft_clip(x,0,1,s); | 416 opus_pcm_soft_clip(x,0,1,s); |
| 410 opus_pcm_soft_clip(x,1,0,s); | 417 opus_pcm_soft_clip(x,1,0,s); |
| 411 opus_pcm_soft_clip(x,1,1,0); | 418 opus_pcm_soft_clip(x,1,1,0); |
| 412 opus_pcm_soft_clip(x,1,-1,s); | 419 opus_pcm_soft_clip(x,1,-1,s); |
| 413 opus_pcm_soft_clip(x,-1,1,s); | 420 opus_pcm_soft_clip(x,-1,1,s); |
| 414 opus_pcm_soft_clip(0,1,1,s); | 421 opus_pcm_soft_clip(0,1,1,s); |
| 415 printf("OK.\n"); | 422 printf("OK.\n"); |
| 416 } | 423 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 429 } | 436 } |
| 430 | 437 |
| 431 env_used=0; | 438 env_used=0; |
| 432 env_seed=getenv("SEED"); | 439 env_seed=getenv("SEED"); |
| 433 if(_argc>1)iseed=atoi(_argv[1]); | 440 if(_argc>1)iseed=atoi(_argv[1]); |
| 434 else if(env_seed) | 441 else if(env_seed) |
| 435 { | 442 { |
| 436 iseed=atoi(env_seed); | 443 iseed=atoi(env_seed); |
| 437 env_used=1; | 444 env_used=1; |
| 438 } | 445 } |
| 439 else iseed=(opus_uint32)time(NULL)^((getpid()&65535)<<16); | 446 else iseed=(opus_uint32)time(NULL)^(((opus_uint32)getpid()&65535)<<16); |
| 440 Rw=Rz=iseed; | 447 Rw=Rz=iseed; |
| 441 | 448 |
| 442 oversion=opus_get_version_string(); | 449 oversion=opus_get_version_string(); |
| 443 if(!oversion)test_failed(); | 450 if(!oversion)test_failed(); |
| 444 fprintf(stderr,"Testing %s decoder. Random seed: %u (%.4X)\n", oversion, isee
d, fast_rand() % 65535); | 451 fprintf(stderr,"Testing %s decoder. Random seed: %u (%.4X)\n", oversion, isee
d, fast_rand() % 65535); |
| 445 if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).
\n", env_seed); | 452 if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).
\n", env_seed); |
| 446 | 453 |
| 447 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data | 454 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data |
| 448 into the decoders. This is helpful because garbage data | 455 into the decoders. This is helpful because garbage data |
| 449 may cause the decoders to clip, which angers CLANG IOC.*/ | 456 may cause the decoders to clip, which angers CLANG IOC.*/ |
| 450 test_decoder_code0(getenv("TEST_OPUS_NOFUZZ")!=NULL); | 457 test_decoder_code0(getenv("TEST_OPUS_NOFUZZ")!=NULL); |
| 451 #ifndef DISABLE_FLOAT_API | 458 #ifndef DISABLE_FLOAT_API |
| 452 test_soft_clip(); | 459 test_soft_clip(); |
| 453 #endif | 460 #endif |
| 454 | 461 |
| 455 return 0; | 462 return 0; |
| 456 } | 463 } |
| OLD | NEW |