-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp3.py
42 lines (29 loc) · 967 Bytes
/
mp3.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
37
38
39
40
41
42
import numpy as np
def make_mp3_analysisfb(h: np.ndarray, M: int) -> np.ndarray:
"""
Args:
h: Impulse response of the standard low-pass filter.
M: Τhe number of zones to split into.
Returns:
A LxM matrix, where L is the length of the filter response. Every column is the h[i] filter response
"""
H = np.zeros([len(h), M], dtype=np.float32)
for i in range(1, M + 1):
n = np.arange(h.shape[0], dtype=np.int64)[:,np.newaxis]
frequency = (2 * i - 1) * np.pi / (2.0 * M)
phase = -(2 * i - 1) * np.pi / 4.0
tmp = np.cos(frequency * n + phase)
x = np.multiply(h, tmp)
H[:, i - 1, np.newaxis] = x
return H
def make_mp3_synthesisfb(h: np.ndarray, M: int) -> np.ndarray:
"""
Args:
h:
M:
Returns:
"""
H = make_mp3_analysisfb(h, M)
L = len(h)
G = np.flip(H, axis=0)
return G