diff --git a/src/samplerate.cpp b/src/samplerate.cpp index 42bb4d3..08ced74 100644 --- a/src/samplerate.cpp +++ b/src/samplerate.cpp @@ -179,7 +179,10 @@ class Resampler { sr_ratio // src_ratio, sampling rate conversion ratio }; - error_handler(src_process(_state, &src_data)); + error_handler([&]() { + py::gil_scoped_release release; + return src_process(_state, &src_data); + }()); // create a shorter view of the array if ((size_t)src_data.output_frames_gen < new_size) { @@ -294,8 +297,12 @@ class CallbackResampler { if (_state == nullptr) _create(); // read from the callback - size_t output_frames_gen = src_callback_read( - _state, _ratio, (long)frames, static_cast(outbuf.ptr)); + size_t output_frames_gen = 0; + { + py::gil_scoped_release release; + output_frames_gen = src_callback_read(_state, _ratio, (long)frames, + static_cast(outbuf.ptr)); + } // check error status if (output_frames_gen == 0) { @@ -340,11 +347,14 @@ long the_callback_func(void *cb_data, float **data) { CallbackResampler *cb = static_cast(cb_data); int cb_channels = cb->get_channels(); - // get the data as a numpy array - auto input = cb->callback(); + py::buffer_info inbuf; + { + py::gil_scoped_acquire acquire; - // accessors for the arrays - py::buffer_info inbuf = input.request(); + // get the data as a numpy array + auto input = cb->callback(); + inbuf = input.request(); + } // end of stream is signaled by a None, which is cast to a ndarray with ndim // == 0 @@ -407,9 +417,10 @@ py::array_t resample( sr_ratio // src_ratio, sampling rate conversion ratio }; - int ret_code = src_simple(&src_data, converter_type_int, channels); - - error_handler(ret_code); + error_handler([&]() { + py::gil_scoped_release release; + return src_simple(&src_data, converter_type_int, channels); + }()); // create a shorter view of the array if ((size_t)src_data.output_frames_gen < new_size) {