Changeset 65 for mppenc/branches/r2d/src/mppenc.c
- Timestamp:
- 10/02/06 20:41:38 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mppenc/branches/r2d/src/mppenc.c
r64 r65 31 31 32 32 /* MS-Coding */ 33 unsigned int MS_Channelmode; // global flag for enhanced functionality34 33 int PredictionBands = 0; 35 34 int CombPenalities = -1; … … 130 129 131 130 static void 132 longhelp ( void)131 longhelp ( PsyModel * m ) 133 132 { 134 133 stderr_printf ( … … 245 244 " --quality x set Quality to x (dflt: 5)\n" ); 246 245 stderr_printf ( 247 " --nmt x set NMT value to x dB (dflt: %4.1f)\n", NMT );248 stderr_printf ( 249 " --tmn x set TMN value to x dB (dflt: %4.1f)\n", TMN );246 " --nmt x set NMT value to x dB (dflt: %4.1f)\n", m->NMT ); 247 stderr_printf ( 248 " --tmn x set TMN value to x dB (dflt: %4.1f)\n", m->TMN ); 250 249 stderr_printf ( 251 250 " --pns x set PNS value to x dB (dflt: %4.1f)\n", PNS ); … … 253 252 "==ATH/Bandwidth settings==\n" ); 254 253 stderr_printf ( 255 " --bw x maximum bandwidth in Hz (dflt: %4.1f kHz)\n", ( Max_Band+1)*(SampleFreq/32000.) );256 stderr_printf ( 257 " --minSMR x minimum SMR of x dB over encoded bandwidth (dflt: %2.1f)\n", m inSMR );254 " --bw x maximum bandwidth in Hz (dflt: %4.1f kHz)\n", (m->Max_Band+1)*(m->SampleFreq/32000.) ); 255 stderr_printf ( 256 " --minSMR x minimum SMR of x dB over encoded bandwidth (dflt: %2.1f)\n", m->minSMR ); 258 257 stderr_printf ( 259 258 " --ltq xyy x=0: ISO threshold in quiet (not recommended)\n" … … 265 264 " y=00...99: HF roll-off (00:+30 dB, 99:-30 dB @20 kHz\n" ); 266 265 stderr_printf ( 267 " --ltq_gain x add offset of x dB to chosen ltq (dflt: %+4.1f)\n", Ltq_offset );268 stderr_printf ( 269 " --ltq_max x maximum level for ltq (dflt: %4.1f dB)\n", Ltq_max );270 stderr_printf ( 271 " --ltq_var x adaptive threshold in quiet: 0: off, >0: on (dflt: %g)\n",varLtq);272 stderr_printf ( 273 " --tmpMask x exploit postmasking: 0: off, 1: on (dflt: %i)\n",tmpMask_used );266 " --ltq_gain x add offset of x dB to chosen ltq (dflt: %+4.1f)\n", m->Ltq_offset ); 267 stderr_printf ( 268 " --ltq_max x maximum level for ltq (dflt: %4.1f dB)\n", m->Ltq_max ); 269 stderr_printf ( 270 " --ltq_var x adaptive threshold in quiet: 0: off, >0: on (dflt: %g)\n", m->varLtq ); 271 stderr_printf ( 272 " --tmpMask x exploit postmasking: 0: off, 1: on (dflt: %i)\n", m->tmpMask_used ); 274 273 stderr_printf ( 275 274 "==Stuff settings==========\n" ); … … 277 276 " --ms x Mid/Side Stereo, 0: off, 1: reduced, 2: on, 3: decoupled,\n" 278 277 " 10: enhanced 1.5/3 dB, 11: 2/6 dB, 12: 2.5/9 dB,\n" 279 " 13: 3/12 dB, 15: 3/oo dB (dflt: %i)\n", MS_Channelmode );280 stderr_printf ( 281 " --ans x Adaptive Noise Shaping Order: 0: off, 1...6: on (dflt: %i)\n",NS_Order );282 stderr_printf ( 283 " --cvd x ClearVoiceDetection, 0: off, 1: on, 2: dual (dflt: %i)\n",CVD_used );284 stderr_printf ( 285 " --shortthr x short FFT threshold (dflt: %4.1f)\n",ShortThr );286 stderr_printf ( 287 " --transdet x slewrate for transient detection (dflt: %3.1f)\n", TransDetect );278 " 13: 3/12 dB, 15: 3/oo dB (dflt: %i)\n", m->MS_Channelmode ); 279 stderr_printf ( 280 " --ans x Adaptive Noise Shaping Order: 0: off, 1...6: on (dflt: %i)\n", m->NS_Order ); 281 stderr_printf ( 282 " --cvd x ClearVoiceDetection, 0: off, 1: on, 2: dual (dflt: %i)\n", m->CVD_used ); 283 stderr_printf ( 284 " --shortthr x short FFT threshold (dflt: %4.1f)\n", m->ShortThr ); 285 stderr_printf ( 286 " --transdet x slewrate for transient detection (dflt: %3.1f)\n", m->TransDetect ); 288 287 stderr_printf ( 289 288 " --minval x calculation of MinVal (1:Buschmann, 2,3:Klemm)\n" ); … … 458 457 459 458 static void 460 SCF_Extraktion ( const int MaxBand, SubbandFloatTyp* x )459 SCF_Extraktion ( PsyModel*m, mpc_encoder_t* e, const int MaxBand, SubbandFloatTyp* x ) 461 460 { 462 461 int Band; … … 606 605 tmp_R [1] = invSCF [comp_R[1] - scfR[1]]; 607 606 tmp_R [2] = invSCF [comp_R[2] - scfR[2]]; 608 SNR_comp_L [Band] = (tmp_L[0]*tmp_L[0] + tmp_L[1]*tmp_L[1] + tmp_L[2]*tmp_L[2]) * 0.3333333333f;609 SNR_comp_R [Band] = (tmp_R[0]*tmp_R[0] + tmp_R[1]*tmp_R[1] + tmp_R[2]*tmp_R[2]) * 0.3333333333f;607 m->SNR_comp_L [Band] = (tmp_L[0]*tmp_L[0] + tmp_L[1]*tmp_L[1] + tmp_L[2]*tmp_L[2]) * 0.3333333333f; 608 m->SNR_comp_R [Band] = (tmp_R[0]*tmp_R[0] + tmp_R[1]*tmp_R[1] + tmp_R[2]*tmp_R[2]) * 0.3333333333f; 610 609 611 610 // normalize the subband samples … … 633 632 for ( n = 0; n < 36; n++ ) { 634 633 if (x[Band].L[n] > +32767.f) { 635 Overflows++;634 e->Overflows++; 636 635 MaxOverFlow = maxf (MaxOverFlow, x[Band].L[n]); 637 636 x[Band].L[n] = 32767.f; 638 637 } 639 638 else if (x[Band].L[n] < -32767.f) { 640 639 e->Overflows++; 641 640 MaxOverFlow = maxf (MaxOverFlow, -x[Band].L[n]); 642 641 x[Band].L[n] = -32767.f; … … 646 645 for ( n = 0; n < 36; n++ ) { 647 646 if (x[Band].R[n] > +32767.f) { 648 647 e->Overflows++; 649 648 MaxOverFlow = maxf (MaxOverFlow, x[Band].R[n]); 650 649 x[Band].R[n] = 32767.f; 651 650 } 652 651 else if (x[Band].R[n] < -32767.f) { 653 652 e->Overflows++; 654 653 MaxOverFlow = maxf (MaxOverFlow, -x[Band].R[n]); 655 654 x[Band].R[n] = -32767.f; … … 662 661 663 662 static void 664 Quantisierung ( const int MaxBand, 663 Quantisierung ( PsyModel * m, 664 const int MaxBand, 665 665 const int* resL, 666 666 const int* resR, … … 676 676 677 677 if ( *resL > 0 ) { 678 if ( NS_Order_L [Band] > 0 ) {679 QuantizeSubbandWithNoiseShaping ( subq[Band].L, subx[Band].L, *resL, errorL [Band], FIR_L [Band] );678 if ( m->NS_Order_L [Band] > 0 ) { 679 QuantizeSubbandWithNoiseShaping ( subq[Band].L, subx[Band].L, *resL, errorL [Band], m->FIR_L [Band] ); 680 680 memcpy ( errorL [Band], errorL[Band] + 36, MAX_NS_ORDER * sizeof (**errorL) ); 681 681 } else { … … 687 687 688 688 if ( *resR > 0 ) { 689 if ( NS_Order_R [Band] > 0 ) {690 QuantizeSubbandWithNoiseShaping ( subq[Band].R, subx[Band].R, *resR, errorR [Band], FIR_R [Band] );689 if ( m->NS_Order_R [Band] > 0 ) { 690 QuantizeSubbandWithNoiseShaping ( subq[Band].R, subx[Band].R, *resR, errorR [Band], m->FIR_R [Band] ); 691 691 memcpy ( errorR [Band], errorR [Band] + 36, MAX_NS_ORDER * sizeof (**errorL) ); 692 692 } else { … … 793 793 } 794 794 795 796 797 798 795 typedef struct { 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 796 float ShortThr; 797 unsigned char MinValChoice; 798 unsigned int EarModelFlag; 799 signed char Ltq_offset; 800 float TMN; 801 float NMT; 802 signed char minSMR; 803 signed char Ltq_max; 804 unsigned short BandWidth; 805 unsigned char tmpMask_used; 806 unsigned char CVD_used; 807 float varLtq; 808 unsigned char MS_Channelmode; 809 unsigned char CombPenalities; 810 unsigned char NS_Order; 811 float PNS; 812 float TransDetect; 816 813 } Profile_Setting_t; 817 818 814 819 815 #define PROFILE_PRE2_TELEPHONE 5 // --quality 0 … … 853 849 854 850 static int 855 TestProfileParams ( void)851 TestProfileParams ( PsyModel* m ) 856 852 { // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 857 853 static signed char TMNStereoAdj [] = { -6, -18, -15, -18, -12, -9, -6, 0,0,0, +1, +1, +1, +1, 0, +1 }; // Penalties for TMN … … 862 858 863 859 for ( i = PROFILE_PRE2_TELEPHONE; i <= PROFILE_POST2_BRAINDEAD; i++ ) { 864 if ( ShortThr > Profiles [i].ShortThr ) continue;865 if ( MinValChoice < Profiles [i].MinValChoice ) continue;866 if ( EarModelFlag < Profiles [i].EarModelFlag ) continue;867 if ( Ltq_offset > Profiles [i].Ltq_offset ) continue;868 if ( Ltq_max > Profiles [i].Ltq_max ) continue; // offset should normally be considered here869 if ( TMN + TMNStereoAdj [MS_Channelmode] <860 if ( m->ShortThr > Profiles [i].ShortThr ) continue; 861 if ( m->MinValChoice < Profiles [i].MinValChoice ) continue; 862 if ( m->EarModelFlag < Profiles [i].EarModelFlag ) continue; 863 if ( m->Ltq_offset > Profiles [i].Ltq_offset ) continue; 864 if ( m->Ltq_max > Profiles [i].Ltq_max ) continue; // offset should normally be considered here 865 if ( m->TMN + TMNStereoAdj [m->MS_Channelmode] < 870 866 Profiles [i].TMN + TMNStereoAdj [Profiles [i].MS_Channelmode] ) 871 867 continue; 872 if ( NMT + NMTStereoAdj [MS_Channelmode] <868 if ( m->NMT + NMTStereoAdj [m->MS_Channelmode] < 873 869 Profiles [i].NMT + NMTStereoAdj [Profiles [i].MS_Channelmode] ) 874 870 continue; 875 if (minSMR < Profiles [i].minSMR ) continue;876 if ( Bandwidth < Profiles [i].BandWidth ) continue;877 if (tmpMask_used < Profiles [i].tmpMask_used ) continue;878 if (CVD_used < Profiles [i].CVD_used ) continue;871 if ( m->minSMR < Profiles [i].minSMR ) continue; 872 if ( m->Bandwidth < Profiles [i].BandWidth ) continue; 873 if ( m->tmpMask_used < Profiles [i].tmpMask_used ) continue; 874 if ( m->CVD_used < Profiles [i].CVD_used ) continue; 879 875 // if ( varLtq > Profiles [i].varLtq ) continue; 880 876 // if ( NS_Order < Profiles [i].NS_Order ) continue; … … 887 883 888 884 static void 889 SetQualityParams ( float qual )885 SetQualityParams (PsyModel * m, float qual ) 890 886 { 891 887 int i; … … 908 904 909 905 MainQual = i; 910 ShortThr = Profiles [i].ShortThr * (1-mix) + Profiles [i+1].ShortThr * mix;911 MinValChoice = Profiles [i].MinValChoice ;912 EarModelFlag = Profiles [i].EarModelFlag ;913 Ltq_offset = Profiles [i].Ltq_offset * (1-mix) + Profiles [i+1].Ltq_offset * mix;914 varLtq = Profiles [i].varLtq * (1-mix) + Profiles [i+1].varLtq * mix;915 Ltq_max = Profiles [i].Ltq_max * (1-mix) + Profiles [i+1].Ltq_max * mix;916 TMN = Profiles [i].TMN * (1-mix) + Profiles [i+1].TMN * mix;917 NMT = Profiles [i].NMT * (1-mix) + Profiles [i+1].NMT * mix;918 m inSMR = Profiles [i].minSMR ;919 Bandwidth = Profiles [i].BandWidth * (1-mix) + Profiles [i+1].BandWidth * mix;920 tmpMask_used = Profiles [i].tmpMask_used ;921 CVD_used = Profiles [i].CVD_used ;922 MS_Channelmode = Profiles [i].MS_Channelmode;906 m->ShortThr = Profiles [i].ShortThr * (1-mix) + Profiles [i+1].ShortThr * mix; 907 m->MinValChoice = Profiles [i].MinValChoice ; 908 m->EarModelFlag = Profiles [i].EarModelFlag ; 909 m->Ltq_offset = Profiles [i].Ltq_offset * (1-mix) + Profiles [i+1].Ltq_offset * mix; 910 m->varLtq = Profiles [i].varLtq * (1-mix) + Profiles [i+1].varLtq * mix; 911 m->Ltq_max = Profiles [i].Ltq_max * (1-mix) + Profiles [i+1].Ltq_max * mix; 912 m->TMN = Profiles [i].TMN * (1-mix) + Profiles [i+1].TMN * mix; 913 m->NMT = Profiles [i].NMT * (1-mix) + Profiles [i+1].NMT * mix; 914 m->minSMR = Profiles [i].minSMR ; 915 m->Bandwidth = Profiles [i].BandWidth * (1-mix) + Profiles [i+1].BandWidth * mix; 916 m->tmpMask_used = Profiles [i].tmpMask_used ; 917 m->CVD_used = Profiles [i].CVD_used ; 918 m->MS_Channelmode = Profiles [i].MS_Channelmode; 923 919 CombPenalities = Profiles [i].CombPenalities; 924 NS_Order = Profiles [i].NS_Order ;920 m->NS_Order = Profiles [i].NS_Order ; 925 921 PNS = Profiles [i].PNS * (1-mix) + Profiles [i+1].PNS * mix; 926 TransDetect = Profiles [i].TransDetect* (1-mix) + Profiles [i+1].TransDetect* mix;922 m->TransDetect = Profiles [i].TransDetect* (1-mix) + Profiles [i+1].TransDetect* mix; 927 923 } 928 924 … … 931 927 932 928 static int 933 EvalParameters ( int argc, char** argv, char** InputFile, char** OutputFile, int onlyfilenames )929 EvalParameters (PsyModel * m, int argc, char** argv, char** InputFile, char** OutputFile, int onlyfilenames ) 934 930 { 935 931 int k; … … 989 985 } 990 986 else if ( 0 == strcmp ( arg, "telephone" ) ) { // MainQual 991 SetQualityParams ( 2.0);987 SetQualityParams (m, 2.0); 992 988 } 993 989 else if ( 0 == strcmp ( arg, "thumb" ) ) { // MainQual 994 SetQualityParams ( 3.0);990 SetQualityParams (m, 3.0); 995 991 } 996 992 else if ( 0 == strcmp ( arg, "radio" ) ) { 997 SetQualityParams ( 4.0);993 SetQualityParams (m, 4.0); 998 994 } 999 995 else if ( 0 == strcmp ( arg, "standard") || 0 == strcmp ( arg, "normal") ) { 1000 SetQualityParams ( 5.0);996 SetQualityParams (m, 5.0); 1001 997 } 1002 998 else if ( 0 == strcmp ( arg, "xtreme") || 0 == strcmp ( arg, "extreme") ) { 1003 SetQualityParams ( 6.0);999 SetQualityParams (m, 6.0); 1004 1000 } 1005 1001 else if ( 0 == strcmp ( arg, "insane") ) { 1006 SetQualityParams ( 7.0);1002 SetQualityParams (m, 7.0); 1007 1003 } 1008 1004 else if ( 0 == strcmp ( arg, "braindead") ) { 1009 SetQualityParams ( 8.0);1005 SetQualityParams (m, 8.0); 1010 1006 } 1011 1007 else if ( 0 == strcmp ( arg, "quality") ) { // Quality 1012 1008 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1013 SetQualityParams ( atof (argv[k]) );1009 SetQualityParams (m, atof (argv[k]) ); 1014 1010 } 1015 1011 else if ( 0 == strcmp ( arg, "neveroverwrite") ) { // NeverOverWrite … … 1037 1033 else if ( 0 == strcmp ( arg, "kbd") ) { // ScalingFactor 1038 1034 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1039 if ( 2 != sscanf ( argv[k], "%f,%f", &KBD1, &KBD2))1035 if ( 2 != sscanf ( argv[k], "%f,%f", &(m->KBD1), &(m->KBD2) )) 1040 1036 { stderr_printf ( "%s: missing two arguments", arg ); return -1; } 1041 1037 Init_FFT (); … … 1073 1069 else if ( 0 == strcmp ( arg, "ans") ) { // AdaptiveNoiseShaping 1074 1070 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1075 NS_Order = atoi (argv[k]);1076 NS_Order = mini (NS_Order, MAX_NS_ORDER );1071 m->NS_Order = atoi (argv[k]); 1072 m->NS_Order = mini ( m->NS_Order, MAX_NS_ORDER ); 1077 1073 } 1078 1074 else if ( 0 == strcmp ( arg, "predict") ) { // AdaptiveNoiseShaping … … 1083 1079 else if ( 0 == strcmp ( arg, "ltq_var") || 0 == strcmp ( arg, "ath_var") ) { // ltq_var 1084 1080 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1085 varLtq = atof (argv[k]);1081 m->varLtq = atof (argv[k]); 1086 1082 } 1087 1083 else if ( 0 == strcmp ( arg, "pns") ) { // pns … … 1091 1087 else if ( 0 == strcmp ( arg, "minval") ) { // MinValChoice 1092 1088 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1093 MinValChoice = atoi (argv[k]);1089 m->MinValChoice = atoi (argv[k]); 1094 1090 } 1095 1091 else if ( 0 == strcmp ( arg, "transdet") ) { // TransDetect 1096 1092 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1097 TransDetect = (float) atof (argv[k]);1093 m->TransDetect = (float) atof (argv[k]); 1098 1094 } 1099 1095 else if ( 0 == strcmp ( arg, "shortthr") ) { // ShortThr 1100 1096 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1101 ShortThr = (float) atof (argv[k]);1097 m->ShortThr = (float) atof (argv[k]); 1102 1098 } 1103 1099 else if ( 0 == strcmp ( arg, "noxlevel") ) { // Xlevel … … 1109 1105 else if ( 0 == strcmp ( arg, "nmt") ) { // NMT 1110 1106 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1111 NMT = (float) atof (argv[k]);1107 m->NMT = (float) atof (argv[k]); 1112 1108 } 1113 1109 else if ( 0 == strcmp ( arg, "tmn") ) { // TMN 1114 1110 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1115 TMN = (float) atof (argv[k]);1111 m->TMN = (float) atof (argv[k]); 1116 1112 } 1117 1113 else if ( 0 == strcmp ( arg, "cvd") ) { // ClearVoiceDetection 1118 1114 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1119 CVD_used = atoi (argv[k]);1120 if ( CVD_used == 0 )1115 m->CVD_used = atoi (argv[k]); 1116 if ( m->CVD_used == 0 ) 1121 1117 stderr_printf ( "\nDisabling CVD always reduces quality!\a\n" ); 1122 1118 } 1123 1119 else if ( 0 == strcmp ( arg, "ms") ) { // Mid/Side Stereo 1124 1120 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1125 MS_Channelmode = atoi (argv[k]);1121 m->MS_Channelmode = atoi (argv[k]); 1126 1122 } 1127 1123 else if ( 0 == strcmp ( arg, "minSMR") ) { // minimum SMR 1128 1124 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1129 if ( m inSMR > (float) atof (argv[k]) )1125 if ( m->minSMR > (float) atof (argv[k]) ) 1130 1126 stderr_printf ( "This option usage may reduces quality!\a\n" ); 1131 m inSMR = (float) atof (argv[k]);1127 m->minSMR = (float) atof (argv[k]); 1132 1128 } 1133 1129 else if ( 0 == strcmp ( arg, "tmpMask") ) { // temporal post-masking 1134 1130 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1135 tmpMask_used = atoi (argv[k]);1131 m->tmpMask_used = atoi (argv[k]); 1136 1132 } 1137 1133 else if ( 0 == strcmp ( arg, "ltq_max") || 0 == strcmp ( arg, "ath_max") ) { // Maximum for threshold in quiet 1138 1134 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1139 1135 m->Ltq_max = (float) atof (argv[k]); 1140 1136 } 1141 1137 else if ( 0 == strcmp ( arg, "ltq_gain") || 0 == strcmp ( arg, "ath_gain") ) {// Offset for threshold in quiet 1142 1138 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1143 1139 m->Ltq_offset = (float) atof (argv[k]); 1144 1140 } 1145 1141 else if ( 0 == strcmp ( arg, "silent") || 0 == strcmp ( arg, "quiet") ) { … … 1152 1148 else if ( 0 == strcmp ( arg, "ltq") || 0 == strcmp ( arg, "ath") ) { // threshold in quiet 1153 1149 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1154 EarModelFlag = atoi (argv[k]);1150 m->EarModelFlag = atoi (argv[k]); 1155 1151 } 1156 1152 else if ( 0 == strcmp ( arg, "noco") ) { … … 1178 1174 else if ( 0 == strcmp ( arg, "bw") || 0 == strcmp ( arg, "lowpass") ) { // bandwidth 1179 1175 if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; } 1180 1176 m->Bandwidth = atof (argv[k]); 1181 1177 } 1182 1178 else if ( 0 == strcmp ( arg, "displayupdatetime") ) { … … 1353 1349 } 1354 1350 1355 TestProfileParams ( );1351 TestProfileParams (m); 1356 1352 return 0; 1357 1353 } … … 1359 1355 1360 1356 static void 1361 ShowParameters ( char* inDatei, char* outDatei )1357 ShowParameters (PsyModel * m, char* inDatei, char* outDatei ) 1362 1358 { 1363 1359 static const char unk [] = "???"; … … 1399 1395 if ( ScalingFactorr != 1. || ScalingFactorl != 1. || verbose > 1 ) 1400 1396 stderr_printf ( " Scaling input by : left %.5f, right: %.5f\n", ScalingFactorl, ScalingFactorr ); 1401 stderr_printf ( " Maximum encoded bandwidth: %4.1f kHz\n", ( Max_Band+1) * (SampleFreq/32./2000.) );1402 stderr_printf ( " Adaptive Noise Shaping : max. %s order\n", th [ NS_Order] );1403 stderr_printf ( " Clear Voice Detection : %s\n", able [ CVD_used] );1404 stderr_printf ( " Mid/Side Stereo : %s\n", stereo [ MS_Channelmode] );1397 stderr_printf ( " Maximum encoded bandwidth: %4.1f kHz\n", (m->Max_Band+1) * (m->SampleFreq/32./2000.) ); 1398 stderr_printf ( " Adaptive Noise Shaping : max. %s order\n", th [m->NS_Order] ); 1399 stderr_printf ( " Clear Voice Detection : %s\n", able [m->CVD_used] ); 1400 stderr_printf ( " Mid/Side Stereo : %s\n", stereo [m->MS_Channelmode] ); 1405 1401 stderr_printf ( " Threshold of Hearing : Model %3u: %s, Max ATH: %2.0f dB, Offset: %+1.0f dB, +Offset@20 kHz:%3.0f dB\n", 1406 EarModelFlag,1407 EarModelFlag/100 < sizeof(EarModel)/sizeof(*EarModel) ? EarModel [EarModelFlag/100] : unk,1408 Ltq_max,1409 Ltq_offset,1410 -0.6 * (int) ( EarModelFlag % 100 - 50) );1411 if (NMT != 6.5 || verbose > 1 )1412 stderr_printf ( " Noise masks Tone Ratio : %4.1f dB\n",NMT );1413 if (TMN != 18.0 || verbose > 1 )1414 stderr_printf ( " Tone masks Noise Ratio : %4.1f dB\n",TMN );1402 m->EarModelFlag, 1403 m->EarModelFlag/100 < sizeof(EarModel)/sizeof(*EarModel) ? EarModel [m->EarModelFlag/100] : unk, 1404 m->Ltq_max, 1405 m->Ltq_offset, 1406 -0.6 * (int) (m->EarModelFlag % 100 - 50) ); 1407 if ( m->NMT != 6.5 || verbose > 1 ) 1408 stderr_printf ( " Noise masks Tone Ratio : %4.1f dB\n", m->NMT ); 1409 if ( m->TMN != 18.0 || verbose > 1 ) 1410 stderr_printf ( " Tone masks Noise Ratio : %4.1f dB\n", m->TMN ); 1415 1411 if ( PNS > 0 ) 1416 1412 stderr_printf ( " PNS Threshold : %4.2f\n", PNS ); 1417 if ( !tmpMask_used )1413 if ( !m->tmpMask_used ) 1418 1414 stderr_printf ( " No exploitation of temporal post masking\n" ); 1419 1415 else if ( verbose > 1 ) 1420 1416 stderr_printf ( " Exploitation of temporal post masking\n" ); 1421 if (minSMR > 0. )1422 stderr_printf ( " Minimum Signal-to-Mask : %4.1f dB\n",minSMR );1417 if ( m->minSMR > 0. ) 1418 stderr_printf ( " Minimum Signal-to-Mask : %4.1f dB\n", m->minSMR ); 1423 1419 else if ( verbose > 1 ) 1424 1420 stderr_printf ( " No minimum SMR (psycho model controlled filtering)\n" ); … … 1440 1436 1441 1437 static const char* 1442 PrintTime ( UintMax_t samples, int sign )1438 PrintTime ( PsyModel* m, UintMax_t samples, int sign ) 1443 1439 { 1444 1440 static char ret [32]; 1445 Ulong tmp = (Ulong) ( UintMAX_FP(samples) * 100. /SampleFreq );1441 Ulong tmp = (Ulong) ( UintMAX_FP(samples) * 100. / m->SampleFreq ); 1446 1442 Uint hour = (Uint) ( tmp / 360000 ); 1447 1443 Uint min = (Uint) ( tmp / 6000 % 60 ); … … 1450 1446 1451 1447 1452 if ( UintMAX_FP(samples) >=SampleFreq * 360000. )1448 if ( UintMAX_FP(samples) >= m->SampleFreq * 360000. ) 1453 1449 return " "; 1454 1450 else if ( hour > 9 ) … … 1467 1463 1468 1464 static void 1469 ShowProgress ( UintMax_t samples, 1465 ShowProgress ( PsyModel* m, 1466 UintMax_t samples, 1470 1467 UintMax_t total_samples, 1471 1468 UintMax_t databits ) … … 1491 1488 1492 1489 percent = 100.f * UintMAX_FP(samples) / UintMAX_FP(total_samples); 1493 kbps = 1.e-3f * UintMAX_FP(databits) *SampleFreq / UintMAX_FP(samples);1494 speed = 1.f * UintMAX_FP(samples) * (CLOCKS_PER_SEC /SampleFreq) / (unsigned long)(curr - start) ;1490 kbps = 1.e-3f * UintMAX_FP(databits) * m->SampleFreq / UintMAX_FP(samples); 1491 speed = 1.f * UintMAX_FP(samples) * (CLOCKS_PER_SEC / m->SampleFreq) / (unsigned long)(curr - start) ; 1495 1492 total_estim = 1.f * UintMAX_FP(total_samples) / UintMAX_FP(samples) * (unsigned long)(curr - start); 1496 1493 … … 1508 1505 1509 1506 // 2x duration in WAVE file time (encoded/total) 1510 stderr_printf ("%10.10s" , PrintTime ( samples , (char)' ')+1 );1511 stderr_printf ("%10.10s ", PrintTime ( total_samples, (char)' ')+1 );1507 stderr_printf ("%10.10s" , PrintTime ( m, samples , (char)' ')+1 ); 1508 stderr_printf ("%10.10s ", PrintTime ( m, total_samples, (char)' ')+1 ); 1512 1509 1513 1510 // 2x coding time (encoded/total) 1514 stderr_printf ("%10.10s" , PrintTime ( (curr - start) * (SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 );1515 stderr_printf ("%10.10s ", PrintTime ( total_estim * (SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 );1511 stderr_printf ("%10.10s" , PrintTime ( m, (curr - start) * (m->SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 ); 1512 stderr_printf ("%10.10s ", PrintTime ( m, total_estim * (m->SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 ); 1516 1513 1517 1514 // ETA 1518 stderr_printf ( "%10.10s\r", samples < total_samples ? PrintTime ((total_estim - curr + start) * (SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 : "" );1515 stderr_printf ( "%10.10s\r", samples < total_samples ? PrintTime (m, (total_estim - curr + start) * (m->SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 : "" ); 1519 1516 fflush ( stderr ); 1520 1517 … … 1542 1539 unsigned n; 1543 1540 for(n=0;n<count;n++) buffer[n] = val; 1541 } 1542 1543 1544 void 1545 OverdriveReport ( mpc_encoder_t * e ) 1546 { 1547 if ( e->Overflows > 0 ) { // report internal clippings 1548 if ( XLevel == 0 ) { 1549 stderr_printf ( "\n" 1550 "\033[1m\rWARNING:\n" 1551 "\033[0m\r There occured %u internal clippings due to a restriction of StreamVersion 7.\n" 1552 " Re-encode with '--scale %.3f', or use option '--xlevel', which normally can\n" 1553 " handle this situation but don't work well with old decoders.\a\n\n", 1554 e->Overflows, ScalingFactorl * 32767. / MaxOverFlow - 0.0005f ); 1555 } 1556 else { 1557 stderr_printf ( "\n" 1558 "\033[1m\rWARNING:\n" 1559 "\033[0m\r There still occured %u SCF clippings due to a restriction of StreamVersion 7.\n" 1560 " Use the '--scale' method to avoid additional distortions. Note that this\n" 1561 " file already has annoying distortions due to slovenly CD mastering.\a\n\n", e->Overflows ); 1562 } 1563 } 1544 1564 } 1545 1565 … … 1569 1589 int TransientR [PART_SHORT]; // Flag of transient detection 1570 1590 int Transient [32]; // Flag of transient detection 1571 1591 PsyModel m; 1592 mpc_encoder_t e; 1593 1594 // initialize tables which must be initialized once and only once 1595 #ifdef FAST_MATH 1596 Init_FastMath (); // check if something has to be done for each file !! 1597 #endif 1598 Init_SV7 (); 1599 Init_Psychoakustiktabellen (&m); 1600 Init_Skalenfaktoren (); 1601 Init_Psychoakustik (&m); 1602 Init_FPU (); 1603 Init_ANS (); 1604 Klemm (); 1572 1605 1573 1606 // initialize PCM-data … … 1575 1608 1576 1609 // open WAV file 1577 if ( EvalParameters ( argc, argv, &InputName, &OutputName, 1 ) < 0 )1610 if ( EvalParameters (&m, argc, argv, &InputName, &OutputName, 1 ) < 0 ) 1578 1611 return 1; 1579 1612 if ( Open_WAV_Header ( &Wave, InputName ) < 0 ) { … … 1590 1623 } 1591 1624 1592 SampleFreq = Wave.SampleFreq;1625 m.SampleFreq = Wave.SampleFreq; 1593 1626 SamplesInWAVE = Wave.PCMSamples; 1594 1627 … … 1617 1650 } 1618 1651 1619 SetQualityParams ( 5.0);1620 1621 if ( EvalParameters ( argc, argv, &InputName, &OutputName, 0 ) < 0 )1652 SetQualityParams (&m, 5.0); 1653 1654 if ( EvalParameters (&m, argc, argv, &InputName, &OutputName, 0 ) < 0 ) 1622 1655 return 1; 1623 1656 … … 1626 1659 } 1627 1660 1628 Init_Psychoakustiktabellen ( ); // must be done AFTER decoding command line parameters1661 Init_Psychoakustiktabellen (&m); // must be done AFTER decoding command line parameters 1629 1662 1630 1663 // check fade-length … … 1684 1717 #endif 1685 1718 1686 ShowParameters ( InputName, OutputName );1719 ShowParameters (&m, InputName, OutputName ); 1687 1720 if ( WIN32_MESSAGES && FrontendPresent ) 1688 1721 SendModeMessage (MainQual); 1689 1722 1690 1723 if ( SkipTime > 0. ) { 1691 unsigned long SkipSamples = SampleFreq * SkipTime;1724 unsigned long SkipSamples = m.SampleFreq * SkipTime; 1692 1725 ssize_t read; 1693 1726 … … 1701 1734 } 1702 1735 1703 BufferedBits = 0;1736 e.BufferedBits = 0; 1704 1737 LastValidFrame = (SamplesInWAVE + BLOCK - 1) / BLOCK; 1705 1738 LastValidSamples = (SamplesInWAVE + BLOCK - 1) - BLOCK * LastValidFrame + 1; 1706 WriteHeader_SV7 ( Max_Band, MainQual, MS_Channelmode > 0, LastValidFrame, LastValidSamples, PNS > 0 ? 0x17 : 0x07,SampleFreq );1739 WriteHeader_SV7 ( m.Max_Band, MainQual, m.MS_Channelmode > 0, LastValidFrame, LastValidSamples, PNS > 0 ? 0x17 : 0x07, m.SampleFreq ); 1707 1740 1708 1741 // initialize timer 1709 ShowProgress ( 0, SamplesInWAVE,BufferedBits );1742 ShowProgress (&m, 0, SamplesInWAVE, e.BufferedBits ); 1710 1743 T = time ( NULL ); 1711 1744 … … 1722 1755 } 1723 1756 1724 Analyse_Init ( Main.L[CENTER], Main.R[CENTER], X, Max_Band );1757 Analyse_Init ( Main.L[CENTER], Main.R[CENTER], X, m.Max_Band ); 1725 1758 1726 1759 // adapt SamplesInWAVE to the real number of contained samples 1727 1760 if ( myfeof (Wave.fp) ) { 1728 1761 stderr_printf ( "WAVE file has incorrect header: header: %.3f s, contents: %.3f s \n", 1729 UintMAX_FP(AllSamplesRead) / SampleFreq, UintMAX_FP(SamplesInWAVE) /SampleFreq );1762 UintMAX_FP(AllSamplesRead) / m.SampleFreq, UintMAX_FP(SamplesInWAVE) / m.SampleFreq ); 1730 1763 SamplesInWAVE = AllSamplesRead; 1731 1764 … … 1766 1799 1767 1800 if ( !Silence || !OldSilence ) { 1768 Analyse_Filter ( &Main, X, Max_Band ); // Analysis-Filterbank (Main -> X)1769 SMR = Psychoakustisches_Modell (Max_Band*0+31, &Main, TransientL, TransientR ); // Psychoacoustics return SMRs for input data 'Main'1770 if ( m inSMR > 0 )1771 RaiseSMR (Max_Band, &SMR ); // Minimum-operation on SBRs (full bandwidth)1772 if (MS_Channelmode > 0 )1773 MS_LR_Entscheidung (Max_Band, MS_Flag, &SMR, X ); // Selection of M/S- or L/R-Coding1774 SCF_Extraktion (Max_Band, X ); // Extraction of the scalefactors and normalization of the subband samples1801 Analyse_Filter ( &Main, X, m.Max_Band ); // Analysis-Filterbank (Main -> X) 1802 SMR = Psychoakustisches_Modell (&m, m.Max_Band*0+31, &Main, TransientL, TransientR ); // Psychoacoustics return SMRs for input data 'Main' 1803 if ( m.minSMR > 0 ) 1804 RaiseSMR (&m, m.Max_Band, &SMR ); // Minimum-operation on SBRs (full bandwidth) 1805 if ( m.MS_Channelmode > 0 ) 1806 MS_LR_Entscheidung ( m.Max_Band, MS_Flag, &SMR, X ); // Selection of M/S- or L/R-Coding 1807 SCF_Extraktion (&m, &e, m.Max_Band, X ); // Extraction of the scalefactors and normalization of the subband samples 1775 1808 TransientenCalc ( Transient, TransientL, TransientR ); 1776 if (NS_Order > 0 ) {1777 NS_Analyse (Max_Band, MS_Flag, SMR, Transient ); // calculate possible ANS-Filter and the expected gain1809 if ( m.NS_Order > 0 ) { 1810 NS_Analyse (&m, m.Max_Band, MS_Flag, SMR, Transient ); // calculate possible ANS-Filter and the expected gain 1778 1811 } 1779 1812 1780 Allocate ( Max_Band, Res_L, X[0].L, SCF_Index_L[0],SNR_comp_L, SMR.L, Power_L, Transient ); // allocate bits for left + right channel1781 Allocate ( Max_Band, Res_R, X[0].R, SCF_Index_R[0],SNR_comp_R, SMR.R, Power_R, Transient );1782 1783 Quantisierung (Max_Band, Res_L, Res_R, X, Q ); // quantize samples1784 } 1785 1786 if ( Zaehler >= BUFFER_ALMOST_FULL || LowDelay ) {1787 FlushBitstream ( OutputFile, Buffer,Zaehler );1788 Zaehler = 0;1813 Allocate ( m.Max_Band, Res_L, X[0].L, SCF_Index_L[0], m.SNR_comp_L, SMR.L, Power_L, Transient ); // allocate bits for left + right channel 1814 Allocate ( m.Max_Band, Res_R, X[0].R, SCF_Index_R[0], m.SNR_comp_R, SMR.R, Power_R, Transient ); 1815 1816 Quantisierung (&m, m.Max_Band, Res_L, Res_R, X, Q ); // quantize samples 1817 } 1818 1819 if ( e.Zaehler >= BUFFER_ALMOST_FULL || LowDelay ) { 1820 FlushBitstream ( OutputFile, e.Buffer, e.Zaehler ); 1821 e.Zaehler = 0; 1789 1822 } 1790 1823 1791 1824 OldSilence = Silence; 1792 OldBufferedBits = BufferedBits;1825 OldBufferedBits = e.BufferedBits; 1793 1826 GetBitstreamPos ( &bitstreampos ); 1794 1827 WriteBits ( 0, 20 ); // Reserve 20 bits for jump-information 1795 WriteBitstream_SV7 ( Max_Band, Q ); // write SV7-Bitstream1796 WriteBitsAt ( (Uint32_t)( BufferedBits - OldBufferedBits - 20), 20, bitstreampos ); // Patch 20 bits for jump-information to the right value1828 WriteBitstream_SV7 ( m.Max_Band, Q ); // write SV7-Bitstream 1829 WriteBitsAt ( (Uint32_t)(e.BufferedBits - OldBufferedBits - 20), 20, bitstreampos ); // Patch 20 bits for jump-information to the right value 1797 1830 1798 1831 if ( (Int)(time (NULL) - T) >= 0 ) { // output 1799 1832 T += labs (DisplayUpdateTime); 1800 ShowProgress ( (UintMax_t)(N+1) * BLOCK, SamplesInWAVE,BufferedBits );1833 ShowProgress (&m, (UintMax_t)(N+1) * BLOCK, SamplesInWAVE, e.BufferedBits ); 1801 1834 } 1802 1835 … … 1821 1854 if ( myfeof (Wave.fp) ) { 1822 1855 stderr_printf ( "WAVE file has incorrect header: header: %.3f s, contents: %.3f s \n", 1823 UintMAX_FP(AllSamplesRead) / SampleFreq, UintMAX_FP(SamplesInWAVE) /SampleFreq );1856 UintMAX_FP(AllSamplesRead) / m.SampleFreq, UintMAX_FP(SamplesInWAVE) / m.SampleFreq ); 1824 1857 SamplesInWAVE = AllSamplesRead; 1825 1858 … … 1843 1876 // write the last incomplete word to buffer, so it's written during the next flush 1844 1877 FinishBitstream(); 1845 ShowProgress ( SamplesInWAVE, SamplesInWAVE,BufferedBits );1846 1847 FlushBitstream ( OutputFile, Buffer,Zaehler );1848 Zaehler = 0;1878 ShowProgress (&m, SamplesInWAVE, SamplesInWAVE, e.BufferedBits ); 1879 1880 FlushBitstream ( OutputFile, e.Buffer, e.Zaehler ); 1881 e.Zaehler = 0; 1849 1882 1850 1883 UpdateHeader ( OutputFile, LastValidFrame, LastValidSamples ); … … 1862 1895 1863 1896 stderr_printf ( "\n" ); 1897 1898 OverdriveReport (&e); // output a report if clipping was necessary 1899 1864 1900 return 0; 1865 }1866 1867 1868 void1869 OverdriveReport ( void )1870 {1871 if ( Overflows > 0 ) { // report internal clippings1872 if ( XLevel == 0 ) {1873 stderr_printf ( "\n"1874 "\033[1m\rWARNING:\n"1875 "\033[0m\r There occured %u internal clippings due to a restriction of StreamVersion 7.\n"1876 " Re-encode with '--scale %.3f', or use option '--xlevel', which normally can\n"1877 " handle this situation but don't work well with old decoders.\a\n\n",1878 Overflows, ScalingFactorl * 32767. / MaxOverFlow - 0.0005f );1879 }1880 else {1881 stderr_printf ( "\n"1882 "\033[1m\rWARNING:\n"1883 "\033[0m\r There still occured %u SCF clippings due to a restriction of StreamVersion 7.\n"1884 " Use the '--scale' method to avoid additional distortions. Note that this\n"1885 " file already has annoying distortions due to slovenly CD mastering.\a\n\n", Overflows );1886 }1887 }1888 1901 } 1889 1902 … … 1915 1928 // no arguments or call for help 1916 1929 if ( argc < 2 || 0==strcmp (argv[1],"-h") || 0==strcmp (argv[1],"-?") || 0==strcmp (argv[1],"--help") ) { 1917 SetQualityParams (5.0); 1930 PsyModel m; 1931 SetQualityParams (&m, 5.0); 1918 1932 dup2 ( 1, 2 ); 1919 1933 shorthelp (); … … 1922 1936 1923 1937 if ( 0==strcmp (argv[1],"--longhelp") || 0==strcmp (argv[1],"-??") ) { 1924 SetQualityParams (5.0); 1938 PsyModel m; 1939 SetQualityParams (&m, 5.0); 1925 1940 dup2 ( 1, 2 ); 1926 longhelp ( );1941 longhelp (&m); 1927 1942 return 1; 1928 1943 } 1929 1944 1930 // initialize tables which must be initialized once and only once1931 #ifdef FAST_MATH1932 Init_FastMath (); // check if something has to be done for each file !!1933 #endif1934 Init_SV7 ();1935 Init_Psychoakustiktabellen ();1936 Init_Skalenfaktoren ();1937 Init_Psychoakustik ();1938 Init_FPU ();1939 Init_ANS ();1940 Klemm ();1941 1942 1945 ret = mainloop ( argc, argv ); // analyze command line and do the requested work 1943 1944 OverdriveReport (); // output a report if clipping was necessary1945 1946 1946 1947 if(IsEndBeep)
Note: See TracChangeset
for help on using the changeset viewer.