00001 #include <stdio.h> 00002 #include <math.h> 00003 #include "common.h" 00004 #include "ath.h" 00005 00006 /* freq in hz */ 00007 FLOAT8 ATH_dB(FLOAT8 f, FLOAT8 value) 00008 { 00009 /* from Painter & Spanias 00010 modified by Gabriel Bouvigne to better fit the reality 00011 ath = 3.640 * pow(f,-0.8) 00012 - 6.800 * exp(-0.6*pow(f-3.4,2.0)) 00013 + 6.000 * exp(-0.15*pow(f-8.7,2.0)) 00014 + 0.6* 0.001 * pow(f,4.0); 00015 00016 00017 In the past LAME was using the Painter &Spanias formula. 00018 But we had some recurrent problems with HF content. 00019 We measured real ATH values, and found the older formula 00020 to be inacurate in the higher part. So we made this new 00021 formula and this solved most of HF problematic testcases. 00022 The tradeoff is that in VBR mode it increases a lot the 00023 bitrate.*/ 00024 00025 00026 /*this curve can be udjusted according to the VBR scale: 00027 it adjusts from something close to Painter & Spanias 00028 on V9 up to Bouvigne's formula for V0. This way the VBR 00029 bitrate is more balanced according to the -V value.*/ 00030 00031 FLOAT8 ath; 00032 FLOAT8 valueold = 0.0; 00033 00034 if (f < -.3) 00035 f=3410; 00036 00037 f /= 1000; // convert to khz 00038 f = MAX(0.01, f); 00039 f = MIN(18.0, f); 00040 00041 ath = 3.640 * pow(f,-0.8) 00042 - 6.800 * exp(-0.6*pow(f-3.4,2.0)) 00043 + 6.000 * exp(-0.15*pow(f-8.7,2.0)) 00044 + (0.6+0.04*valueold)* 0.001 * pow(f,4.0); 00045 00046 /* MFC Feb 2003 00047 I've changed the fudge technique on the code. 00048 The "-l [float]" value raises/lowers the ATH by this many dB */ 00049 return (ath + value); 00050 } 00051 00052 00053 /* Convert ATH values from dB into energy values as required by the psycho model */ 00054 float ATH_energy(float freq, float value) { 00055 float db; 00056 db = ATH_dB(freq, 0) + value; // Originally: ATH_dB(freq,value) 00057 /* The values in the standard, and from the ATH formula are in dB. 00058 In the psycho model we are working in the energy domain. Hence the values that 00059 are in the absthr_X tables are not in dB. This function converts from dB into the energy domain. 00060 As noted on the LAME mailing list from years ago (MFC FIX find the reference), the 00061 absolute threhsold of hearing values in the tables in the standard are dodgy - the 00062 ATH in the tables do not correspond to any previously known values of the ATH. 00063 From ISO 11172 Tables D.4.x 00064 "A value of 0dB represents a level in the absolute threshold calculation of 00065 96dB below the energy of a sine wave of amplitude 32760." 00066 But I still don't know why the factor of 41.837375 is the value that it is. MFC Feb 2003 */ 00067 return(pow(10.0, (db+41.837375)*0.1)); 00068 } 00069 00070 00071 /* Convert a frequency (in Hz) to a bark value 00072 Taken from LAME. MFC Feb 2003 00073 see for example "Zwicker: Psychoakustik, 1982; ISBN 3-540-11401-7 */ 00074 FLOAT8 toolame_freq2bark(FLOAT8 freq) 00075 { 00076 if (freq<0) freq=0; 00077 freq = freq * 0.001; 00078 return 13.0*atan(.76*freq) + 3.5*atan(freq*freq/(7.5*7.5)); 00079 }
1.5.5