python314Packages.samplerate-ledfx: fix Python 3.14 support

This commit is contained in:
Sandro Jäckel
2026-07-10 19:16:49 +02:00
parent bcfca2feda
commit b90e85e10a
2 changed files with 45 additions and 3 deletions

View File

@@ -3,12 +3,12 @@
buildPythonPackage,
cmake,
fetchFromGitHub,
fetchpatch,
libsamplerate,
numpy,
pybind11,
pytest-asyncio,
pytestCheckHook,
pythonAtLeast,
setuptools,
setuptools-scm,
}:
@@ -18,8 +18,6 @@ buildPythonPackage (finalAttrs: {
version = "0.2.6";
pyproject = true;
disabled = pythonAtLeast "3.14";
src = fetchFromGitHub {
owner = "LedFx";
repo = "python-samplerate-ledfx";
@@ -27,6 +25,12 @@ buildPythonPackage (finalAttrs: {
hash = "sha256-SLmaWSq/Ou23BfdWKlzE9gIfORgF9skUVEw1Tzpd5b4=";
};
patches = [
# Fix Python 3.14 support based on https://github.com/tuxu/python-samplerate/commit/06e88d1a869db30ce9037498f4dec2f74601d127
# but with fixes that it applies
./fix-python3.14-support.diff
];
# unvendor pybind11, libsamplerate
postPatch = ''
rm -r external

View File

@@ -0,0 +1,38 @@
diff --git a/src/samplerate.cpp b/src/samplerate.cpp
index f0eba25..04f16fd 100644
--- a/src/samplerate.cpp
+++ b/src/samplerate.cpp
@@ -268,7 +268,9 @@ class Resampler {
// create a shorter view of the array
if ((size_t)output_frames_gen < new_size) {
out_shape[0] = output_frames_gen;
- output.resize(out_shape);
+ return py::array_t<float, py::array::c_style>(
+ out_shape, outbuf.strides, static_cast<float *>(outbuf.ptr),
+ output);
} else if ((size_t)output_frames_gen >= new_size) {
// This means our fudge factor is too small.
throw std::runtime_error("Generated more output samples than expected!");
@@ -434,7 +436,10 @@ class CallbackResampler {
// create a shorter view of the array
if (output_frames_gen < frames) {
out_shape[0] = output_frames_gen;
- output.resize(out_shape);
+ auto strides = std::vector<py::ssize_t>(output.strides(),
+ output.strides() + output.ndim());
+ return py::array_t<float, py::array::c_style>(
+ out_shape, strides, static_cast<float *>(outbuf.ptr), output);
}
return output;
@@ -561,7 +566,9 @@ py::array_t<float, py::array::c_style> resample(
// create a shorter view of the array
if ((size_t)output_frames_gen < new_size) {
out_shape[0] = output_frames_gen;
- output.resize(out_shape);
+ auto base = output;
+ output = py::array_t<float, py::array::c_style>(
+ out_shape, outbuf.strides, static_cast<float *>(outbuf.ptr), base);
} else if ((size_t)output_frames_gen >= new_size) {
// This means our fudge factor is too small.
throw std::runtime_error("Generated more output samples than expected!");