diff options
author | Jamie Bullock <jamie@jamiebullock.com> | 2017-12-05 14:54:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-05 14:54:57 +0000 |
commit | 7aa96facbd4da4270de73b3b8a4e94b98149db9e (patch) | |
tree | 54f05f9a2ebe24009a2a7c213e59f8ef7ce1ad8d /src/scalar.c | |
parent | 287b66756afd9fa44e3605b8eca650852b315003 (diff) | |
parent | 4da3ee149a945cb587deecf262d00bc5ff0f7289 (diff) | |
download | LibXtract-7aa96facbd4da4270de73b3b8a4e94b98149db9e.tar.gz LibXtract-7aa96facbd4da4270de73b3b8a4e94b98149db9e.tar.bz2 LibXtract-7aa96facbd4da4270de73b3b8a4e94b98149db9e.zip |
Merge pull request #95 from kecsap/floorfixes
Don't store the floor() result in integer because it can be out-of-range
Diffstat (limited to 'src/scalar.c')
-rw-r--r-- | src/scalar.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/scalar.c b/src/scalar.c index 95b296b..065566e 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -301,8 +301,8 @@ int xtract_irregularity_j(const double *data, const int N, const void *argv, dou int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result) { - int n = N >> 1, h = 0, i; - double den = 0.0, p1 = 0.0, fund = 0.0, temp = 0.0; + int n = N >> 1, i; + double den = 0.0, p1 = 0.0, fund = 0.0, temp = 0.0, h = 0.0; const double *freqs; fund = *(double *)argv; @@ -314,7 +314,7 @@ int xtract_tristimulus_1(const double *data, const int N, const void *argv, doub { den += temp; h = floor(freqs[i] / fund + 0.5); - if(h == 1) + if(h > 0 && h < 2 && (int)h == 1) p1 += temp; } } @@ -333,10 +333,9 @@ int xtract_tristimulus_1(const double *data, const int N, const void *argv, doub int xtract_tristimulus_2(const double *data, const int N, const void *argv, double *result) { - - int n = N >> 1, h = 0, i; - double den, p2, p3, p4, ps, fund, temp; - den = p2 = p3 = p4 = ps = fund = temp = 0.0; + int n = N >> 1, i; + double den, p2, p3, p4, ps, fund, temp, h; + den = p2 = p3 = p4 = ps = fund = temp = h = 0.0; const double *freqs; fund = *(double *)argv; @@ -348,21 +347,24 @@ int xtract_tristimulus_2(const double *data, const int N, const void *argv, doub { den += temp; h = floor(freqs[i] / fund + 0.5); - switch (h) + if (h > 1 && h < 5) { - case 2: - p2 += temp; + switch ((int)h) + { + case 2: + p2 += temp; break; - case 3: - p3 += temp; + case 3: + p3 += temp; break; - case 4: - p4 += temp; + case 4: + p4 += temp; - default: - break; + default: + break; + } } } } @@ -384,8 +386,8 @@ int xtract_tristimulus_2(const double *data, const int N, const void *argv, doub int xtract_tristimulus_3(const double *data, const int N, const void *argv, double *result) { - int n = N >> 1, h = 0, i; - double den = 0.0, num = 0.0, fund = 0.0, temp = 0.0; + int n = N >> 1, i; + double den = 0.0, num = 0.0, fund = 0.0, temp = 0.0, h = 0.0; const double *freqs; fund = *(double *)argv; |