~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/third_party/gsm/src/short_term.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3
 
 * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
4
 
 * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5
 
 */
6
 
 
7
 
/* $Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/short_term.c,v 1.2 1994/05/10 20:18:47 jutta Exp $ */
8
 
 
9
 
#include "config.h"
10
 
#include <stdio.h>
11
 
#include <assert.h>
12
 
 
13
 
#include "private.h"
14
 
 
15
 
#include "gsm.h"
16
 
#include "proto.h"
17
 
 
18
 
/*
19
 
 *  SHORT TERM ANALYSIS FILTERING SECTION
20
 
 */
21
 
 
22
 
/* 4.2.8 */
23
 
 
24
 
static void Decoding_of_the_coded_Log_Area_Ratios P2((LARc,LARpp),
25
 
        word    * LARc,         /* coded log area ratio [0..7]  IN      */
26
 
        word    * LARpp)        /* out: decoded ..                      */
27
 
{
28
 
        register word   temp1 /* , temp2 */;
29
 
        register long   ltmp;   /* for GSM_ADD */
30
 
 
31
 
        /*  This procedure requires for efficient implementation
32
 
         *  two tables.
33
 
         *
34
 
         *  INVA[1..8] = integer( (32768 * 8) / real_A[1..8])
35
 
         *  MIC[1..8]  = minimum value of the LARc[1..8]
36
 
         */
37
 
 
38
 
        /*  Compute the LARpp[1..8]
39
 
         */
40
 
 
41
 
        /*      for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {
42
 
         *
43
 
         *              temp1  = GSM_ADD( *LARc, *MIC ) << 10;
44
 
         *              temp2  = *B << 1;
45
 
         *              temp1  = GSM_SUB( temp1, temp2 );
46
 
         *
47
 
         *              assert(*INVA != MIN_WORD);
48
 
         *
49
 
         *              temp1  = GSM_MULT_R( *INVA, temp1 );
50
 
         *              *LARpp = GSM_ADD( temp1, temp1 );
51
 
         *      }
52
 
         */
53
 
 
54
 
#undef  STEP
55
 
#define STEP( B, MIC, INVA )    \
56
 
                temp1    = GSM_ADD( *LARc++, MIC ) << 10;       \
57
 
                temp1    = GSM_SUB( temp1, B << 1 );            \
58
 
                temp1    = GSM_MULT_R( INVA, temp1 );           \
59
 
                *LARpp++ = GSM_ADD( temp1, temp1 );
60
 
 
61
 
        STEP(      0,  -32,  13107 );
62
 
        STEP(      0,  -32,  13107 );
63
 
        STEP(   2048,  -16,  13107 );
64
 
        STEP(  -2560,  -16,  13107 );
65
 
 
66
 
        STEP(     94,   -8,  19223 );
67
 
        STEP(  -1792,   -8,  17476 );
68
 
        STEP(   -341,   -4,  31454 );
69
 
        STEP(  -1144,   -4,  29708 );
70
 
 
71
 
        /* NOTE: the addition of *MIC is used to restore
72
 
         *       the sign of *LARc.
73
 
         */
74
 
}
75
 
 
76
 
/* 4.2.9 */
77
 
/* Computation of the quantized reflection coefficients
78
 
 */
79
 
 
80
 
/* 4.2.9.1  Interpolation of the LARpp[1..8] to get the LARp[1..8]
81
 
 */
82
 
 
83
 
/*
84
 
 *  Within each frame of 160 analyzed speech samples the short term
85
 
 *  analysis and synthesis filters operate with four different sets of
86
 
 *  coefficients, derived from the previous set of decoded LARs(LARpp(j-1))
87
 
 *  and the actual set of decoded LARs (LARpp(j))
88
 
 *
89
 
 * (Initial value: LARpp(j-1)[1..8] = 0.)
90
 
 */
91
 
 
92
 
static void Coefficients_0_12 P3((LARpp_j_1, LARpp_j, LARp),
93
 
        register word * LARpp_j_1,
94
 
        register word * LARpp_j,
95
 
        register word * LARp)
96
 
{
97
 
        register int    i;
98
 
        register longword ltmp;
99
 
 
100
 
        for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) {
101
 
                *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
102
 
                *LARp = GSM_ADD( *LARp,  SASR( *LARpp_j_1, 1));
103
 
        }
104
 
}
105
 
 
106
 
static void Coefficients_13_26 P3((LARpp_j_1, LARpp_j, LARp),
107
 
        register word * LARpp_j_1,
108
 
        register word * LARpp_j,
109
 
        register word * LARp)
110
 
{
111
 
        register int i;
112
 
        register longword ltmp;
113
 
        for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
114
 
                *LARp = GSM_ADD( SASR( *LARpp_j_1, 1), SASR( *LARpp_j, 1 ));
115
 
        }
116
 
}
117
 
 
118
 
static void Coefficients_27_39 P3((LARpp_j_1, LARpp_j, LARp),
119
 
        register word * LARpp_j_1,
120
 
        register word * LARpp_j,
121
 
        register word * LARp)
122
 
{
123
 
        register int i;
124
 
        register longword ltmp;
125
 
 
126
 
        for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
127
 
                *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
128
 
                *LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 ));
129
 
        }
130
 
}
131
 
 
132
 
 
133
 
static void Coefficients_40_159 P2((LARpp_j, LARp),
134
 
        register word * LARpp_j,
135
 
        register word * LARp)
136
 
{
137
 
        register int i;
138
 
 
139
 
        for (i = 1; i <= 8; i++, LARp++, LARpp_j++)
140
 
                *LARp = *LARpp_j;
141
 
}
142
 
 
143
 
/* 4.2.9.2 */
144
 
 
145
 
static void LARp_to_rp P1((LARp),
146
 
        register word * LARp)   /* [0..7] IN/OUT  */
147
 
/*
148
 
 *  The input of this procedure is the interpolated LARp[0..7] array.
149
 
 *  The reflection coefficients, rp[i], are used in the analysis
150
 
 *  filter and in the synthesis filter.
151
 
 */
152
 
{
153
 
        register int            i;
154
 
        register word           temp;
155
 
        register longword       ltmp;
156
 
 
157
 
        for (i = 1; i <= 8; i++, LARp++) {
158
 
 
159
 
                /* temp = GSM_ABS( *LARp );
160
 
                 *
161
 
                 * if (temp < 11059) temp <<= 1;
162
 
                 * else if (temp < 20070) temp += 11059;
163
 
                 * else temp = GSM_ADD( temp >> 2, 26112 );
164
 
                 *
165
 
                 * *LARp = *LARp < 0 ? -temp : temp;
166
 
                 */
167
 
 
168
 
                if (*LARp < 0) {
169
 
                        temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp);
170
 
                        *LARp = - ((temp < 11059) ? temp << 1
171
 
                                : ((temp < 20070) ? temp + 11059
172
 
                                :  GSM_ADD( temp >> 2, 26112 )));
173
 
                } else {
174
 
                        temp  = *LARp;
175
 
                        *LARp =    (temp < 11059) ? temp << 1
176
 
                                : ((temp < 20070) ? temp + 11059
177
 
                                :  GSM_ADD( temp >> 2, 26112 ));
178
 
                }
179
 
        }
180
 
}
181
 
 
182
 
 
183
 
/* 4.2.10 */
184
 
static void Short_term_analysis_filtering P4((S,rp,k_n,s),
185
 
        struct gsm_state * S,
186
 
        register word   * rp,   /* [0..7]       IN      */
187
 
        register int    k_n,    /*   k_end - k_start    */
188
 
        register word   * s     /* [0..n-1]     IN/OUT  */
189
 
)
190
 
/*
191
 
 *  This procedure computes the short term residual signal d[..] to be fed
192
 
 *  to the RPE-LTP loop from the s[..] signal and from the local rp[..]
193
 
 *  array (quantized reflection coefficients).  As the call of this
194
 
 *  procedure can be done in many ways (see the interpolation of the LAR
195
 
 *  coefficient), it is assumed that the computation begins with index
196
 
 *  k_start (for arrays d[..] and s[..]) and stops with index k_end
197
 
 *  (k_start and k_end are defined in 4.2.9.1).  This procedure also
198
 
 *  needs to keep the array u[0..7] in memory for each call.
199
 
 */
200
 
{
201
 
        register word           * u = S->u;
202
 
        register int            i;
203
 
        register word           di, zzz, ui, sav, rpi;
204
 
        register longword       ltmp;
205
 
 
206
 
        for (; k_n--; s++) {
207
 
 
208
 
                di = sav = *s;
209
 
 
210
 
                for (i = 0; i < 8; i++) {               /* YYY */
211
 
 
212
 
                        ui    = u[i];
213
 
                        rpi   = rp[i];
214
 
                        u[i]  = sav;
215
 
 
216
 
                        zzz   = GSM_MULT_R(rpi, di);
217
 
                        sav   = GSM_ADD(   ui,  zzz);
218
 
 
219
 
                        zzz   = GSM_MULT_R(rpi, ui);
220
 
                        di    = GSM_ADD(   di,  zzz );
221
 
                }
222
 
 
223
 
                *s = di;
224
 
        }
225
 
}
226
 
 
227
 
#if defined(USE_FLOAT_MUL) && defined(FAST)
228
 
 
229
 
static void Fast_Short_term_analysis_filtering P4((S,rp,k_n,s),
230
 
        struct gsm_state * S,
231
 
        register word   * rp,   /* [0..7]       IN      */
232
 
        register int    k_n,    /*   k_end - k_start    */
233
 
        register word   * s     /* [0..n-1]     IN/OUT  */
234
 
)
235
 
{
236
 
        register word           * u = S->u;
237
 
        register int            i;
238
 
 
239
 
        float     uf[8],
240
 
                 rpf[8];
241
 
 
242
 
        register float scalef = 3.0517578125e-5;
243
 
        register float          sav, di, temp;
244
 
 
245
 
        for (i = 0; i < 8; ++i) {
246
 
                uf[i]  = u[i];
247
 
                rpf[i] = rp[i] * scalef;
248
 
        }
249
 
        for (; k_n--; s++) {
250
 
                sav = di = *s;
251
 
                for (i = 0; i < 8; ++i) {
252
 
                        register float rpfi = rpf[i];
253
 
                        register float ufi  = uf[i];
254
 
 
255
 
                        uf[i] = sav;
256
 
                        temp  = rpfi * di + ufi;
257
 
                        di   += rpfi * ufi;
258
 
                        sav   = temp;
259
 
                }
260
 
                *s = di;
261
 
        }
262
 
        for (i = 0; i < 8; ++i) u[i] = uf[i];
263
 
}
264
 
#endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */
265
 
 
266
 
static void Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),
267
 
        struct gsm_state * S,
268
 
        register word   * rrp,  /* [0..7]       IN      */
269
 
        register int    k,      /* k_end - k_start      */
270
 
        register word   * wt,   /* [0..k-1]     IN      */
271
 
        register word   * sr    /* [0..k-1]     OUT     */
272
 
)
273
 
{
274
 
        register word           * v = S->v;
275
 
        register int            i;
276
 
        register word           sri, tmp1, tmp2;
277
 
        register longword       ltmp;   /* for GSM_ADD  & GSM_SUB */
278
 
 
279
 
        while (k--) {
280
 
                sri = *wt++;
281
 
                for (i = 8; i--;) {
282
 
 
283
 
                        /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );
284
 
                         */
285
 
                        tmp1 = rrp[i];
286
 
                        tmp2 = v[i];
287
 
                        tmp2 =  ( tmp1 == MIN_WORD && tmp2 == MIN_WORD
288
 
                                ? MAX_WORD
289
 
                                : 0x0FFFF & (( (longword)tmp1 * (longword)tmp2
290
 
                                             + 16384) >> 15)) ;
291
 
 
292
 
                        sri  = GSM_SUB( sri, tmp2 );
293
 
 
294
 
                        /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );
295
 
                         */
296
 
                        tmp1  = ( tmp1 == MIN_WORD && sri == MIN_WORD
297
 
                                ? MAX_WORD
298
 
                                : 0x0FFFF & (( (longword)tmp1 * (longword)sri
299
 
                                             + 16384) >> 15)) ;
300
 
 
301
 
                        v[i+1] = GSM_ADD( v[i], tmp1);
302
 
                }
303
 
                *sr++ = v[0] = sri;
304
 
        }
305
 
}
306
 
 
307
 
 
308
 
#if defined(FAST) && defined(USE_FLOAT_MUL)
309
 
 
310
 
static void Fast_Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),
311
 
        struct gsm_state * S,
312
 
        register word   * rrp,  /* [0..7]       IN      */
313
 
        register int    k,      /* k_end - k_start      */
314
 
        register word   * wt,   /* [0..k-1]     IN      */
315
 
        register word   * sr    /* [0..k-1]     OUT     */
316
 
)
317
 
{
318
 
        register word           * v = S->v;
319
 
        register int            i;
320
 
 
321
 
        float va[9], rrpa[8];
322
 
        register float scalef = 3.0517578125e-5, temp;
323
 
 
324
 
        for (i = 0; i < 8; ++i) {
325
 
                va[i]   = v[i];
326
 
                rrpa[i] = (float)rrp[i] * scalef;
327
 
        }
328
 
        while (k--) {
329
 
                register float sri = *wt++;
330
 
                for (i = 8; i--;) {
331
 
                        sri -= rrpa[i] * va[i];
332
 
                        if     (sri < -32768.) sri = -32768.;
333
 
                        else if (sri > 32767.) sri =  32767.;
334
 
 
335
 
                        temp = va[i] + rrpa[i] * sri;
336
 
                        if     (temp < -32768.) temp = -32768.;
337
 
                        else if (temp > 32767.) temp =  32767.;
338
 
                        va[i+1] = temp;
339
 
                }
340
 
                *sr++ = va[0] = sri;
341
 
        }
342
 
        for (i = 0; i < 9; ++i) v[i] = va[i];
343
 
}
344
 
 
345
 
#endif /* defined(FAST) && defined(USE_FLOAT_MUL) */
346
 
 
347
 
void Gsm_Short_Term_Analysis_Filter P3((S,LARc,s),
348
 
 
349
 
        struct gsm_state * S,
350
 
 
351
 
        word    * LARc,         /* coded log area ratio [0..7]  IN      */
352
 
        word    * s             /* signal [0..159]              IN/OUT  */
353
 
)
354
 
{
355
 
        word            * LARpp_j       = S->LARpp[ S->j      ];
356
 
        word            * LARpp_j_1     = S->LARpp[ S->j ^= 1 ];
357
 
 
358
 
        word            LARp[8];
359
 
 
360
 
#undef  FILTER
361
 
#if     defined(FAST) && defined(USE_FLOAT_MUL)
362
 
#       define  FILTER  (* (S->fast                     \
363
 
                           ? Fast_Short_term_analysis_filtering \
364
 
                           : Short_term_analysis_filtering      ))
365
 
 
366
 
#else
367
 
#       define  FILTER  Short_term_analysis_filtering
368
 
#endif
369
 
 
370
 
        Decoding_of_the_coded_Log_Area_Ratios( LARc, LARpp_j );
371
 
 
372
 
        Coefficients_0_12(  LARpp_j_1, LARpp_j, LARp );
373
 
        LARp_to_rp( LARp );
374
 
        FILTER( S, LARp, 13, s);
375
 
 
376
 
        Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
377
 
        LARp_to_rp( LARp );
378
 
        FILTER( S, LARp, 14, s + 13);
379
 
 
380
 
        Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
381
 
        LARp_to_rp( LARp );
382
 
        FILTER( S, LARp, 13, s + 27);
383
 
 
384
 
        Coefficients_40_159( LARpp_j, LARp);
385
 
        LARp_to_rp( LARp );
386
 
        FILTER( S, LARp, 120, s + 40);
387
 
}
388
 
 
389
 
void Gsm_Short_Term_Synthesis_Filter P4((S, LARcr, wt, s),
390
 
        struct gsm_state * S,
391
 
 
392
 
        word    * LARcr,        /* received log area ratios [0..7] IN  */
393
 
        word    * wt,           /* received d [0..159]             IN  */
394
 
 
395
 
        word    * s             /* signal   s [0..159]            OUT  */
396
 
)
397
 
{
398
 
        word            * LARpp_j       = S->LARpp[ S->j     ];
399
 
        word            * LARpp_j_1     = S->LARpp[ S->j ^=1 ];
400
 
 
401
 
        word            LARp[8];
402
 
 
403
 
#undef  FILTER
404
 
#if     defined(FAST) && defined(USE_FLOAT_MUL)
405
 
 
406
 
#       define  FILTER  (* (S->fast                     \
407
 
                           ? Fast_Short_term_synthesis_filtering        \
408
 
                           : Short_term_synthesis_filtering     ))
409
 
#else
410
 
#       define  FILTER  Short_term_synthesis_filtering
411
 
#endif
412
 
 
413
 
        Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j );
414
 
 
415
 
        Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
416
 
        LARp_to_rp( LARp );
417
 
        FILTER( S, LARp, 13, wt, s );
418
 
 
419
 
        Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
420
 
        LARp_to_rp( LARp );
421
 
        FILTER( S, LARp, 14, wt + 13, s + 13 );
422
 
 
423
 
        Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
424
 
        LARp_to_rp( LARp );
425
 
        FILTER( S, LARp, 13, wt + 27, s + 27 );
426
 
 
427
 
        Coefficients_40_159( LARpp_j, LARp );
428
 
        LARp_to_rp( LARp );
429
 
        FILTER(S, LARp, 120, wt + 40, s + 40);
430
 
}