Index: mppenc/branches/r2d/libmpcpsy/psy.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/psy.c	(revision 59)
+++ mppenc/branches/r2d/libmpcpsy/psy.c	(revision 60)
@@ -51,41 +51,40 @@
  */
 
-#include "mppenc.h"
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "libmpcpsy.h"
+#include "fastmath.h"
+
+
+// Antialiasing for calculation of the subband power
+const float  Butfly    [7] = { 0.5f, 0.2776f, 0.1176f, 0.0361f, 0.0075f, 0.000948f, 0.0000598f };
+
+// Antialiasing for calculation of the masking thresholds
+const float  InvButfly [7] = { 2.f, 3.6023f, 8.5034f, 27.701f, 133.33f, 1054.852f, 16722.408f };
 
 /* V A R I A B L E S */
-/* further switches for the psymodel */
-unsigned int  CVD_used;         // global flag for ClearVoiceDetection
-float         varLtq;           // variable threshold in quiet
-unsigned int  tmpMask_used;     // global flag for temporal masking
-float         ShortThr;         // Factor to calculate the masking threshold with transients
-float         minSMR;           // minimum SMR for all subbands
-
-float         a          [PART_LONG];
-float         b          [PART_LONG];
-float         c          [PART_LONG];
-float         d          [PART_LONG];           // Integrations for tmpMask
+
 static float  Xsave_L    [3 * 512];
 static float  Xsave_R    [3 * 512];             // FFT-Amplitudes L/R
 static float  Ysave_L    [3 * 512];
 static float  Ysave_R    [3 * 512];             // FFT-Phases L/R
-float         T_L        [PART_LONG];
-float         T_R        [PART_LONG];           // time-constants for tmpMask
-float         pre_erg_L[2][PART_SHORT];
-float         pre_erg_R[2][PART_SHORT];          // Preecho-control short
-float         PreThr_L   [PART_LONG];
-float         PreThr_R   [PART_LONG];           // for Pre-Echo-control L/R
-float         tmp_Mask_L [PART_LONG];
-float         tmp_Mask_R [PART_LONG];           // for Post-Masking L/R
-int           Vocal_L    [MAX_CVD_LINE + 4];
-int           Vocal_R    [MAX_CVD_LINE + 4];    // FFT-Line belongs to harmonic?
 
 /* F U N C T I O N S */
+
+// fft_routines.c
+void   Init_FFT      ( void );
+void   PowSpec256    ( const float*, float* );
+void   PowSpec1024   ( const float*, float* );
+void   PowSpec2048   ( const float*, float* );
+void   PolarSpec1024 ( const float*, float*, float* );
+void   Cepstrum2048  ( float* cep, const int );
+
 // Resets Arrays
-void
-Init_Psychoakustik ( void )
+void Init_Psychoakustik ( PsyModel* m)
 {
     int  i;
 
-    ENTER(200);
     // generate FFT lookup-tables with largest FFT-size of 1024
     Init_FFT ();
@@ -93,25 +92,27 @@
     // setting pre-echo variables to Ltq
     for ( i = 0; i < PART_LONG; i++ ) {
-        pre_erg_L  [0][i/3] = pre_erg_R  [0][i/3] =
-        pre_erg_L  [1][i/3] = pre_erg_R  [1][i/3] =
-        tmp_Mask_L [i]   = tmp_Mask_R [i]   =
-        PreThr_L   [i]   = PreThr_R   [i]   = partLtq [i];
+		m->pre_erg_L  [0][i/3] = m->pre_erg_R  [0][i/3] =
+				m->pre_erg_L  [1][i/3] = m->pre_erg_R  [1][i/3] =
+				m->tmp_Mask_L [i]   = m->tmp_Mask_R [i]   =
+				m->PreThr_L   [i]   = m->PreThr_R   [i]   = m->partLtq [i];
     }
 
     // initializing arrays with zero
-    memset ( Xsave_L,   0, sizeof Xsave_L );
-    memset ( Xsave_R,   0, sizeof Xsave_R );
-    memset ( Ysave_L,   0, sizeof Ysave_L );
-    memset ( Ysave_R,   0, sizeof Ysave_R );
-    memset ( a,         0, sizeof a       );
-    memset ( b,         0, sizeof b       );
-    memset ( c,         0, sizeof c       );
-    memset ( d,         0, sizeof d       );
-    memset ( T_L,       0, sizeof T_L     );
-    memset ( T_R,       0, sizeof T_R     );
-    memset ( Vocal_L,   0, sizeof Vocal_L );
-    memset ( Vocal_R,   0, sizeof Vocal_R );
-
-    LEAVE(200);
+	memset ( Xsave_L,   0, sizeof Xsave_L );
+	memset ( Xsave_R,   0, sizeof Xsave_R );
+	memset ( Ysave_L,   0, sizeof Ysave_L );
+	memset ( Ysave_R,   0, sizeof Ysave_R );
+	memset ( m->a,         0, sizeof m->a       );
+	memset ( m->b,         0, sizeof m->b       );
+	memset ( m->c,         0, sizeof m->c       );
+	memset ( m->d,         0, sizeof m->d       );
+	memset ( m->T_L,       0, sizeof m->T_L     );
+	memset ( m->T_R,       0, sizeof m->T_R     );
+	memset ( m->Vocal_L,   0, sizeof m->Vocal_L );
+	memset ( m->Vocal_R,   0, sizeof m->Vocal_R );
+
+	m->SampleFreq = 0.;
+	m->Bandwidth = 0.;
+
     return;
 }
@@ -134,10 +135,8 @@
 
 
-void
-RaiseSMR ( const int MaxBand, SMRTyp* smr )
-{
-    float  tmp = POW10 ( 0.1 * minSMR );
-
-    ENTER(201);
+void RaiseSMR (PsyModel* m, const int MaxBand, SMRTyp* smr )
+{
+    float  tmp = POW10 ( 0.1 * m->minSMR );
+
     RaiseSMR_Signal ( MaxBand, smr->L, tmp );
     RaiseSMR_Signal ( MaxBand, smr->R, tmp );
@@ -145,5 +144,4 @@
     RaiseSMR_Signal ( MaxBand, smr->S, 0.5 * tmp );
 
-    LEAVE(201);
     return;
 }
@@ -166,5 +164,4 @@
     float*  r;
 
-    ENTER(202);
 
     for ( Band = 0; Band <= MaxBand; Band++ ) {        // calculate perceptual entropy
@@ -197,5 +194,4 @@
     }
 
-    LEAVE(202);
     return;
 }
@@ -203,5 +199,5 @@
 // input : FFT-spectrums *spec0 und *spec1
 // output: energy in the individual subbands *erg0 and *erg1
-// With Butfly[], you can calculate the results of aliasing during calculation 
+// With Butfly[], you can calculate the results of aliasing during calculation
 // of subband energy from the FFT-spectrums.
 static void
@@ -218,5 +214,4 @@
     float  tmp1;
 
-    ENTER(203);
 
     // Is this here correct for FFT-based data or is this calculation rule only for MDCTs???
@@ -244,5 +239,4 @@
     }
 
-    LEAVE(203);
     return;
 }
@@ -261,5 +255,4 @@
     float         e1;
 
-    ENTER(204);
 
 #if 000000
@@ -314,8 +307,6 @@
     }
 
-
 #endif
 
-    LEAVE(204);
     return;
 }
@@ -337,5 +328,4 @@
     float         e1;
 
-    ENTER(205);
 
 #if 000000
@@ -391,5 +381,4 @@
 #endif
 
-    LEAVE(205);
     return;
 }
@@ -413,5 +402,4 @@
     float         tmp1;
 
-    ENTER(206);
 
     // should be able to optimize it with coasting.  [ 9 ] + n * [ 7 + 7 + 2 ] + [ 7 ]
@@ -440,9 +428,7 @@
     }
 
-    LEAVE(206);
-    return;
-}
-
-#include "fastmath.h"
+    return;
+}
+
 
 // input : current spectrum in the form of power *spec and phase *phase,
@@ -452,11 +438,12 @@
 // output: current amplitude *amp and unpredictability *cw
 static void
-CalcUnpred ( const int     MaxLine,
-             const float*  spec,
-             const float*  phase,
-             const int*    vocal,
-             float*        amp0,
-             float*        phs0,
-             float*        cw )
+CalcUnpred (PsyModel* m,
+			const int     MaxLine,
+			const float*  spec,
+			const float*  phase,
+			const int*    vocal,
+			float*        amp0,
+			float*        phs0,
+			float*        cw )
 {
     int     n;
@@ -468,5 +455,4 @@
 #define phs2  ((phs0) + 1024)           // phs[1024...1535] contains data of frame-2
 
-    ENTER(207);
 
     for ( n = 0; n < MaxLine; n++ ) {
@@ -480,5 +466,5 @@
 
     // postprocessing of harmonic FFT-lines (*cw is set to CVD_UNPRED)
-    if ( CVD_used  &&  vocal != NULL ) {
+	if ( m->CVD_used  &&  vocal != NULL ) {
         for ( n = 0; n < MAX_CVD_LINE; n++, cw++, vocal++ )
             if ( *vocal != 0  &&  *cw > CVD_UNPRED * 0.01 * *vocal )
@@ -486,5 +472,4 @@
     }
 
-    LEAVE(207);
     return;
 }
@@ -499,5 +484,6 @@
 // SPRD describes the spreading function as calculated in psy_tab.c
 static void
-SpreadingSignal ( const float* erg, const float* werg, float* res, float* wres )
+SpreadingSignal ( PsyModel* m, const float* erg, const float* werg, float* res,
+				  float* wres )
 {
     int           n;
@@ -509,10 +495,9 @@
     float         ew;
 
-    ENTER(208);
 
     for (k=0; k<PART_LONG; ++k, ++erg, ++werg) { // Source (masking partition)
         start = maxi(k-5, 0);           // minimum affected partition
         stop  = mini(k+7, PART_LONG-1); // maximum affected partition
-        sprd  = SPRD[k] + start;         // load vector
+        sprd  = m->SPRD[k] + start;         // load vector
         e     = *erg;
         ew    = *werg;
@@ -524,5 +509,4 @@
     }
 
-    LEAVE(208);
     return;
 }
@@ -531,5 +515,5 @@
 // output: masking threshold *erg after applying the tonality-offset
 static void
-ApplyTonalityOffset ( float* erg0, float* erg1, const float* werg0, const float* werg1 )
+ApplyTonalityOffset ( PsyModel* m, float* erg0, float* erg1, const float* werg0, const float* werg1 )
 {
     int    n;
@@ -537,22 +521,20 @@
     float  quot;
 
-    ENTER(230);
 
     // calculation of the masked threshold in the partition range
     for ( n = 0; n < PART_LONG; n++ ) {
         quot = *werg0++ / *erg0;
-        if      (quot <= 0.05737540597f) Offset = O_MAX;
-        else if (quot <  0.5871011603f ) Offset = FAC1 * POW (quot, FAC2);
-        else                             Offset = O_MIN;
-        *erg0++ *= iw[n] * minf(MinVal[n], Offset);
+        if      (quot <= 0.05737540597f) Offset = m->O_MAX;
+        else if (quot <  0.5871011603f ) Offset = m->FAC1 * POW (quot, m->FAC2);
+        else                             Offset = m->O_MIN;
+        *erg0++ *= iw[n] * minf(m->MinVal[n], Offset);
 
         quot = *werg1++ / *erg1;
-        if      (quot <= 0.05737540597f) Offset = O_MAX;
-        else if (quot <  0.5871011603f ) Offset = FAC1 * POW (quot, FAC2);
-        else                             Offset = O_MIN;
-        *erg1++ *= iw[n] * minf(MinVal[n], Offset);
-    }
-
-    LEAVE(230);
+        if      (quot <= 0.05737540597f) Offset = m->O_MAX;
+        else if (quot <  0.5871011603f ) Offset = m->FAC1 * POW (quot, m->FAC2);
+        else                             Offset = m->O_MIN;
+		*erg1++ *= iw[n] * minf(m->MinVal[n], Offset);
+    }
+
     return;
 }
@@ -561,8 +543,8 @@
 // output: tracked loudness *loud, adapted threshold in quiet <Return value>
 static float
-AdaptLtq ( const float* erg0, const float* erg1 )
+AdaptLtq ( PsyModel* m, const float* erg0, const float* erg1 )
 {
     static float  loud   = 0.f;
-    float*        weight = Loudness;
+	float*        weight = m->Loudness;
     float         sum    = 0.f;
     int           n;
@@ -577,5 +559,5 @@
 
     // calculate dynamic offset for threshold in quiet, 0...+20 dB, at 96 dB loudness, an offset of 20 dB is assumed
-    return 1.f + varLtq * loud * 5.023772e-08f;
+    return 1.f + m->varLtq * loud * 5.023772e-08f;
 }
 
@@ -585,15 +567,14 @@
 // output: tracked Integrations *a and *b, time constant *tau
 static void
-CalcTemporalThreshold ( float* a, float* b, float* tau, float* frqthr, float* tmpthr )
+CalcTemporalThreshold ( PsyModel* m, float* a, float* b, float* tau, float* frqthr, float* tmpthr )
 {
     int    n;
     float  tmp;
 
-    ENTER(220);
 
     for ( n = 0; n < PART_LONG; n++ ) {
         // following calculations relative to threshold in quiet
-        frqthr[n] *= invLtq[n];
-        tmpthr[n] *= invLtq[n];
+        frqthr[n] *= m->invLtq[n];
+		tmpthr[n] *= m->invLtq[n];
 
         // new post-masking 'tmp' via time constant tau, if old post-masking  > Ltq (=1)
@@ -608,8 +589,7 @@
 
         // use post-masking of (Re-Normalization)
-        tmpthr[n] = maxf (frqthr[n], tmp) * partLtq[n];
-    }
-
-    LEAVE(220);
+		tmpthr[n] = maxf (frqthr[n], tmp) * m->partLtq[n];
+    }
+
     return;
 }
@@ -620,5 +600,6 @@
 // output: M/S-Masking thresholds in Partitions *thrM, *thrS
 static void
-CalcMSThreshold ( const float*  const ergL,
+CalcMSThreshold ( PsyModel* m,
+				  const float*  const ergL,
                   const float*  const ergR,
                   const float*  const ergM,
@@ -640,5 +621,5 @@
         thrS[n] = thrM[n] = maxf (ergM[n], ergS[n]) / maxf (ergL[n], ergR[n]) * minf (thrL[n], thrR[n]);
 
-        switch ( MS_Channelmode ) { // preserve 'near-mid' signal components
+        switch ( m->MS_Channelmode ) { // preserve 'near-mid' signal components
         case 3:
             if ( n > 0 ) {
@@ -760,9 +741,9 @@
                     tmp = ergS[n] * norm;
                     if ( thrS[n] > tmp )
-                        thrS[n] = maxf (tmp, ergM[n]*iw[n]*0.025);              // +/- 1.414°
+                        thrS[n] = maxf (tmp, ergM[n]*iw[n]*0.025);              // +/- 1.414
                 } else if ( ergS[n] > ergM[n] ) {
                     tmp = ergM[n] * norm;
                     if ( thrM[n] > tmp )
-                        thrM[n] = maxf (tmp, ergS[n]*iw[n]*0.025);              // +/- 1.414°
+                        thrM[n] = maxf (tmp, ergS[n]*iw[n]*0.025);              // +/- 1.414
                 }
             }
@@ -779,5 +760,6 @@
 // inline, because it's called 4x
 static void
-ApplyLtq ( float*        thr0,
+ApplyLtq ( PsyModel* m,
+		   float*        thr0,
            float*        thr1,
            const float*  partThr0,
@@ -800,5 +782,5 @@
 #else
             // Applies a much more gentle ATH rolloff + 6 dB more dynamic
-            ltq   = sqrt (ms * fftLtq [k]);
+            ltq   = sqrt (ms * m->fftLtq [k]);
             tmp   = sqrt (partThr0 [n]) + ltq;
             *thr0 = tmp * tmp;
@@ -896,5 +878,6 @@
 #else
 static void
-CalcShortThreshold ( const float  erg [4] [128],
+CalcShortThreshold ( PsyModel* m,
+					 const float  erg [4] [128],
                      const float  ShortThr,
                      float*       thr,
@@ -907,5 +890,5 @@
     int           k;
     int           n;
-    int           m;
+    int           l;
     float         new_erg;
     float         th;
@@ -917,14 +900,14 @@
         for ( n = 0; n < 4; n++ ) {
             ep   = erg[n] + index_lo [k];
-            m    = index_hi [k] - index_lo [k];
+            l    = index_hi [k] - index_lo [k];
 
             new_erg = *ep++;
-            while (m--)
+            while (l--)
                 new_erg += *ep++;               // e = Short_Partition-energy in piece n
 
             if ( new_erg > old_erg [0][k] ) {           // bigger than the old?
 
-                if ( new_erg > old_erg [0][k] * TransDetect  ||
-                     new_erg > old_erg [1][k] * TransDetect*2 )  // is signal transient?
+                if ( new_erg > old_erg [0][k] * m->TransDetect  ||
+					 new_erg > old_erg [1][k] * m->TransDetect*2 )  // is signal transient?
                     transient [k] = 1;
             }
@@ -992,5 +975,9 @@
 // output: SMRs for the input data
 SMRTyp
-Psychoakustisches_Modell ( const int MaxBand, const PCMDataTyp* data, int* TransientL, int* TransientR )
+Psychoakustisches_Modell ( PsyModel* m,
+						   const int MaxBand,
+						   const PCMDataTyp* data,
+						   int* TransientL,
+						   int* TransientR )
 {
     float      Xi_L[32],     Xi_R[32];                          // acoustic pressure per Subband L/R
@@ -1019,16 +1006,15 @@
     float    factorLTQ  = 1.f;                                  // Offset after variable LTQ
 
-    ENTER(50);
     // 'ClearVocalDetection'-Process
-    if ( CVD_used ) {
-        memset ( Vocal_L, 0, sizeof Vocal_L );
-        memset ( Vocal_R, 0, sizeof Vocal_R );
+    if ( m->CVD_used ) {
+        memset ( m->Vocal_L, 0, sizeof m->Vocal_L );
+        memset ( m->Vocal_R, 0, sizeof m->Vocal_R );
 
         // left channel
         PowSpec2048 ( &data->L[0], Xerg );
-        isvoc_L = CVD2048 ( Xerg, Vocal_L );
+        isvoc_L = CVD2048 ( Xerg, m->Vocal_L );
         // right channel
         PowSpec2048 ( &data->R[0], Xerg );
-        isvoc_R = CVD2048 ( Xerg, Vocal_R );
+        isvoc_R = CVD2048 ( Xerg, m->Vocal_R );
     }
 
@@ -1047,9 +1033,9 @@
     memmove ( Xsave_L+512, Xsave_L, 1024*sizeof(float) );
     memmove ( Ysave_L+512, Ysave_L, 1024*sizeof(float) );
-    CalcUnpred ( MaxLine, erg0, phs0, isvoc_L ? Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );
+    CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? m->Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );
     // right
     memmove ( Xsave_R+512, Xsave_R, 1024*sizeof(float) );
     memmove ( Ysave_R+512, Ysave_R, 1024*sizeof(float) );
-    CalcUnpred ( MaxLine, erg1, phs1, isvoc_R ? Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );
+    CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? m->Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );
 
     // calculation of the weighted acoustic pressures per each partition
@@ -1060,12 +1046,12 @@
     memset ( clow_L    , 0, sizeof clow_L );
     memset ( sim_Mask_L, 0, sizeof sim_Mask_L );
-    SpreadingSignal ( Ls_L, cLs_L, sim_Mask_L, clow_L );
+    SpreadingSignal ( m, Ls_L, cLs_L, sim_Mask_L, clow_L );
     // right
     memset ( clow_R    , 0, sizeof clow_R );
     memset ( sim_Mask_R, 0, sizeof sim_Mask_R );
-    SpreadingSignal ( Ls_R, cLs_R, sim_Mask_R, clow_R );
+    SpreadingSignal ( m, Ls_R, cLs_R, sim_Mask_R, clow_R );
 
     // Offset depending on tonality
-    ApplyTonalityOffset ( sim_Mask_L, sim_Mask_R, clow_L, clow_R );
+    ApplyTonalityOffset ( m, sim_Mask_L, sim_Mask_R, clow_L, clow_R );
 
     // handling of transient signals
@@ -1076,5 +1062,5 @@
     PowSpec256 ( &data->L[432+SHORTFFT_OFFSET], F_256[3] );
     // calculate short Threshold
-    CalcShortThreshold ( F_256, ShortThr, shortThr_L, pre_erg_L, TransientL );
+    CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, m->pre_erg_L, TransientL );
 
     // calculate four short FFTs (right)
@@ -1084,16 +1070,16 @@
     PowSpec256 ( &data->R[432+SHORTFFT_OFFSET], F_256[3] );
     // calculate short Threshold
-    CalcShortThreshold ( F_256, ShortThr, shortThr_R, pre_erg_R, TransientR );
+    CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, m->pre_erg_R, TransientR );
 
     // dynamic adjustment of the threshold in quiet to the loudness of the current sequence
-    if ( varLtq > 0. )
-        factorLTQ = AdaptLtq ( Ls_L, Ls_R );
+    if ( m->varLtq > 0. )
+        factorLTQ = AdaptLtq (m, Ls_L, Ls_R );
 
     // utilization of the temporal post-masking
-    if ( tmpMask_used ) {
-        CalcTemporalThreshold ( a, b, T_L, sim_Mask_L, tmp_Mask_L );
-        CalcTemporalThreshold ( c, d, T_R, sim_Mask_R, tmp_Mask_R );
-        memcpy ( sim_Mask_L, tmp_Mask_L, sizeof sim_Mask_L );
-        memcpy ( sim_Mask_R, tmp_Mask_R, sizeof sim_Mask_R );
+    if ( m->tmpMask_used ) {
+		CalcTemporalThreshold (m, m->a, m->b, m->T_L, sim_Mask_L, m->tmp_Mask_L );
+		CalcTemporalThreshold (m, m->c, m->d, m->T_R, sim_Mask_R, m->tmp_Mask_R );
+		memcpy ( sim_Mask_L, m->tmp_Mask_L, sizeof sim_Mask_L );
+		memcpy ( sim_Mask_R, m->tmp_Mask_R, sizeof sim_Mask_R );
     }
 
@@ -1113,8 +1099,8 @@
 
     // Pre-Echo control
-    PreechoControl ( PartThr_L, PreThr_L, sim_Mask_L, PartThr_R, PreThr_R, sim_Mask_R );
+	PreechoControl ( PartThr_L, m->PreThr_L, sim_Mask_L, PartThr_R, m->PreThr_R, sim_Mask_R );
 
     // utilization of the threshold in quiet
-    ApplyLtq ( Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );
+    ApplyLtq ( m, Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );
 
     // Consideration of aliasing between the subbands (noise is smeared)
@@ -1129,5 +1115,5 @@
     /***************************************************************************************/
     /***************************************************************************************/
-    if ( MS_Channelmode > 0 ) {
+	if ( m->MS_Channelmode > 0 ) {
         // calculation of the spectral energy via FFT
         PowSpec1024 ( &data->M[0], erg0 );      // mid
@@ -1141,6 +1127,6 @@
 
         // calculate masking thresholds for M/S
-        CalcMSThreshold ( Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );
-        ApplyLtq ( Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );
+        CalcMSThreshold ( m, Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );
+        ApplyLtq ( m, Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );
 
         // Consideration of aliasing between the subbands (noise is smeared)
@@ -1154,9 +1140,9 @@
     }
 
-    if ( NS_Order > 0 ) {       // providing the Noise Shaping thresholds
-        memcpy ( ANSspec_L, Thr_L, sizeof ANSspec_L );
-        memcpy ( ANSspec_R, Thr_R, sizeof ANSspec_R );
-        memcpy ( ANSspec_M, Thr_M, sizeof ANSspec_M );
-        memcpy ( ANSspec_S, Thr_S, sizeof ANSspec_S );
+	if ( m->NS_Order > 0 ) {       // providing the Noise Shaping thresholds
+		memcpy ( m->ANSspec_L, Thr_L, sizeof m->ANSspec_L );
+		memcpy ( m->ANSspec_R, Thr_R, sizeof m->ANSspec_R );
+		memcpy ( m->ANSspec_M, Thr_M, sizeof m->ANSspec_M );
+		memcpy ( m->ANSspec_S, Thr_S, sizeof m->ANSspec_S );
     }
     /***************************************************************************************/
@@ -1180,9 +1166,9 @@
     memmove ( Xsave_L+512, Xsave_L, 1024*sizeof(float) );
     memmove ( Ysave_L+512, Ysave_L, 1024*sizeof(float) );
-    CalcUnpred ( MaxLine, erg0, phs0, isvoc_L ? Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );
+	CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? m->Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );
     // right
     memmove ( Xsave_R+512, Xsave_R, 1024*sizeof(float) );
     memmove ( Ysave_R+512, Ysave_R, 1024*sizeof(float) );
-    CalcUnpred ( MaxLine, erg1, phs1, isvoc_R ? Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );
+	CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? m->Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );
 
     // calculation of the weighted acoustic pressure per each partition
@@ -1193,12 +1179,12 @@
     memset ( clow_L    , 0, sizeof clow_L );
     memset ( sim_Mask_L, 0, sizeof sim_Mask_L );
-    SpreadingSignal ( Ls_L, cLs_L, sim_Mask_L, clow_L );
+    SpreadingSignal ( m, Ls_L, cLs_L, sim_Mask_L, clow_L );
     // right
     memset ( clow_R    , 0, sizeof clow_R );
     memset ( sim_Mask_R, 0, sizeof sim_Mask_R );
-    SpreadingSignal ( Ls_R, cLs_R, sim_Mask_R, clow_R );
+    SpreadingSignal ( m, Ls_R, cLs_R, sim_Mask_R, clow_R );
 
     // Offset depending on tonality
-    ApplyTonalityOffset ( sim_Mask_L, sim_Mask_R, clow_L, clow_R );
+    ApplyTonalityOffset ( m, sim_Mask_L, sim_Mask_R, clow_L, clow_R );
 
     // Handling of transient signals
@@ -1209,5 +1195,5 @@
     PowSpec256 ( &data->L[1008+SHORTFFT_OFFSET], F_256[3] );
     // calculate short Threshold
-    CalcShortThreshold ( F_256, ShortThr, shortThr_L, pre_erg_L, TransientL );
+	CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, m->pre_erg_L, TransientL );
 
     // calculate four short FFTs (right)
@@ -1217,16 +1203,16 @@
     PowSpec256 ( &data->R[1008+SHORTFFT_OFFSET], F_256[3] );
     // calculate short Threshold
-    CalcShortThreshold ( F_256, ShortThr, shortThr_R, pre_erg_R, TransientR );
+	CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, m->pre_erg_R, TransientR );
 
     // dynamic adjustment of threshold in quiet to loudness of the current sequence
-    if ( varLtq > 0. )
-        factorLTQ = AdaptLtq ( Ls_L, Ls_R );
+	if ( m->varLtq > 0. )
+        factorLTQ = AdaptLtq ( m, Ls_L, Ls_R );
 
     // utilization of temporal post-masking
-    if (tmpMask_used) {
-        CalcTemporalThreshold ( a, b, T_L, sim_Mask_L, tmp_Mask_L );
-        CalcTemporalThreshold ( c, d, T_R, sim_Mask_R, tmp_Mask_R );
-        memcpy ( sim_Mask_L, tmp_Mask_L, sizeof sim_Mask_L );
-        memcpy ( sim_Mask_R, tmp_Mask_R, sizeof sim_Mask_R );
+	if (m->tmpMask_used) {
+		CalcTemporalThreshold ( m, m->a, m->b, m->T_L, sim_Mask_L, m->tmp_Mask_L );
+		CalcTemporalThreshold ( m, m->c, m->d, m->T_R, sim_Mask_R, m->tmp_Mask_R );
+		memcpy ( sim_Mask_L, m->tmp_Mask_L, sizeof sim_Mask_L );
+		memcpy ( sim_Mask_R, m->tmp_Mask_R, sizeof sim_Mask_R );
     }
 
@@ -1246,8 +1232,8 @@
 
     // Pre-Echo control
-    PreechoControl ( PartThr_L, PreThr_L, sim_Mask_L, PartThr_R, PreThr_R, sim_Mask_R );
+	PreechoControl ( PartThr_L, m->PreThr_L, sim_Mask_L, PartThr_R, m->PreThr_R, sim_Mask_R );
 
     // utilization of threshold in quiet
-    ApplyLtq ( Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );
+    ApplyLtq ( m, Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );
 
     // Consideration of aliasing between the subbands (noise is smeared)
@@ -1262,5 +1248,5 @@
     /***************************************************************************************/
     /***************************************************************************************/
-    if ( MS_Channelmode > 0 ) {
+	if ( m->MS_Channelmode > 0 ) {
         // calculation of the spectral energy via FFT
         PowSpec1024 ( &data->M[576], erg0 );    // mid
@@ -1274,6 +1260,6 @@
 
         // calculate masking thresholds for M/S
-        CalcMSThreshold ( Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );
-        ApplyLtq ( Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );
+        CalcMSThreshold ( m, Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );
+        ApplyLtq ( m, Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );
 
         // Consideration of aliasing between the subbands (noise is smeared)
@@ -1289,10 +1275,10 @@
     /***************************************************************************************/
 
-    if ( NS_Order > 0 ) {
+	if ( m->NS_Order > 0 ) {
         for ( n = 0; n < MAX_ANS_LINES; n++ ) {                 // providing Noise Shaping thresholds
-            ANSspec_L [n] = minf ( ANSspec_L [n], Thr_L [n] );
-            ANSspec_R [n] = minf ( ANSspec_R [n], Thr_R [n] );
-            ANSspec_M [n] = minf ( ANSspec_M [n], Thr_M [n] );
-            ANSspec_S [n] = minf ( ANSspec_S [n], Thr_S [n] );
+			m->ANSspec_L [n] = minf ( m->ANSspec_L [n], Thr_L [n] );
+			m->ANSspec_R [n] = minf ( m->ANSspec_R [n], Thr_R [n] );
+			m->ANSspec_M [n] = minf ( m->ANSspec_M [n], Thr_M [n] );
+			m->ANSspec_S [n] = minf ( m->ANSspec_S [n], Thr_S [n] );
         }
     }
@@ -1304,6 +1290,4 @@
         SMR0.S[n] = maxf ( SMR0.S[n], SMR1.S[n] );
     }
-
-    LEAVE(50);
     return SMR0;
 }
