-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathpostfilter.c
2497 lines (1883 loc) · 130 KB
/
postfilter.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
/*******************************************************************************
* ManyEars: PostFilter - Source Code *
* --------------------------------------------------------------------------- *
* *
* Author: François Grondin *
* Original Code: Jean-Marc Valin *
* Modified Code: Simon Brière *
* Version: 1.1.0 *
* Date: September 16th, 2010 *
* *
* Disclaimer: This software is provided "as is". Use it at your own risk. *
* *
*******************************************************************************
* *
* ManyEars has been created and developped at: *
* *
* IntroLab, Universite de Sherbrooke, Sherbrooke, Quebec, Canada *
* *
* --------------------------------------------------------------------------- *
* *
* The following articles relate to the ManyEars project: *
* *
* S. Brière, J.-M. Valin, F. Michaud, Dominic Létourneau, Embedded Auditory *
* System for Small Mobile Robots, Proc. International Conference on *
* Robotics and Automation (ICRA), 2008. *
* *
* J.-M. Valin, S. Yamamoto, J. Rouat, F. Michaud, K. Nakadai, H. G. Okuno, *
* Robust Recognition of Simultaneous Speech By a Mobile Robot, IEEE *
* Transactions on Robotics, Vol. 23, No. 4, pp. 742-752, 2007. *
* *
* J.-M. Valin, F. Michaud, J. Rouat, Robust Localization and Tracking of *
* Simultaneous Moving Sound Sources Using Beamforming and Particle *
* Filtering. Robotics and Autonomous Systems Journal (Elsevier), Vol. 55, *
* No. 3, pp. 216-228, 2007. *
* *
* S. Yamamoto, K. Nakadai, M. Nakano, H. Tsujino, J.-M. Valin, K. Komatani, *
* T. Ogata, H. G. Okuno, Simultaneous Speech Recognition based on *
* Automatic Missing-Feature Mask Generation integrated with Sound Source *
* Separation (in Japanese). Journal of Robotic Society of Japan, Vol. 25, *
* No. 1, 2007. *
* *
* J.-M. Valin, F. Michaud, J. Rouat, Robust 3D Localization and Tracking of *
* Sound Sources Using Beamforming and Particle Filtering. Proc. IEEE *
* International Conference on Acoustics, Speech and Signal Processing *
* (ICASSP), pp. 841-844, 2006. *
* *
* S. Briere, D. Letourneau, M. Frechette, J.-M. Valin, F. Michaud, Embedded *
* and integration audition for a mobile robot. Proceedings AAAI Fall *
* Symposium Workshop Aurally Informed Performance: Integrating Machine *
* Listening and Auditory Presentation in Robotic Systems, FS-06-01, 6-10, *
* 2006 *
* *
* S. Yamamoto, K. Nakadai, J.-M. Valin, J. Rouat, F. Michaud, K. Komatani, *
* T. Ogata, H. G. Okuno, Making a robot recognize three simultaneous *
* sentences in real-time. Proceedings of IEEE/RSJ International *
* Conference on Intelligent Robots and Systems (IROS), 2005. *
* *
* M. Murase, S. Yamamoto, J.-M. Valin, K. Nakadai, K. Yamada, K. Komatani, *
* T. Ogata, H. G. Okuno, Multiple Moving Speaker Tracking by Microphone *
* Array on Mobile Robot. Proc. European Conference on Speech *
* Communication and Technology (Interspeech), 2005. *
* *
* S. Yamamoto, J.-M. Valin, K. Nakadai, J. Rouat, F. Michaud, T. Ogata, H. *
* G. Okuno, Enhanced Robot Speech Recognition Based on Microphone Array *
* Source Separation and Missing Feature Theory. Proc. International *
* Conference on Robotics and Automation (ICRA), 2005. *
* *
* J.-M. Valin, J. Rouat, F. Michaud, Enhanced Robot Audition Based on *
* Microphone Array Source Separation with Post-Filter. Proc. IEEE/RSJ *
* International Conference on Intelligent Robots and Systems (IROS), *
* pp. 2123-2128, 2004. *
* *
* J.-M. Valin, F. Michaud, J. Rouat, D. Létourneau, Robust Sound Source *
* Localization Using a Microphone Array on a Mobile Robot. Proc. IEEE/RSJ *
* International Conference on Intelligent Robots and Systems (IROS), *
* pp. 1228-1233, 2003. *
* *
* J.-M. Valin, F. Michaud, B. Hadjou, J. Rouat, Localization of Simultaneous *
* Moving Sound Sources for Mobile Robot Using a Frequency-Domain Steered *
* Beamformer Approach. Proc. IEEE International Conference on Robotics *
* and Automation (ICRA), pp. 1033-1038, 2004. *
* *
* J.-M. Valin, J. Rouat, F. Michaud, Microphone Array Post-Filter for *
* Separation of Simultaneous Non-Stationary Sources. Proc. IEEE *
* International Conference on Acoustics, Speech and Signal Processing *
* (ICASSP), pp. 221-224, 2004. *
* *
******************************************************************************/
#include "Separation/postfilter.h"
/*******************************************************************************
* postfilterInit *
* --------------------------------------------------------------------------- *
* *
* Inputs: myPostfilter The postfilter object used to be initialized *
* myParameters The parameters used for initialization *
* *
* Outputs: myPostfilter The initialized postfilter object *
* *
* Description: This function initializes the postfilter object. *
* *
******************************************************************************/
void postfilterInit(struct objPostfilter* myPostfilter, struct ParametersStruct* myParameters)
{
unsigned int indexSource;
unsigned int k;
float* tmpArray;
// *************************************************************************
// * STEP 1: Load parameters *
// *************************************************************************
myPostfilter->POSTFILTER_ALPHAS = myParameters->P_POSTFILTER_ALPHAS;
myPostfilter->POSTFILTER_ETA = myParameters->P_POSTFILTER_ETA;
myPostfilter->POSTFILTER_GAMMA = myParameters->P_POSTFILTER_GAMMA;
myPostfilter->POSTFILTER_DELTA = myParameters->P_POSTFILTER_DELTA;
myPostfilter->POSTFILTER_NBSOURCES = myParameters->P_GEN_DYNSOURCES;
myPostfilter->POSTFILTER_NFRAMES = GLOBAL_FRAMESIZE;
myPostfilter->POSTFILTER_HALFNFRAMES = myPostfilter->POSTFILTER_NFRAMES / 2;
myPostfilter->POSTFILTER_HALFNFRAMESPLUSONE = myPostfilter->POSTFILTER_HALFNFRAMES + 1;
myPostfilter->POSTFILTER_TETA_LOCAL = myParameters->P_POSTFILTER_TETA_LOCAL;
myPostfilter->POSTFILTER_TETA_GLOBAL = myParameters->P_POSTFILTER_TETA_GLOBAL;
myPostfilter->POSTFILTER_TETA_FRAME = myParameters->P_POSTFILTER_TETA_FRAME;
myPostfilter->POSTFILTER_ALPHAZETA = myParameters->P_POSTFILTER_ALPHAZETA;
myPostfilter->POSTFILTER_MAXQ = myParameters->P_POSTFILTER_MAXQ;
myPostfilter->POSTFILTER_GMIN = myParameters->P_POSTFILTER_GMIN;
myPostfilter->POSTFILTER_LOCALWINDOWSIZE = myParameters->P_POSTFILTER_LOCALWINDOWSIZE;
myPostfilter->POSTFILTER_GLOBALWINDOWSIZE = myParameters->P_POSTFILTER_GLOBALWINDOWSIZE;
myPostfilter->POSTFILTER_FRAMEWINDOWSIZE = myPostfilter->POSTFILTER_NFRAMES;
myPostfilter->POSTFILTER_ALPHAPMIN = myParameters->P_POSTFILTER_ALPHAPMIN;
// *************************************************************************
// * STEP 2: Create arrays *
// *************************************************************************
// +-----------------------------------------------------------------------+
// | Step A: Create MCRA objects |
// +-----------------------------------------------------------------------+
myPostfilter->mcra = (struct objMcra*) newTable1D(myPostfilter->POSTFILTER_NBSOURCES, sizeof(struct objMcra));
// +-----------------------------------------------------------------------+
// | Step B: Create sources arrays |
// +-----------------------------------------------------------------------+
idListInit(&myPostfilter->sourcesIDNow, myPostfilter->POSTFILTER_NBSOURCES);
idListInit(&myPostfilter->sourcesIDAdded, myPostfilter->POSTFILTER_NBSOURCES);
idListInit(&myPostfilter->sourcesIDDeleted, myPostfilter->POSTFILTER_NBSOURCES);
myPostfilter->sourcesID = (ID_TYPE*) newTable1D(myPostfilter->POSTFILTER_NBSOURCES, sizeof(ID_TYPE));
// +-----------------------------------------------------------------------+
// | Step C: Create input and output arrays |
// +-----------------------------------------------------------------------+
myPostfilter->YReal = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->YImag = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->YPower = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->SReal = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->SImag = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->SPower = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +-----------------------------------------------------------------------+
// | Step D: Create noise arrays |
// +-----------------------------------------------------------------------+
// +-------------------------------------------------------------------+
// | Step i: Static noise |
// +-------------------------------------------------------------------+
myPostfilter->lambdaStat = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +-------------------------------------------------------------------+
// | Step ii: Leakage noise |
// +-------------------------------------------------------------------+
myPostfilter->Z = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->lambdaLeak = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +-------------------------------------------------------------------+
// | Step iii: Reverberation noise |
// +-------------------------------------------------------------------+
myPostfilter->lambdaRev = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +-------------------------------------------------------------------+
// | Step iv: Total noise |
// +-------------------------------------------------------------------+
myPostfilter->lambda = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +-----------------------------------------------------------------------+
// | Step E: Create speech presence arrays |
// +-----------------------------------------------------------------------+
myPostfilter->gamma = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->xi = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->alphaP = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->v = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
myPostfilter->GH1 = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +-----------------------------------------------------------------------+
// | Step F: Create speech presence gain arrays |
// +-----------------------------------------------------------------------+
// +-------------------------------------------------------------------+
// | Step i: Result after windowing |
// +-------------------------------------------------------------------+
// +---------------------------------------------------------------+
// | Step a: Local window |
// +---------------------------------------------------------------+
myPostfilter->localResultCropped = (float*) newTable1D(myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +---------------------------------------------------------------+
// | Step b: Global window |
// +---------------------------------------------------------------+
myPostfilter->globalResultCropped = (float*) newTable1D(myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +---------------------------------------------------------------+
// | Step c: Frame window |
// +---------------------------------------------------------------+
myPostfilter->frameResultCropped = (float*) newTable1D(myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +-------------------------------------------------------------------+
// | Step ii: A priori SNR |
// +-------------------------------------------------------------------+
// +---------------------------------------------------------------+
// | Step a: Local window |
// +---------------------------------------------------------------+
myPostfilter->localZeta = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +---------------------------------------------------------------+
// | Step b: Global window |
// +---------------------------------------------------------------+
myPostfilter->globalZeta = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +---------------------------------------------------------------+
// | Step c: Frame window |
// +---------------------------------------------------------------+
myPostfilter->frameZeta = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +-------------------------------------------------------------------+
// | Step iii: Speech presence probabilities |
// +-------------------------------------------------------------------+
// +---------------------------------------------------------------+
// | Step a: Local window |
// +---------------------------------------------------------------+
myPostfilter->localP = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +---------------------------------------------------------------+
// | Step b: Global window |
// +---------------------------------------------------------------+
myPostfilter->globalP = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +---------------------------------------------------------------+
// | Step c: Frame window |
// +---------------------------------------------------------------+
myPostfilter->frameP = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +---------------------------------------------------------------+
// | Step d: A priori probability of speech presence |
// +---------------------------------------------------------------+
myPostfilter->p = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +---------------------------------------------------------------+
// | Step e: Probability of speech presence |
// +---------------------------------------------------------------+
myPostfilter->q = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// +-------------------------------------------------------------------+
// | Step iv: Gain |
// +-------------------------------------------------------------------+
// Gain
myPostfilter->G = (float**) newTable2D(myPostfilter->POSTFILTER_NBSOURCES, myPostfilter->POSTFILTER_NFRAMES, sizeof(float));
// *************************************************************************
// * STEP 3: Initialize values *
// *************************************************************************
// +-----------------------------------------------------------------------+
// | Step A: Initialize sources |
// +-----------------------------------------------------------------------+
for (indexSource = 0; indexSource < myPostfilter->POSTFILTER_NBSOURCES; indexSource++)
{
myPostfilter->sourcesID[indexSource] = ID_NOSOURCE;
}
idListInit(&myPostfilter->sourcesIDNow, myPostfilter->POSTFILTER_NBSOURCES);
idListInit(&myPostfilter->sourcesIDAdded, myPostfilter->POSTFILTER_NBSOURCES);
idListInit(&myPostfilter->sourcesIDDeleted, myPostfilter->POSTFILTER_NBSOURCES);
// +-----------------------------------------------------------------------+
// | Step B: Initialize MCRA objects |
// +-----------------------------------------------------------------------+
for (indexSource = 0; indexSource < myPostfilter->POSTFILTER_NBSOURCES; indexSource++)
{
mcraInit(&myPostfilter->mcra[indexSource], myParameters, myPostfilter->POSTFILTER_NFRAMES);
}
// +-----------------------------------------------------------------------+
// | Step C: Initialize transcendental objects |
// +-----------------------------------------------------------------------+
transcendentalInit(&myPostfilter->transcendental);
// +-----------------------------------------------------------------------+
// | Step D: Initialize windows |
// +-----------------------------------------------------------------------+
// +-------------------------------------------------------------------+
// | Step i: Local window |
// +-------------------------------------------------------------------+
linearCorrelationInit(&myPostfilter->localWindow, myPostfilter->POSTFILTER_LOCALWINDOWSIZE, myPostfilter->POSTFILTER_NFRAMES);
tmpArray = (float*) newTable1D(myPostfilter->POSTFILTER_LOCALWINDOWSIZE, sizeof(float));
generateHanningWindow(tmpArray, myPostfilter->POSTFILTER_LOCALWINDOWSIZE);
linearCorrelationLoadVectorA(&myPostfilter->localWindow, tmpArray);
deleteTable1D((void*) tmpArray);
// +-------------------------------------------------------------------+
// | Step ii: Global window |
// +-------------------------------------------------------------------+
linearCorrelationInit(&myPostfilter->globalWindow, myPostfilter->POSTFILTER_GLOBALWINDOWSIZE, myPostfilter->POSTFILTER_NFRAMES);
tmpArray = (float*) newTable1D(myPostfilter->POSTFILTER_GLOBALWINDOWSIZE, sizeof(float));
generateHanningWindow(tmpArray, myPostfilter->POSTFILTER_GLOBALWINDOWSIZE);
linearCorrelationLoadVectorA(&myPostfilter->globalWindow, tmpArray);
deleteTable1D((void*) tmpArray);
// +-------------------------------------------------------------------+
// | Step iii: Frame window |
// +-------------------------------------------------------------------+
linearCorrelationInit(&myPostfilter->frameWindow, myPostfilter->POSTFILTER_FRAMEWINDOWSIZE, myPostfilter->POSTFILTER_NFRAMES);
tmpArray = (float*) newTable1D(myPostfilter->POSTFILTER_FRAMEWINDOWSIZE, sizeof(float));
generateHanningWindow(tmpArray, myPostfilter->POSTFILTER_FRAMEWINDOWSIZE);
linearCorrelationLoadVectorA(&myPostfilter->frameWindow, tmpArray);
deleteTable1D((void*) tmpArray);
// +-----------------------------------------------------------------------+
// | Step E: Set all other arrays to zero |
// +-----------------------------------------------------------------------+
for (indexSource = 0; indexSource < myPostfilter->POSTFILTER_NBSOURCES; indexSource++)
{
for (k = 0; k < myPostfilter->POSTFILTER_NFRAMES; k++)
{
myPostfilter->YReal[indexSource][k] = 0.0f;
myPostfilter->YImag[indexSource][k] = 0.0f;
myPostfilter->YPower[indexSource][k] = 0.0f;
myPostfilter->SReal[indexSource][k] = 0.0f;
myPostfilter->SImag[indexSource][k] = 0.0f;
myPostfilter->SPower[indexSource][k] = 0.0f;
myPostfilter->lambdaStat[indexSource][k] = 0.0f;
myPostfilter->Z[indexSource][k] = 0.0f;
myPostfilter->lambdaLeak[indexSource][k] = 0.0f;
myPostfilter->lambdaRev[indexSource][k] = 0.0f;
myPostfilter->lambda[indexSource][k] = 0.0f;
myPostfilter->gamma[indexSource][k] = 0.0f;
myPostfilter->xi[indexSource][k] = 0.0f;
myPostfilter->alphaP[indexSource][k] = 0.0f;
myPostfilter->v[indexSource][k] = 0.0f;
myPostfilter->GH1[indexSource][k] = 0.0f;
myPostfilter->localZeta[indexSource][k] = 0.0f;
myPostfilter->globalZeta[indexSource][k] = 0.0f;
myPostfilter->frameZeta[indexSource][k] = 0.0f;
myPostfilter->localP[indexSource][k] = 0.0f;
myPostfilter->globalP[indexSource][k] = 0.0f;
myPostfilter->frameP[indexSource][k] = 0.0f;
myPostfilter->p[indexSource][k] = 0.0f;
myPostfilter->q[indexSource][k] = 0.0f;
myPostfilter->G[indexSource][k] = 0.0f;
}
}
for (k = 0; k < myPostfilter->POSTFILTER_NBSOURCES; k++)
{
myPostfilter->localResultCropped[k] = 0.0f;
myPostfilter->globalResultCropped[k] = 0.0f;
myPostfilter->frameResultCropped[k] = 0.0f;
}
}
/*******************************************************************************
* postfilterTerminate *
* --------------------------------------------------------------------------- *
* *
* Inputs: myPostfilter The postfilter object used to be terminated *
* *
* Outputs: (none) *
* *
* Description: This function terminates the postfilter object. *
* *
******************************************************************************/
void postfilterTerminate(struct objPostfilter* myPostfilter)
{
unsigned int indexSource;
// *************************************************************************
// * STEP 1: Free memory *
// *************************************************************************
// +-----------------------------------------------------------------------+
// | Step A: Terminate MCRA objects |
// +-----------------------------------------------------------------------+
for (indexSource = 0; indexSource < myPostfilter->POSTFILTER_NBSOURCES; indexSource++)
{
mcraTerminate(&myPostfilter->mcra[indexSource]);
}
deleteTable1D((void*) myPostfilter->mcra);
// +-----------------------------------------------------------------------+
// | Step B: Delete sources arrays |
// +-----------------------------------------------------------------------+
idListTerminate(&myPostfilter->sourcesIDNow);
idListTerminate(&myPostfilter->sourcesIDAdded);
idListTerminate(&myPostfilter->sourcesIDDeleted);
deleteTable1D((void*) myPostfilter->sourcesID);
// +-----------------------------------------------------------------------+
// | Step C: Delete input and output arrays |
// +-----------------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->YReal);
deleteTable2D((void**) myPostfilter->YImag);
deleteTable2D((void**) myPostfilter->YPower);
deleteTable2D((void**) myPostfilter->SReal);
deleteTable2D((void**) myPostfilter->SImag);
deleteTable2D((void**) myPostfilter->SPower);
// +-----------------------------------------------------------------------+
// | Step D: Delete noise arrays |
// +-----------------------------------------------------------------------+
// +-------------------------------------------------------------------+
// | Step i: Static noise |
// +-------------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->lambdaStat);
// +-------------------------------------------------------------------+
// | Step ii: Leakage noise |
// +-------------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->Z);
deleteTable2D((void**) myPostfilter->lambdaLeak);
// +-------------------------------------------------------------------+
// | Step iii: Reverberation noise |
// +-------------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->lambdaRev);
// +-------------------------------------------------------------------+
// | Step iv: Total noise |
// +-------------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->lambda);
// +-----------------------------------------------------------------------+
// | Step E: Terminate transcendental object |
// +-----------------------------------------------------------------------+
transcendentalTerminate(&myPostfilter->transcendental);
// +-----------------------------------------------------------------------+
// | Step F: Delete speech presence arrays |
// +-----------------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->gamma);
deleteTable2D((void**) myPostfilter->xi);
deleteTable2D((void**) myPostfilter->alphaP);
deleteTable2D((void**) myPostfilter->v);
deleteTable2D((void**) myPostfilter->GH1);
// +-----------------------------------------------------------------------+
// | Step G: Delete speech presence gain arrays |
// +-----------------------------------------------------------------------+
// +-------------------------------------------------------------------+
// | Step i: Terminate windows |
// +-------------------------------------------------------------------+
// +---------------------------------------------------------------+
// | Step a: Local window |
// +---------------------------------------------------------------+
linearCorrelationTerminate(&myPostfilter->localWindow);
// +---------------------------------------------------------------+
// | Step b: Global window |
// +---------------------------------------------------------------+
linearCorrelationTerminate(&myPostfilter->globalWindow);
// +---------------------------------------------------------------+
// | Step c: Frame window |
// +---------------------------------------------------------------+
linearCorrelationTerminate(&myPostfilter->frameWindow);
// +-------------------------------------------------------------------+
// | Step ii: Result after windowing |
// +-------------------------------------------------------------------+
// +---------------------------------------------------------------+
// | Step a: Local window |
// +---------------------------------------------------------------+
deleteTable1D((void*) myPostfilter->localResultCropped);
// +---------------------------------------------------------------+
// | Step b: Global window |
// +---------------------------------------------------------------+
deleteTable1D((void*) myPostfilter->globalResultCropped);
// +---------------------------------------------------------------+
// | Step c: Frame window |
// +---------------------------------------------------------------+
deleteTable1D((void*) myPostfilter->frameResultCropped);
// +-------------------------------------------------------------------+
// | Step iii: A priori SNR |
// +-------------------------------------------------------------------+
// +---------------------------------------------------------------+
// | Step a: Local window |
// +---------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->localZeta);
// +---------------------------------------------------------------+
// | Step b: Global window |
// +---------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->globalZeta);
// +---------------------------------------------------------------+
// | Step c: Frame window |
// +---------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->frameZeta);
// +-------------------------------------------------------------------+
// | Step iv: Speech presence probabilities |
// +-------------------------------------------------------------------+
// +---------------------------------------------------------------+
// | Step a: Local window |
// +---------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->localP);
// +---------------------------------------------------------------+
// | Step b: Global window |
// +---------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->globalP);
// +---------------------------------------------------------------+
// | Step c: Frame window |
// +---------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->frameP);
// +---------------------------------------------------------------+
// | Step d: A priori probability of speech presence |
// +---------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->p);
// +---------------------------------------------------------------+
// | Step e: Probability of speech presence |
// +---------------------------------------------------------------+
deleteTable2D((void**) myPostfilter->q);
// +-----------------------------------------------------------+
// | Step v: Gain |
// +-----------------------------------------------------------+
// Gain
deleteTable2D((void**) myPostfilter->G);
}
/*******************************************************************************
* postfilterAddSource *
* --------------------------------------------------------------------------- *
* *
* Inputs: myPostfilter The postfilter object in which the source is added *
* myPreprocessor The preprocessor object used to init the source *
* newID The ID of the new source *
* *
* Outputs: myPostfilter The updated postfilter object *
* *
* Description: This function adds a source to the postfilter object. *
* *
******************************************************************************/
void postfilterAddSource(struct objPostfilter* myPostfilter, struct objPreprocessor* myPreprocessor, ID_TYPE newID)
{
unsigned int indexID;
unsigned int k;
// Add ID to list
idListAdd(&myPostfilter->sourcesIDNow, newID);
// Find a free spot
for (indexID = 0; indexID < myPostfilter->POSTFILTER_NBSOURCES; indexID++)
{
if (myPostfilter->sourcesID[indexID] == ID_NOSOURCE)
{
// Copy the ID
myPostfilter->sourcesID[indexID] = newID;
// Copy the static noise (which needs to be initiated from
// the static noise of the microphones)
mcraClone(&myPostfilter->mcra[indexID],myPreprocessor->micArray[0]->noiseEstimator);
// Reset the arrays at this spot
for (k = 0; k < myPostfilter->POSTFILTER_NFRAMES; k++)
{
myPostfilter->YReal[indexID][k] = 0.0f;
myPostfilter->YImag[indexID][k] = 0.0f;
myPostfilter->YPower[indexID][k] = 0.0f;
myPostfilter->SReal[indexID][k] = 0.0f;
myPostfilter->SImag[indexID][k] = 0.0f;
myPostfilter->SPower[indexID][k] = 0.0f;
myPostfilter->lambdaStat[indexID][k] = 0.0f;
myPostfilter->Z[indexID][k] = 0.0f;
myPostfilter->lambdaLeak[indexID][k] = 0.0f;
myPostfilter->lambdaRev[indexID][k] = 0.0f;
myPostfilter->lambda[indexID][k] = 0.0f;
myPostfilter->gamma[indexID][k] = 0.0f;
myPostfilter->xi[indexID][k] = 0.0f;
myPostfilter->alphaP[indexID][k] = 0.0f;
myPostfilter->v[indexID][k] = 0.0f;
myPostfilter->GH1[indexID][k] = 0.0f;
myPostfilter->localZeta[indexID][k] = 0.0f;
myPostfilter->globalZeta[indexID][k] = 0.0f;
myPostfilter->frameZeta[indexID][k] = 0.0f;
myPostfilter->localP[indexID][k] = 0.0f;
myPostfilter->globalP[indexID][k] = 0.0f;
myPostfilter->frameP[indexID][k] = 0.0f;
myPostfilter->p[indexID][k] = 0.0f;
myPostfilter->q[indexID][k] = 0.0f;
myPostfilter->G[indexID][k] = 0.0f;
}
break;
}
}
}
/*******************************************************************************
* postfilterDeleteSource *
* --------------------------------------------------------------------------- *
* *
* Inputs: myPostfilter The postfilter object to delete a source *
* deleteID The ID of the source to be deleted *
* *
* Outputs: myPostfilter The updated postfilter object *
* *
* Description: This function deletes a source from the postfilter object. *
* *
******************************************************************************/
void postfilterDeleteSource(struct objPostfilter* myPostfilter, ID_TYPE deleteID)
{
unsigned int indexID;
// Delete ID from list
idListDelete(&myPostfilter->sourcesIDNow, deleteID);
// Free the associated spot
for (indexID = 0; indexID < myPostfilter->POSTFILTER_NBSOURCES; indexID++)
{
if (myPostfilter->sourcesID[indexID] == deleteID)
{
// Free the spot
myPostfilter->sourcesID[indexID] = ID_NOSOURCE;
break;
}
}
}
/*******************************************************************************
* postfilterRefreshSources *
* --------------------------------------------------------------------------- *
* *
* Inputs: myPostfilter The postfilter object used *
* mySeparatedSources *
* The separated sources object used *
* myPreprocessor The preprocessor object used *
* *
* Outputs: myPostfilter The updated postfilter object *
* *
* Description: This function updates the sources in the postfilter object. *
* *
******************************************************************************/
void postfilterRefreshSources(struct objPostfilter* myPostfilter, struct objSeparatedSources* mySeparatedSources, struct objPreprocessor* myPreprocessor)
{
unsigned int indexSource;
unsigned int k;
unsigned int indexID;
ID_TYPE currentID;
#ifdef USE_SIMD
// SIMD registers
__m128_mod regA, regB, regC, regD, regE;
#endif
// *************************************************************************
// * STEP 1: Find sources to be deleted and added *
// *************************************************************************
idListCompare(&myPostfilter->sourcesIDNow, &mySeparatedSources->sourcesID, &myPostfilter->sourcesIDAdded, &myPostfilter->sourcesIDDeleted);
// *************************************************************************
// * STEP 2: Delete sources *
// *************************************************************************
for (indexSource = 0; indexSource < idListGetNElements(&myPostfilter->sourcesIDDeleted); indexSource++)
{
currentID = idListGetID(&myPostfilter->sourcesIDDeleted, indexSource);
postfilterDeleteSource(myPostfilter, currentID);
}
// *************************************************************************
// * STEP 3: Add sources *
// *************************************************************************
for (indexSource = 0; indexSource < idListGetNElements(&myPostfilter->sourcesIDAdded); indexSource++)
{
currentID = idListGetID(&myPostfilter->sourcesIDAdded, indexSource);
postfilterAddSource(myPostfilter, myPreprocessor, currentID);
}
// *************************************************************************
// * STEP 1: Load separated sources *
// *************************************************************************
// Load frames
for (indexID = 0; indexID < idListGetNElements(&mySeparatedSources->sourcesID); indexID++)
{
currentID = idListGetID(&mySeparatedSources->sourcesID, indexID);
for (indexSource = 0; indexSource < myPostfilter->POSTFILTER_NBSOURCES; indexSource++)
{
if (myPostfilter->sourcesID[indexSource] == currentID)
{
#ifndef USE_SIMD
for (k = 0; k < myPostfilter->POSTFILTER_NFRAMES; k++)
{
myPostfilter->YReal[indexSource][k] = mySeparatedSources->sourcesFramesReal[indexID][k];
myPostfilter->YImag[indexSource][k] = mySeparatedSources->sourcesFramesImag[indexID][k];
myPostfilter->YPower[indexSource][k] = myPostfilter->YReal[indexSource][k] * myPostfilter->YReal[indexSource][k] +
myPostfilter->YImag[indexSource][k] * myPostfilter->YImag[indexSource][k];
}
#else
for (k = 0; k < myPostfilter->POSTFILTER_NFRAMES; k+=4)
{
regA.m128 = _mm_load_ps(&mySeparatedSources->sourcesFramesReal[indexID][k]);
regB.m128 = _mm_load_ps(&mySeparatedSources->sourcesFramesImag[indexID][k]);
regC.m128 = _mm_mul_ps(regA.m128,regA.m128);
regD.m128 = _mm_mul_ps(regB.m128,regB.m128);
regE.m128 = _mm_add_ps(regC.m128,regD.m128);
_mm_store_ps(&myPostfilter->YReal[indexSource][k], regA.m128);
_mm_store_ps(&myPostfilter->YImag[indexSource][k], regB.m128);
_mm_store_ps(&myPostfilter->YPower[indexSource][k], regE.m128);
}
for (k = k - 4; k < myPostfilter->POSTFILTER_NFRAMES; k++)
{
myPostfilter->YReal[indexSource][k] = mySeparatedSources->sourcesFramesReal[indexID][k];
myPostfilter->YImag[indexSource][k] = mySeparatedSources->sourcesFramesImag[indexID][k];
myPostfilter->YPower[indexSource][k] = myPostfilter->YReal[indexSource][k] * myPostfilter->YReal[indexSource][k] +
myPostfilter->YImag[indexSource][k] * myPostfilter->YImag[indexSource][k];
}
#endif
}
}
}
}
/*******************************************************************************
* postfilterProcess *
* --------------------------------------------------------------------------- *
* *
* Inputs: myPostfilter The postfilter object used *
* mySeparatedSources *
* The separated sources object used *
* myPreprocessor The preprocessor object used *
* *
* Outputs: myPostfilter The updated postfilter object *
* myPostfilteredSources *
* The postfiltered sources *
* *
* Description: This function uses the separated sources to produce frames for *
* the postfiltered sources. *
* *
******************************************************************************/
void postfilterProcess(struct objPostfilter* myPostfilter, struct objSeparatedSources* mySeparatedSources, struct objPreprocessor* myPreprocessor, struct objPostfilteredSources* myPostfilteredSources)
{
int indexID;
unsigned int indexSource;
unsigned int indexSource2;
unsigned int k;
float tmp;
#ifdef USE_SIMD
// SIMD registers
__m128_mod regA, regB, regC, regD, regE, regF, regG, regH;
#endif
// *************************************************************************
// * STEP 1: Load separated sources *
// *************************************************************************
postfilterRefreshSources(myPostfilter, mySeparatedSources, myPreprocessor);
// *************************************************************************
// * STEP 2: Noise updates *
// *************************************************************************
// +-----------------------------------------------------------------------+
// | Step A: Static noise |
// +-----------------------------------------------------------------------+
for (indexSource = 0; indexSource < myPostfilter->POSTFILTER_NBSOURCES; indexSource++)
{
if (myPostfilter->sourcesID[indexSource] != ID_NOSOURCE)
{
// Update the MCRA objects
mcraProcessFrame(&myPostfilter->mcra[indexSource], myPostfilter->YPower[indexSource], myPostfilter->lambdaStat[indexSource]);
}
}
// +-----------------------------------------------------------------------+
// | Step B: Leakage noise |
// +-----------------------------------------------------------------------+
// +-------------------------------------------------------------------+
// | Step i: Compute Z |
// +-------------------------------------------------------------------+
for (indexSource = 0; indexSource < myPostfilter->POSTFILTER_NBSOURCES; indexSource++)
{
if (myPostfilter->sourcesID[indexSource] != ID_NOSOURCE)
{
#ifndef USE_SIMD
for (k = 0; k < myPostfilter->POSTFILTER_NFRAMES; k++)
{
// Update Z: Z_m(k,l) = alphaS * Z_m,(k,l-1) + (1 - alphaS) * |Y_m(k,l)|^2
myPostfilter->Z[indexSource][k] = myPostfilter->POSTFILTER_ALPHAS * myPostfilter->Z[indexSource][k] +
(1.0f - myPostfilter->POSTFILTER_ALPHAS) * myPostfilter->YPower[indexSource][k];
}
#else
// Load the constant alphaS
regA.m128_f32[0] = myPostfilter->POSTFILTER_ALPHAS;
regA.m128_f32[1] = myPostfilter->POSTFILTER_ALPHAS;
regA.m128_f32[2] = myPostfilter->POSTFILTER_ALPHAS;
regA.m128_f32[3] = myPostfilter->POSTFILTER_ALPHAS;
// Load the constant (1 - alphaS)
regB.m128_f32[0] = 1 - myPostfilter->POSTFILTER_ALPHAS;
regB.m128_f32[1] = 1 - myPostfilter->POSTFILTER_ALPHAS;
regB.m128_f32[2] = 1 - myPostfilter->POSTFILTER_ALPHAS;
regB.m128_f32[3] = 1 - myPostfilter->POSTFILTER_ALPHAS;
for (k = 0; k < myPostfilter->POSTFILTER_HALFNFRAMES; k+=4)
{
// Update Z: Z_m(k,l) = alphaS * Z_m,(k,l-1) + (1 - alphaS) * |Y_m(k,l)|^2
regC.m128 = _mm_load_ps(&myPostfilter->Z[indexSource][k]);
regD.m128 = _mm_load_ps(&myPostfilter->YPower[indexSource][k]);
regE.m128 = _mm_mul_ps(regA.m128, regC.m128);
regF.m128 = _mm_mul_ps(regB.m128, regD.m128);
regG.m128 = _mm_add_ps(regE.m128, regF.m128);
_mm_store_ps(&myPostfilter->Z[indexSource][k], regG.m128);
}
// Update Z: Z_m(k,l) = alphaS * Z_m,(k,l-1) + (1 - alphaS) * |Y_m(k,l)|^2
myPostfilter->Z[indexSource][myPostfilter->POSTFILTER_HALFNFRAMES] = myPostfilter->POSTFILTER_ALPHAS * myPostfilter->Z[indexSource][myPostfilter->POSTFILTER_HALFNFRAMES] +
(1 - myPostfilter->POSTFILTER_ALPHAS) * myPostfilter->YPower[indexSource][myPostfilter->POSTFILTER_HALFNFRAMES];
#endif
}
}
// +-------------------------------------------------------------------+
// | Step ii: Compute lambda_leak |
// +-------------------------------------------------------------------+
for (indexSource = 0; indexSource < myPostfilter->POSTFILTER_NBSOURCES; indexSource++)
{
if (myPostfilter->sourcesID[indexSource] != ID_NOSOURCE)
{
#ifdef USE_SIMD
// Load the constant eta
regA.m128_f32[0] = myPostfilter->POSTFILTER_ETA;
regA.m128_f32[1] = myPostfilter->POSTFILTER_ETA;
regA.m128_f32[2] = myPostfilter->POSTFILTER_ETA;
regA.m128_f32[3] = myPostfilter->POSTFILTER_ETA;
#endif
#ifndef USE_SIMD
// Set lambda_leak to 0 everywhere
for (k = 0; k < myPostfilter->POSTFILTER_NFRAMES; k++)
{
myPostfilter->lambdaLeak[indexSource][k] = 0.0f;
}
#else