~ubuntu-branches/ubuntu/karmic/asterisk/karmic

« back to all changes in this revision

Viewing changes to codecs/lpc10/vparms.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2002-04-27 21:19:32 UTC
  • Revision ID: james.westby@ubuntu.com-20020427211932-kqaertc4bg7ss5mc
Tags: upstream-0.1.11
ImportĀ upstreamĀ versionĀ 0.1.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
$Log: vparms.c,v $
 
4
Revision 1.2  2000/01/05 08:20:40  markster
 
5
Some OSS fixes and a few lpc changes to make it actually work
 
6
 
 
7
 * Revision 1.1  1996/08/19  22:30:04  jaf
 
8
 * Initial revision
 
9
 *
 
10
 
 
11
*/
 
12
 
 
13
#ifdef P_R_O_T_O_T_Y_P_E_S
 
14
extern int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__);
 
15
#endif
 
16
 
 
17
/*  -- translated by f2c (version 19951025).
 
18
   You must link the resulting object file with the libraries:
 
19
        -lf2c -lm   (in that order)
 
20
*/
 
21
 
 
22
#include "f2c.h"
 
23
 
 
24
/* Table of constant values */
 
25
 
 
26
static real c_b2 = 1.f;
 
27
 
 
28
/* ********************************************************************* */
 
29
 
 
30
/*      VPARMS Version 50 */
 
31
 
 
32
/* $Log: vparms.c,v $
 
33
/* Revision 1.2  2000/01/05 08:20:40  markster
 
34
/* Some OSS fixes and a few lpc changes to make it actually work
 
35
/*
 
36
 * Revision 1.1  1996/08/19  22:30:04  jaf
 
37
 * Initial revision
 
38
 * */
 
39
/* Revision 1.6  1996/03/29  18:01:16  jaf */
 
40
/* Added some more comments about the range of INBUF and LPBUF that can */
 
41
/* be read.  Note that it is possible for index VWIN(2)+1 to be read from */
 
42
/* INBUF, which might be outside of its defined range, although that will */
 
43
/* require more careful checking. */
 
44
 
 
45
/* Revision 1.5  1996/03/19  00:02:02  jaf */
 
46
/* I just noticed that the argument DITHER is modified inside of this */
 
47
/* subroutine.  Comments were added explaining the possible final values. */
 
48
 
 
49
/* Revision 1.4  1996/03/18  22:22:59  jaf */
 
50
/* Finishing the job I said I did with the last check-in comments. */
 
51
 
 
52
/* Revision 1.3  1996/03/18  22:22:17  jaf */
 
53
/* Just added a few comments about which array indices of the arguments */
 
54
/* are used, and mentioning that this subroutine has no local state. */
 
55
 
 
56
/* Revision 1.2  1996/03/13  15:02:58  jaf */
 
57
/* Comments added explaining that none of the local variables of this */
 
58
/* subroutine need to be saved from one invocation to the next. */
 
59
 
 
60
/* Revision 1.1  1996/02/07 14:50:42  jaf */
 
61
/* Initial revision */
 
62
 
 
63
 
 
64
/* ********************************************************************* */
 
65
 
 
66
/*  Calculate voicing parameters: */
 
67
 
 
68
/* Input: */
 
69
/*  VWIN   - Voicing window limits */
 
70
/*           Indices 1 through 2 read. */
 
71
/*  INBUF  - Input speech buffer */
 
72
/*           Indices START-1 through STOP read, */
 
73
/*          where START and STOP are defined in the code (only written once).
 
74
*/
 
75
/*           Note that STOP can be as large as VWIN(2)+1 ! */
 
76
/*  LPBUF  - Low pass filtered speech */
 
77
/*           Indices START-MINTAU through STOP+MINTAU read, */
 
78
/*          where START and STOP are defined in the code (only written once).
 
79
*/
 
80
/*  BUFLIM - Array bounds for INBUF and LPBUF */
 
81
/*           Indices 1 through 4 read. */
 
82
/*  HALF   - Half frame (1 or 2) */
 
83
/*  MINTAU - Lag corresponding to minimum AMDF value (pitch estimate) */
 
84
/* Input/Output: */
 
85
/*  DITHER - Zero crossing threshold */
 
86
/*           The resulting value might be the negation of the input */
 
87
/*           value.  It might always be the same as the input value, */
 
88
/*           if the DO loop below always executes an even number of times. */
 
89
/* Output: (all of them are written on every call) */
 
90
/*  ZC     - Zero crossing rate */
 
91
/*  LBE    - Low band energy (sum of magnitudes - SM) */
 
92
/*  FBE    - Full band energy (SM) */
 
93
/*  QS     - Ratio of 6 dB/oct preemphasized energy to full band energy */
 
94
/*  RC1    - First reflection coefficient */
 
95
/*  AR_B   - Product of the causal forward and reverse pitch */
 
96
/*           prediction gains */
 
97
/*  AR_F   - Product of the noncausal forward and reverse pitch */
 
98
/*           prediction gains */
 
99
/* Internal: */
 
100
/*  OLDSGN - Previous sign of dithered signal */
 
101
/*  VLEN   - Length of voicing window */
 
102
/*  START  - Lower address of current half of voicing window */
 
103
/*  STOP   - Upper address of current half of voicing window */
 
104
/*  E_0    - Energy of LPF speech (sum of squares - SS) */
 
105
/*  E_B    - Energy of LPF speech backward one pitch period (SS) */
 
106
/*  E_F    - Energy of LPF speech forward one pitch period (SS) */
 
107
/*  R_B    - Autocovariance of LPF speech backward one pitch period */
 
108
/*  R_F    - Autocovariance of LPF speech forward one pitch period */
 
109
/*  LP_RMS - Energy of LPF speech (sum of magnitudes - SM) */
 
110
/*  AP_RMS - Energy of all-pass speech (SM) */
 
111
/*  E_PRE  - Energy of 6dB preemphasized speech (SM) */
 
112
/*  E0AP   - Energy of all-pass speech (SS) */
 
113
 
 
114
/* This subroutine has no local state. */
 
115
 
 
116
/* Subroutine */ int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer 
 
117
        *buflim, integer *half, real *dither, integer *mintau, integer *zc, 
 
118
        integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *
 
119
        ar_f__)
 
120
{
 
121
    /* System generated locals */
 
122
    integer inbuf_offset, lpbuf_offset, i__1;
 
123
    real r__1, r__2;
 
124
 
 
125
    /* Builtin functions */
 
126
    double r_sign(real *, real *);
 
127
    integer i_nint(real *);
 
128
 
 
129
    /* Local variables */
 
130
    integer vlen, stop, i__;
 
131
    real e_pre__;
 
132
    integer start;
 
133
    real ap_rms__, e_0__, oldsgn, lp_rms__, e_b__, e_f__, r_b__, r_f__, e0ap;
 
134
 
 
135
/*       Arguments */
 
136
/*       Local variables that need not be saved */
 
137
/*   Calculate zero crossings (ZC) and several energy and correlation */
 
138
/*   measures on low band and full band speech.  Each measure is taken */
 
139
/*   over either the first or the second half of the voicing window, */
 
140
/*   depending on the variable HALF. */
 
141
    /* Parameter adjustments */
 
142
    --vwin;
 
143
    --buflim;
 
144
    lpbuf_offset = buflim[3];
 
145
    lpbuf -= lpbuf_offset;
 
146
    inbuf_offset = buflim[1];
 
147
    inbuf -= inbuf_offset;
 
148
 
 
149
    /* Function Body */
 
150
    lp_rms__ = 0.f;
 
151
    ap_rms__ = 0.f;
 
152
    e_pre__ = 0.f;
 
153
    e0ap = 0.f;
 
154
    *rc1 = 0.f;
 
155
    e_0__ = 0.f;
 
156
    e_b__ = 0.f;
 
157
    e_f__ = 0.f;
 
158
    r_f__ = 0.f;
 
159
    r_b__ = 0.f;
 
160
    *zc = 0;
 
161
    vlen = vwin[2] - vwin[1] + 1;
 
162
    start = vwin[1] + (*half - 1) * vlen / 2 + 1;
 
163
    stop = start + vlen / 2 - 1;
 
164
 
 
165
/* I'll use the symbol HVL in the table below to represent the value */
 
166
/* VLEN/2.  Note that if VLEN is odd, then HVL should be rounded down, */
 
167
/* i.e., HVL = (VLEN-1)/2. */
 
168
 
 
169
/* HALF  START          STOP */
 
170
 
 
171
/* 1     VWIN(1)+1      VWIN(1)+HVL */
 
172
/* 2     VWIN(1)+HVL+1  VWIN(1)+2*HVL */
 
173
 
 
174
/* Note that if VLEN is even and HALF is 2, then STOP will be */
 
175
/* VWIN(1)+VLEN = VWIN(2)+1.  That could be bad, if that index of INBUF */
 
176
/* is undefined. */
 
177
 
 
178
    r__1 = inbuf[start - 1] - *dither;
 
179
    oldsgn = r_sign(&c_b2, &r__1);
 
180
    i__1 = stop;
 
181
    for (i__ = start; i__ <= i__1; ++i__) {
 
182
        lp_rms__ += (r__1 = lpbuf[i__], abs(r__1));
 
183
        ap_rms__ += (r__1 = inbuf[i__], abs(r__1));
 
184
        e_pre__ += (r__1 = inbuf[i__] - inbuf[i__ - 1], abs(r__1));
 
185
/* Computing 2nd power */
 
186
        r__1 = inbuf[i__];
 
187
        e0ap += r__1 * r__1;
 
188
        *rc1 += inbuf[i__] * inbuf[i__ - 1];
 
189
/* Computing 2nd power */
 
190
        r__1 = lpbuf[i__];
 
191
        e_0__ += r__1 * r__1;
 
192
/* Computing 2nd power */
 
193
        r__1 = lpbuf[i__ - *mintau];
 
194
        e_b__ += r__1 * r__1;
 
195
/* Computing 2nd power */
 
196
        r__1 = lpbuf[i__ + *mintau];
 
197
        e_f__ += r__1 * r__1;
 
198
        r_f__ += lpbuf[i__] * lpbuf[i__ + *mintau];
 
199
        r_b__ += lpbuf[i__] * lpbuf[i__ - *mintau];
 
200
        r__1 = inbuf[i__] + *dither;
 
201
        if (r_sign(&c_b2, &r__1) != oldsgn) {
 
202
            ++(*zc);
 
203
            oldsgn = -oldsgn;
 
204
        }
 
205
        *dither = -(*dither);
 
206
    }
 
207
/*   Normalized short-term autocovariance coefficient at unit sample delay
 
208
 */
 
209
    *rc1 /= max(e0ap,1.f);
 
210
/*  Ratio of the energy of the first difference signal (6 dB/oct preemphas
 
211
is)*/
 
212
/*   to the energy of the full band signal */
 
213
/* Computing MAX */
 
214
    r__1 = ap_rms__ * 2.f;
 
215
    *qs = e_pre__ / max(r__1,1.f);
 
216
/*   aR_b is the product of the forward and reverse prediction gains, */
 
217
/*   looking backward in time (the causal case). */
 
218
    *ar_b__ = r_b__ / max(e_b__,1.f) * (r_b__ / max(e_0__,1.f));
 
219
/*  aR_f is the same as aR_b, but looking forward in time (non causal case
 
220
).*/
 
221
    *ar_f__ = r_f__ / max(e_f__,1.f) * (r_f__ / max(e_0__,1.f));
 
222
/*   Normalize ZC, LBE, and FBE to old fixed window length of 180. */
 
223
/*   (The fraction 90/VLEN has a range of .58 to 1) */
 
224
    r__2 = (real) (*zc << 1);
 
225
    r__1 = r__2 * (90.f / vlen);
 
226
    *zc = i_nint(&r__1);
 
227
/* Computing MIN */
 
228
    r__1 = lp_rms__ / 4 * (90.f / vlen);
 
229
    i__1 = i_nint(&r__1);
 
230
    *lbe = min(i__1,32767);
 
231
/* Computing MIN */
 
232
    r__1 = ap_rms__ / 4 * (90.f / vlen);
 
233
    i__1 = i_nint(&r__1);
 
234
    *fbe = min(i__1,32767);
 
235
    return 0;
 
236
} /* vparms_ */
 
237