COMMON: Replaced static Sine and Cosine tables with dynamic generated.
This removes the large static tables from the binary (which saves 500K to 1Mb of binary size) and replaced them with a class which generates the required tables as needed in RAM. This has been tested with QDM2 and shows no obvious performance degredation and Memprof shows no significant rise in RAM usage.
This commit is contained in:
parent
1809b9173c
commit
f4ba8a6485
10 changed files with 99 additions and 16492 deletions
File diff suppressed because it is too large
Load diff
|
@ -25,12 +25,30 @@
|
|||
|
||||
namespace Common {
|
||||
|
||||
/**
|
||||
* Get a cosine table with the specified bit precision
|
||||
class CosineTable {
|
||||
public:
|
||||
/**
|
||||
* Construct a cosine table with the specified bit precision
|
||||
*
|
||||
* @param bits Precision of the table, which must be in range [4, 16]
|
||||
* @param bitPrecision Precision of the table, which must be in range [4, 16]
|
||||
*/
|
||||
const float *getCosineTable(int bits);
|
||||
CosineTable(int bitPrecision);
|
||||
~CosineTable();
|
||||
|
||||
/**
|
||||
* Get pointer to table
|
||||
*/
|
||||
const float *getTable() { return _table; }
|
||||
|
||||
/**
|
||||
* Get pointer to table
|
||||
*/
|
||||
int getPrecision() { return _bitPrecision; }
|
||||
|
||||
private:
|
||||
float *_table;
|
||||
int _bitPrecision;
|
||||
};
|
||||
|
||||
} // End of namespace Common
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ namespace Common {
|
|||
DCT::DCT(int bits, TransformType trans) : _bits(bits), _trans(trans), _rdft(0) {
|
||||
int n = 1 << _bits;
|
||||
|
||||
_tCos = getCosineTable(_bits + 2);
|
||||
_cos = new Common::CosineTable(_bits + 2);
|
||||
_tCos = _cos->getTable();
|
||||
|
||||
_csc2 = new float[n / 2];
|
||||
|
||||
|
@ -47,6 +48,7 @@ DCT::DCT(int bits, TransformType trans) : _bits(bits), _trans(trans), _rdft(0) {
|
|||
DCT::~DCT() {
|
||||
delete _rdft;
|
||||
delete[] _csc2;
|
||||
delete _cos;
|
||||
}
|
||||
|
||||
void DCT::calc(float *data) {
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
|
||||
namespace Common {
|
||||
|
||||
class CosineTable;
|
||||
|
||||
/**
|
||||
* (Inverse) Discrete Cosine Transforms.
|
||||
*
|
||||
|
@ -59,6 +61,7 @@ private:
|
|||
int _bits;
|
||||
TransformType _trans;
|
||||
|
||||
CosineTable *_cos;
|
||||
const float *_tCos;
|
||||
|
||||
float *_csc2;
|
||||
|
|
|
@ -167,7 +167,8 @@ static void fft##n(Complex *z) { \
|
|||
fft##n2(z); \
|
||||
fft##n4(z + n4 * 2); \
|
||||
fft##n4(z + n4 * 3); \
|
||||
pass(z, getCosineTable(t), n4 / 2);\
|
||||
Common::CosineTable table(t); \
|
||||
pass(z, table.getTable(), n4 / 2);\
|
||||
}
|
||||
|
||||
static void fft4(Complex *z) {
|
||||
|
@ -209,7 +210,8 @@ static void fft16(Complex *z) {
|
|||
fft4(z + 8);
|
||||
fft4(z + 12);
|
||||
|
||||
const float * const cosTable = getCosineTable(4);
|
||||
Common::CosineTable c(4);
|
||||
const float * const cosTable = c.getTable();
|
||||
|
||||
TRANSFORM_ZERO(z[0], z[4], z[8], z[12]);
|
||||
TRANSFORM(z[2], z[6], z[10], z[14], sqrthalf, sqrthalf);
|
||||
|
|
|
@ -64,9 +64,6 @@ private:
|
|||
Complex *_expTab;
|
||||
Complex *_tmpBuf;
|
||||
|
||||
const float *_tSin;
|
||||
const float *_tCos;
|
||||
|
||||
int _splitRadix;
|
||||
int _permutation;
|
||||
|
||||
|
|
|
@ -40,12 +40,16 @@ RDFT::RDFT(int bits, TransformType trans) : _bits(bits), _fft(0) {
|
|||
|
||||
int n = 1 << bits;
|
||||
|
||||
_tSin = getSineTable(bits) + (trans == DFT_R2C || trans == DFT_C2R) * (n >> 2);
|
||||
_tCos = getCosineTable(bits);
|
||||
_sin = new SineTable(bits);
|
||||
_tSin = _sin->getTable() + (trans == DFT_R2C || trans == DFT_C2R) * (n >> 2);
|
||||
_cos = new CosineTable(bits);
|
||||
_tCos = _cos->getTable();
|
||||
}
|
||||
|
||||
RDFT::~RDFT() {
|
||||
delete _fft;
|
||||
delete _sin;
|
||||
delete _cos;
|
||||
}
|
||||
|
||||
void RDFT::calc(float *data) {
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
|
||||
namespace Common {
|
||||
|
||||
class SineTable;
|
||||
class CosineTable;
|
||||
|
||||
/**
|
||||
* (Inverse) Real Discrete Fourier Transform.
|
||||
*
|
||||
|
@ -59,6 +62,8 @@ private:
|
|||
int _inverse;
|
||||
int _signConvention;
|
||||
|
||||
SineTable *_sin;
|
||||
CosineTable *_cos;
|
||||
const float *_tSin;
|
||||
const float *_tCos;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,12 +25,30 @@
|
|||
|
||||
namespace Common {
|
||||
|
||||
/**
|
||||
* Get a sine table with the specified bit precision
|
||||
class SineTable {
|
||||
public:
|
||||
/**
|
||||
* Construct a sine table with the specified bit precision
|
||||
*
|
||||
* @param bits Precision of the table, which must be in range [4, 16]
|
||||
* @param bitPrecision Precision of the table, which must be in range [4, 16]
|
||||
*/
|
||||
const float *getSineTable(int bits);
|
||||
SineTable(int bitPrecision);
|
||||
~SineTable();
|
||||
|
||||
/**
|
||||
* Get pointer to table
|
||||
*/
|
||||
const float *getTable() { return _table; }
|
||||
|
||||
/**
|
||||
* Get pointer to table
|
||||
*/
|
||||
int getPrecision() { return _bitPrecision; }
|
||||
|
||||
private:
|
||||
float *_table;
|
||||
int _bitPrecision;
|
||||
};
|
||||
|
||||
} // End of namespace Common
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue