Implemented "raw bits"
Making it so all the information encoded directly with ec_enc_bits() gets
stored at the end of the stream, without going through the range coder. This
should be both faster and reduce the effects of bit errors.
Conflicts:
tests/ectest.c
diff --git a/tests/ectest.c b/tests/ectest.c
index e861dfb..397a29e 100644
--- a/tests/ectest.c
+++ b/tests/ectest.c
@@ -11,6 +11,7 @@
#include "entcode.h"
#include "entenc.h"
#include "entdec.h"
+#include <string.h>
#include "../libcelt/rangeenc.c"
#include "../libcelt/rangedec.c"
@@ -21,6 +22,8 @@
#ifndef M_LOG2E
# define M_LOG2E 1.4426950408889634074
#endif
+#define DATA_SIZE 10000000
+#define DATA_SIZE2 10000
int main(int _argc,char **_argv){
ec_byte_buffer buf;
@@ -38,7 +41,7 @@
unsigned int seed;
ret=0;
entropy=0;
-
+ unsigned char *ptr;
if (_argc > 2) {
fprintf(stderr, "Usage: %s [<seed>]\n", _argv[0]);
return 1;
@@ -48,7 +51,8 @@
else
seed = (time(NULL) ^ (getpid()%(1<<16) << 16));
/*Testing encoding of raw bit values.*/
- ec_byte_writeinit(&buf);
+ ptr = malloc(DATA_SIZE);
+ ec_byte_writeinit_buffer(&buf, ptr, DATA_SIZE);
ec_enc_init(&enc,&buf);
for(ft=2;ft<1024;ft++){
for(i=0;i<ft;i++){
@@ -76,7 +80,7 @@
"Encoded %0.2lf bits of entropy to %0.2lf bits (%0.3lf%% wasted).\n",
entropy,ldexp(nbits,-4),100*(nbits-ldexp(entropy,4))/nbits);
fprintf(stderr,"Packed to %li bytes.\n",(long)(buf.ptr-buf.buf));
- ec_byte_readinit(&buf,ec_byte_get_buffer(&buf),ec_byte_bytes(&buf));
+ ec_byte_readinit(&buf,ptr,DATA_SIZE);
ec_dec_init(&dec,&buf);
for(ft=2;ft<1024;ft++){
for(i=0;i<ft;i++){
@@ -114,7 +118,7 @@
ft=rand()/((RAND_MAX>>(rand()%11))+1)+10;
sz=rand()/((RAND_MAX>>(rand()%9))+1);
data=(unsigned *)malloc(sz*sizeof(*data));
- ec_byte_writeinit(&buf);
+ ec_byte_writeinit_buffer(&buf, ptr, DATA_SIZE2);
ec_enc_init(&enc,&buf);
zeros = rand()%13==0;
for(j=0;j<sz;j++){
@@ -136,7 +140,7 @@
ret=-1;
}
tell_bits -= 8*ec_byte_bytes(&buf);
- ec_byte_readinit(&buf,ec_byte_get_buffer(&buf),ec_byte_bytes(&buf));
+ ec_byte_readinit(&buf,ptr,DATA_SIZE2);
ec_dec_init(&dec,&buf);
for(j=0;j<sz;j++){
sym=ec_dec_uint(&dec,ft);
@@ -150,5 +154,6 @@
ec_byte_writeclear(&buf);
free(data);
}
+ free(ptr);
return ret;
}