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 | # compute sinetone at floating point period | 32 | # compute sinetone at floating point period |
| 33 | for i in range(duration): | 33 | for i in range(duration): |
| 34 | x = int((i % period) / float(period) * tablelen) | 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 | # apply some envelope | 41 | # apply some envelope |
| 38 | float_ramp = arange(duration, dtype = 'float32') | 42 | float_ramp = arange(duration, dtype = 'float32') |
| 39 | sinetone *= exp( - e * float_ramp / duration / decay) | 43 | sinetone *= exp( - e * float_ramp / duration / decay) |
| 40 | sinetone[:attack] *= exp( e * ( float_ramp[:attack] / attack - 1 ) ) | 44 | sinetone[:attack] *= exp( e * ( float_ramp[:attack] / attack - 1 ) ) |
| 41 | 45 | ||
| 42 | if 0: | 46 | if 1: |
| 43 | import matplotlib.pyplot as plt | 47 | import matplotlib.pyplot as plt |
| 44 | plt.plot(sinetone) | 48 | plt.plot(sinetone) |
| 45 | plt.show() | 49 | plt.show() |