ref: 789fc14163d662af0ec6b6f4841451fa8147da14
parent: 954fb110b913ef95430ec1c53816702a6be7e497
author: Jean-Marc Valin <[email protected]>
date: Fri Oct 23 17:44:54 EDT 2009
Removing unused code in the entropy coder
--- a/libcelt/entcode.h
+++ b/libcelt/entcode.h
@@ -57,7 +57,6 @@
unsigned char *ptr;
unsigned char *end_ptr;
long storage;
- int resizable;
};
/*Encoding functions.*/
--- a/libcelt/entdec.c
+++ b/libcelt/entdec.c
@@ -44,13 +44,6 @@
_b->end_ptr=_b->buf+_bytes-1;
}
-int ec_byte_look1(ec_byte_buffer *_b){
- ptrdiff_t endbyte;
- endbyte=_b->ptr-_b->buf;
- if(endbyte>=_b->storage)return -1;
- else return _b->ptr[0];
-}
-
unsigned char ec_byte_look_at_end(ec_byte_buffer *_b){
if (_b->end_ptr < _b->buf)
{
@@ -59,38 +52,10 @@
return *(_b->end_ptr--);
}
-int ec_byte_look4(ec_byte_buffer *_b,ec_uint32 *_val){
- ptrdiff_t endbyte;
- endbyte=_b->ptr-_b->buf;
- if(endbyte+4>_b->storage){
- if(endbyte<_b->storage){
- *_val=_b->ptr[0];
- endbyte++;
- if(endbyte<_b->storage){
- *_val|=(ec_uint32)_b->ptr[1]<<8;
- endbyte++;
- if(endbyte<_b->storage)*_val|=(ec_uint32)_b->ptr[2]<<16;
- }
- }
- return -1;
- }
- else{
- *_val=_b->ptr[0];
- *_val|=(ec_uint32)_b->ptr[1]<<8;
- *_val|=(ec_uint32)_b->ptr[2]<<16;
- *_val|=(ec_uint32)_b->ptr[3]<<24;
- }
- return 0;
-}
-
void ec_byte_adv1(ec_byte_buffer *_b){
_b->ptr++;
}
-void ec_byte_adv4(ec_byte_buffer *_b){
- _b->ptr+=4;
-}
-
int ec_byte_read1(ec_byte_buffer *_b){
ptrdiff_t endbyte;
endbyte=_b->ptr-_b->buf;
@@ -97,29 +62,6 @@
if(endbyte>=_b->storage)return -1;
else return *(_b->ptr++);
}
-
-int ec_byte_read4(ec_byte_buffer *_b,ec_uint32 *_val){
- unsigned char *end;
- end=_b->buf+_b->storage;
- if(_b->ptr+4>end){
- if(_b->ptr<end){
- *_val=*(_b->ptr++);
- if(_b->ptr<end){
- *_val|=(ec_uint32)*(_b->ptr++)<<8;
- if(_b->ptr<end)*_val|=(ec_uint32)*(_b->ptr++)<<16;
- }
- }
- return -1;
- }
- else{
- *_val=(*_b->ptr++);
- *_val|=(ec_uint32)*(_b->ptr++)<<8;
- *_val|=(ec_uint32)*(_b->ptr++)<<16;
- *_val|=(ec_uint32)*(_b->ptr++)<<24;
- }
- return 0;
-}
-
ec_uint32 ec_dec_bits(ec_dec *_this,int _ftb){
--- a/libcelt/entenc.c
+++ b/libcelt/entenc.c
@@ -44,22 +44,13 @@
_b->ptr=_b->buf=_buf;
_b->end_ptr=_b->buf+_size-1;
_b->storage=_size;
- _b->resizable=0;
}
void ec_byte_shrink(ec_byte_buffer *_b, long _size){
_b->end_ptr=_b->buf+_size-1;
_b->storage=_size;
- _b->resizable=0;
}
-void ec_byte_writeinit(ec_byte_buffer *_b){
- _b->ptr=_b->buf=celt_alloc(EC_BUFFER_INCREMENT*sizeof(char));
- _b->storage=EC_BUFFER_INCREMENT;
- _b->end_ptr=_b->buf;
- _b->resizable=1;
-}
-
void ec_byte_writetrunc(ec_byte_buffer *_b,long _bytes){
_b->ptr=_b->buf+_bytes;
}
@@ -68,13 +59,7 @@
ptrdiff_t endbyte;
endbyte=_b->ptr-_b->buf;
if(endbyte>=_b->storage){
- if (_b->resizable){
- _b->buf=celt_realloc(_b->buf,(_b->storage+EC_BUFFER_INCREMENT)*sizeof(char));
- _b->storage+=EC_BUFFER_INCREMENT;
- _b->ptr=_b->buf+endbyte;
- } else {
- celt_fatal("range encoder overflow\n");
- }
+ celt_fatal("range encoder overflow\n");
}
*(_b->ptr++)=(unsigned char)_value;
}
@@ -86,49 +71,6 @@
}
*(_b->end_ptr--)=(unsigned char)_value;
}
-
-void ec_byte_write4(ec_byte_buffer *_b,ec_uint32 _value){
- ptrdiff_t endbyte;
- endbyte=_b->ptr-_b->buf;
- if(endbyte+4>_b->storage){
- if (_b->resizable){
- _b->buf=celt_realloc(_b->buf,(_b->storage+EC_BUFFER_INCREMENT)*sizeof(char));
- _b->storage+=EC_BUFFER_INCREMENT;
- _b->ptr=_b->buf+endbyte;
- } else {
- celt_fatal("range encoder overflow\n");
- }
- }
- *(_b->ptr++)=(unsigned char)_value;
- _value>>=8;
- *(_b->ptr++)=(unsigned char)_value;
- _value>>=8;
- *(_b->ptr++)=(unsigned char)_value;
- _value>>=8;
- *(_b->ptr++)=(unsigned char)_value;
-}
-
-void ec_byte_writecopy(ec_byte_buffer *_b,void *_source,long _bytes){
- ptrdiff_t endbyte;
- endbyte=_b->ptr-_b->buf;
- if(endbyte+_bytes>_b->storage){
- if (_b->resizable){
- _b->storage=endbyte+_bytes+EC_BUFFER_INCREMENT;
- _b->buf=celt_realloc(_b->buf,_b->storage*sizeof(char));
- _b->ptr=_b->buf+endbyte;
- } else {
- celt_fatal("range encoder overflow\n");
- }
- }
- memmove(_b->ptr,_source,_bytes);
- _b->ptr+=_bytes;
-}
-
-void ec_byte_writeclear(ec_byte_buffer *_b){
- if (_b->resizable)
- celt_free(_b->buf);
-}
-
void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,int _ftb){
--- a/tests/ectest.c
+++ b/tests/ectest.c
@@ -105,7 +105,6 @@
ldexp(nbits2,-4),ldexp(nbits,-4));
ret=-1;
}
- ec_byte_writeclear(&buf);
srand(seed);
fprintf(stderr,"Testing random streams... Random seed: %u (%.4X)\n", seed, rand() % 65536);
for(i=0;i<409600;i++){
@@ -149,7 +148,6 @@
ret=-1;
}
}
- ec_byte_writeclear(&buf);
free(data);
}
free(ptr);
--- a/tests/laplace-test.c
+++ b/tests/laplace-test.c
@@ -15,6 +15,7 @@
#include "../libcelt/entcode.c"
#include "../libcelt/laplace.c"
+#define DATA_SIZE 40000
int main(void)
{
@@ -23,9 +24,12 @@
ec_enc enc;
ec_dec dec;
ec_byte_buffer buf;
+ unsigned char *ptr;
int val[10000], decay[10000];
ALLOC_STACK;
- ec_byte_writeinit(&buf);
+ ptr = malloc(DATA_SIZE);
+ ec_byte_writeinit_buffer(&buf, ptr, DATA_SIZE);
+ //ec_byte_writeinit(&buf);
ec_enc_init(&enc,&buf);
val[0] = 3; decay[0] = 6000;
@@ -54,6 +58,5 @@
}
}
- ec_byte_writeclear(&buf);
return ret;
}