shithub: aacenc

Download patch

ref: 5df05050ee2d287b4dc9adb71dd4639f4c652013
parent: 2a2cde962f4f63b12ee7e30759f3b0048932328f
author: menno <menno>
date: Sat Feb 5 04:19:38 EST 2000

Fixed lower bitrate encoding

--- a/aac_qc.c
+++ b/aac_qc.c
@@ -97,7 +97,7 @@
 #  define QUANTFAC(rx)  adj_quant_asm[rx]
 #  define XRPOW_FTOI(src, dest) \
      asm ("fistpl %0 " : "=m"(dest) : "t"(src) : "st")
-#elif 0 //defined (_MSC_VER)
+#elif defined (_MSC_VER)
 #  define QUANTFAC(rx)  adj_quant_asm[rx]
 #  define XRPOW_FTOI(src, dest) do { \
      double src_ = (src); \
@@ -109,7 +109,7 @@
      (dest) = dest_; \
    } while (0)
 #else
-#  define QUANTFAC(rx)  adj_quant[min(rx,8999)]
+#  define QUANTFAC(rx)  adj_quant[rx]
 #  define XRPOW_FTOI(src,dest) ((dest) = (int)(src))
 #endif
 
@@ -131,7 +131,7 @@
 {
 	const double istep = pow(2.0, -0.1875*quantInfo->common_scalefac);
 
-#if 1 //ndef _MSC_VER
+#ifndef _MSC_VER
 	{
 		double x;
 		int j, rx;
@@ -620,7 +620,7 @@
     for(sb=0; sb < quantInfo->nr_of_sfb; sb++ )
 		quantInfo->pns_sfb_flag[sb] = 0;
 
-    if (block_type[MONO_CHAN] != ONLY_SHORT_WINDOW) {     /* long blocks only */
+	if (block_type[MONO_CHAN] != ONLY_SHORT_WINDOW) {     /* long blocks only */
 		for(sb = pns_sfb_start; sb < quantInfo->nr_of_sfb; sb++ ) {
 			/* Calc. pseudo scalefactor */
 			if (energy[0][sb] == 0.0) {
@@ -628,17 +628,19 @@
 				continue;
 			}
 
-			if ((10*log10(energy[MONO_CHAN][sb]*sfb_width_table[0][sb]+1e-60)<70)||(SigMaskRatio[sb] > 1.0)) {
-				quantInfo->pns_sfb_flag[sb] = 1;
-				quantInfo->pns_sfb_nrg[sb] = (int) (2.0 * log(energy[0][sb]*sfb_width_table[0][sb]+1e-60) / log(2.0) + 0.5) + PNS_SF_OFFSET;
-				
-				/* Erase spectral lines */
-				for( i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++ ) {
-					p_spectrum[0][i] = 0.0;
+			if (!((is_info->is_present)&&(is_info->is_used[k]))) {
+				if ((10*log10(energy[MONO_CHAN][sb]+1e-60)<50)||(SigMaskRatio[sb] > 1.0)) {
+					quantInfo->pns_sfb_flag[sb] = 1;
+					quantInfo->pns_sfb_nrg[sb] = (int) (2.0 * log(energy[0][sb]*sfb_width_table[0][sb]+1e-60) / log(2.0) + 0.5) + PNS_SF_OFFSET;
+					
+					/* Erase spectral lines */
+					for( i=sfb_offset[sb]; i<sfb_offset[sb+1]; i++ ) {
+						p_spectrum[0][i] = 0.0;
+					}
 				}
 			}
 		}
-    }
+	}
 
 	/* Compute allowed distortion */
 	for(sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
--- a/enc_tf.c
+++ b/enc_tf.c
@@ -517,7 +517,7 @@
 	}
 
 	MSPreprocess(p_ratio_long, p_ratio_short, chpo_long, chpo_short,
-		channelInfo, block_type, quantInfo, as->use_MS, max_ch);
+		channelInfo, block_type, quantInfo, as->use_MS, as->use_IS, max_ch);
 
 	MSEnergy(spectral_line_vector, energy, chpo_long, chpo_short, sfb_width_table,
 		channelInfo, block_type, quantInfo, as->use_MS, max_ch);
@@ -577,7 +577,7 @@
 		/******************************************/
 		/* Apply Intensity Stereo                 */
 		/******************************************/
-		if (as->use_IS) {
+		if (as->use_IS && (as->use_MS != 1)) {
 			ISEncode(spectral_line_vector,
 				channelInfo,
 				sfb_offset_table,
@@ -721,7 +721,7 @@
 		/**********************************************************/
 		/* Reconstruct Intensity Stereo bands for prediction     */
 		/**********************************************************/
-		if (as->use_IS && (pns_sfb_start > 51)) {  /* do intensity only if pns is off  */
+		if ((as->use_IS)&& (pns_sfb_start > 51)) {  /* do intensity only if pns is off  */
 			ISReconstruct(reconstructed_spectrum,
 				channelInfo,
 				sfb_offset_table,
--- a/is.h
+++ b/is.h
@@ -17,8 +17,8 @@
 #include "aac_qc.h"
 #include <math.h>
 
-#define IS_MIN_BAND_L 28
-#define IS_MIN_BAND_S 7
+#define IS_MIN_BAND_L 0 //28
+#define IS_MIN_BAND_S 0 //7
 
 void ISEncode(double *spectrum[MAX_TIME_CHANNELS],   /* array of pointers to spectral data */
 	      Ch_Info *channelInfo,                  /* Pointer to Ch_Info */
--- a/ms.c
+++ b/ms.c
@@ -34,6 +34,7 @@
 
 #include "psych.h"
 #include "ms.h"
+#include "is.h"
 
 void MSPreprocess(double p_ratio_long[][MAX_SCFAC_BANDS],
 				  double p_ratio_short[][MAX_SCFAC_BANDS],
@@ -42,7 +43,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 use_ms, int use_is,
 				  int numberOfChannels
 				  )
 {
@@ -67,7 +68,7 @@
 
 					int numGroups;
 					int groupIndex = 0;
-					int maxSfb;
+					int maxSfb, isBand;
 					int g,b,j;
 					int use_ms_short;
 					MS_Info *msInfo;
@@ -77,6 +78,12 @@
 
 					/* Determine which bands should be enabled */
 					msInfo = &(channelInfo[leftChan].ms_info);
+					if (use_is) {
+						isBand = (block_type[rightChan]==ONLY_SHORT_WINDOW) ? IS_MIN_BAND_S : IS_MIN_BAND_L;
+						isBand = (isBand>maxSfb) ? maxSfb : isBand;
+					} else {
+						isBand = maxSfb;
+					}
 
 					for (g=0;g<numGroups;g++) {
 						for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
@@ -88,7 +95,13 @@
 								for (j = groupIndex; j < quantInfo[leftChan].window_group_length[g]+groupIndex; j++) {
 									use_ms_short = min(use_ms_short, p_chpo_short[1][j].use_ms[sfbNum]);
 								}
-								msInfo->ms_used[b] = use_ms_short;
+								if (sfbNum < isBand) {
+									msInfo->ms_used[b] = use_ms_short;
+								} else {
+									msInfo->ms_used[b] = 0;
+									use_ms_short = 0;
+								}
+
 								if (msInfo->ms_used[b]) {
 									realyused = 1;
 									used++;
@@ -108,7 +121,12 @@
 
 							} else {
 
-								msInfo->ms_used[b] = p_chpo_long[1].use_ms[sfbNum];
+								if (sfbNum < isBand) {
+									msInfo->ms_used[b] = p_chpo_long[1].use_ms[sfbNum];
+								} else {
+									msInfo->ms_used[b] = 0;
+									p_chpo_long[1].use_ms[sfbNum] = 0;
+								}
 								if (msInfo->ms_used[b]) {
 									realyused = 1;
 									used++;