Changeset 60 for mppenc/branches/r2d/libmpcpsy/psy.c
- Timestamp:
- 09/28/06 18:15:21 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mppenc/branches/r2d/libmpcpsy/psy.c
r59 r60 51 51 */ 52 52 53 #include "mppenc.h" 53 #include <string.h> 54 #include <stdio.h> 55 #include <math.h> 56 57 #include "libmpcpsy.h" 58 #include "fastmath.h" 59 60 61 // Antialiasing for calculation of the subband power 62 const float Butfly [7] = { 0.5f, 0.2776f, 0.1176f, 0.0361f, 0.0075f, 0.000948f, 0.0000598f }; 63 64 // Antialiasing for calculation of the masking thresholds 65 const float InvButfly [7] = { 2.f, 3.6023f, 8.5034f, 27.701f, 133.33f, 1054.852f, 16722.408f }; 54 66 55 67 /* V A R I A B L E S */ 56 /* further switches for the psymodel */ 57 unsigned int CVD_used; // global flag for ClearVoiceDetection 58 float varLtq; // variable threshold in quiet 59 unsigned int tmpMask_used; // global flag for temporal masking 60 float ShortThr; // Factor to calculate the masking threshold with transients 61 float minSMR; // minimum SMR for all subbands 62 63 float a [PART_LONG]; 64 float b [PART_LONG]; 65 float c [PART_LONG]; 66 float d [PART_LONG]; // Integrations for tmpMask 68 67 69 static float Xsave_L [3 * 512]; 68 70 static float Xsave_R [3 * 512]; // FFT-Amplitudes L/R 69 71 static float Ysave_L [3 * 512]; 70 72 static float Ysave_R [3 * 512]; // FFT-Phases L/R 71 float T_L [PART_LONG];72 float T_R [PART_LONG]; // time-constants for tmpMask73 float pre_erg_L[2][PART_SHORT];74 float pre_erg_R[2][PART_SHORT]; // Preecho-control short75 float PreThr_L [PART_LONG];76 float PreThr_R [PART_LONG]; // for Pre-Echo-control L/R77 float tmp_Mask_L [PART_LONG];78 float tmp_Mask_R [PART_LONG]; // for Post-Masking L/R79 int Vocal_L [MAX_CVD_LINE + 4];80 int Vocal_R [MAX_CVD_LINE + 4]; // FFT-Line belongs to harmonic?81 73 82 74 /* F U N C T I O N S */ 75 76 // fft_routines.c 77 void Init_FFT ( void ); 78 void PowSpec256 ( const float*, float* ); 79 void PowSpec1024 ( const float*, float* ); 80 void PowSpec2048 ( const float*, float* ); 81 void PolarSpec1024 ( const float*, float*, float* ); 82 void Cepstrum2048 ( float* cep, const int ); 83 83 84 // Resets Arrays 84 void 85 Init_Psychoakustik ( void ) 85 void Init_Psychoakustik ( PsyModel* m) 86 86 { 87 87 int i; 88 88 89 ENTER(200);90 89 // generate FFT lookup-tables with largest FFT-size of 1024 91 90 Init_FFT (); … … 93 92 // setting pre-echo variables to Ltq 94 93 for ( i = 0; i < PART_LONG; i++ ) { 95 pre_erg_L [0][i/3] =pre_erg_R [0][i/3] =96 pre_erg_L [1][i/3] =pre_erg_R [1][i/3] =97 tmp_Mask_L [i] =tmp_Mask_R [i] =98 PreThr_L [i] = PreThr_R [i] =partLtq [i];94 m->pre_erg_L [0][i/3] = m->pre_erg_R [0][i/3] = 95 m->pre_erg_L [1][i/3] = m->pre_erg_R [1][i/3] = 96 m->tmp_Mask_L [i] = m->tmp_Mask_R [i] = 97 m->PreThr_L [i] = m->PreThr_R [i] = m->partLtq [i]; 99 98 } 100 99 101 100 // initializing arrays with zero 102 memset ( Xsave_L, 0, sizeof Xsave_L ); 103 memset ( Xsave_R, 0, sizeof Xsave_R ); 104 memset ( Ysave_L, 0, sizeof Ysave_L ); 105 memset ( Ysave_R, 0, sizeof Ysave_R ); 106 memset ( a, 0, sizeof a ); 107 memset ( b, 0, sizeof b ); 108 memset ( c, 0, sizeof c ); 109 memset ( d, 0, sizeof d ); 110 memset ( T_L, 0, sizeof T_L ); 111 memset ( T_R, 0, sizeof T_R ); 112 memset ( Vocal_L, 0, sizeof Vocal_L ); 113 memset ( Vocal_R, 0, sizeof Vocal_R ); 114 115 LEAVE(200); 101 memset ( Xsave_L, 0, sizeof Xsave_L ); 102 memset ( Xsave_R, 0, sizeof Xsave_R ); 103 memset ( Ysave_L, 0, sizeof Ysave_L ); 104 memset ( Ysave_R, 0, sizeof Ysave_R ); 105 memset ( m->a, 0, sizeof m->a ); 106 memset ( m->b, 0, sizeof m->b ); 107 memset ( m->c, 0, sizeof m->c ); 108 memset ( m->d, 0, sizeof m->d ); 109 memset ( m->T_L, 0, sizeof m->T_L ); 110 memset ( m->T_R, 0, sizeof m->T_R ); 111 memset ( m->Vocal_L, 0, sizeof m->Vocal_L ); 112 memset ( m->Vocal_R, 0, sizeof m->Vocal_R ); 113 114 m->SampleFreq = 0.; 115 m->Bandwidth = 0.; 116 116 117 return; 117 118 } … … 134 135 135 136 136 void 137 RaiseSMR ( const int MaxBand, SMRTyp* smr ) 138 { 139 float tmp = POW10 ( 0.1 * minSMR ); 140 141 ENTER(201); 137 void RaiseSMR (PsyModel* m, const int MaxBand, SMRTyp* smr ) 138 { 139 float tmp = POW10 ( 0.1 * m->minSMR ); 140 142 141 RaiseSMR_Signal ( MaxBand, smr->L, tmp ); 143 142 RaiseSMR_Signal ( MaxBand, smr->R, tmp ); … … 145 144 RaiseSMR_Signal ( MaxBand, smr->S, 0.5 * tmp ); 146 145 147 LEAVE(201);148 146 return; 149 147 } … … 166 164 float* r; 167 165 168 ENTER(202);169 166 170 167 for ( Band = 0; Band <= MaxBand; Band++ ) { // calculate perceptual entropy … … 197 194 } 198 195 199 LEAVE(202);200 196 return; 201 197 } … … 203 199 // input : FFT-spectrums *spec0 und *spec1 204 200 // output: energy in the individual subbands *erg0 and *erg1 205 // With Butfly[], you can calculate the results of aliasing during calculation 201 // With Butfly[], you can calculate the results of aliasing during calculation 206 202 // of subband energy from the FFT-spectrums. 207 203 static void … … 218 214 float tmp1; 219 215 220 ENTER(203);221 216 222 217 // Is this here correct for FFT-based data or is this calculation rule only for MDCTs??? … … 244 239 } 245 240 246 LEAVE(203);247 241 return; 248 242 } … … 261 255 float e1; 262 256 263 ENTER(204);264 257 265 258 #if 000000 … … 314 307 } 315 308 316 317 309 #endif 318 310 319 LEAVE(204);320 311 return; 321 312 } … … 337 328 float e1; 338 329 339 ENTER(205);340 330 341 331 #if 000000 … … 391 381 #endif 392 382 393 LEAVE(205);394 383 return; 395 384 } … … 413 402 float tmp1; 414 403 415 ENTER(206);416 404 417 405 // should be able to optimize it with coasting. [ 9 ] + n * [ 7 + 7 + 2 ] + [ 7 ] … … 440 428 } 441 429 442 LEAVE(206); 443 return; 444 } 445 446 #include "fastmath.h" 430 return; 431 } 432 447 433 448 434 // input : current spectrum in the form of power *spec and phase *phase, … … 452 438 // output: current amplitude *amp and unpredictability *cw 453 439 static void 454 CalcUnpred ( const int MaxLine, 455 const float* spec, 456 const float* phase, 457 const int* vocal, 458 float* amp0, 459 float* phs0, 460 float* cw ) 440 CalcUnpred (PsyModel* m, 441 const int MaxLine, 442 const float* spec, 443 const float* phase, 444 const int* vocal, 445 float* amp0, 446 float* phs0, 447 float* cw ) 461 448 { 462 449 int n; … … 468 455 #define phs2 ((phs0) + 1024) // phs[1024...1535] contains data of frame-2 469 456 470 ENTER(207);471 457 472 458 for ( n = 0; n < MaxLine; n++ ) { … … 480 466 481 467 // postprocessing of harmonic FFT-lines (*cw is set to CVD_UNPRED) 482 if (CVD_used && vocal != NULL ) {468 if ( m->CVD_used && vocal != NULL ) { 483 469 for ( n = 0; n < MAX_CVD_LINE; n++, cw++, vocal++ ) 484 470 if ( *vocal != 0 && *cw > CVD_UNPRED * 0.01 * *vocal ) … … 486 472 } 487 473 488 LEAVE(207);489 474 return; 490 475 } … … 499 484 // SPRD describes the spreading function as calculated in psy_tab.c 500 485 static void 501 SpreadingSignal ( const float* erg, const float* werg, float* res, float* wres ) 486 SpreadingSignal ( PsyModel* m, const float* erg, const float* werg, float* res, 487 float* wres ) 502 488 { 503 489 int n; … … 509 495 float ew; 510 496 511 ENTER(208);512 497 513 498 for (k=0; k<PART_LONG; ++k, ++erg, ++werg) { // Source (masking partition) 514 499 start = maxi(k-5, 0); // minimum affected partition 515 500 stop = mini(k+7, PART_LONG-1); // maximum affected partition 516 sprd = SPRD[k] + start; // load vector501 sprd = m->SPRD[k] + start; // load vector 517 502 e = *erg; 518 503 ew = *werg; … … 524 509 } 525 510 526 LEAVE(208);527 511 return; 528 512 } … … 531 515 // output: masking threshold *erg after applying the tonality-offset 532 516 static void 533 ApplyTonalityOffset ( float* erg0, float* erg1, const float* werg0, const float* werg1 )517 ApplyTonalityOffset ( PsyModel* m, float* erg0, float* erg1, const float* werg0, const float* werg1 ) 534 518 { 535 519 int n; … … 537 521 float quot; 538 522 539 ENTER(230);540 523 541 524 // calculation of the masked threshold in the partition range 542 525 for ( n = 0; n < PART_LONG; n++ ) { 543 526 quot = *werg0++ / *erg0; 544 if (quot <= 0.05737540597f) Offset = O_MAX;545 else if (quot < 0.5871011603f ) Offset = FAC1 * POW (quot,FAC2);546 else Offset = O_MIN;547 *erg0++ *= iw[n] * minf( MinVal[n], Offset);527 if (quot <= 0.05737540597f) Offset = m->O_MAX; 528 else if (quot < 0.5871011603f ) Offset = m->FAC1 * POW (quot, m->FAC2); 529 else Offset = m->O_MIN; 530 *erg0++ *= iw[n] * minf(m->MinVal[n], Offset); 548 531 549 532 quot = *werg1++ / *erg1; 550 if (quot <= 0.05737540597f) Offset = O_MAX; 551 else if (quot < 0.5871011603f ) Offset = FAC1 * POW (quot, FAC2); 552 else Offset = O_MIN; 553 *erg1++ *= iw[n] * minf(MinVal[n], Offset); 554 } 555 556 LEAVE(230); 533 if (quot <= 0.05737540597f) Offset = m->O_MAX; 534 else if (quot < 0.5871011603f ) Offset = m->FAC1 * POW (quot, m->FAC2); 535 else Offset = m->O_MIN; 536 *erg1++ *= iw[n] * minf(m->MinVal[n], Offset); 537 } 538 557 539 return; 558 540 } … … 561 543 // output: tracked loudness *loud, adapted threshold in quiet <Return value> 562 544 static float 563 AdaptLtq ( const float* erg0, const float* erg1 )545 AdaptLtq ( PsyModel* m, const float* erg0, const float* erg1 ) 564 546 { 565 547 static float loud = 0.f; 566 float* weight =Loudness;548 float* weight = m->Loudness; 567 549 float sum = 0.f; 568 550 int n; … … 577 559 578 560 // calculate dynamic offset for threshold in quiet, 0...+20 dB, at 96 dB loudness, an offset of 20 dB is assumed 579 return 1.f + varLtq * loud * 5.023772e-08f;561 return 1.f + m->varLtq * loud * 5.023772e-08f; 580 562 } 581 563 … … 585 567 // output: tracked Integrations *a and *b, time constant *tau 586 568 static void 587 CalcTemporalThreshold ( float* a, float* b, float* tau, float* frqthr, float* tmpthr )569 CalcTemporalThreshold ( PsyModel* m, float* a, float* b, float* tau, float* frqthr, float* tmpthr ) 588 570 { 589 571 int n; 590 572 float tmp; 591 573 592 ENTER(220);593 574 594 575 for ( n = 0; n < PART_LONG; n++ ) { 595 576 // following calculations relative to threshold in quiet 596 frqthr[n] *= invLtq[n];597 tmpthr[n] *=invLtq[n];577 frqthr[n] *= m->invLtq[n]; 578 tmpthr[n] *= m->invLtq[n]; 598 579 599 580 // new post-masking 'tmp' via time constant tau, if old post-masking > Ltq (=1) … … 608 589 609 590 // use post-masking of (Re-Normalization) 610 tmpthr[n] = maxf (frqthr[n], tmp) * partLtq[n]; 611 } 612 613 LEAVE(220); 591 tmpthr[n] = maxf (frqthr[n], tmp) * m->partLtq[n]; 592 } 593 614 594 return; 615 595 } … … 620 600 // output: M/S-Masking thresholds in Partitions *thrM, *thrS 621 601 static void 622 CalcMSThreshold ( const float* const ergL, 602 CalcMSThreshold ( PsyModel* m, 603 const float* const ergL, 623 604 const float* const ergR, 624 605 const float* const ergM, … … 640 621 thrS[n] = thrM[n] = maxf (ergM[n], ergS[n]) / maxf (ergL[n], ergR[n]) * minf (thrL[n], thrR[n]); 641 622 642 switch ( MS_Channelmode ) { // preserve 'near-mid' signal components623 switch ( m->MS_Channelmode ) { // preserve 'near-mid' signal components 643 624 case 3: 644 625 if ( n > 0 ) { … … 760 741 tmp = ergS[n] * norm; 761 742 if ( thrS[n] > tmp ) 762 thrS[n] = maxf (tmp, ergM[n]*iw[n]*0.025); // +/- 1.414 °743 thrS[n] = maxf (tmp, ergM[n]*iw[n]*0.025); // +/- 1.414 763 744 } else if ( ergS[n] > ergM[n] ) { 764 745 tmp = ergM[n] * norm; 765 746 if ( thrM[n] > tmp ) 766 thrM[n] = maxf (tmp, ergS[n]*iw[n]*0.025); // +/- 1.414 °747 thrM[n] = maxf (tmp, ergS[n]*iw[n]*0.025); // +/- 1.414 767 748 } 768 749 } … … 779 760 // inline, because it's called 4x 780 761 static void 781 ApplyLtq ( float* thr0, 762 ApplyLtq ( PsyModel* m, 763 float* thr0, 782 764 float* thr1, 783 765 const float* partThr0, … … 800 782 #else 801 783 // Applies a much more gentle ATH rolloff + 6 dB more dynamic 802 ltq = sqrt (ms * fftLtq [k]);784 ltq = sqrt (ms * m->fftLtq [k]); 803 785 tmp = sqrt (partThr0 [n]) + ltq; 804 786 *thr0 = tmp * tmp; … … 896 878 #else 897 879 static void 898 CalcShortThreshold ( const float erg [4] [128], 880 CalcShortThreshold ( PsyModel* m, 881 const float erg [4] [128], 899 882 const float ShortThr, 900 883 float* thr, … … 907 890 int k; 908 891 int n; 909 int m;892 int l; 910 893 float new_erg; 911 894 float th; … … 917 900 for ( n = 0; n < 4; n++ ) { 918 901 ep = erg[n] + index_lo [k]; 919 m= index_hi [k] - index_lo [k];902 l = index_hi [k] - index_lo [k]; 920 903 921 904 new_erg = *ep++; 922 while ( m--)905 while (l--) 923 906 new_erg += *ep++; // e = Short_Partition-energy in piece n 924 907 925 908 if ( new_erg > old_erg [0][k] ) { // bigger than the old? 926 909 927 if ( new_erg > old_erg [0][k] * TransDetect ||928 new_erg > old_erg [1][k] *TransDetect*2 ) // is signal transient?910 if ( new_erg > old_erg [0][k] * m->TransDetect || 911 new_erg > old_erg [1][k] * m->TransDetect*2 ) // is signal transient? 929 912 transient [k] = 1; 930 913 } … … 992 975 // output: SMRs for the input data 993 976 SMRTyp 994 Psychoakustisches_Modell ( const int MaxBand, const PCMDataTyp* data, int* TransientL, int* TransientR ) 977 Psychoakustisches_Modell ( PsyModel* m, 978 const int MaxBand, 979 const PCMDataTyp* data, 980 int* TransientL, 981 int* TransientR ) 995 982 { 996 983 float Xi_L[32], Xi_R[32]; // acoustic pressure per Subband L/R … … 1019 1006 float factorLTQ = 1.f; // Offset after variable LTQ 1020 1007 1021 ENTER(50);1022 1008 // 'ClearVocalDetection'-Process 1023 if ( CVD_used ) {1024 memset ( Vocal_L, 0, sizeofVocal_L );1025 memset ( Vocal_R, 0, sizeofVocal_R );1009 if ( m->CVD_used ) { 1010 memset ( m->Vocal_L, 0, sizeof m->Vocal_L ); 1011 memset ( m->Vocal_R, 0, sizeof m->Vocal_R ); 1026 1012 1027 1013 // left channel 1028 1014 PowSpec2048 ( &data->L[0], Xerg ); 1029 isvoc_L = CVD2048 ( Xerg, Vocal_L );1015 isvoc_L = CVD2048 ( Xerg, m->Vocal_L ); 1030 1016 // right channel 1031 1017 PowSpec2048 ( &data->R[0], Xerg ); 1032 isvoc_R = CVD2048 ( Xerg, Vocal_R );1018 isvoc_R = CVD2048 ( Xerg, m->Vocal_R ); 1033 1019 } 1034 1020 … … 1047 1033 memmove ( Xsave_L+512, Xsave_L, 1024*sizeof(float) ); 1048 1034 memmove ( Ysave_L+512, Ysave_L, 1024*sizeof(float) ); 1049 CalcUnpred ( MaxLine, erg0, phs0, isvoc_L ?Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );1035 CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? m->Vocal_L : NULL, Xsave_L, Ysave_L, cw_L ); 1050 1036 // right 1051 1037 memmove ( Xsave_R+512, Xsave_R, 1024*sizeof(float) ); 1052 1038 memmove ( Ysave_R+512, Ysave_R, 1024*sizeof(float) ); 1053 CalcUnpred ( MaxLine, erg1, phs1, isvoc_R ?Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );1039 CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? m->Vocal_R : NULL, Xsave_R, Ysave_R, cw_R ); 1054 1040 1055 1041 // calculation of the weighted acoustic pressures per each partition … … 1060 1046 memset ( clow_L , 0, sizeof clow_L ); 1061 1047 memset ( sim_Mask_L, 0, sizeof sim_Mask_L ); 1062 SpreadingSignal ( Ls_L, cLs_L, sim_Mask_L, clow_L );1048 SpreadingSignal ( m, Ls_L, cLs_L, sim_Mask_L, clow_L ); 1063 1049 // right 1064 1050 memset ( clow_R , 0, sizeof clow_R ); 1065 1051 memset ( sim_Mask_R, 0, sizeof sim_Mask_R ); 1066 SpreadingSignal ( Ls_R, cLs_R, sim_Mask_R, clow_R );1052 SpreadingSignal ( m, Ls_R, cLs_R, sim_Mask_R, clow_R ); 1067 1053 1068 1054 // Offset depending on tonality 1069 ApplyTonalityOffset ( sim_Mask_L, sim_Mask_R, clow_L, clow_R );1055 ApplyTonalityOffset ( m, sim_Mask_L, sim_Mask_R, clow_L, clow_R ); 1070 1056 1071 1057 // handling of transient signals … … 1076 1062 PowSpec256 ( &data->L[432+SHORTFFT_OFFSET], F_256[3] ); 1077 1063 // calculate short Threshold 1078 CalcShortThreshold ( F_256, ShortThr, shortThr_L,pre_erg_L, TransientL );1064 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, m->pre_erg_L, TransientL ); 1079 1065 1080 1066 // calculate four short FFTs (right) … … 1084 1070 PowSpec256 ( &data->R[432+SHORTFFT_OFFSET], F_256[3] ); 1085 1071 // calculate short Threshold 1086 CalcShortThreshold ( F_256, ShortThr, shortThr_R,pre_erg_R, TransientR );1072 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, m->pre_erg_R, TransientR ); 1087 1073 1088 1074 // dynamic adjustment of the threshold in quiet to the loudness of the current sequence 1089 if ( varLtq > 0. )1090 factorLTQ = AdaptLtq ( Ls_L, Ls_R );1075 if ( m->varLtq > 0. ) 1076 factorLTQ = AdaptLtq (m, Ls_L, Ls_R ); 1091 1077 1092 1078 // utilization of the temporal post-masking 1093 if ( tmpMask_used ) {1094 CalcTemporalThreshold ( a, b, T_L, sim_Mask_L,tmp_Mask_L );1095 CalcTemporalThreshold ( c, d, T_R, sim_Mask_R,tmp_Mask_R );1096 memcpy ( sim_Mask_L,tmp_Mask_L, sizeof sim_Mask_L );1097 memcpy ( sim_Mask_R,tmp_Mask_R, sizeof sim_Mask_R );1079 if ( m->tmpMask_used ) { 1080 CalcTemporalThreshold (m, m->a, m->b, m->T_L, sim_Mask_L, m->tmp_Mask_L ); 1081 CalcTemporalThreshold (m, m->c, m->d, m->T_R, sim_Mask_R, m->tmp_Mask_R ); 1082 memcpy ( sim_Mask_L, m->tmp_Mask_L, sizeof sim_Mask_L ); 1083 memcpy ( sim_Mask_R, m->tmp_Mask_R, sizeof sim_Mask_R ); 1098 1084 } 1099 1085 … … 1113 1099 1114 1100 // Pre-Echo control 1115 PreechoControl ( PartThr_L, PreThr_L, sim_Mask_L, PartThr_R,PreThr_R, sim_Mask_R );1101 PreechoControl ( PartThr_L, m->PreThr_L, sim_Mask_L, PartThr_R, m->PreThr_R, sim_Mask_R ); 1116 1102 1117 1103 // utilization of the threshold in quiet 1118 ApplyLtq ( Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );1104 ApplyLtq ( m, Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 ); 1119 1105 1120 1106 // Consideration of aliasing between the subbands (noise is smeared) … … 1129 1115 /***************************************************************************************/ 1130 1116 /***************************************************************************************/ 1131 if (MS_Channelmode > 0 ) {1117 if ( m->MS_Channelmode > 0 ) { 1132 1118 // calculation of the spectral energy via FFT 1133 1119 PowSpec1024 ( &data->M[0], erg0 ); // mid … … 1141 1127 1142 1128 // calculate masking thresholds for M/S 1143 CalcMSThreshold ( Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );1144 ApplyLtq ( Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );1129 CalcMSThreshold ( m, Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S ); 1130 ApplyLtq ( m, Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 ); 1145 1131 1146 1132 // Consideration of aliasing between the subbands (noise is smeared) … … 1154 1140 } 1155 1141 1156 if (NS_Order > 0 ) { // providing the Noise Shaping thresholds1157 memcpy ( ANSspec_L, Thr_L, sizeofANSspec_L );1158 memcpy ( ANSspec_R, Thr_R, sizeofANSspec_R );1159 memcpy ( ANSspec_M, Thr_M, sizeofANSspec_M );1160 memcpy ( ANSspec_S, Thr_S, sizeofANSspec_S );1142 if ( m->NS_Order > 0 ) { // providing the Noise Shaping thresholds 1143 memcpy ( m->ANSspec_L, Thr_L, sizeof m->ANSspec_L ); 1144 memcpy ( m->ANSspec_R, Thr_R, sizeof m->ANSspec_R ); 1145 memcpy ( m->ANSspec_M, Thr_M, sizeof m->ANSspec_M ); 1146 memcpy ( m->ANSspec_S, Thr_S, sizeof m->ANSspec_S ); 1161 1147 } 1162 1148 /***************************************************************************************/ … … 1180 1166 memmove ( Xsave_L+512, Xsave_L, 1024*sizeof(float) ); 1181 1167 memmove ( Ysave_L+512, Ysave_L, 1024*sizeof(float) ); 1182 CalcUnpred ( MaxLine, erg0, phs0, isvoc_L ?Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );1168 CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? m->Vocal_L : NULL, Xsave_L, Ysave_L, cw_L ); 1183 1169 // right 1184 1170 memmove ( Xsave_R+512, Xsave_R, 1024*sizeof(float) ); 1185 1171 memmove ( Ysave_R+512, Ysave_R, 1024*sizeof(float) ); 1186 CalcUnpred ( MaxLine, erg1, phs1, isvoc_R ?Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );1172 CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? m->Vocal_R : NULL, Xsave_R, Ysave_R, cw_R ); 1187 1173 1188 1174 // calculation of the weighted acoustic pressure per each partition … … 1193 1179 memset ( clow_L , 0, sizeof clow_L ); 1194 1180 memset ( sim_Mask_L, 0, sizeof sim_Mask_L ); 1195 SpreadingSignal ( Ls_L, cLs_L, sim_Mask_L, clow_L );1181 SpreadingSignal ( m, Ls_L, cLs_L, sim_Mask_L, clow_L ); 1196 1182 // right 1197 1183 memset ( clow_R , 0, sizeof clow_R ); 1198 1184 memset ( sim_Mask_R, 0, sizeof sim_Mask_R ); 1199 SpreadingSignal ( Ls_R, cLs_R, sim_Mask_R, clow_R );1185 SpreadingSignal ( m, Ls_R, cLs_R, sim_Mask_R, clow_R ); 1200 1186 1201 1187 // Offset depending on tonality 1202 ApplyTonalityOffset ( sim_Mask_L, sim_Mask_R, clow_L, clow_R );1188 ApplyTonalityOffset ( m, sim_Mask_L, sim_Mask_R, clow_L, clow_R ); 1203 1189 1204 1190 // Handling of transient signals … … 1209 1195 PowSpec256 ( &data->L[1008+SHORTFFT_OFFSET], F_256[3] ); 1210 1196 // calculate short Threshold 1211 CalcShortThreshold ( F_256, ShortThr, shortThr_L,pre_erg_L, TransientL );1197 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, m->pre_erg_L, TransientL ); 1212 1198 1213 1199 // calculate four short FFTs (right) … … 1217 1203 PowSpec256 ( &data->R[1008+SHORTFFT_OFFSET], F_256[3] ); 1218 1204 // calculate short Threshold 1219 CalcShortThreshold ( F_256, ShortThr, shortThr_R,pre_erg_R, TransientR );1205 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, m->pre_erg_R, TransientR ); 1220 1206 1221 1207 // dynamic adjustment of threshold in quiet to loudness of the current sequence 1222 if (varLtq > 0. )1223 factorLTQ = AdaptLtq ( Ls_L, Ls_R );1208 if ( m->varLtq > 0. ) 1209 factorLTQ = AdaptLtq ( m, Ls_L, Ls_R ); 1224 1210 1225 1211 // utilization of temporal post-masking 1226 if (tmpMask_used) {1227 CalcTemporalThreshold ( a, b, T_L, sim_Mask_L,tmp_Mask_L );1228 CalcTemporalThreshold ( c, d, T_R, sim_Mask_R,tmp_Mask_R );1229 memcpy ( sim_Mask_L,tmp_Mask_L, sizeof sim_Mask_L );1230 memcpy ( sim_Mask_R,tmp_Mask_R, sizeof sim_Mask_R );1212 if (m->tmpMask_used) { 1213 CalcTemporalThreshold ( m, m->a, m->b, m->T_L, sim_Mask_L, m->tmp_Mask_L ); 1214 CalcTemporalThreshold ( m, m->c, m->d, m->T_R, sim_Mask_R, m->tmp_Mask_R ); 1215 memcpy ( sim_Mask_L, m->tmp_Mask_L, sizeof sim_Mask_L ); 1216 memcpy ( sim_Mask_R, m->tmp_Mask_R, sizeof sim_Mask_R ); 1231 1217 } 1232 1218 … … 1246 1232 1247 1233 // Pre-Echo control 1248 PreechoControl ( PartThr_L, PreThr_L, sim_Mask_L, PartThr_R,PreThr_R, sim_Mask_R );1234 PreechoControl ( PartThr_L, m->PreThr_L, sim_Mask_L, PartThr_R, m->PreThr_R, sim_Mask_R ); 1249 1235 1250 1236 // utilization of threshold in quiet 1251 ApplyLtq ( Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );1237 ApplyLtq ( m, Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 ); 1252 1238 1253 1239 // Consideration of aliasing between the subbands (noise is smeared) … … 1262 1248 /***************************************************************************************/ 1263 1249 /***************************************************************************************/ 1264 if (MS_Channelmode > 0 ) {1250 if ( m->MS_Channelmode > 0 ) { 1265 1251 // calculation of the spectral energy via FFT 1266 1252 PowSpec1024 ( &data->M[576], erg0 ); // mid … … 1274 1260 1275 1261 // calculate masking thresholds for M/S 1276 CalcMSThreshold ( Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );1277 ApplyLtq ( Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );1262 CalcMSThreshold ( m, Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S ); 1263 ApplyLtq ( m, Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 ); 1278 1264 1279 1265 // Consideration of aliasing between the subbands (noise is smeared) … … 1289 1275 /***************************************************************************************/ 1290 1276 1291 if (NS_Order > 0 ) {1277 if ( m->NS_Order > 0 ) { 1292 1278 for ( n = 0; n < MAX_ANS_LINES; n++ ) { // providing Noise Shaping thresholds 1293 ANSspec_L [n] = minf (ANSspec_L [n], Thr_L [n] );1294 ANSspec_R [n] = minf (ANSspec_R [n], Thr_R [n] );1295 ANSspec_M [n] = minf (ANSspec_M [n], Thr_M [n] );1296 ANSspec_S [n] = minf (ANSspec_S [n], Thr_S [n] );1279 m->ANSspec_L [n] = minf ( m->ANSspec_L [n], Thr_L [n] ); 1280 m->ANSspec_R [n] = minf ( m->ANSspec_R [n], Thr_R [n] ); 1281 m->ANSspec_M [n] = minf ( m->ANSspec_M [n], Thr_M [n] ); 1282 m->ANSspec_S [n] = minf ( m->ANSspec_S [n], Thr_S [n] ); 1297 1283 } 1298 1284 } … … 1304 1290 SMR0.S[n] = maxf ( SMR0.S[n], SMR1.S[n] ); 1305 1291 } 1306 1307 LEAVE(50);1308 1292 return SMR0; 1309 1293 }
Note: See TracChangeset
for help on using the changeset viewer.