Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: release global interpreter lock #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test_script:
Set-Location "$env:APPVEYOR_BUILD_FOLDER"

after_test:
- python setup.py bdist_wheel
- pip wheel --wheel-dir=.\dist --no-deps .

artifacts:
- path: dist\*
Expand Down
60 changes: 33 additions & 27 deletions pyworld/pyworld.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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":
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -220,12 +222,13 @@ def stonemask(np.ndarray[double, ndim=1, mode="c"] x not None,
cdef int f0_length = <int>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
Expand All @@ -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
Expand Down Expand Up @@ -319,11 +322,12 @@ def cheaptrick(np.ndarray[double, ndim=1, mode="c"] x not None,
cdef np.intp_t[:] tmp = np.zeros(f0_length, dtype=np.intp)
cdef double **cpp_spectrogram = <double**> (<void*> &tmp[0])
cdef np.intp_t i
for i in range(f0_length):
cpp_spectrogram[i] = &spectrogram[i, 0]
with (nogil, cython.boundscheck(False)):
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)
CheapTrick(&x[0], x_length, fs, &temporal_positions[0],
&f0[0], f0_length, &option, cpp_spectrogram)
return np.array(spectrogram, dtype=np.float64)


Expand Down Expand Up @@ -386,12 +390,13 @@ def d4c(np.ndarray[double, ndim=1, mode="c"] x not None,
cdef np.intp_t[:] tmp = np.zeros(f0_length, dtype=np.intp)
cdef double **cpp_aperiodicity = <double**> (<void*> &tmp[0])
cdef np.intp_t i
for i in range(f0_length):
cpp_aperiodicity[i] = &aperiodicity[i, 0]
with (nogil, cython.boundscheck(False)):
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)
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)


Expand Down Expand Up @@ -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 = <int>len(f0)
y_length = int(f0_length * frame_period * fs / 1000)
cdef int y_length = <int>(f0_length * frame_period * fs / 1000)
cdef int fft_size = (<int>spectrogram.shape[1] - 1)*2
cdef np.ndarray[double, ndim=1, mode="c"] y = \
np.zeros(y_length, dtype=np.dtype('float64'))
Expand All @@ -445,12 +450,13 @@ def synthesize(np.ndarray[double, ndim=1, mode="c"] f0 not None,
cdef double **cpp_spectrogram = <double**> (<void*> &tmp[0])
cdef double **cpp_aperiodicity = <double**> (<void*> &tmp2[0])
cdef np.intp_t i
for i in range(f0_length):
cpp_spectrogram[i] = &spectrogram0[i, 0]
cpp_aperiodicity[i] = &aperiodicity0[i, 0]
with (nogil, cython.boundscheck(False)):
for i in range(f0_length):
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])
Synthesis(&f0[0], f0_length, cpp_spectrogram,
cpp_aperiodicity, fft_size, frame_period, fs, y_length, &y[0])
return y


Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
numpy
matplotlib
argparse
cython
pysoundfile
argparse; python_version<"3.5"
soundfile