python/demos/demo_sink_create_woodblock.py: fix wavetable
authorPaul Brossier <piem@piem.org>
Wed, 20 Nov 2013 01:50:37 +0000 (02:50 +0100)
committerPaul Brossier <piem@piem.org>
Wed, 20 Nov 2013 01:50:37 +0000 (02:50 +0100)
python/demos/demo_sink_create_woodblock.py

index 398c41e..2c06a5f 100755 (executable)
@@ -32,14 +32,18 @@ sinetone = zeros((duration,), dtype = 'float32')
 # compute sinetone at floating point period
 for i in range(duration):
     x = int((i % period) / float(period) * tablelen)
-    sinetone[i] = (sinetable[x] + sinetable[x+1]) / 2
+    idx = int(x)
+    frac = x - idx
+    a = sinetable[idx]
+    b = sinetable[idx + 1]
+    sinetone[i] = a + frac * (b -a)
 
 # apply some envelope
 float_ramp = arange(duration, dtype = 'float32')
 sinetone *= exp( - e * float_ramp / duration / decay)
 sinetone[:attack] *= exp( e * ( float_ramp[:attack] / attack - 1 ) )
 
-if 0:
+if 1:
     import matplotlib.pyplot as plt
     plt.plot(sinetone)
     plt.show()