ref: 7b14564af92177533bbdd185c9132671cabbeee0
parent: 8a7e87558610cfae970067562645a3d774b2b142
author: robs <robs>
date: Sun Nov 16 10:50:15 EST 2008
interpolate for accurate pitch
--- a/scripts/synth.sh
+++ b/scripts/synth.sh
@@ -24,20 +24,20 @@
A1="pl %-17 pl %-12 pl %-9 pl %-5 pl %0 pl %4"
B1="pl %-15 pl %-10 pl %-7 pl %-3 pl %2 pl %6"
-e="delay 0 .02 .04 .06 .08 .1 remix - overdrive 40 gain -10 fade 0"
+e="delay 0 .02 .04 .06 .08 .1 remix - overdrive 40 gain -11 fade 0"
s="$sox -q -n -p synth 0 0 0 80 87"
-$play -m \
+$play -m -v .8 \
"|$sox \
\"|$sox -n -p synth noise fade 0 .5 .48 trim 0 .15\" \
\"|$sox -n -p synth noise fade h 0 .26 .11 gain -35 lowpass -1 12k\" \
--p splice .15,.06,0 gain -14 lowpass -1 12k highpass -1 9k \
+-p splice .15,.06,0 gain -15 lowpass -1 12k highpass -1 9k \
equalizer 14k 1.3 13 \
equalizer 9500 10 8 \
equalizer 7000 10 8 \
equalizer 5200 10 8 \
equalizer 3800 10 8 \
-equalizer 1500 10 8 pad 0 .21 remix 1 1 repeat 72" \
+equalizer 1500 10 8 pad 0 .21 remix 1 1 reverb 20 repeat 72" \
"|$sox \
\"|$sox -n -p trim 0 1.4\" \
\"|$s $A0 $e 4 .1 bend .4,+200,.3\" \
--- a/src/synth.c
+++ b/src/synth.c
@@ -159,8 +159,9 @@
double cycle_start_time_s;
double last_out;
PinkNoise pink_noise;
- float *buffer;
- size_t buffer_len;
+
+ double * buffer;
+ size_t buffer_len, pos, dx, dy, acc;
} channel_t;
@@ -394,10 +395,13 @@
set_default_parameters(chan, i);
if (chan->type == synth_pluck) {
int32_t r = 0;
- float colour = pow(2., 4 * (chan->p2 - 1));
- float dc = 0, a = 6.9 / (chan->p2 < .25? chan->p2 / .25 * 11 + 7 :
+ double colour = pow(2., 4 * (chan->p2 - 1));
+ double dc = 0, a = 6.9 / (chan->p2 < .25? chan->p2 / .25 * 11 + 7 :
chan->p2 <= .55? 18 : (1-chan->p2) / .45 * 3 + 15);
chan->buffer_len = effp->in_signal.rate / chan->freq + .5;
+ chan->dx = chan->freq * 1000 + .5;
+ chan->dy = effp->in_signal.rate / chan->buffer_len * 1000 + .5;
+ chan->pos = chan->acc = 0;
chan->buffer = malloc(chan->buffer_len * sizeof(*chan->buffer));
chan->buffer[0] = 0;
for (j = 1; j < chan->buffer_len; dc += chan->buffer[j++])
@@ -584,10 +588,16 @@
break;
case synth_pluck: {
- size_t j = synth->samples_done % chan->buffer_len;
- synth_out = chan->buffer[j];
- chan->buffer[j] = chan->p3 * (synth_out + chan->last_out);
- chan->last_out = synth_out;
+ size_t pos1 = chan->pos + 1 == chan->buffer_len? 0 : chan->pos + 1;
+ double t = (double)chan->acc / chan->dy;
+ synth_out = chan->buffer[chan->pos] * (1-t) + chan->buffer[pos1] * t;
+ for (chan->acc+=chan->dx; chan->acc>=chan->dy; chan->acc-=chan->dy) {
+ t = chan->buffer[chan->pos];
+ chan->buffer[chan->pos] =
+ chan->p3 * (chan->buffer[chan->pos] + chan->last_out);
+ chan->last_out = t;
+ chan->pos = chan->pos + 1 == chan->buffer_len? 0 : chan->pos + 1;
+ }
break;
}