150{
151
152
158 static integer ivtab[32] = { 24960,24960,24960,24960,25480,25480,25483,
159 25480,16640,1560,1560,1560,16640,1816,1563,1560,24960,24960,24859,
160 24856,26001,25881,25915,25913,1560,1560,7800,3640,1561,1561,3643,
161 3641 };
162 static real corth[32] = { 32767.f,10.f,5.f,0.f,
163 32767.f,8.f,4.f,0.f,32.f,6.4f,3.2f,0.f,32.f,6.4f,3.2f,0.f,32.f,
164 11.2f,6.4f,0.f,32.f,11.2f,6.4f,0.f,16.f,5.6f,3.2f,0.f,16.f,5.6f,
165 3.2f,0.f };
166 static integer detau[128] = { 0,0,0,3,0,3,3,31,0,3,3,21,3,3,29,30,0,3,3,
167 20,3,25,27,26,3,23,58,22,3,24,28,3,0,3,3,3,3,39,33,32,3,37,35,36,
168 3,38,34,3,3,42,46,44,50,40,48,3,54,3,56,3,52,3,3,1,0,3,3,108,3,78,
169 100,104,3,84,92,88,156,80,96,3,3,74,70,72,66,76,68,3,62,3,60,3,64,
170 3,3,1,3,116,132,112,148,152,3,3,140,3,136,3,144,3,3,1,124,120,128,
171 3,3,3,3,1,3,3,3,1,3,1,1,1 };
172 static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,
173 384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,
174 92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,
175 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
176 static integer detab7[32] = { 4,11,18,25,32,39,46,53,60,66,72,77,82,87,92,
177 96,101,104,108,111,114,115,117,119,121,122,123,124,125,126,127,
178 127 };
179 static real descl[8] = { .6953f,.625f,.5781f,.5469f,.5312f,.5391f,.4688f,
180 .3828f };
182 static integer deadd[8] = { 1152,-2816,-1536,-3584,-1280,-2432,768,-1920 }
183 ;
184 static integer qb[8] = { 511,511,1023,1023,1023,1023,2047,4095 };
185 static integer nbit[10] = { 8,8,5,5,4,4,4,4,3,2 };
186 static integer zrc[10] = { 0,0,0,0,0,3,0,2,0,0 };
187 static integer bit[5] = { 2,4,8,16,32 };
195
196
198
199
201
202
204 integer ipit, iout, i__, icorf, index, ivoic, ixcor, i1, i2, i4;
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388 if (irc) {
389 --irc;
390 }
391 if (voice) {
392 --voice;
393 }
394 if (rc) {
395 --rc;
396 }
397
398
399
402 ivp2h = &(st->
ivp2h);
404 iavgp = &(st->
iavgp);
405 erate = &(st->
erate);
407 dpit = &(st->
dpit[0]);
408 drms = &(st->
drms[0]);
409
410
411
412
413
414 i4 = detau[*ipitv];
416 voice[1] = 1;
417 voice[2] = 1;
418 if (*ipitv <= 1) {
419 voice[1] = 0;
420 }
421 if (*ipitv == 0 || *ipitv == 2) {
422 voice[2] = 0;
423 }
424 *pitch = i4;
425 if (*pitch <= 4) {
426 *pitch = *iptold;
427 }
428 if (voice[1] == 1 && voice[2] == 1) {
429 *iptold = *pitch;
430 }
431 if (voice[1] != voice[2]) {
432 *pitch = *iptold;
433 }
434 goto L900;
435 }
436
437 if (i4 > 4) {
438 dpit[0] = i4;
439 ivoic = 2;
440 *iavgp = (*iavgp * 15 + i4 + 8) / 16;
441 } else {
442 ivoic = i4;
443 dpit[0] = *iavgp;
444 }
445 drms[0] = *irms;
447 for (i__ = 1; i__ <= i__1; ++i__) {
448 drc[i__ * 3 - 3] = irc[i__];
449 }
450
451
452 index = (*ivp2h << 4) + (*iovoic << 2) + ivoic + 1;
453 i1 = ivtab[index - 1];
454 ipit = i1 & 3;
455 icorf = i1 / 8;
456 if (*erate < ethrs) {
457 icorf /= 64;
458 }
459
460 ixcor = 4;
461 if (*erate < ethrs3) {
462 ixcor = 3;
463 }
464 if (*erate < ethrs2) {
465 ixcor = 2;
466 }
467 if (*erate < ethrs1) {
468 ixcor = 1;
469 }
470
471 voice[1] = icorf / 2 & 1;
472 voice[2] = icorf & 1;
473
476
477
478
479
480
481 *pitch = i4;
482 if (*pitch <= 4) {
483 *pitch = *iptold;
484 }
485 goto L500;
486 }
487
488
489
490
491 if ((icorf & bit[3]) != 0) {
492 errcnt = 0;
493 lsb = drms[1] & 1;
494 index = (drc[22] << 4) + drms[1] / 2;
495 ham84_(&index, &iout, &errcnt);
496 drms[1] = drms[2];
497 if (iout >= 0) {
498 drms[1] = (iout << 1) + lsb;
499 }
500 for (i__ = 1; i__ <= 4; ++i__) {
501 if (i__ == 1) {
502 i1 = ((drc[25] & 7) << 1) + (drc[28] & 1);
503 } else {
504 i1 = drc[(9 - i__) * 3 - 2] & 15;
505 }
506 i2 = drc[(5 - i__) * 3 - 2] & 31;
507 lsb = i2 & 1;
508 index = (i1 << 4) + i2 / 2;
509 ham84_(&index, &iout, &errcnt);
510 if (iout >= 0) {
511 iout = (iout << 1) + lsb;
512 if ((iout & 16) == 16) {
513 iout += -32;
514 }
515 } else {
516 iout = drc[(5 - i__) * 3 - 1];
517 }
518 drc[(5 - i__) * 3 - 2] = iout;
519 }
520
521 *erate = (
integer)(*erate * .96875f + errcnt * 102);
522 }
523
524 *irms = drms[1];
526 for (i__ = 1; i__ <= i__1; ++i__) {
527 irc[i__] = drc[i__ * 3 - 2];
528 }
529 if (ipit == 1) {
530 dpit[1] = dpit[2];
531 }
532 if (ipit == 3) {
533 dpit[1] = dpit[0];
534 }
535 *pitch = dpit[1];
536
537 if ((icorf & bit[1]) != 0) {
538 if ((i__1 = drms[1] - drms[0], (
real)
abs(i__1)) >= corth[ixcor + 3]
539 && (i__2 = drms[1] - drms[2], (
real)
abs(i__2)) >= corth[
540 ixcor + 3]) {
541 *irms =
median_(&drms[2], &drms[1], drms);
542 }
543 for (i__ = 1; i__ <= 6; ++i__) {
544 if ((i__1 = drc[i__ * 3 - 2] - drc[i__ * 3 - 3], (
real)
abs(i__1))
545 >= corth[ixcor + ((i__ + 2) << 2) - 5] && (i__2 = drc[i__ *
546 3 - 2] - drc[i__ * 3 - 1], (
real)
abs(i__2)) >= corth[
547 ixcor + ((i__ + 2) << 2) - 5]) {
548 irc[i__] =
median_(&drc[i__ * 3 - 1], &drc[i__ * 3 - 2], &drc[
549 i__ * 3 - 3]);
550 }
551 }
552 }
553
554 if ((icorf & bit[2]) != 0) {
555 if ((i__1 = dpit[1] - dpit[0], (
real)
abs(i__1)) >= corth[ixcor - 1]
556 && (i__2 = dpit[1] - dpit[2], (
real)
abs(i__2)) >= corth[
557 ixcor - 1]) {
558 *pitch =
median_(&dpit[2], &dpit[1], dpit);
559 }
560 }
561
562
563
564L500:
565 if ((icorf & bit[4]) != 0) {
567 for (i__ = 5; i__ <= i__1; ++i__) {
568 irc[i__] = zrc[i__ - 1];
569 }
570 }
571
572 *iovoic = ivoic;
573 *ivp2h = voice[2];
574 dpit[2] = dpit[1];
575 dpit[1] = dpit[0];
576 drms[2] = drms[1];
577 drms[1] = drms[0];
579 for (i__ = 1; i__ <= i__1; ++i__) {
580 drc[i__ * 3 - 1] = drc[i__ * 3 - 2];
581 drc[i__ * 3 - 2] = drc[i__ * 3 - 3];
582 }
583L900:
584
585
586
587 *irms = rmst[(31 - *irms) * 2];
588
589
590 for (i__ = 1; i__ <= 2; ++i__) {
591 i2 = irc[i__];
592 i1 = 0;
593 if (i2 < 0) {
594 i1 = 1;
595 i2 = -i2;
596 if (i2 > 15) {
597 i2 = 0;
598 }
599 }
600 i2 = detab7[i2 * 2];
601 if (i1 == 1) {
602 i2 = -i2;
603 }
604 ishift = 15 - nbit[i__ - 1];
606 }
607
609 for (i__ = 3; i__ <= i__1; ++i__) {
610 i2 = irc[i__];
611 ishift = 15 - nbit[i__ - 1];
613 i2 += qb[i__ - 3];
614 irc[i__] = (
integer)(i2 * descl[i__ - 3] + deadd[i__ - 3]);
615 }
616
617
618
619 *rms = (
real) (*irms);
621 for (i__ = 1; i__ <= i__1; ++i__) {
622 rc[i__] = irc[i__] / 16384.f;
623 }
624 return 0;
625}
struct sla_ringing_trunk * first
integer pow_ii(integer *ap, integer *bp)
integer median_(integer *d1, integer *d2, integer *d3)
int ham84_(integer *input, integer *output, integer *errcnt)