shithub: aacenc

Download patch

ref: 9b4a10a773d6088483a61b6feb305c2396e67f41
parent: 9631e24e4afbacb183815dc25125657ae2ba7990
author: lenox <lenox>
date: Tue Feb 15 02:01:21 EST 2000

restructure (aacconfig eliminated)

--- a/aacenc.h
+++ b/aacenc.h
@@ -1,5 +1,4 @@
 
-
 typedef struct RCBufStruct RCBuf;	/* buffer handle */
 
 #define MAIN_PROFILE 0
@@ -8,23 +7,9 @@
 #define FNO_ERROR 0
 #define FERROR 1
 
-typedef struct {
-	int channels;      // Number of channels: Currently has to be 2
-	int in_sampling_rate; // Sampling rate of the input file
-	int out_sampling_rate; // Sampling rate of the output AAC file
-	int bit_rate;      // Bitrate: can be any bitrate higher than 16kbps in steps of 1kbps
-	int cut_off;       // Sets the cut_off frequency.
-	int profile;       // AAC Profile: can be MAIN_PROFILE or LOW_PROFILE
-	int write_header;  // If this is 1, a ADIF header will be written, if it is 0, no
-	                   //    header will be written. (better turn this on, because
-                       //    there is some bug when not using ADIF header)
-	int use_MS;        // If 1, MS stereo is on on all scalefactors, if 0 the intelligent switching is used
-	                   // if it is -1 MS is totally off.
-	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;
+#define NO_HEADER	0
+#define ADIF_HEADER     1
+#define ADTS_HEADER     2
 
 typedef struct {
 	int DLLMajorVersion; // These 2 values should always be checked, because the DLL
@@ -45,7 +30,7 @@
 	int in_sampling_rate;
 	int frame_bits;
 	int available_bits;
-	int write_header;
+        int header_type;
 	int use_MS;
 	int use_IS;
 	int use_TNS;
@@ -59,6 +44,7 @@
 	int savedSize;
 	float saved[2048];
 	int cut_off;
+	int bit_rate;
 } faacAACStream;
 
 #ifndef FAAC_DLL
@@ -84,7 +70,7 @@
 //               Later, after calling faacAACFree() the headerBuf should be written to this space in the AAC file.
 // Return value:
 //  faacAACStream structure that should be used in calls to other functions
-typedef faacAACStream* (*FAACENCODEINIT) (faacAACConfig *ac, int *samplesToRead, int *bitBufferSize, int *headerSize);
+typedef int (*FAACENCODEINIT) (faacAACStream *as, int *samplesToRead, int *bitBufferSize, int *headerSize);
 
 
 // int faacEncodeFrame(faacAACStream *as, short *Buffer, int Samples, unsigned char *bitBuffer,
--- a/enc.h
+++ b/enc.h
@@ -1,7 +1,7 @@
 /**********************************************************************
 Header file: enc.h
 
-$Id: enc.h,v 1.3 1999/12/20 14:28:02 lenox Exp $
+$Id: enc.h,v 1.4 2000/02/15 07:01:21 lenox Exp $
 
 Authors:
 HP    Heiko Purnhagen, Uni Hannover <purnhage@tnt.uni-hannover.de>
@@ -37,7 +37,7 @@
 /* EncTfInit() */
 /* Init t/f-based encoder core. */
 
-void EncTfInit (faacAACConfig *ac, int VBR_setting);
+void EncTfInit (faacAACStream *as, int VBR_setting);
 
 
 
--- a/enc_tf.c
+++ b/enc_tf.c
@@ -112,7 +112,7 @@
  ***
  ****************************************************************************************/
 
-void EncTfInit (faacAACConfig *ac, int VBR_setting)
+void EncTfInit (faacAACStream *as, int VBR_setting)
 {
 	int chanNum, i;
 	int SampleRates[] = {
@@ -122,8 +122,8 @@
 //		64000,80000,96000,112000,128000,160000,192000,224000,256000,0
 //	};
 
-	sampling_rate = ac->out_sampling_rate;
-	bit_rate = ac->bit_rate;
+	sampling_rate = as->out_sampling_rate;
+	bit_rate = as->bit_rate;
 
 	for (i = 0; ; i++)
 	{
@@ -136,18 +136,18 @@
 	profile = MAIN;
 	qc_select = AAC_PRED;           /* enable prediction */
 
-	if (ac->profile == LOW) {
+	if (as->profile == LOW) {
 		profile = LOW;
 		qc_select = AAC_QC;          /* disable prediction */
 	}
 
-	if (ac->use_PNS)
+	if (as->use_PNS)
 		pns_sfb_start = 0;
 	else
 		pns_sfb_start = 60;
 
 	/* set the return values */
-	max_ch = ac->channels;
+	max_ch = as->channels;
 
 	/* some global initializations */
 	for (chanNum=0;chanNum<MAX_TIME_CHANNELS;chanNum++) {
--- a/encoder.c
+++ b/encoder.c
@@ -19,66 +19,54 @@
 /* ---------- functions ---------- */
 
 
-faacAACStream *faacEncodeInit(faacAACConfig *ac, int *samplesToRead, int *bitBufferSize, int *headerSize)
+int faacEncodeInit(faacAACStream *as, int *samplesToRead, int *bitBufferSize, int *headerSize)
 {
 	int frameNumSample,delayNumSample;
 	int ch;
-	faacAACStream *as;
+//	faacAACStream *as;
 
 	int startupNumFrame;
 
-	as = malloc( sizeof(faacAACStream));
-	if ((as->inputBuffer = (double**)malloc( ac->channels*sizeof(double*)))==NULL)
+	if ((as->inputBuffer = (double**)malloc( as->channels*sizeof(double*)))==NULL)
 		return NULL;
-	for (ch=0; ch < ac->channels; ch++)
+	for (ch=0; ch < as->channels; ch++)
 	{
 		if ((as->inputBuffer[ch]=(double*)malloc( 1024*sizeof(double)))==NULL)
 			return NULL;
 	}
 
-	if((ac->bit_rate % 1000)||(ac->bit_rate < 16000)) {
+	if((as->bit_rate % 1000)||(as->bit_rate < 16000)) {
 		return NULL;
 	}
-	if (ac->channels != 2)
+	if (as->channels != 2)
 		return NULL;
-	if ((ac->profile != MAIN_PROFILE)&&(ac->profile != LOW_PROFILE))
+	if ((as->profile != MAIN_PROFILE)&&(as->profile != LOW_PROFILE))
 		return NULL;
 
 	as->total_bits = 0;
 	as->frames = 0;
 	as->cur_frame = 0;
-	as->channels = ac->channels;
-	as->out_sampling_rate = ac->out_sampling_rate;
-	as->in_sampling_rate = ac->in_sampling_rate;
-	as->write_header = ac->write_header;
-	as->cut_off = ac->cut_off;
-	as->use_MS = ac->use_MS;
-	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;
 
-	if (ac->in_sampling_rate != ac->out_sampling_rate)
+	if (as->in_sampling_rate != as->out_sampling_rate)
 		as->rc_needed = 1;
 	else
 		as->rc_needed = 0;
 
-	if (as->write_header) {
+	if (as->header_type==ADIF_HEADER) {
 		*headerSize = 17;
 	} else {
 		*headerSize = 0;
 	}
 
-	EncTfInit(ac, 0);
+	EncTfInit(as, 0);
 
 	frameNumSample = 1024;
 	delayNumSample = 2*frameNumSample;
 
-	*samplesToRead = frameNumSample * ac->channels;
+	*samplesToRead = frameNumSample * as->channels;
 
-	as->frame_bits = (int)(ac->bit_rate*frameNumSample/ac->out_sampling_rate+0.5);
+	as->frame_bits = (int)(as->bit_rate*frameNumSample/as->out_sampling_rate+0.5);
 	*bitBufferSize = (int)(((as->frame_bits * 5) + 7)/8);
 
 
@@ -106,7 +94,7 @@
 
 	as->savedSize = 0;
 
-	return as;
+	return 1;
 }
 
 int faacEncodeFrame(faacAACStream *as, short *Buffer, int Samples, unsigned char *bitBuffer, int *bitBufSize)
@@ -261,7 +249,7 @@
 	if (as->rc_needed)
 		RateConvFree (as->rc_buf);
 
-	if (as->write_header)
+	if (as->header_type==ADIF_HEADER)
 	{
 		int i;
 		static int SampleRates[] = {96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000,0};
@@ -328,7 +316,6 @@
 	for (ch=0; ch < as->channels; ch++)
 		if(as->inputBuffer[ch]) free(as->inputBuffer[ch]);
 	if(as->inputBuffer) free(as->inputBuffer);
-	if (as) free(as);
 
 	return FNO_ERROR;
 }
@@ -340,7 +327,7 @@
 	faacv->DLLMajorVersion = 2;
 	faacv->DLLMinorVersion = 20;
 	faacv->MajorVersion = 0;
-	faacv->MinorVersion = 61;
+	faacv->MinorVersion = 65;
 	strcpy(faacv->HomePage, "http://www.slimline.net/aac/");
 
 	return faacv;
@@ -435,7 +422,7 @@
 	int headerSize;
 	int i, frames, cfr;
 	int profile = MAIN_PROFILE;
-	int no_header = 0;
+        int header_type = ADIF_HEADER;
 	int use_IS = 0, use_MS = 0, use_TNS = 0, use_LTP = 1, use_PNS = 0;
 	int cut_off = 0;
 	int bit_rate = 128;
@@ -446,9 +433,9 @@
 	char *argp;
 	char *FileNames[200];
 	int FileCount = 0;
+        int res;
 
 	faacAACStream *as;
-	faacAACConfig ac;
 	faacVersion *faacv;
 
 	long begin, end;
@@ -455,6 +442,7 @@
 	int nTotSecs, nSecs;
 	int nMins;
 
+        as = malloc(sizeof(faacAACStream));
 	faacv = faacEncodeVersion();
 	printf("FAAC cl (Freeware AAC Encoder)\n");
 	printf("FAAC homepage: %s\n", faacv->HomePage);
@@ -530,8 +518,8 @@
 					use_MS = -1;
 				else if ((argv[i][2] == 'p') || (argv[i][2] == 'P'))
 					use_LTP = 0;
-				else
-					no_header = 1;
+				else if ((argv[i][2] == 'h') || (argv[i][2] == 'H'))
+					header_type = NO_HEADER;
 				break;
 			case 'm': case 'M':
 				use_MS = 1;
@@ -577,7 +565,7 @@
 	printf("Temporal Noise Shaping: %s.\n", use_TNS?"On":"Off");
 	printf("Long Term Prediction: %s.\n", use_LTP?"On":"Off");
 	printf("Perceptual Noise Substitution: %s.\n", use_PNS?"On":"Off");
-	printf("ADIF header: %s.\n", no_header?"Off":"On");
+//	printf("ADIF header: %s.\n", no_header?"Off":"On");
 	if (out_dir_set)
 		printf("Output directory: %s.\n", out_dir);
 	if (out_rate)
@@ -628,21 +616,21 @@
 			continue;
 		}
 
-		ac.channels = sf_info.channels;
-		ac.in_sampling_rate = sf_info.samplerate;
-		ac.out_sampling_rate = out_rate ? out_rate : sf_info.samplerate;
-		ac.bit_rate = bit_rate * 1000;
-		ac.cut_off = cut_off ? cut_off : (ac.out_sampling_rate>>1);
-		ac.profile = profile;
-		ac.use_MS = use_MS;
-		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->channels = sf_info.channels;
+		as->in_sampling_rate = sf_info.samplerate;
+		as->out_sampling_rate = out_rate ? out_rate : sf_info.samplerate;
+		as->bit_rate = bit_rate * 1000;
+		as->cut_off = cut_off ? cut_off : (as->out_sampling_rate>>1);
+		as->profile = profile;
+		as->use_MS = use_MS;
+		as->use_IS = use_IS;
+		as->use_TNS = use_TNS;
+		as->use_LTP = use_LTP;
+		as->use_PNS = use_PNS;
+		as->header_type = header_type;
 
-		as = faacEncodeInit(&ac, &readNumSample, &bitBufSize, &headerSize);
-		if (as == NULL) {
+		res = faacEncodeInit(as, &readNumSample, &bitBufSize, &headerSize);
+		if (res == NULL) {
 			printf("Error while encoding %s.\n", FileNames[i]);
 			continue;
 		}
@@ -652,7 +640,7 @@
 
 		if (headerSize > 0) {
 			memset(bitBuffer, 0, headerSize*sizeof(char));
-			// Skip headerSize bytes
+			// Skip headerSize bytes for ADIF header
 			// They should be written after calling faacEncodeFree
 			fwrite(bitBuffer, 1, headerSize, aacfile);
 		}
@@ -706,6 +694,7 @@
 		fclose(aacfile);
 		if (bitBuffer)  free(bitBuffer);
 		if (sampleBuffer)  free(sampleBuffer);
+                free(as);
 #ifdef WIN32
 		end = GetTickCount();
 #else