-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho_effect.py
More file actions
55 lines (54 loc) · 1.69 KB
/
Copy pathecho_effect.py
File metadata and controls
55 lines (54 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
51
52
53
54
55
import soundfile as sf
import matplotlib.pyplot as plt
import numpy as np
x, f_sample = sf.read('input.wav')
delay = int(0.2 * f_sample)
alpha = 0.7
n_samples = x.shape[0]
n = np.arange(n_samples)
if x.ndim == 1:
print("Mono signal")
y = np.zeros_like(x, dtye = 'float')
for i in range(0, len(x)):
if i >= delay:
y[i] = x[i] + alpha * x[i - delay]
else:
y[i] = x[i]
y = y / np.max(np.abs(y))
plt.figure(figsize = (12, 16))
plt.subplot(2, 1, 1)
plt.plot(n / f_sample, x, color = 'red')
plt.title("Original signal")
plt.xlabel("Time[s]")
plt.ylabel("Amplitude[dB]")
plt.subplot(2, 1, 2)
plt.plot(n / f_sample, y, color = 'green')
plt.title("Echo effect applied")
plt.xlabel("Time[s]")
plt.ylabel("Amplitude[dB]")
plt.show()
elif x.ndim == 2:
print("Stereo signal")
y = np.zeros_like(x, dtype = 'float')
for c in range(2):
for i in range(0, len(x)):
if i >= delay:
y[i, c] = x[i, c] + alpha * x[i - delay, c]
else:
y[i, c] = x[i, c]
y = y / np.max(np.abs(y))
plt.figure(figsize = (12, 16))
plt.subplot(2, 1, 1)
plt.plot(n / f_sample, x[:, 0], color = 'blue')
plt.plot(n / f_sample, y[:, 0], color = 'yellow')
plt.title("Left channel")
plt.xlabel("Time[s]")
plt.ylabel("Amplitude[dB]")
plt.subplot(2, 1, 2)
plt.plot(n / f_sample, x[:, 1], color = 'yellow')
plt.plot(n / f_sample, y[:, 1], color = 'blue')
plt.title("Right channel")
plt.xlabel("Time[s]")
plt.ylabel("Amplitude[dB]")
plt.show()
sf.write('output_echo.wav', y, f_sample)