Changeset c078336 for src


Ignore:
Timestamp:
Jun 3, 2005, 2:57:52 AM (19 years ago)
Author:
Paul Brossier <piem@altern.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:
8e8bc50
Parents:
21cc311
Message:

completed pitchdetection wrapper, moved to function pointers

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/pitchdetection.c

    r21cc311 rc078336  
    2121#include "phasevoc.h"
    2222#include "mathutils.h"
    23 #include "filter.h"
     23//#include "filter.h"
     24#include "pitchmcomb.h"
    2425#include "pitchyin.h"
    25 #include "pitchmcomb.h"
     26#include "pitchfcomb.h"
     27#include "pitchschmitt.h"
    2628#include "pitchdetection.h"
     29
     30typedef smpl_t (*aubio_pitchdetection_func_t)(aubio_pitchdetection_t *p,
     31                fvec_t * ibuf);
    2732
    2833struct _aubio_pitchdetection_t {
     
    3540        cvec_t * fftgrain;
    3641        aubio_pitchmcomb_t * mcomb;
    37         aubio_filter_t * filter;
     42        aubio_pitchfcomb_t * fcomb;
     43        aubio_pitchschmitt_t * schmitt;
     44        //aubio_filter_t * filter;
    3845        /* for yin */
    3946        fvec_t * buf;
    4047        fvec_t * yin;
     48        aubio_pitchdetection_func_t callback;
    4149};
    4250
     
    5664                        p->buf      = new_fvec(bufsize,channels);
    5765                        p->yin      = new_fvec(bufsize/2,channels);
     66                        p->callback = aubio_pitchdetection_yin;
    5867                        break;
    5968                case aubio_mcomb:
    6069                        p->pv       = new_aubio_pvoc(bufsize, hopsize, channels);
    6170                        p->fftgrain = new_cvec(bufsize, channels);
    62                         p->filter   = new_aubio_adsgn_filter((smpl_t)samplerate);
    6371                        p->mcomb    = new_aubio_pitchmcomb(bufsize,channels);
     72                        p->callback = aubio_pitchdetection_mcomb;
    6473                        break;
    65                 default:
    66                         break;
     74                case aubio_fcomb:
     75                        p->fcomb    = new_aubio_pitchfcomb(bufsize,samplerate);
     76                        p->callback = aubio_pitchdetection_fcomb;
     77                        break;
     78                case aubio_schmitt:
     79                        p->schmitt  = new_aubio_pitchschmitt(bufsize,samplerate);
     80                        p->callback = aubio_pitchdetection_mcomb;
     81                        break;
     82                default:
     83                        break;
    6784        }
    6885        return p;
     
    7895                        del_aubio_pvoc(p->pv);
    7996                        del_cvec(p->fftgrain);
    80                         //del_aubio_adsgn_filter(p->filter);
    81                         //del_aubio_pitchmcomb(p->mcomb);
     97                        del_aubio_pitchmcomb(p->mcomb);
    8298                        break;
     99                case aubio_schmitt:
     100                        del_aubio_pitchschmitt(p->schmitt);
     101                        break;
     102                case aubio_fcomb:
     103                        del_aubio_pitchfcomb(p->fcomb);
     104                        break;
    83105                default:
    84106                        break;
     
    87109}
    88110
    89 /** \bug ugly, should replace with function pointers or so */
    90111smpl_t aubio_pitchdetection(aubio_pitchdetection_t *p, fvec_t * ibuf) {
     112        return p->callback(p,ibuf);
     113}
     114
     115smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t *ibuf) {
     116        smpl_t pitch = 0.;
     117        aubio_pvoc_do(p->pv,ibuf,p->fftgrain);
     118        pitch = aubio_pitchmcomb_detect(p->mcomb,p->fftgrain);
     119        /** \bug should move the >0 check within bintofreq */
     120        if (pitch>0.) {
     121                pitch = bintofreq(pitch,p->srate,p->bufsize);
     122        } else {
     123                pitch = 0.;
     124        }
     125        return pitch;
     126}
     127
     128smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf) {
    91129        smpl_t pitch = 0.;
    92130        uint_t i,j = 0, overlap_size = 0;
    93         switch(p->type) {
    94                 case aubio_yin:
    95                         overlap_size = p->buf->length-ibuf->length;
    96                         /* do sliding window blocking */
    97                         for (i=0;i<p->buf->channels;i++){
    98                                 for (j=0;j<overlap_size;j++){
    99                                         p->buf->data[i][j] =
    100                                                 p->buf->data[i][j+ibuf->length];
    101                                 }
    102                         }
    103                         for (i=0;i<ibuf->channels;i++){
    104                                 for (j=0;j<ibuf->length;j++){
    105                                         p->buf->data[i][j+overlap_size] =
    106                                                 ibuf->data[i][j];
    107                                 }
    108                         }
    109                         pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, 0.5);
    110                         if (pitch>0) {
    111                                 pitch = p->srate/(pitch+0.);
    112                         } else {
    113                                 pitch = 0.;
    114                         }
    115                         break;
    116                 case aubio_mcomb:
    117                         aubio_filter_do(p->filter,ibuf);
    118                         aubio_filter_do(p->filter,ibuf);
    119                         aubio_pvoc_do(p->pv,ibuf,p->fftgrain);
    120                         pitch = aubio_pitchmcomb_detect(p->mcomb,p->fftgrain);
    121                         if (pitch>0.) {
    122                                 pitch = bintofreq(pitch,p->srate,p->bufsize);
    123                         } else {
    124                                 pitch = 0.;
    125                         }
    126                         break;
    127                 default:
    128                         break;
    129         }
    130         return pitch;
     131        overlap_size = p->buf->length-ibuf->length;
     132        /* do sliding window blocking */
     133        for (i=0;i<p->buf->channels;i++){
     134                for (j=0;j<overlap_size;j++){
     135                        p->buf->data[i][j] =
     136                                p->buf->data[i][j+ibuf->length];
     137                }
     138        }
     139        for (i=0;i<ibuf->channels;i++){
     140                for (j=0;j<ibuf->length;j++){
     141                        p->buf->data[i][j+overlap_size] =
     142                                ibuf->data[i][j];
     143                }
     144        }
     145        pitch = aubio_pitchyin_getpitchfast(p->buf,p->yin, 0.5);
     146        if (pitch>0) {
     147                pitch = p->srate/(pitch+0.);
     148        } else {
     149                pitch = 0.;
     150        }
     151        return pitch;
    131152}
     153
     154
     155smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf){
     156        return aubio_pitchfcomb_detect(p->fcomb,ibuf);
     157}
     158
     159smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf){
     160        return aubio_pitchschmitt_detect(p->schmitt,ibuf);
     161}
  • src/pitchdetection.h

    r21cc311 rc078336  
    2626typedef enum {
    2727        aubio_yin,
    28         aubio_mcomb
     28        aubio_mcomb,
     29        aubio_schmitt,
     30        aubio_fcomb
    2931} aubio_pitchdetection_type;
    3032
     
    3941       
    4042smpl_t aubio_pitchdetection(aubio_pitchdetection_t * p, fvec_t * ibuf);
     43smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t * ibuf);
     44smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf);
     45smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf);
     46smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf);
    4147
    4248void del_aubio_pitchdetection(aubio_pitchdetection_t * p);
Note: See TracChangeset for help on using the changeset viewer.