aboutsummaryrefslogtreecommitdiff
path: root/xtract
diff options
context:
space:
mode:
Diffstat (limited to 'xtract')
-rw-r--r--xtract/Makefile.am5
-rw-r--r--xtract/libxtract.h182
-rw-r--r--xtract/xtract_delta.h61
-rw-r--r--xtract/xtract_macros.h41
-rw-r--r--xtract/xtract_scalar.h144
-rw-r--r--xtract/xtract_types.h46
-rw-r--r--xtract/xtract_vector.h65
7 files changed, 544 insertions, 0 deletions
diff --git a/xtract/Makefile.am b/xtract/Makefile.am
new file mode 100644
index 0000000..b29e60d
--- /dev/null
+++ b/xtract/Makefile.am
@@ -0,0 +1,5 @@
+libxtractdir = $(includedir)/xtract
+
+libxtract_HEADERS = libxtract.h xtract_macros.h xtract_types.h xtract_delta.h \
+ xtract_scalar.h xtract_vector.h
+
diff --git a/xtract/libxtract.h b/xtract/libxtract.h
new file mode 100644
index 0000000..960aa66
--- /dev/null
+++ b/xtract/libxtract.h
@@ -0,0 +1,182 @@
+/* libxtract feature extraction library
+ *
+ * Copyright (C) 2006 Jamie Bullock
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+#ifndef XTRACT_H
+#define XTRACT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file libxtract.h: main header file and API definition
+ */
+
+#define VERSION "0.1"
+
+
+#include "xtract_scalar.h"
+#include "xtract_vector.h"
+#include "xtract_delta.h"
+#include "xtract_types.h"
+#include "xtract_macros.h"
+
+#define XTRACT_FEATURES 40
+#define LOG_LIMIT 10e-10
+#define SR_LIMIT 192000
+#define BARK_BANDS 26
+
+/** \brief Enumeration of features, elements are used as indixes to an array of pointers to feature extracton functions */
+
+enum features_ {
+ MEAN,
+ VARIANCE,
+ STANDARD_DEVIATION,
+ AVERAGE_DEVIATION,
+ SKEWNESS,
+ KURTOSIS,
+ IRREGULARITY_K,
+ IRREGULARITY_J,
+ TRISTIMULUS_1,
+ TRISTIMULUS_2,
+ TRISTIMULUS_3,
+ SMOOTHNESS,
+ SPREAD,
+ ZCR,
+ ROLLOFF,
+ LOUDNESS,
+ FLATNESS,
+ TONALITY,
+ CREST,
+ NOISINESS,
+ RMS_AMPLITUDE,
+ INHARMONICITY,
+ POWER,
+ ODD_EVEN_RATIO,
+ SHARPNESS,
+ SLOPE,
+ F0,
+ HPS,
+ MAGNITUDE_SPECTRUM,
+ AUTOCORRELATION,
+ AUTOCORRELATION_FFT,
+ AMDF,
+ ASDF,
+ MFCC,
+ DCT,
+ BARK_COEFFICIENTS,
+ PEAKS,
+ FLUX,
+ ATTACK_TIME,
+ DECAY_TIME,
+ DELTA_FEATURE
+};
+
+/** \brief Enumeration of feature types */
+
+enum feature_types_ {
+ SCALAR,
+ VECTOR,
+ DELTA
+};
+
+/** \brief Enumeration of mfcc types */
+
+enum mfcc_types_ {
+ EQUAL_GAIN,
+ EQUAL_AREA
+};
+
+/** \brief Enumeration of return codes */
+
+enum return_codes_ {
+ SUCCESS,
+ MALLOC_FAILED,
+ BAD_ARGV,
+ BAD_VECTOR_SIZE
+};
+
+/**
+ *
+ * \brief Perform feature extraction
+ *
+ * \param
+ *
+ * In general functions in this library conform to the following prototpe:
+ *
+ * int xtract_featurename(float *data, int N, void *argv, float *result)
+ *
+ *
+ * float *data: a pointer to an array element
+ *
+ * int N: the number of elements to be processed by the function
+ *
+ * void *argv: an abitrary number of additional arguments
+ *
+ * float *result: a pointer to the result
+ *
+ *
+ * Each function will iterate over N array elements, the first of which is
+ * pointed to by *data. It is therefore up to the caller to ensure that an
+ * approriate range of data is provided. For example, if the function expects
+ * an array containing an harmonic spectrum, then they array pointed to by
+ * *data must contain the amplitudes of harmonic frequencies in adjacent
+ * elemets
+ *
+ * For scalar and delta features, *result will point to a single value.
+ *
+ * For vector features it will point to the first element in an array.
+ *
+ * Memory for this array must be allocated and freed by the calling
+ * function.
+ *
+ * All functions return an integer error code as descibed in the enumeration
+ * return_codes_
+ *
+ * */
+
+
+int(*xtract[XTRACT_FEATURES])(float *, int, void *, float *);
+
+/* Data structures */
+
+typedef struct xtract_mel_filter_ {
+ int n_filters;
+ float **filters;
+} xtract_mel_filter;
+
+
+/* Initialisation functions */
+/* xtract_init_mfcc */
+/* It is up to the caller to pass in a pointer to memory allocated for freq_bands arrays of length N. This function populates these arrays with magnitude coefficients representing the mel filterbank on a linear scale */
+int xtract_init_mfcc(int N, float nyquist, int style, float freq_max, float freq_min, int freq_bands, float **fft_tables);
+
+/* xtract_init_bark */
+/* 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 */
+int xtract_init_bark(int N, float nyquist, int *band_limits);
+
+
+/* Free functions */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/xtract/xtract_delta.h b/xtract/xtract_delta.h
new file mode 100644
index 0000000..68f18a4
--- /dev/null
+++ b/xtract/xtract_delta.h
@@ -0,0 +1,61 @@
+/* libxtract feature extraction library
+ *
+ * Copyright (C) 2006 Jamie Bullock
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+/* xtract_delta.h: declares functions that extract a feature as a single value from more than one input vector */
+
+#ifndef XTRACT_DELTA
+#define XTRACT_DELTA
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "xtract_types.h"
+/* Flux/temporal variation */
+
+/* Gaƫl Richard (2006)*/
+int xtract_flux(float *data, int N, void *argv , float *result);
+/*xtract_frame_tracker *xf */
+
+/* Attack Time */
+
+int xtract_attack_time(float *data, int N, void *argv , float *result);
+/* xtract_amp_tracker *xa */
+
+/* Temporal decrease */
+
+int xtract_decay_time(float *data, int N, void *argv, float *result);
+/* xtract_amp_tracker *xa */
+
+
+/* Delta vector */
+/* Generic function to calculate the delta of a feature over a given period (in frames */
+
+int xtract_delta_feature(float *data, int N, void *argv, float *result);
+/*xtract_frame_tracker *xf */
+/*float frames*/
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/xtract/xtract_macros.h b/xtract/xtract_macros.h
new file mode 100644
index 0000000..d225db2
--- /dev/null
+++ b/xtract/xtract_macros.h
@@ -0,0 +1,41 @@
+/* libxtract feature extraction library
+ *
+ * Copyright (C) 2006 Jamie Bullock
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+
+
+/* xtract_delta.h: defines useful macros */
+
+#ifndef XTRACT_MACROS
+#define XTRACT_MACROS
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SQ(a) ((a) * (a))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define NOT_IMPLEMENTED printf("Feature not implemented yet.\n")
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h
new file mode 100644
index 0000000..d0d780b
--- /dev/null
+++ b/xtract/xtract_scalar.h
@@ -0,0 +1,144 @@
+/* libxtract feature extraction library
+ *
+ * Copyright (C) 2006 Jamie Bullock
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+/* xtract_scalar.h: declares functions that extract a feature as a single value from an input vector */
+
+#ifndef XTRACT_SCALAR
+#define XTRACT_SCALAR
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Statistical features */
+
+int xtract_mean(float *data, int N, void *argv, float *result);
+/* mean is passed in as arg */
+int xtract_variance(float *data, int N, void *argv, float *result);
+/* variance is passed in as arg */
+int xtract_standard_deviation(float *data, int N, void *argv, float *result);
+/* mean is passed in as arg */
+int xtract_average_deviation(float *data, int N, void *argv, float *result);
+/* mean and standard deviation are passed in as arg */
+int xtract_skewness(float *data, int N, void *argv, float *result);
+/* mean and standard deviation are passed in as arg */
+int xtract_kurtosis(float *data, int N, void *argv, float *result);
+
+/* Irregularity */
+
+/* Krimphoff (1994) */
+int xtract_irregularity_k(float *data, int N, void *argv, float *result);
+/* Jensen (1999) */
+int xtract_irregularity_j(float *data, int N, void *argv, float *result);
+
+/* Tristimulus */
+
+/* Pollard and Jansson (1982) */
+int xtract_tristimulus_1(float *data, int N, void *argv, float *result);
+int xtract_tristimulus_2(float *data, int N, void *argv, float *result);
+int xtract_tristimulus_3(float *data, int N, void *argv, float *result);
+
+/* Smoothness */
+
+/*McAdams (1999)*/
+int xtract_smoothness(float *data, int N, void *argv, float *result);
+
+/* Spectral Spread */
+
+/* Casagrande 2005 */
+
+int xtract_spread(float *data, int N, void *argv, float *result);
+
+/* Zero crossing rate */
+
+int xtract_zcr(float *data, int N, void *argv, float *result);
+
+/* Rolloff */
+
+/* Bee Suan Ong (2005) */
+/* Threshold is the percentile at which the rolloff is determined */
+
+int xtract_rolloff(float *data, int N, void *argv, float *result);
+
+/* Loudness */
+/* A set of BARK_BANDS bark coefficients must be passed in, the loudness is calculated approximately according to Moore, Glasberg et al, 1997 */
+
+int xtract_loudness(float *data, int N, void *argv, float *result);
+
+/* Spectral Flatness Measure */
+/* Tristan Jehan (2005) */
+
+int xtract_flatness(float *data, int N, void *argv, float *result);
+
+/* Tonality Factor */
+/* Tristan Jehan (2005) */
+
+int xtract_tonality(float *data, int N, void *argv, float *result);
+
+/* Noisiness */
+/* Tae Hong Park (2000) */
+
+int xtract_noisiness(float *data, int N, void *argv, float *result);
+
+/* RMS amplitude */
+/* Tae Hong Park (2000) */
+
+int xtract_rms_amplitude(float *data, int N, void *argv, float *result);
+
+/* Inharmonicity */
+
+int xtract_inharmonicity(float *data, int N, void *argv, float *result);
+
+/* Spectral Crest */
+/* Peeters (2003) */
+int xtract_crest(float *data, int N, void *argv, float *result);
+
+/* Spectral Power */
+/* Bee Suan Ong (2005) */
+int xtract_power(float *data, int N, void *argv, float *result);
+
+/* Odd to even harmonic ratio */
+
+int xtract_odd_even_ratio(float *data, int N, void *argv, float *result);
+
+/* Sharpness */
+
+int xtract_sharpness(float *data, int N, void *argv, float *result);
+
+/* Slope */
+int xtract_slope(float *data, int N, void *argv, float *result);
+
+/* F0 */
+/*This method takes a guess which can come from taking the ZCR of an autocorrelation function, and then finds the spectral peak that most closely matches the gess */
+int xtract_f0(float *data, int N, void *argv, float *result);
+
+/* Pitch */
+/* Pitch via HPS analysis */
+int xtract_hps(float *data, int N, void *argv, float *result);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
diff --git a/xtract/xtract_types.h b/xtract/xtract_types.h
new file mode 100644
index 0000000..39fce64
--- /dev/null
+++ b/xtract/xtract_types.h
@@ -0,0 +1,46 @@
+/* libxtract feature extraction library
+ *
+ * Copyright (C) 2006 Jamie Bullock
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+/* xtract_types.h: declares specialised variable types used by libxtract */
+
+#ifndef XTRACT_TYPES
+#define XTRACT_TYPES
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Data structure used to store amplitude data between calls to xtract_attack_time and other functions. */
+
+typedef struct _xtract_amp_tracker {
+ int count;
+ float previous_amp;
+} xtract_amp_tracker;
+
+typedef struct _xtract_frame_tracker {
+ int frame_count;
+ float *previous_frame;
+} xtract_frame_tracker;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/xtract/xtract_vector.h b/xtract/xtract_vector.h
new file mode 100644
index 0000000..16a6cc3
--- /dev/null
+++ b/xtract/xtract_vector.h
@@ -0,0 +1,65 @@
+/* libxtract feature extraction library
+ *
+ * Copyright (C) 2006 Jamie Bullock
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+/* xtract_scalar.h: declares functions that extract a feature as a vector from an input vector */
+
+#ifndef XTRACT_VECTOR
+#define XTRACT_VECTOR
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Extracts normalized (0-1) frequency domain magnitude spectrum from time domain signal */
+int xtract_magnitude_spectrum(float *data, int N, void *argv, float *result);
+
+
+/* Autocorrelation */
+int xtract_autocorrelation(float *data, int N, void *argv, float *result);
+
+
+int xtract_autocorrelation_fft(float *data, int N, void *argv, float *result);
+
+/* Average Magnitude Difference Function */
+int xtract_amdf(float *data, int N, void *argv, float *result);
+
+/* Average Squared Difference Function */
+int xtract_asdf(float *data, int N, void *argv, float *result);
+
+/* MFCC */
+/* Rabiner */
+int xtract_mfcc(float *data, int N, void *argv, float *result);
+
+/* Bark band */
+
+int xtract_bark_coefficients(float *data, int N, void *argv, float *result);
+
+/* Discrete cosine transform */
+int xtract_dct(float *data, int N, void *argv, float *result);
+
+/* Frequency and amplitude of spectral peaks */
+/* Takes peak threshold as percentage below max peak, and sr as argv, returns a pointer to an array of size N, containing N/2 freqs and N/2 amplitudes, amplitudes are on a decibel scale with dbFS = 0 */
+int xtract_peaks(float *data, int N, void *argv, float *result);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif