File: crystalizer.py

package info (click to toggle)
pulseeffects 4.8.7-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,952 kB
  • sloc: cpp: 18,501; xml: 3,821; sh: 228; python: 56; makefile: 4
file content (65 lines) | stat: -rwxr-xr-x 1,489 bytes parent folder | download | duplicates (6)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3

import numpy as np
import matplotlib.pyplot as plt
import scipy.io.wavfile as wavefile

rate, wave = wavefile.read('test.wav')

wave_y = wave[14000:15000]
wave_x = np.arange(wave_y.size)

t = wave_x
original = wave_y

standard = np.copy(original)
deriv2 = np.zeros(original.size)

intensity = 2.0

# the boundaries are better handled in the plugin code

for n in range(original.size):
    if n > 0 and n < original.size - 1:
        deriv2[n] = original[n + 1] - 2 * original[n] + original[n - 1]
    elif n == 0:
        deriv2[0] = original[n + 1] - 2 * original[n] + original[n]
    elif n == original.size - 1:
        deriv2[n] = original[n] - 2 * original[n] + original[n - 1]

for n in range(standard.size):
    standard[n] -= intensity * deriv2[n]

aggressive = np.copy(standard)

if intensity >= 1:
    ndivs = 1000
    gain = np.linspace(1, intensity, ndivs)
    dv = 0.5 / ndivs

    for n in range(standard.size):
        v = aggressive[n]

        idx = int(np.floor(np.fabs(v) / dv))

        if idx < 0:
            idx = 0
        elif idx > gain.size:
            idx = gain.size - 1

        aggressive[n] = v * gain[idx]


fig = plt.figure()

plt.plot(t, original, 'bo-', markersize=4, label='original')
plt.plot(t, standard, 'ro-', markersize=4, label='standard')
plt.plot(t, aggressive, 'go-', markersize=4, label='aggressive')

fig.legend()

plt.xlabel('Arbitrary Time', fontsize=18)
plt.ylabel('Waveform', fontsize=18)
plt.grid()

plt.show()