aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Fioramonti2018-08-16 06:37:10 -0700
committerEugene Sandulenko2018-08-18 16:30:57 +0200
commit9cfc70e7fe881cfbd680322b6beeb9a7ab7149c3 (patch)
treefab46172b2fa4f8ef5d46349b110be8095e113de
parent4016cffd7ad0783eed0497e05a98cfc7684813fa (diff)
downloadscummvm-rg350-9cfc70e7fe881cfbd680322b6beeb9a7ab7149c3.tar.gz
scummvm-rg350-9cfc70e7fe881cfbd680322b6beeb9a7ab7149c3.tar.bz2
scummvm-rg350-9cfc70e7fe881cfbd680322b6beeb9a7ab7149c3.zip
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.
-rw-r--r--common/cosinetables.cpp9
-rw-r--r--common/cosinetables.h22
-rw-r--r--common/sinetables.cpp9
-rw-r--r--common/sinetables.h22
4 files changed, 24 insertions, 38 deletions
diff --git a/common/cosinetables.cpp b/common/cosinetables.cpp
index 42c6e4e05a..589c7c78b4 100644
--- a/common/cosinetables.cpp
+++ b/common/cosinetables.cpp
@@ -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];
diff --git a/common/cosinetables.h b/common/cosinetables.h
index c08bb4cddd..ac0aef8f60 100644
--- a/common/cosinetables.h
+++ b/common/cosinetables.h
@@ -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[]
diff --git a/common/sinetables.cpp b/common/sinetables.cpp
index c85a7bf7cf..1dce529d7d 100644
--- a/common/sinetables.cpp
+++ b/common/sinetables.cpp
@@ -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];
diff --git a/common/sinetables.h b/common/sinetables.h
index f91592cf38..5a5f246467 100644
--- a/common/sinetables.h
+++ b/common/sinetables.h
@@ -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[]