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