shithub: aacenc

Download patch

ref: 56a143b9e40f3cd419b30b12b00346efe47b25ad
parent: b691654525bcadb8474734fd421943a8708d4c84
author: menno <menno>
date: Thu Jul 12 15:44:11 EDT 2001

Major bugfixes to Cooledit filter
encoding now works

--- a/cooledit/FAAD.rc
+++ b/cooledit/FAAD.rc
@@ -26,45 +26,42 @@
 // Dialog
 //
 
-IDD_COMPRESSION DIALOG DISCARDABLE  0, 0, 199, 118
+IDD_COMPRESSION DIALOG DISCARDABLE  0, 0, 150, 127
 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
-CAPTION "AAC-MPEG4 Format"
+CAPTION "AAC-MPEG4"
 FONT 8, "MS Sans Serif"
 BEGIN
-    DEFPUSHBUTTON   "OK",IDOK,124,99,36,14
-    PUSHBUTTON      "Cancel",IDCANCEL,159,99,36,14
-    COMBOBOX        IDC_CB_BANDWIDTH,147,73,48,30,CBS_DROPDOWN | WS_VSCROLL | 
-                    WS_TABSTOP
+    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
+    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,
+                    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",
-                    BS_AUTOCHECKBOX | WS_TABSTOP,111,7,63,10
+                    BS_AUTOCHECKBOX | WS_TABSTOP,59,21,63,10
     CONTROL         "Use TNS",IDC_USETNS,"Button",BS_AUTOCHECKBOX | 
-                    WS_TABSTOP,111,19,45,10
+                    WS_TABSTOP,59,33,45,10
     CONTROL         "Use LFE channel",IDC_USELFE,"Button",BS_AUTOCHECKBOX | 
-                    WS_DISABLED | WS_TABSTOP,111,32,67,10
-    CONTROL         "MPEG4",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON | 
-                    WS_GROUP,61,16,42,10
-    CONTROL         "MPEG2",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,61,29,41,
-                    9
-    CONTROL         "RAW",IDC_RADIO7,"Button",BS_AUTORADIOBUTTON | 
-                    WS_DISABLED | WS_GROUP,8,16,33,10
-    CONTROL         "ADIF",IDC_RADIO8,"Button",BS_AUTORADIOBUTTON | 
-                    WS_DISABLED,8,27,32,10
-    CONTROL         "ADTS",IDC_RADIO9,"Button",BS_AUTORADIOBUTTON | 
-                    WS_DISABLED,8,39,31,10
-    CONTROL         "Main",IDC_RADIO3,"Button",BS_AUTORADIOBUTTON | WS_GROUP,
-                    12,63,31,10
-    CONTROL         "Low",IDC_RADIO4,"Button",BS_AUTORADIOBUTTON,12,73,29,10
-    CONTROL         "SSR",IDC_RADIO5,"Button",BS_AUTORADIOBUTTON | 
-                    WS_DISABLED,60,63,31,10
-    CONTROL         "LTP",IDC_RADIO6,"Button",BS_AUTORADIOBUTTON,60,73,29,10
-    LTEXT           "Bitrate",IDC_STATIC,109,61,21,8
-    LTEXT           "Bandwidth",IDC_STATIC,109,78,34,8
-    GROUPBOX        "AAC type",IDC_STATIC,57,4,48,49
-    GROUPBOX        "Header",IDC_STATIC,4,4,48,49
-    GROUPBOX        "Profile",IDC_STATIC,4,55,101,31
-    COMBOBOX        IDC_CB_BITRATE,147,56,48,30,CBS_DROPDOWN | WS_VSCROLL | 
+                    WS_DISABLED | WS_TABSTOP,59,46,67,10
+    COMBOBOX        IDC_CB_BITRATE,98,59,48,30,CBS_DROPDOWN | WS_VSCROLL | 
                     WS_TABSTOP
-    CONTROL         104,IDC_STATIC,"Static",SS_BITMAP,4,90,36,23
+    COMBOBOX        IDC_CB_BANDWIDTH,98,76,48,30,CBS_DROPDOWN | WS_VSCROLL | 
+                    WS_TABSTOP
+    DEFPUSHBUTTON   "OK",IDOK,110,94,36,14
+    PUSHBUTTON      "Cancel",IDCANCEL,110,108,36,14
+    GROUPBOX        "AAC type",IDC_STATIC,4,18,48,38
+    GROUPBOX        "Profile",IDC_STATIC,4,63,48,59
+    LTEXT           "Bitrate",IDC_STATIC,59,64,21,8
+    LTEXT           "Bandwidth",IDC_STATIC,59,80,34,8
+    CONTROL         104,IDC_STATIC,"Static",SS_BITMAP,58,99,36,23
+    CONTROL         "Automatic configuration",IDC_CHK_AUTOCFG,"Button",
+                    BS_AUTOCHECKBOX | WS_TABSTOP,4,4,90,10
 END
 
 
@@ -105,9 +102,9 @@
     IDD_COMPRESSION, DIALOG
     BEGIN
         LEFTMARGIN, 4
-        RIGHTMARGIN, 195
+        RIGHTMARGIN, 146
         TOPMARGIN, 4
-        BOTTOMMARGIN, 113
+        BOTTOMMARGIN, 122
     END
 END
 #endif    // APSTUDIO_INVOKED
--- /dev/null
+++ b/cooledit/Readme.txt
@@ -1,0 +1,6 @@
+Set Active Configuration = FAAD - win32 Release,
+compile,
+copy FAAC.flt into CoolEdit folder
+delete flt.dat
+
+my e-mail: kreel@interfree.it
--- a/cooledit/faac.c
+++ b/cooledit/faac.c
@@ -1,51 +1,187 @@
 #include <windows.h>
-#include <stdio.h>  // for FILE *
+#include <stdio.h>  // FILE *
 #include "filters.h" //CoolEdit
 #include "resource.h"
-#include <faac.h>
+#include "faac.h"
 
-static faacEncHandle hEncoder;
-faacEncConfiguration faacEncCfg;
 
 typedef struct output_tag  // any special vars associated with output file
 {
- FILE *fFile;         
- long lSize;
- long lSamprate;
- WORD wBitsPerSample;
- WORD wChannels;
+ FILE  *fFile;         
+ 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;
- BOOL bStopEnc;
+ long  samplesInput;
+ BOOL  bStopEnc;
 } MYOUTPUT;
 
+
+faacEncConfiguration faacEncCfg;
+
+__declspec(dllexport) BOOL FAR PASCAL DIALOGMsgProc(HWND hWndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
+{
+ switch(Message)
+ {
+  case WM_INITDIALOG:
+       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, 11, 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, 3, 0);
+
+       CheckDlgButton(hWndDlg, IDC_ALLOWMIDSIDE, TRUE);
+       CheckDlgButton(hWndDlg, IDC_USETNS, TRUE);
+       CheckDlgButton(hWndDlg, IDC_USELFE, FALSE);
+
+	   switch((long)lParam)
+	   {
+	    case 1:
+			 CheckDlgButton(hWndDlg,IDC_RADIO_MPEG4,TRUE);
+			 break;
+		case 2:
+			 CheckDlgButton(hWndDlg,IDC_RADIO_MPEG2,TRUE);
+			 break;
+		case 3:
+			 CheckDlgButton(hWndDlg,IDC_RADIO_MAIN,TRUE);
+			 break;
+		case 4:
+			 CheckDlgButton(hWndDlg,IDC_RADIO_LOW,TRUE);
+			 break;
+		case 5:
+			 CheckDlgButton(hWndDlg,IDC_RADIO_SSR,TRUE);
+			 break;
+		case 6:
+			 CheckDlgButton(hWndDlg,IDC_RADIO_LTP,TRUE);
+			 break;
+		case 19:
+			 CheckDlgButton(hWndDlg,IDC_CHK_AUTOCFG, !IsDlgButtonChecked(hWndDlg,IDC_CHK_AUTOCFG));
+			 break;
+		default:
+			 CheckDlgButton(hWndDlg,IDC_RADIO_MPEG4,TRUE);
+			 CheckDlgButton(hWndDlg,IDC_RADIO_MAIN,TRUE);
+			 break;
+	   }         
+       break; // End of WM_INITDIALOG                                 
+
+  case WM_CLOSE:
+       // Closing the Dialog behaves the same as Cancel               
+       PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L);
+       break; // End of WM_CLOSE                                      
+
+  case WM_COMMAND:
+	   switch(LOWORD(wParam))
+       {
+	    case IDOK:
+           	 {
+			 DWORD retVal=0;
+              if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_MPEG4))
+			  {
+               faacEncCfg.mpegVersion=4;
+			   retVal|=4<<29;
+			  }
+              if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_MPEG2))
+			  {
+               faacEncCfg.mpegVersion=2;
+			   retVal|=2<<29;
+			  }
+              if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_MAIN))
+               faacEncCfg.aacObjectType=0;
+              if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_LOW))
+			  {
+               faacEncCfg.aacObjectType=1;
+			   retVal|=1<<27;
+			  }
+              if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_SSR))
+			  {
+               faacEncCfg.aacObjectType=2;
+			   retVal|=2<<27;
+			  }
+              if(IsDlgButtonChecked(hWndDlg,IDC_RADIO_LTP))
+			  {
+               faacEncCfg.aacObjectType=3;
+			   retVal|=3<<27;
+			  }
+
+              faacEncCfg.allowMidside=IsDlgButtonChecked(hWndDlg, IDC_ALLOWMIDSIDE) == BST_CHECKED ? 1 : 0;
+              retVal|=faacEncCfg.allowMidside<<26;
+              faacEncCfg.useTns=IsDlgButtonChecked(hWndDlg, IDC_USETNS) == BST_CHECKED ? 1 : 0;
+              retVal|=faacEncCfg.useTns<<25;
+              faacEncCfg.useLfe=IsDlgButtonChecked(hWndDlg, IDC_USELFE) == BST_CHECKED ? 1 : 0;
+              retVal|=faacEncCfg.useLfe<<24;
+			  
+			  faacEncCfg.bitRate=GetDlgItemInt(hWndDlg, IDC_CB_BITRATE, 0, FALSE);
+              retVal|=faacEncCfg.bitRate;
+			  faacEncCfg.bandWidth=GetDlgItemInt(hWndDlg, IDC_CB_BANDWIDTH, 0, FALSE);
+			  retVal|=(faacEncCfg.bandWidth/1000)<<16;
+             
+			  if(IsDlgButtonChecked(hWndDlg,IDC_CHK_AUTOCFG))
+			   retVal=1;
+
+			  EndDialog(hWndDlg, retVal);
+             }
+             break;
+
+        case IDCANCEL:
+             // Ignore data values entered into the controls        
+             // and dismiss the dialog window returning FALSE       
+             EndDialog(hWndDlg, FALSE);
+             break;
+       }
+       break; // End of WM_COMMAND                                 
+  default: return FALSE;
+ }
+ return TRUE;
+} // End of DIALOGSMsgProc                                      
+
 __declspec(dllexport) DWORD FAR PASCAL FilterGetOptions(HWND hWnd, HINSTANCE hInst, long lSamprate, WORD wChannels, WORD wBitsPerSample, DWORD dwOptions) // return 0 if no options box
 {
-long nDialogReturn=0L;
+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,nDialogReturn);
+ lpfnDIALOGMsgProc=GetProcAddress(hInst,(LPCSTR)MAKELONG(20,0));			
+ nDialogReturn=(long)DialogBoxParam((HINSTANCE)hInst,(LPCSTR)MAKEINTRESOURCE(IDD_COMPRESSION), (HWND)hWnd, (DLGPROC)lpfnDIALOGMsgProc,nDialogReturn);
 
-	return nDialogReturn;
+ return nDialogReturn;
 }
 
 __declspec(dllexport) DWORD FAR PASCAL FilterWriteFirstSpecialData(HANDLE hInput, 
 	SPECIALDATA * psp)
 {
-return 0L;
+ return 0;
 }
 
 __declspec(dllexport) DWORD FAR PASCAL FilterWriteNextSpecialData(HANDLE hInput, SPECIALDATA * psp)
-{	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.
+{	
+ 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.
 }
 
 __declspec(dllexport) DWORD FAR PASCAL FilterWriteSpecialData(HANDLE hOutput,
@@ -67,7 +203,8 @@
   mo->fFile=0;
  }
 
- faacEncClose(mo->hEncoder);
+ if(mo->hEncoder)
+  faacEncClose(mo->hEncoder);
 
  if(mo->bitbuf)
  {
@@ -82,40 +219,34 @@
 
 __declspec(dllexport) HANDLE FAR PASCAL OpenFilterOutput(LPSTR lpstrFilename,long lSamprate,WORD wBitsPerSample,WORD wChannels,long lSize, long far *lpChunkSize, DWORD dwOptions)
 {
-HANDLE hOutput;
-long samplesInput;
-int bytesEncoded;
+HANDLE        hOutput;
+faacEncHandle hEncoder;
+FILE          *outfile;
+unsigned char *bitbuf;
+DWORD         maxBytesOutput;
+long          samplesInput;
+int           bytesEncoded;
 
-//faacEncHandle hEncoder;
-FILE *outfile=0;
-short *pcmbuf=0;
-unsigned char *bitbuf=0;
-DWORD maxBytesOutput=0;
-
 	/* open the aac output file */
-	outfile=fopen(lpstrFilename, "wb");
-	if(!outfile)
+	if(!(outfile=fopen(lpstrFilename, "wb")))
 	{
-     MessageBox(0, lpstrFilename, "Can't create file", MB_OK);
+     MessageBox(0, "Can't create file", "FAAC interface", MB_OK);
 	 return 0;
 	}
 
 	/* open the encoder library */
-	hEncoder=faacEncOpen(lSamprate, wChannels, &samplesInput, &maxBytesOutput);
-	if(!hEncoder)
+	if(!(hEncoder=faacEncOpen(lSamprate, wChannels, &samplesInput, &maxBytesOutput)))
 	{
-	 MessageBox(0, "Can't init library", "Error", MB_OK);
+	 MessageBox(0, "Can't init library", "FAAC interface", MB_OK);
+	 fclose(outfile);
 	 return 0;
 	}
 
-	if(!(pcmbuf=(short*)malloc(samplesInput*sizeof(short))))
-	{
-	 MessageBox(0, "PCM buffer", "Memory allocation error", MB_OK);
-	 return 0;
-	}
 	if(!(bitbuf=(unsigned char*)malloc(maxBytesOutput*sizeof(unsigned char))))
 	{
-	 MessageBox(0, "Output buffer", "Memory allocation error", MB_OK);
+	 MessageBox(0, "Memory allocation error: output buffer", "FAAC interface", MB_OK);
+     faacEncClose(hEncoder);
+	 fclose(outfile);
 	 return 0;
 	}
 
@@ -135,7 +266,7 @@
 	 mo->lSamprate=lSamprate;
 	 mo->wBitsPerSample=wBitsPerSample;
 	 mo->wChannels=wChannels;
-	 mo->dwDataOffset=0; // ??
+	 mo->dwDataOffset=0; // ???
 	 mo->bWrittenHeader=0;
 	 strcpy(mo->szNAME,lpstrFilename);
 
@@ -148,10 +279,49 @@
 	 GlobalUnlock(hOutput);
     }
 	else
-	 MessageBox(0, "hOutput=NULL", "FAAC Error", MB_OK);
+	{
+	 MessageBox(0, "hOutput=NULL", "FAAC interface", MB_OK);
+     faacEncClose(hEncoder);
+	 fclose(outfile);
+	 free(bitbuf);
+	 return 0;
+	}
 
-	if(dwOptions==2)
+	if(dwOptions && dwOptions!=1)
 	{
+    faacEncConfigurationPtr myFormat;
+     myFormat=faacEncGetCurrentConfiguration(hEncoder);
+
+	 myFormat->mpegVersion=(dwOptions>>29)&7;
+	 myFormat->aacObjectType=(dwOptions>>27)&3;
+	 myFormat->allowMidside=(dwOptions>>26)&1;
+	 myFormat->useTns=(dwOptions>>25)&1;
+	 myFormat->useLfe=(dwOptions>>24)&1;
+	 myFormat->bitRate=(dwOptions&0x00ff)*1000;
+	 myFormat->bandWidth=((dwOptions>>16)&127)*1000;
+     switch(myFormat->bandWidth)
+	 {
+     case 11000:
+		  myFormat->bandWidth=11025;
+		  break;
+     case 22000:
+		  myFormat->bandWidth=22050;
+		  break;
+     case 44000:
+		  myFormat->bandWidth=44100;
+		  break;
+	 }
+
+	 if(!faacEncSetConfiguration(hEncoder, myFormat))
+	 {
+      MessageBox(0, "Unsupported parameters", "FAAC interface", MB_OK);
+      faacEncClose(hEncoder);
+	  fclose(outfile);
+	  free(bitbuf);
+      GlobalFree(hOutput);
+	  return 0;
+	 }
+/*	{
 faacEncConfigurationPtr myFormat;
      myFormat=faacEncGetCurrentConfiguration(hEncoder);
 
@@ -165,9 +335,13 @@
 
 	 if(!faacEncSetConfiguration(hEncoder, myFormat))
 	 {
-      MessageBox(0, "Unsupported parameters\n", "FAAC error", MB_OK);
+      MessageBox(0, "Unsupported parameters", "FAAC interface", MB_OK);
+      faacEncClose(hEncoder);
+	  fclose(outfile);
+	  free(bitbuf);
+      GlobalFree(hOutput);
 	  return 0;
-	 }
+	 }*/
 	}
 
     return hOutput;
@@ -177,47 +351,36 @@
 {
 int bytesWritten;
 int bytesEncoded;
-unsigned char *bitbuf;
 
  if(hOutput)
  { 
  MYOUTPUT far *mo;
-
   mo=(MYOUTPUT far *)GlobalLock(hOutput);
 
   if(!mo->bStopEnc)
   {
-   bitbuf=mo->bitbuf;
-
 // call the actual encoding routine
-   bytesEncoded=faacEncEncode(mo->hEncoder, (short *)buf, mo->samplesInput, bitbuf, mo->maxBytesOutput);
-   if(!bytesEncoded) // end of flushing process
-	mo->bStopEnc=1;
-  }
-
-  if(!bytesEncoded) // end of flushing process
-  {
-   GlobalUnlock(hOutput);
-   return 0;
-  }
-  else
-   if(bytesEncoded<0)
+   bytesEncoded=faacEncEncode(mo->hEncoder, (short *)buf, mo->samplesInput, mo->bitbuf, mo->maxBytesOutput);
+   if(bytesEncoded<1) // end of flushing process
    {
-    MessageBox(0, "faacEncEncode() failed", "Error", MB_OK);
+    if(bytesEncoded<0)
+     MessageBox(0, "faacEncEncode() failed", "FAAC interface", MB_OK);
+    mo->bStopEnc=1;
     GlobalUnlock(hOutput);
     return 0;
    }
-
 // write bitstream to aac file 
-  bytesWritten=fwrite(bitbuf, 1, bytesEncoded, mo->fFile);
+   bytesWritten=fwrite(mo->bitbuf, 1, bytesEncoded, mo->fFile);
+   if(bytesWritten!=bytesEncoded)
+   {
+    MessageBox(0, "bytesWritten and bytesEncoded are different", "FAAC interface", MB_OK);
+    mo->bStopEnc=1;
+    GlobalUnlock(hOutput);
+    return 0;
+   }
 
-  GlobalUnlock(hOutput);
- }
-
- if(bytesWritten!=bytesEncoded)
- {
-  MessageBox(0, "bytesWritten and bytesEncoded are different", "Output error", MB_OK);
-  return 0;
+   GlobalUnlock(hOutput);
+  }
  }
 
  return bytesWritten;
--- a/cooledit/faad.c
+++ b/cooledit/faad.c
@@ -1,10 +1,7 @@
 #include <windows.h>
-#include <stdlib.h>  		// for atol conversion  
-#include <stdio.h>  // for FILE *
+#include <stdio.h>  // FILE *
 #include "filters.h" //CoolEdit
-#include "resource.h"
-
-#include <faad.h>
+#include "faad.h"
 #include "aacinfo.h"
 
 
@@ -11,40 +8,27 @@
 #define MAX_CHANNELS 2
 
 
-faacDecHandle hDecoder;
-
 typedef struct input_tag // any special vars associated with input file
 {
  FILE  *fFile;
- long  lSize;    
- DWORD dwFormat;  
+ DWORD lSize;    
  WORD  wChannels;
  DWORD dwSamprate;
  WORD  wBitsPerSample;
- DWORD dwDataOffset;		   
  char  szName[256];
 
  faacDecHandle hDecoder;
- faadAACInfo file_info;
+ faadAACInfo   file_info;
  unsigned char *buffer;
- FILE  *infile;
- long  file_len, tagsize, buffercount, fileread, bytecount;
- char  supported;
- DWORD full_size;
- DWORD bytes_left;
+ 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;
+//	   bytesDec; // Not used because I prefer decode until possible and not until file_info.lenght
 } MYINPUT;
 
-/*
-static FILE   *infile;
-static char Filename[1024];
-static faadAACInfo file_info;
-static long file_len;
-static char supported;
-DWORD   samplerate, channels;
-DWORD full_size;
-*/
-static long tagsize, buffercount, fileread, bytecount, bytesFull;
-//BYTE buffer[768*MAX_CHANNELS];
 
 int id3v2_tag(unsigned char *buffer)
 {
@@ -75,7 +59,6 @@
 __declspec(dllexport) long FAR PASCAL FilterGetFileSize(HANDLE hInput)
 {
 DWORD full_size;
-//DWORD pos;
 
  if(hInput)  
  {
@@ -82,32 +65,16 @@
  MYINPUT *mi;
   mi=(MYINPUT *)GlobalLock(hInput);
   full_size=mi->full_size;
- 
-/*	pos=ftell(mi->fFile);
-	fseek(mi->fFile, 0, SEEK_END);
-	fileread=ftell(mi->fFile);
-	fseek(mi->fFile, pos, SEEK_SET);*/
+
   GlobalUnlock(hInput);
  }
 
- return full_size; //file_len;
+ return full_size;
 }
 
 __declspec(dllexport) DWORD FAR PASCAL FilterOptions(HANDLE hInput)
 {
-	return 0L;
-/*	MYINPUT far *mi;
-	DWORD options;
-	if (!hInput) return 0;
-	mi=(MYINPUT far *)GlobalLock(hInput);
-    
-    options=(DWORD)mi->dwFormat;
-    if (options==3)
-    	options=2;
-    
-    GlobalUnlock(hInput);
-     
-    return options;*/
+ return 0L;
 }	    
 
 __declspec(dllexport) DWORD FAR PASCAL FilterOptionsString(HANDLE hInput, LPSTR szString)
@@ -131,32 +98,31 @@
  
   switch(mi->file_info.headertype)
   {
-  case 0: // Headerless 
-     lstrcat(szString,"RAW\n");
-     return 0;
-     break;
+  case 0:
+       lstrcat(szString,"RAW\n");
+       return 0;
   case 1:
-     lstrcat(szString,"ADIF\n");
-     break;
+       lstrcat(szString,"ADIF\n");
+       break;
   case 2:
-     lstrcat(szString,"ADTS\n");
-     break;
+       lstrcat(szString,"ADTS\n");
+       break;
   }
 
   switch(mi->file_info.object_type)
   {
   case 0:
-     lstrcat(szString,"Main");
-     break;
+       lstrcat(szString,"Main");
+       break;
   case 1:
-     lstrcat(szString,"Low Complexity");
-     break;
+       lstrcat(szString,"Low Complexity");
+       break;
   case 2:
-     lstrcat(szString,"SSR (unsupported)");
-     break;
+       lstrcat(szString,"SSR (unsupported)");
+       break;
   case 3:
-     lstrcat(szString,"Main LTP");
-     break;
+       lstrcat(szString,"Main LTP");
+       break;
   }
 
   GlobalUnlock(hInput);
@@ -184,11 +150,14 @@
   mi=(MYINPUT far *)GlobalLock(hInput);
 
   if(mi->fFile)
-  {
    fclose(mi->fFile);
-   mi->fFile=0;
-  }
   
+  if(mi->buffer)
+   free(mi->buffer);
+
+  if(mi->hDecoder)
+   faacDecClose(mi->hDecoder);
+
   GlobalUnlock(hInput);
   GlobalFree(hInput);
  }
@@ -203,37 +172,41 @@
 											long far *lChunkSize)
 {
 HANDLE hInput;
-DWORD  k;
+faacDecHandle hDecoder;
+DWORD  k,tmp;
 int    shift;
 FILE   *infile;
 DWORD  samplerate, channels;
-DWORD  pos;
+DWORD  pos; // into the file. Needed to obtain length of file
+DWORD  read;
 int    *seek_table;
 faadAACInfo file_info;
 unsigned char *buffer;
+long tagsize;
 
+ if(!(infile=fopen(lpstrFilename,"rb")))
+  return 0;
+
  hInput=GlobalAlloc(GMEM_MOVEABLE|GMEM_SHARE|GMEM_ZEROINIT,sizeof(MYINPUT));
- if(hInput)
+ if(!hInput)
+ {
+  fclose(infile);
+  return 0;
+ }
+ else
  {   
  MYINPUT *mi;
   mi=(MYINPUT *)GlobalLock(hInput);
 
-  if(!(infile=fopen(lpstrFilename,"rb")))
-  {
-   GlobalUnlock(hInput);
-   return 0;
-  }
-
   mi->fFile=infile;
-
   pos=ftell(infile);
   fseek(infile, 0, SEEK_END);
   mi->lSize=ftell(infile);
   fseek(infile, pos, SEEK_SET);
-
   if(!(buffer=(unsigned char*)malloc(768*MAX_CHANNELS)))
   {
-   MessageBox(0, "buffer", "Memory allocation error", MB_OK);
+   MessageBox(0, "Memory allocation error: buffer", "FAAD interface", MB_OK);
+   fclose(infile);
    GlobalUnlock(hInput);
    return 0;
   }
@@ -240,102 +213,140 @@
   mi->buffer=buffer;
   memset(buffer, 0, 768*MAX_CHANNELS);
 
-  buffercount=bytecount=0;
-  fread(buffer, 1, 768*MAX_CHANNELS, infile);
+  if(mi->lSize<768*MAX_CHANNELS)
+   tmp=mi->lSize;
+  else
+   tmp=768*MAX_CHANNELS;
+  read=fread(buffer, 1, tmp, infile);
+  if(read==tmp)
+  {
+   mi->bytes_read=read;
+   mi->bytes_into_buffer=read;
+  }
+  else
+  {
+   MessageBox(0, "fread", "FAAD interface", MB_OK);
+   fclose(mi->fFile);
+   free(mi->buffer);
+   GlobalUnlock(hInput);
+   return 0;
+  }
 
   tagsize=id3v2_tag(buffer);
-  mi->bytes_left=mi->lSize-tagsize;
   if(tagsize)
   {
-   bytecount = tagsize;
-   buffercount = 0;
    for (k=0; k<(768*MAX_CHANNELS - tagsize); k++)
    buffer[k]=buffer[k + tagsize];
-   shift=(768*MAX_CHANNELS)-tagsize;
-   fread(buffer+shift, 1, shift, infile);
+
+   if(mi->bytes_read+tagsize<mi->lSize)
+	tmp=tagsize;
+   else
+    tmp=mi->lSize-mi->bytes_read;
+   read=fread(buffer+mi->bytes_into_buffer, 1, tmp, mi->fFile);
+   if(read==tmp)
+   {
+    mi->bytes_read+=read;
+    mi->bytes_into_buffer+=read;
+   }
+   else
+   {
+    MessageBox(0, "fread", "FAAD interface", MB_OK);
+    fclose(mi->fFile);
+    free(mi->buffer);
+    GlobalUnlock(hInput);
+    return 0;
+   }
   }
+  mi->tagsize=tagsize;
+  mi->bytes_Enc=tagsize;
+//  mi->bytesDec=0;
 
   hDecoder = faacDecOpen();
   if(!hDecoder)
   {
-   MessageBox(0, "Can't init library", "Error", MB_OK);
+   MessageBox(0, "Can't init library", "FAAD interface", MB_OK);
+   fclose(mi->fFile);
+   free(mi->buffer);
+   GlobalUnlock(hInput);
    return 0;
   }
-  if((buffercount=faacDecInit(hDecoder, buffer, &samplerate, &channels)) < 0)
+  mi->hDecoder=hDecoder;
+
+  if((mi->bytes_consumed=faacDecInit(hDecoder, buffer, &samplerate, &channels)) < 0)
   {
-   MessageBox(hWnd, "Error retrieving information form input file", "FAAD Error", MB_OK);
+   MessageBox(hWnd, "Error retrieving information form input file", "FAAD interface", MB_OK);
+   fclose(mi->fFile);
+   free(mi->buffer);
+   faacDecClose(mi->hDecoder);
+   GlobalUnlock(hInput);
    return 0;
   }
-  // bytes will be shifted in ReadFilterInput
+  mi->bytes_into_buffer-=mi->bytes_consumed;
+// if(mi->bytes_consumed>0) 
+// faacDecInit reports there is an header to skip
+// this operation will be done in ReadFilterInput
 
   *lSamprate=samplerate;
   *wBitsPerSample=16;
   *wChannels=channels;
-  *lChunkSize=sizeof(short)*1024*channels; //16384;
+  *lChunkSize=sizeof(short)*1024*channels;
 
-  if(buffercount>0) // faacDecInit reports there is an header to skip
-  {
-//     file_len-=buffercount;
-   bytecount+=buffercount;
-   for (k=0; k<(768*MAX_CHANNELS - buffercount); k++)
-    buffer[k]=buffer[k + buffercount];
-   shift=(768*MAX_CHANNELS)-buffercount;
-   fread(buffer+shift, 1, buffercount, infile);
-   buffercount=0;
-  }
-
-  mi->dwFormat=0;
   mi->wChannels=channels;
   mi->dwSamprate=samplerate;
   mi->wBitsPerSample=*wBitsPerSample;
-  mi->dwDataOffset=0;
   strcpy(mi->szName,lpstrFilename);
 
-  mi->hDecoder=hDecoder;
-  mi->tagsize=tagsize;
-
-  file_info.version=0;
   if(seek_table=(int*)LocalAlloc(LPTR, 10800*sizeof(int)))
   {
-   get_AAC_format(mi->szName, &file_info, seek_table);
+   get_AAC_format(mi->szName, &(mi->file_info), seek_table);
    LocalFree(seek_table);
   }
   else
-   file_info.version='?';
-  memcpy(&(mi->file_info),&file_info,sizeof(file_info));
-  if(file_info.length)
-   mi->full_size=(DWORD)(file_info.length*((float)samplerate/1000)*channels*(16/8));
+   if(!mi->file_info.version)
+   {
+    fclose(mi->fFile);
+    free(mi->buffer);
+    faacDecClose(hDecoder);
+    GlobalUnlock(hInput);
+    return 0;
+   }
+
+  if(mi->file_info.object_type==2) // Unupported type SSR profile
+   {
+    fclose(mi->fFile);
+    free(mi->buffer);
+    faacDecClose(hDecoder);
+    GlobalUnlock(hInput);
+    return 0;
+   }
+
+  if(mi->file_info.length)
+   mi->full_size=(DWORD)(mi->file_info.length*((float)samplerate/1000)*channels*(16/8));
   else
-  {
+   mi->full_size=mi->lSize; // corrupted stream?
+/*  {
+   fclose(mi->fFile);
+   free(mi->buffer);
+   faacDecClose(hDecoder);
    GlobalUnlock(hInput);
    return 0;
-  }
+  }*/
 
-  if(file_info.object_type==2)
-   mi->supported=0;
-  else
-   mi->supported=1;
-
   GlobalUnlock(hInput);
  }
 
- bytesFull=0;
-
  return hInput;
 }
 
 __declspec(dllexport) DWORD FAR PASCAL ReadFilterInput(HANDLE hInput, unsigned char far *bufout, long lBytes)
 {
-DWORD read=0,
-      bytesconsumed,
-      bytestot=0,
+DWORD read,
+      tmp,
+	  bytesDec,
 	  k;
 int   result;
 unsigned char *buffer;
 
-// MessageBox(0, "ReadFilterInput", "FAAD Error", MB_OK);
-
-
  if(hInput)
  {   
  MYINPUT *mi;
@@ -343,64 +354,69 @@
 
   buffer=mi->buffer;
 
-  if(!mi->supported)
+  mi->bytes_Enc+=mi->bytes_consumed;
+  if(mi->bytes_Enc>=mi->lSize)
   {
-   MessageBox(0, "ReadFilterInput: format not supported", "FAAD Error", MB_OK);
+//   MessageBox(0, "ReadFilterInput: mi->bytesEnc>mi->lSize", "FAAD interface", MB_OK);
    GlobalUnlock(hInput);
    return 0;
   }
 
-  if(mi->bytes_left<buffercount)
-   mi->bytes_left=0;
-  else
-   mi->bytes_left-=buffercount;
+  if(mi->bytes_consumed)
+  {
+/*   mi->bytesDec+=sizeof(short)*1024*mi->wChannels;
+   if(mi->bytesDec>mi->full_size+sizeof(short)*1024*mi->wChannels)
+   {
+//    MessageBox(0, "ReadFilterInput: mi->bytesDec>mi->full_size", "FAAD interface", MB_OK);
+    GlobalUnlock(hInput);
+    return 0;
+   }*/
 
-  if(bytesFull>mi->full_size)
+   for(k=0; k<mi->bytes_into_buffer; k++)
+    buffer[k]=buffer[k + mi->bytes_consumed];
+
+   if(mi->bytes_read<mi->lSize)
+   {
+    if(mi->bytes_read+mi->bytes_consumed<mi->lSize)
+	 tmp=mi->bytes_consumed;
+	else
+	 tmp=mi->lSize-mi->bytes_read;
+    read=fread(buffer+mi->bytes_into_buffer, 1, tmp, mi->fFile);
+    if(read==tmp)
+	{
+	 mi->bytes_read+=read;
+     mi->bytes_into_buffer+=read;
+	}
+   }
+   else
+    memset(buffer+mi->bytes_into_buffer, 0, mi->bytes_consumed);
+  }
+
+  if(!mi->bytes_into_buffer)
   {
-//   MessageBox(0, "ReadFilterInput: bytesFull>mi->lSize", "FAAD Error", MB_OK);
+//   MessageBox(0, "ReadFilterInput: buffer empty", "FAAD interface", MB_OK);
    GlobalUnlock(hInput);
    return 0;
   }
 
-  if(!mi->bytes_left)
+  result=faacDecDecode(mi->hDecoder, buffer, &(mi->bytes_consumed), (short*)bufout);
+  if(mi->bytes_into_buffer>mi->bytes_consumed)
+   mi->bytes_into_buffer-=mi->bytes_consumed;
+  else
+   mi->bytes_into_buffer=0;
+//  if(result>FAAD_OK_CHUPDATE)
+  if(result==FAAD_FATAL_ERROR)
   {
+//   MessageBox(0, "ReadFilterInput: FAAD_FATAL_ERROR or FAAD_ERROR", "FAAD interface", MB_OK);
+//   MessageBox(0, "ReadFilterInput: FAAD_FATAL_ERROR", "FAAD interface", MB_OK);
    GlobalUnlock(hInput);
    return 0;
   }
 
-  if(buffercount>0)
-  {
-   for(k=0; k<(768*MAX_CHANNELS - buffercount); k++)
-    buffer[k]=buffer[k + buffercount];
+  bytesDec=sizeof(short)*1024*mi->wChannels;
 
-   read=fread(buffer+(768*MAX_CHANNELS)-buffercount, buffercount, 1, mi->fFile);
-   if(!read)
-    memset(buffer+(768*MAX_CHANNELS)-buffercount, 0, buffercount);
-   buffercount=0;
-  }
-
-  result=faacDecDecode(hDecoder, buffer, &bytesconsumed, (short*)bufout);
-
-  if(result>FAAD_OK_CHUPDATE) // FAAD_FATAL_ERROR or FAAD_ERROR
-   mi->bytes_left=0;
-
-  bytestot=sizeof(short)*1024*mi->wChannels;
-  
   GlobalUnlock(hInput);
  }
-/*
- switch(result) 
- {
- case FAAD_FATAL_ERROR:
-    MessageBox(0, "Fatal error decoding input file\n", "FAAD error", MB_OK);
-    return 0;
-  case FAAD_ERROR:
-    return bytestot;
- }
-*/
- buffercount=bytesconsumed;
- bytecount+=bytesconsumed;
- bytesFull+=bytestot;
 
- return bytestot;// read;
+ return bytesDec;
 }
--- a/cooledit/faad.def
+++ b/cooledit/faad.def
@@ -1,4 +1,4 @@
-LIBRARY   Cool32*SDKAU
+LIBRARY   Cool32*FAAC
 
 HEAPSIZE  2048
 
--- a/cooledit/main.c
+++ b/cooledit/main.c
@@ -1,12 +1,7 @@
 #include <windows.h>
-#include <stdlib.h>
-#include "resource.h"
 #include "filters.h" //CoolEdit
-#include "faac.h"
 
-extern faacEncConfiguration faacEncCfg;
 
-
 BOOL WINAPI DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
 {
    switch (fdwReason)
@@ -68,16 +63,16 @@
 __declspec(dllexport) short FAR PASCAL QueryCoolFilter(COOLQUERY far * cq)
 {
 	lstrcpy(cq->szName,"MPEG4-AAC Format");		
-	lstrcpy(cq->szCopyright,"Freeware AAC-MPEG4 codec");// Compiled on: " __DATE__);
+	lstrcpy(cq->szCopyright,"Freeware AAC-MPEG4 codec");
 	lstrcpy(cq->szExt,"AAC");
 	lstrcpy(cq->szExt2,"MP4"); 
 	cq->lChunkSize=16384; 
 	cq->dwFlags=QF_RATEADJUSTABLE|QF_CANLOAD|QF_CANSAVE|QF_HASOPTIONSBOX;
- 	cq->Stereo8=0xFF; // supports all rates of stereo 8
+ 	cq->Stereo8=0xFF; // supports all rates ???
  	cq->Stereo16=0xFF;
  	cq->Stereo24=0xFF;
  	cq->Stereo32=0xFF;
- 	cq->Mono8=0xFF; // supports all rates of stereo 8
+ 	cq->Mono8=0xFF;
  	cq->Mono16=0xFF;
  	cq->Mono24=0xFF;
  	cq->Mono32=0xFF;
@@ -86,132 +81,3 @@
  	cq->Quad8=0xFF;
  	return C_VALIDLIBRARY;
 }
-
-__declspec(dllexport) BOOL FAR PASCAL DIALOGMsgProc(HWND hWndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
-{
-   switch(Message)
-   {
-   case WM_INITDIALOG:
-         {             
-          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, 11, 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, 3, 0);
-
-          CheckDlgButton(hWndDlg, IDC_ALLOWMIDSIDE, TRUE);
-          CheckDlgButton(hWndDlg, IDC_USETNS, TRUE);
-          CheckDlgButton(hWndDlg, IDC_USELFE, FALSE);
-
-	         switch((long)lParam)
-			 {
-			 case 1:
-			  CheckDlgButton(hWndDlg,IDC_RADIO1,TRUE);
-			  break;
-			 case 2:
-			  CheckDlgButton(hWndDlg,IDC_RADIO2,TRUE);
-			  break;
-			 case 3:
-			  CheckDlgButton(hWndDlg,IDC_RADIO3,TRUE);
-			  break;
-			 case 4:
-			  CheckDlgButton(hWndDlg,IDC_RADIO4,TRUE);
-			  break;
-			 case 5:
-			  CheckDlgButton(hWndDlg,IDC_RADIO5,TRUE);
-			  break;
-			 case 6:
-			  CheckDlgButton(hWndDlg,IDC_RADIO6,TRUE);
-			  break;
-			 case 7:
-			  CheckDlgButton(hWndDlg,IDC_RADIO7,TRUE);
-			  break;
-			 case 8:
-			  CheckDlgButton(hWndDlg,IDC_RADIO8,TRUE);
-			  break;
-			 case 9:
-			  CheckDlgButton(hWndDlg,IDC_RADIO9,TRUE);
-			  break;
-			 default:
-			  CheckDlgButton(hWndDlg,IDC_RADIO1,TRUE);
-			  CheckDlgButton(hWndDlg,IDC_RADIO3,TRUE);
-			  CheckDlgButton(hWndDlg,IDC_RADIO7,TRUE);
-			  break;
-	         }	         
-         }         
-         break; // End of WM_INITDIALOG                                 
-
-    case WM_CLOSE:
-         // Closing the Dialog behaves the same as Cancel               
-         PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L);
-         break; // End of WM_CLOSE                                      
-
-    case WM_COMMAND:
-	{
-		switch(LOWORD(wParam))
-        {
-		    case IDOK:
-            	 {
-				 char szTemp[10];
-            	  if(IsDlgButtonChecked(hWndDlg,IDC_RADIO1))
-            	   faacEncCfg.mpegVersion=4;
-            	  if(IsDlgButtonChecked(hWndDlg,IDC_RADIO2))
-            	   faacEncCfg.mpegVersion=2;
-            	  if(IsDlgButtonChecked(hWndDlg,IDC_RADIO3))
-            	   faacEncCfg.aacObjectType=0;
-            	  if(IsDlgButtonChecked(hWndDlg,IDC_RADIO4))
-            	   faacEncCfg.aacObjectType=1;
-            	  if(IsDlgButtonChecked(hWndDlg,IDC_RADIO5))
-            	   faacEncCfg.aacObjectType=2;
-            	  if(IsDlgButtonChecked(hWndDlg,IDC_RADIO6))
-            	   faacEncCfg.aacObjectType=3;
-/*            	  if(IsDlgButtonChecked(hWndDlg,IDC_RADIO7))
-            	   faacEncCfg=;
-            	  if(IsDlgButtonChecked(hWndDlg,IDC_RADIO8))
-            	   faacEncCfg=;
-            	  if(IsDlgButtonChecked(hWndDlg,IDC_RADIO9))
-            	   faacEncCfg=;*/
-
-                  faacEncCfg.allowMidside=IsDlgButtonChecked(hWndDlg, IDC_ALLOWMIDSIDE) == BST_CHECKED ? 1 : 0;
-                  faacEncCfg.useTns=IsDlgButtonChecked(hWndDlg, IDC_USETNS) == BST_CHECKED ? 1 : 0;
-                  faacEncCfg.useLfe=IsDlgButtonChecked(hWndDlg, IDC_USELFE) == BST_CHECKED ? 1 : 0;
-
-				  GetDlgItemText(hWndDlg, IDC_CB_BITRATE, szTemp, sizeof(szTemp));
-				  faacEncCfg.bitRate=atoi(szTemp);
-				  GetDlgItemText(hWndDlg, IDC_CB_BANDWIDTH, szTemp, sizeof(szTemp));
-				  faacEncCfg.bandWidth=atoi(szTemp);
-                  
-				  EndDialog(hWndDlg, (short)2);
-            	 }
-                 break;
-            case IDCANCEL:
-                 // Ignore data values entered into the controls        
-                 // and dismiss the dialog window returning FALSE       
-                 EndDialog(hWndDlg, FALSE);
-                 break;
-           }
-         break;    // End of WM_COMMAND                                 
-	}
-    default:
-        return FALSE;
-   }
- return TRUE;
-}//  End of DIALOGSMsgProc                                      
--- a/cooledit/resource.h
+++ b/cooledit/resource.h
@@ -5,11 +5,17 @@
 #define IDD_COMPRESSION                 101
 #define IDB_LOGO                        104
 #define IDC_RADIO1                      1000
+#define IDC_RADIO_MPEG4                 1000
 #define IDC_RADIO2                      1001
+#define IDC_RADIO_MPEG2                 1001
 #define IDC_RADIO4                      1002
+#define IDC_RADIO_LOW                   1002
 #define IDC_RADIO3                      1003
+#define IDC_RADIO_MAIN                  1003
 #define IDC_RADIO5                      1004
+#define IDC_RADIO_SSR                   1004
 #define IDC_RADIO6                      1005
+#define IDC_RADIO_LTP                   1005
 #define IDC_RADIO7                      1006
 #define IDC_RADIO8                      1007
 #define IDC_RADIO9                      1008
@@ -18,6 +24,7 @@
 #define IDC_USELFE                      1013
 #define IDC_CB_BANDWIDTH                1015
 #define IDC_CB_BITRATE                  1017
+#define IDC_CHK_AUTOCFG                 1020
 
 // Next default values for new objects
 // 
@@ -25,7 +32,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        105
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1020
+#define _APS_NEXT_CONTROL_VALUE         1021
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif