Chris@69: /* Copyright (c) 2007-2011 Xiph.Org Foundation, Mozilla Corporation, Chris@69: Gregory Maxwell Chris@69: Written by Jean-Marc Valin, Gregory Maxwell, and Timothy B. Terriberry */ Chris@69: /* Chris@69: Redistribution and use in source and binary forms, with or without Chris@69: modification, are permitted provided that the following conditions Chris@69: are met: Chris@69: Chris@69: - Redistributions of source code must retain the above copyright Chris@69: notice, this list of conditions and the following disclaimer. Chris@69: Chris@69: - Redistributions in binary form must reproduce the above copyright Chris@69: notice, this list of conditions and the following disclaimer in the Chris@69: documentation and/or other materials provided with the distribution. Chris@69: Chris@69: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@69: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT Chris@69: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR Chris@69: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER Chris@69: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@69: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@69: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR Chris@69: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF Chris@69: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING Chris@69: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS Chris@69: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@69: */ Chris@69: Chris@69: #ifdef HAVE_CONFIG_H Chris@69: #include "config.h" Chris@69: #endif Chris@69: Chris@69: #include Chris@69: #include Chris@69: #include Chris@69: #include Chris@69: #define CELT_C Chris@69: #include "entcode.h" Chris@69: #include "entenc.h" Chris@69: #include "entdec.h" Chris@69: #include Chris@69: Chris@69: #include "entenc.c" Chris@69: #include "entdec.c" Chris@69: #include "entcode.c" Chris@69: Chris@69: #ifndef M_LOG2E Chris@69: # define M_LOG2E 1.4426950408889634074 Chris@69: #endif Chris@69: #define DATA_SIZE 10000000 Chris@69: #define DATA_SIZE2 10000 Chris@69: Chris@69: int main(int _argc,char **_argv){ Chris@69: ec_enc enc; Chris@69: ec_dec dec; Chris@69: long nbits; Chris@69: long nbits2; Chris@69: double entropy; Chris@69: int ft; Chris@69: int ftb; Chris@69: int sz; Chris@69: int i; Chris@69: int ret; Chris@69: unsigned int sym; Chris@69: unsigned int seed; Chris@69: unsigned char *ptr; Chris@69: const char *env_seed; Chris@69: ret=0; Chris@69: entropy=0; Chris@69: if (_argc > 2) { Chris@69: fprintf(stderr, "Usage: %s []\n", _argv[0]); Chris@69: return 1; Chris@69: } Chris@69: env_seed = getenv("SEED"); Chris@69: if (_argc > 1) Chris@69: seed = atoi(_argv[1]); Chris@69: else if (env_seed) Chris@69: seed = atoi(env_seed); Chris@69: else Chris@69: seed = time(NULL); Chris@69: /*Testing encoding of raw bit values.*/ Chris@69: ptr = (unsigned char *)malloc(DATA_SIZE); Chris@69: ec_enc_init(&enc,ptr, DATA_SIZE); Chris@69: for(ft=2;ft<1024;ft++){ Chris@69: for(i=0;i>(rand()%11U))+1U)+10; Chris@69: sz=rand()/((RAND_MAX>>(rand()%9U))+1U); Chris@69: data=(unsigned *)malloc(sz*sizeof(*data)); Chris@69: tell=(unsigned *)malloc((sz+1)*sizeof(*tell)); Chris@69: ec_enc_init(&enc,ptr,DATA_SIZE2); Chris@69: zeros = rand()%13==0; Chris@69: tell[0]=ec_tell_frac(&enc); Chris@69: for(j=0;j>(rand()%9U))+1U); Chris@69: logp1=(unsigned *)malloc(sz*sizeof(*logp1)); Chris@69: data=(unsigned *)malloc(sz*sizeof(*data)); Chris@69: tell=(unsigned *)malloc((sz+1)*sizeof(*tell)); Chris@69: enc_method=(unsigned *)malloc(sz*sizeof(*enc_method)); Chris@69: ec_enc_init(&enc,ptr,DATA_SIZE2); Chris@69: tell[0]=ec_tell_frac(&enc); Chris@69: for(j=0;j>1)+1); Chris@69: logp1[j]=(rand()%15)+1; Chris@69: enc_method[j]=rand()/((RAND_MAX>>2)+1); Chris@69: switch(enc_method[j]){ Chris@69: case 0:{ Chris@69: ec_encode(&enc,data[j]?(1<>2)+1); Chris@69: switch(dec_method){ Chris@69: case 0:{ Chris@69: fs=ec_decode(&dec,1<=(1<=(1<