diff options
-rw-r--r-- | src/scalar.c | 9 | ||||
-rw-r--r-- | src/vector.c | 8 | ||||
-rw-r--r-- | xtract/xtract_scalar.h | 36 | ||||
-rw-r--r-- | xtract/xtract_vector.h | 13 |
4 files changed, 39 insertions, 27 deletions
diff --git a/src/scalar.c b/src/scalar.c index 612fa3c..49c4408 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -291,14 +291,17 @@ int xtract_rolloff(const float *data, const int N, const void *argv, float *resu int xtract_loudness(const float *data, const int N, const void *argv, float *result){ - int n = BARK_BANDS; + int n = N, rv; - /*if(n != N) return BAD_VECTOR_SIZE; */ + if(n > BARK_BANDS) + rv = BAD_VECTOR_SIZE; + else + rv = SUCCESS; while(n--) *result += pow(data[n], 0.23); - return SUCCESS; + return rv; } int xtract_flatness(const float *data, const int N, const void *argv, float *result){ diff --git a/src/vector.c b/src/vector.c index 739004e..bc7140b 100644 --- a/src/vector.c +++ b/src/vector.c @@ -51,12 +51,12 @@ int xtract_magnitude_spectrum(const float *data, const int N, const void *argv, fftwf_execute(plan); for(n = 1; n < M; n++){ - result[n] = sqrt(SQ(temp[n]) + SQ(temp[N - n])) / N; - result[M + n] = n * q; + result[M + n] = sqrt(SQ(temp[n]) + SQ(temp[N - n])) / N; + result[n] = n * q; } - result[0] = fabs(temp[0]) / N; - result[M] = q * .5; + result[M] = fabs(temp[0]) / N; + result[0] = q * .5; fftwf_destroy_plan(plan); fftwf_free(temp); diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h index 8d8c446..4df5a6d 100644 --- a/xtract/xtract_scalar.h +++ b/xtract/xtract_scalar.h @@ -90,16 +90,19 @@ int xtract_kurtosis(const float *data, const int N, const void *argv, float *re /** \brief Extract the centroid of an input vector * - * \param *data: a pointer to the first element in an array of floats represeting a frequency spectrum of size N/2 and a magnitude peak spectrum of size N/2 (This is the output format of xtract_peaks) + * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector, (e.g. the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the centroid of the values pointed to by *data + * + * Note: for a more 'accurate' result *result from xtract_peaks() can be passed in. This gives the interpolated peak frequency locations. + * */ int xtract_centroid(const float *data, const int N, const void *argv, float *result); /** \brief Calculate the Irregularity of an input vector using a method described by Krimphoff (1994) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the irregularity of N values from the array pointed to by *data @@ -108,7 +111,7 @@ int xtract_irregularity_k(const float *data, const int N, const void *argv, floa /** \brief Calculate the Irregularity of an input vector using a method described by Jensen (1999) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the irregularity of N values from the array pointed to by *data @@ -117,7 +120,7 @@ int xtract_irregularity_j(const float *data, const int N, const void *argv, floa /** \brief Calculate the Tristimulus of an input vector using a method described by Pollard and Jansson (1982) * - * \param *data: a pointer to the first element in an array of floats representing the amplitudes of the harmonic spectrum of an audio vector e.g. a pointer to the second half of the array pointed to by *result from xtract_harmonics(). The amplitudes of the peak spectrum (e.g. *result from xtract_peaks()) can be used if one wishes to consider all partials not just harmonics. + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients of the harmonic spectrum of an audio vector e.g. a pointer to the second half of the array pointed to by *result from xtract_harmonics(). The amplitudes of the peak spectrum (e.g. *result from xtract_peaks()) can be used if one wishes to consider all partials not just harmonics. * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the tristimulus of N values from the array pointed to by *data @@ -131,7 +134,7 @@ int xtract_tristimulus_3(const float *data, const int N, const void *argv, float /** \brief Extract the smoothness of an input vector using a method described by McAdams (1999) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to the first element of an array of integers containing the lower bound, upper bound, and pre-scaling factor, whereby array data in the range lower < n < upper will be pre-scaled by p before processing. * \param *result: the smoothness of N values from the array pointed to by *data @@ -140,7 +143,7 @@ int xtract_smoothness(const float *data, const int N, const void *argv, float *r /** \brief Extract the spectral spread of an input vector using a method described by Casagrande(2005) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the spectral spread of N values from the array pointed to by *data @@ -160,7 +163,7 @@ int xtract_zcr(const float *data, const int N, const void *argv, float *result); /** \brief Extract the spectral rolloff of an input vector using a method described by Bee Suan Ong (2005) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to an array containing a floating point value representing the threshold for rolloff, i.e. the percentile at which the rolloff is determined, expressed in the range 0-1.0, and a float representing the sample rate in Hz * \param *result: the spectral rolloff in Hz of N values from the array pointed to by *data. This is the point in the spectrum below which argv[0] of the energy is distributed. @@ -170,18 +173,21 @@ int xtract_rolloff(const float *data, const int N, const void *argv, float *resu /* Loudness */ /* A set of BARK_BANDS bark coefficients must be passed in, the loudness is calculated approximately according to Moore, Glasberg et al, 1997 */ -/** \brief Extract the loudness of an input vector using a method described by Moore, Glasberg et al (2005) +/** \brief Extract the 'total loudness' of an input vector using a method described by Moore, Glasberg et al (2005) * * \param *data: a pointer to the first element in an array of floats representing a set of BARK_BANDS bark coefficients * \param N: the number of coefficients to be considered * \param *argv: a pointer to NULL - * \param *result: the loudness of N values from the array pointed to by *data + * \param *result: the total loudness of N values from the array pointed to by *data + * + * Note: if N = 1, the 'specific loudness' of the bark band pointed to by *data will be given by *result + * */ int xtract_loudness(const float *data, const int N, const void *argv, float *result); /** \brief Extract the spectral flatness measure of an input vector using a method described by Tristan Jehan (2005) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the spectral flatness of N values from the array pointed to by *data @@ -200,7 +206,7 @@ int xtract_tonality(const float *data, const int N, const void *argv, float *res /** \brief Extract the noisiness of an input vector using a method described by Tae Hong Park (2000) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the noisiness of N values from the array pointed to by *data @@ -227,7 +233,7 @@ int xtract_inharmonicity(const float *data, const int N, const void *argv, float /** \brief Extract the spectral crest of an input vector using a method described by Peeters (2003) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the spectral crest of N values from the array pointed to by *data @@ -236,7 +242,7 @@ int xtract_crest(const float *data, const int N, const void *argv, float *result /** \brief Extract the Spectral Power of an input vector using a method described by Bee Suan Ong (2005) * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the spectral power of N values from the array pointed to by *data @@ -256,6 +262,7 @@ int xtract_odd_even_ratio(const float *data, const int N, const void *argv, floa /** \brief Extract the Sharpness of an input vector * * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the Sharpness of N values from the array pointed to by *data @@ -265,6 +272,7 @@ int xtract_sharpness(const float *data, const int N, const void *argv, float *re /** \brief Extract the Slope of an input vector * * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the Slope of N values from the array pointed to by *data @@ -305,7 +313,7 @@ int xtract_sum(const float *data, const int N, const void *argv, float *result); * * \warning {This function doesn't work properly} * - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of elements to be considered * \param *argv: a pointer to NULL * \param *result: the pitch of N values from the array pointed to by *data diff --git a/xtract/xtract_vector.h b/xtract/xtract_vector.h index 92e908a..21947c5 100644 --- a/xtract/xtract_vector.h +++ b/xtract/xtract_vector.h @@ -38,8 +38,9 @@ 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 NULL - * \param *result: the magnitude spectrum of N values from the array pointed to by *data + * \param *argv: a pointer to a float representing the sample rate of the audio + * \param *result: a pointer to an array containing N/2 bin frequencies, and N/2 + * magnitude coefficients. */ int xtract_magnitude_spectrum(const float *data, const int N, const void *argv, float *result); @@ -54,7 +55,7 @@ int xtract_autocorrelation_fft(const float *data, const int N, const void *argv, /** \brief Extract Mel Frequency Cepstral Coefficients based on a method described by Rabiner * - * \param *data: a pointer to the first element in an array of floats + * \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 a data structure of type xtract_mel_filter, containing n_filters coefficient tables to make up a mel-spaced filterbank * \param *result: a pointer to an array containing the resultant MFCC @@ -82,7 +83,7 @@ int xtract_autocorrelation(const float *data, const int N, const void *argv, flo /** \brief Extract Average Magnitude Difference Function from time domain signal * - * \param *data: a pointer to the first element in an array of floats + * \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 NULL * \param *result: the AMDF of N values from the array pointed to by *data @@ -99,7 +100,7 @@ int xtract_amdf(const float *data, const int N, const void *argv, float *result) int xtract_asdf(const float *data, const int N, const void *argv, float *result); /** \brief Extract Bark band coefficients based on a method - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of array elements to be considered * \param *argv: a pointer to an array of ints representing the limits of each bark band. This can be obtained by calling xtract_init_bark. * \param *result: a pointer to an array containing resultant bark coefficients @@ -110,7 +111,7 @@ 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 frequency and amplitude of spectral peaks from a magnitude spectrum - * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector + * \param *data: a pointer to the first element in an array of floats representing the magnitude coefficients from the magnitude spectrum of an audio vector, (e.g. the second half of the array pointed to by *result from xtract_magnitude_spectrum(). * \param N: the number of array elements to be considered * \param *argv: a pointer to an array containing the peak threshold as percentage of the magnitude of the maximum peak found, and the sample rate in Hz. * \param *result: a pointer to an array of size N, containing N/2 freqs and N/2 amplitudes |