www.pudn.com > T-REC-G.722.1-200505-I!!SOFT-ZST-E.zip > common.c


/***************************************************************** 
****************************************************************** 
** 
**   ITU-T Wideband Coder Candidate (G.WB) Source Code 
** 
**		  File Name : common.c 
** 
**    © 2000 PictureTel Coporation 
**          Andover, MA, USA   
** 
**	    All rights reserved. 
** 
****************************************************************** 
*****************************************************************/ 
 
#include  
#include  
#include "defs.h" 
 
#include "huff_defs.h" 
#include "huff_tables.h" 
 
int region_size; 
float region_size_inverse; 
 
float region_standard_deviation_table[REGION_POWER_TABLE_SIZE]; 
float standard_deviation_inverse_table[REGION_POWER_TABLE_SIZE]; 
float step_size_inverse_table[NUM_CATEGORIES]; 
 
 
float region_power_table[REGION_POWER_TABLE_SIZE]; 
float region_power_table_boundary[REGION_POWER_TABLE_SIZE-1]; 
 
int vector_dimension[NUM_CATEGORIES] =  { 2, 2, 2, 4, 4, 5, 5, 1}; 
int number_of_vectors[NUM_CATEGORIES] = {10,10,10, 5, 5, 4, 4,20}; 
 
/* The last category isn't really coded with scalar quantization. */ 
 
float step_size[NUM_CATEGORIES] = {0.3536, 0.5, 0.7071, 1.0, 1.4142, 2.0, 2.8284, 2.8284}; 
int max_bin[NUM_CATEGORIES] = {13, 9, 6, 4, 3, 2, 1, 1}; 
int int_dead_zone[NUM_CATEGORIES]; 
float dead_zone[NUM_CATEGORIES] = {0.3, 0.33, 0.36, 0.39, 0.42, 0.45, 0.5, 0.5}; 
static int max_bin_plus_one_inverse[NUM_CATEGORIES]; 
 
/**************************************************************************************** 
 Procedure/Function:  index_to_array  
 
 Syntax:   number_of_non_zero = index_to_array(int index,  
                                               int array[MAX_VECTOR_DIMENSION], 
                                               int category) 
 
                inputs:  int index 
                         int category                      
                        
                outputs: int array[MAX_VECTOR_DIMENSION] - used in decoder to access 
                                                             mlt_quant_centroid table 
                         
                         int number_of_non_zero          - number of non zero elements 
                                                             in the array 
  
 Description:   Computes an array of sign bits with the length of the category vector 
                Returns the number of sign bits and the array 
 
****************************************************************************************/ 
 
int index_to_array(index,array,category) 
int index; 
int array[MAX_VECTOR_DIMENSION]; 
int category; 
{ 
  int j,q,p; 
  int number_of_non_zero; 
  int max_bin_plus_one; 
  int inverse_of_max_bin_plus_one; 
 
  number_of_non_zero = 0; 
  p = index; 
  max_bin_plus_one = max_bin[category] + 1; 
  inverse_of_max_bin_plus_one = max_bin_plus_one_inverse[category]; 
 
  for (j=vector_dimension[category]-1; j>=0; j--) { 
 
	  /*    q = p/max_bin_plus_one; */ 
     
	  q = (p*inverse_of_max_bin_plus_one) >> 15; 
    array[j] = p - q*max_bin_plus_one; 
    p = q; 
    if (array[j] != 0) number_of_non_zero++; 
  } 
  return(number_of_non_zero); 
} 
 
/**************************************************************************************** 
 Procedure/Function:  mlt_based_coder_init 
 
 Syntax:        void mlt_based_coder_init() 
                inputs:  none 
                          
                outputs: none 
  
 Description:   Initializes region and category related stuff 
 
****************************************************************************************/ 
 void mlt_based_coder_init() 
	 { 
  int i,j; 
  int category; 
  int number_of_indices; 
  
/*  region_size = (BLOCK_SIZE * 0.875)/NUM_REGIONS; */ 
   
  region_size = 20; 
  region_size_inverse = (float)(1.0/((float) region_size)); 
 
  for (i=0; i> 15)) 
	printf("max_bin_plus_one_inverse ERROR!! %1d: %5d %3d\n",category,max_bin_plus_one_inverse[category],j); 
    } 
  } 
 
  for (category=0; category 320) 
      number_of_available_bits = 
	320 + (((number_of_available_bits - 320)*5) >> 3); 
  } 
 
  offset = -32; 
  delta = 32; 
  do { 
    test_offset = offset + delta; 
    for (region=0; region> 1; 
      if (j < 0) j = 0; 
      if (j > NUM_CATEGORIES-1) j = NUM_CATEGORIES-1; 
      power_categories[region] = j; 
    } 
    expected_number_of_code_bits = 0; 
    for (region=0; region= number_of_available_bits - 32) 
      offset = test_offset; 
 
    delta >>= 1; 
  } while (delta > 0); 
 
 
  for (region=0; region> 1; 
    if (j < 0) j = 0; 
    if (j > NUM_CATEGORIES-1) j = NUM_CATEGORIES-1; 
    power_categories[region] = j; 
  } 
  expected_number_of_code_bits = 0; 
  for (region=0; region 0) { 
	    itemp0 = offset - rms_index[region] - 2*max_rate_categories[region]; 
	    if (itemp0 < raw_min) { 
	      raw_min = itemp0; 
	      raw_min_index = region; 
	    } 
	  } 
	} 
	max_rate_pointer--; 
	temp_category_balances[max_rate_pointer] = raw_min_index; 
 
	max -= expected_bits_table[max_rate_categories[raw_min_index]]; 
	max_rate_categories[raw_min_index] -= 1; 
	max += expected_bits_table[max_rate_categories[raw_min_index]]; 
      } 
 
      else { 
	raw_max = -99; 
 
	/* Search from highest freq regions to lowest for best region to reassign to 
   a lower bit rate category. */ 
 
	for (region=number_of_regions-1; region >= 0; region--) { 
	  if (min_rate_categories[region] < NUM_CATEGORIES-1){ 
	    itemp0 = offset - rms_index[region] - 2*min_rate_categories[region]; 
	    if (itemp0 > raw_max) { 
	      raw_max = itemp0; 
	      raw_max_index = region; 
	    } 
	  } 
	} 
	temp_category_balances[min_rate_pointer] = raw_max_index; 
	min_rate_pointer++; 
 
	min -= expected_bits_table[min_rate_categories[raw_max_index]]; 
	min_rate_categories[raw_max_index] += 1; 
	min += expected_bits_table[min_rate_categories[raw_max_index]]; 
      } 
    } 
 
    for (region=0; region