[Scummvm-cvs-logs] SF.net SVN: scummvm: [28823] scummvm/branches/gsoc2007-mixer/sound
dogmatixman at users.sourceforge.net
dogmatixman at users.sourceforge.net
Sun Sep 2 16:25:05 CEST 2007
Revision: 28823
http://scummvm.svn.sourceforge.net/scummvm/?rev=28823&view=rev
Author: dogmatixman
Date: 2007-09-02 07:25:03 -0700 (Sun, 02 Sep 2007)
Log Message:
-----------
Filter coefficients are now reordered when the filter's first created rather than when performing the actual filtering. This keeps filter coefficients cached nicely.
Modified Paths:
--------------
scummvm/branches/gsoc2007-mixer/sound/filter.cpp
scummvm/branches/gsoc2007-mixer/sound/filter.h
scummvm/branches/gsoc2007-mixer/sound/rate.cpp
Modified: scummvm/branches/gsoc2007-mixer/sound/filter.cpp
===================================================================
--- scummvm/branches/gsoc2007-mixer/sound/filter.cpp 2007-09-02 13:50:26 UTC (rev 28822)
+++ scummvm/branches/gsoc2007-mixer/sound/filter.cpp 2007-09-02 14:25:03 UTC (rev 28823)
@@ -103,7 +103,11 @@
* Derives the coefficients for a Kaiser window of the given properties, using
* standard Kaiser design formulae.
*/
-void FIRFilter::windowDesign(double *coeffs, uint32 length, double ripple) {
+void FIRFilter::windowDesign(
+ double *coeffs,
+ uint32 length,
+ double ripple,
+ uint16 subLen) {
uint32 i;
double alpha = -ripple;
@@ -119,12 +123,13 @@
for (i = 0; i <= (length - 1) / 2; i++) {
double n = (int32)(i - (length - 1) / 2) - ((length % 2) ? 0 : 0.5);
+ uint32 index = ((i * subLen) % length) + ((i * subLen) / length);
/*
* Both this window and the later filter are even symmetric, so we
* only need to calculate half of the window for now.
*/
- coeffs[i] =
+ coeffs[index] =
bessel_i0(beta * sqrt(1 - pow((2.0 * n) / (length - 1), 2.0)))
/ bessel_i0(beta);
}
@@ -148,11 +153,13 @@
uint32 length,
double passbandEdge,
double stopbandEdge,
- uint32 samplingFreq) {
+ uint32 samplingFreq,
+ uint16 subLen) {
uint32 i;
for (i = 0; i <= (length - 1) / 2; i++) {
double n = (int32)(i - (length - 1) / 2) - ((length % 2) ? 0 : 0.5);
+ uint32 index = ((i * subLen) % length) + ((i * subLen) / length);
/*
* Use an ideal transition halfway between the passband and stopband
@@ -161,9 +168,9 @@
double bandwidth = (passbandEdge + stopbandEdge) / samplingFreq;
// == 2 * ((passbandEdge + stopbandEdge) / 2) / samplingFreq
- coeffs[i] *= bandwidth * sinc(M_PI * bandwidth * n);
+ coeffs[index] *= bandwidth * sinc(M_PI * bandwidth * n);
/* Filter is even symmetric */
- coeffs[length - i - 1] = coeffs[i];
+ coeffs[length - index - 1] = coeffs[index];
}
}
@@ -184,12 +191,15 @@
windowLength(_ripple, _stopbandEdge - _passbandEdge, _samplingFreq,
_upFactor);
+ _subLen = _length / _upFactor;
+
/* Calculate the window coefficients */
_coeffs = (double *)malloc(_length * sizeof(double));
- windowDesign(_coeffs, _length, _ripple);
+ windowDesign(_coeffs, _length, _ripple, _subLen);
/* Generate the coefficients of a low pass filter using this window */
- LPDesign(_coeffs, _length, _passbandEdge, _stopbandEdge, _samplingFreq);
+ LPDesign(_coeffs, _length, _passbandEdge, _stopbandEdge, _samplingFreq,
+ _subLen);
}
FIRFilter *FIRFilter::getFilter(double passbandEdge, double stopbandEdge,
Modified: scummvm/branches/gsoc2007-mixer/sound/filter.h
===================================================================
--- scummvm/branches/gsoc2007-mixer/sound/filter.h 2007-09-02 13:50:26 UTC (rev 28822)
+++ scummvm/branches/gsoc2007-mixer/sound/filter.h 2007-09-02 14:25:03 UTC (rev 28823)
@@ -44,6 +44,7 @@
double _ripple;
uint32 _length;
double *_coeffs;
+ uint16 _subLen;
static Common::Array<FIRFilter *> filters;
@@ -88,7 +89,11 @@
uint32 samplingFreq,
uint16 upFactor);
- void windowDesign(double *coeffs, uint32 length, double ripple);
+ void windowDesign(
+ double *coeffs,
+ uint32 length,
+ double ripple,
+ uint16 subLen);
double sinc(double arg);
@@ -97,7 +102,8 @@
uint32 length,
double passbandEdge,
double stopbandEdge,
- uint32 samplingFreq);
+ uint32 samplingFreq,
+ uint16 subLen);
};
Modified: scummvm/branches/gsoc2007-mixer/sound/rate.cpp
===================================================================
--- scummvm/branches/gsoc2007-mixer/sound/rate.cpp 2007-09-02 13:50:26 UTC (rev 28822)
+++ scummvm/branches/gsoc2007-mixer/sound/rate.cpp 2007-09-02 14:25:03 UTC (rev 28823)
@@ -455,12 +455,15 @@
* Convolve the input samples with the filter to get the next
* outputs
*/
+
+ double *base = coeffs + (currBank * subLen);
+
for (i = 0; i < subLen; i++) {
accum0 += (double)inBuf[(inPos + numChan * i) % subLen]
- * coeffs[currBank + i*upFactor];
+ * base[i];
if (stereo) {
accum1 += (double)inBuf[(inPos + numChan * i + 1) % subLen]
- * coeffs[currBank + i*upFactor];
+ * base[i];
}
}
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