Changeset fc61225
- Timestamp:
- Dec 4, 2009, 1:43:29 AM (15 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:
- 168337e
- Parents:
- 8e5c051
- Location:
- src/utils
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/utils/hist.c
r8e5c051 rfc61225 32 32 fvec_t * hist; 33 33 uint_t nelems; 34 uint_t channels;35 34 fvec_t * cent; 36 35 aubio_scale_t *scaler; … … 40 39 * Object creation/deletion calls 41 40 */ 42 aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems , uint_t channels){41 aubio_hist_t * new_aubio_hist (smpl_t ilow, smpl_t ihig, uint_t nelems){ 43 42 aubio_hist_t * s = AUBIO_NEW(aubio_hist_t); 44 43 smpl_t step = (ihig-ilow)/(smpl_t)(nelems); 45 44 smpl_t accum = step; 46 45 uint_t i; 47 s->channels = channels;48 46 s->nelems = nelems; 49 s->hist = new_fvec(nelems , channels);50 s->cent = new_fvec(nelems , 1);47 s->hist = new_fvec(nelems); 48 s->cent = new_fvec(nelems); 51 49 52 50 /* use scale to map ilow/ihig -> 0/nelems */ 53 51 s->scaler = new_aubio_scale(ilow,ihig,0,nelems); 54 52 /* calculate centers now once */ 55 s->cent->data[0] [0]= ilow + 0.5 * step;53 s->cent->data[0] = ilow + 0.5 * step; 56 54 for (i=1; i < s->nelems; i++, accum+=step ) 57 s->cent->data[ 0][i] = s->cent->data[0][0] + accum;55 s->cent->data[i] = s->cent->data[0] + accum; 58 56 59 57 return s; … … 71 69 */ 72 70 void aubio_hist_do (aubio_hist_t *s, fvec_t *input) { 73 uint_t i,j;71 uint_t j; 74 72 sint_t tmp = 0; 75 73 aubio_scale_do(s->scaler, input); 76 74 /* reset data */ 77 for (i=0; i < s->channels; i++) 78 for (j=0; j < s->nelems; j++) 79 s->hist->data[i][j] = 0; 75 fvec_zeros(s->hist); 80 76 /* run accum */ 81 for (i=0; i < input->channels; i++) 82 for (j=0; j < input->length; j++) 83 { 84 tmp = (sint_t)FLOOR(input->data[i][j]); 85 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 86 s->hist->data[i][tmp] += 1; 77 for (j=0; j < input->length; j++) 78 { 79 tmp = (sint_t)FLOOR(input->data[j]); 80 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) { 81 s->hist->data[tmp] += 1; 87 82 } 83 } 88 84 } 89 85 90 86 void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) { 91 uint_t i,j;87 uint_t j; 92 88 sint_t tmp = 0; 93 89 aubio_scale_do(s->scaler, input); 94 90 /* reset data */ 95 for (i=0; i < s->channels; i++) 96 for (j=0; j < s->nelems; j++) 97 s->hist->data[i][j] = 0; 91 fvec_zeros(s->hist); 98 92 /* run accum */ 99 for (i=0; i < input->channels; i++) 100 for (j=0; j < input->length; j++) { 101 if (input->data[i][j] != 0) { 102 tmp = (sint_t)FLOOR(input->data[i][j]); 103 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 104 s->hist->data[i][tmp] += 1; 105 } 93 for (j=0; j < input->length; j++) { 94 if (input->data[j] != 0) { 95 tmp = (sint_t)FLOOR(input->data[j]); 96 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 97 s->hist->data[tmp] += 1; 106 98 } 99 } 107 100 } 108 101 109 102 110 103 void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) { 111 uint_t i ,j;104 uint_t i; 112 105 sint_t tmp = 0; 113 106 smpl_t ilow = fvec_min(input); … … 119 112 120 113 /* recalculate centers */ 121 s->cent->data[0] [0]= ilow + 0.5f * step;114 s->cent->data[0] = ilow + 0.5f * step; 122 115 for (i=1; i < s->nelems; i++) 123 s->cent->data[ 0][i] = s->cent->data[0][0] + i * step;116 s->cent->data[i] = s->cent->data[0] + i * step; 124 117 125 118 /* scale */ … … 127 120 128 121 /* reset data */ 129 for (i=0; i < s->channels; i++) 130 for (j=0; j < s->nelems; j++) 131 s->hist->data[i][j] = 0; 122 fvec_zeros(s->hist); 132 123 /* run accum */ 133 for (i=0; i < input->channels; i++) 134 for (j=0; j < input->length; j++) { 135 if (input->data[i][j] != 0) { 136 tmp = (sint_t)FLOOR(input->data[i][j]); 137 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 138 s->hist->data[i][tmp] += 1; 139 } 124 for (i=0; i < input->length; i++) { 125 if (input->data[i] != 0) { 126 tmp = (sint_t)FLOOR(input->data[i]); 127 if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) 128 s->hist->data[tmp] += 1; 140 129 } 130 } 141 131 } 142 132 143 133 void aubio_hist_weight (aubio_hist_t *s) { 144 uint_t i,j; 145 for (i=0; i < s->channels; i++) 146 for (j=0; j < s->nelems; j++) { 147 s->hist->data[i][j] *= s->cent->data[0][j]; 148 } 134 uint_t j; 135 for (j=0; j < s->nelems; j++) { 136 s->hist->data[j] *= s->cent->data[j]; 137 } 149 138 } 150 139 151 140 smpl_t aubio_hist_mean (aubio_hist_t *s) { 152 uint_t i,j;141 uint_t j; 153 142 smpl_t tmp = 0.0; 154 for (i=0; i < s->channels; i++) 155 for (j=0; j < s->nelems; j++) 156 tmp += s->hist->data[i][j]; 143 for (j=0; j < s->nelems; j++) 144 tmp += s->hist->data[j]; 157 145 return tmp/(smpl_t)(s->nelems); 158 146 } -
src/utils/hist.h
r8e5c051 rfc61225 40 40 * \param fhig maximum input 41 41 * \param nelems number of histogram columns 42 * \param channels number of channels43 42 */ 44 aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems , uint_t channels);43 aubio_hist_t * new_aubio_hist(smpl_t flow, smpl_t fhig, uint_t nelems); 45 44 /** histogram deletion */ 46 45 void del_aubio_hist(aubio_hist_t *s); -
src/utils/scale.c
r8e5c051 rfc61225 70 70 void aubio_scale_do (aubio_scale_t *s, fvec_t *input) 71 71 { 72 uint_t i, j; 73 for (i=0; i < input->channels; i++){ 74 for (j=0; j < input->length; j++){ 75 input->data[i][j] -= s->ilow; 76 input->data[i][j] *= s->scaler; 77 input->data[i][j] += s->olow; 78 } 72 uint_t j; 73 for (j=0; j < input->length; j++){ 74 input->data[j] -= s->ilow; 75 input->data[j] *= s->scaler; 76 input->data[j] += s->olow; 79 77 } 80 78 }
Note: See TracChangeset
for help on using the changeset viewer.