forked from nick-thompson/dsp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
50 lines (39 loc) · 1.69 KB
/
plot.py
File metadata and controls
50 lines (39 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import matplotlib.pyplot as plt
import numpy as np
import wavetable.wavetable as wt
from math import floor
from wavetable.oscillators import StandardOscillator, ResamplingOscillator, RealTimeResamplingOscillator
from wavetable.utils import normalize, trim
# First, a comparison of the two wave tables. The first is our standard
# wavetable, the second uses sigma approximation to attenuate the Gibbs
# phenomenon.
x = np.linspace(0, 1, num=wt.TABLE_SIZE, dtype='d')
plt.figure()
plt.subplot(121)
plt.plot(x, map(wt.get, range(0, wt.TABLE_SIZE)))
plt.subplot(122)
plt.plot(x, map(lambda x: wt.get(x, gibbs=True), range(0, wt.TABLE_SIZE)))
plt.show()
# Next, we'll show the difference in the waveform produced by using resampling
# to apply detune when played next to a similar waveform vs. what I assume is
# the standard method of applying detune, as described in the oscillators file.
_x = np.linspace(0, 44100 * 4, 44100 * 4)
ss = np.zeros(44100 * 4, dtype='d')
StandardOscillator(43.65, 0.0, 0.5).render(ss)
StandardOscillator(43.65, 3.0, 0.5).render(ss)
rs = np.zeros(44100 * 4, dtype='d')
StandardOscillator(43.65, 0.0, 0.5).render(rs)
ResamplingOscillator(43.65, 3.0, 0.5).render(rs)
plt.plot(_x, normalize(trim(rs - ss, pow(2, 3 / 1200.0))))
plt.show()
# Now, to show that we can introduce the same artifacts in real time, we'll
# show that the output of the ResamplingOscillator and the
# RealTimeResamplingOscillator are actually the same.
rs = np.zeros(44100 * 4, dtype='d')
ResamplingOscillator(43.65, 3.0, 1.0).render(rs)
rt = np.zeros(44100 * 4, dtype='d')
RealTimeResamplingOscillator(43.65, 3.0, 1.0).render(rt)
trim(rt, pow(2, 3 / 1200.0))
assert np.allclose(rs, rt)
plt.plot(_x, rs - rt)
plt.show()