1
/***********************************************************************
3
** ITU-T G.722.1 (2005-05) - Fixed point implementation for main body and Annex C
4
** > Software Release 2.1 (2008-06)
5
** (Simple repackaging; no change from 2005-05 Release 2.0 code)
7
** � 2004 Polycom, Inc.
9
** All rights reserved.
11
***********************************************************************/
16
#include "g7221/common/typedef.h"
17
#include "g7221/common/basic_op.h"
19
#define PI 3.141592653589793238462
21
#define MAX_DCT_LENGTH 640
22
#define DCT_LENGTH 320
23
#define DCT_LENGTH_DIV_2 160
24
#define DCT_LENGTH_DIV_4 80
25
#define DCT_LENGTH_DIV_8 40
26
#define DCT_LENGTH_DIV_16 20
27
#define DCT_LENGTH_DIV_32 10
28
#define DCT_LENGTH_DIV_64 5
31
#define MAX(a,b) (a > b ? a : b)
32
#define MIN(a,b) (a < b ? a : b)
34
#define NUM_CATEGORIES 8
35
#define NUM_CATEGORIZATION_CONTROL_BITS 4
36
#define NUM_CATEGORIZATION_CONTROL_POSSIBILITIES 16
38
#define DCT_LENGTH_LOG 6
39
#define MAX_DCT_LENGTH_LOG 7
41
/* region_size = (BLOCK_SIZE * 0.875)/NUM_REGIONS; */
42
#define NUMBER_OF_REGIONS 14
43
#define MAX_NUMBER_OF_REGIONS 28
44
#define REGION_SIZE 20
45
#define NUMBER_OF_VALID_COEFS (NUMBER_OF_REGIONS * REGION_SIZE)
46
#define MAX_NUMBER_OF_VALID_COEFS (MAX_NUMBER_OF_REGIONS * REGION_SIZE)
48
#define REGION_POWER_TABLE_SIZE 64
49
#define REGION_POWER_TABLE_NUM_NEGATIVES 24
51
#define MAX_NUM_CATEGORIZATION_CONTROL_BITS 5
52
#define MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES 32
54
#define ENCODER_SCALE_FACTOR 18318.0
56
/* The MLT output is incorrectly scaled by the factor
57
product of ENCODER_SCALE_FACTOR and sqrt(160.)
58
This is now (9/30/96) 1.0/2^(4.5) or 1/22.627.
59
In the current implementation this
60
must be an integer power of sqrt(2). The
61
integer power is ESF_ADJUSTMENT_TO_RMS_INDEX.
62
The -2 is to conform with the range defined in the spec. */
65
#define ESF_ADJUSTMENT_TO_RMS_INDEX (9-2)
68
#define INTERMEDIATE_FILES_FLAG 0
70
/* Max bit rate is 48000 bits/sec. */
71
#define MAX_BITS_PER_FRAME 960
74
/***************************************************************************/
75
/* Type definitions */
76
/***************************************************************************/
79
Word16 code_bit_count; /* bit count of the current word */
80
Word16 current_word; /* current word in the bitstream being processed */
81
Word16 *code_word_ptr; /* pointer to the bitstream */
82
Word16 number_of_bits_left; /* number of bits left in the current word */
83
Word16 next_bit; /* next bit in the current word */
94
/***************************************************************************/
95
/* Function definitions */
96
/***************************************************************************/
97
extern Word16 compute_region_powers(Word16 *mlt_coefs,
100
UWord16 *drp_code_bits,
101
Word16 *absolute_region_power_index,
102
Word16 number_of_regions);
104
void vector_quantize_mlts(Word16 number_of_available_bits,
105
Word16 number_of_regions,
106
Word16 num_categorization_control_possibilities,
108
Word16 *absolute_region_power_index,
109
Word16 *power_categories,
110
Word16 *category_balances,
111
Word16 *p_categorization_control,
112
Word16 *region_mlt_bit_counts,
113
UWord32 *region_mlt_bits);
115
Word16 vector_huffman(Word16 category,
121
void adjust_abs_region_power_index(Word16 *absolute_region_power_index,Word16 *mlt_coefs,Word16 number_of_regions);
123
void bits_to_words(UWord32 *region_mlt_bits,Word16 *region_mlt_bit_counts,
124
Word16 *drp_num_bits,UWord16 *drp_code_bits,Word16 *out_words,
125
Word16 categorization_control, Word16 number_of_regions,
126
Word16 num_categorization_control_bits, Word16 number_of_bits_per_frame);
128
void encoder(Word16 number_of_available_bits,
129
Word16 number_of_regions,
134
void decoder(Bit_Obj *bitobj,
136
Word16 number_of_regions,
137
Word16 *decoder_mlt_coefs,
139
Word16 *p_old_mag_shift,
140
Word16 *old_decoder_mlt_coefs,
141
Word16 frame_error_flag);
143
Word16 samples_to_rmlt_coefs(const Word16 *new_samples,Word16 *history,Word16 *coefs,Word16 dct_length);
144
void rmlt_coefs_to_samples(Word16 *coefs,
150
Word16 index_to_array(Word16 index,Word16 *array,Word16 category);
151
void categorize(Word16 number_of_available_bits,
152
Word16 number_of_regions,
153
Word16 num_categorization_control_possibilities,
155
Word16 *power_categories,
156
Word16 *category_balances);
158
Word16 calc_offset(Word16 *rms_index,Word16 number_of_regions,Word16 available_bits);
159
void compute_raw_pow_categories(Word16 *power_categories,Word16 *rms_index,Word16 number_of_regions,Word16 offset);
160
void comp_powercat_and_catbalance(Word16 *power_categories,
161
Word16 *category_balances,
163
Word16 number_of_available_bits,
164
Word16 number_of_regions,
165
Word16 num_categorization_control_possibilities,
168
void dct_type_iv_a (Word16 *input,Word16 *output,Word16 dct_length);
169
void dct_type_iv_s(Word16 *input,Word16 *output,Word16 dct_length);
170
void decode_envelope(Bit_Obj *bitobj,
171
Word16 number_of_regions,
172
Word16 *decoder_region_standard_deviation,
173
Word16 *absolute_region_power_index,
174
Word16 *p_mag_shift);
176
void decode_vector_quantized_mlt_indices(Bit_Obj *bitobj,
178
Word16 number_of_regions,
179
Word16 *decoder_region_standard_deviation,
180
Word16 *dedecoder_power_categories,
181
Word16 *dedecoder_mlt_coefs);
183
void rate_adjust_categories(Word16 categorization_control,
184
Word16 *decoder_power_categories,
185
Word16 *decoder_category_balances);
187
void get_next_bit(Bit_Obj *bitobj);
188
Word16 get_rand(Rand_Obj *randobj);
190
void test_4_frame_errors(Bit_Obj *bitobj,
191
Word16 number_of_regions,
192
Word16 num_categorization_control_possibilities,
193
Word16 *frame_error_flag,
194
Word16 categorization_control,
195
Word16 *absolute_region_power_index);
197
void error_handling(Word16 number_of_coefs,
198
Word16 number_of_valid_coefs,
199
Word16 *frame_error_flag,
200
Word16 *decoder_mlt_coefs,
201
Word16 *old_decoder_mlt_coefs,
203
Word16 *p_old_mag_shift);