chanwr.c

Go to the documentation of this file.
00001 /*
00002 
00003 $Log$
00004 Revision 1.15  2004/06/26 03:50:14  markster
00005 Merge source cleanups (bug #1911)
00006 
00007 Revision 1.14  2003/02/12 13:59:14  matteo
00008 mer feb 12 14:56:57 CET 2003
00009 
00010 Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00011 mer feb 12 14:56:57 CET 2003
00012 
00013 Revision 1.2  2000/01/05 08:20:39  markster
00014 Some OSS fixes and a few lpc changes to make it actually work
00015 
00016  * Revision 1.2  1996/08/20  20:20:24  jaf
00017  * Removed all static local variables that were SAVE'd in the Fortran
00018  * code, and put them in struct lpc10_encoder_state that is passed as an
00019  * argument.
00020  *
00021  * Revision 1.1  1996/08/19  22:40:31  jaf
00022  * Initial revision
00023  *
00024 
00025 */
00026 
00027 /*  -- translated by f2c (version 19951025).
00028    You must link the resulting object file with the libraries:
00029    -lf2c -lm   (in that order)
00030 */
00031 
00032 #include <stdlib.h>
00033 #include "f2c.h"
00034 
00035 /* *********************************************************************** */
00036 
00037 /*    CHANL Version 49 */
00038 
00039 /* $Log$
00040  * Revision 1.15  2004/06/26 03:50:14  markster
00041  * Merge source cleanups (bug #1911)
00042  *
00043  * Revision 1.14  2003/02/12 13:59:14  matteo
00044  * mer feb 12 14:56:57 CET 2003
00045  *
00046  * Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00047  * mer feb 12 14:56:57 CET 2003
00048  *
00049  * Revision 1.2  2000/01/05 08:20:39  markster
00050  * Some OSS fixes and a few lpc changes to make it actually work
00051  *
00052  * Revision 1.2  1996/08/20  20:20:24  jaf
00053  * Removed all static local variables that were SAVE'd in the Fortran
00054  * code, and put them in struct lpc10_encoder_state that is passed as an
00055  * argument.
00056  *
00057  * Revision 1.1  1996/08/19  22:40:31  jaf
00058  * Initial revision
00059  * */
00060 /* Revision 1.3  1996/03/21  15:14:57  jaf */
00061 /* Added comments about which indices of argument arrays are read or */
00062 /* written, and about the one bit of local state in CHANWR.  CHANRD */
00063 /* has no local state. */
00064 
00065 /* Revision 1.2  1996/03/13  18:55:10  jaf */
00066 /* Comments added explaining which of the local variables of this */
00067 /* subroutine need to be saved from one invocation to the next, and which */
00068 /* do not. */
00069 
00070 /* Revision 1.1  1996/02/07 14:43:31  jaf */
00071 /* Initial revision */
00072 
00073 
00074 /* *********************************************************************** */
00075 
00076 /* CHANWR: */
00077 /*   Place quantized parameters into bitstream */
00078 
00079 /* Input: */
00080 /*  ORDER  - Number of reflection coefficients (not really variable) */
00081 /*  IPITV  - Quantized pitch/voicing parameter */
00082 /*  IRMS   - Quantized energy parameter */
00083 /*  IRC    - Quantized reflection coefficients */
00084 /*           Indices 1 through ORDER read. */
00085 /* Output: */
00086 /*  IBITS  - Serial bitstream */
00087 /*           Indices 1 through 54 written. */
00088 /*           Bit 54, the SYNC bit, alternates from one call to the next. */
00089 
00090 /* Subroutine CHANWR maintains one bit of local state from one call to */
00091 /* the next, in the variable ISYNC.  I believe that this one bit is only */
00092 /* intended to allow a receiver to resynchronize its interpretation of */
00093 /* the bit stream, by looking for which of the 54 bits alternates every */
00094 /* frame time.  This is just a simple framing mechanism that is not */
00095 /* useful when other, higher overhead framing mechanisms are used to */
00096 /* transmit the coded frames. */
00097 
00098 /* I'm not going to make an entry to reinitialize this bit, since it */
00099 /* doesn't help a receiver much to know whether the first sync bit is a 0 */
00100 /* or a 1.  It needs to examine several frames in sequence to have */
00101 /* reasonably good assurance that its framing is correct. */
00102 
00103 
00104 /* CHANRD: */
00105 /*   Reconstruct parameters from bitstream */
00106 
00107 /* Input: */
00108 /*  ORDER  - Number of reflection coefficients (not really variable) */
00109 /*  IBITS  - Serial bitstream */
00110 /*           Indices 1 through 53 read (SYNC bit is ignored). */
00111 /* Output: */
00112 /*  IPITV  - Quantized pitch/voicing parameter */
00113 /*  IRMS   - Quantized energy parameter */
00114 /*  IRC    - Quantized reflection coefficients */
00115 /*           Indices 1 through ORDER written */
00116 
00117 /* Entry CHANRD has no local state. */
00118 
00119 
00120 
00121 /*   IBITS is 54 bits of LPC data ordered as follows: */
00122 /*    R1-0, R2-0, R3-0,  P-0,  A-0, */
00123 /*    R1-1, R2-1, R3-1,  P-1,  A-1, */
00124 /*    R1-2, R4-0, R3-2,  A-2,  P-2, R4-1, */
00125 /*    R1-3, R2-2, R3-3, R4-2,  A-3, */
00126 /*    R1-4, R2-3, R3-4, R4-3,  A-4, */
00127 /*     P-3, R2-4, R7-0, R8-0,  P-4, R4-4, */
00128 /*    R5-0, R6-0, R7-1,R10-0, R8-1, */
00129 /*    R5-1, R6-1, R7-2, R9-0,  P-5, */
00130 /*    R5-2, R6-2,R10-1, R8-2,  P-6, R9-1, */
00131 /*    R5-3, R6-3, R7-3, R9-2, R8-3, SYNC */
00132 /* Subroutine */ int chanwr_0_(int n__, integer *order, integer *ipitv, 
00133    integer *irms, integer *irc, integer *ibits,
00134                 struct lpc10_encoder_state *st)
00135 {
00136     /* Initialized data */
00137 
00138     integer *isync;
00139     static integer bit[10] = { 2,4,8,8,8,8,16,16,16,16 };
00140     static integer iblist[53] = { 13,12,11,1,2,13,12,11,1,2,13,10,11,2,1,10,
00141        13,12,11,10,2,13,12,11,10,2,1,12,7,6,1,10,9,8,7,4,6,9,8,7,5,1,9,8,
00142        4,6,1,5,9,8,7,5,6 };
00143 
00144     /* System generated locals */
00145     integer i__1;
00146 
00147     /* Local variables */
00148     integer itab[13], i__;
00149 
00150 /*       Arguments */
00151 /*       Parameters/constants */
00152 /*       These arrays are not Fortran PARAMETER's, but they are defined */
00153 /*       by DATA statements below, and their contents are never altered. 
00154 */
00155 /*       Local variables that need not be saved */
00156 /*       Local state */
00157 /*       ISYNC is only used by CHANWR, not by ENTRY CHANRD. */
00158 
00159     /* Parameter adjustments */
00160     --irc;
00161     --ibits;
00162 
00163     /* Function Body */
00164     switch(n__) {
00165    case 1: goto L_chanrd;
00166    }
00167 
00168     isync = &(st->isync);
00169 
00170 /* ***********************************************************************
00171  */
00172 /*    Place quantized parameters into bitstream */
00173 /* ***********************************************************************
00174  */
00175 /*   Place parameters into ITAB */
00176     itab[0] = *ipitv;
00177     itab[1] = *irms;
00178     itab[2] = 0;
00179     i__1 = *order;
00180     for (i__ = 1; i__ <= i__1; ++i__) {
00181    itab[i__ + 2] = irc[*order + 1 - i__] & 32767;
00182     }
00183 /*   Put 54 bits into IBITS array */
00184     for (i__ = 1; i__ <= 53; ++i__) {
00185    ibits[i__] = itab[iblist[i__ - 1] - 1] & 1;
00186    itab[iblist[i__ - 1] - 1] /= 2;
00187     }
00188     ibits[54] = *isync & 1;
00189     *isync = 1 - *isync;
00190     return 0;
00191 /* ***********************************************************************
00192  */
00193 /*    Reconstruct parameters from bitstream */
00194 /* ***********************************************************************
00195  */
00196 
00197 L_chanrd:
00198 /*   Reconstruct ITAB */
00199     for (i__ = 1; i__ <= 13; ++i__) {
00200    itab[i__ - 1] = 0;
00201     }
00202     for (i__ = 1; i__ <= 53; ++i__) {
00203    itab[iblist[54 - i__ - 1] - 1] = (itab[iblist[54 - i__ - 1] - 1] << 1)
00204        + ibits[54 - i__];
00205     }
00206 /*   Sign extend RC's */
00207     i__1 = *order;
00208     for (i__ = 1; i__ <= i__1; ++i__) {
00209    if ((itab[i__ + 2] & bit[i__ - 1]) != 0) {
00210        itab[i__ + 2] -= bit[i__ - 1] << 1;
00211    }
00212     }
00213 /*   Restore variables */
00214     *ipitv = itab[0];
00215     *irms = itab[1];
00216     i__1 = *order;
00217     for (i__ = 1; i__ <= i__1; ++i__) {
00218    irc[i__] = itab[*order + 4 - i__ - 1];
00219     }
00220     return 0;
00221 } /* chanwr_ */
00222 
00223 /* Subroutine */ int chanwr_(integer *order, integer *ipitv, integer *irms, 
00224    integer *irc, integer *ibits, struct lpc10_encoder_state *st)
00225 {
00226     return chanwr_0_(0, order, ipitv, irms, irc, ibits, st);
00227     }
00228 
00229 /* Subroutine */ int chanrd_(integer *order, integer *ipitv, integer *irms, 
00230    integer *irc, integer *ibits)
00231 {
00232     return chanwr_0_(1, order, ipitv, irms, irc, ibits, NULL);
00233     }

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