shithub: aacenc

Download patch

ref: fa41e69553cba9dfbd524684c11381b7d3d7bef9
parent: 40499425d7189ec3a093b8b8e7e330074d0c9283
author: menno <menno>
date: Fri Jan 14 09:23:17 EST 2000

First attempt at doing PNS (use -pns). Also every bitrate higher than 16kbps is now supported in step of 1kbps

--- a/aac_qc.c
+++ b/aac_qc.c
@@ -425,6 +425,22 @@
 		}
     } 
 
+	/* initialize the scale_factors that aren't intensity stereo bands */
+	is_info=&(ch_info->is_info);
+	for(k=0; k< quantInfo -> nr_of_sfb ;k++) {
+		scale_factor[k]=((is_info->is_present)&&(is_info->is_used[k])) ? scale_factor[k] : 0;
+	}
+
+	/* Mark IS bands by setting book_vector to INTENSITY_HCB */
+	ptr_book_vector=quantInfo->book_vector;
+	for (k=0;k<quantInfo->nr_of_sfb;k++) {
+		if ((is_info->is_present)&&(is_info->is_used[k])) {
+			ptr_book_vector[k] = (is_info->sign[k]) ? INTENSITY_HCB2 : INTENSITY_HCB;
+		} else {
+			ptr_book_vector[k] = 0;
+		}
+	}
+
 	/* PNS prepare */
     for(sb=0; sb < quantInfo->nr_of_sfb; sb++ )
 		quantInfo->pns_sfb_flag[sb] = 0;
@@ -436,13 +452,15 @@
 				quantInfo->pns_sfb_flag[sb] = 0;
 				continue;
 			}
-			
-			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 ((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;
+				}
 			}
 		}
     }
@@ -449,16 +467,12 @@
 
 	/* Compute allowed distortion */
 	for(sb = 0; sb < quantInfo->nr_of_sfb; sb++) {
-		if (10*log10(energy[MONO_CHAN][sb]*sfb_width_table[0][sb]+1e-60)>70) {
-			allowed_dist[MONO_CHAN][sb] = energy[MONO_CHAN][sb] * SigMaskRatio[sb];
-//			if (allowed_dist[MONO_CHAN][sb] < ATH[sb]) {
-//				printf("%d Yes\n", sb);
-//				allowed_dist[MONO_CHAN][sb] = ATH[sb];
-//			}
-//			printf("%d\t\t%.3f\n", sb, SigMaskRatio[sb]);
-		} else {
-			allowed_dist[MONO_CHAN][sb] = energy[MONO_CHAN][sb] * 1.1;
-		}
+		allowed_dist[MONO_CHAN][sb] = energy[MONO_CHAN][sb] * SigMaskRatio[sb];
+//		if (allowed_dist[MONO_CHAN][sb] < ATH[sb]) {
+//			printf("%d Yes\n", sb);
+//			allowed_dist[MONO_CHAN][sb] = ATH[sb];
+//		}
+//		printf("%d\t\t%.3f\n", sb, SigMaskRatio[sb]);
 	}
 
 	/** find the maximum spectral coefficient **/
@@ -483,22 +497,6 @@
 	}
 	if ((start_com_sf>200) || (start_com_sf<40) )
 		start_com_sf = 40;
-
-	/* initialize the scale_factors that aren't intensity stereo bands */
-	is_info=&(ch_info->is_info);
-	for(k=0; k< quantInfo -> nr_of_sfb ;k++) {
-		scale_factor[k]=((is_info->is_present)&&(is_info->is_used[k])) ? scale_factor[k] : 0;
-	}
-
-	/* Mark IS bands by setting book_vector to INTENSITY_HCB */
-	ptr_book_vector=quantInfo->book_vector;
-	for (k=0;k<quantInfo->nr_of_sfb;k++) {
-		if ((is_info->is_present)&&(is_info->is_used[k])) {
-			ptr_book_vector[k] = (is_info->sign[k]) ? INTENSITY_HCB2 : INTENSITY_HCB;
-		} else {
-			ptr_book_vector[k] = 0;
-		}
-	}
 
 	outer_loop_count = 0;
 
--- a/aacenc.h
+++ b/aacenc.h
@@ -20,6 +20,7 @@
 	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
 	int use_LTP;       // If 1, LTP is on, if 0, it is off
+	int use_PNS;       // If 1, PNS is on, if 0, it is off
 } faacAACConfig;
 
 // This structure is for internal use of the encoder only.
@@ -37,6 +38,7 @@
 	int use_IS;
 	int use_TNS;
 	int use_LTP;
+	int use_PNS;
 	int profile;
 	double **inputBuffer;
 } faacAACStream;
--- a/enc_tf.c
+++ b/enc_tf.c
@@ -138,7 +138,10 @@
 		qc_select = AAC_QC;          /* disable prediction */
 	}
 
-	pns_sfb_start = 60;
+	if (ac->use_PNS)
+		pns_sfb_start = 0;
+	else
+		pns_sfb_start = 60;
 
 	/* set the return values */
 	max_ch = ac->channels;
--- a/encoder.c
+++ b/encoder.c
@@ -37,18 +37,7 @@
 
 //	if (ac->sampling_rate != 44100)
 //		return NULL;
-	switch (ac->bit_rate) {
-	case 64000:
-	case 80000:
-	case 96000:
-	case 112000:
-	case 128000:
-	case 160000:
-	case 192000:
-	case 224000:
-	case 256000:
-		break;
-	default:
+	if((ac->bit_rate % 1000)||(ac->bit_rate < 16000)) {
 		return NULL;
 	}
 	if (ac->channels != 2)
@@ -66,6 +55,7 @@
 	as->use_IS = ac->use_IS;
 	as->use_TNS = ac->use_TNS;
 	as->use_LTP = ac->use_LTP;
+	as->use_PNS = ac->use_PNS;
 	as->profile = ac->profile;
 	as->is_first_frame = 1;
 
@@ -281,7 +271,7 @@
 	faacVersion *faacv = malloc(sizeof(faacVersion));
 
 	faacv->DLLMajorVersion = 2;
-	faacv->DLLMinorVersion = 10;
+	faacv->DLLMinorVersion = 15;
 	faacv->MajorVersion = 0;
 	faacv->MinorVersion = 55;
 	strcpy(faacv->HomePage, "http://www.slimline.net/aac/");
@@ -340,8 +330,9 @@
 	printf("Options:\n");
 	printf(" -h    Shows this help screen.\n");
 	printf(" -pX   AAC profile (X can be LOW, or MAIN (default).\n");
-	printf(" -bX   Bitrate in kbps (X can be: 64, 80, 96, 112, 128 (default),\n");
-	printf("       160, 192, 224 or 256).\n");
+	printf(" -bX   Bitrate in kbps (in steps of 1kbps, min. 16kbps)\n");
+	printf(" -pns  Use PNS (Perceptual Noise Substitution).\n");
+	printf(" -is   Use intensity stereo coding.\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");
@@ -348,7 +339,6 @@
 	printf(" -nt   Don't use TNS (Temporal Noise Shaping).\n");
 	printf(" -np   Don't use LTP (Long Term Prediction).\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");
 	printf(" file  Multiple files can be given as well as wild cards.\n");
@@ -377,7 +367,7 @@
 	int i, frames, cfr;
 	int profile = MAIN_PROFILE;
 	int no_header = 0;
-	int use_IS = 0, use_MS = 0, use_TNS = 1, use_LTP = 1;
+	int use_IS = 0, use_MS = 0, use_TNS = 1, use_LTP = 1, use_PNS = 0;
 	int bit_rate = 128;
 	char out_dir[255];
 	int out_dir_set = 0;
@@ -457,7 +447,9 @@
 			switch(argv[i][1]) {
 			case 'p':
 			case 'P':
-				if (argv[i][2] == 'l' || 'L')
+				if (argv[i][2] == 'n' || 'N')
+					use_PNS = 1;
+				else if (argv[i][2] == 'l' || 'L')
 					profile = LOW_PROFILE;
 				else
 					profile = MAIN_PROFILE;
@@ -556,6 +548,7 @@
 		ac.use_IS = use_IS;
 		ac.use_TNS = use_TNS;
 		ac.use_LTP = use_LTP;
+		ac.use_PNS = use_PNS;
 		ac.write_header = !no_header;
 
 		as = faacEncodeInit(&ac, &readNumSample, &bitBufSize, &headerSize);