Skip to content

Commit

Permalink
fixup! Release GIL while resampling
Browse files Browse the repository at this point in the history
attempt to fix exception handling on windows, not tested
  • Loading branch information
tuxu committed Jan 26, 2024
1 parent e2ed8bd commit 50ac765
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/samplerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,12 @@ class CallbackResampler {
if (_state == nullptr) _create();

// read from the callback
size_t output_frames_gen = [&]() {
size_t output_frames_gen = 0;
{
py::gil_scoped_release release;
return src_callback_read(_state, _ratio, (long)frames,
static_cast<float *>(outbuf.ptr));
}();
output_frames_gen = src_callback_read(_state, _ratio, (long)frames,
static_cast<float *>(outbuf.ptr));
}

// check error status
if (output_frames_gen == 0) {
Expand Down Expand Up @@ -346,13 +347,14 @@ long the_callback_func(void *cb_data, float **data) {
CallbackResampler *cb = static_cast<CallbackResampler *>(cb_data);
int cb_channels = cb->get_channels();

py::gil_scoped_acquire acquire;

// 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
Expand Down

0 comments on commit 50ac765

Please sign in to comment.