# scummvm/scummvm

COMMON: allow cos/sin number of points to be more flexible

```Previously, the cos/sin table had to be a power of 2, but there
are many use cases where the number of points is not necessarily
a power of 2 so this change the constructor so it now takes
in the number of points rather than the number of points as the
exponent of a power of 2.

The restriction is that the size must be divisible by 4.```
dafioram committed Aug 16, 2018
1 parent d6f2a89 commit 9d0a2ceafaf51670db5cffc3e67e99f4037bb3e0
Showing with 24 additions and 38 deletions.
1. +4 −5 common/cosinetables.cpp
2. +8 −14 common/cosinetables.h
3. +4 −5 common/sinetables.cpp
4. +8 −14 common/sinetables.h
 @@ -27,12 +27,11 @@ namespace Common { CosineTable::CosineTable(int bitPrecision) { assert((bitPrecision >= 4) && (bitPrecision <= 16)); CosineTable::CosineTable(int nPoints) { assert((nPoints >= 16) && (nPoints <= 65536)); // log2 space is in [4,16] assert(nPoints % 4 == 0); _bitPrecision = bitPrecision; _nPoints = 1 << _bitPrecision; _nPoints = nPoints; _radResolution = 2.0 * M_PI / _nPoints; _refSize = _nPoints / 4; _table = new float[_nPoints / 2];
 @@ -28,40 +28,34 @@ namespace Common { class CosineTable { public: /** * Construct a cosine table with the specified bit precision * Construct a cosine table given the number of points * * @param bitPrecision Precision of the table, which must be in range [4, 16] * @param nPoints Number of distinct radian points, which must be in range [16,65536] and be divisible by 4 */ CosineTable(int bitPrecision); CosineTable(int nPoints); ~CosineTable(); /** * Get pointer to table. * * This table contains 2^bitPrecision/2 entries. * This table contains nPoints/2 entries. * Prefer to use at() * The layout of this table is as follows: * - Entries 0 up to (including) 2^bitPrecision/4: * - Entries 0 up to (including) nPoints/4: * cos(0) till (including) cos(1/2*pi) * - Entries (excluding) 2^bitPrecision/4 up to 2^bitPrecision/2: * - Entries (excluding) nPoints/4 up to nPoints/2: * (excluding) cos(3/2*pi) till (excluding) cos(2*pi) */ const float *getTable() { return _table; } /** * Returns cos(2*pi * index / 2^bitPrecision ) * Index must be in range [0,2^bitPrecision-1] * Returns cos(2*pi * index / nPoints ) * Index must be in range [0, nPoints - 1] */ float at(int index) const; /** * Get bit precision */ int getBitPrecision() { return _bitPrecision; } private: float *_table; int _bitPrecision; double _radResolution; // Smallest radian increment int _refSize; // _nPoints / 4 int _nPoints; // range of operator[]
 @@ -27,12 +27,11 @@ namespace Common { SineTable::SineTable(int bitPrecision) { assert((bitPrecision >= 4) && (bitPrecision <= 16)); SineTable::SineTable(int nPoints) { assert((nPoints >= 16) && (nPoints <= 65536)); // log2 space is in [4,16] assert(nPoints % 4 == 0); _bitPrecision = bitPrecision; _nPoints = 1 << _bitPrecision; _nPoints = nPoints; _radResolution = 2.0 * M_PI / _nPoints; _refSize = _nPoints / 4; _table = new float[_nPoints / 2];
 @@ -28,40 +28,34 @@ namespace Common { class SineTable { public: /** * Construct a sine table with the specified bit precision * Construct a sine table given the number of points * * @param bitPrecision Precision of the table, which must be in range [4, 16] * @param nPoints Number of distinct radian points, which must be in range [16,65536] and be divisible by 4 */ SineTable(int bitPrecision); SineTable(int nPoints); ~SineTable(); /** * Get pointer to table * * This table contains 2^bitPrecision/2 entries. * This table contains nPoints/2 entries. * Prefer to use at() * The layout of this table is as follows: * - Entries 0 up to (excluding) 2^bitPrecision/4: * - Entries 0 up to (excluding) nPoints/4: * sin(0) till (excluding) sin(1/2*pi) * - Entries 2^bitPrecision/4 up to 2^bitPrecision/2: * - Entries 2_nPoints/4 up to nPoints/2: * sin(pi) till (excluding) sin(3/2*pi) */ const float *getTable() { return _table; } /** * Returns sin(2*pi * index / 2^bitPrecision ) * Index must be in range [0,2^bitPrecision-1] * Returns sin(2*pi * index / nPoints ) * Index must be in range [0, nPoints - 1] */ float at(int index) const; /** * Get bit precision */ int getBitPrecision() { return _bitPrecision; } private: float *_table; int _bitPrecision; double _radResolution; // Smallest radian increment int _refSize; // _nPoints / 4 int _nPoints; // range of operator[]