### Project Setup and Minimum CMake Version Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt Sets the minimum required CMake version and the project name. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.15...3.26) project(nanobind_example LANGUAGES CXX) ``` -------------------------------- ### Install Dependencies and Run Tests for Python-SoXR Source: https://github.com/dofuuz/python-soxr/blob/main/BUILDING.md Install the pytest testing framework and then execute the test suite for the installed Python-SoXR library. ```sh pip install pytest python -m pytest tests/ ``` -------------------------------- ### Install Built Python-SoXR Wheel Package Source: https://github.com/dofuuz/python-soxr/blob/main/BUILDING.md Install the Python-SoXR library from a previously built wheel (.whl) file. Do not install from the source distribution (.tar.gz). ```sh pip install ./soxr-[...].whl ``` -------------------------------- ### Generate and Install Stub File Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt Generates a Python stub file (.pyi) for the 'soxr_ext' module if not cross-compiling, and installs it. ```cmake if (NOT CMAKE_CROSSCOMPILING) # nanobind's stub generation requires importing the module, so skip it when cross-compiling nanobind_add_stub(soxr_ext_stub MODULE soxr_ext OUTPUT soxr_ext.pyi PYTHON_PATH $ DEPENDS soxr_ext ) install(FILES ${CMAKE_BINARY_DIR}/soxr_ext.pyi DESTINATION soxr) endif () ``` -------------------------------- ### Install Python-SoXR using pip Source: https://github.com/dofuuz/python-soxr/blob/main/README.md Use this command to install the Python-SoXR library via pip. If installation fails, try upgrading pip first. ```sh pip install soxr ``` -------------------------------- ### Install Module Target Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt Installs the 'soxr_ext' module target, making it available for use by the Python package. ```cmake # Install directive for scikit-build-core install(TARGETS soxr_ext LIBRARY DESTINATION soxr) ``` -------------------------------- ### Scikit-build Warning Message Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt Displays a warning if the CMake file is not run via scikit-build, guiding users to the correct installation method. ```cmake if (NOT SKBUILD) message(WARNING "\n This CMake file is meant to be executed using 'scikit-build'. Running\n it directly will almost certainly not produce the desired result. If\n you are a user trying to install this package, please use the command\n below, which will install all necessary build dependencies, compile\n the package in an isolated environment, and then install it.\n =====================================================================\n $ pip install .\n =====================================================================\n If you are a software developer, and this is your own package, then\n it is usually much more efficient to install the build dependencies\n in your environment once and use the following command that avoids\n a costly creation of a new virtual environment at every compilation:\n =====================================================================\n $ pip install nanobind scikit-build-core[pyproject]\n $ pip install --no-build-isolation -ve .\n =====================================================================\n You may optionally add -Ceditable.rebuild=true to auto-rebuild when\n the package is imported. Otherwise, you need to re-run the above\n after editing C++ files.") endif() ``` -------------------------------- ### Build Python-SoXR Wheel with System libsoxr Source: https://github.com/dofuuz/python-soxr/blob/main/BUILDING.md Build the wheel package for Python-SoXR, linking dynamically against a system-installed libsoxr. Ensure libsoxr-dev is installed on your system first. ```sh pip wheel -v . -C cmake.define.USE_SYSTEM_LIBSOXR=ON ``` -------------------------------- ### Install Python-SoXR in Conda environment Source: https://github.com/dofuuz/python-soxr/blob/main/README.md Install the Python-SoXR package using conda. Note that the package name in conda is 'soxr-python'. ```sh conda install -c conda-forge soxr-python ``` -------------------------------- ### Prepare Environment for Building Python-SoXR Source: https://github.com/dofuuz/python-soxr/blob/main/BUILDING.md Upgrade pip to the latest version and clone the Python-SoXR repository, ensuring submodules are included. Navigate into the cloned directory. ```sh python -m pip install --upgrade pip git clone --recurse-submodules https://github.com/dofuuz/python-soxr.git cd python-soxr ``` -------------------------------- ### Conditional libsoxr Versioning Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt Configures how the libsoxr version is handled. If USE_SYSTEM_LIBSOXR is ON, it uses the system library. Otherwise, it sets up VCS versioning for libsoxr. ```cmake if (USE_SYSTEM_LIBSOXR) set(CSOXR_VER_C src/csoxr_version.cpp) else () # libsoxr VCS versioning set(CSOXR_VER_C ${CMAKE_CURRENT_SOURCE_DIR}/src/csoxr_ver_vcs.cpp) set(SOXR_VER_COMMAND ${CMAKE_COMMAND} -DVERSION_IN=src/csoxr_ver_vcs.cpp.in -DVERSION_C=${CSOXR_VER_C} -DVCS_REPO_DIR=libsoxr -P cmake/versioning.cmake ) # run while CMake configuring (for sdist) execute_process( COMMAND ${SOXR_VER_COMMAND} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) # run at every build time add_custom_target(soxr_version_vcs COMMAND ${SOXR_VER_COMMAND} BYPRODUCTS ${CSOXR_VER_C} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif () ``` -------------------------------- ### Find nanobind Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt Finds the nanobind configuration, which is required for building the C++ extension module. ```cmake find_package(nanobind CONFIG REQUIRED) ``` -------------------------------- ### Add nanobind Module Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt Defines the nanobind module 'soxr_ext' with specified build properties and source files, including the versioning file. ```cmake nanobind_add_module(soxr_ext STABLE_ABI FREE_THREADED NB_STATIC src/soxr_ext.cpp ${CSOXR_VER_C} ) ``` -------------------------------- ### Link System libsoxr Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt If using the system libsoxr, this section finds the library and header files and links them to the 'soxr_ext' target. ```cmake if (USE_SYSTEM_LIBSOXR) # Find system libsoxr find_library(SOXR_LIBRARY NAMES soxr) find_path(SOXR_INCLUDE_DIR soxr.h) message (STATUS "Building with external libsoxr") message(SOXR_LIBRARY="${SOXR_LIBRARY}") message(SOXR_INCLUDE_DIR="${SOXR_INCLUDE_DIR}") target_link_libraries(soxr_ext PRIVATE ${SOXR_LIBRARY}) target_include_directories(soxr_ext PRIVATE ${SOXR_INCLUDE_DIR}) else () target_link_libraries(soxr_ext PRIVATE soxr) target_include_directories(soxr_ext PRIVATE src libsoxr/src ) # Build static libsoxr option(BUILD_TESTS "" OFF) option(WITH_OPENMP "" OFF) # OpenMP seems not working (dunno why). Disable it for portability anyway. option(WITH_LSR_BINDINGS "" OFF) option(BUILD_SHARED_LIBS "" OFF) # make it shared someday? set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_INSTALL_PREFIX ../install) add_subdirectory(libsoxr libsoxr) # Copy licenses to package (scikit-build-core) install(FILES cmake/LICENSE-PFFFT.txt DESTINATION ${SKBUILD_METADATA_DIR}/licenses) install(FILES libsoxr/LICENCE DESTINATION ${SKBUILD_METADATA_DIR}/licenses RENAME LICENSE-libsoxr.txt) endif () ``` -------------------------------- ### Option for System libsoxr Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt Defines a CMake option to control whether to use the system's libsoxr or build it from source. Defaults to OFF. ```cmake option(USE_SYSTEM_LIBSOXR "Build using system libsoxr" OFF) ``` -------------------------------- ### Basic Resampling with Python-SoXR Source: https://github.com/dofuuz/python-soxr/blob/main/README.md Demonstrates basic audio resampling using the `soxr.resample` function. The input can be a mono (1D) or multi-channel (2D) numpy array. The input and target sample rates are specified. The output will be a numpy array with the same dimensions and data type as the input. ```python import soxr y = soxr.resample( x, # input array – mono(1D) or multi-channel(2D of [frame, channel]) 48000, # input samplerate 16000 # target samplerate ) ``` -------------------------------- ### Streaming Resampling with Python-SoXR Source: https://github.com/dofuuz/python-soxr/blob/main/README.md Illustrates how to use `ResampleStream` for real-time processing or very long signals. Initialize `ResampleStream` with input/target sample rates, channels, and data type. Process input chunks using `resample_chunk`, setting `last=True` for the final chunk. ```python import soxr rs = soxr.ResampleStream( 44100, # input samplerate 16000, # target samplerate 1, # channel(s) dtype='float32' # data type (default = 'float32') ) eof = False while not eof: # Get chunk ... y_chunk = rs.resample_chunk( x, # input aray – mono(1D) or multi-channel(2D of [frame, channel]) last=eof # Set True at end of input ) ``` -------------------------------- ### Build Python-SoXR Wheel Package Source: https://github.com/dofuuz/python-soxr/blob/main/BUILDING.md Build the wheel package for Python-SoXR using pip wheel. This command compiles the library and creates a distributable wheel file. ```sh pip wheel -v . ``` -------------------------------- ### Find Python Interpreter Source: https://github.com/dofuuz/python-soxr/blob/main/CMakeLists.txt Finds the Python 3.9 interpreter and its development components, which are required for building the Python extension. ```cmake find_package(Python 3.9 REQUIRED COMPONENTS Interpreter Development.Module OPTIONAL_COMPONENTS Development.SABIModule) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.