Ignore:
Timestamp:
10/17/06 16:55:28 (18 years ago)
Author:
r2d
Message:
  • added profile.c in libmpcpsy
File:
1 edited

Legend:

Unmodified
Added
Removed
  • mppenc/branches/r2d/src/mppenc.c

    r76 r77  
    3030float         Power_L    [32] [3];
    3131float         Power_R    [32] [3];
    32 float         PNS = 0.;
    3332
    3433/* MS-Coding */
    3534int           PredictionBands =  0;
    36 int           CombPenalities  = -1;
    3735int           DisplayUpdateTime = 1;
    3836int           APE_Version     = 2000;
     
    4846unsigned int  DelInput        = 0;      // deleting the input file after encoding
    4947unsigned int  WriteMode       = MODE_ASK_FOR_OVERWRITE;      // overwriting a possibly existing MPC file
    50 int           MainQual;                 // Profiles
    5148unsigned int  verbose         = 0;      // more information during output
    5249unsigned int  NoUnicode       = 1;      // console is unicode or not (tag translation)
     
    250247             "  --tmn x          set TMN value to x dB (dflt: %4.1f)\n", m->TMN );
    251248    stderr_printf (
    252              "  --pns x          set PNS value to x dB (dflt: %4.1f)\n", PNS );
     249             "  --pns x          set PNS value to x dB (dflt: %4.1f)\n", m->PNS );
    253250    stderr_printf (
    254251             "==ATH/Bandwidth settings==\n" );
     
    555552        // a smaller one is quantized more roughly, i.e. the noise gets amplified???
    556553
    557         if ( CombPenalities >= 0 ) {
    558             if      ( P(scfL[0],scfL[1]) + P(scfL[0],scfL[2]) <= CombPenalities ) scfL[2] = scfL[1] = scfL[0];
    559             else if ( P(scfL[1],scfL[0]) + P(scfL[1],scfL[2]) <= CombPenalities ) scfL[0] = scfL[2] = scfL[1];
    560             else if ( P(scfL[2],scfL[0]) + P(scfL[2],scfL[1]) <= CombPenalities ) scfL[0] = scfL[1] = scfL[2];
    561             else if ( P(scfL[0],scfL[1])                      <= CombPenalities ) scfL[1] = scfL[0];
    562             else if ( P(scfL[1],scfL[0])                      <= CombPenalities ) scfL[0] = scfL[1];
    563             else if ( P(scfL[1],scfL[2])                      <= CombPenalities ) scfL[2] = scfL[1];
    564             else if ( P(scfL[2],scfL[1])                      <= CombPenalities ) scfL[1] = scfL[2];
    565 
    566             if      ( P(scfR[0],scfR[1]) + P(scfR[0],scfR[2]) <= CombPenalities ) scfR[2] = scfR[1] = scfR[0];
    567             else if ( P(scfR[1],scfR[0]) + P(scfR[1],scfR[2]) <= CombPenalities ) scfR[0] = scfR[2] = scfR[1];
    568             else if ( P(scfR[2],scfR[0]) + P(scfR[2],scfR[1]) <= CombPenalities ) scfR[0] = scfR[1] = scfR[2];
    569             else if ( P(scfR[0],scfR[1])                      <= CombPenalities ) scfR[1] = scfR[0];
    570             else if ( P(scfR[1],scfR[0])                      <= CombPenalities ) scfR[0] = scfR[1];
    571             else if ( P(scfR[1],scfR[2])                      <= CombPenalities ) scfR[2] = scfR[1];
    572             else if ( P(scfR[2],scfR[1])                      <= CombPenalities ) scfR[1] = scfR[2];
     554        if ( m->CombPenalities >= 0 ) {
     555            if      ( P(scfL[0],scfL[1]) + P(scfL[0],scfL[2]) <= m->CombPenalities ) scfL[2] = scfL[1] = scfL[0];
     556            else if ( P(scfL[1],scfL[0]) + P(scfL[1],scfL[2]) <= m->CombPenalities ) scfL[0] = scfL[2] = scfL[1];
     557            else if ( P(scfL[2],scfL[0]) + P(scfL[2],scfL[1]) <= m->CombPenalities ) scfL[0] = scfL[1] = scfL[2];
     558            else if ( P(scfL[0],scfL[1])                      <= m->CombPenalities ) scfL[1] = scfL[0];
     559            else if ( P(scfL[1],scfL[0])                      <= m->CombPenalities ) scfL[0] = scfL[1];
     560            else if ( P(scfL[1],scfL[2])                      <= m->CombPenalities ) scfL[2] = scfL[1];
     561            else if ( P(scfL[2],scfL[1])                      <= m->CombPenalities ) scfL[1] = scfL[2];
     562
     563            if      ( P(scfR[0],scfR[1]) + P(scfR[0],scfR[2]) <= m->CombPenalities ) scfR[2] = scfR[1] = scfR[0];
     564            else if ( P(scfR[1],scfR[0]) + P(scfR[1],scfR[2]) <= m->CombPenalities ) scfR[0] = scfR[2] = scfR[1];
     565            else if ( P(scfR[2],scfR[0]) + P(scfR[2],scfR[1]) <= m->CombPenalities ) scfR[0] = scfR[1] = scfR[2];
     566            else if ( P(scfR[0],scfR[1])                      <= m->CombPenalities ) scfR[1] = scfR[0];
     567            else if ( P(scfR[1],scfR[0])                      <= m->CombPenalities ) scfR[0] = scfR[1];
     568            else if ( P(scfR[1],scfR[2])                      <= m->CombPenalities ) scfR[2] = scfR[1];
     569            else if ( P(scfR[2],scfR[1])                      <= m->CombPenalities ) scfR[1] = scfR[2];
    573570        }
    574571        else {
     
    740737
    741738static void
    742 Allocate ( const int MaxBand, int* res, float* x, int* scf, const float* comp, const float* smr, const SCFTriple* Pow, const int* Transient )
     739Allocate ( const int MaxBand, int* res, float* x, int* scf, const float* comp, const float* smr, const SCFTriple* Pow, const int* Transient, const float PNS )
    743740{
    744741    int    Band;
     
    790787}
    791788
    792 typedef struct {
    793         float            ShortThr;
    794         unsigned char    MinValChoice;
    795         unsigned int     EarModelFlag;
    796         signed char      Ltq_offset;
    797         float            TMN;
    798         float            NMT;
    799         signed char      minSMR;
    800         signed char      Ltq_max;
    801         unsigned short   BandWidth;
    802         unsigned char    tmpMask_used;
    803         unsigned char    CVD_used;
    804         float            varLtq;
    805         unsigned char    MS_Channelmode;
    806         unsigned char    CombPenalities;
    807         unsigned char    NS_Order;
    808         float            PNS;
    809         float            TransDetect;
    810 } Profile_Setting_t;
    811 
    812 #define PROFILE_PRE2_TELEPHONE   5      // --quality  0
    813 #define PROFILE_PRE_TELEPHONE    6      // --quality  1
    814 #define PROFILE_TELEPHONE        7      // --quality  2
    815 #define PROFILE_THUMB            8      // --quality  3
    816 #define PROFILE_RADIO            9      // --quality  4
    817 #define PROFILE_STANDARD        10      // --quality  5
    818 #define PROFILE_XTREME          11      // --quality  6
    819 #define PROFILE_INSANE          12      // --quality  7
    820 #define PROFILE_BRAINDEAD       13      // --quality  8
    821 #define PROFILE_POST_BRAINDEAD  14      // --quality  9
    822 #define PROFILE_POST2_BRAINDEAD 15      // --quality 10
    823 
    824 
    825 static const Profile_Setting_t  Profiles [16] = {
    826     { 0 },
    827     { 0 },
    828     { 0 },
    829     { 0 },
    830     { 0 },
    831 /*    Short   MinVal  EarModel  Ltq_                min   Ltq_  Band-  tmpMask  CVD_  varLtq    MS   Comb   NS_        Trans */
    832 /*    Thr     Choice  Flag      offset  TMN   NMT   SMR   max   Width  _used    used         channel Penal used  PNS    Det  */
    833     { 1.e9f,  1,      300,       30,    3.0, -1.0,    0,  106,   4820,   1,      1,    1.,      3,     24,  6,   1.09f, 200 },  // 0: pre-Telephone
    834     { 1.e9f,  1,      300,       24,    6.0,  0.5,    0,  100,   7570,   1,      1,    1.,      3,     20,  6,   0.77f, 180 },  // 1: pre-Telephone
    835     { 1.e9f,  1,      400,       18,    9.0,  2.0,    0,   94,  10300,   1,      1,    1.,      4,     18,  6,   0.55f, 160 },  // 2: Telephone
    836     { 50.0f,  2,      430,       12,   12.0,  3.5,    0,   88,  13090,   1,      1,    1.,      5,     15,  6,   0.39f, 140 },  // 3: Thumb
    837     { 15.0f,  2,      440,        6,   15.0,  5.0,    0,   82,  15800,   1,      1,    1.,      6,     10,  6,   0.27f, 120 },  // 4: Radio
    838     {  5.0f,  2,      550,        0,   18.0,  6.5,    1,   76,  19980,   1,      2,    1.,     11,      9,  6,   0.00f, 100 },  // 5: Standard
    839     {  4.0f,  2,      560,       -6,   21.0,  8.0,    2,   70,  22000,   1,      2,    1.,     12,      7,  6,   0.00f,  80 },  // 6: Xtreme
    840     {  3.0f,  2,      570,      -12,   24.0,  9.5,    3,   64,  24000,   1,      2,    2.,     13,      5,  6,   0.00f,  60 },  // 7: Insane
    841     {  2.8f,  2,      580,      -18,   27.0, 11.0,    4,   58,  26000,   1,      2,    4.,     13,      4,  6,   0.00f,  40 },  // 8: BrainDead
    842     {  2.6f,  2,      590,      -24,   30.0, 12.5,    5,   52,  28000,   1,      2,    8.,     13,      4,  6,   0.00f,  20 },  // 9: post-BrainDead
    843     {  2.4f,  2,      599,      -30,   33.0, 14.0,    6,   46,  30000,   1,      2,   16.,     15,      2,  6,   0.00f,  10 },  //10: post-BrainDead
    844 };
    845 
    846 
    847 static int
    848 TestProfileParams ( PsyModel* m )
    849 {   //                                       0    1    2    3    4   5   6  7 8 9  10  11  12  13 14  15
    850     static signed char  TMNStereoAdj [] = { -6, -18, -15, -18, -12, -9, -6, 0,0,0, +1, +1, +1, +1, 0, +1 };  // Penalties for TMN
    851     static signed char  NMTStereoAdj [] = { -3, -18, -15, -15,  -9, -6, -3, 0,0,0,  0, +1, +1, +1, 0, +1 };  // Penalties for NMT
    852     int                 i;
    853 
    854     MainQual = PROFILE_PRE2_TELEPHONE;
    855 
    856     for ( i = PROFILE_PRE2_TELEPHONE; i <= PROFILE_POST2_BRAINDEAD; i++ ) {
    857         if ( m->ShortThr     > Profiles [i].ShortThr     ) continue;
    858         if ( m->MinValChoice < Profiles [i].MinValChoice ) continue;
    859         if ( m->EarModelFlag < Profiles [i].EarModelFlag ) continue;
    860         if ( m->Ltq_offset   > Profiles [i].Ltq_offset   ) continue;
    861         if ( m->Ltq_max      > Profiles [i].Ltq_max      ) continue;                     // offset should normally be considered here
    862         if ( m->TMN + TMNStereoAdj [m->MS_Channelmode] <
    863              Profiles [i].TMN + TMNStereoAdj [Profiles [i].MS_Channelmode] )
    864                                                         continue;
    865         if ( m->NMT + NMTStereoAdj [m->MS_Channelmode] <
    866              Profiles [i].NMT + NMTStereoAdj [Profiles [i].MS_Channelmode] )
    867                                                         continue;
    868                 if ( m->minSMR       < Profiles [i].minSMR       ) continue;
    869         if ( m->Bandwidth    < Profiles [i].BandWidth    ) continue;
    870                 if ( m->tmpMask_used < Profiles [i].tmpMask_used ) continue;
    871                 if ( m->CVD_used     < Profiles [i].CVD_used     ) continue;
    872      // if ( varLtq       > Profiles [i].varLtq       ) continue;
    873      // if ( NS_Order     < Profiles [i].NS_Order     ) continue;
    874         if ( PNS          > Profiles [i].PNS          ) continue;
    875         MainQual = i;
    876     }
    877     return MainQual;
    878 }
    879 
    880 
    881 static void
    882 SetQualityParams (PsyModel * m, float qual )
    883 {
    884     int    i;
    885     float  mix;
    886 
    887     if      ( qual <  0. ) {
    888         qual =  0.;
    889     }
    890     if      ( qual > 10. ) {
    891         qual = 10.;
    892 #ifdef _WIN32
    893         stderr_printf ( "\nmppenc: Can't open MACDll.dll, quality set to 10.0\n" );
    894 #else
    895         stderr_printf ( "\nmppenc: Can't open libMAC.so, quality set to 10.0\n" );
    896 #endif
    897     }
    898 
    899     i   = (int) qual + PROFILE_PRE2_TELEPHONE;
    900     mix = qual - (int) qual;
    901 
    902     MainQual       = i;
    903     m->ShortThr       = Profiles [i].ShortThr   * (1-mix) + Profiles [i+1].ShortThr   * mix;
    904     m->MinValChoice   = Profiles [i].MinValChoice  ;
    905     m->EarModelFlag   = Profiles [i].EarModelFlag  ;
    906     m->Ltq_offset     = Profiles [i].Ltq_offset * (1-mix) + Profiles [i+1].Ltq_offset * mix;
    907     m->varLtq         = Profiles [i].varLtq     * (1-mix) + Profiles [i+1].varLtq     * mix;
    908     m->Ltq_max        = Profiles [i].Ltq_max    * (1-mix) + Profiles [i+1].Ltq_max    * mix;
    909     m->TMN            = Profiles [i].TMN        * (1-mix) + Profiles [i+1].TMN        * mix;
    910     m->NMT            = Profiles [i].NMT        * (1-mix) + Profiles [i+1].NMT        * mix;
    911     m->minSMR         = Profiles [i].minSMR        ;
    912     m->Bandwidth      = Profiles [i].BandWidth  * (1-mix) + Profiles [i+1].BandWidth  * mix;
    913     m->tmpMask_used   = Profiles [i].tmpMask_used  ;
    914     m->CVD_used       = Profiles [i].CVD_used      ;
    915     m->MS_Channelmode = Profiles [i].MS_Channelmode;
    916     CombPenalities = Profiles [i].CombPenalities;
    917     m->NS_Order       = Profiles [i].NS_Order      ;
    918     PNS            = Profiles [i].PNS        * (1-mix) + Profiles [i+1].PNS        * mix;
    919     m->TransDetect    = Profiles [i].TransDetect* (1-mix) + Profiles [i+1].TransDetect* mix;
    920 }
     789
    921790
    922791
     
    1080949        else if ( 0 == strcmp ( arg, "pns") ) {                                         // pns
    1081950            if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
    1082             PNS = atof (argv[k]);
     951            m->PNS = atof (argv[k]);
    1083952        }
    1084953        else if ( 0 == strcmp ( arg, "minval") ) {                                      // MinValChoice
     
    11521021        else if ( 0 == strcmp ( arg, "newcomb") ) {
    11531022            if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
    1154             CombPenalities = atoi (argv[k]);
     1023            m->CombPenalities = atoi (argv[k]);
    11551024        }
    11561025        else if ( 0 == strcmp ( arg, "ape1") ) {                                     // Mark APE as APE 1.000
     
    11711040        else if ( 0 == strcmp ( arg, "bw")  ||  0 == strcmp ( arg, "lowpass") ) {       // bandwidth
    11721041            if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
    1173                         m->Bandwidth = atof (argv[k]);
     1042                        m->BandWidth = atof (argv[k]);
    11741043        }
    11751044        else if ( 0 == strcmp ( arg, "displayupdatetime") ) {
     
    13841253                    "\n"
    13851254                    " SV %u.%u%s, Profile '%s'\n",
    1386                     inDatei, outDatei, 7, PNS > 0 ? 1 : 0, XLevel ? " + XLevel coding" : "", Profiles [MainQual] );
     1255                    inDatei, outDatei, 7, m->PNS > 0 ? 1 : 0, XLevel ? " + XLevel coding" : "", Profiles [m->MainQual] );
    13871256
    13881257    if ( verbose > 0 ) {
     
    14061275                if ( m->TMN != 18.0 || verbose > 1 )
    14071276                        stderr_printf ( " Tone masks Noise Ratio   : %4.1f dB\n", m->TMN );
    1408         if ( PNS > 0 )
    1409             stderr_printf ( " PNS Threshold            : %4.2f\n", PNS );
     1277        if ( m->PNS > 0 )
     1278            stderr_printf ( " PNS Threshold            : %4.2f\n", m->PNS );
    14101279                if ( !m->tmpMask_used )
    14111280            stderr_printf ( " No exploitation of temporal post masking\n" );
     
    16201489        m.SCF_Index_R = (int*) SCF_Index_R;
    16211490
    1622     Init_SV7 ();
    1623         Init_Skalenfaktoren ();
    16241491        Init_Psychoakustik (&m);
    16251492        Init_FPU ();
    1626         Klemm    ();
    1627 
    1628         e.dword = 0;
    1629         e.filled = 32;
    1630         e.Zaehler = 0;
    1631         e.BufferedBits = 0;
    1632         e.Overflows = 0;
     1493        Init_SV7 (&e);
    16331494
    16341495    // initialize PCM-data
     
    16511512    }
    16521513
    1653     m.SampleFreq    = Wave.SampleFreq;
     1514    m.SampleFreq = Wave.SampleFreq;
    16541515    SamplesInWAVE = Wave.PCMSamples;
    16551516
     
    17661627    LastValidFrame   = (SamplesInWAVE + BLOCK - 1) / BLOCK;
    17671628    LastValidSamples = (SamplesInWAVE + BLOCK - 1) - BLOCK * LastValidFrame + 1;
    1768     WriteHeader_SV7 ( &e, m.Max_Band, MainQual, m.MS_Channelmode > 0, LastValidFrame, LastValidSamples, PNS > 0 ? 0x17 : 0x07, m.SampleFreq );
     1629    WriteHeader_SV7 ( &e, m.Max_Band, m.MainQual, m.MS_Channelmode > 0, LastValidFrame, LastValidSamples, m.PNS > 0 ? 0x17 : 0x07, m.SampleFreq );
    17691630
    17701631
     
    18411702            }
    18421703
    1843             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
    1844                         Allocate ( m.Max_Band, Res_R, X[0].R, SCF_Index_R[0], m.SNR_comp_R, SMR.R, Power_R, Transient );
     1704            Allocate ( m.Max_Band, Res_L, X[0].L, SCF_Index_L[0], m.SNR_comp_L, SMR.L, Power_L, Transient , m.PNS );   // allocate bits for left + right channel
     1705                        Allocate ( m.Max_Band, Res_R, X[0].R, SCF_Index_R[0], m.SNR_comp_R, SMR.R, Power_R, Transient , m.PNS );
    18451706
    18461707                        Quantisierung (&m, m.Max_Band, Res_L, Res_R, X, Q );             // quantize samples
Note: See TracChangeset for help on using the changeset viewer.