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

Side by Side Diff: tests/test_opus_encode.c

Issue 12388030: Update Opus to 1.0.2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/opus
Patch Set: Created 7 years, 9 months 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') | version.mk » ('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 Xiph.Org Foundation 1 /* Copyright (c) 2011 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 20 matching lines...) Expand all
31 31
32 #include <stdio.h> 32 #include <stdio.h>
33 #include <stdlib.h> 33 #include <stdlib.h>
34 #include <limits.h> 34 #include <limits.h>
35 #include <stdint.h> 35 #include <stdint.h>
36 #include <math.h> 36 #include <math.h>
37 #include <string.h> 37 #include <string.h>
38 #include <time.h> 38 #include <time.h>
39 #if (!defined WIN32 && !defined _WIN32) || defined(__MINGW32__) 39 #if (!defined WIN32 && !defined _WIN32) || defined(__MINGW32__)
40 #include <unistd.h> 40 #include <unistd.h>
41 #else
42 #include <process.h>
43 #define getpid _getpid
41 #endif 44 #endif
42 #include "opus_multistream.h" 45 #include "opus_multistream.h"
43 #include "opus.h" 46 #include "opus.h"
44 #include "../src/opus_private.h" 47 #include "../src/opus_private.h"
45 #include "test_opus_common.h" 48 #include "test_opus_common.h"
46 49
47 #define MAX_PACKET (1500) 50 #define MAX_PACKET (1500)
48 #define SAMPLES (48000*30) 51 #define SAMPLES (48000*30)
49 #define SSAMPLES (SAMPLES/3) 52 #define SSAMPLES (SAMPLES/3)
50 #define MAX_FRAME_SAMP (5760) 53 #define MAX_FRAME_SAMP (5760)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 int fsize; 137 int fsize;
135 int count; 138 int count;
136 139
137 /*FIXME: encoder api tests, fs!=48k, mono, VBR*/ 140 /*FIXME: encoder api tests, fs!=48k, mono, VBR*/
138 141
139 fprintf(stdout," Encode+Decode tests.\n"); 142 fprintf(stdout," Encode+Decode tests.\n");
140 143
141 enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &err); 144 enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &err);
142 if(err != OPUS_OK || enc==NULL)test_failed(); 145 if(err != OPUS_OK || enc==NULL)test_failed();
143 146
147 for(i=0;i<2;i++)
148 {
149 int *ret_err;
150 ret_err = i?0:&err;
151 MSenc = opus_multistream_encoder_create(8000, 2, 2, 0, mapping, OPUS_UNIMP LEMENTED, ret_err);
152 if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
153
154 MSenc = opus_multistream_encoder_create(8000, 0, 1, 0, mapping, OPUS_APPLI CATION_VOIP, ret_err);
155 if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
156
157 MSenc = opus_multistream_encoder_create(44100, 2, 2, 0, mapping, OPUS_APPL ICATION_VOIP, ret_err);
158 if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
159
160 MSenc = opus_multistream_encoder_create(8000, 2, 2, 3, mapping, OPUS_APPLI CATION_VOIP, ret_err);
161 if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
162
163 MSenc = opus_multistream_encoder_create(8000, 2, -1, 0, mapping, OPUS_APPL ICATION_VOIP, ret_err);
164 if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
165
166 MSenc = opus_multistream_encoder_create(8000, 256, 2, 0, mapping, OPUS_APP LICATION_VOIP, ret_err);
167 if((ret_err && *ret_err != OPUS_BAD_ARG) || MSenc!=NULL)test_failed();
168 }
169
144 MSenc = opus_multistream_encoder_create(8000, 2, 2, 0, mapping, OPUS_APPLICAT ION_AUDIO, &err); 170 MSenc = opus_multistream_encoder_create(8000, 2, 2, 0, mapping, OPUS_APPLICAT ION_AUDIO, &err);
145 if(err != OPUS_OK || MSenc==NULL)test_failed(); 171 if(err != OPUS_OK || MSenc==NULL)test_failed();
146 172
173 /*Some multistream encoder API tests*/
147 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_BITRATE(&i))!=OPUS_OK)test_fa iled(); 174 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_BITRATE(&i))!=OPUS_OK)test_fa iled();
148 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_LSB_DEPTH(&i))!=OPUS_OK)test_ failed(); 175 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_LSB_DEPTH(&i))!=OPUS_OK)test_ failed();
176 if(i<16)test_failed();
177
178 {
179 OpusEncoder *tmp_enc;
180 if(opus_multistream_encoder_ctl(MSenc, OPUS_MULTISTREAM_GET_ENCODER_STATE (1,&tmp_enc))!=OPUS_OK)test_failed();
181 if(opus_encoder_ctl(tmp_enc, OPUS_GET_LSB_DEPTH(&j))!=OPUS_OK)test_failed( );
182 if(i!=j)test_failed();
183 if(opus_multistream_encoder_ctl(MSenc, OPUS_MULTISTREAM_GET_ENCODER_STATE (2,&tmp_enc))!=OPUS_BAD_ARG)test_failed();
184 }
149 185
150 dec = opus_decoder_create(48000, 2, &err); 186 dec = opus_decoder_create(48000, 2, &err);
151 if(err != OPUS_OK || dec==NULL)test_failed(); 187 if(err != OPUS_OK || dec==NULL)test_failed();
152 188
153 MSdec = opus_multistream_decoder_create(48000, 2, 2, 0, mapping, &err); 189 MSdec = opus_multistream_decoder_create(48000, 2, 2, 0, mapping, &err);
154 if(err != OPUS_OK || MSdec==NULL)test_failed(); 190 if(err != OPUS_OK || MSdec==NULL)test_failed();
155 191
156 MSdec_err = opus_multistream_decoder_create(48000, 3, 2, 0, mapping, &err); 192 MSdec_err = opus_multistream_decoder_create(48000, 3, 2, 0, mapping, &err);
157 if(err != OPUS_OK || MSdec_err==NULL)test_failed(); 193 if(err != OPUS_OK || MSdec_err==NULL)test_failed();
158 194
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if(modes[j]==2&&bw==OPUS_BANDWIDTH_MEDIUMBAND)bw+=3; 262 if(modes[j]==2&&bw==OPUS_BANDWIDTH_MEDIUMBAND)bw+=3;
227 if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bw))!=OPUS_OK)test_faile d(); 263 if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bw))!=OPUS_OK)test_faile d();
228 len = opus_encode(enc, &inbuf[i<<1], frame_size, packet, MAX_PACKET) ; 264 len = opus_encode(enc, &inbuf[i<<1], frame_size, packet, MAX_PACKET) ;
229 if(len<0 || len>MAX_PACKET)test_failed(); 265 if(len<0 || len>MAX_PACKET)test_failed();
230 if(opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OP US_OK)test_failed(); 266 if(opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OP US_OK)test_failed();
231 out_samples = opus_decode(dec, packet, len, &outbuf[i<<1], MAX_FRAME _SAMP, 0); 267 out_samples = opus_decode(dec, packet, len, &outbuf[i<<1], MAX_FRAME _SAMP, 0);
232 if(out_samples!=frame_size)test_failed(); 268 if(out_samples!=frame_size)test_failed();
233 if(opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OP US_OK)test_failed(); 269 if(opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OP US_OK)test_failed();
234 if(enc_final_range!=dec_final_range)test_failed(); 270 if(enc_final_range!=dec_final_range)test_failed();
235 /*LBRR decode*/ 271 /*LBRR decode*/
236 out_samples = opus_decode(dec_err[0], packet, len, out2buf, MAX_FRAM E_SAMP, (fast_rand()&3)!=0); 272 out_samples = opus_decode(dec_err[0], packet, len, out2buf, frame_si ze, (fast_rand()&3)!=0);
237 if(out_samples!=frame_size)test_failed(); 273 if(out_samples!=frame_size)test_failed();
238 out_samples = opus_decode(dec_err[1], packet, (fast_rand()&3)==0?0:l en, out2buf, MAX_FRAME_SAMP, (fast_rand()&7)!=0); 274 out_samples = opus_decode(dec_err[1], packet, (fast_rand()&3)==0?0:l en, out2buf, MAX_FRAME_SAMP, (fast_rand()&7)!=0);
239 if(out_samples<120)test_failed(); 275 if(out_samples<120)test_failed();
240 i+=frame_size; 276 i+=frame_size;
241 count++; 277 count++;
242 }while(i<(SSAMPLES-MAX_FRAME_SAMP)); 278 }while(i<(SSAMPLES-MAX_FRAME_SAMP));
243 fprintf(stdout," Mode %s FB encode %s, %6d bps OK.\n",mstrings[modes [j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate); 279 fprintf(stdout," Mode %s FB encode %s, %6d bps OK.\n",mstrings[modes [j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate);
244 } 280 }
245 } 281 }
246 282
(...skipping 27 matching lines...) Expand all
274 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PACKET_LOSS_PERC((fa st_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed(); 310 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PACKET_LOSS_PERC((fa st_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed();
275 len = opus_multistream_encode(MSenc, &inbuf[i<<1], frame_size, packe t, MAX_PACKET); 311 len = opus_multistream_encode(MSenc, &inbuf[i<<1], frame_size, packe t, MAX_PACKET);
276 if(len<0 || len>MAX_PACKET)test_failed(); 312 if(len<0 || len>MAX_PACKET)test_failed();
277 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_FINAL_RANGE(&enc_fin al_range))!=OPUS_OK)test_failed(); 313 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_FINAL_RANGE(&enc_fin al_range))!=OPUS_OK)test_failed();
278 out_samples = opus_multistream_decode(MSdec, packet, len, out2buf, M AX_FRAME_SAMP, 0); 314 out_samples = opus_multistream_decode(MSdec, packet, len, out2buf, M AX_FRAME_SAMP, 0);
279 if(out_samples!=frame_size*6)test_failed(); 315 if(out_samples!=frame_size*6)test_failed();
280 if(opus_multistream_decoder_ctl(MSdec, OPUS_GET_FINAL_RANGE(&dec_fin al_range))!=OPUS_OK)test_failed(); 316 if(opus_multistream_decoder_ctl(MSdec, OPUS_GET_FINAL_RANGE(&dec_fin al_range))!=OPUS_OK)test_failed();
281 if(enc_final_range!=dec_final_range)test_failed(); 317 if(enc_final_range!=dec_final_range)test_failed();
282 /*LBRR decode*/ 318 /*LBRR decode*/
283 loss=(fast_rand()&63)==0; 319 loss=(fast_rand()&63)==0;
284 out_samples = opus_multistream_decode(MSdec_err, packet, loss?0:len, out2buf, MAX_FRAME_SAMP, (fast_rand()&3)!=0); 320 out_samples = opus_multistream_decode(MSdec_err, packet, loss?0:len, out2buf, frame_size*6, (fast_rand()&3)!=0);
285 if(loss?out_samples<120:out_samples!=(frame_size*6))test_failed(); 321 if(out_samples!=(frame_size*6))test_failed();
286 i+=frame_size; 322 i+=frame_size;
287 count++; 323 count++;
288 }while(i<(SSAMPLES/12-MAX_FRAME_SAMP)); 324 }while(i<(SSAMPLES/12-MAX_FRAME_SAMP));
289 fprintf(stdout," Mode %s NB dual-mono MS encode %s, %6d bps OK.\n",m strings[modes[j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate); 325 fprintf(stdout," Mode %s NB dual-mono MS encode %s, %6d bps OK.\n",m strings[modes[j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate);
290 } 326 }
291 } 327 }
292 328
293 bitrate_bps=512000; 329 bitrate_bps=512000;
294 fsize=fast_rand()%31; 330 fsize=fast_rand()%31;
295 fswitch=100; 331 fswitch=100;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 435
400 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data 436 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data
401 into the decoders. This is helpful because garbage data 437 into the decoders. This is helpful because garbage data
402 may cause the decoders to clip, which angers CLANG IOC.*/ 438 may cause the decoders to clip, which angers CLANG IOC.*/
403 run_test1(getenv("TEST_OPUS_NOFUZZ")!=NULL); 439 run_test1(getenv("TEST_OPUS_NOFUZZ")!=NULL);
404 440
405 fprintf(stderr,"Tests completed successfully.\n"); 441 fprintf(stderr,"Tests completed successfully.\n");
406 442
407 return 0; 443 return 0;
408 } 444 }
OLDNEW
« no previous file with comments | « tests/test_opus_decode.c ('k') | version.mk » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698