Changeset 7a84b21 for src


Ignore:
Timestamp:
Sep 17, 2009, 7:54:57 PM (15 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
e03f74d
Parents:
c185ebb
Message:

src/spectral/mfcc.c: indent, update to GPLv3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/mfcc.c

    rc185ebb r7a84b21  
    11/*
    2    Copyright (C) 2006 Amaury Hazan
    3    Ported to aubio from LibXtract
    4    http://libxtract.sourceforge.net/
    5    
     2  Copyright (C) 2007-2009 Paul Brossier <piem@aubio.org>
     3                      and Amaury Hazan <ahazan@iua.upf.edu>
    64
    7    This program is free software; you can redistribute it and/or modify
    8    it under the terms of the GNU General Public License as published by
    9    the Free Software Foundation; either version 2 of the License, or
    10    (at your option) any later version.
     5  This file is part of Aubio.
    116
    12    This program is distributed in the hope that it will be useful,
    13    but WITHOUT ANY WARRANTY; without even the implied warranty of
    14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15    GNU General Public License for more details.
     7  Aubio is free software: you can redistribute it and/or modify
     8  it under the terms of the GNU General Public License as published by
     9  the Free Software Foundation, either version 3 of the License, or
     10  (at your option) any later version.
    1611
    17    You should have received a copy of the GNU General Public License
    18    along with this program; if not, write to the Free Software
    19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     12  Aubio is distributed in the hope that it will be useful,
     13  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  GNU General Public License for more details.
     16
     17  You should have received a copy of the GNU General Public License
     18  along with Aubio.  If not, see <http://www.gnu.org/licenses/>.
    2019
    2120*/
     
    2827#include "spectral/mfcc.h"
    2928
    30 /** Internal structure for mfcc object **/
     29/** Internal structure for mfcc object */
    3130
    32 struct aubio_mfcc_t_{
     31struct aubio_mfcc_t_
     32{
    3333  uint_t win_s;             /** grain length */
    3434  uint_t samplerate;        /** sample rate (needed?) */
    3535  uint_t n_filters;         /** number of  *filters */
    3636  uint_t n_coefs;           /** number of coefficients (<= n_filters/2 +1) */
    37   aubio_filterbank_t * fb;  /** filter bank */
    38   fvec_t * in_dct;          /** input buffer for dct * [fb->n_filters] */
    39   fvec_t * dct_coeffs;      /** DCT transform n_filters * n_coeffs */
     37  aubio_filterbank_t *fb;   /** filter bank */
     38  fvec_t *in_dct;           /** input buffer for dct * [fb->n_filters] */
     39  fvec_t *dct_coeffs;       /** DCT transform n_filters * n_coeffs */
    4040};
    4141
    4242
    43 aubio_mfcc_t * new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters, uint_t n_coefs){
     43aubio_mfcc_t *
     44new_aubio_mfcc (uint_t win_s, uint_t samplerate, uint_t n_filters,
     45    uint_t n_coefs)
     46{
     47
     48  /* allocate space for mfcc object */
     49  aubio_mfcc_t *mfcc = AUBIO_NEW (aubio_mfcc_t);
    4450
    4551  uint_t i, j;
    4652
    47   /** allocating space for mfcc object */
    48   aubio_mfcc_t * mfcc = AUBIO_NEW(aubio_mfcc_t);
     53  mfcc->win_s = win_s;
     54  mfcc->samplerate = samplerate;
     55  mfcc->n_filters = n_filters;
     56  mfcc->n_coefs = n_coefs;
    4957
    50   //we need (n_coefs-1)*2 filters to obtain n_coefs coefficients after dct
    51   //uint_t n_filters = (n_coefs-1)*2;
    52  
    53   mfcc->win_s=win_s;
    54   mfcc->samplerate=samplerate;
    55   mfcc->n_filters=n_filters;
    56   mfcc->n_coefs=n_coefs;
     58  /* filterbank allocation */
     59  mfcc->fb = new_aubio_filterbank (n_filters, mfcc->win_s);
     60  aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate);
    5761
    58  
    59   /** filterbank allocation */
    60   mfcc->fb = new_aubio_filterbank(n_filters, mfcc->win_s);
    61   aubio_filterbank_set_mel_coeffs_slaney(mfcc->fb, samplerate);
     62  /* allocating buffers */
     63  mfcc->in_dct = new_fvec (n_filters, 1);
    6264
    63   /** allocating buffers */
    64   mfcc->in_dct=new_fvec(n_filters, 1);
    65  
    66   mfcc->dct_coeffs = new_fvec(n_coefs, n_filters);
     65  mfcc->dct_coeffs = new_fvec (n_coefs, n_filters);
    6766
    68  
    6967  /* compute DCT transform dct_coeffs[i][j] as
    70     cos ( j * (i+.5) * PI / n_filters )
    71   */
    72   smpl_t scaling = 1./SQRT(n_filters/2.);
    73   for (i = 0; i < n_filters; i++) {
     68     cos ( j * (i+.5) * PI / n_filters ) */
     69  smpl_t scaling = 1. / SQRT (n_filters / 2.);
     70  for (i = 0; i < n_filters; i++) {
    7471    for (j = 0; j < n_coefs; j++) {
    7572      mfcc->dct_coeffs->data[i][j] =
    76         scaling * COS (j * (i + 0.5) * PI / n_filters);
     73          scaling * COS (j * (i + 0.5) * PI / n_filters);
    7774    }
    78     mfcc->dct_coeffs->data[i][0] *= SQRT(2.)/2.;
     75    mfcc->dct_coeffs->data[i][0] *= SQRT (2.) / 2.;
    7976  }
    8077
     
    8279};
    8380
    84 void del_aubio_mfcc(aubio_mfcc_t *mf){
    85   /** deleting filterbank */
    86   del_aubio_filterbank(mf->fb);
    87   /** deleting buffers */
    88   del_fvec(mf->in_dct);
    89  
    90   /** deleting mfcc object */
    91   AUBIO_FREE(mf);
     81void
     82del_aubio_mfcc (aubio_mfcc_t * mf)
     83{
     84
     85  /* delete filterbank */
     86  del_aubio_filterbank (mf->fb);
     87
     88  /* delete buffers */
     89  del_fvec (mf->in_dct);
     90
     91  /* delete mfcc object */
     92  AUBIO_FREE (mf);
    9293}
    9394
    9495
    95 void aubio_mfcc_do(aubio_mfcc_t * mf, cvec_t *in, fvec_t *out){
     96void
     97aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out)
     98{
    9699  uint_t i, j;
    97   // compute filterbank
    98   aubio_filterbank_do(mf->fb, in, mf->in_dct);
     100  /* compute filterbank */
     101  aubio_filterbank_do (mf->fb, in, mf->in_dct);
    99102
    100   //extract real part of fft grain
    101   for (i = 0; i < mf->n_filters; i++) { 
     103  /* extract real part of fft grain */
     104  for (i = 0; i < mf->n_filters; i++) {
    102105    for (j = 0; j < mf->n_coefs; j++) {
    103106      out->data[0][j] += mf->in_dct->data[0][i]
    104         * mf->dct_coeffs->data[i][j];
     107          * mf->dct_coeffs->data[i][j];
    105108    }
    106109  }
Note: See TracChangeset for help on using the changeset viewer.