-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_hnm_qfft.py
40 lines (34 loc) · 1.47 KB
/
test_hnm_qfft.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
import numpy as np
import pylab as pl
from revoice import *
from revoice.common import *
#w, sr = loadWav("voices/yuri_orig.wav")
w, sr = loadWav("voices/square110880.wav")
energyList = energy.Analyzer(sr)(w)
print("F0 Detecting...")
hubbleAnalyzer = hubble.Analyzer(sr)
f0List = hubbleAnalyzer(w)
print("HNM Analyzing...")
hnmAnalyzer = hnm.Analyzer(sr, harmonicAnalysisMethod = "qfft")
hFreqList, hAmpList, hPhaseList, sinusoidEnergyList, noiseEnvList, noiseEnergyList = hnmAnalyzer(w, f0List)
assert hFreqList.dtype == hAmpList.dtype == hPhaseList.dtype == sinusoidEnergyList.dtype == noiseEnvList.dtype == noiseEnergyList.dtype == np.float32
print("Sinusoid Synthing...")
synProc = hnm.Synther(sr)
sinusoid = synProc(hFreqList, hAmpList, hPhaseList, sinusoidEnergyList, None, None, enableNoise = False)
srer = calcSRER(w[:min(w.shape[0], sinusoid.shape[0])], sinusoid[:min(w.shape[0], sinusoid.shape[0])])
assert sinusoid.dtype == np.float32
print("HNM Synthing...")
synProc = hnm.Synther(sr)
synthed = synProc(hFreqList, hAmpList, hPhaseList, sinusoidEnergyList, noiseEnvList, noiseEnergyList)
assert synthed.dtype == np.float32
print("Average SRER = %lf" % srer)
tList = np.arange(f0List.shape[0]) * hubbleAnalyzer.hopSize / sr
hFreqList[hFreqList <= 0.0] = np.nan
pl.figure()
pl.plot(tList, hFreqList)
pl.figure()
pl.plot(tList, sinusoidEnergyList)
pl.plot(tList, noiseEnergyList)
pl.figure()
pl.plot(np.arange(synthed.shape[0]) / sr, synthed)
pl.show()