4 Revision 1.10 2000/01/05 08:20:39 markster
5 Version 0.1.11 from FTP
7 Revision 1.2 2000/01/05 08:20:39 markster
8 Some OSS fixes and a few lpc changes to make it actually work
10 * Revision 1.2 1996/08/20 20:42:59 jaf
11 * Removed all static local variables that were SAVE'd in the Fortran
12 * code, and put them in struct lpc10_decoder_state that is passed as an
15 * Removed init function, since all initialization is now done in
16 * init_lpc10_decoder_state().
18 * Revision 1.1 1996/08/19 22:30:33 jaf
24 #ifdef P_R_O_T_O_T_Y_P_E_S
25 extern int synths_(integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st);
26 /* comlen contrl_ 12 */
27 /*:ref: pitsyn_ 14 12 4 4 4 6 6 4 4 4 6 6 4 6 */
28 /*:ref: irc2pc_ 14 5 6 6 4 6 6 */
29 /*:ref: bsynz_ 14 7 6 4 4 6 6 6 6 */
30 /*:ref: deemp_ 14 2 6 4 */
31 /*:ref: initpitsyn_ 14 0 */
32 /*:ref: initbsynz_ 14 0 */
33 /*:ref: initdeemp_ 14 0 */
36 /* -- translated by f2c (version 19951025).
37 You must link the resulting object file with the libraries:
38 -lf2c -lm (in that order)
43 /* Common Block Declarations */
46 integer order, lframe;
50 #define contrl_1 contrl_
52 /* Table of constant values */
54 static real c_b2 = .7f;
56 /* ***************************************************************** */
58 /* SYNTHS Version 54 */
61 * Revision 1.10 2000/01/05 08:20:39 markster
62 * Version 0.1.11 from FTP
64 /* Revision 1.2 2000/01/05 08:20:39 markster
65 /* Some OSS fixes and a few lpc changes to make it actually work
67 * Revision 1.2 1996/08/20 20:42:59 jaf
68 * Removed all static local variables that were SAVE'd in the Fortran
69 * code, and put them in struct lpc10_decoder_state that is passed as an
72 * Removed init function, since all initialization is now done in
73 * init_lpc10_decoder_state().
75 * Revision 1.1 1996/08/19 22:30:33 jaf
78 /* Revision 1.5 1996/03/26 19:31:58 jaf */
79 /* Commented out trace statements. */
81 /* Revision 1.4 1996/03/25 19:41:01 jaf */
82 /* Changed so that MAXFRM samples are always returned in the output array */
85 /* This required delaying the returned samples by MAXFRM sample times, */
86 /* and remembering any "left over" samples returned by PITSYN from one */
87 /* call of SYNTHS to the next. */
89 /* Changed size of SPEECH from 2*MAXFRM to MAXFRM. Removed local */
90 /* variable SOUT. Added local state variables BUF and BUFLEN. */
92 /* Revision 1.3 1996/03/25 19:20:10 jaf */
93 /* Added comments about the range of possible return values for argument */
94 /* K, and increased the size of the arrays filled in by PITSYN from 11 to */
95 /* 16, as has been already done inside of PITSYN. */
97 /* Revision 1.2 1996/03/22 00:18:18 jaf */
98 /* Added comments explaining meanings of input and output parameters, and */
99 /* indicating which array indices can be read or written. */
101 /* Added entry INITSYNTHS, which does nothing except call the */
102 /* corresponding initialization entries for subroutines PITSYN, BSYNZ, */
105 /* Revision 1.1 1996/02/07 14:49:44 jaf */
106 /* Initial revision */
109 /* ***************************************************************** */
111 /* The note below is from the distributed version of the LPC10 coder. */
112 /* The version of the code below has been modified so that SYNTHS always */
113 /* has a constant frame length output of MAXFRM. */
115 /* Also, BSYNZ and DEEMP need not be modified to work on variable */
116 /* positions within an array. It is only necessary to pass the first */
117 /* index desired as the array argument. What actually gets passed is the */
118 /* address of that array position, which the subroutine treats as the */
119 /* first index of the array. */
121 /* This technique is used in subroutine ANALYS when calling PREEMP, so it */
122 /* appears that multiple people wrote different parts of this LPC10 code, */
123 /* and that they didn't necessarily have equivalent knowledge of Fortran */
124 /* (not surprising). */
126 /* NOTE: There is excessive buffering here, BSYNZ and DEEMP should be */
127 /* changed to operate on variable positions within SOUT. Also, */
128 /* the output length parameter is bogus, and PITSYN should be */
129 /* rewritten to allow a constant frame length output. */
132 /* VOICE - Half frame voicing decisions */
133 /* Indices 1 through 2 read. */
136 /* PITCH is restricted to range 20 to 156, inclusive, */
137 /* before calling subroutine PITSYN, and then PITSYN */
138 /* can modify it further under some conditions. */
140 /* Only use is for debugging, and passed to PITSYN. */
141 /* See comments there for how it can be modified. */
142 /* RC - Reflection coefficients */
143 /* Indices 1 through ORDER restricted to range -.99 to .99, */
144 /* before calling subroutine PITSYN, and then PITSYN */
145 /* can modify it further under some conditions. */
147 /* SPEECH - Synthesized speech samples. */
148 /* Indices 1 through the final value of K are written. */
149 /* K - Number of samples placed into array SPEECH. */
150 /* This is always MAXFRM. */
152 /* Subroutine */ int synths_(integer *voice, integer *pitch, real *
153 rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st)
155 /* Initialized data */
160 /* System generated locals */
164 /* Local variables */
166 integer nout, ivuv[16], i__, j;
167 extern /* Subroutine */ int deemp_(real *, integer *, struct lpc10_decoder_state *);
170 extern /* Subroutine */ bsynz_(real *, integer *,
171 integer *, real *, real *, real *, real *, struct lpc10_decoder_state *), irc2pc_(real *, real *
172 , integer *, real *, real *);
175 extern /* Subroutine */ int pitsyn_(integer *, integer *, integer *, real
176 *, real *, integer *, integer *, integer *, real *, real *,
177 integer *, real *, struct lpc10_decoder_state *);
178 real rci[160] /* was [10][16] */;
181 * Revision 1.10 2000/01/05 08:20:39 markster
182 * Version 0.1.11 from FTP
184 /* Revision 1.2 2000/01/05 08:20:39 markster
185 /* Some OSS fixes and a few lpc changes to make it actually work
187 * Revision 1.2 1996/08/20 20:42:59 jaf
188 * Removed all static local variables that were SAVE'd in the Fortran
189 * code, and put them in struct lpc10_decoder_state that is passed as an
192 * Removed init function, since all initialization is now done in
193 * init_lpc10_decoder_state().
195 * Revision 1.1 1996/08/19 22:30:33 jaf
198 /* Revision 1.3 1996/03/29 22:03:47 jaf */
199 /* Removed definitions for any constants that were no longer used. */
201 /* Revision 1.2 1996/03/26 19:34:33 jaf */
202 /* Added comments indicating which constants are not needed in an */
203 /* application that uses the LPC-10 coder. */
205 /* Revision 1.1 1996/02/07 14:43:51 jaf */
206 /* Initial revision */
208 /* LPC Configuration parameters: */
209 /* Frame size, Prediction order, Pitch period */
212 * Revision 1.10 2000/01/05 08:20:39 markster
213 * Version 0.1.11 from FTP
215 /* Revision 1.2 2000/01/05 08:20:39 markster
216 /* Some OSS fixes and a few lpc changes to make it actually work
218 * Revision 1.2 1996/08/20 20:42:59 jaf
219 * Removed all static local variables that were SAVE'd in the Fortran
220 * code, and put them in struct lpc10_decoder_state that is passed as an
223 * Removed init function, since all initialization is now done in
224 * init_lpc10_decoder_state().
226 * Revision 1.1 1996/08/19 22:30:33 jaf
229 /* Revision 1.3 1996/03/29 22:05:55 jaf */
230 /* Commented out the common block variables that are not needed by the */
231 /* embedded version. */
233 /* Revision 1.2 1996/03/26 19:34:50 jaf */
234 /* Added comments indicating which constants are not needed in an */
235 /* application that uses the LPC-10 coder. */
237 /* Revision 1.1 1996/02/07 14:44:09 jaf */
238 /* Initial revision */
240 /* LPC Processing control variables: */
242 /* *** Read-only: initialized in setup */
244 /* Files for Speech, Parameter, and Bitstream Input & Output, */
245 /* and message and debug outputs. */
247 /* Here are the only files which use these variables: */
249 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
251 /* Many files which use fdebug are not listed, since it is only used in */
252 /* those other files conditionally, to print trace statements. */
253 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
254 /* LPC order, Frame size, Quantization rate, Bits per frame, */
255 /* Error correction */
256 /* Subroutine SETUP is the only place where order is assigned a value, */
257 /* and that value is 10. It could increase efficiency 1% or so to */
258 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
260 /* a variable in a COMMON block, since it is used in many places in the */
261 /* core of the coding and decoding routines. Actually, I take that back.
263 /* At least when compiling with f2c, the upper bound of DO loops is */
264 /* stored in a local variable before the DO loop begins, and then that is
266 /* compared against on each iteration. */
267 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
268 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
269 /* is used in only a few places, and never in the core coding and */
270 /* decoding routines, so it could be eliminated entirely. */
271 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
272 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
273 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
274 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
276 /* a constant or a variable, since it is only examined once per frame. */
277 /* Leaving it as a variable that is set to .TRUE. seems like a good */
278 /* idea, since it does enable some error-correction capability for */
279 /* unvoiced frames, with no change in the coding rate, and no noticeable
281 /* quality difference in the decoded speech. */
282 /* integer quant, nbits */
283 /* *** Read/write: variables for debugging, not needed for LPC algorithm
286 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
288 /* Debug listing detail level, Line count on listing page */
290 /* nframe is not needed for an embedded LPC10 at all. */
291 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
292 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
293 /* an application, I would recommend removing the call to ERROR in RCCHK,
295 /* and remove ERROR and nunsfm completely. */
296 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
298 /* sread.f. When LPC10 is embedded into an application, one might want */
299 /* to cause it to be incremented in a routine that takes the output of */
300 /* SYNTHS and sends it to an audio device. It could be optionally */
301 /* displayed, for those that might want to know what it is. */
302 /* maxosp is never initialized to 0 in SETUP, although it probably should
304 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
305 /* would be of much interest to an application in which LPC10 is */
307 /* listl and lincnt are not needed for an embedded LPC10 at all. */
308 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
309 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
310 /* common /contrl/ quant, nbits */
311 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
312 /* Parameters/constants */
313 /* Local variables that need not be saved */
315 /* BUF is a buffer of speech samples that would have been returned
317 /* by the older version of SYNTHS, but the newer version doesn't, */
318 /* so that the newer version can always return MAXFRM samples on */
319 /* every call. This has the effect of delaying the return of */
320 /* samples for one additional frame time. */
322 /* Indices 1 through BUFLEN contain samples that are left over from
324 /* the last call to SYNTHS. Given the way that PITSYN works, */
325 /* BUFLEN should always be in the range MAXFRM-MAXPIT+1 through */
326 /* MAXFRM, inclusive, after a call to SYNTHS is complete. */
328 /* On the first call to SYNTHS (or the first call after */
329 /* reinitializing with the entry INITSYNTHS), BUFLEN is MAXFRM, and
331 /* a frame of silence is always returned. */
332 /* Parameter adjustments */
345 buflen = &(st->buflen);
348 i__1 = min(*pitch,156);
349 *pitch = max(i__1,20);
350 i__1 = contrl_1.order;
351 for (i__ = 1; i__ <= i__1; ++i__) {
355 r__1 = min(r__2,.99f);
356 rc[i__] = max(r__1,-.99f);
358 pitsyn_(&contrl_1.order, &voice[1], pitch, rms, &rc[1], &contrl_1.lframe,
359 ivuv, ipiti, rmsi, rci, &nout, &ratio, st);
362 for (j = 1; j <= i__1; ++j) {
364 /* Add synthesized speech for pitch period J to the en
368 irc2pc_(&rci[j * 10 - 10], pc, &contrl_1.order, &c_b2, &g2pass);
369 bsynz_(pc, &ipiti[j - 1], &ivuv[j - 1], &buf[*buflen], &rmsi[j - 1]
370 , &ratio, &g2pass, st);
371 deemp_(&buf[*buflen], &ipiti[j - 1], st);
372 *buflen += ipiti[j - 1];
375 /* Copy first MAXFRM samples from BUF to output array SPEECH
377 /* (scaling them), and then remove them from the beginning of
381 for (i__ = 1; i__ <= 180; ++i__) {
382 speech[i__] = buf[i__ - 1] / 4096.f;
387 for (i__ = 1; i__ <= i__1; ++i__) {
388 buf[i__ - 1] = buf[i__ + 179];