Skip to content

Commit

Permalink
Merge pull request #42 from r9y9/mc2e
Browse files Browse the repository at this point in the history
Add mc2e
  • Loading branch information
r9y9 committed May 8, 2017
2 parents 023c71b + ba89f34 commit f2a3e30
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -2,6 +2,7 @@

## v0.1.6

- Add `mc2e`. [#42]
- Add `sp2mc` and `mc2sp`. [#41]

## v0.1.5
Expand Down Expand Up @@ -59,3 +60,4 @@
[#35]: https://github.com/r9y9/pysptk/pull/35
[#39]: https://github.com/r9y9/pysptk/pull/39
[#41]: https://github.com/r9y9/pysptk/pull/41
[#42]: https://github.com/r9y9/pysptk/pull/42
2 changes: 1 addition & 1 deletion pysptk/__init__.py
Expand Up @@ -43,5 +43,5 @@
from .sptk import * # pylint: disable=wildcard-import

from . import synthesis
from .conversion import mgc2b, sp2mc, mc2sp
from .conversion import mgc2b, sp2mc, mc2sp, mc2e
from . import util
34 changes: 32 additions & 2 deletions pysptk/conversion.py
Expand Up @@ -9,14 +9,14 @@
mgc2b
sp2mc
mc2sp
mc2e
"""

from __future__ import division, print_function, absolute_import

import numpy as np

from pysptk.sptk import mc2b, gnorm, freqt
from pysptk.sptk import mc2b, gnorm, freqt, c2ir


def mgc2b(mgc, alpha=0.35, gamma=0.0):
Expand Down Expand Up @@ -141,3 +141,33 @@ def mc2sp(mc, alpha, fftlen):
# back to power spectrum
# c(m) -> log(|X(ω)|²) -> |X(ω)|²
return np.exp(np.fft.rfft(symc).real)


def mc2e(mc, alpha=0.35, irlen=256):
"""Compute energy from mel-cepstrum
Inspired from hts_engine
Parameters
----------
mc : array
Mel-spectrum
alpha : float
All-pass constant.
irlen : int
IIR filter length
Returns
-------
energy : floating point, scalar
frame energy
"""
# back to linear frequency domain
c = freqt(mc, irlen - 1, -alpha)

# compute impule response from cepsturm
ir = c2ir(c, irlen)

return np.sum(np.abs(ir * ir))
6 changes: 6 additions & 0 deletions tests/test_conversions.py
Expand Up @@ -282,3 +282,9 @@ def __test(order, alpha, fftlen):
for alpha in [0.35, 0.41]:
for fftlen in [512, 1024, 2048]:
yield __test, order, alpha, fftlen


def test_mc2b():
x = windowed_dummy_data(1024)
mc = pysptk.mcep(x)
assert pysptk.mc2e(mc) > 0

0 comments on commit f2a3e30

Please sign in to comment.