Ignore:
Timestamp:
Nov 3, 2009, 4:14:03 PM (14 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
bafe71d
Parents:
63f3c70
Message:

src/pitch/: indent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitchmcomb.c

    r63f3c70 rfddfa64  
    2929typedef struct _aubio_spectralpeak_t aubio_spectralpeak_t;
    3030typedef struct _aubio_spectralcandidate_t aubio_spectralcandidate_t;
    31 uint_t aubio_pitchmcomb_get_root_peak(aubio_spectralpeak_t * peaks, uint_t length);
    32 uint_t aubio_pitchmcomb_quadpick(aubio_spectralpeak_t * spectral_peaks, fvec_t * X);
    33 void aubio_pitchmcomb_spectral_pp(aubio_pitchmcomb_t * p, fvec_t * oldmag);
    34 void aubio_pitchmcomb_combdet(aubio_pitchmcomb_t * p, fvec_t * newmag);
     31uint_t aubio_pitchmcomb_get_root_peak (aubio_spectralpeak_t * peaks,
     32    uint_t length);
     33uint_t aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks,
     34    fvec_t * X);
     35void aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * oldmag);
     36void aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag);
    3537/* not used but useful : sort by amplitudes (or anything else)
    3638 * sort_pitchpeak(peaks, length);
    3739 */
    3840/** spectral_peak comparison function (must return signed int) */
    39 static sint_t aubio_pitchmcomb_sort_peak_comp(const void *x, const void *y);
     41static sint_t aubio_pitchmcomb_sort_peak_comp (const void *x, const void *y);
    4042/** sort spectral_peak against their mag */
    41 void aubio_pitchmcomb_sort_peak(aubio_spectralpeak_t * peaks, uint_t nbins);
     43void aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins);
    4244/** select the best candidates */
    43 uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands);
     45uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain,
     46    smpl_t * cands);
    4447
    4548/** sort spectral_candidate against their comb ene */
    46 void aubio_pitchmcomb_sort_cand_ene(aubio_spectralcandidate_t ** candidates, uint_t nbins);
     49void aubio_pitchmcomb_sort_cand_ene (aubio_spectralcandidate_t ** candidates,
     50    uint_t nbins);
    4751/** sort spectral_candidate against their frequency */
    48 void aubio_pitchmcomb_sort_cand_freq(aubio_spectralcandidate_t ** candidates, uint_t nbins);
    49 
    50 struct _aubio_pitchmcomb_t {
     52void aubio_pitchmcomb_sort_cand_freq (aubio_spectralcandidate_t ** candidates,
     53    uint_t nbins);
     54
     55struct _aubio_pitchmcomb_t
     56{
    5157  smpl_t threshold;                        /**< offset threshold [0.033 or 0.01]     */
    5258  smpl_t alpha;                            /**< normalisation exponent [9]           */
     
    6167  uint_t goodcandidate;                    /**< best candidate                       */
    6268  uint_t spec_partition;                   /**< spectrum partition to consider       */
    63   aubio_spectralpeak_t * peaks;            /**< up to length win/spec_partition      */
    64   aubio_spectralcandidate_t ** candidates; /** up to five candidates                 */
     69  aubio_spectralpeak_t *peaks;             /**< up to length win/spec_partition      */
     70  aubio_spectralcandidate_t **candidates; /** up to five candidates                 */
    6571  /* some scratch pads */
    6672  /** \bug  (unnecessary copied from fftgrain?) */
    67   fvec_t * newmag;                         /**< vec to store mag                     */
    68   fvec_t * scratch;                        /**< vec to store modified mag            */
    69   fvec_t * scratch2;                       /**< vec to compute moving median         */
    70   fvec_t * theta;                         /**< vec to store phase                     */
     73  fvec_t *newmag;                          /**< vec to store mag                     */
     74  fvec_t *scratch;                         /**< vec to store modified mag            */
     75  fvec_t *scratch2;                        /**< vec to compute moving median         */
     76  fvec_t *theta;                          /**< vec to store phase                     */
    7177  smpl_t phasediff;
    7278  smpl_t phasefreq;
     
    7884
    7985/** spectral peak object */
    80 struct _aubio_spectralpeak_t {
     86struct _aubio_spectralpeak_t
     87{
    8188  uint_t bin;     /**< bin [0-(length-1)] */
    8289  smpl_t ebin;    /**< estimated bin */
     
    8592
    8693/** spectral candidates array object */
    87 struct _aubio_spectralcandidate_t {
     94struct _aubio_spectralcandidate_t
     95{
    8896  smpl_t ebin;    /**< interpolated bin */
    89   smpl_t * ecomb; /**< comb */
     97  smpl_t *ecomb; /**< comb */
    9098  smpl_t ene;     /**< candidate energy */
    9199  smpl_t len;     /**< length */
     
    93101
    94102
    95 void aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output) {
    96   uint_t i,j;
     103void
     104aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output)
     105{
     106  uint_t i, j;
    97107  smpl_t instfreq;
    98   fvec_t * newmag = (fvec_t *)p->newmag;
     108  fvec_t *newmag = (fvec_t *) p->newmag;
    99109  //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta;
    100110  /* copy incoming grain to newmag */
    101   for (i=0; i< fftgrain->channels; i++) {
    102   for (j=0; j< newmag->length; j++)
    103     newmag->data[0][j]=fftgrain->norm[i][j];
    104   /* detect only if local energy > 10. */
    105   //if (fvec_local_energy(newmag)>10.) {
     111  for (i = 0; i < fftgrain->channels; i++) {
     112    for (j = 0; j < newmag->length; j++)
     113      newmag->data[0][j] = fftgrain->norm[i][j];
     114    /* detect only if local energy > 10. */
     115    //if (fvec_local_energy(newmag)>10.) {
    106116    //hfc = fvec_local_hfc(newmag); //not used
    107     aubio_pitchmcomb_spectral_pp(p, newmag);
    108     aubio_pitchmcomb_combdet(p,newmag);
     117    aubio_pitchmcomb_spectral_pp (p, newmag);
     118    aubio_pitchmcomb_combdet (p, newmag);
    109119    //aubio_pitchmcomb_sort_cand_freq(p->candidates,p->ncand);
    110120    //return p->candidates[p->goodcandidate]->ebin;
    111   j = (uint_t)FLOOR(p->candidates[p->goodcandidate]->ebin+.5);
    112   instfreq  = aubio_unwrap2pi(fftgrain->phas[i][j]
    113       - p->theta->data[i][j] - j*p->phasediff);
    114   instfreq *= p->phasefreq;
    115   /* store phase for next run */
    116   for (j=0; j< p->theta->length; j++) {
    117     p->theta->data[i][j]=fftgrain->phas[i][j];
    118   }
    119   //return p->candidates[p->goodcandidate]->ebin;
    120   output->data[i][0] = FLOOR(p->candidates[p->goodcandidate]->ebin+.5) + instfreq;
    121   /*} else {
    122     return -1.;
    123   }*/
    124   }
    125 }
    126 
    127 uint_t aubio_pitch_cands(aubio_pitchmcomb_t * p, cvec_t * fftgrain,
    128     smpl_t * cands) {
    129   uint_t i=0,j;
     121    j = (uint_t) FLOOR (p->candidates[p->goodcandidate]->ebin + .5);
     122    instfreq = aubio_unwrap2pi (fftgrain->phas[i][j]
     123        - p->theta->data[i][j] - j * p->phasediff);
     124    instfreq *= p->phasefreq;
     125    /* store phase for next run */
     126    for (j = 0; j < p->theta->length; j++) {
     127      p->theta->data[i][j] = fftgrain->phas[i][j];
     128    }
     129    //return p->candidates[p->goodcandidate]->ebin;
     130    output->data[i][0] =
     131        FLOOR (p->candidates[p->goodcandidate]->ebin + .5) + instfreq;
     132    /*} else {
     133       return -1.;
     134       } */
     135  }
     136}
     137
     138uint_t
     139aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands)
     140{
     141  uint_t i = 0, j;
    130142  uint_t k;
    131   fvec_t * newmag = (fvec_t *)p->newmag;
    132   aubio_spectralcandidate_t ** scands =
    133     (aubio_spectralcandidate_t **)(p->candidates);
     143  fvec_t *newmag = (fvec_t *) p->newmag;
     144  aubio_spectralcandidate_t **scands =
     145      (aubio_spectralcandidate_t **) (p->candidates);
    134146  //smpl_t hfc; //fe=instfreq(theta1,theta,ops); //theta1=theta;
    135147  /* copy incoming grain to newmag */
    136   for (j=0; j< newmag->length; j++)
    137     newmag->data[i][j]=fftgrain->norm[i][j];
     148  for (j = 0; j < newmag->length; j++)
     149    newmag->data[i][j] = fftgrain->norm[i][j];
    138150  /* detect only if local energy > 10. */
    139   if (fvec_local_energy(newmag)>10.) {
     151  if (fvec_local_energy (newmag) > 10.) {
    140152    /* hfc = fvec_local_hfc(newmag); do not use */
    141     aubio_pitchmcomb_spectral_pp(p, newmag);
    142     aubio_pitchmcomb_combdet(p,newmag);
    143     aubio_pitchmcomb_sort_cand_freq(scands,p->ncand);
     153    aubio_pitchmcomb_spectral_pp (p, newmag);
     154    aubio_pitchmcomb_combdet (p, newmag);
     155    aubio_pitchmcomb_sort_cand_freq (scands, p->ncand);
    144156    /* store ncand comb energies in cands[1:ncand] */
    145     for (k = 0; k<p->ncand; k++)
     157    for (k = 0; k < p->ncand; k++)
    146158      cands[k] = p->candidates[k]->ene;
    147159    /* store ncand[end] freq in cands[end] */
    148     cands[p->ncand] = p->candidates[p->ncand-1]->ebin;
     160    cands[p->ncand] = p->candidates[p->ncand - 1]->ebin;
    149161    return 1;
    150162  } else {
    151     for (k = 0; k<p->ncand; k++)
     163    for (k = 0; k < p->ncand; k++)
    152164      cands[k] = 0;
    153165    return 0;
     
    155167}
    156168
    157 void aubio_pitchmcomb_spectral_pp(aubio_pitchmcomb_t * p, fvec_t * newmag) {
    158   fvec_t * mag = (fvec_t *)p->scratch;
    159   fvec_t * tmp = (fvec_t *)p->scratch2;
    160   uint_t i=0,j;
     169void
     170aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * newmag)
     171{
     172  fvec_t *mag = (fvec_t *) p->scratch;
     173  fvec_t *tmp = (fvec_t *) p->scratch2;
     174  uint_t i = 0, j;
    161175  uint_t length = mag->length;
    162176  /* copy newmag to mag (scracth) */
    163   for (j=0;j<length;j++) {
     177  for (j = 0; j < length; j++) {
    164178    mag->data[i][j] = newmag->data[i][j];
    165179  }
    166   fvec_min_removal(mag);              /* min removal          */
    167   fvec_alpha_normalise(mag,p->alpha); /* alpha normalisation  */
    168   /* skipped */                       /* low pass filtering   */
     180  fvec_min_removal (mag);       /* min removal          */
     181  fvec_alpha_normalise (mag, p->alpha); /* alpha normalisation  */
     182  /* skipped *//* low pass filtering   */
    169183  /** \bug fvec_moving_thres may write out of bounds */
    170   fvec_adapt_thres(mag,tmp,p->win_post,p->win_pre,i); /* adaptative threshold */
    171   fvec_add(mag,-p->threshold);        /* fixed threshold      */
     184  fvec_adapt_thres (mag, tmp, p->win_post, p->win_pre, i);      /* adaptative threshold */
     185  fvec_add (mag, -p->threshold);        /* fixed threshold      */
    172186  {
    173     aubio_spectralpeak_t * peaks = (aubio_spectralpeak_t *)p->peaks;
     187    aubio_spectralpeak_t *peaks = (aubio_spectralpeak_t *) p->peaks;
    174188    uint_t count;
    175189    /*  return bin and ebin */
    176     count = aubio_pitchmcomb_quadpick(peaks,mag);
    177     for (j=0;j<count;j++)
     190    count = aubio_pitchmcomb_quadpick (peaks, mag);
     191    for (j = 0; j < count; j++)
    178192      peaks[j].mag = newmag->data[i][peaks[j].bin];
    179193    /* reset non peaks */
    180     for (j=count;j<length;j++)
     194    for (j = count; j < length; j++)
    181195      peaks[j].mag = 0.;
    182196    p->peaks = peaks;
     
    185199}
    186200
    187 void aubio_pitchmcomb_combdet(aubio_pitchmcomb_t * p, fvec_t * newmag) {
    188   aubio_spectralpeak_t * peaks = (aubio_spectralpeak_t *)p->peaks;
    189   aubio_spectralcandidate_t ** candidate =
    190     (aubio_spectralcandidate_t **)p->candidates;
     201void
     202aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag)
     203{
     204  aubio_spectralpeak_t *peaks = (aubio_spectralpeak_t *) p->peaks;
     205  aubio_spectralcandidate_t **candidate =
     206      (aubio_spectralcandidate_t **) p->candidates;
    191207
    192208  /* parms */
    193   uint_t N = p->npartials; /* maximum number of partials to be considered 10 */
    194   uint_t M = p->ncand;  /* maximum number of combs to be considered 5 */
     209  uint_t N = p->npartials;      /* maximum number of partials to be considered 10 */
     210  uint_t M = p->ncand;          /* maximum number of combs to be considered 5 */
    195211  uint_t length = newmag->length;
    196212  uint_t count = p->count;
     
    209225
    210226  /* get the biggest peak in the spectrum */
    211   root_peak = aubio_pitchmcomb_get_root_peak(peaks,count);
     227  root_peak = aubio_pitchmcomb_get_root_peak (peaks, count);
    212228  /* not enough partials in highest notes, could be forced */
    213229  //if (peaks[root_peak].ebin >= aubio_miditofreq(85.)/p->tau) N=2;
    214230  //if (peaks[root_peak].ebin >= aubio_miditofreq(90.)/p->tau) N=1;
    215231  /* now calculate the energy of each of the 5 combs */
    216   for (l=0;l<M;l++) {
    217     smpl_t scaler = (1./(l+1.));
    218     candidate[l]->ene = 0.; /* reset ene and len sums */
     232  for (l = 0; l < M; l++) {
     233    smpl_t scaler = (1. / (l + 1.));
     234    candidate[l]->ene = 0.;     /* reset ene and len sums */
    219235    candidate[l]->len = 0.;
    220     candidate[l]->ebin=scaler*peaks[root_peak].ebin;
     236    candidate[l]->ebin = scaler * peaks[root_peak].ebin;
    221237    /* if less than N peaks available, curlen < N */
    222238    if (candidate[l]->ebin != 0.)
    223       curlen = (uint_t)FLOOR(length/(candidate[l]->ebin));
    224     curlen = (N < curlen )? N : curlen;
     239      curlen = (uint_t) FLOOR (length / (candidate[l]->ebin));
     240    curlen = (N < curlen) ? N : curlen;
    225241    /* fill candidate[l]->ecomb[k] with (k+1)*candidate[l]->ebin */
    226     for (k=0;k<curlen;k++)
    227       candidate[l]->ecomb[k]=(candidate[l]->ebin)*(k+1.);
    228     for (k=curlen;k<length;k++)
    229       candidate[l]->ecomb[k]=0.;
     242    for (k = 0; k < curlen; k++)
     243      candidate[l]->ecomb[k] = (candidate[l]->ebin) * (k + 1.);
     244    for (k = curlen; k < length; k++)
     245      candidate[l]->ecomb[k] = 0.;
    230246    /* for each in candidate[l]->ecomb[k] */
    231     for (k=0;k<curlen;k++) {
     247    for (k = 0; k < curlen; k++) {
    232248      xx = 100000.;
    233249      /** get the candidate->ecomb the closer to peaks.ebin
    234250       * (to cope with the inharmonicity)*/
    235       for (d=0;d<count;d++) {
    236         delta2 = ABS(candidate[l]->ecomb[k]-peaks[d].ebin);
     251      for (d = 0; d < count; d++) {
     252        delta2 = ABS (candidate[l]->ecomb[k] - peaks[d].ebin);
    237253        if (delta2 <= xx) {
    238254          position = d;
     
    242258      /* for a Q factor of 17, maintaining "constant Q filtering",
    243259       * and sum energy and length over non null combs */
    244       if ( 17. * xx < candidate[l]->ecomb[k] ) {
    245         candidate[l]->ecomb[k]=peaks[position].ebin;
    246         candidate[l]->ene += /* ecomb rounded to nearest int */
    247           POW(newmag->data[0][(uint_t)FLOOR(candidate[l]->ecomb[k]+.5)],0.25);
    248         candidate[l]->len += 1./curlen;
     260      if (17. * xx < candidate[l]->ecomb[k]) {
     261        candidate[l]->ecomb[k] = peaks[position].ebin;
     262        candidate[l]->ene +=    /* ecomb rounded to nearest int */
     263            POW (newmag->data[0][(uint_t) FLOOR (candidate[l]->ecomb[k] + .5)],
     264            0.25);
     265        candidate[l]->len += 1. / curlen;
    249266      } else
    250         candidate[l]->ecomb[k]=0.;
     267        candidate[l]->ecomb[k] = 0.;
    251268    }
    252269    /* punishment */
    253270    /*if (candidate[l]->len<0.6)
    254       candidate[l]->ene=0.; */
     271       candidate[l]->ene=0.; */
    255272    /* remember best candidate energy (in polyphonic, could check for
    256273     * tmpene*1.1 < candidate->ene to reduce jumps towards low frequencies) */
     
    270287 * \bug peak-picking too picky, sometimes counts too many peaks ?
    271288 */
    272 uint_t aubio_pitchmcomb_quadpick(aubio_spectralpeak_t * spectral_peaks, fvec_t * X){
     289uint_t
     290aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, fvec_t * X)
     291{
    273292  uint_t i, j, ispeak, count = 0;
    274   for (i=0;i<X->channels;i++)
    275     for (j=1;j<X->length-1;j++) {
    276       ispeak = fvec_peakpick(X,j);
     293  for (i = 0; i < X->channels; i++)
     294    for (j = 1; j < X->length - 1; j++) {
     295      ispeak = fvec_peakpick (X, j);
    277296      if (ispeak) {
    278297        count += ispeak;
    279         spectral_peaks[count-1].bin = j;
    280         spectral_peaks[count-1].ebin = fvec_quadint(X, j, i) - 1.;
     298        spectral_peaks[count - 1].bin = j;
     299        spectral_peaks[count - 1].ebin = fvec_quadint (X, j, i) - 1.;
    281300      }
    282301    }
     
    285304
    286305/* get predominant partial */
    287 uint_t aubio_pitchmcomb_get_root_peak(aubio_spectralpeak_t * peaks, uint_t length) {
    288   uint_t i,pos=0;
     306uint_t
     307aubio_pitchmcomb_get_root_peak (aubio_spectralpeak_t * peaks, uint_t length)
     308{
     309  uint_t i, pos = 0;
    289310  smpl_t tmp = 0.;
    290   for (i=0;i<length;i++)
     311  for (i = 0; i < length; i++)
    291312    if (tmp <= peaks[i].mag) {
    292313      pos = i;
     
    296317}
    297318
    298 void aubio_pitchmcomb_sort_peak(aubio_spectralpeak_t * peaks, uint_t nbins) {
    299   qsort(peaks, nbins, sizeof(aubio_spectralpeak_t),
     319void
     320aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins)
     321{
     322  qsort (peaks, nbins, sizeof (aubio_spectralpeak_t),
    300323      aubio_pitchmcomb_sort_peak_comp);
    301324}
    302 static sint_t aubio_pitchmcomb_sort_peak_comp(const void *x, const void *y) {
    303   return (((aubio_spectralpeak_t *)y)->mag - ((aubio_spectralpeak_t *)x)->mag);
    304 }
    305 
    306 
    307 void aubio_pitchmcomb_sort_cand_ene(aubio_spectralcandidate_t ** candidates, uint_t nbins) {
     325
     326static sint_t
     327aubio_pitchmcomb_sort_peak_comp (const void *x, const void *y)
     328{
     329  return (((aubio_spectralpeak_t *) y)->mag -
     330      ((aubio_spectralpeak_t *) x)->mag);
     331}
     332
     333
     334void
     335aubio_pitchmcomb_sort_cand_ene (aubio_spectralcandidate_t ** candidates,
     336    uint_t nbins)
     337{
    308338  uint_t cur = 0;
    309339  uint_t run = 0;
    310   for (cur=0;cur<nbins;cur++) {
     340  for (cur = 0; cur < nbins; cur++) {
    311341    run = cur + 1;
    312     for (run=cur;run<nbins;run++) {
    313       if(candidates[run]->ene > candidates[cur]->ene)
    314         CAND_SWAP(candidates[run], candidates[cur]);
    315     }
    316   }
    317 }
    318 
    319 
    320 void aubio_pitchmcomb_sort_cand_freq(aubio_spectralcandidate_t ** candidates, uint_t nbins) {
     342    for (run = cur; run < nbins; run++) {
     343      if (candidates[run]->ene > candidates[cur]->ene)
     344        CAND_SWAP (candidates[run], candidates[cur]);
     345    }
     346  }
     347}
     348
     349
     350void
     351aubio_pitchmcomb_sort_cand_freq (aubio_spectralcandidate_t ** candidates,
     352    uint_t nbins)
     353{
    321354  uint_t cur = 0;
    322355  uint_t run = 0;
    323   for (cur=0;cur<nbins;cur++) {
     356  for (cur = 0; cur < nbins; cur++) {
    324357    run = cur + 1;
    325     for (run=cur;run<nbins;run++) {
    326       if(candidates[run]->ebin < candidates[cur]->ebin)
    327         CAND_SWAP(candidates[run], candidates[cur]);
    328     }
    329   }
    330 }
    331 
    332 aubio_pitchmcomb_t * new_aubio_pitchmcomb(uint_t bufsize, uint_t hopsize, uint_t channels) {
    333   aubio_pitchmcomb_t * p = AUBIO_NEW(aubio_pitchmcomb_t);
     358    for (run = cur; run < nbins; run++) {
     359      if (candidates[run]->ebin < candidates[cur]->ebin)
     360        CAND_SWAP (candidates[run], candidates[cur]);
     361    }
     362  }
     363}
     364
     365aubio_pitchmcomb_t *
     366new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize, uint_t channels)
     367{
     368  aubio_pitchmcomb_t *p = AUBIO_NEW (aubio_pitchmcomb_t);
    334369  /* bug: should check if size / 8 > post+pre+1 */
    335370  uint_t i, j;
    336371  uint_t spec_size;
    337   p->spec_partition   = 4;
    338   p->ncand            = 5;
    339   p->npartials        = 5;
    340   p->cutoff           = 1.;
    341   p->threshold        = 0.01;
    342   p->win_post         = 8;
    343   p->win_pre          = 7;
     372  p->spec_partition = 4;
     373  p->ncand = 5;
     374  p->npartials = 5;
     375  p->cutoff = 1.;
     376  p->threshold = 0.01;
     377  p->win_post = 8;
     378  p->win_pre = 7;
    344379  // p->tau              = samplerate/bufsize;
    345   p->alpha            = 9.;
    346   p->goodcandidate    = 0;
    347   p->phasefreq        = bufsize/hopsize/TWO_PI;
    348   p->phasediff        = TWO_PI*hopsize/bufsize;
    349   spec_size = bufsize/p->spec_partition;
     380  p->alpha = 9.;
     381  p->goodcandidate = 0;
     382  p->phasefreq = bufsize / hopsize / TWO_PI;
     383  p->phasediff = TWO_PI * hopsize / bufsize;
     384  spec_size = bufsize / p->spec_partition;
    350385  //p->pickerfn = quadpick;
    351386  //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348);
    352387  /* allocate temp memory */
    353   p->newmag     = new_fvec(spec_size,1);
     388  p->newmag = new_fvec (spec_size, 1);
    354389  /* array for median */
    355   p->scratch    = new_fvec(spec_size,1);
     390  p->scratch = new_fvec (spec_size, 1);
    356391  /* array for phase */
    357   p->theta      = new_fvec(spec_size,channels);
     392  p->theta = new_fvec (spec_size, channels);
    358393  /* array for adaptative threshold */
    359   p->scratch2   = new_fvec(p->win_post+p->win_pre+1,1);
     394  p->scratch2 = new_fvec (p->win_post + p->win_pre + 1, 1);
    360395  /* array of spectral peaks */
    361   p->peaks      = AUBIO_ARRAY(aubio_spectralpeak_t,spec_size);
     396  p->peaks = AUBIO_ARRAY (aubio_spectralpeak_t, spec_size);
    362397  for (i = 0; i < spec_size; i++) {
    363398    p->peaks[i].bin = 0.;
     
    366401  }
    367402  /* array of pointers to spectral candidates */
    368   p->candidates = AUBIO_ARRAY(aubio_spectralcandidate_t *,p->ncand);
    369   for (i=0;i<p->ncand;i++) {
    370     p->candidates[i] = AUBIO_NEW(aubio_spectralcandidate_t);
    371     p->candidates[i]->ecomb = AUBIO_ARRAY(smpl_t, spec_size);
    372     for (j=0; j < spec_size; j++) {
     403  p->candidates = AUBIO_ARRAY (aubio_spectralcandidate_t *, p->ncand);
     404  for (i = 0; i < p->ncand; i++) {
     405    p->candidates[i] = AUBIO_NEW (aubio_spectralcandidate_t);
     406    p->candidates[i]->ecomb = AUBIO_ARRAY (smpl_t, spec_size);
     407    for (j = 0; j < spec_size; j++) {
    373408      p->candidates[i]->ecomb[j] = 0.;
    374409    }
     
    381416
    382417
    383 void del_aubio_pitchmcomb (aubio_pitchmcomb_t *p) {
     418void
     419del_aubio_pitchmcomb (aubio_pitchmcomb_t * p)
     420{
    384421  uint_t i;
    385   del_fvec(p->newmag);
    386   del_fvec(p->scratch);
    387   del_fvec(p->theta);
    388   del_fvec(p->scratch2);
    389   AUBIO_FREE(p->peaks);
    390   for (i=0;i<p->ncand;i++) {
    391     AUBIO_FREE(p->candidates[i]->ecomb);
    392     AUBIO_FREE(p->candidates[i]);
    393   }
    394   AUBIO_FREE(p->candidates);
    395   AUBIO_FREE(p);
    396 }
     422  del_fvec (p->newmag);
     423  del_fvec (p->scratch);
     424  del_fvec (p->theta);
     425  del_fvec (p->scratch2);
     426  AUBIO_FREE (p->peaks);
     427  for (i = 0; i < p->ncand; i++) {
     428    AUBIO_FREE (p->candidates[i]->ecomb);
     429    AUBIO_FREE (p->candidates[i]);
     430  }
     431  AUBIO_FREE (p->candidates);
     432  AUBIO_FREE (p);
     433}
Note: See TracChangeset for help on using the changeset viewer.