shithub: aacenc

Download patch

ref: 9bee769ba88a72b69915ed4a2062bfdf2fff67dd
parent: d011c78e03d017c10e8b9931bbcd63b57d78ea88
author: menno <menno>
date: Mon Feb 12 09:39:14 EST 2001

Different MS switching model

--- a/frontend/faac.dsp
+++ b/frontend/faac.dsp
@@ -42,7 +42,7 @@
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /I "../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /O2 /I "../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
 # ADD BASE RSC /l 0x413 /d "NDEBUG"
 # ADD RSC /l 0x413 /d "NDEBUG"
 BSC32=bscmake.exe
@@ -50,7 +50,7 @@
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 libsndfile.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 libsndfile.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /machine:I386
 
 !ELSEIF  "$(CFG)" == "faac - Win32 Debug"
 
--- a/frontend/faacgui.dsp
+++ b/frontend/faacgui.dsp
@@ -54,6 +54,7 @@
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
 # ADD LINK32 libsndfile.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# SUBTRACT LINK32 /profile
 
 !ELSEIF  "$(CFG)" == "faacgui - Win32 Debug"
 
--- 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.4 2001/01/25 15:57:55 menno Exp $
+ * $Id: maingui.c,v 1.5 2001/02/12 14:39:14 menno Exp $
  */
 
 #include <windows.h>
@@ -132,9 +132,6 @@
 	{
 		faacEncConfigurationPtr config;
 
-		SendDlgItemMessage (hWnd, IDC_OUTPUTFORMAT, CB_RESETCONTENT, 0, 0L);
-
-		EnableWindow(GetDlgItem(hWnd, IDC_OUTPUTFORMAT), TRUE);
 		EnableWindow(GetDlgItem(hWnd, IDOK), TRUE);
 
 		config = faacEncGetCurrentConfiguration(hEncoder);
@@ -192,6 +189,11 @@
 				sf_close(infile);
 
 				MessageBox (hWnd, "faacEncSetConfiguration failed!", "Error", MB_OK | MB_ICONSTOP);
+
+				SendMessage(hWnd,WM_SETTEXT,0,(long)"FAAC GUI");
+				Encoding = FALSE;
+				SetDlgItemText(hWnd, IDOK, "Encode");
+
 				return 0;
 			}
 
--- a/frontend/resource.h
+++ b/frontend/resource.h
@@ -8,7 +8,6 @@
 #define IDC_OUTPUTFILENAME              1002
 #define IDC_SELECT_OUTPUTFILE           1003
 #define IDC_INPUTPARAMS                 1004
-#define IDC_OUTPUTFORMAT                1005
 #define IDC_PROGRESS                    1006
 #define IDC_ALLOWMIDSIDE                1007
 #define IDC_TIME                        1008
--- 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.8 2001/02/10 12:28:54 menno Exp $
+ * $Id: frame.c,v 1.9 2001/02/12 14:39:14 menno Exp $
  */
 
 /*
@@ -57,7 +57,7 @@
 	/* Check for correct bitrate */
 	if (config->bitRate > MaxBitrate(hEncoder->sampleRate))
 		return 0;
-	if (config->bitRate < MinBitrate(hEncoder->sampleRate))
+	if (config->bitRate < MinBitrate())
 		return 0;
 
 	/* Bitrate check passed */
@@ -278,7 +278,7 @@
 	MSEncode(coderInfo, channelInfo, hEncoder->freqBuff, numChannels, allowMidside);
 
 	/* Quantize and code the signal */
-	bitsToUse = (int)((bitRate)*FRAME_LEN/sampleRate+0.5);
+	bitsToUse = (int)(bitRate*FRAME_LEN/sampleRate+0.5);
 	for (channel = 0; channel < numChannels; channel++) {
 		if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
 			AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
--- a/libfaac/psych.c
+++ b/libfaac/psych.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: psych.c,v 1.5 2001/02/04 17:50:47 oxygene2000 Exp $
+ * $Id: psych.c,v 1.6 2001/02/12 14:39:14 menno Exp $
  */
 
 #include <stdlib.h>
@@ -753,10 +753,12 @@
 	} else if (psyInfo->threeInARow >= 3) {
 		psyInfo->block_type = ONLY_SHORT_WINDOW;
 		psyInfo->threeInARow = 0;
-	} else
+	} else {
 		psyInfo->block_type = ONLY_LONG_WINDOW;
+	}
 
  	psyInfo->lastEnr = mx/tot;
+	psyInfo->pe = psyInfo->lastPe;
 	psyInfo->lastPe = pe;
 }
 
@@ -779,7 +781,7 @@
 	double cM[MAX_NPART];
 	double cS[MAX_NPART];
 
-	double x1, x2, db, mld;
+	double mld;
 
 #ifdef _DEBUG
 	int ms_used = 0;
@@ -931,24 +933,11 @@
 
 			psyInfoL->maskThrMS[b] = min(thmM,psyInfoL->maskThrMS[b]);
 			psyInfoR->maskThrMS[b] = min(thmS,psyInfoR->maskThrMS[b]);
-			channelInfoL->msInfo.ms_used[b] = 1;
+			if (psyInfoL->maskThr[b] * psyInfoR->maskThr[b] < psyInfoL->maskThrMS[b] * psyInfoR->maskThrMS[b])
+				channelInfoL->msInfo.ms_used[b] = 0;
+			else
+				channelInfoL->msInfo.ms_used[b] = 1;
 		}
-
-#if 0
-		x1 = min(npartM, npartS);
-		x2 = max(npartM, npartS);
-		/* thresholds difference in db */
-		if (x2 >= 1000*x1) db=3;
-		else db = log10(x2/x1);  
-		if (db < 0.05) {
-#ifdef _DEBUG
-			ms_used++;
-#endif
-			channelInfoL->msInfo.ms_used[b] = 1;
-		} else {
-			channelInfoL->msInfo.ms_used[b] = 0;
-		}
-#endif
 	}
 
 
@@ -1093,24 +1082,12 @@
 
 				psyInfoL->maskThrSMS[j][b] = min(thmM,psyInfoL->maskThrSMS[j][b]);
 				psyInfoR->maskThrSMS[j][b] = min(thmS,psyInfoR->maskThrSMS[j][b]);
-				channelInfoL->msInfo.ms_usedS[j][b] = 1;
+				if (psyInfoL->maskThrS[j][b] * psyInfoR->maskThrS[j][b] < 
+					psyInfoL->maskThrSMS[j][b] * psyInfoR->maskThrSMS[j][b])
+					channelInfoL->msInfo.ms_usedS[j][b] = 0;
+				else
+					channelInfoL->msInfo.ms_usedS[j][b] = 1;
 			}
-
-#if 0
-			x1 = min(npartM, npartS);
-			x2 = max(npartM, npartS);
-			/* thresholds difference in db */
-			if (x2 >= 1000*x1) db = 3;
-			else db = log10(x2/x1);
-			if (db < 0.05) {
-#ifdef _DEBUG
-				ms_usedS++;
-#endif
-				channelInfoL->msInfo.ms_usedS[j][b] = 1;
-			} else {
-				channelInfoL->msInfo.ms_usedS[j][b] = 0;
-			}
-#endif
 		}
 	}
 
--- a/libfaac/psych.h
+++ b/libfaac/psych.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: psych.h,v 1.3 2001/02/04 17:50:47 oxygene2000 Exp $
+ * $Id: psych.h,v 1.4 2001/02/12 14:39:14 menno Exp $
  */
 
 #ifndef PSYCH_H
@@ -73,6 +73,7 @@
 	int block_type;
 
 	/* Final threshold values */
+	double pe;
 	double *nb;
 	double *nbS[8];
 	double *maskThr;
--- a/libfaac/util.c
+++ b/libfaac/util.c
@@ -16,9 +16,17 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: util.c,v 1.3 2001/02/10 12:28:54 menno Exp $
+ * $Id: util.c,v 1.4 2001/02/12 14:39:14 menno Exp $
  */
 
+
+#ifndef max
+#define max(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+#ifndef min
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
 /* Returns the sample rate index */
 int GetSRIndex(unsigned int sampleRate)
 {
@@ -43,21 +51,37 @@
 	/*
 	 *  Maximum of 6144 bit for a channel
 	 */
-	return (int)(6144.0 * (double)sampleRate/1024.0 + .5);
+	return (unsigned int)(6144.0 * (double)sampleRate/1024.0 + .5);
 }
 
 /* Returns the minimum bitrate per channel for that sampling frequency */
-unsigned int MinBitrate(unsigned long sampleRate)
+unsigned int MinBitrate()
 {
 	return 8000;
 }
 
-int max(a, b)
+/* Calculate bit_allocation based on PE */
+unsigned int BitAllocation(double pe, int short_block)
 {
-	return (((a) > (b)) ? (a) : (b));
+	double pew1;
+	double pew2;
+	double bit_allocation;
+
+	if (short_block) {
+		pew1 = 0.6;
+		pew2 = 24.0;
+	} else {
+		pew1 = 0.3;
+		pew2 = 6.0;
+	}
+	bit_allocation = pew1 * pe + pew2 * sqrt(pe);
+	bit_allocation = min(max(0.0, bit_allocation), 6144.0);
+
+	return (unsigned int)(bit_allocation+0.5);
 }
 
-int min(a, b)
+/* Returns the maximum bit reservoir size */
+unsigned int MaxBitresSize(unsigned long bitRate, unsigned long sampleRate)
 {
-	return (((a) < (b)) ? (a) : (b));
+	return 6144 - (unsigned int)((double)bitRate/(double)sampleRate*1024.0);
 }
--- a/libfaac/util.h
+++ b/libfaac/util.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: util.h,v 1.2 2001/02/10 12:28:54 menno Exp $
+ * $Id: util.h,v 1.3 2001/02/12 14:39:14 menno Exp $
  */
 
 #ifndef UTIL_H
@@ -30,7 +30,9 @@
 
 int GetSRIndex(unsigned int sampleRate);
 unsigned int MaxBitrate(unsigned long sampleRate);
-unsigned int MinBitrate(unsigned long sampleRate);
+unsigned int MinBitrate();
+unsigned int MaxBitresSize(unsigned long bitRate, unsigned long sampleRate);
+unsigned int BitAllocation(double pe, int short_block);
 
 
 #ifdef __cplusplus