aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in2
-rw-r--r--examples/puredata/xtract~.c2
-rw-r--r--src/descriptors.c77
-rw-r--r--src/init.c8
-rw-r--r--src/libxtract.c1
-rw-r--r--src/scalar.c87
-rw-r--r--src/vector.c16
-rw-r--r--src/xtract_macros_private.h1
-rw-r--r--xtract/libxtract.h13
-rw-r--r--xtract/xtract_scalar.h26
-rw-r--r--xtract/xtract_vector.h8
11 files changed, 151 insertions, 90 deletions
diff --git a/configure.in b/configure.in
index 47dea7b..9ec848a 100644
--- a/configure.in
+++ b/configure.in
@@ -4,7 +4,7 @@ m4_define(libxtract_major_version, 0)
# Increment for feature additions and enhancements
m4_define(libxtract_minor_version, 4)
# Increment for fixes
-m4_define(libxtract_fix_version, 0)
+m4_define(libxtract_fix_version, 1)
m4_define(libxtract_version, libxtract_major_version.libxtract_minor_version.libxtract_fix_version)
diff --git a/examples/puredata/xtract~.c b/examples/puredata/xtract~.c
index df74ce7..a769bdc 100644
--- a/examples/puredata/xtract~.c
+++ b/examples/puredata/xtract~.c
@@ -140,7 +140,7 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) {
if(n_args){
for(n = 0; n < n_args; n++){
argv_max = &fd[f].argv.max[n];
- post("Argument %d, max: %.2f", n, *argv_max);
+ //post("Argument %d, max: %.2f", n, *argv_max);
}
if(type == XTRACT_MEL_FILTER){
x->memory.argv = (size_t)(n_args * sizeof(xtract_mel_filter));
diff --git a/src/descriptors.c b/src/descriptors.c
index c47ad60..14e12ac 100644
--- a/src/descriptors.c
+++ b/src/descriptors.c
@@ -57,7 +57,6 @@ void *xtract_make_descriptors(){
case XTRACT_SPECTRAL_STANDARD_DEVIATION:
case XTRACT_SPECTRAL_AVERAGE_DEVIATION:
case XTRACT_SPECTRAL_INHARMONICITY:
- case XTRACT_ODD_EVEN_RATIO:
case XTRACT_LOWEST_VALUE:
case XTRACT_F0:
case XTRACT_FAILSAFE_F0:
@@ -115,6 +114,8 @@ void *xtract_make_descriptors(){
case XTRACT_AUTOCORRELATION:
case XTRACT_AMDF:
case XTRACT_ASDF:
+ case XTRACT_NONZERO_COUNT:
+ case XTRACT_ODD_EVEN_RATIO:
default:
*argc = 0;
break;
@@ -141,7 +142,6 @@ void *xtract_make_descriptors(){
*argv_def = XTRACT_ANY;
*argv_unit = XTRACT_ANY;
case XTRACT_SPECTRAL_INHARMONICITY:
- case XTRACT_ODD_EVEN_RATIO:
*argv_min = 0.f;
*argv_max = XTRACT_SR_UPPER_LIMIT / 2;
*argv_def = XTRACT_FUNDAMENTAL_DEFAULT;
@@ -235,7 +235,6 @@ void *xtract_make_descriptors(){
*argv_donor = XTRACT_SPECTRAL_MEAN;
break;
case XTRACT_SPECTRAL_INHARMONICITY:
- case XTRACT_ODD_EVEN_RATIO:
*argv_donor = XTRACT_FAILSAFE_F0;
break;
case XTRACT_TONALITY:
@@ -276,7 +275,7 @@ void *xtract_make_descriptors(){
break;
case XTRACT_CREST:
*argv_donor = XTRACT_HIGHEST_VALUE;
- *(argv_donor + 1) = XTRACT_SPECTRAL_MEAN;
+ *(argv_donor + 1) = XTRACT_MEAN;
break;
/* argc = BARK_BANDS */
case XTRACT_BARK_COEFFICIENTS:
@@ -300,7 +299,6 @@ void *xtract_make_descriptors(){
case XTRACT_LOWEST_VALUE:
case XTRACT_HIGHEST_VALUE:
case XTRACT_SUM:
- case XTRACT_ZCR:
*data_format = XTRACT_ARBITRARY_SERIES;
break;
case XTRACT_SPECTRAL_MEAN:
@@ -311,8 +309,6 @@ void *xtract_make_descriptors(){
case XTRACT_SPECTRAL_KURTOSIS:
case XTRACT_SPECTRAL_CENTROID:
case XTRACT_SPECTRAL_SLOPE:
- case XTRACT_PEAK_SPECTRUM:
- case XTRACT_HARMONIC_SPECTRUM:
*data_format = XTRACT_SPECTRAL;
break;
case XTRACT_ROLLOFF:
@@ -324,17 +320,17 @@ void *xtract_make_descriptors(){
case XTRACT_SMOOTHNESS:
case XTRACT_FLATNESS:
case XTRACT_SPREAD:
- case XTRACT_RMS_AMPLITUDE:
case XTRACT_POWER:
- case XTRACT_SHARPNESS:
case XTRACT_HPS:
+ case XTRACT_PEAK_SPECTRUM:
*data_format = XTRACT_SPECTRAL_MAGNITUDES;
break;
case XTRACT_SPECTRAL_INHARMONICITY:
+ case XTRACT_HARMONIC_SPECTRUM:
*data_format = XTRACT_SPECTRAL_PEAKS;
break;
- case XTRACT_ODD_EVEN_RATIO:
- *data_format = XTRACT_SPECTRAL_HARMONICS_FREQUENCIES;
+ case XTRACT_NONZERO_COUNT:
+ *data_format = XTRACT_SPECTRAL_PEAKS_MAGNITUDES;
break;
case XTRACT_F0:
case XTRACT_FAILSAFE_F0:
@@ -345,6 +341,8 @@ void *xtract_make_descriptors(){
case XTRACT_DCT:
case XTRACT_AMDF:
case XTRACT_ASDF:
+ case XTRACT_ZCR:
+ case XTRACT_RMS_AMPLITUDE:
*data_format = XTRACT_AUDIO_SAMPLES;
break;
case XTRACT_TONALITY:
@@ -353,9 +351,11 @@ void *xtract_make_descriptors(){
case XTRACT_TRISTIMULUS_1:
case XTRACT_TRISTIMULUS_2:
case XTRACT_TRISTIMULUS_3:
+ case XTRACT_ODD_EVEN_RATIO:
*data_format = XTRACT_SPECTRAL_HARMONICS_MAGNITUDES;
break;
case XTRACT_LOUDNESS:
+ case XTRACT_SHARPNESS:
*data_format = XTRACT_BARK_COEFFS;
break;
case XTRACT_FLUX:
@@ -413,6 +413,7 @@ void *xtract_make_descriptors(){
case XTRACT_SPECTRUM:
case XTRACT_TONALITY:
case XTRACT_LOUDNESS:
+ case XTRACT_NONZERO_COUNT:
*data_unit = XTRACT_ANY;
break;
case XTRACT_SPECTRAL_MEAN:
@@ -475,6 +476,24 @@ void *xtract_make_descriptors(){
"Extract the average deviation of a range of values");
strcpy(author, "");
break;
+ case XTRACT_SKEWNESS:
+ strcpy(name, "skewness");
+ strcpy(p_name, "Skewness");
+ strcpy(desc,
+ "Extract the skewness of an input vector");
+ strcpy(p_desc,
+ "Extract the skewness of a range of values");
+ strcpy(author, "");
+ break;
+ case XTRACT_KURTOSIS:
+ strcpy(name, "kurtosis");
+ strcpy(p_name, "Kurtosis");
+ strcpy(desc,
+ "Extract the kurtosis of an input vector");
+ strcpy(p_desc,
+ "Extract the kurtosis of a range of values");
+ strcpy(author, "");
+ break;
case XTRACT_SPECTRAL_MEAN:
strcpy(name, "spectral_mean");
strcpy(p_name, "Spectral Mean");
@@ -555,23 +574,23 @@ void *xtract_make_descriptors(){
strcpy(desc, "Extract the fundamental frequency of a signal");
strcpy(p_desc,
"Extract the fundamental frequency of an audio signal");
- strcpy(author, "");
+ strcpy(author, "Jamie Bullock");
break;
case XTRACT_FAILSAFE_F0:
strcpy(name, "failsafe_f0");
strcpy(p_name, "Fundamental Frequency (failsafe)");
- strcpy(desc, "Extract the fundamental frequency of a signal");
+ strcpy(desc, "Extract the fundamental frequency of a signal (failsafe)");
strcpy(p_desc,
- "Extract the fundamental frequency of an audio signal");
- strcpy(author, "");
+ "Extract the fundamental frequency of an audio signal (failsafe)");
+ strcpy(author, "Jamie Bullock");
break;
case XTRACT_TONALITY:
strcpy(name, "tonality");
strcpy(p_name, "Tonality");
strcpy(desc, "Extract the tonality of a spectrum");
strcpy(p_desc, "Extract the tonality an audio spectrum");
- strcpy(author, "Tristan Jehan");
- *year = 2005;
+ strcpy(author, "J. D. Johnston");
+ *year = 1988;
break;
case XTRACT_SPECTRAL_SKEWNESS:
strcpy(name, "spectral_skewness");
@@ -646,18 +665,18 @@ void *xtract_make_descriptors(){
case XTRACT_IRREGULARITY_K:
strcpy(name, "irregularity_k");
strcpy(p_name, "Irregularity I");
- strcpy(desc, "Extract the irregularity of a spectrum");
+ strcpy(desc, "Extract the irregularity (type I) of a spectrum");
strcpy(p_desc,
- "Extract the irregularity of an audio spectrum");
+ "Extract the irregularity (type I) of an audio spectrum");
strcpy(author, "Krimphoff");
*year = 1994;
break;
case XTRACT_IRREGULARITY_J:
strcpy(name, "irregularity_j");
strcpy(p_name, "Irregularity II");
- strcpy(desc, "Extract the irregularity of a spectrum");
+ strcpy(desc, "Extract the irregularity (type II) of a spectrum");
strcpy(p_desc,
- "Extract the irregularity of an audio spectrum");
+ "Extract the irregularity (type II) of an audio spectrum");
strcpy(author, "Jensen");
*year = 1999;
break;
@@ -823,8 +842,8 @@ void *xtract_make_descriptors(){
case XTRACT_AUTOCORRELATION_FFT:
strcpy(name, "autocorrelation_fft");
strcpy(p_name, "Autocorrelation (FFT method)");
- strcpy(desc, "Extract the autocorrelation of a signal");
- strcpy(p_desc, "Extract the autocorrelation of an audio signal");
+ strcpy(desc, "Extract the autocorrelation of a signal (fft method)");
+ strcpy(p_desc, "Extract the autocorrelation of an audio signal (fft method)");
strcpy(author, "");
break;
case XTRACT_DCT:
@@ -856,6 +875,13 @@ void *xtract_make_descriptors(){
strcpy(p_desc, "Extract the ASDF of an audio signal");
strcpy(author, "");
break;
+ case XTRACT_NONZERO_COUNT:
+ strcpy(name, "nonzero_count");
+ strcpy(p_name, "Non-zero count");
+ strcpy(desc, "Extract the number of non-zero elements in the input vector");
+ strcpy(p_desc, "Extract the number of non-zero elements in an input spectrum");
+ strcpy(author, "");
+ break;
default:
strcpy(name, "");
strcpy(p_name, "");
@@ -875,7 +901,6 @@ void *xtract_make_descriptors(){
case XTRACT_SPECTRAL_STANDARD_DEVIATION:
case XTRACT_SPECTRAL_AVERAGE_DEVIATION:
case XTRACT_SPECTRAL_INHARMONICITY:
- case XTRACT_ODD_EVEN_RATIO:
case XTRACT_LOWEST_VALUE:
case XTRACT_F0:
case XTRACT_FAILSAFE_F0:
@@ -933,6 +958,8 @@ void *xtract_make_descriptors(){
case XTRACT_AUTOCORRELATION:
case XTRACT_AMDF:
case XTRACT_ASDF:
+ case XTRACT_NONZERO_COUNT:
+ case XTRACT_ODD_EVEN_RATIO:
default:
*argc = 0;
break;
@@ -980,6 +1007,7 @@ void *xtract_make_descriptors(){
case XTRACT_HPS:
case XTRACT_F0:
case XTRACT_FAILSAFE_F0:
+ case XTRACT_NONZERO_COUNT:
*is_scalar = XTRACT_TRUE;
break;
case XTRACT_AUTOCORRELATION:
@@ -1017,6 +1045,7 @@ void *xtract_make_descriptors(){
case XTRACT_LOWEST_VALUE:
case XTRACT_HIGHEST_VALUE:
case XTRACT_SUM:
+ case XTRACT_NONZERO_COUNT:
*result_unit = XTRACT_ANY;
*result_min = XTRACT_ANY;
*result_max = XTRACT_ANY;
diff --git a/src/init.c b/src/init.c
index b7cc99c..09e2d77 100644
--- a/src/init.c
+++ b/src/init.c
@@ -122,16 +122,14 @@ int xtract_init_mfcc(int N, float nyquist, int style, float freq_min, float freq
}
-int xtract_init_bark(int N, float nyquist, int *band_limits){
+int xtract_init_bark(int N, float sr, int *band_limits){
float edges[] = {0, 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500, 20500, 27000}; /* Takes us up to sr = 54kHz (CCRMA: JOS)*/
- int M, bands = XTRACT_BARK_BANDS;
-
- M = N >> 1;
+ int bands = XTRACT_BARK_BANDS;
while(bands--)
- band_limits[bands] = edges[bands] / nyquist * M;
+ band_limits[bands] = edges[bands] / sr * N;
/*FIX shohuld use rounding, but couldn't get it to work */
return XTRACT_SUCCESS;
diff --git a/src/libxtract.c b/src/libxtract.c
index 7028486..ce946a7 100644
--- a/src/libxtract.c
+++ b/src/libxtract.c
@@ -60,6 +60,7 @@ int(*xtract[])(const float *, const int, const void *, float *) = {
xtract_lowest_value,
xtract_highest_value,
xtract_sum,
+ xtract_nonzero_count,
xtract_hps,
xtract_f0,
xtract_failsafe_f0,
diff --git a/src/scalar.c b/src/scalar.c
index b34818f..d85d28c 100644
--- a/src/scalar.c
+++ b/src/scalar.c
@@ -53,7 +53,8 @@ int xtract_variance(const float *data, const int N, const void *argv, float *res
int xtract_standard_deviation(const float *data, const int N, const void *argv, float *result){
- *result = sqrt(*(float *)argv);
+ //*result = sqrt(*(float *)argv);
+ *result = sqrt(-40.);
return XTRACT_SUCCESS;
}
@@ -74,7 +75,7 @@ int xtract_skewness(const float *data, const int N, const void *argv, float *re
int n = N;
- float temp;
+ float temp = 0.f;
while(n--){
temp = (data[n] - ((float *)argv)[0]) / ((float *)argv)[1];
@@ -83,6 +84,7 @@ int xtract_skewness(const float *data, const int N, const void *argv, float *re
*result /= N;
+
return XTRACT_SUCCESS;
}
@@ -142,17 +144,17 @@ int xtract_spectral_variance(const float *data, const int N, const void *argv, f
while(m--){
A += amps[m];
- *result += pow((freqs[m] - *(float *)argv) * amps[m], 2);
+ *result += powf((freqs[m] - *(float *)argv) * amps[m], 2);
}
- *result = *result / (A - 1);
+ *result = *result / (A /*- 1*/);
return XTRACT_SUCCESS;
}
int xtract_spectral_standard_deviation(const float *data, const int N, const void *argv, float *result){
- *result = sqrt(*(float *)argv);
+ *result = sqrt(*(float *)argv);
return XTRACT_SUCCESS;
}
@@ -240,14 +242,14 @@ int xtract_irregularity_j(const float *data, const int N, const void *argv, floa
int n = N;
- float num = 0.f, den = 0.f;
+ double num = 0.f, den = 0.f;
while(n--){
num += pow(data[n] - data[n+1], 2);
den += pow(data[n], 2);
}
- *result = num / den;
+ *result = (float)(num / den);
return XTRACT_SUCCESS;
}
@@ -322,20 +324,21 @@ int xtract_tristimulus_3(const float *data, const int N, const void *argv, float
int xtract_smoothness(const float *data, const int N, const void *argv, float *result){
- int n = N;
+ int n, M;
float *input;
input = (float *)malloc(N * sizeof(float));
- input = memcpy(input, data, N * sizeof(float));
+ memcpy(input, data, N * sizeof(float));
if (input[0] <= 0) input[0] = 1;
- if (input[1] <= 0) input[1] = 1;
- for(n = 2; n < N; n++){
+ M = N - 1;
+
+ for(n = 1; n < M; n++){
if(input[n] <= 0) input[n] = 1;
- *result += abs(20 * log(input[n-1]) - (20 * log(input[n-2]) +
- 20 * log(input[n-1]) + 20 * log(input[n])) / 3);
+ *result += fabs(20 * log(input[n]) - (20 * log(input[n-1]) +
+ 20 * log(input[n]) + 20 * log(input[n+1])) / 3);
}
free(input);
@@ -403,7 +406,7 @@ int xtract_loudness(const float *data, const int N, const void *argv, float *res
rv = XTRACT_SUCCESS;
while(n--)
- *result += pow(data[n], 0.23);
+ *result += powf(data[n], 0.23);
return rv;
}
@@ -424,7 +427,7 @@ int xtract_flatness(const float *data, const int N, const void *argv, float *res
}
}
- num = pow(num, 1.f / N);
+ num = powf(num, 1.f / N);
den /= N;
if(num < XTRACT_VERY_SMALL_NUMBER)
@@ -433,7 +436,7 @@ int xtract_flatness(const float *data, const int N, const void *argv, float *res
if(den < XTRACT_VERY_SMALL_NUMBER)
den = XTRACT_VERY_SMALL_NUMBER;
- *result = num / den;
+ *result = 10 * log10(num / den);
return XTRACT_SUCCESS;
@@ -445,9 +448,10 @@ int xtract_tonality(const float *data, const int N, const void *argv, float *res
sfm = *(float *)argv;
- sfmdb = (sfm > 0 ? ((10 * log10(sfm)) / -60) : 0);
+ sfmdb = sfm / -60.f;
*result = XTRACT_MIN(sfmdb, 1);
+ //*result = sfmdb;
return XTRACT_SUCCESS;
}
@@ -506,8 +510,10 @@ int xtract_spectral_inharmonicity(const float *data, const int N, const void *ar
freqs = data + n;
while(n--){
- num += abs(freqs[n] - n * fund) * XTRACT_SQ(amps[n]);
- den += XTRACT_SQ(amps[n]);
+ if(amps[n]){
+ num += fabs(freqs[n] - n * fund) * XTRACT_SQ(amps[n]);
+ den += XTRACT_SQ(amps[n]);
+ }
}
*result = (2 * num) / (fund * den);
@@ -526,17 +532,15 @@ int xtract_odd_even_ratio(const float *data, const int N, const void *argv, floa
int M = (N >> 1), n;
- float num = 0.f, den = 0.f, temp, f0;
-
- f0 = *(float *)argv;
+ float num = 0.f, den = 0.f, temp;
for(n = 0; n < M; n++){
if((temp = data[n])){
- if(((int)(rintf(temp / f0)) % 2) != 0){
- num += data[M + n];
+ if(XTRACT_IS_ODD(n)){
+ num += temp;
}
else{
- den += data[M + n];
+ den += temp;
}
}
}
@@ -560,8 +564,8 @@ int xtract_sharpness(const float *data, const int N, const void *argv, float *re
while(n--){
- sl = pow(data[n], 0.23);
- g = (n < 15 ? 1.f : 0.066 * exp(0.171 * n));
+ sl = powf(data[n], 0.23);
+ g = (n < 15 ? 1.f : 0.066 * expf(0.171 * n));
temp += n * g * sl;
}
@@ -638,6 +642,17 @@ int xtract_sum(const float *data, const int N, const void *argv, float *result){
}
+int xtract_nonzero_count(const float *data, const int N, const void *argv, float *result){
+
+ int n = N;
+
+ while(n--)
+ *result += (*data++ ? 1 : 0);
+
+ return XTRACT_SUCCESS;
+
+}
+
int xtract_hps(const float *data, const int N, const void *argv, float *result){
int n = N, M, m, l, peak_index, position1_lwr;
@@ -773,22 +788,24 @@ int xtract_f0(const float *data, const int N, const void *argv, float *result){
int xtract_failsafe_f0(const float *data, const int N, const void *argv, float *result){
- float *magnitudes = NULL, argf[2], *peaks = NULL, return_code;
+ float *spectrum = NULL, argf[2], *peaks = NULL, return_code, sr;
return_code = xtract_f0(data, N, argv, result);
if(return_code == XTRACT_NO_RESULT){
- magnitudes = (float *)malloc(N * sizeof(float));
+ sr = *(float *)argv;
+ spectrum = (float *)malloc(N * sizeof(float));
peaks = (float *)malloc(N * sizeof(float));
- xtract_spectrum(data, N, argv, magnitudes);
- argf[0] = 10.f;
- argf[1] = *(float *)argv;
- xtract_peak_spectrum(magnitudes, N, argf, peaks);
+ argf[0] = sr;
+ argf[1] = XTRACT_MAGNITUDE_SPECTRUM;
+ xtract_spectrum(data, N, argf, spectrum);
+ argf[1] = 10.f;
+ xtract_peak_spectrum(spectrum, N >> 1, argf, peaks);
argf[0] = 0.f;
- xtract_lowest_value(peaks, N >> 1, argf, result);
+ xtract_lowest_value(peaks+(N >> 1), N >> 1, argf, result);
- free(magnitudes);
+ free(spectrum);
free(peaks);
}
diff --git a/src/vector.c b/src/vector.c
index 1602da3..aa11e6a 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -270,7 +270,7 @@ int xtract_bark_coefficients(const float *data, const int N, const void *argv, f
limits = (int *)argv;
- for(band = 0; band < XTRACT_BARK_BANDS; band++){
+ for(band = 0; band < XTRACT_BARK_BANDS - 1; band++){
for(n = limits[band]; n < limits[band + 1]; n++)
result[band] += data[n];
}
@@ -282,7 +282,7 @@ int xtract_peak_spectrum(const float *data, const int N, const void *argv, float
float threshold, max, y, y2, y3, p, q, *input = NULL;
size_t bytes;
- int n = N, M, rv = XTRACT_SUCCESS;
+ int n = N, rv = XTRACT_SUCCESS;
threshold = max = y = y2 = y3 = p = q = 0.f;
@@ -307,32 +307,30 @@ int xtract_peak_spectrum(const float *data, const int N, const void *argv, float
else
return XTRACT_MALLOC_FAILED;
- M = N >> 1;
-
while(n--)
max = XTRACT_MAX(max, input[n]);
threshold *= .01 * max;
result[0] = 0;
- result[M] = 0;
+ result[N] = 0;
- for(n = 1; n < M; n++){
+ for(n = 1; n < N; n++){
if(input[n] >= threshold){
if(input[n] > input[n - 1] && input[n] > input[n + 1]){
- result[M + n] = q * (n + (p = .5 * (y = input[n-1] -
+ result[N + n] = q * (n + (p = .5 * (y = input[n-1] -
(y3 = input[n+1])) / (input[n - 1] - 2 *
(y2 = input[n]) + input[n + 1])));
result[n] = y2 - .25 * (y - y3) * p;
}
else{
result[n] = 0;
- result[M + n] = 0;
+ result[N + n] = 0;
}
}
else{
result[n] = 0;
- result[M + n] = 0;
+ result[N + n] = 0;
}
}
diff --git a/src/xtract_macros_private.h b/src/xtract_macros_private.h
index d8e46fd..3a479ed 100644
--- a/src/xtract_macros_private.h
+++ b/src/xtract_macros_private.h
@@ -40,6 +40,7 @@
#define XTRACT_FUNDAMENTAL_DEFAULT 440
#define XTRACT_CHECK_nyquist if(!nyquist) nyquist = XTRACT_SR_DEFAULT / 2
#define XTRACT_CHECK_q if(!q) q = XTRACT_SR_DEFAULT / N
+#define XTRACT_IS_ODD(x) (x % 2 != 0 ? 1 : 0)
#define XTRACT_SR_LIMIT SR_UPPER_LIMIT
#define XTRACT_FFT_BANDS_MIN 16
#define XTRACT_FFT_BANDS_MAX 65536
diff --git a/xtract/libxtract.h b/xtract/libxtract.h
index 7249a94..b4808ba 100644
--- a/xtract/libxtract.h
+++ b/xtract/libxtract.h
@@ -53,7 +53,7 @@ extern "C" {
* @{
*/
-#define XTRACT_FEATURES 53
+#define XTRACT_FEATURES 54
/** \brief Enumeration of features, elements are used as indixes to an array of pointers to feature extracton functions */
enum xtract_features_ {
@@ -93,6 +93,7 @@ enum xtract_features_ {
XTRACT_LOWEST_VALUE,
XTRACT_HIGHEST_VALUE,
XTRACT_SUM,
+ XTRACT_NONZERO_COUNT,
XTRACT_HPS,
XTRACT_F0,
XTRACT_FAILSAFE_F0,
@@ -184,7 +185,9 @@ typedef enum xtract_vector_ {
* frequencies */
XTRACT_SPECTRAL_PEAKS,
/* N spectral peak amplitudes */
- XTRACT_SPECTRAL_PEAK_MAGNITUDES,
+ XTRACT_SPECTRAL_PEAKS_MAGNITUDES,
+ /* N spectral peak frequencies */
+ XTRACT_SPECTRAL_PEAKS_FREQUENCIES,
/* N/2 magnitude/log-magnitude/power/log-power harmonic peak coeffs and N/2
* frequencies */
XTRACT_SPECTRAL_HARMONICS,
@@ -313,8 +316,12 @@ int xtract_init_mfcc(int N, float nyquist, int style, float freq_min, float freq
/** \brief A function to initialise bark filter bounds
*
* A pointer to an array of BARK_BANDS ints most be passed in, and is populated with BARK_BANDS fft bin numbers representing the limits of each band
+ *
+ * \param N: the audio block size
+ * \param sr: The sample audio sample rate
+ * \param *band_limits: a pointer to an array of BARK_BANDS ints
*/
-int xtract_init_bark(int N, float nyquist, int *band_limits);
+int xtract_init_bark(int N, float sr, int *band_limits);
/* \brief A function to build an array of function descriptors */
void *xtract_make_descriptors();
diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h
index ee4323b..dc2e4ac 100644
--- a/xtract/xtract_scalar.h
+++ b/xtract/xtract_scalar.h
@@ -102,7 +102,7 @@ int xtract_spectral_mean(const float *data, const int N, const void *argv, float
* \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
* \param N: the number of elements to be considered
* \param N: the size of the array pointed to by *data
- * \param *argv: a pointer to a float representing the mean of the input spectrum
+ * \param *argv: a pointer to a float representing the spectral mean of the input spectrum
* \param *result: the variance of the spectrum pointed to by *data
*/
int xtract_spectral_variance(const float *data, const int N, const void *argv, float *result);
@@ -111,7 +111,7 @@ int xtract_spectral_variance(const float *data, const int N, const void *argv, f
*
* \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
* \param N: the size of the array pointed to by *data
- * \param *argv: a pointer to a float representing the variance of the input spectrum
+ * \param *argv: a pointer to a float representing the spectral variance of the input spectrum
* \param *result: the deviation of the spectrum pointed to by *data
*/
int xtract_spectral_standard_deviation(const float *data, const int N, const void *argv, float *result);
@@ -120,7 +120,7 @@ int xtract_spectral_standard_deviation(const float *data, const int N, const voi
*
* \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
* \param N: the size of the array pointed to by *data
- * \param *argv: a pointer to a float representing the mean of the input spectrum
+ * \param *argv: a pointer to a float representing the spectral mean of the input spectrum
* \param *result: the average deviation of the spectrum pointed to by *data
*/
int xtract_spectral_average_deviation(const float *data, const int N, const void *argv, float *result);
@@ -129,7 +129,7 @@ int xtract_spectral_average_deviation(const float *data, const int N, const void
*
* \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
* \param N: the size of the array pointed to by *data
- * \param *argv: a pointer to an array of floats representing the mean and standard deviation of the input spectrum
+ * \param *argv: a pointer to an array of floats representing the spectral mean and spectral standard deviation of the input spectrum
* \param *result: the skewness of the spectrum pointed to by *data
*/
int xtract_spectral_skewness(const float *data, const int N, const void *argv, float *result);
@@ -138,7 +138,7 @@ int xtract_spectral_skewness(const float *data, const int N, const void *argv,
*
* \param *data: a pointer to the first element in an array of floats representing the spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(), xtract_spectral_peaks() or xtract_spectral_harmonics()).
* \param N: the size of the array pointed to by *data
- * \param *argv: a pointer to an array of values representing the mean and standard deviation of the input spectrum
+ * \param *argv: a pointer to an array of values representing the spectral mean and spectral standard deviation of the input spectrum
* \param *result: the kurtosis of the spectrum pointed to by *data
*/
int xtract_spectral_kurtosis(const float *data, const int N, const void *argv, float *result);
@@ -304,9 +304,9 @@ int xtract_power(const float *data, const int N, const void *argv, float *result
/* Odd to even harmonic ratio */
/** \brief Extract the Odd to even harmonic ratio of an input vector
*
- * \param *data: a pointer to the first element in an array of floats representing the frequencies of the harmonic spectrum of an audio vector. It is sufficient to pass in a pointer to the second half of the array pointed to by *result from xtract_harmonic_spectrum().
- * \param N: the number of elements to be considered. If using the array pointed to by *result from xtract_harmonics, N should equal half the total array size i.e., just the frequencies of the peaks.
- * \param *argv: a pointer to a float representing the fundamental frequency of the input vector.
+ * \param *data: a pointer to the first element in an array of floats representing the amplitudes of the harmonic spectrum of an audio vector. It is sufficient to pass in a pointer to the first half of the array pointed to by *result from xtract_harmonic_spectrum().
+ * \param N: the number of elements to be considered. If using the array pointed to by *result from xtract_harmonics, N should equal half the total array size i.e., just the amplitudes of the peaks.
+ * \param *argv: a pointer to NULL
* \param *result: the odd/even harmonic ratio of N values from the array pointed to by *data
*/
int xtract_odd_even_ratio(const float *data, const int N, const void *argv, float *result);
@@ -394,6 +394,16 @@ int xtract_f0(const float *data, const int N, const void *argv, float *result);
*/
int xtract_failsafe_f0(const float *data, const int N, const void *argv, float *result);
+/** \brief Extract the number of non-zero elements in an input vector
+ *
+ * \param *data: a pointer to the first element in an array of floats
+ * \param N: the number of elements to be considered
+ * \param *argv: not used
+ * \param *result: the number of non-zero elements in the array pointed to by *data
+ *
+ */
+int xtract_nonzero_count(const float *data, const int N, const void *argv, float *result);
+
/** @} */
#ifdef __cplusplus
diff --git a/xtract/xtract_vector.h b/xtract/xtract_vector.h
index a66e840..d93f953 100644
--- a/xtract/xtract_vector.h
+++ b/xtract/xtract_vector.h
@@ -38,7 +38,7 @@ extern "C" {
*
* \param *data: a pointer to the first element in an array of floats representing an audio vector
* \param N: the number of array elements to be considered
- * \param *argv: a pointer to an array of floats, the first representing (samplerate / N), the second will be cast to an integer and determines the spectrum type (e.g. MAGNITUDE_SPECTRUM, LOG_POWER_SPECTRUM)
+ * \param *argv: a pointer to an array of floats, the first representing (samplerate / N), the second will be cast to an integer and determines the spectrum type (e.g. XTRACT_MAGNITUDE_SPECTRUM, XTRACT_LOG_POWER_SPECTRUM)
* \param *result: a pointer to an array of size N containing N/2 magnitude/power/log magnitude/log power coefficients and N/2 bin frequencies.
*/
int xtract_spectrum(const float *data, const int N, const void *argv, float *result);
@@ -110,10 +110,10 @@ int xtract_asdf(const float *data, const int N, const void *argv, float *result)
int xtract_bark_coefficients(const float *data, const int N, const void *argv, float *result);
/** \brief Extract the amplitude and frequency of spectral peaks from a magnitude spectrum
- * \param *data: a pointer to an array of size N containing N/2 magnitude/power/log magnitude/log power coefficients and N/2 bin frequencies. (e.g. the first half of the array pointed to by *result from xtract_spectrum().
- * \param N: the size of the output array (note: the input array can be of size N/2, i.e. just the magnitudes)
+ * \param *data: a pointer to an array of size N containing N magnitude/power/log magnitude/log power coefficients. (e.g. the first half of the array pointed to by *result from xtract_spectrum().
+ * \param N: the size of the input array (note: it is assumed that enough memory has been allocated for an output array twice the size)
* \param *argv: a pointer to an array of floats, the first representing (samplerate / N), the second representing the peak threshold as percentage of the magnitude of the maximum peak found
- * \param *result: a pointer to an array of size N containing N/2 magnitude/power/log magnitude/log power coefficients and N/2 bin frequencies.
+ * \param *result: a pointer to an array of size N * 2 containing N magnitude/power/log magnitude/log power coefficients and N bin frequencies.
*
*/
int xtract_peak_spectrum(const float *data, const int N, const void *argv, float *result);