Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -32,14 +32,18 @@ sinetone = zeros((duration,), dtype = 'float32') · 31 unmodified lines | ||
| 32 | 32 | # compute sinetone at floating point period |
| 33 | 33 | for i in range(duration): |
| 34 | 34 | x = int((i % period) / float(period) * tablelen) |
| 35 | − sinetone[i] = (sinetable[x] + sinetable[x+1]) / 2 | |
| 35 | + idx = int(x) | |
| 36 | + frac = x - idx | |
| 37 | + a = sinetable[idx] | |
| 38 | + b = sinetable[idx + 1] | |
| 39 | + sinetone[i] = a + frac * (b -a) | |
| 36 | 40 | |
| 37 | 41 | # apply some envelope |
| 38 | 42 | float_ramp = arange(duration, dtype = 'float32') |
| 39 | 43 | sinetone *= exp( - e * float_ramp / duration / decay) |
| 40 | 44 | sinetone[:attack] *= exp( e * ( float_ramp[:attack] / attack - 1 ) ) |
| 41 | 45 | |
| 42 | −if 0: | |
| 46 | +if 1: | |
| 43 | 47 | import matplotlib.pyplot as plt |
| 44 | 48 | plt.plot(sinetone) |
| 45 | 49 | plt.show() |