-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtaming.c
135 lines (111 loc) · 3.54 KB
/
taming.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
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.
*/
/**************************************************************************
* Taming functions. *
**************************************************************************/
#include "typedef.h"
#include "basic_op.h"
#include "oper_32b.h"
#include "ld8a.h"
#include "tab_ld8a.h"
static int32_t L_exc_err[4];
void Init_exc_err(void)
{
int16_t i;
for(i=0; i<4; i++) L_exc_err[i] = 0x00004000L; /* Q14 */
}
/**************************************************************************
* routine test_err - computes the accumulated potential error in the *
* adaptive codebook contribution *
**************************************************************************/
int16_t test_err( /* (o) flag set to 1 if taming is necessary */
int16_t T0, /* (i) integer part of pitch delay */
int16_t T0_frac /* (i) fractional part of pitch delay */
)
{
int16_t i, t1, zone1, zone2, flag;
int32_t L_maxloc, L_acc;
if(T0_frac > 0) {
t1 = add(T0, 1);
}
else {
t1 = T0;
}
i = sub(t1, (L_SUBFR+L_INTER10));
if(i < 0) {
i = 0;
}
zone1 = tab_zone[i];
i = add(t1, (L_INTER10 - 2));
zone2 = tab_zone[i];
L_maxloc = -1L;
flag = 0 ;
for(i=zone2; i>=zone1; i--) {
L_acc = L_sub(L_exc_err[i], L_maxloc);
if(L_acc > 0L) {
L_maxloc = L_exc_err[i];
}
}
L_acc = L_sub(L_maxloc, L_THRESH_ERR);
if(L_acc > 0L) {
flag = 1;
}
return(flag);
}
/**************************************************************************
*routine update_exc_err - maintains the memory used to compute the error *
* function due to an adaptive codebook mismatch between encoder and *
* decoder *
**************************************************************************/
void update_exc_err(
int16_t gain_pit, /* (i) pitch gain */
int16_t T0 /* (i) integer part of pitch delay */
)
{
int16_t i, zone1, zone2, n;
int32_t L_worst, L_temp, L_acc;
int16_t hi, lo;
L_worst = -1L;
n = sub(T0, L_SUBFR);
if(n < 0) {
L_Extract(L_exc_err[0], &hi, &lo);
L_temp = Mpy_32_16(hi, lo, gain_pit);
L_temp = L_shl(L_temp, 1);
L_temp = L_add(0x00004000L, L_temp);
L_acc = L_sub(L_temp, L_worst);
if(L_acc > 0L) {
L_worst = L_temp;
}
L_Extract(L_temp, &hi, &lo);
L_temp = Mpy_32_16(hi, lo, gain_pit);
L_temp = L_shl(L_temp, 1);
L_temp = L_add(0x00004000L, L_temp);
L_acc = L_sub(L_temp, L_worst);
if(L_acc > 0L) {
L_worst = L_temp;
}
}
else {
zone1 = tab_zone[n];
i = sub(T0, 1);
zone2 = tab_zone[i];
for(i = zone1; i <= zone2; i++) {
L_Extract(L_exc_err[i], &hi, &lo);
L_temp = Mpy_32_16(hi, lo, gain_pit);
L_temp = L_shl(L_temp, 1);
L_temp = L_add(0x00004000L, L_temp);
L_acc = L_sub(L_temp, L_worst);
if(L_acc > 0L) L_worst = L_temp;
}
}
for(i=3; i>=1; i--) {
L_exc_err[i] = L_exc_err[i-1];
}
L_exc_err[0] = L_worst;
return;
}