[Scummvm-cvs-logs] SF.net SVN: scummvm: [27920] scummvm/branches/gsoc2007-mixer/sound

dogmatixman at users.sourceforge.net dogmatixman at users.sourceforge.net
Thu Jul 5 13:58:19 CEST 2007


Revision: 27920
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27920&view=rev
Author:   dogmatixman
Date:     2007-07-05 04:58:18 -0700 (Thu, 05 Jul 2007)

Log Message:
-----------
Added initial generation of lowpass filter coefficients.

Modified Paths:
--------------
    scummvm/branches/gsoc2007-mixer/sound/filter.cpp
    scummvm/branches/gsoc2007-mixer/sound/filter.h

Modified: scummvm/branches/gsoc2007-mixer/sound/filter.cpp
===================================================================
--- scummvm/branches/gsoc2007-mixer/sound/filter.cpp	2007-07-05 11:43:08 UTC (rev 27919)
+++ scummvm/branches/gsoc2007-mixer/sound/filter.cpp	2007-07-05 11:58:18 UTC (rev 27920)
@@ -42,6 +42,15 @@
 			double samplingFreq);
 
 static void windowDesign(double *coeffs, uint16 length, double ripple);
+
+static double sinc(double arg);
+
+static void LPDesign(
+		double *coeffs,
+		uint16 length,
+		double passbandEdge,
+		double stopbandEdge,
+		double samplingFreq);
  
 /* 
  * Modified Bessel function of the first type and zeroth order.  This is
@@ -120,19 +129,56 @@
 	for (i = 0; i <= (length - 1) / 2; i++) {
 		int16 n = i - (length - 1) / 2;
 		
+		/*
+		 * Both this window and the later filter are even symmetric, so we
+		 * only need to calculate half of the window for now.
+		 */
 		coeffs[i] = 
 			bessel_i0(beta * sqrt(1 - pow((2.0 * n) / (length - 1), 2.0)))
 			/ bessel_i0(beta);
-		coeffs[length - i - 1] = coeffs[i];
 	}
 }
 
+static inline double sinc(double arg) {
+	if (arg == 0) {
+		/* continuous extension of sin(arg) / arg */
+		return 1;
+	} else {
+		return sin(arg) / arg;
+	}
+}
+
 /*
- * Generates a Kaiser window using the parameters expected to be available to
- * a rate converter.
+ * Generates the filter coefficients for a windowed lowpass filter by applying
+ * the provided window to the ideal lowpass (sinc) filter
  */
+static void LPDesign(
+		double *coeffs,
+		uint16 length,
+		double passbandEdge,
+		double stopbandEdge,
+		double samplingFreq) {
+	uint16 i;
+	
+	for (i = 0; i <= (length - 1) / 2; i++) {
+		int16 n = i - (length - 1) / 2;
+		
+		/*
+		 * Use an ideal transition halfway between the passband and stopband
+		 * edges
+		 */
+		double bandwidth = (passbandEdge + stopbandEdge) / samplingFreq;
+		// == 2 * ((passbandEdge + stopbandEdge) / 2) / samplingFreq
+		
+		coeffs[i] *= bandwidth *  sinc(M_PI * bandwidth * n);
+		/* Filter is even symmetric */
+		coeffs[length - i - 1] = coeffs[i];
+	}
+}
+
+/* Generates lowpass filter coefficients using the parameters provided */
 // TODO: Write a nice interface for this :)
-void kaiserWindow(
+void lowPassCoeffs(
 		double passbandEdge,
 		double stopbandEdge,
 		double dBPassbandRipple,
@@ -142,9 +188,13 @@
 	double ripple = equiripple(dBPassbandRipple, dBStopbandAtten);
 	
 	/* Find the number of coefficients in the window */
-	uint16 length = windowLength(ripple, stopbandEdge - passbandEdge, samplingFreq);
+	uint16 length = 
+		windowLength(ripple, stopbandEdge - passbandEdge, samplingFreq);
 	
 	/* Calculate the window coefficients */
 	double *coeffs = (double *)malloc(length * sizeof(double));
 	windowDesign(coeffs, length, ripple);
+	
+	/* Generate the coefficients of a low pass filter using this window */
+	LPDesign(coeffs, length, passbandEdge, stopbandEdge, samplingFreq);
 }

Modified: scummvm/branches/gsoc2007-mixer/sound/filter.h
===================================================================
--- scummvm/branches/gsoc2007-mixer/sound/filter.h	2007-07-05 11:43:08 UTC (rev 27919)
+++ scummvm/branches/gsoc2007-mixer/sound/filter.h	2007-07-05 11:58:18 UTC (rev 27920)
@@ -28,11 +28,8 @@
 
 #include "common/scummsys.h"
 
-/*
- * Generates a Kaiser window using the parameters expected to be available to
- * a rate converter.
- */
-double *kaiserWindow(
+/* Generates lowpass filter coefficients using the parameters provided */
+void lowPassCoeffs(
 		double passbandEdge,
 		double stopbandEdge,
 		double dBPassbandRipple,


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list