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 {
|
namespace Common {
|
||||||
|
|
||||||
/**
|
class CosineTable {
|
||||||
* Get a cosine table with the specified bit precision
|
public:
|
||||||
*
|
/**
|
||||||
* @param bits Precision of the table, which must be in range [4, 16]
|
* Construct a cosine table with the specified bit precision
|
||||||
*/
|
*
|
||||||
const float *getCosineTable(int bits);
|
* @param bitPrecision Precision of the table, which must be in range [4, 16]
|
||||||
|
*/
|
||||||
|
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
|
} // End of namespace Common
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ namespace Common {
|
||||||
DCT::DCT(int bits, TransformType trans) : _bits(bits), _trans(trans), _rdft(0) {
|
DCT::DCT(int bits, TransformType trans) : _bits(bits), _trans(trans), _rdft(0) {
|
||||||
int n = 1 << _bits;
|
int n = 1 << _bits;
|
||||||
|
|
||||||
_tCos = getCosineTable(_bits + 2);
|
_cos = new Common::CosineTable(_bits + 2);
|
||||||
|
_tCos = _cos->getTable();
|
||||||
|
|
||||||
_csc2 = new float[n / 2];
|
_csc2 = new float[n / 2];
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ DCT::DCT(int bits, TransformType trans) : _bits(bits), _trans(trans), _rdft(0) {
|
||||||
DCT::~DCT() {
|
DCT::~DCT() {
|
||||||
delete _rdft;
|
delete _rdft;
|
||||||
delete[] _csc2;
|
delete[] _csc2;
|
||||||
|
delete _cos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCT::calc(float *data) {
|
void DCT::calc(float *data) {
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
class CosineTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Inverse) Discrete Cosine Transforms.
|
* (Inverse) Discrete Cosine Transforms.
|
||||||
*
|
*
|
||||||
|
@ -59,6 +61,7 @@ private:
|
||||||
int _bits;
|
int _bits;
|
||||||
TransformType _trans;
|
TransformType _trans;
|
||||||
|
|
||||||
|
CosineTable *_cos;
|
||||||
const float *_tCos;
|
const float *_tCos;
|
||||||
|
|
||||||
float *_csc2;
|
float *_csc2;
|
||||||
|
|
|
@ -167,7 +167,8 @@ static void fft##n(Complex *z) { \
|
||||||
fft##n2(z); \
|
fft##n2(z); \
|
||||||
fft##n4(z + n4 * 2); \
|
fft##n4(z + n4 * 2); \
|
||||||
fft##n4(z + n4 * 3); \
|
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) {
|
static void fft4(Complex *z) {
|
||||||
|
@ -209,7 +210,8 @@ static void fft16(Complex *z) {
|
||||||
fft4(z + 8);
|
fft4(z + 8);
|
||||||
fft4(z + 12);
|
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_ZERO(z[0], z[4], z[8], z[12]);
|
||||||
TRANSFORM(z[2], z[6], z[10], z[14], sqrthalf, sqrthalf);
|
TRANSFORM(z[2], z[6], z[10], z[14], sqrthalf, sqrthalf);
|
||||||
|
|
|
@ -64,9 +64,6 @@ private:
|
||||||
Complex *_expTab;
|
Complex *_expTab;
|
||||||
Complex *_tmpBuf;
|
Complex *_tmpBuf;
|
||||||
|
|
||||||
const float *_tSin;
|
|
||||||
const float *_tCos;
|
|
||||||
|
|
||||||
int _splitRadix;
|
int _splitRadix;
|
||||||
int _permutation;
|
int _permutation;
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,16 @@ RDFT::RDFT(int bits, TransformType trans) : _bits(bits), _fft(0) {
|
||||||
|
|
||||||
int n = 1 << bits;
|
int n = 1 << bits;
|
||||||
|
|
||||||
_tSin = getSineTable(bits) + (trans == DFT_R2C || trans == DFT_C2R) * (n >> 2);
|
_sin = new SineTable(bits);
|
||||||
_tCos = getCosineTable(bits);
|
_tSin = _sin->getTable() + (trans == DFT_R2C || trans == DFT_C2R) * (n >> 2);
|
||||||
|
_cos = new CosineTable(bits);
|
||||||
|
_tCos = _cos->getTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
RDFT::~RDFT() {
|
RDFT::~RDFT() {
|
||||||
delete _fft;
|
delete _fft;
|
||||||
|
delete _sin;
|
||||||
|
delete _cos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RDFT::calc(float *data) {
|
void RDFT::calc(float *data) {
|
||||||
|
|
|
@ -33,6 +33,9 @@
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
class SineTable;
|
||||||
|
class CosineTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Inverse) Real Discrete Fourier Transform.
|
* (Inverse) Real Discrete Fourier Transform.
|
||||||
*
|
*
|
||||||
|
@ -59,6 +62,8 @@ private:
|
||||||
int _inverse;
|
int _inverse;
|
||||||
int _signConvention;
|
int _signConvention;
|
||||||
|
|
||||||
|
SineTable *_sin;
|
||||||
|
CosineTable *_cos;
|
||||||
const float *_tSin;
|
const float *_tSin;
|
||||||
const float *_tCos;
|
const float *_tCos;
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,12 +25,30 @@
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
/**
|
class SineTable {
|
||||||
* Get a sine table with the specified bit precision
|
public:
|
||||||
*
|
/**
|
||||||
* @param bits Precision of the table, which must be in range [4, 16]
|
* Construct a sine table with the specified bit precision
|
||||||
*/
|
*
|
||||||
const float *getSineTable(int bits);
|
* @param bitPrecision Precision of the table, which must be in range [4, 16]
|
||||||
|
*/
|
||||||
|
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
|
} // End of namespace Common
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue