shithub: aacenc

Download patch

ref: 9d1738850bdf64dbb97fc4c215e0ddd8028b2669
parent: 06e3bf39a8ba9ce4beb189a421413c43afa9505e
author: menno <menno>
date: Wed Dec 15 19:23:38 EST 1999

Fixed bug with bitBuffer and better ADIF header writing

--- a/encoder.c
+++ b/encoder.c
@@ -547,17 +547,15 @@
 			continue;
 		}
 
+		bitBuffer = malloc((bitBufSize+100)*sizeof(char));
+
 		if (headerSize > 0) {
-			bitBuffer = malloc(headerSize*sizeof(char));
 			memset(bitBuffer, 0, headerSize*sizeof(char));
 			// Skip headerSize bytes
 			// They should be written after calling faacEncodeFree
 			fwrite(bitBuffer, 1, headerSize, aacfile);
-			if (bitBuffer) { free(bitBuffer); bitBuffer = NULL; }
 		}
 
-		bitBuffer = malloc(bitBufSize*sizeof(char));
-
 		cfr = 0;
 
 		// Keep encoding frames until the end of the audio file
@@ -592,8 +590,6 @@
 
 		sf_close(sndfile);
 
-		fclose(aacfile);
-
 		error = faacEncodeFree(as, bitBuffer);
 		if (error == FERROR) {
 			printf("Error while encoding %s.\n", FileNames[i]);
@@ -602,11 +598,11 @@
 
 		// Write the header to the beginning of the file now
 		if (headerSize > 0) {
-			aacfile = fopen(aac_fn, "rb+");
+			fseek(aacfile, 0, SEEK_SET);
 			fwrite(bitBuffer, 1, headerSize, aacfile);
-			fclose(aacfile);
 		}
 
+		fclose(aacfile);
 		if (bitBuffer) { free(bitBuffer); bitBuffer = NULL; }
 
 #ifdef WIN32