Changeset c2e0aef for src/synth/wavetable.c
- Timestamp:
- Oct 28, 2013, 12:16:11 AM (11 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:
- 509e8f9
- Parents:
- 650cae3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/synth/wavetable.c
r650cae3 rc2e0aef 24 24 #include "fvec.h" 25 25 #include "fmat.h" 26 #include " io/source.h"26 #include "utils/parameter.h" 27 27 #include "synth/wavetable.h" 28 28 … … 37 37 smpl_t last_pos; 38 38 39 smpl_t target_freq; 40 smpl_t freq; 41 smpl_t inc_freq; 42 43 smpl_t target_amp; 44 smpl_t amp; 45 smpl_t inc_amp; 39 aubio_parameter_t *freq; 40 aubio_parameter_t *amp; 46 41 }; 47 42 … … 62 57 s->playing = 0; 63 58 s->last_pos = 0.; 64 s->freq = 0.; 65 s->target_freq = 0.; 66 s->inc_freq = 0.; 67 68 s->amp = 0.; 69 s->target_amp = 0.; 70 s->inc_amp = 0.; 59 s->freq = new_aubio_parameter( 0., s->samplerate / 2., 10 ); 60 s->amp = new_aubio_parameter( 0., 1., 100 ); 71 61 return s; 72 62 } … … 86 76 smpl_t pos = s->last_pos; 87 77 for (i = 0; i < output->length; i++) { 88 if ( ABS(s->freq - s->target_freq) > ABS(s->inc_freq) ) 89 s->freq += s->inc_freq; 90 else 91 s->freq = s->target_freq; 92 smpl_t inc = s->freq * (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate); 78 smpl_t inc = aubio_parameter_get_next_value( s->freq ); 79 inc *= (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate); 93 80 pos += inc; 94 81 while (pos > s->wavetable_length) { 95 82 pos -= s->wavetable_length; 96 83 } 97 if ( ABS(s->amp - s->target_amp) > ABS(s->inc_amp) ) 98 s->amp += s->inc_amp; 99 else 100 s->amp = s->target_amp; 101 output->data[i] = s->amp * interp_2(s->wavetable, pos); 84 output->data[i] = aubio_parameter_get_next_value ( s->amp ); 85 output->data[i] *= interp_2(s->wavetable, pos); 102 86 } 103 87 s->last_pos = pos; 104 88 } else { 89 for (i = 0; i < output->length; i++) { 90 aubio_parameter_get_next_value ( s->freq ); 91 aubio_parameter_get_next_value ( s->amp ); 92 } 105 93 fvec_set(output, 0.); 106 94 } … … 119 107 smpl_t pos = s->last_pos; 120 108 for (j = 0; j < output->length; j++) { 121 if ( ABS(s->freq - s->target_freq) > ABS(s->inc_freq) ) 122 s->freq += s->inc_freq; 123 else 124 s->freq = s->target_freq; 125 smpl_t inc = s->freq * (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate); 109 smpl_t inc = aubio_parameter_get_next_value( s->freq ); 110 inc *= (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate); 126 111 pos += inc; 127 112 while (pos > s->wavetable_length) { 128 113 pos -= s->wavetable_length; 129 114 } 130 if ( ABS(s->amp - s->target_amp) > ABS(s->inc_amp) ) 131 s->amp += s->inc_amp; 132 else 133 s->amp = s->target_amp; 115 smpl_t amp = aubio_parameter_get_next_value ( s->amp ); 134 116 for (i = 0; i < output->height; i++) { 135 output->data[i][j] = s->amp * interp_2(s->wavetable, pos);117 output->data[i][j] = amp * interp_2(s->wavetable, pos); 136 118 } 137 119 } … … 139 121 } else { 140 122 for (j = 0; j < output->length; j++) { 141 if (s->freq != s->target_freq)142 s->freq += s->inc_freq;123 aubio_parameter_get_next_value ( s->freq ); 124 aubio_parameter_get_next_value ( s->amp ); 143 125 } 144 126 fmat_set(output, 0.); … … 181 163 uint_t aubio_wavetable_set_freq ( aubio_wavetable_t * s, smpl_t freq ) 182 164 { 183 if (freq >= 0 && freq < s->samplerate / 2.) { 184 uint_t steps = 10; 185 s->inc_freq = (freq - s->freq) / steps; 186 s->target_freq = freq; 187 return 0; 188 } else { 189 return 1; 190 } 165 return aubio_parameter_set_target_value ( s->freq, freq ); 191 166 } 192 167 193 168 smpl_t aubio_wavetable_get_freq ( aubio_wavetable_t * s) { 194 return s->freq;169 return aubio_parameter_get_current_value ( s->freq); 195 170 } 196 171 197 172 uint_t aubio_wavetable_set_amp ( aubio_wavetable_t * s, smpl_t amp ) 198 173 { 199 AUBIO_MSG("amp: %f, s->amp: %f, target_amp: %f, inc_amp: %f\n", 200 amp, s->amp, s->target_amp, s->inc_amp); 201 if (amp >= 0. && amp < 1.) { 202 uint_t steps = 100; 203 s->inc_amp = (amp - s->amp) / steps; 204 s->target_amp = amp; 205 AUBIO_ERR("amp: %f, s->amp: %f, target_amp: %f, inc_amp: %f\n", 206 amp, s->amp, s->target_amp, s->inc_amp); 207 return 0; 208 } else { 209 return 1; 210 } 174 return aubio_parameter_set_target_value ( s->amp, amp ); 211 175 } 212 176 213 177 smpl_t aubio_wavetable_get_amp ( aubio_wavetable_t * s) { 214 return s->amp;178 return aubio_parameter_get_current_value ( s->amp ); 215 179 } 216 180
Note: See TracChangeset
for help on using the changeset viewer.