shithub: aacenc

Download patch

ref: 26f8cf583b3c3d2577c83acebf7885c1d493493f
parent: 010133517b5d362c27080b08459e14f9213727ca
author: menno <menno>
date: Mon Mar 12 15:12:37 EST 2001

Small change in API

--- a/frontend/main.c
+++ b/frontend/main.c
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: main.c,v 1.10 2001/03/06 21:02:33 menno Exp $
+ * $Id: main.c,v 1.11 2001/03/12 20:12:37 menno Exp $
  */
 
 #ifdef _WIN32
@@ -38,9 +38,6 @@
 #include "faac.h"
 
 
-#define PCMBUFSIZE 1024
-#define BITBUFSIZE 8192
-
 int main(int argc, char *argv[])
 {
 	int i, frames, currentFrame;
@@ -49,6 +46,7 @@
 	SF_INFO sfinfo;
 
 	unsigned int sr, chan;
+	unsigned long samplesInput, maxBytesOutput;
 
 	short *pcmbuf;
 
@@ -105,12 +103,12 @@
 	sr = sfinfo.samplerate;
 	chan = sfinfo.channels;
 
-	pcmbuf = (short*)malloc(PCMBUFSIZE*chan*sizeof(short));
-	bitbuf = (unsigned char*)malloc(BITBUFSIZE*sizeof(unsigned char));
-
 	/* open the encoder library */
-	hEncoder = faacEncOpen(sr, chan);
+	hEncoder = faacEncOpen(sr, chan, &samplesInput, &maxBytesOutput);
 
+	pcmbuf = (short*)malloc(samplesInput*sizeof(short));
+	bitbuf = (unsigned char*)malloc(maxBytesOutput*sizeof(unsigned char));
+
 	/* set other options */
 	if (argc > 3)
 	{
@@ -177,7 +175,7 @@
 
 			currentFrame++;
 
-			bytesInput = sf_read_short(infile, pcmbuf, chan*PCMBUFSIZE) * sizeof(short);
+			bytesInput = sf_read_short(infile, pcmbuf, samplesInput) * sizeof(short);
 
 			/* call the actual encoding routine */
 			bytesWritten = faacEncEncode(hEncoder,
@@ -184,7 +182,7 @@
 				pcmbuf,
 				bytesInput/2,
 				bitbuf,
-				BITBUFSIZE);
+				maxBytesOutput);
 
 #ifndef _DEBUG
 			printf("%.2f%%\tBusy encoding %s.\r",
--- a/frontend/maingui.c
+++ b/frontend/maingui.c
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: maingui.c,v 1.11 2001/03/12 16:58:36 menno Exp $
+ * $Id: maingui.c,v 1.12 2001/03/12 20:12:37 menno Exp $
  */
 
 #include <windows.h>
@@ -29,8 +29,6 @@
 #include "faac.h"
 #include "resource.h"
 
-#define PCMBUFSIZE 1024
-#define BITBUFSIZE 8192
 
 static HINSTANCE hInstance;
 
@@ -141,8 +139,13 @@
 		unsigned int sampleRate = sfinfo.samplerate;
 		unsigned int numChannels = sfinfo.channels;
 
+		unsigned long inputSamples;
+		unsigned long maxOutputBytes;
+
 		/* open and setup the encoder */
-		faacEncHandle hEncoder = faacEncOpen(sampleRate, numChannels);
+		faacEncHandle hEncoder = faacEncOpen(sampleRate, numChannels,
+			&inputSamples, &maxOutputBytes);
+
 		if (hEncoder)
 		{
 			HANDLE hOutfile;
@@ -193,8 +196,8 @@
 				char HeaderText[50];
 				char Percentage[5];
 
-				pcmbuf = (short*)LocalAlloc(0, PCMBUFSIZE*numChannels*sizeof(short));
-				bitbuf = (unsigned char*)LocalAlloc(0, BITBUFSIZE*sizeof(unsigned char));
+				pcmbuf = (short*)LocalAlloc(0, inputSamples*sizeof(short));
+				bitbuf = (unsigned char*)LocalAlloc(0, maxOutputBytes*sizeof(unsigned char));
 
 				SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 1024));
 				SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
@@ -202,10 +205,9 @@
 				for ( ;; )
 				{
 					int bytesWritten;
-					int samplesToRead = PCMBUFSIZE;
 					UINT timeElapsed, timeEncoded;
 
-					bytesInput = sf_read_short(infile, pcmbuf, numChannels*PCMBUFSIZE) * sizeof(short);
+					bytesInput = sf_read_short(infile, pcmbuf, inputSamples) * sizeof(short);
 					
 					SendDlgItemMessage (hWnd, IDC_PROGRESS, PBM_SETPOS, (unsigned long)((float)totalBytesRead * 1024.0f / (sfinfo.samples*2*numChannels)), 0);
 					
@@ -242,7 +244,7 @@
 						pcmbuf,
 						bytesInput/2,
 						bitbuf,
-						BITBUFSIZE);
+						maxOutputBytes);
 
 					/* Stop Pressed */
 					if ( !Encoding ) 
--- a/include/faac.h
+++ b/include/faac.h
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: faac.h,v 1.4 2001/03/05 11:33:37 menno Exp $
+ * $Id: faac.h,v 1.5 2001/03/12 20:12:37 menno Exp $
  */
 
 #ifndef FAACLIB_H
@@ -77,7 +77,9 @@
 int FAACAPI faacEncSetConfiguration (faacEncHandle hEncoder, faacEncConfigurationPtr config);
 
 faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
-								  unsigned int numChannels);
+								  unsigned int numChannels,
+								  unsigned long *inputSamples,
+								  unsigned long *maxOutputBytes);
 
 int FAACAPI faacEncEncode(faacEncHandle hEncoder,
 						  short *inputBuffer,
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: frame.c,v 1.14 2001/03/12 16:58:37 menno Exp $
+ * $Id: frame.c,v 1.15 2001/03/12 20:12:37 menno Exp $
  */
 
 /*
@@ -81,10 +81,15 @@
 }
 
 faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
-								  unsigned int numChannels)
+								  unsigned int numChannels,
+								  unsigned long *inputSamples,
+								  unsigned long *maxOutputBytes)
 {
 	unsigned int channel;
 	faacEncHandle hEncoder;
+
+	*inputSamples = 1024*numChannels;
+	*maxOutputBytes = (6144/8)*numChannels;
 
 	hEncoder = (faacEncStruct*)AllocMemory(sizeof(faacEncStruct));
 	SetMemory(hEncoder, 0, sizeof(faacEncStruct));
--- a/libfaac/frame.h
+++ b/libfaac/frame.h
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: frame.h,v 1.7 2001/03/06 14:01:36 menno Exp $
+ * $Id: frame.h,v 1.8 2001/03/12 20:12:37 menno Exp $
  */
 
 #ifndef FRAME_H
@@ -119,7 +119,9 @@
 int FAACAPI faacEncSetConfiguration (faacEncHandle hEncoder, faacEncConfigurationPtr config);
 
 faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
-								  unsigned int numChannels);
+								  unsigned int numChannels,
+								  unsigned long *inputSamples,
+								  unsigned long *maxOutputBytes);
 
 int FAACAPI faacEncEncode(faacEncHandle hEncoder,
 						  short *inputBuffer,