aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorD G Turner2012-04-17 20:23:38 +0100
committerD G Turner2012-04-17 20:23:38 +0100
commitaa61c9abd3d1f89b6e689a25a81040011a25a069 (patch)
tree5ddd1c083d82dd844e42ff6f186a09163b767945
parent422334da5a29ec56261c51827ee31378e07a04f3 (diff)
downloadscummvm-rg350-aa61c9abd3d1f89b6e689a25a81040011a25a069.tar.gz
scummvm-rg350-aa61c9abd3d1f89b6e689a25a81040011a25a069.tar.bz2
scummvm-rg350-aa61c9abd3d1f89b6e689a25a81040011a25a069.zip
COMMON: Refactoring of FFT class to remove repeated fft<x>() functions.
The repeated functions expanded from the original DECL_FFT macros are now replaced by a recursive fft() function.
-rw-r--r--common/fft.cpp149
-rw-r--r--common/fft.h13
2 files changed, 15 insertions, 147 deletions
diff --git a/common/fft.cpp b/common/fft.cpp
index 2ed9b97edc..a9c58ead9b 100644
--- a/common/fft.cpp
+++ b/common/fft.cpp
@@ -218,104 +218,8 @@ void FFT::fft16(Complex *z) {
TRANSFORM(z[3], z[7], z[11], z[15], cosTable[3], cosTable[1]);
}
-void FFT::fft32(Complex *z) {
- fft16(z);
- fft8(z + 8 * 2);
- fft8(z + 8 * 3);
- assert(_cosTables[1]);
- pass(z, _cosTables[1]->getTable(), 8 / 2);
-}
-
-void FFT::fft64(Complex *z) {
- fft32(z);
- fft16(z + 16 * 2);
- fft16(z + 16 * 3);
- assert(_cosTables[2]);
- pass(z, _cosTables[2]->getTable(), 16 / 2);
-}
-
-void FFT::fft128(Complex *z) {
- fft64(z);
- fft32(z + 32 * 2);
- fft32(z + 32 * 3);
- assert(_cosTables[3]);
- pass(z, _cosTables[3]->getTable(), 32 / 2);
-}
-
-void FFT::fft256(Complex *z) {
- fft128(z);
- fft64(z + 64 * 2);
- fft64(z + 64 * 3);
- assert(_cosTables[4]);
- pass(z, _cosTables[4]->getTable(), 64 / 2);
-}
-
-void FFT::fft512(Complex *z) {
- fft256(z);
- fft128(z + 128 * 2);
- fft128(z + 128 * 3);
- assert(_cosTables[5]);
- pass(z, _cosTables[5]->getTable(), 128 / 2);
-}
-
-void FFT::fft1024(Complex *z) {
- fft512(z);
- fft256(z + 256 * 2);
- fft256(z + 256 * 3);
- assert(_cosTables[6]);
- pass_big(z, _cosTables[6]->getTable(), 256 / 2);
-}
-
-void FFT::fft2048(Complex *z) {
- fft1024(z);
- fft512(z + 512 * 2);
- fft512(z + 512 * 3);
- assert(_cosTables[7]);
- pass_big(z, _cosTables[7]->getTable(), 512 / 2);
-}
-
-void FFT::fft4096(Complex *z) {
- fft2048(z);
- fft1024(z + 1024 * 2);
- fft1024(z + 1024 * 3);
- assert(_cosTables[8]);
- pass_big(z, _cosTables[8]->getTable(), 1024 / 2);
-}
-
-void FFT::fft8192(Complex *z) {
- fft4096(z);
- fft2048(z + 2048 * 2);
- fft2048(z + 2048 * 3);
- assert(_cosTables[9]);
- pass_big(z, _cosTables[9]->getTable(), 2048 / 2);
-}
-
-void FFT::fft16384(Complex *z) {
- fft8192(z);
- fft4096(z + 4096 * 2);
- fft4096(z + 4096 * 3);
- assert(_cosTables[10]);
- pass_big(z, _cosTables[10]->getTable(), 4096 / 2);
-}
-
-void FFT::fft32768(Complex *z) {
- fft16384(z);
- fft8192(z + 8192 * 2);
- fft8192(z + 8192 * 3);
- assert(_cosTables[11]);
- pass_big(z, _cosTables[11]->getTable(), 8192 / 2);
-}
-
-void FFT::fft65536(Complex *z) {
- fft32768(z);
- fft16384(z + 16384 * 2);
- fft16384(z + 16384 * 3);
- assert(_cosTables[12]);
- pass_big(z, _cosTables[12]->getTable(), 16384 / 2);
-}
-
-void FFT::calc(Complex *z) {
- switch (_bits) {
+void FFT::fft(int n, int logn, Complex *z) {
+ switch (logn) {
case 2:
fft4(z);
break;
@@ -325,45 +229,20 @@ void FFT::calc(Complex *z) {
case 4:
fft16(z);
break;
- case 5:
- fft32(z);
- break;
- case 6:
- fft64(z);
- break;
- case 7:
- fft128(z);
- break;
- case 8:
- fft256(z);
- break;
- case 9:
- fft512(z);
- break;
- case 10:
- fft1024(z);
- break;
- case 11:
- fft2048(z);
- break;
- case 12:
- fft4096(z);
- break;
- case 13:
- fft8192(z);
- break;
- case 14:
- fft16384(z);
- break;
- case 15:
- fft32768(z);
- break;
- case 16:
- fft65536(z);
- break;
default:
- error("Should Not Happen!");
+ fft((n / 2), logn - 1, z);
+ fft((n / 4), logn - 2, z + (n / 4) * 2);
+ fft((n / 4), logn - 2, z + (n / 4) * 3);
+ assert(_cosTables[logn - 4]);
+ if (n > 1024)
+ pass_big(z, _cosTables[logn - 4]->getTable(), (n / 4) / 2);
+ else
+ pass(z, _cosTables[logn - 4]->getTable(), (n / 4) / 2);
}
}
+void FFT::calc(Complex *z) {
+ fft(1 << _bits, _bits, z);
+}
+
} // End of namespace Common
diff --git a/common/fft.h b/common/fft.h
index d510e51d9c..bc58f1dded 100644
--- a/common/fft.h
+++ b/common/fft.h
@@ -76,18 +76,7 @@ private:
void fft4(Complex *z);
void fft8(Complex *z);
void fft16(Complex *z);
- void fft32(Complex *z);
- void fft64(Complex *z);
- void fft128(Complex *z);
- void fft256(Complex *z);
- void fft512(Complex *z);
- void fft1024(Complex *z);
- void fft2048(Complex *z);
- void fft4096(Complex *z);
- void fft8192(Complex *z);
- void fft16384(Complex *z);
- void fft32768(Complex *z);
- void fft65536(Complex *z);
+ void fft(int n, int logn, Complex *z);
};
} // End of namespace Common