shithub: aacenc

Download patch

ref: 5b66a8ca04e73b7c495eb23ab546ee02863ac366
parent: 2665b6d84f8d760080aa854fb931efdf2d645ed8
author: menno <menno>
date: Tue Mar 6 09:01:36 EST 2001

Fix in reconstruction of spectrum before LTP buffer update

--- a/libfaac/aacquant.c
+++ b/libfaac/aacquant.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: aacquant.c,v 1.5 2001/03/05 11:33:37 menno Exp $
+ * $Id: aacquant.c,v 1.6 2001/03/06 14:01:36 menno Exp $
  */
 
 #include <math.h>
@@ -507,7 +507,7 @@
 		error_energy[sb] = 0.0;
 
 		for (i = coderInfo->sfb_offset[sb]; i < coderInfo->sfb_offset[sb+1]; i++){
-			requant_xr[i] =  pow43[xi[i]] * invQuantFac; 
+			requant_xr[i] = pow43[xi[i]] * invQuantFac; 
 
 			/* measure the distortion in each scalefactor band */
 			linediff = fabs(xr[i]) - requant_xr[i];
--- 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.12 2001/03/05 11:36:14 menno Exp $
+ * $Id: frame.c,v 1.13 2001/03/06 14:01:36 menno Exp $
  */
 
 /*
@@ -371,40 +371,43 @@
 		}
 	}
 
+	MSReconstruct(coderInfo, channelInfo, numChannels);
+
 	for (channel = 0; channel < numChannels; channel++) 
 	{
-		if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
-			tnsDecInfo = &(coderInfo[channel].tnsInfo);
-		else
-			tnsDecInfo = NULL;
-		
-		if ((!channelInfo[channel].lfe) && (useLtp)) {  /* no reconstruction needed for LFE channel*/
+		/* If short window, reconstruction not needed for prediction */
+		if ((coderInfo[channel].block_type == ONLY_SHORT_WINDOW)) {
+			int sind;
+			for (sind = 0; sind < 1024; sind++) {
+				coderInfo[channel].requantFreq[sind] = 0.0;
+			}
+		} else {
 
-			LtpReconstruct(&coderInfo[channel], &(coderInfo[channel].ltpInfo),
-				coderInfo[channel].requantFreq);
+			if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
+				tnsDecInfo = &(coderInfo[channel].tnsInfo);
+			else
+				tnsDecInfo = NULL;
+			
+			if ((!channelInfo[channel].lfe) && (useLtp)) {  /* no reconstruction needed for LFE channel*/
 
-			if(tnsDecInfo != NULL)
-				TnsDecodeFilterOnly(&(coderInfo[channel].tnsInfo), coderInfo[channel].nr_of_sfb,
+				LtpReconstruct(&coderInfo[channel], &(coderInfo[channel].ltpInfo),
+					coderInfo[channel].requantFreq);
+
+				if(tnsDecInfo != NULL)
+					TnsDecodeFilterOnly(&(coderInfo[channel].tnsInfo), coderInfo[channel].nr_of_sfb,
 					coderInfo[channel].max_sfb, coderInfo[channel].block_type,
 					coderInfo[channel].sfb_offset, coderInfo[channel].requantFreq);
 
-			IFilterBank(hEncoder, &coderInfo[channel],
-				coderInfo[channel].requantFreq,
-				coderInfo[channel].ltpInfo.time_buffer,
-				coderInfo[channel].ltpInfo.ltp_overlap_buffer,
-				MOVERLAPPED);
+				IFilterBank(hEncoder, &coderInfo[channel],
+					coderInfo[channel].requantFreq,
+					coderInfo[channel].ltpInfo.time_buffer,
+					coderInfo[channel].ltpInfo.ltp_overlap_buffer,
+					MOVERLAPPED);
 
-			LtpUpdate(&(coderInfo[channel].ltpInfo),
-				coderInfo[channel].ltpInfo.time_buffer,
-				coderInfo[channel].ltpInfo.ltp_overlap_buffer,
-				BLOCK_LEN_LONG);
-		}
-
-		/* If short window, reconstruction not needed for prediction */
-		if ((coderInfo[channel].block_type == ONLY_SHORT_WINDOW)) {
-			int sind;
-			for (sind = 0; sind < 1024; sind++) {
-				coderInfo[channel].requantFreq[sind] = 0.0;
+				LtpUpdate(&(coderInfo[channel].ltpInfo),
+					coderInfo[channel].ltpInfo.time_buffer,
+					coderInfo[channel].ltpInfo.ltp_overlap_buffer,
+					BLOCK_LEN_LONG);
 			}
 		}
 	}
--- 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.6 2001/03/05 11:33:37 menno Exp $
+ * $Id: frame.h,v 1.7 2001/03/06 14:01:36 menno Exp $
  */
 
 #ifndef FRAME_H
@@ -99,6 +99,8 @@
 	double *kbd_window_short;
 	double *freqBuff[MAX_CHANNELS];
 	double *overlapBuff[MAX_CHANNELS];
+
+	double *msSpectrum[MAX_CHANNELS];
 
 	/* Channel and Coder data for all channels */
 	CoderInfo coderInfo[MAX_CHANNELS];
--- a/libfaac/joint.c
+++ b/libfaac/joint.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: joint.c,v 1.3 2001/02/28 18:39:34 menno Exp $
+ * $Id: joint.c,v 1.4 2001/03/06 14:01:36 menno Exp $
  */
 
 #include "channels.h"
@@ -86,8 +86,8 @@
 								for (w=startWindow;w<stopWindow;w++) {
 									if (msInfoL->ms_usedS[w][sfbNum]) {
 										for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
-										lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
-										lineNum++)
+											 lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
+											 lineNum++)
 										{
 											line_offset = w*BLOCK_LEN_SHORT;
 											sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
@@ -107,8 +107,8 @@
 							/* Enable MS mask */
 							if (msInfoL->ms_used[sfbNum]) {
 								for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
-								lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
-								lineNum++)
+									 lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
+									 lineNum++)
 								{
 									sum=spectrum[leftChan][lineNum]+spectrum[rightChan][lineNum];
 									diff=spectrum[leftChan][lineNum]-spectrum[rightChan][lineNum];
@@ -124,3 +124,51 @@
 	}
 }
 
+void MSReconstruct(CoderInfo *coderInfo,
+				   ChannelInfo *channelInfo,
+				   int numberOfChannels)
+{
+	int chanNum;
+	int sfbNum;
+	int lineNum;
+	double sum,diff;
+
+	/* Look for channel_pair_elements */
+	for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+		if (channelInfo[chanNum].present) {
+			if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
+				int leftChan=chanNum;
+				int rightChan=channelInfo[chanNum].paired_ch;
+
+				MSInfo *msInfoL;
+				msInfoL = &(channelInfo[leftChan].msInfo);
+				if (msInfoL->is_present) {
+					int numGroups = coderInfo[leftChan].num_window_groups;
+					int maxSfb = coderInfo[leftChan].max_sfb;
+					int w,line_offset;
+					int startWindow;
+					w=0;
+
+					line_offset=0;
+					startWindow = 0;
+					if (coderInfo[leftChan].block_type != ONLY_SHORT_WINDOW) {
+						for (sfbNum = 0;sfbNum < maxSfb; sfbNum++) {
+
+							if (msInfoL->ms_used[sfbNum]) {
+								for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
+									 lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
+									 lineNum++)
+								{
+									sum=coderInfo[leftChan].requantFreq[lineNum];
+									diff=coderInfo[rightChan].requantFreq[lineNum];
+									coderInfo[leftChan].requantFreq[lineNum] = (sum+diff);
+									coderInfo[rightChan].requantFreq[lineNum] = (sum-diff);
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+}
--- a/libfaac/joint.h
+++ b/libfaac/joint.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: joint.h,v 1.2 2001/01/23 13:23:04 menno Exp $
+ * $Id: joint.h,v 1.3 2001/03/06 14:01:36 menno Exp $
  */
 
 #ifndef JOINT_H
@@ -31,6 +31,7 @@
 
 void MSEncode(CoderInfo *coderInfo, ChannelInfo *channelInfo, double *spectrum[MAX_CHANNELS],
 			  unsigned int numberOfChannels, unsigned int msenable);
+void MSReconstruct(CoderInfo *coderInfo, ChannelInfo *channelInfo, int numberOfChannels);
 
 #ifdef __cplusplus
 }
--- 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.7 2001/02/28 18:39:34 menno Exp $
+ * $Id: psych.c,v 1.8 2001/03/06 14:01:36 menno Exp $
  */
 
 #include <malloc.h>
@@ -168,7 +168,7 @@
 		for (bb = 0; bb < gpsyInfo->psyPart->width[b]; bb++, j++) {
 			double freq = gpsyInfo->sampleRate*j/(1000.0*2*size);
 			double level;
-			level = ATHformula(freq*1000) - 20;
+			level = ATHformula(freq*1000.0) - 20.0;
 			level = pow(10., 0.1*level);
 			level *= gpsyInfo->psyPart->width[b];
 			if (level < gpsyInfo->ath[b])
@@ -235,7 +235,7 @@
 		for (bb = 0; bb < gpsyInfo->psyPartS->width[b]; bb++, j++) {
 			double freq = gpsyInfo->sampleRate*j/(1000.0*2*size);
 			double level;
-			level = ATHformula(freq*1000) - 20;
+			level = ATHformula(freq*1000.0) - 20.0;
 			level = pow(10., 0.1*level);
 			level *= gpsyInfo->psyPartS->width[b];
 			if (level < gpsyInfo->athS[b])