@@ -11,7 +11,7 @@ cdef extern from "world/synthesis.h":
11
11
int f0_length, const double * const * spectrogram,
12
12
const double * const * aperiodicity,
13
13
int fft_size, double frame_period,
14
- int fs, int y_length, double * y) except +
14
+ int fs, int y_length, double * y) except + nogil
15
15
16
16
17
17
cdef extern from " world/cheaptrick.h" :
@@ -25,7 +25,7 @@ cdef extern from "world/cheaptrick.h":
25
25
void InitializeCheapTrickOption(int fs, CheapTrickOption * option) except +
26
26
void CheapTrick(const double * x, int x_length, int fs, const double * temporal_positions,
27
27
const double * f0, int f0_length, const CheapTrickOption * option,
28
- double ** spectrogram) except +
28
+ double ** spectrogram) except + nogil
29
29
30
30
31
31
cdef extern from " world/dio.h" :
@@ -40,7 +40,7 @@ cdef extern from "world/dio.h":
40
40
void InitializeDioOption(DioOption * option) except +
41
41
int GetSamplesForDIO(int fs, int x_length, double frame_period)
42
42
void Dio(const double * x, int x_length, int fs, const DioOption * option,
43
- double * temporal_positions, double * f0) except +
43
+ double * temporal_positions, double * f0) except + nogil
44
44
45
45
46
46
cdef extern from " world/harvest.h" :
@@ -52,7 +52,7 @@ cdef extern from "world/harvest.h":
52
52
void InitializeHarvestOption(HarvestOption * option)
53
53
int GetSamplesForHarvest(int fs, int x_length, double frame_period)
54
54
void Harvest(const double * x, int x_length, int fs, const HarvestOption * option,
55
- double * temporal_positions, double * f0) except +
55
+ double * temporal_positions, double * f0) except + nogil
56
56
57
57
58
58
cdef extern from " world/d4c.h" :
@@ -62,13 +62,13 @@ cdef extern from "world/d4c.h":
62
62
void InitializeD4COption(D4COption * option) except +
63
63
void D4C(const double * x, int x_length, int fs, const double * temporal_positions,
64
64
const double * f0, int f0_length, int fft_size, const D4COption * option,
65
- double ** aperiodicity) except +
65
+ double ** aperiodicity) except + nogil
66
66
67
67
68
68
cdef extern from " world/stonemask.h" :
69
69
void StoneMask(const double * x, int x_length, int fs,
70
70
const double * temporal_positions, const double * f0, int f0_length,
71
- double * refined_f0) except +
71
+ double * refined_f0) except + nogil
72
72
73
73
74
74
cdef extern from " world/codec.h" :
@@ -147,7 +147,8 @@ def dio(np.ndarray[double, ndim=1, mode="c"] x not None, int fs,
147
147
np.zeros(f0_length, dtype = np.dtype(' float64' ))
148
148
cdef np.ndarray[double , ndim= 1 , mode= " c" ] temporal_positions = \
149
149
np.zeros(f0_length, dtype = np.dtype(' float64' ))
150
- Dio(& x[0 ], x_length, fs, & option, & temporal_positions[0 ], & f0[0 ])
150
+ with (nogil, cython.boundscheck(False )):
151
+ Dio(& x[0 ], x_length, fs, & option, & temporal_positions[0 ], & f0[0 ])
151
152
return f0, temporal_positions
152
153
153
154
@@ -190,7 +191,8 @@ def harvest(np.ndarray[double, ndim=1, mode="c"] x not None, int fs,
190
191
np.zeros(f0_length, dtype = np.dtype(' float64' ))
191
192
cdef np.ndarray[double , ndim= 1 , mode= " c" ] temporal_positions = \
192
193
np.zeros(f0_length, dtype = np.dtype(' float64' ))
193
- Harvest(& x[0 ], x_length, fs, & option, & temporal_positions[0 ], & f0[0 ])
194
+ with (nogil, cython.boundscheck(False )):
195
+ Harvest(& x[0 ], x_length, fs, & option, & temporal_positions[0 ], & f0[0 ])
194
196
return f0, temporal_positions
195
197
196
198
@@ -220,12 +222,13 @@ def stonemask(np.ndarray[double, ndim=1, mode="c"] x not None,
220
222
cdef int f0_length = < int > len (f0)
221
223
cdef np.ndarray[double , ndim= 1 , mode= " c" ] refined_f0 = \
222
224
np.zeros(f0_length, dtype = np.dtype(' float64' ))
223
- StoneMask(& x[0 ], x_length, fs, & temporal_positions[0 ],
224
- & f0[0 ], f0_length, & refined_f0[0 ])
225
+ with (nogil, cython.boundscheck(False )):
226
+ StoneMask(& x[0 ], x_length, fs, & temporal_positions[0 ],
227
+ & f0[0 ], f0_length, & refined_f0[0 ])
225
228
return refined_f0
226
229
227
230
228
- def get_cheaptrick_fft_size (fs , f0_floor = default_f0_floor):
231
+ def get_cheaptrick_fft_size (int fs , f0_floor = default_f0_floor):
229
232
""" Calculate suitable FFT size for CheapTrick given F0 floor.
230
233
231
234
Parameters
@@ -247,7 +250,7 @@ def get_cheaptrick_fft_size(fs, f0_floor=default_f0_floor):
247
250
cdef int fft_size = GetFFTSizeForCheapTrick(fs, & option)
248
251
return fft_size
249
252
250
- def get_cheaptrick_f0_floor (fs , fft_size ):
253
+ def get_cheaptrick_f0_floor (int fs , int fft_size ):
251
254
""" Calculates actual lower F0 limit for CheapTrick
252
255
based on the sampling frequency and FFT size used. Whenever F0 is below
253
256
this threshold the spectrum will be analyzed as if the frame is unvoiced
@@ -319,11 +322,12 @@ def cheaptrick(np.ndarray[double, ndim=1, mode="c"] x not None,
319
322
cdef np.intp_t[:] tmp = np.zeros(f0_length, dtype = np.intp)
320
323
cdef double ** cpp_spectrogram = < double ** > (< void * > & tmp[0 ])
321
324
cdef np.intp_t i
322
- for i in range (f0_length):
323
- cpp_spectrogram[i] = & spectrogram[i, 0 ]
325
+ with (nogil, cython.boundscheck(False )):
326
+ for i in range (f0_length):
327
+ cpp_spectrogram[i] = & spectrogram[i, 0 ]
324
328
325
- CheapTrick(& x[0 ], x_length, fs, & temporal_positions[0 ],
326
- & f0[0 ], f0_length, & option, cpp_spectrogram)
329
+ CheapTrick(& x[0 ], x_length, fs, & temporal_positions[0 ],
330
+ & f0[0 ], f0_length, & option, cpp_spectrogram)
327
331
return np.array(spectrogram, dtype = np.float64)
328
332
329
333
@@ -386,12 +390,13 @@ def d4c(np.ndarray[double, ndim=1, mode="c"] x not None,
386
390
cdef np.intp_t[:] tmp = np.zeros(f0_length, dtype = np.intp)
387
391
cdef double ** cpp_aperiodicity = < double ** > (< void * > & tmp[0 ])
388
392
cdef np.intp_t i
389
- for i in range (f0_length):
390
- cpp_aperiodicity[i] = & aperiodicity[i, 0 ]
393
+ with (nogil, cython.boundscheck(False )):
394
+ for i in range (f0_length):
395
+ cpp_aperiodicity[i] = & aperiodicity[i, 0 ]
391
396
392
- D4C(& x[0 ], x_length, fs, & temporal_positions[0 ],
393
- & f0[0 ], f0_length, fft_size0, & option,
394
- cpp_aperiodicity)
397
+ D4C(& x[0 ], x_length, fs, & temporal_positions[0 ],
398
+ & f0[0 ], f0_length, fft_size0, & option,
399
+ cpp_aperiodicity)
395
400
return np.array(aperiodicity, dtype = np.float64)
396
401
397
402
@@ -433,7 +438,7 @@ def synthesize(np.ndarray[double, ndim=1, mode="c"] f0 not None,
433
438
.format(spectrogram.shape[1 ], aperiodicity.shape[1 ]))
434
439
435
440
cdef int f0_length = < int > len (f0)
436
- y_length = int (f0_length * frame_period * fs / 1000 )
441
+ cdef int y_length = < int > (f0_length * frame_period * fs / 1000 )
437
442
cdef int fft_size = (< int > spectrogram.shape[1 ] - 1 )* 2
438
443
cdef np.ndarray[double , ndim= 1 , mode= " c" ] y = \
439
444
np.zeros(y_length, dtype = np.dtype(' float64' ))
@@ -445,12 +450,13 @@ def synthesize(np.ndarray[double, ndim=1, mode="c"] f0 not None,
445
450
cdef double ** cpp_spectrogram = < double ** > (< void * > & tmp[0 ])
446
451
cdef double ** cpp_aperiodicity = < double ** > (< void * > & tmp2[0 ])
447
452
cdef np.intp_t i
448
- for i in range (f0_length):
449
- cpp_spectrogram[i] = & spectrogram0[i, 0 ]
450
- cpp_aperiodicity[i] = & aperiodicity0[i, 0 ]
453
+ with (nogil, cython.boundscheck(False )):
454
+ for i in range (f0_length):
455
+ cpp_spectrogram[i] = & spectrogram0[i, 0 ]
456
+ cpp_aperiodicity[i] = & aperiodicity0[i, 0 ]
451
457
452
- Synthesis(& f0[0 ], f0_length, cpp_spectrogram,
453
- cpp_aperiodicity, fft_size, frame_period, fs, y_length, & y[0 ])
458
+ Synthesis(& f0[0 ], f0_length, cpp_spectrogram,
459
+ cpp_aperiodicity, fft_size, frame_period, fs, y_length, & y[0 ])
454
460
return y
455
461
456
462
0 commit comments