shithub: aacenc

Download patch

ref: c621ff3bf032d0808a4696ba1a2d1fc0c0dca24f
parent: 103cb120b29b1b9a6290b96b0fddb1de6d24c6b6
author: menno <menno>
date: Sun Dec 19 18:33:16 EST 1999

Added some extra options

--- a/aacenc.h
+++ b/aacenc.h
@@ -15,8 +15,10 @@
 	int write_header;  // If this is 1, a ADIF header will be written, if it is 0, no
 	                   //    header will be written. (better turn this on, because
                        //    there is some bug when not using ADIF header)
-	int use_MS;        // If 1, MS stereo is on, if 0, it is off
+	int use_MS;        // If 1, MS stereo is on on all scalefactors, if 0 the intelligent switching is used
+	                   // if it is -1 MS is totally off.
 	int use_IS;        // If 1, IS stereo is on, if 0, it is off
+	int use_TNS;       // If 1, TNS is on, if 0, it is off
 } faacAACConfig;
 
 // This structure is for internal use of the encoder only.
@@ -32,6 +34,7 @@
 	int write_header;
 	int use_MS;
 	int use_IS;
+	int use_TNS;
 	int profile;
 	double **inputBuffer;
 } faacAACStream;
--- a/enc_tf.c
+++ b/enc_tf.c
@@ -236,7 +236,7 @@
 			for( i=0; i<block_size_samples; i++ ) {
 				/* last frame input data are encoded now */
 				DTimeSigBuf[chanNum][i] = DTimeSigLookAheadBuf[chanNum][i];
-				DTimeSigLookAheadBuf[chanNum][i] = (double)as->inputBuffer[chanNum][i];
+				DTimeSigLookAheadBuf[chanNum][i] = as->inputBuffer[chanNum][i];
 			} /* end for(i ..) */
 		} /* end for(chanNum ... ) */
 
@@ -339,8 +339,8 @@
 		for (chanNum=0;chanNum<max_ch;chanNum++) {
 
 			/* Set window shape paremeter in quantInfo */
-			quantInfo[chanNum].window_shape = WS_DOLBY;
-//			quantInfo[chanNum].window_shape = WS_FHG;
+//			quantInfo[chanNum].window_shape = WS_DOLBY;
+			quantInfo[chanNum].window_shape = WS_FHG;
 
 			switch( block_type[chanNum] ) {
 			case ONLY_SHORT_WINDOW  :
@@ -356,6 +356,13 @@
 #else
 				quantInfo[chanNum].num_window_groups = 1;
 				quantInfo[chanNum].window_group_length[0] = 8;
+				quantInfo[chanNum].window_group_length[1] = 0;
+				quantInfo[chanNum].window_group_length[2] = 0;
+				quantInfo[chanNum].window_group_length[3] = 0;
+				quantInfo[chanNum].window_group_length[4] = 0;
+				quantInfo[chanNum].window_group_length[5] = 0;
+				quantInfo[chanNum].window_group_length[6] = 0;
+				quantInfo[chanNum].window_group_length[7] = 0;
 #endif
 				break;
 				
@@ -442,7 +449,7 @@
 
 //	if (as->use_MS) {
 		MSPreprocess(p_ratio_long, p_ratio_short, chpo_long, chpo_short,
-			channelInfo, block_type, quantInfo,max_ch);
+			channelInfo, block_type, quantInfo, as->use_MS, max_ch);
 //	} else {
 //		int chanNum;
 //		for (chanNum=0;chanNum<max_ch;chanNum++) {
@@ -459,8 +466,8 @@
 //		}
 //	}
 
-	MSEnergy(spectral_line_vector, energy, chpo_long, chpo_short,
-		sfb_width_table, channelInfo, block_type, quantInfo, max_ch);
+	MSEnergy(spectral_line_vector, energy, chpo_long, chpo_short, sfb_width_table,
+		channelInfo, block_type, quantInfo, as->use_MS, max_ch);
 
 	{
 		int chanNum;   
@@ -508,7 +515,8 @@
 				block_type[chanNum],
 				sfb_offset_table[chanNum],
 				spectral_line_vector[chanNum],
-				&tnsInfo[chanNum]);
+				&tnsInfo[chanNum],
+				as->use_TNS);
 			if (error == FERROR)
 				return FERROR;
 		}
@@ -551,7 +559,7 @@
 		/******************************************/
 		/* Apply MS stereo                        */
 		/******************************************/
-//		if (as->use_MS) {
+		if (as->use_MS == 1) {
 			MSEncode(spectral_line_vector,
 				channelInfo,
 				sfb_offset_table,
@@ -558,7 +566,14 @@
 				block_type,
 				quantInfo,
 				max_ch);
-//		}
+		} else if (as->use_MS == 0) {
+			MSEncodeSwitch(spectral_line_vector,
+				channelInfo,
+				sfb_offset_table,
+				block_type,
+				quantInfo,
+				max_ch);
+		}
 
 		/************************************************/
 		/* Call the AAC quantization and coding module. */
--- a/encoder.c
+++ b/encoder.c
@@ -64,6 +64,7 @@
 	as->write_header = ac->write_header;
 	as->use_MS = ac->use_MS;
 	as->use_IS = ac->use_IS;
+	as->use_TNS = ac->use_TNS;
 	as->profile = ac->profile;
 	as->is_first_frame = 1;
 
@@ -338,10 +339,13 @@
 	printf("Options:\n");
 	printf(" -h    Shows this help screen.\n");
 	printf(" -pX   AAC profile (X can be LOW, or MAIN (default).\n");
-	printf(" -n    No header will be written to the AAC file.\n");
 	printf(" -bX   Bitrate in kbps (X can be: 64, 80, 96, 112, 128 (default),\n");
 	printf("       160, 192, 224 or 256).\n");
-	printf(" -ms   Use mid/side stereo coding (currently ignored).\n");
+	printf(" -ms   Use mid/side stereo coding.\n");
+	printf(" -nm   Don't use mid/side stereo coding.\n");
+	printf("       The default for MS is intelligent switching.\n");
+	printf(" -nt   Don't use TNS (Temporal Noise Shaping).\n");
+	printf(" -nh   No header will be written to the AAC file.\n");
 	printf(" -is   Use intensity stereo coding.\n");
 	printf(" -oX   Set output directory.\n");
 	printf(" -r    Use raw data input file.\n");
@@ -371,7 +375,7 @@
 	int i, frames, cfr;
 	int profile = MAIN_PROFILE;
 	int no_header = 0;
-	int use_IS = 0, use_MS = 0;
+	int use_IS = 0, use_MS = 0, use_TNS = 1;
 	int bit_rate = 128;
 	char out_dir[255];
 	int out_dir_set = 0;
@@ -458,7 +462,12 @@
 				break;
 			case 'n':
 			case 'N':
-				no_header = 1;
+				if (argv[i][2] == 'm' || 'M')
+					use_MS = -1;
+				else if (argv[i][2] == 't' || 'T')
+					use_TNS = 0;
+				else
+					no_header = 1;
 				break;
 			case 'm':
 			case 'M':
@@ -541,6 +550,7 @@
 		ac.profile = profile;
 		ac.use_MS = use_MS;
 		ac.use_IS = use_IS;
+		ac.use_TNS = use_TNS;
 		ac.write_header = !no_header;
 
 		as = faacEncodeInit(&ac, &readNumSample, &bitBufSize, &headerSize);
--- a/ms.h
+++ b/ms.h
@@ -47,6 +47,7 @@
 				  Ch_Info *channelInfo,                  /* Pointer to Ch_Info */
 				  enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
 				  AACQuantInfo* quantInfo,               /* Quant info */
+				  int use_ms,
 				  int numberOfChannels
 				  );
 
@@ -58,9 +59,17 @@
 			  Ch_Info *channelInfo,                  /* Pointer to Ch_Info */
 			  enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
 			  AACQuantInfo* quantInfo,               /* Quant info */
+			  int use_ms,
 			  int numberOfChannels
 			  );
 			  
+void MSEncodeSwitch(double *spectrum[MAX_TIME_CHANNELS],   /* array of pointers to spectral data */
+	      Ch_Info *channelInfo,                  /* Pointer to Ch_Info */
+	      int sfb_offset_table[][MAX_SCFAC_BANDS+1],
+	      enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS], /* Block type */
+	      AACQuantInfo* quantInfo,
+	      int numberOfChannels);                 /* Number of channels */
+
 void MSEncode(double *spectrum[MAX_TIME_CHANNELS],   /* array of pointers to spectral data */
 	      Ch_Info *channelInfo,                  /* Pointer to Ch_Info */
 	      int sfb_offset_table[][MAX_SCFAC_BANDS+1],
--- a/tns.c
+++ b/tns.c
@@ -93,7 +93,7 @@
 	       enum WINDOW_TYPE blockType,   /* block type */
 	       int* sfbOffsetTable,     /* Scalefactor band offset table */
 	       double* spec,            /* Spectral data array */
-	       TNS_INFO* tnsInfo)       /* TNS info */
+	       TNS_INFO* tnsInfo, int use_tns)       /* TNS info */
 {
 	int numberOfWindows,windowSize;
 	int startBand,stopBand,order;    /* Bands over which to apply TNS */
@@ -136,6 +136,7 @@
 	tnsInfo->tnsDataPresent=0;     /* default TNS not used */
 
 #if 1
+	if (use_tns)
 	/* Doesn't work well on short windows. */
 	if (blockType != ONLY_SHORT_WINDOW)
 	/* Perform analysis and filtering for each window */
--- a/tns.h
+++ b/tns.h
@@ -114,7 +114,7 @@
 void TnsFilter(int length,double* spec,TNS_FILTER_DATA* filter);
 int TnsInvFilter(int length,double* spec,TNS_FILTER_DATA* filter);
 void TnsInit(long samplingRate,enum AAC_PROFILE profile,TNS_INFO* tnsInfo); 
-int TnsEncode(int numberOfBands,int maxSfb,enum WINDOW_TYPE blockType,int* sfbOffsetTable,double* spec,TNS_INFO* tnsInfo);
+int TnsEncode(int numberOfBands,int maxSfb,enum WINDOW_TYPE blockType,int* sfbOffsetTable,double* spec,TNS_INFO* tnsInfo,int use_tns);
 
 #endif