comparison g726.c @ 7072:be6f9be3a79d libavcodec

Get rid of G726Tables.bits.
author michael
date Thu, 19 Jun 2008 10:52:47 +0000
parents cbc38c3580da
children 33dc1d1705f0
comparison
equal deleted inserted replaced
7071:cbc38c3580da 7072:be6f9be3a79d
61 { 61 {
62 return (value < 0) ? -1 : 1; 62 return (value < 0) ? -1 : 1;
63 } 63 }
64 64
65 typedef struct G726Tables { 65 typedef struct G726Tables {
66 int bits; /**< bits per sample */
67 const int* quant; /**< quantization table */ 66 const int* quant; /**< quantization table */
68 const int16_t* iquant; /**< inverse quantization table */ 67 const int16_t* iquant; /**< inverse quantization table */
69 const int16_t* W; /**< special table #1 ;-) */ 68 const int16_t* W; /**< special table #1 ;-) */
70 const uint8_t* F; /**< special table #2 */ 69 const uint8_t* F; /**< special table #2 */
71 } G726Tables; 70 } G726Tables;
137 static const uint8_t F_tbl40[] = 136 static const uint8_t F_tbl40[] =
138 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6, 137 { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6,
139 6, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; 138 6, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
140 139
141 static const G726Tables G726Tables_pool[] = 140 static const G726Tables G726Tables_pool[] =
142 {{ 2, quant_tbl16, iquant_tbl16, W_tbl16, F_tbl16 }, 141 {{ quant_tbl16, iquant_tbl16, W_tbl16, F_tbl16 },
143 { 3, quant_tbl24, iquant_tbl24, W_tbl24, F_tbl24 }, 142 { quant_tbl24, iquant_tbl24, W_tbl24, F_tbl24 },
144 { 4, quant_tbl32, iquant_tbl32, W_tbl32, F_tbl32 }, 143 { quant_tbl32, iquant_tbl32, W_tbl32, F_tbl32 },
145 { 5, quant_tbl40, iquant_tbl40, W_tbl40, F_tbl40 }}; 144 { quant_tbl40, iquant_tbl40, W_tbl40, F_tbl40 }};
146 145
147 146
148 /** 147 /**
149 * Para 4.2.2 page 18: Adaptive quantizer. 148 * Para 4.2.2 page 18: Adaptive quantizer.
150 */ 149 */
163 while (c->tbls.quant[i] < INT_MAX && c->tbls.quant[i] < dln) 162 while (c->tbls.quant[i] < INT_MAX && c->tbls.quant[i] < dln)
164 ++i; 163 ++i;
165 164
166 if (sign) 165 if (sign)
167 i = ~i; 166 i = ~i;
168 if (c->tbls.bits != 2 && i == 0) /* I'm not sure this is a good idea */ 167 if (c->code_size != 2 && i == 0) /* I'm not sure this is a good idea */
169 i = 0xff; 168 i = 0xff;
170 169
171 return i; 170 return i;
172 } 171 }
173 172
186 185
187 static int16_t g726_decode(G726Context* c, int I) 186 static int16_t g726_decode(G726Context* c, int I)
188 { 187 {
189 int dq, re_signal, pk0, fa1, i, tr, ylint, ylfrac, thr2, al, dq0; 188 int dq, re_signal, pk0, fa1, i, tr, ylint, ylfrac, thr2, al, dq0;
190 Float11 f; 189 Float11 f;
191 int I_sig= I >> (c->tbls.bits - 1); 190 int I_sig= I >> (c->code_size - 1);
192 191
193 dq = inverse_quant(c, I); 192 dq = inverse_quant(c, I);
194 193
195 /* Transition detect */ 194 /* Transition detect */
196 ylint = (c->yl >> 15); 195 ylint = (c->yl >> 15);
288 #ifdef CONFIG_ENCODERS 287 #ifdef CONFIG_ENCODERS
289 static int16_t g726_encode(G726Context* c, int16_t sig) 288 static int16_t g726_encode(G726Context* c, int16_t sig)
290 { 289 {
291 uint8_t i; 290 uint8_t i;
292 291
293 i = quant(c, sig/4 - c->se) & ((1<<c->tbls.bits) - 1); 292 i = quant(c, sig/4 - c->se) & ((1<<c->code_size) - 1);
294 g726_decode(c, i); 293 g726_decode(c, i);
295 return i; 294 return i;
296 } 295 }
297 #endif 296 #endif
298 297
314 if(index>3){ 313 if(index>3){
315 av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); 314 av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2);
316 return -1; 315 return -1;
317 } 316 }
318 g726_reset(c, index); 317 g726_reset(c, index);
319 c->code_size = c->tbls.bits; 318 c->code_size = index+2;
320 319
321 avctx->coded_frame = avcodec_alloc_frame(); 320 avctx->coded_frame = avcodec_alloc_frame();
322 if (!avctx->coded_frame) 321 if (!avctx->coded_frame)
323 return AVERROR(ENOMEM); 322 return AVERROR(ENOMEM);
324 avctx->coded_frame->key_frame = 1; 323 avctx->coded_frame->key_frame = 1;