shithub: aacenc

Download patch

ref: 0c90a284583ab426b01db402188428a6d8643196
parent: 33a424159664eb248f31d57bb2016d27f0fc5174
author: menno <menno>
date: Thu Apr 19 09:20:34 EDT 2001

Changes in MPEG4 file format, mainly comments for clarification

--- a/frontend/faacgui.rc
+++ b/frontend/faacgui.rc
@@ -52,15 +52,15 @@
 // Dialog
 //
 
-IDD_MAINDIALOG DIALOGEX 0, 0, 266, 175
+IDD_MAINDIALOG DIALOGEX 0, 0, 277, 175
 STYLE DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | 
     WS_SYSMENU
 CAPTION "FAAC GUI"
 FONT 8, "MS Sans Serif"
 BEGIN
-    PUSHBUTTON      "...",IDC_SELECT_INPUTFILE,228,12,19,14,0,
+    PUSHBUTTON      "...",IDC_SELECT_INPUTFILE,238,12,19,14,0,
                     WS_EX_STATICEDGE
-    PUSHBUTTON      "...",IDC_SELECT_OUTPUTFILE,228,32,19,14,WS_DISABLED,
+    PUSHBUTTON      "...",IDC_SELECT_OUTPUTFILE,238,33,19,14,WS_DISABLED,
                     WS_EX_STATICEDGE
     CONTROL         "Allow Mid/Side",IDC_ALLOWMIDSIDE,"Button",
                     BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,13,78,71,10
@@ -68,36 +68,35 @@
     EDITTEXT        IDC_BANDWIDTH,138,95,31,14,ES_AUTOHSCROLL
     DEFPUSHBUTTON   "Encode",IDOK,75,154,50,14,WS_DISABLED
     PUSHBUTTON      "Quit",IDCANCEL,141,154,50,14
-    EDITTEXT        IDC_INPUTFILENAME,61,12,161,14,ES_AUTOHSCROLL
-    EDITTEXT        IDC_OUTPUTFILENAME,61,32,161,14,ES_AUTOHSCROLL | 
+    EDITTEXT        IDC_INPUTFILENAME,61,12,171,14,ES_AUTOHSCROLL
+    EDITTEXT        IDC_OUTPUTFILENAME,61,33,171,14,ES_AUTOHSCROLL | 
                     WS_DISABLED
     LTEXT           "Input File:",IDC_STATIC,18,13,38,8
     LTEXT           "Output File:",IDC_STATIC,18,34,37,8
     CONTROL         "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,7,54,
-                    252,1
+                    263,1
     LTEXT           "-",IDC_INPUTPARAMS,32,66,55,8
     LTEXT           "In:",IDC_STATIC,14,66,12,8
     CONTROL         "Progress1",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7,
-                    126,252,10
-    GROUPBOX        "Output Format",IDC_STATIC,94,62,165,59
-    CTEXT           "- - -",IDC_TIME,7,142,252,8
+                    126,263,10
+    GROUPBOX        "Output Format",IDC_STATIC,92,62,178,59
+    CTEXT           "- - -",IDC_TIME,7,142,263,8
     LTEXT           "Bandwidth:",IDC_STATIC,97,98,37,8
     LTEXT           "Bitrate:",IDC_STATIC,97,80,37,8
     LTEXT           "bps/ch",IDC_STATIC,173,80,24,8
     LTEXT           "Hz",IDC_STATIC,173,98,10,8
     CONTROL         "Use LFE channel",IDC_USELFE,"Button",BS_AUTOCHECKBOX | 
-                    BS_LEFTTEXT | WS_DISABLED | WS_TABSTOP,13,111,71,10
+                    BS_LEFTTEXT | WS_DISABLED | WS_TABSTOP,13,100,71,10
     CONTROL         "Use TNS",IDC_USETNS,"Button",BS_AUTOCHECKBOX | 
                     BS_LEFTTEXT | WS_TABSTOP,13,89,71,10
-    CONTROL         "Use LTP",IDC_USELTP,"Button",BS_AUTOCHECKBOX | 
-                    BS_LEFTTEXT | WS_TABSTOP,13,100,71,10
-    RTEXT           "-",IDC_COMPILEDATE,196,160,63,8
-    GROUPBOX        "AAC Profile",IDC_STATIC,200,71,53,46
-    CONTROL         "Main LTP",IDC_MAIN,"Button",BS_AUTORADIOBUTTON,204,92,
-                    47,10
-    CONTROL         "LC",IDC_LC,"Button",BS_AUTORADIOBUTTON,204,81,25,10
-    CONTROL         "SSR",IDC_SSR,"Button",BS_AUTORADIOBUTTON | WS_DISABLED,
-                    204,103,31,10
+    RTEXT           "-",IDC_COMPILEDATE,207,160,63,8
+    GROUPBOX        "AAC Profile",IDC_STATIC,200,71,61,46
+    CONTROL         "MPEG4 LTP",IDC_MPEG4LTP,"Button",BS_AUTORADIOBUTTON,204,
+                    103,56,10
+    CONTROL         "MPEG2 LC",IDC_MPEG2LC,"Button",BS_AUTORADIOBUTTON,204,
+                    81,51,10
+    CONTROL         "MPEG4 LC",IDC_MPEG4LC,"Button",BS_AUTORADIOBUTTON,204,
+                    92,51,10
 END
 
 
@@ -112,7 +111,7 @@
     IDD_MAINDIALOG, DIALOG
     BEGIN
         LEFTMARGIN, 7
-        RIGHTMARGIN, 259
+        RIGHTMARGIN, 270
         TOPMARGIN, 7
         BOTTOMMARGIN, 168
     END
--- 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.13 2001/04/11 13:50:31 menno Exp $
+ * $Id: main.c,v 1.14 2001/04/19 13:20:33 menno Exp $
  */
 
 #ifdef _WIN32
@@ -74,10 +74,10 @@
 	{
 		printf("USAGE: %s -options infile outfile\n", argv[0]);
 		printf("Options:\n");
-		printf("  -pX   AAC object type, X=L gives LC, X=M gives MAIN with LTP\n");
+		printf("  -pX   AAC object type, X=LC2 gives MPEG2 LC,");
+		printf("        X=LC4 gives MPEG4 LC and X=LTP gives LTP\n");
 		printf("  -nm   Don\'t use mid/side coding\n");
 		printf("  -tns  Use TNS coding\n");
-		printf("  -ltp  Use LTP coding\n");
 		printf("  -bwX  Set the bandwidth, X in Hz\n");
 		printf("  -brX  Set the bitrate per channel, X in bps\n\n");
 		return 1;
@@ -119,18 +119,22 @@
 			if ((argv[i][0] == '-') || (argv[i][0] == '/')) {
 				switch(argv[i][1]) {
 				case 'p': case 'P':
-					if ((argv[i][2] == 'l') || (argv[i][2] == 'L'))
+					if ((argv[i][2] == 'l') || (argv[i][2] == 'L')) {
 						myFormat->aacObjectType = LOW;
-					else if ((argv[i][2] == 'm') || (argv[i][2] == 'M'))
-						myFormat->aacObjectType = LTP;
+						if (argv[i][4] == '2')
+							myFormat->mpegVersion = MPEG2;
+						else
+							myFormat->mpegVersion = MPEG4;
+					} else if ((argv[i][2] == 'l') || (argv[i][2] == 'L')) {
+						if ((argv[i][3] == 't') || (argv[i][2] == 'T')) {
+							myFormat->aacObjectType = LTP;
+							myFormat->mpegVersion = MPEG4;
+						}
+					}
 				break;
 				case 't': case 'T':
 					if ((argv[i][2] == 'n') || (argv[i][2] == 'N'))
 						myFormat->useTns = 1;
-				break;
-				case 'l': case 'L':
-					if ((argv[i][2] == 't') || (argv[i][2] == 'T'))
-						myFormat->useLtp = 1;
 				break;
 				case 'n': case 'N':
 					if ((argv[i][2] == 'm') || (argv[i][2] == 'M'))
--- 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.13 2001/04/11 13:50:31 menno Exp $
+ * $Id: maingui.c,v 1.14 2001/04/19 13:20:33 menno Exp $
  */
 
 #include <windows.h>
@@ -157,10 +157,18 @@
 			config->allowMidside = IsDlgButtonChecked(hWnd, IDC_ALLOWMIDSIDE) == BST_CHECKED ? 1 : 0;
 			config->useTns = IsDlgButtonChecked(hWnd, IDC_USETNS) == BST_CHECKED ? 1 : 0;
 			config->useLfe = IsDlgButtonChecked(hWnd, IDC_USELFE) == BST_CHECKED ? 1 : 0;
-			config->useLtp = IsDlgButtonChecked(hWnd, IDC_USELTP) == BST_CHECKED ? 1 : 0;
-			config->aacObjectType = IsDlgButtonChecked(hWnd, IDC_LC) == BST_CHECKED ? LOW : 0;
-			config->aacObjectType = IsDlgButtonChecked(hWnd, IDC_MAIN) == BST_CHECKED ? LTP : 0;
-			config->aacObjectType = IsDlgButtonChecked(hWnd, IDC_SSR) == BST_CHECKED ? SSR : 0;
+			if (IsDlgButtonChecked(hWnd, IDC_MPEG2LC) == BST_CHECKED) {
+				config->aacObjectType = LOW;
+				config->mpegVersion = MPEG2;
+			}
+			if (IsDlgButtonChecked(hWnd, IDC_MPEG4LC) == BST_CHECKED) {
+				config->aacObjectType = LOW;
+				config->mpegVersion = MPEG4;
+			}
+			if (IsDlgButtonChecked(hWnd, IDC_MPEG4LTP) == BST_CHECKED) {
+				config->aacObjectType = LTP;
+				config->mpegVersion = MPEG4;
+			}
 			GetDlgItemText(hWnd, IDC_BITRATE, szTemp, sizeof(szTemp));
 			config->bitRate = atoi(szTemp);
 			GetDlgItemText(hWnd, IDC_BANDWIDTH, szTemp, sizeof(szTemp));
@@ -294,11 +302,10 @@
 
 		inputFilename [0] = 0x00;
 
-		CheckDlgButton(hWnd, IDC_MAIN, TRUE);
+		CheckDlgButton(hWnd, IDC_MPEG4LTP, TRUE);
 		CheckDlgButton(hWnd, IDC_ALLOWMIDSIDE, TRUE);
 		CheckDlgButton(hWnd, IDC_USELFE, FALSE);
 		CheckDlgButton(hWnd, IDC_USETNS, TRUE);
-		CheckDlgButton(hWnd, IDC_USELTP, TRUE);
 		SetDlgItemText(hWnd, IDC_BITRATE, "64000");
 		SetDlgItemText(hWnd, IDC_BANDWIDTH, "18000");
 
--- a/frontend/resource.h
+++ b/frontend/resource.h
@@ -15,11 +15,10 @@
 #define IDC_BITRATE                     1010
 #define IDC_USELFE                      1011
 #define IDC_USETNS                      1012
-#define IDC_USELTP                      1013
 #define IDC_COMPILEDATE                 1018
-#define IDC_MAIN                        1019
-#define IDC_LC                          1020
-#define IDC_SSR                         1021
+#define IDC_MPEG4LTP                    1019
+#define IDC_MPEG2LC                     1020
+#define IDC_MPEG4LC                     1021
 
 // Next default values for new objects
 // 
--- 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.6 2001/04/11 13:50:31 menno Exp $
+ * $Id: faac.h,v 1.7 2001/04/19 13:20:33 menno Exp $
  */
 
 #ifndef FAACLIB_H
@@ -40,6 +40,10 @@
 #define FAACENC_VERSION 1.0
 #define FAACENC_VERSIONB 1 /* If 1 this version is still in beta */
 
+/* MPEG ID's */
+#define MPEG2 1
+#define MPEG4 0
+
 /* AAC object types */
 #define MAIN 0
 #define LOW  1
@@ -48,6 +52,9 @@
 
 typedef struct faacEncConfiguration
 {
+	/* MPEG version, 2 or 4 */
+	unsigned int mpegVersion;
+
 	/* AAC object type */
 	unsigned int aacObjectType;
 
@@ -59,9 +66,6 @@
 
 	/* Use Temporal Noise Shaping */
 	unsigned int useTns;
-
-	/* Use Long Term Prediction */
-	unsigned int useLtp;
 
 	/* bitrate / channel of AAC file */
 	unsigned long bitRate;
--- a/libfaac/bitstream.c
+++ b/libfaac/bitstream.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: bitstream.c,v 1.12 2001/04/11 13:50:31 menno Exp $
+ * $Id: bitstream.c,v 1.13 2001/04/19 13:20:34 menno Exp $
  */
 
 #include <stdlib.h>
@@ -96,6 +96,11 @@
     PutBit(bitStream, ID_END, LEN_SE_ID);
 
 	/* Now byte align the bitstream */
+	/*
+	 * This byte_alignment() is correct for both MPEG2 and MPEG4, although
+	 * in MPEG4 the byte_alignment() is officially done before the new frame
+	 * instead of at the end. But this is basically the same.
+	 */
 	bits += ByteAlign(bitStream, 1);
 
 	return bits;
@@ -177,14 +182,12 @@
 						   BitStream *bitStream,
 						   int writeFlag)
 {
+	int bits = 56;
+
 	if (writeFlag) {
 		/* Fixed ADTS header */
 		PutBit(bitStream, 0xFFFF, 12); /* 12 bit Syncword */
-#ifdef MPEG2AAC
-		PutBit(bitStream, 1, 1); /* ID == 1 for MPEG2 AAC */
-#else
-		PutBit(bitStream, 0, 1); /* ID == 0 for MPEG4 AAC */
-#endif
+		PutBit(bitStream, hEncoder->config.mpegVersion, 1); /* ID == 0 for MPEG4 AAC, 1 for MPEG2 AAC */
 		PutBit(bitStream, 0, 2); /* layer == 0 */
 		PutBit(bitStream, 1, 1); /* protection absent */
 		PutBit(bitStream, hEncoder->config.aacObjectType, 2); /* profile */
@@ -196,9 +199,8 @@
 														configuration should be written */
 		PutBit(bitStream, 0, 1); /* original/copy */
 		PutBit(bitStream, 0, 1); /* home */
-#ifndef MPEG2AAC
-		PutBit(bitStream, 0, 2); /* emphasis */
-#endif
+		if (hEncoder->config.mpegVersion == 0)
+			PutBit(bitStream, 0, 2); /* emphasis */
 
 		/* Variable ADTS header */
 		PutBit(bitStream, 0, 1); /* copyr. id. bit */
@@ -206,13 +208,22 @@
 		PutBit(bitStream, hEncoder->usedBytes, 13);
 		PutBit(bitStream, 0x7FF, 11); /* buffer fullness (0x7FF for VBR) */
 		PutBit(bitStream, 0, 2); /* raw data blocks (0+1=1) */
+
 	}
 
-#ifdef MPEG2AAC
-	return 56;
-#else
-	return 58;
-#endif
+	/*
+	 * MPEG2 says byte_aligment() here, but ADTS always is multiple of 8 bits
+	 * MPEG4 has no byte_alignment() here
+	 */
+	/*
+	if (hEncoder->config.mpegVersion == 1)
+		bits += ByteAlign(bitStream, writeFlag);
+	*/
+
+	if (hEncoder->config.mpegVersion == 0)
+		bits += 2; /* emphasis */
+
+	return bits;
 }
 
 static int WriteCPE(CoderInfo *coderInfoL,
--- a/libfaac/bitstream.h
+++ b/libfaac/bitstream.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: bitstream.h,v 1.4 2001/04/11 13:50:31 menno Exp $
+ * $Id: bitstream.h,v 1.5 2001/04/19 13:20:34 menno Exp $
  */
 
 #ifndef BITSTREAM_H
@@ -95,6 +95,11 @@
 #define ID_PCE 5
 #define ID_FIL 6
 #define ID_END 7
+
+
+/* MPEG ID's */
+#define MPEG2 1
+#define MPEG4 0
 
 /* AAC object types */
 #define MAIN 0
--- 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.17 2001/04/11 13:50:31 menno Exp $
+ * $Id: frame.c,v 1.18 2001/04/19 13:20:34 menno Exp $
  */
 
 /*
@@ -57,8 +57,8 @@
 	hEncoder->config.allowMidside = config->allowMidside;
 	hEncoder->config.useLfe = config->useLfe;
 	hEncoder->config.useTns = config->useTns;
-	hEncoder->config.useLtp = config->useLtp;
 	hEncoder->config.aacObjectType = config->aacObjectType;
+	hEncoder->config.mpegVersion = config->mpegVersion;
 
 	 /* No SSR / MAIN supported for now */
 	if ((hEncoder->config.aacObjectType != LTP)&&(hEncoder->config.aacObjectType != LOW))
@@ -103,11 +103,11 @@
 	hEncoder->flushFrame = 0;
 
 	/* Default configuration */
+	hEncoder->config.mpegVersion = MPEG4;
 	hEncoder->config.aacObjectType = LTP;
 	hEncoder->config.allowMidside = 1;
 	hEncoder->config.useLfe = 0;
 	hEncoder->config.useTns = 0;
-	hEncoder->config.useLtp = 0;
 	hEncoder->config.bitRate = 64000; /* default bitrate / channel */
 	hEncoder->config.bandWidth = 18000; /* default bandwidth */
 
@@ -194,9 +194,9 @@
 	unsigned int numChannels = hEncoder->numChannels;
 	unsigned int sampleRate = hEncoder->sampleRate;
 	unsigned int aacObjectType = hEncoder->config.aacObjectType;
+	unsigned int mpegVersion = hEncoder->config.mpegVersion;
 	unsigned int useLfe = hEncoder->config.useLfe;
 	unsigned int useTns = hEncoder->config.useTns;
-	unsigned int useLtp = hEncoder->config.useLtp;
 	unsigned int allowMidside = hEncoder->config.allowMidside;
 	unsigned int bitRate = hEncoder->config.bitRate;
 	unsigned int bandWidth = hEncoder->config.bandWidth;
@@ -346,7 +346,8 @@
 			tnsInfo_for_LTP = NULL;
 
 		if(channelInfo[channel].present && (!channelInfo[channel].lfe) &&
-			(coderInfo[channel].block_type != ONLY_SHORT_WINDOW) && (useLtp) && (aacObjectType == LTP)) 
+			(coderInfo[channel].block_type != ONLY_SHORT_WINDOW) &&
+			(mpegVersion == MPEG4) && (aacObjectType == LTP)) 
 		{
 			LtpEncode(hEncoder,
 				&coderInfo[channel],
@@ -392,7 +393,7 @@
 			else
 				tnsDecInfo = NULL;
 			
-			if ((!channelInfo[channel].lfe) && (useLtp) && (aacObjectType == LTP)) {  /* no reconstruction needed for LFE channel*/
+			if ((!channelInfo[channel].lfe) && (mpegVersion == MPEG4) && (aacObjectType == LTP)) {  /* no reconstruction needed for LFE channel*/
 
 				LtpReconstruct(&coderInfo[channel], &(coderInfo[channel].ltpInfo),
 					coderInfo[channel].requantFreq);
--- 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.9 2001/04/11 13:50:31 menno Exp $
+ * $Id: frame.h,v 1.10 2001/04/19 13:20:34 menno Exp $
  */
 
 #ifndef FRAME_H
@@ -46,6 +46,9 @@
 
 typedef struct faacEncConfiguration
 {
+	/* MPEG version, 2 or 4 */
+	unsigned int mpegVersion;
+
 	/* AAC object type */
 	unsigned int aacObjectType;
 
@@ -57,9 +60,6 @@
 
 	/* Use Temporal Noise Shaping */
 	unsigned int useTns;
-
-	/* Use Long Term Prediction */
-	unsigned int useLtp;
 
 	/* bitrate / channel of AAC file */
 	unsigned long bitRate;
--- a/libfaac/tns.c
+++ b/libfaac/tns.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: tns.c,v 1.5 2001/04/11 13:50:31 menno Exp $
+ * $Id: tns.c,v 1.6 2001/04/19 13:20:34 menno Exp $
  */
 
 #include <math.h>
@@ -69,27 +69,27 @@
 		case LTP:
 			tnsInfo->tnsMaxBandsLong = tnsMaxBandsLongMainLow[fsIndex];
 			tnsInfo->tnsMaxBandsShort = tnsMaxBandsShortMainLow[fsIndex];
-#ifdef MPEG2AAC
-			tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongMain;
-#else
-			if (fsIndex <= 5) /* fs > 32000Hz */
-				tnsInfo->tnsMaxOrderLong = 12;
-			else
-				tnsInfo->tnsMaxOrderLong = 20;
-#endif
+			if (hEncoder->config.mpegVersion == 1) { /* MPEG2 */
+				tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongMain;
+			} else { /* MPEG4 */
+				if (fsIndex <= 5) /* fs > 32000Hz */
+					tnsInfo->tnsMaxOrderLong = 12;
+				else
+					tnsInfo->tnsMaxOrderLong = 20;
+			}
 			tnsInfo->tnsMaxOrderShort = tnsMaxOrderShortMainLow;
 			break;
 		case LOW :
 			tnsInfo->tnsMaxBandsLong = tnsMaxBandsLongMainLow[fsIndex];
 			tnsInfo->tnsMaxBandsShort = tnsMaxBandsShortMainLow[fsIndex];
-#ifdef MPEG2AAC
-			tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongLow;
-#else
-			if (fsIndex <= 5) /* fs > 32000Hz */
-				tnsInfo->tnsMaxOrderLong = 12;
-			else
-				tnsInfo->tnsMaxOrderLong = 20;
-#endif
+			if (hEncoder->config.mpegVersion == 1) { /* MPEG2 */
+				tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongLow;
+			} else { /* MPEG4 */
+				if (fsIndex <= 5) /* fs > 32000Hz */
+					tnsInfo->tnsMaxOrderLong = 12;
+				else
+					tnsInfo->tnsMaxOrderLong = 20;
+			}
 			tnsInfo->tnsMaxOrderShort = tnsMaxOrderShortMainLow;
 			break;
 		}