Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mfcc.h

    rb276dee r7c6c806d  
    11/*
    2    Copyright (C) 2007 Amaury Hazan <ahazan@iua.upf.edu>
    3                   and Paul Brossier <piem@piem.org>
     2   Copyright (C) 2006 Amaury Hazan
     3   Ported to aubio from LibXtract
     4   http://libxtract.sourceforge.net/
     5   
    46
    57   This program is free software; you can redistribute it and/or modify
     
    1921*/
    2022
    21 /* part of this mfcc implementation were inspired from LibXtract
    22    http://libxtract.sourceforge.net/
    23 */
    24 
    2523#ifndef MFCC_H
    2624#define MFCC_H
     
    3028#endif
    3129
    32 #include "sample.h"
    3330#include "filterbank.h"
    3431
    35 typedef struct aubio_mfcc_t_ aubio_mfcc_t;
     32//libXtract constants and enums
     33// TODO: remove them
    3634
    37 /** create mfcc object
     35#define XTRACT_SQ(a) ((a) * (a))
     36#define XTRACT_MIN(a, b) ((a) < (b) ? (a) : (b))
     37#define XTRACT_MAX(a, b) ((a) > (b) ? (a) : (b))
     38#define XTRACT_NEEDS_FFTW printf("LibXtract must be compiled with fftw support to use this function.\n")
     39#define XTRACT_VERY_SMALL_NUMBER 2e-42
     40#define XTRACT_LOG_LIMIT XTRACT_VERY_SMALL_NUMBER
     41#define XTRACT_LOG_LIMIT_DB -96.0
     42#define XTRACT_DB_SCALE_OFFSET 96.0
     43#define XTRACT_VERY_BIG_NUMBER 2e42
     44#define XTRACT_SR_UPPER_LIMIT 192000.0
     45#define XTRACT_SR_LOWER_LIMIT 22050.0
     46#define XTRACT_SR_DEFAULT 44100.0
     47#define XTRACT_FUNDAMENTAL_DEFAULT 440.0
     48#define XTRACT_CHECK_nyquist if(!nyquist) nyquist = XTRACT_SR_DEFAULT / 2
     49#define XTRACT_CHECK_q if(!q) q = XTRACT_SR_DEFAULT / N
     50#define XTRACT_IS_ODD(x) (x % 2 != 0 ? 1 : 0)
     51#define XTRACT_SR_LIMIT SR_UPPER_LIMIT
     52#define XTRACT_FFT_BANDS_MIN 16
     53#define XTRACT_FFT_BANDS_MAX 65536
     54#define XTRACT_FFT_BANDS_DEF 1024
     55#define XTRACT_SPEC_BW_MIN 0.168 /* Minimum spectral bandwidth \
     56            (= SR_LOWER_LIMIT / FFT_BANDS_MAX*/
     57#define XTRACT_SPEC_BW_MAX 12000.0 /* SR_UPPER_LIMIT / FFT_BANDS_MIN */
     58#define XTRACT_SPEC_BW_DEF 43.066 /* SR_DEFAULT / FFT_BANDS_DEF */
    3859
    39   \param win_s size of analysis buffer (and length the FFT transform)
    40   \param samplerate
    41   \param n_coefs: number of desired coefs
    42   \param lowfreq: lowest frequency to use in filterbank
    43   \param highfreq highest frequency to use in filterbank
    44   \param channels number of channels
     60/** \brief Enumeration of feature initialisation functions */
     61enum xtract_feature_init_ {
     62    XTRACT_INIT_MFCC = 100,
     63    XTRACT_INIT_BARK
     64};
    4565
    46 */
    47 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate ,uint_t n_coefs, smpl_t lowfreq, smpl_t highfreq, uint_t channels);
    48 /** delete mfcc object
     66/** \brief Enumeration of feature types */
     67enum xtract_feature_types_ {
     68    XTRACT_SCALAR,
     69    XTRACT_VECTOR,
     70    XTRACT_DELTA
     71};
    4972
    50   \param mf mfcc object as returned by new_aubio_mfcc
     73/** \brief Enumeration of mfcc types */
     74enum xtract_mfcc_types_ {
     75    XTRACT_EQUAL_GAIN,
     76    XTRACT_EQUAL_AREA
     77};
    5178
    52 */
    53 void del_aubio_mfcc(aubio_mfcc_t *mf);
    54 /** mfcc object processing
     79/** \brief Enumeration of return codes */
     80enum xtract_return_codes_ {
     81    XTRACT_SUCCESS,
     82    XTRACT_MALLOC_FAILED,
     83    XTRACT_BAD_ARGV,
     84    XTRACT_BAD_VECTOR_SIZE,
     85    XTRACT_NO_RESULT,
     86    XTRACT_FEATURE_NOT_IMPLEMENTED
     87};
    5588
    56   \param mf mfcc object as returned by new_aubio_mfcc
    57   \param in input spectrum (win_s long)
    58   \param out output mel coefficients buffer (n_filters/2 +1 long)
     89/** \brief Enumeration of spectrum types */
     90enum xtract_spectrum_ {
     91    XTRACT_MAGNITUDE_SPECTRUM,
     92    XTRACT_LOG_MAGNITUDE_SPECTRUM,
     93    XTRACT_POWER_SPECTRUM,
     94    XTRACT_LOG_POWER_SPECTRUM
     95};
    5996
    60 */
    61 void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out);
     97/** \brief Enumeration of data types*/
     98typedef enum type_ {
     99    XTRACT_FLOAT,
     100    XTRACT_FLOATARRAY,
     101    XTRACT_INT,
     102    XTRACT_MEL_FILTER
     103} xtract_type_t;
    62104
    63 /** intermediate dct involved in aubio_mfcc_do
     105/** \brief Enumeration of units*/
     106typedef enum unit_ {
     107    /* NONE, ANY */
     108    XTRACT_HERTZ = 2,
     109    XTRACT_ANY_AMPLITUDE_HERTZ,
     110    XTRACT_DBFS,
     111    XTRACT_DBFS_HERTZ,
     112    XTRACT_PERCENT,
     113    XTRACT_SONE
     114} xtract_unit_t;
    64115
    65   \param mf mfcc object as returned by new_aubio_mfcc
    66   \param in input spectrum (n_filters long)
    67   \param out output mel coefficients buffer (n_filters/2 +1 long)
     116/** \brief Boolean */
     117typedef enum {
     118    XTRACT_FALSE,
     119    XTRACT_TRUE
     120} xtract_bool_t;
    68121
    69 */
    70 void aubio_dct_do(aubio_mfcc_t * mf, fvec_t *in, fvec_t *out);
     122/** \brief Enumeration of vector format types*/
     123typedef enum xtract_vector_ {
     124    /* N/2 magnitude/log-magnitude/power/log-power coeffs and N/2 frequencies */
     125    XTRACT_SPECTRAL,     
     126    /* N spectral amplitudes */
     127    XTRACT_SPECTRAL_MAGNITUDES,
     128    /* N/2 magnitude/log-magnitude/power/log-power peak coeffs and N/2
     129     * frequencies */
     130    XTRACT_SPECTRAL_PEAKS,
     131    /* N spectral peak amplitudes */
     132    XTRACT_SPECTRAL_PEAKS_MAGNITUDES,
     133    /* N spectral peak frequencies */
     134    XTRACT_SPECTRAL_PEAKS_FREQUENCIES,
     135    /* N/2 magnitude/log-magnitude/power/log-power harmonic peak coeffs and N/2
     136     * frequencies */
     137    XTRACT_SPECTRAL_HARMONICS,
     138    /* N spectral harmonic amplitudes */
     139    XTRACT_SPECTRAL_HARMONICS_MAGNITUDES,
     140    /* N spectral harmonic frequencies */
     141    XTRACT_SPECTRAL_HARMONICS_FREQUENCIES,
     142    XTRACT_ARBITRARY_SERIES,
     143    XTRACT_AUDIO_SAMPLES,
     144    XTRACT_MEL_COEFFS,
     145    XTRACT_BARK_COEFFS,
     146    XTRACT_NO_DATA
     147} xtract_vector_t;
     148
     149
     150
     151
     152// Computation
     153
     154/** \brief Extract Mel Frequency Cepstral Coefficients based on a method described by Rabiner
     155 *
     156 * \param *data: a pointer to the first element in an array of spectral magnitudes, e.g. the first half of the array pointed to by *resul from xtract_spectrum()
     157 * \param N: the number of array elements to be considered
     158 * \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
     159 * \param *result: a pointer to an array containing the resultant MFCC
     160 *
     161 * The data structure pointed to by *argv must be obtained by first calling xtract_init_mfcc
     162 */
     163
     164
     165int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct);
     166
     167/** \brief Extract the Discrete Cosine transform of a time domain signal
     168 * \param *data: a pointer to the first element in an array of floats representing an audio vector
     169 * \param N: the number of array elements to be considered
     170 * \param *argv: a pointer to NULL
     171 * \param *result: a pointer to an array containing resultant dct coefficients
     172 */
     173int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct);
    71174
    72175#ifdef __cplusplus
     
    74177#endif
    75178
    76 #endif // MFCC_H
     179#endif
Note: See TracChangeset for help on using the changeset viewer.