shithub: aacdec

Download patch

ref: a2a56b3ea59188e2e2b60b69a0a8f77aa3093144
parent: 8e9935e445dd2988b93a5d0410c0344e9efac506
author: menno <menno>
date: Sun Sep 29 18:19:48 EDT 2002

Some more initial work for SBR

--- a/frontend/faad.dsp
+++ b/frontend/faad.dsp
@@ -91,10 +91,6 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\libfaad\cfft.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\common\faad\getopt.c
 # End Source File
 # Begin Source File
--- a/libfaad/libfaad.dsp
+++ b/libfaad/libfaad.dsp
@@ -25,7 +25,7 @@
 # PROP AllowPerConfigDependencies 0
 # PROP Scc_ProjName ""
 # PROP Scc_LocalPath ""
-CPP=xicl6.exe
+CPP=cl.exe
 RSC=rc.exe
 
 !IF  "$(CFG)" == "libfaad - Win32 Release"
@@ -47,7 +47,7 @@
 BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
-LIB32=xilink6.exe -lib
+LIB32=link.exe -lib
 # ADD BASE LIB32 /nologo
 # ADD LIB32 /nologo
 
@@ -64,13 +64,13 @@
 # PROP Intermediate_Dir "Debug"
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /Zp8 /MTd /W3 /Gm /GX /ZI /Od /I "fftw" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FFTW_ENABLE_FLOAT" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "fftw" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "FFTW_ENABLE_FLOAT" /YX /FD /GZ /c
 # ADD BASE RSC /l 0x413 /d "_DEBUG"
 # ADD RSC /l 0x413 /d "_DEBUG"
 BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
-LIB32=xilink6.exe -lib
+LIB32=link.exe -lib
 # ADD BASE LIB32 /nologo
 # ADD LIB32 /nologo
 
@@ -233,6 +233,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\sbr_util.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\specrec.c
 # End Source File
 # Begin Source File
@@ -362,6 +366,10 @@
 # Begin Source File
 
 SOURCE=.\sbr_syntax.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_util.h
 # End Source File
 # Begin Source File
 
--- a/libfaad/libfaad.vcproj
+++ b/libfaad/libfaad.vcproj
@@ -182,6 +182,9 @@
 				RelativePath=".\sbr_syntax.c">
 			</File>
 			<File
+				RelativePath="sbr_util.c">
+			</File>
+			<File
 				RelativePath=".\specrec.c">
 			</File>
 			<File
@@ -326,6 +329,9 @@
 			</File>
 			<File
 				RelativePath=".\sbr_syntax.h">
+			</File>
+			<File
+				RelativePath="sbr_util.h">
 			</File>
 			<File
 				RelativePath="sine_win.h">
--- a/libfaad/libfaad2_dll.dsp
+++ b/libfaad/libfaad2_dll.dsp
@@ -25,7 +25,7 @@
 # PROP AllowPerConfigDependencies 0
 # PROP Scc_ProjName ""
 # PROP Scc_LocalPath ""
-CPP=xicl6.exe
+CPP=cl.exe
 MTL=midl.exe
 RSC=rc.exe
 
@@ -51,7 +51,7 @@
 BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
-LINK32=xilink6.exe
+LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
 # ADD LINK32 /nologo /dll /machine:I386 /out:"ReleaseDLL/libfaad2.dll"
 
@@ -77,7 +77,7 @@
 BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
-LINK32=xilink6.exe
+LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
 # ADD LINK32 /nologo /dll /debug /machine:I386 /out:"DebugDLL/libfaad2.dll" /pdbtype:sept
 
@@ -152,6 +152,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\data.c
 # End Source File
 # Begin Source File
@@ -220,6 +224,26 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\sbr_dec.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_huff.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_qmf.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_syntax.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_util.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\specrec.c
 # End Source File
 # Begin Source File
@@ -325,6 +349,26 @@
 # Begin Source File
 
 SOURCE=.\rvlc_scale_factors.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_dec.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_huff.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_qmf.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_syntax.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_util.h
 # End Source File
 # Begin Source File
 
--- a/libfaad/libfaad2_dll.vcproj
+++ b/libfaad/libfaad2_dll.vcproj
@@ -142,6 +142,9 @@
 				RelativePath=".\cfft.c">
 			</File>
 			<File
+				RelativePath="common.c">
+			</File>
+			<File
 				RelativePath=".\data.c">
 			</File>
 			<File
@@ -148,6 +151,9 @@
 				RelativePath=".\decoder.c">
 			</File>
 			<File
+				RelativePath="dither.c">
+			</File>
+			<File
 				RelativePath=".\drc.c">
 			</File>
 			<File
@@ -190,6 +196,21 @@
 				RelativePath=".\rvlc_scale_factors.c">
 			</File>
 			<File
+				RelativePath="sbr_dec.c">
+			</File>
+			<File
+				RelativePath="sbr_huff.c">
+			</File>
+			<File
+				RelativePath="sbr_qmf.c">
+			</File>
+			<File
+				RelativePath="sbr_syntax.c">
+			</File>
+			<File
+				RelativePath="sbr_util.c">
+			</File>
+			<File
 				RelativePath=".\specrec.c">
 			</File>
 			<File
@@ -264,6 +285,9 @@
 				RelativePath=".\decoder.h">
 			</File>
 			<File
+				RelativePath="dither.h">
+			</File>
+			<File
 				RelativePath=".\drc.h">
 			</File>
 			<File
@@ -310,6 +334,21 @@
 			</File>
 			<File
 				RelativePath=".\rvlc_scale_factors.h">
+			</File>
+			<File
+				RelativePath="sbr_dec.h">
+			</File>
+			<File
+				RelativePath="sbr_huff.h">
+			</File>
+			<File
+				RelativePath="sbr_qmf.h">
+			</File>
+			<File
+				RelativePath="sbr_syntax.h">
+			</File>
+			<File
+				RelativePath="sbr_util.h">
 			</File>
 			<File
 				RelativePath=".\specrec.h">
--- a/libfaad/sbr_dec.h
+++ b/libfaad/sbr_dec.h
@@ -16,11 +16,9 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: sbr_dec.h,v 1.1 2002/04/20 22:20:15 menno Exp $
+** $Id: sbr_dec.h,v 1.2 2002/09/29 22:19:48 menno Exp $
 **/
 
-#ifdef SBR
-
 #ifndef __SBR_DEC_H__
 #define __SBR_DEC_H__
 
@@ -35,4 +33,3 @@
 #endif
 #endif
 
-#endif /* SBR */
\ No newline at end of file
--- a/libfaad/sbr_huff.h
+++ b/libfaad/sbr_huff.h
@@ -16,11 +16,9 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: sbr_huff.h,v 1.2 2002/04/23 21:08:26 menno Exp $
+** $Id: sbr_huff.h,v 1.3 2002/09/29 22:19:48 menno Exp $
 **/
 
-#ifdef SBR
-
 #ifndef __SBR_HUFF_H__
 #define __SBR_HUFF_H__
 
@@ -55,4 +53,3 @@
 #endif
 #endif
 
-#endif /* SBR */
\ No newline at end of file
--- a/libfaad/sbr_qmf.c
+++ b/libfaad/sbr_qmf.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: sbr_qmf.c,v 1.2 2002/04/21 09:00:40 menno Exp $
+** $Id: sbr_qmf.c,v 1.3 2002/09/29 22:19:48 menno Exp $
 **/
 
 #include "common.h"
@@ -25,19 +25,17 @@
 
 #include "sbr_qmf.h"
 
-void sbr_qmf_analysis(real_t *input, complex_t **Xlow)
+void sbr_qmf_analysis(real_t *input, real_t *x, complex_t **Xlow)
 {
     uint8_t l;
-    real_t x[320], z[320], u[64];
+    real_t z[320], u[64];
     real_t *inptr = input;
 
-    memset(x, 0, 320*sizeof(real_t));
-
     /* qmf subsample l */
     for (l = 0; l < 32; l++)
     {
         uint8_t k;
-        uint16_t n;
+        int16_t n;
 
         /* shift input buffer x */
         for (n = 320 - 1; n <= 0; n--)
@@ -72,8 +70,8 @@
         /* calculate 32 subband samples by introducing Xlow */
         for (k = 0; k < 32; k++)
         {
-            Xlow[k][l].re = 0.0;
-            Xlow[k][l].im = 0.0;
+            RE(Xlow[k][l]) = 0.0;
+            IM(Xlow[k][l]) = 0.0;
 
             for (n = 0; n < 64; n++)
             {
@@ -80,22 +78,20 @@
                 /* complex exponential
                 Xlow[k][l] += 2.0 * u[n] * exp(i*M_PI/64.0 * (k + 0.5) * (2.0*n - 0.5));
                 */
-                Xlow[k][l].re += 2.0 * u[n] * cos(M_PI/64.0 * (k + 0.5) * (2.0*n - 0.5));
-                Xlow[k][l].im += 2.0 * u[n] * sin(M_PI/64.0 * (k + 0.5) * (2.0*n - 0.5));
+                RE(Xlow[k][l]) += 2.0 * u[n] * cos(M_PI/64.0 * (k + 0.5) * (2.0*n - 0.5));
+                IM(Xlow[k][l]) += 2.0 * u[n] * sin(M_PI/64.0 * (k + 0.5) * (2.0*n - 0.5));
             }
         }
     }
 }
 
-void sbr_qmf_synthesis(complex_t **Xlow, real_t *output)
+void sbr_qmf_synthesis(complex_t **Xlow, real_t *v, real_t *output)
 {
     uint8_t l, k;
-    uint16_t n;
-    real_t v[640], w[640];
+    int16_t n;
+    real_t w[640];
     real_t *outptr = output;
 
-    memset(v, 0, 640 * sizeof(real_t));
-
     /* qmf subsample l */
     for (l = 0; l < 32; l++)
     {
@@ -117,11 +113,11 @@
                 /* complex exponential
                 vc = 64.0 * sin(i*M_PI/128.0 * (k + 0.5) * (2.0*n - 255.0));
                 */
-                vc.re = 64.0 * cos(M_PI/128.0 * (k + 0.5) * (2.0*n - 255.0));
-                vc.im = 64.0 * sin(M_PI/128.0 * (k + 0.5) * (2.0*n - 255.0));
+                RE(vc) = 64.0 * cos(M_PI/128.0 * (k + 0.5) * (2.0*n - 255.0));
+                IM(vc) = 64.0 * sin(M_PI/128.0 * (k + 0.5) * (2.0*n - 255.0));
 
                 /* take the real part only */
-                v[n] += Xlow[k][l].re * vc.re - Xlow[k][l].im * vc.im;
+                v[n] += RE(Xlow[k][l]) * RE(vc) - IM(Xlow[k][l]) * IM(vc);
             }
         }
 
@@ -154,136 +150,5 @@
         }
     }
 }
-
-static real_t qmf_c[] = {
-    0.0000000000, -0.0005525286, -0.0005617692, -0.0004947518, -0.0004875227,
-    -0.0004893791, -0.0005040714, -0.0005226564, -0.0005466565, -0.0005677802,
-    -0.0005870930, -0.0006132747, -0.0006312493, -0.0006540333, -0.0006777690,
-    -0.0006941614, -0.0007157736, -0.0007255043, -0.0007440941, -0.0007490598,
-    -0.0007681371, -0.0007724848, -0.0007834332, -0.0007779869, -0.0007803664,
-    -0.0007801449, -0.0007757977, -0.0007630793, -0.0007530001, -0.0007319357,
-    -0.0007215391, -0.0006917937, -0.0006650415, -0.0006341594, -0.0005946118,
-    -0.0005564576, -0.0005145572, -0.0004606325, -0.0004095121, -0.0003501175,
-    -0.0002896981, -0.0002098337, -0.0001446380, -0.0000617334, 0.0000134949,
-    0.0001094383, 0.0002043017, 0.0002949531, 0.0004026540, 0.0005107388, 
-    0.0006239376, 0.0007458025, 0.0008608443, 0.0009885988, 0.0011250155, 
-    0.0012577884, 0.0013902494, 0.0015443219, 0.0016868083, 0.0018348265,
-    0.0019841140, 0.0021461583, 0.0023017254, 0.0024625616, 0.0026201758,
-    0.0027870464, 0.0029469447, 0.0031125420, 0.0032739613, 0.0034418874,
-    0.0036008268, 0.0037603922, 0.0039207432, 0.0040819753, 0.0042264269,
-    0.0043730719, 0.0045209852, 0.0046606460, 0.0047932560, 0.0049137603,
-    0.0050393022, 0.0051407353, 0.0052461166, 0.0053471681, 0.0054196775,
-    0.0054876040, 0.0055475714, 0.0055938023, 0.0056220643, 0.0056455196,
-    0.0056389199, 0.0056266114, 0.0055917128, 0.0055404363, 0.0054753783,
-    0.0053838975, 0.0052715758, 0.0051382275, 0.0049839687, 0.0048109469,
-    0.0046039530, 0.0043801861, 0.0041251642, 0.0038456408, 0.0035401246,
-    0.0032091885, 0.0028446757, 0.0024508540, 0.0020274176, 0.0015784682,
-    0.0010902329, 0.0005832264, 0.0000276045, -0.0005464280, -0.0011568135,
-    -0.0018039472, -0.0024826723, -0.0031933778, -0.0039401124, -0.0047222596,
-    -0.0055337211, -0.0063792293, -0.0072615816, -0.0081798233, -0.0091325329,
-    -0.0101150215, -0.0111315548, -0.0121849995, 0.0132718220, 0.0143904666,
-    0.0155405553, 0.0167324712, 0.0179433381, 0.0191872431, 0.0204531793,
-    0.0217467550, 0.0230680169, 0.0244160992, 0.0257875847, 0.0271859429,
-    0.0286072173, 0.0300502657, 0.0315017608, 0.0329754081, 0.0344620948,
-    0.0359697560, 0.0374812850, 0.0390053679, 0.0405349170, 0.0420649094,
-    0.0436097542, 0.0451488405, 0.0466843027, 0.0482165720, 0.0497385755,
-    0.0512556155, 0.0527630746, 0.0542452768, 0.0557173648, 0.0571616450,
-    0.0585915683, 0.0599837480, 0.0613455171, 0.0626857808, 0.0639715898,
-    0.0652247106, 0.0664367512, 0.0676075985, 0.0687043828, 0.0697630244,
-    0.0707628710, 0.0717002673, 0.0725682583, 0.0733620255, 0.0741003642,
-    0.0747452558, 0.0753137336, 0.0758008358, 0.0761992479, 0.0764992170,
-    0.0767093490, 0.0768173975, 0.0768230011, 0.0767204924, 0.0765050718,
-    0.0761748321, 0.0757305756, 0.0751576255, 0.0744664394, 0.0736406005,
-    0.0726774642, 0.0715826364, 0.0703533073, 0.0689664013, 0.0674525021,
-    0.0657690668, 0.0639444805, 0.0619602779, 0.0598166570, 0.0575152691,
-    0.0550460034, 0.0524093821, 0.0495978676, 0.0466303305, 0.0434768782,
-    0.0401458278, 0.0366418116, 0.0329583930, 0.0290824006, 0.0250307561,
-    0.0207997072, 0.0163701258, 0.0117623832, 0.0069636862, 0.0019765601,
-    -0.0032086896, -0.0085711749, -0.0141288827, -0.0198834129, -0.0258227288,
-    -0.0319531274, -0.0382776572, -0.0447806821, -0.0514804176, -0.0583705326,
-    -0.0654409853, -0.0726943300, -0.0801372934, -0.0877547536, -0.0955533352,
-    -0.1035329531, -0.1116826931, -0.1200077984, -0.1285002850, -0.1371551761,
-    -0.1459766491, -0.1549607071, -0.1640958855, -0.1733808172, -0.1828172548,
-    -0.1923966745, -0.2021250176, -0.2119735853, -0.2219652696, -0.2320690870,
-    -0.2423016884, -0.2526480309, -0.2631053299, -0.2736634040, -0.2843214189,
-    -0.2950716717, -0.3059098575, -0.3168278913, -0.3278113727, -0.3388722693,
-    -0.3499914122, 0.3611589903, 0.3723795546, 0.3836350013, 0.3949211761,
-    0.4062317676, 0.4175696896, 0.4289119920, 0.4402553754, 0.4515996535,
-    0.4629308085, 0.4742453214, 0.4855253091, 0.4967708254, 0.5079817500,
-    0.5191234970, 0.5302240895, 0.5412553448, 0.5522051258, 0.5630789140, 
-    0.5738524131, 0.5845403235, 0.5951123086, 0.6055783538, 0.6159109932,
-    0.6261242695, 0.6361980107, 0.6461269695, 0.6559016302, 0.6655139880,
-    0.6749663190, 0.6842353293, 0.6933282376, 0.7022388719, 0.7109410426,
-    0.7194462634, 0.7277448900, 0.7358211758, 0.7436827863, 0.7513137456,
-    0.7587080760, 0.7658674865, 0.7727780881, 0.7794287519, 0.7858353120,
-    0.7919735841, 0.7978466413, 0.8034485751, 0.8087695004, 0.8138191270,
-    0.8185776004, 0.8230419890, 0.8272275347, 0.8311038457, 0.8346937361,
-    0.8379717337, 0.8409541392, 0.8436238281, 0.8459818469, 0.8480315777,
-    0.8497805198, 0.8511971524, 0.8523047035, 0.8531020949, 0.8535720573,
-    0.8537385600, 0.8535720573, 0.8531020949, 0.8523047035, 0.8511971524,
-    0.8497805198, 0.8480315777, 0.8459818469, 0.8436238281, 0.8409541392,
-    0.8379717337, 0.8346937361, 0.8311038457, 0.8272275347, 0.8230419890,
-    0.8185776004, 0.8138191270, 0.8087695004, 0.8034485751, 0.7978466413,
-    0.7919735841, 0.7858353120, 0.7794287519, 0.7727780881, 0.7658674865,
-    0.7587080760, 0.7513137456, 0.7436827863, 0.7358211758, 0.7277448900,
-    0.7194462634, 0.7109410426, 0.7022388719, 0.6933282376, 0.6842353293,
-    0.6749663190, 0.6655139880, 0.6559016302, 0.6461269695, 0.6361980107,
-    0.6261242695, 0.6159109932, 0.6055783538, 0.5951123086, 0.5845403235,
-    0.5738524131, 0.5630789140, 0.5522051258, 0.5412553448, 0.5302240895,
-    0.5191234970, 0.5079817500, 0.4967708254, 0.4855253091, 0.4742453214,
-    0.4629308085, 0.4515996535, 0.4402553754, 0.4289119920, 0.4175696896,
-    0.4062317676, 0.3949211761, 0.3836350013, 0.3723795546, -0.3611589903,
-    -0.3499914122, -0.3388722693, -0.3278113727, -0.3168278913, -0.3059098575,
-    -0.2950716717, -0.2843214189, -0.2736634040, -0.2631053299, -0.2526480309,
-    -0.2423016884, -0.2320690870, -0.2219652696, -0.2119735853, -0.2021250176,
-    -0.1923966745, -0.1828172548, -0.1733808172, -0.1640958855, -0.1549607071,
-    -0.1459766491, -0.1371551761, -0.1285002850, -0.1200077984, -0.1116826931,
-    -0.1035329531, -0.0955533352, -0.0877547536, -0.0801372934, -0.0726943300,
-    -0.0654409853, -0.0583705326, -0.0514804176, -0.0447806821, -0.0382776572,
-    -0.0319531274, -0.0258227288, -0.0198834129, -0.0141288827, -0.0085711749,
-    -0.0032086896, 0.0019765601, 0.0069636862, 0.0117623832, 0.0163701258,
-    0.0207997072, 0.0250307561, 0.0290824006, 0.0329583930, 0.0366418116,
-    0.0401458278, 0.0434768782, 0.0466303305, 0.0495978676, 0.0524093821,
-    0.0550460034, 0.0575152691, 0.0598166570, 0.0619602779, 0.0639444805,
-    0.0657690668, 0.0674525021, 0.0689664013, 0.0703533073, 0.0715826364,
-    0.0726774642, 0.0736406005, 0.0744664394, 0.0751576255, 0.0757305756,
-    0.0761748321, 0.0765050718, 0.0767204924, 0.0768230011, 0.0768173975,
-    0.0767093490, 0.0764992170, 0.0761992479, 0.0758008358, 0.0753137336,
-    0.0747452558, 0.0741003642, 0.0733620255, 0.0725682583, 0.0717002673,
-    0.0707628710, 0.0697630244, 0.0687043828, 0.0676075985, 0.0664367512,
-    0.0652247106, 0.0639715898, 0.0626857808, 0.0613455171, 0.0599837480,
-    0.0585915683, 0.0571616450, 0.0557173648, 0.0542452768, 0.0527630746,
-    0.0512556155, 0.0497385755, 0.0482165720, 0.0466843027, 0.0451488405,
-    0.0436097542, 0.0420649094, 0.0405349170, 0.0390053679, 0.0374812850,
-    0.0359697560, 0.0344620948, 0.0329754081, 0.0315017608, 0.0300502657,
-    0.0286072173, 0.0271859429, 0.0257875847, 0.0244160992, 0.0230680169,
-    0.0217467550, 0.0204531793, 0.0191872431, 0.0179433381, 0.0167324712,
-    0.0155405553, 0.0143904666, -0.0132718220, -0.0121849995, -0.0111315548,
-    -0.0101150215, -0.0091325329, -0.0081798233, -0.0072615816, -0.0063792293,
-    -0.0055337211, -0.0047222596, -0.0039401124, -0.0031933778, -0.0024826723,
-    -0.0018039472, -0.0011568135, -0.0005464280, 0.0000276045, 0.0005832264,
-    0.0010902329, 0.0015784682, 0.0020274176, 0.0024508540, 0.0028446757,
-    0.0032091885, 0.0035401246, 0.0038456408, 0.0041251642, 0.0043801861,
-    0.0046039530, 0.0048109469, 0.0049839687, 0.0051382275, 0.0052715758,
-    0.0053838975, 0.0054753783, 0.0055404363, 0.0055917128, 0.0056266114,
-    0.0056389199, 0.0056455196, 0.0056220643, 0.0055938023, 0.0055475714,
-    0.0054876040, 0.0054196775, 0.0053471681, 0.0052461166, 0.0051407353,
-    0.0050393022, 0.0049137603, 0.0047932560, 0.0046606460, 0.0045209852,
-    0.0043730719, 0.0042264269, 0.0040819753, 0.0039207432, 0.0037603922,
-    0.0036008268, 0.0034418874, 0.0032739613, 0.0031125420, 0.0029469447,
-    0.0027870464, 0.0026201758, 0.0024625616, 0.0023017254, 0.0021461583,
-    0.0019841140, 0.0018348265, 0.0016868083, 0.0015443219, 0.0013902494,
-    0.0012577884, 0.0011250155, 0.0009885988, 0.0008608443, 0.0007458025,
-    0.0006239376, 0.0005107388, 0.0004026540, 0.0002949531, 0.0002043017,
-    0.0001094383, 0.0000134949, -0.0000617334, -0.0001446380, -0.0002098337,
-    -0.0002896981, -0.0003501175, -0.0004095121, -0.0004606325, -0.0005145572,
-    -0.0005564576, -0.0005946118, -0.0006341594, -0.0006650415, -0.0006917937,
-    -0.0007215391, -0.0007319357, -0.0007530001, -0.0007630793, -0.0007757977,
-    -0.0007801449, -0.0007803664, -0.0007779869, -0.0007834332, -0.0007724848,
-    -0.0007681371, -0.0007490598, -0.0007440941, -0.0007255043, -0.0007157736,
-    -0.0006941614, -0.0006777690, -0.0006540333, -0.0006312493, -0.0006132747,
-    -0.0005870930, -0.0005677802, -0.0005466565, -0.0005226564, -0.0005040714,
-    -0.0004893791, -0.0004875227, -0.0004947518, -0.0005617692, -0.000552528
-};
 
 #endif
\ No newline at end of file
--- a/libfaad/sbr_qmf.h
+++ b/libfaad/sbr_qmf.h
@@ -16,11 +16,9 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: sbr_qmf.h,v 1.2 2002/04/21 09:00:40 menno Exp $
+** $Id: sbr_qmf.h,v 1.3 2002/09/29 22:19:48 menno Exp $
 **/
 
-#ifdef SBR
-
 #ifndef __SBR_QMF_H__
 #define __SBR_QMF_H__
 
@@ -28,14 +26,147 @@
 extern "C" {
 #endif
 
-static real_t qmf_c[];
-
 void sbr_qmf_analysis(real_t *input, complex_t **Xlow);
 void sbr_qmf_synthesis(complex_t **Xlow, real_t *output);
 
+#ifdef _MSC_VER
+#pragma warning(disable:4305)
+#pragma warning(disable:4244)
+#endif
+
+static real_t qmf_c[] = {
+    0.0000000000, -0.0005525286, -0.0005617692, -0.0004947518, -0.0004875227,
+    -0.0004893791, -0.0005040714, -0.0005226564, -0.0005466565, -0.0005677802,
+    -0.0005870930, -0.0006132747, -0.0006312493, -0.0006540333, -0.0006777690,
+    -0.0006941614, -0.0007157736, -0.0007255043, -0.0007440941, -0.0007490598,
+    -0.0007681371, -0.0007724848, -0.0007834332, -0.0007779869, -0.0007803664,
+    -0.0007801449, -0.0007757977, -0.0007630793, -0.0007530001, -0.0007319357,
+    -0.0007215391, -0.0006917937, -0.0006650415, -0.0006341594, -0.0005946118,
+    -0.0005564576, -0.0005145572, -0.0004606325, -0.0004095121, -0.0003501175,
+    -0.0002896981, -0.0002098337, -0.0001446380, -0.0000617334, 0.0000134949,
+    0.0001094383, 0.0002043017, 0.0002949531, 0.0004026540, 0.0005107388, 
+    0.0006239376, 0.0007458025, 0.0008608443, 0.0009885988, 0.0011250155, 
+    0.0012577884, 0.0013902494, 0.0015443219, 0.0016868083, 0.0018348265,
+    0.0019841140, 0.0021461583, 0.0023017254, 0.0024625616, 0.0026201758,
+    0.0027870464, 0.0029469447, 0.0031125420, 0.0032739613, 0.0034418874,
+    0.0036008268, 0.0037603922, 0.0039207432, 0.0040819753, 0.0042264269,
+    0.0043730719, 0.0045209852, 0.0046606460, 0.0047932560, 0.0049137603,
+    0.0050393022, 0.0051407353, 0.0052461166, 0.0053471681, 0.0054196775,
+    0.0054876040, 0.0055475714, 0.0055938023, 0.0056220643, 0.0056455196,
+    0.0056389199, 0.0056266114, 0.0055917128, 0.0055404363, 0.0054753783,
+    0.0053838975, 0.0052715758, 0.0051382275, 0.0049839687, 0.0048109469,
+    0.0046039530, 0.0043801861, 0.0041251642, 0.0038456408, 0.0035401246,
+    0.0032091885, 0.0028446757, 0.0024508540, 0.0020274176, 0.0015784682,
+    0.0010902329, 0.0005832264, 0.0000276045, -0.0005464280, -0.0011568135,
+    -0.0018039472, -0.0024826723, -0.0031933778, -0.0039401124, -0.0047222596,
+    -0.0055337211, -0.0063792293, -0.0072615816, -0.0081798233, -0.0091325329,
+    -0.0101150215, -0.0111315548, -0.0121849995, 0.0132718220, 0.0143904666,
+    0.0155405553, 0.0167324712, 0.0179433381, 0.0191872431, 0.0204531793,
+    0.0217467550, 0.0230680169, 0.0244160992, 0.0257875847, 0.0271859429,
+    0.0286072173, 0.0300502657, 0.0315017608, 0.0329754081, 0.0344620948,
+    0.0359697560, 0.0374812850, 0.0390053679, 0.0405349170, 0.0420649094,
+    0.0436097542, 0.0451488405, 0.0466843027, 0.0482165720, 0.0497385755,
+    0.0512556155, 0.0527630746, 0.0542452768, 0.0557173648, 0.0571616450,
+    0.0585915683, 0.0599837480, 0.0613455171, 0.0626857808, 0.0639715898,
+    0.0652247106, 0.0664367512, 0.0676075985, 0.0687043828, 0.0697630244,
+    0.0707628710, 0.0717002673, 0.0725682583, 0.0733620255, 0.0741003642,
+    0.0747452558, 0.0753137336, 0.0758008358, 0.0761992479, 0.0764992170,
+    0.0767093490, 0.0768173975, 0.0768230011, 0.0767204924, 0.0765050718,
+    0.0761748321, 0.0757305756, 0.0751576255, 0.0744664394, 0.0736406005,
+    0.0726774642, 0.0715826364, 0.0703533073, 0.0689664013, 0.0674525021,
+    0.0657690668, 0.0639444805, 0.0619602779, 0.0598166570, 0.0575152691,
+    0.0550460034, 0.0524093821, 0.0495978676, 0.0466303305, 0.0434768782,
+    0.0401458278, 0.0366418116, 0.0329583930, 0.0290824006, 0.0250307561,
+    0.0207997072, 0.0163701258, 0.0117623832, 0.0069636862, 0.0019765601,
+    -0.0032086896, -0.0085711749, -0.0141288827, -0.0198834129, -0.0258227288,
+    -0.0319531274, -0.0382776572, -0.0447806821, -0.0514804176, -0.0583705326,
+    -0.0654409853, -0.0726943300, -0.0801372934, -0.0877547536, -0.0955533352,
+    -0.1035329531, -0.1116826931, -0.1200077984, -0.1285002850, -0.1371551761,
+    -0.1459766491, -0.1549607071, -0.1640958855, -0.1733808172, -0.1828172548,
+    -0.1923966745, -0.2021250176, -0.2119735853, -0.2219652696, -0.2320690870,
+    -0.2423016884, -0.2526480309, -0.2631053299, -0.2736634040, -0.2843214189,
+    -0.2950716717, -0.3059098575, -0.3168278913, -0.3278113727, -0.3388722693,
+    -0.3499914122, 0.3611589903, 0.3723795546, 0.3836350013, 0.3949211761,
+    0.4062317676, 0.4175696896, 0.4289119920, 0.4402553754, 0.4515996535,
+    0.4629308085, 0.4742453214, 0.4855253091, 0.4967708254, 0.5079817500,
+    0.5191234970, 0.5302240895, 0.5412553448, 0.5522051258, 0.5630789140, 
+    0.5738524131, 0.5845403235, 0.5951123086, 0.6055783538, 0.6159109932,
+    0.6261242695, 0.6361980107, 0.6461269695, 0.6559016302, 0.6655139880,
+    0.6749663190, 0.6842353293, 0.6933282376, 0.7022388719, 0.7109410426,
+    0.7194462634, 0.7277448900, 0.7358211758, 0.7436827863, 0.7513137456,
+    0.7587080760, 0.7658674865, 0.7727780881, 0.7794287519, 0.7858353120,
+    0.7919735841, 0.7978466413, 0.8034485751, 0.8087695004, 0.8138191270,
+    0.8185776004, 0.8230419890, 0.8272275347, 0.8311038457, 0.8346937361,
+    0.8379717337, 0.8409541392, 0.8436238281, 0.8459818469, 0.8480315777,
+    0.8497805198, 0.8511971524, 0.8523047035, 0.8531020949, 0.8535720573,
+    0.8537385600, 0.8535720573, 0.8531020949, 0.8523047035, 0.8511971524,
+    0.8497805198, 0.8480315777, 0.8459818469, 0.8436238281, 0.8409541392,
+    0.8379717337, 0.8346937361, 0.8311038457, 0.8272275347, 0.8230419890,
+    0.8185776004, 0.8138191270, 0.8087695004, 0.8034485751, 0.7978466413,
+    0.7919735841, 0.7858353120, 0.7794287519, 0.7727780881, 0.7658674865,
+    0.7587080760, 0.7513137456, 0.7436827863, 0.7358211758, 0.7277448900,
+    0.7194462634, 0.7109410426, 0.7022388719, 0.6933282376, 0.6842353293,
+    0.6749663190, 0.6655139880, 0.6559016302, 0.6461269695, 0.6361980107,
+    0.6261242695, 0.6159109932, 0.6055783538, 0.5951123086, 0.5845403235,
+    0.5738524131, 0.5630789140, 0.5522051258, 0.5412553448, 0.5302240895,
+    0.5191234970, 0.5079817500, 0.4967708254, 0.4855253091, 0.4742453214,
+    0.4629308085, 0.4515996535, 0.4402553754, 0.4289119920, 0.4175696896,
+    0.4062317676, 0.3949211761, 0.3836350013, 0.3723795546, -0.3611589903,
+    -0.3499914122, -0.3388722693, -0.3278113727, -0.3168278913, -0.3059098575,
+    -0.2950716717, -0.2843214189, -0.2736634040, -0.2631053299, -0.2526480309,
+    -0.2423016884, -0.2320690870, -0.2219652696, -0.2119735853, -0.2021250176,
+    -0.1923966745, -0.1828172548, -0.1733808172, -0.1640958855, -0.1549607071,
+    -0.1459766491, -0.1371551761, -0.1285002850, -0.1200077984, -0.1116826931,
+    -0.1035329531, -0.0955533352, -0.0877547536, -0.0801372934, -0.0726943300,
+    -0.0654409853, -0.0583705326, -0.0514804176, -0.0447806821, -0.0382776572,
+    -0.0319531274, -0.0258227288, -0.0198834129, -0.0141288827, -0.0085711749,
+    -0.0032086896, 0.0019765601, 0.0069636862, 0.0117623832, 0.0163701258,
+    0.0207997072, 0.0250307561, 0.0290824006, 0.0329583930, 0.0366418116,
+    0.0401458278, 0.0434768782, 0.0466303305, 0.0495978676, 0.0524093821,
+    0.0550460034, 0.0575152691, 0.0598166570, 0.0619602779, 0.0639444805,
+    0.0657690668, 0.0674525021, 0.0689664013, 0.0703533073, 0.0715826364,
+    0.0726774642, 0.0736406005, 0.0744664394, 0.0751576255, 0.0757305756,
+    0.0761748321, 0.0765050718, 0.0767204924, 0.0768230011, 0.0768173975,
+    0.0767093490, 0.0764992170, 0.0761992479, 0.0758008358, 0.0753137336,
+    0.0747452558, 0.0741003642, 0.0733620255, 0.0725682583, 0.0717002673,
+    0.0707628710, 0.0697630244, 0.0687043828, 0.0676075985, 0.0664367512,
+    0.0652247106, 0.0639715898, 0.0626857808, 0.0613455171, 0.0599837480,
+    0.0585915683, 0.0571616450, 0.0557173648, 0.0542452768, 0.0527630746,
+    0.0512556155, 0.0497385755, 0.0482165720, 0.0466843027, 0.0451488405,
+    0.0436097542, 0.0420649094, 0.0405349170, 0.0390053679, 0.0374812850,
+    0.0359697560, 0.0344620948, 0.0329754081, 0.0315017608, 0.0300502657,
+    0.0286072173, 0.0271859429, 0.0257875847, 0.0244160992, 0.0230680169,
+    0.0217467550, 0.0204531793, 0.0191872431, 0.0179433381, 0.0167324712,
+    0.0155405553, 0.0143904666, -0.0132718220, -0.0121849995, -0.0111315548,
+    -0.0101150215, -0.0091325329, -0.0081798233, -0.0072615816, -0.0063792293,
+    -0.0055337211, -0.0047222596, -0.0039401124, -0.0031933778, -0.0024826723,
+    -0.0018039472, -0.0011568135, -0.0005464280, 0.0000276045, 0.0005832264,
+    0.0010902329, 0.0015784682, 0.0020274176, 0.0024508540, 0.0028446757,
+    0.0032091885, 0.0035401246, 0.0038456408, 0.0041251642, 0.0043801861,
+    0.0046039530, 0.0048109469, 0.0049839687, 0.0051382275, 0.0052715758,
+    0.0053838975, 0.0054753783, 0.0055404363, 0.0055917128, 0.0056266114,
+    0.0056389199, 0.0056455196, 0.0056220643, 0.0055938023, 0.0055475714,
+    0.0054876040, 0.0054196775, 0.0053471681, 0.0052461166, 0.0051407353,
+    0.0050393022, 0.0049137603, 0.0047932560, 0.0046606460, 0.0045209852,
+    0.0043730719, 0.0042264269, 0.0040819753, 0.0039207432, 0.0037603922,
+    0.0036008268, 0.0034418874, 0.0032739613, 0.0031125420, 0.0029469447,
+    0.0027870464, 0.0026201758, 0.0024625616, 0.0023017254, 0.0021461583,
+    0.0019841140, 0.0018348265, 0.0016868083, 0.0015443219, 0.0013902494,
+    0.0012577884, 0.0011250155, 0.0009885988, 0.0008608443, 0.0007458025,
+    0.0006239376, 0.0005107388, 0.0004026540, 0.0002949531, 0.0002043017,
+    0.0001094383, 0.0000134949, -0.0000617334, -0.0001446380, -0.0002098337,
+    -0.0002896981, -0.0003501175, -0.0004095121, -0.0004606325, -0.0005145572,
+    -0.0005564576, -0.0005946118, -0.0006341594, -0.0006650415, -0.0006917937,
+    -0.0007215391, -0.0007319357, -0.0007530001, -0.0007630793, -0.0007757977,
+    -0.0007801449, -0.0007803664, -0.0007779869, -0.0007834332, -0.0007724848,
+    -0.0007681371, -0.0007490598, -0.0007440941, -0.0007255043, -0.0007157736,
+    -0.0006941614, -0.0006777690, -0.0006540333, -0.0006312493, -0.0006132747,
+    -0.0005870930, -0.0005677802, -0.0005466565, -0.0005226564, -0.0005040714,
+    -0.0004893791, -0.0004875227, -0.0004947518, -0.0005617692, -0.000552528
+};
+
 #ifdef __cplusplus
 }
 #endif
 #endif
 
-#endif /* SBR */
\ No newline at end of file
--- a/libfaad/sbr_syntax.c
+++ b/libfaad/sbr_syntax.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: sbr_syntax.c,v 1.4 2002/04/23 21:08:26 menno Exp $
+** $Id: sbr_syntax.c,v 1.5 2002/09/29 22:19:48 menno Exp $
 **/
 
 /*
@@ -61,6 +61,9 @@
     } else if (bs_extension_type == SBR_STD) {
         sbr_data(ld, sbr, id_aac);
     }
+
+    /* no error */
+    return 0;
 }
 
 /* table 3 */
@@ -112,6 +115,18 @@
             DEBUGVAR(1,217,"sbr_header(): bs_smoothing_mode"));
         faad_get1bit(ld
             DEBUGVAR(1,218,"sbr_header(): bs_reserved"));
+    }
+
+    /* if these are different from the previous frame: Reset = 1 */
+    if (bs_start_freq
+        bs_stop_freq
+        bs_freq_scale
+        bs_alter_scale
+        bs_xover_band
+        bs_noise_bands
+        )
+    {
+        Reset = 1
     }
 }
 
--- a/libfaad/sbr_syntax.h
+++ b/libfaad/sbr_syntax.h
@@ -16,11 +16,9 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: sbr_syntax.h,v 1.3 2002/04/23 21:08:26 menno Exp $
+** $Id: sbr_syntax.h,v 1.4 2002/09/29 22:19:48 menno Exp $
 **/
 
-#ifdef SBR
-
 #ifndef __SBR_SYNTAX_H__
 #define __SBR_SYNTAX_H__
 
@@ -112,4 +110,3 @@
 #endif
 #endif /* __SBR_SYNTAX_H__ */
 
-#endif /* SBR */
\ No newline at end of file
--- /dev/null
+++ b/libfaad/sbr_util.c
@@ -1,0 +1,248 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** $Id: sbr_util.c,v 1.1 2002/09/29 22:19:48 menno Exp $
+**/
+
+#include "common.h"
+
+#ifdef SBR
+
+#include <stdlib.h>
+
+#include "sbr_util.h"
+
+/* calculate the start QMF channel for the master frequency band table */
+/* parameter is also called k0 */
+uint16_t qmf_start_channel(uint8_t bs_start_freq, uint32_t sample_rate)
+{
+    static uint8_t offset[] = {
+        0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24, 28, 33
+    };
+    uint8_t startMin;
+
+    if (sample_rate >= 64000)
+    {
+        startMin = (uint8_t)((5000.*128.)/(float)sample_rate + 0.5);
+    } else if (sample_rate < 32000) {
+        startMin = (uint8_t)((3000.*128.)/(float)sample_rate + 0.5);
+    } else {
+        startMin = (uint8_t)((4000.*128.)/(float)sample_rate + 0.5);
+    }
+
+    return startMin + offset[bs_start_freq];
+}
+
+static int32_t longcmp(const void *a, const void *b)
+{
+    return ((int32_t)(*(int32_t*)a - *(int32_t*)b));
+}
+
+/* calculate the stop QMF channel for the master frequency band table */
+/* parameter is also called k2 */
+uint16_t qmf_stop_channel(uint8_t bs_stop_freq, uint32_t sample_rate,
+                          uint16_t k0)
+{
+    if (bs_stop_freq == 15)
+        return k0 * 3;
+    else if (bs_stop_freq == 14)
+        return k0 * 2;
+    else {
+        uint8_t i;
+        uint8_t stopMin;
+        uint32_t stopDk[13], k2;
+
+        if (sample_rate >= 64000)
+        {
+            stopMin = (uint8_t)((10000.*128.)/(float)sample_rate + 0.5);
+        } else if (sample_rate < 32000) {
+            stopMin = (uint8_t)((6000.*128.)/(float)sample_rate + 0.5);
+        } else {
+            stopMin = (uint8_t)((8000.*128.)/(float)sample_rate + 0.5);
+        }
+
+        /* TODO: PUT THIS IN MAPLE, CAN BE SIMPLIFIED A LOT */
+        for (i = 0; i < 13; i++)
+        {
+            stopDk[i] = (uint32_t)(stopMin*pow(64./(float)stopMin, (i+1)/13.) + 0.5) -
+                (uint32_t)(stopMin*pow(64./(float)stopMin, i/13.) + 0.5);
+        }
+
+        /* needed? or does this always reverse the array? */
+        qsort(stopDk, 13, sizeof(stopDk[0]), longcmp);
+
+        k2 = stopMin;
+        for (i = 0; i < bs_stop_freq-1; i++)
+        {
+            k2 += stopDk[i];
+        }
+        return k2;
+    }
+
+    return 0;
+}
+
+/* calculate the master frequency table from k0, k2, bs_freq_scale
+   and bs_alter_scale
+
+   returns N_master
+
+   version for bs_freq_scale = 0
+*/
+uint32_t master_frequency_table_fs0(int32_t *f_master,
+                                    uint16_t k0, uint16_t k2,
+                                    uint8_t bs_alter_scale)
+{
+    int8_t incr;
+    uint8_t k;
+    uint8_t dk;
+    uint32_t nrBands, k2Achieved;
+    int32_t k2Diff, vDk[100 /*TODO*/];
+
+    /* mft only defined for k2 > k0 */
+    if (k2 <= k0)
+        return 0;
+
+    dk = bs_alter_scale ? 2 : 1;
+    nrBands = 2 * (int32_t)((k2-k0)/(float)dk*2. + 0.5);
+
+    k2Achieved = k0 + nrBands * dk;
+    k2Diff = k2 - k2Achieved;
+    for (k = 0; k <= nrBands; k++)
+        vDk[k] = dk;
+
+    if (k2Diff)
+    {
+        incr = (k2Diff > 0) ? -1 : 1;
+        k = (k2Diff > 0) ? (nrBands-1) : 0;
+
+        while (k2Diff != 0)
+        {
+            vDk[k] = vDk[k] - 1;
+            k += incr;
+            k2Diff += incr;
+        }
+    }
+
+    f_master[0] = k0;
+    for (k = 1; k <= nrBands; k++)
+        f_master[k] = f_master[k-1] + vDk[k-1];
+
+    return nrBands;
+}
+
+/*
+   version for bs_freq_scale > 0
+*/
+uint32_t master_frequency_table(int32_t *f_master,
+                                uint16_t k0, uint16_t k2,
+                                uint8_t bs_freq_scale,
+                                uint8_t bs_alter_scale)
+{
+    uint8_t k, bands, twoRegions;
+    uint16_t k1;
+    uint32_t nrBand0, nrBand1, N_master;
+    int32_t max_vDk0, min_vDk1;
+    int32_t vDk0[100 /*TODO*/], vDk1[100 /*TODO*/];
+    int32_t vk0[100 /*TODO*/], vk1[100 /*TODO*/];
+    float warp;
+    uint8_t temp1[] = { 12, 10, 8 };
+    float temp2[] = { 1.0, 1.3 };
+
+    /* mft only defined for k2 > k0 */
+    if (k2 <= k0)
+        return 0;
+
+    bands = temp1[bs_freq_scale-1];
+    warp = temp2[bs_alter_scale];
+
+    if ((float)k2/(float)k0 > 2.2449)
+    {
+        twoRegions = 1;
+        k1 = 2 * k0;
+    } else {
+        twoRegions = 0;
+        k1 = k2;
+    }
+
+    nrBand0 = 2 * (int32_t)(bands * log(k1/k0)/(2.0*log(2.0)) + 0.5);
+    max_vDk0 = 0;
+    for (k = 0; k <= nrBand0; k++)
+    {
+        vDk0[k] = (int32_t)(k0 * pow((float)k1/(float)k0, (k+1)/(float)nrBand0)+0.5) -
+            (int32_t)(k0 * pow((float)k1/(float)k0, k/(float)nrBand0)+0.5);
+        max_vDk0 = (max_vDk0 < vDk0[k]) ? vDk0[k] : max_vDk0;
+    }
+
+    /* needed? */
+    qsort(vDk0, nrBand0 + 1, sizeof(vDk0[0]), longcmp);
+
+    vk0[0] = k0;
+    for (k = 1; k <= nrBand0; k++)
+    {
+        vk0[k] = vk0[k-1] + vDk0[k-1];
+    }
+
+    if (!twoRegions)
+    {
+        for (k = 0; k <= nrBand0; k++)
+            f_master[k] = vk0[k];
+
+        return nrBand0;
+    }
+
+    nrBand1 = 2 * (int32_t)(bands * log((float)k2/(float)k1)/(2.0 * log(2.0) * warp) + 0.5);
+    min_vDk1 = 9999999;
+    for (k = 0; k <= nrBand1 - 1; k++)
+    {
+        vDk1[k] = (int32_t)(k0 * pow((float)k1/(float)k0, (k+1)/(float)nrBand1)+0.5) -
+            (int32_t)(k0 * pow((float)k1/(float)k0, k/(float)nrBand1)+0.5);
+        min_vDk1 = (min_vDk1 > vDk1[k]) ? vDk1[k] : min_vDk1;
+    }
+
+    if (min_vDk1 < max_vDk0)
+    {
+        int32_t change;
+
+        qsort(vDk1, nrBand1 + 1, sizeof(vDk1[0]), longcmp);
+        change = max_vDk0 - vDk1[0];
+        vDk1[0] = max_vDk0;
+        vDk1[nrBand1 - 1] = vDk1[nrBand1 - 1] - change;
+    }
+
+    qsort(vDk1, nrBand1 + 1, sizeof(vDk1[0]), longcmp);
+    vk1[0] = k1;
+    for (k = 1; k <= nrBand1; k++)
+    {
+        vk1[k] = vk1[k-1] + vDk1[k-1];
+    }
+
+    N_master = nrBand0 + nrBand1;
+    for (k = 0; k <= nrBand0; k++)
+    {
+        f_master[k] = vk0[k];
+    }
+    for (k = nrBand0 + 1; k <= N_master; k++)
+    {
+        f_master[k] = vk1[k - nrBand0];
+    }
+
+    return N_master;
+}
+
+#endif
--- /dev/null
+++ b/libfaad/sbr_util.h
@@ -1,0 +1,33 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**  
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+** 
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+** 
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** $Id: sbr_util.h,v 1.1 2002/09/29 22:19:48 menno Exp $
+**/
+
+#ifndef __SBR_UTIL_H__
+#define __SBR_UTIL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+