diff --git a/lib/World b/lib/World index 13d96fc..8d79b88 160000 --- a/lib/World +++ b/lib/World @@ -1 +1 @@ -Subproject commit 13d96fc7da25da5fb808844d88337317e9fa0d76 +Subproject commit 8d79b88b7dd92e8a132996cf74080b2d6f881b98 diff --git a/pyworld/pyworld.pyx b/pyworld/pyworld.pyx index 8ca2b80..937128b 100644 --- a/pyworld/pyworld.pyx +++ b/pyworld/pyworld.pyx @@ -11,7 +11,7 @@ cdef extern from "world/synthesis.h": int f0_length, const double * const *spectrogram, const double * const *aperiodicity, int fft_size, double frame_period, - int fs, int y_length, double *y) except + + int fs, int y_length, double *y) except + nogil cdef extern from "world/cheaptrick.h": @@ -25,7 +25,7 @@ cdef extern from "world/cheaptrick.h": void InitializeCheapTrickOption(int fs, CheapTrickOption *option) except + void CheapTrick(const double *x, int x_length, int fs, const double *temporal_positions, const double *f0, int f0_length, const CheapTrickOption *option, - double **spectrogram) except + + double **spectrogram) except + nogil cdef extern from "world/dio.h": @@ -40,7 +40,7 @@ cdef extern from "world/dio.h": void InitializeDioOption(DioOption *option) except + int GetSamplesForDIO(int fs, int x_length, double frame_period) void Dio(const double *x, int x_length, int fs, const DioOption *option, - double *temporal_positions, double *f0) except + + double *temporal_positions, double *f0) except + nogil cdef extern from "world/harvest.h": @@ -52,7 +52,7 @@ cdef extern from "world/harvest.h": void InitializeHarvestOption(HarvestOption *option) int GetSamplesForHarvest(int fs, int x_length, double frame_period) void Harvest(const double *x, int x_length, int fs, const HarvestOption *option, - double *temporal_positions, double *f0) except + + double *temporal_positions, double *f0) except + nogil cdef extern from "world/d4c.h": @@ -62,13 +62,13 @@ cdef extern from "world/d4c.h": void InitializeD4COption(D4COption *option) except + void D4C(const double *x, int x_length, int fs, const double *temporal_positions, const double *f0, int f0_length, int fft_size, const D4COption *option, - double **aperiodicity) except + + double **aperiodicity) except + nogil cdef extern from "world/stonemask.h": void StoneMask(const double *x, int x_length, int fs, const double *temporal_positions, const double *f0, int f0_length, - double *refined_f0) except + + double *refined_f0) except + nogil cdef extern from "world/codec.h": @@ -85,9 +85,9 @@ cdef extern from "world/codec.h": double **spectrogram) except + -default_frame_period = 5.0 -default_f0_floor = 71.0 -default_f0_ceil = 800.0 +cdef double default_frame_period = 5.0 +cdef double default_f0_floor = 71.0 +cdef double default_f0_ceil = 800.0 def dio(np.ndarray[double, ndim=1, mode="c"] x not None, int fs, @@ -147,7 +147,8 @@ def dio(np.ndarray[double, ndim=1, mode="c"] x not None, int fs, np.zeros(f0_length, dtype=np.dtype('float64')) cdef np.ndarray[double, ndim=1, mode="c"] temporal_positions = \ np.zeros(f0_length, dtype=np.dtype('float64')) - Dio(&x[0], x_length, fs, &option, &temporal_positions[0], &f0[0]) + with (nogil, cython.boundscheck(False)): + Dio(&x[0], x_length, fs, &option, &temporal_positions[0], &f0[0]) return f0, temporal_positions @@ -190,7 +191,8 @@ def harvest(np.ndarray[double, ndim=1, mode="c"] x not None, int fs, np.zeros(f0_length, dtype=np.dtype('float64')) cdef np.ndarray[double, ndim=1, mode="c"] temporal_positions = \ np.zeros(f0_length, dtype=np.dtype('float64')) - Harvest(&x[0], x_length, fs, &option, &temporal_positions[0], &f0[0]) + with (nogil, cython.boundscheck(False)): + Harvest(&x[0], x_length, fs, &option, &temporal_positions[0], &f0[0]) return f0, temporal_positions @@ -220,12 +222,13 @@ def stonemask(np.ndarray[double, ndim=1, mode="c"] x not None, cdef int f0_length = len(f0) cdef np.ndarray[double, ndim=1, mode="c"] refined_f0 = \ np.zeros(f0_length, dtype=np.dtype('float64')) - StoneMask(&x[0], x_length, fs, &temporal_positions[0], - &f0[0], f0_length, &refined_f0[0]) + with (nogil, cython.boundscheck(False)): + StoneMask(&x[0], x_length, fs, &temporal_positions[0], + &f0[0], f0_length, &refined_f0[0]) return refined_f0 -def get_cheaptrick_fft_size(fs, f0_floor=default_f0_floor): +def get_cheaptrick_fft_size(int fs, f0_floor=default_f0_floor): """Calculate suitable FFT size for CheapTrick given F0 floor. Parameters @@ -247,7 +250,7 @@ def get_cheaptrick_fft_size(fs, f0_floor=default_f0_floor): cdef int fft_size = GetFFTSizeForCheapTrick(fs, &option) return fft_size -def get_cheaptrick_f0_floor(fs, fft_size): +def get_cheaptrick_f0_floor(int fs, int fft_size): """Calculates actual lower F0 limit for CheapTrick based on the sampling frequency and FFT size used. Whenever F0 is below this threshold the spectrum will be analyzed as if the frame is unvoiced @@ -322,8 +325,9 @@ def cheaptrick(np.ndarray[double, ndim=1, mode="c"] x not None, for i in range(f0_length): cpp_spectrogram[i] = &spectrogram[i, 0] - CheapTrick(&x[0], x_length, fs, &temporal_positions[0], - &f0[0], f0_length, &option, cpp_spectrogram) + with (nogil, cython.boundscheck(False)): + CheapTrick(&x[0], x_length, fs, &temporal_positions[0], + &f0[0], f0_length, &option, cpp_spectrogram) return np.array(spectrogram, dtype=np.float64) @@ -389,9 +393,10 @@ def d4c(np.ndarray[double, ndim=1, mode="c"] x not None, for i in range(f0_length): cpp_aperiodicity[i] = &aperiodicity[i, 0] - D4C(&x[0], x_length, fs, &temporal_positions[0], - &f0[0], f0_length, fft_size0, &option, - cpp_aperiodicity) + with (nogil, cython.boundscheck(False)): + D4C(&x[0], x_length, fs, &temporal_positions[0], + &f0[0], f0_length, fft_size0, &option, + cpp_aperiodicity) return np.array(aperiodicity, dtype=np.float64) @@ -433,7 +438,7 @@ def synthesize(np.ndarray[double, ndim=1, mode="c"] f0 not None, .format(spectrogram.shape[1], aperiodicity.shape[1])) cdef int f0_length = len(f0) - y_length = int(f0_length * frame_period * fs / 1000) + cdef int y_length = (f0_length * frame_period * fs / 1000) cdef int fft_size = (spectrogram.shape[1] - 1)*2 cdef np.ndarray[double, ndim=1, mode="c"] y = \ np.zeros(y_length, dtype=np.dtype('float64')) @@ -449,8 +454,9 @@ def synthesize(np.ndarray[double, ndim=1, mode="c"] f0 not None, cpp_spectrogram[i] = &spectrogram0[i, 0] cpp_aperiodicity[i] = &aperiodicity0[i, 0] - Synthesis(&f0[0], f0_length, cpp_spectrogram, - cpp_aperiodicity, fft_size, frame_period, fs, y_length, &y[0]) + with (nogil, cython.boundscheck(False)): + Synthesis(&f0[0], f0_length, cpp_spectrogram, + cpp_aperiodicity, fft_size, frame_period, fs, y_length, &y[0]) return y