-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.h
163 lines (148 loc) · 10.3 KB
/
utils.h
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
utils.h
Copyright (C) 2011 Belledonne Communications, Grenoble, France
Author : Johan Pascal
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef UTILS_H
#define UTILS_H
/*****************************************************************************/
/* insertionSort : sort an array in growing order using insertion algorithm */
/* parameters : */
/* -(i/o) x: the array to be sorted */
/* -(i) length: the array length */
/* */
/*****************************************************************************/
void insertionSort(word16_t x[], int length);
/*****************************************************************************/
/* computeParity : compute parity for pitch delay adaptative codebook index */
/* XOR of the 6 MSB (pitchDelay on 8 bits) */
/* parameters : */
/* -(i) adaptativeCodebookIndex: the pitch delay on 8 bits */
/* return value : */
/* the parity bit */
/* */
/*****************************************************************************/
uint16_t computeParity(uint16_t adaptativeCodebookIndex);
/*****************************************************************************/
/* rearrangeCoefficients: rearrange coefficients according to spec 3.2.4 */
/* Have a minimum distance of J beetwen two consecutive coefficients */
/* parameters: */
/* -(i/o) qLSP: 10 ordered coefficients in Q13 replaced by new values */
/* if needed */
/* -(i) J: minimum distance between coefficients in Q0.13 (10 or 5) */
/* */
/*****************************************************************************/
void rearrangeCoefficients(word16_t qLSP[], word16_t J);
/*****************************************************************************/
/* synthesisFilter : compute 1/[A(z)] using the following algorithm */
/* filteredSignal[n] = inputSignal[n] */
/* - Sum(i=1..10)filterCoefficients[i]*filteredSignal[n-i] */
/* for n in [0, L_SUBFRAME[ */
/* parameters: */
/* -(i) inputSignal: 40 values in Q0 */
/* -(i) filterCoefficients: 10 coefficients in Q12 */
/* -(i/o) filteredSignal: 50 values in Q0 accessed in ranges [-10,-1] */
/* as input and [0, 39] as output. */
/* */
/*****************************************************************************/
void synthesisFilter(word16_t inputSignal[], word16_t filterCoefficients[], word16_t filteredSignal[]);
/*****************************************************************************/
/* correlateVectors : compute the correlations between two vectors of */
/* L_SUBFRAME length: c[i] = Sum(x[j]*y[j-i]) j in [i..L_SUBFRAME] */
/* parameters: */
/* -(i) x : L_SUBFRAME length input vector on 16 bits */
/* -(i) y : L_SUBFRAME length input vector on 16 bits */
/* -(o) c : L_SUBFRAME length output vector on 32 bits */
/* */
/*****************************************************************************/
void correlateVectors (word16_t x[], word16_t y[], word32_t c[]);
/*****************************************************************************/
/* countLeadingZeros : return the number of zero heading the argument */
/* MSB is excluded as considered sign bit. */
/* May be replaced by one asm instruction. */
/* parameters : */
/* -(i) x : 32 bits values >= 0 (no checking done by this function) */
/* return value : */
/* - number of heading zeros(MSB excluded. Ex: 0x0080 00000 returns 7) */
/* */
/*****************************************************************************/
static inline uint16_t countLeadingZeros(word32_t x)
{
if (x==0) return 31;
uint16_t leadingZeros = 0;
while (x<(word32_t)0x40000000) {
leadingZeros++;
x <<=1;
}
return leadingZeros;
}
/*** gain related functions ***/
/*****************************************************************************/
/* MACodeGainPrediction : spec 3.9.1 */
/* parameters: */
/* -(i) previousGainPredictionError: qU(m) in eq69 4 values in Q10 */
/* -(i) fixedCodebookVector: the current subframe fixed codebook vector */
/* 40 values in Q1.13 */
/* return value : */
/* - predicted Fixed Codebook gain on 32 bits in Q16 range [3, 1830] */
/* */
/*****************************************************************************/
word32_t MACodeGainPrediction(word16_t *previousGainPredictionError, word16_t *fixedCodebookVector);
/*****************************************************************************/
/* computeGainPredictionError : apply eq72 to compute current fixed Codebook */
/* gain prediction error and store the result in the adhoc array */
/* parameters : */
/* -(i) fixedCodebookGainCorrectionFactor: gamma in eq72 in Q3.12 */
/* -(i/o) previousGainPredictionError: array to be updated in Q10 */
/* */
/*****************************************************************************/
void computeGainPredictionError(word16_t fixedCodebookGainCorrectionFactor, word16_t *previousGainPredictionError);
/*** bitStream to parameters Array conversions functions ***/
/* Note: these functions are in utils.c because used by test source code too */
/*****************************************************************************/
/* parametersArray2BitStream : convert array of parameters to bitStream */
/* according to spec 4 - Table 8 and following mapping of values */
/* 0 -> L0 (1 bit) */
/* 1 -> L1 (7 bits) */
/* 2 -> L2 (5 bits) */
/* 3 -> L3 (5 bits) */
/* 4 -> P1 (8 bit) */
/* 5 -> P0 (1 bits) */
/* 6 -> C1 (13 bits) */
/* 7 -> S1 (4 bits) */
/* 8 -> GA1(3 bits) */
/* 9 -> GB1(4 bits) */
/* 10 -> P2 (5 bits) */
/* 11 -> C2 (13 bits) */
/* 12 -> S2 (4 bits) */
/* 13 -> GA2(3 bits) */
/* 14 -> GB2(4 bits) */
/* parameters: */
/* -(i) parameters : 16 values parameters array */
/* -(o) bitStream : the 16 values streamed on 80 bits in a */
/* 10*8bits values array */
/* */
/*****************************************************************************/
void parametersArray2BitStream(uint16_t parameters[], uint8_t bitStream[]);
/*****************************************************************************/
/* parametersArray2BitStream : convert bitStream to an array of parameters */
/* reverse operation of previous funtion */
/* parameters: */
/* -(i) bitStream : the 16 values streamed on 80 bits in a */
/* 10*8bits values array */
/* -(o) parameters : 16 values parameters array */
/* */
/*****************************************************************************/
void parametersBitStream2Array(uint8_t bitStream[], uint16_t parameters[]);
#endif /* ifndef UTILS_H */