bsynz.c File Reference

#include "f2c.h"

Include dependency graph for bsynz.c:

Go to the source code of this file.

Defines

#define contrl_1   contrl_

Functions

int bsynz_ (real *coef, integer *ip, integer *iv, real *sout, real *rms, real *ratio, real *g2pass, struct lpc10_decoder_state *st)

Variables

struct {
   logical   corrp
   integer   lframe
   integer   order
contrl_


Define Documentation

#define contrl_1   contrl_

Definition at line 50 of file bsynz.c.


Function Documentation

int bsynz_ ( real coef,
integer ip,
integer iv,
real sout,
real rms,
real ratio,
real g2pass,
struct lpc10_decoder_state st 
)

Definition at line 122 of file bsynz.c.

References contrl_1, e, lpc10_decoder_state::exc, lpc10_decoder_state::exc2, f, lpc10_decoder_state::hpi1, lpc10_decoder_state::hpi2, lpc10_decoder_state::hpi3, lpc10_decoder_state::ipo, lpc10_decoder_state::lpi1, lpc10_decoder_state::lpi2, lpc10_decoder_state::lpi3, min, random_(), and lpc10_decoder_state::rmso_bsynz.

Referenced by synths_().

00125 {
00126     /* Initialized data */
00127 
00128     integer *ipo;
00129     real *rmso;
00130     static integer kexc[25] = { 8,-16,26,-48,86,-162,294,-502,718,-728,184,
00131        672,-610,-672,184,728,718,502,294,162,86,48,26,16,8 };
00132     real *exc;
00133     real *exc2;
00134     real *lpi1;
00135     real *lpi2;
00136     real *lpi3;
00137     real *hpi1;
00138     real *hpi2;
00139     real *hpi3;
00140 
00141     /* System generated locals */
00142     integer i__1, i__2;
00143     real r__1, r__2;
00144 
00145     /* Builtin functions */
00146     double sqrt(doublereal);
00147 
00148     /* Local variables */
00149     real gain, xssq;
00150     integer i__, j, k;
00151     real noise[166], pulse;
00152     integer px;
00153     real sscale;
00154     extern integer random_(struct lpc10_decoder_state *);
00155     real xy, sum, ssq;
00156     real lpi0, hpi0;
00157 
00158 /* $Log$
00159  * Revision 1.15  2004/06/26 03:50:14  markster
00160  * Merge source cleanups (bug #1911)
00161  *
00162  * Revision 1.14  2003/02/12 13:59:14  matteo
00163  * mer feb 12 14:56:57 CET 2003
00164  *
00165  * Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00166  * mer feb 12 14:56:57 CET 2003
00167  *
00168  * Revision 1.2  2000/01/05 08:20:39  markster
00169  * Some OSS fixes and a few lpc changes to make it actually work
00170  *
00171  * Revision 1.2  1996/08/20  20:18:55  jaf
00172  * Removed all static local variables that were SAVE'd in the Fortran
00173  * code, and put them in struct lpc10_decoder_state that is passed as an
00174  * argument.
00175  *
00176  * Removed init function, since all initialization is now done in
00177  * init_lpc10_decoder_state().
00178  *
00179  * Revision 1.1  1996/08/19  22:32:58  jaf
00180  * Initial revision
00181  * */
00182 /* Revision 1.3  1996/03/29  22:03:47  jaf */
00183 /* Removed definitions for any constants that were no longer used. */
00184 
00185 /* Revision 1.2  1996/03/26  19:34:33  jaf */
00186 /* Added comments indicating which constants are not needed in an */
00187 /* application that uses the LPC-10 coder. */
00188 
00189 /* Revision 1.1  1996/02/07  14:43:51  jaf */
00190 /* Initial revision */
00191 
00192 /*   LPC Configuration parameters: */
00193 /* Frame size, Prediction order, Pitch period */
00194 /*       Arguments */
00195 /* $Log$
00196  * Revision 1.15  2004/06/26 03:50:14  markster
00197  * Merge source cleanups (bug #1911)
00198  *
00199  * Revision 1.14  2003/02/12 13:59:14  matteo
00200  * mer feb 12 14:56:57 CET 2003
00201  *
00202  * Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00203  * mer feb 12 14:56:57 CET 2003
00204  *
00205  * Revision 1.2  2000/01/05 08:20:39  markster
00206  * Some OSS fixes and a few lpc changes to make it actually work
00207  *
00208  * Revision 1.2  1996/08/20  20:18:55  jaf
00209  * Removed all static local variables that were SAVE'd in the Fortran
00210  * code, and put them in struct lpc10_decoder_state that is passed as an
00211  * argument.
00212  *
00213  * Removed init function, since all initialization is now done in
00214  * init_lpc10_decoder_state().
00215  *
00216  * Revision 1.1  1996/08/19  22:32:58  jaf
00217  * Initial revision
00218  * */
00219 /* Revision 1.3  1996/03/29  22:05:55  jaf */
00220 /* Commented out the common block variables that are not needed by the */
00221 /* embedded version. */
00222 
00223 /* Revision 1.2  1996/03/26  19:34:50  jaf */
00224 /* Added comments indicating which constants are not needed in an */
00225 /* application that uses the LPC-10 coder. */
00226 
00227 /* Revision 1.1  1996/02/07  14:44:09  jaf */
00228 /* Initial revision */
00229 
00230 /*   LPC Processing control variables: */
00231 
00232 /* *** Read-only: initialized in setup */
00233 
00234 /*  Files for Speech, Parameter, and Bitstream Input & Output, */
00235 /*    and message and debug outputs. */
00236 
00237 /* Here are the only files which use these variables: */
00238 
00239 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
00240 
00241 /* Many files which use fdebug are not listed, since it is only used in */
00242 /* those other files conditionally, to print trace statements. */
00243 /*    integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
00244 /*  LPC order, Frame size, Quantization rate, Bits per frame, */
00245 /*    Error correction */
00246 /* Subroutine SETUP is the only place where order is assigned a value, */
00247 /* and that value is 10.  It could increase efficiency 1% or so to */
00248 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as 
00249 */
00250 /* a variable in a COMMON block, since it is used in many places in the */
00251 /* core of the coding and decoding routines.  Actually, I take that back. 
00252 */
00253 /* At least when compiling with f2c, the upper bound of DO loops is */
00254 /* stored in a local variable before the DO loop begins, and then that is 
00255 */
00256 /* compared against on each iteration. */
00257 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
00258 /* Similarly for quant, which is given a value of 2400 in SETUP.  quant */
00259 /* is used in only a few places, and never in the core coding and */
00260 /* decoding routines, so it could be eliminated entirely. */
00261 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
00262 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
00263 /* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */
00264 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is 
00265 */
00266 /* a constant or a variable, since it is only examined once per frame. */
00267 /* Leaving it as a variable that is set to .TRUE.  seems like a good */
00268 /* idea, since it does enable some error-correction capability for */
00269 /* unvoiced frames, with no change in the coding rate, and no noticeable 
00270 */
00271 /* quality difference in the decoded speech. */
00272 /*    integer quant, nbits */
00273 /* *** Read/write: variables for debugging, not needed for LPC algorithm 
00274 */
00275 
00276 /*  Current frame, Unstable frames, Output clip count, Max onset buffer, 
00277 */
00278 /*    Debug listing detail level, Line count on listing page */
00279 
00280 /* nframe is not needed for an embedded LPC10 at all. */
00281 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
00282 /* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */
00283 /* an application, I would recommend removing the call to ERROR in RCCHK, 
00284 */
00285 /* and remove ERROR and nunsfm completely. */
00286 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in 
00287 */
00288 /* sread.f.  When LPC10 is embedded into an application, one might want */
00289 /* to cause it to be incremented in a routine that takes the output of */
00290 /* SYNTHS and sends it to an audio device.  It could be optionally */
00291 /* displayed, for those that might want to know what it is. */
00292 /* maxosp is never initialized to 0 in SETUP, although it probably should 
00293 */
00294 /* be, and it is updated in subroutine ANALYS.  I doubt that its value */
00295 /* would be of much interest to an application in which LPC10 is */
00296 /* embedded. */
00297 /* listl and lincnt are not needed for an embedded LPC10 at all. */
00298 /*    integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
00299 /*    common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
00300 /*    common /contrl/ quant, nbits */
00301 /*    common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
00302 /*       Function return value definitions */
00303 /*    Parameters/constants */
00304 /*       KEXC is not a Fortran PARAMETER, but it is an array initialized 
00305 */
00306 /*       with a DATA statement that is never modified. */
00307 /*       Local variables that need not be saved */
00308 /*       NOISE is declared with range (1:MAXPIT+MAXORD), but only indices 
00309 */
00310 /*       ORDER+1 through ORDER+IP are ever used, and I think that IP */
00311 /*       .LE. MAXPIT.  Why not declare it to be in the range (1:MAXPIT) */
00312 /*       and use that range? */
00313 /*       Local state */
00314 /*       I believe that only indices 1 through ORDER of EXC need to be */
00315 /*       saved from one invocation to the next, but we may as well save */
00316 /*       the whole array. */
00317 /*       None of these local variables were given initial values in the */
00318 /*       original code.  I'm guessing that 0 is a reasonable initial */
00319 /*       value for all of them. */
00320     /* Parameter adjustments */
00321     if (coef) {
00322    --coef;
00323    }
00324     if (sout) {
00325    --sout;
00326    }
00327 
00328     /* Function Body */
00329     ipo = &(st->ipo);
00330     exc = &(st->exc[0]);
00331     exc2 = &(st->exc2[0]);
00332     lpi1 = &(st->lpi1);
00333     lpi2 = &(st->lpi2);
00334     lpi3 = &(st->lpi3);
00335     hpi1 = &(st->hpi1);
00336     hpi2 = &(st->hpi2);
00337     hpi3 = &(st->hpi3);
00338     rmso = &(st->rmso_bsynz);
00339 
00340 /*                  MAXPIT+MAXORD=166 */
00341 /*  Calculate history scale factor XY and scale filter state */
00342 /* Computing MIN */
00343     r__1 = *rmso / (*rms + 1e-6f);
00344     xy = min(r__1,8.f);
00345     *rmso = *rms;
00346     i__1 = contrl_1.order;
00347     for (i__ = 1; i__ <= i__1; ++i__) {
00348    exc2[i__ - 1] = exc2[*ipo + i__ - 1] * xy;
00349     }
00350     *ipo = *ip;
00351     if (*iv == 0) {
00352 /*  Generate white noise for unvoiced */
00353    i__1 = *ip;
00354    for (i__ = 1; i__ <= i__1; ++i__) {
00355        exc[contrl_1.order + i__ - 1] = (real) (random_(st) / 64);
00356    }
00357 /*  Impulse doublet excitation for plosives */
00358 /*       (RANDOM()+32768) is in the range 0 to 2**16-1.  Therefore the
00359  */
00360 /*       following expression should be evaluated using integers with 
00361 at */
00362 /*       least 32 bits (16 isn't enough), and PX should be in the rang
00363 e */
00364 /*       ORDER+1+0 through ORDER+1+(IP-2) .EQ. ORDER+IP-1. */
00365    px = (random_(st) + 32768) * (*ip - 1) / 65536 + contrl_1.order + 1;
00366    r__1 = *ratio / 4 * 1.f;
00367    pulse = r__1 * 342;
00368    if (pulse > 2e3f) {
00369        pulse = 2e3f;
00370    }
00371    exc[px - 1] += pulse;
00372    exc[px] -= pulse;
00373 /*  Load voiced excitation */
00374     } else {
00375    sscale = (real)sqrt((real) (*ip)) / 6.928f;
00376    i__1 = *ip;
00377    for (i__ = 1; i__ <= i__1; ++i__) {
00378        exc[contrl_1.order + i__ - 1] = 0.f;
00379        if (i__ <= 25) {
00380       exc[contrl_1.order + i__ - 1] = sscale * kexc[i__ - 1];
00381        }
00382        lpi0 = exc[contrl_1.order + i__ - 1];
00383        r__2 = exc[contrl_1.order + i__ - 1] * .125f + *lpi1 * .75f;
00384        r__1 = r__2 + *lpi2 * .125f;
00385        exc[contrl_1.order + i__ - 1] = r__1 + *lpi3 * 0.f;
00386        *lpi3 = *lpi2;
00387        *lpi2 = *lpi1;
00388        *lpi1 = lpi0;
00389    }
00390    i__1 = *ip;
00391    for (i__ = 1; i__ <= i__1; ++i__) {
00392        noise[contrl_1.order + i__ - 1] = random_(st) * 1.f / 64;
00393        hpi0 = noise[contrl_1.order + i__ - 1];
00394        r__2 = noise[contrl_1.order + i__ - 1] * -.125f + *hpi1 * .25f;
00395        r__1 = r__2 + *hpi2 * -.125f;
00396        noise[contrl_1.order + i__ - 1] = r__1 + *hpi3 * 0.f;
00397        *hpi3 = *hpi2;
00398        *hpi2 = *hpi1;
00399        *hpi1 = hpi0;
00400    }
00401    i__1 = *ip;
00402    for (i__ = 1; i__ <= i__1; ++i__) {
00403        exc[contrl_1.order + i__ - 1] += noise[contrl_1.order + i__ - 1];
00404    }
00405     }
00406 /*   Synthesis filters: */
00407 /*    Modify the excitation with all-zero filter  1 + G*SUM */
00408     xssq = 0.f;
00409     i__1 = *ip;
00410     for (i__ = 1; i__ <= i__1; ++i__) {
00411    k = contrl_1.order + i__;
00412    sum = 0.f;
00413    i__2 = contrl_1.order;
00414    for (j = 1; j <= i__2; ++j) {
00415        sum += coef[j] * exc[k - j - 1];
00416    }
00417    sum *= *g2pass;
00418    exc2[k - 1] = sum + exc[k - 1];
00419     }
00420 /*   Synthesize using the all pole filter  1 / (1 - SUM) */
00421     i__1 = *ip;
00422     for (i__ = 1; i__ <= i__1; ++i__) {
00423    k = contrl_1.order + i__;
00424    sum = 0.f;
00425    i__2 = contrl_1.order;
00426    for (j = 1; j <= i__2; ++j) {
00427        sum += coef[j] * exc2[k - j - 1];
00428    }
00429    exc2[k - 1] = sum + exc2[k - 1];
00430    xssq += exc2[k - 1] * exc2[k - 1];
00431     }
00432 /*  Save filter history for next epoch */
00433     i__1 = contrl_1.order;
00434     for (i__ = 1; i__ <= i__1; ++i__) {
00435    exc[i__ - 1] = exc[*ip + i__ - 1];
00436    exc2[i__ - 1] = exc2[*ip + i__ - 1];
00437     }
00438 /*  Apply gain to match RMS */
00439     r__1 = *rms * *rms;
00440     ssq = r__1 * *ip;
00441     gain = (real)sqrt(ssq / xssq);
00442     i__1 = *ip;
00443     for (i__ = 1; i__ <= i__1; ++i__) {
00444    sout[i__] = gain * exc2[contrl_1.order + i__ - 1];
00445     }
00446     return 0;
00447 } /* bsynz_ */


Variable Documentation

struct { ... } contrl_

Definition at line 47 of file bsynz.c.

Definition at line 46 of file bsynz.c.

Definition at line 46 of file bsynz.c.


Generated on Thu Apr 16 06:29:14 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6