#include "avcodec.h"
#include "bitstream.h"
#include "dsputil.h"
-#include "common.h"
#include "bytestream.h"
#include "random.h"
result = 0;
for (i=0 ; i<13 ; i++) {
- result &= init_vlc (&q->envelope_quant_index[i], 9, 24,
+ result |= init_vlc (&q->envelope_quant_index[i], 9, 24,
envelope_quant_index_huffbits[i], 1, 1,
envelope_quant_index_huffcodes[i], 2, 2, 0);
}
av_log(NULL,AV_LOG_DEBUG,"sqvh VLC init\n");
for (i=0 ; i<7 ; i++) {
- result &= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
+ result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
cvh_huffbits[i], 1, 1,
cvh_huffcodes[i], 2, 2, 0);
}
if (q->nb_channels==2 && q->joint_stereo==1){
- result &= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
+ result |= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0);
av_log(NULL,AV_LOG_DEBUG,"Joint-stereo VLC used.\n");
static void decode_envelope(COOKContext *q, int* quant_index_table) {
int i,j, vlc_index;
- int bitbias;
- bitbias = get_bits_count(&q->gb);
quant_index_table[0]= get_bits(&q->gb,6) - 6; //This is used later in categorize
for (i=1 ; i < q->total_subbands ; i++){
static void categorize(COOKContext *q, int* quant_index_table,
int* category, int* category_index){
- int exp_idx, bias, tmpbias, bits_left, num_bits, index, v, i, j;
+ int exp_idx, bias, tmpbias1, tmpbias2, bits_left, num_bits, index, v, i, j;
int exp_index2[102];
int exp_index1[102];
- int tmp_categorize_array1[128];
- int tmp_categorize_array1_idx=0;
- int tmp_categorize_array2[128];
- int tmp_categorize_array2_idx=0;
- int category_index_size=0;
+ int tmp_categorize_array[128*2];
+ int tmp_categorize_array1_idx=q->numvector_size;
+ int tmp_categorize_array2_idx=q->numvector_size;
bits_left = q->bits_per_subpacket - get_bits_count(&q->gb);
memset(&exp_index1,0,102*sizeof(int));
memset(&exp_index2,0,102*sizeof(int));
- memset(&tmp_categorize_array1,0,128*sizeof(int));
- memset(&tmp_categorize_array2,0,128*sizeof(int));
+ memset(&tmp_categorize_array,0,128*2*sizeof(int));
bias=-32;
num_bits = 0;
index = 0;
for (j=q->total_subbands ; j>0 ; j--){
- exp_idx = (i - quant_index_table[index] + bias) / 2;
- if (exp_idx<0){
- exp_idx=0;
- } else if(exp_idx >7) {
- exp_idx=7;
- }
+ exp_idx = av_clip((i - quant_index_table[index] + bias) / 2, 0, 7);
index++;
num_bits+=expbits_tab[exp_idx];
}
/* Calculate total number of bits. */
num_bits=0;
for (i=0 ; i<q->total_subbands ; i++) {
- exp_idx = (bias - quant_index_table[i]) / 2;
- if (exp_idx<0) {
- exp_idx=0;
- } else if(exp_idx >7) {
- exp_idx=7;
- }
+ exp_idx = av_clip((bias - quant_index_table[i]) / 2, 0, 7);
num_bits += expbits_tab[exp_idx];
exp_index1[i] = exp_idx;
exp_index2[i] = exp_idx;
}
- tmpbias = bias = num_bits;
+ tmpbias1 = tmpbias2 = num_bits;
for (j = 1 ; j < q->numvector_size ; j++) {
- if (tmpbias + bias > 2*bits_left) { /* ---> */
+ if (tmpbias1 + tmpbias2 > 2*bits_left) { /* ---> */
int max = -999999;
index=-1;
for (i=0 ; i<q->total_subbands ; i++){
if (exp_index1[i] < 7) {
- v = (-2*exp_index1[i]) - quant_index_table[i] - 32;
+ v = (-2*exp_index1[i]) - quant_index_table[i] + bias;
if ( v >= max) {
max = v;
index = i;
}
}
if(index==-1)break;
- tmp_categorize_array1[tmp_categorize_array1_idx++] = index;
- tmpbias -= expbits_tab[exp_index1[index]] -
- expbits_tab[exp_index1[index]+1];
+ tmp_categorize_array[tmp_categorize_array1_idx++] = index;
+ tmpbias1 -= expbits_tab[exp_index1[index]] -
+ expbits_tab[exp_index1[index]+1];
++exp_index1[index];
} else { /* <--- */
int min = 999999;
index=-1;
for (i=0 ; i<q->total_subbands ; i++){
if(exp_index2[i] > 0){
- v = (-2*exp_index2[i])-quant_index_table[i];
+ v = (-2*exp_index2[i])-quant_index_table[i]+bias;
if ( v < min) {
min = v;
index = i;
}
}
if(index == -1)break;
- tmp_categorize_array2[tmp_categorize_array2_idx++] = index;
- tmpbias -= expbits_tab[exp_index2[index]] -
- expbits_tab[exp_index2[index]-1];
+ tmp_categorize_array[--tmp_categorize_array2_idx] = index;
+ tmpbias2 -= expbits_tab[exp_index2[index]] -
+ expbits_tab[exp_index2[index]-1];
--exp_index2[index];
}
}
for(i=0 ; i<q->total_subbands ; i++)
category[i] = exp_index2[i];
- /* Concatenate the two arrays. */
- for(i=tmp_categorize_array2_idx-1 ; i >= 0; i--)
- category_index[category_index_size++] = tmp_categorize_array2[i];
-
- for(i=0;i<tmp_categorize_array1_idx;i++)
- category_index[category_index_size++ ] = tmp_categorize_array1[i];
-
- /* FIXME: mc_sich_ra8_20.rm triggers this, not sure with what we
- should fill the remaining bytes. */
- for(i=category_index_size;i<q->numvector_size;i++)
- category_index[i]=0;
+ for(i=0 ; i<q->numvector_size-1 ; i++)
+ category_index[i] = tmp_categorize_array[tmp_categorize_array2_idx++];
}
* @param category_index pointer to the category_index array
*/
-static void inline expand_category(COOKContext *q, int* category,
+static inline void expand_category(COOKContext *q, int* category,
int* category_index){
int i;
for(i=0 ; i<q->num_vectors ; i++){
int* subband_coef_sign) {
int i,j;
int vlc, vd ,tmp, result;
- int ub;
- int cb;
vd = vd_tab[category];
result = 0;
for(i=0 ; i<vpr_tab[category] ; i++){
- ub = get_bits_count(&q->gb);
vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3);
- cb = get_bits_count(&q->gb);
if (q->bits_per_subpacket < get_bits_count(&q->gb)){
vlc = 0;
result = 1;