aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
6 files changed, 117 insertions, 73 deletions
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