Lines Matching full:_this
60 static int ec_write_byte(ec_enc *_this,unsigned _value){
61 if(_this->offs+_this->end_offs>=_this->storage)return -1;
62 _this->buf[_this->offs++]=(unsigned char)_value;
66 static int ec_write_byte_at_end(ec_enc *_this,unsigned _value){
67 if(_this->offs+_this->end_offs>=_this->storage)return -1;
68 _this->buf[_this->storage-++(_this->end_offs)]=(unsigned char)_value;
82 static void ec_enc_carry_out(ec_enc *_this,int _c){
89 if(_this->rem>=0)_this->error|=ec_write_byte(_this,_this->rem+carry);
90 if(_this->ext>0){
93 do _this->error|=ec_write_byte(_this,sym);
94 while(--(_this->ext)>0);
96 _this->rem=_c&EC_SYM_MAX;
98 else _this->ext++;
101 static void ec_enc_normalize(ec_enc *_this){
103 while(_this->rng<=EC_CODE_BOT){
104 ec_enc_carry_out(_this,(int)(_this->val>>EC_CODE_SHIFT));
106 _this->val=(_this->val<<EC_SYM_BITS)&(EC_CODE_TOP-1);
107 _this->rng<<=EC_SYM_BITS;
108 _this->nbits_total+=EC_SYM_BITS;
112 void ec_enc_init(ec_enc *_this,unsigned char *_buf,opus_uint32 _size){
113 _this->buf=_buf;
114 _this->end_offs=0;
115 _this->end_window=0;
116 _this->nend_bits=0;
118 _this->nbits_total=EC_CODE_BITS+1;
119 _this->offs=0;
120 _this->rng=EC_CODE_TOP;
121 _this->rem=-1;
122 _this->val=0;
123 _this->ext=0;
124 _this->storage=_size;
125 _this->error=0;
128 void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft){
130 r=_this->rng/_ft;
132 _this->val+=_this->rng-IMUL32(r,(_ft-_fl));
133 _this->rng=IMUL32(r,(_fh-_fl));
135 else _this->rng-=IMUL32(r,(_ft-_fh));
136 ec_enc_normalize(_this);
139 void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits){
141 r=_this->rng>>_bits;
143 _this->val+=_this->rng-IMUL32(r,((1U<<_bits)-_fl));
144 _this->rng=IMUL32(r,(_fh-_fl));
146 else _this->rng-=IMUL32(r,((1U<<_bits)-_fh));
147 ec_enc_normalize(_this);
151 void ec_enc_bit_logp(ec_enc *_this,int _val,unsigned _logp){
155 r=_this->rng;
156 l=_this->val;
159 if(_val)_this->val=l+r;
160 _this->rng=_val?s:r;
161 ec_enc_normalize(_this);
164 void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb){
166 r=_this->rng>>_ftb;
168 _this->val+=_this->rng-IMUL32(r,_icdf[_s-1]);
169 _this->rng=IMUL32(r,_icdf[_s-1]-_icdf[_s]);
171 else _this->rng-=IMUL32(r,_icdf[_s]);
172 ec_enc_normalize(_this);
175 void ec_enc_uint(ec_enc *_this,opus_uint32 _fl,opus_uint32 _ft){
187 ec_encode(_this,fl,fl+1,ft);
188 ec_enc_bits(_this,_fl&(((opus_uint32)1<<ftb)-1U),ftb);
190 else ec_encode(_this,_fl,_fl+1,_ft+1);
193 void ec_enc_bits(ec_enc *_this,opus_uint32 _fl,unsigned _bits){
196 window=_this->end_window;
197 used=_this->nend_bits;
201 _this->error|=ec_write_byte_at_end(_this,(unsigned)window&EC_SYM_MAX);
209 _this->end_window=window;
210 _this->nend_bits=used;
211 _this->nbits_total+=_bits;
214 void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits){
220 if(_this->offs>0){
222 _this->buf[0]=(unsigned char)((_this->buf[0]&~mask)|_val<<shift);
224 else if(_this->rem>=0){
226 _this->rem=(_this->rem&~mask)|_val<<shift;
228 else if(_this->rng<=(EC_CODE_TOP>>_nbits)){
230 _this->val=(_this->val&~((opus_uint32)mask<<EC_CODE_SHIFT))|
234 else _this->error=-1;
237 void ec_enc_shrink(ec_enc *_this,opus_uint32 _size){
238 celt_assert(_this->offs+_this->end_offs<=_size);
239 OPUS_MOVE(_this->buf+_size-_this->end_offs,
240 _this->buf+_this->storage-_this->end_offs,_this->end_offs);
241 _this->storage=_size;
244 void ec_enc_done(ec_enc *_this){
252 l=EC_CODE_BITS-EC_ILOG(_this->rng);
254 end=(_this->val+msk)&~msk;
255 if((end|msk)>=_this->val+_this->rng){
258 end=(_this->val+msk)&~msk;
261 ec_enc_carry_out(_this,(int)(end>>EC_CODE_SHIFT));
266 if(_this->rem>=0||_this->ext>0)ec_enc_carry_out(_this,0);
268 window=_this->end_window;
269 used=_this->nend_bits;
271 _this->error|=ec_write_byte_at_end(_this,(unsigned)window&EC_SYM_MAX);
276 if(!_this->error){
277 OPUS_CLEAR(_this->buf+_this->offs,
278 _this->storage-_this->offs-_this->end_offs);
281 if(_this->end_offs>=_this->storage)_this->error=-1;
286 if(_this->offs+_this->end_offs>=_this->storage&&l<used){
288 _this->error=-1;
290 _this->buf[_this->storage-_this->end_offs-1]|=(unsigned char)window;