-
Notifications
You must be signed in to change notification settings - Fork 0
/
reconstruct.py
25 lines (21 loc) · 982 Bytes
/
reconstruct.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
# extract and reconstruct module
import numpy as np
from train import train_given_Pf, train
from spectrogram import relative_restore, reconstruct
def extract_given_Pf(frames, Pf, extraz=None, maxstep=300, progress_step=50):
""" Given original spectrogram and pretrained Pf, extract conforming and complementary wave """
zn1, _ = np.shape(Pf)
if extraz is None:
extraz = zn1
zn = zn1 + extraz
Pf2, Pt, Pz = train_given_Pf(frames, Pf, zn, maxstep, progress_step)
return (extract_partial(frames, Pf2, Pt, Pz, range(zn1)), \
extract_partial(frames, Pf2, Pt, Pz, range(zn1, zn)))
def extract_partial(frames, Pf, Pt, Pz, partial=None):
""" Given original spectrogram, Pf, Pt, Pz, extract partial features and return restored wave """
if partial is None:
partial = range(len(Pz))
z = np.zeros_like(Pz)
z[partial] = Pz[partial]
extracted = reconstruct(Pf, Pz, z)
return relative_restore(frames, extracted)