Skip to content

Commit 06e88d1

Browse files
authored
Changes buffer resize to a view. (#36)
* Replaces output.resize by a view (issue #35).
1 parent 235d720 commit 06e88d1

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/samplerate.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ class Resampler {
184184
// create a shorter view of the array
185185
if ((size_t)src_data.output_frames_gen < new_size) {
186186
out_shape[0] = src_data.output_frames_gen;
187-
output.resize(out_shape);
187+
return py::array_t<float, py::array::c_style>(
188+
out_shape, outbuf.strides, static_cast<float *>(outbuf.ptr),
189+
output);
188190
}
189191

190192
return output;
@@ -313,7 +315,10 @@ class CallbackResampler {
313315
// create a shorter view of the array
314316
if (output_frames_gen < frames) {
315317
out_shape[0] = output_frames_gen;
316-
output.resize(out_shape);
318+
auto strides = std::vector<py::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);
317322
}
318323

319324
return output;
@@ -414,7 +419,9 @@ py::array_t<float, py::array::c_style> resample(
414419
// create a shorter view of the array
415420
if ((size_t)src_data.output_frames_gen < new_size) {
416421
out_shape[0] = src_data.output_frames_gen;
417-
output.resize(out_shape);
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) {

0 commit comments

Comments
 (0)