-
Notifications
You must be signed in to change notification settings - Fork 4
/
AudioUtils.py
36 lines (26 loc) · 949 Bytes
/
AudioUtils.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
def delay_f(x, time, fs):
N = len(x)
x_f = np.fft.fft(x)
y_f = np.zeros(N, dtype=np.complex_)
w = np.array(range(0, (N / 2) + 1) + range((-N / 2) + 1, 0)) / float(N) * float(fs)
y_f = x_f * np.exp(-1j * 2 * np.pi * w * time)
y = np.fft.ifft(y_f).real
return y
def to_dB_spect(magnitude, MIN_AMP, AMP_FAC):
magnitude = np.maximum(magnitude, np.max(magnitude) / MIN_AMP)
magnitude = 20. * np.log10(magnitude * AMP_FAC)
return magnitude
def to_dB_mag(magnitude, MIN_AMP, AMP_FAC):
magnitude = np.maximum(magnitude, np.max(magnitude) / float(MIN_AMP))
magnitude = 20. * np.log10(magnitude * AMP_FAC)
return magnitude
def add_SIR_(s1, sir1):
s1 = 10. ** (sir1 / 20.0) * s1
if (s1.max() > 1.0):
s1 = s1 * (1.0) / float(s1.max())
if (s1.min() < -1.0):
s1 = s1 * (-1.0) / float(s1.min())
return s1