Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/r9y9/pysptk
Browse files Browse the repository at this point in the history
  • Loading branch information
r9y9 committed May 4, 2018
2 parents 99f9c73 + 7520100 commit abdad49
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pysptk/sptk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,10 @@ def mgc2sp(ceps, alpha=0.0, gamma=0.0, fftlen=256):
Returns
-------
sp : array, shape (``fftlen // 2 + 1``)
Complex spectrum
Complex spectrum log_e(H(ω))
.. warning:: There's no equivalent option ``o`` in SPTK's mgc2sp.
You have to normalize spectrum manually if needed.
Raises
------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from os.path import join
import subprocess

version = '0.1.11'
version = '0.1.12'

# Adapted from https://github.com/pytorch/pytorch
cwd = os.path.dirname(os.path.abspath(__file__))
Expand Down
Binary file added tests/data/test16k_57.mgc
Binary file not shown.
Binary file added tests/data/test16k_57.sp
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/regression/test_mcep.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,26 @@ def test_mcep_from_H():

assert mc.shape == mc_hat.shape
assert np.allclose(mc, mc_hat, atol=1e-6)


def test_mgc2sp():
"""mgc2sp
ref: https://github.com/r9y9/pysptk/issues/57
"""
# frame -l 512 -p 80 < test16k.float | window -l 512| mcep -q 0 -l 512 \
# -a 0.41 -m 24 | mgc2sp -a 0.41 -m 24 -l 512 -o 3 > test16k_57.sp
# output type 3 means we get power spectrum |H(w)|^2
sp = np.fromfile(
join(DATA_DIR, "test16k_57.sp"), dtype=np.float32).reshape(759, 257).astype(np.float64)

# frame -l 512 -p 80 < test16k.float | window -l 512 \
# | mcep -q 0 -l 512 -a 0.41 -m 24 > test16k_57.mgc
mgc = np.fromfile(join(DATA_DIR, "test16k_57.mgc"), dtype=np.float32).reshape(
759, 25).astype(np.float64)

# mgc2sp does conversion: c(k) -> log H(w)
# so convert it to |H(w)|^2 to get power spectrum
sp_hat = np.exp(pysptk.mgc2sp(mgc, 0.41, 0, 512).real*2)

assert np.allclose(sp, sp_hat)

0 comments on commit abdad49

Please sign in to comment.