shithub: aacenc

Download patch

ref: 70953ef97dc61e5942930635454934c1f7c26897
parent: 27afaa1f7b2eed61b42b2b3c7bf848c907fa4b28
author: menno <menno>
date: Thu Aug 22 18:58:57 EDT 2002

Bugfixed Cooledit filter

--- /dev/null
+++ b/plugins/cooledit/CRegistry.cpp
@@ -1,0 +1,331 @@
+/*
+FAAD - codec plugin for Cooledit
+Copyright (C) 2002 Antonio Foranna
+
+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.
+	
+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., 675 Mass Ave, Cambridge, MA 02139, USA.
+			
+The author can be contacted at:
+kreel@interfree.it
+*/
+
+//#include "stdafx.h"
+#include <windows.h>
+#include <string.h>
+#include <memory.h>
+#include "CRegistry.h"
+
+CRegistry::CRegistry()
+{
+	regKey=NULL;
+	path=NULL;
+}
+
+CRegistry::~CRegistry()
+{
+	if(regKey)
+		RegCloseKey(regKey);
+	if(path)
+		free(path);
+}
+// *****************************************************************************
+// *****************************************************************************
+// *****************************************************************************
+
+#define setPath(SubKey) \
+	if(path) \
+		free(path); \
+	path=strdup(SubKey);
+
+BOOL CRegistry::openReg(HKEY hKey, char *SubKey)
+{
+	if(regKey)
+		RegCloseKey(regKey);
+	if(RegOpenKeyEx(hKey, SubKey, NULL , KEY_ALL_ACCESS , &regKey)==ERROR_SUCCESS)
+	{
+		setPath(SubKey);
+		return TRUE;
+	}
+	else // can't open the key -> error
+	{
+		regKey=0;
+		setPath("");
+		return FALSE;
+	}
+}
+// *****************************************************************************
+
+BOOL CRegistry::openCreateReg(HKEY hKey, char *SubKey)
+{
+	if(regKey)
+		RegCloseKey(regKey);
+	if(RegOpenKeyEx(hKey, SubKey, NULL , KEY_ALL_ACCESS , &regKey)==ERROR_SUCCESS)
+	{
+		setPath(SubKey);
+		return TRUE;
+	}
+	else // open failed -> create the key
+	{
+	DWORD disp;
+		RegCreateKeyEx(hKey , SubKey, NULL , NULL, REG_OPTION_NON_VOLATILE , KEY_ALL_ACCESS , NULL , &regKey , &disp );
+		if(disp==REG_CREATED_NEW_KEY) 
+		{
+			setPath(SubKey);
+			return TRUE;
+		}
+		else // can't create the key -> error
+		{
+			regKey=0;
+			setPath("");
+			return FALSE;
+		}
+	}
+}
+// *****************************************************************************
+
+void CRegistry::closeReg()
+{
+	if(regKey)
+		RegCloseKey(regKey);
+	regKey=NULL;
+	if(path) 
+		delete path; 
+	path=NULL;
+}
+// *****************************************************************************
+// *****************************************************************************
+// *****************************************************************************
+
+void CRegistry::DeleteRegVal(char *SubKey)
+{
+	RegDeleteValue(regKey,SubKey);
+}
+// *****************************************************************************
+
+void CRegistry::DeleteRegKey(char *SubKey)
+{
+	RegDeleteKey(regKey,SubKey);
+}
+
+// *****************************************************************************
+// *****************************************************************************
+// *****************************************************************************
+
+void CRegistry::setRegBool(char *keyStr , BOOL val)
+{
+BOOL tempVal;
+DWORD len;
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS ||
+		tempVal!=val)
+		RegSetValueEx(regKey , keyStr , NULL , REG_BINARY , (BYTE *)&val , sizeof(BOOL));
+}
+// *****************************************************************************
+
+void CRegistry::setRegByte(char *keyStr , BYTE val)
+{
+DWORD	t=val;
+DWORD	tempVal;
+DWORD	len;
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS ||
+		tempVal!=val)
+		RegSetValueEx(regKey , keyStr , NULL , REG_DWORD , (BYTE *)&t , sizeof(DWORD));
+}
+// *****************************************************************************
+
+void CRegistry::setRegWord(char *keyStr , WORD val)
+{
+DWORD	t=val;
+DWORD	tempVal;
+DWORD	len;
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS ||
+		tempVal!=val)
+		RegSetValueEx(regKey , keyStr , NULL , REG_DWORD , (BYTE *)&t , sizeof(DWORD));
+}
+// *****************************************************************************
+
+void CRegistry::setRegDword(char *keyStr , DWORD val)
+{
+DWORD tempVal;
+DWORD len;
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS ||
+		tempVal!=val)
+		RegSetValueEx(regKey , keyStr , NULL , REG_DWORD , (BYTE *)&val , sizeof(DWORD));
+}
+// *****************************************************************************
+
+void CRegistry::setRegFloat(char *keyStr , float val)
+{
+float tempVal;
+DWORD len;
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS ||
+		tempVal!=val)
+		RegSetValueEx(regKey , keyStr , NULL , REG_BINARY , (BYTE *)&val , sizeof(float));
+}
+// *****************************************************************************
+
+void CRegistry::setRegStr(char *keyStr , char *valStr)
+{
+DWORD len;
+DWORD slen=strlen(valStr)+1;
+
+	if(!valStr || !*valStr)
+		return;
+
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, NULL , &len )!=ERROR_SUCCESS ||
+		len!=slen)
+		RegSetValueEx(regKey , keyStr , NULL , REG_SZ , (BYTE *)valStr , slen);
+	else
+	{
+	char *tempVal=new char[slen];
+		if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)tempVal , &len )!=ERROR_SUCCESS ||
+			strcmpi(tempVal,valStr))
+			RegSetValueEx(regKey , keyStr , NULL , REG_SZ , (BYTE *)valStr , slen);
+		delete tempVal;
+	}
+}
+// *****************************************************************************
+
+void CRegistry::setRegValN(char *keyStr , BYTE *addr,  DWORD size)
+{
+DWORD len;
+	if(!addr || !size)
+		return;
+
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, NULL , &len )!=ERROR_SUCCESS ||
+		len!=size)
+		RegSetValueEx(regKey , keyStr , NULL , REG_BINARY , addr , size);
+	else
+	{
+	BYTE *tempVal=new BYTE[size];
+		if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)tempVal , &len )!=ERROR_SUCCESS ||
+			memcmp(tempVal,addr,len))
+			RegSetValueEx(regKey , keyStr , NULL , REG_BINARY , addr , size);
+		delete tempVal;
+	}
+}
+
+
+
+// *****************************************************************************
+// *****************************************************************************
+// *****************************************************************************
+
+
+
+BOOL CRegistry::getSetRegBool(char *keyStr, BOOL val)
+{
+BOOL tempVal;
+DWORD len=sizeof(BOOL);
+
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS)
+	{
+		RegSetValueEx(regKey , keyStr , NULL , REG_BINARY , (BYTE *)&val , sizeof(BOOL));
+		return val;
+	}
+	return tempVal;
+}
+// *****************************************************************************
+
+BYTE CRegistry::getSetRegByte(char *keyStr, BYTE val)
+{
+DWORD tempVal;
+DWORD len=sizeof(DWORD);
+
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS)
+	{
+		tempVal=val;
+		RegSetValueEx(regKey , keyStr , NULL , REG_DWORD , (BYTE *)&tempVal , sizeof(DWORD));
+		return val;
+	}
+	return (BYTE)tempVal;
+}
+// *****************************************************************************
+
+WORD CRegistry::getSetRegWord(char *keyStr, WORD val)
+{
+DWORD tempVal;
+DWORD len=sizeof(DWORD);
+
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS)
+	{
+		tempVal=val;
+		RegSetValueEx(regKey , keyStr , NULL , REG_DWORD , (BYTE *)&tempVal , sizeof(DWORD));
+		return val;
+	}
+	return (WORD)tempVal;
+}
+// *****************************************************************************
+
+DWORD CRegistry::getSetRegDword(char *keyStr, DWORD val)
+{
+DWORD tempVal;
+DWORD len=sizeof(DWORD);
+
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS)
+	{
+		RegSetValueEx(regKey , keyStr , NULL , REG_DWORD , (BYTE *)&val , sizeof(DWORD));
+		return val;
+	}
+	return (DWORD)tempVal;
+}
+// *****************************************************************************
+
+float CRegistry::getSetRegFloat(char *keyStr, float val)
+{
+float tempVal;
+DWORD len=sizeof(float);
+
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS)
+	{
+		RegSetValueEx(regKey , keyStr , NULL , REG_BINARY , (BYTE *)&val , sizeof(float));
+		return val;
+	}
+	return tempVal;
+}
+// *****************************************************************************
+
+int CRegistry::getSetRegStr(char *keyStr, char *tempString, char *dest, int maxLen)
+{
+DWORD tempLen=maxLen;
+	
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *) dest , &tempLen )!=ERROR_SUCCESS)
+	{
+		if(!tempString)
+		{
+			*dest=0;
+			return 0;
+		}
+		strcpy(dest,tempString);
+		tempLen=strlen(tempString)+1;
+		RegSetValueEx(regKey , keyStr , NULL , REG_SZ , (BYTE *)tempString , tempLen);
+	}
+	return tempLen;
+}
+// *****************************************************************************
+
+int CRegistry::getSetRegValN(char *keyStr, BYTE *tempAddr, BYTE *addr, DWORD size)
+{
+DWORD tempLen=size;
+
+	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)addr , &tempLen )!=ERROR_SUCCESS)
+	{
+		if(!tempAddr)
+		{
+			*addr=0;
+			return 0;
+		}
+		memcpy(addr,tempAddr,size);
+		RegSetValueEx(regKey , keyStr , NULL , REG_BINARY , (BYTE *)addr , size);
+	}
+	return tempLen;
+}
--- /dev/null
+++ b/plugins/cooledit/CRegistry.h
@@ -1,0 +1,35 @@
+#ifndef registry_h
+#define registry_h
+
+class CRegistry 
+{
+public:
+			CRegistry();
+			~CRegistry();
+
+	BOOL	openReg(HKEY hKey, char *SubKey);
+	BOOL	openCreateReg(HKEY hKey, char *SubKey);
+	void	closeReg();
+	void	DeleteRegVal(char *SubKey);
+	void	DeleteRegKey(char *SubKey);
+
+	void	setRegBool(char *keyStr , BOOL val);
+	void	setRegByte(char *keyStr , BYTE val);
+	void	setRegWord(char *keyStr , WORD val);
+	void	setRegDword(char *keyStr , DWORD val);
+	void	setRegFloat(char *keyStr , float val);
+	void	setRegStr(char *keyStr , char *valStr);
+	void	setRegValN(char *keyStr , BYTE *addr,  DWORD size);
+
+	BOOL	getSetRegBool(char *keyStr, BOOL var);
+	BYTE	getSetRegByte(char *keyStr, BYTE var);
+	WORD	getSetRegWord(char *keyStr, WORD var);
+	DWORD	getSetRegDword(char *keyStr, DWORD var);
+	float	getSetRegFloat(char *keyStr, float var);
+	int		getSetRegStr(char *keyStr, char *tempString, char *dest, int maxLen);
+	int		getSetRegValN(char *keyStr, BYTE *tempAddr, BYTE *addr, DWORD size);
+
+	HKEY	regKey;
+	char	*path;
+};
+#endif
\ No newline at end of file
--- a/plugins/cooledit/FAAD.DSP
+++ b/plugins/cooledit/FAAD.DSP
@@ -98,6 +98,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\CRegistry.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\Faac.cpp
 # End Source File
 # Begin Source File
@@ -116,10 +120,6 @@
 
 SOURCE=.\Main.cpp
 # End Source File
-# Begin Source File
-
-SOURCE=.\Registry.cpp
-# End Source File
 # End Group
 # Begin Group "Header Files"
 
@@ -126,19 +126,27 @@
 # PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
 # Begin Source File
 
-SOURCE=..\..\include\faac.h
+SOURCE=.\AACINFO.H
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\..\faad2\include\faad.h
+SOURCE=.\CRegistry.h
 # End Source File
 # Begin Source File
 
-SOURCE=.\filters.h
+SOURCE=.\defines.h
 # End Source File
 # Begin Source File
 
-SOURCE=.\Registry.h
+SOURCE=..\..\include\faac.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\faad2\include\faad.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\filters.h
 # End Source File
 # Begin Source File
 
--- a/plugins/cooledit/FAAD.rc
+++ b/plugins/cooledit/FAAD.rc
@@ -28,7 +28,7 @@
 
 IDD_COMPRESSION DIALOG DISCARDABLE  0, 0, 184, 126
 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
-CAPTION "AAC-MPEG4 options"
+CAPTION "MPEG4-AAC options"
 FONT 8, "MS Sans Serif"
 BEGIN
     CONTROL         "Automatic configuration",IDC_CHK_AUTOCFG,"Button",
@@ -55,8 +55,8 @@
                     WS_TABSTOP,108,33,45,10
     CONTROL         "Use LFE channel",IDC_USELFE,"Button",BS_AUTOCHECKBOX | 
                     WS_DISABLED | WS_TABSTOP,108,46,67,10
-    COMBOBOX        IDC_CB_BITRATE,132,68,48,30,CBS_DROPDOWNLIST | 
-                    WS_VSCROLL | WS_TABSTOP
+    COMBOBOX        IDC_CB_BITRATE,132,68,48,30,CBS_DROPDOWN | WS_VSCROLL | 
+                    WS_TABSTOP
     COMBOBOX        IDC_CB_BANDWIDTH,132,85,48,30,CBS_DROPDOWN | WS_VSCROLL | 
                     WS_TABSTOP
     DEFPUSHBUTTON   "OK",IDOK,72,107,36,14
@@ -65,7 +65,7 @@
     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 (0=full)",IDC_STATIC,59,89,57,8
+    LTEXT           "Bandwidth",IDC_STATIC,59,89,34,8
     GROUPBOX        "Header",IDC_STATIC,55,18,48,38
 END
 
--- a/plugins/cooledit/Faac.cpp
+++ b/plugins/cooledit/Faac.cpp
@@ -1,17 +1,34 @@
+/*
+FAAD - codec plugin for Cooledit
+Copyright (C) 2002 Antonio Foranna
+
+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.
+	
+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., 675 Mass Ave, Cambridge, MA 02139, USA.
+			
+The author can be contacted at:
+kreel@interfree.it
+*/
+
 #include <windows.h>
 #include <stdio.h>  // FILE *
 #include "filters.h" //CoolEdit
 #include "resource.h"
 #include "faac.h"
-#include "registry.h"
+#include "CRegistry.h"
+#include "defines.h"
 
 
 
-#define PI_VER "v2.0 beta2"
-#define REGISTRY_PROGRAM_NAME "SOFTWARE\\4N\\CoolEdit\\AAC-MPEG4"
-
-
-
 typedef struct output_tag  // any special vars associated with output file
 {
 FILE			*fFile;
@@ -44,38 +61,43 @@
 
 void RD_Cfg(MYCFG *cfg) 
 { 
-registryClass *reg=new registryClass();
+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); 
-	delete 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); 
 }
 
 void WR_Cfg(MYCFG *cfg) 
 { 
-registryClass *reg=new registryClass();
+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); 
-	delete 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); 
 }
 
+#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); \
+}
+
 #define DISABLE_LTP \
 { \
 	if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_MPEG2) && \
@@ -118,36 +140,16 @@
 	{
 	case WM_INITDIALOG:
 		{
-		char buf[10];
+		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;
 
 			RD_Cfg(&cfg);
 
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"8");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"18");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"20");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"24");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"32");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"40");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"48");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"56");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"64");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"96");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"112");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"128");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"160");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"192");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"256");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_SETCURSEL, 8, 0);
+			INIT_CB(hWndDlg,IDC_CB_BITRATE,BitRate,0);
+			INIT_CB(hWndDlg,IDC_CB_BANDWIDTH,BandWidth,0);
 
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BANDWIDTH), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"0");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BANDWIDTH), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"4000");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BANDWIDTH), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"8000");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BANDWIDTH), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"16000");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BANDWIDTH), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"22050");
-			SendMessage(GetDlgItem(hWndDlg, IDC_CB_BANDWIDTH), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"24000");
-//       SendMessage(GetDlgItem(hWndDlg, IDC_CB_BANDWIDTH), CB_SETCURSEL, 0, 0);
-
 			if(cfg.EncCfg.mpegVersion==MPEG4)
 				CheckDlgButton(hWndDlg,IDC_RADIO_MPEG4,TRUE);
 			else
@@ -183,10 +185,29 @@
 			CheckDlgButton(hWndDlg, IDC_ALLOWMIDSIDE, cfg.EncCfg.allowMidside);
 			CheckDlgButton(hWndDlg, IDC_USETNS, cfg.EncCfg.useTns);
 			CheckDlgButton(hWndDlg, IDC_USELFE, cfg.EncCfg.useLfe);
-			sprintf(buf,"%lu",cfg.EncCfg.bitRate);
-			SetDlgItemText(hWndDlg, IDC_CB_BITRATE, buf);
-			sprintf(buf,"%lu",cfg.EncCfg.bandWidth);
-			SetDlgItemText(hWndDlg, IDC_CB_BANDWIDTH, buf);
+			switch(cfg.EncCfg.bitRate)
+			{
+			case 0:
+				SendMessage(GetDlgItem(hWndDlg, IDC_CB_BITRATE), CB_SETCURSEL, 0, 0);
+				break;
+			default:
+				sprintf(buf,"%lu",cfg.EncCfg.bitRate);
+				SetDlgItemText(hWndDlg, IDC_CB_BITRATE, buf);
+				break;
+			}
+			switch(cfg.EncCfg.bandWidth)
+			{
+			case 0:
+				SendMessage(GetDlgItem(hWndDlg, IDC_CB_BANDWIDTH), CB_SETCURSEL, 0, 0);
+				break;
+			case 0xffffffff:
+				SendMessage(GetDlgItem(hWndDlg, IDC_CB_BANDWIDTH), CB_SETCURSEL, 1, 0);
+				break;
+			default:
+				sprintf(buf,"%lu",cfg.EncCfg.bandWidth);
+				SetDlgItemText(hWndDlg, IDC_CB_BANDWIDTH, buf);
+				break;
+			}
 
 			CheckDlgButton(hWndDlg,IDC_CHK_AUTOCFG, cfg.AutoCfg);
 
@@ -211,34 +232,48 @@
 
 		case IDOK:
 			{
+			char buf[50];
 			HANDLE hCfg=(HANDLE)lParam;
-			MYCFG far *cfg=0;
+			MYCFG cfg;
 
-				if(!(hCfg=GlobalAlloc(GMEM_MOVEABLE|GMEM_SHARE,sizeof(MYCFG))))
-					return TRUE;
-				cfg=(MYCFG *)GlobalLock(hCfg);
-
-				cfg->AutoCfg=IsDlgButtonChecked(hWndDlg,IDC_CHK_AUTOCFG) ? TRUE : FALSE;
-				cfg->EncCfg.mpegVersion=IsDlgButtonChecked(hWndDlg,IDC_RADIO_MPEG4) ? MPEG4 : MPEG2;
+				cfg.AutoCfg=IsDlgButtonChecked(hWndDlg,IDC_CHK_AUTOCFG) ? TRUE : FALSE;
+				cfg.EncCfg.mpegVersion=IsDlgButtonChecked(hWndDlg,IDC_RADIO_MPEG4) ? MPEG4 : MPEG2;
 				if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_MAIN))
-					cfg->EncCfg.aacObjectType=MAIN;
+					cfg.EncCfg.aacObjectType=MAIN;
 				if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_LOW))
-					cfg->EncCfg.aacObjectType=LOW;
+					cfg.EncCfg.aacObjectType=LOW;
 				if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_SSR))
-					cfg->EncCfg.aacObjectType=SSR;
+					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.bitRate=1000*GetDlgItemInt(hWndDlg, IDC_CB_BITRATE, 0, FALSE);
-				cfg->EncCfg.bandWidth=GetDlgItemInt(hWndDlg, IDC_CB_BANDWIDTH, 0, FALSE);
-				cfg->EncCfg.outputFormat=IsDlgButtonChecked(hWndDlg,IDC_RADIO_RAW) ? 0 : 1;
-				WR_Cfg(cfg);
+					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);
+				
+				GetDlgItemText(hWndDlg, IDC_CB_BITRATE, buf, 50);
+				switch(*buf)
+				{
+				case 'A': 
+						cfg.EncCfg.bitRate=0;
+						break;
+				default:
+						cfg.EncCfg.bitRate=1000*GetDlgItemInt(hWndDlg, IDC_CB_BITRATE, 0, FALSE);
+				}
+				GetDlgItemText(hWndDlg, IDC_CB_BANDWIDTH, buf, 50);
+				switch(*buf)
+				{
+				case 'A': 
+					cfg.EncCfg.bandWidth=0;
+					break;
+				case 'F':
+					cfg.EncCfg.bandWidth=0xffffffff;
+					break;
+				default:
+					cfg.EncCfg.bandWidth=GetDlgItemInt(hWndDlg, IDC_CB_BANDWIDTH, 0, FALSE);
+				}
+				cfg.EncCfg.outputFormat=IsDlgButtonChecked(hWndDlg,IDC_RADIO_RAW) ? 0 : 1;
 
-				GlobalUnlock(hCfg);
-//				dwOptions=(DWORD)hCfg;
-
+				WR_Cfg(&cfg);
 				EndDialog(hWndDlg, (DWORD)hCfg);
 			}
 			break;
@@ -252,11 +287,11 @@
 		case IDC_BTN_ABOUT:
            	 {
 		     char buf[256];
- 			  sprintf(buf,	"AAC-MPEG4 plugin %s by 4N\n"
-				  "This plugin uses FAAC encoder engine v"
-				  FAACENC_VERSION " and FAAD2 decoder engine\n\n"
+ 			  sprintf(buf,	APP_NAME " plugin %s by 4N\n"
+							"This plugin uses FAAC encoder engine v%g and FAAD2 decoder engine\n\n"
 							"Compiled on %s\n",
-							PI_VER,
+							APP_VER,
+							FAACENC_VERSION,
 							__DATE__
 						  );
 		      MessageBox(hWndDlg, buf, "About", MB_OK);
@@ -286,23 +321,31 @@
 long nDialogReturn=0;
 FARPROC lpfnDIALOGMsgProc;
 	
- lpfnDIALOGMsgProc=GetProcAddress(hInst,(LPCSTR)MAKELONG(20,0));			
- nDialogReturn=(long)DialogBoxParam((HINSTANCE)hInst,(LPCSTR)MAKEINTRESOURCE(IDD_COMPRESSION), (HWND)hWnd, (DLGPROC)lpfnDIALOGMsgProc, dwOptions);
+	lpfnDIALOGMsgProc=GetProcAddress(hInst,(LPCSTR)MAKELONG(20,0));			
+	nDialogReturn=(long)DialogBoxParam((HINSTANCE)hInst,(LPCSTR)MAKEINTRESOURCE(IDD_COMPRESSION), (HWND)hWnd, (DLGPROC)lpfnDIALOGMsgProc, dwOptions);
 
- return nDialogReturn;
+	return nDialogReturn;
 }
 // *********************************************************************************************
 
+__declspec(dllexport) void FAR PASCAL GetSuggestedSampleType(LONG *lplSamprate, WORD *lpwBitsPerSample, WORD *wChannels)
+{
+	*lplSamprate=0; // don't care
+	*lpwBitsPerSample= *lpwBitsPerSample<=24 ? 0: 24;
+	*wChannels= *wChannels<=2 ? 0 : 2;
+}
+// *********************************************************************************************
+
 __declspec(dllexport) DWORD FAR PASCAL FilterWriteFirstSpecialData(HANDLE hInput, 
 	SPECIALDATA * psp)
 {
- return 0;
+	return 0;
 }
 // *********************************************************************************************
 
 __declspec(dllexport) DWORD FAR PASCAL FilterWriteNextSpecialData(HANDLE hInput, SPECIALDATA * psp)
 {	
- return 0;
+	return 0;
 // only has 1 special data!  Otherwise we would use psp->hSpecialData
 // as either a counter to know which item to retrieve next, or as a
 // structure with other state information in it.
@@ -312,36 +355,37 @@
 __declspec(dllexport) DWORD FAR PASCAL FilterWriteSpecialData(HANDLE hOutput,
 	LPCSTR szListType, LPCSTR szType, char * pData,DWORD dwSize)
 {
- return 0;
+	return 0;
 }
 // *********************************************************************************************
 
 __declspec(dllexport) void FAR PASCAL CloseFilterOutput(HANDLE hOutput)
 {
- if(hOutput)
- {
- MYOUTPUT *mo;
-  mo=(MYOUTPUT *)GlobalLock(hOutput);
+	if(!hOutput)
+		return;
 
- if(mo->fFile)
- {
-  fclose(mo->fFile);
-  mo->fFile=0;
- }
+MYOUTPUT *mo;
 
- if(mo->hEncoder)
-  faacEncClose(mo->hEncoder);
-
- if(mo->bitbuf)
- {
-  free(mo->bitbuf);
-  mo->bitbuf=0;
- }
-
- 
-  GlobalUnlock(hOutput);
-  GlobalFree(hOutput);
- }
+	mo=(MYOUTPUT *)GlobalLock(hOutput);
+	
+	if(mo->fFile)
+	{
+		fclose(mo->fFile);
+		mo->fFile=0;
+	}
+	
+	if(mo->hEncoder)
+		faacEncClose(mo->hEncoder);
+	
+	if(mo->bitbuf)
+	{
+		free(mo->bitbuf);
+		mo->bitbuf=0;
+	}
+	
+	
+	GlobalUnlock(hOutput);
+	GlobalFree(hOutput);
 }              
 // *********************************************************************************************
 
@@ -348,7 +392,7 @@
 #define ERROR_OFO(msg) \
 { \
 	if(msg) \
-		MessageBox(0, msg, "FAAC plugin", MB_OK); \
+		MessageBox(0, msg, APP_NAME " plugin", MB_OK); \
 	if(hOutput) \
 	{ \
 		GlobalUnlock(hOutput); \
@@ -391,10 +435,21 @@
 	if(!cfg.AutoCfg)
 	{
     faacEncConfigurationPtr myFormat=&cfg.EncCfg;
-//     myFormat=faacEncGetCurrentConfiguration(mo->hEncoder);
+    faacEncConfigurationPtr CurFormat=faacEncGetCurrentConfiguration(mo->hEncoder);
 
-		if(!myFormat->bandWidth)
+		if(!myFormat->bitRate)
+			myFormat->bitRate=CurFormat->bitRate;
+
+		switch(myFormat->bandWidth)
+		{
+		case 0:
+			myFormat->bandWidth=CurFormat->bandWidth;
+			break;
+		case 0xffffffff:
 			myFormat->bandWidth=lSamprate/2;
+			break;
+		default: break;
+		}
 
 		if(!faacEncSetConfiguration(mo->hEncoder, myFormat))
 			ERROR_OFO("Unsupported parameters");
@@ -431,7 +486,7 @@
 #define ERROR_WFO(msg) \
 { \
 	if(msg) \
-		MessageBox(0, msg, "FAAC plugin", MB_OK); \
+		MessageBox(0, msg, APP_NAME " plugin", MB_OK); \
 	if(hOutput) \
 	{ \
 		mo->bStopEnc=1; \
@@ -442,34 +497,34 @@
 
 __declspec(dllexport) DWORD FAR PASCAL WriteFilterOutput(HANDLE hOutput, unsigned char far *buf, long lBytes)
 {
+	if(!hOutput)
+		return 0;
+
 int bytesWritten;
 int bytesEncoded;
+MYOUTPUT far *mo;
 
- if(hOutput)
- { 
- MYOUTPUT far *mo;
-  mo=(MYOUTPUT far *)GlobalLock(hOutput);
+	mo=(MYOUTPUT far *)GlobalLock(hOutput);
+	
+	if(!mo->bStopEnc) // Is this case possible?
+	{
+		// call the actual encoding routine
+		bytesEncoded=faacEncEncode(mo->hEncoder, (short *)buf, mo->samplesInput, mo->bitbuf, mo->maxBytesOutput);
+		if(bytesEncoded<1) // end of flushing process
+		{
+			if(bytesEncoded<0)
+				ERROR_WFO("faacEncEncode");
+			bytesWritten=lBytes ? 1 : 0; // bytesWritten==0 stops CoolEdit...
+			GlobalUnlock(hOutput);
+			return bytesWritten;
+		}
+		// write bitstream to aac file 
+		bytesWritten=fwrite(mo->bitbuf, 1, bytesEncoded, mo->fFile);
+		if(bytesWritten!=bytesEncoded)
+			ERROR_WFO("fwrite");
+		
+		GlobalUnlock(hOutput);
+	}
 
-  if(!mo->bStopEnc) // Is this case possible?
-  {
-// call the actual encoding routine
-   bytesEncoded=faacEncEncode(mo->hEncoder, (short *)buf, mo->samplesInput, mo->bitbuf, mo->maxBytesOutput);
-   if(bytesEncoded<1) // end of flushing process
-   {
-    if(bytesEncoded<0)
-		ERROR_WFO("faacEncEncode");
-	bytesWritten=lBytes ? 1 : 0; // bytesWritten==0 stops CoolEdit...
-    GlobalUnlock(hOutput);
-    return bytesWritten;
-   }
-// write bitstream to aac file 
-   bytesWritten=fwrite(mo->bitbuf, 1, bytesEncoded, mo->fFile);
-   if(bytesWritten!=bytesEncoded)
-		ERROR_WFO("fwrite");
-
-   GlobalUnlock(hOutput);
-  }
- }
-
- return bytesWritten;
+return bytesWritten;
 }
--- a/plugins/cooledit/Faad.cpp
+++ b/plugins/cooledit/Faad.cpp
@@ -1,3 +1,24 @@
+/*
+FAAD - codec plugin for Cooledit
+Copyright (C) 2002 Antonio Foranna
+
+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.
+	
+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., 675 Mass Ave, Cambridge, MA 02139, USA.
+			
+The author can be contacted at:
+kreel@interfree.it
+*/
+
 #include <windows.h>
 #include <stdio.h>  // FILE *
 #include "filters.h" //CoolEdit
@@ -5,9 +26,17 @@
 #include "faac.h"
 #include "aacinfo.h"
 #include "..\..\..\faad2\common\mp4v2\mp4.h"
+#include "defines.h"
 
 
+
 #define MAX_CHANNELS 2
+#define FREE(ptr) \
+{ \
+	if(ptr) \
+		free(ptr); \
+	ptr=0; \
+}
 
 
 typedef struct input_tag // any special vars associated with input file
@@ -25,13 +54,13 @@
  MP4FileHandle	mp4File;
  MP4SampleId	sampleId, numSamples;
  int			track;
- DWORD			type;
+ BYTE			type;
 
-// GENERAL
+// GLOBAL
  faacDecHandle	hDecoder;
  faadAACInfo	file_info;
  __int32		len_ms;
- WORD			wChannels;
+ BYTE			wChannels;
  DWORD			dwSamprate;
  WORD			wBitsPerSample;
  char			szName[256];
@@ -62,18 +91,18 @@
 
 int id3v2_tag(unsigned char *buffer)
 {
- if(StringComp((const char *)buffer, "ID3", 3) == 0) 
- {
-unsigned long tagsize;
+	if(StringComp((const char *)buffer, "ID3", 3) == 0) 
+	{
+		unsigned long tagsize;
+		
+		// high bit is not used 
+		tagsize=(buffer[6] << 21) | (buffer[7] << 14) |
+			(buffer[8] <<  7) | (buffer[9] <<  0);
+		tagsize += 10;
+		return tagsize;
+	}
 
-// high bit is not used 
-  tagsize=(buffer[6] << 21) | (buffer[7] << 14) |
-          (buffer[8] <<  7) | (buffer[9] <<  0);
-  tagsize += 10;
-  return tagsize;
- }
- else 
-  return 0;
+	return 0;
 }
 
 int GetAACTrack(MP4FileHandle infile)
@@ -80,26 +109,26 @@
 {
     /* find AAC track */
     int i, rc;
-	int numTracks = MP4GetNumberOfTracks(infile, NULL);
+	int numTracks = MP4GetNumberOfTracks(infile, NULL, 0);
 
 	for (i = 0; i < numTracks; i++)
     {
-        MP4TrackId trackId = MP4FindTrackId(infile, i, NULL);
+        MP4TrackId trackId = MP4FindTrackId(infile, i, NULL, 0);
         const char* trackType = MP4GetTrackType(infile, trackId);
 
         if (!strcmp(trackType, MP4_AUDIO_TRACK_TYPE))
         {
             unsigned char *buff = NULL;
-            unsigned __int32 buff_size = 0;
-			DWORD dummy1_32;
-			BYTE dummy2_8, dummy3_8, dummy4_8, dummy5_8, dummy6_8,
+            int buff_size = 0;
+            unsigned char dummy2_8, dummy3_8, dummy4_8, dummy5_8, dummy6_8,
                 dummy7_8, dummy8_8;
+            unsigned int dummy1_32;
             MP4GetTrackESConfiguration(infile, trackId, &buff, &buff_size);
 
             if (buff)
             {
-                rc = AudioSpecificConfig(buff, &dummy1_32, &dummy2_8, &dummy3_8,
-                    &dummy4_8, &dummy5_8, &dummy6_8, &dummy7_8, &dummy8_8);
+                rc = AudioSpecificConfig(buff, &dummy1_32, &dummy2_8, &dummy3_8, &dummy4_8,
+                    &dummy5_8, &dummy6_8, &dummy7_8, &dummy8_8);
                 free(buff);
 
                 if (rc < 0)
@@ -114,7 +143,6 @@
 }
 
 
-
 // *********************************************************************************************
 
 
@@ -122,11 +150,12 @@
 __declspec(dllexport) BOOL FAR PASCAL FilterUnderstandsFormat(LPSTR filename)
 {
 WORD len;
- if((len=lstrlen(filename))>4 && 
-	(!strcmpi(filename+len-4,".aac") ||
-	 !strcmpi(filename+len-4,".mp4")))
-  return TRUE;
- return FALSE;
+
+	if((len=lstrlen(filename))>4 && 
+		(!strcmpi(filename+len-4,".aac") ||
+		!strcmpi(filename+len-4,".mp4")))
+		return TRUE;
+	return FALSE;
 }
 // *********************************************************************************************
 
@@ -134,75 +163,84 @@
 {
 DWORD full_size;
 
- if(hInput)  
- {
- MYINPUT *mi;
-  mi=(MYINPUT *)GlobalLock(hInput);
-  full_size=mi->full_size;
+	if(hInput)  
+	{
+		MYINPUT *mi;
+		mi=(MYINPUT *)GlobalLock(hInput);
+		full_size=mi->full_size;
+		
+		GlobalUnlock(hInput);
+	}
 
-  GlobalUnlock(hInput);
- }
-
- return full_size;
+	return full_size;
 }
 // *********************************************************************************************
 
 __declspec(dllexport) DWORD FAR PASCAL FilterOptionsString(HANDLE hInput, LPSTR szString)
 {
-char buf[20];
-
- if(hInput)
- {
- MYINPUT *mi;
-  mi=(MYINPUT *)GlobalLock(hInput);
- 
-  lstrcpy(szString,"");
-
-  if(mi->file_info.version == 2)
-   lstrcat(szString,"MPEG2 - ");
-  else
-   lstrcat(szString,"MPEG4 - ");
- 
-  sprintf(buf,"%lu bps\n",mi->file_info.bitrate);
-  lstrcat(szString,buf);
- 
-  if(mi->IsAAC)  // AAC file --------------------------------------------------------------------
-  {
-	switch(mi->file_info.headertype)
+	if(!hInput)
 	{
-	case 0:
-		lstrcat(szString,"RAW\n");
-		return 0L;
-	case 1:
-		lstrcat(szString,"ADIF\n");
-		break;
-	case 2:
-		lstrcat(szString,"ADTS\n");
-		break;
+		lstrcpy(szString,"");
+		return 0;
 	}
 
-	switch(mi->file_info.object_type)
+char buf[20];
+MYINPUT *mi;
+
+mi=(MYINPUT *)GlobalLock(hInput);
+	
+	lstrcpy(szString,"");
+	
+	if(mi->file_info.version == 2)
+		lstrcat(szString,"MPEG2 - ");
+	else
+		lstrcat(szString,"MPEG4 - ");
+	
+	sprintf(buf,"%lu bps\n",mi->file_info.bitrate);
+	lstrcat(szString,buf);
+	
+	if(mi->IsAAC)  // AAC file --------------------------------------------------------------------
 	{
-	case MAIN:
-		lstrcat(szString,"Main");
-		break;
-	case LOW:
-		lstrcat(szString,"Low Complexity");
-		break;
-	case SSR:
-		lstrcat(szString,"SSR (unsupported)");
-		break;
-	case LTP:
-		lstrcat(szString,"Main LTP");
-		break;
+		switch(mi->file_info.headertype)
+		{
+		case 0:
+			lstrcat(szString,"RAW\n");
+			return 0L;
+		case 1:
+			lstrcat(szString,"ADIF\n");
+			break;
+		case 2:
+			lstrcat(szString,"ADTS\n");
+			break;
+		}
+		
+		switch(mi->file_info.object_type)
+		{
+		case MAIN:
+			lstrcat(szString,"Main");
+			break;
+		case LOW:
+			lstrcat(szString,"Low Complexity");
+			break;
+		case SSR:
+			lstrcat(szString,"SSR (unsupported)");
+			break;
+		case LTP:
+			lstrcat(szString,"Main LTP");
+			break;
+		}
 	}
-  }
-  else  // MP4 file -----------------------------------------------------------------------------
-	lstrcat(szString,mpeg4AudioNames[mi->type]);
+	else  // MP4 file -----------------------------------------------------------------------------
+    {
+        if (mi->type > 16)
+            lstrcat(szString,"Type not known");
+        else
+            lstrcat(szString,mpeg4AudioNames[mi->type]);
+    }
+	
+	GlobalUnlock(hInput);
 
-  GlobalUnlock(hInput);
- }
- return 1;
+	return 1;
 }
 // *********************************************************************************************
 
@@ -209,7 +247,7 @@
 __declspec(dllexport) DWORD FAR PASCAL FilterGetFirstSpecialData(HANDLE hInput, 
 	SPECIALDATA * psp)
 {
-return 0L;
+	return 0L;
 }
 // *********************************************************************************************
     
@@ -222,28 +260,28 @@
 
 __declspec(dllexport) void FAR PASCAL CloseFilterInput(HANDLE hInput)
 {
- if(hInput)
- {
- MYINPUT far *mi;
-	mi=(MYINPUT far *)GlobalLock(hInput);
+	if(!hInput)
+		return;
 
+MYINPUT far *mi;
+
+	mi=(MYINPUT far *)GlobalLock(hInput);
+	
 // AAC file ---------------------------------------------------------------------
 	if(mi->aacFile)
 		fclose(mi->aacFile);
-  
-	if(mi->buffer)
-		free(mi->buffer);
-
+	
+	FREE(mi->buffer);
+	
 // MP4 file ---------------------------------------------------------------------
 	if(mi->mp4File)
 		MP4Close(mi->mp4File);
-
+	
 	if(mi->hDecoder)
 		faacDecClose(mi->hDecoder);
-
+	
 	GlobalUnlock(hInput);
 	GlobalFree(hInput);
- }
 }
 // *********************************************************************************************
 
@@ -250,7 +288,7 @@
 #define ERROR_OFI(msg) \
 { \
 	if(msg) \
-		MessageBox(0, msg, "FAAD plugin", MB_OK); \
+		MessageBox(0, msg, APP_NAME " plugin", MB_OK); \
 	if(hInput) \
 	{ \
 		GlobalUnlock(hInput); \
@@ -265,7 +303,8 @@
 HANDLE					hInput;
 MYINPUT					*mi;
 faacDecConfigurationPtr	config;
-DWORD					samplerate, channels;
+DWORD					samplerate;
+BYTE channels;
 DWORD					tmp;
 BYTE					BitsPerSample=16;
 
@@ -283,7 +322,8 @@
 	MP4Duration			length;
 	int					track;
 	unsigned __int32	buffer_size;
-	unsigned long		timeScale, sf;
+	unsigned long		timeScale;
+    BYTE sf;
     BYTE dummy1, dummy2, dummy3, dummy4;
 
 		if(!(mi->mp4File = MP4Read(lpstrFilename, 0)))
@@ -301,14 +341,18 @@
 	    if(!mi->buffer)
 			ERROR_OFI("MP4GetTrackESConfiguration");
 
-		AudioSpecificConfig(mi->buffer, &timeScale, &channels, &sf, &mi->type, &dummy1,
-            &dummy2, &dummy3, &dummy4);
-		if(memcmp(mpeg4AudioNames[mi->type],"AAC",3))
-			ERROR_OFI(0);
+		AudioSpecificConfig(mi->buffer, &timeScale, &channels, &sf, &mi->type, &dummy1, &dummy2,
+            &dummy3, &dummy4);
+        if (mi->type <= 16)
+        {
+            if(memcmp(mpeg4AudioNames[mi->type],"AAC",3))
+                ERROR_OFI(0);
+        } else
+            ERROR_OFI(0);
 		if(faacDecInit2(mi->hDecoder, mi->buffer, buffer_size, &samplerate, &channels) < 0)
 			ERROR_OFI("Error initializing decoder library");
 
-	    free(mi->buffer);
+	    FREE(mi->buffer);
 
 		length = MP4GetTrackDuration(mi->mp4File, track);
 		mi->len_ms=(DWORD) MP4ConvertFromTrackDuration(mi->mp4File, track, length, MP4_MSECS_TIME_SCALE);
@@ -377,7 +421,7 @@
 		{
 			if(get_AAC_format(lpstrFilename, &(mi->file_info), seek_table)<0)
 				ERROR_OFI("Error retrieving information form input file");
-			free(seek_table);
+			FREE(seek_table);
 		}
 		if(mi->file_info.headertype==0)
 		{
@@ -437,7 +481,7 @@
 #define ERROR_RFI(msg) \
 { \
 	if(msg) \
-		MessageBox(0, msg, "FAAD plugin", MB_OK); \
+		MessageBox(0, msg, APP_NAME " plugin", MB_OK); \
 	if(hInput) \
 		GlobalUnlock(hInput); \
 	return 0; \
@@ -445,6 +489,9 @@
 
 __declspec(dllexport) DWORD FAR PASCAL ReadFilterInput(HANDLE hInput, unsigned char far *bufout, long lBytes)
 {
+	if(!hInput)
+		ERROR_RFI("Memory allocation error: hInput");
+
 DWORD				read,
 					tmp,
 					shorts_decoded=0;
@@ -453,8 +500,6 @@
 char				*sample_buffer=0;
 MYINPUT				*mi;
 
-	if(!hInput)
-		ERROR_RFI("Memory allocation error: hInput");
 	mi=(MYINPUT *)GlobalLock(hInput);
 
 	if(!mi->IsAAC) // MP4 file --------------------------------------------------------------------------
@@ -471,7 +516,7 @@
 			rc=MP4ReadSample(mi->mp4File, mi->track, mi->sampleId++, &buffer, &buffer_size, NULL, NULL, NULL, NULL);
 			if(rc==0 || buffer==NULL)
 			{
-				if(buffer) free(buffer);
+				FREE(buffer);
 				ERROR_RFI("MP4ReadSample")
 			}
 
@@ -478,7 +523,7 @@
 			sample_buffer=(char *)faacDecDecode(mi->hDecoder,&frameInfo,buffer);
 			shorts_decoded=frameInfo.samples*sizeof(short);
 			memcpy(bufout,sample_buffer,shorts_decoded);
-			if (buffer) free(buffer);
+			FREE(buffer);
 		}while(!shorts_decoded && !frameInfo.error);
 	}
 	else // AAC file --------------------------------------------------------------------------
binary files a/plugins/cooledit/Logo.bmp /dev/null differ
--- a/plugins/cooledit/Main.cpp
+++ b/plugins/cooledit/Main.cpp
@@ -1,5 +1,27 @@
+/*
+FAAD - codec plugin for Cooledit
+Copyright (C) 2002 Antonio Foranna
+
+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.
+	
+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., 675 Mass Ave, Cambridge, MA 02139, USA.
+			
+The author can be contacted at:
+kreel@interfree.it
+*/
+
 #include <windows.h>
 #include "filters.h" //CoolEdit
+#include "defines.h"
 
 
 
@@ -60,11 +82,10 @@
 }
 
 // Fill COOLQUERY structure with information regarding this file filter
-
 __declspec(dllexport) short FAR PASCAL QueryCoolFilter(COOLQUERY far * cq)
 {
-	lstrcpy(cq->szName,"MPEG4-AAC Format");		
-	lstrcpy(cq->szCopyright,"Freeware AAC-MPEG4 codec");
+	lstrcpy(cq->szName, APP_NAME " Format");		
+	lstrcpy(cq->szCopyright, APP_NAME " codec");
 	lstrcpy(cq->szExt,"AAC");
 	lstrcpy(cq->szExt2,"MP4"); 
 	cq->lChunkSize=16384; 
--- a/plugins/cooledit/Readme.txt
+++ b/plugins/cooledit/Readme.txt
@@ -1,11 +1,28 @@
-Cooledit plugin by Antonio Foranna
-This plugin is free software and is released WITHOUT ANY WARRANTY;
-you can redistribute it and/or modify it freely.
++-----------------------------------------------------------------+
+|                                                                 |
+|                            FAAD Readme                          |
+|                            -----------                          |
+|                                                                 |
++-----------------------------------------------------------------+
 
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY.
+
+----------------------------------------------------------------------------
+
+FAAD is a codec plugin for Cooledit
+to import .aac/.mp4 files and to export in AAC format.
+
 To use it:
+----------
 
 In visual studio set "Active Configuration = FAAD - win32 Release" and compile,
 copy FAAC.flt into CoolEdit folder
 delete flt.dat
 
-mail: kreel@interfree.it
+----------------------------------------------------------------------------
+
+For suggestions, bugs report, etc., you can contact me at
+kreel@interfree.it
--- a/plugins/cooledit/Registry.cpp
+++ /dev/null
@@ -1,75 +1,0 @@
-//#include "stdafx.h"
-#include <windows.h>
-//#include <memory.h>
-#include "Registry.h"
-
-registryClass::registryClass()
-{
-	regKey=NULL;
-	path=NULL;
-}
-
-registryClass::~registryClass()
-{
-	if(regKey)
-		RegCloseKey(regKey);
-	if(path)
-		delete path;
-}
-
-#define setPath(SubKey) \
-	if(path) \
-		delete path; \
-	path=strdup(SubKey);
-
-// *****************************************************************************
-
-BOOL registryClass::openCreateReg(HKEY hKey, char *SubKey)
-{
-	if(regKey)
-		RegCloseKey(regKey);
-	if(RegOpenKeyEx(hKey, SubKey, NULL , KEY_ALL_ACCESS , &regKey)==ERROR_SUCCESS)
-	{
-		setPath(SubKey);
-		return TRUE;
-	}
-	else // open failed -> create the key
-	{
-	DWORD disp;
-		RegCreateKeyEx(hKey , SubKey, NULL , NULL, REG_OPTION_NON_VOLATILE , KEY_ALL_ACCESS , NULL , &regKey , &disp );
-		if(disp==REG_CREATED_NEW_KEY) 
-		{
-			setPath(SubKey);
-			return TRUE;
-		}
-		else
-		{
-			setPath("");
-			return FALSE;
-		}
-	}
-}
-// *****************************************************************************
-
-void registryClass::setRegDword(char *keyStr , DWORD val)
-{
-DWORD tempVal;
-DWORD len;
-	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS ||
-		tempVal!=val)
-		RegSetValueEx(regKey , keyStr , NULL , REG_DWORD , (BYTE *)&val , sizeof(DWORD));
-}
-// *****************************************************************************
-
-DWORD registryClass::getSetRegDword(char *keyStr, DWORD val)
-{
-DWORD tempVal;
-DWORD len=sizeof(DWORD);
-
-	if(RegQueryValueEx(regKey , keyStr , NULL , NULL, (BYTE *)&tempVal , &len )!=ERROR_SUCCESS)
-	{
-		RegSetValueEx(regKey , keyStr , NULL , REG_DWORD , (BYTE *)&val , sizeof(DWORD));
-		return val;
-	}
-	return (DWORD)tempVal;
-}
--- a/plugins/cooledit/Registry.h
+++ /dev/null
@@ -1,17 +1,0 @@
-#ifndef registry_h
-#define registry_h
-
-class registryClass 
-{
-public:
-			registryClass();
-			~registryClass();
-
-	BOOL	openCreateReg(HKEY hKey, char *SubKey);
-	void	setRegDword(char *keyStr , DWORD val);
-	DWORD	getSetRegDword(char *keyStr, DWORD var);
-
-	HKEY	regKey;
-	char	*path;
-};
-#endif
\ No newline at end of file
binary files a/plugins/cooledit/bitmap1.bmp /dev/null differ
--- /dev/null
+++ b/plugins/cooledit/defines.h
@@ -1,0 +1,3 @@
+#define APP_NAME "MPEG4-AAC"
+#define APP_VER "v2.0 beta2"
+#define REGISTRY_PROGRAM_NAME "SOFTWARE\\4N\\CoolEdit\\AAC-MPEG4"
--- a/plugins/cooledit/faad.def
+++ b/plugins/cooledit/faad.def
@@ -14,4 +14,4 @@
 	FilterGetFirstSpecialData	@31
 	FilterGetNextSpecialData	@32
 	FilterWriteSpecialData		@33
-
+	GetSuggestedSampleType