shithub: aacenc

Download patch

ref: be63b1cdcfdb00b76238d4a854ae833f3b61b783
parent: b9415c12883a69718eae31cccda92afffc8b1e8e
author: menno <menno>
date: Mon Oct 29 05:01:31 EST 2001

Updated cooledit plugin, now working correctly with new library interface

--- a/plugins/cooledit/FAAD.DSP
+++ b/plugins/cooledit/FAAD.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" /YX /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /I "..\..\..\faad\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /G4 /MT /W3 /GX /O2 /I "../../include" /I "../../../faad/include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
 # ADD BASE MTL /nologo /D "NDEBUG" /win32
 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x409 /d "NDEBUG"
@@ -53,7 +53,8 @@
 # ADD BSC32 /nologo
 LINK32=xilink6.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /machine:I386 /nodefaultlib:"libc" /nodefaultlib:"libcd" /out:"Release\faac.flt"
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /incremental:yes /machine:I386 /out:"Release\FAAC.flt"
+# SUBTRACT LINK32 /pdb:none
 
 !ELSEIF  "$(CFG)" == "FAAD - Win32 Debug"
 
@@ -69,7 +70,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" /YX /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\include" /I "..\..\..\faad\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /G4 /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /I "../../../faad/include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
 # ADD BASE MTL /nologo /D "_DEBUG" /win32
 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x409 /d "_DEBUG"
@@ -79,8 +80,8 @@
 # ADD BSC32 /nologo
 LINK32=xilink6.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /debug /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libcd.dll" /out:"Debug\faac.flt"
-# SUBTRACT LINK32 /nodefaultlib
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"Debug\FAAC.flt"
+# SUBTRACT LINK32 /pdb:none
 
 !ENDIF 
 
@@ -125,14 +126,6 @@
 # PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
 # Begin Source File
 
-SOURCE=.\aacinfo.h
-# End Source File
-# Begin Source File
-
-SOURCE="E:\Program Files\Microsoft Visual Studio\VC98\Include\BASETSD.H"
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\include\faac.h
 # End Source File
 # Begin Source File
@@ -151,6 +144,10 @@
 # Begin Group "Resource Files"
 
 # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
+# Begin Source File
+
+SOURCE=.\bitmap1.bmp
+# End Source File
 # Begin Source File
 
 SOURCE=.\Logo.bmp
--- a/plugins/cooledit/faad.c
+++ b/plugins/cooledit/faad.c
@@ -2,6 +2,7 @@
 #include <stdio.h>  // FILE *
 #include "filters.h" //CoolEdit
 #include "faad.h"
+#include "faac.h"
 #include "aacinfo.h"
 
 
@@ -10,24 +11,22 @@
 
 typedef struct input_tag // any special vars associated with input file
 {
- FILE  *fFile;
- DWORD lSize;    
- DWORD len_ms;
- WORD  wChannels;
- DWORD dwSamprate;
- WORD  wBitsPerSample;
- char  szName[256];
+ FILE	*fFile;
+ DWORD	lSize;    
+ DWORD	len_ms;
+ WORD	wChannels;
+ DWORD	dwSamprate;
+ WORD	wBitsPerSample;
+ char	szName[256];
 
- faacDecHandle hDecoder;
- faadAACInfo   file_info;
- unsigned char *buffer;
- 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
+ faacDecHandle	hDecoder;
+ faadAACInfo	file_info;
+ unsigned char	*buffer;
+ 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
+ long	bytes_into_buffer;
 } MYINPUT;
 
 
@@ -37,7 +36,7 @@
  {
 unsigned long tagsize;
 
-/* high bit is not used */
+// high bit is not used 
   tagsize=(buffer[6] << 21) | (buffer[7] << 14) |
           (buffer[8] <<  7) | (buffer[9] <<  0);
   tagsize += 10;
@@ -73,10 +72,6 @@
  return full_size;
 }
 
-__declspec(dllexport) DWORD FAR PASCAL FilterOptions(HANDLE hInput)
-{
- return 0L;
-}	    
 
 __declspec(dllexport) DWORD FAR PASCAL FilterOptionsString(HANDLE hInput, LPSTR szString)
 {
@@ -101,7 +96,7 @@
   {
   case 0:
        lstrcat(szString,"RAW\n");
-       return 0;
+       return 0L;
   case 1:
        lstrcat(szString,"ADIF\n");
        break;
@@ -112,16 +107,16 @@
 
   switch(mi->file_info.object_type)
   {
-  case 0:
+  case MAIN:
        lstrcat(szString,"Main");
        break;
-  case 1:
+  case LOW:
        lstrcat(szString,"Low Complexity");
        break;
-  case 2:
+  case SSR:
        lstrcat(szString,"SSR (unsupported)");
        break;
-  case 3:
+  case LTP:
        lstrcat(szString,"Main LTP");
        break;
   }
@@ -174,7 +169,7 @@
 {
 HANDLE hInput;
 faacDecHandle hDecoder;
-DWORD  k,tmp;
+DWORD  tmp;
 //int    shift;
 FILE   *infile;
 DWORD  samplerate, channels;
@@ -184,6 +179,7 @@
 //faadAACInfo file_info;
 unsigned char *buffer;
 long tagsize;
+faacDecConfigurationPtr config;
 
  if(!(infile=fopen(lpstrFilename,"rb")))
   return 0;
@@ -204,7 +200,7 @@
   fseek(infile, 0, SEEK_END);
   mi->lSize=ftell(infile);
   fseek(infile, pos, SEEK_SET);
-  if(!(buffer=(unsigned char*)malloc(768*MAX_CHANNELS)))
+  if(!(buffer=(BYTE *)malloc(768*MAX_CHANNELS)))
   {
    MessageBox(0, "Memory allocation error: buffer", "FAAD interface", MB_OK);
    fclose(infile);
@@ -236,8 +232,7 @@
   tagsize=id3v2_tag(buffer);
   if(tagsize)
   {
-   for (k=0; k<(768*MAX_CHANNELS - tagsize); k++)
-   buffer[k]=buffer[k + tagsize];
+   memcpy(buffer,buffer+tagsize,768*MAX_CHANNELS - tagsize);
 
    if(mi->bytes_read+tagsize<mi->lSize)
 	tmp=tagsize;
@@ -259,8 +254,6 @@
    }
   }
   mi->tagsize=tagsize;
-  mi->bytes_Enc=tagsize;
-//  mi->bytesDec=0;
 
   hDecoder = faacDecOpen();
   if(!hDecoder)
@@ -273,6 +266,11 @@
   }
   mi->hDecoder=hDecoder;
 
+  config = faacDecGetCurrentConfiguration(hDecoder);
+//  config->defObjectType = MAIN;
+  config->defSampleRate = 44100;
+  faacDecSetConfiguration(hDecoder, config);
+
   if((mi->bytes_consumed=faacDecInit(hDecoder, buffer, &samplerate, &channels)) < 0)
   {
    MessageBox(hWnd, "Error retrieving information form input file", "FAAD interface", MB_OK);
@@ -289,18 +287,18 @@
 
   *lSamprate=samplerate;
   *wBitsPerSample=16;
-  *wChannels=channels;
+  *wChannels=(WORD)channels;
   *lChunkSize=sizeof(short)*1024*channels;
 
-  mi->wChannels=channels;
+  mi->wChannels=(WORD)channels;
   mi->dwSamprate=samplerate;
   mi->wBitsPerSample=*wBitsPerSample;
   strcpy(mi->szName,lpstrFilename);
 
-  if(seek_table=(int*)LocalAlloc(LPTR, 10800*sizeof(int)))
+  if(seek_table=(int *)malloc(sizeof(int)*10800))
   {
    get_AAC_format(mi->szName, &(mi->file_info), seek_table);
-   LocalFree(seek_table);
+   free(seek_table);
   }
   else
    if(!mi->file_info.version)
@@ -312,26 +310,11 @@
     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;
-   }
-
-  mi->len_ms=1000*(mi->lSize*8)/mi->file_info.bitrate;
+   mi->len_ms=1000*(mi->lSize*8)/mi->file_info.bitrate;
   if(mi->len_ms)
    mi->full_size=(DWORD)(mi->len_ms*((float)mi->dwSamprate/1000)*mi->wChannels*(16/8));
   else
    mi->full_size=mi->lSize; // corrupted stream?
-/*
-  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);
@@ -348,84 +331,63 @@
 
 __declspec(dllexport) DWORD FAR PASCAL ReadFilterInput(HANDLE hInput, unsigned char far *bufout, long lBytes)
 {
-DWORD read,
-      tmp,
-	  bytesDec,
-	  k;
-int   result;
+DWORD	read,
+		tmp,
+		shorts_decoded=0;
+long	result=0;
 unsigned char *buffer;
-unsigned long samples;
 
- if(hInput)
- {   
- MYINPUT *mi;
-  mi=(MYINPUT *)GlobalLock(hInput);
+	if(hInput)
+	{   
+	MYINPUT *mi;
+		mi=(MYINPUT *)GlobalLock(hInput);
 
-  buffer=mi->buffer;
+		buffer=mi->buffer;
 
-  mi->bytes_Enc+=mi->bytes_consumed;
-  if(mi->bytes_Enc>=mi->lSize)
-  {
-//   MessageBox(0, "ReadFilterInput: mi->bytesEnc>mi->lSize", "FAAD interface", MB_OK);
-   GlobalUnlock(hInput);
-   return 0;
-  }
+		do
+		{
+			if(mi->bytes_consumed>0 && mi->bytes_into_buffer>=0)
+			{
+				memcpy(buffer,buffer+mi->bytes_consumed,mi->bytes_into_buffer);
 
-  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(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);
+			}
 
-   for(k=0; k<mi->bytes_into_buffer; k++)
-    buffer[k]=buffer[k + mi->bytes_consumed];
+			if(mi->bytes_into_buffer<1)
+			{
+//				MessageBox(0, "ReadFilterInput: buffer empty", "FAAD interface", MB_OK);
+				GlobalUnlock(hInput);
+				return 0;
+			}
 
-   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;
+			result=faacDecDecode(mi->hDecoder, buffer, &(mi->bytes_consumed), (short*)bufout, &shorts_decoded);
+			mi->bytes_into_buffer-=mi->bytes_consumed;
+		}while(!shorts_decoded || result==FAAD_OK_CHUPDATE);
+
+		GlobalUnlock(hInput);
 	}
-   }
-   else
-    memset(buffer+mi->bytes_into_buffer, 0, mi->bytes_consumed);
-  }
 
-  if(!mi->bytes_into_buffer)
-  {
-//   MessageBox(0, "ReadFilterInput: buffer empty", "FAAD interface", MB_OK);
-   GlobalUnlock(hInput);
-   return 0;
-  }
-
-  result=faacDecDecode(mi->hDecoder, buffer, &(mi->bytes_consumed), (short*)bufout, &samples);
-  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;
-  }
-
-  bytesDec=sizeof(short)*1024*mi->wChannels;
-
-  GlobalUnlock(hInput);
- }
-
- return bytesDec;
+	if(result==FAAD_FATAL_ERROR || result==FAAD_ERROR)
+	{
+		MessageBox(0, "ReadFilterInput: FAAD_FATAL_ERROR or FAAD_ERROR", "FAAD interface", MB_OK);
+		GlobalUnlock(hInput);
+		return 0;
+	}
+/*    if(shorts_decoded>1024*MAX_CHANNELS)
+		return 0;*/
+	return shorts_decoded*sizeof(short);
 }
--- a/plugins/cooledit/faad.def
+++ b/plugins/cooledit/faad.def
@@ -12,7 +12,6 @@
 				ReadFilterInput    @8
                 FilterUnderstandsFormat @9
 				FilterGetOptions		@14 
-				FilterOptions			@15
 				FilterGetFileSize		@16
 				FilterOptionsString		@17
 				DIALOGMsgProc 			@20
--- a/plugins/cooledit/faad.dsw
+++ b/plugins/cooledit/faad.dsw
@@ -12,6 +12,9 @@
 Package=<4>
 {{{
     Begin Project Dependency
+    Project_Dep_Name id3lib
+    End Project Dependency
+    Begin Project Dependency
     Project_Dep_Name libfaad
     End Project Dependency
     Begin Project Dependency
@@ -21,7 +24,7 @@
 
 ###############################################################################
 
-Project: "libfaac"=..\libfaac\libfaac.dsp - Package Owner=<4>
+Project: "id3lib"=..\common\id3lib\prj\id3lib.dsp - Package Owner=<4>
 
 Package=<5>
 {{{
@@ -33,7 +36,19 @@
 
 ###############################################################################
 
-Project: "libfaad"=..\..\faad\libfaad\libfaad.dsp - Package Owner=<4>
+Project: "libfaac"=..\..\faac\libfaac\libfaac.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "libfaad"=..\libfaad\libfaad.dsp - Package Owner=<4>
 
 Package=<5>
 {{{
--