Changeset 71 for mppenc/branches/r2d/libmpcpsy/psy.c
- Timestamp:
- 10/07/06 02:49:28 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mppenc/branches/r2d/libmpcpsy/psy.c
r66 r71 60 60 #include "minimax.h" 61 61 62 62 // psy_tab.c 63 63 extern const float iw [PART_LONG]; // inverse partition-width for long 64 64 extern const float iw_short [PART_SHORT]; // inverse partition-width for short … … 67 67 extern const int wh [PART_LONG]; // w_high for long 68 68 extern const int wh_short [PART_SHORT]; // w_high for short 69 69 extern float MinVal [PART_LONG]; // minimum quality that's adapted to the model, minval for long 70 extern float Loudness [PART_LONG]; // weighting factors for loudness calculation 71 extern float SPRD [PART_LONG] [PART_LONG]; // tabulated spreading function 72 extern float O_MAX; 73 extern float O_MIN; 74 extern float FAC1; 75 extern float FAC2; // constants for offset calculation 76 extern float partLtq [PART_LONG]; // threshold in quiet (partitions) 77 extern float invLtq [PART_LONG]; // inverse threshold in quiet (partitions, long) 78 extern float fftLtq [512]; // threshold in quiet (FFT) 79 80 // ans.c 81 extern float ANSspec_L [MAX_ANS_LINES]; 82 extern float ANSspec_R [MAX_ANS_LINES]; // L/R-masking threshold for ANS 83 extern float ANSspec_M [MAX_ANS_LINES]; 84 extern float ANSspec_S [MAX_ANS_LINES]; // M/S-masking threshold for ANS 85 86 void Init_Psychoakustiktabellen ( PsyModel* ); 87 int CVD2048 ( PsyModel*, const float*, int* ); 70 88 71 89 // Antialiasing for calculation of the subband power … … 77 95 /* V A R I A B L E S */ 78 96 97 static float a [PART_LONG]; 98 static float b [PART_LONG]; 99 static float c [PART_LONG]; 100 static float d [PART_LONG]; // Integrations for tmpMask 79 101 static float Xsave_L [3 * 512]; 80 102 static float Xsave_R [3 * 512]; // FFT-Amplitudes L/R 81 103 static float Ysave_L [3 * 512]; 82 104 static float Ysave_R [3 * 512]; // FFT-Phases L/R 105 static float T_L [PART_LONG]; 106 static float T_R [PART_LONG]; // time-constants for tmpMask 107 static float pre_erg_L[2][PART_SHORT]; 108 static float pre_erg_R[2][PART_SHORT]; // Preecho-control short 109 static float PreThr_L [PART_LONG]; 110 static float PreThr_R [PART_LONG]; // for Pre-Echo-control L/R 111 static float tmp_Mask_L [PART_LONG]; 112 static float tmp_Mask_R [PART_LONG]; // for Post-Masking L/R 113 static int Vocal_L [MAX_CVD_LINE + 4]; 114 static int Vocal_R [MAX_CVD_LINE + 4]; // FFT-Line belongs to harmonic? 83 115 84 116 /* F U N C T I O N S */ … … 102 134 memset ( Ysave_L, 0, sizeof Ysave_L ); 103 135 memset ( Ysave_R, 0, sizeof Ysave_R ); 104 memset ( m->a, 0, sizeof m->a );105 memset ( m->b, 0, sizeof m->b );106 memset ( m->c, 0, sizeof m->c );107 memset ( m->d, 0, sizeof m->d );108 memset ( m->T_L, 0, sizeof m->T_L );109 memset ( m->T_R, 0, sizeof m->T_R );110 memset ( m->Vocal_L, 0, sizeof m->Vocal_L );111 memset ( m->Vocal_R, 0, sizeof m->Vocal_R );136 memset ( a, 0, sizeof a ); 137 memset ( b, 0, sizeof b ); 138 memset ( c, 0, sizeof c ); 139 memset ( d, 0, sizeof d ); 140 memset ( T_L, 0, sizeof T_L ); 141 memset ( T_R, 0, sizeof T_R ); 142 memset ( Vocal_L, 0, sizeof Vocal_L ); 143 memset ( Vocal_R, 0, sizeof Vocal_R ); 112 144 113 145 m->SampleFreq = 0.; … … 115 147 m->KBD1 = 2.; 116 148 m->KBD2 = -1.; 149 m->Ltq_offset = 0; 150 m->Ltq_max = 0; 151 m->EarModelFlag = 0; 117 152 118 153 // generate FFT lookup-tables with largest FFT-size of 1024 119 154 Init_FFT (m); 120 155 156 Init_Psychoakustiktabellen (m); 157 121 158 // setting pre-echo variables to Ltq 122 159 for ( i = 0; i < PART_LONG; i++ ) { 123 m->pre_erg_L [0][i/3] = m->pre_erg_R [0][i/3] =124 m->pre_erg_L [1][i/3] = m->pre_erg_R [1][i/3] =125 m->tmp_Mask_L [i] = m->tmp_Mask_R [i] =126 m->PreThr_L [i] = m->PreThr_R [i] = m->partLtq [i];160 pre_erg_L [0][i/3] = pre_erg_R [0][i/3] = 161 pre_erg_L [1][i/3] = pre_erg_R [1][i/3] = 162 tmp_Mask_L [i] = tmp_Mask_R [i] = 163 PreThr_L [i] = PreThr_R [i] = partLtq [i]; 127 164 } 128 165 … … 496 533 // SPRD describes the spreading function as calculated in psy_tab.c 497 534 static void 498 SpreadingSignal ( PsyModel* m,const float* erg, const float* werg, float* res,535 SpreadingSignal ( const float* erg, const float* werg, float* res, 499 536 float* wres ) 500 537 { … … 511 548 start = maxi(k-5, 0); // minimum affected partition 512 549 stop = mini(k+7, PART_LONG-1); // maximum affected partition 513 sprd = m->SPRD[k] + start; // load vector550 sprd = SPRD[k] + start; // load vector 514 551 e = *erg; 515 552 ew = *werg; … … 527 564 // output: masking threshold *erg after applying the tonality-offset 528 565 static void 529 ApplyTonalityOffset ( PsyModel* m,float* erg0, float* erg1, const float* werg0, const float* werg1 )566 ApplyTonalityOffset ( float* erg0, float* erg1, const float* werg0, const float* werg1 ) 530 567 { 531 568 int n; … … 537 574 for ( n = 0; n < PART_LONG; n++ ) { 538 575 quot = *werg0++ / *erg0; 539 if (quot <= 0.05737540597f) Offset = m->O_MAX;540 else if (quot < 0.5871011603f ) Offset = m->FAC1 * POW (quot, m->FAC2);541 else Offset = m->O_MIN;542 *erg0++ *= iw[n] * minf( m->MinVal[n], Offset);576 if (quot <= 0.05737540597f) Offset = O_MAX; 577 else if (quot < 0.5871011603f ) Offset = FAC1 * POW (quot, FAC2); 578 else Offset = O_MIN; 579 *erg0++ *= iw[n] * minf(MinVal[n], Offset); 543 580 544 581 quot = *werg1++ / *erg1; 545 if (quot <= 0.05737540597f) Offset = m->O_MAX;546 else if (quot < 0.5871011603f ) Offset = m->FAC1 * POW (quot, m->FAC2);547 else Offset = m->O_MIN;548 *erg1++ *= iw[n] * minf( m->MinVal[n], Offset);582 if (quot <= 0.05737540597f) Offset = O_MAX; 583 else if (quot < 0.5871011603f ) Offset = FAC1 * POW (quot, FAC2); 584 else Offset = O_MIN; 585 *erg1++ *= iw[n] * minf(MinVal[n], Offset); 549 586 } 550 587 … … 558 595 { 559 596 static float loud = 0.f; 560 float* weight = m->Loudness;597 float* weight = Loudness; 561 598 float sum = 0.f; 562 599 int n; … … 579 616 // output: tracked Integrations *a and *b, time constant *tau 580 617 static void 581 CalcTemporalThreshold ( PsyModel* m,float* a, float* b, float* tau, float* frqthr, float* tmpthr )618 CalcTemporalThreshold ( float* a, float* b, float* tau, float* frqthr, float* tmpthr ) 582 619 { 583 620 int n; … … 587 624 for ( n = 0; n < PART_LONG; n++ ) { 588 625 // following calculations relative to threshold in quiet 589 frqthr[n] *= m->invLtq[n];590 tmpthr[n] *= m->invLtq[n];626 frqthr[n] *= invLtq[n]; 627 tmpthr[n] *= invLtq[n]; 591 628 592 629 // new post-masking 'tmp' via time constant tau, if old post-masking > Ltq (=1) … … 601 638 602 639 // use post-masking of (Re-Normalization) 603 tmpthr[n] = maxf (frqthr[n], tmp) * m->partLtq[n];640 tmpthr[n] = maxf (frqthr[n], tmp) * partLtq[n]; 604 641 } 605 642 … … 772 809 // inline, because it's called 4x 773 810 static void 774 ApplyLtq ( PsyModel* m, 775 float* thr0, 811 ApplyLtq ( float* thr0, 776 812 float* thr1, 777 813 const float* partThr0, … … 794 830 #else 795 831 // Applies a much more gentle ATH rolloff + 6 dB more dynamic 796 ltq = sqrt (ms * m->fftLtq [k]);832 ltq = sqrt (ms * fftLtq [k]); 797 833 tmp = sqrt (partThr0 [n]) + ltq; 798 834 *thr0 = tmp * tmp; … … 1020 1056 // 'ClearVocalDetection'-Process 1021 1057 if ( m->CVD_used ) { 1022 memset ( m->Vocal_L, 0, sizeof m->Vocal_L );1023 memset ( m->Vocal_R, 0, sizeof m->Vocal_R );1058 memset ( Vocal_L, 0, sizeof Vocal_L ); 1059 memset ( Vocal_R, 0, sizeof Vocal_R ); 1024 1060 1025 1061 // left channel 1026 1062 PowSpec2048 ( &data->L[0], Xerg ); 1027 isvoc_L = CVD2048 ( Xerg, m->Vocal_L );1063 isvoc_L = CVD2048 ( m, Xerg, Vocal_L ); 1028 1064 // right channel 1029 1065 PowSpec2048 ( &data->R[0], Xerg ); 1030 isvoc_R = CVD2048 ( Xerg, m->Vocal_R );1066 isvoc_R = CVD2048 ( m, Xerg, Vocal_R ); 1031 1067 } 1032 1068 … … 1045 1081 memmove ( Xsave_L+512, Xsave_L, 1024*sizeof(float) ); 1046 1082 memmove ( Ysave_L+512, Ysave_L, 1024*sizeof(float) ); 1047 CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? m->Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );1083 CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? Vocal_L : NULL, Xsave_L, Ysave_L, cw_L ); 1048 1084 // right 1049 1085 memmove ( Xsave_R+512, Xsave_R, 1024*sizeof(float) ); 1050 1086 memmove ( Ysave_R+512, Ysave_R, 1024*sizeof(float) ); 1051 CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? m->Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );1087 CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? Vocal_R : NULL, Xsave_R, Ysave_R, cw_R ); 1052 1088 1053 1089 // calculation of the weighted acoustic pressures per each partition … … 1058 1094 memset ( clow_L , 0, sizeof clow_L ); 1059 1095 memset ( sim_Mask_L, 0, sizeof sim_Mask_L ); 1060 SpreadingSignal ( m,Ls_L, cLs_L, sim_Mask_L, clow_L );1096 SpreadingSignal ( Ls_L, cLs_L, sim_Mask_L, clow_L ); 1061 1097 // right 1062 1098 memset ( clow_R , 0, sizeof clow_R ); 1063 1099 memset ( sim_Mask_R, 0, sizeof sim_Mask_R ); 1064 SpreadingSignal ( m,Ls_R, cLs_R, sim_Mask_R, clow_R );1100 SpreadingSignal ( Ls_R, cLs_R, sim_Mask_R, clow_R ); 1065 1101 1066 1102 // Offset depending on tonality 1067 ApplyTonalityOffset ( m,sim_Mask_L, sim_Mask_R, clow_L, clow_R );1103 ApplyTonalityOffset ( sim_Mask_L, sim_Mask_R, clow_L, clow_R ); 1068 1104 1069 1105 // handling of transient signals … … 1074 1110 PowSpec256 ( &data->L[432+SHORTFFT_OFFSET], F_256[3] ); 1075 1111 // calculate short Threshold 1076 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, m->pre_erg_L, TransientL );1112 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, pre_erg_L, TransientL ); 1077 1113 1078 1114 // calculate four short FFTs (right) … … 1082 1118 PowSpec256 ( &data->R[432+SHORTFFT_OFFSET], F_256[3] ); 1083 1119 // calculate short Threshold 1084 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, m->pre_erg_R, TransientR );1120 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, pre_erg_R, TransientR ); 1085 1121 1086 1122 // dynamic adjustment of the threshold in quiet to the loudness of the current sequence … … 1090 1126 // utilization of the temporal post-masking 1091 1127 if ( m->tmpMask_used ) { 1092 CalcTemporalThreshold ( m, m->a, m->b, m->T_L, sim_Mask_L, m->tmp_Mask_L );1093 CalcTemporalThreshold ( m, m->c, m->d, m->T_R, sim_Mask_R, m->tmp_Mask_R );1094 memcpy ( sim_Mask_L, m->tmp_Mask_L, sizeof sim_Mask_L );1095 memcpy ( sim_Mask_R, m->tmp_Mask_R, sizeof sim_Mask_R );1128 CalcTemporalThreshold ( a, b, T_L, sim_Mask_L, tmp_Mask_L ); 1129 CalcTemporalThreshold ( c, d, T_R, sim_Mask_R, tmp_Mask_R ); 1130 memcpy ( sim_Mask_L, tmp_Mask_L, sizeof sim_Mask_L ); 1131 memcpy ( sim_Mask_R, tmp_Mask_R, sizeof sim_Mask_R ); 1096 1132 } 1097 1133 … … 1111 1147 1112 1148 // Pre-Echo control 1113 PreechoControl ( PartThr_L, m->PreThr_L, sim_Mask_L, PartThr_R, m->PreThr_R, sim_Mask_R );1149 PreechoControl ( PartThr_L,PreThr_L, sim_Mask_L, PartThr_R, PreThr_R, sim_Mask_R ); 1114 1150 1115 1151 // utilization of the threshold in quiet 1116 ApplyLtq ( m,Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );1152 ApplyLtq ( Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 ); 1117 1153 1118 1154 // Consideration of aliasing between the subbands (noise is smeared) … … 1140 1176 // calculate masking thresholds for M/S 1141 1177 CalcMSThreshold ( m, Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S ); 1142 ApplyLtq ( m,Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );1178 ApplyLtq ( Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 ); 1143 1179 1144 1180 // Consideration of aliasing between the subbands (noise is smeared) … … 1153 1189 1154 1190 if ( m->NS_Order > 0 ) { // providing the Noise Shaping thresholds 1155 memcpy ( m->ANSspec_L, Thr_L, sizeof m->ANSspec_L );1156 memcpy ( m->ANSspec_R, Thr_R, sizeof m->ANSspec_R );1157 memcpy ( m->ANSspec_M, Thr_M, sizeof m->ANSspec_M );1158 memcpy ( m->ANSspec_S, Thr_S, sizeof m->ANSspec_S );1191 memcpy ( ANSspec_L, Thr_L, sizeof ANSspec_L ); 1192 memcpy ( ANSspec_R, Thr_R, sizeof ANSspec_R ); 1193 memcpy ( ANSspec_M, Thr_M, sizeof ANSspec_M ); 1194 memcpy ( ANSspec_S, Thr_S, sizeof ANSspec_S ); 1159 1195 } 1160 1196 /***************************************************************************************/ … … 1178 1214 memmove ( Xsave_L+512, Xsave_L, 1024*sizeof(float) ); 1179 1215 memmove ( Ysave_L+512, Ysave_L, 1024*sizeof(float) ); 1180 CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? m->Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );1216 CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? Vocal_L : NULL, Xsave_L, Ysave_L, cw_L ); 1181 1217 // right 1182 1218 memmove ( Xsave_R+512, Xsave_R, 1024*sizeof(float) ); 1183 1219 memmove ( Ysave_R+512, Ysave_R, 1024*sizeof(float) ); 1184 CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? m->Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );1220 CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? Vocal_R : NULL, Xsave_R, Ysave_R, cw_R ); 1185 1221 1186 1222 // calculation of the weighted acoustic pressure per each partition … … 1191 1227 memset ( clow_L , 0, sizeof clow_L ); 1192 1228 memset ( sim_Mask_L, 0, sizeof sim_Mask_L ); 1193 SpreadingSignal ( m,Ls_L, cLs_L, sim_Mask_L, clow_L );1229 SpreadingSignal ( Ls_L, cLs_L, sim_Mask_L, clow_L ); 1194 1230 // right 1195 1231 memset ( clow_R , 0, sizeof clow_R ); 1196 1232 memset ( sim_Mask_R, 0, sizeof sim_Mask_R ); 1197 SpreadingSignal ( m,Ls_R, cLs_R, sim_Mask_R, clow_R );1233 SpreadingSignal ( Ls_R, cLs_R, sim_Mask_R, clow_R ); 1198 1234 1199 1235 // Offset depending on tonality 1200 ApplyTonalityOffset ( m,sim_Mask_L, sim_Mask_R, clow_L, clow_R );1236 ApplyTonalityOffset ( sim_Mask_L, sim_Mask_R, clow_L, clow_R ); 1201 1237 1202 1238 // Handling of transient signals … … 1207 1243 PowSpec256 ( &data->L[1008+SHORTFFT_OFFSET], F_256[3] ); 1208 1244 // calculate short Threshold 1209 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, m->pre_erg_L, TransientL );1245 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, pre_erg_L, TransientL ); 1210 1246 1211 1247 // calculate four short FFTs (right) … … 1215 1251 PowSpec256 ( &data->R[1008+SHORTFFT_OFFSET], F_256[3] ); 1216 1252 // calculate short Threshold 1217 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, m->pre_erg_R, TransientR );1253 CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, pre_erg_R, TransientR ); 1218 1254 1219 1255 // dynamic adjustment of threshold in quiet to loudness of the current sequence … … 1223 1259 // utilization of temporal post-masking 1224 1260 if (m->tmpMask_used) { 1225 CalcTemporalThreshold ( m, m->a, m->b, m->T_L, sim_Mask_L, m->tmp_Mask_L );1226 CalcTemporalThreshold ( m, m->c, m->d, m->T_R, sim_Mask_R, m->tmp_Mask_R );1227 memcpy ( sim_Mask_L, m->tmp_Mask_L, sizeof sim_Mask_L );1228 memcpy ( sim_Mask_R, m->tmp_Mask_R, sizeof sim_Mask_R );1261 CalcTemporalThreshold ( a, b, T_L, sim_Mask_L, tmp_Mask_L ); 1262 CalcTemporalThreshold ( c, d, T_R, sim_Mask_R, tmp_Mask_R ); 1263 memcpy ( sim_Mask_L, tmp_Mask_L, sizeof sim_Mask_L ); 1264 memcpy ( sim_Mask_R, tmp_Mask_R, sizeof sim_Mask_R ); 1229 1265 } 1230 1266 … … 1244 1280 1245 1281 // Pre-Echo control 1246 PreechoControl ( PartThr_L, m->PreThr_L, sim_Mask_L, PartThr_R, m->PreThr_R, sim_Mask_R );1282 PreechoControl ( PartThr_L, PreThr_L, sim_Mask_L, PartThr_R, PreThr_R, sim_Mask_R ); 1247 1283 1248 1284 // utilization of threshold in quiet 1249 ApplyLtq ( m,Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );1285 ApplyLtq ( Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 ); 1250 1286 1251 1287 // Consideration of aliasing between the subbands (noise is smeared) … … 1273 1309 // calculate masking thresholds for M/S 1274 1310 CalcMSThreshold ( m, Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S ); 1275 ApplyLtq ( m,Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );1311 ApplyLtq ( Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 ); 1276 1312 1277 1313 // Consideration of aliasing between the subbands (noise is smeared) … … 1289 1325 if ( m->NS_Order > 0 ) { 1290 1326 for ( n = 0; n < MAX_ANS_LINES; n++ ) { // providing Noise Shaping thresholds 1291 m->ANSspec_L [n] = minf ( m->ANSspec_L [n], Thr_L [n] );1292 m->ANSspec_R [n] = minf ( m->ANSspec_R [n], Thr_R [n] );1293 m->ANSspec_M [n] = minf ( m->ANSspec_M [n], Thr_M [n] );1294 m->ANSspec_S [n] = minf ( m->ANSspec_S [n], Thr_S [n] );1327 ANSspec_L [n] = minf ( ANSspec_L [n], Thr_L [n] ); 1328 ANSspec_R [n] = minf ( ANSspec_R [n], Thr_R [n] ); 1329 ANSspec_M [n] = minf ( ANSspec_M [n], Thr_M [n] ); 1330 ANSspec_S [n] = minf ( ANSspec_S [n], Thr_S [n] ); 1295 1331 } 1296 1332 }
Note: See TracChangeset
for help on using the changeset viewer.