Asterisk - The Open Source Telephony Project GIT-master-7e7a603
synths.c
Go to the documentation of this file.
1/*
2
3$Log$
4Revision 1.16 2004/06/26 03:50:14 markster
5Merge source cleanups (bug #1911)
6
7Revision 1.15 2003/09/27 02:45:37 markster
8Fix various compiler warnings (bug #322)
9
10Revision 1.2 2003/09/27 02:45:37 markster
11Fix various compiler warnings (bug #322)
12
13Revision 1.1.1.1 2003/02/12 13:59:15 matteo
14mer feb 12 14:56:57 CET 2003
15
16Revision 1.2 2000/01/05 08:20:39 markster
17Some OSS fixes and a few lpc changes to make it actually work
18
19 * Revision 1.2 1996/08/20 20:42:59 jaf
20 * Removed all static local variables that were SAVE'd in the Fortran
21 * code, and put them in struct lpc10_decoder_state that is passed as an
22 * argument.
23 *
24 * Removed init function, since all initialization is now done in
25 * init_lpc10_decoder_state().
26 *
27 * Revision 1.1 1996/08/19 22:30:33 jaf
28 * Initial revision
29 *
30
31*/
32
33/* -- translated by f2c (version 19951025).
34 You must link the resulting object file with the libraries:
35 -lf2c -lm (in that order)
36*/
37
38#include "f2c.h"
39
40#ifdef P_R_O_T_O_T_Y_P_E_S
41extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st);
42/* comlen contrl_ 12 */
43/*:ref: pitsyn_ 14 12 4 4 4 6 6 4 4 4 6 6 4 6 */
44/*:ref: irc2pc_ 14 5 6 6 4 6 6 */
45/*:ref: bsynz_ 14 7 6 4 4 6 6 6 6 */
46/*:ref: deemp_ 14 2 6 4 */
47/*:ref: initpitsyn_ 14 0 */
48/*:ref: initbsynz_ 14 0 */
49/*:ref: initdeemp_ 14 0 */
50#endif
51
52/* Common Block Declarations */
53
54extern struct {
58
59#define contrl_1 contrl_
60
61/* Table of constant values */
62
63static real c_b2 = .7f;
64
65/* ***************************************************************** */
66
67/* SYNTHS Version 54 */
68
69/* $Log$
70 * Revision 1.16 2004/06/26 03:50:14 markster
71 * Merge source cleanups (bug #1911)
72 *
73 * Revision 1.15 2003/09/27 02:45:37 markster
74 * Fix various compiler warnings (bug #322)
75 *
76 * Revision 1.2 2003/09/27 02:45:37 markster
77 * Fix various compiler warnings (bug #322)
78 *
79 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
80 * mer feb 12 14:56:57 CET 2003
81 *
82 * Revision 1.2 2000/01/05 08:20:39 markster
83 * Some OSS fixes and a few lpc changes to make it actually work
84 *
85 * Revision 1.2 1996/08/20 20:42:59 jaf
86 * Removed all static local variables that were SAVE'd in the Fortran
87 * code, and put them in struct lpc10_decoder_state that is passed as an
88 * argument.
89 *
90 * Removed init function, since all initialization is now done in
91 * init_lpc10_decoder_state().
92 *
93 * Revision 1.1 1996/08/19 22:30:33 jaf
94 * Initial revision
95 * */
96/* Revision 1.5 1996/03/26 19:31:58 jaf */
97/* Commented out trace statements. */
98
99/* Revision 1.4 1996/03/25 19:41:01 jaf */
100/* Changed so that MAXFRM samples are always returned in the output array */
101/* SPEECH. */
102
103/* This required delaying the returned samples by MAXFRM sample times, */
104/* and remembering any "left over" samples returned by PITSYN from one */
105/* call of SYNTHS to the next. */
106
107/* Changed size of SPEECH from 2*MAXFRM to MAXFRM. Removed local */
108/* variable SOUT. Added local state variables BUF and BUFLEN. */
109
110/* Revision 1.3 1996/03/25 19:20:10 jaf */
111/* Added comments about the range of possible return values for argument */
112/* K, and increased the size of the arrays filled in by PITSYN from 11 to */
113/* 16, as has been already done inside of PITSYN. */
114
115/* Revision 1.2 1996/03/22 00:18:18 jaf */
116/* Added comments explaining meanings of input and output parameters, and */
117/* indicating which array indices can be read or written. */
118
119/* Added entry INITSYNTHS, which does nothing except call the */
120/* corresponding initialization entries for subroutines PITSYN, BSYNZ, */
121/* and DEEMP. */
122
123/* Revision 1.1 1996/02/07 14:49:44 jaf */
124/* Initial revision */
125
126
127/* ***************************************************************** */
128
129/* The note below is from the distributed version of the LPC10 coder. */
130/* The version of the code below has been modified so that SYNTHS always */
131/* has a constant frame length output of MAXFRM. */
132
133/* Also, BSYNZ and DEEMP need not be modified to work on variable */
134/* positions within an array. It is only necessary to pass the first */
135/* index desired as the array argument. What actually gets passed is the */
136/* address of that array position, which the subroutine treats as the */
137/* first index of the array. */
138
139/* This technique is used in subroutine ANALYS when calling PREEMP, so it */
140/* appears that multiple people wrote different parts of this LPC10 code, */
141/* and that they didn't necessarily have equivalent knowledge of Fortran */
142/* (not surprising). */
143
144/* NOTE: There is excessive buffering here, BSYNZ and DEEMP should be */
145/* changed to operate on variable positions within SOUT. Also, */
146/* the output length parameter is bogus, and PITSYN should be */
147/* rewritten to allow a constant frame length output. */
148
149/* Input: */
150/* VOICE - Half frame voicing decisions */
151/* Indices 1 through 2 read. */
152/* Input/Output: */
153/* PITCH - Pitch */
154/* PITCH is restricted to range 20 to 156, inclusive, */
155/* before calling subroutine PITSYN, and then PITSYN */
156/* can modify it further under some conditions. */
157/* RMS - Energy */
158/* Only use is for debugging, and passed to PITSYN. */
159/* See comments there for how it can be modified. */
160/* RC - Reflection coefficients */
161/* Indices 1 through ORDER restricted to range -.99 to .99, */
162/* before calling subroutine PITSYN, and then PITSYN */
163/* can modify it further under some conditions. */
164/* Output: */
165/* SPEECH - Synthesized speech samples. */
166/* Indices 1 through the final value of K are written. */
167/* K - Number of samples placed into array SPEECH. */
168/* This is always MAXFRM. */
169
170/* Subroutine */ int synths_(integer *voice, integer *pitch, real *
171 rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st)
172{
173 /* Initialized data */
174
175 real *buf;
176 integer *buflen;
177
178 /* System generated locals */
179 integer i__1;
180 real r__1, r__2;
181
182 /* Local variables */
183 real rmsi[16];
184 integer nout, ivuv[16], i__, j;
185 extern /* Subroutine */ int deemp_(real *, integer *, struct lpc10_decoder_state *);
186 real ratio;
187 integer ipiti[16];
188 real g2pass;
189 real pc[10];
190 extern /* Subroutine */ int pitsyn_(integer *, integer *, integer *, real
191 *, real *, integer *, integer *, integer *, real *, real *,
192 integer *, real *, struct lpc10_decoder_state *);
193 real rci[160] /* was [10][16] */;
194
195/* $Log$
196 * Revision 1.16 2004/06/26 03:50:14 markster
197 * Merge source cleanups (bug #1911)
198 *
199 * Revision 1.15 2003/09/27 02:45:37 markster
200 * Fix various compiler warnings (bug #322)
201 *
202 * Revision 1.2 2003/09/27 02:45:37 markster
203 * Fix various compiler warnings (bug #322)
204 *
205 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
206 * mer feb 12 14:56:57 CET 2003
207 *
208 * Revision 1.2 2000/01/05 08:20:39 markster
209 * Some OSS fixes and a few lpc changes to make it actually work
210 *
211 * Revision 1.2 1996/08/20 20:42:59 jaf
212 * Removed all static local variables that were SAVE'd in the Fortran
213 * code, and put them in struct lpc10_decoder_state that is passed as an
214 * argument.
215 *
216 * Removed init function, since all initialization is now done in
217 * init_lpc10_decoder_state().
218 *
219 * Revision 1.1 1996/08/19 22:30:33 jaf
220 * Initial revision
221 * */
222/* Revision 1.3 1996/03/29 22:03:47 jaf */
223/* Removed definitions for any constants that were no longer used. */
224
225/* Revision 1.2 1996/03/26 19:34:33 jaf */
226/* Added comments indicating which constants are not needed in an */
227/* application that uses the LPC-10 coder. */
228
229/* Revision 1.1 1996/02/07 14:43:51 jaf */
230/* Initial revision */
231
232/* LPC Configuration parameters: */
233/* Frame size, Prediction order, Pitch period */
234/* Arguments */
235/* $Log$
236 * Revision 1.16 2004/06/26 03:50:14 markster
237 * Merge source cleanups (bug #1911)
238 *
239 * Revision 1.15 2003/09/27 02:45:37 markster
240 * Fix various compiler warnings (bug #322)
241 *
242 * Revision 1.2 2003/09/27 02:45:37 markster
243 * Fix various compiler warnings (bug #322)
244 *
245 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
246 * mer feb 12 14:56:57 CET 2003
247 *
248 * Revision 1.2 2000/01/05 08:20:39 markster
249 * Some OSS fixes and a few lpc changes to make it actually work
250 *
251 * Revision 1.2 1996/08/20 20:42:59 jaf
252 * Removed all static local variables that were SAVE'd in the Fortran
253 * code, and put them in struct lpc10_decoder_state that is passed as an
254 * argument.
255 *
256 * Removed init function, since all initialization is now done in
257 * init_lpc10_decoder_state().
258 *
259 * Revision 1.1 1996/08/19 22:30:33 jaf
260 * Initial revision
261 * */
262/* Revision 1.3 1996/03/29 22:05:55 jaf */
263/* Commented out the common block variables that are not needed by the */
264/* embedded version. */
265
266/* Revision 1.2 1996/03/26 19:34:50 jaf */
267/* Added comments indicating which constants are not needed in an */
268/* application that uses the LPC-10 coder. */
269
270/* Revision 1.1 1996/02/07 14:44:09 jaf */
271/* Initial revision */
272
273/* LPC Processing control variables: */
274
275/* *** Read-only: initialized in setup */
276
277/* Files for Speech, Parameter, and Bitstream Input & Output, */
278/* and message and debug outputs. */
279
280/* Here are the only files which use these variables: */
281
282/* lpcsim.f setup.f trans.f error.f vqsetup.f */
283
284/* Many files which use fdebug are not listed, since it is only used in */
285/* those other files conditionally, to print trace statements. */
286/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
287/* LPC order, Frame size, Quantization rate, Bits per frame, */
288/* Error correction */
289/* Subroutine SETUP is the only place where order is assigned a value, */
290/* and that value is 10. It could increase efficiency 1% or so to */
291/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
292*/
293/* a variable in a COMMON block, since it is used in many places in the */
294/* core of the coding and decoding routines. Actually, I take that back.
295*/
296/* At least when compiling with f2c, the upper bound of DO loops is */
297/* stored in a local variable before the DO loop begins, and then that is
298*/
299/* compared against on each iteration. */
300/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
301/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
302/* is used in only a few places, and never in the core coding and */
303/* decoding routines, so it could be eliminated entirely. */
304/* nbits is similar to quant, and is given a value of 54 in SETUP. */
305/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
306/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
307/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
308*/
309/* a constant or a variable, since it is only examined once per frame. */
310/* Leaving it as a variable that is set to .TRUE. seems like a good */
311/* idea, since it does enable some error-correction capability for */
312/* unvoiced frames, with no change in the coding rate, and no noticeable
313*/
314/* quality difference in the decoded speech. */
315/* integer quant, nbits */
316/* *** Read/write: variables for debugging, not needed for LPC algorithm
317*/
318
319/* Current frame, Unstable frames, Output clip count, Max onset buffer,
320*/
321/* Debug listing detail level, Line count on listing page */
322
323/* nframe is not needed for an embedded LPC10 at all. */
324/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
325/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
326/* an application, I would recommend removing the call to ERROR in RCCHK,
327*/
328/* and remove ERROR and nunsfm completely. */
329/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
330*/
331/* sread.f. When LPC10 is embedded into an application, one might want */
332/* to cause it to be incremented in a routine that takes the output of */
333/* SYNTHS and sends it to an audio device. It could be optionally */
334/* displayed, for those that might want to know what it is. */
335/* maxosp is never initialized to 0 in SETUP, although it probably should
336*/
337/* be, and it is updated in subroutine ANALYS. I doubt that its value */
338/* would be of much interest to an application in which LPC10 is */
339/* embedded. */
340/* listl and lincnt are not needed for an embedded LPC10 at all. */
341/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
342/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
343/* common /contrl/ quant, nbits */
344/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
345/* Parameters/constants */
346/* Local variables that need not be saved */
347/* Local state */
348/* BUF is a buffer of speech samples that would have been returned
349*/
350/* by the older version of SYNTHS, but the newer version doesn't, */
351/* so that the newer version can always return MAXFRM samples on */
352/* every call. This has the effect of delaying the return of */
353/* samples for one additional frame time. */
354
355/* Indices 1 through BUFLEN contain samples that are left over from
356*/
357/* the last call to SYNTHS. Given the way that PITSYN works, */
358/* BUFLEN should always be in the range MAXFRM-MAXPIT+1 through */
359/* MAXFRM, inclusive, after a call to SYNTHS is complete. */
360
361/* On the first call to SYNTHS (or the first call after */
362/* reinitializing with the entry INITSYNTHS), BUFLEN is MAXFRM, and
363*/
364/* a frame of silence is always returned. */
365 /* Parameter adjustments */
366 if (voice) {
367 --voice;
368 }
369 if (rc) {
370 --rc;
371 }
372 if (speech) {
373 --speech;
374 }
375
376 /* Function Body */
377 buf = &(st->buf[0]);
378 buflen = &(st->buflen);
379
380/* Computing MAX */
381 i__1 = min(*pitch,156);
382 *pitch = max(i__1,20);
383 i__1 = contrl_1.order;
384 for (i__ = 1; i__ <= i__1; ++i__) {
385/* Computing MAX */
386/* Computing MIN */
387 r__2 = rc[i__];
388 r__1 = min(r__2,.99f);
389 rc[i__] = max(r__1,-.99f);
390 }
391 pitsyn_(&contrl_1.order, &voice[1], pitch, rms, &rc[1], &contrl_1.lframe,
392 ivuv, ipiti, rmsi, rci, &nout, &ratio, st);
393 if (nout > 0) {
394 i__1 = nout;
395 for (j = 1; j <= i__1; ++j) {
396
397/* Add synthesized speech for pitch period J to the en
398d of */
399/* BUF. */
400
401 irc2pc_(&rci[j * 10 - 10], pc, &contrl_1.order, &c_b2, &g2pass);
402 bsynz_(pc, &ipiti[j - 1], &ivuv[j - 1], &buf[*buflen], &rmsi[j - 1]
403 , &ratio, &g2pass, st);
404 deemp_(&buf[*buflen], &ipiti[j - 1], st);
405 *buflen += ipiti[j - 1];
406 }
407
408/* Copy first MAXFRM samples from BUF to output array SPEECH
409*/
410/* (scaling them), and then remove them from the beginning of
411 */
412/* BUF. */
413
414 for (i__ = 1; i__ <= 180; ++i__) {
415 speech[i__] = buf[i__ - 1] / 4096.f;
416 }
417 *k = 180;
418 *buflen += -180;
419 i__1 = *buflen;
420 for (i__ = 1; i__ <= i__1; ++i__) {
421 buf[i__ - 1] = buf[i__ + 179];
422 }
423 }
424 return 0;
425} /* synths_ */
int bsynz_(real *coef, integer *ip, integer *iv, real *sout, real *rms, real *ratio, real *g2pass, struct lpc10_decoder_state *st)
Definition: bsynz.c:122
int deemp_(real *x, integer *n, struct lpc10_decoder_state *st)
Definition: deemp.c:106
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pass)
Definition: irc2pc.c:82
int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st)
Definition: pitsyn.c:132
#define min(a, b)
Definition: f2c.h:197
#define max(a, b)
Definition: f2c.h:198
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80
INT32 logical
Definition: lpc10.h:81
real buf[360]
Definition: lpc10.h:163
integer buflen
Definition: lpc10.h:164
int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st)
Definition: synths.c:170
logical corrp
Definition: synths.c:56
static real c_b2
Definition: synths.c:63
struct @157 contrl_
integer lframe
Definition: synths.c:55
#define contrl_1
Definition: synths.c:59
integer order
Definition: synths.c:55