Skip to content

Commit 9798349

Browse files
committed
Replaces output.resize by a view (issue #35).
1 parent 5fa9d14 commit 9798349

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/samplerate.cpp

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

184184
// create a shorter view of the array
185185
if ((size_t)src_data.output_frames_gen < new_size) {
186-
out_shape[0] = src_data.output_frames_gen;
187-
output.resize(out_shape);
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;
188190
}
189-
190-
return output;
191191
}
192192

193193
void set_ratio(double new_ratio) {
@@ -312,11 +312,11 @@ class CallbackResampler {
312312

313313
// create a shorter view of the array
314314
if (output_frames_gen < frames) {
315-
out_shape[0] = output_frames_gen;
316-
output.resize(out_shape);
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;
317319
}
318-
319-
return output;
320320
}
321321

322322
void set_starting_ratio(double new_ratio) {
@@ -413,8 +413,8 @@ py::array_t<float, py::array::c_style> resample(
413413

414414
// create a shorter view of the array
415415
if ((size_t)src_data.output_frames_gen < new_size) {
416-
out_shape[0] = src_data.output_frames_gen;
417-
output.resize(out_shape);
416+
output = output[py::slice(0, src_data.output_frames_gen, 1)]
417+
.cast<py::array_t<float, py::array::c_style>>();
418418
}
419419

420420
if (verbose) {

0 commit comments

Comments
 (0)