shithub: aacenc

Download patch

ref: ef32d5a8a81741b07fcd235e07690aeccafa5f72
parent: c73fe399a9d2456101c39a0af7dc973cab7ac7d7
author: menno <menno>
date: Tue Jul 29 04:59:11 EDT 2003

updated plugins to work with new faac

--- a/plugins/cooledit/CRegistry.cpp
+++ b/plugins/cooledit/CRegistry.cpp
@@ -21,8 +21,8 @@
 
 //#include "stdafx.h"
 #include <windows.h>
+#include <stdlib.h>		// malloc, free
 #include <string.h>
-#include <memory.h>
 #include "CRegistry.h"
 
 
--- a/plugins/cooledit/FAAC.def
+++ b/plugins/cooledit/FAAC.def
@@ -13,6 +13,6 @@
 	FilterOptionsString
 	FilterGetOptions
 	GetSuggestedSampleType
-	DIALOGMsgProc
-	FilterOptions
-	FilterSetOptions
+;	DIALOGMsgProc
+;	FilterOptions
+;	FilterSetOptions
--- a/plugins/cooledit/FAAC.dsp
+++ b/plugins/cooledit/FAAC.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
 
@@ -43,7 +43,7 @@
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FAAC_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "../../../faad2/common/faad" /I "../../include" /I "../../../faad2/include" /I "../../../faad2/common/mp4v2" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FAAC_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "../../../faad2/common/faad" /I "../../include" /I "../../../faad2/include" /I "../../../faad2/common/mp4v2" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /YX /FD /c
 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x410 /d "NDEBUG"
@@ -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 ws2_32.lib 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 /incremental:yes /machine:I386 /out:"Release/FAAC.flt"
 
@@ -69,7 +69,7 @@
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FAAC_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../../faad2/common/faad" /I "../../include" /I "../../../faad2/include" /I "../../../faad2/common/mp4v2" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FAAC_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../../faad2/common/faad" /I "../../include" /I "../../../faad2/include" /I "../../../faad2/common/mp4v2" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /YX /FD /GZ /c
 # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x410 /d "_DEBUG"
@@ -77,10 +77,10 @@
 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 ws2_32.lib 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 /out:"Debug/FAAC.flt" /pdbtype:sept
-# SUBTRACT LINK32 /nodefaultlib
+# ADD LINK32 ws2_32.lib 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 /out:"C:\Program Files\Sound\Wav\CoolPro/FAAC.flt" /pdbtype:sept
+# SUBTRACT LINK32 /nodefaultlib /force
 
 !ENDIF 
 
--- a/plugins/cooledit/FAAC.rc
+++ b/plugins/cooledit/FAAC.rc
@@ -26,28 +26,28 @@
 // Dialog
 //
 
-IDD_ENCODER DIALOG DISCARDABLE  0, 0, 184, 126
+IDD_ENCODER DIALOG DISCARDABLE  0, 0, 197, 147
 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "MPEG4-AAC options"
 FONT 8, "MS Sans Serif"
 BEGIN
-    DEFPUSHBUTTON   "&OK",IDOK,72,107,36,14
-    PUSHBUTTON      "&Cancel",IDCANCEL,108,107,36,14
-    PUSHBUTTON      "&About",IDC_BTN_ABOUT,144,107,36,14
+    DEFPUSHBUTTON   "&OK",IDOK,85,128,36,14
+    PUSHBUTTON      "&Cancel",IDCANCEL,121,128,36,14
+    PUSHBUTTON      "&About",IDC_BTN_ABOUT,157,128,36,14
     CONTROL         "Automatic configuration",IDC_CHK_AUTOCFG,"Button",
                     BS_AUTOCHECKBOX | WS_TABSTOP,4,4,90,10
     CONTROL         "MPEG4",IDC_RADIO_MPEG4,"Button",BS_AUTORADIOBUTTON | 
-                    WS_GROUP,8,29,42,10
-    CONTROL         "MPEG2",IDC_RADIO_MPEG2,"Button",BS_AUTORADIOBUTTON,8,42,
-                    41,9
+                    WS_GROUP,9,29,40,10
+    CONTROL         "MPEG2",IDC_RADIO_MPEG2,"Button",BS_AUTORADIOBUTTON,9,42,
+                    40,9
     CONTROL         "Main",IDC_RADIO_MAIN,"Button",BS_AUTORADIOBUTTON | 
-                    WS_GROUP,12,73,31,10
-    CONTROL         "Low",IDC_RADIO_LOW,"Button",BS_AUTORADIOBUTTON,12,85,29,
+                    WS_GROUP,9,73,31,10
+    CONTROL         "LC",IDC_RADIO_LOW,"Button",BS_AUTORADIOBUTTON,9,85,25,
                     10
     CONTROL         "SSR",IDC_RADIO_SSR,"Button",BS_AUTORADIOBUTTON | 
-                    WS_DISABLED,12,97,31,10
-    CONTROL         "LTP",IDC_RADIO_LTP,"Button",BS_AUTORADIOBUTTON,12,109,
-                    29,10
+                    WS_DISABLED,9,97,31,10
+    CONTROL         "LTP",IDC_RADIO_LTP,"Button",BS_AUTORADIOBUTTON,9,109,29,
+                    10
     CONTROL         "Raw",IDC_RADIO_RAW,"Button",BS_AUTORADIOBUTTON | 
                     WS_GROUP,59,29,42,10
     CONTROL         "ADTS",IDC_RADIO_ADTS,"Button",BS_AUTORADIOBUTTON,59,42,
@@ -58,34 +58,45 @@
                     WS_TABSTOP,108,33,45,10
     CONTROL         "Use LFE channel",IDC_CHK_USELFE,"Button",
                     BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,108,46,67,10
-    COMBOBOX        IDC_CB_BITRATE,132,68,48,30,CBS_DROPDOWN | WS_VSCROLL | 
+    CONTROL         "Quality",IDC_RADIO_QUALITY,"Button",BS_AUTORADIOBUTTON | 
+                    WS_GROUP,61,73,37,10
+    COMBOBOX        IDC_CB_QUALITY,138,71,48,97,CBS_DROPDOWN | WS_VSCROLL | 
                     WS_TABSTOP
-    COMBOBOX        IDC_CB_BANDWIDTH,132,85,48,30,CBS_DROPDOWN | WS_VSCROLL | 
+    CONTROL         "Bitrate per channel",IDC_RADIO_BITRATE,"Button",
+                    BS_AUTORADIOBUTTON,61,89,75,10
+    COMBOBOX        IDC_CB_BITRATE,138,87,48,86,CBS_DROPDOWN | WS_VSCROLL | 
                     WS_TABSTOP
+    COMBOBOX        IDC_CB_BANDWIDTH,138,108,48,81,CBS_DROPDOWN | WS_VSCROLL | 
+                    WS_TABSTOP
     GROUPBOX        "AAC type",IDC_STATIC,4,18,48,38
     GROUPBOX        "Profile",IDC_STATIC,4,62,48,59
-    LTEXT           "Bitrate per channel",IDC_STATIC,59,73,60,8
-    LTEXT           "Bandwidth",IDC_STATIC,59,89,34,8
+    LTEXT           "Bandwidth",IDC_STATIC,73,111,34,8
     GROUPBOX        "Header",IDC_STATIC,55,18,48,38
+    GROUPBOX        "Encoding mode",IDC_STATIC,56,62,135,42
 END
 
-IDD_DECODER DIALOG DISCARDABLE  0, 0, 114, 76
+IDD_DECODER DIALOG DISCARDABLE  0, 0, 141, 94
 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
-CAPTION "MPEG4-AAC options"
+CAPTION "Raw .AAC options"
 FONT 8, "MS Sans Serif"
 BEGIN
-    DEFPUSHBUTTON   "&OK",IDOK,70,25,36,14
-    PUSHBUTTON      "&Cancel",IDCANCEL,70,40,36,14
-    PUSHBUTTON      "&About",IDC_BTN_ABOUT,70,55,36,14
+    DEFPUSHBUTTON   "&OK",IDOK,24,73,36,14
+    PUSHBUTTON      "&Cancel",IDCANCEL,61,73,36,14
+    PUSHBUTTON      "&About",IDC_BTN_ABOUT,97,73,36,14
     CONTROL         "Main",IDC_RADIO_MAIN,"Button",BS_AUTORADIOBUTTON | 
-                    WS_GROUP,15,17,31,10
-    CONTROL         "Low",IDC_RADIO_LOW,"Button",BS_AUTORADIOBUTTON,15,30,29,
+                    WS_GROUP,93,17,31,10
+    CONTROL         "Low",IDC_RADIO_LOW,"Button",BS_AUTORADIOBUTTON,93,30,29,
                     10
     CONTROL         "SSR",IDC_RADIO_SSR,"Button",BS_AUTORADIOBUTTON | 
-                    WS_DISABLED,15,41,31,10
-    CONTROL         "LTP",IDC_RADIO_LTP,"Button",BS_AUTORADIOBUTTON,15,54,29,
+                    WS_DISABLED,93,41,31,10
+    CONTROL         "LTP",IDC_RADIO_LTP,"Button",BS_AUTORADIOBUTTON,93,54,29,
                     10
-    GROUPBOX        "Profile",IDC_STATIC,7,7,48,62
+    GROUPBOX        "Profile",IDC_STATIC,85,7,48,61
+    COMBOBOX        IDC_CB_SAMPLERATE,13,48,62,87,CBS_DROPDOWN | WS_VSCROLL | 
+                    WS_TABSTOP
+    CONTROL         "Default settings",IDC_CHK_DEFAULTCFG,"Button",
+                    BS_AUTOCHECKBOX | WS_TABSTOP,7,11,64,10
+    GROUPBOX        "Sample rate",IDC_STATIC,7,37,73,31
 END
 
 
@@ -126,17 +137,17 @@
     IDD_ENCODER, DIALOG
     BEGIN
         LEFTMARGIN, 4
-        RIGHTMARGIN, 180
+        RIGHTMARGIN, 193
         TOPMARGIN, 4
-        BOTTOMMARGIN, 121
+        BOTTOMMARGIN, 142
     END
 
     IDD_DECODER, DIALOG
     BEGIN
         LEFTMARGIN, 7
-        RIGHTMARGIN, 106
+        RIGHTMARGIN, 133
         TOPMARGIN, 7
-        BOTTOMMARGIN, 69
+        BOTTOMMARGIN, 87
     END
 END
 #endif    // APSTUDIO_INVOKED
--- a/plugins/cooledit/Faac.cpp
+++ b/plugins/cooledit/Faac.cpp
@@ -20,9 +20,12 @@
 */
 
 #include <windows.h>
+#include <shellapi.h>	// ShellExecute
 #include <stdio.h>		// FILE *
+#include <stdlib.h>		// malloc, free
 #include "resource.h"
 #include "filters.h"	// CoolEdit
+#include <mp4.h>		// int32_t, ...
 #include <faac.h>
 #include <faad.h>		// FAAD2 version
 #include <win32_ver.h>	// mpeg4ip version
@@ -42,8 +45,10 @@
 
 // *********************************************************************************************
 
-#define RAW		0
-#define ADTS	1
+#ifdef	ADTS
+#undef	ADTS
+#define ADTS 1
+#endif
 
 // *********************************************************************************************
 
@@ -57,12 +62,168 @@
 //char			*dst_name;		// name of compressed file
 
 faacEncHandle	hEncoder;
+int32_t			*buffer;
 unsigned char	*bitbuf;
 DWORD			maxBytesOutput;
 long			samplesInput;
 } MYOUTPUT;
+
+
+
 // *********************************************************************************************
 
+
+
+#define SWAP32(x) (((x & 0xff) << 24) | ((x & 0xff00) << 8) \
+	| ((x & 0xff0000) >> 8) | ((x & 0xff000000) >> 24))
+#define SWAP16(x) (((x & 0xff) << 8) | ((x & 0xff00) >> 8))
+
+inline void To32bit(int32_t *buf, BYTE *bufi, int size, BYTE samplebytes, BYTE bigendian)
+{
+int i;
+
+	switch(samplebytes)
+	{
+	case 1:
+		// this is endian clean
+		for (i = 0; i < size; i++)
+			buf[i] = (bufi[i] - 128) * 65536;
+		break;
+		
+	case 2:
+#ifdef WORDS_BIGENDIAN
+		if (!bigendian)
+#else
+			if (bigendian)
+#endif
+			{
+				// swap bytes
+				for (i = 0; i < size; i++)
+				{
+					int16_t s = ((int16_t *)bufi)[i];
+					
+					s = SWAP16(s);
+					
+					buf[i] = ((u_int32_t)s) << 8;
+				}
+			}
+			else
+			{
+				// no swap
+				for (i = 0; i < size; i++)
+				{
+					int s = ((int16_t *)bufi)[i];
+					
+					buf[i] = s << 8;
+				}
+			}
+			break;
+			
+	case 3:
+		if (!bigendian)
+		{
+			for (i = 0; i < size; i++)
+			{
+				int s = bufi[3 * i] | (bufi[3 * i + 1] << 8) | (bufi[3 * i + 2] << 16);
+				
+				// fix sign
+				if (s & 0x800000)
+					s |= 0xff000000;
+				
+				buf[i] = s;
+			}
+		}
+		else // big endian input
+		{
+			for (i = 0; i < size; i++)
+			{
+				int s = (bufi[3 * i] << 16) | (bufi[3 * i + 1] << 8) | bufi[3 * i + 2];
+				
+				// fix sign
+				if (s & 0x800000)
+					s |= 0xff000000;
+				
+				buf[i] = s;
+			}
+		}
+		break;
+		
+	case 4:		
+#ifdef WORDS_BIGENDIAN
+		if (!bigendian)
+#else
+			if (bigendian)
+#endif
+			{
+				// swap bytes
+				for (i = 0; i < size; i++)
+				{
+					int s = bufi[i];
+					
+					buf[i] = SWAP32(s);
+				}
+			}
+			else
+				memcpy(buf,bufi,size*sizeof(u_int32_t));
+		/*
+		int exponent, mantissa;
+		float *bufo=(float *)buf;
+			
+			for (i = 0; i < size; i++)
+			{
+				exponent=bufi[(i<<2)+3]<<1;
+				if(bufi[i*4+2] & 0x80)
+					exponent|=0x01;
+				exponent-=126;
+				mantissa=(DWORD)bufi[(i<<2)+2]<<16;
+				mantissa|=(DWORD)bufi[(i<<2)+1]<<8;
+				mantissa|=bufi[(i<<2)];
+				bufo[i]=(float)ldexp(mantissa,exponent);
+			}*/
+			break;
+	}
+}
+// *********************************************************************************************
+/*
+DWORD PackCfg(MY_ENC_CFG *cfg)
+{
+DWORD dwOptions=0;
+
+	if(cfg->AutoCfg)
+		dwOptions=1<<31;
+	dwOptions|=(DWORD)cfg->EncCfg.mpegVersion<<30;
+	dwOptions|=(DWORD)cfg->EncCfg.aacObjectType<<28;
+	dwOptions|=(DWORD)cfg->EncCfg.allowMidside<<27;
+	dwOptions|=(DWORD)cfg->EncCfg.useTns<<26;
+	dwOptions|=(DWORD)cfg->EncCfg.useLfe<<25;
+	dwOptions|=(DWORD)cfg->EncCfg.outputFormat<<24;
+	if(cfg->UseQuality)
+		dwOptions|=(((DWORD)cfg->EncCfg.quantqual>>1)&0xff)<<16; // [2,512]
+	else
+		dwOptions|=(((DWORD)cfg->EncCfg.bitRate>>1)&0xff)<<16; // [2,512]
+	if(cfg->UseQuality)
+		dwOptions|=1<<15;
+	dwOptions|=((DWORD)cfg->EncCfg.bandWidth>>1)&&0x7fff; // [0,65536]
+
+	return dwOptions;
+}
+// -----------------------------------------------------------------------------------------------
+
+void UnpackCfg(MY_ENC_CFG *cfg, DWORD dwOptions)
+{
+	cfg->AutoCfg=dwOptions>>31;
+	cfg->EncCfg.mpegVersion=(dwOptions>>30)&1;
+	cfg->EncCfg.aacObjectType=(dwOptions>>28)&3;
+	cfg->EncCfg.allowMidside=(dwOptions>>27)&1;
+	cfg->EncCfg.useTns=(dwOptions>>26)&1;
+	cfg->EncCfg.useLfe=(dwOptions>>25)&1;
+	cfg->EncCfg.outputFormat=(dwOptions>>24)&1;
+	cfg->EncCfg.bitRate=((dwOptions>>16)&0xff)<<1;
+	cfg->UseQuality=(dwOptions>>15)&1;
+	cfg->EncCfg.bandWidth=(dwOptions&0x7fff)<<1;
+}*/
+// -----------------------------------------------------------------------------------------------
+
 void ReadCfgEnc(MY_ENC_CFG *cfg) 
 { 
 CRegistry reg;
@@ -70,11 +231,13 @@
 	if(reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME "\\FAAC"))
 	{
 		cfg->AutoCfg=reg.getSetRegBool("Auto",true);
-		cfg->EncCfg.mpegVersion=reg.getSetRegDword("MPEG version",MPEG2); 
+		cfg->EncCfg.mpegVersion=reg.getSetRegDword("MPEG version",MPEG4); 
 		cfg->EncCfg.aacObjectType=reg.getSetRegDword("Profile",LOW); 
 		cfg->EncCfg.allowMidside=reg.getSetRegDword("MidSide",true); 
 		cfg->EncCfg.useTns=reg.getSetRegDword("TNS",true); 
 		cfg->EncCfg.useLfe=reg.getSetRegDword("LFE",false);
+		cfg->UseQuality=reg.getSetRegBool("Use quality",false);
+		cfg->EncCfg.quantqual=reg.getSetRegDword("Quality",100); 
 		cfg->EncCfg.bitRate=reg.getSetRegDword("BitRate",0); 
 		cfg->EncCfg.bandWidth=reg.getSetRegDword("BandWidth",0); 
 		cfg->EncCfg.outputFormat=reg.getSetRegDword("Header",ADTS); 
@@ -96,6 +259,8 @@
 		reg.setRegDword("MidSide",cfg->EncCfg.allowMidside); 
 		reg.setRegDword("TNS",cfg->EncCfg.useTns); 
 		reg.setRegDword("LFE",cfg->EncCfg.useLfe); 
+		reg.setRegBool("Use quality",cfg->UseQuality); 
+		reg.setRegDword("Quality",cfg->EncCfg.quantqual); 
 		reg.setRegDword("BitRate",cfg->EncCfg.bitRate); 
 		reg.setRegDword("BandWidth",cfg->EncCfg.bandWidth); 
 		reg.setRegDword("Header",cfg->EncCfg.outputFormat); 
@@ -213,12 +378,14 @@
 	case WM_INITDIALOG:
 		{
 		char buf[50];
-		char *BitRate[]={"Auto","8","18","20","24","32","40","48","56","64","96","112","128","160","192","256",0};
-		char *BandWidth[]={"Auto","Full","4000","8000","16000","22050","24000","48000",0};
+		char *Quality[]={"Default","10","20","30","40","50","60","70","80","90","100","110","120","130","140","150","200","300","400","500",0};
+		char *BitRate[]={"Auto","8","18","20","24","32","40","48","56","64","96","112","128","160","192","224","256","320","384",0};
+		char *BandWidth[]={"Auto","Full","4000","8000","11025","16000","22050","24000","32000","44100","48000",0};
 		MY_ENC_CFG cfg;
 
 			ReadCfgEnc(&cfg);
 
+			INIT_CB(hWndDlg,IDC_CB_QUALITY,Quality,0);
 			INIT_CB(hWndDlg,IDC_CB_BITRATE,BitRate,0);
 			INIT_CB(hWndDlg,IDC_CB_BANDWIDTH,BandWidth,0);
 
@@ -257,6 +424,26 @@
 			CheckDlgButton(hWndDlg, IDC_CHK_ALLOWMIDSIDE, cfg.EncCfg.allowMidside);
 			CheckDlgButton(hWndDlg, IDC_CHK_USETNS, cfg.EncCfg.useTns);
 			CheckDlgButton(hWndDlg, IDC_CHK_USELFE, cfg.EncCfg.useLfe);
+
+			if(cfg.UseQuality)
+				CheckDlgButton(hWndDlg,IDC_RADIO_QUALITY,TRUE);
+			else
+				CheckDlgButton(hWndDlg,IDC_RADIO_BITRATE,TRUE);
+
+			switch(cfg.EncCfg.quantqual)
+			{
+			case 100:
+				SendMessage(GetDlgItem(hWndDlg, IDC_CB_QUALITY), CB_SETCURSEL, 0, 0);
+				break;
+			default:
+				if(cfg.EncCfg.quantqual<10)
+					cfg.EncCfg.quantqual=10;
+				if(cfg.EncCfg.quantqual>500)
+					cfg.EncCfg.quantqual=500;
+				sprintf(buf,"%lu",cfg.EncCfg.quantqual);
+				SetDlgItemText(hWndDlg, IDC_CB_QUALITY, buf);
+				break;
+			}
 			switch(cfg.EncCfg.bitRate)
 			{
 			case 0:
@@ -342,6 +529,16 @@
 				default:
 					cfg.EncCfg.bandWidth=GetDlgItemInt(hWndDlg, IDC_CB_BANDWIDTH, 0, FALSE);
 				}
+				cfg.UseQuality=IsDlgButtonChecked(hWndDlg,IDC_RADIO_QUALITY) ? TRUE : FALSE;
+				GetDlgItemText(hWndDlg, IDC_CB_QUALITY, buf, 50);
+				switch(*buf)
+				{
+				case 'D': // Default
+					cfg.EncCfg.quantqual=100;
+					break;
+				default:
+					cfg.EncCfg.quantqual=GetDlgItemInt(hWndDlg, IDC_CB_QUALITY, 0, FALSE);
+				}
 				cfg.EncCfg.outputFormat=IsDlgButtonChecked(hWndDlg,IDC_RADIO_RAW) ? RAW : ADTS;
 
 				WriteCfgEnc(&cfg);
@@ -395,7 +592,7 @@
 long		retVal;
 BOOL		OpenDialog=FALSE;
 
-	if(!reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME  "\\FAAD"))
+/*	if(!reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME  "\\FAAD"))
 		ERROR_FGO("Can't open registry!")
 	else
 		if(OpenDialog=reg.getSetRegBool("OpenDialog",FALSE))
@@ -427,7 +624,7 @@
 		WriteCfgDec(Cfg);
 		FREE(Cfg);
 	}
-	else
+	else*/
 		retVal=DialogBoxParam((HINSTANCE)hInst,(LPCSTR)MAKEINTRESOURCE(IDD_ENCODER), (HWND)hWnd, (DLGPROC)DIALOGMsgProc, dwOptions);
 
 	if(retVal==-1)
@@ -441,7 +638,7 @@
 void FAR PASCAL GetSuggestedSampleType(LONG *lplSamprate, WORD *lpwBitsPerSample, WORD *wChannels)
 {
 	*lplSamprate=0; // don't care
-	*lpwBitsPerSample= *lpwBitsPerSample==16 ? 0: 16;
+	*lpwBitsPerSample= *lpwBitsPerSample<=16 ? 0: 16;
 	*wChannels= *wChannels<49 ? 0 : 48;
 }
 // *********************************************************************************************
@@ -464,11 +661,8 @@
 	if(mo->hEncoder)
 		faacEncClose(mo->hEncoder);
 	
-	if(mo->bitbuf)
-	{
-		free(mo->bitbuf);
-		mo->bitbuf=0;
-	}
+	FREE(mo->bitbuf)
+	FREE(mo->buffer)
 	
 //	FREE(mi->dst_name);
 	
@@ -498,7 +692,9 @@
 DWORD			samplesInput,
 				maxBytesOutput;
 
-	if(wBitsPerSample!=16)	// FAAC supports 16 bit audio only!
+//	if(wBitsPerSample!=8 && wBitsPerSample!=16) // 32 bit audio from cooledit is in unsupported format
+//		return 0;
+	if(wChannels>=49)	// FAAC supports max 48 tracks!
 		return 0;
 
     if(!(hOutput=GlobalAlloc(GMEM_MOVEABLE|GMEM_SHARE|GMEM_ZEROINIT,sizeof(MYOUTPUT))))
@@ -517,9 +713,12 @@
 	if(!(mo->hEncoder=faacEncOpen(lSamprate, wChannels, &samplesInput, &maxBytesOutput)))
 		ERROR_OFO("Can't open library");
 
-	if(!(mo->bitbuf=(unsigned char*)malloc(maxBytesOutput*sizeof(unsigned char))))
+	if(!(mo->bitbuf=(unsigned char *)malloc(maxBytesOutput*sizeof(unsigned char))))
 		ERROR_OFO("Memory allocation error: output buffer");
 
+	if(!(mo->buffer=(int32_t *)malloc(samplesInput*sizeof(int32_t))))
+		ERROR_OFO("Memory allocation error: input buffer");
+
 	ReadCfgEnc(&cfg);
 	if(!cfg.AutoCfg)
 	{
@@ -526,10 +725,16 @@
     faacEncConfigurationPtr myFormat=&cfg.EncCfg;
     faacEncConfigurationPtr CurFormat=faacEncGetCurrentConfiguration(mo->hEncoder);
 
-		if(!myFormat->bitRate)
+		if(cfg.UseQuality)
+		{
+			myFormat->quantqual=cfg.EncCfg.quantqual;
 			myFormat->bitRate=CurFormat->bitRate;
+		}
 		else
-			myFormat->bitRate*=1000;
+			if(!myFormat->bitRate)
+				myFormat->bitRate=CurFormat->bitRate;
+			else
+				myFormat->bitRate*=1000;
 
 		switch(myFormat->bandWidth)
 		{
@@ -546,7 +751,7 @@
 			ERROR_OFO("Unsupported parameters");
 	}
 
-	*lpChunkSize=samplesInput*2;
+	*lpChunkSize=samplesInput*(wBitsPerSample>>3);
 
 //	mo->src_size=lSize;
 	mo->Samprate=lSamprate;
@@ -556,6 +761,17 @@
 	mo->maxBytesOutput=maxBytesOutput;
 //	mi->dst_name=strdup(lpstrFilename);
 
+	// init flushing process
+int bytesEncoded, tmp;
+
+    bytesEncoded=faacEncEncode(mo->hEncoder, 0, 0, mo->bitbuf, maxBytesOutput); // initializes the flushing process
+    if(bytesEncoded>0)
+	{
+		tmp=fwrite(mo->bitbuf, 1, bytesEncoded, mo->aacFile);
+		if(tmp!=bytesEncoded)
+			ERROR_OFO("fwrite()");
+	}
+
 	GlobalUnlock(hOutput);
 
     return hOutput;
@@ -572,7 +788,7 @@
 }
 // -----------------------------------------------------------------------------------------------
 
-DWORD FAR PASCAL WriteFilterOutput(HANDLE hOutput, unsigned char far *buf, long lBytes)
+DWORD FAR PASCAL WriteFilterOutput(HANDLE hOutput, unsigned char far *bufIn, long lBytes)
 {
 	if(!hOutput)
 		return 0;
@@ -582,21 +798,25 @@
 MYOUTPUT far *mo;
 
 	GLOBALLOCK(mo,hOutput,MYOUTPUT,return 0);
-	
+
+int32_t *buf=mo->buffer;
+
+	To32bit(buf,bufIn,mo->samplesInput,mo->BitsPerSample>>3,false);
+
 	// call the actual encoding routine
-	bytesEncoded=faacEncEncode(mo->hEncoder, (short *)buf, mo->samplesInput, mo->bitbuf, mo->maxBytesOutput);
-	if(bytesEncoded<1) // end of flushing process
+	bytesEncoded=faacEncEncode(mo->hEncoder, (int32_t *)buf, mo->samplesInput, mo->bitbuf, mo->maxBytesOutput);
+	if(bytesEncoded>0)
 	{
-		if(bytesEncoded<0)
-			ERROR_WFO("faacEncEncode");
-		bytesWritten=lBytes ? 1 : 0; // bytesWritten==0 stops CoolEdit. 1 is used when intializing flushing process
-	}
-	else
-	{
 		// write bitstream to aac file 
 		bytesWritten=fwrite(mo->bitbuf, 1, bytesEncoded, mo->aacFile);
 		if(bytesWritten!=bytesEncoded)
-			ERROR_WFO("fwrite");
+			ERROR_WFO("bytesWritten and bytesEncoded are different");
+	}
+	else
+	{
+		if(bytesEncoded<0)
+			ERROR_WFO("faacEncEncode()");
+		bytesWritten=lBytes ? 1 : 0; // bytesWritten==0 stops CoolEdit
 	}
 	
 	GlobalUnlock(hOutput);
--- a/plugins/cooledit/Faad.cpp
+++ b/plugins/cooledit/Faad.cpp
@@ -23,9 +23,9 @@
 #include <stdio.h>		// FILE *
 #include "resource.h"
 #include "filters.h"	// CoolEdit
+#include <mp4.h>
 #include <faac.h>
 #include <faad.h>
-#include <mp4.h>
 extern "C" {
 #include <aacinfo.h>	// get_AAC_format()
 }
@@ -45,9 +45,6 @@
 
 #define MAX_CHANNELS	2
 #define	FAAD_STREAMSIZE	(FAAD_MIN_STREAMSIZE*MAX_CHANNELS)
-#define RAW		0
-#define ADIF	1
-#define ADTS	2
 
 // *********************************************************************************************
 
@@ -89,9 +86,9 @@
 {
 	"Raw PCM",
 	"AAC Main",
-	"AAC Low Complexity",
+	"AAC LC (Low Complexity)",
 	"AAC SSR",
-	"AAC LTP",
+	"AAC LTP (Long Term Prediction)",
 	"Reserved",
 	"AAC Scalable",
 	"TwinVQ",
@@ -105,13 +102,13 @@
 	"General MIDI",
 	"Algorithmic Synthesis and Audio FX",
 // defined in MPEG-4 version 2
-	"ER AAC LC",
+	"ER AAC LC (Low Complexity)",
 	"Reserved",
-	"ER AAC LTP",
+	"ER AAC LTP (Long Term Prediction)",
 	"ER AAC Scalable",
 	"ER TwinVQ",
 	"ER BSAC",
-	"ER AAC LD",
+	"ER AAC LD (Low Delay)",
 	"ER CELP",
 	"ER HVXC",
 	"ER HILN",
@@ -182,10 +179,11 @@
 
 	if(reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME  "\\FAAD"))
 	{
+		cfg->DefaultCfg=reg.getSetRegBool("Default",true);
 		cfg->DecCfg.defObjectType=reg.getSetRegByte("Profile",LOW);
 		cfg->DecCfg.defSampleRate=reg.getSetRegDword("SampleRate",44100);
 		cfg->DecCfg.outputFormat=reg.getSetRegByte("Bps",FAAD_FMT_16BIT);
-		cfg->Channels=reg.getSetRegByte("Channels",2);
+//		cfg->Channels=reg.getSetRegByte("Channels",2);
 	}
 	else
 		MessageBox(0,"Can't open registry!",0,MB_OK|MB_ICONSTOP);
@@ -198,10 +196,11 @@
 
 	if(reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME  "\\FAAD"))
 	{
-		reg.setRegByte("Profile",cfg->DecCfg.defObjectType); 
-		reg.setRegDword("SampleRate",cfg->DecCfg.defSampleRate); 
+		reg.setRegBool("Default",cfg->DefaultCfg);
+		reg.setRegByte("Profile",cfg->DecCfg.defObjectType);
+		reg.setRegDword("SampleRate",cfg->DecCfg.defSampleRate);
 		reg.setRegByte("Bps",cfg->DecCfg.outputFormat);
-		reg.setRegByte("Channels",cfg->Channels);
+//		reg.setRegByte("Channels",cfg->Channels);
 	}
 	else
 		MessageBox(0,"Can't open registry!",0,MB_OK|MB_ICONSTOP);
@@ -208,6 +207,14 @@
 }
 // -----------------------------------------------------------------------------------------------
 
+#define INIT_CB(hWnd,nID,list,IdSelected) \
+{ \
+	for(int i=0; list[i]; i++) \
+		SendMessage(GetDlgItem(hWnd, nID), CB_ADDSTRING, 0, (LPARAM)list[i]); \
+	SendMessage(GetDlgItem(hWnd, nID), CB_SETCURSEL, IdSelected, 0); \
+}
+// -----------------------------------------------------------------------------------------------
+
 //	EnableWindow(GetDlgItem(hWndDlg, IDC_RADIO_SSR), Enabled);
 #define DISABLE_CTRL(Enabled) \
 { \
@@ -214,6 +221,7 @@
     EnableWindow(GetDlgItem(hWndDlg, IDC_RADIO_MAIN), Enabled); \
     EnableWindow(GetDlgItem(hWndDlg, IDC_RADIO_LOW), Enabled); \
     EnableWindow(GetDlgItem(hWndDlg, IDC_RADIO_LTP), Enabled); \
+    EnableWindow(GetDlgItem(hWndDlg, IDC_CB_SAMPLERATE), Enabled); \
 }
 // -----------------------------------------------------------------------------------------------
 
@@ -231,8 +239,15 @@
 				EndDialog(hWndDlg, 0);
 				return TRUE;
 			}
+
+		char buf[50];
+		char *SampleRate[]={"6000","8000","16000","22050","32000","44100","48000","64000","88200","96000","192000",0};
 			CfgDecoder=(MY_DEC_CFG *)lParam;
 
+			INIT_CB(hWndDlg,IDC_CB_SAMPLERATE,SampleRate,5);
+			sprintf(buf,"%lu",CfgDecoder->DecCfg.defSampleRate);
+			SetDlgItemText(hWndDlg, IDC_CB_SAMPLERATE, buf);
+
 			switch(CfgDecoder->DecCfg.defObjectType)
 			{
 			case MAIN:
@@ -248,6 +263,9 @@
 				CheckDlgButton(hWndDlg,IDC_RADIO_LTP,TRUE);
 				break;
 			}
+
+			CheckDlgButton(hWndDlg,IDC_CHK_DEFAULTCFG, CfgDecoder->DefaultCfg);
+			DISABLE_CTRL(!CfgDecoder->DefaultCfg);
 		}
 		break; // End of WM_INITDIALOG                                 
 
@@ -259,6 +277,13 @@
 	case WM_COMMAND:
 		switch(LOWORD(wParam))
 		{
+		case IDC_CHK_DEFAULTCFG:
+			{
+			char Enabled=!IsDlgButtonChecked(hWndDlg,IDC_CHK_DEFAULTCFG);
+				DISABLE_CTRL(Enabled);
+			}
+			break;
+
 		case IDOK:
 			{
 				if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_MAIN))
@@ -270,6 +295,10 @@
 				if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_LTP))
 					CfgDecoder->DecCfg.defObjectType=LTP;
 
+				CfgDecoder->DecCfg.defSampleRate=GetDlgItemInt(hWndDlg, IDC_CB_SAMPLERATE, 0, FALSE);
+				CfgDecoder->DefaultCfg=IsDlgButtonChecked(hWndDlg,IDC_CHK_DEFAULTCFG) ? TRUE : FALSE;
+				WriteCfgDec(CfgDecoder);
+
 				EndDialog(hWndDlg, (DWORD)CfgDecoder);
 			}
 			break;
@@ -346,7 +375,7 @@
 		case RAW:
 			lstrcpy(szString,"AAC\nRaw");
 			GlobalUnlock(hInput);
-			return 0; // call FilterGetOptions()
+			return 1;//0; // call FilterGetOptions()
 		case ADIF:
 			lstrcat(szString,"ADIF\n");
 			break;
@@ -361,13 +390,13 @@
 			lstrcat(szString,"Main");
 			break;
 		case LOW:
-			lstrcat(szString,"Low Complexity");
+			lstrcat(szString,"LC (Low Complexity)");
 			break;
 		case SSR:
 			lstrcat(szString,"SSR (unsupported)");
 			break;
 		case LTP:
-			lstrcat(szString,"Main LTP");
+			lstrcat(szString,"LTP (Long Term Prediction)");
 			break;
 		}
 	}
@@ -378,14 +407,13 @@
 	return 1; // don't call FilterGetOptions()
 }
 // *********************************************************************************************
-
+/*
 DWORD FAR PASCAL FilterOptions(HANDLE hInput)
 {
-/*
-	FilterGetOptions() is called if this function and FilterSetOptions() are exported and FilterOptionsString() returns 0
-	FilterSetOptions() is called only if this function is exported and and it returns 0
-*/
-	return 0;
+//	FilterGetOptions() is called if this function and FilterSetOptions() are exported and FilterOptionsString() returns 0
+//	FilterSetOptions() is called only if this function is exported and and it returns 0
+
+	return 1;
 }
 // ---------------------------------------------------------------------------------------------
 
@@ -392,7 +420,7 @@
 DWORD FAR PASCAL FilterSetOptions(HANDLE hInput, DWORD dwOptions, LONG lSamprate, WORD wChannels, WORD wBPS)
 {
 	return dwOptions;
-}
+}*/
 // *********************************************************************************************
 
 void FAR PASCAL CloseFilterInput(HANDLE hInput)
@@ -587,20 +615,20 @@
 			ERROR_OFI("Can't open library");
 
 		if(mi->file_info.headertype==RAW)
-			if(!*lSamprate && !*wBitsPerSample && !*wChannels)
+			if(!*lSamprate || !*wBitsPerSample || !*wChannels)
 			{
-			CRegistry	reg;
+/*			CRegistry	reg;
 
 				if(reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME  "\\FAAD"))
 					reg.setRegBool("OpenDialog",TRUE);
 				else
-					ERROR_OFI("Can't open registry!");
-			/*
-			CoolEdit resamples audio if the following code is activated
-				*wBitsPerSample=BitsPerSample;
-				*wChannels=2;
+					ERROR_OFI("Can't open registry!");*/
+
+//			CoolEdit ask for format if the following code isn't activated
 				*lSamprate=44100;
-			*/
+				*wBitsPerSample=16;
+				*wChannels=2;
+
 				GlobalUnlock(hInput);
 				return hInput;
 			}
@@ -609,10 +637,20 @@
 			MY_DEC_CFG	Cfg;
 
 				ReadCfgDec(&Cfg);
+				if(!Bitrate4RawAAC)
+					DialogBoxParam((HINSTANCE)hInst,(LPCSTR)MAKEINTRESOURCE(IDD_DECODER),(HWND)hWnd, (DLGPROC)DialogMsgProcDecoder, (DWORD)&Cfg);
 				config=faacDecGetCurrentConfiguration(mi->hDecoder);
-				config->defObjectType=Cfg.DecCfg.defObjectType;
-				config->defSampleRate=Cfg.DecCfg.defSampleRate;//*lSamprate; // doesn't work! Why???
-				config->outputFormat=Cfg.DecCfg.outputFormat;
+				if(Cfg.DefaultCfg)
+				{
+					config->defObjectType=mi->file_info.object_type;
+					config->defSampleRate=mi->file_info.sampling_rate;//*lSamprate; // doesn't work!
+				}
+				else
+				{
+					config->defObjectType=Cfg.DecCfg.defObjectType;
+					config->defSampleRate=Cfg.DecCfg.defSampleRate;
+				}
+				config->outputFormat=FAAD_FMT_16BIT;
 				faacDecSetConfiguration(mi->hDecoder, config);
 
 				if(Bitrate4RawAAC)
@@ -637,12 +675,12 @@
 					Channels4RawAAC=(BYTE)mi->Channels;
 					if(!Channels4RawAAC)
 						ERROR_OFI("Channels reported by decoder: 0");
-					if(Channels4RawAAC!=Cfg.Channels)
+/*					if(Channels4RawAAC!=Cfg.Channels)
 					{
 					char	buf[256]="";
 						sprintf(buf,"Channels reported by decoder: %d",mi->Channels);
 						MessageBox(0,buf,0,MB_OK|MB_ICONWARNING);
-					}
+					}*/
 					GlobalUnlock(hInput);
 					CloseFilterInput(hInput);
 					goto start_point;
--- a/plugins/cooledit/Main.cpp
+++ b/plugins/cooledit/Main.cpp
@@ -21,7 +21,7 @@
 
 #include <windows.h>
 #include "filters.h"	//CoolEdit
-#include "faac.h"
+//#include "faac.h"
 #include "Defines.h"	// my defines
 
 // Plugins of CoolEdit can be unloaded between each call of its exported funcs,
@@ -92,17 +92,19 @@
 	lstrcpy(cq->szExt,"AAC");
 	lstrcpy(cq->szExt2,"MP4"); 
 	cq->lChunkSize=16384; 
-	cq->dwFlags=QF_RATEADJUSTABLE|QF_CANLOAD|QF_CANSAVE|QF_HASOPTIONSBOX;
- 	cq->Mono8=0;		// no support
- 	cq->Mono16=0xFF;
- 	cq->Mono24=0xFF;
- 	cq->Mono32=0xFF;
- 	cq->Stereo8=0xFF;
- 	cq->Stereo16=0xFF;
- 	cq->Stereo24=0xFF;
- 	cq->Stereo32=0xFF;
+	cq->dwFlags=QF_RATEADJUSTABLE|QF_CANLOAD|QF_CANSAVE|QF_HASOPTIONSBOX|QF_CANDO32BITFLOATS;
+ 	cq->Mono8=R_5500|R_11025|R_22050|R_32075|R_44100|R_48000;
+ 	cq->Mono12=0;		// no support
+ 	cq->Mono16=R_5500|R_11025|R_22050|R_32075|R_44100|R_48000;
+ 	cq->Mono24=0;
+ 	cq->Mono32=R_5500|R_11025|R_22050|R_32075|R_44100|R_48000;
+ 	cq->Stereo8=R_5500|R_11025|R_22050|R_32075|R_44100|R_48000;
+ 	cq->Stereo12=0;
+ 	cq->Stereo16=R_5500|R_11025|R_22050|R_32075|R_44100|R_48000;
+ 	cq->Stereo24=0;
+ 	cq->Stereo32=R_5500|R_11025|R_22050|R_32075|R_44100|R_48000;
  	cq->Quad8=0;
- 	cq->Quad16=0xFF;
- 	cq->Quad32=0xFF;
+ 	cq->Quad16=0;
+ 	cq->Quad32=0;
  	return C_VALIDLIBRARY;
 }
--- a/plugins/cooledit/Structs.h
+++ b/plugins/cooledit/Structs.h
@@ -1,10 +1,11 @@
 
-#ifndef _STRUCTS___
-#define _STRUCTS___
+#ifndef Structs_h
+#define Structs_h
 
 typedef struct mec
 {
 bool					AutoCfg;
+bool					UseQuality;
 faacEncConfiguration	EncCfg;
 } MY_ENC_CFG;
 // -----------------------------------------------------------------------------------------------
@@ -11,7 +12,7 @@
 
 typedef struct mdc
 {
-bool					AutoCfg;
+bool					DefaultCfg;
 BYTE					Channels;
 DWORD					BitRate;
 faacDecConfiguration	DecCfg;
--- /dev/null
+++ b/plugins/cooledit/TypeDef.h
@@ -1,0 +1,27 @@
+//---------------------------------------------------------------------------
+#ifndef TypeDefH
+#define TypeDefH
+//---------------------------------------------------------------------------
+
+/* typedef.h */
+
+#ifndef BYTE
+typedef unsigned char    BYTE;
+#endif
+#ifndef WORD
+typedef unsigned short   WORD;
+#endif
+#ifndef DWORD
+typedef unsigned long    DWORD;
+#endif
+typedef signed char      SBYTE;
+typedef signed short     SWORD;
+typedef signed long      SDWORD;
+typedef unsigned long    ULONG;
+typedef unsigned __int64 QWORD;
+typedef __int64          SQWORD;
+
+//---------------------------------------------------------------------------
+#endif
+//---------------------------------------------------------------------------
+
--- a/plugins/cooledit/aacInfoLib.dsp
+++ b/plugins/cooledit/aacInfoLib.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)" == "aacInfoLib - Win32 Release"
@@ -48,7 +48,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
 
@@ -66,13 +66,13 @@
 # PROP Target_Dir ""
 MTL=midl.exe
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../../faad2/common/faad" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../../faad2/common/faad" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
 # ADD BASE RSC /l 0x410 /d "_DEBUG"
 # ADD RSC /l 0x410 /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
 
--- a/plugins/cooledit/defines.h
+++ b/plugins/cooledit/defines.h
@@ -1,5 +1,5 @@
 #define APP_NAME "MPEG4-AAC"
-#define APP_VER "v2.0"
+#define APP_VER "v2.1"
 #define REGISTRY_PROGRAM_NAME "SOFTWARE\\4N\\CoolEdit\\AAC-MPEG4"
 
 // -----------------------------------------------------------------------------------------------
--- a/plugins/cooledit/resource.h
+++ b/plugins/cooledit/resource.h
@@ -27,6 +27,11 @@
 #define IDC_AUDIOCODING                 1016
 #define IDC_EMAIL                       1017
 #define IDC_MPEG4IP                     1018
+#define IDC_CHK_DEFAULTCFG              1019
+#define IDC_CB_SAMPLERATE               1020
+#define IDC_RADIO_BITRATE               1022
+#define IDC_RADIO_QUALITY               1023
+#define IDC_CB_QUALITY                  1024
 
 // Next default values for new objects
 // 
@@ -34,7 +39,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        108
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1019
+#define _APS_NEXT_CONTROL_VALUE         1025
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif
--- a/plugins/winamp/CRegistry.cpp
+++ b/plugins/winamp/CRegistry.cpp
@@ -22,7 +22,7 @@
 //#include "stdafx.h"
 #include <windows.h>
 #include <string.h>
-#include <memory.h>
+#include <stdlib.h>		// malloc, free
 #include "CRegistry.h"
 
 CRegistry::CRegistry()
--- a/plugins/winamp/FAAC.rc
+++ b/plugins/winamp/FAAC.rc
@@ -26,7 +26,7 @@
 // Dialog
 //
 
-IDD_COMPRESSION DIALOG DISCARDABLE  0, 0, 186, 142
+IDD_ENCODER DIALOG DISCARDABLE  0, 0, 195, 166
 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "AAC-MPEG4 options"
 FONT 8, "MS Sans Serif"
@@ -39,36 +39,42 @@
                     41,9
     CONTROL         "Main",IDC_RADIO_MAIN,"Button",BS_AUTORADIOBUTTON | 
                     WS_GROUP,12,73,31,10
-    CONTROL         "Low",IDC_RADIO_LOW,"Button",BS_AUTORADIOBUTTON,12,85,29,
+    CONTROL         "LC",IDC_RADIO_LOW,"Button",BS_AUTORADIOBUTTON,12,85,25,
                     10
     CONTROL         "SSR",IDC_RADIO_SSR,"Button",BS_AUTORADIOBUTTON | 
                     WS_DISABLED,12,97,31,10
     CONTROL         "LTP",IDC_RADIO_LTP,"Button",BS_AUTORADIOBUTTON,12,109,
                     29,10
-    CONTROL         "Allow Mid/Side",IDC_ALLOWMIDSIDE,"Button",
+    CONTROL         "Allow Mid/Side",IDC_CHK_ALLOWMIDSIDE,"Button",
                     BS_AUTOCHECKBOX | WS_TABSTOP,107,21,63,10
-    CONTROL         "Use TNS",IDC_USETNS,"Button",BS_AUTOCHECKBOX | 
+    CONTROL         "Use TNS",IDC_CHK_USETNS,"Button",BS_AUTOCHECKBOX | 
                     WS_TABSTOP,107,34,45,10
-    CONTROL         "Use LFE channel",IDC_USELFE,"Button",BS_AUTOCHECKBOX | 
-                    WS_DISABLED | WS_TABSTOP,107,47,67,10
-    COMBOBOX        IDC_CB_BITRATE,134,68,48,30,CBS_DROPDOWNLIST | 
-                    WS_VSCROLL | WS_TABSTOP
-    COMBOBOX        IDC_CB_BANDWIDTH,134,85,48,30,CBS_DROPDOWN | WS_VSCROLL | 
-                    WS_TABSTOP
-    EDITTEXT        IDC_E_BROWSE,57,103,100,14,ES_AUTOHSCROLL
-    PUSHBUTTON      "Browse",IDC_BTN_BROWSE,164,103,18,14,BS_BITMAP | 
+    CONTROL         "Use LFE channel",IDC_CHK_USELFE,"Button",
+                    BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,107,47,67,10
+    EDITTEXT        IDC_E_BROWSE,4,128,163,14,ES_AUTOHSCROLL
+    PUSHBUTTON      "Browse",IDC_BTN_BROWSE,173,128,18,14,BS_BITMAP | 
                     BS_FLAT
-    DEFPUSHBUTTON   "OK",IDOK,109,123,36,14
-    PUSHBUTTON      "Cancel",IDCANCEL,146,123,36,14
+    DEFPUSHBUTTON   "OK",IDOK,119,148,36,14
+    PUSHBUTTON      "Cancel",IDCANCEL,155,148,36,14
     GROUPBOX        "AAC type",IDC_STATIC,4,18,48,38
     GROUPBOX        "Profile",IDC_STATIC,4,63,48,59
-    LTEXT           "Bitrate per channel",IDC_STATIC,59,73,60,8
-    LTEXT           "Bandwidth (0=full)",IDC_STATIC,59,89,57,8
     CONTROL         "Raw",IDC_RADIO_RAW,"Button",BS_AUTORADIOBUTTON | 
                     WS_GROUP,59,30,42,10
     CONTROL         "ADTS",IDC_RADIO_ADTS,"Button",BS_AUTORADIOBUTTON,59,42,
                     41,9
     GROUPBOX        "Header",IDC_STATIC,55,18,48,38
+    CONTROL         "Quality",IDC_RADIO_QUALITY,"Button",BS_AUTORADIOBUTTON | 
+                    WS_GROUP,62,74,37,10
+    COMBOBOX        IDC_CB_QUALITY,138,72,48,97,CBS_DROPDOWN | WS_VSCROLL | 
+                    WS_TABSTOP
+    CONTROL         "Bitrate per channel",IDC_RADIO_BITRATE,"Button",
+                    BS_AUTORADIOBUTTON,62,90,75,10
+    COMBOBOX        IDC_CB_BITRATE,138,88,48,86,CBS_DROPDOWN | WS_VSCROLL | 
+                    WS_TABSTOP
+    COMBOBOX        IDC_CB_BANDWIDTH,138,109,48,81,CBS_DROPDOWN | WS_VSCROLL | 
+                    WS_TABSTOP
+    LTEXT           "Bandwidth",IDC_STATIC,74,112,34,8
+    GROUPBOX        "Encoding mode",IDC_STATIC,56,63,135,42
 END
 
 
@@ -106,12 +112,12 @@
 #ifdef APSTUDIO_INVOKED
 GUIDELINES DESIGNINFO DISCARDABLE 
 BEGIN
-    IDD_COMPRESSION, DIALOG
+    IDD_ENCODER, DIALOG
     BEGIN
         LEFTMARGIN, 4
-        RIGHTMARGIN, 182
+        RIGHTMARGIN, 191
         TOPMARGIN, 4
-        BOTTOMMARGIN, 137
+        BOTTOMMARGIN, 161
     END
 END
 #endif    // APSTUDIO_INVOKED
--- a/plugins/winamp/Out_faac.cpp
+++ b/plugins/winamp/Out_faac.cpp
@@ -24,12 +24,23 @@
 #include <stdio.h>  // FILE *
 #include "resource.h"
 #include "out.h"
-#include "faac.h"
+#include <mp4.h>
+#include <faac.h>
 #include "CRegistry.h"
 #include "defines.h"
 
+#define RAW  0
+#define ADTS 1
 
+#define FREE(ptr) \
+{ \
+	if(ptr) \
+		free(ptr); \
+	ptr=0; \
+}
 
+
+
 void Config(HWND);
 void About(HWND);
 void Init();
@@ -50,28 +61,29 @@
 
 typedef struct output_tag  // any special vars associated with output file
 {
- FILE  *fFile;         
- DWORD lSize;
- long  lSamprate;
- WORD  wBitsPerSample;
- WORD  wChannels;
+FILE  *aacFile;         
+DWORD lSize;
+long  lSamprate;
+WORD  wBitsPerSample;
+WORD  wChannels;
 // DWORD dwDataOffset;
- //BOOL  bWrittenHeader;
- char  szNAME[256];
+//BOOL  bWrittenHeader;
+char  szNAME[256];
 
- faacEncHandle hEncoder;
- unsigned char *bitbuf;
- DWORD maxBytesOutput;
- long  samplesInput;
- BYTE  bStopEnc;
+faacEncHandle hEncoder;
+int32_t			*buffer;
+unsigned char	*bitbuf;
+DWORD maxBytesOutput;
+long  samplesInput;
+BYTE  bStopEnc;
 
- unsigned char *inbuf;
- DWORD full_size; // size of decoded file needed to set the length of progress bar
- DWORD tagsize;
- DWORD bytes_read;		// from file
- DWORD bytes_consumed;	// by faadDecDecode
- DWORD bytes_into_buffer;
- DWORD bytes_Enc;
+unsigned char *bufIn;
+DWORD full_size; // size of decoded file needed to set the length of progress bar
+DWORD tagsize;
+DWORD bytes_read;		// from file
+DWORD bytes_consumed;	// by faadDecDecode
+DWORD bytes_into_buffer;
+DWORD bytes_Enc;
 } MYOUTPUT;
 
 
@@ -79,9 +91,10 @@
 typedef struct mc
 {
 bool					AutoCfg;
+bool					UseQuality;
 faacEncConfiguration	EncCfg;
 char					OutDir[MAX_PATH];
-} MYCFG;
+} MY_ENC_CFG;
 
 
 
@@ -96,7 +109,7 @@
 
 Out_Module out = {
 	OUT_VER,
-	APP_NAME APP_VER,
+	APP_NAME " " APP_VER,
 	NULL,
     NULL, // hmainwindow
     NULL, // hdllinstance
@@ -194,6 +207,117 @@
 }
 // *********************************************************************************************
 
+#define SWAP32(x) (((x & 0xff) << 24) | ((x & 0xff00) << 8) \
+	| ((x & 0xff0000) >> 8) | ((x & 0xff000000) >> 24))
+#define SWAP16(x) (((x & 0xff) << 8) | ((x & 0xff00) >> 8))
+
+inline void To32bit(int32_t *buf, BYTE *bufi, int size, BYTE samplebytes, BYTE bigendian)
+{
+int i;
+
+	switch(samplebytes)
+	{
+	case 1:
+		// this is endian clean
+		for (i = 0; i < size; i++)
+			buf[i] = (bufi[i] - 128) * 65536;
+		break;
+		
+	case 2:
+#ifdef WORDS_BIGENDIAN
+		if (!bigendian)
+#else
+			if (bigendian)
+#endif
+			{
+				// swap bytes
+				for (i = 0; i < size; i++)
+				{
+					int16_t s = ((int16_t *)bufi)[i];
+					
+					s = SWAP16(s);
+					
+					buf[i] = ((u_int32_t)s) << 8;
+				}
+			}
+			else
+			{
+				// no swap
+				for (i = 0; i < size; i++)
+				{
+					int s = ((int16_t *)bufi)[i];
+					
+					buf[i] = s << 8;
+				}
+			}
+			break;
+			
+	case 3:
+		if (!bigendian)
+		{
+			for (i = 0; i < size; i++)
+			{
+				int s = bufi[3 * i] | (bufi[3 * i + 1] << 8) | (bufi[3 * i + 2] << 16);
+				
+				// fix sign
+				if (s & 0x800000)
+					s |= 0xff000000;
+				
+				buf[i] = s;
+			}
+		}
+		else // big endian input
+		{
+			for (i = 0; i < size; i++)
+			{
+				int s = (bufi[3 * i] << 16) | (bufi[3 * i + 1] << 8) | bufi[3 * i + 2];
+				
+				// fix sign
+				if (s & 0x800000)
+					s |= 0xff000000;
+				
+				buf[i] = s;
+			}
+		}
+		break;
+		
+	case 4:		
+#ifdef WORDS_BIGENDIAN
+		if (!bigendian)
+#else
+			if (bigendian)
+#endif
+			{
+				// swap bytes
+				for (i = 0; i < size; i++)
+				{
+					int s = bufi[i];
+					
+					buf[i] = SWAP32(s);
+				}
+			}
+			else
+				memcpy(buf,bufi,size*sizeof(u_int32_t));
+		/*
+		int exponent, mantissa;
+		float *bufo=(float *)buf;
+			
+			for (i = 0; i < size; i++)
+			{
+				exponent=bufi[(i<<2)+3]<<1;
+				if(bufi[i*4+2] & 0x80)
+					exponent|=0x01;
+				exponent-=126;
+				mantissa=(DWORD)bufi[(i<<2)+2]<<16;
+				mantissa|=(DWORD)bufi[(i<<2)+1]<<8;
+				mantissa|=bufi[(i<<2)];
+				bufo[i]=(float)ldexp(mantissa,exponent);
+			}*/
+			break;
+	}
+}
+// *********************************************************************************************
+
 static int CALLBACK WINAPI BrowseCallbackProc( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
 {
 	if (uMsg == BFFM_INITIALIZED)
@@ -204,38 +328,51 @@
 	return 0;
 }
 
-void RD_Cfg(MYCFG *cfg) 
+void ReadCfgEnc(MY_ENC_CFG *cfg) 
 { 
 CRegistry reg;
 
-	reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME);
-	cfg->AutoCfg=reg.getSetRegDword("Auto",true) ? true : false; 
-	cfg->EncCfg.mpegVersion=reg.getSetRegDword("MPEG version",MPEG2); 
-	cfg->EncCfg.aacObjectType=reg.getSetRegDword("Profile",LOW); 
-	cfg->EncCfg.allowMidside=reg.getSetRegDword("MidSide",true); 
-	cfg->EncCfg.useTns=reg.getSetRegDword("TNS",true); 
-	cfg->EncCfg.useLfe=reg.getSetRegDword("LFE",false);
-	cfg->EncCfg.bitRate=reg.getSetRegDword("BitRate",128000); 
-	cfg->EncCfg.bandWidth=reg.getSetRegDword("BandWidth",0); 
-	cfg->EncCfg.outputFormat=reg.getSetRegDword("Header",1); 
-	reg.getSetRegStr("OutDir","",cfg->OutDir,MAX_PATH); 
+	if(reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME))
+	{
+		cfg->AutoCfg=reg.getSetRegDword("Auto",true) ? true : false; 
+		cfg->EncCfg.mpegVersion=reg.getSetRegDword("MPEG version",MPEG2); 
+		cfg->EncCfg.aacObjectType=reg.getSetRegDword("Profile",LOW); 
+		cfg->EncCfg.allowMidside=reg.getSetRegDword("MidSide",true); 
+		cfg->EncCfg.useTns=reg.getSetRegDword("TNS",true); 
+		cfg->EncCfg.useLfe=reg.getSetRegDword("LFE",false);
+		cfg->UseQuality=reg.getSetRegDword("Use quality",false) ? true : false;
+		cfg->EncCfg.quantqual=reg.getSetRegDword("Quality",100); 
+		cfg->EncCfg.bitRate=reg.getSetRegDword("BitRate",128000); 
+		cfg->EncCfg.bandWidth=reg.getSetRegDword("BandWidth",0); 
+		cfg->EncCfg.outputFormat=reg.getSetRegDword("Header",1); 
+		reg.getSetRegStr("OutDir","",cfg->OutDir,MAX_PATH); 
+	}
+	else
+		MessageBox(0,"Can't open registry!",0,MB_OK|MB_ICONSTOP);
 }
+// -----------------------------------------------------------------------------------------------
 
-void WR_Cfg(MYCFG *cfg) 
+void WriteCfgEnc(MY_ENC_CFG *cfg) 
 { 
 CRegistry reg;
 
-	reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME);
-	reg.setRegDword("Auto",cfg->AutoCfg); 
-	reg.setRegDword("MPEG version",cfg->EncCfg.mpegVersion); 
-	reg.setRegDword("Profile",cfg->EncCfg.aacObjectType); 
-	reg.setRegDword("MidSide",cfg->EncCfg.allowMidside); 
-	reg.setRegDword("TNS",cfg->EncCfg.useTns); 
-	reg.setRegDword("LFE",cfg->EncCfg.useLfe); 
-	reg.setRegDword("BitRate",cfg->EncCfg.bitRate); 
-	reg.setRegDword("BandWidth",cfg->EncCfg.bandWidth); 
-	reg.setRegDword("Header",cfg->EncCfg.outputFormat); 
-	reg.setRegStr("OutDir",cfg->OutDir); 
+	if(reg.openCreateReg(HKEY_LOCAL_MACHINE,REGISTRY_PROGRAM_NAME))
+	{
+		reg.setRegDword("Auto",cfg->AutoCfg); 
+		reg.setRegDword("MPEG version",cfg->EncCfg.mpegVersion); 
+		reg.setRegDword("Profile",cfg->EncCfg.aacObjectType); 
+		reg.setRegDword("MidSide",cfg->EncCfg.allowMidside); 
+		reg.setRegDword("TNS",cfg->EncCfg.useTns); 
+		reg.setRegDword("LFE",cfg->EncCfg.useLfe); 
+		reg.setRegDword("Use quality",cfg->UseQuality); 
+		reg.setRegDword("Quality",cfg->EncCfg.quantqual); 
+		reg.setRegDword("BitRate",cfg->EncCfg.bitRate); 
+		reg.setRegDword("BandWidth",cfg->EncCfg.bandWidth); 
+		reg.setRegDword("Header",cfg->EncCfg.outputFormat); 
+		reg.setRegStr("OutDir",cfg->OutDir); 
+	}
+	else
+		MessageBox(0,"Can't open registry!",0,MB_OK|MB_ICONSTOP);
 }
 
 #define INIT_CB(hWnd,nID,list,IdSelected) \
@@ -283,12 +420,14 @@
 	case WM_INITDIALOG:
 		{
 		char buf[50];
-		char *BitRate[]={"Auto","8","18","20","24","32","40","48","56","64","96","112","128","160","192","256",0};
-		char *BandWidth[]={"Auto","Full","4000","8000","16000","22050","24000","48000",0};
-		MYCFG cfg;
+		char *Quality[]={"Default","10","20","30","40","50","60","70","80","90","100","110","120","130","140","150","200","300","400","500",0};
+		char *BitRate[]={"Auto","8","18","20","24","32","40","48","56","64","96","112","128","160","192","224","256","320","384",0};
+		char *BandWidth[]={"Auto","Full","4000","8000","11025","16000","22050","24000","32000","44100","48000",0};
+		MY_ENC_CFG cfg;
 			
-			RD_Cfg(&cfg);
+			ReadCfgEnc(&cfg);
 			
+			INIT_CB(hWndDlg,IDC_CB_QUALITY,Quality,0);
 			INIT_CB(hWndDlg,IDC_CB_BITRATE,BitRate,0);
 			INIT_CB(hWndDlg,IDC_CB_BANDWIDTH,BandWidth,0);
 			
@@ -321,17 +460,37 @@
 			
 			switch(cfg.EncCfg.outputFormat)
 			{
-			case 0:
+			case RAW:
 				CheckDlgButton(hWndDlg,IDC_RADIO_RAW,TRUE);
 				break;
-			case 1:
+			case ADTS:
 				CheckDlgButton(hWndDlg,IDC_RADIO_ADTS,TRUE);
 				break;
 			}
 			
-			CheckDlgButton(hWndDlg, IDC_ALLOWMIDSIDE, cfg.EncCfg.allowMidside);
-			CheckDlgButton(hWndDlg, IDC_USETNS, cfg.EncCfg.useTns);
-			CheckDlgButton(hWndDlg, IDC_USELFE, cfg.EncCfg.useLfe);
+			CheckDlgButton(hWndDlg, IDC_CHK_ALLOWMIDSIDE, cfg.EncCfg.allowMidside);
+			CheckDlgButton(hWndDlg, IDC_CHK_USETNS, cfg.EncCfg.useTns);
+			CheckDlgButton(hWndDlg, IDC_CHK_USELFE, cfg.EncCfg.useLfe);
+
+			if(cfg.UseQuality)
+				CheckDlgButton(hWndDlg,IDC_RADIO_QUALITY,TRUE);
+			else
+				CheckDlgButton(hWndDlg,IDC_RADIO_BITRATE,TRUE);
+
+			switch(cfg.EncCfg.quantqual)
+			{
+			case 100:
+				SendMessage(GetDlgItem(hWndDlg, IDC_CB_QUALITY), CB_SETCURSEL, 0, 0);
+				break;
+			default:
+				if(cfg.EncCfg.quantqual<10)
+					cfg.EncCfg.quantqual=10;
+				if(cfg.EncCfg.quantqual>500)
+					cfg.EncCfg.quantqual=500;
+				sprintf(buf,"%lu",cfg.EncCfg.quantqual);
+				SetDlgItemText(hWndDlg, IDC_CB_QUALITY, buf);
+				break;
+			}
 			switch(cfg.EncCfg.bitRate)
 			{
 			case 0:
@@ -379,9 +538,9 @@
 			
 		case IDOK:
 			{
-			char buf[50];
 			HANDLE hCfg=(HANDLE)lParam;
-			MYCFG cfg;
+			char buf[50];
+			MY_ENC_CFG cfg;
 				
 				cfg.AutoCfg=IsDlgButtonChecked(hWndDlg,IDC_CHK_AUTOCFG) ? TRUE : FALSE;
 				cfg.EncCfg.mpegVersion=IsDlgButtonChecked(hWndDlg,IDC_RADIO_MPEG4) ? MPEG4 : MPEG2;
@@ -393,9 +552,9 @@
 					cfg.EncCfg.aacObjectType=SSR;
 				if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_LTP))
 					cfg.EncCfg.aacObjectType=LTP;
-				cfg.EncCfg.allowMidside=IsDlgButtonChecked(hWndDlg, IDC_ALLOWMIDSIDE);
-				cfg.EncCfg.useTns=IsDlgButtonChecked(hWndDlg, IDC_USETNS);
-				cfg.EncCfg.useLfe=IsDlgButtonChecked(hWndDlg, IDC_USELFE);
+				cfg.EncCfg.allowMidside=IsDlgButtonChecked(hWndDlg, IDC_CHK_ALLOWMIDSIDE);
+				cfg.EncCfg.useTns=IsDlgButtonChecked(hWndDlg, IDC_CHK_USETNS);
+				cfg.EncCfg.useLfe=IsDlgButtonChecked(hWndDlg, IDC_CHK_USELFE);
 				
 				GetDlgItemText(hWndDlg, IDC_CB_BITRATE, buf, 50);
 				switch(*buf)
@@ -418,10 +577,20 @@
 				default:
 					cfg.EncCfg.bandWidth=GetDlgItemInt(hWndDlg, IDC_CB_BANDWIDTH, 0, FALSE);
 				}
-				cfg.EncCfg.outputFormat=IsDlgButtonChecked(hWndDlg,IDC_RADIO_RAW) ? 0 : 1;
+				cfg.UseQuality=IsDlgButtonChecked(hWndDlg,IDC_RADIO_QUALITY) ? TRUE : FALSE;
+				GetDlgItemText(hWndDlg, IDC_CB_QUALITY, buf, 50);
+				switch(*buf)
+				{
+				case 'D': // Default
+					cfg.EncCfg.quantqual=100;
+					break;
+				default:
+					cfg.EncCfg.quantqual=GetDlgItemInt(hWndDlg, IDC_CB_QUALITY, 0, FALSE);
+				}
+				cfg.EncCfg.outputFormat=IsDlgButtonChecked(hWndDlg,IDC_RADIO_RAW) ? RAW : ADTS;
 				GetDlgItemText(hWndDlg, IDC_E_BROWSE, cfg.OutDir, MAX_PATH);
 				
-				WR_Cfg(&cfg);
+				WriteCfgEnc(&cfg);
 				EndDialog(hWndDlg, (DWORD)hCfg);
 			}
 			break;
@@ -475,8 +644,8 @@
 
 void Config(HWND hWnd)
 {
-	DialogBox(out.hDllInstance, MAKEINTRESOURCE(IDD_COMPRESSION), hWnd, DIALOGMsgProc);
-//	dwOptions=DialogBoxParam((HINSTANCE)out.hDllInstance,(LPCSTR)MAKEINTRESOURCE(IDD_COMPRESSION), (HWND)hWnd, (DLGPROC)DIALOGMsgProc, dwOptions);
+	DialogBox(out.hDllInstance, MAKEINTRESOURCE(IDD_ENCODER), hWnd, DIALOGMsgProc);
+//	dwOptions=DialogBoxParam((HINSTANCE)out.hDllInstance,(LPCSTR)MAKEINTRESOURCE(IDD_ENCODER), (HWND)hWnd, (DLGPROC)DIALOGMsgProc, dwOptions);
 }
 // *********************************************************************************************
 
@@ -483,8 +652,17 @@
 void About(HWND hwnd)
 {
 char buf[256];
+#ifndef FAACENC_VERSION
 	sprintf(buf,
-			APP_NAME " encoder plug-in %s by Antonio Foranna\n\n"
+			APP_NAME " %s by Antonio Foranna\n\n"
+			"This plugin uses FAAC encoder engine\n\n"
+			"Compiled on %s\n",
+			 APP_VER,
+			 __DATE__
+			 );
+#elif
+	sprintf(buf,
+			APP_NAME " %s by Antonio Foranna\n\n"
 			"This plugin uses FAAC encoder engine v%g\n\n"
 			"Compiled on %s\n",
 			 APP_VER,
@@ -491,6 +669,7 @@
 			 FAACENC_VERSION,
 			 __DATE__
 			 );
+#endif
 	MessageBox(hwnd, buf, "About", MB_OK);
 }
 // *********************************************************************************************
@@ -587,7 +766,7 @@
 
 int Open(int lSamprate, int wChannels, int wBitsPerSample, int bufferlenms, int prebufferms)
 {
-MYCFG			cfg;
+MY_ENC_CFG			cfg;
 DWORD			maxBytesOutput;
 unsigned long	samplesInput;
 int				bytesEncoded;
@@ -599,7 +778,7 @@
 	srate = lSamprate;
 	bps = wBitsPerSample;
 
-	RD_Cfg(&cfg);
+	ReadCfgEnc(&cfg);
 
 	strcpy(config_AACoutdir,cfg.OutDir);
 	GetNewFileName(lpstrFilename);
@@ -607,11 +786,11 @@
 	memset(mo,0,sizeof(MYOUTPUT));
 	
 	// open the aac output file
-	if(!(mo->fFile=fopen(lpstrFilename, "wb")))
+	if(!(mo->aacFile=fopen(lpstrFilename, "wb")))
 		ERROR_O("Can't create file");
 	
 	// use bufferized stream
-	setvbuf(mo->fFile,NULL,_IOFBF,32767);
+	setvbuf(mo->aacFile,NULL,_IOFBF,32767);
 
 	// open the encoder library
 	if(!(mo->hEncoder=faacEncOpen(lSamprate, wChannels, &samplesInput, &maxBytesOutput)))
@@ -620,16 +799,26 @@
 	if(!(mo->bitbuf=(unsigned char*)malloc(maxBytesOutput*sizeof(unsigned char))))
 		ERROR_O("Memory allocation error: output buffer");
 	
-	if(!(mo->inbuf=(unsigned char*)malloc(samplesInput*sizeof(short))))
+	if(!(mo->bufIn=(unsigned char*)malloc(samplesInput*(wBitsPerSample>>3))))
 		ERROR_O("Memory allocation error: input buffer");
+
+	if(!(mo->buffer=(int32_t *)malloc(samplesInput*sizeof(int32_t))))
+		ERROR_O("Memory allocation error: input buffer");
 	
+//	ReadCfgEnc(&cfg);
 	if(!cfg.AutoCfg)
 	{
 	faacEncConfigurationPtr myFormat=&cfg.EncCfg;
 	faacEncConfigurationPtr CurFormat=faacEncGetCurrentConfiguration(mo->hEncoder);
 		
-		if(!myFormat->bitRate)
+		if(cfg.UseQuality)
+		{
+			myFormat->quantqual=cfg.EncCfg.quantqual;
 			myFormat->bitRate=CurFormat->bitRate;
+		}
+		else
+			if(!myFormat->bitRate)
+				myFormat->bitRate=CurFormat->bitRate;
 		
 		switch(myFormat->bandWidth)
 		{
@@ -659,9 +848,9 @@
     bytesEncoded=faacEncEncode(mo->hEncoder, 0, 0, mo->bitbuf, maxBytesOutput); // initializes the flushing process
     if(bytesEncoded>0)
 	{
-		tmp=fwrite(mo->bitbuf, 1, bytesEncoded, mo->fFile);
+		tmp=fwrite(mo->bitbuf, 1, bytesEncoded, mo->aacFile);
 		if(tmp!=bytesEncoded)
-			ERROR_O("fwrite");
+			ERROR_O("fwrite()");
 	}
 	
 	return 0;
@@ -670,37 +859,32 @@
 
 void Close()
 {
-// Following code crashes winamp. why???
-
 	if(mo->bytes_into_buffer)
 	{
 	int bytesEncoded;
-		bytesEncoded=faacEncEncode(mo->hEncoder, (short *)mo->inbuf, mo->bytes_into_buffer/sizeof(short), mo->bitbuf, mo->maxBytesOutput);
+	int32_t *buf=mo->buffer;
+
+		To32bit(buf,mo->bufIn,mo->samplesInput,mo->wBitsPerSample>>3,false);
+
+		// call the actual encoding routine
+		bytesEncoded=faacEncEncode(mo->hEncoder, (int32_t *)buf, mo->samplesInput, mo->bitbuf, mo->maxBytesOutput);
 		if(bytesEncoded>0)
-			fwrite(mo->bitbuf, 1, bytesEncoded, mo->fFile);
+			fwrite(mo->bitbuf, 1, bytesEncoded, mo->aacFile);
 	}
 	
-	if(mo->fFile)
+	if(mo->aacFile)
 	{
-		fclose(mo->fFile);
-		mo->fFile=0;
+		fclose(mo->aacFile);
+		mo->aacFile=0;
 	}
 	
 	if(mo->hEncoder)
 		faacEncClose(mo->hEncoder);
 	
-	if(mo->bitbuf)
-	{
-		free(mo->bitbuf);
-		mo->bitbuf=0;
-	}
+	FREE(mo->bitbuf)
+	FREE(mo->bufIn)
+	FREE(mo->buffer)
 	
-	if(mo->inbuf)
-	{
-		free(mo->inbuf);
-		mo->inbuf=0;
-	}
-	
 //	CloseHandle(outfile);
 }
 // *********************************************************************************************
@@ -713,68 +897,53 @@
 	return -1; \
 }
 
-int Write(char *buf, int len)
+int Write(char *wabuf, int len)
 {
+int32_t *buf=mo->buffer;
+BYTE	InputSize=mo->wBitsPerSample>>3;
 int bytesWritten;
 int bytesEncoded;
-int k,i,shift=0;
+int shift=0;
 
 	writtentime += len;
 
 	if(!mo->bStopEnc)
-	{
-		
-		if(mo->bytes_into_buffer+len<mo->samplesInput*sizeof(short))
+		do
 		{
-			memcpy(mo->inbuf+mo->bytes_into_buffer, buf, len);
-			mo->bytes_into_buffer+=len;
-			return 0;
-		}
-		else
-			if(mo->bytes_into_buffer)
+			if(mo->bytes_into_buffer+len<mo->samplesInput*InputSize)
 			{
-				shift=mo->samplesInput*sizeof(short)-mo->bytes_into_buffer;
-				memcpy(mo->inbuf+mo->bytes_into_buffer, buf, shift);
+				memcpy(mo->bufIn+mo->bytes_into_buffer, wabuf, len);
+				mo->bytes_into_buffer+=len;
+				len=0;
+			}
+			else
+			{
+				shift=mo->samplesInput*InputSize-mo->bytes_into_buffer;
+				memcpy(mo->bufIn+mo->bytes_into_buffer, wabuf, shift);
 				mo->bytes_into_buffer+=shift;
-				buf+=shift;
+				wabuf+=shift;
 				len-=shift;
 				
-				bytesEncoded=faacEncEncode(mo->hEncoder, (short *)mo->inbuf, mo->samplesInput, mo->bitbuf, mo->maxBytesOutput);
+				To32bit(buf,mo->bufIn,mo->samplesInput,InputSize,false);
+
+				// call the actual encoding routine
+				bytesEncoded=faacEncEncode(mo->hEncoder, (int32_t *)buf, mo->samplesInput, mo->bitbuf, mo->maxBytesOutput);
+
 				mo->bytes_into_buffer=0;
-				if(bytesEncoded<1) // end of flushing process
+				if(bytesEncoded>0)
 				{
-					if(bytesEncoded<0)
-						ERROR_W("faacEncEncode() failed");
-					return 0;
+					// write bitstream to aac file 
+					bytesWritten=fwrite(mo->bitbuf, 1, bytesEncoded, mo->aacFile);
+					if(bytesWritten!=bytesEncoded)
+						ERROR_W("bytesWritten and bytesEncoded are different");
 				}
-				// write bitstream to aac file 
-				bytesWritten=fwrite(mo->bitbuf, 1, bytesEncoded, mo->fFile);
-				if(bytesWritten!=bytesEncoded)
-					ERROR_W("bytesWritten and bytesEncoded are different");
-			}
-			
-			// call the actual encoding routine
-			k=len/(mo->samplesInput*sizeof(short));
-			for(i=0; i<k; i++)
-			{
-				bytesEncoded+=faacEncEncode(mo->hEncoder, ((short *)buf)+i*mo->samplesInput, mo->samplesInput, mo->bitbuf, mo->maxBytesOutput);
-				if(bytesEncoded<1) // end of flushing process
-				{
+				else
 					if(bytesEncoded<0)
-						ERROR_W("faacEncEncode() failed");
-					return 0;
-				}
-				// write bitstream to aac file 
-				bytesWritten=fwrite(mo->bitbuf, 1, bytesEncoded, mo->fFile);
-				if(bytesWritten!=bytesEncoded)
-					ERROR_W("bytesWritten and bytesEncoded are different");
+						ERROR_W("faacEncEncode()");
 			}
-			
-			mo->bytes_into_buffer=len%(mo->samplesInput*sizeof(short));
-			memcpy(mo->inbuf, buf+k*mo->samplesInput*sizeof(short), mo->bytes_into_buffer);
-	}
+		}while(len);
 
-	Sleep(0);
+	Sleep(10);
 	return 0;
 }
 // *********************************************************************************************
@@ -782,7 +951,7 @@
 int CanWrite()
 {
 	return last_pause ? 0 : 16*1024*1024;
-//	return last_pause ? 0 : mo->samplesInput;
+//	return last_pause ? 0 : mo->samplesInput*(mo->wBitsPerSample>>3);
 }
 // *********************************************************************************************
 
--- a/plugins/winamp/RESOURCE.H
+++ b/plugins/winamp/RESOURCE.H
@@ -3,6 +3,7 @@
 // Used by FAAC.rc
 //
 #define IDD_COMPRESSION                 101
+#define IDD_ENCODER                     101
 #define IDB_LOGO                        104
 #define IDB_BROWSE                      105
 #define IDC_RADIO_MPEG4                 1000
@@ -12,8 +13,11 @@
 #define IDC_RADIO_SSR                   1004
 #define IDC_RADIO_LTP                   1005
 #define IDC_ALLOWMIDSIDE                1006
+#define IDC_CHK_ALLOWMIDSIDE            1006
 #define IDC_USETNS                      1007
+#define IDC_CHK_USETNS                  1007
 #define IDC_USELFE                      1008
+#define IDC_CHK_USELFE                  1008
 #define IDC_CB_BANDWIDTH                1009
 #define IDC_CB_BITRATE                  1010
 #define IDC_CHK_AUTOCFG                 1011
@@ -23,6 +27,9 @@
 #define IDC_RADIO_RAW                   1014
 #define IDC_BTN_ABOUT                   1015
 #define IDC_RADIO_ADTS                  1015
+#define IDC_RADIO_BITRATE               1022
+#define IDC_RADIO_QUALITY               1023
+#define IDC_CB_QUALITY                  1024
 
 // Next default values for new objects
 // 
--- a/plugins/winamp/defines.h
+++ b/plugins/winamp/defines.h
@@ -1,3 +1,3 @@
-#define APP_NAME "Freeware AAC encoder"
-#define APP_VER "v1.0 beta3"
+#define APP_NAME "MPEG4-AAC encoder plug-in"
+#define APP_VER "v1.1"
 #define REGISTRY_PROGRAM_NAME "SOFTWARE\\4N\\Winamp\\Out_AAC"
--- a/plugins/winamp/out_FAAC.dsp
+++ b/plugins/winamp/out_FAAC.dsp
@@ -43,7 +43,7 @@
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OUT_FAAC_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OUT_FAAC_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\include" /I "../../../faad2/common/mp4v2" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /YX /FD /c
 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x410 /d "NDEBUG"
@@ -69,7 +69,7 @@
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OUT_FAAC_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OUT_FAAC_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\include" /I "../../../faad2/common/mp4v2" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /YX /FD /GZ /c
 # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x410 /d "_DEBUG"
@@ -79,7 +79,7 @@
 # ADD BSC32 /nologo
 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 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 /out:"Debug/Out_AAC.dll" /pdbtype:sept
+# ADD 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 /out:"C:\Program Files\Sound\Gen\Winamp\Plugins\Out_AAC.dll" /pdbtype:sept
 
 !ENDIF 
 
@@ -117,6 +117,10 @@
 # Begin Source File
 
 SOURCE=.\defines.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\faac.h
 # End Source File
 # Begin Source File