Skip to content

Commit a3ba943

Browse files
committed
Release GIL while resampling
Fixes #13.
1 parent 354ce05 commit a3ba943

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/samplerate.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ class Resampler {
179179
sr_ratio // src_ratio, sampling rate conversion ratio
180180
};
181181

182-
error_handler(src_process(_state, &src_data));
182+
error_handler([&]() {
183+
py::gil_scoped_release release;
184+
return src_process(_state, &src_data);
185+
}());
183186

184187
// create a shorter view of the array
185188
if ((size_t)src_data.output_frames_gen < new_size) {
@@ -294,8 +297,11 @@ class CallbackResampler {
294297
if (_state == nullptr) _create();
295298

296299
// read from the callback
297-
size_t output_frames_gen = src_callback_read(
298-
_state, _ratio, (long)frames, static_cast<float *>(outbuf.ptr));
300+
size_t output_frames_gen = [&]() {
301+
py::gil_scoped_release release;
302+
return src_callback_read(_state, _ratio, (long)frames,
303+
static_cast<float *>(outbuf.ptr));
304+
}();
299305

300306
// check error status
301307
if (output_frames_gen == 0) {
@@ -407,9 +413,10 @@ py::array_t<float, py::array::c_style> resample(
407413
sr_ratio // src_ratio, sampling rate conversion ratio
408414
};
409415

410-
int ret_code = src_simple(&src_data, converter_type_int, channels);
411-
412-
error_handler(ret_code);
416+
error_handler([&]() {
417+
py::gil_scoped_release release;
418+
return src_simple(&src_data, converter_type_int, channels);
419+
}());
413420

414421
// create a shorter view of the array
415422
if ((size_t)src_data.output_frames_gen < new_size) {

0 commit comments

Comments
 (0)