shithub: aacenc

Download patch

ref: a406642c783fc7d3bbbb1531f1e309e98008de96
parent: f1da21d5b79294f24d55fc5ea8aaa6ff0a076987
author: menno <menno>
date: Wed Jan 17 10:51:15 EST 2001

Added frequency cut off filter

--- a/frontend/main.c
+++ b/frontend/main.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: main.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ * $Id: main.c,v 1.2 2001/01/17 15:51:15 menno Exp $
  */
 
 #ifdef _WIN32
@@ -69,6 +69,7 @@
 		printf("USAGE: %s -options infile outfile\n", argv[0]);
 		printf("Options:\n");
 		printf("  -nm   Don\'t use mid/side coding\n");
+		printf("  -bwX  Set the bandwidth, X in Hz\n");
 		printf("  -brX  Set the bitrate per channel, X in bps\n\n");
 		return 1;
 	}
@@ -119,6 +120,12 @@
 						if (bitrate)
 						{
 							myFormat->bitRate = bitrate;
+						}
+					} else if ((argv[i][2] == 'w') || (argv[i][2] == 'W')) {
+						unsigned int bandwidth = atol(&argv[i][3]);
+						if (bandwidth)
+						{
+							myFormat->bandWidth = bandwidth;
 						}
 					}
 				break;
--- a/frontend/usage.txt
+++ b/frontend/usage.txt
@@ -7,4 +7,5 @@
 
 options:
 -nm   Don't use mid/side coding
+-bwX  Use bandwidth X, this is in Hz
 -brX  Use bitrate X, this is in bps/channel
--- a/include/faac.h
+++ b/include/faac.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: faac.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ * $Id: faac.h,v 1.2 2001/01/17 15:51:15 menno Exp $
  */
 
 #ifndef FAACLIB_H
@@ -50,6 +50,9 @@
 
 	/* bitrate / channel of AAC file */
 	unsigned long bitRate;
+
+	/* AAC file frequency bandwidth */
+	unsigned int bandWidth;
 
 } faacEncConfiguration, *faacEncConfigurationPtr;
 
--- a/libfaac/filtbank.c
+++ b/libfaac/filtbank.c
@@ -16,9 +16,15 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * $Id: filtbank.c,v 1.1 2001/01/17 11:21:40 menno Exp $
+ * $Id: filtbank.c,v 1.2 2001/01/17 15:51:15 menno Exp $
  */
 
+/*
+ * CHANGES:
+ *  2001/01/17: menno: Added frequency cut off filter.
+ *
+ */
+
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -166,6 +172,21 @@
 	}
 
 	if (transf_buf) free(transf_buf);
+}
+
+void specFilter(double *freqBuff,
+				int sampleRate,
+				int lowpassFreq,
+				int specLen
+				)
+{
+	int lowpass,xlowpass;
+
+	/* calculate the last line which is not zero */
+	lowpass = (lowpassFreq * specLen) / (sampleRate>>1) + 1;
+	xlowpass = (lowpass < specLen) ? lowpass : specLen ;
+
+	memset(freqBuff+xlowpass,0,(specLen-xlowpass)*sizeof(double));
 }
 
 static void MDCT(double *data, int N)
--- a/libfaac/filtbank.h
+++ b/libfaac/filtbank.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: filtbank.h,v 1.1 2001/01/17 11:21:40 menno Exp $
+ * $Id: filtbank.h,v 1.2 2001/01/17 15:51:15 menno Exp $
  */
 
 #ifndef FILTBANK_H
@@ -51,6 +51,12 @@
 				double *p_in_data,
 				double *p_out_mdct,
 				double *p_overlap);
+
+void specFilter(double *freqBuff,
+				int sampleRate,
+				int lowpassFreq,
+				int specLen
+				);
 
 static void MDCT(double *data, int N);
 static void IMDCT(double *data, int N);
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -16,9 +16,15 @@
  * 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.1 2001/01/17 11:21:40 menno Exp $
+ * $Id: frame.c,v 1.2 2001/01/17 15:51:15 menno Exp $
  */
 
+/*
+ * CHANGES:
+ *  2001/01/17: menno: Added frequency cut off filter.
+ *
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <memory.h>
@@ -71,6 +77,7 @@
 	hEncoder->config.allowMidside = 1;
 	hEncoder->config.useLfe = 0;
 	hEncoder->config.bitRate = 64000; /* default bitrate / channel */
+	hEncoder->config.bandWidth = 18000; /* default bandwidth */
 
 	/* find correct sampling rate depending parameters */
 	hEncoder->srInfo = &srInfo[hEncoder->sampleRateIdx];
@@ -140,6 +147,7 @@
 	unsigned int useLfe = hEncoder->config.useLfe;
 	unsigned int allowMidside = hEncoder->config.allowMidside;
 	unsigned int bitRate = hEncoder->config.bitRate;
+	unsigned int bandWidth = hEncoder->config.bandWidth;
 
 	/* Increase frame number */
 	hEncoder->frameNum++;
@@ -194,11 +202,23 @@
 
 	/* AAC Filterbank, MDCT with overlap and add */
 	for (channel = 0; channel < numChannels; channel++) {
+		int k;
+
 		FilterBank(hEncoder,
 			&coderInfo[channel],
 			hEncoder->sampleBuff[channel],
 			hEncoder->freqBuff[channel],
 			hEncoder->overlapBuff[channel]);
+
+		if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
+			for (k = 0; k < 8; k++) {
+				specFilter(hEncoder->freqBuff[channel]+k*BLOCK_LEN_SHORT,
+					sampleRate, bandWidth, BLOCK_LEN_SHORT);
+			}
+		} else {
+			specFilter(hEncoder->freqBuff[channel], sampleRate,
+				bandWidth, BLOCK_LEN_LONG);
+		}
 	}
 
 	/* TMP: Build sfb offset table and other stuff */
--- 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.1 2001/01/17 11:21:40 menno Exp $
+ * $Id: frame.h,v 1.2 2001/01/17 15:51:15 menno Exp $
  */
 
 #ifndef FRAME_H
@@ -53,6 +53,9 @@
 
 	/* bitrate / channel of AAC file */
 	unsigned long bitRate;
+
+	/* AAC file frequency bandwidth */
+	unsigned int bandWidth;
 
 } faacEncConfiguration, *faacEncConfigurationPtr;
 
--- a/todo.txt
+++ b/todo.txt
@@ -2,8 +2,8 @@
 Big list, but a lot of it can be done fairly easily with some old code
 
 
+- DONE: Add frequency cutoff filter
 - Add ADTS headers
-- Add frequency cutoff filter
 - Add TNS
 - Add PNS
 - Add LTP