-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
56 lines (43 loc) · 1.66 KB
/
data.py
File metadata and controls
56 lines (43 loc) · 1.66 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
56
import numpy as np
import backend
class Data:
def __init__(self):
return
@classmethod
def load_sound(cls, location):
''' Loads wav file from "location" and calculates its fft.\n
Sets the same input as output sound as filter of 0 threshold'''
cls.fs, cls.input_sound = backend.get_audio(location)
cls.ifft = cls.input_sound
cls.time = np.arange(0, len(cls.input_sound)/cls.fs, 1/cls.fs)
cls.fft = backend.furiour(cls.input_sound)
@classmethod
def load_power_graph(cls):
cls.power = backend.power_spectrum(cls.fft)[1:]
cls.frequency = np.linspace(0, cls.fs, len(cls.power))
cls.min = 0
cls.max = np.amax(cls.power)
cls.slope = (cls.max - cls.min) / 100
cls.truncated_power = cls.power[:backend.get_last_non_zero_index(
cls.power)+1]
cls.truncated_frequency = np.linspace(
1, len(cls.truncated_power), len(cls.truncated_power))
@classmethod
def load_output(cls, threshold):
ifft_freq = [0]
for i in range(len(cls.power)):
if cls.power[i] >= threshold:
ifft_freq.append(cls.fft[i+1])
else:
ifft_freq.append(0)
temp = np.array(ifft_freq)
cls.ifft = np.fft.irfft(temp, n=len(cls.time))
@classmethod
def export(cls):
backend.export("audio_filter_output.wav", cls.fs, cls.ifft)
@classmethod
def add_noise(cls):
rand = np.random.rand(len(cls.input_sound)) * max(cls.input_sound)
cls.input_sound = cls.input_sound + rand
cls.fft = backend.furiour(cls.input_sound)
cls.ifft = cls.input_sound