-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathowng729fp.c
2247 lines (1831 loc) · 75.1 KB
/
owng729fp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*/////////////////////////////////////////////////////////////////////////////
//
// INTEL CORPORATION PROPRIETARY INFORMATION
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// or disclosed except in accordance with the terms of that agreement.
// Copyright(c) 2004-2008 Intel Corporation. All Rights Reserved.
//
// Intel(R) Integrated Performance Primitives
// USC - Unified Speech Codec interface library
//
// By downloading and installing USC codec, you hereby agree that the
// accompanying Materials are being provided to you under the terms and
// conditions of the End User License Agreement for the Intel(R) Integrated
// Performance Primitives product previously accepted by you. Please refer
// to the file ippEULA.rtf or ippEULA.txt located in the root directory of your Intel(R) IPP
// product installation for more information.
//
// A speech coding standards promoted by ITU, ETSI, 3GPP and other
// organizations. Implementations of these standards, or the standard enabled
// platforms may require licenses from various entities, including
// Intel Corporation.
//
//
// Purpose: G.729 floating-point speech codec: internal functions.
//
*/
#include <math.h>
#include "vadg729fp.h"
#include "owng729fp.h"
#define sqr(a) ((a)*(a))
/* Hamming_cos window for LPC analysis. */
static __ALIGN32 CONST Ipp32f HammingWindow[WINDOW_LEN] = { /* hamming-cosine window */
0.08000000f, 0.08005703f, 0.08022812f, 0.08051321f,
0.08091225f, 0.08142514f, 0.08205172f, 0.08279188f,
0.08364540f, 0.08461212f, 0.08569173f, 0.08688401f,
0.08818865f, 0.08960532f, 0.09113365f, 0.09277334f,
0.09452391f, 0.09638494f, 0.09835598f, 0.10043652f,
0.10262608f, 0.10492408f, 0.10732999f, 0.10984316f,
0.11246302f, 0.11518890f, 0.11802010f, 0.12095598f,
0.12399574f, 0.12713866f, 0.13038395f, 0.13373083f,
0.13717847f, 0.14072597f, 0.14437246f, 0.14811710f,
0.15195890f, 0.15589692f, 0.15993017f, 0.16405767f,
0.16827843f, 0.17259133f, 0.17699537f, 0.18148938f,
0.18607232f, 0.19074300f, 0.19550033f, 0.20034306f,
0.20527001f, 0.21027996f, 0.21537170f, 0.22054392f,
0.22579536f, 0.23112471f, 0.23653066f, 0.24201185f,
0.24756692f, 0.25319457f, 0.25889328f, 0.26466170f,
0.27049842f, 0.27640197f, 0.28237087f, 0.28840363f,
0.29449883f, 0.30065489f, 0.30687031f, 0.31314352f,
0.31947297f, 0.32585713f, 0.33229437f, 0.33878314f,
0.34532180f, 0.35190874f, 0.35854232f, 0.36522087f,
0.37194279f, 0.37870640f, 0.38550997f, 0.39235184f,
0.39923036f, 0.40614375f, 0.41309035f, 0.42006844f,
0.42707625f, 0.43411207f, 0.44117412f, 0.44826069f,
0.45537004f, 0.46250033f, 0.46964988f, 0.47681686f,
0.48399949f, 0.49119604f, 0.49840465f, 0.50562358f,
0.51285106f, 0.52008528f, 0.52732444f, 0.53456670f,
0.54181033f, 0.54905349f, 0.55629444f, 0.56353134f,
0.57076240f, 0.57798582f, 0.58519983f, 0.59240264f,
0.59959245f, 0.60676748f, 0.61392599f, 0.62106609f,
0.62818617f, 0.63528436f, 0.64235890f, 0.64940804f,
0.65643007f, 0.66342324f, 0.67038584f, 0.67731601f,
0.68421221f, 0.69107264f, 0.69789559f, 0.70467937f,
0.71142232f, 0.71812278f, 0.72477907f, 0.73138952f,
0.73795253f, 0.74446648f, 0.75092971f, 0.75734061f,
0.76369762f, 0.76999915f, 0.77624369f, 0.78242958f,
0.78855544f, 0.79461962f, 0.80062068f, 0.80655706f,
0.81242740f, 0.81823015f, 0.82396388f, 0.82962728f,
0.83521879f, 0.84073710f, 0.84618086f, 0.85154873f,
0.85683930f, 0.86205131f, 0.86718345f, 0.87223446f,
0.87720311f, 0.88208807f, 0.88688827f, 0.89160240f,
0.89622939f, 0.90076804f, 0.90521723f, 0.90957582f,
0.91384280f, 0.91801709f, 0.92209762f, 0.92608339f,
0.92997342f, 0.93376678f, 0.93746245f, 0.94105959f,
0.94455731f, 0.94795465f, 0.95125085f, 0.95444512f,
0.95753652f, 0.96052444f, 0.96340811f, 0.96618676f,
0.96885973f, 0.97142631f, 0.97388595f, 0.97623801f,
0.97848189f, 0.98061699f, 0.98264289f, 0.98455900f,
0.98636484f, 0.98806006f, 0.98964417f, 0.99111670f,
0.99247742f, 0.99372596f, 0.99486196f, 0.99588519f,
0.99679530f, 0.99759221f, 0.99827564f, 0.99884540f,
0.99930143f, 0.99964350f, 0.99987161f, 0.99998569f,
1.00000000f, 0.99921930f, 0.99687845f, 0.99298108f,
0.98753333f, 0.98054361f, 0.97202289f, 0.96198452f,
0.95044410f, 0.93741965f, 0.92293155f, 0.90700239f,
0.88965708f, 0.87092263f, 0.85082841f, 0.82940567f,
0.80668795f, 0.78271067f, 0.75751126f, 0.73112911f,
0.70360541f, 0.67498308f, 0.64530689f, 0.61462307f,
0.58297962f, 0.55042595f, 0.51701277f, 0.48279238f,
0.44781810f, 0.41214463f, 0.37582767f, 0.33892387f,
0.30149087f, 0.26358715f, 0.22527184f, 0.18660481f,
0.14764643f, 0.10845750f, 0.06909923f, 0.02963307f};
void ownAutoCorr_G729_32f(Ipp32f *pSrc, Ipp32s len, Ipp32f *pDst, Ipp32f *pExtBuff)
{
ippsMul_32f(pSrc, HammingWindow, pExtBuff, WINDOW_LEN);
ippsAutoCorr_32f(pExtBuff, WINDOW_LEN, pDst, len+1);
if (pDst[0]<(Ipp32f)1.0) pDst[0]=(Ipp32f)1.0;
return;
}
void ownACOS_G729_32f(Ipp32f *pSrc, Ipp32f *pDst, Ipp32s len)
{
Ipp32s i;
for (i=0; i<len; i++ )
pDst[i] = (Ipp32f)acos(pSrc[i]);
return;
}
void ownCOS_G729_32f(Ipp32f *pSrc, Ipp32f *pDst, Ipp32s len)
{
Ipp32s i;
for (i=0; i<len; i++ )
pDst[i] = (Ipp32f)cos(pSrc[i]);
return;
}
Ipp32f ownAdaptiveCodebookGainCoeff_G729_32f(Ipp32f *pSrcTargetVector, Ipp32f *pSrcFltAdaptivCdbkVec,
Ipp32f *pDstCorrCoeff, Ipp32s len)
{
Ipp32f fCorr, fEnergy, fGain;
Ipp64f sum;
/* energy of filtered excitation */
ippsDotProd_32f64f(pSrcFltAdaptivCdbkVec, pSrcFltAdaptivCdbkVec, len, &sum);
fEnergy = (Ipp32f)(sum + 0.01);
ippsDotProd_32f64f(pSrcTargetVector, pSrcFltAdaptivCdbkVec, len, &sum);
fCorr = (Ipp32f)sum;
pDstCorrCoeff[0] = fEnergy;
pDstCorrCoeff[1] = -2.0f*fCorr +0.01f;
/* find pitch fGain and bound it by [0,1.2] */
fGain = fCorr/fEnergy;
CLIP_TO_LOWLEVEL(fGain,0.f);
CLIP_TO_UPLEVEL(fGain,GAIN_PIT_MAX);
return fGain;
}
void WeightLPCCoeff_G729(Ipp32f *pSrcLPC, Ipp32f valWeightingFactor, Ipp32s len, Ipp32f *pDstWeightedLPC)
{
Ipp32f fFactor;
Ipp32s i;
pDstWeightedLPC[0]=pSrcLPC[0];
fFactor=valWeightingFactor;
for (i = 1; i < len; i++)
{
pDstWeightedLPC[i] = fFactor*pSrcLPC[i];
fFactor *= valWeightingFactor;
}
pDstWeightedLPC[len] = fFactor*pSrcLPC[len];
return;
}
void AdaptiveCodebookGainCoeff_G729_32f( Ipp32f *pSrcTargetVector, Ipp32f *pSrcFltAdaptiveCodebookVector,
Ipp32f *pSrcFltInnovation, Ipp32f *pDstCoeff)
{
Ipp64f sum;
ippsDotProd_32f64f(pSrcFltInnovation, pSrcFltInnovation, SUBFR_LEN, &sum);
pDstCoeff[2] = (Ipp32f)(sum + 0.01);
ippsDotProd_32f64f(pSrcTargetVector, pSrcFltInnovation, SUBFR_LEN, &sum);
pDstCoeff[3] = (Ipp32f)(-2.0*(sum + 0.01));
ippsDotProd_32f64f(pSrcFltAdaptiveCodebookVector, pSrcFltInnovation, SUBFR_LEN, &sum);
pDstCoeff[4] = (Ipp32f)(2.0*(sum + 0.01));
return;
}
Ipp32s ownAdaptiveCodebookSearch_G729A_32f(Ipp32f *pSrcExc, Ipp32f *pSrcTargetVector, Ipp32f *pSrcImpulseResponse,
Ipp32s minPitchDelay, Ipp32s maxPitchDelay, Ipp32s nSbfr, Ipp32s *fracPartPitchDelay, Ipp32f *pExtBuff)
{
Ipp32s pitchPeriod;
Ipp32f *pCorr;
Ipp32f *pTmpExcitation;
Ipp64f corr, max;
Ipp32s delayLine[2];
pCorr = &pExtBuff[0];
pTmpExcitation = &pExtBuff[SUBFR_LEN];
/* Compute correlations of input response with the target vector.*/
ippsCrossCorr_32f(pSrcImpulseResponse, SUBFR_LEN, pSrcTargetVector, SUBFR_LEN, pCorr, SUBFR_LEN, 0);
/* Find maximum integer delay */
ippsCrossCorrLagMax_32f64f(pCorr, &pSrcExc[-maxPitchDelay], SUBFR_LEN, maxPitchDelay-minPitchDelay, &max, &pitchPeriod);
pitchPeriod = (maxPitchDelay-minPitchDelay-pitchPeriod) + minPitchDelay;
/* Test fractions */
/* Fraction 0 */
delayLine[0] = pitchPeriod;
delayLine[1] = 0;
ippsDecodeAdaptiveVector_G729_32f_I(delayLine, pSrcExc);
ippsDotProd_32f64f( pCorr, pSrcExc, SUBFR_LEN, &max);
*fracPartPitchDelay = 0;
/* If first subframe and lag > 84 do not search fractional pitch */
if( (nSbfr == 0) && (pitchPeriod > 84) )
return pitchPeriod;
ippsCopy_32f(pSrcExc, pTmpExcitation, SUBFR_LEN);
/* Fraction -1/3 */
delayLine[1] = -1;
ippsDecodeAdaptiveVector_G729_32f_I(delayLine, pSrcExc);
ippsDotProd_32f64f( pCorr, pSrcExc, SUBFR_LEN, &corr);
if(corr > max){
max = corr;
*fracPartPitchDelay = -1;
ippsCopy_32f(pSrcExc, pTmpExcitation, SUBFR_LEN);
}
/* Fraction +1/3 */
delayLine[1] = 1;
ippsDecodeAdaptiveVector_G729_32f_I(delayLine, pSrcExc);
ippsDotProd_32f64f( pCorr, pSrcExc, SUBFR_LEN, &corr);
if(corr > max){
max = corr;
*fracPartPitchDelay = 1;
}
else
ippsCopy_32f(pTmpExcitation, pSrcExc, SUBFR_LEN);
return pitchPeriod;
}
Ipp32s ExtractBitsG729FP( const Ipp8u **pBits, Ipp32s *nBit, Ipp32s Count )
{
Ipp32s i ;
Ipp32s Rez = 0L ;
for ( i = 0 ; i < Count ; i ++ ){
Ipp32s fTmp ;
fTmp = ((*pBits)[(i + *nBit)>>3] >> (7 - ((i + *nBit) & 0x0007)) ) & 1;
Rez <<= 1 ;
Rez += fTmp ;
}
*pBits += (Count + *nBit)>>3;
*nBit = (Count + *nBit) & 0x0007;
return Rez ;
}
void PWGammaFactor_G729(Ipp32f *pGamma1, Ipp32f *pGamma2, Ipp32f *pIntLSF, Ipp32f *CurrLSF,
Ipp32f *ReflectCoeff, Ipp32s *isFlat, Ipp32f *PrevLogAreaRatioCoeff)
{
Ipp32f logAreaRatioCoeff[4];
Ipp32f *logAreaRatioCoeffNew;
Ipp32f *lsf;
Ipp32f minDist, fTmp;
Ipp32s i, k;
logAreaRatioCoeffNew = &logAreaRatioCoeff[2];
/* Convert reflection coefficients to the Log Area Ratio coefficient*/
for (i=0; i<2; i++)
logAreaRatioCoeffNew[i] = (Ipp32f)log10( (Ipp64f)( ( 1.0f + ReflectCoeff[i]) / (1.0f - ReflectCoeff[i])));
/* Interpolation of lar for the 1st subframe */
for (i=0; i<2; i++) {
logAreaRatioCoeff[i] = 0.5f * (logAreaRatioCoeffNew[i] + PrevLogAreaRatioCoeff[i]);
PrevLogAreaRatioCoeff[i] = logAreaRatioCoeffNew[i];
}
for (k=0; k<2; k++) { /* LOOP : gamma2 for 1st to 2nd subframes */
if (*isFlat != 0) {
if ((logAreaRatioCoeff[2*k] <LAR_THRESH1 )&&(logAreaRatioCoeff[2*k+1] > LAR_THRESH3)) *isFlat = 0;
} else {
if ((logAreaRatioCoeff[2*k] > LAR_THRESH2)||(logAreaRatioCoeff[2*k+1] < LAR_THRESH4)) *isFlat = 1;
}
if (*isFlat == 0) {
/* Second criterion based on the minimum distance between two successives lsfs. */
pGamma1[k] = GAMMA1_TILTED;
if (k == 0) lsf = pIntLSF;
else lsf = CurrLSF;
minDist = lsf[1] - lsf[0];
for (i=1; i<LPC_ORDER-1; i++) {
fTmp = lsf[i+1] - lsf[i];
if (fTmp < minDist) minDist = fTmp;
}
pGamma2[k] = GAMMA2_TILTED_SCALE * minDist + GAMMA2_TILTED_SHIFT;
if (pGamma2[k] > GAMMA2_TILTED_MAX) pGamma2[k] = GAMMA2_TILTED_MAX;
if (pGamma2[k] < GAMMA2_TILTED_MIN) pGamma2[k] = GAMMA2_TILTED_MIN;
} else {
pGamma1[k] = GAMMA1_FLAT;
pGamma2[k] = GAMMA2_FLAT;
}
}
return;
}
void CodewordImpConv_G729_32f(Ipp32s index, const Ipp32f *pSrc1,const Ipp32f *pSrc2,Ipp32f *pDst)
{
Ipp32s i;
Ipp32s lPos0, lPos1, lPos2, lPos3; /* position*/
Ipp32s lSign0, lSign1, lSign2, lSign3; /*signs: 1,-1*/
lPos0 = index & 0x7;
lPos1 = (index>>3) & 0x7;
lPos2 = (index>>6) & 0x7;
lPos3 = index>>9;
lPos0 = (lPos0<<2)+lPos0; /* lPos0*5;*/
lPos1 = (lPos1<<2)+lPos1+1; /* 1+lPos1*5;*/
lPos2 = (lPos2<<2)+lPos2+2; /* 2+lPos2*5;*/
lPos3 = ((lPos3>>1)<<2)+(lPos3>>1)+(lPos3&1)+3; /* 3+(lPos3>>1)*5+(lPos3&1);*/
if (lPos0>lPos1) {i=lPos0; lPos0=lPos1; lPos1=i; }
if (lPos2>lPos3) {i=lPos2; lPos2=lPos3; lPos3=i; }
if (lPos0>lPos2) {i=lPos0; lPos0=lPos2; lPos2=i; }
if (lPos1>lPos3) {i=lPos1; lPos1=lPos3; lPos3=i; }
if (lPos1>lPos2) {i=lPos1; lPos1=lPos2; lPos2=i; }
lSign0 = (pSrc1[lPos0] > 0)? 1:-1;
lSign1 = (pSrc1[lPos1] > 0)? 1:-1;
lSign2 = (pSrc1[lPos2] > 0)? 1:-1;
lSign3 = (pSrc1[lPos3] > 0)? 1:-1;
for (i=0; i<lPos0; i++)
pDst[i]=0;
for (; i<lPos1; i++)
pDst[i]=lSign0*pSrc2[i-lPos0];
for (; i<lPos2; i++)
pDst[i]=lSign0*pSrc2[i-lPos0]+lSign1*pSrc2[i-lPos1];
for (; i<lPos3; i++)
pDst[i]=lSign0*pSrc2[i-lPos0]+lSign1*pSrc2[i-lPos1]+lSign2*pSrc2[i-lPos2];
for (; i<SUBFR_LEN; i++)
pDst[i]=lSign0*pSrc2[i-lPos0]+lSign1*pSrc2[i-lPos1]+lSign2*pSrc2[i-lPos2]+lSign3*pSrc2[i-lPos3];
}
void MSDGetSize(Ipp32s *pDstSize)
{
*pDstSize = sizeof(CNGmemory);
return;
}
void MSDInit(Ipp8s *msdMem)
{
MusDetectMemory *msdState = (MusDetectMemory *)msdMem;
ippsZero_16s((Ipp16s*)msdState,sizeof(MusDetectMemory)>>1) ;
ippsZero_32f(msdState->MeanRC,10);
msdState->lMusicCounter=0;
msdState->fMusicCounter=0.0f;
msdState->lZeroMusicCounter=0;
msdState->fMeanPitchGain =0.5f;
msdState->lPFlagCounter=0;
msdState->fMeanPFlagCounter=0.0;
msdState->lConscPFlagCounter=0;
msdState->lRCCounter=0;
msdState->fMeanFullBandEnergy =0.0f;
return;
}
void MusicDetection_G729E_32f(G729FPEncoder_Obj *encoderObj, G729Codec_Type codecType, Ipp32f Energy,
Ipp32f *ReflectCoeff, Ipp32s *VadDecision, Ipp32f LLenergy, Ipp8s *msdMem,Ipp32f *pExtBuff)
{
Ipp32s i;
Ipp32f fSum1, fSum2,fStandartDeviation;
Ipp16s VoicingStrenght1, VoicingStrenght2, VoicingStrenght;
Ipp32f fError, fEnergy , fSpectralDifference, *pTmpVec;
Ipp32f fThreshold;
MusDetectMemory *msdState = (MusDetectMemory *)msdMem;
pTmpVec = &pExtBuff[0]; /*10 elements*/
fError = 1.0f;
for (i=0; i< 4; i++) fError *= (1.0f - ReflectCoeff[i]*ReflectCoeff[i]);
ippsSub_32f(msdState->MeanRC, ReflectCoeff, pTmpVec, 10);
ippsDotProd_32f(pTmpVec, pTmpVec, 10, &fSpectralDifference);
fEnergy = 10.0f*(Ipp32f)log10(fError*Energy/240.0f +IPP_MINABS_32F);
if( *VadDecision == VAD_NOISE ){
ippsInterpolateC_G729_32f(msdState->MeanRC, 0.9f, ReflectCoeff, 0.1f, msdState->MeanRC, 10);
msdState->fMeanFullBandEnergy = 0.9f * msdState->fMeanFullBandEnergy + 0.1f * fEnergy;
}
fSum1 = 0.0f;
fSum2 = 0.0f;
for(i=0; i<5; i++){
fSum1 += (Ipp32f) encoderObj->LagBuffer[i];
fSum2 += encoderObj->PitchGainBuffer[i];
}
fSum1 = fSum1/5.0f;
fSum2 = fSum2/5.0f;
fStandartDeviation =0.0f;
for(i=0; i<5; i++) fStandartDeviation += sqr(((Ipp32f) encoderObj->LagBuffer[i] - fSum1));
fStandartDeviation = (Ipp32f)sqrt(fStandartDeviation/4.0f);
msdState->fMeanPitchGain = 0.8f * msdState->fMeanPitchGain + 0.2f * fSum2;
/* See I.5.1.1 Pitch lag smoothness and voicing strenght indicator.*/
if ( codecType == G729D_CODEC)
fThreshold = 0.73f;
else
fThreshold = 0.63f;
if ( msdState->fMeanPitchGain > fThreshold)
VoicingStrenght2 = 1;
else
VoicingStrenght2 = 0;
if ( fStandartDeviation < 1.30f && msdState->fMeanPitchGain > 0.45f )
VoicingStrenght1 = 1;
else
VoicingStrenght1 = 0;
VoicingStrenght= (Ipp16s)( ((Ipp16s)encoderObj->prevVADDec & (Ipp16s)(VoicingStrenght1 | VoicingStrenght2))| (Ipp16s)(VoicingStrenght2));
if( ReflectCoeff[1] <= 0.45f && ReflectCoeff[1] >= 0.0f && msdState->fMeanPitchGain < 0.5f)
msdState->lRCCounter++;
else
msdState->lRCCounter =0;
if( encoderObj->prevLPCMode== 1 && (*VadDecision == VAD_VOICE))
msdState->lMusicCounter++;
if ((encoderObj->sFrameCounter%64) == 0 ){
if( encoderObj->sFrameCounter == 64)
msdState->fMusicCounter = (Ipp32f)msdState->lMusicCounter;
else
msdState->fMusicCounter = 0.9f*msdState->fMusicCounter + 0.1f*(Ipp32f)msdState->lMusicCounter;
}
if( msdState->lMusicCounter == 0)
msdState->lZeroMusicCounter++;
else
msdState->lZeroMusicCounter = 0;
if( msdState->lZeroMusicCounter > 500 || msdState->lRCCounter > 150) msdState->fMusicCounter = 0.0f;
if ((encoderObj->sFrameCounter%64) == 0)
msdState->lMusicCounter = 0;
if( VoicingStrenght== 1 )
msdState->lPFlagCounter++;
if ((encoderObj->sFrameCounter%64) == 0 ){
if( encoderObj->sFrameCounter == 64)
msdState->fMeanPFlagCounter = (Ipp32f)msdState->lPFlagCounter;
else{
if( msdState->lPFlagCounter > 25)
msdState->fMeanPFlagCounter = 0.98f * msdState->fMeanPFlagCounter + 0.02f * msdState->lPFlagCounter;
else if( msdState->lPFlagCounter > 20)
msdState->fMeanPFlagCounter = 0.95f * msdState->fMeanPFlagCounter + 0.05f * msdState->lPFlagCounter;
else
msdState->fMeanPFlagCounter = 0.90f * msdState->fMeanPFlagCounter + 0.10f * msdState->lPFlagCounter;
}
}
if( msdState->lPFlagCounter == 0)
msdState->lConscPFlagCounter++;
else
msdState->lConscPFlagCounter = 0;
if( msdState->lConscPFlagCounter > 100 || msdState->lRCCounter > 150) msdState->fMeanPFlagCounter = 0.0f;
if ((encoderObj->sFrameCounter%64) == 0)
msdState->lPFlagCounter = 0;
if (codecType == G729E_CODEC){
if( fSpectralDifference > 0.15f && (fEnergy -msdState->fMeanFullBandEnergy)> 4.0f && (LLenergy> 50.0) )
*VadDecision =VAD_VOICE;
else if( (fSpectralDifference > 0.38f || (fEnergy -msdState->fMeanFullBandEnergy)> 4.0f ) && (LLenergy> 50.0f))
*VadDecision =VAD_VOICE;
else if( (msdState->fMeanPFlagCounter >= 10.0f || msdState->fMusicCounter >= 5.0f || encoderObj->sFrameCounter < 64)&& (LLenergy> 7.0))
*VadDecision =VAD_VOICE;
}
return;
}
void PitchTracking_G729FPE(Ipp32s *pitchDelay, Ipp32s *fracPitchDelay, Ipp32s *prevPitchDelay, Ipp32s *stat_N,
Ipp32s *lStatPitch2PT, Ipp32s *lStatFracPT)
{
Ipp32s pitchDistance, minDist, lPitchMult;
Ipp32s j, distSign;
pitchDistance = (*pitchDelay) - (*prevPitchDelay);
if(pitchDistance < 0) {
distSign = 0;
pitchDistance = - pitchDistance;
} else {
distSign = 1;
}
/* Test pitch stationarity */
if (pitchDistance < 5) {
(*stat_N)++;
if (*stat_N > 7) *stat_N = 7 ;
*lStatPitch2PT = *pitchDelay;
*lStatFracPT = *fracPitchDelay;
} else {
/* Find multiples or sub-multiples */
minDist = pitchDistance;
if( distSign == 0) {
lPitchMult = 2 * (*pitchDelay);
for (j=2; j<5; j++) {
pitchDistance = abs(lPitchMult - (*prevPitchDelay));
if (pitchDistance <= minDist) {
minDist = pitchDistance;
}
lPitchMult += (*pitchDelay);
}
} else {
lPitchMult = 2 * (*prevPitchDelay);
for (j=2; j<5; j++) {
pitchDistance = abs(lPitchMult - (*pitchDelay));
if (pitchDistance <= minDist) {
minDist = pitchDistance;
}
lPitchMult += (*prevPitchDelay);
}
}
if (minDist < 5) { /* Multiple or sub-multiple detected */
if (*stat_N > 0) {
*pitchDelay = *lStatPitch2PT;
*fracPitchDelay = *lStatFracPT;
}
*stat_N -= 1;
if (*stat_N < 0) *stat_N = 0 ;
} else {
*stat_N = 0; /* No (sub-)multiple detected => Pitch transition */
*lStatPitch2PT = *pitchDelay;
*lStatFracPT = *fracPitchDelay;
}
}
*prevPitchDelay = *pitchDelay;
return;
}
void OpenLoopPitchSearch_G729_32f(const Ipp32f *pSrc, Ipp32s* lBestLag)
{
Ipp32f fTmp;
Ipp64f dTmp;
Ipp32f fMax1, fMax2, fMax3;
Ipp32s max1Idx, max2Idx, max3Idx;
/* Find a maximum for three sections and compare the maxima
of each section by favoring small lag. */
/* First section: lag delay = PITCH_LAG_MAX to 80 */
ippsAutoCorrLagMax_32f(pSrc, FRM_LEN, 80,PITCH_LAG_MAX+1, &fMax1, &max1Idx);
/* Second section: lag delay = 79 to 40 */
ippsAutoCorrLagMax_32f(pSrc, FRM_LEN, 40,80, &fMax2, &max2Idx);
/* Third section: lag delay = 39 to 20 */
ippsAutoCorrLagMax_32f(pSrc, FRM_LEN, PITCH_LAG_MIN,40, &fMax3, &max3Idx);
ippsDotProd_32f64f(&pSrc[-max1Idx], &pSrc[-max1Idx], FRM_LEN, &dTmp);
fTmp = (Ipp32f) (1.0f / sqrt(dTmp+0.01f));
fMax1 = (Ipp32f)(fMax1) * fTmp; /* max/sqrt(energy) */
ippsDotProd_32f64f(&pSrc[-max2Idx], &pSrc[-max2Idx], FRM_LEN, &dTmp);
fTmp = (Ipp32f) (1.0f / sqrt(dTmp+0.01));
fMax2 = (Ipp32f)(fMax2) * fTmp; /* max/sqrt(energy) */
/* Calc energy */
ippsDotProd_32f64f(&pSrc[-max3Idx], &pSrc[-max3Idx], FRM_LEN, &dTmp);
/* 1/sqrt(energy) */
fTmp = 1.0f / (Ipp32f)sqrt(dTmp+0.01);
fMax3 = (Ipp32f)(fMax3) * fTmp; /* max/sqrt(energy) */
/* Compare the 3 sections maxima and choose the small one. */
if ( fMax1 * PITCH_THRESH < fMax2 ) {
fMax1 = fMax2;
max1Idx = max2Idx;
}
if ( fMax1 * PITCH_THRESH < fMax3 ) max1Idx = max3Idx;
*lBestLag = max1Idx;
return;
}
Ipp32s TestErrorContribution_G729(Ipp32s valPitchDelay, Ipp32s valFracPitchDelay, Ipp32f *ExcErr)
{
Ipp32s j, lTmp, l1, l2, lTaming;
Ipp32f maxErrExc;
lTmp = (valFracPitchDelay > 0) ? (valPitchDelay+1) : valPitchDelay;
j = lTmp - SUBFR_LEN - INTER_PITCH_LEN;
if(j < 0) j = 0;
l1 = (Ipp32s) (j * INV_SUBFR_LEN);
j = lTmp + INTER_PITCH_LEN - 2;
l2 = (Ipp32s) (j * INV_SUBFR_LEN);
maxErrExc = -1.f;
lTaming = 0 ;
for(j=l2; j>=l1; j--) {
if(ExcErr[j] > maxErrExc) maxErrExc = ExcErr[j];
}
if(maxErrExc > THRESH_ERR) {
lTaming = 1;
}
return(lTaming);
}
void UpdateExcErr_G729(Ipp32f valPitchGain, Ipp32s valPitchDelay, Ipp32f *pExcErr)
{
Ipp32s i, l1, l2, n;
Ipp32f fMax, fTmp;
fMax = -1.f;
n = valPitchDelay- SUBFR_LEN;
if(n < 0) {
fTmp = 1.f + valPitchGain * pExcErr[0];
if(fTmp > fMax) fMax = fTmp;
fTmp = 1.f + valPitchGain * fTmp;
if(fTmp > fMax) fMax = fTmp;
} else {
l1 = (Ipp32s) (n * INV_SUBFR_LEN);
i = valPitchDelay - 1;
l2 = (Ipp32s) (i * INV_SUBFR_LEN);
for(i = l1; i <= l2; i++) {
fTmp = 1.f + valPitchGain * pExcErr[i];
if(fTmp > fMax) fMax = fTmp;
}
}
for(i=3; i>=1; i--) pExcErr[i] = pExcErr[i-1];
pExcErr[0] = fMax;
return;
}
void isBackwardModeDominant_G729(Ipp32s *isBackwardModeDominant, Ipp32s LPCMode, Ipp32s *pCounterBackward, Ipp32s *pCounterForward)
{
Ipp32s lTmp, lCounter;
if (LPCMode == 0) (*pCounterForward)++;
else (*pCounterBackward)++;
lCounter = *pCounterBackward + *pCounterForward;
if (lCounter == 100) {
lCounter = lCounter >> 1;
*pCounterBackward = (*pCounterBackward) >> 1;
*pCounterForward = (*pCounterForward) >> 1;
}
*isBackwardModeDominant = 0;
if (lCounter >= 10) {
lTmp = (*pCounterForward) << 2;
if (*pCounterBackward > lTmp) *isBackwardModeDominant = 1;
}
return;
}
Ipp32f CalcEnergy_dB_G729(Ipp32f *pSrc, Ipp32s len)
{
Ipp64f dEnergy;
Ipp32f fEnergydB;
Ipp32s n, k, lTmp;
ippsDotProd_32f64f(pSrc, pSrc, len, &dEnergy);
dEnergy += 0.0001;
fEnergydB = (Ipp32f)log10(dEnergy);
n = (Ipp32s) (fEnergydB * INVERSE_LOG2);
if(n >= 4) {
if(dEnergy > 2147483647.) dEnergy = 93.1814;
else {
k = (Ipp32s)dEnergy;
lTmp = -(1 << (n-4));
k &= lTmp;
dEnergy = 10. * log10((Ipp32f)k);
}
}
else dEnergy = 0.005;
return (Ipp32f)dEnergy;
}
void InterpolatedBackwardFilter_G729(Ipp32f *pSrcDstLPCBackwardFlt, Ipp32f *pSrcPrevFilter, Ipp32f *pSrcDstIntCoeff)
{
Ipp32s i;
Ipp32f s1, s2;
Ipp32f *pBwdLPC;
Ipp32f fIntFactor;
pBwdLPC = pSrcDstLPCBackwardFlt + BWD_LPC_ORDERP1;
/* Calculate the interpolated filters */
fIntFactor = *pSrcDstIntCoeff - 0.1f;
if( fIntFactor < 0) fIntFactor = 0;
for (i=0; i<BWD_LPC_ORDERP1; i++) {
s1 = pBwdLPC[i] * (1.f - fIntFactor);
s2 = pSrcPrevFilter[i] * fIntFactor;
pBwdLPC[i] = s1 + s2;
}
//ippsInterpolateC_G729_32f(pBwdLPC, (1.f - fIntFactor), pSrcPrevFilter, fIntFactor, pBwdLPC, BWD_LPC_ORDERP1);
for (i=0; i<BWD_LPC_ORDERP1; i++) {
pSrcDstLPCBackwardFlt[i] = 0.5f * (pBwdLPC[i] + pSrcPrevFilter[i]);
}
//ippsInterpolateC_G729_32f(pBwdLPC, 0.5f, pSrcPrevFilter, 0.5f, pBwdLPC, BWD_LPC_ORDERP1);
*pSrcDstIntCoeff = fIntFactor;
return;
}
/* anti-sparseness post-processing */
static __ALIGN32 CONST Ipp32f ImpLow[SUBFR_LEN]={
0.4483f, 0.3515f, 0.0387f,-0.0843f,-0.1731f, 0.2293f,-0.0011f,
-0.0857f,-0.0928f, 0.1472f, 0.0901f,-0.2571f, 0.1155f, 0.0444f,
0.0665f,-0.2636f, 0.2457f,-0.0642f,-0.0444f, 0.0237f, 0.0338f,
-0.0728f, 0.0688f,-0.0111f,-0.0206f,-0.0642f, 0.1845f,-0.1734f,
0.0327f, 0.0953f,-0.1544f, 0.1621f,-0.0711f,-0.1138f, 0.2113f,
-0.1187f, 0.0206f,-0.0542f, 0.0009f,0.3096f
};
static __ALIGN32 CONST Ipp32f ImpMiddle[SUBFR_LEN]={
0.9239f, 0.1169f, -0.1232f, 0.0907f, -0.0320f, -0.0306f, 0.0756f,
-0.0929f, 0.0859f, -0.0681f, 0.0535f, -0.0492f, 0.0523f, -0.0542f,
0.0471f, -0.0308f, 0.0131f, -0.0052f, 0.0144f, -0.0386f, 0.0664f,
-0.0826f, 0.0770f, -0.0495f, 0.0105f, 0.0252f, -0.0467f, 0.0526f,
-0.0506f, 0.0519f, -0.0630f, 0.0807f, -0.0934f, 0.0884f, -0.0604f,
0.0170f, 0.0238f, -0.0418f, 0.0257f, 0.0200f
};
static __ALIGN32 CONST Ipp32f ImpHigh[SUBFR_LEN]={
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f
};
void PHDGetSize(Ipp32s *pDstSize)
{
*pDstSize = sizeof(PHDmemory);
return;
}
void PHDInit(Ipp8s *phdMem)
{
PHDmemory *phdState = (PHDmemory *)phdMem;
ippsZero_32f(phdState->gainMem,6);
phdState->prevDispState = 0;
phdState->prevCbGain = 0.;
phdState->onset = 0;
}
void PhaseDispersionUpdate_G729D(Ipp32f valPitchGain, Ipp32f valCodebookGain, Ipp8s *phdMem)
{
Ipp32s i;
PHDmemory *phdState = (PHDmemory *)phdMem;
for (i = 5; i > 0; i--) phdState->gainMem[i] = phdState->gainMem[i-1];
phdState->gainMem[0] = valPitchGain;
phdState->prevDispState = 2;
phdState->prevCbGain = valCodebookGain;
phdState->onset = 0;
return;
}
void PhaseDispersion_G729D(Ipp32f *pSrcExcSignal, Ipp32f *pDstFltExcSignal, Ipp32f valCodebookGain,
Ipp32f valPitchGain, Ipp32f *pSrcDstInnovation, Ipp8s *phdMem,Ipp8s *pExtBuff)
{
Ipp32s i;
PHDmemory *phdState = (PHDmemory *)phdMem;
Ipp32f *pScaledLTP;
Ipp32f *pMemory;
Ipp32s *pPos;
Ipp32s numNonZeroElem, nPulse, i1, lPos;
Ipp32s phDispState;
const Ipp32f *pTable=NULL;
pScaledLTP = (Ipp32f *)pExtBuff;
pMemory = (Ipp32f *)(pExtBuff + SUBFR_LEN*sizeof(Ipp32f));
pPos = (Ipp32s *)(pMemory + SUBFR_LEN*sizeof(Ipp32f));
/* anti-sparseness post-processing */
ippsAdaptiveCodebookContribution_G729_32f(valCodebookGain, pSrcDstInnovation, pSrcExcSignal, pScaledLTP);
ippsCopy_32f(pSrcDstInnovation,pMemory,SUBFR_LEN);
ippsZero_32f(pSrcDstInnovation,SUBFR_LEN);
numNonZeroElem=0;
for (i=0; i<SUBFR_LEN; i++) {
if (pMemory[i]) /*Can't change to if(fabs(pMemory[i]) < IPP_MINABS_32F)*/
pPos[numNonZeroElem++] = i;
}
if (valPitchGain <= 0.6f) {
phDispState = 0;
} else if ( (valPitchGain > 0.6f) && (valPitchGain < 0.9f) ) {
phDispState = 1;
} else {
phDispState = 2;
}
for (i = 5; i > 0; i--) {
phdState->gainMem[i]=phdState->gainMem[i-1];
}
phdState->gainMem[0] = valPitchGain;
if (valCodebookGain > 2.0f * phdState->prevCbGain)
phdState->onset = 2;
else {
if (phdState->onset) phdState->onset -= 1;
}
i1=0;
for (i = 0; i < 6; i++) {
if (phdState->gainMem[i] < 0.6f) i1 += 1;
}
if (i1 > 2 && !phdState->onset) phDispState = 0;
if (phDispState - phdState->prevDispState > 1 && !phdState->onset) phDispState -= 1;
if (phdState->onset) {
if (phDispState < 2) phDispState++;
}
phdState->prevDispState=phDispState;
phdState->prevCbGain = valCodebookGain;
if (phDispState == 0) {
pTable = ImpLow;
} else if (phDispState == 1) {
pTable = ImpMiddle;
} else if (phDispState == 2) {
pTable = ImpHigh;
}
for (nPulse=0; nPulse<numNonZeroElem; nPulse++) {
lPos = pPos[nPulse];
for (i=lPos; i<SUBFR_LEN; i++)
pSrcDstInnovation[i] += pMemory[lPos] * pTable[i-lPos];
for (i=0; i < lPos; i++)
pSrcDstInnovation[i] += pMemory[lPos] * pTable[SUBFR_LEN-lPos+i];
}
ippsAdaptiveCodebookContribution_G729_32f(-valCodebookGain, pSrcDstInnovation, pScaledLTP, pDstFltExcSignal);
return;
}
static void GlobalStationnarityAdaptation_G729E(G729FPEncoder_Obj* encoderObj, Ipp32f valBackwardPredGain, Ipp32f valForwardPredGain, Ipp32s valLPCMode)
{
Ipp16s sTmp;
/* First adaptation based on previous backward / forward decisions */
if (valLPCMode == 1) { /* Backward stationnary mode */
(encoderObj->sBWDStatInd)++;
CLIP_TO_UPLEVEL(encoderObj->sBWDStatInd,21);
if(encoderObj->sValBWDStatInd < 32517) encoderObj->sValBWDStatInd += 250;
else encoderObj->sValBWDStatInd = 32767;
/* after 20 backward frames => increase stat */
if (encoderObj->sBWDStatInd == 20) {
if(encoderObj->sGlobalStatInd < 30267) encoderObj->sGlobalStatInd += 2500;
else encoderObj->sGlobalStatInd = 32767;
}
else if (encoderObj->sBWDStatInd > 20) encoderObj->sGlobalStatInd += 500;
}
else if ((valLPCMode == 0)&&(encoderObj->prevLPCMode == 1)) { /* Backward -> Forward transition */
/* Transition occurs after less than 20 backward frames => decrease stat */
if (encoderObj->sBWDStatInd < 20) {
sTmp = (Ipp16s)(5000 - encoderObj->sValBWDStatInd);
encoderObj->sGlobalStatInd = (Ipp16s)(encoderObj->sGlobalStatInd-sTmp);
}
/* Reset consecutive backward frames counter */
encoderObj->sBWDStatInd = 0;
encoderObj->sValBWDStatInd = 0;
}
/* Second adaptation based on prediction gains */
if (encoderObj->sGlobalStatInd < 13000) {
if (valBackwardPredGain > valForwardPredGain + TH4) encoderObj->sGlobalStatInd += 3200;
else if (valBackwardPredGain > valForwardPredGain + TH3) encoderObj->sGlobalStatInd += 2400;
else if (valBackwardPredGain > valForwardPredGain + TH2) encoderObj->sGlobalStatInd += 1600;
else if (valBackwardPredGain > valForwardPredGain + TH1) encoderObj->sGlobalStatInd += 800;
else if (valBackwardPredGain > valForwardPredGain) encoderObj->sGlobalStatInd += 400;
}
if (valBackwardPredGain < valForwardPredGain - TH5) encoderObj->sGlobalStatInd -= 6400;
else if (valBackwardPredGain < valForwardPredGain - TH4) encoderObj->sGlobalStatInd -= 3200;
else if (valBackwardPredGain < valForwardPredGain - TH3) encoderObj->sGlobalStatInd -= 1600;
else if (valBackwardPredGain < valForwardPredGain - TH2) encoderObj->sGlobalStatInd -= 800;
else if (valBackwardPredGain < valForwardPredGain - TH1) encoderObj->sGlobalStatInd -= 400;
CLIP_TO_UPLEVEL(encoderObj->sGlobalStatInd,32000);
CLIP_TO_LOWLEVEL(encoderObj->sGlobalStatInd,0);
return;
}
void SetLPCMode_G729FPE(G729FPEncoder_Obj* encoderObj, Ipp32f *pSrcSignal, Ipp32f *pSrcForwardLPCFilter,
Ipp32f *pSrcBackwardLPCFilter, Ipp32s *pDstLPCMode, Ipp32f *pSrcLSP,Ipp32f *pExtBuff)
{
Ipp32s i;
Ipp32f *pLPCFlt, *PPtr;
Ipp32f fGap, forwardPredGain, backwardPredGain, intBackwardPredGain;
Ipp32f LSPThreshold, LSPDist, fTmp;
Ipp32f ener_DB_pSrcSignal;
PPtr = &pExtBuff[0]; /*FRM_LEN elements*/
ener_DB_pSrcSignal = CalcEnergy_dB_G729(pSrcSignal, FRM_LEN);
pLPCFlt = pSrcBackwardLPCFilter + BWD_LPC_ORDERP1;
/* Calc backward filter prediction gain (without interpolation ) */
ippsConvBiased_32f(pLPCFlt,BWD_LPC_ORDER+1,pSrcSignal,FRM_LEN+BWD_LPC_ORDER,PPtr,FRM_LEN,BWD_LPC_ORDER);
backwardPredGain = ener_DB_pSrcSignal - CalcEnergy_dB_G729(PPtr, FRM_LEN);
/* Interpolated backward filter for the first sub-frame */
InterpolatedBackwardFilter_G729(pSrcBackwardLPCFilter, encoderObj->PrevFlt, &encoderObj->fInterpolationCoeff);
/* Calc interpolated backward filter prediction gain */
ippsConvBiased_32f(pSrcBackwardLPCFilter,BWD_LPC_ORDER+1,pSrcSignal,SUBFR_LEN+BWD_LPC_ORDER,PPtr,SUBFR_LEN,BWD_LPC_ORDER);
ippsConvBiased_32f(pLPCFlt,BWD_LPC_ORDER+1,&pSrcSignal[SUBFR_LEN],SUBFR_LEN+BWD_LPC_ORDER,&PPtr[SUBFR_LEN],SUBFR_LEN,BWD_LPC_ORDER);
intBackwardPredGain = ener_DB_pSrcSignal - CalcEnergy_dB_G729(PPtr, FRM_LEN);
/* Calc forward filter prediction gain */
ippsConvBiased_32f(pSrcForwardLPCFilter,LPC_ORDER+1,pSrcSignal,SUBFR_LEN+LPC_ORDER,PPtr,SUBFR_LEN,LPC_ORDER);
ippsConvBiased_32f(&pSrcForwardLPCFilter[LPC_ORDERP1],LPC_ORDER+1,&pSrcSignal[SUBFR_LEN],SUBFR_LEN+LPC_ORDER,&PPtr[SUBFR_LEN],SUBFR_LEN,LPC_ORDER);
forwardPredGain = ener_DB_pSrcSignal - CalcEnergy_dB_G729(PPtr, FRM_LEN);
/* Choose: backward/forward mode.*/
/* 1st criterion with prediction gains. The global stationarity index
is used to adapt the threshold value " GAP ".*/
/* Do the threshold adaptation according to the global stationarity indicator */
fGap = (Ipp32f)(encoderObj->sGlobalStatInd) * GAP_FACT;
fGap += 1.f;
if ( (intBackwardPredGain > forwardPredGain - fGap)&& (backwardPredGain > forwardPredGain - fGap)&&
(backwardPredGain > 0.f) && (intBackwardPredGain > 0.f) ) *pDstLPCMode = 1;
else *pDstLPCMode = 0;
if (encoderObj->sGlobalStatInd < 13000) *pDstLPCMode = 0; /* => Forward mode imposed */
/* 2nd criterion with a distance between 2 successive LSP vectors */
/* Computation of the LPC distance */
LSPDist = 0;
for(i=0; i<LPC_ORDER; i++){
fTmp = encoderObj->OldLSP[i] - pSrcLSP[i];
LSPDist += fTmp * fTmp;