Changeset d95ff38


Ignore:
Timestamp:
Dec 4, 2009, 1:38:30 AM (10 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
741bdda
Parents:
0b9a02a
Message:

src/spectral: switch to mono

Location:
src/spectral
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/fft.c

    r0b9a02a rd95ff38  
    7575struct _aubio_fft_t {
    7676  uint_t winsize;
    77   uint_t channels;
    7877  uint_t fft_size;
    7978  real_t *in, *out;
     
    8382};
    8483
    85 aubio_fft_t * new_aubio_fft(uint_t winsize, uint_t channels) {
     84aubio_fft_t * new_aubio_fft(uint_t winsize) {
    8685  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
    8786  uint_t i;
    8887  s->winsize  = winsize;
    89   s->channels = channels;
    9088  /* allocate memory */
    9189  s->in       = AUBIO_ARRAY(real_t,winsize);
    9290  s->out      = AUBIO_ARRAY(real_t,winsize);
    93   s->compspec = new_fvec(winsize,channels);
     91  s->compspec = new_fvec(winsize);
    9492  /* create plans */
    9593#ifdef HAVE_COMPLEX_H
     
    136134
    137135void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) {
    138   uint_t i, j;
    139   for (i = 0; i < s->channels; i++) {
    140     for (j=0; j < s->winsize; j++) {
    141       s->in[j] = input->data[i][j];
    142     }
    143     fftw_execute(s->pfw);
    144 #ifdef HAVE_COMPLEX_H
    145     compspec->data[i][0] = REAL(s->specdata[0]);
    146     for (j = 1; j < s->fft_size -1 ; j++) {
    147       compspec->data[i][j] = REAL(s->specdata[j]);
    148       compspec->data[i][compspec->length - j] = IMAG(s->specdata[j]);
    149     }
    150     compspec->data[i][s->fft_size-1] = REAL(s->specdata[s->fft_size-1]);
    151 #else
    152     for (j = 0; j < s->fft_size; j++) {
    153       compspec->data[i][j] = s->specdata[j];
    154     }
    155 #endif
    156   }
     136  uint_t j;
     137  for (j=0; j < s->winsize; j++) {
     138    s->in[j] = input->data[j];
     139  }
     140  fftw_execute(s->pfw);
     141#ifdef HAVE_COMPLEX_H
     142  compspec->data[0] = REAL(s->specdata[0]);
     143  for (j = 1; j < s->fft_size -1 ; j++) {
     144    compspec->data[j] = REAL(s->specdata[j]);
     145    compspec->data[compspec->length - j] = IMAG(s->specdata[j]);
     146  }
     147  compspec->data[s->fft_size-1] = REAL(s->specdata[s->fft_size-1]);
     148#else
     149  for (j = 0; j < s->fft_size; j++) {
     150    compspec->data[j] = s->specdata[j];
     151  }
     152#endif
    157153}
    158154
    159155void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) {
    160   uint_t i, j;
     156  uint_t j;
    161157  const smpl_t renorm = 1./(smpl_t)s->winsize;
    162   for (i = 0; i < compspec->channels; i++) {
    163 #ifdef HAVE_COMPLEX_H
    164     s->specdata[0] = compspec->data[i][0];
    165     for (j=1; j < s->fft_size - 1; j++) {
    166       s->specdata[j] = compspec->data[i][j] +
    167         I * compspec->data[i][compspec->length - j];
    168     }
    169     s->specdata[s->fft_size - 1] = compspec->data[i][s->fft_size - 1];
    170 #else
    171     for (j=0; j < s->fft_size; j++) {
    172       s->specdata[j] = compspec->data[i][j];
    173     }
    174 #endif
    175     fftw_execute(s->pbw);
    176     for (j = 0; j < output->length; j++) {
    177       output->data[i][j] = s->out[j]*renorm;
    178     }
     158#ifdef HAVE_COMPLEX_H
     159  s->specdata[0] = compspec->data[0];
     160  for (j=1; j < s->fft_size - 1; j++) {
     161    s->specdata[j] = compspec->data[j] +
     162      I * compspec->data[compspec->length - j];
     163  }
     164  s->specdata[s->fft_size - 1] = compspec->data[s->fft_size - 1];
     165#else
     166  for (j=0; j < s->fft_size; j++) {
     167    s->specdata[j] = compspec->data[j];
     168  }
     169#endif
     170  fftw_execute(s->pbw);
     171  for (j = 0; j < output->length; j++) {
     172    output->data[j] = s->out[j]*renorm;
    179173  }
    180174}
     
    191185
    192186void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
    193   uint_t i, j;
    194   for (i = 0; i < spectrum->channels; i++) {
    195     if (compspec->data[i][0] < 0) {
    196       spectrum->phas[i][0] = PI;
    197     } else {
    198       spectrum->phas[i][0] = 0.;
    199     }
    200     for (j=1; j < spectrum->length - 1; j++) {
    201       spectrum->phas[i][j] = ATAN2(compspec->data[i][compspec->length-j],
    202           compspec->data[i][j]);
    203     }
    204     if (compspec->data[i][compspec->length/2] < 0) {
    205       spectrum->phas[i][spectrum->length - 1] = PI;
    206     } else {
    207       spectrum->phas[i][spectrum->length - 1] = 0.;
    208     }
     187  uint_t j;
     188  if (compspec->data[0] < 0) {
     189    spectrum->phas[0] = PI;
     190  } else {
     191    spectrum->phas[0] = 0.;
     192  }
     193  for (j=1; j < spectrum->length - 1; j++) {
     194    spectrum->phas[j] = ATAN2(compspec->data[compspec->length-j],
     195        compspec->data[j]);
     196  }
     197  if (compspec->data[compspec->length/2] < 0) {
     198    spectrum->phas[spectrum->length - 1] = PI;
     199  } else {
     200    spectrum->phas[spectrum->length - 1] = 0.;
    209201  }
    210202}
    211203
    212204void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) {
    213   uint_t i, j = 0;
    214   for (i = 0; i < spectrum->channels; i++) {
    215     spectrum->norm[i][0] = ABS(compspec->data[i][0]);
    216     for (j=1; j < spectrum->length - 1; j++) {
    217       spectrum->norm[i][j] = SQRT(SQR(compspec->data[i][j])
    218           + SQR(compspec->data[i][compspec->length - j]) );
    219     }
    220     spectrum->norm[i][spectrum->length-1] =
    221       ABS(compspec->data[i][compspec->length/2]);
    222   }
     205  uint_t j = 0;
     206  spectrum->norm[0] = ABS(compspec->data[0]);
     207  for (j=1; j < spectrum->length - 1; j++) {
     208    spectrum->norm[j] = SQRT(SQR(compspec->data[j])
     209        + SQR(compspec->data[compspec->length - j]) );
     210  }
     211  spectrum->norm[spectrum->length-1] =
     212    ABS(compspec->data[compspec->length/2]);
    223213}
    224214
    225215void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) {
    226   uint_t i, j;
    227   for (i = 0; i < compspec->channels; i++) {
    228     for (j = 1; j < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; j++) {
    229       compspec->data[i][compspec->length - j] =
    230         spectrum->norm[i][j]*SIN(spectrum->phas[i][j]);
    231     }
     216  uint_t j;
     217  for (j = 1; j < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; j++) {
     218    compspec->data[compspec->length - j] =
     219      spectrum->norm[j]*SIN(spectrum->phas[j]);
    232220  }
    233221}
    234222
    235223void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) {
    236   uint_t i, j;
    237   for (i = 0; i < compspec->channels; i++) {
    238     for (j = 0; j < compspec->length / 2 + 1; j++) {
    239       compspec->data[i][j] =
    240         spectrum->norm[i][j]*COS(spectrum->phas[i][j]);
    241     }
    242   }
    243 }
     224  uint_t j;
     225  for (j = 0; j < compspec->length / 2 + 1; j++) {
     226    compspec->data[j] =
     227      spectrum->norm[j]*COS(spectrum->phas[j]);
     228  }
     229}
  • src/spectral/fft.h

    r0b9a02a rd95ff38  
    4545
    4646  \param size length of the FFT
    47   \param channels number of channels
    4847
    4948*/
    50 aubio_fft_t * new_aubio_fft(uint_t size, uint_t channels);
     49aubio_fft_t * new_aubio_fft (uint_t size);
    5150/** delete FFT object
    5251
  • src/spectral/filterbank.c

    r0b9a02a rd95ff38  
    2222#include "aubio_priv.h"
    2323#include "fvec.h"
     24#include "fmat.h"
    2425#include "cvec.h"
    2526#include "spectral/filterbank.h"
     
    3132  uint_t win_s;
    3233  uint_t n_filters;
    33   fvec_t *filters;
     34  fmat_t *filters;
    3435};
    3536
     
    4243  fb->n_filters = n_filters;
    4344
    44   /* allocate filter tables, an fvec of length win_s and of filter_cnt channel */
    45   fb->filters = new_fvec (win_s / 2 + 1, n_filters);
     45  /* allocate filter tables, a matrix of length win_s and of height n_filters */
     46  fb->filters = new_fmat (win_s / 2 + 1, n_filters);
    4647
    4748  return fb;
     
    5152del_aubio_filterbank (aubio_filterbank_t * fb)
    5253{
    53   del_fvec (fb->filters);
     54  del_fmat (fb->filters);
    5455  AUBIO_FREE (fb);
    5556}
     
    5859aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out)
    5960{
    60   uint_t i, j, fn;
     61  uint_t j, fn;
    6162
    6263  /* apply filter to all input channel, provided out has enough channels */
    63   uint_t max_channels = MIN (in->channels, out->channels);
    6464  uint_t max_filters = MIN (f->n_filters, out->length);
    6565  uint_t max_length = MIN (in->length, f->filters->length);
     
    6868  fvec_zeros (out);
    6969
    70   /* apply filters on all channels */
    71   for (i = 0; i < max_channels; i++) {
     70  /* for each filter */
     71  for (fn = 0; fn < max_filters; fn++) {
    7272
    73     /* for each filter */
    74     for (fn = 0; fn < max_filters; fn++) {
    75 
    76       /* for each sample */
    77       for (j = 0; j < max_length; j++) {
    78         out->data[i][fn] += in->norm[i][j] * f->filters->data[fn][j];
    79       }
     73    /* for each sample */
     74    for (j = 0; j < max_length; j++) {
     75      out->data[fn] += in->norm[j] * f->filters->data[fn][j];
    8076    }
    8177  }
     
    8480}
    8581
    86 fvec_t *
     82fmat_t *
    8783aubio_filterbank_get_coeffs (aubio_filterbank_t * f)
    8884{
     
    9187
    9288uint_t
    93 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fvec_t * filters)
     89aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filter_coeffs)
    9490{
    95   fvec_copy(filters, f->filters);
     91  fmat_copy(filter_coeffs, f->filters);
    9692  return 0;
    9793}
  • src/spectral/filterbank.h

    r0b9a02a rd95ff38  
    6363void aubio_filterbank_do (aubio_filterbank_t * fb, cvec_t * in, fvec_t * out);
    6464
    65 /** return a pointer to the fvec object containing all filter coefficients
     65/** return a pointer to the matrix object containing all filter coefficients
    6666
    6767  \param f filterbank object to get coefficients from
    6868
    6969 */
    70 fvec_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f);
     70fmat_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f);
    7171
    7272/** copy filter coefficients to the filterbank
     
    7676
    7777 */
    78 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fvec_t * filters);
     78uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filters);
    7979
    8080#ifdef __cplusplus
  • src/spectral/filterbank_mel.c

    r0b9a02a rd95ff38  
    2121
    2222#include "aubio_priv.h"
     23#include "fmat.h"
    2324#include "fvec.h"
    2425#include "cvec.h"
     
    3132{
    3233
    33   fvec_t *filters = aubio_filterbank_get_coeffs (fb);
    34   uint_t n_filters = filters->channels, win_s = filters->length;
     34  fmat_t *filters = aubio_filterbank_get_coeffs (fb);
     35  uint_t n_filters = filters->height, win_s = filters->length;
    3536
    3637  uint_t fn;                    /* filter counter */
     
    4950  }
    5051
    51   if (freqs->data[0][freqs->length - 1] > samplerate / 2) {
     52  if (freqs->data[freqs->length - 1] > samplerate / 2) {
    5253    AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \
    53 %fHz\n", samplerate / 2, freqs->data[0][freqs->length - 1]);
     54%fHz\n", samplerate / 2, freqs->data[freqs->length - 1]);
    5455  }
    5556
    5657  /* convenience reference to lower/center/upper frequency for each triangle */
    57   fvec_t *lower_freqs = new_fvec (n_filters, 1);
    58   fvec_t *upper_freqs = new_fvec (n_filters, 1);
    59   fvec_t *center_freqs = new_fvec (n_filters, 1);
     58  fvec_t *lower_freqs = new_fvec (n_filters);
     59  fvec_t *upper_freqs = new_fvec (n_filters);
     60  fvec_t *center_freqs = new_fvec (n_filters);
    6061
    6162  /* height of each triangle */
    62   fvec_t *triangle_heights = new_fvec (n_filters, 1);
     63  fvec_t *triangle_heights = new_fvec (n_filters);
    6364
    6465  /* lookup table of each bin frequency in hz */
    65   fvec_t *fft_freqs = new_fvec (win_s, 1);
     66  fvec_t *fft_freqs = new_fvec (win_s);
    6667
    6768  /* fill up the lower/center/upper */
    6869  for (fn = 0; fn < n_filters; fn++) {
    69     lower_freqs->data[0][fn] = freqs->data[0][fn];
    70     center_freqs->data[0][fn] = freqs->data[0][fn + 1];
    71     upper_freqs->data[0][fn] = freqs->data[0][fn + 2];
     70    lower_freqs->data[fn] = freqs->data[fn];
     71    center_freqs->data[fn] = freqs->data[fn + 1];
     72    upper_freqs->data[fn] = freqs->data[fn + 2];
    7273  }
    7374
    7475  /* compute triangle heights so that each triangle has unit area */
    7576  for (fn = 0; fn < n_filters; fn++) {
    76     triangle_heights->data[0][fn] =
    77         2. / (upper_freqs->data[0][fn] - lower_freqs->data[0][fn]);
     77    triangle_heights->data[fn] =
     78        2. / (upper_freqs->data[fn] - lower_freqs->data[fn]);
    7879  }
    7980
    8081  /* fill fft_freqs lookup table, which assigns the frequency in hz to each bin */
    8182  for (bin = 0; bin < win_s; bin++) {
    82     fft_freqs->data[0][bin] =
     83    fft_freqs->data[bin] =
    8384        aubio_bintofreq (bin, samplerate, (win_s - 1) * 2);
    8485  }
    8586
    8687  /* zeroing of all filters */
    87   fvec_zeros (filters);
    88 
    89   if (fft_freqs->data[0][1] >= lower_freqs->data[0][0]) {
     88  fmat_zeros (filters);
     89
     90  if (fft_freqs->data[1] >= lower_freqs->data[0]) {
    9091    /* - 1 to make sure we don't miss the smallest power of two */
    9192    uint_t min_win_s =
    92         (uint_t) FLOOR (samplerate / lower_freqs->data[0][0]) - 1;
     93        (uint_t) FLOOR (samplerate / lower_freqs->data[0]) - 1;
    9394    AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \
    9495band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n",
    95         fft_freqs->data[0][1], lower_freqs->data[0][0],
    96         upper_freqs->data[0][0], (win_s - 1) * 2,
     96        fft_freqs->data[1], lower_freqs->data[0],
     97        upper_freqs->data[0], (win_s - 1) * 2,
    9798        aubio_next_power_of_two (min_win_s));
    9899  }
     
    103104    /* skip first elements */
    104105    for (bin = 0; bin < win_s - 1; bin++) {
    105       if (fft_freqs->data[0][bin] <= lower_freqs->data[0][fn] &&
    106           fft_freqs->data[0][bin + 1] > lower_freqs->data[0][fn]) {
     106      if (fft_freqs->data[bin] <= lower_freqs->data[fn] &&
     107          fft_freqs->data[bin + 1] > lower_freqs->data[fn]) {
    107108        bin++;
    108109        break;
     
    112113    /* compute positive slope step size */
    113114    smpl_t riseInc =
    114         triangle_heights->data[0][fn] /
    115         (center_freqs->data[0][fn] - lower_freqs->data[0][fn]);
     115        triangle_heights->data[fn] /
     116        (center_freqs->data[fn] - lower_freqs->data[fn]);
    116117
    117118    /* compute coefficients in positive slope */
    118119    for (; bin < win_s - 1; bin++) {
    119120      filters->data[fn][bin] =
    120           (fft_freqs->data[0][bin] - lower_freqs->data[0][fn]) * riseInc;
    121 
    122       if (fft_freqs->data[0][bin + 1] >= center_freqs->data[0][fn]) {
     121          (fft_freqs->data[bin] - lower_freqs->data[fn]) * riseInc;
     122
     123      if (fft_freqs->data[bin + 1] >= center_freqs->data[fn]) {
    123124        bin++;
    124125        break;
     
    128129    /* compute negative slope step size */
    129130    smpl_t downInc =
    130         triangle_heights->data[0][fn] /
    131         (upper_freqs->data[0][fn] - center_freqs->data[0][fn]);
     131        triangle_heights->data[fn] /
     132        (upper_freqs->data[fn] - center_freqs->data[fn]);
    132133
    133134    /* compute coefficents in negative slope */
    134135    for (; bin < win_s - 1; bin++) {
    135136      filters->data[fn][bin] +=
    136           (upper_freqs->data[0][fn] - fft_freqs->data[0][bin]) * downInc;
     137          (upper_freqs->data[fn] - fft_freqs->data[bin]) * downInc;
    137138
    138139      if (filters->data[fn][bin] < 0.) {
     
    140141      }
    141142
    142       if (fft_freqs->data[0][bin + 1] >= upper_freqs->data[0][fn])
     143      if (fft_freqs->data[bin + 1] >= upper_freqs->data[fn])
    143144        break;
    144145    }
     
    176177
    177178  /* buffers to compute filter frequencies */
    178   fvec_t *freqs = new_fvec (n_filters + 2, 1);
     179  fvec_t *freqs = new_fvec (n_filters + 2);
    179180
    180181  /* first step: fill all the linear filter frequencies */
    181182  for (fn = 0; fn < linearFilters; fn++) {
    182     freqs->data[0][fn] = lowestFrequency + fn * linearSpacing;
    183   }
    184   smpl_t lastlinearCF = freqs->data[0][fn - 1];
     183    freqs->data[fn] = lowestFrequency + fn * linearSpacing;
     184  }
     185  smpl_t lastlinearCF = freqs->data[fn - 1];
    185186
    186187  /* second step: fill all the log filter frequencies */
    187188  for (fn = 0; fn < logFilters + 2; fn++) {
    188     freqs->data[0][fn + linearFilters] =
     189    freqs->data[fn + linearFilters] =
    189190        lastlinearCF * (POW (logSpacing, fn + 1));
    190191  }
  • src/spectral/mfcc.c

    r0b9a02a rd95ff38  
    2222#include "aubio_priv.h"
    2323#include "fvec.h"
     24#include "fmat.h"
    2425#include "cvec.h"
    2526#include "mathutils.h"
     
    4041  aubio_filterbank_t *fb;   /** filter bank */
    4142  fvec_t *in_dct;           /** input buffer for dct * [fb->n_filters] */
    42   fvec_t *dct_coeffs;       /** DCT transform n_filters * n_coeffs */
     43  fmat_t *dct_coeffs;       /** DCT transform n_filters * n_coeffs */
    4344};
    4445
     
    6465
    6566  /* allocating buffers */
    66   mfcc->in_dct = new_fvec (n_filters, 1);
     67  mfcc->in_dct = new_fvec (n_filters);
    6768
    68   mfcc->dct_coeffs = new_fvec (n_coefs, n_filters);
     69  mfcc->dct_coeffs = new_fmat (n_coefs, n_filters);
    6970
    7071  /* compute DCT transform dct_coeffs[i][j] as
     
    100101aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out)
    101102{
    102   uint_t i, j, k;
     103  uint_t j, k;
    103104
    104105  /* compute filterbank */
     
    115116
    116117  /* compute discrete cosine transform */
    117   for (i = 0; i < out->channels; i++) {
    118     for (j = 0; j < mf->n_filters; j++) {
    119       for (k = 0; k < mf->n_coefs; k++) {
    120         out->data[i][k] += mf->in_dct->data[i][j]
    121             * mf->dct_coeffs->data[j][k];
    122       }
     118  for (j = 0; j < mf->n_filters; j++) {
     119    for (k = 0; k < mf->n_coefs; k++) {
     120      out->data[k] += mf->in_dct->data[j]
     121          * mf->dct_coeffs->data[j][k];
    123122    }
    124123  }
  • src/spectral/phasevoc.c

    r0b9a02a rd95ff38  
    3030  uint_t win_s;       /** grain length */
    3131  uint_t hop_s;       /** overlap step */
    32   uint_t channels;    /** number of channels */
    3332  aubio_fft_t * fft;  /** fft object */
    3433  fvec_t * synth;     /** cur output grain [win_s] */
     
    4948
    5049void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {
    51   uint_t i;
    52   for (i=0; i<pv->channels; i++) {
    53     /* slide  */
    54     aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
    55         datanew->data[i],pv->win_s,pv->hop_s);
    56   }
     50  /* slide  */
     51  aubio_pvoc_swapbuffers(pv->data->data,pv->dataold->data,
     52      datanew->data,pv->win_s,pv->hop_s);
    5753  /* windowing */
    5854  fvec_weight(pv->data, pv->w);
     
    6460
    6561void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) {
    66   uint_t i;
    6762  /* calculate rfft */
    6863  aubio_fft_rdo(pv->fft,fftgrain,pv->synth);
    6964  /* unshift */
    7065  fvec_shift(pv->synth);
    71   for (i=0; i<pv->channels; i++) {
    72     aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
    73         synthnew->data[i],pv->win_s,pv->hop_s);
    74   }
     66  aubio_pvoc_addsynth(pv->synth->data,pv->synthold->data,
     67      synthnew->data,pv->win_s,pv->hop_s);
    7568}
    7669
    77 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) {
     70aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s) {
    7871  aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
    7972
     
    8881  }
    8982
    90   pv->fft      = new_aubio_fft(win_s,channels);
     83  pv->fft      = new_aubio_fft (win_s);
    9184
    9285  /* remember old */
    93   pv->data     = new_fvec (win_s, channels);
    94   pv->synth    = new_fvec (win_s, channels);
     86  pv->data     = new_fvec (win_s);
     87  pv->synth    = new_fvec (win_s);
    9588
    9689  /* new input output */
    97   pv->dataold  = new_fvec  (win_s-hop_s, channels);
    98   pv->synthold = new_fvec (win_s-hop_s, channels);
     90  pv->dataold  = new_fvec  (win_s-hop_s);
     91  pv->synthold = new_fvec (win_s-hop_s);
    9992  pv->w        = new_aubio_window ("hanningz", win_s);
    10093
    101   pv->channels = channels;
    10294  pv->hop_s    = hop_s;
    10395  pv->win_s    = win_s;
  • src/spectral/phasevoc.h

    r0b9a02a rd95ff38  
    2626  using a HanningZ window and a swapped version of the signal to simplify the
    2727  phase relationships across frames. The window sizes and overlap are specified
    28   at creation time. Multiple channels are fully supported.
     28  at creation time.
    2929
    3030*/
     
    4444  \param win_s size of analysis buffer (and length the FFT transform)
    4545  \param hop_s step size between two consecutive analysis
    46   \param channels number of channels
    4746
    4847*/
    49 aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels);
     48aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s);
    5049/** delete phase vocoder object
    5150
     
    5756/** compute spectral frame
    5857 
    59   This function accepts an input vector of size [channels]x[hop_s]. The
     58  This function accepts an input vector of size [hop_s]. The
    6059  analysis buffer is rotated and filled with the new data. After windowing of
    6160  this signal window, the Fourier transform is computed and returned in
     
    7170
    7271  This function takes an input spectral frame fftgrain of size
    73   [channels]x[buf_s] and computes its inverse Fourier transform. Overlap-add
     72  [buf_s] and computes its inverse Fourier transform. Overlap-add
    7473  synthesis is then computed using the previously synthetised frames, and the
    7574  output stored in out.
     
    9493*/
    9594uint_t aubio_pvoc_get_hop(aubio_pvoc_t* pv);
    96 /** get channel number
    97  
    98   \param pv phase vocoder to get the number of channels from
    99 
    100 */
    101 uint_t aubio_pvoc_get_channels(aubio_pvoc_t* pv);
    10295
    10396#ifdef __cplusplus
  • src/spectral/specdesc.c

    r0b9a02a rd95ff38  
    8989void aubio_specdesc_energy  (aubio_specdesc_t *o UNUSED,
    9090    cvec_t * fftgrain, fvec_t * onset) {
    91   uint_t i,j;
    92   for (i=0;i<fftgrain->channels;i++) {
    93     onset->data[i][0] = 0.;
    94     for (j=0;j<fftgrain->length;j++) {
    95       onset->data[i][0] += SQR(fftgrain->norm[i][j]);
    96     }
     91  uint_t j;
     92  onset->data[0] = 0.;
     93  for (j=0;j<fftgrain->length;j++) {
     94    onset->data[0] += SQR(fftgrain->norm[j]);
    9795  }
    9896}
     
    10199void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED,
    102100    cvec_t * fftgrain, fvec_t * onset){
    103   uint_t i,j;
    104   for (i=0;i<fftgrain->channels;i++) {
    105     onset->data[i][0] = 0.;
    106     for (j=0;j<fftgrain->length;j++) {
    107       onset->data[i][0] += (j+1)*fftgrain->norm[i][j];
    108     }
     101  uint_t j;
     102  onset->data[0] = 0.;
     103  for (j=0;j<fftgrain->length;j++) {
     104    onset->data[0] += (j+1)*fftgrain->norm[j];
    109105  }
    110106}
     
    113109/* Complex Domain Method onset detection function */
    114110void aubio_specdesc_complex (aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset) {
    115   uint_t i, j;
     111  uint_t j;
    116112  uint_t nbins = fftgrain->length;
    117   for (i=0;i<fftgrain->channels; i++)  {
    118     onset->data[i][0] = 0.;
    119     for (j=0;j<nbins; j++)  {
    120       // compute the predicted phase
    121       o->dev1->data[i][j] = 2. * o->theta1->data[i][j] - o->theta2->data[i][j];
    122       // compute the euclidean distance in the complex domain
    123       // sqrt ( r_1^2 + r_2^2 - 2 * r_1 * r_2 * \cos ( \phi_1 - \phi_2 ) )
    124       onset->data[i][0] +=
    125         SQRT (ABS (SQR (o->oldmag->data[i][j]) + SQR (fftgrain->norm[i][j])
    126               - 2. * o->oldmag->data[i][j] * fftgrain->norm[i][j]
    127               * COS (o->dev1->data[i][j] - fftgrain->phas[i][j])));
    128       /* swap old phase data (need to remember 2 frames behind)*/
    129       o->theta2->data[i][j] = o->theta1->data[i][j];
    130       o->theta1->data[i][j] = fftgrain->phas[i][j];
    131       /* swap old magnitude data (1 frame is enough) */
    132       o->oldmag->data[i][j] = fftgrain->norm[i][j];
    133     }
     113  onset->data[0] = 0.;
     114  for (j=0;j<nbins; j++)  {
     115    // compute the predicted phase
     116    o->dev1->data[j] = 2. * o->theta1->data[j] - o->theta2->data[j];
     117    // compute the euclidean distance in the complex domain
     118    // sqrt ( r_1^2 + r_2^2 - 2 * r_1 * r_2 * \cos ( \phi_1 - \phi_2 ) )
     119    onset->data[0] +=
     120      SQRT (ABS (SQR (o->oldmag->data[j]) + SQR (fftgrain->norm[j])
     121            - 2. * o->oldmag->data[j] * fftgrain->norm[j]
     122            * COS (o->dev1->data[j] - fftgrain->phas[j])));
     123    /* swap old phase data (need to remember 2 frames behind)*/
     124    o->theta2->data[j] = o->theta1->data[j];
     125    o->theta1->data[j] = fftgrain->phas[j];
     126    /* swap old magnitude data (1 frame is enough) */
     127    o->oldmag->data[j] = fftgrain->norm[j];
    134128  }
    135129}
     
    139133void aubio_specdesc_phase(aubio_specdesc_t *o,
    140134    cvec_t * fftgrain, fvec_t * onset){
    141   uint_t i, j;
     135  uint_t j;
    142136  uint_t nbins = fftgrain->length;
    143   for (i=0;i<fftgrain->channels; i++)  {
    144     onset->data[i][0] = 0.0;
    145     o->dev1->data[i][0]=0.;
    146     for ( j=0;j<nbins; j++ )  {
    147       o->dev1->data[i][j] =
    148         aubio_unwrap2pi(
    149             fftgrain->phas[i][j]
    150             -2.0*o->theta1->data[i][j]
    151             +o->theta2->data[i][j]);
    152       if ( o->threshold < fftgrain->norm[i][j] )
    153         o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
    154       else
    155         o->dev1->data[i][j] = 0.0;
    156       /* keep a track of the past frames */
    157       o->theta2->data[i][j] = o->theta1->data[i][j];
    158       o->theta1->data[i][j] = fftgrain->phas[i][j];
    159     }
    160     /* apply o->histogram */
    161     aubio_hist_dyn_notnull(o->histog,o->dev1);
    162     /* weight it */
    163     aubio_hist_weight(o->histog);
    164     /* its mean is the result */
    165     onset->data[i][0] = aubio_hist_mean(o->histog); 
    166     //onset->data[i][0] = fvec_mean(o->dev1);
    167   }
     137  onset->data[0] = 0.0;
     138  o->dev1->data[0]=0.;
     139  for ( j=0;j<nbins; j++ )  {
     140    o->dev1->data[j] =
     141      aubio_unwrap2pi(
     142          fftgrain->phas[j]
     143          -2.0*o->theta1->data[j]
     144          +o->theta2->data[j]);
     145    if ( o->threshold < fftgrain->norm[j] )
     146      o->dev1->data[j] = ABS(o->dev1->data[j]);
     147    else
     148      o->dev1->data[j] = 0.0;
     149    /* keep a track of the past frames */
     150    o->theta2->data[j] = o->theta1->data[j];
     151    o->theta1->data[j] = fftgrain->phas[j];
     152  }
     153  /* apply o->histogram */
     154  aubio_hist_dyn_notnull(o->histog,o->dev1);
     155  /* weight it */
     156  aubio_hist_weight(o->histog);
     157  /* its mean is the result */
     158  onset->data[0] = aubio_hist_mean(o->histog); 
     159  //onset->data[0] = fvec_mean(o->dev1);
    168160}
    169161
     
    171163void aubio_specdesc_specdiff(aubio_specdesc_t *o,
    172164    cvec_t * fftgrain, fvec_t * onset){
    173   uint_t i, j;
     165  uint_t j;
    174166  uint_t nbins = fftgrain->length;
    175   for (i=0;i<fftgrain->channels; i++)  {
    176     onset->data[i][0] = 0.0;
     167    onset->data[0] = 0.0;
    177168    for (j=0;j<nbins; j++)  {
    178       o->dev1->data[i][j] = SQRT(
    179           ABS(SQR( fftgrain->norm[i][j])
    180             - SQR(o->oldmag->data[i][j])));
    181       if (o->threshold < fftgrain->norm[i][j] )
    182         o->dev1->data[i][j] = ABS(o->dev1->data[i][j]);
     169      o->dev1->data[j] = SQRT(
     170          ABS(SQR( fftgrain->norm[j])
     171            - SQR(o->oldmag->data[j])));
     172      if (o->threshold < fftgrain->norm[j] )
     173        o->dev1->data[j] = ABS(o->dev1->data[j]);
    183174      else
    184         o->dev1->data[i][j] = 0.0;
    185       o->oldmag->data[i][j] = fftgrain->norm[i][j];
     175        o->dev1->data[j] = 0.0;
     176      o->oldmag->data[j] = fftgrain->norm[j];
    186177    }
    187178
     
    192183    aubio_hist_weight(o->histog);
    193184    /* its mean is the result */
    194     onset->data[i][0] = aubio_hist_mean(o->histog); 
    195 
    196   }
     185    onset->data[0] = aubio_hist_mean(o->histog); 
    197186}
    198187
     
    201190 * negative (1.+) and infinite values (+1.e-10) */
    202191void aubio_specdesc_kl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
    203   uint_t i,j;
    204   for (i=0;i<fftgrain->channels;i++) {
    205     onset->data[i][0] = 0.;
     192  uint_t j;
     193    onset->data[0] = 0.;
    206194    for (j=0;j<fftgrain->length;j++) {
    207       onset->data[i][0] += fftgrain->norm[i][j]
    208         *LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
    209       o->oldmag->data[i][j] = fftgrain->norm[i][j];
     195      onset->data[0] += fftgrain->norm[j]
     196        *LOG(1.+fftgrain->norm[j]/(o->oldmag->data[j]+1.e-10));
     197      o->oldmag->data[j] = fftgrain->norm[j];
    210198    }
    211     if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
    212   }
     199    if (isnan(onset->data[0])) onset->data[0] = 0.;
    213200}
    214201
     
    217204 * negative (1.+) and infinite values (+1.e-10) */
    218205void aubio_specdesc_mkl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
    219   uint_t i,j;
    220   for (i=0;i<fftgrain->channels;i++) {
    221     onset->data[i][0] = 0.;
     206  uint_t j;
     207    onset->data[0] = 0.;
    222208    for (j=0;j<fftgrain->length;j++) {
    223       onset->data[i][0] += LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
    224       o->oldmag->data[i][j] = fftgrain->norm[i][j];
     209      onset->data[0] += LOG(1.+fftgrain->norm[j]/(o->oldmag->data[j]+1.e-10));
     210      o->oldmag->data[j] = fftgrain->norm[j];
    225211    }
    226     if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
    227   }
     212    if (isnan(onset->data[0])) onset->data[0] = 0.;
    228213}
    229214
    230215/* Spectral flux */
    231216void aubio_specdesc_specflux(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
    232   uint_t i, j;
    233   for (i=0;i<fftgrain->channels;i++) {
    234     onset->data[i][0] = 0.;
    235     for (j=0;j<fftgrain->length;j++) {
    236       if (fftgrain->norm[i][j] > o->oldmag->data[i][j])
    237         onset->data[i][0] += fftgrain->norm[i][j] - o->oldmag->data[i][j];
    238       o->oldmag->data[i][j] = fftgrain->norm[i][j];
    239     }
     217  uint_t j;
     218  onset->data[0] = 0.;
     219  for (j=0;j<fftgrain->length;j++) {
     220    if (fftgrain->norm[j] > o->oldmag->data[j])
     221      onset->data[0] += fftgrain->norm[j] - o->oldmag->data[j];
     222    o->oldmag->data[j] = fftgrain->norm[j];
    240223  }
    241224}
     
    252235 */
    253236aubio_specdesc_t *
    254 new_aubio_specdesc (char_t * onset_mode,
    255     uint_t size, uint_t channels){
     237new_aubio_specdesc (char_t * onset_mode, uint_t size){
    256238  aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t);
    257239  uint_t rsize = size/2+1;
     
    303285      /* the other approaches will need some more memory spaces */
    304286    case aubio_onset_complex:
    305       o->oldmag = new_fvec(rsize,channels);
    306       o->dev1   = new_fvec(rsize,channels);
    307       o->theta1 = new_fvec(rsize,channels);
    308       o->theta2 = new_fvec(rsize,channels);
     287      o->oldmag = new_fvec(rsize);
     288      o->dev1   = new_fvec(rsize);
     289      o->theta1 = new_fvec(rsize);
     290      o->theta2 = new_fvec(rsize);
    309291      break;
    310292    case aubio_onset_phase:
    311       o->dev1   = new_fvec(rsize,channels);
    312       o->theta1 = new_fvec(rsize,channels);
    313       o->theta2 = new_fvec(rsize,channels);
    314       o->histog = new_aubio_hist(0.0, PI, 10, channels);
     293      o->dev1   = new_fvec(rsize);
     294      o->theta1 = new_fvec(rsize);
     295      o->theta2 = new_fvec(rsize);
     296      o->histog = new_aubio_hist(0.0, PI, 10);
    315297      o->threshold = 0.1;
    316298      break;
    317299    case aubio_onset_specdiff:
    318       o->oldmag = new_fvec(rsize,channels);
    319       o->dev1   = new_fvec(rsize,channels);
    320       o->histog = new_aubio_hist(0.0, PI, 10, channels);
     300      o->oldmag = new_fvec(rsize);
     301      o->dev1   = new_fvec(rsize);
     302      o->histog = new_aubio_hist(0.0, PI, 10);
    321303      o->threshold = 0.1;
    322304      break;
     
    324306    case aubio_onset_mkl:
    325307    case aubio_onset_specflux:
    326       o->oldmag = new_fvec(rsize,channels);
     308      o->oldmag = new_fvec(rsize);
    327309      break;
    328310    default:
  • src/spectral/specdesc.h

    r0b9a02a rd95ff38  
    2525  All of the following spectral description functions take as arguments the FFT
    2626  of a windowed signal (as created with aubio_pvoc). They output one smpl_t per
    27   buffer and per channel (stored in a vector of size [channels]x[1]).
     27  buffer (stored in a vector of size [1]).
    2828 
    2929  A list of the spectral description methods currently available follows.
     
    168168  \param method spectral description method
    169169  \param buf_size length of the input spectrum frame
    170   \param channels number of input channels
    171170
    172171*/
    173 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size,
    174     uint_t channels);
     172aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size);
    175173
    176174/** deletion of a spectral descriptor
  • src/spectral/statistics.c

    r0b9a02a rd95ff38  
    2424
    2525smpl_t
    26 cvec_sum_channel (cvec_t * s, uint_t i)
     26cvec_sum (cvec_t * s)
    2727{
    2828  uint_t j;
    2929  smpl_t tmp = 0.0;
    30   for (j = 0; j < s->length; j++)
    31       tmp += s->norm[i][j];
     30  for (j = 0; j < s->length; j++) {
     31    tmp += s->norm[j];
     32  }
    3233  return tmp;
    3334}
    3435
    3536smpl_t
    36 cvec_mean_channel (cvec_t * s, uint_t i)
     37cvec_mean (cvec_t * s)
    3738{
    38   return cvec_sum_channel(s, i) / (smpl_t) (s->length);
     39  return cvec_sum (s) / (smpl_t) (s->length);
    3940}
    4041
    4142smpl_t
    42 cvec_centroid_channel (cvec_t * spec, uint_t i)
     43cvec_centroid (cvec_t * spec)
    4344{
    4445  smpl_t sum = 0., sc = 0.;
    4546  uint_t j;
    46   sum = cvec_sum_channel (spec, i);
     47  sum = cvec_sum (spec);
    4748  if (sum == 0.) {
    4849    return 0.;
    4950  } else {
    5051    for (j = 0; j < spec->length; j++) {
    51       sc += (smpl_t) j *spec->norm[i][j];
     52      sc += (smpl_t) j *spec->norm[j];
    5253    }
    5354    return sc / sum;
     
    5657
    5758smpl_t
    58 cvec_moment_channel (cvec_t * spec, uint_t i, uint_t order)
     59cvec_moment (cvec_t * spec, uint_t order)
    5960{
    6061  smpl_t sum = 0., centroid = 0., sc = 0.;
    6162  uint_t j;
    62   sum = cvec_sum_channel (spec, i);
     63  sum = cvec_sum (spec);
    6364  if (sum == 0.) {
    6465    return 0.;
    6566  } else {
    66     centroid = cvec_centroid_channel (spec, i);
     67    centroid = cvec_centroid (spec);
    6768    for (j = 0; j < spec->length; j++) {
    68       sc += (smpl_t) POW(j - centroid, order) * spec->norm[i][j];
     69      sc += (smpl_t) POW(j - centroid, order) * spec->norm[j];
    6970    }
    7071    return sc / sum;
     
    7677    fvec_t * desc)
    7778{
    78   uint_t i;
    79   for (i = 0; i < spec->channels; i++) {
    80     desc->data[i][0] = cvec_centroid_channel (spec, i);
    81   }
     79  desc->data[0] = cvec_centroid (spec);
    8280}
    8381
     
    8684    fvec_t * desc)
    8785{
    88   uint_t i;
    89   for (i = 0; i < spec->channels; i++) {
    90     desc->data[i][0] = cvec_moment_channel (spec, i, 2);
    91   }
     86  desc->data[0] = cvec_moment (spec, 2);
    9287}
    9388
     
    9691    fvec_t * desc)
    9792{
    98   uint_t i; smpl_t spread;
    99   for (i = 0; i < spec->channels; i++) {
    100     spread = cvec_moment_channel (spec, i, 2);
    101     if (spread == 0) {
    102       desc->data[i][0] = 0.;
    103     } else {
    104       desc->data[i][0] = cvec_moment_channel (spec, i, 3);
    105       desc->data[i][0] /= POW ( SQRT (spread), 3);
    106     }
     93  smpl_t spread;
     94  spread = cvec_moment (spec, 2);
     95  if (spread == 0) {
     96    desc->data[0] = 0.;
     97  } else {
     98    desc->data[0] = cvec_moment (spec, 3);
     99    desc->data[0] /= POW ( SQRT (spread), 3);
    107100  }
    108101}
     
    112105    fvec_t * desc)
    113106{
    114   uint_t i; smpl_t spread;
    115   for (i = 0; i < spec->channels; i++) {
    116     spread = cvec_moment_channel (spec, i, 2);
    117     if (spread == 0) {
    118       desc->data[i][0] = 0.;
    119     } else {
    120       desc->data[i][0] = cvec_moment_channel (spec, i, 4);
    121       desc->data[i][0] /= SQR (spread);
    122     }
     107  smpl_t spread;
     108  spread = cvec_moment (spec, 2);
     109  if (spread == 0) {
     110    desc->data[0] = 0.;
     111  } else {
     112    desc->data[0] = cvec_moment (spec, 4);
     113    desc->data[0] /= SQR (spread);
    123114  }
    124115}
     
    128119    fvec_t * desc)
    129120{
    130   uint_t i, j;
     121  uint_t j;
    131122  smpl_t norm = 0, sum = 0.;
    132123  // compute N * sum(j**2) - sum(j)**2
     
    137128  // sum_0^N(j) = length * (length + 1) / 2
    138129  norm -= SQR( (spec->length) * (spec->length - 1.) / 2. );
    139   for (i = 0; i < spec->channels; i++) {
    140     sum = cvec_sum_channel (spec, i);
    141     desc->data[i][0] = 0.;
    142     if (sum == 0.) {
    143       break;
    144     } else {
    145       for (j = 0; j < spec->length; j++) {
    146         desc->data[i][0] += j * spec->norm[i][j];
    147       }
    148       desc->data[i][0] *= spec->length;
    149       desc->data[i][0] -= sum * spec->length * (spec->length - 1) / 2.;
    150       desc->data[i][0] /= norm;
    151       desc->data[i][0] /= sum;
     130  sum = cvec_sum (spec);
     131  desc->data[0] = 0.;
     132  if (sum == 0.) {
     133    return;
     134  } else {
     135    for (j = 0; j < spec->length; j++) {
     136      desc->data[0] += j * spec->norm[j];
    152137    }
     138    desc->data[0] *= spec->length;
     139    desc->data[0] -= sum * spec->length * (spec->length - 1) / 2.;
     140    desc->data[0] /= norm;
     141    desc->data[0] /= sum;
    153142  }
    154143}
     
    158147    fvec_t * desc)
    159148{
    160   uint_t i, j; smpl_t sum;
    161   for (i = 0; i < spec->channels; i++) {
    162     sum = cvec_sum_channel (spec, i);
    163     desc->data[i][0] = 0;
    164     if (sum == 0.) {
    165       break;
    166     } else {
    167       sum -= spec->norm[i][0];
    168       for (j = 1; j < spec->length; j++) {
    169         desc->data[i][0] += (spec->norm[i][j] - spec->norm[i][0]) / j;
    170       }
    171       desc->data[i][0] /= sum;
     149  uint_t j; smpl_t sum;
     150  sum = cvec_sum (spec);
     151  desc->data[0] = 0;
     152  if (sum == 0.) {
     153    return;
     154  } else {
     155    sum -= spec->norm[0];
     156    for (j = 1; j < spec->length; j++) {
     157      desc->data[0] += (spec->norm[j] - spec->norm[0]) / j;
    172158    }
     159    desc->data[0] /= sum;
    173160  }
    174161}
     
    178165    fvec_t *desc)
    179166{
    180   uint_t i, j; smpl_t cumsum, rollsum;
    181   for (i = 0; i < spec->channels; i++) {
    182     cumsum = 0.; rollsum = 0.;
    183     for (j = 0; j < spec->length; j++) {
    184       cumsum += SQR (spec->norm[i][j]);
     167  uint_t j; smpl_t cumsum, rollsum;
     168  cumsum = 0.; rollsum = 0.;
     169  for (j = 0; j < spec->length; j++) {
     170    cumsum += SQR (spec->norm[j]);
     171  }
     172  if (cumsum == 0) {
     173    desc->data[0] = 0.;
     174  } else {
     175    cumsum *= 0.95;
     176    j = 0;
     177    while (rollsum < cumsum) {
     178      rollsum += SQR (spec->norm[j]);
     179      j++;
    185180    }
    186     if (cumsum == 0) {
    187       desc->data[i][0] = 0.;
    188     } else {
    189       cumsum *= 0.95;
    190       j = 0;
    191       while (rollsum < cumsum) {
    192         rollsum += SQR (spec->norm[i][j]);
    193         j++;
    194       }
    195       desc->data[i][0] = j;
    196     }
     181    desc->data[0] = j;
    197182  }
    198183}
  • src/spectral/tss.c

    r0b9a02a rd95ff38  
    4444    cvec_t * trans, cvec_t * stead)
    4545{
    46   uint_t i,j;
     46  uint_t j;
    4747  uint_t test;
    4848  uint_t nbins     = input->length;
    49   uint_t channels  = input->channels;
    5049  smpl_t alpha     = o->alpha;
    5150  smpl_t beta      = o->beta;
    5251  smpl_t parm      = o->parm;
    53   smpl_t ** dev    = (smpl_t **)o->dev->data;
    54   smpl_t ** oft1   = (smpl_t **)o->oft1->data;
    55   smpl_t ** oft2   = (smpl_t **)o->oft2->data;
    56   smpl_t ** theta1 = (smpl_t **)o->theta1->data;
    57   smpl_t ** theta2 = (smpl_t **)o->theta2->data;
     52  smpl_t * dev    = (smpl_t *)o->dev->data;
     53  smpl_t * oft1   = (smpl_t *)o->oft1->data;
     54  smpl_t * oft2   = (smpl_t *)o->oft2->data;
     55  smpl_t * theta1 = (smpl_t *)o->theta1->data;
     56  smpl_t * theta2 = (smpl_t *)o->theta2->data;
    5857  /* second phase derivative */
    59   for (i=0;i<channels; i++){
    60     for (j=0;j<nbins; j++){
    61       dev[i][j] = aubio_unwrap2pi(input->phas[i][j]
    62           -2.0*theta1[i][j]+theta2[i][j]);
    63       theta2[i][j] = theta1[i][j];
    64       theta1[i][j] = input->phas[i][j];
    65     }
     58  for (j=0;j<nbins; j++){
     59    dev[j] = aubio_unwrap2pi(input->phas[j]
     60        -2.0*theta1[j]+theta2[j]);
     61    theta2[j] = theta1[j];
     62    theta1[j] = input->phas[j];
     63  }
    6664
    67     for (j=0;j<nbins; j++){
    68       /* transient analysis */
    69       test = (ABS(dev[i][j]) > parm*oft1[i][j]);
    70       trans->norm[i][j] = input->norm[i][j] * test;
    71       trans->phas[i][j] = input->phas[i][j] * test;
    72     }
     65  for (j=0;j<nbins; j++){
     66    /* transient analysis */
     67    test = (ABS(dev[j]) > parm*oft1[j]);
     68    trans->norm[j] = input->norm[j] * test;
     69    trans->phas[j] = input->phas[j] * test;
     70  }
    7371
    74     for (j=0;j<nbins; j++){
    75       /* steady state analysis */
    76       test = (ABS(dev[i][j]) < parm*oft2[i][j]);
    77       stead->norm[i][j] = input->norm[i][j] * test;
    78       stead->phas[i][j] = input->phas[i][j] * test;
     72  for (j=0;j<nbins; j++){
     73    /* steady state analysis */
     74    test = (ABS(dev[j]) < parm*oft2[j]);
     75    stead->norm[j] = input->norm[j] * test;
     76    stead->phas[j] = input->phas[j] * test;
    7977
    80       /*increase sstate probability for sines */
    81       test = (trans->norm[i][j]==0.);
    82       oft1[i][j]  = test;
    83       test = (stead->norm[i][j]==0.);
    84       oft2[i][j]  = test;
    85       test = (trans->norm[i][j]>0.);
    86       oft1[i][j] += alpha*test;
    87       test = (stead->norm[i][j]>0.);
    88       oft2[i][j] += alpha*test;
    89       test = (oft1[i][j]>1. && trans->norm[i][j]>0.);
    90       oft1[i][j] += beta*test;
    91       test = (oft2[i][j]>1. && stead->norm[i][j]>0.);
    92       oft2[i][j] += beta*test;
    93     }
     78    /*increase sstate probability for sines */
     79    test = (trans->norm[j]==0.);
     80    oft1[j]  = test;
     81    test = (stead->norm[j]==0.);
     82    oft2[j]  = test;
     83    test = (trans->norm[j]>0.);
     84    oft1[j] += alpha*test;
     85    test = (stead->norm[j]>0.);
     86    oft2[j] += alpha*test;
     87    test = (oft1[j]>1. && trans->norm[j]>0.);
     88    oft1[j] += beta*test;
     89    test = (oft2[j]>1. && stead->norm[j]>0.);
     90    oft2[j] += beta*test;
    9491  }
    9592}
     
    10198}
    10299
    103 aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size, uint_t channels)
     100aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size)
    104101{
    105102  aubio_tss_t * o = AUBIO_NEW(aubio_tss_t);
     
    110107  o->beta = 4.;
    111108  o->parm = o->threshold*o->thrsfact;
    112   o->theta1 = new_fvec(rsize,channels);
    113   o->theta2 = new_fvec(rsize,channels);
    114   o->oft1 = new_fvec(rsize,channels);
    115   o->oft2 = new_fvec(rsize,channels);
    116   o->dev = new_fvec(rsize,channels);
     109  o->theta1 = new_fvec(rsize);
     110  o->theta2 = new_fvec(rsize);
     111  o->oft1 = new_fvec(rsize);
     112  o->oft2 = new_fvec(rsize);
     113  o->dev = new_fvec(rsize);
    117114  return o;
    118115}
  • src/spectral/tss.h

    r0b9a02a rd95ff38  
    4949  \param buf_size buffer size
    5050  \param hop_size step size
    51   \param channels number of input channels
    5251
    5352*/
    54 aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size, uint_t channels);
     53aubio_tss_t *new_aubio_tss (uint_t buf_size, uint_t hop_size);
    5554
    5655/** delete tss object
Note: See TracChangeset for help on using the changeset viewer.