Asterisk - The Open Source Telephony Project GIT-master-f36a736
Macros | Functions | Variables
encode.c File Reference
#include "f2c.h"
Include dependency graph for encode.c:

Go to the source code of this file.

Macros

#define contrl_1   contrl_
 

Functions

int encode_ (integer *voice, integer *pitch, real *rms, real *rc, integer *ipitch, integer *irms, integer *irc)
 

Variables

static integer c__2 = 2
 
struct {
   logical   corrp
 
   integer   lframe
 
   integer   order
 
contrl_
 

Macro Definition Documentation

◆ contrl_1

#define contrl_1   contrl_

Definition at line 41 of file encode.c.

Function Documentation

◆ encode_()

int encode_ ( integer voice,
integer pitch,
real rms,
real rc,
integer ipitch,
integer irms,
integer irc 
)

Definition at line 111 of file encode.c.

113{
114 /* Initialized data */
115
116 static integer enctab[16] = { 0,7,11,12,13,10,6,1,14,9,5,2,3,4,8,15 };
117 static integer entau[60] = { 19,11,27,25,29,21,23,22,30,14,15,7,39,38,46,
118 42,43,41,45,37,53,49,51,50,54,52,60,56,58,26,90,88,92,84,86,82,83,
119 81,85,69,77,73,75,74,78,70,71,67,99,97,113,112,114,98,106,104,108,
120 100,101,76 };
121 static integer enadd[8] = { 1920,-768,2432,1280,3584,1536,2816,-1152 };
122 static real enscl[8] = { .0204f,.0167f,.0145f,.0147f,.0143f,.0135f,.0125f,
123 .0112f };
124 static integer enbits[8] = { 6,5,4,4,4,4,3,3 };
125 static integer entab6[64] = { 0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,
126 3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,9,9,
127 9,10,10,11,11,12,13,14,15 };
128 static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,
129 384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,
130 92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,
131 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
132
133 /* System generated locals */
134 integer i__1, i__2;
135
136 /* Builtin functions */
138
139 /* Local variables */
140 integer idel, nbit, i__, j, i2, i3, mrk;
141
142/* $Log$
143 * Revision 1.15 2004/06/26 03:50:14 markster
144 * Merge source cleanups (bug #1911)
145 *
146 * Revision 1.14 2003/02/12 13:59:15 matteo
147 * mer feb 12 14:56:57 CET 2003
148 *
149 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
150 * mer feb 12 14:56:57 CET 2003
151 *
152 * Revision 1.2 2000/01/05 08:20:39 markster
153 * Some OSS fixes and a few lpc changes to make it actually work
154 *
155 * Revision 1.1 1996/08/19 22:32:21 jaf
156 * Initial revision
157 * */
158/* Revision 1.3 1996/03/29 22:03:47 jaf */
159/* Removed definitions for any constants that were no longer used. */
160
161/* Revision 1.2 1996/03/26 19:34:33 jaf */
162/* Added comments indicating which constants are not needed in an */
163/* application that uses the LPC-10 coder. */
164
165/* Revision 1.1 1996/02/07 14:43:51 jaf */
166/* Initial revision */
167
168/* LPC Configuration parameters: */
169/* Frame size, Prediction order, Pitch period */
170/* Arguments */
171/* $Log$
172 * Revision 1.15 2004/06/26 03:50:14 markster
173 * Merge source cleanups (bug #1911)
174 *
175 * Revision 1.14 2003/02/12 13:59:15 matteo
176 * mer feb 12 14:56:57 CET 2003
177 *
178 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
179 * mer feb 12 14:56:57 CET 2003
180 *
181 * Revision 1.2 2000/01/05 08:20:39 markster
182 * Some OSS fixes and a few lpc changes to make it actually work
183 *
184 * Revision 1.1 1996/08/19 22:32:21 jaf
185 * Initial revision
186 * */
187/* Revision 1.3 1996/03/29 22:05:55 jaf */
188/* Commented out the common block variables that are not needed by the */
189/* embedded version. */
190
191/* Revision 1.2 1996/03/26 19:34:50 jaf */
192/* Added comments indicating which constants are not needed in an */
193/* application that uses the LPC-10 coder. */
194
195/* Revision 1.1 1996/02/07 14:44:09 jaf */
196/* Initial revision */
197
198/* LPC Processing control variables: */
199
200/* *** Read-only: initialized in setup */
201
202/* Files for Speech, Parameter, and Bitstream Input & Output, */
203/* and message and debug outputs. */
204
205/* Here are the only files which use these variables: */
206
207/* lpcsim.f setup.f trans.f error.f vqsetup.f */
208
209/* Many files which use fdebug are not listed, since it is only used in */
210/* those other files conditionally, to print trace statements. */
211/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
212/* LPC order, Frame size, Quantization rate, Bits per frame, */
213/* Error correction */
214/* Subroutine SETUP is the only place where order is assigned a value, */
215/* and that value is 10. It could increase efficiency 1% or so to */
216/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
217*/
218/* a variable in a COMMON block, since it is used in many places in the */
219/* core of the coding and decoding routines. Actually, I take that back.
220*/
221/* At least when compiling with f2c, the upper bound of DO loops is */
222/* stored in a local variable before the DO loop begins, and then that is
223*/
224/* compared against on each iteration. */
225/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
226/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
227/* is used in only a few places, and never in the core coding and */
228/* decoding routines, so it could be eliminated entirely. */
229/* nbits is similar to quant, and is given a value of 54 in SETUP. */
230/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
231/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
232/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
233*/
234/* a constant or a variable, since it is only examined once per frame. */
235/* Leaving it as a variable that is set to .TRUE. seems like a good */
236/* idea, since it does enable some error-correction capability for */
237/* unvoiced frames, with no change in the coding rate, and no noticeable
238*/
239/* quality difference in the decoded speech. */
240/* integer quant, nbits */
241/* *** Read/write: variables for debugging, not needed for LPC algorithm
242*/
243
244/* Current frame, Unstable frames, Output clip count, Max onset buffer,
245*/
246/* Debug listing detail level, Line count on listing page */
247
248/* nframe is not needed for an embedded LPC10 at all. */
249/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
250/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
251/* an application, I would recommend removing the call to ERROR in RCCHK,
252*/
253/* and remove ERROR and nunsfm completely. */
254/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
255*/
256/* sread.f. When LPC10 is embedded into an application, one might want */
257/* to cause it to be incremented in a routine that takes the output of */
258/* SYNTHS and sends it to an audio device. It could be optionally */
259/* displayed, for those that might want to know what it is. */
260/* maxosp is never initialized to 0 in SETUP, although it probably should
261*/
262/* be, and it is updated in subroutine ANALYS. I doubt that its value */
263/* would be of much interest to an application in which LPC10 is */
264/* embedded. */
265/* listl and lincnt are not needed for an embedded LPC10 at all. */
266/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
267/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
268/* common /contrl/ quant, nbits */
269/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
270/* Parameters/constants */
271/* These arrays are not Fortran PARAMETER's, but they are defined */
272/* by DATA statements below, and their contents are never altered.
273*/
274/* Local variables that need not be saved */
275 /* Parameter adjustments */
276 --irc;
277 --rc;
278 --voice;
279
280 /* Function Body */
281/* Scale RMS and RC's to integers */
282 *irms = (integer)*rms;
283 i__1 = contrl_1.order;
284 for (i__ = 1; i__ <= i__1; ++i__) {
285 irc[i__] = (integer)(rc[i__] * 32768.f);
286 }
287/* IF(LISTL.GE.3)WRITE(FDEBUG,800)VOICE,PITCH,IRMS,(IRC(I),I=1,ORDER) */
288/* 800 FORMAT(1X,/,' <<ENCODE IN>>',T32,2I3,I6,I5,T50,10I8) */
289/* Encode pitch and voicing */
290 if (voice[1] != 0 && voice[2] != 0) {
291 *ipitch = entau[*pitch - 1];
292 } else {
293 if (contrl_1.corrp) {
294 *ipitch = 0;
295 if (voice[1] != voice[2]) {
296 *ipitch = 127;
297 }
298 } else {
299 *ipitch = (voice[1] << 1) + voice[2];
300 }
301 }
302/* Encode RMS by binary table search */
303 j = 32;
304 idel = 16;
305 *irms = min(*irms,1023);
306 while(idel > 0) {
307 if (*irms > rmst[j - 1]) {
308 j -= idel;
309 }
310 if (*irms < rmst[j - 1]) {
311 j += idel;
312 }
313 idel /= 2;
314 }
315 if (*irms > rmst[j - 1]) {
316 --j;
317 }
318 *irms = 31 - j / 2;
319/* Encode RC(1) and (2) as log-area-ratios */
320 for (i__ = 1; i__ <= 2; ++i__) {
321 i2 = irc[i__];
322 mrk = 0;
323 if (i2 < 0) {
324 i2 = -i2;
325 mrk = 1;
326 }
327 i2 /= 512;
328 i2 = min(i2,63);
329 i2 = entab6[i2];
330 if (mrk != 0) {
331 i2 = -i2;
332 }
333 irc[i__] = i2;
334 }
335/* Encode RC(3) - (10) linearly, remove bias then scale */
336 i__1 = contrl_1.order;
337 for (i__ = 3; i__ <= i__1; ++i__) {
338 i2 = irc[i__] / 2;
339 i2 = (integer)((i2 + enadd[contrl_1.order + 1 - i__ - 1]) * enscl[
340 contrl_1.order + 1 - i__ - 1]);
341/* Computing MIN */
342 i__2 = max(i2,-127);
343 i2 = min(i__2,127);
344 nbit = enbits[contrl_1.order + 1 - i__ - 1];
345 i3 = 0;
346 if (i2 < 0) {
347 i3 = -1;
348 }
349 i2 /= pow_ii(&c__2, &nbit);
350 if (i3 == -1) {
351 --i2;
352 }
353 irc[i__] = i2;
354 }
355/* Protect the most significant bits of the most */
356/* important parameters during non-voiced frames. */
357/* RC(1) - RC(4) are protected using 20 parity bits */
358/* replacing RC(5) - RC(10). */
359 if (contrl_1.corrp) {
360 if (*ipitch == 0 || *ipitch == 127) {
361 irc[5] = enctab[(irc[1] & 30) / 2];
362 irc[6] = enctab[(irc[2] & 30) / 2];
363 irc[7] = enctab[(irc[3] & 30) / 2];
364 irc[8] = enctab[(*irms & 30) / 2];
365 irc[9] = enctab[(irc[4] & 30) / 2] / 2;
366 irc[10] = enctab[(irc[4] & 30) / 2] & 1;
367 }
368 }
369/* IF(LISTL.GE.3)WRITE(FDEBUG,801)VOICE,IPITCH,IRMS,(IRC(J),J=1,ORDER) */
370/* 801 FORMAT(1X,'<<ENCODE OUT>>',T32,2I3,I6,I5,T50,10I8) */
371 return 0;
372} /* encode_ */
static integer c__2
Definition: encode.c:45
#define contrl_1
Definition: encode.c:41
integer pow_ii(integer *ap, integer *bp)
Definition: f2clib.c:30
#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

References c__2, contrl_1, max, min, and pow_ii().

Referenced by lpc10_encode().

Variable Documentation

◆ c__2

integer c__2 = 2
static

Definition at line 45 of file encode.c.

Referenced by encode_().

◆ 

struct { ... } contrl_

◆ corrp

logical corrp

Definition at line 38 of file encode.c.

◆ lframe

integer lframe

Definition at line 37 of file encode.c.

◆ order

integer order

Definition at line 37 of file encode.c.