Changes in / [c1656cf:7873363]


Ignore:
Files:
59 added
42 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    rc1656cf r7873363  
    3636uninstall-hook: uninstall-pkgconfig
    3737
     38lcov: all
     39        mkdir -p $(top_builddir)/lcov
     40        lcov --directory $(top_builddir) --output-file $(top_builddir)/lcov/aubio.info --compat-libtool --zerocounters
     41        cd tests/python && ./run_all_tests -v || echo "some tests failed"
     42        lcov --directory $(top_builddir) --output-file $(top_builddir)/lcov/aubio.info --compat-libtool --capture
     43        genhtml --output-directory $(top_builddir)/lcov $(top_builddir)/lcov/aubio.info
  • configure.ac

    rc1656cf r7873363  
    3535dnl Enable debugging (no)
    3636AC_ARG_ENABLE(debug,
    37   [  --enable-debug[[=value]]  compile with debug [[default=no]]],
     37  AC_HELP_STRING([--enable-debug],[compile in debug mode [[default=no]]]),
    3838  with_debug="yes",
    3939  with_debug="no")
     
    4646dnl Enable full warnings (yes)
    4747AC_ARG_ENABLE(warnings,
    48   [  --enable-warnings[[=value]] compile with all gcc warnings [[default=yes]]],
     48  AC_HELP_STRING([--enable-warnings],[compile with all gcc warnings [[default=yes]]]),
    4949  with_warnme="no",
    5050  with_warnme="yes")
     
    6767fi
    6868
     69dnl fail on compilation warnings
    6970AC_ARG_ENABLE(errorfail,
    70   [  --enable-errorfail[[=value]]  fail on compilation warnings [[default=no]]],
     71  AC_HELP_STRING([--enable-errorfail],[fail on compilation warnings [[default=no]]]),
    7172  AUBIO_CFLAGS="$AUBIO_CFLAGS -Werror -Wmissing-prototypes -Wmissing-declarations -Wno-unused-parameter",
    72   with_warnme="no")
     73  with_errorfail="no")
     74
     75dnl add gcov/lcov profiling and coverage flags
     76AC_ARG_ENABLE(lcov,
     77  AC_HELP_STRING([--enable-lcov],[compile with gcov/lcov profiling flags [[default=no]]]),
     78  AUBIO_CFLAGS="$AUBIO_CFLAGS -fprofile-arcs -ftest-coverage",
     79  with_lcov="no")
    7380
    7481dnl Check for libtool
     
    241248    ext/Makefile
    242249    examples/Makefile
    243     examples/tests/Makefile
     250    tests/Makefile
     251    tests/src/Makefile
    244252    sounds/Makefile
    245253    swig/Makefile
  • examples/Makefile.am

    rc1656cf r7873363  
    1 if COMPILE_TESTS
    2 SUBDIRS = tests
    3 endif
    4 
    51# global flags
    62AM_CFLAGS = -DAUBIO_PREFIX=\"$(prefix)\" -I$(top_srcdir)/src -I$(top_srcdir)/ext @AUBIO_CFLAGS@ @LASH_CFLAGS@ @FFTWLIB_CFLAGS@
  • examples/aubioonset.c

    rc1656cf r7873363  
    7272      if (isonset && output_filename == NULL) {
    7373        if(frames >= 4) {
    74           outmsg("%f\n",(frames-4)*overlap_size/(float)samplerate);
    75         } else if (frames < 4) {
     74          outmsg("%f\n",(frames-frames_delay)*overlap_size/(float)samplerate);
     75        } else if (frames < frames_delay) {
    7676          outmsg("%f\n",0.);
    7777        }
     
    8080
    8181int main(int argc, char **argv) {
     82  frames_delay = 4;
    8283  examples_common_init(argc,argv);
    8384  examples_common_process(aubio_process,process_print);
  • examples/utils.c

    rc1656cf r7873363  
    2222void save_data (void);
    2323void restore_data(lash_config_t * lash_config);
     24void flush_process(aubio_process_func_t process_func, aubio_print_func_t print);
    2425pthread_t lash_thread;
    2526#endif /* LASH_SUPPORT */
     
    3334int usejack = 0;
    3435int usedoubled = 1;
     36int frames_delay = 0;
    3537
    3638
     
    6062int isonset = 0;
    6163aubio_pickpeak_t * parms;
     64
    6265
    6366/* pitch objects */
     
    171174                                else if (strcmp(optarg,"kl") == 0)
    172175                                        type_onset = aubio_onset_kl;
     176                                else if (strcmp(optarg,"specflux") == 0)
     177                                        type_onset = aubio_onset_specflux;
    173178                                else {
    174179                                        errmsg("unknown onset type.\n");
     
    300305  fftgrain  = new_cvec(buffer_size, channels);
    301306
    302  
    303307  if (usepitch) {
    304308    pitchdet = new_aubio_pitchdetection(buffer_size*4,
     
    313317  /* phase vocoder */
    314318  pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
    315  
    316319  /* onsets */
    317320  parms = new_aubio_peakpicker(threshold);
     
    347350  del_fvec(onset);
    348351  del_fvec(woodblock);
    349  
    350352  aubio_cleanup();
    351353}
     
    397399
    398400    debug("Processed %d frames of %d samples.\n", frames, buffer_size);
     401
     402    flush_process(process_func, print);
    399403    del_aubio_sndfile(file);
    400404
     
    405409}
    406410
     411void flush_process(aubio_process_func_t process_func, aubio_print_func_t print){
     412  uint i,j;
     413  for (i = 0; i < channels; i++) {
     414    for (j = 0; j < obuf->length; j++) {
     415      fvec_write_sample(obuf,0.,i,j);
     416    }
     417  }
     418  for (i = 0; (signed)i < frames_delay; i++) {
     419    process_func(ibuf->data, obuf->data, overlap_size);
     420    print();
     421  }
     422}
    407423
    408424
  • examples/utils.h

    rc1656cf r7873363  
    4242extern int usejack;
    4343extern int usedoubled;
     44extern int frames_delay;
    4445extern unsigned int median;
    4546extern const char * output_filename;
     
    9899extern aubio_pickpeak_t * parms;
    99100
     101
    100102/* pitch objects */
    101103extern smpl_t pitch;
  • python/aubio/aubioclass.py

    rc1656cf r7873363  
    4343        else:
    4444            self.file = new_aubio_sndfile_ro(filename)
     45        if self.file == None: raise(ValueError, "failed opening file")
    4546    def __del__(self):
    46         del_aubio_sndfile(self.file)
     47        if self.file != None: del_aubio_sndfile(self.file)
    4748    def info(self):
    4849        aubio_sndfile_info(self.file)
     
    7374        aubio_onsetdetection(self.od,tc(),tf())
    7475    def __del__(self):
    75         aubio_onsetdetection_free(self.od)
     76        del_aubio_onsetdetection(self.od)
    7677
    7778class peakpick:
  • python/aubio/task/utils.py

    rc1656cf r7873363  
    1717        elif nvalue == 'mkl'           :
    1818                 return aubio_onset_mkl
     19        elif nvalue == 'specflux'      :
     20                 return aubio_onset_specflux
    1921        elif nvalue == 'dual'          :
    2022                 return 'dual'
    2123        else:
    2224                 import sys
    23                  print "unknown onset detection function selected"
     25                 print "unknown onset detection function selected: %s" % nvalue
    2426                 sys.exit(1)
    2527
  • src/Makefile.am

    rc1656cf r7873363  
    66        fft.h \
    77        sample.h \
     8        fvec.h \
     9        cvec.h \
    810        hist.h \
    911        scale.h \
     
    3739        fft.c \
    3840        fft.h \
    39         sample.c \
    40         sample.h \
     41        fvec.c \
     42        fvec.h \
     43        cvec.c \
     44        cvec.h \
    4145        hist.c \
    4246        hist.h \
  • src/aubio.h

    rc1656cf r7873363  
    11/*
    2         Copyright (C) 2003 Paul Brossier <piem@altern.org>
     2  Copyright (C) 2003 Paul Brossier <piem@altern.org>
    33
    4         This program is free software; you can redistribute it and/or modify
    5         it under the terms of the GNU General Public License as published by
    6         the Free Software Foundation; either version 2 of the License, or
    7         (at your option) any later version.
     4  This program is free software; you can redistribute it and/or modify
     5  it under the terms of the GNU General Public License as published by
     6  the Free Software Foundation; either version 2 of the License, or
     7  (at your option) any later version.
    88
    9         This program is distributed in the hope that it will be useful,
    10         but WITHOUT ANY WARRANTY; without even the implied warranty of
    11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12         GNU General Public License for more details.
     9  This program is distributed in the hope that it will be useful,
     10  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  GNU General Public License for more details.
    1313
    14         You should have received a copy of the GNU General Public License
    15         along with this program; if not, write to the Free Software
    16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    17        
     14  You should have received a copy of the GNU General Public License
     15  along with this program; if not, write to the Free Software
     16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     17 
    1818*/
    1919
     
    2222 * \section whatis Introduction
    2323 *
    24  *      Aubio is a library for audio labelling: it provides functions for pitch
    25  *      estimation, onset detection, beat tracking, and other annotation tasks.
     24 *  Aubio is a library for audio labelling: it provides functions for pitch
     25 *  estimation, onset detection, beat tracking, and other annotation tasks.
    2626 *
    2727 *  \verbinclude README
     
    2929 * \section bugs bugs and todo
    3030 *
    31  *      This software is under development. It needs debugging and
    32  *      optimisations.
     31 *  This software is under development. It needs debugging and
     32 *  optimisations.
    3333 *
    3434 *  See <a href='bug.html'>bugs</a> and <a href='todo.html'>todo</a> lists.
  • src/aubio_priv.h

    rc1656cf r7873363  
    11/*
    2          Copyright (C) 2003 Paul Brossier
     2   Copyright (C) 2003-2007 Paul Brossier
    33
    4         This program is free software; you can redistribute it and/or modify
    5         it under the terms of the GNU General Public License as published by
    6         the Free Software Foundation; either version 2 of the License, or
    7         (at your option) any later version.
     4  This program is free software; you can redistribute it and/or modify
     5  it under the terms of the GNU General Public License as published by
     6  the Free Software Foundation; either version 2 of the License, or
     7  (at your option) any later version.
    88
    9         This program is distributed in the hope that it will be useful,
    10         but WITHOUT ANY WARRANTY; without even the implied warranty of
    11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12         GNU General Public License for more details.
     9  This program is distributed in the hope that it will be useful,
     10  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  GNU General Public License for more details.
    1313
    14         You should have received a copy of the GNU General Public License
    15         along with this program; if not, write to the Free Software
    16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    17        
     14  You should have received a copy of the GNU General Public License
     15  along with this program; if not, write to the Free Software
     16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     17 
    1818*/
    1919
     
    7171
    7272/* Memory management */
    73 #define AUBIO_MALLOC(_n)                malloc(_n)
    74 #define AUBIO_REALLOC(_p,_n)            realloc(_p,_n)
    75 #define AUBIO_NEW(_t)                   (_t*)malloc(sizeof(_t))
    76 #define AUBIO_ARRAY(_t,_n)              (_t*)malloc((_n)*sizeof(_t))
    77 #define AUBIO_MEMCPY(_dst,_src,_n)      memcpy(_dst,_src,_n)
    78 #define AUBIO_MEMSET(_dst,_src,_t)      memset(_dst,_src,_t)
    79 #define AUBIO_FREE(_p)                  free(_p)       
     73#define AUBIO_MALLOC(_n)             malloc(_n)
     74#define AUBIO_REALLOC(_p,_n)         realloc(_p,_n)
     75#define AUBIO_NEW(_t)                (_t*)malloc(sizeof(_t))
     76#define AUBIO_ARRAY(_t,_n)           (_t*)malloc((_n)*sizeof(_t))
     77#define AUBIO_MEMCPY(_dst,_src,_n)   memcpy(_dst,_src,_n)
     78#define AUBIO_MEMSET(_dst,_src,_t)   memset(_dst,_src,_t)
     79#define AUBIO_FREE(_p)               free(_p)
    8080
    8181
  • src/fft.c

    rc1656cf r7873363  
    1919
    2020#include "aubio_priv.h"
    21 #include "sample.h"
     21#include "fvec.h"
     22#include "cvec.h"
    2223#include "mathutils.h"
    2324#include "fft.h"
    2425
    2526#if FFTW3F_SUPPORT
    26 #define fftw_malloc             fftwf_malloc
    27 #define fftw_free               fftwf_free
    28 #define fftw_execute            fftwf_execute
    29 #define fftw_plan_dft_r2c_1d    fftwf_plan_dft_r2c_1d
    30 #define fftw_plan_dft_c2r_1d    fftwf_plan_dft_c2r_1d
    31 #define fftw_plan_r2r_1d      fftwf_plan_r2r_1d
    32 #define fftw_plan               fftwf_plan
    33 #define fftw_destroy_plan       fftwf_destroy_plan
     27#define fftw_malloc            fftwf_malloc
     28#define fftw_free              fftwf_free
     29#define fftw_execute           fftwf_execute
     30#define fftw_plan_dft_r2c_1d   fftwf_plan_dft_r2c_1d
     31#define fftw_plan_dft_c2r_1d   fftwf_plan_dft_c2r_1d
     32#define fftw_plan_r2r_1d       fftwf_plan_r2r_1d
     33#define fftw_plan              fftwf_plan
     34#define fftw_destroy_plan      fftwf_destroy_plan
    3435#endif
    3536
     
    4142
    4243struct _aubio_fft_t {
    43         uint_t fft_size;
    44         uint_t channels;
    45         real_t          *in, *out;
    46         fft_data_t      *specdata;
    47         fftw_plan       pfw, pbw;
     44  uint_t winsize;
     45  uint_t channels;
     46  uint_t fft_size;
     47  real_t *in, *out;
     48  fftw_plan pfw, pbw;
     49  fft_data_t * specdata;     /* complex spectral data */
     50  fvec_t * compspec;
    4851};
    4952
    50 static void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size);
    51 
    52 aubio_fft_t * new_aubio_fft(uint_t size) {
    53         aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
    54         /* allocate memory */
    55         s->in       = AUBIO_ARRAY(real_t,size);
    56         s->out      = AUBIO_ARRAY(real_t,size);
    57         s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*size);
    58         /* create plans */
     53aubio_fft_t * new_aubio_fft(uint_t winsize, uint_t channels) {
     54  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
     55  s->winsize  = winsize;
     56  s->channels = channels;
     57  /* allocate memory */
     58  s->in       = AUBIO_ARRAY(real_t,winsize);
     59  s->out      = AUBIO_ARRAY(real_t,winsize);
     60  s->compspec = new_fvec(winsize,channels);
     61  /* create plans */
    5962#ifdef HAVE_COMPLEX_H
    60         s->pfw = fftw_plan_dft_r2c_1d(size, s->in,  s->specdata, FFTW_ESTIMATE);
    61         s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE);
     63  s->fft_size = winsize/2 + 1;
     64  s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
     65  s->pfw = fftw_plan_dft_r2c_1d(winsize, s->in,  s->specdata, FFTW_ESTIMATE);
     66  s->pbw = fftw_plan_dft_c2r_1d(winsize, s->specdata, s->out, FFTW_ESTIMATE);
    6267#else
    63         s->pfw = fftw_plan_r2r_1d(size, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
    64         s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
     68  s->fft_size = winsize;
     69  s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
     70  s->pfw = fftw_plan_r2r_1d(winsize, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
     71  s->pbw = fftw_plan_r2r_1d(winsize, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
    6572#endif
    66         return s;
     73  return s;
    6774}
    6875
    6976void del_aubio_fft(aubio_fft_t * s) {
    70         /* destroy data */
    71         fftw_destroy_plan(s->pfw);
    72         fftw_destroy_plan(s->pbw);
    73         fftw_free(s->specdata);
    74         AUBIO_FREE(s->out);
    75         AUBIO_FREE(s->in );
    76         AUBIO_FREE(s);
     77  /* destroy data */
     78  del_fvec(s->compspec);
     79  fftw_destroy_plan(s->pfw);
     80  fftw_destroy_plan(s->pbw);
     81  fftw_free(s->specdata);
     82  AUBIO_FREE(s->out);
     83  AUBIO_FREE(s->in );
     84  AUBIO_FREE(s);
    7785}
    7886
    79 void aubio_fft_do(const aubio_fft_t * s,
    80                 const smpl_t * data, fft_data_t * spectrum,
    81                 const uint_t size) {
    82         uint_t i;
    83         for (i=0;i<size;i++) s->in[i] = data[i];
    84         fftw_execute(s->pfw);
    85         for (i=0;i<size;i++) spectrum[i] = s->specdata[i];
     87void aubio_fft_do(aubio_fft_t * s, fvec_t * input, cvec_t * spectrum) {
     88  aubio_fft_do_complex(s, input, s->compspec);
     89  aubio_fft_get_spectrum(s->compspec, spectrum);
    8690}
    8791
    88 void aubio_fft_rdo(const aubio_fft_t * s,
    89                 const fft_data_t * spectrum,
    90                 smpl_t * data,
    91                 const uint_t size) {
    92         uint_t i;
    93         const smpl_t renorm = 1./(smpl_t)size;
    94         for (i=0;i<size;i++) s->specdata[i] = spectrum[i];
    95         fftw_execute(s->pbw);
    96         for (i=0;i<size;i++) data[i] = s->out[i]*renorm;
     92void aubio_fft_rdo(aubio_fft_t * s, cvec_t * spectrum, fvec_t * output) {
     93  aubio_fft_get_realimag(spectrum, s->compspec);
     94  aubio_fft_rdo_complex(s, s->compspec, output);
    9795}
    9896
     97void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) {
     98  uint_t i, j;
     99  for (i = 0; i < s->channels; i++) {
     100    for (j=0; j < s->winsize; j++) {
     101      s->in[j] = input->data[i][j];
     102    }
     103    fftw_execute(s->pfw);
    99104#ifdef HAVE_COMPLEX_H
    100 
    101 void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
    102         uint_t i;
    103         for (i=0;i<size/2+1;i++) norm[i] = ABSC(spectrum[i]);
    104         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
    105 }
    106 
    107 void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
    108         uint_t i;
    109         for (i=0;i<size/2+1;i++) phas[i] = ARGC(spectrum[i]);
    110         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
    111 }
    112 
    113 void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size) {
    114   uint_t j;
    115   for (j=0; j<size/2+1; j++) {
    116     spectrum[j]  = CEXPC(I*phas[j]);
    117     spectrum[j] *= norm[j];
     105    compspec->data[i][0] = REAL(s->specdata[0]);
     106    for (j = 1; j < s->fft_size -1 ; j++) {
     107      compspec->data[i][j] = REAL(s->specdata[j]);
     108      compspec->data[i][compspec->length - j] = IMAG(s->specdata[j]);
     109    }
     110    compspec->data[i][s->fft_size-1] = REAL(s->specdata[s->fft_size-1]);
     111#else
     112    for (j = 0; j < s->fft_size; j++) {
     113      compspec->data[i][j] = s->specdata[j];
     114    }
     115#endif
    118116  }
    119117}
    120118
     119void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) {
     120  uint_t i, j;
     121  const smpl_t renorm = 1./(smpl_t)s->winsize;
     122  for (i = 0; i < compspec->channels; i++) {
     123#ifdef HAVE_COMPLEX_H
     124    s->specdata[0] = compspec->data[i][0];
     125    for (j=1; j < s->fft_size - 1; j++) {
     126      s->specdata[j] = compspec->data[i][j] +
     127        I * compspec->data[i][compspec->length - j];
     128    }
     129    s->specdata[s->fft_size - 1] = compspec->data[i][s->fft_size - 1];
    121130#else
    122 
    123 void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
    124         uint_t i;
    125   norm[0] = -spectrum[0];
    126         for (i=1;i<size/2+1;i++) norm[i] = SQRT(SQR(spectrum[i]) + SQR(spectrum[size-i]));
    127         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
    128 }
    129 
    130 void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
    131         uint_t i;
    132   phas[0] = PI;
    133         for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]);
    134         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
    135 }
    136 
    137 void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, uint_t size) {
    138   uint_t j;
    139   for (j=0; j<size/2+1; j++) {
    140     spectrum[j]       = norm[j]*COS(phas[j]);
    141   }
    142   for (j=1; j<size/2+1; j++) {
    143     spectrum[size-j]  = norm[j]*SIN(phas[j]);
     131    for (j=0; j < s->fft_size; j++) {
     132      s->specdata[j] = compspec->data[i][j];
     133    }
     134#endif
     135    fftw_execute(s->pbw);
     136    for (j = 0; j < output->length; j++) {
     137      output->data[i][j] = s->out[j]*renorm;
     138    }
    144139  }
    145140}
    146141
    147 #endif
    148 
    149 /* new interface aubio_mfft */
    150 struct _aubio_mfft_t {
    151         aubio_fft_t * fft;      /* fftw interface */
    152         fft_data_t ** spec;     /* complex spectral data */
    153         uint_t winsize;
    154         uint_t channels;
    155 };
    156 
    157 aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels){
    158         uint_t i;
    159         aubio_mfft_t * fft = AUBIO_NEW(aubio_mfft_t);
    160         fft->winsize       = winsize;
    161         fft->channels      = channels;
    162         fft->fft           = new_aubio_fft(winsize);
    163         fft->spec          = AUBIO_ARRAY(fft_data_t*,channels);
    164         for (i=0; i < channels; i++)
    165                 fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize);
    166         return fft;
     142void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum) {
     143  aubio_fft_get_phas(compspec, spectrum);
     144  aubio_fft_get_norm(compspec, spectrum);
    167145}
    168146
    169 /* execute stft */
    170 void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain){
    171         uint_t i=0;
    172         /* execute stft */
    173         for (i=0; i < fft->channels; i++) {
    174                 aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize);
    175                 /* put norm and phase into fftgrain */
    176                 aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize);
    177                 aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize);
    178         }
     147void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec) {
     148  aubio_fft_get_imag(spectrum, compspec);
     149  aubio_fft_get_real(spectrum, compspec);
    179150}
    180151
    181 /* execute inverse fourier transform */
    182 void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out){
    183         uint_t i=0;
    184         for (i=0; i < fft->channels; i++) {
    185                 aubio_fft_getspectrum(fft->spec[i],fftgrain->norm[i],fftgrain->phas[i],fft->winsize);
    186                 aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize);
    187         }
     152void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
     153  uint_t i, j;
     154  for (i = 0; i < spectrum->channels; i++) {
     155    spectrum->phas[i][0] = 0.;
     156    for (j=1; j < spectrum->length - 1; j++) {
     157      spectrum->phas[i][j] = atan2f(compspec->data[i][compspec->length-j],
     158          compspec->data[i][j]);
     159    }
     160    spectrum->phas[i][spectrum->length-1] = 0.;
     161  }
    188162}
    189163
    190 void del_aubio_mfft(aubio_mfft_t * fft) {
    191         uint_t i;
    192         for (i=0; i < fft->channels; i++)
    193                 AUBIO_FREE(fft->spec[i]);
    194         AUBIO_FREE(fft->spec);
    195         del_aubio_fft(fft->fft);
    196         AUBIO_FREE(fft);       
     164void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) {
     165  uint_t i, j = 0;
     166  for (i = 0; i < spectrum->channels; i++) {
     167    spectrum->norm[i][0] = compspec->data[i][0];
     168    for (j=1; j < spectrum->length - 1; j++) {
     169      spectrum->norm[i][j] = SQRT(SQR(compspec->data[i][j])
     170          + SQR(compspec->data[i][compspec->length - j]) );
     171    }
     172    spectrum->norm[i][spectrum->length-1] = compspec->data[i][compspec->length/2];
     173  }
    197174}
     175
     176void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) {
     177  uint_t i, j;
     178  for (i = 0; i < compspec->channels; i++) {
     179    for (j = 1; j < compspec->length / 2 + 1; j++) {
     180      compspec->data[i][compspec->length - j] =
     181        spectrum->norm[i][j]*SIN(spectrum->phas[i][j]);
     182    }
     183  }
     184}
     185
     186void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) {
     187  uint_t i, j;
     188  for (i = 0; i < compspec->channels; i++) {
     189    for (j = 0; j< compspec->length / 2 + 1; j++) {
     190      compspec->data[i][j] =
     191        spectrum->norm[i][j]*COS(spectrum->phas[i][j]);
     192    }
     193  }
     194}
  • src/fft.h

    rc1656cf r7873363  
    11/*
    2         Copyright (C) 2003 Paul Brossier
     2  Copyright (C) 2003 Paul Brossier
    33
    4         This program is free software; you can redistribute it and/or modify
    5         it under the terms of the GNU General Public License as published by
    6         the Free Software Foundation; either version 2 of the License, or
    7         (at your option) any later version.
     4  This program is free software; you can redistribute it and/or modify
     5  it under the terms of the GNU General Public License as published by
     6  the Free Software Foundation; either version 2 of the License, or
     7  (at your option) any later version.
    88
    9         This program is distributed in the hope that it will be useful,
    10         but WITHOUT ANY WARRANTY; without even the implied warranty of
    11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12         GNU General Public License for more details.
     9  This program is distributed in the hope that it will be useful,
     10  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  GNU General Public License for more details.
    1313
    14         You should have received a copy of the GNU General Public License
    15         along with this program; if not, write to the Free Software
    16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    17        
     14  You should have received a copy of the GNU General Public License
     15  along with this program; if not, write to the Free Software
     16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     17 
    1818*/
    1919
     
    6767
    6868  \param size length of the FFT
     69  \param channels number of channels
    6970
    7071*/
    71 aubio_fft_t * new_aubio_fft(uint_t size);
     72aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels);
    7273/** delete FFT object
    7374
     
    7677*/
    7778void del_aubio_fft(aubio_fft_t * s);
     79
    7880/** compute forward FFT
    7981
    8082  \param s fft object as returned by new_aubio_fft
    81   \param data input signal
     83  \param input input signal
    8284  \param spectrum output spectrum
    83   \param size length of the input vector
    8485
    8586*/
    86 void aubio_fft_do (const aubio_fft_t *s, const smpl_t * data,
    87     fft_data_t * spectrum, const uint_t size);
     87void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum);
    8888/** compute backward (inverse) FFT
    8989
    9090  \param s fft object as returned by new_aubio_fft
    9191  \param spectrum input spectrum
    92   \param data output signal
    93   \param size length of the input vector
     92  \param output output signal
    9493
    9594*/
    96 void aubio_fft_rdo(const aubio_fft_t *s, const fft_data_t * spectrum,
    97     smpl_t * data, const uint_t size);
    98 /** compute norm vector from input spectrum
     95void aubio_fft_rdo (aubio_fft_t *s, cvec_t * spectrum, fvec_t * output);
    9996
    100   \param norm magnitude vector output
    101   \param spectrum spectral data input
    102   \param size size of the vectors
     97/** compute forward FFT
     98
     99  \param s fft object as returned by new_aubio_fft
     100  \param input real input signal
     101  \param compspec complex output fft real/imag
    103102
    104103*/
    105 void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size);
    106 /** compute phase vector from input spectrum
    107  
    108   \param phase phase vector output
    109   \param spectrum spectral data input
    110   \param size size of the vectors
     104void aubio_fft_do_complex (aubio_fft_t *s, fvec_t * input, fvec_t * compspec);
     105/** compute backward (inverse) FFT from real/imag
     106
     107  \param s fft object as returned by new_aubio_fft
     108  \param compspec real/imag input fft array
     109  \param output real output array
    111110
    112111*/
    113 void aubio_fft_getphas(smpl_t * phase, fft_data_t * spectrum, uint_t size);
     112void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output);
    114113
    115 /** FFT object (using cvec)
     114/** convert real/imag spectrum to norm/phas spectrum
    116115
    117   This object works similarly as aubio_fft_t, except the spectral data is
    118   stored in a cvec_t as two vectors, magnitude and phase.
     116  \param compspec real/imag input fft array
     117  \param spectrum cvec norm/phas output array
    119118
    120119*/
    121 typedef struct _aubio_mfft_t aubio_mfft_t;
     120void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum);
     121/** convert real/imag spectrum to norm/phas spectrum
    122122
    123 /** create new FFT computation object
    124 
    125   \param winsize length of the FFT
    126   \param channels number of channels
     123  \param compspec real/imag input fft array
     124  \param spectrum cvec norm/phas output array
    127125
    128126*/
    129 aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels);
    130 /** compute forward FFT
     127void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec);
    131128
    132   \param fft fft object as returned by new_aubio_mfft
    133   \param in input signal
    134   \param fftgrain output spectrum
     129/** compute phas spectrum from real/imag parts
     130
     131  \param compspec real/imag input fft array
     132  \param spectrum cvec norm/phas output array
    135133
    136134*/
    137 void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain);
    138 /** compute backward (inverse) FFT
     135void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum);
     136/** compute imaginary part from the norm/phas cvec
    139137
    140   \param fft fft object as returned by new_aubio_mfft
    141   \param fftgrain input spectrum (cvec)
    142   \param out output signal
     138  \param spectrum norm/phas input array
     139  \param compspec real/imag output fft array
    143140
    144141*/
    145 void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out);
    146 /** delete FFT object
     142void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec);
    147143
    148   \param fft fft object as returned by new_aubio_mfft
     144/** compute norm component from real/imag parts
     145
     146  \param compspec real/imag input fft array
     147  \param spectrum cvec norm/phas output array
    149148
    150149*/
    151 void del_aubio_mfft(aubio_mfft_t * fft);
     150void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum);
     151/** compute real part from norm/phas components
    152152
     153  \param spectrum norm/phas input array
     154  \param compspec real/imag output fft array
     155
     156*/
     157void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec);
    153158
    154159#ifdef __cplusplus
     
    156161#endif
    157162
    158 #endif
     163#endif // FFT_H_
  • src/filterbank.c

    rc1656cf r7873363  
    2727#include "stdio.h"
    2828
    29 #define USE_EQUAL_GAIN 1
    3029#define VERY_SMALL_NUMBER 2e-42
    3130
  • src/hist.c

    rc1656cf r7873363  
    11/*
    2         Copyright (C) 2003 Paul Brossier
     2  Copyright (C) 2003 Paul Brossier
    33
    4         This program is free software; you can redistribute it and/or modify
    5         it under the terms of the GNU General Public License as published by
    6         the Free Software Foundation; either version 2 of the License, or
    7         (at your option) any later version.
     4  This program is free software; you can redistribute it and/or modify
     5  it under the terms of the GNU General Public License as published by
     6  the Free Software Foundation; either version 2 of the License, or
     7  (at your option) any later version.
    88
    9         This program is distributed in the hope that it will be useful,
    10         but WITHOUT ANY WARRANTY; without even the implied warranty of
    11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12         GNU General Public License for more details.
     9  This program is distributed in the hope that it will be useful,
     10  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  GNU General Public License for more details.
    1313
    14         You should have received a copy of the GNU General Public License
    15         along with this program; if not, write to the Free Software
    16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    17          */
     14  You should have received a copy of the GNU General Public License
     15  along with this program; if not, write to the Free Software
     16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     17*/
    1818
    1919#include "aubio_priv.h"
     
    2828
    2929struct _aubio_hist_t {
    30         /*bug: move to a fvec */
    31         smpl_t ** hist;
    32         uint_t nelems;
    33         uint_t channels;
    34         smpl_t * cent;
    35         aubio_scale_t *scaler;
     30  fvec_t * hist;
     31  uint_t nelems;
     32  uint_t channels;
     33  fvec_t * cent;
     34  aubio_scale_t *scaler;
    3635};
    3736
     
    4039 */
    4140aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems, uint_t channels){
    42         aubio_hist_t * s = AUBIO_NEW(aubio_hist_t);
    43         smpl_t step = (ihig-ilow)/(smpl_t)(nelems);
    44         smpl_t accum = step;
    45         uint_t i;
    46         s->channels = channels;
    47         s->nelems = nelems;
    48         s->hist = AUBIO_ARRAY(smpl_t*, channels);
    49         for (i=0; i< s->channels; i++) {
    50                 s->hist[i] = AUBIO_ARRAY(smpl_t, nelems);
    51         }
    52         s->cent = AUBIO_ARRAY(smpl_t, nelems);
    53        
    54         /* use scale to map ilow/ihig -> 0/nelems */
    55         s->scaler = new_aubio_scale(ilow,ihig,0,nelems);
    56         /* calculate centers now once */
    57         s->cent[0] = ilow + 0.5 * step;
    58         for (i=1; i < s->nelems; i++, accum+=step )
    59                 s->cent[i] = s->cent[0] + accum;
    60        
    61         return s;       
     41  aubio_hist_t * s = AUBIO_NEW(aubio_hist_t);
     42  smpl_t step = (ihig-ilow)/(smpl_t)(nelems);
     43  smpl_t accum = step;
     44  uint_t i;
     45  s->channels = channels;
     46  s->nelems = nelems;
     47  s->hist = new_fvec(nelems, channels);
     48  s->cent = new_fvec(nelems, 1);
     49
     50  /* use scale to map ilow/ihig -> 0/nelems */
     51  s->scaler = new_aubio_scale(ilow,ihig,0,nelems);
     52  /* calculate centers now once */
     53  s->cent->data[0][0] = ilow + 0.5 * step;
     54  for (i=1; i < s->nelems; i++, accum+=step )
     55    s->cent->data[0][i] = s->cent->data[0][0] + accum;
     56
     57  return s;
    6258}
    6359
    6460void del_aubio_hist(aubio_hist_t *s) {
    65         uint_t i;
    66         for (i=0; i< s->channels; i++) {
    67                 AUBIO_FREE(s->hist[i]);
    68         }
    69         AUBIO_FREE(s->hist);
    70         AUBIO_FREE(s->cent);
    71         del_aubio_scale(s->scaler);
    72         AUBIO_FREE(s);
     61  del_fvec(s->hist);
     62  del_fvec(s->cent);
     63  del_aubio_scale(s->scaler);
     64  AUBIO_FREE(s);
    7365}
    7466
     
    7668 * do it
    7769 */
    78 void aubio_hist_do (aubio_hist_t *s, fvec_t *input)
    79 {
    80         uint_t i,j;
    81         sint_t tmp = 0;
    82         aubio_scale_do(s->scaler, input);
    83         /* reset data */
    84         for (i=0; i < s->channels; i++)
    85                 for (j=0; j < s->nelems; j++)
    86                         s->hist[i][j] = 0;
    87         /* run accum */
    88         for (i=0; i < input->channels; i++)
    89                 for (j=0;  j < input->length; j++)
    90                 {
    91                         tmp = (sint_t)FLOOR(input->data[i][j]);
    92                         if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
    93                                 s->hist[i][tmp] += 1;
    94                 }
     70void aubio_hist_do (aubio_hist_t *s, fvec_t *input) {
     71  uint_t i,j;
     72  sint_t tmp = 0;
     73  aubio_scale_do(s->scaler, input);
     74  /* reset data */
     75  for (i=0; i < s->channels; i++)
     76    for (j=0; j < s->nelems; j++)
     77      s->hist->data[i][j] = 0;
     78  /* run accum */
     79  for (i=0; i < input->channels; i++)
     80    for (j=0;  j < input->length; j++)
     81    {
     82      tmp = (sint_t)FLOOR(input->data[i][j]);
     83      if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
     84        s->hist->data[i][tmp] += 1;
     85    }
    9586}
    9687
    97 void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input)
    98 {
    99         uint_t i,j;
    100         sint_t tmp = 0;
    101         aubio_scale_do(s->scaler, input);
    102         /* reset data */
    103         for (i=0; i < s->channels; i++)
    104                 for (j=0; j < s->nelems; j++)
    105                         s->hist[i][j] = 0;
    106         /* run accum */
    107         for (i=0; i < input->channels; i++)
    108                 for (j=0;  j < input->length; j++)
    109                 {
    110                         if (input->data[i][j] != 0) {
    111                                 tmp = (sint_t)FLOOR(input->data[i][j]);
    112                                 if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
    113                                         s->hist[i][tmp] += 1;
    114                         }
    115                 }
     88void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) {
     89  uint_t i,j;
     90  sint_t tmp = 0;
     91  aubio_scale_do(s->scaler, input);
     92  /* reset data */
     93  for (i=0; i < s->channels; i++)
     94    for (j=0; j < s->nelems; j++)
     95      s->hist->data[i][j] = 0;
     96  /* run accum */
     97  for (i=0; i < input->channels; i++)
     98    for (j=0;  j < input->length; j++) {
     99      if (input->data[i][j] != 0) {
     100        tmp = (sint_t)FLOOR(input->data[i][j]);
     101        if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
     102          s->hist->data[i][tmp] += 1;
     103      }
     104    }
    116105}
    117106
    118107
    119 void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input)
    120 {
    121         uint_t i,j;
    122         sint_t tmp = 0;
    123         smpl_t ilow = vec_min(input);
    124         smpl_t ihig = vec_max(input);
    125         smpl_t step = (ihig-ilow)/(smpl_t)(s->nelems);
    126        
    127         /* readapt */
    128         aubio_scale_set(s->scaler, ilow, ihig, 0, s->nelems);
     108void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) {
     109  uint_t i,j;
     110  sint_t tmp = 0;
     111  smpl_t ilow = vec_min(input);
     112  smpl_t ihig = vec_max(input);
     113  smpl_t step = (ihig-ilow)/(smpl_t)(s->nelems);
    129114
    130         /* recalculate centers */
    131         s->cent[0] = ilow + 0.5f * step;
    132         for (i=1; i < s->nelems; i++)
    133                 s->cent[i] = s->cent[0] + i * step;
     115  /* readapt */
     116  aubio_scale_set(s->scaler, ilow, ihig, 0, s->nelems);
    134117
    135         /* scale */     
    136         aubio_scale_do(s->scaler, input);
     118  /* recalculate centers */
     119  s->cent->data[0][0] = ilow + 0.5f * step;
     120  for (i=1; i < s->nelems; i++)
     121    s->cent->data[0][i] = s->cent->data[0][0] + i * step;
    137122
    138         /* reset data */
    139         for (i=0; i < s->channels; i++)
    140                 for (j=0; j < s->nelems; j++)
    141                         s->hist[i][j] = 0;
    142         /* run accum */
    143         for (i=0; i < input->channels; i++)
    144                 for (j=0;  j < input->length; j++)
    145                 {
    146                         if (input->data[i][j] != 0) {
    147                                 tmp = (sint_t)FLOOR(input->data[i][j]);
    148                                 if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
    149                                         s->hist[i][tmp] += 1;
    150                         }
    151                 }
     123  /* scale */
     124  aubio_scale_do(s->scaler, input);
     125
     126  /* reset data */
     127  for (i=0; i < s->channels; i++)
     128    for (j=0; j < s->nelems; j++)
     129      s->hist->data[i][j] = 0;
     130  /* run accum */
     131  for (i=0; i < input->channels; i++)
     132    for (j=0;  j < input->length; j++) {
     133      if (input->data[i][j] != 0) {
     134        tmp = (sint_t)FLOOR(input->data[i][j]);
     135        if ((tmp >= 0) && (tmp < (sint_t)s->nelems))
     136          s->hist->data[i][tmp] += 1;
     137      }
     138    }
    152139}
    153140
    154 void aubio_hist_weigth (aubio_hist_t *s)
    155 {
    156         uint_t i,j;
    157         for (i=0; i < s->channels; i++)
    158                 for (j=0; j < s->nelems; j++) {
    159                         s->hist[i][j] *= s->cent[j];
    160                 }
     141void aubio_hist_weight (aubio_hist_t *s) {
     142  uint_t i,j;
     143  for (i=0; i < s->channels; i++)
     144    for (j=0; j < s->nelems; j++) {
     145      s->hist->data[i][j] *= s->cent->data[0][j];
     146    }
    161147}
    162148
    163 smpl_t aubio_hist_mean (aubio_hist_t *s)
    164 {
    165         uint_t i,j;
    166         smpl_t tmp = 0.0f;
    167         for (i=0; i < s->channels; i++)
    168                 for (j=0; j < s->nelems; j++)
    169                         tmp += s->hist[i][j];
    170         return tmp/(smpl_t)(s->nelems);
     149smpl_t aubio_hist_mean (aubio_hist_t *s) {
     150  uint_t i,j;
     151  smpl_t tmp = 0.0f;
     152  for (i=0; i < s->channels; i++)
     153    for (j=0; j < s->nelems; j++)
     154      tmp += s->hist->data[i][j];
     155  return tmp/(smpl_t)(s->nelems);
    171156}
    172157
  • src/hist.h

    rc1656cf r7873363  
    11/*
    2         Copyright (C) 2003 Paul Brossier
     2  Copyright (C) 2003 Paul Brossier
    33
    4         This program is free software; you can redistribute it and/or modify
    5         it under the terms of the GNU General Public License as published by
    6         the Free Software Foundation; either version 2 of the License, or
    7         (at your option) any later version.
     4  This program is free software; you can redistribute it and/or modify
     5  it under the terms of the GNU General Public License as published by
     6  the Free Software Foundation; either version 2 of the License, or
     7  (at your option) any later version.
    88
    9         This program is distributed in the hope that it will be useful,
    10         but WITHOUT ANY WARRANTY; without even the implied warranty of
    11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12         GNU General Public License for more details.
     9  This program is distributed in the hope that it will be useful,
     10  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  GNU General Public License for more details.
    1313
    14          You should have received a copy of the GNU General Public License
    15          along with this program; if not, write to the Free Software
    16          Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    17          */
     14   You should have received a copy of the GNU General Public License
     15   along with this program; if not, write to the Free Software
     16   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     17
     18*/
    1819
    1920/** @file
     
    3435typedef struct _aubio_hist_t aubio_hist_t;
    3536
    36 /** histogram creation 
     37/** histogram creation
    3738 * \param flow minimum input
    3839 * \param fhig maximum input
    3940 * \param nelems number of histogram columns
    40  * \param channels number of channels 
     41 * \param channels number of channels
    4142 */
    4243aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems, uint_t channels);
     
    4849void aubio_hist_do_notnull(aubio_hist_t *s, fvec_t * input);
    4950/** compute the mean of the histogram */
    50 smpl_t aubio_hist_mean(aubio_hist_t *s); 
     51smpl_t aubio_hist_mean(aubio_hist_t *s);
    5152/** weight the histogram */
    52 void aubio_hist_weigth(aubio_hist_t *s);
     53void aubio_hist_weight(aubio_hist_t *s);
    5354/** compute dynamic histogram for non-null elements */
    5455void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input);
  • src/mathutils.c

    rc1656cf r7873363  
    227227  /* pre part of the buffer does not exist */
    228228  } else {
    229     for (k=0;k<length-pos+post+1;k++)
     229    for (k=0;k<length-pos+post;k++)
    230230      medar[k] = vec->data[0][k+pos-post];
    231     for (k=length-pos+post+1;k<win_length;k++)
     231    for (k=length-pos+post;k<win_length;k++)
    232232      medar[k] = 0.; /* 0-padding at the end */
    233233  }
  • src/mfcc.c

    rc1656cf r7873363  
    4040  aubio_filterbank_t * fb;  /** filter bank */
    4141  fvec_t * in_dct;          /** input buffer for dct * [fb->n_filters] */
    42   aubio_mfft_t * fft_dct;   /** fft object for dct */
     42  aubio_fft_t * fft_dct;   /** fft object for dct */
    4343  cvec_t * fftgrain_dct;    /** output buffer for dct */
    4444};
     
    6565
    6666  /** allocating space for fft object (used for dct) */
    67   mfcc->fft_dct=new_aubio_mfft(n_filters, 1);
     67  mfcc->fft_dct=new_aubio_fft(n_filters, 1);
    6868
    6969  /** allocating buffers */
     
    7878  /** deleting filterbank */
    7979  del_aubio_filterbank(mf->fb);
    80   /** deleting mfft object */
    81   del_aubio_mfft(mf->fft_dct);
     80  /** deleting fft object */
     81  del_aubio_fft(mf->fft_dct);
    8282  /** deleting buffers */
    8383  del_fvec(mf->in_dct);
     
    113113    uint_t i;
    114114    //compute mag spectrum
    115     aubio_mfft_do (mf->fft_dct, in, mf->fftgrain_dct);
     115    aubio_fft_do (mf->fft_dct, in, mf->fftgrain_dct);
    116116    //extract real part of fft grain
    117117    for(i=0; i<mf->n_coefs ;i++){
  • src/onsetdetection.c

    rc1656cf r7873363  
    3131  /** Pointer to aubio_onsetdetection_<type> function */
    3232  void (*funcpointer)(aubio_onsetdetection_t *o,
    33     cvec_t * fftgrain, fvec_t * onset);
     33      cvec_t * fftgrain, fvec_t * onset);
    3434  smpl_t threshold;      /**< minimum norm threshold for phase and specdiff */
    3535  fvec_t *oldmag;        /**< previous norm vector */
     
    4444/* Energy based onset detection function */
    4545void aubio_onsetdetection_energy  (aubio_onsetdetection_t *o UNUSED,
    46                 cvec_t * fftgrain, fvec_t * onset) {
    47         uint_t i,j;
    48         for (i=0;i<fftgrain->channels;i++) {
    49                 onset->data[i][0] = 0.;
    50                 for (j=0;j<fftgrain->length;j++) {
    51                         onset->data[i][0] += SQR(fftgrain->norm[i][j]);
    52                 }
    53         }
     46    cvec_t * fftgrain, fvec_t * onset) {
     47  uint_t i,j;
     48  for (i=0;i<fftgrain->channels;i++) {
     49    onset->data[i][0] = 0.;
     50    for (j=0;j<fftgrain->length;j++) {
     51      onset->data[i][0] += SQR(fftgrain->norm[i][j]);
     52    }
     53  }
    5454}
    5555
     
    5757void aubio_onsetdetection_hfc(aubio_onsetdetection_t *o UNUSED,
    5858    cvec_t * fftgrain, fvec_t * onset){
    59         uint_t i,j;
    60         for (i=0;i<fftgrain->channels;i++) {
    61                 onset->data[i][0] = 0.;
    62                 for (j=0;j<fftgrain->length;j++) {
    63                         onset->data[i][0] += (j+1)*fftgrain->norm[i][j];
    64                 }
    65         }
     59  uint_t i,j;
     60  for (i=0;i<fftgrain->channels;i++) {
     61    onset->data[i][0] = 0.;
     62    for (j=0;j<fftgrain->length;j++) {
     63      onset->data[i][0] += (j+1)*fftgrain->norm[i][j];
     64    }
     65  }
    6666}
    6767
     
    6969/* Complex Domain Method onset detection function */
    7070void aubio_onsetdetection_complex (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset) {
    71         uint_t i, j;
    72         uint_t nbins = fftgrain->length;
    73         for (i=0;i<fftgrain->channels; i++)     {
    74                 onset->data[i][0] = 0.;
    75                 for (j=0;j<nbins; j++)  {
    76                         o->dev1->data[i][j]      = aubio_unwrap2pi(
    77                                         fftgrain->phas[i][j]
    78                                         -2.0*o->theta1->data[i][j]+
    79                                         o->theta2->data[i][j]);
     71  uint_t i, j;
     72  uint_t nbins = fftgrain->length;
     73  for (i=0;i<fftgrain->channels; i++)  {
     74    onset->data[i][0] = 0.;
     75    for (j=0;j<nbins; j++)  {
     76      o->dev1->data[i][j]    = aubio_unwrap2pi(
     77          fftgrain->phas[i][j]
     78          -2.0*o->theta1->data[i][j]+
     79          o->theta2->data[i][j]);
    8080#ifdef HAVE_COMPLEX_H
    81                         o->meas[j] = fftgrain->norm[i][j]*CEXPC(I*o->dev1->data[i][j]);
    82                         /* sum on all bins */
    83                         onset->data[i][0]                += //(fftgrain->norm[i][j]);
    84                                         SQRT(SQR( REAL(o->oldmag->data[i][j]-o->meas[j]) )
    85                                                 +  SQR( IMAG(o->oldmag->data[i][j]-o->meas[j]) )
    86                                                 );
     81      o->meas[j] = fftgrain->norm[i][j]*CEXPC(I*o->dev1->data[i][j]);
     82      /* sum on all bins */
     83      onset->data[i][0]    += //(fftgrain->norm[i][j]);
     84          SQRT(SQR( REAL(o->oldmag->data[i][j]-o->meas[j]) )
     85            +  SQR( IMAG(o->oldmag->data[i][j]-o->meas[j]) )
     86            );
    8787#else
    88                         o->meas[j]             = (fftgrain->norm[i][j])*COS(o->dev1->data[i][j]);
    89                         o->meas[(nbins-1)*2-j] = (fftgrain->norm[i][j])*SIN(o->dev1->data[i][j]);
    90                         /* sum on all bins */
    91                         onset->data[i][0]                += //(fftgrain->norm[i][j]);
    92                                         SQRT(SQR( (o->oldmag->data[i][j]-o->meas[j]) )
    93                                                 +  SQR( (-o->meas[(nbins-1)*2-j]) )
    94                                                 );
     88      o->meas[j]             = (fftgrain->norm[i][j])*COS(o->dev1->data[i][j]);
     89      o->meas[(nbins-1)*2-j] = (fftgrain->norm[i][j])*SIN(o->dev1->data[i][j]);
     90      /* sum on all bins */
     91      onset->data[i][0]    += //(fftgrain->norm[i][j]);
     92          SQRT(SQR( (o->oldmag->data[i][j]-o->meas[j]) )
     93            +  SQR( (-o->meas[(nbins-1)*2-j]) )
     94            );
    9595#endif
    96                         /* swap old phase data (need to remember 2 frames behind)*/
    97                         o->theta2->data[i][j] = o->theta1->data[i][j];
    98                         o->theta1->data[i][j] = fftgrain->phas[i][j];
    99                         /* swap old magnitude data (1 frame is enough) */
    100                         o->oldmag->data[i][j] = fftgrain->norm[i][j];
    101                 }
    102         }
     96      /* swap old phase data (need to remember 2 frames behind)*/
     97      o->theta2->data[i][j] = o->theta1->data[i][j];
     98      o->theta1->data[i][j] = fftgrain->phas[i][j];
     99      /* swap old magnitude data (1 frame is enough) */
     100      o->oldmag->data[i][j] = fftgrain->norm[i][j];
     101    }
     102  }
    103103}
    104104
     
    106106/* Phase Based Method onset detection function */
    107107void aubio_onsetdetection_phase(aubio_onsetdetection_t *o,
    108                 cvec_t * fftgrain, fvec_t * onset){
    109         uint_t i, j;
    110         uint_t nbins = fftgrain->length;
    111         for (i=0;i<fftgrain->channels; i++)     {
    112                 onset->data[i][0] = 0.0f;
    113                 o->dev1->data[i][0]=0.;
    114                 for ( j=0;j<nbins; j++ )        {
    115                         o->dev1->data[i][j] =
    116                                 aubio_unwrap2pi(
    117                                                 fftgrain->phas[i][j]
    118                                                 -2.0*o->theta1->data[i][j]
    119                                                 +o->theta2->data[i][j]);
    120                         if ( o->threshold < fftgrain->norm[i][j] )
    121                                 o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
    122                         else
    123                                 o->dev1->data[i][j] = 0.0f;
    124                         /* keep a track of the past frames */
    125                         o->theta2->data[i][j] = o->theta1->data[i][j];
    126                         o->theta1->data[i][j] = fftgrain->phas[i][j];
    127                 }
    128                 /* apply o->histogram */
    129                 aubio_hist_dyn_notnull(o->histog,o->dev1);
    130                 /* weight it */
    131                 aubio_hist_weigth(o->histog);
    132                 /* its mean is the result */
    133                 onset->data[i][0] = aubio_hist_mean(o->histog);
    134                 //onset->data[i][0] = vec_mean(o->dev1);
    135         }
     108    cvec_t * fftgrain, fvec_t * onset){
     109  uint_t i, j;
     110  uint_t nbins = fftgrain->length;
     111  for (i=0;i<fftgrain->channels; i++)  {
     112    onset->data[i][0] = 0.0f;
     113    o->dev1->data[i][0]=0.;
     114    for ( j=0;j<nbins; j++ )  {
     115      o->dev1->data[i][j] =
     116        aubio_unwrap2pi(
     117            fftgrain->phas[i][j]
     118            -2.0*o->theta1->data[i][j]
     119            +o->theta2->data[i][j]);
     120      if ( o->threshold < fftgrain->norm[i][j] )
     121        o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
     122      else
     123        o->dev1->data[i][j] = 0.0f;
     124      /* keep a track of the past frames */
     125      o->theta2->data[i][j] = o->theta1->data[i][j];
     126      o->theta1->data[i][j] = fftgrain->phas[i][j];
     127    }
     128    /* apply o->histogram */
     129    aubio_hist_dyn_notnull(o->histog,o->dev1);
     130    /* weight it */
     131    aubio_hist_weight(o->histog);
     132    /* its mean is the result */
     133    onset->data[i][0] = aubio_hist_mean(o->histog); 
     134    //onset->data[i][0] = vec_mean(o->dev1);
     135  }
    136136}
    137137
    138138/* Spectral difference method onset detection function */
    139139void aubio_onsetdetection_specdiff(aubio_onsetdetection_t *o,
    140                 cvec_t * fftgrain, fvec_t * onset){
    141         uint_t i, j;
    142         uint_t nbins = fftgrain->length;
    143         for (i=0;i<fftgrain->channels; i++)     {
    144                 onset->data[i][0] = 0.0f;
    145                 for (j=0;j<nbins; j++)  {
    146                         o->dev1->data[i][j] = SQRT(
    147                                         ABS(SQR( fftgrain->norm[i][j])
    148                                                 - SQR(o->oldmag->data[i][j])));
    149                         if (o->threshold < fftgrain->norm[i][j] )
    150                                 o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
    151                         else
    152                                 o->dev1->data[i][j] = 0.0f;
    153                         o->oldmag->data[i][j] = fftgrain->norm[i][j];
    154                 }
    155 
    156                 /* apply o->histogram (act somewhat as a low pass on the
    157                 * overall function)*/
    158                 aubio_hist_dyn_notnull(o->histog,o->dev1);
    159                 /* weight it */
    160                 aubio_hist_weigth(o->histog);
    161                 /* its mean is the result */
    162                 onset->data[i][0] = aubio_hist_mean(o->histog);
    163 
    164         }
     140    cvec_t * fftgrain, fvec_t * onset){
     141  uint_t i, j;
     142  uint_t nbins = fftgrain->length;
     143  for (i=0;i<fftgrain->channels; i++)  {
     144    onset->data[i][0] = 0.0f;
     145    for (j=0;j<nbins; j++)  {
     146      o->dev1->data[i][j] = SQRT(
     147          ABS(SQR( fftgrain->norm[i][j])
     148            - SQR(o->oldmag->data[i][j])));
     149      if (o->threshold < fftgrain->norm[i][j] )
     150        o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
     151      else
     152        o->dev1->data[i][j] = 0.0f;
     153      o->oldmag->data[i][j] = fftgrain->norm[i][j];
     154    }
     155
     156    /* apply o->histogram (act somewhat as a low pass on the
     157    * overall function)*/
     158    aubio_hist_dyn_notnull(o->histog,o->dev1);
     159    /* weight it */
     160    aubio_hist_weight(o->histog);
     161    /* its mean is the result */
     162    onset->data[i][0] = aubio_hist_mean(o->histog); 
     163
     164  }
    165165}
    166166
     
    169169 * negative (1.+) and infinite values (+1.e-10) */
    170170void aubio_onsetdetection_kl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset){
    171         uint_t i,j;
    172         for (i=0;i<fftgrain->channels;i++) {
    173                 onset->data[i][0] = 0.;
    174                 for (j=0;j<fftgrain->length;j++) {
    175                         onset->data[i][0] += fftgrain->norm[i][j]
    176                                 *LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
    177                         o->oldmag->data[i][j] = fftgrain->norm[i][j];
    178                 }
    179                 if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
    180         }
     171  uint_t i,j;
     172  for (i=0;i<fftgrain->channels;i++) {
     173    onset->data[i][0] = 0.;
     174    for (j=0;j<fftgrain->length;j++) {
     175      onset->data[i][0] += fftgrain->norm[i][j]
     176        *LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
     177      o->oldmag->data[i][j] = fftgrain->norm[i][j];
     178    }
     179    if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
     180  }
    181181}
    182182
     
    185185 * negative (1.+) and infinite values (+1.e-10) */
    186186void aubio_onsetdetection_mkl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset){
    187         uint_t i,j;
    188         for (i=0;i<fftgrain->channels;i++) {
    189                 onset->data[i][0] = 0.;
    190                 for (j=0;j<fftgrain->length;j++) {
    191                         onset->data[i][0] += LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
    192                         o->oldmag->data[i][j] = fftgrain->norm[i][j];
    193                 }
    194                 if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
    195         }
     187  uint_t i,j;
     188  for (i=0;i<fftgrain->channels;i++) {
     189    onset->data[i][0] = 0.;
     190    for (j=0;j<fftgrain->length;j++) {
     191      onset->data[i][0] += LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
     192      o->oldmag->data[i][j] = fftgrain->norm[i][j];
     193    }
     194    if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
     195  }
     196}
     197
     198/* Spectral flux */
     199void aubio_onsetdetection_specflux(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset){
     200  uint_t i, j;
     201  for (i=0;i<fftgrain->channels;i++) {
     202    onset->data[i][0] = 0.;
     203    for (j=0;j<fftgrain->length;j++) {
     204      if (fftgrain->norm[i][j] > o->oldmag->data[i][j])
     205        onset->data[i][0] += fftgrain->norm[i][j] - o->oldmag->data[i][j];
     206      o->oldmag->data[i][j] = fftgrain->norm[i][j];
     207    }
     208  }
    196209}
    197210
     
    199212void
    200213aubio_onsetdetection(aubio_onsetdetection_t *o, cvec_t * fftgrain,
    201                 fvec_t * onset) {
    202         o->funcpointer(o,fftgrain,onset);
     214    fvec_t * onset) {
     215  o->funcpointer(o,fftgrain,onset);
    203216}
    204217
     
    208221aubio_onsetdetection_t *
    209222new_aubio_onsetdetection (aubio_onsetdetection_type type,
    210                 uint_t size, uint_t channels){
    211         aubio_onsetdetection_t * o = AUBIO_NEW(aubio_onsetdetection_t);
    212         uint_t rsize = size/2+1;
     223    uint_t size, uint_t channels){
     224  aubio_onsetdetection_t * o = AUBIO_NEW(aubio_onsetdetection_t);
     225  uint_t rsize = size/2+1;
    213226  uint_t i;
    214         switch(type) {
    215                 /* for both energy and hfc, only fftgrain->norm is required */
    216                 case aubio_onset_energy:
    217                         break;
    218                 case aubio_onset_hfc:
    219                         break;
    220                 /* the other approaches will need some more memory spaces */
    221                 case aubio_onset_complex:
    222                         o->oldmag = new_fvec(rsize,channels);
    223                         /** bug: must be complex array */
    224                         o->meas = AUBIO_ARRAY(fft_data_t,size+1);
    225                         for (i=0; i<size+1; i++) o->meas[i] = 0;
    226                         o->dev1  = new_fvec(rsize,channels);
    227                         o->theta1 = new_fvec(rsize,channels);
    228                         o->theta2 = new_fvec(rsize,channels);
    229                         break;
    230                 case aubio_onset_phase:
    231                         o->dev1  = new_fvec(rsize,channels);
    232                         o->theta1 = new_fvec(rsize,channels);
    233                         o->theta2 = new_fvec(rsize,channels);
    234                         o->histog = new_aubio_hist(0.0f, PI, 10, channels);
    235                         o->threshold = 0.1;
    236                         break;
    237                 case aubio_onset_specdiff:
    238                         o->oldmag = new_fvec(rsize,channels);
    239                         o->dev1   = new_fvec(rsize,channels);
    240                         o->histog = new_aubio_hist(0.0f, PI, 10, channels);
    241                         o->threshold = 0.1;
    242                         break;
    243                 case aubio_onset_kl:
    244                         o->oldmag = new_fvec(rsize,channels);
    245                         break;
    246                 case aubio_onset_mkl:
    247                         o->oldmag = new_fvec(rsize,channels);
    248                         break;
    249                 default:
    250                         break;
    251         }
    252        
    253         /* this switch could be in its own function to change between
    254          * detections on the fly. this would need getting rid of the switch
    255          * above and always allocate all the structure */
    256 
    257         switch(type) {
    258                 case aubio_onset_energy:
    259                         o->funcpointer = aubio_onsetdetection_energy;
    260                         break;
    261                 case aubio_onset_hfc:
    262                         o->funcpointer = aubio_onsetdetection_hfc;
    263                         break;
    264                 case aubio_onset_complex:
    265                         o->funcpointer = aubio_onsetdetection_complex;
    266                         break;
    267                 case aubio_onset_phase:
    268                         o->funcpointer = aubio_onsetdetection_phase;
    269                         break;
    270                 case aubio_onset_specdiff:
    271                         o->funcpointer = aubio_onsetdetection_specdiff;
    272                         break;
    273                 case aubio_onset_kl:
    274                         o->funcpointer = aubio_onsetdetection_kl;
    275                         break;
    276                 case aubio_onset_mkl:
    277                         o->funcpointer = aubio_onsetdetection_mkl;
    278                         break;
    279                 default:
    280                         break;
    281         }
    282         o->type = type;
    283         return o;
    284 }
    285 
    286 void aubio_onsetdetection_free (aubio_onsetdetection_t *o){
    287   del_aubio_onsetdetection(o);
     227  switch(type) {
     228    /* for both energy and hfc, only fftgrain->norm is required */
     229    case aubio_onset_energy:
     230      break;
     231    case aubio_onset_hfc:
     232      break;
     233      /* the other approaches will need some more memory spaces */
     234    case aubio_onset_complex:
     235      o->oldmag = new_fvec(rsize,channels);
     236      /** bug: must be complex array */
     237      o->meas = AUBIO_ARRAY(fft_data_t,size+1);
     238      for (i=0; i<size+1; i++) o->meas[i] = 0;
     239      o->dev1   = new_fvec(rsize,channels);
     240      o->theta1 = new_fvec(rsize,channels);
     241      o->theta2 = new_fvec(rsize,channels);
     242      break;
     243    case aubio_onset_phase:
     244      o->dev1   = new_fvec(rsize,channels);
     245      o->theta1 = new_fvec(rsize,channels);
     246      o->theta2 = new_fvec(rsize,channels);
     247      o->histog = new_aubio_hist(0.0f, PI, 10, channels);
     248      o->threshold = 0.1;
     249      break;
     250    case aubio_onset_specdiff:
     251      o->oldmag = new_fvec(rsize,channels);
     252      o->dev1   = new_fvec(rsize,channels);
     253      o->histog = new_aubio_hist(0.0f, PI, 10, channels);
     254      o->threshold = 0.1;
     255      break;
     256    case aubio_onset_kl:
     257    case aubio_onset_mkl:
     258    case aubio_onset_specflux:
     259      o->oldmag = new_fvec(rsize,channels);
     260      break;
     261    default:
     262      break;
     263  }
     264
     265  /* this switch could be in its own function to change between
     266   * detections on the fly. this would need getting rid of the switch
     267   * above and always allocate all the structure */
     268
     269  switch(type) {
     270    case aubio_onset_energy:
     271      o->funcpointer = aubio_onsetdetection_energy;
     272      break;
     273    case aubio_onset_hfc:
     274      o->funcpointer = aubio_onsetdetection_hfc;
     275      break;
     276    case aubio_onset_complex:
     277      o->funcpointer = aubio_onsetdetection_complex;
     278      break;
     279    case aubio_onset_phase:
     280      o->funcpointer = aubio_onsetdetection_phase;
     281      break;
     282    case aubio_onset_specdiff:
     283      o->funcpointer = aubio_onsetdetection_specdiff;
     284      break;
     285    case aubio_onset_kl:
     286      o->funcpointer = aubio_onsetdetection_kl;
     287      break;
     288    case aubio_onset_mkl:
     289      o->funcpointer = aubio_onsetdetection_mkl;
     290      break;
     291    case aubio_onset_specflux:
     292      o->funcpointer = aubio_onsetdetection_specflux;
     293      break;
     294    default:
     295      break;
     296  }
     297  o->type = type;
     298  return o;
    288299}
    289300
    290301void del_aubio_onsetdetection (aubio_onsetdetection_t *o){
    291 
    292         switch(o->type) {
    293                 /* for both energy and hfc, only fftgrain->norm is required */
    294                 case aubio_onset_energy:
    295                         break;
    296                 case aubio_onset_hfc:
    297                         break;
    298                 /* the other approaches will need some more memory spaces */
    299                 case aubio_onset_complex:
    300                         AUBIO_FREE(o->meas);
    301                         del_fvec(o->oldmag);
    302                         del_fvec(o->dev1);
    303                         del_fvec(o->theta1);
    304                         del_fvec(o->theta2);
    305                         break;
    306                 case aubio_onset_phase:
    307                         del_fvec(o->dev1);
    308                         del_fvec(o->theta1);
    309                         del_fvec(o->theta2);
    310                         del_aubio_hist(o->histog);
    311                         break;
    312                 case aubio_onset_specdiff:
    313                         del_fvec(o->oldmag);
    314                         del_fvec(o->dev1);
    315                         del_aubio_hist(o->histog);
    316                         break;
    317                 case aubio_onset_kl:
    318                         del_fvec(o->oldmag);
    319                         break;
    320                 case aubio_onset_mkl:
    321                         del_fvec(o->oldmag);
    322                         break;
    323                 default:
    324                         break;
    325         }
    326         AUBIO_FREE(o);
    327        
    328 }
     302  switch(o->type) {
     303    /* for both energy and hfc, only fftgrain->norm is required */
     304    case aubio_onset_energy:
     305      break;
     306    case aubio_onset_hfc:
     307      break;
     308      /* the other approaches will need some more memory spaces */
     309    case aubio_onset_complex:
     310      AUBIO_FREE(o->meas);
     311      del_fvec(o->oldmag);
     312      del_fvec(o->dev1);
     313      del_fvec(o->theta1);
     314      del_fvec(o->theta2);
     315      break;
     316    case aubio_onset_phase:
     317      del_fvec(o->dev1);
     318      del_fvec(o->theta1);
     319      del_fvec(o->theta2);
     320      del_aubio_hist(o->histog);
     321      break;
     322    case aubio_onset_specdiff:
     323      del_fvec(o->oldmag);
     324      del_fvec(o->dev1);
     325      del_aubio_hist(o->histog);
     326      break;
     327    case aubio_onset_kl:
     328      del_fvec(o->oldmag);
     329      break;
     330    case aubio_onset_mkl:
     331      del_fvec(o->oldmag);
     332      break;
     333    default:
     334      break;
     335  }
     336  AUBIO_FREE(o);
     337}
  • src/onsetdetection.h

    rc1656cf r7873363  
    4747        aubio_onset_phase,          /**< phase fast */           
    4848        aubio_onset_kl,             /**< Kullback Liebler */
    49         aubio_onset_mkl             /**< modified Kullback Liebler */
     49        aubio_onset_mkl,            /**< modified Kullback Liebler */
     50        aubio_onset_specflux,       /**< spectral flux */
    5051} aubio_onsetdetection_type;
    5152
     
    137138*/
    138139void aubio_onsetdetection_mkl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
     140/** Spectral Flux
     141
     142  Simon Dixon, Onset Detection Revisited, in ``Proceedings of the 9th
     143  International Conference on Digital Audio Effects'' (DAFx-06), Montreal,
     144  Canada, 2006.
     145
     146  \param o onset detection object as returned by new_aubio_onsetdetection()
     147  \param fftgrain input spectral frame
     148  \param onset output onset detection function
     149
     150*/
     151void aubio_onsetdetection_specflux(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
    139152/** execute onset detection function on a spectral frame
    140153
     
    161174*/
    162175void del_aubio_onsetdetection(aubio_onsetdetection_t *o);
    163 /** deletion of an onset detection object (obsolete)
    164 
    165   \param o onset detection object as returned by new_aubio_onsetdetection()
    166 
    167 */
    168 void aubio_onsetdetection_free(aubio_onsetdetection_t *o);
    169 
    170176
    171177#ifdef __cplusplus
  • src/phasevoc.c

    rc1656cf r7873363  
    1919
    2020#include "aubio_priv.h"
    21 #include "sample.h"
     21#include "fvec.h"
     22#include "cvec.h"
    2223#include "fft.h"
    2324#include "mathutils.h"
     
    2627/** phasevocoder internal object */
    2728struct _aubio_pvoc_t {
    28         /** grain length */
    29         uint_t win_s;
    30         /** overlap step */
    31         uint_t hop_s;
    32         /** number of channels */
    33         uint_t channels;
    34         /** spectral data */
    35         aubio_mfft_t * fft;
    36         /**cur output grain             [win_s] */
    37         fvec_t * synth;         
    38         /**last input frame             [win_s-hop_s] */
    39         fvec_t * synthold;
    40         /**current input grain          [win_s] */
    41         fvec_t * data;           
    42         /**last input frame             [win_s-hop_s] */
    43         fvec_t * dataold; 
    44         /** grain window                [win_s] */
    45         float * w;
     29  uint_t win_s;       /** grain length */
     30  uint_t hop_s;       /** overlap step */
     31  uint_t channels;    /** number of channels */
     32  aubio_fft_t * fft;  /** fft object */
     33  fvec_t * synth;     /** cur output grain [win_s] */
     34  fvec_t * synthold;  /** last input frame [win_s-hop_s] */
     35  fvec_t * data;      /** current input grain [win_s] */
     36  fvec_t * dataold;   /** last input frame [win_s-hop_s] */
     37  smpl_t * w;         /** grain window [win_s] */
    4638};
    4739
    4840
    4941/** returns data and dataold slided by hop_s */
    50 static void aubio_pvoc_swapbuffers(
    51                 smpl_t * data,
    52                 smpl_t * dataold,
    53                 const smpl_t * datanew,
    54                 uint_t win_s, uint_t hop_s);
     42static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, const
     43    smpl_t * datanew, uint_t win_s, uint_t hop_s);
     44
    5545/** do additive synthesis from 'old' and 'cur' */
    56 static void aubio_pvoc_addsynth(
    57                 const smpl_t * synth,
    58                 smpl_t * synthold,
    59                 smpl_t * synthnew,
    60                 uint_t win_s, uint_t hop_s);
    61 
     46static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold,
     47    smpl_t * synthnew, uint_t win_s, uint_t hop_s);
    6248
    6349void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {
    64         uint_t i,j;
    65         for (i=0; i<pv->channels; i++) {
    66                 /* slide  */
    67                 aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
    68                                 datanew->data[i],pv->win_s,pv->hop_s);
    69                 /* windowing */
    70                 for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j];
    71         }
    72         /* shift */
    73         vec_shift(pv->data);
    74         /* calculate fft */
    75         aubio_mfft_do (pv->fft,pv->data,fftgrain);
     50  uint_t i,j;
     51  for (i=0; i<pv->channels; i++) {
     52    /* slide  */
     53    aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
     54        datanew->data[i],pv->win_s,pv->hop_s);
     55    /* windowing */
     56    for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j];
     57  }
     58  /* shift */
     59  vec_shift(pv->data);
     60  /* calculate fft */
     61  aubio_fft_do (pv->fft,pv->data,fftgrain);
    7662}
    7763
    7864void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) {
    79         uint_t i,j;
    80         /* calculate rfft */
    81         aubio_mfft_rdo(pv->fft,fftgrain,pv->synth);
    82         /* unshift */
    83         vec_shift(pv->synth);
    84         for (i=0; i<pv->channels; i++) {
    85                 for (j=0; j<pv->win_s; j++) pv->synth->data[i][j] *= pv->w[j];
    86                 aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
    87                                 synthnew->data[i],pv->win_s,pv->hop_s);
    88         }
     65  uint_t i;
     66  /* calculate rfft */
     67  aubio_fft_rdo(pv->fft,fftgrain,pv->synth);
     68  /* unshift */
     69  vec_shift(pv->synth);
     70  for (i=0; i<pv->channels; i++) {
     71    aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
     72        synthnew->data[i],pv->win_s,pv->hop_s);
     73  }
    8974}
    9075
    9176aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) {
    92         aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
     77  aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
    9378
    94         if (win_s < 2*hop_s) {
    95                 AUBIO_ERR("Hop size bigger than half the window size!\n");
    96                 AUBIO_ERR("Resetting hop size to half the window size.\n");
    97                 hop_s = win_s / 2;
    98         }
     79  if (win_s < 2*hop_s) {
     80    AUBIO_ERR("Hop size bigger than half the window size!\n");
     81    AUBIO_ERR("Resetting hop size to half the window size.\n");
     82    hop_s = win_s / 2;
     83  }
    9984
    100         if (hop_s < 1) {
    101                 AUBIO_ERR("Hop size is smaller than 1!\n");
    102                 AUBIO_ERR("Resetting hop size to half the window size.\n");
    103                 hop_s = win_s / 2;
    104         }
    105        
    106         pv->fft      = new_aubio_mfft(win_s,channels);
     85  if (hop_s < 1) {
     86    AUBIO_ERR("Hop size is smaller than 1!\n");
     87    AUBIO_ERR("Resetting hop size to half the window size.\n");
     88    hop_s = win_s / 2;
     89  }
    10790
    108         /* remember old */
    109         pv->data     = new_fvec (win_s, channels);
    110         pv->synth    = new_fvec (win_s, channels);
     91  pv->fft      = new_aubio_fft(win_s,channels);
    11192
    112         /* new input output */
    113         pv->dataold  = new_fvec  (win_s-hop_s, channels);
    114         pv->synthold = new_fvec (win_s-hop_s, channels);
    115         pv->w        = AUBIO_ARRAY(smpl_t,win_s);
    116         aubio_window(pv->w,win_s,aubio_win_hanningz);
     93  /* remember old */
     94  pv->data     = new_fvec (win_s, channels);
     95  pv->synth    = new_fvec (win_s, channels);
    11796
    118         pv->channels = channels;
    119         pv->hop_s    = hop_s;
    120         pv->win_s    = win_s;
     97  /* new input output */
     98  pv->dataold  = new_fvec  (win_s-hop_s, channels);
     99  pv->synthold = new_fvec (win_s-hop_s, channels);
     100  pv->w        = AUBIO_ARRAY(smpl_t,win_s);
     101  aubio_window(pv->w,win_s,aubio_win_hanningz);
    121102
    122         return pv;
     103  pv->channels = channels;
     104  pv->hop_s    = hop_s;
     105  pv->win_s    = win_s;
     106
     107  return pv;
    123108}
    124109
    125110void del_aubio_pvoc(aubio_pvoc_t *pv) {
    126         del_fvec(pv->data);
    127         del_fvec(pv->synth);
    128         del_fvec(pv->dataold);
    129         del_fvec(pv->synthold);
    130         del_aubio_mfft(pv->fft);
    131         AUBIO_FREE(pv->w);
    132         AUBIO_FREE(pv);
     111  del_fvec(pv->data);
     112  del_fvec(pv->synth);
     113  del_fvec(pv->dataold);
     114  del_fvec(pv->synthold);
     115  del_aubio_fft(pv->fft);
     116  AUBIO_FREE(pv->w);
     117  AUBIO_FREE(pv);
    133118}
    134119
    135120static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold,
    136                 const smpl_t * datanew, uint_t win_s, uint_t hop_s)
     121    const smpl_t * datanew, uint_t win_s, uint_t hop_s)
    137122{
    138         uint_t i;
    139         for (i=0;i<win_s-hop_s;i++)
    140                 data[i] = dataold[i];
    141         for (i=0;i<hop_s;i++)
    142                 data[win_s-hop_s+i] = datanew[i];
    143         for (i=0;i<win_s-hop_s;i++)
    144                 dataold[i] = data[i+hop_s];
     123  uint_t i;
     124  for (i=0;i<win_s-hop_s;i++)
     125    data[i] = dataold[i];
     126  for (i=0;i<hop_s;i++)
     127    data[win_s-hop_s+i] = datanew[i];
     128  for (i=0;i<win_s-hop_s;i++)
     129    dataold[i] = data[i+hop_s];
    145130}
    146131
     
    148133                smpl_t * synthnew, uint_t win_s, uint_t hop_s)
    149134{
    150         uint_t i;
    151         smpl_t scale = 2*hop_s/(win_s+.0);
    152         /* add new synth to old one and put result in synthnew */
    153         for (i=0;i<hop_s;i++)                                           
    154                 synthnew[i] = synthold[i]+synth[i]*scale;
    155         /* shift synthold */
    156         for (i=0;i<win_s-2*hop_s;i++)   
    157                 synthold[i] = synthold[i+hop_s];
    158         /* erase last frame in synthold */
    159         for (i=win_s-hop_s;i<win_s;i++)
    160                 synthold[i-hop_s]=0.;
    161         /* additive synth */
    162         for (i=0;i<win_s-hop_s;i++)     
    163                 synthold[i] += synth[i+hop_s]*scale;
     135  uint_t i;
     136  smpl_t scale = 2*hop_s/(win_s+.0);
     137  /* add new synth to old one and put result in synthnew */
     138  for (i=0;i<hop_s;i++)
     139    synthnew[i] = synthold[i]+synth[i]*scale;
     140  /* shift synthold */
     141  for (i=0;i<win_s-2*hop_s;i++)
     142    synthold[i] = synthold[i+hop_s];
     143  /* erase last frame in synthold */
     144  for (i=win_s-hop_s;i<win_s;i++)
     145    synthold[i-hop_s]=0.;
     146  /* additive synth */
     147  for (i=0;i<win_s-hop_s;i++)
     148    synthold[i] += synth[i+hop_s]*scale;
    164149}
    165150
  • src/pitchdetection.c

    rc1656cf r7873363  
    1515   along with this program; if not, write to the Free Software
    1616   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    17 */
     17   */
    1818
    1919#include "aubio_priv.h"
     
    2929#include "pitchdetection.h"
    3030
    31 typedef smpl_t (*aubio_pitchdetection_func_t)(aubio_pitchdetection_t *p,
    32                 fvec_t * ibuf);
    33 typedef smpl_t (*aubio_pitchdetection_conv_t)(smpl_t value,uint_t srate,uint_t bufsize);
     31typedef smpl_t (*aubio_pitchdetection_func_t)
     32  (aubio_pitchdetection_t *p, fvec_t * ibuf);
     33typedef smpl_t (*aubio_pitchdetection_conv_t)
     34  (smpl_t value, uint_t srate, uint_t bufsize);
     35
    3436void aubio_pitchdetection_slideblock(aubio_pitchdetection_t *p, fvec_t *ibuf);
    3537
    36 smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t * ibuf);
    37 smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf);
    38 smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf);
    39 smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf);
    40 smpl_t aubio_pitchdetection_yinfft(aubio_pitchdetection_t *p, fvec_t *ibuf);
     38smpl_t aubio_pitchdetection_mcomb   (aubio_pitchdetection_t *p, fvec_t *ibuf);
     39smpl_t aubio_pitchdetection_yin     (aubio_pitchdetection_t *p, fvec_t *ibuf);
     40smpl_t aubio_pitchdetection_schmitt (aubio_pitchdetection_t *p, fvec_t *ibuf);
     41smpl_t aubio_pitchdetection_fcomb   (aubio_pitchdetection_t *p, fvec_t *ibuf);
     42smpl_t aubio_pitchdetection_yinfft  (aubio_pitchdetection_t *p, fvec_t *ibuf);
    4143
    4244/** generic pitch detection structure */
     
    6466smpl_t freqconvbin(smpl_t f,uint_t srate,uint_t bufsize);
    6567smpl_t freqconvbin(smpl_t f,uint_t srate,uint_t bufsize){
    66         return aubio_freqtobin(f,srate,bufsize);
     68  return aubio_freqtobin(f,srate,bufsize);
    6769}
    6870
    6971smpl_t freqconvmidi(smpl_t f,uint_t srate,uint_t bufsize);
    7072smpl_t freqconvmidi(smpl_t f,uint_t srate UNUSED,uint_t bufsize UNUSED){
    71         return aubio_freqtomidi(f);
     73  return aubio_freqtomidi(f);
    7274}
    7375
    7476smpl_t freqconvpass(smpl_t f,uint_t srate,uint_t bufsize);
    7577smpl_t freqconvpass(smpl_t f,uint_t srate UNUSED,uint_t bufsize UNUSED){
    76         return f;
     78  return f;
    7779}
    7880
    7981aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize,
    80                 uint_t hopsize,
    81                 uint_t channels,
    82                 uint_t samplerate,
    83                 aubio_pitchdetection_type type,
    84                 aubio_pitchdetection_mode mode)
     82    uint_t hopsize,
     83    uint_t channels,
     84    uint_t samplerate,
     85    aubio_pitchdetection_type type,
     86    aubio_pitchdetection_mode mode)
    8587{
    86         aubio_pitchdetection_t *p = AUBIO_NEW(aubio_pitchdetection_t);
    87         p->srate = samplerate;
    88         p->type = type;
    89         p->mode = mode;
    90         p->bufsize = bufsize;
    91         switch(p->type) {
    92                 case aubio_pitch_yin:
    93                         p->buf      = new_fvec(bufsize,channels);
    94                         p->yin      = new_fvec(bufsize/2,channels);
    95                         p->callback = aubio_pitchdetection_yin;
    96                         p->yinthres = 0.15;
    97                         break;
    98                 case aubio_pitch_mcomb:
    99                         p->pv       = new_aubio_pvoc(bufsize, hopsize, channels);
    100                         p->fftgrain = new_cvec(bufsize, channels);
    101                         p->mcomb    = new_aubio_pitchmcomb(bufsize,hopsize,channels,samplerate);
    102                         p->filter   = new_aubio_cdsgn_filter(samplerate);
    103                         p->callback = aubio_pitchdetection_mcomb;
    104                         break;
    105                 case aubio_pitch_fcomb:
    106                         p->buf      = new_fvec(bufsize,channels);
    107                         p->fcomb    = new_aubio_pitchfcomb(bufsize,hopsize,samplerate);
    108                         p->callback = aubio_pitchdetection_fcomb;
    109                         break;
    110                 case aubio_pitch_schmitt:
    111                         p->buf      = new_fvec(bufsize,channels);
    112                         p->schmitt  = new_aubio_pitchschmitt(bufsize,samplerate);
    113                         p->callback = aubio_pitchdetection_schmitt;
    114                         break;
    115                 case aubio_pitch_yinfft:
    116                         p->buf      = new_fvec(bufsize,channels);
    117                         p->yinfft   = new_aubio_pitchyinfft(bufsize);
    118                         p->callback = aubio_pitchdetection_yinfft;
    119                         p->yinthres = 0.85;
    120                         break;
    121                 default:
    122                         break;
    123         }
    124         switch(p->mode) {
    125                 case aubio_pitchm_freq:
    126                         p->freqconv = freqconvpass;
    127                         break;
    128                 case aubio_pitchm_midi:
    129                         p->freqconv = freqconvmidi;
    130                         break;
    131                 case aubio_pitchm_cent:
    132                         /* bug: not implemented */
    133                         p->freqconv = freqconvmidi;
    134                         break;
    135                 case aubio_pitchm_bin:
    136                         p->freqconv = freqconvbin;
    137                         break;
    138                 default:
    139                         break;
    140         }
    141         return p;
     88  aubio_pitchdetection_t *p = AUBIO_NEW(aubio_pitchdetection_t);
     89  p->srate = samplerate;
     90  p->type = type;
     91  p->mode = mode;
     92  p->bufsize = bufsize;
     93  switch(p->type) {
     94    case aubio_pitch_yin:
     95      p->buf      = new_fvec(bufsize,channels);
     96      p->yin      = new_fvec(bufsize/2,channels);
     97      p->callback = aubio_pitchdetection_yin;
     98      p->yinthres = 0.15;
     99      break;
     100    case aubio_pitch_mcomb:
     101      p->pv       = new_aubio_pvoc(bufsize, hopsize, channels);
     102      p->fftgrain = new_cvec(bufsize, channels);
     103      p->mcomb    = new_aubio_pitchmcomb(bufsize,hopsize,channels,samplerate);
     104      p->filter   = new_aubio_cdsgn_filter(samplerate);
     105      p->callback = aubio_pitchdetection_mcomb;
     106      break;
     107    case aubio_pitch_fcomb:
     108      p->buf      = new_fvec(bufsize,channels);
     109      p->fcomb    = new_aubio_pitchfcomb(bufsize,hopsize,samplerate);
     110      p->callback = aubio_pitchdetection_fcomb;
     111      break;
     112    case aubio_pitch_schmitt:
     113      p->buf      = new_fvec(bufsize,channels);
     114      p->schmitt  = new_aubio_pitchschmitt(bufsize,samplerate);
     115      p->callback = aubio_pitchdetection_schmitt;
     116      break;
     117    case aubio_pitch_yinfft:
     118      p->buf      = new_fvec(bufsize,channels);
     119      p->yinfft   = new_aubio_pitchyinfft(bufsize);
     120      p->callback = aubio_pitchdetection_yinfft;
     121      p->yinthres = 0.85;
     122      break;
     123    default:
     124      break;
     125  }
     126  switch(p->mode) {
     127    case aubio_pitchm_freq:
     128      p->freqconv = freqconvpass;
     129      break;
     130    case aubio_pitchm_midi:
     131      p->freqconv = freqconvmidi;
     132      break;
     133    case aubio_pitchm_cent:
     134      /* bug: not implemented */
     135      p->freqconv = freqconvmidi;
     136      break;
     137    case aubio_pitchm_bin:
     138      p->freqconv = freqconvbin;
     139      break;
     140    default:
     141      break;
     142  }
     143  return p;
    142144}
    143145
    144146void del_aubio_pitchdetection(aubio_pitchdetection_t * p) {
    145         switch(p->type) {
    146                 case aubio_pitch_yin:
    147                         del_fvec(p->yin);
    148                         del_fvec(p->buf);
    149                         break;
    150                 case aubio_pitch_mcomb:
    151                         del_aubio_pvoc(p->pv);
    152                         del_cvec(p->fftgrain);
    153                         del_aubio_pitchmcomb(p->mcomb);
    154                         break;
    155                 case aubio_pitch_schmitt:
    156                         del_fvec(p->buf);
    157                         del_aubio_pitchschmitt(p->schmitt);
    158                         break;
    159                 case aubio_pitch_fcomb:
    160                         del_fvec(p->buf);
    161                         del_aubio_pitchfcomb(p->fcomb);
    162                         break;
    163                 case aubio_pitch_yinfft:
    164                         del_fvec(p->buf);
    165                         del_aubio_pitchyinfft(p->yinfft);
    166                         break;
    167                 default:
    168                         break;
    169         }
    170         AUBIO_FREE(p);
     147  switch(p->type) {
     148    case aubio_pitch_yin:
     149      del_fvec(p->yin);
     150      del_fvec(p->buf);
     151      break;
     152    case aubio_pitch_mcomb:
     153      del_aubio_pvoc(p->pv);
     154      del_cvec(p->fftgrain);
     155      del_aubio_filter(p->filter);
     156      del_aubio_pitchmcomb(p->mcomb);
     157      break;
     158    case aubio_pitch_schmitt:
     159      del_fvec(p->buf);
     160      del_aubio_pitchschmitt(p->schmitt);
     161      break;
     162    case aubio_pitch_fcomb:
     163      del_fvec(p->buf);
     164      del_aubio_pitchfcomb(p->fcomb);
     165      break;
     166    case aubio_pitch_yinfft:
     167      del_fvec(p->buf);
     168      del_aubio_pitchyinfft(p->yinfft);
     169      break;
     170    default:
     171      break;
     172  }
     173  AUBIO_FREE(p);
    171174}
    172175
    173176void aubio_pitchdetection_slideblock(aubio_pitchdetection_t *p, fvec_t *ibuf){
    174         uint_t i,j = 0, overlap_size = 0;
    175         overlap_size = p->buf->length-ibuf->length;
    176         for (i=0;i<p->buf->channels;i++){
    177                 for (j=0;j<overlap_size;j++){
    178                         p->buf->data[i][j] =
    179                                 p->buf->data[i][j+ibuf->length];
    180                 }
    181         }
    182         for (i=0;i<ibuf->channels;i++){
    183                 for (j=0;j<ibuf->length;j++){
    184                         p->buf->data[i][j+overlap_size] =
    185                                 ibuf->data[i][j];
    186                 }
    187         }
     177  uint_t i,j = 0, overlap_size = 0;
     178  overlap_size = p->buf->length-ibuf->length;
     179  for (i=0;i<p->buf->channels;i++){
     180    for (j=0;j<overlap_size;j++){
     181      p->buf->data[i][j] = p->buf->data[i][j+ibuf->length];
     182    }
     183  }
     184  for (i=0;i<ibuf->channels;i++){
     185    for (j=0;j<ibuf->length;j++){
     186      p->buf->data[i][j+overlap_size] = ibuf->data[i][j];
     187    }
     188  }
    188189}
    189190
    190191void aubio_pitchdetection_set_yinthresh(aubio_pitchdetection_t *p, smpl_t thres) {
    191         p->yinthres = thres;
     192  p->yinthres = thres;
    192193}
    193194
    194195smpl_t aubio_pitchdetection(aubio_pitchdetection_t *p, fvec_t * ibuf) {
    195         return p->freqconv(p->callback(p,ibuf),p->srate,p->bufsize);
     196  return p->freqconv(p->callback(p,ibuf),p->srate,p->bufsize);
    196197}
    197198
    198199smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t *ibuf) {
    199         smpl_t pitch = 0.;
    200         aubio_filter_do(p->filter,ibuf);
    201         aubio_pvoc_do(p->pv,ibuf,p->fftgrain);
    202         pitch = aubio_pitchmcomb_detect(p->mcomb,p->fftgrain);
    203         /** \bug should move the >0 check within aubio_bintofreq */
    204         if (pitch>0.) {
    205                 pitch = aubio_bintofreq(pitch,p->srate,p->bufsize);
    206         } else {
    207                 pitch = 0.;
    208         }
    209         return pitch;
     200  smpl_t pitch = 0.;
     201  aubio_filter_do(p->filter,ibuf);
     202  aubio_pvoc_do(p->pv,ibuf,p->fftgrain);
     203  pitch = aubio_pitchmcomb_detect(p->mcomb,p->fftgrain);
     204  /** \bug should move the >0 check within aubio_bintofreq */
     205  if (pitch>0.) {
     206    pitch = aubio_bintofreq(pitch,p->srate,p->bufsize);
     207  } else {
     208    pitch = 0.;
     209  }
     210  return pitch;
    210211}
    211212
    212213smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf) {
    213         smpl_t pitch = 0.;
    214         aubio_pitchdetection_slideblock(p,ibuf);
    215         pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, p->yinthres);
    216         if (pitch>0) {
    217                 pitch = p->srate/(pitch+0.);
    218         } else {
    219                 pitch = 0.;
    220         }
    221         return pitch;
     214  smpl_t pitch = 0.;
     215  aubio_pitchdetection_slideblock(p,ibuf);
     216  pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, p->yinthres);
     217  if (pitch>0) {
     218    pitch = p->srate/(pitch+0.);
     219  } else {
     220    pitch = 0.;
     221  }
     222  return pitch;
    222223}
    223224
    224225
    225226smpl_t aubio_pitchdetection_yinfft(aubio_pitchdetection_t *p, fvec_t *ibuf){
    226         smpl_t pitch = 0.;
    227         aubio_pitchdetection_slideblock(p,ibuf);
    228         pitch = aubio_pitchyinfft_detect(p->yinfft,p->buf,p->yinthres);
    229         if (pitch>0) {
    230                 pitch = p->srate/(pitch+0.);
    231         } else {
    232                 pitch = 0.;
    233         }
    234         return pitch;
     227  smpl_t pitch = 0.;
     228  aubio_pitchdetection_slideblock(p,ibuf);
     229  pitch = aubio_pitchyinfft_detect(p->yinfft,p->buf,p->yinthres);
     230  if (pitch>0) {
     231    pitch = p->srate/(pitch+0.);
     232  } else {
     233    pitch = 0.;
     234  }
     235  return pitch;
    235236}
    236237
    237238smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf){
    238         aubio_pitchdetection_slideblock(p,ibuf);
    239         return aubio_pitchfcomb_detect(p->fcomb,p->buf);
     239  aubio_pitchdetection_slideblock(p,ibuf);
     240  return aubio_pitchfcomb_detect(p->fcomb,p->buf);
    240241}
    241242
    242243smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf){
    243         aubio_pitchdetection_slideblock(p,ibuf);
    244         return aubio_pitchschmitt_detect(p->schmitt,p->buf);
    245 }
     244  aubio_pitchdetection_slideblock(p,ibuf);
     245  return aubio_pitchschmitt_detect(p->schmitt,p->buf);
     246}
  • src/pitchdetection.h

    rc1656cf r7873363  
    1515   along with this program; if not, write to the Free Software
    1616   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    17 */
     17   */
    1818
    1919#ifndef PITCHAUTOTCORR_H
     
    2626/** \file
    2727
    28   Generic method for pitch detection 
     28  Generic method for pitch detection
    2929
    3030  This file creates the objects required for the computation of the selected
     
    3535/** pitch detection algorithm */
    3636typedef enum {
    37         aubio_pitch_yin,     /**< YIN algorithm */
    38         aubio_pitch_mcomb,   /**< Multi-comb filter */
    39         aubio_pitch_schmitt, /**< Schmitt trigger */
    40         aubio_pitch_fcomb,   /**< Fast comb filter */
    41         aubio_pitch_yinfft   /**< Spectral YIN */
     37  aubio_pitch_yin,     /**< YIN algorithm */
     38  aubio_pitch_mcomb,   /**< Multi-comb filter */
     39  aubio_pitch_schmitt, /**< Schmitt trigger */
     40  aubio_pitch_fcomb,   /**< Fast comb filter */
     41  aubio_pitch_yinfft   /**< Spectral YIN */
    4242} aubio_pitchdetection_type;
    4343
    4444/** pitch detection output mode */
    4545typedef enum {
    46         aubio_pitchm_freq,   /**< Frequency (Hz) */
    47         aubio_pitchm_midi,   /**< MIDI note (0.,127) */
    48         aubio_pitchm_cent,   /**< Cent */
    49         aubio_pitchm_bin     /**< Frequency bin (0,bufsize) */
     46  aubio_pitchm_freq,   /**< Frequency (Hz) */
     47  aubio_pitchm_midi,   /**< MIDI note (0.,127) */
     48  aubio_pitchm_cent,   /**< Cent */
     49  aubio_pitchm_bin     /**< Frequency bin (0,bufsize) */
    5050} aubio_pitchdetection_mode;
    5151
     
    5454
    5555/** execute pitch detection on an input signal frame
    56  
     56
    5757  \param p pitch detection object as returned by new_aubio_pitchdetection
    58   \param ibuf input signal of length hopsize 
    59  
     58  \param ibuf input signal of length hopsize
     59
    6060*/
    6161smpl_t aubio_pitchdetection(aubio_pitchdetection_t * p, fvec_t * ibuf);
    6262
    6363/** change yin or yinfft tolerance threshold
    64  
     64
    6565  default is 0.15 for yin and 0.85 for yinfft
    66  
     66
    6767*/
    6868void aubio_pitchdetection_set_yinthresh(aubio_pitchdetection_t *p, smpl_t thres);
    6969
    7070/** deletion of the pitch detection object
    71  
     71
    7272  \param p pitch detection object as returned by new_aubio_pitchdetection
    73  
     73
    7474*/
    7575void del_aubio_pitchdetection(aubio_pitchdetection_t * p);
    7676
    7777/** creation of the pitch detection object
    78  
    79   \param bufsize size of the input buffer to analyse 
    80   \param hopsize step size between two consecutive analysis instant 
     78
     79  \param bufsize size of the input buffer to analyse
     80  \param hopsize step size between two consecutive analysis instant
    8181  \param channels number of channels to analyse
    82   \param samplerate sampling rate of the signal 
     82  \param samplerate sampling rate of the signal
    8383  \param type set pitch detection algorithm
    8484  \param mode set pitch units for output
    85  
     85
    8686*/
    87 aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize, 
    88         uint_t hopsize,
    89         uint_t channels,
    90         uint_t samplerate,
    91         aubio_pitchdetection_type type,
    92         aubio_pitchdetection_mode mode);
     87aubio_pitchdetection_t * new_aubio_pitchdetection(uint_t bufsize,
     88    uint_t hopsize,
     89    uint_t channels,
     90    uint_t samplerate,
     91    aubio_pitchdetection_type type,
     92    aubio_pitchdetection_mode mode);
    9393
    9494#ifdef __cplusplus
     
    9696#endif
    9797
    98 #endif /*PITCHDETECTION_H*/ 
     98#endif /*PITCHDETECTION_H*/
  • src/pitchfcomb.c

    rc1656cf r7873363  
    3232
    3333struct _aubio_pitchfcomb_t {
    34         uint_t fftSize;
    35         uint_t stepSize;
    36         uint_t rate;
    37         fvec_t * winput;
    38         fvec_t * win;
    39         cvec_t * fftOut;
    40         fvec_t * fftLastPhase;
    41         aubio_mfft_t * fft;
    42         //aubio_pvoc_t * pvoc;
     34  uint_t fftSize;
     35  uint_t stepSize;
     36  uint_t rate;
     37  fvec_t * winput;
     38  fvec_t * win;
     39  cvec_t * fftOut;
     40  fvec_t * fftLastPhase;
     41  aubio_fft_t * fft;
     42  //aubio_pvoc_t * pvoc;
    4343};
    4444
     
    4848  p->rate         = samplerate;
    4949  p->fftSize      = bufsize;
    50   p->stepSize     = hopsize; 
     50  p->stepSize     = hopsize;
    5151  p->winput       = new_fvec(bufsize,1);
    5252  p->fftOut       = new_cvec(bufsize,1);
    5353  p->fftLastPhase = new_fvec(bufsize,1);
    54   p->fft = new_aubio_mfft(bufsize, 1);
     54  p->fft = new_aubio_fft(bufsize, 1);
    5555  p->win = new_fvec(bufsize,1);
    5656  aubio_window(p->win->data[0], bufsize, aubio_win_hanning);
     
    7272
    7373  for (k=0; k < input->length; k++){
    74           p->winput->data[0][k] = p->win->data[0][k] * input->data[0][k];
     74    p->winput->data[0][k] = p->win->data[0][k] * input->data[0][k];
    7575  }
    76   aubio_mfft_do(p->fft,p->winput,p->fftOut);
     76  aubio_fft_do(p->fft,p->winput,p->fftOut);
    7777
    7878  for (k=0; k<=p->fftSize/2; k++) {
     
    104104    }
    105105  }
    106  
     106
    107107  k = 0;
    108108  for (l=1; l<MAX_PEAKS && peaks[l].freq > 0.0; l++) {
     
    110110    for (harmonic=5; harmonic>1; harmonic--) {
    111111      if (peaks[0].freq / peaks[l].freq < harmonic+.02 &&
    112         peaks[0].freq / peaks[l].freq > harmonic-.02) {
     112          peaks[0].freq / peaks[l].freq > harmonic-.02) {
    113113        if (harmonic > (sint_t)maxharm &&
    114           peaks[0].db < peaks[l].db/2) {
     114            peaks[0].db < peaks[l].db/2) {
    115115          maxharm = harmonic;
    116           k = l;
     116          k = l;
    117117        }
    118118      }
     
    130130  del_fvec(p->win);
    131131  del_fvec(p->winput);
    132   del_aubio_mfft(p->fft);
     132  del_aubio_fft(p->fft);
    133133  AUBIO_FREE(p);
    134134}
  • src/pitchmcomb.c

    rc1656cf r7873363  
    9797  for (j=0; j< newmag->length; j++)
    9898    newmag->data[i][j]=fftgrain->norm[i][j];
    99   /* detect only if local energy > 10. */ 
     99  /* detect only if local energy > 10. */
    100100  //if (vec_local_energy(newmag)>10.) {
    101101    //hfc = vec_local_hfc(newmag); //not used
     
    106106  j = (uint_t)FLOOR(p->candidates[p->goodcandidate]->ebin+.5);
    107107  instfreq  = aubio_unwrap2pi(fftgrain->phas[0][j]
    108                   - p->theta->data[0][j] - j*p->phasediff);
     108      - p->theta->data[0][j] - j*p->phasediff);
    109109  instfreq *= p->phasefreq;
    110110  /* store phase for next run */
     
    119119}
    120120
    121 uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain, 
     121uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain,
    122122    smpl_t * cands) {
    123123  uint_t i=0,j;
    124124  uint_t k;
    125125  fvec_t * newmag = (fvec_t *)p->newmag;
    126   aubio_spectralcandidate_t ** scands = 
     126  aubio_spectralcandidate_t ** scands =
    127127    (aubio_spectralcandidate_t **)(p->candidates);
    128128  //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta;
     
    130130  for (j=0; j< newmag->length; j++)
    131131    newmag->data[i][j]=fftgrain->norm[i][j];
    132   /* detect only if local energy > 10. */ 
    133   if (vec_local_energy(newmag)>10.)     {
     132  /* detect only if local energy > 10. */
     133  if (vec_local_energy(newmag)>10.) {
    134134    /* hfc = vec_local_hfc(newmag); do not use */
    135135    aubio_pitchmcomb_spectral_pp(p, newmag);
    136136    aubio_pitchmcomb_combdet(p,newmag);
    137137    aubio_pitchmcomb_sort_cand_freq(scands,p->ncand);
    138     /* store ncand comb energies in cands[1:ncand] */ 
    139     for (k = 0; k<p->ncand; k++) 
     138    /* store ncand comb energies in cands[1:ncand] */
     139    for (k = 0; k<p->ncand; k++)
    140140      cands[k] = p->candidates[k]->ene;
    141     /* store ncand[end] freq in cands[end] */ 
     141    /* store ncand[end] freq in cands[end] */
    142142    cands[p->ncand] = p->candidates[p->ncand-1]->ebin;
    143143    return 1;
     
    156156  /* copy newmag to mag (scracth) */
    157157  for (j=0;j<length;j++) {
    158     mag->data[i][j] = newmag->data[i][j]; 
     158    mag->data[i][j] = newmag->data[i][j];
    159159  }
    160160  vec_dc_removal(mag);               /* dc removal           */
     
    169169    /*  return bin and ebin */
    170170    count = aubio_pitchmcomb_quadpick(peaks,mag);
    171     for (j=0;j<count;j++) 
     171    for (j=0;j<count;j++)
    172172      peaks[j].mag = newmag->data[i][peaks[j].bin];
    173173    /* reset non peaks */
     
    181181void aubio_pitchmcomb_combdet(aubio_pitchmcomb_t * p, fvec_t * newmag) {
    182182  aubio_spectralpeak_t * peaks = (aubio_spectralpeak_t *)p->peaks;
    183   aubio_spectralcandidate_t ** candidate = 
     183  aubio_spectralcandidate_t ** candidate =
    184184    (aubio_spectralcandidate_t **)p->candidates;
    185185
     
    192192  uint_t l;
    193193  uint_t d;
    194   uint_t curlen;
     194  uint_t curlen = 0;
    195195
    196196  smpl_t delta2;
     
    214214    candidate[l]->ebin=scaler*peaks[root_peak].ebin;
    215215    /* if less than N peaks available, curlen < N */
    216     curlen = (uint_t)FLOOR(length/(candidate[l]->ebin));
     216    if (candidate[l]->ebin != 0.)
     217      curlen = (uint_t)FLOOR(length/(candidate[l]->ebin));
    217218    curlen = (N < curlen )? N : curlen;
    218219    /* fill candidate[l]->ecomb[k] with (k+1)*candidate[l]->ebin */
     
    224225    for (k=0;k<curlen;k++) {
    225226      xx = 100000.;
    226       /** get the candidate->ecomb the closer to peaks.ebin 
     227      /** get the candidate->ecomb the closer to peaks.ebin
    227228       * (to cope with the inharmonicity)*/
    228       for (d=0;d<count;d++) { 
     229      for (d=0;d<count;d++) {
    229230        delta2 = ABS(candidate[l]->ecomb[k]-peaks[d].ebin);
    230231        if (delta2 <= xx) {
     
    233234        }
    234235      }
    235       /* for a Q factor of 17, maintaining "constant Q filtering", 
     236      /* for a Q factor of 17, maintaining "constant Q filtering",
    236237       * and sum energy and length over non null combs */
    237238      if ( 17. * xx < candidate[l]->ecomb[k] ) {
     
    261262 * exact peak positions are retrieved by quadratic interpolation
    262263 *
    263  * \bug peak-picking too picky, sometimes counts too many peaks ? 
     264 * \bug peak-picking too picky, sometimes counts too many peaks ?
    264265 */
    265266uint_t aubio_pitchmcomb_quadpick(aubio_spectralpeak_t * spectral_peaks, fvec_t * X){
    266267  uint_t i, j, ispeak, count = 0;
    267268  for (i=0;i<X->channels;i++)
    268     for (j=1;j<X->length-1;j++) {
     269    for (j=1;j<X->length-1;j++) {
    269270      ispeak = vec_peakpick(X,j);
    270271      if (ispeak) {
     
    290291
    291292void aubio_pitchmcomb_sort_peak(aubio_spectralpeak_t * peaks, uint_t nbins) {
    292   qsort(peaks, nbins, sizeof(aubio_spectralpeak_t), 
     293  qsort(peaks, nbins, sizeof(aubio_spectralpeak_t),
    293294      aubio_pitchmcomb_sort_peak_comp);
    294295}
     
    326327  aubio_pitchmcomb_t * p = AUBIO_NEW(aubio_pitchmcomb_t);
    327328  /* bug: should check if size / 8 > post+pre+1 */
    328   uint_t i;
     329  uint_t i, j;
    329330  uint_t spec_size;
    330331  p->spec_partition   = 4;
     
    353354  /* array of spectral peaks */
    354355  p->peaks      = AUBIO_ARRAY(aubio_spectralpeak_t,spec_size);
     356  for (i = 0; i < spec_size; i++) {
     357    p->peaks[i].bin = 0.;
     358    p->peaks[i].ebin = 0.;
     359    p->peaks[i].mag = 0.;
     360  }
    355361  /* array of pointers to spectral candidates */
    356362  p->candidates = AUBIO_ARRAY(aubio_spectralcandidate_t *,p->ncand);
     
    358364    p->candidates[i] = AUBIO_NEW(aubio_spectralcandidate_t);
    359365    p->candidates[i]->ecomb = AUBIO_ARRAY(smpl_t, spec_size);
     366    for (j=0; j < spec_size; j++) {
     367      p->candidates[i]->ecomb[j] = 0.;
     368    }
     369    p->candidates[i]->ene = 0.;
     370    p->candidates[i]->ebin = 0.;
     371    p->candidates[i]->len = 0.;
    360372  }
    361373  return p;
     
    367379  del_fvec(p->newmag);
    368380  del_fvec(p->scratch);
     381  del_fvec(p->theta);
    369382  del_fvec(p->scratch2);
    370383  AUBIO_FREE(p->peaks);
    371384  for (i=0;i<p->ncand;i++) {
     385    AUBIO_FREE(p->candidates[i]->ecomb);
    372386    AUBIO_FREE(p->candidates[i]);
    373387  }
  • src/pitchyin.c

    rc1656cf r7873363  
    3333/* outputs the difference function */
    3434void aubio_pitchyin_diff(fvec_t * input, fvec_t * yin){
    35         uint_t c,j,tau;
    36         smpl_t tmp;
    37         for (c=0;c<input->channels;c++)
    38         {
    39                 for (tau=0;tau<yin->length;tau++)
    40                 {
    41                         yin->data[c][tau] = 0.;
    42                 }
    43                 for (tau=1;tau<yin->length;tau++)
    44                 {
    45                         for (j=0;j<yin->length;j++)
    46                         {
    47                                 tmp = input->data[c][j] - input->data[c][j+tau];
    48                                 yin->data[c][tau] += SQR(tmp);
    49                         }
    50                 }
    51         }
     35  uint_t c,j,tau;
     36  smpl_t tmp;
     37  for (c=0;c<input->channels;c++)
     38  {
     39    for (tau=0;tau<yin->length;tau++)
     40    {
     41      yin->data[c][tau] = 0.;
     42    }
     43    for (tau=1;tau<yin->length;tau++)
     44    {
     45      for (j=0;j<yin->length;j++)
     46      {
     47        tmp = input->data[c][j] - input->data[c][j+tau];
     48        yin->data[c][tau] += SQR(tmp);
     49      }
     50    }
     51  }
    5252}
    5353
    5454/* cumulative mean normalized difference function */
    5555void aubio_pitchyin_getcum(fvec_t * yin) {
    56         uint_t c,tau;
    57         smpl_t tmp;
    58         for (c=0;c<yin->channels;c++)
    59         {
    60                 tmp = 0.;
    61                 yin->data[c][0] = 1.;
    62                 //AUBIO_DBG("%f\t",yin->data[c][0]);
    63                 for (tau=1;tau<yin->length;tau++)
    64                 {
    65                         tmp += yin->data[c][tau];
    66                         yin->data[c][tau] *= tau/tmp;
    67                         //AUBIO_DBG("%f\t",yin->data[c][tau]);
    68                 }
    69                 //AUBIO_DBG("\n");
    70         }
     56  uint_t c,tau;
     57  smpl_t tmp;
     58  for (c=0;c<yin->channels;c++)
     59  {
     60    tmp = 0.;
     61    yin->data[c][0] = 1.;
     62    //AUBIO_DBG("%f\t",yin->data[c][0]);
     63    for (tau=1;tau<yin->length;tau++)
     64    {
     65      tmp += yin->data[c][tau];
     66      yin->data[c][tau] *= tau/tmp;
     67      //AUBIO_DBG("%f\t",yin->data[c][tau]);
     68    }
     69    //AUBIO_DBG("\n");
     70  }
    7171}
    7272
    7373uint_t aubio_pitchyin_getpitch(fvec_t * yin) {
    74         uint_t c=0,tau=1;
    75         do
    76         {
    77                 if(yin->data[c][tau] < 0.1) {
    78                         while (yin->data[c][tau+1] < yin->data[c][tau]) {
    79                                 tau++;
    80                         }
    81                         return tau;
    82                 }
    83                 tau++;
    84         } while (tau<yin->length);
    85         //AUBIO_DBG("No pitch found");
    86         return 0;
     74  uint_t c=0,tau=1;
     75  do
     76  {
     77    if(yin->data[c][tau] < 0.1) {
     78      while (yin->data[c][tau+1] < yin->data[c][tau]) {
     79        tau++;
     80      }
     81      return tau;
     82    }
     83    tau++;
     84  } while (tau<yin->length);
     85  //AUBIO_DBG("No pitch found");
     86  return 0;
    8787}
    8888
     
    9090/* all the above in one */
    9191smpl_t aubio_pitchyin_getpitchfast(fvec_t * input, fvec_t * yin, smpl_t tol){
    92         uint_t c=0,j,tau = 0;
    93         sint_t period;
    94         smpl_t tmp = 0., tmp2 = 0.;
    95         yin->data[c][0] = 1.;
    96         for (tau=1;tau<yin->length;tau++)
    97         {
    98                 yin->data[c][tau] = 0.;
    99                 for (j=0;j<yin->length;j++)
    100                 {
    101                         tmp = input->data[c][j] - input->data[c][j+tau];
    102                         yin->data[c][tau] += SQR(tmp);
    103                 }
    104                 tmp2 += yin->data[c][tau];
    105                 yin->data[c][tau] *= tau/tmp2;
    106                 period = tau-3;
    107                 if(tau > 4 && (yin->data[c][period] < tol) &&
    108                                 (yin->data[c][period] < yin->data[c][period+1])) {
    109                         return vec_quadint_min(yin,period,1);
    110                 }
    111         }
    112         return vec_quadint_min(yin,vec_min_elem(yin),1);
    113         //return 0;
     92  uint_t c=0,j,tau = 0;
     93  sint_t period;
     94  smpl_t tmp = 0., tmp2 = 0.;
     95  yin->data[c][0] = 1.;
     96  for (tau=1;tau<yin->length;tau++)
     97  {
     98    yin->data[c][tau] = 0.;
     99    for (j=0;j<yin->length;j++)
     100    {
     101      tmp = input->data[c][j] - input->data[c][j+tau];
     102      yin->data[c][tau] += SQR(tmp);
     103    }
     104    tmp2 += yin->data[c][tau];
     105    yin->data[c][tau] *= tau/tmp2;
     106    period = tau-3;
     107    if(tau > 4 && (yin->data[c][period] < tol) &&
     108        (yin->data[c][period] < yin->data[c][period+1])) {
     109      return vec_quadint_min(yin,period,1);
     110    }
     111  }
     112  return vec_quadint_min(yin,vec_min_elem(yin),1);
     113  //return 0;
    114114}
    115115
  • src/pitchyinfft.c

    rc1656cf r7873363  
    3131  fvec_t * weight;    /**< spectral weighting window (psychoacoustic model) */
    3232  cvec_t * fftout;    /**< Fourier transform output */
    33   aubio_mfft_t * fft; /**< fft object to compute square difference function */
     33  aubio_fft_t * fft; /**< fft object to compute square difference function */
    3434  fvec_t * yinfft;    /**< Yin function */
    3535};
    3636
    3737static const smpl_t freqs[] = {0., 20., 25., 31.5, 40., 50., 63., 80., 100.,
    38         125., 160., 200., 250., 315., 400., 500., 630., 800., 1000., 1250.,
    39         1600., 2000., 2500., 3150., 4000., 5000., 6300., 8000., 9000., 10000.,
    40         12500., 15000., 20000.,  25100};
     38  125., 160., 200., 250., 315., 400., 500., 630., 800., 1000., 1250.,
     39  1600., 2000., 2500., 3150., 4000., 5000., 6300., 8000., 9000., 10000.,
     40  12500., 15000., 20000.,  25100};
    4141
    4242static const smpl_t weight[] = {-75.8, -70.1, -60.8, -52.1, -44.2, -37.5,
    43         -31.3, -25.6, -20.9, -16.5, -12.6, -9.6, -7.0, -4.7, -3.0, -1.8, -0.8,
    44         -0.2, -0.0, 0.5, 1.6, 3.2, 5.4, 7.8, 8.1, 5.3, -2.4, -11.1, -12.8,
    45         -12.2, -7.4, -17.8, -17.8, -17.8};
     43  -31.3, -25.6, -20.9, -16.5, -12.6, -9.6, -7.0, -4.7, -3.0, -1.8, -0.8,
     44  -0.2, -0.0, 0.5, 1.6, 3.2, 5.4, 7.8, 8.1, 5.3, -2.4, -11.1, -12.8,
     45  -12.2, -7.4, -17.8, -17.8, -17.8};
    4646
    4747aubio_pitchyinfft_t * new_aubio_pitchyinfft (uint_t bufsize)
    4848{
    4949  aubio_pitchyinfft_t * p = AUBIO_NEW(aubio_pitchyinfft_t);
    50   p->winput       = new_fvec(bufsize,1);
    51   p->fft          = new_aubio_mfft(bufsize, 1);
    52   p->fftout       = new_cvec(bufsize,1);
    53   p->sqrmag       = new_fvec(bufsize,1);
    54   p->res          = new_cvec(bufsize,1);
    55   p->yinfft       = new_fvec(bufsize/2+1,1);
    56   p->win          = new_fvec(bufsize,1);
     50  p->winput = new_fvec(bufsize,1);
     51  p->fft    = new_aubio_fft(bufsize, 1);
     52  p->fftout = new_cvec(bufsize,1);
     53  p->sqrmag = new_fvec(bufsize,1);
     54  p->res    = new_cvec(bufsize,1);
     55  p->yinfft = new_fvec(bufsize/2+1,1);
     56  p->win    = new_fvec(bufsize,1);
    5757  aubio_window(p->win->data[0], bufsize, aubio_win_hanningz);
    5858  p->weight      = new_fvec(bufsize/2+1,1);
    5959  {
    60           uint_t i = 0, j = 1;
    61           smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
    62           for (i=0; i<p->weight->length; i++) {
    63                   freq = (smpl_t)i/(smpl_t)bufsize*(smpl_t)44100.;
    64                   while (freq > freqs[j]) {
    65                           j +=1;
    66                   }
    67                   a0 = weight[j-1];
    68                   f0 = freqs[j-1];
    69                   a1 = weight[j];
    70                   f1 = freqs[j];
    71                   if (f0 == f1) { // just in case
    72                           p->weight->data[0][i] = a0;
    73                   } else if (f0 == 0) { // y = ax+b
    74                           p->weight->data[0][i] = (a1-a0)/f1*freq + a0;
    75                   } else {
    76                           p->weight->data[0][i] = (a1-a0)/(f1-f0)*freq +
    77                                   (a0 - (a1 - a0)/(f1/f0 - 1.));
    78                   }
    79                   while (freq > freqs[j]) {
    80                           j +=1;
    81                   }
    82                   //AUBIO_DBG("%f\n",p->weight->data[0][i]);
    83                   p->weight->data[0][i] = DB2LIN(p->weight->data[0][i]);
    84                   //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i]));
    85           }
     60    uint_t i = 0, j = 1;
     61    smpl_t freq = 0, a0 = 0, a1 = 0, f0 = 0, f1 = 0;
     62    for (i=0; i<p->weight->length; i++) {
     63      freq = (smpl_t)i/(smpl_t)bufsize*(smpl_t)44100.;
     64      while (freq > freqs[j]) {
     65        j +=1;
     66            }
     67      a0 = weight[j-1];
     68      f0 = freqs[j-1];
     69            a1 = weight[j];
     70      f1 = freqs[j];
     71      if (f0 == f1) { // just in case
     72        p->weight->data[0][i] = a0;
     73      } else if (f0 == 0) { // y = ax+b
     74        p->weight->data[0][i] = (a1-a0)/f1*freq + a0;
     75      } else {
     76        p->weight->data[0][i] = (a1-a0)/(f1-f0)*freq +
     77          (a0 - (a1 - a0)/(f1/f0 - 1.));
     78      }
     79      while (freq > freqs[j]) {
     80        j +=1;
     81      }
     82      //AUBIO_DBG("%f\n",p->weight->data[0][i]);
     83      p->weight->data[0][i] = DB2LIN(p->weight->data[0][i]);
     84      //p->weight->data[0][i] = SQRT(DB2LIN(p->weight->data[0][i]));
     85    }
    8686  }
    8787  return p;
     
    9595  fvec_t * yin = (fvec_t *)p->yinfft;
    9696  for (l=0; l < input->length; l++){
    97           p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l];
     97    p->winput->data[0][l] = p->win->data[0][l] * input->data[0][l];
    9898  }
    99   aubio_mfft_do(p->fft,p->winput,p->fftout);
     99  aubio_fft_do(p->fft,p->winput,p->fftout);
    100100  for (l=0; l < p->fftout->length; l++){
    101           p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]);
    102           p->sqrmag->data[0][l] *= p->weight->data[0][l];
     101    p->sqrmag->data[0][l] = SQR(p->fftout->norm[0][l]);
     102    p->sqrmag->data[0][l] *= p->weight->data[0][l];
    103103  }
    104104  for (l=1; l < p->fftout->length; l++){
    105           p->sqrmag->data[0][(p->fftout->length-1)*2-l] =
    106            SQR(p->fftout->norm[0][l]);
    107           p->sqrmag->data[0][(p->fftout->length-1)*2-l] *=
    108                 p->weight->data[0][l];
     105    p->sqrmag->data[0][(p->fftout->length-1)*2-l] =
     106     SQR(p->fftout->norm[0][l]);
     107    p->sqrmag->data[0][(p->fftout->length-1)*2-l] *=
     108    p->weight->data[0][l];
    109109  }
    110110  for (l=0; l < p->sqrmag->length/2+1; l++) {
    111           sum += p->sqrmag->data[0][l];
     111    sum += p->sqrmag->data[0][l];
    112112  }
    113113  sum *= 2.;
    114   aubio_mfft_do(p->fft,p->sqrmag,res);
    115   yin->data[0][0] = 1.; 
     114  aubio_fft_do(p->fft,p->sqrmag,res);
     115  yin->data[0][0] = 1.;
    116116  for (tau=1; tau < yin->length; tau++) {
    117           yin->data[0][tau] = sum -
    118                   res->norm[0][tau]*COS(res->phas[0][tau]);
    119           tmp += yin->data[0][tau];
    120           yin->data[0][tau] *= tau/tmp;
     117    yin->data[0][tau] = sum -
     118      res->norm[0][tau]*COS(res->phas[0][tau]);
     119    tmp += yin->data[0][tau];
     120    yin->data[0][tau] *= tau/tmp;
    121121  }
    122   tau = vec_min_elem(yin); 
     122  tau = vec_min_elem(yin);
    123123  if (yin->data[0][tau] < tol) {
    124           /* no interpolation */
    125           //return tau;
    126           /* 3 point quadratic interpolation */
    127           //return vec_quadint_min(yin,tau,1);
    128           /* additional check for (unlikely) octave doubling in higher frequencies */
    129           if (tau>35) {
    130                   return vec_quadint_min(yin,tau,1);
    131           } else {
    132                   /* should compare the minimum value of each interpolated peaks */
    133                   halfperiod = FLOOR(tau/2+.5);
    134                   if (yin->data[0][halfperiod] < tol)
    135                           return vec_quadint_min(yin,halfperiod,1);
    136                   else
    137                           return vec_quadint_min(yin,tau,1);
    138           }
     124    /* no interpolation */
     125    //return tau;
     126    /* 3 point quadratic interpolation */
     127    //return vec_quadint_min(yin,tau,1);
     128    /* additional check for (unlikely) octave doubling in higher frequencies */
     129    if (tau>35) {
     130      return vec_quadint_min(yin,tau,1);
     131    } else {
     132      /* should compare the minimum value of each interpolated peaks */
     133      halfperiod = FLOOR(tau/2+.5);
     134      if (yin->data[0][halfperiod] < tol)
     135        return vec_quadint_min(yin,halfperiod,1);
     136      else
     137        return vec_quadint_min(yin,tau,1);
     138    }
    139139  } else
    140           return 0;
     140    return 0.;
    141141}
    142142
    143143void del_aubio_pitchyinfft(aubio_pitchyinfft_t *p){
    144         del_fvec(p->win);
    145         del_aubio_mfft(p->fft);
    146         del_fvec(p->yinfft);
    147         del_fvec(p->sqrmag);
    148         del_cvec(p->res);
    149         del_cvec(p->fftout);
    150         del_fvec(p->winput);
    151         del_fvec(p->weight);
    152         AUBIO_FREE(p);
     144  del_fvec(p->win);
     145  del_aubio_fft(p->fft);
     146  del_fvec(p->yinfft);
     147  del_fvec(p->sqrmag);
     148  del_cvec(p->res);
     149  del_cvec(p->fftout);
     150  del_fvec(p->winput);
     151  del_fvec(p->weight);
     152  AUBIO_FREE(p);
    153153}
  • src/sample.h

    rc1656cf r7873363  
    11/*
    2    Copyright (C) 2003 Paul Brossier
     2   Copyright (C) 2003-2007 Paul Brossier <piem@piem.org>
    33
    44   This program is free software; you can redistribute it and/or modify
     
    2121#define _SAMPLE_H
    2222
    23 #ifdef __cplusplus
    24 extern "C" {
    25 #endif
    26 
    27 /** \file
    28 
    29   Real and complex buffers
    30 
    31   This file specifies fvec_t and cvec_t buffers types, which are used
    32   throughout aubio to store real and complex data. Complex values are stored in
    33   terms of phase and norm.
    34 
    35 */
    36 
    37 /** Sample buffer type */
    38 typedef struct _fvec_t fvec_t;
    39 /** Spectrum buffer type */
    40 typedef struct _cvec_t cvec_t;
    41 /** Buffer for real values */
    42 struct _fvec_t {
    43   uint_t length;   /**< length of buffer */
    44   uint_t channels; /**< number of channels */
    45   smpl_t **data;   /**< data array of size [length] * [channels] */
    46 };
    47 /** Buffer for complex data */
    48 struct _cvec_t {
    49   uint_t length;   /**< length of buffer = (requested length)/2 + 1 */
    50   uint_t channels; /**< number of channels */
    51   smpl_t **norm;   /**< norm array of size [length] * [channels] */
    52   smpl_t **phas;   /**< phase array of size [length] * [channels] */
    53 };
    54 /** fvec_t buffer creation function
    55 
    56   \param length the length of the buffer to create
    57   \param channels the number of channels in the buffer
    58 
    59 */
    60 fvec_t * new_fvec(uint_t length, uint_t channels);
    61 /** fvec_t buffer deletion function
    62 
    63   \param s buffer to delete as returned by new_fvec()
    64 
    65 */
    66 void del_fvec(fvec_t *s);
    67 /** read sample value in a buffer
    68 
    69   Note that this function is not used in the aubio library, since the same
    70   result can be obtained using vec->data[channel][position]. Its purpose is to
    71   access these values from wrappers, as created by swig.
    72 
    73   \param s vector to read from
    74   \param channel channel to read from
    75   \param position sample position to read from
    76 
    77 */
    78 smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position);
    79 /** write sample value in a buffer
    80 
    81   Note that this function is not used in the aubio library, since the same
    82   result can be obtained by assigning vec->data[channel][position]. Its purpose
    83   is to access these values from wrappers, as created by swig.
    84 
    85   \param s vector to write to
    86   \param data value to write in s->data[channel][position]
    87   \param channel channel to write to
    88   \param position sample position to write to
    89 
    90 */
    91 void  fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position);
    92 /** read channel vector from a buffer
    93 
    94   Note that this function is not used in the aubio library, since the same
    95   result can be obtained with vec->data[channel]. Its purpose is to access
    96   these values from wrappers, as created by swig.
    97 
    98   \param s vector to read from
    99   \param channel channel to read from
    100 
    101 */
    102 smpl_t * fvec_get_channel(fvec_t *s, uint_t channel);
    103 /** write channel vector into a buffer
    104 
    105   Note that this function is not used in the aubio library, since the same
    106   result can be obtained by assigning vec->data[channel]. Its purpose is to
    107   access these values from wrappers, as created by swig.
    108 
    109   \param s vector to write to
    110   \param data vector of [length] values to write
    111   \param channel channel to write to
    112 
    113 */
    114 void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel);
    115 /** read data from a buffer
    116 
    117   Note that this function is not used in the aubio library, since the same
    118   result can be obtained with vec->data. Its purpose is to access these values
    119   from wrappers, as created by swig.
    120 
    121   \param s vector to read from
    122 
    123 */
    124 smpl_t ** fvec_get_data(fvec_t *s);
    125 
    126 /** cvec_t buffer creation function
    127 
    128   This function creates a cvec_t structure holding two arrays of size
    129   [length/2+1] * channels, corresponding to the norm and phase values of the
    130   spectral frame. The length stored in the structure is the actual size of both
    131   arrays, not the length of the complex and symetrical vector, specified as
    132   creation argument.
    133 
    134   \param length the length of the buffer to create
    135   \param channels the number of channels in the buffer
    136 
    137 */
    138 cvec_t * new_cvec(uint_t length, uint_t channels);
    139 /** cvec_t buffer deletion function
    140 
    141   \param s buffer to delete as returned by new_cvec()
    142 
    143 */
    144 void del_cvec(cvec_t *s);
    145 /** write norm value in a complex buffer
    146 
    147   Note that this function is not used in the aubio library, since the same
    148   result can be obtained by assigning vec->norm[channel][position]. Its purpose
    149   is to access these values from wrappers, as created by swig.
    150 
    151   \param s vector to write to
    152   \param data norm value to write in s->norm[channel][position]
    153   \param channel channel to write to
    154   \param position sample position to write to
    155 
    156 */
    157 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
    158 /** write phase value in a complex buffer
    159 
    160   Note that this function is not used in the aubio library, since the same
    161   result can be obtained by assigning vec->phas[channel][position]. Its purpose
    162   is to access these values from wrappers, as created by swig.
    163 
    164   \param s vector to write to
    165   \param data phase value to write in s->phas[channel][position]
    166   \param channel channel to write to
    167   \param position sample position to write to
    168 
    169 */
    170 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
    171 /** read norm value from a complex buffer
    172 
    173   Note that this function is not used in the aubio library, since the same
    174   result can be obtained with vec->norm[channel][position]. Its purpose is to
    175   access these values from wrappers, as created by swig.
    176 
    177   \param s vector to read from
    178   \param channel channel to read from
    179   \param position sample position to read from
    180 
    181 */
    182 smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position);
    183 /** read phase value from a complex buffer
    184 
    185   Note that this function is not used in the aubio library, since the same
    186   result can be obtained with vec->phas[channel][position]. Its purpose is to
    187   access these values from wrappers, as created by swig.
    188 
    189   \param s vector to read from
    190   \param channel channel to read from
    191   \param position sample position to read from
    192 
    193 */
    194 smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position);
    195 /** write norm channel in a complex buffer
    196 
    197   Note that this function is not used in the aubio library, since the same
    198   result can be obtained by assigning vec->norm[channel]. Its purpose is to
    199   access these values from wrappers, as created by swig.
    200 
    201   \param s vector to write to
    202   \param data norm vector of [length] samples to write in s->norm[channel]
    203   \param channel channel to write to
    204 
    205 */
    206 void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel);
    207 /** write phase channel in a complex buffer
    208 
    209   Note that this function is not used in the aubio library, since the same
    210   result can be obtained by assigning vec->phas[channel]. Its purpose is to
    211   access these values from wrappers, as created by swig.
    212 
    213   \param s vector to write to
    214   \param data phase vector of [length] samples to write in s->phas[channel]
    215   \param channel channel to write to
    216 
    217 */
    218 void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel);
    219 /** read norm channel from a complex buffer
    220 
    221   Note that this function is not used in the aubio library, since the same
    222   result can be obtained with vec->norm[channel]. Its purpose is to access
    223   these values from wrappers, as created by swig.
    224 
    225   \param s vector to read from
    226   \param channel channel to read from
    227 
    228 */
    229 smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel);
    230 /** write phase channel in a complex buffer
    231 
    232   Note that this function is not used in the aubio library, since the same
    233   result can be obtained with vec->phas[channel]. Its purpose is to access
    234   these values from wrappers, as created by swig.
    235 
    236   \param s vector to read from
    237   \param channel channel to read from
    238 
    239 */
    240 smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel);
    241 /** read norm data from a complex buffer
    242 
    243   Note that this function is not used in the aubio library, since the same
    244   result can be obtained with vec->norm. Its purpose is to access these values
    245   from wrappers, as created by swig.
    246 
    247   \param s vector to read from
    248 
    249 */
    250 smpl_t ** cvec_get_norm(cvec_t *s);
    251 /** read phase data from a complex buffer
    252 
    253   Note that this function is not used in the aubio library, since the same
    254   result can be obtained with vec->phas. Its purpose is to access these values
    255   from wrappers, as created by swig.
    256 
    257   \param s vector to read from
    258 
    259 */
    260 smpl_t ** cvec_get_phas(cvec_t *s);
    261 
    262 #ifdef __cplusplus
    263 }
    264 #endif
     23#include "fvec.h"
     24#include "cvec.h"
    26525
    26626#endif /* _SAMPLE_H */
  • src/scale.c

    rc1656cf r7873363  
    11/*
    2         Copyright (C) 2003 Paul Brossier
     2  Copyright (C) 2003 Paul Brossier
    33
    4         This program is free software; you can redistribute it and/or modify
    5         it under the terms of the GNU General Public License as published by
    6         the Free Software Foundation; either version 2 of the License, or
    7         (at your option) any later version.
     4  This program is free software; you can redistribute it and/or modify
     5  it under the terms of the GNU General Public License as published by
     6  the Free Software Foundation; either version 2 of the License, or
     7  (at your option) any later version.
    88
    9         This program is distributed in the hope that it will be useful,
    10         but WITHOUT ANY WARRANTY; without even the implied warranty of
    11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12         GNU General Public License for more details.
     9  This program is distributed in the hope that it will be useful,
     10  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  GNU General Public License for more details.
    1313
    14          You should have received a copy of the GNU General Public License
    15          along with this program; if not, write to the Free Software
    16          Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     14   You should have received a copy of the GNU General Public License
     15   along with this program; if not, write to the Free Software
     16   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     17
    1718*/
    1819
     
    2223
    2324struct _aubio_scale_t {
    24         smpl_t ilow;
    25         smpl_t ihig;
    26         smpl_t olow;
    27         smpl_t ohig;
     25  smpl_t ilow;
     26  smpl_t ihig;
     27  smpl_t olow;
     28  smpl_t ohig;
    2829
    29         smpl_t scaler;
    30         smpl_t irange;
    31        
    32         /* not implemented yet : type in/out data
    33         bool inint;
    34         bool outint;
    35         */
     30  smpl_t scaler;
     31  smpl_t irange;
     32
     33  /* not implemented yet : type in/out data
     34     bool inint;
     35     bool outint;
     36     */
    3637};
    3738
    38 aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig     ){
    39         aubio_scale_t * s = AUBIO_NEW(aubio_scale_t);
    40         aubio_scale_set (s, ilow, ihig, olow, ohig);
    41         return s;       
     39aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig,
     40    smpl_t olow, smpl_t ohig) {
     41  aubio_scale_t * s = AUBIO_NEW(aubio_scale_t);
     42  aubio_scale_set (s, ilow, ihig, olow, ohig);
     43  return s;
    4244}
    4345
    4446void del_aubio_scale(aubio_scale_t *s) {
    45         AUBIO_FREE(s);
     47  AUBIO_FREE(s);
    4648}
    4749
    48 void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig)
    49 {
    50         smpl_t inputrange = ihig - ilow;
    51         smpl_t outputrange= ohig - olow;
    52         s->ilow = ilow;
    53         s->ihig = ihig;
    54         s->olow = olow;
    55         s->ohig = ohig;
    56         if (inputrange == 0 )
    57                 s->scaler = 0.0f;
    58         else {
    59                 s->scaler = outputrange/inputrange;
    60                 if (inputrange < 0 )
    61                         inputrange = inputrange * -1.0f;
    62         }
     50void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig,
     51    smpl_t olow, smpl_t ohig) {
     52  smpl_t inputrange = ihig - ilow;
     53  smpl_t outputrange= ohig - olow;
     54  s->ilow = ilow;
     55  s->ihig = ihig;
     56  s->olow = olow;
     57  s->ohig = ohig;
     58  if (inputrange == 0) {
     59    s->scaler = 0.0f;
     60  } else {
     61    s->scaler = outputrange/inputrange;
     62    if (inputrange < 0) {
     63      inputrange = inputrange * -1.0f;
     64    }
     65  }
    6366}
    6467
    6568void aubio_scale_do (aubio_scale_t *s, fvec_t *input)
    6669{
    67         uint_t i, j;
    68         for (i=0; i < input->channels; i++){
    69                 for (j=0;  j < input->length; j++){
    70                         input->data[i][j] -= s->ilow;
    71                         input->data[i][j] *= s->scaler;
    72                         input->data[i][j] += s->olow;
    73                 }
    74         }
     70  uint_t i, j;
     71  for (i=0; i < input->channels; i++){
     72    for (j=0;  j < input->length; j++){
     73      input->data[i][j] -= s->ilow;
     74      input->data[i][j] *= s->scaler;
     75      input->data[i][j] += s->olow;
     76    }
     77  }
    7578}
    7679
  • src/scale.h

    rc1656cf r7873363  
    11/*
    2         Copyright (C) 2003 Paul Brossier
     2  Copyright (C) 2003 Paul Brossier
    33
    4         This program is free software; you can redistribute it and/or modify
    5         it under the terms of the GNU General Public License as published by
    6         the Free Software Foundation; either version 2 of the License, or
    7         (at your option) any later version.
     4  This program is free software; you can redistribute it and/or modify
     5  it under the terms of the GNU General Public License as published by
     6  the Free Software Foundation; either version 2 of the License, or
     7  (at your option) any later version.
    88
    9         This program is distributed in the hope that it will be useful,
    10         but WITHOUT ANY WARRANTY; without even the implied warranty of
    11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12         GNU General Public License for more details.
     9  This program is distributed in the hope that it will be useful,
     10  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  GNU General Public License for more details.
    1313
    14         You should have received a copy of the GNU General Public License
    15         along with this program; if not, write to the Free Software
    16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     14  You should have received a copy of the GNU General Public License
     15  along with this program; if not, write to the Free Software
     16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    1717*/
    1818
     
    4545
    4646*/
    47 aubio_scale_t * new_aubio_scale(smpl_t flow, smpl_t fhig, smpl_t ilow, smpl_t ihig      );
     47aubio_scale_t * new_aubio_scale(smpl_t flow, smpl_t fhig,
     48    smpl_t ilow, smpl_t ihig);
    4849/** delete a scale object
    4950
     
    6869
    6970*/
    70 void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig, smpl_t olow, smpl_t ohig);
     71void aubio_scale_set (aubio_scale_t *s, smpl_t ilow, smpl_t ihig,
     72    smpl_t olow, smpl_t ohig);
    7173
    7274#ifdef __cplusplus
  • swig/aubio.i

    rc1656cf r7873363  
    7272
    7373/* fft */
    74 extern void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size);
    75 extern void aubio_fft_getphas(smpl_t * phase, fft_data_t * spectrum, uint_t size);
    76 
    77 extern aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels);
    78 extern void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain);
    79 extern void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out);
    80 extern void del_aubio_mfft(aubio_mfft_t * fft);
    81 
     74extern aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels);
     75extern void del_aubio_fft(aubio_fft_t * s);
     76extern void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum);
     77extern void aubio_fft_rdo (aubio_fft_t *s, cvec_t * spectrum, fvec_t * output);
     78extern void aubio_fft_do_complex (aubio_fft_t *s, fvec_t * input, fvec_t * compspec);
     79extern void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output);
     80extern void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum);
     81extern void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec);
     82extern void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum);
     83extern void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec);
     84extern void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum);
     85extern void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec);
    8286
    8387/* filter */
     
    101105extern void aubio_hist_do(aubio_hist_t *s, fvec_t * input);
    102106extern void aubio_hist_do_notnull(aubio_hist_t *s, fvec_t * input);
    103 extern void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input);
     107extern void aubio_hist_dyn_notnull(aubio_hist_t *s, fvec_t *input);
     108extern void aubio_hist_weight(aubio_hist_t *s);
     109extern smpl_t aubio_hist_mean(aubio_hist_t *s);
    104110
    105111/* mathutils */
     
    161167void aubio_mfcc_do(aubio_mfcc_t *mf, cvec_t *in, fvec_t *out);
    162168
    163 
    164169/* scale */
    165170extern aubio_scale_t * new_aubio_scale(smpl_t flow, smpl_t fhig, smpl_t ilow, smpl_t ihig       );
     
    181186        aubio_onset_phase,
    182187        aubio_onset_kl,
    183         aubio_onset_mkl
     188        aubio_onset_mkl,
     189        aubio_onset_specflux,
    184190} aubio_onsetdetection_type;
    185191aubio_onsetdetection_t * new_aubio_onsetdetection(aubio_onsetdetection_type type, uint_t size, uint_t channels);
    186192void aubio_onsetdetection(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
    187 void aubio_onsetdetection_free(aubio_onsetdetection_t *o);
     193void del_aubio_onsetdetection(aubio_onsetdetection_t *o);
    188194
    189195/* should these still be exposed ? */
Note: See TracChangeset for help on using the changeset viewer.