From 12fde9b612a7808457484824ccfbc43696355055 Mon Sep 17 00:00:00 2001 From: Tino Wagner Date: Wed, 6 Sep 2023 00:41:30 +0200 Subject: [PATCH 1/3] Move definition of _create back into CallbackResampler --- src/samplerate.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/samplerate.cpp b/src/samplerate.cpp index 88b1d35..0326a46 100644 --- a/src/samplerate.cpp +++ b/src/samplerate.cpp @@ -201,6 +201,12 @@ class Resampler { Resampler clone() const { return Resampler(*this); } }; +namespace { + +long the_callback_func(void *cb_data, float **data); + +} // namespace + class CallbackResampler { private: SRC_STATE *_state = nullptr; @@ -214,9 +220,13 @@ class CallbackResampler { size_t _channels = 0; private: - // the definition of `_create` is defered to after the definition and - // declaration of `the_callback_func` callback function below. - void _create(); + void _create() { + int _err_num = 0; + _state = src_callback_new(the_callback_func, _converter_type, (int)_channels, + &_err_num, static_cast(this)); + if (_state == nullptr) error_handler(_err_num); + } + void _destroy() { if (_state != nullptr) { src_delete(_state); @@ -329,8 +339,6 @@ class CallbackResampler { namespace { -long the_callback_func(void *cb_data, float **data); - long the_callback_func(void *cb_data, float **data) { CallbackResampler *cb = static_cast(cb_data); int cb_channels = cb->get_channels(); @@ -362,13 +370,6 @@ long the_callback_func(void *cb_data, float **data) { } // namespace -void CallbackResampler::_create() { - int _err_num = 0; - _state = src_callback_new(the_callback_func, _converter_type, (int)_channels, - &_err_num, static_cast(this)); - if (_state == nullptr) error_handler(_err_num); -} - py::array_t resample( const py::array_t &input, double sr_ratio, const py::object &converter_type, bool verbose) { From 86f51710ae596f65680085b85aa491add892bdaa Mon Sep 17 00:00:00 2001 From: Tino Wagner Date: Wed, 6 Sep 2023 00:57:08 +0200 Subject: [PATCH 2/3] Fix build of documentation, no more mocking --- docs/conf.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index a81346f..fc2cc0c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,29 +18,10 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. # # import os -import sys +# import sys # sys.path.insert(0, os.path.abspath('.')) -# Mock C modules -try: - from unittest.Mock import MagicMock # Python >3.3 -except ImportError: - try: - from mock import MagicMock - except ImportError: - raise ImportError("No module named mock") - - -class Mock(MagicMock): - @classmethod - def __getattr__(cls, name): - return MagicMock() - - -mock_modules = ["numpy", "samplerate._src"] -sys.modules.update((mod_name, Mock()) for mod_name in mock_modules) - import samplerate # -- General configuration ------------------------------------------------ From 68d011fd1c2d26a718d29c90b30c31a212103568 Mon Sep 17 00:00:00 2001 From: Tino Wagner Date: Wed, 6 Sep 2023 01:55:58 +0200 Subject: [PATCH 3/3] Pass package version to CMake --- CMakeLists.txt | 7 +++++-- setup.py | 3 +-- src/samplerate.cpp | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d495f33..6635a53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,8 +28,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR target_compile_options(python-samplerate PRIVATE -std=c++14 -O3 -Wall -Wextra) endif() -### stick the libsamlerate version into the compilation -target_compile_definitions(python-samplerate PUBLIC LIBSAMPLERATE_VERSION="${LIBSAMPLERATE_VERSION}") +### stick the package and libsamplerate version into the module +target_compile_definitions(python-samplerate + PUBLIC LIBSAMPLERATE_VERSION="${LIBSAMPLERATE_VERSION}" + PRIVATE $<$:VERSION_INFO="${PACKAGE_VERSION_INFO}"> +) ### Final target setup set_target_properties( diff --git a/setup.py b/setup.py index 36f517e..53f9fcd 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,6 @@ import re import subprocess import sys -from distutils.version import LooseVersion from pathlib import Path import setuptools @@ -64,7 +63,7 @@ def build_extension(self, ext: CMakeExtension) -> None: cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] # In this example, we pass in the version to C++. You might not need to. - # cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"] + cmake_args += [f"-DPACKAGE_VERSION_INFO={self.distribution.get_version()}"] if self.compiler.compiler_type != "msvc": # Using Ninja-build since it a) is available as a wheel and b) diff --git a/src/samplerate.cpp b/src/samplerate.cpp index 0326a46..1a8873f 100644 --- a/src/samplerate.cpp +++ b/src/samplerate.cpp @@ -36,7 +36,6 @@ #include #include -// avoids an error if we compile with raw cmake #ifndef VERSION_INFO #define VERSION_INFO "nightly" #endif