shithub: aacenc

Download patch

ref: 11af283c2493c1b03adcc5d668f4b1a415178883
parent: 7edc234f6ddb73047ee23397aa52b2e5af2471bc
author: menno <menno>
date: Fri Nov 10 08:27:06 EST 2000

Bugfix in psychoacoustics and window shape switching changed

--- a/enc_tf.c
+++ b/enc_tf.c
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.68 $
-  $Date: 2000/11/07 20:03:18 $ (check in)
+  $Revision: 1.69 $
+  $Date: 2000/11/10 13:27:06 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -261,7 +261,7 @@
 
   /* initialize spectrum processing */
   /* initialize quantization and coding */
-  tf_init_encode_spectrum_aac(0);
+  aacQuantizeInit(0);
 
   /* Init TNS */
   for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
@@ -271,7 +271,7 @@
   /* Init LTP predictor */
   for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
     init_lt_pred (&quantInfo[chanNum].ltpInfo);
-    quantInfo[chanNum].prev_window_shape = WS_SIN;
+    quantInfo[chanNum].window_shape = WS_SIN;
   }
 
   for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
@@ -454,28 +454,33 @@
 //	block_type[1] = ONLY_SHORT_WINDOW;
 
   {
+	  int chanNum;
+
+	  for (chanNum = 0; chanNum < max_ch; chanNum++) {
+		  /* Set window shape paremeter in quantInfo */
+		  switch( block_type[chanNum] ) {
+		  case ONLY_SHORT_WINDOW:
+		  case LONG_SHORT_WINDOW:
+			  quantInfo[chanNum].prev_window_shape = quantInfo[chanNum].window_shape;
+			  quantInfo[chanNum].window_shape = WS_SIN;
+			  break;
+		  case ONLY_LONG_WINDOW:
+		  case SHORT_LONG_WINDOW:
+			  quantInfo[chanNum].prev_window_shape = quantInfo[chanNum].window_shape;
+			  quantInfo[chanNum].window_shape = WS_KBD;
+			  break;
+		  }
+	  }
+  }
+
+  {
     int chanNum;
 
     for (chanNum=0;chanNum<max_ch;chanNum++) {
-      /* Set window shape paremeter in quantInfo */
-      quantInfo[chanNum].prev_window_shape = quantInfo[chanNum].window_shape;
-      if (block_type[chanNum] == ONLY_SHORT_WINDOW)
-		  quantInfo[chanNum].window_shape = WS_KBD;
-	  else
-		  quantInfo[chanNum].window_shape = WS_SIN;
-
       switch( block_type[chanNum] ) {
-        case ONLY_SHORT_WINDOW  :
-//      no_sub_win   = short_win_in_long;
-//      sub_win_size = block_size_samples/short_win_in_long;
+        case ONLY_SHORT_WINDOW:
+
         quantInfo[chanNum].max_sfb = max_sfb_s[quantInfo[chanNum].srate_idx];
-#if 0
-        quantInfo[chanNum].num_window_groups = 4;
-        quantInfo[chanNum].window_group_length[0] = 1;
-        quantInfo[chanNum].window_group_length[1] = 2;
-        quantInfo[chanNum].window_group_length[2] = 3;
-        quantInfo[chanNum].window_group_length[3] = 2;
-#else
         quantInfo[chanNum].num_window_groups = 8;
         quantInfo[chanNum].window_group_length[0] = 1;
         quantInfo[chanNum].window_group_length[1] = 1;
@@ -485,12 +490,9 @@
         quantInfo[chanNum].window_group_length[5] = 1;
         quantInfo[chanNum].window_group_length[6] = 1;
         quantInfo[chanNum].window_group_length[7] = 1;
-#endif
         break;
 
         default:
-//      no_sub_win   = 1;
-//      sub_win_size = block_size_samples;
         quantInfo[chanNum].max_sfb = max_sfb_l[quantInfo[chanNum].srate_idx];
         quantInfo[chanNum].num_window_groups = 1;
         quantInfo[chanNum].window_group_length[0]=1;
@@ -736,7 +738,8 @@
 		  }
 	  }
 
-      error = tf_encode_spectrum_aac(&spectral_line_vector[chanNum],
+      error = aacQuantize(&quantInfo[chanNum],
+		  &spectral_line_vector[chanNum],
 		  &p_ratio[chanNum],
 		  &allowed_distortion[chanNum],
 		  &energy[chanNum],
@@ -744,8 +747,7 @@
 		  &sfb_width_table[chanNum],
 		  bitsToUse,
 		  fixed_stream,
-		  &reconstructed_spectrum[chanNum],		  
-		  &quantInfo[chanNum]
+		  &reconstructed_spectrum[chanNum]		  
 		  );
       if (error == FERROR)
         return error;
--- a/psych.c
+++ b/psych.c
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.72 $
-  $Date: 2000/11/01 14:05:32 $ (check in)
+  $Revision: 1.73 $
+  $Date: 2000/11/10 13:27:06 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -355,7 +355,7 @@
 		if (quantInfo[chanNum].channelInfo.present) {
 			p_sri = quantInfo[chanNum].sr_info;
 			
-			if ((quantInfo[chanNum].channelInfo.cpe) && (quantInfo[chanNum].channelInfo.ch_is_left)) { /* CPE */
+			if (quantInfo[chanNum].channelInfo.cpe && quantInfo[chanNum].channelInfo.ch_is_left) { /* CPE */
 				int leftChan = chanNum;
 				int rightChan = quantInfo[chanNum].channelInfo.paired_ch;
 				int midChan = chanNum + MAX_TIME_CHANNELS;
@@ -485,7 +485,7 @@
 					memcpy(p_chpo_short[rightChan][i].use_ms, psy_stvar_short[rightChan].use_ms[i], NSFB_SHORT*sizeof(int));
 				}
 
-			} else if (quantInfo[chanNum].channelInfo.lfe) { /* LFE */
+			} else if (!quantInfo[chanNum].channelInfo.cpe && quantInfo[chanNum].channelInfo.lfe) { /* LFE */
 
 				// LFE psych ratios are set to -24 dB for low frequencies
 				for (i = 0; i < 10; i++) {
@@ -503,7 +503,7 @@
 					p_chpo_short[chanNum][i].p_ratio  = psy_stvar_short[chanNum].ismr[i];
 				}
 
-			} else { /* SCE */
+			} else if (!quantInfo[chanNum].channelInfo.cpe) { /* SCE */
 
 				psy_step1(p_time_signal, sample, chanNum);
 				psy_step2(sample, &psy_stvar_long[chanNum], &psy_stvar_short[chanNum],
@@ -784,7 +784,7 @@
 			psy_var_short[midChan].c[i][b] = psy_var_short[sideChan].c[i][b] = min(psy_var_short[leftChan].c[i][b], psy_var_short[rightChan].c[i][b]);
 }
 
-/* caluculation of energy and unpredictability in each partition */
+/* calculation of energy and unpredictability in each partition */
 void psy_step5(PARTITION_TABLE_LONG *part_tbl_long,
 			   PARTITION_TABLE_SHORT *part_tbl_short,
 			   PSY_STATVARIABLE_LONG *psy_stvar_long,
@@ -879,7 +879,7 @@
 	}
 }
 
-/* caluculation of tonality in each partition */
+/* calculation of tonality in each partition */
 void psy_step7(PARTITION_TABLE_LONG *part_tbl_long,
 	       PARTITION_TABLE_SHORT *part_tbl_short,
 	       PSY_VARIABLE_LONG *psy_var_long, 
--- a/quant.c
+++ b/quant.c
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.13 $
-  $Date: 2000/11/07 20:03:18 $ (check in)
+  $Revision: 1.14 $
+  $Date: 2000/11/10 13:27:06 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -95,7 +95,7 @@
 }
 
 
-void tf_init_encode_spectrum_aac( int quality )
+void aacQuantizeInit(int quality)
 {
 	int i;
 
@@ -522,7 +522,6 @@
 
 	/* calculate the amount of bits needed for encoding the huffman codebook numbers */
 	bits += sort_book_numbers(quantInfo,             /* Quantization information */
-//		output_book_vector,    /* Output codebook vector, formatted for bitstream */
 		NULL,          /* Bitstream */
 		0);                    /* Write flag: 0 count, 1 write */
 
@@ -568,18 +567,17 @@
 	return bits;
 }
 
-int tf_encode_spectrum_aac(
-			   double      *p_spectrum[MAX_TIME_CHANNELS],
-			   double      *PsySigMaskRatio[MAX_TIME_CHANNELS],
-			   double      allowed_dist[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			   double      energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			   enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS],
-			   int         sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			   int         average_block_bits,
-			   BsBitStream *fixed_stream,
-			   double      *p_reconstructed_spectrum[MAX_TIME_CHANNELS],
-			   AACQuantInfo* quantInfo      /* AAC quantization information */ 
-			   )
+int aacQuantize(AACQuantInfo* quantInfo,      /* AAC quantization information */
+				double      *p_spectrum[MAX_TIME_CHANNELS],
+				double      *PsySigMaskRatio[MAX_TIME_CHANNELS],
+				double      allowed_dist[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
+				double      energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
+				enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS],
+				int         sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
+				int         average_block_bits,
+				BsBitStream *fixed_stream,
+				double      *p_reconstructed_spectrum[MAX_TIME_CHANNELS]
+				)
 {
 	int quant[BLOCK_LEN_LONG];
 	int s_quant[BLOCK_LEN_LONG];
--- a/quant.h
+++ b/quant.h
@@ -21,8 +21,8 @@
 /**************************************************************************
   Version Control Information			Method: CVS
   Identifiers:
-  $Revision: 1.8 $
-  $Date: 2000/11/07 20:03:18 $ (check in)
+  $Revision: 1.9 $
+  $Date: 2000/11/10 13:27:06 $ (check in)
   $Author: menno $
   *************************************************************************/
 
@@ -127,24 +127,23 @@
 /*********************************************************/
 /* tf_init_encode_spectrum_aac                           */
 /*********************************************************/
-void tf_init_encode_spectrum_aac( int quality );
+void aacQuantizeInit(int quality);
 
 
 /*********************************************************/
 /* tf_encode_spectrum_aac                                */
 /*********************************************************/
-int tf_encode_spectrum_aac(
-			   double      *p_spectrum[MAX_TIME_CHANNELS],
-			   double      *SigMaksRatio[MAX_TIME_CHANNELS],
-			   double      allowed_dist[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			   double      energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			   enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS],
-			   int         sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
-			   int         average_block_bits,
-			   BsBitStream *fixed_stream,
-			   double      *p_reconstructed_spectrum[MAX_TIME_CHANNELS],
-			   AACQuantInfo* quantInfo      /* AAC quantization information */
-			   );
+int aacQuantize(AACQuantInfo* quantInfo,      /* AAC quantization information */
+				double      *p_spectrum[MAX_TIME_CHANNELS],
+				double      *SigMaksRatio[MAX_TIME_CHANNELS],
+				double      allowed_dist[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
+				double      energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
+				enum WINDOW_TYPE block_type[MAX_TIME_CHANNELS],
+				int         sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],
+				int         average_block_bits,
+				BsBitStream *fixed_stream,
+				double      *p_reconstructed_spectrum[MAX_TIME_CHANNELS]			   
+				);