Skip to content

Commit a687ad1

Browse files
committed
Addressing review comments.
1 parent 5ae5e8a commit a687ad1

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

src/samplerate.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,13 @@ class Resampler {
183183

184184
// create a shorter view of the array
185185
if ((size_t)src_data.output_frames_gen < new_size) {
186-
return output[py::slice(0, src_data.output_frames_gen, 1)]
187-
.cast<py::array_t<float, py::array::c_style>>();
188-
} else {
189-
return output;
186+
out_shape[0] = src_data.output_frames_gen;
187+
return py::array_t<float, py::array::c_style>(
188+
out_shape, outbuf.strides, static_cast<float *>(outbuf.ptr),
189+
output);
190190
}
191+
192+
return output;
191193
}
192194

193195
void set_ratio(double new_ratio) {
@@ -312,11 +314,14 @@ class CallbackResampler {
312314

313315
// create a shorter view of the array
314316
if (output_frames_gen < frames) {
315-
return output[py::slice(0, output_frames_gen, 1)]
316-
.cast<py::array_t<float, py::array::c_style>>();
317-
} else {
318-
return output;
317+
out_shape[0] = output_frames_gen;
318+
auto strides = std::vector<ssize_t>(output.strides(),
319+
output.strides() + output.ndim());
320+
return py::array_t<float, py::array::c_style>(
321+
out_shape, strides, static_cast<float *>(outbuf.ptr), output);
319322
}
323+
324+
return output;
320325
}
321326

322327
void set_starting_ratio(double new_ratio) {
@@ -413,8 +418,10 @@ py::array_t<float, py::array::c_style> resample(
413418

414419
// create a shorter view of the array
415420
if ((size_t)src_data.output_frames_gen < new_size) {
416-
output = output[py::slice(0, src_data.output_frames_gen, 1)]
417-
.cast<py::array_t<float, py::array::c_style>>();
421+
out_shape[0] = src_data.output_frames_gen;
422+
auto base = output;
423+
output = py::array_t<float, py::array::c_style>(
424+
out_shape, outbuf.strides, static_cast<float *>(outbuf.ptr), base);
418425
}
419426

420427
if (verbose) {
@@ -430,7 +437,7 @@ py::array_t<float, py::array::c_style> resample(
430437

431438
namespace sr = samplerate;
432439

433-
PYBIND11_MODULE(samplerate, m, py::mod_gil_not_used()) {
440+
PYBIND11_MODULE(samplerate, m) {
434441
m.doc() =
435442
"A simple python wrapper library around libsamplerate"; // optional
436443
// module

0 commit comments

Comments
 (0)