shithub: aacenc

Download patch

ref: 9bffa38f24f9c853b71d50f216141dcbc5f2f741
parent: baf654499f217819635257bfd9d68204d4397b97
author: menno <menno>
date: Fri Feb 4 15:31:52 EST 2000

Bugs fixed

--- 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 defined (_MSC_VER)
+#elif 0 //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[rx]
+#  define QUANTFAC(rx)  adj_quant[min(rx,8999)]
 #  define XRPOW_FTOI(src,dest) ((dest) = (int)(src))
 #endif
 
@@ -125,14 +125,13 @@
  *    Acy Stapp <AStapp@austin.rr.com> 11/1999
  *    Takehiro Tominaga <tominaga@isoternet.org> 11/1999
  *********************************************************************/
-int quantize(AACQuantInfo *quantInfo,
-			 double *p_spectrum,
-			 double *pow_spectrum,
-			 int quant[NUM_COEFF])
+void quantize(AACQuantInfo *quantInfo,
+			  double *pow_spectrum,
+			  int *quant)
 {
 	const double istep = pow(2.0, -0.1875*quantInfo->common_scalefac);
 
-#ifndef _MSC_VER
+#if 1 //ndef _MSC_VER
 	{
 		double x;
 		int j, rx;
@@ -239,7 +238,7 @@
 	do
 	{
 		quantInfo->common_scalefac += 1;
-		quantize(quantInfo, p_spectrum, pow_spectrum, quant);
+		quantize(quantInfo, pow_spectrum, quant);
 		bits = count_bits(quantInfo, quant, quantInfo->book_vector); 
 	} while ( bits > max_bits );
 
@@ -260,7 +259,7 @@
 	do
 	{
 		quantInfo->common_scalefac = StepSize;
-		quantize(quantInfo, p_spectrum, pow_spectrum, quant);
+		quantize(quantInfo, pow_spectrum, quant);
 		nBits = count_bits(quantInfo, quant, quantInfo->book_vector);  
 
 		if (CurrentStep == 1 ) {
@@ -325,7 +324,7 @@
 		error_energy[sb] = 0.0;
 
 		for (i = quantInfo->sfb_offset[sb]; i < quantInfo->sfb_offset[sb+1]; i++){
-			requant[i] =  pow_quant[ABS(quant[i])] * invQuantFac; 
+			requant[i] =  pow_quant[min(ABS(quant[i]),8999)] * invQuantFac; 
 
 			/* measure the distortion in each scalefactor band */
 			linediff = (double)(ABS(p_spectrum[i]) - ABS(requant[i]));
@@ -643,7 +642,7 @@
 
 	/* Compute allowed distortion */
 	for(sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-		allowed_dist[MONO_CHAN][sb] = energy[MONO_CHAN][sb] * SigMaskRatio[sb];
+		allowed_dist[MONO_CHAN][sb] = energy[MONO_CHAN][sb] * SigMaskRatio[sb] * 2;
 //		if (allowed_dist[MONO_CHAN][sb] < ATH[sb]) {
 //			printf("%d Yes\n", sb);
 //			allowed_dist[MONO_CHAN][sb] = ATH[sb];
@@ -662,11 +661,9 @@
 		}
 	}
 
-	if (old_startsf == 0) {
-		if (max_dct_line!=0.0) {
-			old_startsf = 30 + (int)(16/3 * (log(ABS(pow(max_dct_line,0.75)/MAX_QUANT)/log(2.0))));
-		} else {
-			old_startsf = 40;
+	if (max_dct_line!=0.0) {
+		if ((int)(16/3 * (log(ABS(pow(max_dct_line,0.75)/MAX_QUANT)/log(2.0)))) > old_startsf) {
+			old_startsf = (int)(16/3 * (log(ABS(pow(max_dct_line,0.75)/MAX_QUANT)/log(2.0))));
 		}
 		if ((old_startsf > 200) || (old_startsf < 40))
 			old_startsf = 40;
@@ -899,7 +896,7 @@
 			double worstISMR = PsySigMaskRatio[bandNum];
 			int w=0;
 			for (w=0;w<window_group_length[i];w++) {
-				bandNum=w*NSFB_SHORT + k;
+				bandNum=(w+windowOffset)*NSFB_SHORT + k;
 				if (PsySigMaskRatio[bandNum]<worstISMR) {
 					worstISMR = (PsySigMaskRatio[bandNum] > 0)?PsySigMaskRatio[bandNum]:worstISMR;
 				}
--- a/aac_qc.h
+++ b/aac_qc.h
@@ -71,11 +71,10 @@
 
 void PulseCoder(AACQuantInfo *quantInfo, int *quant);
 void PulseDecoder(AACQuantInfo *quantInfo, int *quant);
-int quantize(AACQuantInfo *quantInfo,
-			 double *p_spectrum,
-			 double *pow_spectrum,
-			 int quant[NUM_COEFF]
-			 );
+void quantize(AACQuantInfo *quantInfo,
+			  double *pow_spectrum,
+			  int quant[NUM_COEFF]
+			  );
 void dequantize(AACQuantInfo *quantInfo,
 				double *p_spectrum,
 				int quant[NUM_COEFF],