aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/simpletest/simpletest.c15
-rw-r--r--src/scalar.c9
-rw-r--r--xtract/xtract_scalar.h7
3 files changed, 27 insertions, 4 deletions
diff --git a/examples/simpletest/simpletest.c b/examples/simpletest/simpletest.c
index 14fd6ee..443de22 100644
--- a/examples/simpletest/simpletest.c
+++ b/examples/simpletest/simpletest.c
@@ -98,6 +98,7 @@ int main(void)
double f0 = 0.0;
double flux = 0.0;
double centroid = 0.0;
+ double lowest = 0.0;
double spectrum[BLOCKSIZE] = {0};
double windowed[BLOCKSIZE] = {0};
double peaks[BLOCKSIZE] = {0};
@@ -109,6 +110,7 @@ int main(void)
double argd[4] = {0};
double samplerate = 44100.0;
int n;
+ int rv = XTRACT_SUCCESS;
xtract_mel_filter mel_filters;
fill_wavetable(344.53125f, NOISE); // 344.53125f = 128 samples @ 44100 Hz
@@ -122,6 +124,19 @@ int main(void)
xtract[XTRACT_MEAN](wavetable, BLOCKSIZE, NULL, &mean);
printf("\nInput mean = %.2f\n\n", mean); /* We expect this to be zero for a square wave */
+ /* get the lowest value in the input */
+ argd[0] = -.5;
+ rv = xtract[XTRACT_LOWEST_VALUE](wavetable, BLOCKSIZE, argd, &lowest);
+
+ if (rv == XTRACT_SUCCESS)
+ {
+ printf("\nLowest value = %.6f\n\n", lowest);
+ }
+ else
+ {
+ printf("\nUnable to get lowest value, all values below threshold?\n\n");
+ }
+ exit(0);
/* create the window function */
window = xtract_init_window(BLOCKSIZE, XTRACT_HANN);
xtract_windowed(wavetable, BLOCKSIZE, window, windowed);
diff --git a/src/scalar.c b/src/scalar.c
index 934f14e..3ecd446 100644
--- a/src/scalar.c
+++ b/src/scalar.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <stdio.h>
#include <math.h>
+#include <limits.h>
#include "dywapitchtrack/dywapitchtrack.h"
@@ -746,16 +747,18 @@ int xtract_lowest_value(const double *data, const int N, const void *argv, doubl
{
int n = N;
- double temp;
- *result = data[--n];
+ *result = DBL_MAX;
while(n--)
{
- if((temp = data[n]) > *(double *)argv)
+ if(data[n] > *(double *)argv)
*result = XTRACT_MIN(*result, data[n]);
}
+ if (*result == DBL_MAX)
+ return XTRACT_NO_RESULT;
+
return XTRACT_SUCCESS;
}
diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h
index 50fc213..dc0e5cf 100644
--- a/xtract/xtract_scalar.h
+++ b/xtract/xtract_scalar.h
@@ -353,8 +353,13 @@ int xtract_spectral_slope(const double *data, const int N, const void *argv, dou
*
* \param *data: a pointer to the first element in an array of doubles
* \param N: the number of elements to be considered
- * \param *argv: a pointer to a double representing the lower limit for the search. i.e. (*result > *argv) returns 1.
+ * \param *argv: a pointer to a double representing the lower limit for the search. All values in the array pointed to by *data that are below or equal to this threshold will be ignored.
* \param *result: a pointer to a value representing the lowest component in *data that falls above a given threshold.
+ *
+ * \return XTRACT_SUCCESS is a lowest value was found or XTRACT_NO_VALUE if all values
+ * in the array pointed to by *data are below or equal to the threshold set with *argv
+ *
+ * \note If XTRACT_NO_VALUE is returned, *result will be set to DBL_MAX
*
*/
int xtract_lowest_value(const double *data, const int N, const void *argv, double *result);