ref: 8247249d64130dfb06b5c0d206456439f17f5282
parent: dc467b5d5a7c321235d4defb3ce8541e70460fc9
author: Paul Brossier <piem@piem.org>
date: Sun Oct 27 19:36:06 EDT 2013
src/synth/wavetable.c: fix frequency interpolation, add amp to do_multi
--- a/src/synth/wavetable.c
+++ b/src/synth/wavetable.c
@@ -85,8 +85,10 @@
if (s->playing) {
smpl_t pos = s->last_pos;
for (i = 0; i < output->length; i++) {
- if (s->freq != s->target_freq)
+ if ( ABS(s->freq - s->target_freq) > ABS(s->inc_freq) )
s->freq += s->inc_freq;
+ else
+ s->freq = s->target_freq;
smpl_t inc = s->freq * (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate);
pos += inc;
while (pos > s->wavetable_length) {
@@ -116,15 +118,21 @@
if (s->playing) {
smpl_t pos = s->last_pos;
for (j = 0; j < output->length; j++) {
- if (s->freq != s->target_freq)
+ if ( ABS(s->freq - s->target_freq) > ABS(s->inc_freq) )
s->freq += s->inc_freq;
+ else
+ s->freq = s->target_freq;
smpl_t inc = s->freq * (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate);
pos += inc;
while (pos > s->wavetable_length) {
pos -= s->wavetable_length;
}
+ if ( ABS(s->amp - s->target_amp) > ABS(s->inc_amp) )
+ s->amp += s->inc_amp;
+ else
+ s->amp = s->target_amp;
for (i = 0; i < output->height; i++) {
- output->data[i][j] = interp_2(s->wavetable, pos);
+ output->data[i][j] = s->amp * interp_2(s->wavetable, pos);
}
}
s->last_pos = pos;