Changeset 155cc10 for src/spectral


Ignore:
Timestamp:
Mar 10, 2017, 2:26:32 PM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler
Children:
ee8a57c
Parents:
00d0275 (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into awhitening

Location:
src/spectral
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/fft.c

    r00d0275 r155cc10  
    6565#ifdef HAVE_FFTW3F
    6666#if HAVE_AUBIO_DOUBLE
    67 #warning "Using aubio in double precision with fftw3 in single precision"
     67#error "Using aubio in double precision with fftw3 in single precision"
    6868#endif /* HAVE_AUBIO_DOUBLE */
    6969#define real_t float
    70 #else /* HAVE_FFTW3F */
     70#elif defined (HAVE_FFTW3) /* HAVE_FFTW3F */
    7171#if !HAVE_AUBIO_DOUBLE
    72 #warning "Using aubio in single precision with fftw3 in double precision"
     72#error "Using aubio in single precision with fftw3 in double precision"
    7373#endif /* HAVE_AUBIO_DOUBLE */
    7474#define real_t double
     
    115115#else                         // using OOURA
    116116// let's use ooura instead
    117 extern void rdft(int, int, smpl_t *, int *, smpl_t *);
     117extern void aubio_ooura_rdft(int, int, smpl_t *, int *, smpl_t *);
    118118
    119119#endif /* HAVE_ACCELERATE */
     
    144144aubio_fft_t * new_aubio_fft (uint_t winsize) {
    145145  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
    146   if ((sint_t)winsize < 1) {
    147     AUBIO_ERR("fft: got winsize %d, but can not be < 1\n", winsize);
     146  if ((sint_t)winsize < 2) {
     147    AUBIO_ERR("fft: got winsize %d, but can not be < 2\n", winsize);
    148148    goto beach;
    149149  }
     
    189189#else                         // using OOURA
    190190  if (aubio_is_power_of_two(winsize) != 1) {
    191     AUBIO_ERR("fft: can only create with sizes power of two,"
    192               " requested %d\n", winsize);
     191    AUBIO_ERR("fft: can only create with sizes power of two, requested %d,"
     192        " try recompiling aubio with --enable-fftw3\n", winsize);
    193193    goto beach;
    194194  }
     
    213213  del_fvec(s->compspec);
    214214#ifdef HAVE_FFTW3             // using FFTW3
     215  pthread_mutex_lock(&aubio_fftw_mutex);
    215216  fftw_destroy_plan(s->pfw);
    216217  fftw_destroy_plan(s->pbw);
    217218  fftw_free(s->specdata);
     219  pthread_mutex_unlock(&aubio_fftw_mutex);
    218220#else /* HAVE_FFTW3 */
    219221#ifdef HAVE_ACCELERATE        // using ACCELERATE
     
    231233}
    232234
    233 void aubio_fft_do(aubio_fft_t * s, fvec_t * input, cvec_t * spectrum) {
     235void aubio_fft_do(aubio_fft_t * s, const fvec_t * input, cvec_t * spectrum) {
    234236  aubio_fft_do_complex(s, input, s->compspec);
    235237  aubio_fft_get_spectrum(s->compspec, spectrum);
    236238}
    237239
    238 void aubio_fft_rdo(aubio_fft_t * s, cvec_t * spectrum, fvec_t * output) {
     240void aubio_fft_rdo(aubio_fft_t * s, const cvec_t * spectrum, fvec_t * output) {
    239241  aubio_fft_get_realimag(spectrum, s->compspec);
    240242  aubio_fft_rdo_complex(s, s->compspec, output);
    241243}
    242244
    243 void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) {
     245void aubio_fft_do_complex(aubio_fft_t * s, const fvec_t * input, fvec_t * compspec) {
    244246  uint_t i;
    245247#ifndef HAVE_MEMCPY_HACKS
     
    281283  aubio_vDSP_vsmul(compspec->data, 1, &scale, compspec->data, 1, s->fft_size);
    282284#else                         // using OOURA
    283   rdft(s->winsize, 1, s->in, s->ip, s->w);
     285  aubio_ooura_rdft(s->winsize, 1, s->in, s->ip, s->w);
    284286  compspec->data[0] = s->in[0];
    285287  compspec->data[s->winsize / 2] = s->in[1];
     
    292294}
    293295
    294 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) {
     296void aubio_fft_rdo_complex(aubio_fft_t * s, const fvec_t * compspec, fvec_t * output) {
    295297  uint_t i;
    296298#ifdef HAVE_FFTW3
     
    339341    s->out[2 * i + 1] = - compspec->data[s->winsize - i];
    340342  }
    341   rdft(s->winsize, -1, s->out, s->ip, s->w);
     343  aubio_ooura_rdft(s->winsize, -1, s->out, s->ip, s->w);
    342344  for (i=0; i < s->winsize; i++) {
    343345    output->data[i] = s->out[i] * scale;
     
    347349}
    348350
    349 void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum) {
     351void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum) {
    350352  aubio_fft_get_phas(compspec, spectrum);
    351353  aubio_fft_get_norm(compspec, spectrum);
    352354}
    353355
    354 void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec) {
     356void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec) {
    355357  aubio_fft_get_imag(spectrum, compspec);
    356358  aubio_fft_get_real(spectrum, compspec);
    357359}
    358360
    359 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
     361void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum) {
    360362  uint_t i;
    361363  if (compspec->data[0] < 0) {
     
    375377}
    376378
    377 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) {
     379void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum) {
    378380  uint_t i = 0;
    379381  spectrum->norm[0] = ABS(compspec->data[0]);
     
    386388}
    387389
    388 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) {
     390void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec) {
    389391  uint_t i;
    390392  for (i = 1; i < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; i++) {
     
    394396}
    395397
    396 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) {
     398void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec) {
    397399  uint_t i;
    398400  for (i = 0; i < compspec->length / 2 + 1; i++) {
  • src/spectral/fft.h

    r00d0275 r155cc10  
    2828    - [vDSP](https://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html)
    2929
    30   \example src/spectral/test-fft.c
     30  \example spectral/test-fft.c
    3131
    3232*/
    3333
    34 #ifndef _AUBIO_FFT_H
    35 #define _AUBIO_FFT_H
     34#ifndef AUBIO_FFT_H
     35#define AUBIO_FFT_H
    3636
    3737#ifdef __cplusplus
     
    6666
    6767*/
    68 void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum);
     68void aubio_fft_do (aubio_fft_t *s, const fvec_t * input, cvec_t * spectrum);
    6969/** compute backward (inverse) FFT
    7070
     
    7474
    7575*/
    76 void aubio_fft_rdo (aubio_fft_t *s, cvec_t * spectrum, fvec_t * output);
     76void aubio_fft_rdo (aubio_fft_t *s, const cvec_t * spectrum, fvec_t * output);
    7777
    7878/** compute forward FFT
     
    8383
    8484*/
    85 void aubio_fft_do_complex (aubio_fft_t *s, fvec_t * input, fvec_t * compspec);
     85void aubio_fft_do_complex (aubio_fft_t *s, const fvec_t * input, fvec_t * compspec);
    8686/** compute backward (inverse) FFT from real/imag
    8787
     
    9191
    9292*/
    93 void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output);
     93void aubio_fft_rdo_complex (aubio_fft_t *s, const fvec_t * compspec, fvec_t * output);
    9494
    9595/** convert real/imag spectrum to norm/phas spectrum
     
    9999
    100100*/
    101 void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum);
     101void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum);
    102102/** convert real/imag spectrum to norm/phas spectrum
    103103
     
    106106
    107107*/
    108 void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec);
     108void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec);
    109109
    110110/** compute phas spectrum from real/imag parts
     
    114114
    115115*/
    116 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum);
     116void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum);
    117117/** compute imaginary part from the norm/phas cvec
    118118
     
    121121
    122122*/
    123 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec);
     123void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec);
    124124
    125125/** compute norm component from real/imag parts
     
    129129
    130130*/
    131 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum);
     131void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum);
    132132/** compute real part from norm/phas components
    133133
     
    136136
    137137*/
    138 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec);
     138void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec);
    139139
    140140#ifdef __cplusplus
     
    142142#endif
    143143
    144 #endif /* _AUBIO_FFT_H */
     144#endif /* AUBIO_FFT_H */
  • src/spectral/filterbank.c

    r00d0275 r155cc10  
    5757
    5858void
    59 aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out)
     59aubio_filterbank_do (aubio_filterbank_t * f, const cvec_t * in, fvec_t * out)
    6060{
    61   uint_t j, fn;
     61  /* apply filter to all input channel, provided out has enough channels */
     62  //uint_t max_filters = MIN (f->n_filters, out->length);
     63  //uint_t max_length = MIN (in->length, f->filters->length);
    6264
    63   /* apply filter to all input channel, provided out has enough channels */
    64   uint_t max_filters = MIN (f->n_filters, out->length);
    65   uint_t max_length = MIN (in->length, f->filters->length);
     65  // view cvec->norm as fvec->data
     66  fvec_t tmp;
     67  tmp.length = in->length;
     68  tmp.data = in->norm;
    6669
    67   /* reset all values in output vector */
    68   fvec_zeros (out);
    69 
    70   /* for each filter */
    71   for (fn = 0; fn < max_filters; fn++) {
    72     /* for each sample */
    73     for (j = 0; j < max_length; j++) {
    74       out->data[fn] += in->norm[j] * f->filters->data[fn][j];
    75     }
    76   }
     70  fmat_vecmul(f->filters, &tmp, out);
    7771
    7872  return;
     
    8074
    8175fmat_t *
    82 aubio_filterbank_get_coeffs (aubio_filterbank_t * f)
     76aubio_filterbank_get_coeffs (const aubio_filterbank_t * f)
    8377{
    8478  return f->filters;
     
    8680
    8781uint_t
    88 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filter_coeffs)
     82aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filter_coeffs)
    8983{
    9084  fmat_copy(filter_coeffs, f->filters);
  • src/spectral/filterbank.h

    r00d0275 r155cc10  
    3030*/
    3131
    32 #ifndef _AUBIO_FILTERBANK_H
    33 #define _AUBIO_FILTERBANK_H
     32#ifndef AUBIO_FILTERBANK_H
     33#define AUBIO_FILTERBANK_H
    3434
    3535#ifdef __cplusplus
     
    6767
    6868*/
    69 void aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out);
     69void aubio_filterbank_do (aubio_filterbank_t * f, const cvec_t * in, fvec_t * out);
    7070
    7171/** return a pointer to the matrix object containing all filter coefficients
     
    7474
    7575 */
    76 fmat_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f);
     76fmat_t *aubio_filterbank_get_coeffs (const aubio_filterbank_t * f);
    7777
    7878/** copy filter coefficients to the filterbank
     
    8282
    8383 */
    84 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filters);
     84uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filters);
    8585
    8686#ifdef __cplusplus
     
    8888#endif
    8989
    90 #endif /* _AUBIO_FILTERBANK_H */
     90#endif /* AUBIO_FILTERBANK_H */
  • src/spectral/filterbank_mel.c

    r00d0275 r155cc10  
    3030uint_t
    3131aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
    32     fvec_t * freqs, smpl_t samplerate)
     32    const fvec_t * freqs, smpl_t samplerate)
    3333{
    3434
  • src/spectral/filterbank_mel.h

    r00d0275 r155cc10  
    3232*/
    3333
    34 #ifndef _AUBIO_FILTERBANK_MEL_H
    35 #define _AUBIO_FILTERBANK_MEL_H
     34#ifndef AUBIO_FILTERBANK_MEL_H
     35#define AUBIO_FILTERBANK_MEL_H
    3636
    3737#ifdef __cplusplus
     
    5151*/
    5252uint_t aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
    53     fvec_t * freqs, smpl_t samplerate);
     53    const fvec_t * freqs, smpl_t samplerate);
    5454
    5555/** filterbank initialization for Mel filters using Slaney's coefficients
     
    7070#endif
    7171
    72 #endif /* _AUBIO_FILTERBANK_MEL_H */
     72#endif /* AUBIO_FILTERBANK_MEL_H */
  • src/spectral/mfcc.c

    r00d0275 r155cc10  
    6868  mfcc->in_dct = new_fvec (n_filters);
    6969
    70   mfcc->dct_coeffs = new_fmat (n_filters, n_coefs);
     70  mfcc->dct_coeffs = new_fmat (n_coefs, n_filters);
    7171
    72   /* compute DCT transform dct_coeffs[i][j] as
     72  /* compute DCT transform dct_coeffs[j][i] as
    7373     cos ( j * (i+.5) * PI / n_filters ) */
    7474  scaling = 1. / SQRT (n_filters / 2.);
    7575  for (i = 0; i < n_filters; i++) {
    7676    for (j = 0; j < n_coefs; j++) {
    77       mfcc->dct_coeffs->data[i][j] =
     77      mfcc->dct_coeffs->data[j][i] =
    7878          scaling * COS (j * (i + 0.5) * PI / n_filters);
    7979    }
    80     mfcc->dct_coeffs->data[i][0] *= SQRT (2.) / 2.;
     80    mfcc->dct_coeffs->data[0][i] *= SQRT (2.) / 2.;
    8181  }
    8282
    8383  return mfcc;
    84 };
     84}
    8585
    8686void
     
    101101
    102102void
    103 aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out)
     103aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out)
    104104{
    105   uint_t j, k;
    106 
    107105  /* compute filterbank */
    108106  aubio_filterbank_do (mf->fb, in, mf->in_dct);
     
    114112  //fvec_pow (mf->in_dct, 3.);
    115113
    116   /* zeros output */
    117   fvec_zeros(out);
    118 
    119   /* compute discrete cosine transform */
    120   for (j = 0; j < mf->n_filters; j++) {
    121     for (k = 0; k < mf->n_coefs; k++) {
    122       out->data[k] += mf->in_dct->data[j]
    123           * mf->dct_coeffs->data[j][k];
    124     }
    125   }
     114  /* compute mfccs */
     115  fmat_vecmul(mf->dct_coeffs, mf->in_dct, out);
    126116
    127117  return;
  • src/spectral/mfcc.h

    r00d0275 r155cc10  
    3535*/
    3636
    37 #ifndef _AUBIO_MFCC_H
    38 #define _AUBIO_MFCC_H
     37#ifndef AUBIO_MFCC_H
     38#define AUBIO_MFCC_H
    3939
    4040#ifdef __cplusplus
     
    7171
    7272*/
    73 void aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out);
     73void aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out);
    7474
    7575#ifdef __cplusplus
     
    7777#endif
    7878
    79 #endif /* _AUBIO_MFCC_H */
     79#endif /* AUBIO_MFCC_H */
  • src/spectral/ooura_fft8g.c

    r00d0275 r155cc10  
    33//  - include "aubio_priv.h" (for config.h and types.h)
    44//  - add missing prototypes
    5 //  - use COS and SIN macros
     5//  - use COS, SIN, and ATAN macros
     6//  - add cast to (smpl_t) to avoid float conversion warnings
     7//  - declare initialization as static
     8//  - prefix public function with aubio_ooura_
    69
    710#include "aubio_priv.h"
    811
    9 void cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
    10 void rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
    11 void ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
    12 void ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
    13 void dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);
    14 void dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);
    15 void makewt(int nw, int *ip, smpl_t *w);
    16 void makect(int nc, int *ip, smpl_t *c);
    17 void bitrv2(int n, int *ip, smpl_t *a);
    18 void bitrv2conj(int n, int *ip, smpl_t *a);
    19 void cftfsub(int n, smpl_t *a, smpl_t *w);
    20 void cftbsub(int n, smpl_t *a, smpl_t *w);
    21 void cft1st(int n, smpl_t *a, smpl_t *w);
    22 void cftmdl(int n, int l, smpl_t *a, smpl_t *w);
    23 void rftfsub(int n, smpl_t *a, int nc, smpl_t *c);
    24 void rftbsub(int n, smpl_t *a, int nc, smpl_t *c);
    25 void dctsub(int n, smpl_t *a, int nc, smpl_t *c);
    26 void dstsub(int n, smpl_t *a, int nc, smpl_t *c);
     12void aubio_ooura_cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
     13void aubio_ooura_rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
     14void aubio_ooura_ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
     15void aubio_ooura_ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
     16void aubio_ooura_dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);
     17void aubio_ooura_dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);
     18static void makewt(int nw, int *ip, smpl_t *w);
     19static void makect(int nc, int *ip, smpl_t *c);
     20static void bitrv2(int n, int *ip, smpl_t *a);
     21static void bitrv2conj(int n, int *ip, smpl_t *a);
     22static void cftfsub(int n, smpl_t *a, smpl_t *w);
     23static void cftbsub(int n, smpl_t *a, smpl_t *w);
     24static void cft1st(int n, smpl_t *a, smpl_t *w);
     25static void cftmdl(int n, int l, smpl_t *a, smpl_t *w);
     26static void rftfsub(int n, smpl_t *a, int nc, smpl_t *c);
     27static void rftbsub(int n, smpl_t *a, int nc, smpl_t *c);
     28static void dctsub(int n, smpl_t *a, int nc, smpl_t *c);
     29static void dstsub(int n, smpl_t *a, int nc, smpl_t *c);
    2730
    2831/*
     
    303306
    304307
    305 void cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
     308void aubio_ooura_cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
    306309{
    307310    void makewt(int nw, int *ip, smpl_t *w);
     
    328331
    329332
    330 void rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
     333void aubio_ooura_rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
    331334{
    332335    void makewt(int nw, int *ip, smpl_t *w);
     
    362365        a[1] = xi;
    363366    } else {
    364         a[1] = 0.5 * (a[0] - a[1]);
     367        a[1] = (smpl_t)0.5 * (a[0] - a[1]);
    365368        a[0] -= a[1];
    366369        if (n > 4) {
     
    375378
    376379
    377 void ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
     380void aubio_ooura_ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
    378381{
    379382    void makewt(int nw, int *ip, smpl_t *w);
     
    434437
    435438
    436 void ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
     439void aubio_ooura_ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
    437440{
    438441    void makewt(int nw, int *ip, smpl_t *w);
     
    493496
    494497
    495 void dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)
     498void aubio_ooura_dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)
    496499{
    497500    void makewt(int nw, int *ip, smpl_t *w);
     
    589592
    590593
    591 void dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)
     594void aubio_ooura_dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)
    592595{
    593596    void makewt(int nw, int *ip, smpl_t *w);
     
    691694    if (nw > 2) {
    692695        nwh = nw >> 1;
    693         delta = atan(1.0) / nwh;
     696        delta = ATAN(1.0) / nwh;
    694697        w[0] = 1;
    695698        w[1] = 0;
     
    725728    if (nc > 1) {
    726729        nch = nc >> 1;
    727         delta = atan(1.0) / nch;
    728         c[0] = cos(delta * nch);
    729         c[nch] = 0.5 * c[0];
     730        delta = ATAN(1.0) / nch;
     731        c[0] = COS(delta * nch);
     732        c[nch] = (smpl_t)0.5 * c[0];
    730733        for (j = 1; j < nch; j++) {
    731             c[j] = 0.5 * cos(delta * j);
    732             c[nc - j] = 0.5 * sin(delta * j);
     734            c[j] = (smpl_t)0.5 * COS(delta * j);
     735            c[nc - j] = (smpl_t)0.5 * SIN(delta * j);
    733736        }
    734737    }
     
    15861589        k = n - j;
    15871590        kk += ks;
    1588         wkr = 0.5 - c[nc - kk];
     1591        wkr = (smpl_t)0.5 - c[nc - kk];
    15891592        wki = c[kk];
    15901593        xr = a[j] - a[k];
     
    16121615        k = n - j;
    16131616        kk += ks;
    1614         wkr = 0.5 - c[nc - kk];
     1617        wkr = (smpl_t)0.5 - c[nc - kk];
    16151618        wki = c[kk];
    16161619        xr = a[j] - a[k];
  • src/spectral/phasevoc.c

    r00d0275 r155cc10  
    4545
    4646/** returns data and dataold slided by hop_s */
    47 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new);
     47static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, const fvec_t *new);
    4848
    4949/** do additive synthesis from 'old' and 'cur' */
    5050static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t * synthnew);
    5151
    52 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {
     52void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t * datanew, cvec_t *fftgrain) {
    5353  /* slide  */
    5454  aubio_pvoc_swapbuffers(pv, datanew);
     
    6565  aubio_fft_rdo(pv->fft,fftgrain,pv->synth);
    6666  /* unshift */
    67   fvec_shift(pv->synth);
     67  fvec_ishift(pv->synth);
     68  /* windowing */
     69  // if overlap = 50%, do not apply window (identity)
     70  if (pv->hop_s * 2 < pv->win_s) {
     71    fvec_weight(pv->synth, pv->w);
     72  }
    6873  /* additive synthesis */
    6974  aubio_pvoc_addsynth(pv, synthnew);
     
    8085    AUBIO_ERR("pvoc: got hop_size %d, but can not be < 1\n", hop_s);
    8186    goto beach;
    82   } else if ((sint_t)win_s < 1) {
    83     AUBIO_ERR("pvoc: got buffer_size %d, but can not be < 1\n", win_s);
     87  } else if ((sint_t)win_s < 2) {
     88    AUBIO_ERR("pvoc: got buffer_size %d, but can not be < 2\n", win_s);
    8489    goto beach;
    8590  } else if (win_s < hop_s) {
    86     AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", win_s, hop_s);
     91    AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", hop_s, win_s);
    8792    goto beach;
    8893  }
    8994
    9095  pv->fft      = new_aubio_fft (win_s);
     96  if (pv->fft == NULL) {
     97    goto beach;
     98  }
    9199
    92100  /* remember old */
     
    118126  pv->hop_datasize = pv->hop_s * sizeof(smpl_t);
    119127
    120   pv->scale = pv->hop_s * 2. / pv->win_s;
     128  // for reconstruction with 75% overlap
     129  if (win_s == hop_s * 4) {
     130    pv->scale = 2./3.;
     131  } else if (win_s == hop_s * 8) {
     132    pv->scale = 1./3.;
     133  } else if (win_s == hop_s * 2) {
     134    pv->scale = 1.;
     135  } else {
     136    pv->scale = .5;
     137  }
    121138
    122139  return pv;
     
    137154}
    138155
    139 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new)
     156static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, const fvec_t *new)
    140157{
    141158  /* some convenience pointers */
     
    143160  smpl_t * dataold = pv->dataold->data;
    144161  smpl_t * datanew = new->data;
    145 #if !HAVE_MEMCPY_HACKS
     162#ifndef HAVE_MEMCPY_HACKS
    146163  uint_t i;
    147164  for (i = 0; i < pv->end; i++)
  • src/spectral/phasevoc.h

    r00d0275 r155cc10  
    3232*/
    3333
    34 #ifndef _AUBIO_PHASEVOC_H
    35 #define _AUBIO_PHASEVOC_H
     34#ifndef AUBIO_PHASEVOC_H
     35#define AUBIO_PHASEVOC_H
    3636
    3737#ifdef __cplusplus
     
    6868
    6969*/
    70 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t *in, cvec_t * fftgrain);
     70void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t *in, cvec_t * fftgrain);
    7171/** compute signal from spectral frame
    7272
     
    100100#endif
    101101
    102 #endif /* _AUBIO_PHASEVOC_H */
     102#endif /* AUBIO_PHASEVOC_H */
  • src/spectral/specdesc.c

    r00d0275 r155cc10  
    2727#include "utils/hist.h"
    2828
    29 void aubio_specdesc_energy(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    30 void aubio_specdesc_hfc(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    31 void aubio_specdesc_complex(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    32 void aubio_specdesc_phase(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    33 void aubio_specdesc_specdiff(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    34 void aubio_specdesc_kl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    35 void aubio_specdesc_mkl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    36 void aubio_specdesc_specflux(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    37 
    38 extern void aubio_specdesc_centroid (aubio_specdesc_t * o, cvec_t * spec,
    39     fvec_t * desc);
    40 extern void aubio_specdesc_spread (aubio_specdesc_t * o, cvec_t * spec,
    41     fvec_t * desc);
    42 extern void aubio_specdesc_skewness (aubio_specdesc_t * o, cvec_t * spec,
    43     fvec_t * desc);
    44 extern void aubio_specdesc_kurtosis (aubio_specdesc_t * o, cvec_t * spec,
    45     fvec_t * desc);
    46 extern void aubio_specdesc_slope (aubio_specdesc_t * o, cvec_t * spec,
    47     fvec_t * desc);
    48 extern void aubio_specdesc_decrease (aubio_specdesc_t * o, cvec_t * spec,
    49     fvec_t * desc);
    50 extern void aubio_specdesc_rolloff (aubio_specdesc_t * o, cvec_t * spec,
     29void aubio_specdesc_energy(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     30void aubio_specdesc_hfc(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     31void aubio_specdesc_complex(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     32void aubio_specdesc_phase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     33void aubio_specdesc_specdiff(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     34void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     35void aubio_specdesc_mkl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     36void aubio_specdesc_specflux(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     37
     38extern void aubio_specdesc_centroid (aubio_specdesc_t * o, const cvec_t * spec,
     39    fvec_t * desc);
     40extern void aubio_specdesc_spread (aubio_specdesc_t * o, const cvec_t * spec,
     41    fvec_t * desc);
     42extern void aubio_specdesc_skewness (aubio_specdesc_t * o, const cvec_t * spec,
     43    fvec_t * desc);
     44extern void aubio_specdesc_kurtosis (aubio_specdesc_t * o, const cvec_t * spec,
     45    fvec_t * desc);
     46extern void aubio_specdesc_slope (aubio_specdesc_t * o, const cvec_t * spec,
     47    fvec_t * desc);
     48extern void aubio_specdesc_decrease (aubio_specdesc_t * o, const cvec_t * spec,
     49    fvec_t * desc);
     50extern void aubio_specdesc_rolloff (aubio_specdesc_t * o, const cvec_t * spec,
    5151    fvec_t * desc);
    5252
     
    7676  /** Pointer to aubio_specdesc_<type> function */
    7777  void (*funcpointer)(aubio_specdesc_t *o,
    78       cvec_t * fftgrain, fvec_t * onset);
     78      const cvec_t * fftgrain, fvec_t * onset);
    7979  smpl_t threshold;      /**< minimum norm threshold for phase and specdiff */
    8080  fvec_t *oldmag;        /**< previous norm vector */
     
    8888/* Energy based onset detection function */
    8989void aubio_specdesc_energy  (aubio_specdesc_t *o UNUSED,
    90     cvec_t * fftgrain, fvec_t * onset) {
     90    const cvec_t * fftgrain, fvec_t * onset) {
    9191  uint_t j;
    9292  onset->data[0] = 0.;
     
    9898/* High Frequency Content onset detection function */
    9999void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED,
    100     cvec_t * fftgrain, fvec_t * onset){
     100    const cvec_t * fftgrain, fvec_t * onset){
    101101  uint_t j;
    102102  onset->data[0] = 0.;
     
    108108
    109109/* Complex Domain Method onset detection function */
    110 void aubio_specdesc_complex (aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset) {
     110void aubio_specdesc_complex (aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset) {
    111111  uint_t j;
    112112  uint_t nbins = fftgrain->length;
     
    132132/* Phase Based Method onset detection function */
    133133void aubio_specdesc_phase(aubio_specdesc_t *o,
    134     cvec_t * fftgrain, fvec_t * onset){
     134    const cvec_t * fftgrain, fvec_t * onset){
    135135  uint_t j;
    136136  uint_t nbins = fftgrain->length;
     
    162162/* Spectral difference method onset detection function */
    163163void aubio_specdesc_specdiff(aubio_specdesc_t *o,
    164     cvec_t * fftgrain, fvec_t * onset){
     164    const cvec_t * fftgrain, fvec_t * onset){
    165165  uint_t j;
    166166  uint_t nbins = fftgrain->length;
     
    189189 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid
    190190 * negative (1.+) and infinite values (+1.e-10) */
    191 void aubio_specdesc_kl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
     191void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){
    192192  uint_t j;
    193193    onset->data[0] = 0.;
     
    203203 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid
    204204 * negative (1.+) and infinite values (+1.e-10) */
    205 void aubio_specdesc_mkl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
     205void aubio_specdesc_mkl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){
    206206  uint_t j;
    207207    onset->data[0] = 0.;
     
    214214
    215215/* Spectral flux */
    216 void aubio_specdesc_specflux(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
     216void aubio_specdesc_specflux(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){
    217217  uint_t j;
    218218  onset->data[0] = 0.;
     
    226226/* Generic function pointing to the choosen one */
    227227void
    228 aubio_specdesc_do (aubio_specdesc_t *o, cvec_t * fftgrain,
     228aubio_specdesc_do (aubio_specdesc_t *o, const cvec_t * fftgrain,
    229229    fvec_t * onset) {
    230230  o->funcpointer(o,fftgrain,onset);
     
    235235 */
    236236aubio_specdesc_t *
    237 new_aubio_specdesc (char_t * onset_mode, uint_t size){
     237new_aubio_specdesc (const char_t * onset_mode, uint_t size){
    238238  aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t);
    239239  uint_t rsize = size/2+1;
     
    274274      onset_type = aubio_onset_default;
    275275  else {
    276       AUBIO_ERR("unknown spectral descriptor type %s, using default.\n", onset_mode);
    277       onset_type = aubio_onset_default;
     276      AUBIO_ERR("unknown spectral descriptor type %s\n", onset_mode);
     277      AUBIO_FREE(o);
     278      return NULL;
    278279  }
    279280  switch(onset_type) {
    280281    /* for both energy and hfc, only fftgrain->norm is required */
    281     case aubio_onset_energy: 
     282    case aubio_onset_energy:
    282283      break;
    283284    case aubio_onset_hfc:
     
    367368void del_aubio_specdesc (aubio_specdesc_t *o){
    368369  switch(o->onset_type) {
    369     case aubio_onset_energy: 
     370    case aubio_onset_energy:
    370371      break;
    371372    case aubio_onset_hfc:
  • src/spectral/specdesc.h

    r00d0275 r155cc10  
    146146
    147147
    148 #ifndef _AUBIO_SPECDESC_H
    149 #define _AUBIO_SPECDESC_H
     148#ifndef AUBIO_SPECDESC_H
     149#define AUBIO_SPECDESC_H
    150150
    151151#ifdef __cplusplus
     
    165165
    166166*/
    167 void aubio_specdesc_do (aubio_specdesc_t * o, cvec_t * fftgrain,
     167void aubio_specdesc_do (aubio_specdesc_t * o, const cvec_t * fftgrain,
    168168    fvec_t * desc);
    169169
     
    179179
    180180*/
    181 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size);
     181aubio_specdesc_t *new_aubio_specdesc (const char_t * method, uint_t buf_size);
    182182
    183183/** deletion of a spectral descriptor
     
    192192#endif
    193193
    194 #endif /* _AUBIO_SPECDESC_H */
     194#endif /* AUBIO_SPECDESC_H */
  • src/spectral/statistics.c

    r00d0275 r155cc10  
    2323#include "spectral/specdesc.h"
    2424
    25 void aubio_specdesc_centroid (aubio_specdesc_t * o, cvec_t * spec,
    26     fvec_t * desc);
    27 void aubio_specdesc_spread (aubio_specdesc_t * o, cvec_t * spec,
    28     fvec_t * desc);
    29 void aubio_specdesc_skewness (aubio_specdesc_t * o, cvec_t * spec,
    30     fvec_t * desc);
    31 void aubio_specdesc_kurtosis (aubio_specdesc_t * o, cvec_t * spec,
    32     fvec_t * desc);
    33 void aubio_specdesc_slope (aubio_specdesc_t * o, cvec_t * spec,
    34     fvec_t * desc);
    35 void aubio_specdesc_decrease (aubio_specdesc_t * o, cvec_t * spec,
    36     fvec_t * desc);
    37 void aubio_specdesc_rolloff (aubio_specdesc_t * o, cvec_t * spec,
    38     fvec_t * desc);
    39 
    40 
    41 smpl_t cvec_sum (cvec_t * s);
    42 smpl_t cvec_mean (cvec_t * s);
    43 smpl_t cvec_centroid (cvec_t * s);
    44 smpl_t cvec_moment (cvec_t * s, uint_t moment);
    45 
    46 smpl_t
    47 cvec_sum (cvec_t * s)
     25void aubio_specdesc_centroid (aubio_specdesc_t * o, const cvec_t * spec,
     26    fvec_t * desc);
     27void aubio_specdesc_spread (aubio_specdesc_t * o, const cvec_t * spec,
     28    fvec_t * desc);
     29void aubio_specdesc_skewness (aubio_specdesc_t * o, const cvec_t * spec,
     30    fvec_t * desc);
     31void aubio_specdesc_kurtosis (aubio_specdesc_t * o, const cvec_t * spec,
     32    fvec_t * desc);
     33void aubio_specdesc_slope (aubio_specdesc_t * o, const cvec_t * spec,
     34    fvec_t * desc);
     35void aubio_specdesc_decrease (aubio_specdesc_t * o, const cvec_t * spec,
     36    fvec_t * desc);
     37void aubio_specdesc_rolloff (aubio_specdesc_t * o, const cvec_t * spec,
     38    fvec_t * desc);
     39
     40
     41smpl_t cvec_sum (const cvec_t * s);
     42smpl_t cvec_mean (const cvec_t * s);
     43smpl_t cvec_centroid (const cvec_t * s);
     44smpl_t cvec_moment (const cvec_t * s, uint_t moment);
     45
     46smpl_t
     47cvec_sum (const cvec_t * s)
    4848{
    4949  uint_t j;
     
    5656
    5757smpl_t
    58 cvec_mean (cvec_t * s)
     58cvec_mean (const cvec_t * s)
    5959{
    6060  return cvec_sum (s) / (smpl_t) (s->length);
     
    6262
    6363smpl_t
    64 cvec_centroid (cvec_t * spec)
     64cvec_centroid (const cvec_t * spec)
    6565{
    6666  smpl_t sum = 0., sc = 0.;
     
    7878
    7979smpl_t
    80 cvec_moment (cvec_t * spec, uint_t order)
     80cvec_moment (const cvec_t * spec, uint_t order)
    8181{
    8282  smpl_t sum = 0., centroid = 0., sc = 0.;
     
    9595
    9696void
    97 aubio_specdesc_centroid (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     97aubio_specdesc_centroid (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    9898    fvec_t * desc)
    9999{
     
    102102
    103103void
    104 aubio_specdesc_spread (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     104aubio_specdesc_spread (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    105105    fvec_t * desc)
    106106{
     
    109109
    110110void
    111 aubio_specdesc_skewness (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     111aubio_specdesc_skewness (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    112112    fvec_t * desc)
    113113{
     
    123123
    124124void
    125 aubio_specdesc_kurtosis (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     125aubio_specdesc_kurtosis (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    126126    fvec_t * desc)
    127127{
     
    137137
    138138void
    139 aubio_specdesc_slope (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     139aubio_specdesc_slope (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    140140    fvec_t * desc)
    141141{
     
    165165
    166166void
    167 aubio_specdesc_decrease (aubio_specdesc_t *o UNUSED, cvec_t * spec,
     167aubio_specdesc_decrease (aubio_specdesc_t *o UNUSED, const cvec_t * spec,
    168168    fvec_t * desc)
    169169{
     
    183183
    184184void
    185 aubio_specdesc_rolloff (aubio_specdesc_t *o UNUSED, cvec_t * spec,
     185aubio_specdesc_rolloff (aubio_specdesc_t *o UNUSED, const cvec_t * spec,
    186186    fvec_t *desc)
    187187{
  • src/spectral/tss.c

    r00d0275 r155cc10  
    4141};
    4242
    43 void aubio_tss_do(aubio_tss_t *o, cvec_t * input,
     43void aubio_tss_do(aubio_tss_t *o, const cvec_t * input,
    4444    cvec_t * trans, cvec_t * stead)
    4545{
  • src/spectral/tss.h

    r00d0275 r155cc10  
    3737*/
    3838
    39 #ifndef _AUBIO_TSS_H
    40 #define _AUBIO_TSS_H
     39#ifndef AUBIO_TSS_H
     40#define AUBIO_TSS_H
    4141
    4242#ifdef __cplusplus
     
    7070
    7171*/
    72 void aubio_tss_do (aubio_tss_t * o, cvec_t * input, cvec_t * trans,
     72void aubio_tss_do (aubio_tss_t * o, const cvec_t * input, cvec_t * trans,
    7373    cvec_t * stead);
    7474
     
    101101#endif
    102102
    103 #endif /* _AUBIO_TSS_H */
     103#endif /* AUBIO_TSS_H */
Note: See TracChangeset for help on using the changeset viewer.