4 Revision 1.14 2003/02/12 13:59:15 matteo
5 mer feb 12 14:56:57 CET 2003
7 Revision 1.1.1.1 2003/02/12 13:59:15 matteo
8 mer feb 12 14:56:57 CET 2003
10 Revision 1.2 2000/01/05 08:20:39 markster
11 Some OSS fixes and a few lpc changes to make it actually work
13 * Revision 1.2 1996/08/20 20:42:59 jaf
14 * Removed all static local variables that were SAVE'd in the Fortran
15 * code, and put them in struct lpc10_decoder_state that is passed as an
18 * Removed init function, since all initialization is now done in
19 * init_lpc10_decoder_state().
21 * Revision 1.1 1996/08/19 22:30:33 jaf
27 #ifdef P_R_O_T_O_T_Y_P_E_S
28 extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st);
29 /* comlen contrl_ 12 */
30 /*:ref: pitsyn_ 14 12 4 4 4 6 6 4 4 4 6 6 4 6 */
31 /*:ref: irc2pc_ 14 5 6 6 4 6 6 */
32 /*:ref: bsynz_ 14 7 6 4 4 6 6 6 6 */
33 /*:ref: deemp_ 14 2 6 4 */
34 /*:ref: initpitsyn_ 14 0 */
35 /*:ref: initbsynz_ 14 0 */
36 /*:ref: initdeemp_ 14 0 */
39 /* -- translated by f2c (version 19951025).
40 You must link the resulting object file with the libraries:
41 -lf2c -lm (in that order)
46 /* Common Block Declarations */
49 integer order, lframe;
53 #define contrl_1 contrl_
55 /* Table of constant values */
57 static real c_b2 = .7f;
59 /* ***************************************************************** */
61 /* SYNTHS Version 54 */
64 * Revision 1.14 2003/02/12 13:59:15 matteo
65 * mer feb 12 14:56:57 CET 2003
67 /* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
68 /* mer feb 12 14:56:57 CET 2003
70 /* Revision 1.2 2000/01/05 08:20:39 markster
71 /* Some OSS fixes and a few lpc changes to make it actually work
73 * Revision 1.2 1996/08/20 20:42:59 jaf
74 * Removed all static local variables that were SAVE'd in the Fortran
75 * code, and put them in struct lpc10_decoder_state that is passed as an
78 * Removed init function, since all initialization is now done in
79 * init_lpc10_decoder_state().
81 * Revision 1.1 1996/08/19 22:30:33 jaf
84 /* Revision 1.5 1996/03/26 19:31:58 jaf */
85 /* Commented out trace statements. */
87 /* Revision 1.4 1996/03/25 19:41:01 jaf */
88 /* Changed so that MAXFRM samples are always returned in the output array */
91 /* This required delaying the returned samples by MAXFRM sample times, */
92 /* and remembering any "left over" samples returned by PITSYN from one */
93 /* call of SYNTHS to the next. */
95 /* Changed size of SPEECH from 2*MAXFRM to MAXFRM. Removed local */
96 /* variable SOUT. Added local state variables BUF and BUFLEN. */
98 /* Revision 1.3 1996/03/25 19:20:10 jaf */
99 /* Added comments about the range of possible return values for argument */
100 /* K, and increased the size of the arrays filled in by PITSYN from 11 to */
101 /* 16, as has been already done inside of PITSYN. */
103 /* Revision 1.2 1996/03/22 00:18:18 jaf */
104 /* Added comments explaining meanings of input and output parameters, and */
105 /* indicating which array indices can be read or written. */
107 /* Added entry INITSYNTHS, which does nothing except call the */
108 /* corresponding initialization entries for subroutines PITSYN, BSYNZ, */
111 /* Revision 1.1 1996/02/07 14:49:44 jaf */
112 /* Initial revision */
115 /* ***************************************************************** */
117 /* The note below is from the distributed version of the LPC10 coder. */
118 /* The version of the code below has been modified so that SYNTHS always */
119 /* has a constant frame length output of MAXFRM. */
121 /* Also, BSYNZ and DEEMP need not be modified to work on variable */
122 /* positions within an array. It is only necessary to pass the first */
123 /* index desired as the array argument. What actually gets passed is the */
124 /* address of that array position, which the subroutine treats as the */
125 /* first index of the array. */
127 /* This technique is used in subroutine ANALYS when calling PREEMP, so it */
128 /* appears that multiple people wrote different parts of this LPC10 code, */
129 /* and that they didn't necessarily have equivalent knowledge of Fortran */
130 /* (not surprising). */
132 /* NOTE: There is excessive buffering here, BSYNZ and DEEMP should be */
133 /* changed to operate on variable positions within SOUT. Also, */
134 /* the output length parameter is bogus, and PITSYN should be */
135 /* rewritten to allow a constant frame length output. */
138 /* VOICE - Half frame voicing decisions */
139 /* Indices 1 through 2 read. */
142 /* PITCH is restricted to range 20 to 156, inclusive, */
143 /* before calling subroutine PITSYN, and then PITSYN */
144 /* can modify it further under some conditions. */
146 /* Only use is for debugging, and passed to PITSYN. */
147 /* See comments there for how it can be modified. */
148 /* RC - Reflection coefficients */
149 /* Indices 1 through ORDER restricted to range -.99 to .99, */
150 /* before calling subroutine PITSYN, and then PITSYN */
151 /* can modify it further under some conditions. */
153 /* SPEECH - Synthesized speech samples. */
154 /* Indices 1 through the final value of K are written. */
155 /* K - Number of samples placed into array SPEECH. */
156 /* This is always MAXFRM. */
158 /* Subroutine */ int synths_(integer *voice, integer *pitch, real *
159 rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st)
161 /* Initialized data */
166 /* System generated locals */
170 /* Local variables */
172 integer nout, ivuv[16], i__, j;
173 extern /* Subroutine */ int deemp_(real *, integer *, struct lpc10_decoder_state *);
176 extern /* Subroutine */ bsynz_(real *, integer *,
177 integer *, real *, real *, real *, real *, struct lpc10_decoder_state *), irc2pc_(real *, real *
178 , integer *, real *, real *);
181 extern /* Subroutine */ int pitsyn_(integer *, integer *, integer *, real
182 *, real *, integer *, integer *, integer *, real *, real *,
183 integer *, real *, struct lpc10_decoder_state *);
184 real rci[160] /* was [10][16] */;
187 * Revision 1.14 2003/02/12 13:59:15 matteo
188 * mer feb 12 14:56:57 CET 2003
190 /* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
191 /* mer feb 12 14:56:57 CET 2003
193 /* Revision 1.2 2000/01/05 08:20:39 markster
194 /* Some OSS fixes and a few lpc changes to make it actually work
196 * Revision 1.2 1996/08/20 20:42:59 jaf
197 * Removed all static local variables that were SAVE'd in the Fortran
198 * code, and put them in struct lpc10_decoder_state that is passed as an
201 * Removed init function, since all initialization is now done in
202 * init_lpc10_decoder_state().
204 * Revision 1.1 1996/08/19 22:30:33 jaf
207 /* Revision 1.3 1996/03/29 22:03:47 jaf */
208 /* Removed definitions for any constants that were no longer used. */
210 /* Revision 1.2 1996/03/26 19:34:33 jaf */
211 /* Added comments indicating which constants are not needed in an */
212 /* application that uses the LPC-10 coder. */
214 /* Revision 1.1 1996/02/07 14:43:51 jaf */
215 /* Initial revision */
217 /* LPC Configuration parameters: */
218 /* Frame size, Prediction order, Pitch period */
221 * Revision 1.14 2003/02/12 13:59:15 matteo
222 * mer feb 12 14:56:57 CET 2003
224 /* Revision 1.1.1.1 2003/02/12 13:59:15 matteo
225 /* mer feb 12 14:56:57 CET 2003
227 /* Revision 1.2 2000/01/05 08:20:39 markster
228 /* Some OSS fixes and a few lpc changes to make it actually work
230 * Revision 1.2 1996/08/20 20:42:59 jaf
231 * Removed all static local variables that were SAVE'd in the Fortran
232 * code, and put them in struct lpc10_decoder_state that is passed as an
235 * Removed init function, since all initialization is now done in
236 * init_lpc10_decoder_state().
238 * Revision 1.1 1996/08/19 22:30:33 jaf
241 /* Revision 1.3 1996/03/29 22:05:55 jaf */
242 /* Commented out the common block variables that are not needed by the */
243 /* embedded version. */
245 /* Revision 1.2 1996/03/26 19:34:50 jaf */
246 /* Added comments indicating which constants are not needed in an */
247 /* application that uses the LPC-10 coder. */
249 /* Revision 1.1 1996/02/07 14:44:09 jaf */
250 /* Initial revision */
252 /* LPC Processing control variables: */
254 /* *** Read-only: initialized in setup */
256 /* Files for Speech, Parameter, and Bitstream Input & Output, */
257 /* and message and debug outputs. */
259 /* Here are the only files which use these variables: */
261 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
263 /* Many files which use fdebug are not listed, since it is only used in */
264 /* those other files conditionally, to print trace statements. */
265 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
266 /* LPC order, Frame size, Quantization rate, Bits per frame, */
267 /* Error correction */
268 /* Subroutine SETUP is the only place where order is assigned a value, */
269 /* and that value is 10. It could increase efficiency 1% or so to */
270 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
272 /* a variable in a COMMON block, since it is used in many places in the */
273 /* core of the coding and decoding routines. Actually, I take that back.
275 /* At least when compiling with f2c, the upper bound of DO loops is */
276 /* stored in a local variable before the DO loop begins, and then that is
278 /* compared against on each iteration. */
279 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
280 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
281 /* is used in only a few places, and never in the core coding and */
282 /* decoding routines, so it could be eliminated entirely. */
283 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
284 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
285 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
286 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
288 /* a constant or a variable, since it is only examined once per frame. */
289 /* Leaving it as a variable that is set to .TRUE. seems like a good */
290 /* idea, since it does enable some error-correction capability for */
291 /* unvoiced frames, with no change in the coding rate, and no noticeable
293 /* quality difference in the decoded speech. */
294 /* integer quant, nbits */
295 /* *** Read/write: variables for debugging, not needed for LPC algorithm
298 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
300 /* Debug listing detail level, Line count on listing page */
302 /* nframe is not needed for an embedded LPC10 at all. */
303 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
304 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
305 /* an application, I would recommend removing the call to ERROR in RCCHK,
307 /* and remove ERROR and nunsfm completely. */
308 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
310 /* sread.f. When LPC10 is embedded into an application, one might want */
311 /* to cause it to be incremented in a routine that takes the output of */
312 /* SYNTHS and sends it to an audio device. It could be optionally */
313 /* displayed, for those that might want to know what it is. */
314 /* maxosp is never initialized to 0 in SETUP, although it probably should
316 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
317 /* would be of much interest to an application in which LPC10 is */
319 /* listl and lincnt are not needed for an embedded LPC10 at all. */
320 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
321 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
322 /* common /contrl/ quant, nbits */
323 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
324 /* Parameters/constants */
325 /* Local variables that need not be saved */
327 /* BUF is a buffer of speech samples that would have been returned
329 /* by the older version of SYNTHS, but the newer version doesn't, */
330 /* so that the newer version can always return MAXFRM samples on */
331 /* every call. This has the effect of delaying the return of */
332 /* samples for one additional frame time. */
334 /* Indices 1 through BUFLEN contain samples that are left over from
336 /* the last call to SYNTHS. Given the way that PITSYN works, */
337 /* BUFLEN should always be in the range MAXFRM-MAXPIT+1 through */
338 /* MAXFRM, inclusive, after a call to SYNTHS is complete. */
340 /* On the first call to SYNTHS (or the first call after */
341 /* reinitializing with the entry INITSYNTHS), BUFLEN is MAXFRM, and
343 /* a frame of silence is always returned. */
344 /* Parameter adjustments */
357 buflen = &(st->buflen);
360 i__1 = min(*pitch,156);
361 *pitch = max(i__1,20);
362 i__1 = contrl_1.order;
363 for (i__ = 1; i__ <= i__1; ++i__) {
367 r__1 = min(r__2,.99f);
368 rc[i__] = max(r__1,-.99f);
370 pitsyn_(&contrl_1.order, &voice[1], pitch, rms, &rc[1], &contrl_1.lframe,
371 ivuv, ipiti, rmsi, rci, &nout, &ratio, st);
374 for (j = 1; j <= i__1; ++j) {
376 /* Add synthesized speech for pitch period J to the en
380 irc2pc_(&rci[j * 10 - 10], pc, &contrl_1.order, &c_b2, &g2pass);
381 bsynz_(pc, &ipiti[j - 1], &ivuv[j - 1], &buf[*buflen], &rmsi[j - 1]
382 , &ratio, &g2pass, st);
383 deemp_(&buf[*buflen], &ipiti[j - 1], st);
384 *buflen += ipiti[j - 1];
387 /* Copy first MAXFRM samples from BUF to output array SPEECH
389 /* (scaling them), and then remove them from the beginning of
393 for (i__ = 1; i__ <= 180; ++i__) {
394 speech[i__] = buf[i__ - 1] / 4096.f;
399 for (i__ = 1; i__ <= i__1; ++i__) {
400 buf[i__ - 1] = buf[i__ + 179];