# Path: sprocket/speech/analyzer.py
# class WORLD(object):
#     """WORLD-based speech analyzer
# 
#     Parameters
#     ----------
#     fs : int, optional
#         Sampling frequency
#         Default set to 16000
#     fftl : int, optional
#         FFT length
#         Default set to 1024
#     shiftms : int, optional
#         Shift lengs [ms]
#         Default set to 5.0
#     minf0 : int, optional
#         Floor in f0 estimation
#         Default set to 50
#     maxf0 : int, optional
#         Ceil in f0 estimation
#         Default set to 500
#     """
# 
#     def __init__(self, fs=16000, fftl=1024, shiftms=5.0, minf0=40.0, maxf0=500.0):
#         self.fs = fs
#         self.fftl = fftl
#         self.shiftms = shiftms
#         self.minf0 = minf0
#         self.maxf0 = maxf0
# 
#     def analyze(self, x):
#         """Analyze acoustic features based on WORLD
# 
#         analyze F0, spectral envelope, aperiodicity
# 
#         Paramters
#         ---------
#         x : array, shape (`T`)
#             monoral speech signal in time domain
# 
#         Returns
#         ---------
#         f0 : array, shape (`T`,)
#             F0 sequence
#         spc : array, shape (`T`, `fftl / 2 + 1`)
#             Spectral envelope sequence
#         ap: array, shape (`T`, `fftl / 2 + 1`)
#             aperiodicity sequence
# 
#         """
#         f0, time_axis = pyworld.harvest(x, self.fs, f0_floor=self.minf0,
#                                         f0_ceil=self.maxf0, frame_period=self.shiftms)
#         spc = pyworld.cheaptrick(x, f0, time_axis, self.fs,
#                                  fft_size=self.fftl)
#         ap = pyworld.d4c(x, f0, time_axis, self.fs, fft_size=self.fftl)
# 
#         assert spc.shape == ap.shape
#         return f0, spc, ap
# 
#     def analyze_f0(self, x):
#         """Analyze decomposes a speech signal into F0:
# 
#         Paramters
#         ---------
#         x: array, shape (`T`)
#             monoral speech signal in time domain
# 
#         Returns
#         ---------
#         f0 : array, shape (`T`,)
#             F0 sequence
# 
#         """
# 
#         f0, time_axis = pyworld.harvest(x, self.fs, f0_floor=self.minf0,
#                                         f0_ceil=self.maxf0, frame_period=self.shiftms)
# 
#         return f0
# 
#     def synthesis(self, f0, spc, ap):
#         """Synthesis re-synthesizes a speech waveform from:
# 
#         Parameters
#         ----------
#         f0 : array, shape (`T`)
#             F0 sequence
#         spc : array, shape (`T`, `dim`)
#             Spectral envelope sequence
#         ap: array, shape (`T`, `dim`)
#             Aperiodicity sequence
# 
#         """
# 
#         return pyworld.synthesize(f0, spc, ap, self.fs, frame_period=self.shiftms)
# 
# Path: sprocket/speech/parameterizer.py
# def spc2npow(spectrogram):
#     """Calculate normalized power sequence from spectrogram
# 
#     Parameters
#     ----------
#     spectrogram : array, shape (T, `fftlen / 2 + 1`)
#         Array of spectrum envelope
# 
#     Return
#     ------
#     npow : array, shape (`T`, `1`)
#         Normalized power sequence
# 
#     """
# 
#     # frame based processing
#     npow = np.apply_along_axis(_spvec2pow, 1, spectrogram)
# 
#     meanpow = np.mean(npow)
#     npow = 10.0 * np.log10(npow / meanpow)
# 
#     return npow


import pysptk
import pyworld
import numpy as np
from .analyzer import WORLD
from .parameterizer import spc2npow

    def codeap(self):
        """Return coded aperiodicity sequence

        Returns
        -------
        codeap : array, shape (`T`, `dim`)
            Encoded aperiodicity sequence of the waveform
            The `dim` of code ap is defined based on the `fs` as follow:
            fs = `16000` : `1`
            fs = `22050` : `2`
            fs = `44100` : `5`
            fs = `48000` : `5`
        """

        self._analyzed_check()

        return pyworld.code_aperiodicity(self._ap, self.fs)

    def npow(self):
        """Return normalized power sequence parameterized from spectral envelope

        Returns
        -------
        npow: vector, shape (`T`,)
            Normalized power sequence of the given waveform

        """
        self._analyzed_check()


# Path: sprocket/speech/analyzer.py
# class WORLD(object):
#     """WORLD-based speech analyzer
# 
#     Parameters
#     ----------
#     fs : int, optional
#         Sampling frequency
#         Default set to 16000
#     fftl : int, optional
#         FFT length
#         Default set to 1024
#     shiftms : int, optional
#         Shift lengs [ms]
#         Default set to 5.0
#     minf0 : int, optional
#         Floor in f0 estimation
#         Default set to 50
#     maxf0 : int, optional
#         Ceil in f0 estimation
#         Default set to 500
#     """
# 
#     def __init__(self, fs=16000, fftl=1024, shiftms=5.0, minf0=40.0, maxf0=500.0):
#         self.fs = fs
#         self.fftl = fftl
#         self.shiftms = shiftms
#         self.minf0 = minf0
#         self.maxf0 = maxf0
# 
#     def analyze(self, x):
#         """Analyze acoustic features based on WORLD
# 
#         analyze F0, spectral envelope, aperiodicity
# 
#         Paramters
#         ---------
#         x : array, shape (`T`)
#             monoral speech signal in time domain
# 
#         Returns
#         ---------
#         f0 : array, shape (`T`,)
#             F0 sequence
#         spc : array, shape (`T`, `fftl / 2 + 1`)
#             Spectral envelope sequence
#         ap: array, shape (`T`, `fftl / 2 + 1`)
#             aperiodicity sequence
# 
#         """
#         f0, time_axis = pyworld.harvest(x, self.fs, f0_floor=self.minf0,
#                                         f0_ceil=self.maxf0, frame_period=self.shiftms)
#         spc = pyworld.cheaptrick(x, f0, time_axis, self.fs,
#                                  fft_size=self.fftl)
#         ap = pyworld.d4c(x, f0, time_axis, self.fs, fft_size=self.fftl)
# 
#         assert spc.shape == ap.shape
#         return f0, spc, ap
# 
#     def analyze_f0(self, x):
#         """Analyze decomposes a speech signal into F0:
# 
#         Paramters
#         ---------
#         x: array, shape (`T`)
#             monoral speech signal in time domain
# 
#         Returns
#         ---------
#         f0 : array, shape (`T`,)
#             F0 sequence
# 
#         """
# 
#         f0, time_axis = pyworld.harvest(x, self.fs, f0_floor=self.minf0,
#                                         f0_ceil=self.maxf0, frame_period=self.shiftms)
# 
#         return f0
# 
#     def synthesis(self, f0, spc, ap):
#         """Synthesis re-synthesizes a speech waveform from:
# 
#         Parameters
#         ----------
#         f0 : array, shape (`T`)
#             F0 sequence
#         spc : array, shape (`T`, `dim`)
#             Spectral envelope sequence
#         ap: array, shape (`T`, `dim`)
#             Aperiodicity sequence
# 
#         """
# 
#         return pyworld.synthesize(f0, spc, ap, self.fs, frame_period=self.shiftms)
# 
# Path: sprocket/speech/parameterizer.py
# def spc2npow(spectrogram):
#     """Calculate normalized power sequence from spectrogram
# 
#     Parameters
#     ----------
#     spectrogram : array, shape (T, `fftlen / 2 + 1`)
#         Array of spectrum envelope
# 
#     Return
#     ------
#     npow : array, shape (`T`, `1`)
#         Normalized power sequence
# 
#     """
# 
#     # frame based processing
#     npow = np.apply_along_axis(_spvec2pow, 1, spectrogram)
# 
#     meanpow = np.mean(npow)
#     npow = 10.0 * np.log10(npow / meanpow)
# 
#     return npow


# Path: sprocket/speech/feature_extractor.py
import pysptk
import pyworld
import numpy as np
from .analyzer import WORLD
from .parameterizer import spc2npow


    def codeap(self):
        """Return coded aperiodicity sequence

        Returns
        -------
        codeap : array, shape (`T`, `dim`)
            Encoded aperiodicity sequence of the waveform
            The `dim` of code ap is defined based on the `fs` as follow:
            fs = `16000` : `1`
            fs = `22050` : `2`
            fs = `44100` : `5`
            fs = `48000` : `5`
        """

        self._analyzed_check()

        return pyworld.code_aperiodicity(self._ap, self.fs)

    def npow(self):
        """Return normalized power sequence parameterized from spectral envelope

        Returns
        -------
        npow: vector, shape (`T`,)
            Normalized power sequence of the given waveform

        """
        self._analyzed_check()


        return spc2npow(self._spc)