Changeset c078336
- Timestamp:
- Jun 3, 2005, 2:57:52 AM (20 years ago)
- 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
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/pitchdetection.c
r21cc311 rc078336 21 21 #include "phasevoc.h" 22 22 #include "mathutils.h" 23 #include "filter.h" 23 //#include "filter.h" 24 #include "pitchmcomb.h" 24 25 #include "pitchyin.h" 25 #include "pitchmcomb.h" 26 #include "pitchfcomb.h" 27 #include "pitchschmitt.h" 26 28 #include "pitchdetection.h" 29 30 typedef smpl_t (*aubio_pitchdetection_func_t)(aubio_pitchdetection_t *p, 31 fvec_t * ibuf); 27 32 28 33 struct _aubio_pitchdetection_t { … … 35 40 cvec_t * fftgrain; 36 41 aubio_pitchmcomb_t * mcomb; 37 aubio_filter_t * filter; 42 aubio_pitchfcomb_t * fcomb; 43 aubio_pitchschmitt_t * schmitt; 44 //aubio_filter_t * filter; 38 45 /* for yin */ 39 46 fvec_t * buf; 40 47 fvec_t * yin; 48 aubio_pitchdetection_func_t callback; 41 49 }; 42 50 … … 56 64 p->buf = new_fvec(bufsize,channels); 57 65 p->yin = new_fvec(bufsize/2,channels); 66 p->callback = aubio_pitchdetection_yin; 58 67 break; 59 68 case aubio_mcomb: 60 69 p->pv = new_aubio_pvoc(bufsize, hopsize, channels); 61 70 p->fftgrain = new_cvec(bufsize, channels); 62 p->filter = new_aubio_adsgn_filter((smpl_t)samplerate);63 71 p->mcomb = new_aubio_pitchmcomb(bufsize,channels); 72 p->callback = aubio_pitchdetection_mcomb; 64 73 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; 67 84 } 68 85 return p; … … 78 95 del_aubio_pvoc(p->pv); 79 96 del_cvec(p->fftgrain); 80 //del_aubio_adsgn_filter(p->filter); 81 //del_aubio_pitchmcomb(p->mcomb); 97 del_aubio_pitchmcomb(p->mcomb); 82 98 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; 83 105 default: 84 106 break; … … 87 109 } 88 110 89 /** \bug ugly, should replace with function pointers or so */90 111 smpl_t aubio_pitchdetection(aubio_pitchdetection_t *p, fvec_t * ibuf) { 112 return p->callback(p,ibuf); 113 } 114 115 smpl_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 128 smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf) { 91 129 smpl_t pitch = 0.; 92 130 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; 131 152 } 153 154 155 smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf){ 156 return aubio_pitchfcomb_detect(p->fcomb,ibuf); 157 } 158 159 smpl_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 26 26 typedef enum { 27 27 aubio_yin, 28 aubio_mcomb 28 aubio_mcomb, 29 aubio_schmitt, 30 aubio_fcomb 29 31 } aubio_pitchdetection_type; 30 32 … … 39 41 40 42 smpl_t aubio_pitchdetection(aubio_pitchdetection_t * p, fvec_t * ibuf); 43 smpl_t aubio_pitchdetection_mcomb(aubio_pitchdetection_t *p, fvec_t * ibuf); 44 smpl_t aubio_pitchdetection_yin(aubio_pitchdetection_t *p, fvec_t *ibuf); 45 smpl_t aubio_pitchdetection_schmitt(aubio_pitchdetection_t *p, fvec_t *ibuf); 46 smpl_t aubio_pitchdetection_fcomb(aubio_pitchdetection_t *p, fvec_t *ibuf); 41 47 42 48 void del_aubio_pitchdetection(aubio_pitchdetection_t * p);
Note: See TracChangeset
for help on using the changeset viewer.