-
Notifications
You must be signed in to change notification settings - Fork 3
/
dec_gain.c
108 lines (87 loc) · 4.68 KB
/
dec_gain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
ITU-T G.729A Speech Coder ANSI-C Source Code
Version 1.1 Last modified: September 1996
Copyright (c) 1996,
AT&T, France Telecom, NTT, Universite de Sherbrooke, Lucent Technologies
All rights reserved.
*/
#include "typedef.h"
#include "basic_op.h"
#include "ld8a.h"
#include "tab_ld8a.h"
/*---------------------------------------------------------------------------*
* Function Dec_gain *
* ~~~~~~~~~~~~~~~~~~ *
* Decode the pitch and codebook gains *
* *
*---------------------------------------------------------------------------*
* input arguments: *
* *
* index :Quantization index *
* code[] :Innovative code vector *
* L_subfr :Subframe size *
* bfi :Bad frame indicator *
* *
* output arguments: *
* *
* gain_pit :Quantized pitch gain *
* gain_cod :Quantized codebook gain *
* *
*---------------------------------------------------------------------------*/
void Dec_gain(
int16_t index, /* (i) :Index of quantization. */
int16_t code[], /* (i) Q13 :Innovative vector. */
int16_t L_subfr, /* (i) :Subframe length. */
int16_t bfi, /* (i) :Bad frame indicator */
int16_t *gain_pit, /* (o) Q14 :Pitch gain. */
int16_t *gain_cod /* (o) Q1 :Code gain. */
)
{
int16_t index1, index2, tmp;
int16_t gcode0, exp_gcode0;
int32_t L_gbk12, L_acc, L_accb;
void Gain_predict( int16_t past_qua_en[], int16_t code[], int16_t L_subfr,
int16_t *gcode0, int16_t *exp_gcode0 );
void Gain_update( int16_t past_qua_en[], int32_t L_gbk12 );
void Gain_update_erasure( int16_t past_qua_en[] );
/* Gain predictor, Past quantized energies = -14.0 in Q10 */
static int16_t past_qua_en[4] = { -14336, -14336, -14336, -14336 };
/*-------------- Case of erasure. ---------------*/
if(bfi != 0){
*gain_pit = mult( *gain_pit, 29491 ); /* *0.9 in Q15 */
if (sub( *gain_pit, 29491) > 0) *gain_pit = 29491;
*gain_cod = mult( *gain_cod, 32111 ); /* *0.98 in Q15 */
/*----------------------------------------------*
* update table of past quantized energies *
* (frame erasure) *
*----------------------------------------------*/
Gain_update_erasure(past_qua_en);
return;
}
/*-------------- Decode pitch gain ---------------*/
index1 = imap1[ shr(index,NCODE2_B) ] ;
index2 = imap2[ index & (NCODE2-1) ] ;
*gain_pit = add( gbk1[index1][0], gbk2[index2][0] );
/*-------------- Decode codebook gain ---------------*/
/*---------------------------------------------------*
*- energy due to innovation -*
*- predicted energy -*
*- predicted codebook gain => gcode0[exp_gcode0] -*
*---------------------------------------------------*/
Gain_predict( past_qua_en, code, L_subfr, &gcode0, &exp_gcode0 );
/*-----------------------------------------------------------------*
* *gain_code = (gbk1[indice1][1]+gbk2[indice2][1]) * gcode0; *
*-----------------------------------------------------------------*/
L_acc = L_deposit_l( gbk1[index1][1] );
L_accb = L_deposit_l( gbk2[index2][1] );
L_gbk12 = L_add( L_acc, L_accb ); /* Q13 */
tmp = extract_l( L_shr( L_gbk12,1 ) ); /* Q12 */
L_acc = L_mult(tmp, gcode0); /* Q[exp_gcode0+12+1] */
L_acc = L_shl(L_acc, add( negate(exp_gcode0),(-12-1+1+16) ));
*gain_cod = extract_h( L_acc ); /* Q1 */
/*----------------------------------------------*
* update table of past quantized energies *
*----------------------------------------------*/
Gain_update( past_qua_en, L_gbk12 );
return;
}