Changeset 7c6c806


Ignore:
Timestamp:
Sep 6, 2007, 7:32:13 PM (13 years ago)
Author:
Amaury Hazan <mahmoudax@gmail.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
7a46bf6, fdf39ba
Parents:
71b1b4b
Message:

minor changes

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • examples/aubiomfcc.c

    r71b1b4b r7c6c806  
    2727  unsigned int j;       /*frames*/
    2828 
    29   // declare the mel filter bank
    30   // TODO: should be done only once
    31   aubio_mfcc_init(int N, NYQUIST, int style, float freq_min, float freq_max, int freq_bands, float **fft_tables);
    32 
    3329  for (j=0;j<(unsigned)nframes;j++) {
    3430    if(usejack) {
     
    4743      aubio_pvoc_do (pv,ibuf, fftgrain);
    4844     
     45      uint_t n_coefs= n_filters/2 +1;
    4946      uint_t coef_cnt;
    50       uint_t n_filters=20;
    51       smpl_t outbuf[20];
     47       
    5248
    53       for (coef_cnt=0; coef_cnt<n_filters ; coef_cnt++)
    54         outbuf[coef_cnt]=0.f;
     49      for (coef_cnt=0; coef_cnt<n_coefs ; coef_cnt++)
     50        mfcc_outbuf[coef_cnt]=0.f;
    5551       
    5652      //compute mfccs
    57       aubio_mffc_do(fftgrain->norm, nframes, mf, outbuf);
     53      aubio_mffc_do(fftgrain->norm, nframes, mf, mfcc_outbuf, fft_dct, fftgrain_dct);
    5854     
    59       for (coef_cnt=0; coef_cnt<n_filters ; coef_cnt++)
    60         outmsg("%f ",outbuf[coef_cnt]);
     55      for (coef_cnt=0; coef_cnt<n_coefs ; coef_cnt++)
     56        outmsg("%f ",mfcc_outbuf[coef_cnt]);
    6157      outmsg("\n");
    6258     
     
    9086 
    9187  //allocate and initialize mel filter bank
    92   uint_t n_filters=20;
    93   uint_t nyquist= samplerate / 2.;
    94   smpl_t lowfreq=80.f;
    95   smpl_t highfreq=18000.f;
     88 
    9689
     90  //allocating global mf (in utils.c)
    9791  uint_t banksize = (uint) ( sizeof(aubio_mel_filter));
    98   aubio_mel_filter * mf = (aubio_mel_filter *)getbytes(banksize);
     92  mf = (aubio_mel_filter *)getbytes(banksize);
    9993
    10094  mf->n_filters = 20;
  • examples/utils.c

    r71b1b4b r7c6c806  
    6060int isonset = 0;
    6161aubio_pickpeak_t * parms;
     62
     63/* mfcc objects */
     64//parameters
     65uint_t n_filters=20;
     66uint_t nyquist= samplerate / 2.;
     67smpl_t lowfreq=80.f;
     68smpl_t highfreq=18000.f;
     69// filterbank object
     70aubio_mel_filter * mf;
     71
     72// DCT mfft and result storage
     73aubio_mfft * fft_dct;
     74cvec_t * fftgrain_dct;
     75smpl_t mfcc_outbuf[11];
    6276
    6377
     
    301315  fftgrain  = new_cvec(buffer_size, channels);
    302316
     317  //init for mfcc process
     318  fftgrain_dct= new_cvec(n_filters, channels);
     319
    303320  if (usepitch) {
    304321    pitchdet = new_aubio_pitchdetection(buffer_size*4,
     
    313330  /* phase vocoder */
    314331  pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
     332 
     333  // dct phase vocoder
     334  //TODO: check size
     335  fft_dct = new_aubio_mfft(n_filters, channels);
     336
    315337  /* onsets */
    316338  parms = new_aubio_peakpicker(threshold);
     
    346368  del_fvec(onset);
    347369  del_fvec(woodblock);
     370 
     371  //mffc related
     372  del_aubio_mfft(fft_dct);
     373  del_cvec(fftgrain_dct);
     374 
    348375  aubio_cleanup();
    349376}
  • examples/utils.h

    r71b1b4b r7c6c806  
    9898extern aubio_pickpeak_t * parms;
    9999
     100/* mfcc objects */
     101// params
     102extern uint_t n_filters;
     103extern uint_t nyquist;
     104extern smpl_t lowfreq;
     105extern smpl_t highfreq;
     106// filterbank object
     107extern aubio_mel_filter * mf;
     108// DCT pvoc and result storage
     109extern aubio_mfft_t * fft_dct;
     110extern cvec_t * fftgrain_dct;
     111extern smpl_t mfcc_outbuf[20];
    100112
    101113/* pitch objects */
  • src/Makefile.am

    r71b1b4b r7c6c806  
    2222        onset.h \
    2323        tempo.h \
    24         filter.h
     24        filter.h \
     25        mfcc.h
    2526
    2627nodist_pkginclude_HEADERS = config.h
     
    7172        filter.c \
    7273        filter.h \
     74        mfcc.h \
     75        mfcc.c
    7376
    7477AM_CFLAGS = @AUBIO_CFLAGS@ @FFTWLIB_CFLAGS@ @SAMPLERATE_CFLAGS@
  • src/filterbank.c

    r71b1b4b r7c6c806  
    2121*/
    2222
     23#include "aubio_priv.h"
    2324#include "filterbank.h"
     25
     26
     27// Struct Declaration
     28
     29/** \brief A structure to store a set of n_filters Mel filters */
     30typedef struct aubio_mel_filter_ {
     31    int n_filters;
     32    smpl_t **filters;
     33};
    2434
    2535// Initialization
  • src/filterbank.h

    r71b1b4b r7c6c806  
    2323#define AUBIOFILTERBANK_H
    2424
     25#ifdef __cplusplus
     26extern "C" {
     27#endif
    2528
    26 // Struct Declaration
    2729
    28 /** \brief A structure to store a set of n_filters Mel filters */
    29 typedef struct aubio_mel_filter_ {
    30     int n_filters;
    31     smpl_t **filters;
    32 } aubio_mel_filter;
     30
     31typedef struct aubio_mel_filter_ aubio_mel_filter;
    3332
    3433// Initialization
     
    3837 * 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
    3938 */
    40 int aubio_mfcc_init(int N, float nyquist, int style, float freq_min, float freq_max, int freq_bands, smpl_t ** fft_tables);
     39int aubio_mfcc_init(int N, smpl_t nyquist, int style, smpl_t freq_min, smpl_t freq_max, int freq_bands, smpl_t ** fft_tables);
     40
     41#ifdef __cplusplus
     42}
     43#endif
    4144
    4245#endif
  • src/mfcc.c

    r71b1b4b r7c6c806  
    2121*/
    2222
     23#include "aubio_priv.h"
     24#include "sample.h"
     25#include "fft.h"
     26#include "mfcc.h"
     27#include "math.h"
    2328
    24 #include "mffc.h"
     29/*
     30new_aubio_mfcc
     31aubio_mfcc_do
     32del_aubio_mfcc
     33*/
    2534
    2635// Computation
     36// Added last two arguments to be able to pass from example
    2737
    28 int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result){
     38
     39
     40int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){
    2941
    3042    aubio_mel_filter *f;
     
    3850            result[filter] += data[n] * f->filters[filter][n];
    3951        }
    40         result[filter] = log(result[filter] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : result[filter]);
     52        result[filter] = LOG(result[filter] < XTRACT_LOG_LIMIT ? XTRACT_LOG_LIMIT : result[filter]);
    4153    }
    4254
    43     //TODO: check that zero padding
     55    //TODO: check that zero padding 
    4456    for(n = filter + 1; n < N; n++) result[n] = 0;
    4557   
    46     aubio_dct_do(result, f->n_filters, NULL, result);
     58    aubio_dct_do(result, f->n_filters, NULL, result, fft_dct, fftgrain_dct);
    4759   
    4860    return XTRACT_SUCCESS;
    4961}
    5062
    51 int aubio_dct_do(const float *data, const int N, const void *argv, float *result){
     63// Added last two arguments to be able to pass from example
     64
     65int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t * fft_dct, cvec_t * fftgrain_dct){
    5266   
    5367   
     
    5670    //TODO: fvec as input? Remove data length, N?
    5771
     72    fvec_t * momo = new_fvec(20, 1);
     73    momo->data = data;
     74   
    5875    //compute mag spectrum
    59     aubio_pvoc_do (pv,data, fftgrain);
     76    aubio_mfft_do (fft_dct, data, fftgrain_dct);
    6077
    6178    int i;
    6279    //extract real part of fft grain
    6380    for(i=0; i<N ;i++){
    64       result[i]= fftgrain->norm[i]*cos(fftgrain->phase[i]);
     81      result[i]= fftgrain_dct->norm[0][i]*COS(fftgrain_dct->phas[0][i]);
    6582    }
    66    
    67     /*
    68     fftwf_plan plan;
    69    
    70     plan =
    71         fftwf_plan_r2r_1d(N, (float *) data, result, FFTW_REDFT00, FFTW_ESTIMATE);
    72    
    73     fftwf_execute(plan);
    74     fftwf_destroy_plan(plan);*/
     83
    7584
    7685    return XTRACT_SUCCESS;
  • src/mfcc.h

    r71b1b4b r7c6c806  
    2424#define MFCC_H
    2525
     26#ifdef __cplusplus
     27extern "C" {
     28#endif
     29
    2630#include "filterbank.h"
    2731
    28 //libXtract enums
     32//libXtract constants and enums
    2933// TODO: remove them
     34
     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 */
    3059
    3160/** \brief Enumeration of feature initialisation functions */
     
    132161 * The data structure pointed to by *argv must be obtained by first calling xtract_init_mfcc
    133162 */
    134 int aubio_mfcc_do(const float *data, const int N, const void *argv, float *result);
     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);
    135166
    136167/** \brief Extract the Discrete Cosine transform of a time domain signal
     
    140171 * \param *result: a pointer to an array containing resultant dct coefficients
    141172 */
    142 int aubio_dct_do(const float *data, const int N, const void *argv, float *result);
     173int aubio_dct_do(const float *data, const int N, const void *argv, float *result, aubio_mfft_t *fft_dct, cvec_t *fftgrain_dct);
    143174
     175#ifdef __cplusplus
     176}
     177#endif
    144178
    145179#endif
Note: See TracChangeset for help on using the changeset viewer.