Moved the content of libentcode into libcelt to reduce dependencies,
[opus.git] / libcelt / probmod.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include "probmod.h"
4 #include "bitree.h"
5
6 void ec_probmod_init(ec_probmod *_this,unsigned _sz){
7   ec_probmod_init_full(_this,_sz,1U,1U<<23,NULL);
8 }
9
10 void ec_probmod_init_from_counts(ec_probmod *_this,unsigned _sz,
11  const unsigned *_counts){
12   ec_probmod_init_full(_this,_sz,1U,1U<<23,_counts);
13 }
14
15 void ec_probmod_init_full(ec_probmod *_this,unsigned _sz,unsigned _inc,
16  unsigned _thresh,const unsigned *_counts){
17   unsigned s;
18   _this->sz=_sz;
19   for(s=1;s<=_this->sz;s<<=1);
20   _this->split=s>>1;
21   _this->inc=_inc;
22   _this->thresh=_thresh;
23   _this->bitree=(unsigned *)malloc(_sz*sizeof(*_this->bitree));
24   if(_counts!=NULL)memcpy(_this->bitree,_counts,_sz*sizeof(*_this->bitree));
25   else for(s=0;s<_this->sz;s++)_this->bitree[s]=1;
26   ec_bitree_from_counts(_this->bitree,_sz);
27   _this->ft=ec_bitree_get_cumul(_this->bitree,_sz);
28 }
29
30 void ec_probmod_clear(ec_probmod *_this){
31   free(_this->bitree);
32 }