Changeset 60 for mppenc/branches/r2d/libmpcpsy/psy_tab.c
- Timestamp:
- 09/28/06 18:15:21 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mppenc/branches/r2d/libmpcpsy/psy_tab.c
r59 r60 18 18 */ 19 19 20 #include "mppenc.h" 21 22 // Antialiasing for calculation of the subband power 23 const float Butfly [7] = { 0.5f, 0.2776f, 0.1176f, 0.0361f, 0.0075f, 0.000948f, 0.0000598f }; 24 25 // Antialiasing for calculation of the masking thresholds 26 const float InvButfly [7] = { 2.f, 3.6023f, 8.5034f, 27.701f, 133.33f, 1054.852f, 16722.408f }; 27 28 // w_low for long 0 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 29 const int wl [PART_LONG] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 38, 41, 44, 47, 50, 54, 58, 62, 67, 72, 78, 84, 91, 98, 106, 115, 124, 134, 145, 157, 170, 184, 199, 216, 234, 254, 276, 301, 329, 360, 396, 437, 485 }; 30 const int wh [PART_LONG] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 37, 40, 43, 46, 49, 53, 57, 61, 66, 71, 77, 83, 90, 97, 105, 114, 123, 133, 144, 156, 169, 183, 198, 215, 233, 253, 275, 300, 328, 359, 395, 436, 484, 511 }; 31 // Width: 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 4 4 4 5 5 6 6 7 7 8 9 9 10 11 12 13 14 15 17 18 20 22 25 28 31 36 41 48 27 32 33 // inverse partition-width for long 34 const float iw [PART_LONG] = { 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/3, 1.f/3, 1.f/3, 1.f/3, 1.f/3, 1.f/4, 1.f/4, 1.f/4, 1.f/5, 1.f/5, 1.f/6, 1.f/6, 1.f/7, 1.f/7, 1.f/8, 1.f/9, 1.f/9, 1.f/10, 1.f/11, 1.f/12, 1.f/13, 1.f/14, 1.f/15, 1.f/17, 1.f/18, 1.f/20, 1.f/22, 1.f/25, 1.f/28, 1.f/31, 1.f/36, 1.f/41, 1.f/48, 1.f/27 }; 35 36 // w_low for short 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 37 const int wl_short [PART_SHORT] = { 0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 18, 23, 29, 36, 46, 59, 75, 99 }; 38 const int wh_short [PART_SHORT] = { 0, 1, 2, 3, 5, 6, 7, 9, 12, 14, 18, 23, 29, 36, 46, 58, 75, 99, 127 }; 39 40 // inverse partition-width for short 41 const float iw_short [PART_SHORT] = { 1.f, 1.f, 1.f, 1.f, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/3, 1.f/3, 1.f/4, 1.f/6, 1.f/7, 1.f/8, 1.f/11, 1.f/13, 1.f/17, 1.f/25, 1.f/29 }; 42 43 /* 44 Nr. wl wh fl fh bl bh bm Nr. wl wh fl fh bl bh bm 45 0: 0 0 0 0 0.000000 0.000000 0.000000 46 1: 1 1 43 43 0.425460 0.425460 0.425460 0: 0 0 0 0 0.000000 0.000000 0.000000 47 2: 2 2 86 86 0.850241 0.850241 0.850241 48 49 3: 3 3 129 129 1.273448 1.273448 1.273448 50 4: 4 4 172 172 1.694205 1.694205 1.694205 1: 1 1 172 172 1.694205 1.694205 1.694205 51 5: 5 5 215 215 2.111672 2.111672 2.111672 52 53 6: 6 6 258 258 2.525051 2.525051 2.525051 54 7: 7 7 301 301 2.933594 2.933594 2.933594 2: 2 2 345 345 3.336612 3.336612 3.336612 55 8: 8 8 345 345 3.336612 3.336612 3.336612 56 57 9: 9 9 388 388 3.733479 3.733479 3.733479 58 10: 10 10 431 431 4.123635 4.123635 4.123635 3: 3 3 517 517 4.881924 4.881924 4.881924 59 11- 11 12 474 517 4.506591 4.881924 4.695234 60 61 12: 13 14 560 603 5.249283 5.608381 5.429880 62 13: 15 16 646 689 5.958998 6.300971 6.131073 4: 4 5 689 861 6.300971 7.581073 6.958618 63 14: 17 18 732 775 6.634195 6.958618 6.797509 64 65 15: 19 20 818 861 7.274232 7.581073 7.428745 66 16: 21 22 904 947 7.879211 8.168753 8.025049 5: 5 6 861 1034 7.581073 8.722594 8.168753 67 17: 23 24 991 1034 8.449828 8.722594 8.587239 68 69 18: 25 26 1077 1120 8.987223 9.243908 9.116546 70 19: 27 28 1163 1206 9.492850 9.734263 9.614484 6: 6 7 1034 1206 8.722594 9.734263 9.243908 71 20: 29 30 1249 1292 9.968365 10.195382 10.082745 72 73 21: 31 32 1335 1378 10.415539 10.629064 10.523116 74 22: 33 34 1421 1464 10.836184 11.037125 10.937413 7: 8 9 1378 1550 10.629064 11.421352 11.037125 75 23: 35 37 1507 1593 11.232108 11.605071 11.421352 76 77 24: 38 40 1637 1723 11.783474 12.125139 11.956764 78 25: 41 43 1766 1852 12.288791 12.602659 12.447904 8: 10 12 1723 2067 12.125139 13.316883 12.753228 79 26: 44 46 1895 1981 12.753228 13.042468 12.899777 80 81 27: 47 49 2024 2110 13.181453 13.448898 13.316883 82 28: 50 53 2153 2283 13.577635 13.945465 13.764881 9: 12 14 2067 2412 13.316883 14.288198 13.825796 83 29: 54 57 2326 2455 14.062349 14.397371 14.232693 84 85 30: 58 61 2498 2627 14.504172 14.811258 14.660130 86 31: 62 66 2670 2842 14.909464 15.283564 15.100115 10: 15 18 2584 3101 14.711029 15.795819 15.283564 87 32: 67 71 2885 3058 15.372757 15.714074 15.546390 88 89 33: 72 77 3101 3316 15.795819 16.185532 15.994471 90 34: 78 83 3359 3575 16.259980 16.616871 16.441494 11: 18 23 3101 3962 15.795819 17.204658 16.547424 91 35: 84 90 3618 3876 16.685418 17.079349 16.885941 92 93 36: 91 97 3919 4177 17.142352 17.506445 17.327264 94 37: 98 105 4221 4522 17.564981 17.959646 17.765487 12: 23 29 3962 4996 17.204658 18.533945 17.904788 95 38: 106 114 4565 4910 18.014031 18.433233 18.227034 96 97 39: 115 123 4953 5297 18.483782 18.874805 18.682185 98 40: 124 133 5340 5728 18.922095 19.332992 19.130789 13: 29 36 4996 6202 18.533945 19.801451 19.198897 99 41: 134 144 5771 6202 19.377073 19.801451 19.592946 100 101 42: 145 156 6245 6718 19.842285 20.272889 20.061808 102 43: 157 169 6761 7278 20.310373 20.739167 20.529583 14: 36 46 6202 7924 19.801451 21.222342 20.565177 103 44: 170 183 7321 7881 20.773175 21.191895 20.987911 104 105 45: 184 198 7924 8527 21.222342 21.623344 21.428652 106 46: 199 215 8570 9259 21.650236 22.050787 21.857360 15: 46 58 7924 9991 21.222342 22.420001 21.882271 107 47: 216 233 9302 10034 22.074042 22.440072 22.263795 108 109 48- 234 253 10078 10896 22.459969 22.807140 22.640652 110 49: 254 275 10939 11843 22.823891 23.144847 22.991444 16: 59 75 10164 12920 22.499251 23.461146 23.044078 111 50: 276 300 11886 12920 23.158772 23.461146 23.317264 112 113 51: 301 328 12963 14126 23.472530 23.748999 23.617861 114 52: 329 359 14169 15461 23.758199 24.005540 23.888450 17: 75 99 12920 17054 23.461146 24.248491 23.920884 115 53: 360 395 15504 17011 24.012922 24.242660 24.134368 116 117 54: 396 436 17054 18777 24.248491 24.454928 24.357873 118 55: 437 484 18820 20844 24.459492 24.647977 24.559711 18: 99 127 17054 21878 24.248491 24.727775 24.524955 119 56: 485 511 20887 22007 24.651498 24.737100 24.695685 120 */ 121 122 123 /* V A R I A B L E S */ 124 float MinVal [PART_LONG]; // contains minimum tonality soffsets 125 float Loudness [PART_LONG]; // weighting factors for loudness calculation 126 float SPRD [PART_LONG] [PART_LONG]; // tabulated spreading function 127 float O_MAX; 128 float O_MIN; 129 float FAC1; 130 float FAC2; // constants for offset calculation 131 float partLtq [PART_LONG]; // threshold in quiet (partitions) 132 float invLtq [PART_LONG]; // inverse threshold in quiet (partitions, long) 133 float fftLtq [512]; // threshold in quiet (FFT) 134 float Ltq_offset; // Offset for threshold in quiet 135 float Ltq_max; // maximum level for threshold in quiet 136 float TMN; 137 float NMT; 138 float TransDetect; 139 unsigned int EarModelFlag; 140 int MinValChoice; 141 20 #include "libmpcpsy.h" 21 22 #include <math.h> 142 23 143 24 /* … … 156 37 * third = 1/12 157 38 * octave = 1/40 decade 158 * rest is linear interpolated, values are currently in millibel rel. 20 µPa39 * rest is linear interpolated, values are currently in millibel rel. 20 Pa 159 40 */ 160 41 static short tab [] = { … … 216 97 // calculation of the threshold in quiet in FFT-resolution 217 98 static void 218 Ruhehoerschwelle ( unsigned int EarModelFlag, 99 Ruhehoerschwelle ( PsyModel* m, 100 unsigned int EarModelFlag, 219 101 int Ltq_offset, 220 102 int Ltq_max ) … … 228 110 229 111 for ( n = 0; n < 512; n++ ) { 230 f = (float) ( (n+1) * (float)(SampleFreq / 2000.) / 512 ); // Frequency in kHz112 f = (float) ( (n+1) * (float)(m->SampleFreq / 2000.) / 512 ); // Frequency in kHz 231 113 232 114 switch ( EarModelFlag / 100 ) { … … 235 117 break; 236 118 default: 237 case 1: // measured threshold in quiet (Nick Berglmeir, Andree Buschmann, Kopfh örer)119 case 1: // measured threshold in quiet (Nick Berglmeir, Andree Buschmann, Kopfhï¿œer) 238 120 tmp = 3.00*pow (f,-0.8) - 5.0*exp (-0.1*(f-3.0)*(f-3.0)) + 0.0000015022693846297*pow (f, 6.0) + 10.*exp (-(f-0.1)*(f-0.1)); 239 121 break; 240 case 2: // measured threshold in quiet (Filburt, Kopfh örer)122 case 2: // measured threshold in quiet (Filburt, Kopfhï¿œer) 241 123 tmp = 9.00*pow (f,-0.5) - 15.0*exp (-0.1*(f-4.0)*(f-4.0)) + 0.0341796875*pow (f, 2.5) + 15.*exp (-(f-0.1)*(f-0.1)) - 18; 242 124 tmp = mind ( tmp, Ltq_max - 18 ); … … 264 146 tmp = mind ( tmp, Ltq_max ); // Limit ATH 265 147 tmp += Ltq_offset - 23; // Add chosen Offset 266 fftLtq[n] = absLtq[n] = POW10 ( 0.1 * tmp); // conversion into power148 m->fftLtq[n] = absLtq[n] = POW10 ( 0.1 * tmp); // conversion into power 267 149 } 268 150 … … 273 155 erg = minf (erg, absLtq[k]); 274 156 275 276 invLtq [n] = 1.f /partLtq[n]; // Inverse157 m->partLtq[n] = erg; // threshold in quiet 158 m->invLtq [n] = 1.f / m->partLtq[n]; // Inverse 277 159 } 278 160 } … … 300 182 301 183 static double 302 LongPart2Bark ( int Part )303 { 304 return Freq2Bark ((wl [Part] + wh [Part]) *SampleFreq / 2048.);184 LongPart2Bark ( PsyModel* m, int Part ) 185 { 186 return Freq2Bark ((wl [Part] + wh [Part]) * m->SampleFreq / 2048.); 305 187 } 306 188 307 189 // calculating the table for loudness calculation based on absLtq = ank 308 190 static void 309 Loudness_Tabelle ( void)191 Loudness_Tabelle (PsyModel* m) 310 192 { 311 193 int n; … … 315 197 // ca. dB(A) 316 198 for ( n = 0; n < PART_LONG; n++ ){ 317 midfreq = (wh[n] + wl[n] + 3) * (0.25 *SampleFreq / 512); // center frequency in kHz, why +3 ???199 midfreq = (wh[n] + wl[n] + 3) * (0.25 * m->SampleFreq / 512); // center frequency in kHz, why +3 ??? 318 200 tmp = LOG10 (midfreq) - 3.5f; // dB(A) 319 201 tmp = -10 * tmp * tmp + 3 - midfreq/3000; 320 202 m->Loudness [n] = POW10 ( 0.1 * tmp ); // conversion into power 321 203 } 322 204 } … … 370 252 // calculating the coefficient for utilization of the tonality offset, depending on TMN und NMT 371 253 static void 372 Tonalitaetskoeffizienten ( void)254 Tonalitaetskoeffizienten ( PsyModel* m ) 373 255 { 374 256 double tmp; … … 376 258 float bass; 377 259 378 bass = 0.1/8 *NMT;379 if (MinValChoice <= 2 && bass > 0.1 )260 bass = 0.1/8 * m->NMT; 261 if ( m->MinValChoice <= 2 && bass > 0.1 ) 380 262 bass = 0.1f; 381 if (MinValChoice <= 1 )263 if ( m->MinValChoice <= 1 ) 382 264 bass = 0.0f; 383 265 384 266 // alternative: calculation of the minval-values dependent on TMN and TMN 385 267 for ( n = 0; n < PART_LONG; n++ ) { 386 tmp = Bass ( (wl [n] + wh [n]) / 2048. * SampleFreq, TMN,NMT, bass );387 268 tmp = Bass ( (wl [n] + wh [n]) / 2048. * m->SampleFreq, m->TMN, m->NMT, bass ); 269 m->MinVal [n] = POW10 ( -0.1 * tmp ); // conversion into power 388 270 } 389 271 390 272 // calculation of the constants for "tonality offset" 391 O_MAX = POW10 ( -0.1 *TMN );392 O_MIN = POW10 ( -0.1 *NMT );393 FAC1 = POW10 ( -0.1 * (NMT - (TMN -NMT) * 0.229) ) ;394 FAC2 = (TMN -NMT) * (0.99011159 * 0.1);273 m->O_MAX = POW10 ( -0.1 * m->TMN ); 274 m->O_MIN = POW10 ( -0.1 * m->NMT ); 275 m->FAC1 = POW10 ( -0.1 * (m->NMT - (m->TMN - m->NMT) * 0.229) ) ; 276 m->FAC2 = (m->TMN - m->NMT) * (0.99011159 * 0.1); 395 277 } 396 278 … … 398 280 // calculation of the spreading function 399 281 static void 400 Spread ( void)282 Spread ( PsyModel* m ) 401 283 { 402 284 int i; … … 410 292 for ( i = 0; i < PART_LONG; i++ ) { // i is masking Partition, Source 411 293 for ( j = 0; j < PART_LONG; j++ ) { // j is masking Partition, Target 412 tmpx = LongPart2Bark ( j) - LongPart2Bark (i);// Difference of the partitions in Bark294 tmpx = LongPart2Bark (m, j) - LongPart2Bark (m, i);// Difference of the partitions in Bark 413 295 tmpy = tmpz = 0.; // tmpz = 0: no dip 414 296 … … 422 304 #else 423 305 x = i ? wl[i]+wh[i] : 1; 424 x *= SampleFreq / 1000. / 2048; // center frequency in kHz306 x *= m->SampleFreq / 1000. / 2048; // center frequency in kHz 425 307 #endif 426 308 // dB/Bark … … 432 314 433 315 // calculate coefficient 434 316 m->SPRD[i][j] = POW10 ( -0.1 * (tmpy+tmpz) ); // [Source] [Target] 435 317 } 436 318 } … … 440 322 float norm = 0.f; 441 323 for ( j = 0; j < PART_LONG; j++ ) // j is masking Partition 442 norm +=SPRD [j] [i];324 norm += m->SPRD [j] [i]; 443 325 for ( j = 0; j < PART_LONG; j++ ) // j is masking Partition 444 326 m->SPRD [j] [i] /= norm; 445 327 } 446 328 } … … 448 330 // call all initialisation procedures 449 331 void 450 Init_Psychoakustiktabellen ( void)451 { 452 Max_Band = (int) ( Bandwidth * 64. /SampleFreq );453 if ( Max_Band < 1 )Max_Band = 1;454 if ( Max_Band > 31 )Max_Band = 31;455 456 Tonalitaetskoeffizienten ( );457 Ruhehoerschwelle ( EarModelFlag, Ltq_offset,Ltq_max );458 Loudness_Tabelle ( );459 Spread ( );332 Init_Psychoakustiktabellen ( PsyModel* m ) 333 { 334 m->Max_Band = (int) ( m->Bandwidth * 64. / m->SampleFreq ); 335 if ( m->Max_Band < 1 ) m->Max_Band = 1; 336 if ( m->Max_Band > 31 ) m->Max_Band = 31; 337 338 Tonalitaetskoeffizienten (m); 339 Ruhehoerschwelle ( m, m->EarModelFlag, m->Ltq_offset, m->Ltq_max ); 340 Loudness_Tabelle (m); 341 Spread (m); 460 342 } 461 343
Note: See TracChangeset
for help on using the changeset viewer.